예제 #1
0
        public void DeleteRecord(string index)
        {
            try
            {
                //Step 1 Code to delete the object from the database
                AssetManagementLoan n = new AssetManagementLoan();
                n.recordId = index;



                PostRequest <AssetManagementLoan> req = new PostRequest <AssetManagementLoan>();
                req.entity = n;
                PostResponse <AssetManagementLoan> res = _assetManagementService.ChildDelete <AssetManagementLoan>(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();
            }
        }
예제 #2
0
        protected void SaveNewRecord(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"];
                AssetManagementLoan b = JsonConvert.DeserializeObject <AssetManagementLoan>(obj);
                if (!string.IsNullOrEmpty(apId.GetApprovalStatus()))
                {
                    b.status = Convert.ToInt16(apId.GetApprovalStatus());
                }
                b.assetId = assetId.GetAssetId();



                // 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 <AssetManagementLoan> request = new PostRequest <AssetManagementLoan>();
                        request.entity = b;
                        PostResponse <AssetManagementLoan> r = _assetManagementService.ChildAddOrUpdate <AssetManagementLoan>(request);
                        b.recordId = r.recordId;

                        //check if the insert failed
                        if (!r.Success)//it maybe be another condition
                        {
                            //Show an error saving...

                            Common.errorMessage(r);
                            return;
                        }
                        else
                        {
                            //Add this record to the store


                            //Display successful notification
                            Notification.Show(new NotificationConfig
                            {
                                Title = Resources.Common.Notification,
                                Icon  = Icon.Information,
                                Html  = Resources.Common.RecordSavingSucc
                            });

                            this.EditRecordWindow.Close();
                            Store1.Reload();
                        }
                    }
                    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 <AssetManagementLoan> request = new PostRequest <AssetManagementLoan>();
                        request.entity          = b;
                        request.entity.recordId = index.ToString();
                        PostResponse <AssetManagementLoan> r = _assetManagementService.ChildAddOrUpdate <AssetManagementLoan>(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;
                            X.Msg.Alert(Resources.Common.Error, Resources.Common.ErrorUpdatingRecord).Show();
                            return;
                        }
                        else
                        {
                            Store1.Reload();
                            Notification.Show(new NotificationConfig
                            {
                                Title = Resources.Common.Notification,
                                Icon  = Icon.Information,
                                Html  = Resources.Common.RecordUpdatedSucc
                            });
                            this.EditRecordWindow.Close();
                        }
                    }
                    catch (Exception ex)
                    {
                        X.MessageBox.ButtonText.Ok = Resources.Common.Ok;
                        X.Msg.Alert(Resources.Common.Error, Resources.Common.ErrorUpdatingRecord).Show();
                    }
                }
            }
            catch (Exception exp)
            {
                X.Msg.Alert(Resources.Common.Error, Resources.Common.ErrorUpdatingRecord).Show();
            }
        }