public static SalaryAllowanceModel Create(SalaryAllowanceModel model) { var entity = new sal_SalaryAllowance(); model.FillEntity(ref entity); return(new SalaryAllowanceModel(sal_SalaryAllowanceServices.Create(entity))); }
public static SalaryAllowanceModel Update(SalaryAllowanceModel model) { var entity = sal_SalaryAllowanceServices.GetById(model.Id); if (entity == null) { return(null); } model.EditedDate = DateTime.Now; model.FillEntity(ref entity); return(new SalaryAllowanceModel(sal_SalaryAllowanceServices.Update(entity))); }
/// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnUpdateImportExcel_Click(object sender, DirectEventArgs e) { var workbook = new WorkBook(); if (fileExcel.HasFile) { var path = UploadFile(fileExcel, Constant.PathTemplate); if (path != null) { // init list changes var allowanceChanges = new List <SalaryAllowanceModel>(); // Read data from excel workbook.readXLSX(Path.Combine(Server.MapPath("~/"), Constant.PathTemplate, path)); // Export to data table var dataTable = workbook.ExportDataTable(0, //first row 0, //first col workbook.LastRow + 1, //last row workbook.LastCol + 1, //last col true, //first row as header false //convert to DateTime object if it match date pattern ); foreach (DataRow row in dataTable.Rows) { // get value from cell var allowanceCode = row[nameof(SalaryAllowanceModel.AllowanceCode)].ToString(); var allowanceName = row[nameof(SalaryAllowanceModel.AllowanceName)].ToString(); var factor = row[nameof(SalaryAllowanceModel.Factor)].ToString(); var percent = row[nameof(SalaryAllowanceModel.Percent)].ToString(); var value = row[nameof(SalaryAllowanceModel.Value)].ToString(); var salaryDecisionId = int.TryParse(hdfId.Text, out var result) && result > 0 ? result : 0; // check condition if (string.IsNullOrEmpty(allowanceCode)) { continue; } if (!decimal.TryParse(factor, out var factorResult)) { continue; } if (!decimal.TryParse(percent, out var percentResult)) { continue; } if (!decimal.TryParse(value, out var valueResult)) { continue; } // get catalog by code var catalogAllowance = CatalogAllowanceController.GetByCode(allowanceCode); if (catalogAllowance == null) { continue; } // init model var salaryAllowance = new SalaryAllowanceModel(); // get allowance by decision and code var salaryAllowances = SalaryAllowanceController.GetAll(null, salaryDecisionId, allowanceCode, null, 1); if (salaryAllowances.Any()) { salaryAllowance = salaryAllowances.First(); } else { salaryAllowance.Id = 0; salaryAllowance.AllowanceCode = allowanceCode; } // check are there any changes if (salaryAllowance.Factor != factorResult || salaryAllowance.Percent != percentResult || salaryAllowance.Value != valueResult) { // set value salaryAllowance.AllowanceName = allowanceName; salaryAllowance.Factor = factorResult; salaryAllowance.Percent = percentResult; salaryAllowance.Value = valueResult; // save data to hidden field SaveEditData(JSON.Serialize(salaryAllowance)); // add data to list changes allowanceChanges.Add(salaryAllowance); } if (salaryAllowance.Factor != 0 || salaryAllowance.Percent != 0 || salaryAllowance.Value != 0) { allowanceChanges.Add(salaryAllowance); } } // hide window wdExcel.Hide(); // bind data storeAllowanceCatalog.DataSource = CreateSalaryAllowanceTable(allowanceChanges); storeAllowanceCatalog.DataBind(); } Dialog.ShowNotification("Thêm thành công"); } else { Dialog.Alert("Bạn chưa chọn tệp tin đính kèm. Vui lòng chọn."); } }