Exemplo n.º 1
0
            public string convertStringFormula(string[] lstStringFormula)
            {
                string result = "";

                for (int i = 0; i < lstStringFormula.Length; i++)
                {
                    string str = lstStringFormula[i];
                    if (lstStringFormula[i].Contains("PC_"))
                    {
                        string[] parseElement = lstStringFormula[i].Split('_');
                        lstStringFormula[i] = ReplaceValue(lstStringFormula[i],
                                                           "PC_" + "\\d+",
                                                           data.spGetBenefit(ID_NhanVien, Int32.Parse(parseElement[1])).FirstOrDefault().Value.ToString("0.000"));
                    }
                    else if (lstStringFormula[i].Contains("BH_TH_"))
                    {
                        string[] parseElement = lstStringFormula[i].Split('_');
                        lstStringFormula[i] = ReplaceValue(lstStringFormula[i],
                                                           "BH_TH_" + "\\d+",
                                                           data.BAOHIEM_THUE.Find(Int32.Parse(parseElement[2].
                                                                                              Replace(")", "").
                                                                                              Replace("(", "").
                                                                                              Replace(",", ""))).PhanTramBaoHiem.ToString());
                    }
                    else if (lstStringFormula[i].Contains("NV_"))
                    {
                        string[] parseElement = lstStringFormula[i].Split('_');
                        switch (parseElement[1])
                        {
                        case "Km":
                        {
                            lstStringFormula[i] = lstStringFormula[i].Replace("NV_Km", data.NHANSUs.Find(this.ID_NhanVien).Km.HasValue ? data.NHANSUs.Find(this.ID_NhanVien).Km.Value.ToString() : "0");
                            break;
                        }

                        case "LuongCB":
                        {
                            lstStringFormula[i] = lstStringFormula[i].Replace("NV_LuongCB", data.NHANSUs.Find(this.ID_NhanVien).LuongCB.HasValue ? data.NHANSUs.Find(this.ID_NhanVien).LuongCB.Value.ToString() : "0");
                            break;
                        }

                        case "PayBack":
                        {
                            lstStringFormula[i] = lstStringFormula[i].Replace("NV_PayBack", data.NHANSUs.Find(this.ID_NhanVien).PayBack.HasValue ? data.NHANSUs.Find(this.ID_NhanVien).LuongCB.Value.ToString() : "0");
                            break;
                        }

                        case "NguoiPhuThuoc":
                        {
                            lstStringFormula[i] = lstStringFormula[i].Replace("NV_NguoiPhuThuoc", data.NHANSUs.Find(this.ID_NhanVien).SoNguoiPhuThuoc.HasValue ? data.NHANSUs.Find(this.ID_NhanVien).SoNguoiPhuThuoc.Value.ToString() : "0");
                            break;
                        }

                        default:
                        {
                            lstStringFormula[i] = "0";
                            break;
                        }
                        }
                    }
                    else if (lstStringFormula[i].Contains("OTH_"))
                    {
                        string[] parseElement = lstStringFormula[i].Split('_');
                        if (parseElement.Length < 0)
                        {
                            return(lstStringFormula[i]);
                        }
                        string[] resultFromFormulaPayrall = data.FORMULA_OF_PAYROLL.Find(Int32.Parse(parseElement[1]
                                                                                                     .Replace("(", "")
                                                                                                     .Replace(")", "")
                                                                                                     .Replace(",", "")
                                                                                                     )).Formula.Split(' ');
                        Calculate val = new Calculate();
                        lstStringFormula[i] = ReplaceValue(lstStringFormula[i],
                                                           "OTH_" + "\\d+",
                                                           val.CALCULATE(convertStringFormula(resultFromFormulaPayrall).Split(' '), ID_NhanVien, date).ToString());
                    }
                    else if (lstStringFormula[i].Contains("OT_"))
                    {
                        lstStringFormula[i] = "1";
                    }
                    else if (lstStringFormula[i].Contains("WorkingDays"))
                    {
                        lstStringFormula[i] = Weekdays(new DateTime(date.Year, date.Month, 1), new DateTime(date.Year, date.Month, 1).AddMonths(1).AddDays(-1)).ToString();
                    }
                    else if (lstStringFormula[i].Contains("AtWorks"))
                    {
                        int weekdays = Weekdays(new DateTime(date.Year, date.Month, 1), new DateTime(date.Year, date.Month, 1).AddMonths(1).AddDays(-1));
                        int OFFDays  = CalculateTotalOFFDayInWeekdays(ID_NhanVien,
                                                                      new DateTime(date.Year, date.Month, 1),
                                                                      new DateTime(date.Year, date.Month, 1).AddMonths(1).AddDays(-1));
                        string nameStaff = data.NHANSUs.Find(ID_NhanVien).HoVaTen;
                        fnDisplayWorkingDaysStaffOfMonth_Result WorkingHoursStaff = data.fnDisplayWorkingDaysStaffOfMonth(nameStaff, date).FirstOrDefault();
                        int WFHDays = WorkingHoursStaff.WFH.HasValue ? WorkingHoursStaff.WFH.Value : 0;
                        lstStringFormula[i] = (weekdays - OFFDays - WFHDays).ToString();
                    }
                    else if (lstStringFormula[i].Contains("WFHDays"))
                    {
                        string nameStaff = data.NHANSUs.Find(ID_NhanVien).HoVaTen;
                        fnDisplayWorkingDaysStaffOfMonth_Result WorkingHoursStaff = data.fnDisplayWorkingDaysStaffOfMonth(nameStaff, date).FirstOrDefault();
                        lstStringFormula[i] = WorkingHoursStaff.WFH.HasValue ? WorkingHoursStaff.WFH.Value.ToString() : "0";
                    }
                    else if (lstStringFormula[i].Contains("LeaveHours"))
                    {
                        string nameStaff = data.NHANSUs.Find(ID_NhanVien).HoVaTen;
                        fnDisplayWorkingDaysStaffOfMonth_Result WorkingHoursStaff = data.fnDisplayWorkingDaysStaffOfMonth(nameStaff, date).FirstOrDefault();
                        lstStringFormula[i] = WorkingHoursStaff.LEAVES.HasValue ? WorkingHoursStaff.LEAVES.Value.ToString() : "0";
                    }
                    else if (lstStringFormula[i].Contains("OFFDays"))
                    {
                        lstStringFormula[i] = CalculateTotalOFFDayInWeekdays(ID_NhanVien,
                                                                             new DateTime(date.Year, date.Month, 1),
                                                                             new DateTime(date.Year, date.Month, 1).AddMonths(1).AddDays(-1)).ToString();
                    }
                }
                foreach (string element in lstStringFormula)
                {
                    result += element;
                }
                return(result);
            }