Example #1
0
 public virtual int Add()
 {
     try
     {
         EmployeesDAL employeeDal = new EmployeesDAL();
         Employees    employee    = new Employees()
         {
             EmployeeIDNo              = this.EmployeeIDNo,
             FirstNameAr               = this.FirstNameAr,
             MiddleNameAr              = this.MiddleNameAr,
             GrandFatherNameAr         = this.GrandFatherNameAr,
             FifthNameAr               = this.FifthNameAr,
             LastNameAr                = this.LastNameAr,
             FirstNameEn               = this.FirstNameEn,
             MiddleNameEn              = this.MiddleNameEn,
             GrandFatherNameEn         = this.GrandFatherNameEn,
             FifthNameEn               = this.FifthNameEn,
             LastNameEn                = this.LastNameEn,
             EmployeeBirthDate         = (DateTime)this.EmployeeBirthDate.Value.Date,
             EmployeeBirthPlace        = this.EmployeeBirthPlace,
             EmployeeMobileNo          = this.EmployeeMobileNo,
             EmployeePassportNo        = this.EmployeePassportNo,
             EmployeeEMail             = this.EmployeeEMail,
             EmployeeIDIssueDate       = this.EmployeeIDIssueDate != null ? (DateTime)this.EmployeeIDIssueDate.Value.Date : (DateTime?)null,
             EmployeePassportSource    = this.EmployeePassportSource,
             EmployeePassportIssueDate = this.EmployeePassportIssueDate != null ? (DateTime)this.EmployeePassportIssueDate.Value.Date : (DateTime?)null,
             EmployeePassportEndDate   = this.EmployeePassportEndDate != null ? (DateTime)this.EmployeePassportEndDate.Value.Date : (DateTime?)null,
             EmployeeIDExpiryDate      = this.EmployeeIDExpiryDate,
             EmployeeIDCopyNo          = this.EmployeeIDCopyNo,
             EmployeeIDIssuePlace      = this.EmployeeIDIssuePlace,
             DependentCount            = this.DependentCount,
             MaritalStatusID           = this.MaritalStatus.MaritalStatusID,
             GenderID      = this.Gender.GenderID,
             NationalityID = this.Nationality.CountryID,
             CreatedDate   = DateTime.Now,
             CreatedBy     = this.LoginIdentity.EmployeeCodeID,
         };
         employeeDal.Insert(employee);
         return(this.EmployeeID);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
        static void Main(string[] args)
        {
            //string connectionString =
            //    @"  Data Source=(localdb)\MSSQLLocalDB;
            //        Initial Catalog=DataEmployees_22_08_2019;
            //        Integrated Security=True;
            //        Connect Timeout=30;
            //        Encrypt=False;
            //        TrustServerCertificate=False;
            //        ApplicationIntent=ReadWrite;
            //        MultiSubnetFailover=False";

            string connectionString =
                @"  Data Source=andrey-kotelnik\sqlexpress;
                    Initial Catalog=EmployeesDataMSSQL;
                    Integrated Security=True";


            ConnectionString.Text = connectionString;
            EmployeesDAL   employeesDAL   = new EmployeesDAL();
            DepartmentsDAL departmentsDAL = new DepartmentsDAL();


            try
            {
                ReadDataFromBase(employeesDAL);
                employeesDAL.OpenConnection();
                //SqlDataAdapter dataAdapter = employeesDAL.GetDataAdapter();
                ////SqlParameter[] parameters = new SqlParameter[cmdTest.Parameters.Count];
                ////cmdTest.Parameters.CopyTo(parameters, 0);
                ////cmdTest.Parameters.Remove(parameters[0]);
                ////parameters[0].Value = 58;
                ////cmdTest.Parameters.Add(parameters[0]);

                ////cmdTest.ExecuteNonQuery();
                ////employeesDAL.CloseConnection();
                //DataTable table = new DataTable();
                //dataAdapter.Fill(table);
                //DataRow rowUpd = table.Rows[0];
                //var res = rowUpd.ItemArray.GetValue(1);
                //var f = rowUpd.ItemArray.IsReadOnly;
                //rowUpd.ItemArray[1] = "ИИИИИИИИ";
                //var arr = rowUpd.ItemArray;
                //arr[1] = "Иваныч2";
                //rowUpd.ItemArray = arr;
                //res = rowUpd.ItemArray.GetValue(1);

                //DataRow row = table.NewRow();
                //row[1] = "Andr2";
                //row[2] = "Andr2";
                //row[3] = 35;
                //table.Rows.Add(row);

                //table.AcceptChanges();
                //WriteLine($"The number of rows successfully updated: {dataAdapter.Update(table)}");


                //////employeesDAL.OpenConnection();
                var empList = Employee.GetEmployees();

                foreach (var item in empList)
                {
                    employeesDAL.Insert(item.Name, item.Surname, item.Age, item.DepID);
                }


                //WriteLine($"Номер вставленной строки: {employeesDAL.Insert("Й", "Й", 10, null)}");
                WriteLine($"Количество строк в таблице: {employeesDAL.CountRows}");
                //employeesDAL.Delete(25);
                //employeesDAL.Update(8, "8", "8", 8, 1);
                SqlDataReader reader;
                reader = employeesDAL.Select();
                WriteLine("Объект чтения данных --> " + reader.GetType().Name);

                while (reader.Read())
                {
                    for (int i = 0; i < reader.FieldCount; i++)
                    {
                        Write($"|{reader[i],15}");
                    }
                    WriteLine();
                }
            }
            catch (SqlException ex)
            {
                WriteLine(ex.Message);
            }
            finally
            {
                employeesDAL.CloseConnection();
            }

            //try
            //{
            //    departmentsDAL.OpenConnection();
            //    WriteLine($"Номер вставленной строки: {departmentsDAL.Insert("qwerty")}");
            //    WriteLine($"Количество строк в таблице: {departmentsDAL.CountRows}");
            //    departmentsDAL.Delete(3);
            //    departmentsDAL.Update(1, "FFFFFF");
            //    SqlDataReader reader;
            //    reader = departmentsDAL.Select();
            //    WriteLine("Объект чтения данных --> " + reader.GetType().Name);

            //    while (reader.Read())
            //    {
            //        for (int i = 0; i < reader.FieldCount; i++)
            //        {
            //            Write($"|{reader[i],15}");
            //        }
            //        WriteLine();
            //    }

            //}
            //catch (SqlException ex)
            //{

            //    WriteLine(ex.Message);
            //}
            //finally
            //{
            //    departmentsDAL.CloseConnection();
            //}

            //SqlDataAdapter dataAdapterEmp = employeesDAL.GetDataAdapter();
            //DataTable dataEmp = new DataTable("Employees");


            //SqlDataAdapter dataAdapterDep = departmentsDAL.GetDataAdapter();
            //DataTable dataDep = new DataTable("Departments");

            //try
            //{
            //    dataAdapterEmp.Fill(dataEmp);
            //}
            //catch (SqlException ex)
            //{

            //    WriteLine(ex.Message);
            //}
            //try
            //{
            //    dataAdapterDep.Fill(dataDep);
            //}
            //catch (SqlException ex)
            //{

            //    WriteLine(ex.Message);
            //}

            //WriteLine($"Столбцы в Emp: { dataEmp.Columns.Count}");
            //WriteLine($"Столбцы в Dep: { dataDep.Columns.Count}");
        }
Example #3
0
        public virtual int AddHiringNewEmployee(EmployeesBLL EmployeesBLL, EmployeesCodesBLL EmployeesCodesBLL, EmployeesCareersHistoryBLL EmployeesCareersHistoryBLL, EmployeesQualificationsBLL EmployeesQualificationsBLL, ContractorsBasicSalariesBLL ContractorsBasicSalariesBLL, List <EmployeesAllowancesBLL> EmployeesAllowancesBLLLst)
        {
            try
            {
                EmployeesDAL employeeDal = new EmployeesDAL();
                Employees    employee    = new Employees()
                {
                    EmployeeIDNo              = this.EmployeeIDNo,
                    FirstNameAr               = this.FirstNameAr,
                    MiddleNameAr              = this.MiddleNameAr,
                    GrandFatherNameAr         = this.GrandFatherNameAr,
                    FifthNameAr               = this.FifthNameAr,
                    LastNameAr                = this.LastNameAr,
                    FirstNameEn               = this.FirstNameEn,
                    MiddleNameEn              = this.MiddleNameEn,
                    GrandFatherNameEn         = this.GrandFatherNameEn,
                    FifthNameEn               = this.FifthNameEn,
                    LastNameEn                = this.LastNameEn,
                    EmployeeBirthDate         = (DateTime)this.EmployeeBirthDate.Value.Date,
                    EmployeeBirthPlace        = this.EmployeeBirthPlace,
                    EmployeeMobileNo          = this.EmployeeMobileNo,
                    EmployeePassportNo        = this.EmployeePassportNo,
                    EmployeeEMail             = this.EmployeeEMail,
                    EmployeeIDIssueDate       = this.EmployeeIDIssueDate != null ? (DateTime)this.EmployeeIDIssueDate.Value.Date : (DateTime?)null,
                    EmployeePassportSource    = this.EmployeePassportSource,
                    EmployeePassportIssueDate = this.EmployeePassportIssueDate != null ? (DateTime)this.EmployeePassportIssueDate.Value.Date : (DateTime?)null,
                    EmployeePassportEndDate   = this.EmployeePassportEndDate != null ? (DateTime)this.EmployeePassportEndDate.Value.Date : (DateTime?)null,
                    EmployeeIDExpiryDate      = this.EmployeeIDExpiryDate,
                    EmployeeIDCopyNo          = this.EmployeeIDCopyNo,
                    EmployeeIDIssuePlace      = this.EmployeeIDIssuePlace,
                    DependentCount            = this.DependentCount,
                    MaritalStatusID           = this.MaritalStatus.MaritalStatusID,
                    GenderID      = this.Gender.GenderID,
                    NationalityID = this.Nationality.CountryID,
                    CreatedDate   = DateTime.Now,
                    CreatedBy     = this.LoginIdentity.EmployeeCodeID,
                };
                EmployeesCodes employeesCode = new EmployeesCodes()
                {
                    EmployeeCodeNo = EmployeesCodesBLL.EmployeeCodeNo,
                    EmployeeTypeID = EmployeesCodesBLL.EmployeeType.EmployeeTypeID,
                    IsActive       = true,
                    CreatedDate    = DateTime.Now,
                    CreatedBy      = this.LoginIdentity.EmployeeCodeID
                };

                EmployeesCareersHistory employeeCareerHistory = new EmployeesCareersHistory()
                {
                    CareerHistoryTypeID  = EmployeesCareersHistoryBLL.CareerHistoryType.CareerHistoryTypeID,
                    CareerDegreeID       = EmployeesCareersHistoryBLL.CareerDegree.CareerDegreeID,
                    OrganizationJobID    = EmployeesCareersHistoryBLL.OrganizationJob.OrganizationJobID,
                    JoinDate             = EmployeesCareersHistoryBLL.JoinDate.Date,
                    TransactionStartDate = EmployeesCareersHistoryBLL.JoinDate.Date,
                    IsActive             = true,
                    CreatedBy            = this.LoginIdentity.EmployeeCodeID,
                    CreatedDate          = DateTime.Now
                };
                EmployeesQualifications employeeQualification = new EmployeesQualifications();
                employeeQualification.QualificationDegreeID   = EmployeesQualificationsBLL.QualificationDegree.QualificationDegreeID;
                employeeQualification.QualificationID         = EmployeesQualificationsBLL.Qualification.QualificationID;
                employeeQualification.GeneralSpecializationID = EmployeesQualificationsBLL.GeneralSpecialization.GeneralSpecializationID;
                employeeQualification.ExactSpecializationID   = EmployeesQualificationsBLL.ExactSpecialization.ExactSpecializationID == 0 ? (int?)null : EmployeesQualificationsBLL.ExactSpecialization.ExactSpecializationID;
                employeeQualification.UniSchName          = EmployeesQualificationsBLL.UniSchName;
                employeeQualification.Department          = EmployeesQualificationsBLL.Department;
                employeeQualification.FullGPA             = EmployeesQualificationsBLL.FullGPA;
                employeeQualification.GPA                 = EmployeesQualificationsBLL.GPA;
                employeeQualification.StudyPlace          = EmployeesQualificationsBLL.StudyPlace;
                employeeQualification.GraduationDate      = EmployeesQualificationsBLL.GraduationDate;
                employeeQualification.GraduationYear      = EmployeesQualificationsBLL.GraduationYear;
                employeeQualification.Percentage          = EmployeesQualificationsBLL.Percentage;
                employeeQualification.QualificationTypeID = EmployeesQualificationsBLL.QualificationType.QualificationTypeID == 0 ? (int?)null : EmployeesQualificationsBLL.QualificationType.QualificationTypeID;
                employeeQualification.CreatedDate         = DateTime.Now;
                employeeQualification.CreatedBy           = this.LoginIdentity.EmployeeCodeID;

                ContractorsBasicSalaries contractorBasicSalary = new ContractorsBasicSalaries();
                contractorBasicSalary.BasicSalary        = ContractorsBasicSalariesBLL.BasicSalary;
                contractorBasicSalary.TransfareAllowance = ContractorsBasicSalariesBLL.TransfareAllowance;
                contractorBasicSalary.CreatedDate        = DateTime.Now;
                contractorBasicSalary.CreatedBy          = this.LoginIdentity.EmployeeCodeID;

                List <EmployeesAllowances> employeesAllowancesList = new List <EmployeesAllowances>();
                foreach (var EmployeeAllowanceBLL in EmployeesAllowancesBLLLst)
                {
                    employeesAllowancesList.Add(new EmployeesAllowances()
                    {
                        AllowanceID        = EmployeeAllowanceBLL.Allowance.AllowanceID,
                        AllowanceStartDate = EmployeeAllowanceBLL.AllowanceStartDate,
                        IsActive           = EmployeeAllowanceBLL.IsActive,
                        CreatedBy          = this.LoginIdentity.EmployeeCodeID,
                        CreatedDate        = DateTime.Now
                    });
                }


                employee.EmployeesCodes = new List <EmployeesCodes>();
                employee.EmployeesCodes.Add(employeesCode);
                employeesCode.EmployeesCareersHistory = new List <EmployeesCareersHistory>();
                employeesCode.EmployeesCareersHistory.Add(employeeCareerHistory);
                employeesCode.EmployeesQualifications = new List <EmployeesQualifications>();
                employeesCode.EmployeesQualifications.Add(employeeQualification);
                #region check if the new employee is contractor then add financial advantages to him
                OrganizationsJobsBLL OrganizationsJobsBLL = new OrganizationsJobsBLL().GetByOrganizationJobID(employeeCareerHistory.OrganizationJobID);
                if (OrganizationsJobsBLL.Rank.RankCategory.RankCategoryID == (int)RanksCategoriesEnum.ContractualExpats || OrganizationsJobsBLL.Rank.RankCategory.RankCategoryID == (int)RanksCategoriesEnum.ContractualSaudis)
                {
                    employeesCode.ContractorsBasicSalaries = new List <ContractorsBasicSalaries>();
                    employeesCode.ContractorsBasicSalaries.Add(contractorBasicSalary);
                    employeeCareerHistory.EmployeesAllowances = employeesAllowancesList;
                }
                #endregion
                employeeDal.Insert(employee);
                return(this.EmployeeID);
            }
            catch
            {
                throw;
            }
        }