void TreeViewDocumentFinanceYears_RecordAfterInsert(object sender, EventArgs e)
        {
            try
            {
                //Get References to TreeViewDocumentFinanceSeries and TreeViewDocumentFinanceYearSerieTerminal
                TreeViewDocumentFinanceSeries treeViewDocumentFinanceSeries = ((_sourceWindow as BackOfficeMainWindow).Accordion.Nodes["TopMenuDocuments"].Childs["DocumentFinanceSeries"].Content as TreeViewDocumentFinanceSeries);
                //Store Reference to BackOffice TreeViewDocumentFinanceYearSerieTerminal
                TreeViewDocumentFinanceYearSerieTerminal treeViewDocumentFinanceYearSerieTerminal =
                    ((_sourceWindow as BackOfficeMainWindow).Accordion.Nodes["TopMenuDocuments"].Childs.ContainsKey("DocumentFinanceYearSerieTerminal"))
                    ? ((_sourceWindow as BackOfficeMainWindow).Accordion.Nodes["TopMenuDocuments"].Childs["DocumentFinanceYearSerieTerminal"].Content as TreeViewDocumentFinanceYearSerieTerminal)
                    : null;
                //Refresh TreeViews after Insert Record, and Hide old Series
                Refresh();
                treeViewDocumentFinanceSeries.Refresh();
                if (treeViewDocumentFinanceYearSerieTerminal != null)
                {
                    treeViewDocumentFinanceYearSerieTerminal.Refresh();
                }
                //Apply Permissions ButtonCreateDocumentFinanceSeries
                treeViewDocumentFinanceSeries.ButtonCreateDocumentFinanceSeries.Sensitive = FrameworkUtils.HasPermissionTo("BACKOFFICE_MAN_DOCUMENTFINANCESERIES_MANAGE_SERIES");

                //Request Create Series for all Type of Finance Documents
                ResponseType responseType = Utils.ShowMessageTouch(
                    _sourceWindow,
                    DialogFlags.Modal,
                    new Size(600, 400),
                    MessageType.Question,
                    ButtonsType.YesNo,
                    Resx.window_title_series_create_series,
                    Resx.dialog_message_series_create_document_type_series
                    );

                if (responseType == ResponseType.Yes)
                {
                    //Get Current Active FinanceYear
                    FIN_DocumentFinanceYears currentDocumentFinanceYear = ProcessFinanceDocumentSeries.GetCurrentDocumentFinanceYear();
                    bool result = TreeViewDocumentFinanceSeries.UICreateDocumentFinanceYearSeriesTerminal(_sourceWindow, currentDocumentFinanceYear);
                }
            }
            catch (Exception ex)
            {
                _log.Error(ex.Message, ex);
            }
        }
        void TreeViewDocumentFinanceYears_RecordBeforeInsert(object sender, EventArgs e)
        {
            try
            {
                //Get Current Active FinanceYear
                FIN_DocumentFinanceYears currentDocumentFinanceYear = ProcessFinanceDocumentSeries.GetCurrentDocumentFinanceYear();

                //If has Active FiscalYear, Show Warning Request to Close/Open
                if (currentDocumentFinanceYear != null)
                {
                    ResponseType responseType = Utils.ShowMessageTouch(
                        GlobalApp.WindowStartup,
                        DialogFlags.Modal,
                        new Size(600, 400),
                        MessageType.Question,
                        ButtonsType.YesNo,
                        Resx.window_title_series_fiscal_year_close_current,
                        string.Format(Resx.dialog_message_series_fiscal_year_close_current, currentDocumentFinanceYear.Designation)
                        );

                    //Override Insert CRUD ShowDialog using SkipRecordInsert, this prevent create Record
                    _skipRecordInsert = (responseType == ResponseType.No);

                    if (responseType == ResponseType.Yes)
                    {
                        //Disable All Related Year Series and TerminalSeries
                        bool resultDisableFiscalYear = ProcessFinanceDocumentSeries.DisableActiveYearSeriesAndTerminalSeries(currentDocumentFinanceYear);
                        //Now we can disable currentDocumentFinanceYear
                        if (resultDisableFiscalYear)
                        {
                            //Disable Object
                            currentDocumentFinanceYear.Disabled = true;
                            currentDocumentFinanceYear.Save();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                _log.Error(ex.Message, ex);
            }
        }
        private void buttonCreateDocumentFinanceSeries_Clicked(object sender, EventArgs e)
        {
            try
            {
                //Refresh Terminal XPO Object
                XPCollection xpcDocumentFinanceYears = new XPCollection(GlobalFramework.SessionXpo, typeof(FIN_DocumentFinanceYears));
                xpcDocumentFinanceYears.Reload();

                //Store Reference to BackOffice TreeViewDocumentFinanceYearSerieTerminal
                TreeViewDocumentFinanceYearSerieTerminal treeViewDocumentFinanceYearSerieTerminal =
                    ((_sourceWindow as BackOfficeMainWindow).Accordion.Nodes["TopMenuDocuments"].Childs.ContainsKey("DocumentFinanceYearSerieTerminal"))
                    ? ((_sourceWindow as BackOfficeMainWindow).Accordion.Nodes["TopMenuDocuments"].Childs["DocumentFinanceYearSerieTerminal"].Content as TreeViewDocumentFinanceYearSerieTerminal)
                    : null;

                //Internal Shared Action to Refresh Components
                var internalMethodRefreshComponents = new System.Action(() =>
                {
                    //Refresh Current Tree Model
                    Refresh();
                    //Refresh TreeViewDocumentFinanceYearSerieTerminal (If Visible/Enabled)
                    if (treeViewDocumentFinanceYearSerieTerminal != null)
                    {
                        treeViewDocumentFinanceYearSerieTerminal.Refresh();
                    }
                });

                //Get Current Active FinanceYear
                FIN_DocumentFinanceYears currentDocumentFinanceYear = ProcessFinanceDocumentSeries.GetCurrentDocumentFinanceYear();

                //If has Active FiscalYear, Show Warning Request to Close/Open
                if (currentDocumentFinanceYear != null)
                {
                    //Call Create Series UI
                    bool result = UICreateDocumentFinanceYearSeriesTerminal(_sourceWindow, currentDocumentFinanceYear);
                    //Refresh Current Tree Model
                    if (result)
                    {
                        //Refresh Current Tree Model
                        Refresh();
                        //Refresh TreeViewDocumentFinanceYearSerieTerminal (If Visible/Enabled)
                        if (treeViewDocumentFinanceYearSerieTerminal != null)
                        {
                            treeViewDocumentFinanceYearSerieTerminal.Refresh();
                        }
                    }
                }
                else
                {
                    ResponseType responseType = Utils.ShowMessageTouch(
                        _sourceWindow,
                        DialogFlags.Modal,
                        new Size(600, 400),
                        MessageType.Error,
                        ButtonsType.Close,
                        Resx.window_title_series_create_series,
                        Resx.dialog_message_series_create_document_type_series_miss_year
                        );
                    //Disable Button, Extra protection for deleted year outside App
                    _buttonCreateDocumentFinanceSeries.Sensitive = false;
                }
            }
            catch (Exception ex)
            {
                _log.Error(ex.Message, ex);
            }
        }
        //XpoMode
        public TreeViewDocumentFinanceSeries(Window pSourceWindow, XPGuidObject pDefaultValue, CriteriaOperator pXpoCriteria, Type pDialogType, GenericTreeViewMode pGenericTreeViewMode = GenericTreeViewMode.Default, GenericTreeViewNavigatorMode pGenericTreeViewNavigatorMode = GenericTreeViewNavigatorMode.Default)
        {
            //Assign Parameters to Members
            _sourceWindow = pSourceWindow;

            //Init Vars
            Type xpoGuidObjectType = typeof(FIN_DocumentFinanceSeries);
            //Override Default Value with Parameter Default Value, this way we can have diferent Default Values for GenericTreeView
            FIN_DocumentFinanceSeries defaultValue = (pDefaultValue != null) ? pDefaultValue as FIN_DocumentFinanceSeries : null;
            //Override Default DialogType with Parameter Dialog Type, this way we can have diferent DialogTypes for GenericTreeView
            Type typeDialogClass = (pDialogType != null) ? pDialogType : typeof(DialogDocumentFinanceSeries);

            //Configure columnProperties
            List <GenericTreeViewColumnProperty> columnProperties = new List <GenericTreeViewColumnProperty>();

            columnProperties.Add(new GenericTreeViewColumnProperty("FiscalYear")
            {
                Title = Resx.global_fiscal_year, ChildName = "Designation", MinWidth = 160
            });
            columnProperties.Add(new GenericTreeViewColumnProperty("DocumentType")
            {
                Title = Resx.global_documentfinanceseries_documenttype, ChildName = "Designation", Expand = true
            });
            columnProperties.Add(new GenericTreeViewColumnProperty("Designation")
            {
                Title = Resx.global_designation, Expand = true
            });
            columnProperties.Add(new GenericTreeViewColumnProperty("UpdatedAt")
            {
                Title = Resx.global_record_date_updated, MinWidth = 150, MaxWidth = 150
            });

            //Configure Criteria/XPCollection/Model : Use Default Filter
            CriteriaOperator criteria = (ReferenceEquals(pXpoCriteria, null))
                                        // Generate Default Criteria
                ? CriteriaOperator.Parse("(Disabled = 0 OR Disabled IS NULL)")
                                        // Add to Parameter Criteria
                : CriteriaOperator.Parse(string.Format("(Disabled = 0 OR Disabled IS NULL) AND ({0})", pXpoCriteria.ToString()))
            ;
            XPCollection xpoCollection = new XPCollection(GlobalFramework.SessionXpo, xpoGuidObjectType, criteria);

            //Call Base Initializer
            base.InitObject(
                pSourceWindow,                 //Pass parameter
                defaultValue,                  //Pass parameter
                pGenericTreeViewMode,          //Pass parameter
                pGenericTreeViewNavigatorMode, //Pass parameter
                columnProperties,              //Created Here
                xpoCollection,                 //Created Here
                typeDialogClass                //Created Here
                );

            //Add Extra Button to Navigator
            _buttonCreateDocumentFinanceSeries = Navigator.GetNewButton("touchButtonCreateDocumentFinanceSeries_DialogActionArea", Resx.pos_button_create_series, @"Icons/icon_pos_nav_new.png");
            //_buttonCreateDocumentFinanceSeries.WidthRequest = 110;
            //Check if Has an Active Year Open before apply Permissions
            FIN_DocumentFinanceYears currentDocumentFinanceYear = ProcessFinanceDocumentSeries.GetCurrentDocumentFinanceYear();

            //Apply Permissions
            _buttonCreateDocumentFinanceSeries.Sensitive = (currentDocumentFinanceYear != null && FrameworkUtils.HasPermissionTo("BACKOFFICE_MAN_DOCUMENTFINANCESERIES_MANAGE_SERIES"));
            //Event
            _buttonCreateDocumentFinanceSeries.Clicked += buttonCreateDocumentFinanceSeries_Clicked;
            //Add to Extra Slot
            Navigator.ExtraSlot.PackStart(_buttonCreateDocumentFinanceSeries, false, false, 0);
        }
Exemple #5
0
        public static bool Restore(Window pSourceWindow, DataBaseRestoreFrom pRestoreFrom)
        {
            try
            {
                //FrameworkUtils.ShowWaitingCursor();

                Init();

                bool   restoreResult  = false;
                string sql            = string.Empty;
                string fileName       = string.Empty;
                string fileNamePacked = string.Empty;
                //default pathBackups from Settings, can be Overrided in ChooseFromFilePickerDialog Mode
                string pathBackups = _pathBackups;
                DataBaseBackupFileInfo fileInfo = null;
                Guid systemBackupGuid           = Guid.Empty;
                //Required to assign current FileName and FileNamePacked after restore, else name will be the TempName ex acegvpls.soj & n2sjiamk.32o
                sys_systembackup systemBackup = null;
                string           currentFileName = string.Empty, currentFileNamePacked = string.Empty, currentFilePath = string.Empty, currentFileHash = string.Empty;
                sys_userdetail   currentUserDetail = null;

                switch (pRestoreFrom)
                {
                case DataBaseRestoreFrom.SystemBackup:
                    fileInfo = GetSelectRecordFileName(pSourceWindow);
                    //Equal to Filename not FileNamePacked
                    fileNamePacked = fileInfo.FileNamePacked;
                    if (_debug)
                    {
                        _log.Debug(string.Format("RestoreBackup: FileNamePacked:[{0}], FileHashDB:[{1}], FileHashFile:[{2}] FileHashValid:[{3}]", fileInfo.FileNamePacked, fileInfo.FileHashDB, fileInfo.FileHashFile, fileInfo.FileHashValid));
                    }
                    if (fileInfo.Response != ResponseType.Cancel && !fileInfo.FileHashValid)
                    {
                        //#EQUAL#1
                        string message = string.Format(resources.CustomResources.GetCustomResources(GlobalFramework.Settings["customCultureResourceDefinition"], "dialog_message_database_restore_error_invalid_backup_file"), fileNamePacked);
                        Utils.ShowMessageTouch(pSourceWindow, DialogFlags.Modal, new Size(600, 300), MessageType.Error, ButtonsType.Ok, resources.CustomResources.GetCustomResources(GlobalFramework.Settings["customCultureResourceDefinition"], "global_error"), message);
                        return(false);
                    }
                    break;

                case DataBaseRestoreFrom.ChooseFromFilePickerDialog:
                    FileFilter          fileFilterBackups = Utils.GetFileFilterBackups();
                    PosFilePickerDialog dialog            = new PosFilePickerDialog(pSourceWindow, DialogFlags.DestroyWithParent, fileFilterBackups, FileChooserAction.Open);
                    ResponseType        response          = (ResponseType)dialog.Run();
                    if (response == ResponseType.Ok)
                    {
                        fileNamePacked = dialog.FilePicker.Filename;
                        //Override Default pathBackups
                        pathBackups = string.Format("{0}/", Path.GetDirectoryName(fileNamePacked));

                        dialog.Destroy();
                    }
                    else
                    {     /* IN009164 */
                        dialog.Destroy();
                        return(false);
                    }
                    break;

                default:
                    break;
                }

                if (GlobalFramework.DatabaseType != DatabaseType.MSSqlServer)
                {
                    fileName = Path.ChangeExtension(fileNamePacked, _fileExtension);
                }
                else
                {
                    //Require to assign filename and packed filename from fileInfo
                    fileName       = fileInfo.FileName;
                    fileNamePacked = fileInfo.FileName;
                }

                if (fileName != string.Empty)
                {
                    if (_debug)
                    {
                        _log.Debug(string.Format("Restore Filename:[{0}] to pathBackups[{1}]", fileNamePacked, pathBackups));
                    }
                    if (GlobalFramework.DatabaseType != DatabaseType.MSSqlServer)
                    {
                        // Old Method before PluginSoftwareVendor Implementation
                        //restoreResult = Utils.ZipUnPack(fileNamePacked, pathBackups, true);
                        restoreResult = GlobalFramework.PluginSoftwareVendor.RestoreBackup(SettingsApp.SecretKey, fileNamePacked, pathBackups, true);
                        if (_debug)
                        {
                            _log.Debug(string.Format("RestoreBackup: unpackResult:[{0}]", restoreResult));
                        }
                    }

                    if (restoreResult || GlobalFramework.DatabaseType == DatabaseType.MSSqlServer)
                    {
                        //Get properties from SystemBackup Object before Restore, to Assign Properties after Restore (FilePath,FileHash,User,Terminal)
                        sql = string.Format("SELECT Oid FROM sys_systembackup WHERE fileNamePacked = '{0}';", Path.GetFileName(fileNamePacked));
                        systemBackupGuid = FrameworkUtils.GetGuidFromQuery(sql);
                        if (systemBackupGuid != Guid.Empty)
                        {
                            systemBackup          = (sys_systembackup)FrameworkUtils.GetXPGuidObject(GlobalFramework.SessionXpo, typeof(sys_systembackup), systemBackupGuid);
                            currentFileName       = systemBackup.FileName;
                            currentFileNamePacked = systemBackup.FileNamePacked;
                            currentFilePath       = systemBackup.FilePath;
                            currentFileHash       = systemBackup.FileHash;
                            currentUserDetail     = systemBackup.User;
                        }

                        //Send fileNamePacked only to show its name in success dialog
                        if (Restore(pSourceWindow, fileName, fileNamePacked, systemBackup))
                        {
                            //Audit DATABASE_RESTORE
                            FrameworkUtils.Audit("DATABASE_RESTORE", string.Format(resources.CustomResources.GetCustomResources(GlobalFramework.Settings["customCultureResourceDefinition"], "audit_message_database_restore"), fileNamePacked));
                            //Required to DropIdentity before get currentDocumentFinanceYear Object, else it exists in old non restored Session
                            GlobalFramework.SessionXpo.DropIdentityMap();
                            //Get Current Active FinanceYear
                            fin_documentfinanceyears currentDocumentFinanceYear = ProcessFinanceDocumentSeries.GetCurrentDocumentFinanceYear();

                            //Disable all Active FinanceYear Series and SeriesTerminal if Exists
                            if (currentDocumentFinanceYear != null)
                            {
                                ProcessFinanceDocumentSeries.DisableActiveYearSeriesAndTerminalSeries(currentDocumentFinanceYear);
                            }

                            //Restore SystemBackup properties else it keeps temp names after Restore acegvpls.soj & n2sjiamk.32o, empty hash etc
                            if (systemBackupGuid != Guid.Empty)
                            {
                                //ReFresh UserDetail from Repository
                                currentUserDetail = (currentUserDetail != null) ? (sys_userdetail)FrameworkUtils.GetXPGuidObject(GlobalFramework.SessionXpo, typeof(sys_userdetail), currentUserDetail.Oid) : null;
                                //Get Current Restored systemBackup Object
                                systemBackup                = (sys_systembackup)FrameworkUtils.GetXPGuidObject(GlobalFramework.SessionXpo, typeof(sys_systembackup), systemBackupGuid);
                                systemBackup.FileName       = currentFileName;
                                systemBackup.FileNamePacked = currentFileNamePacked;
                                systemBackup.FilePath       = currentFilePath;
                                systemBackup.FileHash       = currentFileHash;
                                systemBackup.User           = currentUserDetail;
                                systemBackup.Save();
                            }
                            //If Cant get Record, because works on ChooseFromFilePickerDialog, we must recreate Record from file, only in the case of record with miss fileNamePacked
                            else
                            {
                                sql = "DELETE FROM sys_systembackup WHERE FilePath IS NULL AND FileHash IS NULL AND User IS NULL;";
                                GlobalFramework.SessionXpo.ExecuteNonQuery(sql);
                            }

                            //Audit
                            FrameworkUtils.Audit("APP_CLOSE");
                            //Call QuitWithoutConfirmation without Audit
                            LogicPos.QuitWithoutConfirmation(false);

                            return(true);
                        }
                        else
                        {
                            return(false);
                        }
                    }
                    else
                    {
                        //#EQUAL#1
                        string message = string.Format(resources.CustomResources.GetCustomResources(GlobalFramework.Settings["customCultureResourceDefinition"], "dialog_message_database_restore_error_invalid_backup_file"), fileNamePacked);
                        Utils.ShowMessageTouch(pSourceWindow, DialogFlags.Modal, new Size(600, 300), MessageType.Error, ButtonsType.Ok, resources.CustomResources.GetCustomResources(GlobalFramework.Settings["customCultureResourceDefinition"], "global_error"), message);
                        return(false);
                    }
                }
                else
                {
                    return(false);
                }
            }
            catch (Exception ex)
            {
                _log.Error(ex.Message, ex);
                return(false);
            }
            finally
            {
                //FrameworkUtils.HideWaitingCursor();
            }
        }