/// <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ố KPI cho nhân viên"; wdSetting.Icon = Icon.Pencil; if (!string.IsNullOrEmpty(e.ExtraParams["Id"])) { var model = EmployeeArgumentController.GetById(Convert.ToInt32(e.ExtraParams["Id"])); 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); hdfGroupInput.Text = model.GroupId.ToString(); cboGroupInput.Text = model.GroupName; } } } else { // insert wdSetting.Title = @"Thêm mới tham số KPI cho nhân viên"; wdSetting.Icon = Icon.Add; cboArgument.Disabled = false; cboEmployee.Disabled = false; cboMonth.Disabled = false; spnYear.Disabled = false; } // show window wdSetting.Show(); } catch (Exception exception) { Dialog.ShowError(exception); } }
/// <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 EmployeeArgumentModel(); // check id if (!string.IsNullOrEmpty(hdfId.Text)) { if (Convert.ToInt32(hdfId.Text) > 0) { var result = EmployeeArgumentController.GetById(Convert.ToInt32(hdfId.Text)); ; if (result != null) { model = result; } } } // set new props for entity if (!string.IsNullOrEmpty(hdfArgumentId.Text)) { model.ArgumentId = Convert.ToInt32(hdfArgumentId.Text); } if (!string.IsNullOrEmpty(hdfGroupInput.Text)) { model.GroupId = Convert.ToInt32(hdfGroupInput.Text); } if (!string.IsNullOrEmpty(hdfChooseEmployee.Text)) { model.RecordId = Convert.ToInt32(hdfChooseEmployee.Text); } model.Value = txtValue.Text; if (!string.IsNullOrEmpty(hdfMonth.Text)) { model.Month = Convert.ToInt32(hdfMonth.Text); } if (!string.IsNullOrEmpty(hdfYear.Text)) { model.Year = Convert.ToInt32(hdfYear.Text); } // check entity id if (model.Id > 0) { model.EditedDate = DateTime.Now; model.EditedBy = CurrentUser.User.UserName; // update EmployeeArgumentController.Update(model); } else { model.CreatedBy = CurrentUser.User.UserName; model.CreatedDate = DateTime.Now; model.EditedDate = DateTime.Now; model.EditedBy = ""; //check argument exist var employeeArgument = EmployeeArgumentController.GetUnique(model.GroupId, model.RecordId, model.ArgumentId, model.Month, model.Year); if (employeeArgument != null) { Dialog.ShowNotification("Giá trị tham số này đã được tạo. Vui lòng chọn tham số khác."); } else { // insert EmployeeArgumentController.Create(model); } } // hide window wdSetting.Hide(); //reset form ResetForm(); // reload data gpEmployeeArgument.Reload(); } catch (Exception exception) { Dialog.ShowError(exception); } }