From: <che...@us...> - 2007-06-20 19:01:05
|
Revision: 579 http://mp-plugins.svn.sourceforge.net/mp-plugins/?rev=579&view=rev Author: chef_koch Date: 2007-06-20 12:01:03 -0700 (Wed, 20 Jun 2007) Log Message: ----------- cleaned up some the db methods (no sql code changes, mostly move the pre conditions to the beginning of each method) Modified Paths: -------------- trunk/plugins/myGUIProgramsAlt/GUIProgramsAlt/ApplicationItems/ApplicationItem.cs Modified: trunk/plugins/myGUIProgramsAlt/GUIProgramsAlt/ApplicationItems/ApplicationItem.cs =================================================================== --- trunk/plugins/myGUIProgramsAlt/GUIProgramsAlt/ApplicationItems/ApplicationItem.cs 2007-06-20 18:43:30 UTC (rev 578) +++ trunk/plugins/myGUIProgramsAlt/GUIProgramsAlt/ApplicationItems/ApplicationItem.cs 2007-06-20 19:01:03 UTC (rev 579) @@ -540,9 +540,6 @@ - - - void proc_Exited(object sender, EventArgs e) { @@ -741,7 +738,6 @@ } - #region old sorting stuff, some(all) might be obsolete, but maybe usefull for improving new sorting method public virtual void OnSort(GUIFacadeControl view, bool doSwitchState) @@ -794,7 +790,6 @@ #endregion - public virtual bool RefreshButtonVisible() { return false; // otherwise, override this in child class @@ -837,208 +832,191 @@ // descendant classes do that! } + #region Database stuff - #region DB stuff - + /// <summary> + /// get an unused SQL application KEY-number + /// </summary> private int GetNewAppID() { - // get an unused SQL application KEY-number - if (sqlDB != null) + if (sqlDB == null) return -1; + + // won't work in multiuser environment :) + SQLiteResultSet results; + int res = 0; + results = sqlDB.Execute("SELECT MAX(APPID) FROM tblApplicationItem"); + SQLiteResultSet.Row arr = results.Rows[0]; + if (arr.fields[0] != null) { - // won't work in multiuser environment :) - SQLiteResultSet results; - int res = 0; - results = sqlDB.Execute("SELECT MAX(APPID) FROM tblApplicationItem"); - SQLiteResultSet.Row arr = results.Rows[0]; - if (arr.fields[0] != null) + if (arr.fields[0] != "") { - if (arr.fields[0] != "") - { - res = Int32.Parse(arr.fields[0]); - } + res = Int32.Parse(arr.fields[0]); } - return res + 1; } - else return -1; + return res + 1; } private void Insert() { - if (sqlDB != null) + if (sqlDB == null) return; + + string sql = ""; + string Pincode = ""; //to remove + + if (ContentID <= 0) + ContentID = 100; + try { - try - { - if (ContentID <= 0) - { - ContentID = 100; - } - //to remove - string Pincode = ""; - AppID = GetNewAppID(); // important to avoid subsequent inserts! - string sql = String.Format("insert into tblApplicationItem (appid, fatherID, title, shorttitle, filename, arguments, windowstyle, startupdir, useshellexecute, usequotes, source_type, source, imagefile, filedirectory, imagedirectory, validextensions, importvalidimagesonly, iposition, enabled, enableGUIRefresh, GUIRefreshPossible, pincode, contentID, systemDefault, WaitForExit, preLaunch, postLaunch) values('{0}', '{1}', '{2}', '{3}', '{4}', '{5}', '{6}', '{7}', '{8}', '{9}', '{10}', '{11}', '{12}', '{13}', '{14}', '{15}', '{16}', '{17}', '{18}', '{19}', '{20}', '{21}', '{22}', '{23}', '{24}', '{25}', '{26}')", - AppID, FatherID, ProgramUtils.Encode(Title), ProgramUtils.Encode(ShortTitle), ProgramUtils.Encode(Filename), ProgramUtils.Encode(Arguments), - ProgramUtils.WindowStyleToStr(WindowStyle), ProgramUtils.Encode(StartupDir), ProgramUtils.BooleanToStr(UseShellExecute), - ProgramUtils.BooleanToStr(UseQuotes), ProgramUtils.ApplicationTypeToString(SourceType), ProgramUtils.Encode(Source), ProgramUtils.Encode(Imagefile), - ProgramUtils.Encode(FileDirectory), ProgramUtils.Encode(ImageDirectory), ProgramUtils.Encode(ValidExtensions), ProgramUtils.BooleanToStr(importValidImagesOnly), Position, - ProgramUtils.BooleanToStr(Enabled), ProgramUtils.BooleanToStr(EnableGUIRefresh), ProgramUtils.BooleanToStr(GUIRefreshPossible), Pincode, - ContentID, ProgramUtils.Encode(SystemDefault), ProgramUtils.BooleanToStr(WaitForExit), ProgramUtils.Encode(PreLaunch), ProgramUtils.Encode(PostLaunch) - ); - sqlDB.Execute(sql); - } - catch (SQLiteException ex) - { - Log.Info("programdatabase exception err:{0} stack:{1}", ex.Message, ex.StackTrace); - } + AppID = GetNewAppID(); // important to avoid subsequent inserts! + string sql = String.Format("insert into tblApplicationItem (appid, fatherID, title, shorttitle, filename, arguments, windowstyle, startupdir, useshellexecute, usequotes, source_type, source, imagefile, filedirectory, imagedirectory, validextensions, importvalidimagesonly, iposition, enabled, enableGUIRefresh, GUIRefreshPossible, pincode, contentID, systemDefault, WaitForExit, preLaunch, postLaunch) values('{0}', '{1}', '{2}', '{3}', '{4}', '{5}', '{6}', '{7}', '{8}', '{9}', '{10}', '{11}', '{12}', '{13}', '{14}', '{15}', '{16}', '{17}', '{18}', '{19}', '{20}', '{21}', '{22}', '{23}', '{24}', '{25}', '{26}')", + AppID, FatherID, ProgramUtils.Encode(Title), ProgramUtils.Encode(ShortTitle), ProgramUtils.Encode(Filename), ProgramUtils.Encode(Arguments), + ProgramUtils.WindowStyleToStr(WindowStyle), ProgramUtils.Encode(StartupDir), ProgramUtils.BooleanToStr(UseShellExecute), + ProgramUtils.BooleanToStr(UseQuotes), ProgramUtils.ApplicationTypeToString(SourceType), ProgramUtils.Encode(Source), ProgramUtils.Encode(Imagefile), + ProgramUtils.Encode(FileDirectory), ProgramUtils.Encode(ImageDirectory), ProgramUtils.Encode(ValidExtensions), ProgramUtils.BooleanToStr(importValidImagesOnly), Position, + ProgramUtils.BooleanToStr(Enabled), ProgramUtils.BooleanToStr(EnableGUIRefresh), ProgramUtils.BooleanToStr(GUIRefreshPossible), Pincode, + ContentID, ProgramUtils.Encode(SystemDefault), ProgramUtils.BooleanToStr(WaitForExit), ProgramUtils.Encode(PreLaunch), ProgramUtils.Encode(PostLaunch) + ); + sqlDB.Execute(sql); } + catch (SQLiteException ex) + { + Log.Info("programdatabase exception err:{0} stack:{1}", ex.Message, ex.StackTrace); + } } private void Update() { + if (sqlDB == null) return; + if (AppID == -1) return; + string sql = ""; - //to remove - string Pincode = ""; - if ((AppID >= 0) && (sqlDB != null)) + string Pincode = ""; //to remove + + if (ContentID <= 0) + ContentID = 100; + try { - if (ContentID <= 0) - { - ContentID = 100; - } - try - { - sql = String.Format( - "update tblApplicationItem set" + - "title = '" + ProgramUtils.Encode(Title) + - "', shorttitle = '" + ProgramUtils.Encode(ShortTitle) + - "', filename = '" + ProgramUtils.Encode(Filename) + - "', arguments = '" + ProgramUtils.Encode(Arguments) + - "', windowstyle = '" + ProgramUtils.WindowStyleToStr(WindowStyle) + - "', startupdir = '" + ProgramUtils.Encode(StartupDir) + - "', useshellexecute = '" + ProgramUtils.BooleanToStr(UseShellExecute) + - "', usequotes = '" + ProgramUtils.BooleanToStr(UseQuotes) + - "', source_type = '" + ProgramUtils.ApplicationTypeToString(SourceType) + - "', source = '" + ProgramUtils.Encode(Source) + - "', imagefile = '" + ProgramUtils.Encode(Imagefile) + - "', filedirectory = '" + ProgramUtils.Encode(FileDirectory) + - "', imagedirectory = '" + ProgramUtils.Encode(ImageDirectory) + - "', validextensions = '" + ProgramUtils.Encode(ValidExtensions) + - "', importvalidimagesonly = '" + ProgramUtils.BooleanToStr(importValidImagesOnly) + - "', iposition = " + Position + - ", enabled = '" + ProgramUtils.BooleanToStr(Enabled) + - "', fatherID = '" + FatherID + - "', enableGUIRefresh = '" + ProgramUtils.BooleanToStr(EnableGUIRefresh) + - "', GUIRefreshPossible = '" + ProgramUtils.BooleanToStr(GUIRefreshPossible) + - "', pincode = '" + Pincode + - "', contentID = '" + ContentID + - "', systemDefault = '" + ProgramUtils.Encode(SystemDefault) + - "', WaitForExit = '" + ProgramUtils.BooleanToStr(WaitForExit) + - "', preLaunch = '" + ProgramUtils.Encode(PreLaunch) + - "', postLaunch = '" + ProgramUtils.Encode(PostLaunch) + - "' where appID = " + AppID); - sqlDB.Execute(sql); - } - catch (SQLiteException ex) - { - Log.Info("programdatabase exception err:{0} stack:{1}", ex.Message, ex.StackTrace); - Log.Info("sql \n{0}", sql); - } + sql = String.Format( + "update tblApplicationItem set" + + "title = '" + ProgramUtils.Encode(Title) + + "', shorttitle = '" + ProgramUtils.Encode(ShortTitle) + + "', filename = '" + ProgramUtils.Encode(Filename) + + "', arguments = '" + ProgramUtils.Encode(Arguments) + + "', windowstyle = '" + ProgramUtils.WindowStyleToStr(WindowStyle) + + "', startupdir = '" + ProgramUtils.Encode(StartupDir) + + "', useshellexecute = '" + ProgramUtils.BooleanToStr(UseShellExecute) + + "', usequotes = '" + ProgramUtils.BooleanToStr(UseQuotes) + + "', source_type = '" + ProgramUtils.ApplicationTypeToString(SourceType) + + "', source = '" + ProgramUtils.Encode(Source) + + "', imagefile = '" + ProgramUtils.Encode(Imagefile) + + "', filedirectory = '" + ProgramUtils.Encode(FileDirectory) + + "', imagedirectory = '" + ProgramUtils.Encode(ImageDirectory) + + "', validextensions = '" + ProgramUtils.Encode(ValidExtensions) + + "', importvalidimagesonly = '" + ProgramUtils.BooleanToStr(importValidImagesOnly) + + "', iposition = " + Position + + ", enabled = '" + ProgramUtils.BooleanToStr(Enabled) + + "', fatherID = '" + FatherID + + "', enableGUIRefresh = '" + ProgramUtils.BooleanToStr(EnableGUIRefresh) + + "', GUIRefreshPossible = '" + ProgramUtils.BooleanToStr(GUIRefreshPossible) + + "', pincode = '" + Pincode + + "', contentID = '" + ContentID + + "', systemDefault = '" + ProgramUtils.Encode(SystemDefault) + + "', WaitForExit = '" + ProgramUtils.BooleanToStr(WaitForExit) + + "', preLaunch = '" + ProgramUtils.Encode(PreLaunch) + + "', postLaunch = '" + ProgramUtils.Encode(PostLaunch) + + "' where appID = " + AppID); + sqlDB.Execute(sql); } + catch (SQLiteException ex) + { + Log.Info("programdatabase exception err:{0} stack:{1}", ex.Message, ex.StackTrace); + Log.Info("sql \n{0}", sql); + } } public void Delete() { - if ((AppID >= 0) && (sqlDB != null)) + if (sqlDB == null) return; + if (AppID == -1) return; + + try { - try - { - DeleteFiles(); - DeleteFileLinks(); - sqlDB.Execute(String.Format("delete from tblApplicationItem where appid = {0}", AppID)); - } - catch (SQLiteException ex) - { - Log.Info("programdatabase exception err:{0} stack:{1}", ex.Message, ex.StackTrace); - } + DeleteFiles(); + DeleteFileLinks(); + sqlDB.Execute(String.Format("delete from tblApplicationItem where appid = {0}", AppID)); } + catch (SQLiteException ex) + { + Log.Info("programdatabase exception err:{0} stack:{1}", ex.Message, ex.StackTrace); + } } protected void DeleteFiles() { - if ((AppID >= 0) && (sqlDB != null)) + if (sqlDB == null) return; + if (AppID == -1) return; + + try { - try - { - sqlDB.Execute(String.Format("delete from tblFileItem where appid = {0}", AppID)); - } - catch (SQLiteException ex) - { - Log.Info("programdatabase exception err:{0} stack:{1}", ex.Message, ex.StackTrace); - } + sqlDB.Execute(String.Format("delete from tblFileItem where appid = {0}", AppID)); } + catch (SQLiteException ex) + { + Log.Info("programdatabase exception err:{0} stack:{1}", ex.Message, ex.StackTrace); + } } protected void DeleteFileLinks() { - if ((AppID >= 0) && (sqlDB != null)) + if (sqlDB == null) return; + if (AppID == -1) return; + + try { - try - { - sqlDB.Execute(String.Format("delete from tblFilterItem where appid = {0} or grouperappid = {0}", AppID)); - } - catch (SQLiteException ex) - { - Log.Info("programdatabase exception err:{0} stack:{1}", ex.Message, ex.StackTrace); - } + sqlDB.Execute(String.Format("delete from tblFilterItem where appid = {0} or grouperappid = {0}", AppID)); } + catch (SQLiteException ex) + { + Log.Info("programdatabase exception err:{0} stack:{1}", ex.Message, ex.StackTrace); + } } public virtual void LoadFiles() { - if (sqlDB != null) - { - // load Files and fill Files-List<string> here! - if (fileList == null) - { - fileList = new FileItemList(sqlDB); - } - else - { - fileList.Clear(); - } - lastFilepath = ""; - fileList.Load(AppID, ""); - filesAreLoaded = true; - } + if (sqlDB == null) return; + + // load Files and fill Files-List<string> here! + if (fileList == null) + fileList = new FileItemList(sqlDB); + else + fileList.Clear(); + + lastFilepath = ""; + fileList.Load(AppID, ""); + filesAreLoaded = true; } public virtual void LoadFileLinks() { - if (sqlDB != null) - { - if (fileLinks == null) - { - fileLinks = new FilelinkItemList(sqlDB); - } - else - { - fileLinks.Clear(); - } - lastFilepath = ""; - fileLinks.Load(AppID, ""); - linksAreLoaded = true; - } + if (sqlDB == null) return; + + if (fileLinks == null) + fileLinks = new FilelinkItemList(sqlDB); + else + fileLinks.Clear(); + + lastFilepath = ""; + fileLinks.Load(AppID, ""); + linksAreLoaded = true; } public void InsertOrUpdateSettings() { if (appID == -1) - { Insert(); - } else - { Update(); - } } #endregion This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |