public static IniciarSesion getInstance()
        {
            if (instance == null)
            {
                instance = new IniciarSesion();
            }

            return(instance);
        }
Exemple #2
0
 static void Main()
 {
     Application.EnableVisualStyles();
     Application.SetCompatibleTextRenderingDefault(false);
     Application.Run(IniciarSesion.getInstance());
 }
 private void salirToolStripMenuItem_Click(object sender, EventArgs e)
 {
     IniciarSesion.getInstance().Show();
     showLogin = true;
     this.Close();
 }
Exemple #4
0
        private void btnDelete_Click(object sender, EventArgs e)
        {
            DataGridViewRow row = null;

            if (dgvUsers.SelectedRows.Count == 1)
            {
                row = dgvUsers.SelectedRows[0];
            }
            else if (dgvUsers.SelectedCells.Count == 1)
            {
                int i = dgvUsers.SelectedCells[0].RowIndex;
                row = dgvUsers.Rows[i];
            }
            else
            {
                MessageBox.Show(
                    "Debes seleccionar solo 1 usuario a eliminar",
                    "Información",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Information
                    );
            }

            if (row != null)
            {
                DialogResult deleteIt = MessageBox.Show(
                    "¿Estas seguro de eliminar este usuario?",
                    "Confirmar",
                    MessageBoxButtons.YesNoCancel,
                    MessageBoxIcon.Question
                    );

                if (deleteIt != DialogResult.Yes)
                {
                    return;
                }

                int   id        = Int32.Parse(row.Cells[0].Value.ToString());
                users localUser = (from em in entities.users
                                   where em.id == id
                                   select em).First();

                if (localUser == null)
                {
                    MessageBox.Show(
                        "El Usuario seleccionado no existe",
                        "Error",
                        MessageBoxButtons.OK,
                        MessageBoxIcon.Error
                        );
                    loadUsers("");
                }
                else
                {
                    int adminTotal = entities.users.Count(el => el.permission == 1);

                    if (adminTotal == 1 && localUser.permission == 1)
                    {
                        MessageBox.Show(
                            "No puedes eliminar al único administrador",
                            "Error",
                            MessageBoxButtons.OK,
                            MessageBoxIcon.Error
                            );
                    }
                    else
                    {
                        bool delete       = true;
                        bool sameAsLogged = false;
                        if (localUser.id == Contabilidad.user.id)
                        {
                            delete       = false;
                            sameAsLogged = true;
                            DialogResult response = MessageBox.Show(
                                "Estas a punto de eliminar tu usuario. Esta acción te expulsará del sistema\n\n¿Deseas continuar?",
                                "Confirmar",
                                MessageBoxButtons.YesNoCancel,
                                MessageBoxIcon.Question
                                );

                            if (response == DialogResult.Yes)
                            {
                                delete = true;
                            }
                        }

                        if (delete)
                        {
                            entities.users.Remove(localUser);
                            entities.SaveChanges();

                            MessageBox.Show(
                                "¡Usuario eliminado con éxito!",
                                "Información",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Information
                                );

                            if (sameAsLogged)
                            {
                                IniciarSesion.getInstance().Show();
                                Contabilidad.showLogin = true;
                                Contabilidad.getInstance().Close();
                            }
                            else
                            {
                                loadUsers("");
                            }
                        }
                    }
                }
            }
        }