Exemplo n.º 1
0
        protected void addPosition(object sender, DirectEventArgs e)
        {
            if (string.IsNullOrEmpty(referToPositionId.Text))
            {
                return;
            }
            Model.Company.Structure.Position dept = new Model.Company.Structure.Position();
            dept.name = referToPositionId.Text;

            PostRequest <Model.Company.Structure.Position> depReq = new PostRequest <Model.Company.Structure.Position>();

            depReq.entity = dept;
            PostResponse <Model.Company.Structure.Position> response = _branchService.ChildAddOrUpdate <Model.Company.Structure.Position>(depReq);

            if (response.Success)
            {
                dept.recordId = response.recordId;
                positionStore.Reload();
                referToPositionId.Select(dept.recordId);
                Store1.Insert(0, dept);
            }
            else
            {
                X.MessageBox.ButtonText.Ok = Resources.Common.Ok;
                Common.errorMessage(response);
                return;
            }
        }
Exemplo n.º 2
0
        protected void addDepartment(object sender, DirectEventArgs e)
        {
            Department dept = new Department();

            if (string.IsNullOrEmpty(parentId.Text))
            {
                return;
            }
            dept.name = parentId.Text;

            PostRequest <Department> depReq = new PostRequest <Department>();

            depReq.entity = dept;
            PostResponse <Department> response = _branchService.ChildAddOrUpdate <Department>(depReq);

            if (response.Success)
            {
                dept.recordId = response.recordId;
                departmentStore.Reload();
                parentId.Select(dept.recordId);
                Store1.Insert(0, dept);
            }
            else
            {
                X.MessageBox.ButtonText.Ok = Resources.Common.Ok;
                Common.errorMessage(response);
                return;
            }
        }
Exemplo n.º 3
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();
                }
            }
        }
Exemplo n.º 4
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"];
            MediaItem b   = JsonConvert.DeserializeObject <MediaItem>(obj);

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

            // Define the object to add or edit as null

            if (mcId.SelectedItem != null)
            {
                b.mcName = mcId.SelectedItem.Text;
            }

            if (departmentId.SelectedItem != null)
            {
                b.departmentName = departmentId.SelectedItem.Text;
            }


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

                    PostRequest <MediaItem> request = new PostRequest <MediaItem>();
                    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 <MediaItem> r = _mediaGalleryService.ChildAddOrUpdate <MediaItem>(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 (fileData != null)
                        {
                            SystemAttachmentsPostRequest req = new SystemAttachmentsPostRequest();
                            req.entity = new Model.System.Attachement()
                            {
                                date = DateTime.Now, classId = ClassId.MGME, recordId = Convert.ToInt32(b.recordId), fileName = rwFile.PostedFile.FileName, seqNo = null
                            };
                            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;
                                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;
                            }
                        }
                        b.recordId = r.recordId;
                        //Add this record to the store
                        MediaItem m = GetMEById(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 <MediaItem> request = new PostRequest <MediaItem>();
                    request.entity = b;
                    byte[] fileData = null;
                    if (rwFile.PostedFile != null && rwFile.PostedFile.ContentLength > 0)
                    {
                        fileData = new byte[rwFile.PostedFile.ContentLength];
                        fileData = rwFile.FileBytes;
                    }


                    PostResponse <MediaItem> r = _mediaGalleryService.ChildAddOrUpdate <MediaItem>(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, GetGlobalResourceObject("Errors", r.ErrorCode) != null ? GetGlobalResourceObject("Errors", r.ErrorCode).ToString() + "<br>" + GetGlobalResourceObject("Errors", "ErrorLogId") + r.LogId : r.Summary).Show();
                        return;
                    }
                    else
                    {
                        if (fileData != null)
                        {
                            SystemAttachmentsPostRequest req = new SystemAttachmentsPostRequest();
                            req.entity = new Model.System.Attachement()
                            {
                                date = DateTime.Now, classId = ClassId.MGME, 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;
                                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;
                            }
                        }
                        MediaItem m = GetMEById(id);

                        ModelProxy record = this.Store1.GetById(id);
                        BasicInfoTab.UpdateRecord(record);
                        record.Set("mcName", b.mcName);
                        record.Set("departmentName", b.departmentName);
                        recordId.Set("pictureUrl", m.pictureUrl);
                        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();
                }
            }
        }