public void DeleteJI(string index) { try { //Step 1 Code to delete the object from the database JobInfo n = new JobInfo(); n.recordId = index; n.positionId = 0; n.branchId = 0; n.departmentId = 0; n.divisionId = 0; n.employeeId = Convert.ToInt32(CurrentEmployee.Text); n.date = DateTime.Now; n.notes = " "; PostRequest <JobInfo> req = new PostRequest <JobInfo>(); req.entity = n; PostResponse <JobInfo> res = _employeeService.ChildDelete <JobInfo>(req); if (!res.Success) { //Show an error saving... X.MessageBox.ButtonText.Ok = Resources.Common.Ok; X.Msg.Alert(Resources.Common.Error, res.Summary).Show(); return; } else { //Step 2 : remove the object from the store JIStore.Reload(); //Step 3 : Showing a notification for the user Notification.Show(new NotificationConfig { Title = Resources.Common.Notification, Icon = Icon.Information, Html = Resources.Common.RecordDeletedSucc }); X.Call("parent.refreshQV"); X.Call("parent.SetJobInfo", null, null, null, null, null); } } catch (Exception ex) { //In case of error, showing a message box to the user X.MessageBox.ButtonText.Ok = Resources.Common.Ok; X.Msg.Alert(Resources.Common.Error, Resources.Common.ErrorDeletingRecord).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(); } }