public ReturnCode SettingRename(int IdFolder, string IdSettingOld, string IdSettingNew) { if (FolderNotFound(IdFolder)) { return(FolderNotFound()); } ReturnCode code = ReturnCodeFactory.Success($"Setting has been renamed: {IdSettingNew}"); if (IdSettingNew.Trim().Length < 1) { return(ReturnCodeFactory.Error((int)Errors.SettingNameNotSpecified, "New setting name not specified")); } int count = 0; using (SQLiteConnection connection = GetSqliteConnection()) using (SQLiteCommand command = new SQLiteCommand(connection)) { count = command.ZzOpenConnection().ZzAdd("@IdFolder", IdFolder).ZzAdd("@IdSetting", IdSettingNew).ZzGetScalarInteger(DbManager.SqlSettingCount); if (count > 0) { return(ReturnCodeFactory.Error((int)Errors.SettingAlreadyExists, "A setting with the same name already exists")); } command.Parameters.Clear(); count = command.ZzAdd("@IdFolder", IdFolder).ZzAdd("@IdSettingOld", IdSettingOld).ZzAdd("@IdSettingNew", IdSettingNew).ZzExecuteNonQuery(DbManager.SqlSettingRename); if (count != 1) { return(ReturnCodeFactory.Error((int)Errors.Unknown, "Error trying to rename a setting")); } } return(code); }
public ReturnCode DeleteAllSettingsOfOneFolder(int IdFolder) { if (FolderNotFound(IdFolder)) { return(FolderNotFound()); } ReturnCode code = ReturnCodeFactory.Success($"Settings has been deleted"); int count = 0; using (SQLiteConnection connection = GetSqliteConnection()) using (SQLiteCommand command = new SQLiteCommand(connection)) { count = command.ZzOpenConnection().ZzAdd("@IdFolder", IdFolder).ZzExecuteNonQuery(DbManager.SqlDeleteAllSettingsOfOneFolder); if (count == 0) { code = ReturnCodeFactory.Success($"No any settings were deleted"); } count = command.ZzGetScalarInteger(DbManager.SqlAllSettingsCount); if (count != 0) { return(ReturnCodeFactory.Error((int)Errors.Unknown, "Error trying to delete all settings of the folder")); } } return(code); }
public ReturnCode FolderInsert(int IdParent, string NameFolder) { if (FolderNotFound(IdParent)) { return(FolderNotFound()); } ReturnCode code = ReturnCodeFactory.Success($"New folder has been created: {NameFolder}"); int IdNewFolder = -1; using (SQLiteConnection connection = GetSqliteConnection()) using (SQLiteCommand command = new SQLiteCommand(connection)) { command.ZzOpenConnection().ZzText(DbManager.SqlFolderCountByIdParent).ZzAdd("@IdParent", IdParent).ZzAdd("@NameFolder", NameFolder); int count = command.ZzGetScalarInteger(); if (count != 0) { return(ReturnCodeFactory.Error((int)Errors.FolderAlreadyExists, "A folder with the same name already exists")); } count = command.ZzExecuteNonQuery(DbManager.SqlFolderInsert); if (count != 1) { return(ReturnCodeFactory.Error((int)Errors.Unknown, "Error trying to add a new folder")); } IdNewFolder = command.ZzGetScalarInteger(DbManager.SqlGetIdFolder); if (IdNewFolder > 0) { code.IdObject = IdNewFolder; } else { return(ReturnCodeFactory.Error((int)Errors.Unknown, "Error trying to add a new folder")); } } return(code); }
public ReturnCode SwapRank(int IdFolder, Setting settingOne, Setting settingTwo) { if (FolderNotFound(IdFolder)) { return(FolderNotFound()); } ReturnCode code = ReturnCodeFactory.Success($"Setting rank exchange completed"); if ((settingOne == null) || (settingTwo == null)) { return(ReturnCodeFactory.Error("At least one parameter is null")); } int count = 0; using (SQLiteConnection connection = GetSqliteConnection()) using (SQLiteCommand command = new SQLiteCommand(connection)) { count = command.ZzOpenConnection().ZzAdd("@IdFolder", IdFolder).ZzAdd("@IdSetting", settingOne.IdSetting).ZzAdd("@Rank", settingTwo.Rank).ZzExecuteNonQuery(DbManager.SqlSetRank); if (count != 1) { return(ReturnCodeFactory.Error("Error trying to change a rank of a setting")); } command.Parameters.Clear(); count = command.ZzAdd("@IdFolder", IdFolder).ZzAdd("@IdSetting", settingTwo.IdSetting).ZzAdd("@Rank", settingOne.Rank).ZzExecuteNonQuery(DbManager.SqlSetRank); if (count != 1) { return(ReturnCodeFactory.Error("Error trying to change a rank of a setting")); } } return(code); }
public ReturnCode SettingCreate(int IdFolder, string IdSetting, int IdType, string value) { //IdSetting = IdSetting.RemoveSpecialCharacters(); if (FolderNotFound(IdFolder)) { return(FolderNotFound()); } ReturnCode code = ReturnCodeFactory.Success($"New setting has been created: {IdSetting}"); if (IdSetting.Trim().Length < 1) { return(ReturnCodeFactory.Error((int)Errors.SettingNameNotSpecified, "Setting name not specified")); } int count = 0; using (SQLiteConnection connection = GetSqliteConnection()) using (SQLiteCommand command = new SQLiteCommand(connection)) { count = command.ZzOpenConnection().ZzAdd("@IdFolder", IdFolder).ZzAdd("@IdSetting", IdSetting).ZzGetScalarInteger(DbManager.SqlSettingCount); if (count > 0) { return(ReturnCodeFactory.Error((int)Errors.SettingAlreadyExists, "A setting with the same name already exists")); } count = command.ZzAdd("@IdType", IdType).ZzAdd("@SettingValue", value).ZzExecuteNonQuery(DbManager.SqlSettingInsert); if (count != 1) { return(ReturnCodeFactory.Error((int)Errors.SettingInsertFailed, "Error trying to add a new setting")); } code.StringNote = value; } return(code); }
private void EventLoadDataFromDatabaseFile(bool LoadDataFirstTimeFromThisFile) { DataTable table = null; bool Error = false; ReturnCode ConnectToDatabase = ReturnCodeFactory.Success(); try { ConnectToDatabase = DbSettings.ConnectToDatabase(TxDatabaseFile.Text); if (ConnectToDatabase.Error) { throw new DatabaseStructureCheckException(ConnectToDatabase.StringValue); } table = DbSettings.GetTableFolders(); } catch (DatabaseStructureCheckException ex) { Error = true; Ms.Message("Checking database structure", ex.Message).Control(TxDatabaseFile).Error(); } catch (Exception ex) { Error = true; if (ex.Message.Contains("not a database")) { Ms.Message("Failed to read data from the file", "This file is not a database of the specified type").Control(TxDatabaseFile).Error(); } else { Ms.Error("Failed to read data from the file you specified", ex).Control(TxDatabaseFile).Create(); } } if (Error == false) { try { if (TableFolders != null) { TableFolders.Clear(); //TableFolders.Columns.Clear();// TableFolders.Dispose(); } DbSettings.FillTreeView(TvFolders, table); TvManager.SetFontAndImageForAllNodes(); TableFolders = table; } catch (Exception ex) { Error = true; Ms.Error("An error occurred while trying to read the settings structure from the file", ex).Control(TxDatabaseFile).Create(); } } if (Error == false) { Program.ApplicationSettings.SettingsDatabaseLocation = TxDatabaseFile.Text; if (LoadDataFirstTimeFromThisFile) { EventLoadDataFromFileFirstTime(); } } }
private void EventButtonRenameFolder(object sender, EventArgs e) { const string ErrorHeader = "Failed to rename folder"; RadTreeNode node = TvFolders.SelectedNode; ReturnCode code = ReturnCodeFactory.Error(ErrorHeader); if (node == null) { Ms.ShortMessage(MsgType.Fail, "The folder you want to rename is not specified", 380, TxFolderRename).Create(); return; } int IdFolder = DbSettings.GetIdFolder(node); string NodeFullPath = node.FullPath; if (IdFolder < 0) { Ms.ShortMessage(MsgType.Fail, "The folder you want to rename is not specified", 350, TxFolderRename).Create(); return; } string NameFolder = TxFolderRename.Text.RemoveSpecialCharacters(); TxFolderRename.Text = NameFolder; if (NameFolder.Length < 1) { Ms.ShortMessage(MsgType.Fail, "No new folder name specified", 340, TxFolderRename).Create(); return; } if (node.Text == NameFolder) { Ms.ShortMessage(MsgType.Fail, "The new name is no different from the previous one", 400, TxFolderRename).Create(); return; } try { code = DbSettings.FolderRename(IdFolder, NameFolder); } catch (Exception ex) { Ms.Error(ErrorHeader, ex).Control(TxFolderRename).Create(); return; } if (code.Success) { Ms.ShortMessage(MsgType.Debug, code.StringValue, GetMessageBoxWidth(code.StringValue), TxFolderRename).Create(); ClearArraySearchResult(); node.Text = NameFolder; node.Selected = false; node.Selected = true; } else { Ms.Message(ErrorHeader, code.StringValue, TxFolderRename).Fail(); } }
private async Task EventButtonSettingDelete(object sender, EventArgs e) { const string ErrorHeader = "Error trying to delete a setting"; ReturnCode code = ReturnCodeFactory.Error(ErrorHeader); string NameSetting = CurrentIdSetting; try { code = DbSettings.SettingDelete(CurrentIdFolder, CurrentIdSetting); } catch (Exception ex) { Ms.Error(ErrorHeader, ex).Control(TxSettingRename).Create(); return; } if (code.Success) { await RefreshGridSettingsAndClearSelection(); // Setting was deleted // } else { Ms.Message(ErrorHeader, code.StringValue).Wire(TxSettingDelete).Warning(); } ShowNotification(code.Success, code.StringValue); }
public ReturnCode FolderRename(int IdFolder, string NameFolder) { if (FolderNotFound(IdFolder)) { return(FolderNotFound()); } ReturnCode code = ReturnCodeFactory.Success($"Folder has been renamed: {NameFolder}"); int count = 0; using (SQLiteConnection connection = GetSqliteConnection()) using (SQLiteCommand command = new SQLiteCommand(connection)) { command.ZzOpenConnection().ZzText(DbManager.SqlFolderCountByIdFolder).ZzAdd("@IdFolder", IdFolder).ZzAdd("@NameFolder", NameFolder); count = command.ZzGetScalarInteger(); if (count != 0) { return(ReturnCodeFactory.Error((int)Errors.FolderAlreadyExists, "A folder with the same name already exists")); } count = command.ZzExecuteNonQuery(DbManager.SqlFolderRename); if (count < 1) { return(ReturnCodeFactory.Error((int)Errors.Unknown, "Error trying to rename a folder")); } } if (IdFolder == DbManager.IdFolderRoot) { RootFolderName = GetRootFolderName(); } return(code); }
public ReturnCode SettingDelete(int IdFolder, string IdSetting) { if (FolderNotFound(IdFolder)) { return(FolderNotFound()); } ReturnCode code = ReturnCodeFactory.Success($"Setting has been deleted: {IdSetting}"); if (IdSetting.Trim().Length < 1) { return(ReturnCodeFactory.Error((int)Errors.SettingNameNotSpecified, "Setting name not specified")); } int count = 0; using (SQLiteConnection connection = GetSqliteConnection()) using (SQLiteCommand command = new SQLiteCommand(connection)) { count = command.ZzOpenConnection().ZzAdd("@IdFolder", IdFolder).ZzAdd("@IdSetting", IdSetting).ZzGetScalarInteger(DbManager.SqlSettingCount); if (count != 1) { return(ReturnCodeFactory.Error((int)Errors.SettingNotFound, "Setting not found")); } count = command.ZzExecuteNonQuery(DbManager.SqlSettingDelete); if (count != 1) { return(ReturnCodeFactory.Error((int)Errors.Unknown, "Error trying to delete a setting")); } } return(code); }
public ReturnCode SettingUpdate(int IdFolder, string IdSetting, int IdType, string value) { if (FolderNotFound(IdFolder)) { return(FolderNotFound()); } ReturnCode code = ReturnCodeFactory.Success($"Changes saved: {IdSetting}"); if (IdSetting.Trim().Length < 1) { return(ReturnCodeFactory.Error((int)Errors.SettingNameNotSpecified, "Setting name not specified")); } int count = 0; using (SQLiteConnection connection = GetSqliteConnection()) using (SQLiteCommand command = new SQLiteCommand(connection)) { count = command.ZzOpenConnection().ZzAdd("@IdFolder", IdFolder).ZzAdd("@IdSetting", IdSetting).ZzGetScalarInteger(DbManager.SqlSettingCount); if (count != 1) { return(ReturnCodeFactory.Error((int)Errors.SettingDoesNotExist, "The setting with the specified name does not exist")); } count = command.ZzAdd("@IdType", IdType).ZzAdd("@SettingValue", value).ZzExecuteNonQuery(DbManager.SqlSettingUpdate); if (count != 1) { return(ReturnCodeFactory.Error((int)Errors.SettingUpdateFailed, "Error trying to change a value of the setting")); } code.StringNote = value; } return(code); }
public ReturnCode SaveSettingText(string FolderPath, string IdSetting, TypeSetting type, string value) { if (SettingTypeIsText(type) == false) { return(ReturnCodeFactory.Error((int)Errors.SettingInappropriateType, "Incorrect [TypeSetting] value for the [SaveSettingText] method.")); } return(SettingCreateOrUpdate(FolderPath, IdSetting, type, value)); }
private void EventButtonDeleteFolder(object sender, EventArgs e) { const string ErrorHeader = "Failed to delete folder"; RadTreeNode node = TvFolders.SelectedNode; ReturnCode code = ReturnCodeFactory.Error(ErrorHeader); if (node == null) { Ms.ShortMessage(MsgType.Fail, "The folder you want to delete is not specified", 350, TxFolderDelete).Create(); return; } if (node.Level == 0) { Ms.ShortMessage(MsgType.Warning, "It is not allowed to delete a root folder", 350, TxFolderDelete).Create(); return; } RadTreeNode parent = node.Parent; if (parent == null) { Ms.ShortMessage(MsgType.Fail, "The folder containing the folder to be deleted was not found", 450, TxFolderDelete).Create(); return; } string NodeFullPath = parent.FullPath; int IdFolder = DbSettings.GetIdFolder(node); try { code = DbSettings.FolderDelete(IdFolder, node.Text); } catch (Exception ex) { Ms.Error(ErrorHeader, ex).Control(TxFolderDelete).Create(); return; } if (code.Success) { Ms.ShortMessage(MsgType.Debug, code.StringValue, GetMessageBoxWidth(code.StringValue), TxFolderDelete).Create(); parent.Selected = true; ClearArraySearchResult(); node.Remove(); if (parent.Nodes.Count < 1) { parent.ImageIndex = 0; } } else { Ms.Message(ErrorHeader, code.StringValue, TxFolderDelete).Fail(); } }
public async Task <ReturnCode> FolderForceDeleteAsync(string FolderPath) { ReturnCode code = ReturnCodeFactory.Error(); int IdFolder = await GetIdFolderAsync(FolderPath); if (FolderNotFound(IdFolder)) { return(FolderNotFound()); } if (IdFolder == DbManager.IdFolderRoot) { return(ReturnCodeFactory.Error("The root folder cannot be specified as an argument to this function.")); } List <int> list = await GetListOfIdFoldersAsync(IdFolder); int count = 0; async Task ProcessOneFolder(SQLiteCommand cmd, int InnerIdFolder) { List <int> InnerList = GetListOfIdFolders(cmd, InnerIdFolder); foreach (int item in InnerList) { await ProcessOneFolder(cmd, item); } await DeleteSettingsAndFolder(cmd, InnerIdFolder); } async Task DeleteSettingsAndFolder(SQLiteCommand cmd, int InnerIdFolder) { cmd.Parameters.Clear(); await cmd.ZzAdd("@IdFolder", InnerIdFolder).ZzExecuteNonQueryAsync(DbManager.SqlDeleteAllSettingsOfOneFolder); cmd.ZzExecuteNonQuery(DbManager.SqlFolderDelete); count++; } using (SQLiteConnection connection = GetSqliteConnection()) using (SQLiteCommand command = new SQLiteCommand(connection).ZzOpenConnection()) { foreach (int item in list) { await ProcessOneFolder(command, item); } } DeleteAllSettingsOfOneFolder(IdFolder); code = FolderDelete(IdFolder, FolderPath); code.StringNote += $" Folders processed = {++count}"; return(code); }
public ReturnCode CheckIdSettingCharacters(string IdSetting) { if (IdSetting.Trim() == string.Empty) { return(ReturnCodeFactory.Error("Incorrect name of the setting.")); } string CorrectedIdSetting = IdSetting.RemoveSpecialCharacters(); if (CorrectedIdSetting != IdSetting) { return(ReturnCodeFactory.Error($"Special characters are not allowed in the setting name. Allowed name may be = {CorrectedIdSetting}")); } return(ReturnCodeFactory.Success()); }
public ReturnCode GetRandomSetting() { ReturnCode code = ReturnCodeFactory.Error(); using (SQLiteConnection connection = GetSqliteConnection()) using (SQLiteCommand command = new SQLiteCommand(DbManager.SqlGetRandomSetting, connection).ZzOpenConnection()) using (SQLiteDataReader reader = command.ExecuteReader()) while (reader.Read()) { code = ReturnCodeFactory.Create(ReturnCodeFactory.NcSuccess, reader.GetInt32(0), reader.GetString(1), string.Empty); //Trace.WriteLine("---> " + ReturnCodeFormatter.ToString(code)); break; } return(code); }
private ReturnCode CheckDatabaseStructure() { ReturnCode code = ReturnCodeFactory.Success($"Database structure is ok"); int CheckObjectCount = 4; using (SQLiteConnection connection = GetSqliteConnection()) using (SQLiteCommand command = new SQLiteCommand(connection)) { command.ZzOpenConnection().ZzText(DbManager.SqlCheckDatabaseStructure); if (command.ZzGetScalarInteger() != CheckObjectCount) { code = ReturnCodeFactory.Error(ReturnCodeFactory.NcError, "The database structure is not compliant with the standard. When working with the database errors may occur."); } } return(code); }
private async Task EventButtonSettingRename(object sender, EventArgs e) { ReturnCode code = ReturnCodeFactory.Error("An error occurred while trying to change the setting name"); string NameSettingDraft = TxSettingRename.Text.Trim(); string NameSetting = NameSettingDraft.RemoveSpecialCharacters(); TxSettingRename.Text = NameSetting; if (NameSetting.Length < 1) { if (NameSettingDraft.Length < 1) { Ms.ShortMessage(MsgType.Fail, "Missing new setting name", 350, TxSettingRename).Create(); return; } else { Ms.ShortMessage(MsgType.Fail, "You have specified characters that cannot be used in the name of setting", 400, TxSettingRename).Create(); return; } } const string ErrorHeader = "Failed to change setting name"; try { code = DbSettings.SettingRename(CurrentIdFolder, CurrentIdSetting, NameSetting); } catch (Exception ex) { Ms.Error(ErrorHeader, ex).Control(TxSettingRename).Create(); return; } if (code.Success) { await RefreshGridSettingsAndClearSelection(); // Setting was renamed // //Ms.Message($"{NameSetting}", code.StringValue).Wire(TxSettingRename).Offset(TxSettingRename.Width, -2 * TxSettingRename.Height).Ok(); //SettingsToolbarSetEmptyPage(); } else { Ms.Message(ErrorHeader, code.StringValue).Wire(TxSettingRename).Warning(); } ShowNotification(code.Success, code.StringValue); }
private ReturnCode SettingCreateOrUpdate(string FolderPath, string IdSetting, TypeSetting type, string value) { int IdFolder = GetIdFolder(FolderPath); if (FolderNotFound(IdFolder)) { return(FolderNotFound()); } int IdType = (int)type; //IdSetting = IdSetting.RemoveSpecialCharacters(); ReturnCode code = ReturnCodeFactory.Success($"New setting has been created: {IdSetting}"); if (IdSetting.Trim().Length < 1) { return(ReturnCodeFactory.Error((int)Errors.SettingNameNotSpecified, "Setting name not specified")); } int count = 0; using (SQLiteConnection connection = GetSqliteConnection()) using (SQLiteCommand command = new SQLiteCommand(connection)) { count = command.ZzOpenConnection().ZzAdd("@IdFolder", IdFolder).ZzAdd("@IdSetting", IdSetting).ZzGetScalarInteger(DbManager.SqlSettingCount); if (count > 0) // UPDATE value of existing setting // { code = ReturnCodeFactory.Success($"Changes saved: {IdSetting}"); count = command.ZzAdd("@IdType", IdType).ZzAdd("@SettingValue", value).ZzExecuteNonQuery(DbManager.SqlSettingUpdate); if (count != 1) { return(ReturnCodeFactory.Error((int)Errors.SettingUpdateFailed, "Error trying to change a value of the setting")); } code.StringNote = value; } else // ADD a new value of setting // { count = command.ZzAdd("@IdType", IdType).ZzAdd("@SettingValue", value).ZzExecuteNonQuery(DbManager.SqlSettingInsert); if (count != 1) { return(ReturnCodeFactory.Error((int)Errors.SettingInsertFailed, "Error trying to add a new setting")); } code.StringNote = value; } } return(code); }
public ReturnCode ConnectToDatabase(string PathToDatabase = "") { if (PathToDatabase == string.Empty) { PathToDatabase = Path.Combine(Path.Combine(Application.StartupPath, DefaultFolder), DefaultFileName); } //MessageBox.Show(PathToDatabase); SetPathToDatabase(PathToDatabase); ReturnCode code; try { code = CheckDatabaseStructure(); } catch { return(ReturnCodeFactory.Error("The file you specified is not a SQLite database.")); } if (code.Error) { return(code); } if (TableTypes != null) { TableTypes.Clear(); } try { TableTypes = GetTable(DbManager.TnTypes); RootFolderName = GetRootFolderName(); } catch (Exception ex) { RootFolderName = string.Empty; return(ReturnCodeFactory.Error("Could not read data from the database file.", ex.Message)); } return(ReturnCodeFactory.Success()); }
/// <summary> /// Get all settings of all folders. /// </summary> public List <Setting> GetAllSettings() { ReturnCode code = ReturnCodeFactory.Error(); List <Setting> list = new List <Setting>(); using (SQLiteConnection connection = GetSqliteConnection()) using (SQLiteCommand command = new SQLiteCommand(DbManager.SqlGetAllSettings, connection).ZzOpenConnection()) using (SQLiteDataReader reader = command.ExecuteReader()) while (reader.Read()) { list.Add(Setting.Create ( reader.GetInt32(0), reader.GetString(1), reader.GetInt32(2), reader.GetString(3), reader.GetInt32(4) )); } return(list); }
public ReturnCode FolderDelete(int IdFolder, string NameFolder) { if (FolderNotFound(IdFolder)) { return(FolderNotFound()); } ReturnCode code = ReturnCodeFactory.Success($"Folder has been deleted: {NameFolder}"); int count = 0; using (SQLiteConnection connection = GetSqliteConnection()) using (SQLiteCommand command = new SQLiteCommand(connection)) { command.ZzOpenConnection().ZzText(DbManager.SqlFolderCountSimple).ZzAdd("@IdFolder", IdFolder); count = command.ZzGetScalarInteger(); if (count != 1) { return(ReturnCodeFactory.Error((int)Errors.FolderNotFound, "The folder you specified was not found")); } count = command.ZzGetScalarInteger(DbManager.SqlCountChildFolder); if (count != 0) { return(ReturnCodeFactory.Error((int)Errors.FolderHasChildFolder, "You cannot delete a folder that has other folders inside")); } count = command.ZzGetScalarInteger(DbManager.SqlCountChildSettings); if (count != 0) { return(ReturnCodeFactory.Error((int)Errors.FolderHasSettings, "You cannot delete a folder that contains settings")); } count = command.ZzExecuteNonQuery(DbManager.SqlFolderDelete); if (count == 0) { return(ReturnCodeFactory.Error((int)Errors.Unknown, "Error trying to delete a folder")); } } return(code); }
private void EventButtonAddFolder(object sender, EventArgs e) { const string ErrorHeader = "Error trying to add a new folder"; RadTreeNode parent = TvFolders.SelectedNode; ReturnCode code = ReturnCodeFactory.Error(ErrorHeader); if (parent == null) { Ms.ShortMessage(MsgType.Fail, "The folder where the new one is added is not specified", 400, TxFolderAdd).Create(); return; } int IdFolder = DbSettings.GetIdFolder(parent); string ParentFullPath = parent.FullPath; bool Error = false; if (IdFolder < 0) { Ms.ShortMessage(MsgType.Fail, "The folder where the new one is added is not specified", 400, TxFolderAdd).Create(); return; } if (parent.Level > 14) { Ms.ShortMessage(MsgType.Fail, "Hierarchical nesting too deep", 280, TxFolderAdd).Create(); return; } string NameFolderDraft = TxFolderAdd.Text.Trim(); string NameFolder = NameFolderDraft.RemoveSpecialCharacters(); TxFolderAdd.Text = NameFolder; if (NameFolder.Length < 1) { if (NameFolderDraft.Length < 1) { Ms.ShortMessage(MsgType.Fail, "New folder name not specified", 230, TxFolderAdd).Offset(-100 + TxFolderAdd.Size.Width, -70).Create(); return; } else { Ms.ShortMessage(MsgType.Fail, "You have specified characters that cannot be used in the folder name", 470, TxFolderAdd).Create(); return; } } int IdNewFolder = -1; try { code = DbSettings.FolderInsert(IdFolder, NameFolder); } catch (Exception ex) { Error = true; Ms.Error(ErrorHeader, ex).Control(TxFolderAdd).Create(); IdNewFolder = -1; } IdNewFolder = code.IdObject; if (code.Error) { if (Error == false) { Ms.Message(ErrorHeader, code.StringValue, TxFolderAdd).Fail(); } } if (IdNewFolder <= 0) { if ((Error == false) && (code.Success)) { Ms.Message(ErrorHeader, code.StringValue, TxFolderAdd).Fail(); } } else // Give out SUCCESS MESSAGE // { if (NameFolderDraft.Length == NameFolder.Length) { Ms.ShortMessage(MsgType.Debug, code.StringValue, GetMessageBoxWidth(code.StringValue), TxFolderAdd) .Offset(TxFolderAdd.Width, -5 * TxFolderAdd.Height).Create(); } else { Ms.Message("Some characters you specify\nhave been excluded from the name", code.StringValue) .Control(TxFolderAdd).Offset(200, 0).Delay(7).Info(); Ms.Message("The folder name contained forbidden characters:", NameFolderDraft).NoAlert().Warning(); Ms.Message("The name has been corrected:", NameFolder).NoAlert().Warning(); } EventRefreshDataFromDatabaseFile(); parent = TvFolders.GetNodeByPath(ParentFullPath); if (parent == null) { Ms.Message(MsgType.Error, "Error!", $"Method TvFolders.GetNodeByPath(ParentFullPath) has returned [null]. ParentFullPath={ParentFullPath}", null, MsgPos.Unknown, 0).NoAlert().Create(); Ms.ShortMessage(MsgType.Warning, $"Error! Details in the message log", 300, TxFolderAdd).NoTable().Create(); } else { TvManager.TryToSelectFolderAfterCreating(parent, NameFolder); } } TxFolderAdd.Clear(); }
public ReturnCode CreateNewDatabase(string FileName) { string sql = string.Empty; ReturnCode code = ReturnCodeFactory.Success(); try { SQLiteConnection.CreateFile(FileName); using (SQLiteConnection connection = new SQLiteConnection($"Data Source={FileName};Version=3;")) { connection.Open(); using (SQLiteCommand command = new SQLiteCommand(connection)) { sql = @"CREATE TABLE FOLDERS ( IdFolder INTEGER CONSTRAINT PK_FOLDERS PRIMARY KEY ON CONFLICT ROLLBACK AUTOINCREMENT NOT NULL ON CONFLICT ROLLBACK, IdParent INTEGER NOT NULL ON CONFLICT ROLLBACK CONSTRAINT FK_FOLDERS REFERENCES FOLDERS (IdFolder) ON DELETE RESTRICT ON UPDATE CASCADE, NameFolder TEXT (255) NOT NULL );"; command.ZzExecuteNonQuery(sql); sql = $@" INSERT INTO FOLDERS VALUES({IdFolderRoot}, {IdFolderRoot}, 'application'); INSERT INTO FOLDERS VALUES(1, {IdFolderRoot}, 'local_database');"; command.ZzExecuteNonQuery(sql); sql = @" CREATE TABLE TYPES (IdType INTEGER PRIMARY KEY NOT NULL, NameType TEXT (255) NOT NULL, Note TEXT (4000));"; command.ZzExecuteNonQuery(sql); sql = @" INSERT INTO TYPES VALUES(0,'unknown',NULL); INSERT INTO TYPES VALUES(1,'boolean',NULL); INSERT INTO TYPES VALUES(2,'datetime',NULL); INSERT INTO TYPES VALUES(3,'integer',NULL); INSERT INTO TYPES VALUES(4,'text',NULL); INSERT INTO TYPES VALUES(5,'password',NULL); INSERT INTO TYPES VALUES(6,'folder name',NULL); INSERT INTO TYPES VALUES(7,'file name',NULL); INSERT INTO TYPES VALUES(8,'font',NULL); INSERT INTO TYPES VALUES(9,'color',NULL);"; command.ZzExecuteNonQuery(sql); sql = @"CREATE TABLE SETTINGS ( IdFolder INTEGER NOT NULL, IdSetting TEXT (255) NOT NULL, IdType INTEGER NOT NULL, SettingValue TEXT, Rank INTEGER NOT NULL, CONSTRAINT PK_SETTINGS PRIMARY KEY (IdFolder, IdSetting) ON CONFLICT ROLLBACK, CONSTRAINT FK_SETTINGS_FOLDERS FOREIGN KEY (IdFolder) REFERENCES FOLDERS (IdFolder) ON DELETE RESTRICT ON UPDATE CASCADE, CONSTRAINT FK_SETTINGS_TYPES FOREIGN KEY (IdType) REFERENCES TYPES (IdType) ON DELETE RESTRICT ON UPDATE CASCADE);"; command.ZzExecuteNonQuery(sql); sql = @"DELETE FROM sqlite_sequence;"; command.ZzExecuteNonQuery(sql); sql = @"INSERT INTO sqlite_sequence VALUES('FOLDERS',2);"; command.ZzExecuteNonQuery(sql); sql = @"CREATE UNIQUE INDEX UX_NameFolder ON FOLDERS(IdParent, NameFolder);"; command.ZzExecuteNonQuery(sql); sql = @"CREATE VIEW V_SETTINGS AS SELECT A.IdFolder, A.IdSetting, A.IdType, B.NameType, A.SettingValue, A.Rank, CASE WHEN A.IdType = 1 THEN A.SettingValue ELSE '' END AS BooleanValue FROM SETTINGS A LEFT JOIN TYPES B ON A.IdType = B.IdType ORDER BY A.Rank, A.IdSetting;"; command.ZzExecuteNonQuery(sql); connection.Close(); } } } catch (Exception ex) { code = ReturnCodeFactory.Error(ex.Message, "Could not create a new database"); } return(code); }
private void TestActionUpdateRandomSetting(object sender) { Setting setting = GetRandomSetting(); string FolderPath = GetFolderPath(setting); ReturnCode code = ReturnCodeFactory.Error("cancel"); string guid = "U-" + GetNewGuid(); OperationBegin(guid); Trace.WriteLine($"update ... {guid} ... [[{setting.IdSetting}]]"); Stopwatch sw = Stopwatch.StartNew(); if (setting.IdType == (int)TypeSetting.Boolean) { code = DbSettings.SaveSettingBoolean(FolderPath, setting.IdSetting, VxFaker.Random.Bool()); } else if (setting.IdType == (int)TypeSetting.Datetime) { DateTime dt = new DateTime(2000, 1, 1).AddSeconds(VxFaker.Random.Int(1, 600000000)); code = DbSettings.SaveSettingDatetime(FolderPath, setting.IdSetting, dt); } else if (setting.IdType == (int)TypeSetting.Integer64) { code = DbSettings.SaveSettingInteger64(FolderPath, setting.IdSetting, VxFaker.Random.Long()); } if ( (setting.IdType == (int)TypeSetting.Password) || (setting.IdType == (int)TypeSetting.File) || (setting.IdType == (int)TypeSetting.Folder) || (setting.IdType == (int)TypeSetting.Text)) { string Text = VxFaker.Hacker.Abbreviation() + "~" + VxFaker.Hacker.Adjective() + "$" + VxFaker.Hacker.Phrase() + VxFaker.Company.CompanyName() + VxFaker.Lorem.Sentence(5) + VxFaker.Phone.PhoneNumber() + " " + VxFaker.Address.SecondaryAddress() + " " + VxFaker.System.DirectoryPath() + " " + VxFaker.Address.StreetAddress(); Text = Text.SafeSubstring(1, VxFaker.Random.Int(1, Text.Length)); code = DbSettings.SaveSettingText(FolderPath, setting.IdSetting, (TypeSetting)setting.IdType, Text); } if (setting.IdType == (int)TypeSetting.Color) { Color color = Color.FromArgb(rnd.Next(256), rnd.Next(256), rnd.Next(256)); code = DbSettings.SaveSettingColor(FolderPath, setting.IdSetting, color); } if (setting.IdType == (int)TypeSetting.Font) { Font font = new Font("Arial", rnd.Next(8, 28)); code = DbSettings.SaveSettingFont(FolderPath, setting.IdSetting, font); } sw.Stop(); if (code.StringValue == "cancel") { Trace.WriteLine($"^^^ {guid} --- Cancel updating of setting"); return; } if (code.Error) { Trace.WriteLine($"!!! {guid} --- Could not update a setting. Error = {code.StringValue}"); } else { Trace.WriteLine($"UPDATE --- {guid} --- [[{setting.IdSetting}]] --- {setting.IdType} >>>> ms = {sw.ElapsedMilliseconds}"); OperationSuccess(guid); } }
public static ReceivedValueInteger32 Success(int value) => new ReceivedValueInteger32(ReturnCodeFactory.Success(), value);
public static ReceivedValueInteger32 Error(int ErrorCode, string ErrorMessage = CxConvert.Empty) { return(new ReceivedValueInteger32(ReturnCodeFactory.Error(ErrorCode, ErrorMessage), DefaultValue)); }
private ReturnCode FolderForceDeleteUsingTreeviewOldVersionDeprecated(string FolderPath) { // Trace.WriteLine($"FolderForceDelete(string FolderPath) ---> {FolderPath}"); // This method uses RadTreeView class to perform search operations // ReturnCode code = ReturnCodeFactory.Error(); FolderPath = AddRootFolderNameIfNotSpecified(FolderPath); int IdFolder = GetIdFolder(FolderPath); if (FolderNotFound(IdFolder)) { return(FolderNotFound()); } //Trace.WriteLine($"FolderForceDelete(string FolderPath) ---> Point 1 --- IdFolder = {IdFolder}"); bool FlagFound = false; int count = 0; void SearchNode(RadTreeNode node) { if (FlagFound) { return; } //if (GetIdFolder(node) == IdFolder) if (node.FullPath == FolderPath) { FlagFound = true; //Trace.WriteLine($"Found !!! ---> {node.FullPath}"); LocalMethodDeleteAllSettingsOfOneFolder(node); LocalMethodDeleteFolderAndAllChildFolders(node); } if (!FlagFound) { foreach (var item in node.Nodes) { SearchNode(item); } } } void LocalMethodDeleteAllSettingsOfOneFolder(RadTreeNode node) { DeleteAllSettingsOfOneFolder(node.FullPath); //Trace.WriteLine($"Delete settings of folder ======= {node.FullPath}"); foreach (var item in node.Nodes) { LocalMethodDeleteAllSettingsOfOneFolder(item); } } void LocalMethodDeleteFolderAndAllChildFolders(RadTreeNode node) { foreach (var item in node.Nodes) { LocalMethodDeleteFolderAndAllChildFolders(item); } ReturnCode result = FolderDelete(node.FullPath, string.Empty); if (IdFolder == GetIdFolder(node)) { code = result; } count++; //Trace.WriteLine($@"Delete folder /\/\/\/\/\/\/\ === {node.FullPath}"); } DataTable table = GetTableFolders(); FxTreeView form = new FxTreeView(); form.Visible = false; FillTreeView(form.TvFolders, table); foreach (var item in form.TvFolders.Nodes) { SearchNode(item); } form.TvFolders.DataSource = null; table.Clear(); form.TvFolders.Dispose(); table.Dispose(); form.Close(); //Trace.WriteLine($@" >>>>>>>>>>>>>>>>>>>>> {ReturnCodeFormatter.ToString(code)}"); code.StringNote += $" Folders processed = {count}"; return(code); }
public ReturnCode FolderNotFound() => ReturnCodeFactory.Error((int)Errors.FolderNotFound, "Folder not found");
public ReturnCode FolderForceDeleteUsingTreeview(string FolderPath) { // This method uses RadTreeView class to perform search operations // ReturnCode code = ReturnCodeFactory.Error(); FolderPath = AddRootFolderNameIfNotSpecified(FolderPath); int IdFolder = GetIdFolder(FolderPath); if (FolderNotFound(IdFolder)) { return(FolderNotFound()); } if (IdFolder == DbManager.IdFolderRoot) { return(ReturnCodeFactory.Error("The root folder cannot be specified as an argument to this function.")); } bool FlagFound = false; int count = 0; Stack <int> stack = new Stack <int>(); void MarkNodeToBeDeleted(RadTreeNode node) { stack.Push(GetIdFolder(node)); //Trace.WriteLine($"Push to stack >>> {node.FullPath} === {x}"); foreach (var item in node.Nodes) { MarkNodeToBeDeleted(item); } } void SearchNode(RadTreeNode node) { if (FlagFound) { return; } //if (GetIdFolder(node) == IdFolder) if (node.FullPath == FolderPath) { FlagFound = true; MarkNodeToBeDeleted(node); } if (!FlagFound) { foreach (var item in node.Nodes) { SearchNode(item); } } } DataTable table = GetTableFolders(); FxTreeView form = new FxTreeView(); form.Visible = false; FillTreeView(form.TvFolders, table); foreach (var item in form.TvFolders.Nodes) { SearchNode(item); } using (SQLiteConnection connection = GetSqliteConnection()) using (SQLiteCommand command = new SQLiteCommand(connection).ZzOpenConnection()) while (stack.Count > 0) { int x = stack.Pop(); command.Parameters.Clear(); command.ZzAdd("@IdFolder", x).ZzExecuteNonQuery(DbManager.SqlDeleteAllSettingsOfOneFolder); if (stack.Count > 0) { command.ZzExecuteNonQuery(DbManager.SqlFolderDelete); } count++; } code = FolderDelete(FolderPath, FolderPath); form.TvFolders.DataSource = null; table.Clear(); form.TvFolders.Dispose(); table.Dispose(); form.Close(); code.StringNote += $" Folders processed = {count}"; return(code); }