public DataTable addData(DataTable data, string loaihopdong)
        {
            foreach (DataRow row in data.Rows)
            {
                if (row != null)
                {
                    string         loaiHD = "";
                    tblEmpContract empCT  = null;
                    if (loaihopdong == "0" || loaihopdong == "1")
                    {
                        loaiHD = "TV";
                        empCT  = db.tblEmpContracts.Where(p => p.EmployeeID == row["EmployeeID"].ToString() &&
                                                          p.ContractID != null && p.ContractID.Length > 2 &&
                                                          p.ContractID.Substring(0, 2).ToUpper() == "TV"
                                                          ).OrderByDescending(p => p.BeginDate).FirstOrDefault();
                    }
                    if (loaihopdong == "2" || loaihopdong == "3")
                    {
                        loaiHD = "CT";
                        empCT  = db.tblEmpContracts.Where(p => p.EmployeeID == row["EmployeeID"].ToString() &&
                                                          p.ContractID != null && p.ContractID.Length > 2 &&
                                                          p.ContractID.Substring(0, 2).ToUpper() == "CT" &&
                                                          p.ContractTypeID == "05"
                                                          ).OrderByDescending(p => p.BeginDate).FirstOrDefault();
                    }

                    if (loaihopdong == "4" || loaihopdong == "5")
                    {
                        loaiHD = "CT";
                        empCT  = db.tblEmpContracts.Where(p => p.EmployeeID == row["EmployeeID"].ToString() &&
                                                          p.ContractID != null && p.ContractID.Length > 2 &&
                                                          p.ContractID.Substring(0, 2).ToUpper() == "CT" &&
                                                          p.ContractTypeID == "14"
                                                          ).OrderByDescending(p => p.BeginDate).FirstOrDefault();
                    }
                    if (empCT != null)
                    {
                        row["TuNgay"]  = empCT.BeginDate.ToString("dd/MM/yyyy");
                        row["DenNgay"] = empCT.EndDate.Value.ToString("dd/MM/yyyy");
                        tblEmpSalary empSal = db.tblEmpSalaries.Where(p => p.EmployeeID == row["EmployeeID"].ToString() &&
                                                                      p.DateChange >= empCT.BeginDate &&
                                                                      p.DateChange <= empCT.EndDate &&
                                                                      p.ContractCode != null && p.ContractCode != "" &&
                                                                      p.ContractCode.Length > 2 &&
                                                                      p.ContractCode.Substring(0, 2).ToUpper() == loaiHD
                                                                      ).OrderBy(p => p.DateChange).FirstOrDefault();
                        if (empSal != null)
                        {
                            row["BasicSalary"]      = empSal.BasicSalary;
                            row["RegularAllowance"] = empSal.BasicSalary_Ins;
                        }
                    }
                }
            }
            return(data);
        }
Ejemplo n.º 2
0
        public DataTable addData(DataTable data, string loaihopdong)
        {
            foreach (DataRow row in data.Rows)
            {
                string depID     = row["DepID"].ToString();
                string depParent = db.tblRef_Departments.Where(p => p.DepID == depID).First().DepParent;
                if (db.tblRef_Departments.Where(p => p.DepID == depParent).First().DepName == "Khối văn phòng / Office")
                {
                    row["TgTu"]  = "08:00 AM";
                    row["TgDen"] = "05:00 PM";
                }
                else
                {
                    row["TgTu"]  = "07:30 AM";
                    row["TgDen"] = "04:30 PM";
                }

                if (row != null)
                {
                    tblEmpContract empCT  = null;
                    string         loaiHD = "";
                    if (loaihopdong == "0" || loaihopdong == "1")
                    {
                        loaiHD = "TV";
                        empCT  = db.tblEmpContracts.Where(p => p.EmployeeID == row["EmployeeID"].ToString() &&
                                                          p.ContractID != null && p.ContractID.Length > 2 &&
                                                          p.ContractID.Substring(0, 2).ToUpper() == "TV"
                                                          ).OrderByDescending(p => p.BeginDate).FirstOrDefault();
                    }
                    if (loaihopdong == "2" || loaihopdong == "3")
                    {
                        loaiHD = "CT";
                        empCT  = db.tblEmpContracts.Where(p => p.EmployeeID == row["EmployeeID"].ToString() &&
                                                          p.ContractID != null && p.ContractID.Length > 2 &&
                                                          p.ContractID.Substring(0, 2).ToUpper() == "CT" &&
                                                          p.ContractTypeID == "05"
                                                          ).OrderByDescending(p => p.BeginDate).FirstOrDefault();
                    }

                    if (loaihopdong == "4" || loaihopdong == "5")
                    {
                        loaiHD = "CT";
                        empCT  = db.tblEmpContracts.Where(p => p.EmployeeID == row["EmployeeID"].ToString() &&
                                                          p.ContractID != null && p.ContractID.Length > 2 &&
                                                          p.ContractID.Substring(0, 2).ToUpper() == "CT" &&
                                                          p.ContractTypeID == "14"
                                                          ).OrderByDescending(p => p.BeginDate).FirstOrDefault();
                    }
                    if (empCT != null)
                    {
                        row["TuNgay"]  = empCT.BeginDate.ToString("dd/MM/yyyy");
                        row["DenNgay"] = empCT.EndDate.Value.ToString("dd/MM/yyyy");
                        tblEmpSalary empSal = db.tblEmpSalaries.Where(p => p.EmployeeID == row["EmployeeID"].ToString() &&
                                                                      p.DateChange >= empCT.BeginDate &&
                                                                      p.DateChange <= empCT.EndDate &&
                                                                      p.ContractCode != null && p.ContractCode != "" &&
                                                                      p.ContractCode.Length > 2 &&
                                                                      p.ContractCode.Substring(0, 2).ToUpper() == loaiHD
                                                                      ).OrderBy(p => p.DateChange).FirstOrDefault();
                        if (empSal != null)
                        {
                            row["BasicSalary"] = empSal.BasicSalary;
                        }
                    }
                }
            }
            return(data);
        }