Ejemplo n.º 1
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      dateParam = e.ExtraParams["date"];
            string      obj       = e.ExtraParams["values"];
            LeaveReturn b         = JsonConvert.DeserializeObject <LeaveReturn>(obj);

            b.apStatus = "1";
            DateTime temp = new DateTime();

            if (DateTime.TryParse(dateParam, out temp))
            {
                b.date = temp;
            }


            PostRequest <LeaveReturn> request = new PostRequest <LeaveReturn>();

            request.entity = b;
            PostResponse <LeaveReturn> r = _leaveManagementService.ChildAddOrUpdate <LeaveReturn>(request);


            //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
                Store1.Reload();

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

                this.EditRecordWindow.Close();

                //if (string.IsNullOrEmpty(id))
                //{

                //    try
                //    {
                //        //New Mode
                //        //Step 1 : Fill The object and insert in the store
                //        PostRequest<CertificateLevel> request = new PostRequest<CertificateLevel>();

                //        request.entity = b;
                //        PostResponse<CertificateLevel> r = _employeeService.ChildAddOrUpdate<CertificateLevel>(request);


                //        //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
                //        {
                //            b.recordId = r.recordId;
                //            //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
                //    {
                //        //getting the id of the record
                //        PostRequest<CertificateLevel> request = new PostRequest<CertificateLevel>();
                //        request.entity = b;
                //        PostResponse<CertificateLevel> r = _employeeService.ChildAddOrUpdate<CertificateLevel>(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.Store1.GetById(id);
                //            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();
                //    }
                //}
            }
        }
Ejemplo n.º 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"];
            VacationSchedule b    = JsonConvert.DeserializeObject <VacationSchedule>(obj);
            string           pers = e.ExtraParams["periods"];

            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 <VacationSchedule> request = new PostRequest <VacationSchedule>();
                    request.entity = b;
                    PostResponse <VacationSchedule> r = _branchService.ChildAddOrUpdate <VacationSchedule>(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;
                        X.Msg.Alert(Resources.Common.Error, r.Summary).Show();
                        return;
                    }
                    List <VacationSchedulePeriod>           periods = JsonConvert.DeserializeObject <List <VacationSchedulePeriod> >(pers);
                    PostResponse <VacationSchedulePeriod[]> result  = AddPeriodsList(b.recordId, periods);


                    if (!result.Success)
                    {
                        X.MessageBox.ButtonText.Ok = Resources.Common.Ok;
                        X.Msg.Alert(Resources.Common.Error, result.Message).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 <VacationSchedule> modifyHeaderRequest = new PostRequest <VacationSchedule>();
                    modifyHeaderRequest.entity = b;
                    PostResponse <VacationSchedule> r = _branchService.ChildAddOrUpdate <VacationSchedule>(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;
                    }

                    var deleteDesponse = _branchService.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, Resources.Common.ErrorUpdatingRecord).Show();
                        return;
                    }
                    List <VacationSchedulePeriod>           periods = JsonConvert.DeserializeObject <List <VacationSchedulePeriod> >(pers);
                    PostResponse <VacationSchedulePeriod[]> 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, result.Message).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();
                }
            }
        }
Ejemplo n.º 3
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    obj = e.ExtraParams["values"];
            LeaveType b   = JsonConvert.DeserializeObject <LeaveType>(obj);

            string id = e.ExtraParams["id"];

            // Define the object to add or edit as null
            b.apName = apId.SelectedItem.Text;

            if (string.IsNullOrEmpty(id))
            {
                try
                {
                    //New Mode
                    //Step 1 : Fill The object and insert in the store
                    PostRequest <LeaveType> request = new PostRequest <LeaveType>();

                    request.entity = b;
                    PostResponse <LeaveType> r = _leaveManagementService.ChildAddOrUpdate <LeaveType>(request);


                    //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
                    {
                        b.recordId = r.recordId;
                        //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
                {
                    //getting the id of the record
                    PostRequest <LeaveType> request = new PostRequest <LeaveType>();
                    request.entity = b;
                    PostResponse <LeaveType> r = _leaveManagementService.ChildAddOrUpdate <LeaveType>(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
                    {
                        //ModelProxy record = this.Store1.GetById(id);

                        //BasicInfoTab.UpdateRecord(record);
                        //record.Commit();
                        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();
                }
            }
        }