void Button_Clicked(object sender, EventArgs e) { TouchButtonIcon button = (TouchButtonIcon)sender; EntryBoxValidationButton entryBoxValidationButton = (button.Parent.Parent.Parent as EntryBoxValidationButton); try { FileFilter fileFilter = Utils.GetFileFilterImages(); //Get Current FileList Index Position int currentFileListIndexPosition = -1; for (int i = 0; i < (button.Parent.Parent.Parent.Parent as VBox).Children.Length; i++) { EntryBoxValidationButton curentrEntryBox = ((button.Parent.Parent.Parent.Parent as VBox).Children.GetValue(i) as EntryBoxValidationButton); if (curentrEntryBox == entryBoxValidationButton) { currentFileListIndexPosition = i; if (_debug) { _log.Debug(string.Format("Current file List Index [{0}]: [{1}]", currentFileListIndexPosition, _fileList[currentFileListIndexPosition])); } } } PosFilePickerDialog dialog = new PosFilePickerDialog(_sourceWindow, DialogFlags.DestroyWithParent, fileFilter, FileChooserAction.Open); ResponseType response = (ResponseType)dialog.Run(); if (response == ResponseType.Ok) { if (entryBoxValidationButton.EntryValidation.Text == dialog.FilePicker.Filename) { //Do Nothing } else if (_fileList.Contains(dialog.FilePicker.Filename)) { Utils.ShowMessageTouch(null, DialogFlags.Modal, MessageType.Error, ButtonsType.Ok, resources.CustomResources.GetCustomResources(GlobalFramework.Settings["customCultureResourceDefinition"], "global_error"), resources.CustomResources.GetCustomResources(GlobalFramework.Settings["customCultureResourceDefinition"], "dialog_message_filepicker_existing_file_error")); } else { //Update fileList with Changed Value _fileList[currentFileListIndexPosition] = dialog.FilePicker.Filename; //Update and Validate Entry entryBoxValidationButton.EntryValidation.Text = dialog.FilePicker.Filename; entryBoxValidationButton.EntryValidation.Validate(); //Trigger Event OnChange(); if (_debug) { ListValue(); } } } dialog.Destroy(); } catch (Exception ex) { _log.Error(ex.Message, ex); } }
//Events protected void PopupDialog() { try { PosFilePickerDialog dialog = new PosFilePickerDialog(_sourceWindow, DialogFlags.DestroyWithParent, _fileFilter, FileChooserAction.Open); ResponseType response = (ResponseType)dialog.Run(); if (response == ResponseType.Ok) { _fileName = dialog.FilePicker.Filename; _entryValidation.Text = _fileName; _entryValidation.Validate(); //Call Custom Event, Triggered only when Dialog Response is OK, else Ignored OnClosePopup(); } dialog.Destroy(); } catch (Exception ex) { _log.Error(ex.Message, ex); } }
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(); } }