Files
ravenqbi/AyaNovaQBI/MainForm.cs
2022-07-07 20:15:36 +00:00

158 lines
5.4 KiB
C#

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace AyaNovaQBI
{
public partial class MainForm : Form
{
public MainForm()
{
InitializeComponent();
this.Icon = AyaNovaQBI.Properties.Resources.logo;
}
async private void MainForm_Load(object sender, EventArgs e)
{
//Initialize
StringBuilder initErrors = new StringBuilder();
if (await util.InitializeQBI(initErrors) == false)
{
if (initErrors.Length > 0)
{
if (util.LOG_AVAILABLE) await util.IntegrationLog(initErrors.ToString());
await Task.Run(() => MessageBox.Show($"AyaNova QBI was unable to start:\r\n{initErrors.ToString()}"));
}
Close();
}
else
{
//Confirm main settings and set any that are missing:
if (await util.ValidateSettings(false) == util.pfstat.Cancel)
{
await util.IntegrationLog("PFC: User settings not completed, user selected cancel");
Close();
}
//check if setup is required
//if (util.QBIntegration.Items.Count == 0)
//{
// MessageBox.Show("STUB: mainform,no maps, no integration data set");
//}
}
Text = "AyaNova QBI - " + util.QCompanyName;
grid.Visible = true;
menuStrip1.Enabled = true;
//MessageBox.Show("DONE / OK");
// grid.DataSource = util.GetInvoiceableItems();
}
private void grid_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
{
if (e.ColumnIndex == grid.Columns["Status"].Index
&& e.Value != null)
{
var isLinked = (bool)grid.Rows[e.RowIndex].Cells["linked"].Value;
if (!isLinked)
{
grid.Rows[e.RowIndex].ErrorText = "Not invoiceable: use \"Invoice\" -> \"Fix problems\" to resolve";
}
else
{
grid.Rows[e.RowIndex].ErrorText = null;
}
}
}
private void exitToolStripMenuItem_Click(object sender, EventArgs e)
{
Close();
}
private void multipleWorkordersPerInvoiceToolStripMenuItem_Click(object sender, EventArgs e)
{
if (grid.SelectedRows.Count < 1)
{
MessageBox.Show("There are no rows selected, select one or more rows to invoice");
return;
}
MessageBox.Show($"STUB: MULTIPLEwoperinvoice {grid.SelectedRows.Count} rows selected");
}
private void oneWorkOrderPerInvoiceToolStripMenuItem_Click(object sender, EventArgs e)
{
if (grid.SelectedRows.Count < 1)
{
MessageBox.Show("There are no rows selected, select one or more rows to invoice");
return;
}
MessageBox.Show($"STUB: onwoperinvoice {grid.SelectedRows.Count} rows selected");
}
private void fixProblemsToolStripMenuItem_Click(object sender, EventArgs e)
{
MessageBox.Show("STUB: FIX PROBLEMS");
}
private void refreshInvoicesToolStripMenuItem_Click(object sender, EventArgs e)
{
MessageBox.Show("STUB: REFRESH INVOICES");
}
private async void preferencesToolStripMenuItem_Click(object sender, EventArgs e)
{
await util.ValidateSettings(true);
//TODO: CODE THIS InitInvoices();
}
private void mapAndImportToolStripMenuItem_Click(object sender, EventArgs e)
{
Map m = new Map();
if (m.ShowDialog() == DialogResult.Abort)
this.Close();
else
{
m.Dispose();
//todo: this.InitInvoices();
}
}
private void aboutToolStripMenuItem_Click(object sender, EventArgs e)
{
Assembly a = Assembly.GetExecutingAssembly();
string sVersion = "AyaNova QBI version " + util.DisplayVersion(a.GetName().Version) + "\r\n";
System.Diagnostics.FileVersionInfo fileVersion = System.Diagnostics.FileVersionInfo.GetVersionInfo(a.Location);
if (fileVersion.FileBuildPart > 0)
sVersion += " (Patch " + fileVersion.FileBuildPart.ToString() + ")\r\n";
sVersion += "Copyright 2000-2022 Ground Zero Tech-Works Inc.\r\n";
MessageBox.Show(sVersion, "About");
}
private void onlineManualToolStripMenuItem_Click(object sender, EventArgs e)
{
util.OpenWebURL("https://ayanova.com/qbi/docs");
}
private async void refreshCachedDataToolStripMenuItem_Click(object sender, EventArgs e)
{
await util.PopulateQBListCache();
await util.PopulateAyaListCache();
}
}
}