/// <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> /// init setting window /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void InitWindow(object sender, DirectEventArgs e) { try { //reset form ResetForm(); // init window props if (e.ExtraParams["Command"] == "Update") { // edit wdSetting.Title = @"Cập nhật tham số cho mục tiêu đánh giá"; wdSetting.Icon = Icon.Pencil; var model = ArgumentController.GetById(Convert.ToInt32(hdfId.Text)); if (model != null) { // set props txtImportCode.Text = model.Code; cboCalculateCode.Text = model.CalculateCode; txtOrder.Text = model.Order.ToString(); cboValueType.Text = model.ValueTypeName; hdfValueType.Text = ((int)model.ValueType).ToString(); txtName.Text = model.Name; txtDescription.Text = model.Description; if (model.Status == KpiStatus.Active) { chkIsActive.Checked = true; } } } else { // insert wdSetting.Title = @"Thêm mới tham số cho mục tiêu đánh giá"; wdSetting.Icon = Icon.Add; } // show window wdSetting.Show(); } catch (Exception exception) { Dialog.ShowError(exception); } }
/// <summary> /// /// </summary> private void AddColumnToGridPanel() { var arguments = ArgumentController.GetAll(null, false, KpiStatus.Active, null, null, null); var count = 0; foreach (var item in arguments) { var recordField = new RecordField() { Name = item.Code, Mapping = "ArgumentDetailModels[{0}].Value".FormatWith(count++) }; var col = new Column { ColumnID = recordField.Name, Header = item.Name, DataIndex = recordField.Name, Width = 150, Renderer = { Fn = "RenderArgument" } }; switch (item.ValueType) { case KpiValueType.Percent: col.Renderer.Fn = "RenderPercent"; col.Align = Alignment.Left; break; case KpiValueType.String: col.Align = Alignment.Center; break; case KpiValueType.Number: break; case KpiValueType.Formula: break; default: throw new ArgumentOutOfRangeException(); } storeEmployeeArgument.AddField(recordField); gpEmployeeArgument.ColumnModel.Columns.Add(col); } }
/// <summary> /// Delete /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void Delete(object sender, DirectEventArgs e) { try { if (!string.IsNullOrEmpty(hdfId.Text)) { //delete ArgumentController.Delete(Convert.ToInt32(hdfId.Text)); } // reload data gpCriterionArgument.Reload(); } catch (Exception exception) { Dialog.ShowError(exception); } }
public void InitWindowArgument(string argumentCode, string recordId) { try { wdSetting.Title = @"Cập nhật tham số KPI cho nhân viên"; wdSetting.Icon = Icon.Pencil; if (!string.IsNullOrEmpty(argumentCode) && !string.IsNullOrEmpty(recordId)) { var argument = ArgumentController.GetUnique(argumentCode, null); if (argument != null) { var model = EmployeeArgumentController.GetUnique(Convert.ToInt32(hdfGroupFilter.Text), Convert.ToInt32(recordId), argument.Id, Convert.ToInt32(hdfMonth.Text), Convert.ToInt32(hdfYear.Text)); if (model != null) { // set props hdfChooseEmployee.Text = model.RecordId.ToString(); cboEmployee.Text = model.FullName; txtValue.Text = model.Value; hdfArgumentId.Text = model.ArgumentId.ToString(); cboArgument.Text = model.ArgumentName; txtValueType.Text = model.ValueTypeName; cboMonth.Text = @"Tháng " + model.Month; hdfYear.Text = model.Year.ToString(); spnYear.SetValue(model.Year); hdfId.Text = model.Id.ToString(); hdfGroupInput.Text = model.GroupId.ToString(); cboGroupInput.Text = model.GroupName; } } cboArgument.Disabled = true; cboEmployee.Disabled = true; cboMonth.Disabled = true; spnYear.Disabled = true; //show window wdSetting.Show(); } } catch (Exception exception) { Dialog.ShowError(exception); } }
/// <summary> /// get unused caculated code /// </summary> /// <returns></returns> private static List <ArgumentCalculateCodeModel> GetCalculateCodes(int num) { var codes = new List <ArgumentCalculateCodeModel>(); var argument = ArgumentController.GetAll(null, false, null, null, null, null); for (var i = 1; i < num + argument.Count; i++) { codes.Add(new ArgumentCalculateCodeModel { Code = i.ToExcelColumnName() }); } //check calculateCode exist var argumentCodes = argument.Select(a => a.CalculateCode).ToList(); codes.RemoveAll(o => argumentCodes.Contains(o.Code)); return(codes); }
/// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void OnSelectArgument(object sender, DirectEventArgs e) { try { if (!string.IsNullOrEmpty(hdfArgumentId.Text)) { var argument = ArgumentController.GetById(Convert.ToInt32(hdfArgumentId.Text)); if (argument != null) { txtValueType.Text = argument.ValueTypeName; } } else { txtValueType.Text = ""; } } catch (Exception exception) { Dialog.ShowError(exception); } }
/// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void DownloadTemplate_Click(object sender, DirectEventArgs e) { // init table var dataTable = new DataTable(); // adjust table dataTable.Rows.Add(); dataTable.Columns.Add(new DataColumn(EmployeeCode)); dataTable.Columns.Add(new DataColumn(FullName)); //add argument var argumentModels = ArgumentController.GetAll(null, false, KpiStatus.Active, null, null, null); foreach (var argument in argumentModels) { dataTable.Columns.Add(new DataColumn(argument.Name)); } // get record by department var departmentIds = DepartmentIds; if (!string.IsNullOrEmpty(hdfDepartmentId.Text)) { departmentIds = hdfDepartmentId.Text; } var records = RecordController.GetAll(null, null, departmentIds, RecordType.Default, null, null); // fill employee name and code for (var i = 0; i < records.Count; i++) { dataTable.Rows.Add(); dataTable.Rows[i][EmployeeCode] = records[i].EmployeeCode; dataTable.Rows[i][FullName] = records[i].FullName; } ExportToExcel(dataTable, "~/" + Constant.PathTemplate, ImportEmployeeArgumentExcelFile); }
/// <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); } }
/// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnUpdateImportExcel_Click(object sender, DirectEventArgs e) { var workbook = new WorkBook(); // upload file if (fileExcel.HasFile) { var path = UploadFile(fileExcel, Constant.PathTemplate); if (path != null) { // Read data from excel workbook.readXLSX(Path.Combine(Server.MapPath("~/"), Constant.PathTemplate, path)); // Check validation workbook if (CheckValidation(workbook, out _, out _, txtFromRow, txtToRow, txtSheetName) == false) { return; } // Export to datatable 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 ); var argumentModels = ArgumentController.GetAll(null, false, KpiStatus.Active, null, null, null); foreach (DataRow row in dataTable.Rows) { //get employee code var employeeCode = row[EmployeeCode].ToString(); if (string.IsNullOrEmpty(employeeCode)) { continue; } // get record by employee code var record = RecordController.GetByEmployeeCode(employeeCode); foreach (DataColumn col in dataTable.Columns) { foreach (var argument in argumentModels) { //check column name exists if (argument.Name != col.ColumnName) { continue; } //check empty string var value = Convert.ToString(row[col], CultureInfo.InvariantCulture); if (string.IsNullOrEmpty(value)) { continue; } //check if value exists var employeeArgument = EmployeeArgumentController.GetUnique(Convert.ToInt32(hdfGroup.Text), record.Id, argument.Id, Convert.ToInt32(hdfMonth.Text), Convert.ToInt32(hdfYear.Text)); if (employeeArgument != null) { //update value employeeArgument.Value = value; employeeArgument.GroupId = !string.IsNullOrEmpty(hdfGroup.Text) ? Convert.ToInt32(hdfGroup.Text) : 0; employeeArgument.EditedBy = CurrentUser.User.UserName; employeeArgument.EditedDate = DateTime.Now; EmployeeArgumentController.Update(employeeArgument); } else { var model = new EmployeeArgumentModel() { RecordId = record.Id, ArgumentId = argument.Id, GroupId = !string.IsNullOrEmpty(hdfGroup.Text) ? Convert.ToInt32(hdfGroup.Text) : 0, Month = Convert.ToInt32(hdfMonth.Text), Year = Convert.ToInt32(hdfYear.Text), Value = value }; EmployeeArgumentController.Create(model); } } } } //reset hdfGroup.Reset(); cboGroup.Reset(); hdfDepartmentId.Reset(); cboDepartment.Reset(); } } else { Dialog.Alert("Bạn chưa chọn tệp tin đính kèm. Vui lòng chọn."); return; } Dialog.Alert("Cập nhật thành công"); //Reset form excel fileExcel.Reset(); txtSheetName.Reset(); //reload grid gpEmployeeArgument.Reload(); }