public void DeleteRecord(string index) { try { //Step 1 Code to delete the object from the database AssetManagementPurchaseOrder n = new AssetManagementPurchaseOrder(); n.recordId = index; PostRequest <AssetManagementPurchaseOrder> req = new PostRequest <AssetManagementPurchaseOrder>(); req.entity = n; PostResponse <AssetManagementPurchaseOrder> res = _assetManagementService.ChildDelete <AssetManagementPurchaseOrder>(req); if (!res.Success) { //Show an error saving... X.MessageBox.ButtonText.Ok = Resources.Common.Ok; Common.errorMessage(res); return; } else { //Step 2 : remove the object from the store Store1.Remove(index); //Step 3 : Showing a notification for the user Notification.Show(new NotificationConfig { Title = Resources.Common.Notification, Icon = Icon.Information, Html = Resources.Common.RecordDeletedSucc }); } } 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 SaveNewRecord(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"]; AssetManagementPurchaseOrder b = JsonConvert.DeserializeObject <AssetManagementPurchaseOrder>(obj); b.supplierId = supplierId.GetSupplierId() == "0" ? null : supplierId.GetSupplierId(); b.categoryId = categoryId.GetCategoryId(); b.currencyId = CurrencyControl.getCurrency() == "0"?null : CurrencyControl.getCurrency(); b.apStatus = apStatus.GetApprovalStatus() == "0" ? null : apStatus.GetApprovalStatus(); b.recordId = id; // Define the object to add or edit as null if (string.IsNullOrEmpty(id)) { try { //New Mode //Step 1 : Fill The object and insert in the store PostRequest <AssetManagementPurchaseOrder> request = new PostRequest <AssetManagementPurchaseOrder>(); request.entity = b; PostResponse <AssetManagementPurchaseOrder> resp = _assetManagementService.ChildAddOrUpdate <AssetManagementPurchaseOrder>(request); b.recordId = resp.recordId; //check if the insert failed if (!resp.Success)//it maybe be another condition { //Show an error saving... X.MessageBox.ButtonText.Ok = Resources.Common.Ok; Common.errorMessage(resp); return; } else { Store1.Reload(); this.EditRecordWindow.Close(); Notification.Show(new NotificationConfig { Title = Resources.Common.Notification, Icon = Icon.Information, Html = Resources.Common.RecordSavingSucc }); //Add this record to the store } } 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 { PostRequest <AssetManagementPurchaseOrder> request = new PostRequest <AssetManagementPurchaseOrder>(); b.recordId = id; request.entity = b; PostResponse <AssetManagementPurchaseOrder> r = _assetManagementService.ChildAddOrUpdate <AssetManagementPurchaseOrder>(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 { Store1.Reload(); Notification.Show(new NotificationConfig { Title = Resources.Common.Notification, Icon = Icon.Information, Html = Resources.Common.RecordUpdatedSucc }); // this.EditRecordWindow.Close(); } AssetPOReception POReception = JsonConvert.DeserializeObject <AssetPOReception>(obj); POReception.recordId = id; POReception.supplierId = supplierId.GetSupplierId() == "0" ? null : supplierId.GetSupplierId(); POReception.categoryId = categoryId.GetCategoryId(); POReception.currencyId = CurrencyControl.getCurrency() == "0" ? null : CurrencyControl.getCurrency(); POReception.apStatus = apStatus.GetApprovalStatus() == "0" ? null : apStatus.GetApprovalStatus(); if (b.status == 2) { PostRequest <AssetPOReception> req = new PostRequest <AssetPOReception>(); req.entity = POReception; PostResponse <AssetPOReception> resp = _assetManagementService.ChildAddOrUpdate <AssetPOReception>(req); if (!resp.Success)//it maybe another check { Common.errorMessage(resp); return; } AssetManagementAssetListRequest request1 = new AssetManagementAssetListRequest(); request1.branchId = "0"; request1.departmentId = "0"; request1.positionId = "0"; request1.categoryId = "0"; request1.employeeId = "0"; request1.supplierId = "0"; request1.PurchaseOrderId = b.poRef; request1.Filter = ""; ListResponse <AssetManagementAsset> resp1 = _assetManagementService.ChildGetAll <AssetManagementAsset>(request1); if (!resp1.Success)//it maybe another check { Common.errorMessage(resp1); return; } FillCondition(); AssetPOReceptionStore.DataSource = resp1.Items; AssetPOReceptionStore.DataBind(); AssetPOReceptionWindow.Show(); } } catch (Exception ex) { X.MessageBox.ButtonText.Ok = Resources.Common.Ok; X.Msg.Alert(Resources.Common.Error, Resources.Common.ErrorUpdatingRecord).Show(); } } }