protected void ADDNewJI(object sender, DirectEventArgs e) { //Reset all values of the relative object EditJobInfoTab.Reset(); this.EditJobInfoWindow.Title = Resources.Common.AddNewRecord; FillDivision(); FillDepartment(); FillBranch(); FillPosition(); date.SelectedDate = DateTime.Today; RecordRequest request = new RecordRequest(); request.RecordID = CurrentEmployee.Text; RecordResponse <Employee> qv = _employeeService.Get <Employee>(request); departmentId.Select(qv.result.departmentId); branchId.Select(qv.result.branchId); divisionId.Select(qv.result.divisionId); positionId.Select(qv.result.positionId); reportToId.Select(qv.result.reportToId); if (!string.IsNullOrEmpty(TotalJIRecords.Text)) { if (TotalJIRecords.Text == "0") { if (qv.result.hireDate != null) { date.SelectedDate = (DateTime)qv.result.hireDate; } } } this.EditJobInfoWindow.Show(); }
protected void SaveJI(object sender, DirectEventArgs e) { try { //Getting the id to check if it is an Add or an edit as they are managed within the same form. string id = e.ExtraParams["id"]; string obj = e.ExtraParams["values"]; JobInfo b = JsonConvert.DeserializeObject <JobInfo>(obj); b.employeeId = Convert.ToInt32(CurrentEmployee.Text); b.recordId = id; b.date = new DateTime(b.date.Year, b.date.Month, b.date.Day, 14, 0, 0); if (branchId.SelectedItem != null) { b.branchName = branchId.SelectedItem.Text; } if (departmentId.SelectedItem != null) { b.departmentName = departmentId.SelectedItem.Text; } if (positionId.SelectedItem != null) { b.positionName = positionId.SelectedItem.Text; } if (divisionId.SelectedItem != null) { b.divisionName = divisionId.SelectedItem.Text; } // b.reportToName = new EmployeeName(); if (reportToId.SelectedItem != null) { b.reportToName = reportToId.SelectedItem.Text; } // Define the object to add or edit as null if (b.reportToId == 0) { b.reportToId = null; } if (string.IsNullOrEmpty(id)) { try { //New Mode //Step 1 : Fill The object and insert in the store PostRequest <JobInfo> request = new PostRequest <JobInfo>(); request.entity = b; PostResponse <JobInfo> r = _employeeService.ChildAddOrUpdate <JobInfo>(request); b.recordId = r.recordId; //check if the insert failed if (!r.Success)//it maybe be another condition { //Show an error saving... X.MessageBox.ButtonText.Ok = Resources.Common.Ok; Common.errorMessage(r);; return; } else { //Add this record to the store JIStore.Reload(); //Display successful notification Notification.Show(new NotificationConfig { Title = Resources.Common.Notification, Icon = Icon.Information, Html = Resources.Common.RecordSavingSucc }); this.EditJobInfoWindow.Close(); RowSelectionModel sm = this.JobInfoGrid.GetSelectionModel() as RowSelectionModel; sm.DeselectAll(); sm.Select(b.recordId.ToString()); } } catch (Exception ex) { //Error exception displaying a messsage box X.MessageBox.ButtonText.Ok = Resources.Common.Ok; X.Msg.Alert(Resources.Common.Error, Resources.Common.ErrorSavingRecord).Show(); } } else { //Update Mode try { int index = Convert.ToInt32(id);//getting the id of the record PostRequest <JobInfo> request = new PostRequest <JobInfo>(); request.entity = b; PostResponse <JobInfo> r = _employeeService.ChildAddOrUpdate <JobInfo>(request); //Step 1 Selecting the object or building up the object for update purpose //Step 2 : saving to store //Step 3 : Check if request fails if (!r.Success)//it maybe another check { X.MessageBox.ButtonText.Ok = Resources.Common.Ok; Common.errorMessage(r);; return; } else { ModelProxy record = this.JIStore.GetById(index); EditJobInfoTab.UpdateRecord(record); record.Set("departmentName", b.departmentName); record.Set("branchName", b.branchName); record.Set("positionName", b.positionName); record.Set("divisionName", b.divisionName); record.Set("reportToName", b.reportToName); record.Commit(); Notification.Show(new NotificationConfig { Title = Resources.Common.Notification, Icon = Icon.Information, Html = Resources.Common.RecordUpdatedSucc }); JIStore.Reload(); this.EditJobInfoWindow.Close(); } } catch (Exception ex) { X.MessageBox.ButtonText.Ok = Resources.Common.Ok; X.Msg.Alert(Resources.Common.Error, Resources.Common.ErrorUpdatingRecord).Show(); } } X.Call("parent.refreshQV"); X.Call("parent.SetJobInfo", b.departmentId, b.branchId, b.positionId, b.divisionId, b.reportToId); } catch (Exception exp) { X.Msg.Alert(Resources.Common.Error, exp.Message).Show(); } }