/// <summary> /// Nhập dữ liệu file excel /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void ImportFile(object sender, DirectEventArgs e) { try { if (fileExcel.HasFile) { // upload file var path = UploadFile(fileExcel, Constant.PathTemplate); // get file path path = Path.Combine(Server.MapPath("~/"), Constant.PathTemplate, path); // get list import var importList = ExcelHelper.ImportExcel <ArgumentModel>(path); foreach (var item in importList) { item.Code = item.Name.ToUpperString(); ArgumentController.Create(item); } } gpCriterionArgument.Reload(); ResetForm(); wdExcel.Hide(); Dialog.ShowNotification("Lưu thành công"); } catch (Exception ex) { Dialog.ShowError(ex); } }
/// <summary> /// insert or update /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void InsertOrUpdate(object sender, DirectEventArgs e) { try { // init entity var model = new ArgumentModel(); var resultModel = new ArgumentModel(); // check id if (!string.IsNullOrEmpty(hdfId.Text) && Convert.ToInt32(hdfId.Text) > 0) { var result = ArgumentController.GetById(Convert.ToInt32(hdfId.Text));; if (result != null) { model = result; } } // set new props for entity model.CalculateCode = cboCalculateCode.SelectedItem.Value; model.ValueType = (KpiValueType)Enum.Parse(typeof(KpiValueType), hdfValueType.Text); model.Name = txtName.Text; model.Code = txtName.Text.ToUpperString(); model.Description = txtDescription.Text; model.Order = !string.IsNullOrEmpty(txtOrder.Text) ? Convert.ToInt32(txtOrder.Text) : 0; model.Status = chkIsActive.Checked ? KpiStatus.Active : KpiStatus.Locked; // check entity id if (model.Id > 0) { model.EditedDate = DateTime.Now; model.EditedBy = CurrentUser.User.UserName; // update resultModel = ArgumentController.Update(model); } else { model.CreatedBy = CurrentUser.User.UserName; model.CreatedDate = DateTime.Now; model.EditedDate = DateTime.Now; model.EditedBy = ""; // insert resultModel = ArgumentController.Create(model); } if (resultModel != null) { // show success notification Dialog.ShowNotification("Lưu thành công"); // hide window wdSetting.Hide(); //reset form ResetForm(); // reload data gpCriterionArgument.Reload(); } else { Dialog.ShowNotification("Lưu không thành công, mã tham số hoặc mã tính toán đã tồn tại"); } } catch (Exception exception) { Dialog.ShowError(exception); } }