コード例 #1
0
        public void DeleteRecord(string index)
        {
            try
            {
                //Step 1 Code to delete the object from the database
                PayrollIndemnity s = new PayrollIndemnity();
                s.recordId = index;
                s.name     = "";

                PostRequest <PayrollIndemnity> req = new PostRequest <PayrollIndemnity>();
                req.entity = s;
                PostResponse <PayrollIndemnity> r = _payrollService.ChildDelete <PayrollIndemnity>(req);
                if (!r.Success)
                {
                    X.MessageBox.ButtonText.Ok = Resources.Common.Ok;
                    Common.errorMessage(r);
                    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)
        {
            //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["schedule"];
            PayrollIndemnity b           = JsonConvert.DeserializeObject <PayrollIndemnity>(obj);
            string           pers        = e.ExtraParams["periods"];
            string           indemnities = e.ExtraParams["indemnities"];

            b.recordId = id;
            // Define the object to add or edit as null
            List <PayrollIndemnityDetails>     periods         = JsonConvert.DeserializeObject <List <PayrollIndemnityDetails> >(pers);
            List <PayrollIndemnityRecognition> indemnitiesList = JsonConvert.DeserializeObject <List <PayrollIndemnityRecognition> >(indemnities);

            if (periods == null || periods.Count == 0 || indemnitiesList == null || indemnitiesList.Count == 0)
            {
                X.MessageBox.ButtonText.Ok = Resources.Common.Ok;
                X.Msg.Alert(Resources.Common.Error, GetGlobalResourceObject("Errors", "Error_Empty_IndemnityDetails_IndemnityResignation")).Show();
                return;
            }
            if (string.IsNullOrEmpty(id))
            {
                try
                {
                    //New Mode
                    //Step 1 : Fill The object and insert in the store
                    PostRequest <PayrollIndemnity> request = new PostRequest <PayrollIndemnity>();
                    request.entity = b;
                    PostResponse <PayrollIndemnity> r = _payrollService.ChildAddOrUpdate <PayrollIndemnity>(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;
                    }

                    PostResponse <PayrollIndemnityDetails[]> result = AddPeriodsList(b.recordId, periods);
                    //  AddPeriodsList1(b.recordId, periods);


                    if (!result.Success)
                    {
                        X.MessageBox.ButtonText.Ok = Resources.Common.Ok;
                        X.Msg.Alert(Resources.Common.Error, GetGlobalResourceObject("Errors", result.ErrorCode) != null ? GetGlobalResourceObject("Errors", result.ErrorCode).ToString() : GetGlobalResourceObject("Errors", result.ErrorCode) != null ? GetGlobalResourceObject("Errors", result.ErrorCode).ToString() : result.Summary).Show();
                        return;
                    }


                    PostResponse <PayrollIndemnityRecognition[]> result1 = AddindemnitiesList(b.recordId, indemnitiesList);
                    //  AddPeriodsList1(b.recordId, periods);

                    if (!result1.Success)
                    {
                        X.MessageBox.ButtonText.Ok = Resources.Common.Ok;
                        X.Msg.Alert(Resources.Common.Error, GetGlobalResourceObject("Errors", result.ErrorCode) != null ? GetGlobalResourceObject("Errors", result.ErrorCode).ToString() : GetGlobalResourceObject("Errors", result.ErrorCode) != null ? GetGlobalResourceObject("Errors", result.ErrorCode).ToString() : result.Summary).Show();
                        return;
                    }

                    else
                    {
                        //Add this record to the store
                        this.Store1.Insert(0, b);

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

                        this.EditRecordWindow.Close();
                        RowSelectionModel sm = this.GridPanel1.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 <PayrollIndemnity> modifyHeaderRequest = new PostRequest <PayrollIndemnity>();
                    modifyHeaderRequest.entity = b;

                    PostResponse <PayrollIndemnity> r = _payrollService.ChildAddOrUpdate <PayrollIndemnity>(modifyHeaderRequest);

                    //Step 1 Selecting the object or building up the object for update purpose
                    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;
                    }
                    //List<PayrollIndemnityDetails> periods = JsonConvert.DeserializeObject<List<PayrollIndemnityDetails>>(pers);
                    //List<PayrollIndemnityRecognition> indemnitiesList = JsonConvert.DeserializeObject<List<PayrollIndemnityRecognition>>(indemnities);
                    //if (periods == null || periods.Count == 0 || indemnitiesList == null || indemnitiesList.Count == 0)
                    //{
                    //    X.MessageBox.ButtonText.Ok = Resources.Common.Ok;
                    //    X.Msg.Alert(Resources.Common.Error, GetGlobalResourceObject("Errors", "Error_Empty_IndemnityDetails_IndemnityResignation")).Show();
                    //    return;

                    //}

                    //_payrollService.DeleteVacationSchedulePeriods(Convert.ToInt32(b.recordId));
                    DeleteVacationSchedulePeriods(Convert.ToInt32(b.recordId));
                    //if (!deleteDesponse.Success)//it maybe another check
                    // {
                    //     X.MessageBox.ButtonText.Ok = Resources.Common.Ok;
                    //      X.Msg.Alert(Resources.Common.Error, GetGlobalResourceObject("Errors", deleteDesponse.ErrorCode) != null ? GetGlobalResourceObject("Errors", deleteDesponse.ErrorCode).ToString() : deleteDesponse.Summary).Show();
                    //     return;
                    // }

                    PostResponse <PayrollIndemnityDetails[]> result = AddPeriodsList(b.recordId, periods);

                    //Step 2 : saving to store

                    //Step 3 :  Check if request fails
                    if (!result.Success)//it maybe another check
                    {
                        X.MessageBox.ButtonText.Ok = Resources.Common.Ok;
                        X.Msg.Alert(Resources.Common.Error, GetGlobalResourceObject("Errors", result.ErrorCode) != null ? GetGlobalResourceObject("Errors", result.ErrorCode).ToString() : result.Summary).Show();
                        return;
                    }


                    PostResponse <PayrollIndemnityRecognition[]> result1 = AddindemnitiesList(b.recordId, indemnitiesList);
                    //  AddPeriodsList1(b.recordId, periods);

                    if (!result1.Success)
                    {
                        X.MessageBox.ButtonText.Ok = Resources.Common.Ok;
                        X.Msg.Alert(Resources.Common.Error, GetGlobalResourceObject("Errors", result.ErrorCode) != null ? GetGlobalResourceObject("Errors", result.ErrorCode).ToString() : GetGlobalResourceObject("Errors", result.ErrorCode) != null ? GetGlobalResourceObject("Errors", result.ErrorCode).ToString() : result.Summary).Show();
                        return;
                    }
                    else
                    {
                        ModelProxy record = this.Store1.GetById(index);
                        BasicInfoTab.UpdateRecord(record);

                        record.Commit();
                        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();
                }
            }
            Store1.Reload();
        }