/// <summary> /// Delete /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void Delete(object sender, DirectEventArgs e) { try { // init id var param = e.ExtraParams["Id"]; // parse id if (!int.TryParse(param, out var id) || id <= 0) { // parse error, show error Dialog.ShowError("Có lỗi xảy ra trong quá trình xử lý"); return; } // delete TimeSheetMachineController.Delete(id); // reload data gpTimeSheetMachine.Reload(); } catch (Exception exception) { Dialog.ShowError(exception); } }
/// <summary> /// init setting window /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void InitWindow(object sender, DirectEventArgs e) { try { // init id var param = e.ExtraParams["Id"]; // parse id if (int.TryParse(param, out var id)) { // init window props if (id > 0) { // edit wdSetting.Title = @"Sửa"; wdSetting.Icon = Icon.Pencil; } else { // insert wdSetting.Title = @"Thêm mới"; wdSetting.Icon = Icon.Add; } // init id hdfId.Text = id.ToString(); // init object var model = new TimeSheetMachineModel(null); // check id if (id > 0) { var result = TimeSheetMachineController.GetById(id); if (result != null) { model = result; } } // set props txtName.Text = model.Name; txtIpAddress.Text = model.IPAddress; txtLocation.Text = model.Location; txtSerialNumber.Text = model.SerialNumber; hdfDepartmentId.Text = model.DepartmentId.ToString(); cbxDepartment.Text = model.DepartmentName; // show window wdSetting.Show(); } } catch (Exception exception) { Dialog.ShowError(exception); } }
/// <summary> /// /// </summary> /// <param name="workbook"></param> /// <param name="col"></param> /// <param name="fromRow"></param> /// <param name="toRow"></param> private void CreateDropDownSerialNumberExcel(WorkBook workbook, DataColumn col, int fromRow, int toRow) { var list = TimeSheetMachineController.GetAll(null, null, null, null, null, null, null); if (list == null) { return; } var validation = workbook.CreateDataValidation(); validation.Type = DataValidation.eUser; var validateList = "\"{0}\"".FormatWith(string.Join(",", list.Select(l => l.SerialNumber + " ({0})".FormatWith(l.Id)).ToList())); // formula string length cannot be greater than 256 if (validateList.Length < 256) { // set formula by string validation.Formula1 = validateList; } else { var columnName = GetExcelColumnName(col.Ordinal + 1); // select info sheet workbook.Sheet = 1; // write list into info sheet foreach (var item in list.Select((value, index) => new { value, index })) { workbook.setText(item.index + 1, col.Ordinal, item.value.Name + " ({0})".FormatWith(item.value.Id)); } // select workbook.Sheet = 0; // set formula by selected range validation.Formula1 = "Info!${0}$2:${0}${1}".FormatWith(columnName, list.Count); } // selection range workbook.setSelection(fromRow, col.Ordinal, toRow, col.Ordinal); workbook.DataValidation = validation; }
/// <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 TimeSheetMachineModel(null); // check id if (!string.IsNullOrEmpty(hdfId.Text) && Convert.ToInt32(hdfId.Text) > 0) { var result = TimeSheetMachineController.GetById(Convert.ToInt32(hdfId.Text));; if (result != null) { model = result; } } // set new props for entity model.Name = txtName.Text; model.SerialNumber = txtSerialNumber.Text; model.IPAddress = txtIpAddress.Text; model.Location = txtLocation.Text; if (!string.IsNullOrEmpty(hdfDepartmentId.Text)) { model.DepartmentId = Convert.ToInt32(hdfDepartmentId.Text); } // check entity id if (model.Id > 0) { var timeSheetMachineModal = TimeSheetMachineController.GetBySerialNumber(model.SerialNumber); // check existed if (timeSheetMachineModal == null || timeSheetMachineModal.Id == model.Id) { model.UpdatedAt = DateTime.Now; model.UpdatedBy = CurrentUser.User.UserName; // update TimeSheetMachineController.Update(model); } else { Dialog.Alert("Số serial máy đã tồn tại, vui lòng nhập serial khác"); } } else { var timeSheetMachineModal = TimeSheetMachineController.GetBySerialNumber(model.SerialNumber); // check existed if (timeSheetMachineModal == null) { model.CreatedBy = CurrentUser.User.UserName; model.CreatedAt = DateTime.Now; model.UpdatedAt = DateTime.Now; model.UpdatedBy = ""; // insert TimeSheetMachineController.Create(model); } else { Dialog.Alert("Số serial máy đã tồn tại, vui lòng nhập serial khác"); } } // hide window wdSetting.Hide(); // reload data gpTimeSheetMachine.Reload(); } catch (Exception exception) { Dialog.ShowError(exception); } }