Пример #1
0
        private void RefreshSources(List <Empresa> empresas)
        {
            ClearDataGridView();
            var empresasDictionary = new Dictionary <int, Empresa>();

            #region Get the dictionary of visibilities

            if (empresas == null)
            {
                //The datasource must be all the visibilities records stored in the database
                CleanFiltersUI();
                _empresas          = EmpresaPersistance.GetAllBusiness();
                empresasDictionary = _empresas.ToDictionary(a => a.ID, a => a);
            }
            else
            {
                //The datasource must be the list of visibilities received as parameter
                empresasDictionary = empresas.ToDictionary(a => a.ID, a => a);
            }

            #endregion

            var bind = empresasDictionary.Values.Select(a => new
            {
                ID           = a.ID,
                ID_Usuario   = a.IdUsuario,
                Razon_Social = a.RazonSocial,
                Mail         = a.Mail,
                Telefono     = a.Telefono,
                Direccion    = a.Direccion,
                Cod_Postal   = a.CodigoPostal,
                Ciudad       = a.Ciudad,
                CUIT         = a.CUIT,
                Nom_Contacto = a.NombreContacto,
                F_Creacion   = a.FechaCreacion,
                Habilitado   = a.Habilitado
            });

            DgvEmpresas.DataSource = bind.ToList();
            AddButtonsColumns();

            DgvEmpresas.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
        }
