Skip to content

Commit

Permalink
v.0.51.02 automatic save of configuration file if a demo database is …
Browse files Browse the repository at this point in the history
…in .\Data folder.
  • Loading branch information
gamondue committed Apr 1, 2021
1 parent ddebdea commit a70da08
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 16 deletions.
21 changes: 14 additions & 7 deletions SchoolGrades/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,19 @@ static void Main()
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);

// read configuration file or run configuration form
Commons.ReadConfigFile();
if (!System.IO.File.Exists(Commons.PathAndFileDatabase))
// read configuration file or run configuration
if (!Commons.ReadConfigFile())
{
// if demo database exists, save the configuration program with demo file
if (Commons.PathAndFileDatabase.Contains("DEMO") && !System.IO.File.Exists(Commons.PathAndFileDatabase))
// config file is unexistent or broken
if (Commons.PathAndFileDatabase.Contains("DEMO") && File.Exists(Commons.PathAndFileDatabase))
{
WriteConfigFile(); // !!!! TODO move this method to general functions of the program !!!!
// if demo database exists, save the configuration program with demo file
WriteConfigFile();
}
else
{
MessageBox.Show("Configurazione del programma.\r\nSistemare le cartelle con il percorso dei file (in particalore la cartella che contiene il database), " +
// we don't want the demo file or it doesn't exist. Let's ask the user
MessageBox.Show("Configurazione del programma.\r\nSistemare le cartelle con il percorso dei file (in particolare la cartella che contiene il database), " +
"poi scegliere il file di dati .sqlite e premere 'Salva configurazione'", "SchoolGrades", MessageBoxButtons.OK, MessageBoxIcon.Information);
FrmSetup f = new FrmSetup();
f.ShowDialog();
Expand All @@ -42,6 +43,12 @@ static void Main()
}
}
}
else
{
// config file has been read
// di nothing
}

//Application.Run(new frmLogin());
Application.Run(new frmMain());
}
Expand Down
Binary file modified SchoolGrades/bin/Release/netcoreapp3.1/SchoolGrades.dll
Binary file not shown.
8 changes: 4 additions & 4 deletions SchoolGrades/frmMain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,10 @@ public Student CurrentStudent
public frmMain()
{
InitializeComponent();


db = new DbAndBusiness();
bl = new BusinessLayer.BusinessLayer();

this.Text += " v. " + version;

// first default year in the "years" combo
Expand Down Expand Up @@ -112,9 +115,6 @@ private void frmMain_Load(object sender, EventArgs e)
AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
btnTemporary.Visible = false;
#endif
db = new DbAndBusiness();
bl = new BusinessLayer.BusinessLayer();

school = db.GetSchool(Commons.IdSchool);
if (school == null)
return;
Expand Down
15 changes: 10 additions & 5 deletions SharedItems/Commons.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public static class Commons
public static string FileDatabase = "SchoolGrades_DEMO.sqlite";
//public static string PathDatabase = PathUser + "\\SchoolGrades\\Data";
public static string PathDatabase = PathExe + "\\Data";
public static string PathAndFileDatabase = PathDatabase + FileDatabase; // if will be read with Commons.ReadConfigFile()!
public static string PathAndFileDatabase = PathDatabase + "\\" + FileDatabase; // if will be read with Commons.ReadConfigFile()!

//public static string PathStartLink = PathUser + "\\SchoolGrades\\";
public static string PathStartLinks = PathExe;
Expand Down Expand Up @@ -166,7 +166,7 @@ internal static DateTime NextWeekSameDay(DateTime from, DayOfWeek dayOfWeek)
target += 7;
return from.AddDays(target - start);
}
internal static void ReadConfigFile()
internal static bool ReadConfigFile()
{
string[] dati = null;
try
Expand All @@ -184,20 +184,25 @@ internal static void ReadConfigFile()
Commons.PathDatabase = dati[3];
Commons.PathAndFileDatabase = Commons.PathDatabase + "\\" + Commons.FileDatabase;
Commons.PathDocuments = dati[4];

// we try the next to avoid stopping the program whe a new config file,
// we try the next to avoid stopping the program whem we have a new config file,
// with another field will show up. You have to add some data in.config file.
try
{
Commons.SaveBackupWhenExiting = bool.Parse(dati[5]);
return true;
}
catch
{
return false;
}
catch { }
}
}
catch
{
// if error do nothing. the rest of the code will generate the default data
return false;
}
return false;
}
public static object CloneObject(object o)
{
Expand Down

0 comments on commit a70da08

Please sign in to comment.