feature: welcome screen, toolbar & chore: more docs
This commit is contained in:
@@ -4,13 +4,14 @@ using System.Data;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
using CarManagerV3.Forms;
|
||||
|
||||
namespace CarManagerV3
|
||||
{
|
||||
public partial class MainForm : Form
|
||||
{
|
||||
List<Car> cars = new List<Car>();
|
||||
string filepath = "cars.csv";
|
||||
string filepath = "";
|
||||
|
||||
public MainForm()
|
||||
{
|
||||
@@ -18,14 +19,18 @@ namespace CarManagerV3
|
||||
|
||||
// Open the most recent file if it exists. Otherwise, use default filepath.
|
||||
List<string> recentFiles = SafeManager.GetRecentPaths();
|
||||
if(recentFiles.Count > 0)
|
||||
if (recentFiles.Count > 0)
|
||||
{
|
||||
filepath = recentFiles[0];
|
||||
}
|
||||
else
|
||||
{
|
||||
openWelcomeScreen();
|
||||
}
|
||||
|
||||
SafeManager.InitializeFile(filepath);
|
||||
StateManager.setFilePath(filepath);
|
||||
try
|
||||
try
|
||||
{
|
||||
List<Car> _cars = SafeManager.ReadCars(filepath);
|
||||
cars = _cars;
|
||||
@@ -41,11 +46,44 @@ namespace CarManagerV3
|
||||
|
||||
}
|
||||
|
||||
public void openWelcomeScreen()
|
||||
{
|
||||
Welcome welcome = new Welcome();
|
||||
// disable main form while welcome screen is open
|
||||
this.Enabled = false;
|
||||
welcome.OpenFileCallback = () =>
|
||||
{
|
||||
showOpenFileDialog();
|
||||
if (filepath != "")
|
||||
{
|
||||
welcome.Close();
|
||||
this.Enabled = true;
|
||||
}
|
||||
};
|
||||
welcome.NewFileCallback = () =>
|
||||
{
|
||||
showSaveAsDialog();
|
||||
if (filepath != "")
|
||||
{
|
||||
welcome.Close();
|
||||
this.Enabled = true;
|
||||
}
|
||||
};
|
||||
|
||||
welcome.ShowDialog();
|
||||
|
||||
}
|
||||
|
||||
public void showOpenFileDialog()
|
||||
{
|
||||
openToolStripMenuItem.PerformClick();
|
||||
}
|
||||
|
||||
|
||||
public void showSaveAsDialog()
|
||||
{
|
||||
saveAsToolStripMenuItem.PerformClick();
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Refreshes the cars displayed in the flow layout panel.
|
||||
@@ -264,12 +302,12 @@ namespace CarManagerV3
|
||||
try
|
||||
{
|
||||
List<Car> importedCars = SafeManager.ReadCars(dlgOpen.FileName);
|
||||
if(importedCars.Count == 0)
|
||||
if (importedCars.Count == 0)
|
||||
{
|
||||
throw new Exception("File doesn't contain valid Cars.");
|
||||
}
|
||||
filepath = dlgOpen.FileName;
|
||||
|
||||
|
||||
cars = importedCars;
|
||||
StateManager.setFilePath(filepath);
|
||||
// Refresh display
|
||||
@@ -343,7 +381,7 @@ namespace CarManagerV3
|
||||
{
|
||||
Console.WriteLine("Starting merge...");
|
||||
List<Car> importedCars = SafeManager.ReadCars(dlgOpen.FileName);
|
||||
if(importedCars.Count == 0)
|
||||
if (importedCars.Count == 0)
|
||||
{
|
||||
throw new Exception("File doesn't contain valid Cars.");
|
||||
}
|
||||
@@ -398,7 +436,7 @@ namespace CarManagerV3
|
||||
// TODO: Unbind and remove this.
|
||||
private void recentFilesToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -418,7 +456,7 @@ namespace CarManagerV3
|
||||
try
|
||||
{
|
||||
List<Car> importedCars = SafeManager.ReadCars(path);
|
||||
if(importedCars.Count == 0)
|
||||
if (importedCars.Count == 0)
|
||||
{
|
||||
throw new Exception("File doesn't contain valid Cars.");
|
||||
}
|
||||
@@ -429,6 +467,10 @@ namespace CarManagerV3
|
||||
refreshCars(cars);
|
||||
MessageBox.Show("File loaded successfully.", "Load File", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
}
|
||||
catch (LegacyException)
|
||||
{
|
||||
MessageBox.Show("The file you are trying to open is in a legacy format that is no longer supported. Please convert the file to the new format and try again.", "Load Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show("Error loading file: " + ex.Message);
|
||||
@@ -451,5 +493,31 @@ namespace CarManagerV3
|
||||
MessageBox.Show("File does not exist.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private void openWelcomeScreenToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
openWelcomeScreen();
|
||||
}
|
||||
|
||||
private void addCarToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
btnNewCar.PerformClick();
|
||||
}
|
||||
|
||||
private void clearSearchToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
tbxSearch.Text = "";
|
||||
}
|
||||
|
||||
private void exitToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
SafeManager.SaveCars(filepath, cars);
|
||||
Environment.Exit(0);
|
||||
}
|
||||
|
||||
private void clearRecentFilesToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
SafeManager.ClearRecentPaths();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user