Guest User

Untitled

a guest
Dec 5th, 2018
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.67 KB | None | 0 0
  1. //capa usuario
  2.  
  3. public class Usuario
  4. {
  5. private string _IdUsuario;
  6. private string _Rut;
  7. private string _NombreCompleto;
  8. private int _Telefono;
  9. private string _Correo;
  10.  
  11. //constructor hecho
  12. //getter y setter hechos
  13.  
  14. }
  15.  
  16. //capa para llamar instancia del cmt
  17. public string MetodoCMT()
  18. {
  19. try
  20. {
  21. return obNombreUsuarioDA.MetodoCMT();
  22. }
  23. catch (Exception ex)
  24. {
  25. throw ex;
  26. return null;
  27. }
  28. }
  29.  
  30. //capa para conectar al CMT
  31. public class ConectarCMT
  32. {
  33. static public String _userName = ConfigurationManager.AppSettings["USER_CRM"];
  34. static public String _password = ConfigurationManager.AppSettings["PASS_CRM"];
  35. static public string _deviceId = "";
  36. static public string _devicePass = "";
  37. static public String organizationUri = ConfigurationManager.AppSettings["URL_CRM"];
  38.  
  39. static public OrganizationServiceProxy CreateOrganization()
  40. {
  41. ClientCredentials cred1 = new ClientCredentials();
  42. cred1.UserName.UserName = _userName;
  43. cred1.UserName.Password = _password;
  44. ClientCredentials cred2 = new ClientCredentials();
  45. cred2.UserName.UserName = _deviceId;
  46. cred2.UserName.Password = _devicePass;
  47. OrganizationServiceProxy obj;
  48. if (_deviceId.Length > 0)
  49. obj = new OrganizationServiceProxy(
  50. new Uri(organizationUri),
  51. null,
  52. cred1,
  53. cred2);
  54. else
  55. obj = new OrganizationServiceProxy(
  56. new Uri(organizationUri),
  57. null,
  58. cred1,
  59. null);
  60. obj.EnableProxyTypes();
  61.  
  62. return obj;
  63.  
  64. }
  65. }
  66.  
  67. //Capa de datos
  68. public static bool MetodoAgregarCRM(Usuario us)
  69. {
  70. IOrganizationService servicio;
  71. servicio = ConectarCMT.CreateOrganization();
  72. try
  73. {
  74. Account ac = new Account();
  75. ac.zth_idn = us.Rut;
  76. ac.Name = us.NombreCompleto;
  77. ac.Telephone1 = us.Telefono.ToString();
  78. ac.EMailAddress1 = us.Correo;
  79. servicio.Create(ac);
  80. return true;
  81. }
  82. catch (Exception ex)
  83. {
  84. throw new Exception(ex.Message);
  85. }
  86.  
  87. }
  88. //capa de vista
  89. protected void btnAgregar_Click(object sender, EventArgs e)
  90. {
  91. try
  92. {
  93. Usuario us = new Usuario();
  94. us.Rut = txtRut.Text;
  95. us.NombreCompleto = txtNombreCompleto.Text;
  96. us.Telefono = int.Parse(txtTelefono.Text);
  97. us.Correo = txtCorreo.Text;
  98. bool resp = NombreUsuarioDA.MetodoAgregarCMT(us);
  99. }
  100. catch (Exception ex)
  101. {
  102. throw new Exception(ex.Message); ;
  103. }
  104.  
  105. Limpiar();
  106.  
  107. }
  108.  
  109. private void Limpiar()
  110. {
  111. txtRut.Text = "";
  112. txtNombreCompleto.Text = "";
  113. txtTelefono.Text = "";
  114. txtCorreo.Text = "";
  115. }
Add Comment
Please, Sign In to add comment