Ejemplo n.º 1
0
        private void InitUI()
        {
            Accordion = new Accordion(GetAccordionDefinition(), SettingsApp.PrivilegesBackOfficeMenuOperationFormat)
            {
                WidthRequest = _widthAccordion
            };
            //Reajustar posição dos Botões do Accordion para 1024x768
            if (GlobalApp.boScreenSize.Height <= 800)
            {
                _fixAccordion.Put(Accordion, 0, 28);
            }
            else
            {
                _fixAccordion.Put(Accordion, 0, 40);
            }
            _fixAccordion.Add(Accordion);
            Accordion.Clicked += accordion_Clicked;
            //_dashboardButton.Clicked += ((AccordionNode)_accordionChildArticlesTemp["Article"]).Clicked;
            //_dashboardButton.Content = ((Widget)_accordionChildDocumentsTemp["DocumentsListall"].Content);
            //_dashboardButton.Content = Utils.GetGenericTreeViewXPO<DashBoard>(this);
            _exitButton.Clicked += delegate { LogicPos.Quit(this); };

            //TK016248 BackOffice - Check New Version
            _NewVersion.Clicked += delegate
            {
                DateTime actualDate = DateTime.Now;
                if (actualDate <= GlobalFramework.LicenceUpdateDate)
                {
                    string fileName       = "\\LPUpdater\\LPUpdater.exe";
                    string lPathToUpdater = FrameworkUtils.OSSlash(string.Format(@"{0}\{1}", Environment.CurrentDirectory, fileName));
                    //string lPathToUpdater = "" + Utils.GetCurrentDirectory() + "\\LPUpdater\\LPUpdater.exe";

                    if (File.Exists(lPathToUpdater))
                    {
                        ResponseType responseType = Utils.ShowMessageTouch(this, DialogFlags.Modal, new System.Drawing.Size(600, 400), MessageType.Question, ButtonsType.YesNo, string.Format(resources.CustomResources.GetCustomResources(GlobalFramework.Settings["customCultureResourceDefinition"], "window_title_dialog_update_POS"), GlobalFramework.ServerVersion), resources.CustomResources.GetCustomResources(GlobalFramework.Settings["customCultureResourceDefinition"], "global_pos_update"));

                        if (responseType == ResponseType.Yes)
                        {
                            System.Diagnostics.Process.Start(lPathToUpdater);
                            //Process.Start(lPathToUpdater);
                            LogicPos.QuitWithoutConfirmation();
                        }
                    }
                }
                else
                {
                    Utils.ShowMessageTouch(this, DialogFlags.Modal, new System.Drawing.Size(600, 400), MessageType.Error, ButtonsType.Ok, string.Format(resources.CustomResources.GetCustomResources(GlobalFramework.Settings["customCultureResourceDefinition"], "global_error"), GlobalFramework.ServerVersion), resources.CustomResources.GetCustomResources(GlobalFramework.Settings["customCultureResourceDefinition"], "dialog_message_license_blocked"));
                }
            };

            //Imagem do dashboard carregada novamente. evento chamado
            _dashboardButton.Clicked += delegate
            {
                _dashboardButton.Content = Utils.GetGenericTreeViewXPO <DashBoard>(this);
                _dashboardButton_Clicked(_dashboardButton, null);
            };

            _backPOS.Clicked += ClickedSystemPos;
        }
Ejemplo n.º 2
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();
            }
        }