예제 #1
0
        public int Save(UsersML User)
        {
            try
            {
                ModelDAL ModelDAL = new ModelDAL();
                String   Response = ModelDAL.InsertModel(User, TableName, IdUserSession);

                SqlConnection Conexion = new SqlConnection
                {
                    ConnectionString = ConnectionString
                };

                using (SqlCommand cmd2 = new SqlCommand(Response.ToString(), Conexion))
                {
                    Conexion.Open();
                    int newID = (Int32)cmd2.ExecuteScalar();

                    if (Conexion.State == System.Data.ConnectionState.Open)
                    {
                        Conexion.Close();
                    }
                    return(newID);
                }
            }
            catch (Exception ex)
            {
                throw new Exception(String.Format("{0}.save : {1}", core, ex));
            }
        }
예제 #2
0
        public UsersML IsUser(UsersML user)
        {
            try
            {
                if (user != null)
                {
                    if (!string.IsNullOrEmpty(user.UserName) && !string.IsNullOrEmpty(user.Password))
                    {
                        String        Query    = String.Format("SELECT * FROM {0} WHERE _registry = 1 AND userName='******' AND password='******'", TableName, user.UserName, user.Password);
                        SqlConnection Conexion = new SqlConnection
                        {
                            ConnectionString = ConnectionString
                        };
                        Conexion.Open();
                        SqlDataAdapter cmd    = new SqlDataAdapter(Query, Conexion);
                        DataTable      dtUser = new DataTable();
                        cmd.Fill(dtUser);
                        Conexion.Close();

                        if (dtUser != null && dtUser.Rows.Count > 0)
                        {
                            return(getEntity(dtUser.Rows[0]));
                        }
                    }
                }

                return(null);
            }
            catch (Exception ex)
            {
                throw new Exception(String.Format("{0}.delete: {1}", core, ex));
            }
        }
예제 #3
0
 public void Delete(UsersML users)
 {
     try
     {
         UsersDAL.Delete(users);
     }
     catch (Exception ex)
     {
         throw new Exception(String.Format("{0}.Delete: {1}", core, ex));
     }
 }
예제 #4
0
 public UsersML IsUser(UsersML user)
 {
     try
     {
         user.Password = conexion.Encriptar(user.Password);
         //UsersDAL.IdUserSession = UsersDAL.IsUser(user).Id;
         return(UsersDAL.IsUser(user));
     }
     catch (Exception ex)
     {
         throw new Exception(String.Format("{0}.IsUser: {1}", core, ex));
     }
 }
예제 #5
0
 public UsersML GetEntityById(int Id)
 {
     try
     {
         UsersML UsersML = UsersDAL.GetEntityById(Id);
         UsersML.Password = conexion.DesEncriptar(UsersML.Password);
         return(UsersML);
     }
     catch (Exception ex)
     {
         throw new Exception(String.Format("{0}.GetIdEntity: {1}", core, ex));
     }
 }
예제 #6
0
        public void LoadUser()
        {
            try
            {
                employeeBLL = new EmployeeBLL();
                employeeML  = employeeBLL.GetEmploymentByIdUser(BussinesLayer.GlobalBLL.userML.Id);

                if (employeeML != null)
                {
                    KeyTextBox.Text      = employeeML.Id.ToString();
                    NameTextBox.Text     = employeeML.Name;
                    LastNameTextBox.Text = employeeML.LastName;
                }

                if (GlobalBLL.userML != null)
                {
                    UsersBLL usersBLL = new UsersBLL();
                    UsersML  usersML  = usersBLL.GetEntityById(GlobalBLL.userML.Id);

                    UserNameTextBox.Text = usersML.UserName;
                    PasswordTextBox.Text = usersML.Password;

                    if (!string.IsNullOrEmpty(GlobalBLL.userML.Image))
                    {
                        PathFileProfileTextBox.Text = string.Format("{0}\\{1}", System.IO.Path.GetFullPath(GlobalBLL.DirectoryFiles), GlobalBLL.userML.Image);

                        if (System.IO.File.Exists(PathFileProfileTextBox.Text))
                        {
                            ProfilePictureBox.BackgroundImage = new Bitmap(PathFileProfileTextBox.Text);
                        }
                        else
                        {
                            throw new Exception("No se encontró la imagen");
                        }
                    }
                }
                //else
                //{
                //    Alerts.cFAT100010 alr = new Alerts.cFAT100010("ERROR", "No se encontró la información del usuarios", MessageBoxIcon.Error);
                //    alr.ShowDialog();
                //}
            }
            catch (Exception ex)
            {
                MessageBox.Show(string.Format("LoadUser: {0}", ex.Message));
            }
        }
