Exemplo n.º 1
0
        protected void AddShift(object sender, DirectEventArgs e)
        {
            //Reset all values of the relative object

            EditShiftForm.Reset();
            ca.Text                    = CurrentCA.Text;
            sc.Text                    = CurrentSC.Text;
            shiftDayId.Text            = CurrentDay.Text;
            shiftEmpId.Text            = CurrentEmployee.Text;
            this.EditShiftWindow.Title = Resources.Common.AddNewRecord;

            this.EditShiftWindow.Show();
        }
Exemplo n.º 2
0
        protected void SaveShift(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["recordId"];
            string day = e.ExtraParams["dayId"];
            string emp = e.ExtraParams["EmployeeId"];


            string          obj = e.ExtraParams["values"];
            AttendanceShift b   = JsonConvert.DeserializeObject <AttendanceShift>(obj);

            b.recordId   = id;
            b.dayId      = day;
            b.employeeId = emp;
            // 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 <AttendanceShift> request = new PostRequest <AttendanceShift>();
                    request.entity = b;
                    PostResponse <AttendanceShift> r = _selfServiceService.ChildAddOrUpdate <AttendanceShift>(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.attendanceShiftStore.Insert(0, b);

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

                        this.EditShiftWindow.Close();
                        RowSelectionModel sm = this.GridPanel1.GetSelectionModel() as RowSelectionModel;
                        sm.DeselectAll();
                        sm.Select(b.recordId.ToString());


                        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 <AttendanceShift> request = new PostRequest <AttendanceShift>();
                    request.entity = b;
                    PostResponse <AttendanceShift> r = _selfServiceService.ChildAddOrUpdate <AttendanceShift>(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.attendanceShiftStore.GetById(index);

                        EditShiftForm.UpdateRecord(record);
                        record.Commit();
                        Notification.Show(new NotificationConfig
                        {
                            Title = Resources.Common.Notification,
                            Icon  = Icon.Information,
                            Html  = Resources.Common.RecordUpdatedSucc
                        });
                        this.EditShiftWindow.Close();
                    }
                }
                catch (Exception ex)
                {
                    X.MessageBox.ButtonText.Ok = Resources.Common.Ok;
                    X.Msg.Alert(Resources.Common.Error, Resources.Common.ErrorUpdatingRecord).Show();
                }

                Store1.Reload();
            }
        }