예제 #1
0
        public void DeleteRW(string index, string path)
        {
            try
            {
                //Step 1 Code to delete the object from the database
                EmployeeRightToWork n = new EmployeeRightToWork();
                n.recordId    = index;
                n.remarks     = "";
                n.employeeId  = 0;
                n.expiryDate  = DateTime.Now;
                n.issueDate   = DateTime.Now;
                n.documentRef = "";
                n.fileUrl     = path;

                PostRequest <EmployeeRightToWork> req = new PostRequest <EmployeeRightToWork>();
                req.entity = n;
                PostResponse <EmployeeRightToWork> res = _employeeService.ChildDelete <EmployeeRightToWork>(req);
                if (!res.Success)
                {
                    //Show an error saving...
                    X.MessageBox.ButtonText.Ok = Resources.Common.Ok;
                    X.Msg.Alert(Resources.Common.Error, res.Summary).Show();
                    return;
                }
                else
                {
                    //Step 2 :  remove the object from the store
                    rightToWorkStore.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 SaveRW(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   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"]);
            }

            string obj = e.ExtraParams["values"];
            JsonSerializerSettings settings = new JsonSerializerSettings();

            settings.NullValueHandling = NullValueHandling.Ignore;

            EmployeeRightToWork b = JsonConvert.DeserializeObject <EmployeeRightToWork>(obj, settings);

            b.fileUrl    = Regex.Replace(b.fileUrl, @"[^0-9a-zA-Z.]+", "");
            b.employeeId = Convert.ToInt32(CurrentEmployee.Text);
            b.recordId   = id;
            bool hijriSupported = _systemService.SessionHelper.GetHijriSupport();

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

            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 <EmployeeRightToWork> request = new PostRequest <EmployeeRightToWork>();
                    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;
                    }
                    else
                    {
                        fileData = null;
                    }
                    PostResponse <EmployeeRightToWork> r = _employeeService.ChildAddOrUpdate <EmployeeRightToWork>(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.EPRW, recordId = Convert.ToInt32(b.recordId), fileName = rwFile.PostedFile.FileName, seqNo = 0
                            };
                            req.FileNames.Add(Regex.Replace(rwFile.PostedFile.FileName, @"[^0-9a-zA-Z.]+", ""));
                            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;
                            }
                        }
                        EmployeeRightToWork rw = GetRWById(r.recordId);

                        //Add this record to the store
                        this.rightToWorkStore.Insert(0, rw);


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

                        this.EditRWwindow.Close();
                        RowSelectionModel sm = this.rightToWorkGrid.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 <EmployeeRightToWork> request = new PostRequest <EmployeeRightToWork>();
                    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 <EmployeeRightToWork> r = _employeeService.ChildAddOrUpdate <EmployeeRightToWork>(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.EPRW, recordId = Convert.ToInt32(b.recordId), fileName = rwFile.PostedFile.FileName, seqNo = 0
                            };
                            req.FileNames.Add(Regex.Replace(rwFile.PostedFile.FileName, @"[^0-9a-zA-Z.]+", ""));
                            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;
                            }
                        }
                        EmployeeRightToWork rw     = GetRWById(b.recordId);
                        ModelProxy          record = this.rightToWorkStore.GetById(id);
                        record.Set("expireDateFormatted", rw.expireDateFormatted);
                        record.Set("issueDateFormatted", rw.issueDateFormatted);
                        record.Set("fileUrl", rw.fileUrl);
                        record.Set("documentRef", rw.documentRef);
                        record.Set("dtId", rw.dtId);
                        record.Set("dtName", rw.dtName);
                        record.Set("remarks", rw.remarks);

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