/// <summary> /// Deleting all selected record /// </summary> /// <param name="sender"></param> /// <param name="e"></param> /// <summary> /// Direct method for removing multiple records /// </summary> /// <summary> /// Adding new record /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void ADDNewEH(object sender, DirectEventArgs e) { ADDNewRecord.Text = "1"; //Reset all values of the relative object ecDate.ReadOnly = false; EditEHForm.Reset(); this.EditEHwindow.Title = Resources.Common.AddNewRecord; this.EditEHwindow.Show(); // FillEHStatus(); /* if (EHCount.Text == "0") * ehDate.SelectedDate = DateTime.ParseExact(CurrentHireDate.Text, "yyyy/MM/dd", new CultureInfo("en")); * else * ehDate.SelectedDate = DateTime.Today; */ }
protected void SaveEH(object sender, DirectEventArgs e) { //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"]; EmploymentHistory b = JsonConvert.DeserializeObject <EmploymentHistory>(obj); b.employeeId = Convert.ToInt32(CurrentEmployee.Text); b.recordId = id; // Define the object to add or edit as null b.statusName = statusId.SelectedItem.Text; b.date = new DateTime(b.date.Year, b.date.Month, b.date.Day, 14, 0, 0); if (string.IsNullOrEmpty(id)) { try { //New Mode //Step 1 : Fill The object and insert in the store PostRequest <EmploymentHistory> request = new PostRequest <EmploymentHistory>(); request.entity = b; PostResponse <EmploymentHistory> r = _employeeService.ChildAddOrUpdate <EmploymentHistory>(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 this.employeementHistoryStore.Insert(0, b); //Display successful notification Notification.Show(new NotificationConfig { Title = Resources.Common.Notification, Icon = Icon.Information, Html = Resources.Common.RecordSavingSucc }); this.EditEHwindow.Close(); RowSelectionModel sm = this.employeementHistoryGrid.GetSelectionModel() as RowSelectionModel; sm.DeselectAll(); sm.Select(b.recordId.ToString()); EHCount.Text = (Convert.ToInt32(EHCount.Text) + 1).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 <EmploymentHistory> request = new PostRequest <EmploymentHistory>(); request.entity = b; PostResponse <EmploymentHistory> r = _employeeService.ChildAddOrUpdate <EmploymentHistory>(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.employeementHistoryStore.GetById(index); record.Set("date", b.date.ToShortDateString()); record.Set("statusName", b.statusName); EditEHForm.UpdateRecord(record); record.Commit(); Notification.Show(new NotificationConfig { Title = Resources.Common.Notification, Icon = Icon.Information, Html = Resources.Common.RecordUpdatedSucc }); this.EditEHwindow.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"); }