Added file picker dialog to import

This commit is contained in:
Bobbie Hodgetts
2020-02-15 10:35:17 +00:00
parent c5e0d8c6d8
commit 2f97a17598

View File

@@ -174,19 +174,40 @@ namespace BealeEngineering.Accounts
private void xeroInvoiceToolStripMenuItem_Click(object sender, EventArgs e) private void xeroInvoiceToolStripMenuItem_Click(object sender, EventArgs e)
{ {
string fileInputPath = string fileInputPath = null;
Environment.GetFolderPath(Environment.SpecialFolder.UserProfile)
+ @"\Dropbox\Beale Engineering Services Ltd\BE Accounts\Xero-Export-Invoices.csv";
string dialogText = "Importing file from location: " + Environment.NewLine + Environment.NewLine + fileInputPath; using (OpenFileDialog openFileDialog = new OpenFileDialog())
{
openFileDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile) + @"\Downloads";
openFileDialog.Filter = ".csv files (*.csv)|*.csv|All files (*.*)|*.*";
openFileDialog.FilterIndex = 1;
openFileDialog.RestoreDirectory = true;
DialogResult dialogResult = MessageBox.Show(dialogText, "Import Xero Invoice flat-file", MessageBoxButtons.OKCancel); if (openFileDialog.ShowDialog() == DialogResult.OK)
if (dialogResult == DialogResult.OK) {
//Get the path of specified file
fileInputPath = openFileDialog.FileName;
}
else
{
return;
}
}
if (fileInputPath != null)
{ {
var importXeroInvoice = new BealeEngineering.Core.Logic.Import.XeroInvoiceFlatFile(sqlConnectionString); var importXeroInvoice = new BealeEngineering.Core.Logic.Import.XeroInvoiceFlatFile(sqlConnectionString);
importXeroInvoice.ByFilePath(fileInputPath); try
{
Cursor.Current = Cursors.WaitCursor;
importXeroInvoice.ByFilePath(fileInputPath);
}
finally
{
Cursor.Current = Cursors.Default;
}
dialogText = "Import complete." + Environment.NewLine + Environment.NewLine string dialogText = "Import complete." + Environment.NewLine + Environment.NewLine
+ importXeroInvoice.InvoicesProcessed + " invoice(s) found" + Environment.NewLine + importXeroInvoice.InvoicesProcessed + " invoice(s) found" + Environment.NewLine
+ importXeroInvoice.InvoicesCreated + " invoice(s) created" + Environment.NewLine + importXeroInvoice.InvoicesCreated + " invoice(s) created" + Environment.NewLine
+ importXeroInvoice.InvoicesUpdated + " invoice(s) updated" + Environment.NewLine + importXeroInvoice.InvoicesUpdated + " invoice(s) updated" + Environment.NewLine