private void RefreshSources(List <Cliente> clientes) { #region Load sources //Carga el combobox de TipoDocumento CboTipoDocumento.DataSource = TipoDocumentoPersistance.GetAll(); CboTipoDocumento.ValueMember = "ID"; CboTipoDocumento.DisplayMember = "Descripcion"; #endregion ClearDataGridView(); var clientesDictionary = new Dictionary <int, Cliente>(); #region Cargar el diccionario a mostrar en la grilla if (clientes == null) { //El datasource se carga con todos los Clientes de la BD CleanFiltersUI(); _clientes = ClientePersistance.GetAllClients(); clientesDictionary = _clientes.ToDictionary(a => a.ID, a => a); } else { //El datasource se carga con la lista de Clientes recibida por parámetro clientesDictionary = clientes.ToDictionary(a => a.ID, a => a); } #endregion //Muestra en la grilla el contenido de los clientes que se encuentran cargados en el diccionario var bind = clientesDictionary.Values.Select(a => new { ID = a.ID, ID_Usuario = a.IdUsuario, Nombre = a.Nombre, Apellido = a.Apellido, Tipo_Documento = TipoDocumentoPersistance.GetById(a.TipoDocumento).Descripcion, Nro_Documento = a.NroDocumento, Mail = a.Mail, Telefono = a.Telefono, Direccion = a.Direccion, Cod_Postal = a.CodigoPostal, F_Nacimiento = a.FechaNacimiento, CUIL = a.CUIL, Habilitado = a.Habilitado }); DgvClientes.DataSource = bind.ToList(); AddButtonsColumns(); DgvClientes.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; }
public FrmDatosVendedor(Usuario user) { InitializeComponent(); try { Cliente userCliente = ClientePersistance.GetByUserId(user.ID); if (userCliente != null) { lblNombre.Text = userCliente.Nombre + " " + userCliente.Apellido; lblMail.Text = userCliente.Mail; lblDireccion.Text = userCliente.Direccion; lblCodigoPostal.Text = userCliente.CodigoPostal; lblTelefono.Text = userCliente.Telefono; } else { Empresa userEmpresa = EmpresaPersistance.GetByUserId(user.ID); if (userEmpresa != null) { lblNombre.Text = userEmpresa.NombreContacto; lblMail.Text = userEmpresa.Mail; lblDireccion.Text = userEmpresa.Direccion; lblCodigoPostal.Text = userEmpresa.CodigoPostal; lblTelefono.Text = userEmpresa.Telefono; } else { throw new Exception("No se pudo encontrar al vendedor"); } } } catch (Exception e) { MessageBox.Show(e.Message); } }
private void LblBuscar_Click(object sender, EventArgs e) { try { #region Validations var filtersSetted = false; var exceptionMessage = string.Empty; if (!TypesHelper.IsEmpty(TxtNombre.Text)) { filtersSetted = true; } if (!TypesHelper.IsEmpty(TxtApellido.Text)) { filtersSetted = true; } if (!TypesHelper.IsEmpty(CboTipoDocumento.Text)) { filtersSetted = true; } if (!TypesHelper.IsEmpty(TxtDocumento.Text)) { filtersSetted = true; } int document; if (int.TryParse(TxtDocumento.Text, out document)) { filtersSetted = true; } if (!TypesHelper.IsEmpty(TxtEmail.Text)) { filtersSetted = true; } if (!filtersSetted) { exceptionMessage = "No se puede realizar la búsqueda. Verifique que haya ingresado algún filtro y que los mismos sean válidos."; } if (!TypesHelper.IsEmpty(exceptionMessage)) { throw new Exception(exceptionMessage); } #endregion //Cargar los filtros ingresados en el objeto de tipo ClienteFilters var filters = new ClienteFilters { Nombre = (!TypesHelper.IsEmpty(TxtNombre.Text)) ? TxtNombre.Text : null, Apellido = (!TypesHelper.IsEmpty(TxtApellido.Text)) ? TxtApellido.Text : null, TipoDocumento = (!TypesHelper.IsEmpty(CboTipoDocumento.Text)) ? (int)CboTipoDocumento.SelectedValue : (int?)null, NroDocumento = (!TypesHelper.IsEmpty(TxtDocumento.Text)) ? Convert.ToInt32(TxtDocumento.Text) : (int?)null, Email = (!TypesHelper.IsEmpty(TxtEmail.Text)) ? TxtEmail.Text : null }; var clientes = (ChkBusquedaExacta.Checked) ? ClientePersistance.GetAllClientsByParameters(filters) : ClientePersistance.GetAllClientsByParametersLike(filters); if (clientes == null || clientes.Count == 0) { throw new Exception("No se encontraron clientes según los filtros informados."); } //Refrescar la grilla, cargando los Clientes que se obtuvieron como resultado de los filtros RefreshSources(clientes); } catch (Exception ex) { MessageBox.Show(ex.Message, "Atención"); } }
private void LblGrabar_Click(object sender, EventArgs e) { try { #region Validaciones var exceptionMessage = string.Empty; if (string.IsNullOrEmpty(TxtNombre.Text)) { exceptionMessage += "El nombre del cliente no puede ser vacío.\n"; } if (string.IsNullOrEmpty(TxtApellido.Text)) { exceptionMessage += "El apellido del cliente no puede ser vacío.\n"; } if (string.IsNullOrEmpty(CboTipoDocumento.Text)) { exceptionMessage += "El tipo de documento del cliente no puede ser vacío.\n"; } if (string.IsNullOrEmpty(TxtDocumento.Text)) { exceptionMessage += "El número de documento del cliente no puede ser vacío.\n"; } else { int nroDoc; if (!int.TryParse(TxtDocumento.Text, out nroDoc)) { exceptionMessage += "El número de documento del cliente no es válido.\n"; } } if (string.IsNullOrEmpty(TxtMail.Text)) { exceptionMessage += "El mail del cliente no puede ser vacío.\n"; } if (string.IsNullOrEmpty(TxtTelefono.Text)) { exceptionMessage += "El teléfono del cliente no puede ser vacío.\n"; } if (string.IsNullOrEmpty(TxtDireccion.Text)) { exceptionMessage += "La dirección del cliente no puede ser vacío.\n"; } if (string.IsNullOrEmpty(TxtCodigoPostal.Text)) { exceptionMessage += "El código postal del cliente no puede ser vacío.\n"; } if (string.IsNullOrEmpty(TxtCuil.Text)) { exceptionMessage += "El CUIL del cliente no puede ser vacío.\n"; } else { if (!TypesHelper.IsCUITValid(TxtCuil.Text)) { exceptionMessage += Environment.NewLine + "El CUIL no es válido.\n"; } } if (!string.IsNullOrEmpty(exceptionMessage)) { throw new Exception(exceptionMessage); } #endregion if (insertMode) { //Valido que no se dupliquen los telefonos ni documentos if (ClientePersistance.GetByPhone(TxtTelefono.Text, this.currentTransaction) != null) { throw new Exception("Ya existe un cliente con el teléfono ingresado."); } if (ClientePersistance.GetByDocument((int)CboTipoDocumento.SelectedValue, Int32.Parse(TxtDocumento.Text), this.currentTransaction) != null) { throw new Exception("Ya existe un cliente con el tipo y número de documento ingresados."); } #region Inserto el nuevo cliente var client = new Cliente(); client.IdUsuario = SessionManager.CurrentUser.ID; client.Nombre = TxtNombre.Text; client.Apellido = TxtApellido.Text; client.TipoDocumento = (int)CboTipoDocumento.SelectedValue; client.NroDocumento = Int32.Parse(TxtDocumento.Text); client.Mail = TxtMail.Text; client.Telefono = TxtTelefono.Text; client.Direccion = TxtDireccion.Text; client.CodigoPostal = TxtCodigoPostal.Text; client.CUIL = TxtCuil.Text; client.FechaNacimiento = DtpFechaNacimiento.Value; var dialogAnswer = MessageBox.Show("¿Está seguro que quiere insertar el nuevo cliente?", "Atencion", MessageBoxButtons.YesNo); if (dialogAnswer == DialogResult.Yes) { //Si es el administrador el que hace el Alta, se genera un usuario con password temporal if (insertDefaultUser) { var user = new Usuario(); user.Username = client.NroDocumento.ToString(); user.Password = SHA256Helper.Encode("temporal"); var userIngresado = UsuarioPersistance.InsertUserTemporal(user, this.currentTransaction); client.IdUsuario = userIngresado.ID; ClientePersistance.InsertClient(client, this.currentTransaction); this.currentTransaction.Commit(); var rol = RolPersistance.GetByName("Cliente"); RolPersistance.InsertUserRole(userIngresado, rol, null); } else { ClientePersistance.InsertClient(client, this.currentTransaction); this.currentTransaction.Commit(); } MessageBox.Show("El Cliente ha sido ingresado con éxito.", "Atención!"); this.Hide(); if (!_abmCliente) { var frmHome = new FrmHome(); frmHome.ShowDialog(); } } #endregion } else { if (TxtTelefono.Text != CurrentCliente.Telefono) { if (ClientePersistance.GetByPhone(TxtTelefono.Text, this.currentTransaction) != null) { throw new Exception("Ya existe un cliente con el teléfono ingresado."); } } var client = new Cliente(); client.IdUsuario = CurrentCliente.IdUsuario; client.Nombre = TxtNombre.Text; client.Apellido = TxtApellido.Text; client.TipoDocumento = (int)CboTipoDocumento.SelectedValue; client.NroDocumento = Convert.ToInt32(TxtDocumento.Text); client.Mail = TxtMail.Text; client.Telefono = TxtTelefono.Text; client.Direccion = TxtDireccion.Text; client.CodigoPostal = TxtCodigoPostal.Text; client.CUIL = TxtCuil.Text; client.FechaNacimiento = DtpFechaNacimiento.Value; var dialogAnswer = MessageBox.Show("¿Está seguro que quiere modificar el cliente?", "Atención", MessageBoxButtons.YesNo); if (dialogAnswer == DialogResult.Yes) { ClientePersistance.UpdateClient(client); CompleteAction = true; this.Hide(); } } } catch (Exception ex) { MessageBox.Show(ex.Message, "Atención"); } }