Esempio n. 1
0
        protected void SaveEC(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"];
            JsonSerializerSettings settings = new JsonSerializerSettings();
            CustomResolver         res      = new CustomResolver();

            res.AddRule("ecnaId", "naId");
            res.AddRule("ecstId", "stateId");
            settings.ContractResolver = res;
            EmployeeEmergencyContact b = JsonConvert.DeserializeObject <EmployeeEmergencyContact>(obj, settings);

            b.employeeId = Convert.ToInt32(CurrentEmployee.Text);
            b.recordId   = id;
            // Define the object to add or edit as null
            b.rtName  = rtId.SelectedItem.Text;
            b.address = new AddressBook()
            {
                street1 = street1.Text, street2 = street2.Text, city = city.Text, postalCode = postalCode.Text, countryId = b.naId, countryName = ecnaId.SelectedItem.Text, stateId = b.stateId
            };
            b.employeeId       = Convert.ToInt32(CurrentEmployee.Text);
            b.address.recordId = ecaddressId.Text;
            if (string.IsNullOrEmpty(id))
            {
                try
                {
                    //New Mode
                    PostRequest <EmployeeEmergencyContact> request = new PostRequest <EmployeeEmergencyContact>();
                    request.entity = b;

                    PostResponse <EmployeeEmergencyContact> r = _employeeService.ChildAddOrUpdate <EmployeeEmergencyContact>(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
                        emergencyContactStore.Reload();

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

                        this.EditEmergencyContactWindow.Close();
                    }
                }
                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 <EmployeeEmergencyContact> request = new PostRequest <EmployeeEmergencyContact>();
                    request.entity = b;



                    PostResponse <EmployeeEmergencyContact> r = _employeeService.ChildAddOrUpdate <EmployeeEmergencyContact>(request);


                    //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
                    {
                        emergencyContactStore.Reload();
                        Notification.Show(new NotificationConfig
                        {
                            Title = Resources.Common.Notification,
                            Icon  = Icon.Information,
                            Html  = Resources.Common.RecordUpdatedSucc
                            ,
                            HideDelay = 250
                        });
                        this.EditEmergencyContactWindow.Close();
                    }
                }
                catch (Exception ex)
                {
                    X.MessageBox.ButtonText.Ok = Resources.Common.Ok;
                    X.Msg.Alert(Resources.Common.Error, Resources.Common.ErrorUpdatingRecord).Show();
                }
            }
        }
Esempio 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["values"];
            string addr = e.ExtraParams["address"];
            Branch b    = JsonConvert.DeserializeObject <Branch>(obj);

            b.managerId = managerId.Value.ToString();

            b.isInactive   = isInactive.Checked;
            b.activeStatus = isInactive.Checked ? Convert.ToInt16(ActiveStatus.INACTIVE) : Convert.ToInt16(ActiveStatus.ACTIVE);
            b.recordId     = id;
            // Define the object to add or edit as null
            CustomResolver res = new CustomResolver();

            res.AddRule("naId", "countryId");
            res.AddRule("stId", "stateId");
            JsonSerializerSettings settings = new JsonSerializerSettings();

            settings.ContractResolver = res;
            b.caName = caId.SelectedItem.Text;
            AddressBook add = JsonConvert.DeserializeObject <AddressBook>(addr, settings);

            if (string.IsNullOrEmpty(add.city) && string.IsNullOrEmpty(add.countryId) && string.IsNullOrEmpty(add.street1) && string.IsNullOrEmpty(add.stateId) && string.IsNullOrEmpty(add.phone))
            {
                b.address = null;
            }
            else
            {
                if (string.IsNullOrEmpty(add.city) || string.IsNullOrEmpty(add.countryId) || string.IsNullOrEmpty(add.street1) || string.IsNullOrEmpty(add.stateId) || string.IsNullOrEmpty(add.phone))
                {
                    X.MessageBox.ButtonText.Ok = Resources.Common.Ok;
                    X.Msg.Alert(Resources.Common.Error, GetLocalResourceObject("ErrorAddressMissing")).Show();
                    return;
                }
                b.address          = JsonConvert.DeserializeObject <AddressBook>(addr, settings);
                b.address.recordId = address.Text;
            }

            if (string.IsNullOrEmpty(branchId.Text))
            {
                try
                {
                    //New Mode
                    //Step 1 : Fill The object and insert in the store
                    PostRequest <Branch> request = new PostRequest <Branch>();
                    request.entity = b;
                    PostResponse <Branch> r = _branchService.ChildAddOrUpdate <Branch>(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, GetGlobalResourceObject("Errors", r.ErrorCode) != null ? GetGlobalResourceObject("Errors", r.ErrorCode).ToString() + "<br>" + GetGlobalResourceObject("Errors", "ErrorLogId") + r.LogId :r.Summary).Show();
                        return;
                    }
                    else
                    {
                        if (!string.IsNullOrEmpty(branchId.Text))
                        {
                            //this.Store1.Insert(0, b);


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

                        Notification.Show(new NotificationConfig
                        {
                            Title = Resources.Common.Notification,
                            Icon  = Icon.Information,
                            Html  = Resources.Common.RecordSavingSucc
                        });
                        //Add this record to the store
                        managerId.Disabled = false;

                        //Display successful notification
                        branchId.Text = b.recordId;
                        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(branchId.Text);//getting the id of the record
                    PostRequest <Branch> request = new PostRequest <Branch>();
                    b.recordId     = branchId.Text;
                    request.entity = b;
                    PostResponse <Branch> r = _branchService.ChildAddOrUpdate <Branch>(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(index);
                        record.Set("caName", b.caName);
                        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();
                }
            }
        }
Esempio 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 id = e.ExtraParams["id"];

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


            b.recordId = id;
            // Define the object to add or edit as null



            // Define the object to add or edit as null
            CustomResolver res = new CustomResolver();

            res.AddRule("naId", "countryId");
            res.AddRule("stId", "stateId");
            JsonSerializerSettings settings = new JsonSerializerSettings();

            settings.ContractResolver = res;

            AddressBook add = JsonConvert.DeserializeObject <AddressBook>(addr, settings);

            if (string.IsNullOrEmpty(add.city) && string.IsNullOrEmpty(add.countryId) && string.IsNullOrEmpty(add.street1) && string.IsNullOrEmpty(add.stateId) && string.IsNullOrEmpty(add.phone))
            {
                b.address = null;
            }
            else
            {
                if (string.IsNullOrEmpty(add.city) || string.IsNullOrEmpty(add.countryId) || string.IsNullOrEmpty(add.street1) || string.IsNullOrEmpty(add.stateId) || string.IsNullOrEmpty(add.phone))
                {
                    X.MessageBox.ButtonText.Ok = Resources.Common.Ok;
                    X.Msg.Alert(Resources.Common.Error, GetLocalResourceObject("ErrorAddressMissing")).Show();
                    return;
                }
                b.address          = JsonConvert.DeserializeObject <AddressBook>(addr, settings);
                b.address.recordId = address.Text;


                if (string.IsNullOrEmpty(id))
                {
                    try
                    {
                        //New Mode
                        //Step 1 : Fill The object and insert in the store
                        PostRequest <BusinessPartner> request = new PostRequest <BusinessPartner>();
                        request.entity = b;
                        PostResponse <BusinessPartner> r = _administrationService.ChildAddOrUpdate <BusinessPartner>(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
                        {
                            Notification.Show(new NotificationConfig
                            {
                                Title = Resources.Common.Notification,
                                Icon  = Icon.Information,
                                Html  = Resources.Common.RecordSavingSucc
                            });
                            //Add this record to the store


                            //Display successful notification

                            Store1.Reload();
                            EditRecordWindow.Close();
                        }
                    }
                    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 <BusinessPartner> request = new PostRequest <BusinessPartner>();

                        request.entity = b;
                        PostResponse <BusinessPartner> r = _administrationService.ChildAddOrUpdate <BusinessPartner>(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();
                    }
                }
            }
        }