Пример #1
0
 private void LblNuevo_Click(object sender, EventArgs e)
 {
     this.Hide();
     using (var transaction = DataBaseManager.Instance().Connection.BeginTransaction(IsolationLevel.Serializable))
     {
         var frmABMInsertUpdateEmpresa = new FrmABMInsertUpdateEmpresa(transaction);
         frmABMInsertUpdateEmpresa.ShowDialog();
     }
 }
Пример #2
0
        private void DgvEmpresas_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            //Only works when user clicks one of the buttons (column index 5 and 6)
            if (e.ColumnIndex < 12 || e.RowIndex == -1)
            {
                return;
            }

            var selectedEmpresa = _empresas.Find(empresa => empresa.ID == (int)DgvEmpresas.Rows[e.RowIndex].Cells[0].Value);

            if (selectedEmpresa != null)
            {
                //User clicked update button
                if (e.ColumnIndex == 12)
                {
                    var insertUpdateEmpresa = new FrmABMInsertUpdateEmpresa(selectedEmpresa);
                    insertUpdateEmpresa.ShowDialog();

                    if (insertUpdateEmpresa.CompleteAction)
                    {
                        RefreshSources(null);
                    }
                }
                else
                {
                    //User clicked delete button
                    if (selectedEmpresa.Habilitado == true)
                    {
                        var dialogAnswer = MessageBox.Show(string.Format("Esta seguro que quiere desactivar la empresa {0}?", selectedEmpresa.RazonSocial), "Atención", MessageBoxButtons.YesNo);
                        if (dialogAnswer == DialogResult.Yes)
                        {
                            UsuarioPersistance.UpdateToDisabledById(selectedEmpresa.IdUsuario);

                            RefreshSources(null);
                        }
                    }
                    else
                    {
                        var dialogAnswer = MessageBox.Show(string.Format("Esta seguro que quiere activar la empresa {0}?", selectedEmpresa.RazonSocial), "Atención", MessageBoxButtons.YesNo);
                        if (dialogAnswer == DialogResult.Yes)
                        {
                            UsuarioPersistance.UpdateToActivateById(selectedEmpresa.IdUsuario);

                            RefreshSources(null);
                        }
                    }
                }
            }
        }
Пример #3
0
        private void DgvEmpresas_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            //Only works when user clicks one of the buttons (column index 5 and 6)
            if (e.ColumnIndex < 12 || e.RowIndex == -1)
                return;

            var selectedEmpresa = _empresas.Find(empresa => empresa.ID == (int)DgvEmpresas.Rows[e.RowIndex].Cells[0].Value);

            if (selectedEmpresa != null)
            {
                //User clicked update button
                if (e.ColumnIndex == 12)
                {
                    var insertUpdateEmpresa = new FrmABMInsertUpdateEmpresa(selectedEmpresa);
                    insertUpdateEmpresa.ShowDialog();

                    if (insertUpdateEmpresa.CompleteAction)
                        RefreshSources(null);
                }
                else
                {
                    //User clicked delete button
                    if (selectedEmpresa.Habilitado == true)
                    {
                        var dialogAnswer = MessageBox.Show(string.Format("Esta seguro que quiere desactivar la empresa {0}?", selectedEmpresa.RazonSocial), "Atención", MessageBoxButtons.YesNo);
                        if (dialogAnswer == DialogResult.Yes)
                        {
                            UsuarioPersistance.UpdateToDisabledById(selectedEmpresa.IdUsuario);

                            RefreshSources(null);
                        }
                    }
                    else
                    {
                        var dialogAnswer = MessageBox.Show(string.Format("Esta seguro que quiere activar la empresa {0}?", selectedEmpresa.RazonSocial), "Atención", MessageBoxButtons.YesNo);
                        if (dialogAnswer == DialogResult.Yes)
                        {
                            UsuarioPersistance.UpdateToActivateById(selectedEmpresa.IdUsuario);

                            RefreshSources(null);
                        }
                    }
                }
            }
        }
Пример #4
0
 private void LblNuevo_Click(object sender, EventArgs e)
 {
     this.Hide();
     using (var transaction = DataBaseManager.Instance().Connection.BeginTransaction(IsolationLevel.Serializable))
     {
         var frmABMInsertUpdateEmpresa = new FrmABMInsertUpdateEmpresa(transaction);
         frmABMInsertUpdateEmpresa.ShowDialog();
     }
 }
Пример #5
0
        private void LblGrabar_Click(object sender, EventArgs e)
        {
            try
            {
                #region Validaciones
                var exceptionMessage = string.Empty;

                if (string.IsNullOrEmpty(TxtUsuario.Text))
                    throw new Exception("El usuario no puede ser vacío.");

                if (string.IsNullOrEmpty(TxtContrasena.Text))
                    throw new Exception("La contraseña no puede ser vacía.");

                if (UsuarioPersistance.GetByUsername(TxtUsuario.Text) != null)
                    exceptionMessage += Environment.NewLine + "Ya existe un usuario con el nombre ingresado.";

                if (!string.IsNullOrEmpty(exceptionMessage))
                    throw new Exception(exceptionMessage);
                #endregion

                #region Inserto el nuevo usuario

                var user = new Usuario();
                user.Username = TxtUsuario.Text;
                user.Password = SHA256Helper.Encode(TxtContrasena.Text);

                var dialogAnswer = MessageBox.Show("Esta seguro que quiere insertar el nuevo usuario?", "Atencion", MessageBoxButtons.YesNo);
                if (dialogAnswer == DialogResult.Yes)
                {
                    using (var transaction = DataBaseManager.Instance().Connection.BeginTransaction(IsolationLevel.Serializable))
                    {
                        if (_abmEmpresa || _abmCliente)
                            user = UsuarioPersistance.InsertUserTemporal(user, transaction);
                        else
                            user = UsuarioPersistance.InsertUser(user, transaction);

                        Rol selectedRol = (Rol)CboRoles.SelectedItem;
                        RolPersistance.InsertUserRole(user, selectedRol, transaction);

                        if (!_abmEmpresa && !_abmCliente)
                        {
                            //Cargo los datos en sesion
                            SessionManager.CurrentUser = user;
                            SessionManager.CurrentRol = selectedRol;
                            SessionManager.CurrentRol.Funcionalidades = FuncionalidadPersistance.GetByRole(SessionManager.CurrentRol, transaction);
                        }

                        switch (selectedRol.Descripcion)
                        {
                            case "Cliente":
                                this.Hide();
                                var frmABMInsertUpdateCliente = new FrmABMInsertUpdateCliente(transaction, _abmCliente, user);
                                frmABMInsertUpdateCliente.ShowDialog();
                                break;
                            case "Empresa":
                                this.Hide();
                                var frmABMInsertUpdateEmpresa = new FrmABMInsertUpdateEmpresa(transaction, _abmEmpresa, user);
                                frmABMInsertUpdateEmpresa.ShowDialog();
                                break;
                            default:
                                transaction.Commit();
                                this.Hide();
                                var frmHome = new FrmHome();
                                frmHome.ShowDialog();
                                break;
                        }
                    }
                }
                #endregion

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