/// <summary> /// Insert or Update Catalog /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void InsertOrUpdate(object sender, DirectEventArgs e) { var payrollModel = new PayrollModel(); // check id if (!string.IsNullOrEmpty(hdfSalaryBoardListId.Text) && Convert.ToInt32(hdfSalaryBoardListId.Text) > 0) { var result = PayrollController.GetById(Convert.ToInt32(hdfSalaryBoardListId.Text)); if (result != null) { payrollModel = result; } } // set new props if (!string.IsNullOrEmpty(hdfConfigId.Text)) { payrollModel.ConfigId = Convert.ToInt32(hdfConfigId.Text); } if (!string.IsNullOrEmpty(hdfMonth.Text)) { payrollModel.Month = Convert.ToInt32(hdfMonth.Text); } if (!string.IsNullOrEmpty(hdfYear.Text)) { payrollModel.Year = Convert.ToInt32(hdfYear.Text); } payrollModel.Title = txtName.Text; payrollModel.Code = txtCode.Text; payrollModel.Description = txtNote.Text; if (payrollModel.Id > 0) { payrollModel.EditedDate = DateTime.Now; payrollModel.EditedBy = CurrentUser.User.UserName; // update var resultModel = PayrollController.Update(payrollModel); // check if payroll code exists if (resultModel != null) { // show success message Dialog.ShowNotification("Lưu thành công"); wdSetting.Hide(); ResetForm(); } else { Dialog.ShowNotification("Mã bảng lương đã tồn tại"); } } else { payrollModel.CreatedDate = DateTime.Now; payrollModel.CreatedBy = CurrentUser.User.UserName; payrollModel.EditedDate = DateTime.Now; payrollModel.EditedBy = CurrentUser.User.UserName; // create payroll var resultModel = PayrollController.Create(payrollModel); // check if payroll code exists if (resultModel != null) { // init list var listEvents = GetAllEvents(resultModel, true); // create salaryBoardInfo foreach (var employee in chkEmployeeRowSelection.SelectedRows) { var salaryInfo = new SalaryBoardInfoModel(new hr_SalaryBoardInfo()) { RecordId = Convert.ToInt32(employee.RecordID), SalaryBoardId = resultModel.Id, CreatedDate = DateTime.Now, EditedDate = DateTime.Now }; //Lay tu timeSheet GetDataFromTimeSheet(salaryInfo, listEvents); //Lay tu sal_SalaryDecision EditDataSalary(salaryInfo.RecordId, salaryInfo); //create SalaryBoardInfoController.Create(salaryInfo); } // show success message Dialog.ShowNotification("Lưu thành công"); wdSetting.Hide(); ResetForm(); } else { Dialog.ShowNotification("Mã bảng lương đã tồn tại"); } } grdSalaryBoardList.Reload(); }