Пример #2
0
 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 LblGrabar_Click(object sender, EventArgs e)
        {
            try
            {
                #region Validations

                var exceptionMessage = string.Empty;

                if (string.IsNullOrEmpty(TxtRazonSocial.Text))
                {
                    exceptionMessage += "La razón social de la empresa no puede ser vacío.\n";
                }

                if (string.IsNullOrEmpty(TxtMail.Text))
                {
                    exceptionMessage += "El mail de la empresa no puede ser vacío.\n";
                }

                if (string.IsNullOrEmpty(TxtTelefono.Text))
                {
                    exceptionMessage += "El telefono de la empresa no puede ser vacío.\n";
                }

                if (string.IsNullOrEmpty(TxtDireccion.Text))
                {
                    exceptionMessage += "La dirección de la empresa no puede ser vacío.\n";
                }

                if (string.IsNullOrEmpty(TxtCodigoPostal.Text))
                {
                    exceptionMessage += "El código postal de la empresa no puede ser vacío.\n";
                }

                if (string.IsNullOrEmpty(TxtCiudad.Text))
                {
                    exceptionMessage += "La ciudad de la empresa no puede ser vacío.\n";
                }

                if (string.IsNullOrEmpty(TxtCuit.Text))
                {
                    exceptionMessage += "El CUIT de la empresa no puede ser vacío.\n";
                }

                if (string.IsNullOrEmpty(TxtNombreContacto.Text))
                {
                    exceptionMessage += "El nombre de contacto de la empresa no puede ser vacío.\n";
                }

                if (!string.IsNullOrEmpty(exceptionMessage))
                {
                    throw new Exception(exceptionMessage);
                }



                #endregion

                if (insertMode)
                {
                    if (EmpresaPersistance.GetByBusinessName(TxtRazonSocial.Text, this.currentTransaction) != null)
                    {
                        throw new Exception("Ya existe una empresa con la razón social ingresada.");
                    }

                    if (EmpresaPersistance.GetByCUIT(TxtCuit.Text, this.currentTransaction) != null)
                    {
                        throw new Exception("Ya existe una empresa con el CUIT ingresado.");
                    }

                    #region Inserto la nueva empresa

                    var company = new Empresa();
                    company.IdUsuario      = SessionManager.CurrentUser.ID;
                    company.RazonSocial    = TxtRazonSocial.Text;
                    company.Mail           = TxtMail.Text;
                    company.Telefono       = TxtTelefono.Text;
                    company.Direccion      = TxtDireccion.Text;
                    company.CodigoPostal   = TxtCodigoPostal.Text;
                    company.Ciudad         = TxtCiudad.Text;
                    company.CUIT           = TxtCuit.Text;
                    company.NombreContacto = TxtNombreContacto.Text;
                    company.FechaCreacion  = DtpFechaCreacion.Value;

                    var dialogAnswer = MessageBox.Show("Esta seguro que quiere insertar la nueva empresa?", "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 = company.CUIT;
                            user.Password = SHA256Helper.Encode("temporal");
                            var userIngresado = UsuarioPersistance.InsertUserTemporal(user, this.currentTransaction);

                            company.IdUsuario = userIngresado.ID;
                            EmpresaPersistance.InsertCompany(company, this.currentTransaction);
                            this.currentTransaction.Commit();

                            var rol = RolPersistance.GetByName("Empresa");
                            RolPersistance.InsertUserRole(userIngresado, rol, null);
                        }
                        else
                        {
                            EmpresaPersistance.InsertCompany(company, this.currentTransaction);
                            this.currentTransaction.Commit();
                        }

                        MessageBox.Show("La Empresa ha sido ingresada con éxito.", "Atención!");
                        this.Hide();
                        if (!_abmEmpresa)
                        {
                            var frmHome = new FrmHome();
                            frmHome.ShowDialog();
                        }
                    }

                    #endregion
                }
                else
                {
                    var company = new Empresa();
                    company.IdUsuario      = CurrentEmpresa.IdUsuario;
                    company.RazonSocial    = TxtRazonSocial.Text;
                    company.Mail           = TxtMail.Text;
                    company.Telefono       = TxtTelefono.Text;
                    company.Direccion      = TxtDireccion.Text;
                    company.CodigoPostal   = TxtCodigoPostal.Text;
                    company.Ciudad         = TxtCiudad.Text;
                    company.CUIT           = TxtCuit.Text;
                    company.NombreContacto = TxtNombreContacto.Text;
                    company.FechaCreacion  = DtpFechaCreacion.Value;

                    var dialogAnswer = MessageBox.Show("Esta seguro que quiere modificar la empresa?", "Atencion", MessageBoxButtons.YesNo);
                    if (dialogAnswer == DialogResult.Yes)
                    {
                        EmpresaPersistance.UpdateCompany(company);
                        CompleteAction = true;
                        this.Hide();
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Atención");
            }
        }
Пример #4
0
        private void LblBuscar_Click(object sender, EventArgs e)
        {
            try
            {
                #region Validations

                var filtersSetted    = false;
                var exceptionMessage = string.Empty;

                if (!TypesHelper.IsEmpty(TxtRazonSocial.Text))
                {
                    filtersSetted = true;
                }

                if (!TypesHelper.IsEmpty(TxtCuit.Text))
                {
                    filtersSetted = true;
                    if (!TypesHelper.IsCUITValid(TxtCuit.Text))
                    {
                        exceptionMessage += Environment.NewLine + "El cuit no es un cuit válido.";
                    }
                }

                if (!TypesHelper.IsEmpty(TxtEmail.Text))
                {
                    filtersSetted = true;
                }

                if (!filtersSetted)
                {
                    exceptionMessage = "No se puede realizar la busqueda ya que no se informó ningún filtro";
                }

                if (!TypesHelper.IsEmpty(exceptionMessage))
                {
                    throw new Exception(exceptionMessage);
                }

                #endregion

                var filters = new EmpresaFilters
                {
                    RazonSocial = (!TypesHelper.IsEmpty(TxtRazonSocial.Text)) ? TxtRazonSocial.Text : null,
                    Cuit        = (!TypesHelper.IsEmpty(TxtCuit.Text)) ? TxtCuit.Text : null,
                    Email       = (!TypesHelper.IsEmpty(TxtEmail.Text)) ? TxtEmail.Text : null
                };

                var empresas = (ChkBusquedaExacta.Checked) ? EmpresaPersistance.GetAllBusinessByParameters(filters) : EmpresaPersistance.GetAllBusinessByParametersLike(filters);

                if (empresas == null || empresas.Count == 0)
                {
                    throw new Exception("No se encontraron empresas según los filtros informados.");
                }

                RefreshSources(empresas);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Atención");
            }
        }