예제 #7
0
 public int Save(UsersML users)
 {
     try
     {
         users.Password = conexion.Encriptar(users.Password);
         if (users.Id == 0)
         {
             return(UsersDAL.Save(users));
         }
         else
         {
             return(UsersDAL.Update(users));
         }
     }
     catch (Exception ex)
     {
         throw new Exception(String.Format("{0}.Save: {1}", core, ex));
     }
 }
예제 #8
0
 public void Delete(UsersML User)
 {
     try
     {
         ModelDAL      ModelDAL = new ModelDAL();
         String        Response = ModelDAL.DeleteModel(User, TableName, IdUserSession);
         SqlConnection Conexion = new SqlConnection()
         {
             ConnectionString = ConnectionString
         };
         Conexion.Open();
         SqlCommand cmd2 = new SqlCommand(Response.ToString(), Conexion);
         cmd2.ExecuteNonQuery();
         Conexion.Close();
     }
     catch (Exception ex)
     {
         throw new Exception(String.Format("{0}.delete: {1}", core, ex));
     }
 }
예제 #9
0
        private UsersML getEntity(DataRow row)
        {
            try
            {
                if (row != null)
                {
                    UsersML userML = new UsersML()
                    {
                        Id       = (row[UsersML.DataBase.Id] != DBNull.Value) ? int.Parse(row[UsersML.DataBase.Id].ToString()) : 0,
                        UserName = (row[UsersML.DataBase.UserName] != DBNull.Value) ? row[UsersML.DataBase.UserName].ToString() : string.Empty,
                        Password = (row[UsersML.DataBase.Password] != DBNull.Value) ? row[UsersML.DataBase.Password].ToString() : string.Empty,
                        Rol      = (row[UsersML.DataBase.Rol] != DBNull.Value) ? int.Parse(row[UsersML.DataBase.Rol].ToString()) : 0,
                        Image    = (row[UsersML.DataBase.Image] != DBNull.Value) ? row[UsersML.DataBase.Image].ToString() : string.Empty,
                    };

                    return(userML);
                }
                return(null);
            }catch (Exception ex)
            {
                throw new Exception(string.Format("getEntity: {0}", ex.Message));
            }
        }
예제 #10
0
 public Boolean VerificationUser(String USER, String PASSWORD)
 {
     try
     {
         UsersBLL UsersBLL = new UsersBLL();
         UsersML  UsersML  = new UsersML()
         {
             UserName = USER, Password = PASSWORD
         };
         GlobalBLL.userML = UsersBLL.IsUser(UsersML);
         if (GlobalBLL.userML == null)
         {
             return(false);
         }
         else
         {
             return(true);
         }
     }
     catch (Exception ex)
     {
         throw new Exception(String.Format("{0}.VerificationUser: {1}", core, ex.Message));
     }
 }
