예제 #1
0
        private void btnIngresar_Click(object sender, EventArgs e)
        {
            if (cbxModo.Text != "")
            {
                if (txtUsuario.Text != "")
                {
                    if (txtContrasenia.Text != "")
                    {
                        switch (cbxModo.Text)
                        {
                        case "ADMINISTRADOR":
                            Administrador administrador = new Administrador(txtUsuario.Text, txtContrasenia.Text);
                            if (administrador.validarAdministrador())
                            {
                                MessageBox.Show("Bienvenido al sistema", "IESS", MessageBoxButtons.OK, MessageBoxIcon.Information);
                                desplazar();
                                this.Hide();
                                FrmAdministrador frmAdministrador = new FrmAdministrador();
                                frmAdministrador.asignarAdministrador(administrador);
                                frmAdministrador.Show();
                            }
                            else
                            {
                                MessageBox.Show("Usuario no existe", "IESS", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                            }
                            break;

                        case "DOCTOR":
                            Doctor doctor = new Doctor(txtUsuario.Text, txtContrasenia.Text);
                            if (doctor.validarDoctor())
                            {
                                MessageBox.Show("Bienvenido al sistema", "IESS", MessageBoxButtons.OK, MessageBoxIcon.Information);
                                desplazar();
                                this.Hide();
                                FrmDoctor frmDoctor = new FrmDoctor();
                                doctor.asignarEspecialidad(doctor.Especialidad.IdEspecialidad);
                                frmDoctor.asignarDoctor(doctor);
                                frmDoctor.Show();
                                this.Hide();
                            }
                            else
                            {
                                MessageBox.Show("Usuario no existe", "IESS", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                            }
                            break;

                        case "RECEPCIONISTA":
                            Recepcionista recepcionista = new Recepcionista(txtUsuario.Text, txtContrasenia.Text);
                            if (recepcionista.validarRecepcionista())
                            {
                                MessageBox.Show("Bienvenido al sistema", "IESS", MessageBoxButtons.OK, MessageBoxIcon.Information);
                                desplazar();
                                this.Hide();
                                FrmRecepcionista frmRecepcionista = new FrmRecepcionista();
                                frmRecepcionista.asignarRecepcionista(recepcionista);
                                frmRecepcionista.Show();
                            }
                            else
                            {
                                MessageBox.Show("Usuario no existe", "IESS", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                            }
                            break;

                        case "FARMACEÚTICO":
                            Farmaceutico farmaceutico = new Farmaceutico(txtUsuario.Text, txtContrasenia.Text);
                            if (farmaceutico.validarFarmaceutico())
                            {
                                MessageBox.Show("Bienvenido al sistema", "IESS", MessageBoxButtons.OK, MessageBoxIcon.Information);
                                desplazar();
                                this.Hide();
                                FrmFarmaceutico frmFarmaceutico = new FrmFarmaceutico();
                                frmFarmaceutico.asignarFarmaceutico(farmaceutico);
                                frmFarmaceutico.Show();
                                this.Hide();
                            }
                            else
                            {
                                MessageBox.Show("Usuario no existe", "IESS", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                            }
                            break;

                        case "PACIENTE":
                            Paciente paciente = new Paciente(txtUsuario.Text, txtContrasenia.Text);
                            if (paciente.validarPaciente())
                            {
                                MessageBox.Show("Bienvenido al sistema", "IESS", MessageBoxButtons.OK, MessageBoxIcon.Information);
                                desplazar();
                                this.Hide();
                                FrmPaciente frmPaciente = new FrmPaciente();
                                frmPaciente.asignarPaciente(paciente);
                                frmPaciente.Show();
                                this.Hide();
                            }
                            else
                            {
                                MessageBox.Show("Usuario no existe", "IESS", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                            }
                            break;
                        }
                    }
                    else
                    {
                        MessageBox.Show("Ingrese la contraseñia", "IESS", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                }
                else
                {
                    MessageBox.Show("Ingrese el usuario", "IESS", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
            else
            {
                MessageBox.Show("Seleccione un MODO", "IESS", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
예제 #2
0
        private void Button1_Click(object sender, EventArgs e)
        {
            user objUser;

            objUser = userService.GetUserByUsername(txtUsername.Text.ToLower());
            //validar tipo
            if (cmbTypeOfUser.SelectedIndex == -1)
            {
                MessageBox.Show("Select a type of user");
            }
            //Validar si existe
            else if (objUser == null)
            {
                MessageBox.Show("Username incorrect");
            }

            //Validar Contraseña
            else if (objUser.password == txtPassword.Text)
            {
                String userString = txtUsername.Text.ToString();
                username = userString;
                int    dni  = Int32.Parse(userString.Substring(1));
                String name = personService.GetPersonByDni(dni).name;
                MessageBox.Show("Welcome " + name);
                String path   = @"C:\Users\anthony\source\repos\ClinicPlus\Logs.txt";
                int    userid = objUser.id;
                idUsuario = userid;
                String type = cmbTypeOfUser.SelectedItem.ToString();
                if (!File.Exists(path))
                {
                    File.Create(path);
                    TextWriter tw = new StreamWriter(path);
                    tw.WriteLine(type + " " + username + " " + DateTime.Now);
                    tw.WriteLine();
                    tw.Close();
                }
                else if (File.Exists(path))
                {
                    using (var tw = new StreamWriter(path, true))
                    {
                        tw.WriteLine(type + " " + username + " " + DateTime.Now);
                    }
                }
                if (type.Equals("Admin"))
                {
                    IAdminService adminService = new AdminService();
                    if (adminService.GetAdminByUserId(userid) == null)
                    {
                        MessageBox.Show("Access Denied");
                    }
                    else
                    {
                        this.Hide();
                        FrmAdministrador.Show();
                    }
                }
                else if (type.Equals("Nurse"))
                {
                    INurseService nurService = new NurseService();
                    if (nurService.GetNurseByUserId(userid) == null)
                    {
                        MessageBox.Show("Access Denied");
                    }
                    else
                    {
                        this.Hide();
                        FrmNurses.Show();
                    }
                }
                else if (type.Equals("Doctor"))
                {
                    IDoctorService docService = new DoctorService();
                    if (docService.GetDoctorByUserId(userid) == null)
                    {
                        MessageBox.Show("Access Denied");
                    }
                    else
                    {
                        this.Hide();
                        FrmDoctor.Show();
                    }
                }
            }
            else
            {
                MessageBox.Show("Password or username incorrect");
            }
        }