예제 #1
0
 // 建構子
 public ProduceSalaryService(ProduceSalaryModel produceSlaryModel)
 {
     this._produceSlaryModel = produceSlaryModel;
 }
        // 產出薪資單(所有員工)
        public void ProduceSalary()
        {
            List<EmployeeModel> emplList = new List<EmployeeModel>();
            emplList = this.GetAllEmplDate();

            int totalEmpl = emplList.Count;
            float emplBasicSalary = 0;
            float emplBonus = 0;
            float totalSalary = 0;
            String emplID;
            List<String> salaryPayWayData = new List<String>();
            String salaryPayWay = null;
            String accountData = null;

            ProduceSalaryModel produceSalaryModel;
            ProduceSalaryService produceSalaryService;

            for (int i = 0; i < totalEmpl; i++)
            {
                emplID = emplList[i].GetEmplID();
                emplBasicSalary = emplList[i].GetBasicSalary();
                emplBonus = this.ComputeEmplBonus(emplID);
                salaryPayWayData = this.GetEmplSalaryPayWay(emplID);
                salaryPayWay = salaryPayWayData[0];
                accountData = salaryPayWayData[1];

                totalSalary = emplBasicSalary + emplBonus;

                produceSalaryModel = new ProduceSalaryModel();
                produceSalaryModel.SetStartDate(this._startDate);
                produceSalaryModel.SetEndDate(this._endDate);
                produceSalaryModel.SetSalaryT(this._salaryT);
                produceSalaryModel.SetEmplID(emplID);
                produceSalaryModel.SetPayWay(salaryPayWay);
                produceSalaryModel.SetAccountData(accountData);
                produceSalaryModel.SetTotalSalary(totalSalary);

                produceSalaryService = new ProduceSalaryService(produceSalaryModel);

                if (!produceSalaryService.AddProduceSalary())
                {
                    MessageBox.Show("發生錯誤, 系統停止運算! 先前共計算" + (i + 1) + "筆資料");
                    return;
                }
            }

            MessageBox.Show("計算完畢, 共" + totalEmpl + "筆資料!");
        }