예제 #11
0
        private void buttonGuardar_Click(object sender, EventArgs e)
        {
            try
            {
                if (FormValidate())
                {
                    CompanyBLL CompanyBLL = new CompanyBLL();
                    CompanyML  Company    = CompanyBLL.GetEntity();

                    UsersML User = new UsersML
                    {
                        UserName = textBoxUsuario.Text,
                        Password = textBoxPassword.Text,
                        Image    = System.IO.Path.GetFileName(PathFileNameTextBox.Text),
                        Rol      = int.Parse(comboBoxRol.SelectedValue.ToString())
                    };

                    if (IdUser > 0)
                    {
                        User.Id = IdUser;
                    }

                    UsersBLL   UsersBALL = new UsersBLL();
                    EmployeeML Employee  = new EmployeeML
                    {
                        RFC           = textBoxRfc.Text,
                        Curp          = textBoxCurp.Text,
                        Name          = textBoxNombre.Text,
                        LastName      = textBoxApellidos.Text,
                        Scholarship   = comboBoxEscolaridad.SelectedValue.ToString(),
                        Birthdate     = dateTimeFechaNacimiento.Value,
                        Nationality   = textBoxNacionalidad.Text,
                        Address       = textBoxCalle.Text,
                        Municipality  = textBoxMunicipio.Text,
                        Country       = textBoxPais.Text,
                        Email         = textBoxEmail.Text,
                        Telephone     = textBoxTelefono.Text,
                        CivilStatus   = comboBoxEstadoCivil.SelectedValue.ToString(),
                        PostalCode    = (String.IsNullOrEmpty(textBoxCodigoPostal.Text))?0: int.Parse(textBoxCodigoPostal.Text),
                        Colony        = textBoxColonia.Text,
                        StateCountry  = textBoxEstado.Text,
                        AdmissionDate = dateTimeFechaIngreso.Value,
                        IdDepartament = Int32.Parse(comboBoxDepartamento.SelectedValue.ToString()),
                        IdJob         = Int32.Parse(comboBoxPuesto.SelectedValue.ToString()),
                        SureType      = comboBoxTipoSeguro.SelectedValue.ToString(),
                        NumberSure    = textBoxNumSeguro.Text,
                        Salary        = Convert.ToDecimal(textBoxSueldo.Text),
                        HoursDay      = Convert.ToDateTime(textBoxNumHours.Text),
                    };

                    if (radioButtonHombre.Checked)
                    {
                        Employee.Gender = "Hombre";
                    }
                    else
                    {
                        Employee.Gender = "Mujer";
                    }

                    if (IdEmployee > 0)
                    {
                        Employee.Id = IdEmployee;
                    }
                    Employee.IdUser = UsersBALL.Save(User);
                    EmployeeBLL EmployeeBLL   = new EmployeeBLL();
                    int         IdNewEmployee = EmployeeBLL.Save(Employee);

                    DaysOfWorkEmployeeBLL DaysOfWorkEmployeeBLL = new DaysOfWorkEmployeeBLL();
                    DaysOfWorkEmployeeBLL.DeleteRegistrys(IdEmployee);
                    foreach (object item in checkedListBoxDias.CheckedItems)
                    {
                        DaysOfWorkEmployeeML DaysOfWorkEmployee = new DaysOfWorkEmployeeML()
                        {
                            IdDays     = Int32.Parse(item.GetType().GetProperty("Value").GetValue(item, null).ToString()),
                            IdEmployee = IdNewEmployee
                        };
                        DaysOfWorkEmployeeBLL.Save(DaysOfWorkEmployee);
                    }

                    TurnsOfEmployeeBLL TurnsOfEmployeeBLL = new TurnsOfEmployeeBLL();
                    TurnsOfEmployeeBLL.DeleteRegistrys(IdEmployee);
                    foreach (object item in checkedListBoxTurns.CheckedItems)
                    {
                        TurnsOfEmployeeML TurnsOfEmployee = new TurnsOfEmployeeML()
                        {
                            IdTurn       = Int32.Parse(item.GetType().GetProperty("Value").GetValue(item, null).ToString()),
                            IdEmployee   = IdNewEmployee,
                            IdUserInsert = GlobalBLL.userML.Id
                        };
                        TurnsOfEmployeeBLL.Save(TurnsOfEmployee);
                    }

                    if (!string.IsNullOrEmpty(PathFileNameTextBox.Text) && !string.IsNullOrEmpty(PathFileImage) && System.IO.Path.GetFileName(PathFileImageOld) != PathFileImage)
                    {
                        if (!System.IO.Directory.Exists(DirectoryFiles))
                        {
                            System.IO.Directory.CreateDirectory(DirectoryFiles);
                        }

                        System.IO.File.Delete(string.Format("{0}/{1}", DirectoryFiles, PathFileNameTextBox.Text));
                        System.IO.File.Copy(PathFileImage, string.Format("{0}/{1}", DirectoryFiles, System.IO.Path.GetFileName(PathFileNameTextBox.Text)));
                    }

                    ZKTecoDeviceBLL        zKTecoDevice = new ZKTecoDeviceBLL();
                    BiometricCore.UserInfo _userInfo    = new BiometricCore.UserInfo()
                    {
                        EnrollNumber = string.Format("{0}", IdNewEmployee),
                        Name         = Employee.Name,
                        Privelage    = (int)BiometricCore.Enums.Privileges.CommonUser,
                        TmpData      = "",
                        Password     = string.Format("{0}", IdNewEmployee)
                    };
                    zKTecoDevice.SetUserInfo(_userInfo, Convert.ToInt32(Company.NumberUserEmploye));

                    cFMEM100010 FrmDataGrid = this.Owner as cFMEM100010;
                    FrmDataGrid.LoadDataGridView();
                    cFAT100010 Alert = new cFAT100010("Información", "Información Guardado con exito!!", MessageBoxIcon.Information);
                    Alert.ShowDialog();
                    Alert.Dispose();
                    Clear();
                    this.Close();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(String.Format("buttonGuardar_Click: {0}", ex.Message), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }