예제 #1
0
        public void DeleteRecord(string index)
        {
            try
            {
                //Step 1 Code to delete the object from the database
                CompanyRightToWork s = new CompanyRightToWork();
                s.recordId    = index;
                s.remarks     = "";
                s.documentRef = "";
                s.issueDate   = DateTime.Now;
                s.expiryDate  = DateTime.Now;
                s.dtId        = 0;
                s.dtName      = "";
                s.branchId    = 0;
                s.branchName  = "";



                PostRequest <CompanyRightToWork> req = new PostRequest <CompanyRightToWork>();
                req.entity = s;
                PostResponse <CompanyRightToWork> r = _systemService.ChildDelete <CompanyRightToWork>(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)
        {
            string ExpiryDateString    = e.ExtraParams["rwExpiryDate"];
            string IssueDateDateString = e.ExtraParams["rwIssueDate"];

            DateTime ExpiryDate = new DateTime();
            DateTime IssueDate  = new DateTime();

            if (!string.IsNullOrEmpty(ExpiryDateString))
            {
                ExpiryDate = DateTime.Parse(e.ExtraParams["rwExpiryDate"]);
            }
            if (!string.IsNullOrEmpty(IssueDateDateString))
            {
                IssueDate = DateTime.Parse(e.ExtraParams["rwIssueDate"]);
            }

            //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"];
            JsonSerializerSettings settings = new JsonSerializerSettings();

            settings.NullValueHandling = NullValueHandling.Ignore;
            CompanyRightToWork b = JsonConvert.DeserializeObject <CompanyRightToWork>(obj, settings);

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

            // Define the object to add or edit as null

            if (dtId.SelectedItem != null)
            {
                b.dtName = dtId.SelectedItem.Text;
            }

            if (branchId.SelectedItem != null)
            {
                b.branchName = branchId.SelectedItem.Text;
            }
            bool hijriSupported = _systemService.SessionHelper.GetHijriSupport();

            try
            {
                CultureInfo c      = new CultureInfo("en");
                string      format = "";
                if (hijriSupported)
                {
                    if (hijriSelected.Text == "true")
                    {
                        b.hijriCal   = true;
                        c            = new CultureInfo("ar");
                        format       = "yyyy/MM/dd";
                        b.issueDate  = DateTime.ParseExact(rwIssueDateMulti.Text, format, c);
                        b.expiryDate = DateTime.ParseExact(rwExpiryDateMulti.Text, format, c);
                    }
                    //else
                    //{
                    //    c = new CultureInfo("en");
                    //    if (_systemService.SessionHelper.CheckIfArabicSession())
                    //    {

                    //        format = "dd/MM/yyyy";
                    //    }
                    //    else
                    //    {
                    //        format = "MM/dd/yyyy";
                    //    }
                    //}
                    else
                    {
                        b.issueDate = IssueDate;


                        b.expiryDate = ExpiryDate;
                    }
                }
            }
            catch (Exception exp)
            {
                X.MessageBox.ButtonText.Ok = Resources.Common.Ok;
                X.Msg.Alert(Resources.Common.Error, GetLocalResourceObject("DateFormatError")).Show();

                return;
            }
            //b.remarks =
            if (b.issueDate != null && (b.issueDate > b.expiryDate))
            {
                X.MessageBox.ButtonText.Ok = Resources.Common.Ok;
                X.Msg.Alert(Resources.Common.Error, GetLocalResourceObject("DateRangeError")).Show();

                return;
            }

            if (string.IsNullOrEmpty(id))
            {
                try
                {
                    //New Mode
                    //Step 1 : Fill The object and insert in the store

                    PostRequest <CompanyRightToWork> request = new PostRequest <CompanyRightToWork>();
                    request.entity = b;
                    byte[] fileData = null;
                    if (rwFile.PostedFile != null && rwFile.PostedFile.ContentLength > 0)
                    {
                        //using (var binaryReader = new BinaryReader(picturePath.PostedFile.InputStream))
                        //{
                        //    fileData = binaryReader.ReadBytes(picturePath.PostedFile.ContentLength);
                        //}
                        fileData = new byte[rwFile.PostedFile.ContentLength];
                        fileData = rwFile.FileBytes;
                    }



                    PostResponse <CompanyRightToWork> r = _systemService.ChildAddOrUpdate <CompanyRightToWork>(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
                    {
                        if (fileData != null)
                        {
                            SystemAttachmentsPostRequest req = new SystemAttachmentsPostRequest();
                            req.entity = new Model.System.Attachement()
                            {
                                date = DateTime.Now, classId = ClassId.SYRW, recordId = Convert.ToInt32(b.recordId), fileName = rwFile.PostedFile.FileName, seqNo = 0
                            };
                            req.FileNames.Add(rwFile.PostedFile.FileName);
                            req.FilesData.Add(fileData);
                            PostResponse <Attachement> resp = _systemService.UploadMultipleAttachments(req);
                            if (!resp.Success)//it maybe be another condition
                            {
                                //Show an error saving...
                                X.MessageBox.ButtonText.Ok = Resources.Common.Ok;
                                Common.errorMessage(r);
                                return;
                            }
                        }
                        b.recordId = r.recordId;
                        //Add this record to the store
                        CompanyRightToWork m = GetRWById(r.recordId);
                        Store1.Insert(0, m);
                        //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
                    int index = Convert.ToInt32(id);//getting the id of the record
                    PostRequest <CompanyRightToWork> request = new PostRequest <CompanyRightToWork>();
                    b.recordId     = index.ToString();;
                    request.entity = b;

                    byte[] fileData = null;
                    if (rwFile.PostedFile != null && rwFile.PostedFile.ContentLength > 0)
                    {
                        fileData = new byte[rwFile.PostedFile.ContentLength];
                        fileData = rwFile.FileBytes;
                    }


                    PostResponse <CompanyRightToWork> r = _systemService.ChildAddOrUpdate <CompanyRightToWork>(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
                    {
                        if (fileData != null)
                        {
                            SystemAttachmentsPostRequest req = new SystemAttachmentsPostRequest();
                            req.entity = new Model.System.Attachement()
                            {
                                date = DateTime.Now, classId = ClassId.SYRW, recordId = Convert.ToInt32(b.recordId), fileName = rwFile.PostedFile.FileName, seqNo = 0
                            };
                            req.FileNames.Add(rwFile.PostedFile.FileName);
                            req.FilesData.Add(fileData);
                            PostResponse <Attachement> resp = _systemService.UploadMultipleAttachments(req);
                            if (!resp.Success)//it maybe be another condition
                            {
                                //Show an error saving...
                                X.MessageBox.ButtonText.Ok = Resources.Common.Ok;
                                Common.errorMessage(r);
                                return;
                            }
                        }
                        CompanyRightToWork m = GetRWById(id);

                        ModelProxy record = this.Store1.GetById(id);
                        BasicInfoTab.UpdateRecord(record);
                        record.Set("dtName", b.dtName);
                        record.Set("branchName", b.branchName);
                        record.Set("fileUrl", m.fileUrl);
                        record.Set("issueDateFormatted", m.issueDateFormatted);
                        record.Set("expireDateFormatted", m.expireDateFormatted);
                        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();
                }
            }
        }