private static void WriteConfigFile() { string[] dati = new string[6]; try { if (!Directory.Exists(Commons.PathConfig)) { Directory.CreateDirectory(Commons.PathConfig); } if (!Directory.Exists(Commons.PathLogs)) { Directory.CreateDirectory(Commons.PathLogs); } if (!Directory.Exists(Commons.PathImages)) { Directory.CreateDirectory(Commons.PathImages); } if (!Directory.Exists(Commons.PathStartLinks)) { Directory.CreateDirectory(Commons.PathStartLinks); } if (!Directory.Exists(Commons.PathDatabase)) { Directory.CreateDirectory(Commons.PathDatabase); } if (!Directory.Exists(Commons.PathDocuments)) { if (Commons.PathDocuments != "") { Directory.CreateDirectory(Commons.PathDocuments); } else { Commons.PathDocuments = "."; } } dati[0] = Commons.FileDatabase; dati[1] = Commons.PathImages; dati[2] = Commons.PathStartLinks; dati[3] = Commons.PathDatabase; dati[4] = Commons.PathDocuments; dati[5] = CommonsWinForms.SaveBackupWhenExiting.ToString(); #if DEBUG TextFile.ArrayToFile(Commons.PathAndFileConfig + "_DEBUG", dati, false); #else TextFile.ArrayToFile(Commons.PathAndFileConfig, dati, false); #endif MessageBox.Show("File di configurazione salvato in " + Commons.PathAndFileConfig); } catch (Exception e) { string err = @"[Error in program's directories] \r\n" + e.Message; Commons.ErrorLog(err); throw new FileNotFoundException(err); //return; } }
internal DataLayer(string PathAndFile) { if (!System.IO.File.Exists(PathAndFile)) { string err = @"[" + PathAndFile + " not in the current nor in the dev directory]"; Commons.ErrorLog(err); throw new System.IO.FileNotFoundException(err); } dbName = PathAndFile; }
/// <summary> /// Constructor of DataLayer class that uses the default database of the program /// Assumes that the file exists. /// </summary> internal DataLayer() { // ???? is next if() useful ???? if (!System.IO.File.Exists(Commons.PathAndFileDatabase)) { string err = @"[" + Commons.PathAndFileDatabase + " not in the current nor in the dev directory]"; Commons.ErrorLog(err); throw new System.IO.FileNotFoundException(err); } dbName = Commons.PathAndFileDatabase; }
internal int?SaveStartLink(int?IdStartLink, int?IdClass, string SchoolYear, string StartLink, string Desc) { DbCommand cmd = null; try { using (DbConnection conn = Connect()) { cmd = conn.CreateCommand(); if (IdStartLink != null && IdStartLink != 0) { cmd.CommandText = "UPDATE Classes_StartLinks" + " SET" + //" idStartLink=" + IdStartLink + " idClass=" + IdClass + "" + ",startLink=" + SqlString(StartLink) + "" + ",desc=" + SqlString(Desc) + "" + " WHERE idStartLink=" + IdStartLink + ";"; } else { IdStartLink = NextKey("Classes_StartLinks", "IdStartLink"); cmd.CommandText = "INSERT INTO Classes_StartLinks" + " (idStartLink,idClass,startLink,desc)" + " VALUES " + "(" + IdStartLink + "," + IdClass + "," + SqlString(StartLink) + "" + "," + SqlString(Desc) + "" + ");"; } cmd.ExecuteNonQuery(); cmd.Dispose(); } } catch (Exception ex) { Commons.ErrorLog("DbLayer.SaveStartLink: " + ex.Message); IdStartLink = null; cmd.Dispose(); } return(IdStartLink); }
internal void RemoveImageFromLesson(Lesson Lesson, Image Image, bool AlsoEraseFile) { if (AlsoEraseFile) { try { // !!!! TODO: FIX: this gives error every time, so currently the program doesn't erase the pictures !!!! File.Delete(Commons.PathImages + "\\" + Image.RelativePathAndFilename); } catch (Exception ex) { string err = "DbLayer|RemoveImageFromLesson|" + Commons.PathImages + "\\" + Image.RelativePathAndFilename + ".\r\n" + ex.Message + ex.StackTrace; Commons.ErrorLog(err); Console.Beep(); //////throw new Exception(err); } } dl.RemoveImageFromLesson(Lesson, Image, AlsoEraseFile); }
internal DbConnection Connect() { DbConnection connection; try { connection = new SQLiteConnection("Data Source=" + dbName + ";version=3;new=False;datetimeformat=CurrentCulture"); connection.Open(); } catch (Exception ex) { #if DEBUG //Get call stack StackTrace stackTrace = new StackTrace(); //Log calling method name Commons.ErrorLog("Connect Method in: " + stackTrace.GetFrame(1).GetMethod().Name); #endif Commons.ErrorLog("Error connecting to the database: " + ex.Message + "\r\nFile SQLIte>: " + dbName + " " + "\n"); connection = null; } return(connection); }
internal void DeleteStartLink(Nullable <int> IdStartLink) { DbCommand cmd = null; try { using (DbConnection conn = Connect()) { cmd = conn.CreateCommand(); cmd.CommandText = "DELETE FROM Classes_StartLinks" + " WHERE idStartLink=" + IdStartLink + ";"; cmd.ExecuteNonQuery(); cmd.Dispose(); } } catch (Exception ex) { Commons.ErrorLog("DbLayer.SaveStartLink: " + ex.Message); IdStartLink = null; cmd.Dispose(); } }
private void WriteConfigFile() { string[] dati = new string[6]; try { if (!Directory.Exists(Commons.PathConfig)) { Directory.CreateDirectory(Commons.PathConfig); } if (!Directory.Exists(Commons.PathLogs)) { Directory.CreateDirectory(Commons.PathLogs); } Commons.PathImages = dati[1] = TxtPathImages.Text; if (!Directory.Exists(Commons.PathImages)) { Directory.CreateDirectory(Commons.PathImages); } // path of the startlinks (PathStartLinks) is not longer used, substituted by PathRestrictedApp Commons.PathStartLinks = dati[2] = TxtPathStartLinks.Text; if (!Directory.Exists(Commons.PathStartLinks)) { Directory.CreateDirectory(Commons.PathStartLinks); } Commons.PathDatabase = dati[3] = TxtPathDatabase.Text; if (!Directory.Exists(Commons.PathDatabase)) { Directory.CreateDirectory(Commons.PathDatabase); } Commons.PathDocuments = dati[4] = TxtPathDocuments.Text; if (!Directory.Exists(Commons.PathDocuments)) { if (Commons.PathDocuments != "") { Directory.CreateDirectory(Commons.PathDocuments); } else { Commons.PathDocuments = "."; } } Commons.FileDatabase = dati[0] = TxtFileDatabase.Text; Commons.SaveBackupWhenExiting = chkSaveBackup.Checked; dati[5] = Commons.SaveBackupWhenExiting.ToString(); Commons.PathAndFileDatabase = Commons.PathDatabase + "\\" + Commons.FileDatabase; if (!File.Exists(Commons.PathAndFileDatabase)) { File.Copy(".\\SchoolGrades.sqlite", Commons.PathAndFileDatabase); } #if DEBUG TextFile.ArrayToFile(Commons.PathAndFileConfig + "_DEBUG", dati, false); #else TextFile.ArrayToFile(Commons.PathAndFileConfig, dati, false); #endif MessageBox.Show("File di configurazione salvato in " + Commons.PathAndFileConfig); } catch (Exception e) { Commons.ErrorLog(e.Message, false); return; //throw new FileNotFoundException(@"[Error in program's directories] \r\n" + e.Message); } //Application.Exit(); NewDatabaseFile = true; this.Close(); }