This commit is contained in:
2022-07-08 23:37:11 +00:00
parent cd1e43081f
commit 1cd70a5be8
6 changed files with 398 additions and 368 deletions

View File

@@ -16,7 +16,7 @@ namespace AyaNovaQBI
public MainForm()
{
InitializeComponent();
InitDataSet();
//InitDataSet();
Icon = AyaNovaQBI.Properties.Resources.logo;
}
@@ -45,7 +45,7 @@ namespace AyaNovaQBI
}
Text = "AyaNova QBI - " + util.QCompanyName;
InitializeGrid();
//See if there are *any* data mappings, if not then we will prompt the user to start that process
if (util.QBIntegration.Items.Count == 0)
{
@@ -60,7 +60,7 @@ namespace AyaNovaQBI
}
//Display billable workorders
InitInvoices();
await InitInvoices();
grid.Visible = true;
menuStrip1.Enabled = true;
@@ -128,7 +128,7 @@ namespace AyaNovaQBI
await util.ValidateSettings(true);
}
private void mapAndImportToolStripMenuItem_Click(object sender, EventArgs e)
private async Task mapAndImportToolStripMenuItem_Click(object sender, EventArgs e)
{
Map m = new Map();
if (m.ShowDialog() == DialogResult.Abort)
@@ -136,7 +136,7 @@ namespace AyaNovaQBI
else
{
m.Dispose();
InitInvoices();
await InitInvoices();
}
}
@@ -175,159 +175,159 @@ namespace AyaNovaQBI
#region DataSet stuff
private DataSet dsInvoices;
private DataTable Invoices;
private DataColumn Client;
private DataColumn WorkingID;
private DataColumn Linked;
private DataColumn ClientID;
private DataTable Workorders;
private DataColumn InvoiceWorkingID;
private DataColumn WorkorderID;
private DataColumn wostatus;
private DataColumn ServiceNumber;
private DataColumn ServiceDate;
private DataColumn Project;
private DataColumn StatusARGB;
private DataColumn dataColumn1;
private void InitDataSet()
{
dsInvoices = new DataSet();
Invoices = new DataTable();
Client = new DataColumn();
WorkingID = new DataColumn();
Linked = new DataColumn();
ClientID = new DataColumn();
Workorders = new DataTable();
InvoiceWorkingID = new DataColumn();
WorkorderID = new DataColumn();
wostatus = new DataColumn();
ServiceNumber = new DataColumn();
ServiceDate = new DataColumn();
Project = new DataColumn();
StatusARGB = new DataColumn();
dataColumn1 = new DataColumn();
//
// dsInvoices
//
dsInvoices.DataSetName = "Invoices";
dsInvoices.Locale = new System.Globalization.CultureInfo("en-US");
dsInvoices.Relations.AddRange(new DataRelation[] {
new DataRelation("Relation1", "Invoices", "Workorders", new string[] {
"WorkingID"}, new string[] {
"InvoiceWorkingID"}, false)});
dsInvoices.Tables.AddRange(new DataTable[] {
Invoices,
Workorders});
//
// Invoices
//
Invoices.Columns.AddRange(new DataColumn[] {
Client,
WorkingID,
Linked,
ClientID});
Invoices.Constraints.AddRange(new Constraint[] {
new UniqueConstraint("Constraint1", new string[] {
"WorkingID"}, true)});
Invoices.PrimaryKey = new DataColumn[] {
WorkingID};
Invoices.TableName = "Invoices";
//
// Client
//
Client.ColumnName = "Client";
//
// WorkingID
//
WorkingID.AllowDBNull = false;
WorkingID.AutoIncrement = true;
WorkingID.Caption = "WorkingID";
WorkingID.ColumnName = "WorkingID";
WorkingID.DataType = typeof(int);
WorkingID.ReadOnly = true;
//
// Linked
//
Linked.Caption = "Linked";
Linked.ColumnName = "Linked";
Linked.DataType = typeof(bool);
Linked.DefaultValue = false;
//
// ClientID
//
ClientID.Caption = "ClientID";
ClientID.ColumnName = "ClientID";
ClientID.DataType = typeof(System.Guid);
//
// Workorders
//
Workorders.Columns.AddRange(new DataColumn[] {
InvoiceWorkingID,
WorkorderID,
wostatus,
ServiceNumber,
ServiceDate,
Project,
StatusARGB,
dataColumn1});
Workorders.Constraints.AddRange(new Constraint[] {
new UniqueConstraint("Constraint1", new string[] {
"WorkorderID"}, true),
new ForeignKeyConstraint("Relation1", "Invoices", new string[] {
"WorkingID"}, new string[] {
"InvoiceWorkingID"}, AcceptRejectRule.None, Rule.None, Rule.None)});
Workorders.PrimaryKey = new DataColumn[] {
WorkorderID};
Workorders.TableName = "Workorders";
//
// InvoiceWorkingID
//
InvoiceWorkingID.Caption = "InvoiceWorkingID";
InvoiceWorkingID.ColumnName = "InvoiceWorkingID";
InvoiceWorkingID.DataType = typeof(int);
//
// WorkorderID
//
WorkorderID.AllowDBNull = false;
WorkorderID.Caption = "WorkorderID";
WorkorderID.ColumnName = "WorkorderID";
WorkorderID.DataType = typeof(System.Guid);
//
// wostatus
//
wostatus.Caption = "Status";
wostatus.ColumnName = "Status";
//
// ServiceNumber
//
ServiceNumber.Caption = "ServiceNumber";
ServiceNumber.ColumnName = "ServiceNumber";
ServiceNumber.DataType = typeof(int);
//
// ServiceDate
//
ServiceDate.Caption = "ServiceDate";
ServiceDate.ColumnName = "ServiceDate";
ServiceDate.DataType = typeof(object);
//
// Project
//
Project.Caption = "Project";
Project.ColumnName = "Project";
//
// StatusARGB
//
StatusARGB.Caption = "StatusARGB";
StatusARGB.ColumnName = "StatusARGB";
StatusARGB.DataType = typeof(int);
//
// dataColumn1
//
dataColumn1.ColumnName = "Linked";
dataColumn1.DataType = typeof(bool);
dataColumn1.DefaultValue = false;
}
//private DataSet dsInvoices;
//private DataTable Invoices;
//private DataColumn Client;
//private DataColumn WorkingID;
//private DataColumn Linked;
//private DataColumn ClientID;
//private DataTable Workorders;
//private DataColumn InvoiceWorkingID;
//private DataColumn WorkorderID;
//private DataColumn wostatus;
//private DataColumn ServiceNumber;
//private DataColumn ServiceDate;
//private DataColumn Project;
//private DataColumn StatusARGB;
//private DataColumn dataColumn1;
//private void InitDataSet()
//{
// dsInvoices = new DataSet();
// Invoices = new DataTable();
// Client = new DataColumn();
// WorkingID = new DataColumn();
// Linked = new DataColumn();
// ClientID = new DataColumn();
// Workorders = new DataTable();
// InvoiceWorkingID = new DataColumn();
// WorkorderID = new DataColumn();
// wostatus = new DataColumn();
// ServiceNumber = new DataColumn();
// ServiceDate = new DataColumn();
// Project = new DataColumn();
// StatusARGB = new DataColumn();
// dataColumn1 = new DataColumn();
// //
// // dsInvoices
// //
// dsInvoices.DataSetName = "Invoices";
// dsInvoices.Locale = new System.Globalization.CultureInfo("en-US");
// dsInvoices.Relations.AddRange(new DataRelation[] {
// new DataRelation("Relation1", "Invoices", "Workorders", new string[] {
// "WorkingID"}, new string[] {
// "InvoiceWorkingID"}, false)});
// dsInvoices.Tables.AddRange(new DataTable[] {
// Invoices,
// Workorders});
// //
// // Invoices
// //
// Invoices.Columns.AddRange(new DataColumn[] {
// Client,
// WorkingID,
// Linked,
// ClientID});
// Invoices.Constraints.AddRange(new Constraint[] {
// new UniqueConstraint("Constraint1", new string[] {
// "WorkingID"}, true)});
// Invoices.PrimaryKey = new DataColumn[] {
//WorkingID};
// Invoices.TableName = "Invoices";
// //
// // Client
// //
// Client.ColumnName = "Client";
// //
// // WorkingID
// //
// WorkingID.AllowDBNull = false;
// WorkingID.AutoIncrement = true;
// WorkingID.Caption = "WorkingID";
// WorkingID.ColumnName = "WorkingID";
// WorkingID.DataType = typeof(int);
// WorkingID.ReadOnly = true;
// //
// // Linked
// //
// Linked.Caption = "Linked";
// Linked.ColumnName = "Linked";
// Linked.DataType = typeof(bool);
// Linked.DefaultValue = false;
// //
// // ClientID
// //
// ClientID.Caption = "ClientID";
// ClientID.ColumnName = "ClientID";
// ClientID.DataType = typeof(System.Guid);
// //
// // Workorders
// //
// Workorders.Columns.AddRange(new DataColumn[] {
// InvoiceWorkingID,
// WorkorderID,
// wostatus,
// ServiceNumber,
// ServiceDate,
// Project,
// StatusARGB,
// dataColumn1});
// Workorders.Constraints.AddRange(new Constraint[] {
// new UniqueConstraint("Constraint1", new string[] {
// "WorkorderID"}, true),
// new ForeignKeyConstraint("Relation1", "Invoices", new string[] {
// "WorkingID"}, new string[] {
// "InvoiceWorkingID"}, AcceptRejectRule.None, Rule.None, Rule.None)});
// Workorders.PrimaryKey = new DataColumn[] {
//WorkorderID};
// Workorders.TableName = "Workorders";
// //
// // InvoiceWorkingID
// //
// InvoiceWorkingID.Caption = "InvoiceWorkingID";
// InvoiceWorkingID.ColumnName = "InvoiceWorkingID";
// InvoiceWorkingID.DataType = typeof(int);
// //
// // WorkorderID
// //
// WorkorderID.AllowDBNull = false;
// WorkorderID.Caption = "WorkorderID";
// WorkorderID.ColumnName = "WorkorderID";
// WorkorderID.DataType = typeof(System.Guid);
// //
// // wostatus
// //
// wostatus.Caption = "Status";
// wostatus.ColumnName = "Status";
// //
// // ServiceNumber
// //
// ServiceNumber.Caption = "ServiceNumber";
// ServiceNumber.ColumnName = "ServiceNumber";
// ServiceNumber.DataType = typeof(int);
// //
// // ServiceDate
// //
// ServiceDate.Caption = "ServiceDate";
// ServiceDate.ColumnName = "ServiceDate";
// ServiceDate.DataType = typeof(object);
// //
// // Project
// //
// Project.Caption = "Project";
// Project.ColumnName = "Project";
// //
// // StatusARGB
// //
// StatusARGB.Caption = "StatusARGB";
// StatusARGB.ColumnName = "StatusARGB";
// StatusARGB.DataType = typeof(int);
// //
// // dataColumn1
// //
// dataColumn1.ColumnName = "Linked";
// dataColumn1.DataType = typeof(bool);
// dataColumn1.DefaultValue = false;
//}
#endregion dataset stuff
@@ -390,7 +390,7 @@ namespace AyaNovaQBI
*/
private List<WorkOrderAccountingListItem> _wolist = null;
private List<WorkOrderGridListItem> _WorkOrderGridListItems = new List<WorkOrderGridListItem>();
private List<util.MisMatch> _MisMatches = new List<util.MisMatch>();
private List<long> _PartPriceOverrides = new List<long>();
/// <summary>
@@ -407,151 +407,173 @@ namespace AyaNovaQBI
try
{
_MisMatches.Clear();
dsInvoices.Clear();
//[HttpGet("accounting-list-billable/{workOrderStatusId}")]
var r = await util.GetAsync($"accounting-list-billable/{util.QDat.PreWOStatus}");
_wolist = r.ObjectResponse["data"].ToObject<List<WorkOrderAccountingListItem>>();
DataTable dtInvoice = dsInvoices.Tables["Invoices"];
DataTable dtWorkorder = dsInvoices.Tables["Workorders"];
foreach (WorkorderServiceBillableList.WorkorderServiceBillableListInfo i in _wolist)
{
bool bLinked = Util.ScanLinksOK(i.ID, _MisMatches, _PartPriceOverrides);
DataRow dri = InvoiceRowForClientID(i.ClientID);
w.Step = "WO: " + i.ServiceNumber;
if (dri == null)
_WorkOrderGridListItems = r.ObjectResponse["data"]
.ToObject<List<WorkOrderAccountingListItem>>()
.Select(z => new WorkOrderGridListItem
{
dri = dtInvoice.NewRow();
dri["Client"] = i.Client;
dri["ClientID"] = i.ClientID;
dtInvoice.Rows.Add(dri);
}
//If any one single workorder is linked
//then the invoice is flagged as linked because
//you can invoice out anything under it that is linked and the
//not linked items simply won't invoice
if (bLinked)
dri["Linked"] = true;
DataRow drw = dtWorkorder.NewRow();
drw["InvoiceWorkingID"] = (int)dri["WorkingID"];
drw["WorkorderID"] = i.ID;
drw["Status"] = i.Status;
drw["ServiceNumber"] = i.ServiceNumber;
drw["ServiceDate"] = i.ServiceDate;
drw["Project"] = i.Project;
drw["StatusARGB"] = i.StatusARGB;
drw["Linked"] = bLinked;
dtWorkorder.Rows.Add(drw);
Color = z.Color,
CustomerId = z.CustomerId,
CustomerName = z.CustomerName,
Id = z.Id,
ProjectName = z.ProjectName,
Serial = z.Serial,
ServiceDate = z.ServiceDate,
WorkorderStatusName = z.WorkorderStatusName
})
.ToList();
foreach (WorkOrderGridListItem i in _WorkOrderGridListItems)
{
w.Step = "WO: " + i.Serial;
i.Linked = util.ScanLinksOK(i.Id, _MisMatches, _PartPriceOverrides);
//DataRow dri = InvoiceRowForClientID(i.ClientID);
//if (dri == null)
//{
// dri = dtInvoice.NewRow();
// dri["Client"] = i.Client;
// dri["ClientID"] = i.ClientID;
// dtInvoice.Rows.Add(dri);
}
grid.DisplayLayout.Rows.CollapseAll(false);
foreach (UltraGridRow r in grid.Rows)
{
foreach (UltraGridRow rr in r.ChildBands[0].Rows)
{
if ((bool)rr.Cells["Linked"].Value == false)
r.Expanded = true;
}
//If any one single workorder is linked
//then the invoice is flagged as linked because
//you can invoice out anything under it that is linked and the
//not linked items simply won't invoice
//if (bLinked)
// dri["Linked"] = true;
//DataRow drw = dtWorkorder.NewRow();
//drw["InvoiceWorkingID"] = (int)dri["WorkingID"];
//drw["WorkorderID"] = i.ID;
//drw["Status"] = i.Status;
//drw["ServiceNumber"] = i.ServiceNumber;
//drw["ServiceDate"] = i.ServiceDate;
//drw["Project"] = i.Project;
//drw["StatusARGB"] = i.StatusARGB;
//drw["Linked"] = bLinked;
//dtWorkorder.Rows.Add(drw);
// grid.DisplayLayout.Rows.CollapseAll(false);
//foreach (UltraGridRow r in grid.Rows)
//{
// foreach (UltraGridRow rr in r.ChildBands[0].Rows)
// {
// if ((bool)rr.Cells["Linked"].Value == false)
// r.Expanded = true;
// }
//}
//grid.EndUpdate();
}
grid.EndUpdate();
}
finally
{
w.Close();
}
SetState();
await SetState();
}
/// <summary>
/// Helper for grouping workorders by client
/// </summary>
/// <param name="ClientID"></param>
/// <returns>null if not found else datarow containing invoice for client</returns>
private DataRow InvoiceRowForClientID(Guid ClientID)
{
foreach (DataRow r in dsInvoices.Tables["Invoices"].Rows)
{
if ((Guid)r["ClientID"] == ClientID)
{
return r;
}
}
return null;
}
///// <summary>
///// Helper for grouping workorders by client
///// </summary>
///// <param name="ClientID"></param>
///// <returns>null if not found else datarow containing invoice for client</returns>
//private DataRow InvoiceRowForClientID(Guid ClientID)
//{
// foreach (DataRow r in dsInvoices.Tables["Invoices"].Rows)
// {
// if ((Guid)r["ClientID"] == ClientID)
// {
// return r;
// }
// }
// return null;
//}
private void InitializeGrid()
{
grid.DataSource = dsInvoices;
string currentAssemblyDirectoryName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
grid.DataSource = _WorkOrderGridListItems;
//grid.Columns["WorkingID"].Visible = false;
//grid.Columns["ClientID"].Visible = false;
//grid.Columns["Linked"].Visible = false;
//grid.Columns["Client"].Visible = false;
//grid.Columns["InvoiceWorkingID"].Visible = false;
//grid.Columns["WorkorderID"].Visible = false;
//grid.Columns["StatusARGB"].Visible = false;
//grid.Columns["WorkingID"].Visible = false;
//string currentAssemblyDirectoryName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
//Load the grid layout from file
if (System.IO.File.Exists(currentAssemblyDirectoryName + "\\MainGrid.lyt"))
grid.DisplayLayout.Load(currentAssemblyDirectoryName + "\\MainGrid.lyt");
grid.DisplayLayout.Bands[0].Columns["WorkingID"].Hidden = true;
grid.DisplayLayout.Bands[0].Columns["ClientID"].Hidden = true;
grid.DisplayLayout.Bands[0].Columns["Linked"].Hidden = true;
grid.DisplayLayout.Bands[0].Columns["Client"].Header.Caption = "Invoice";
//if (System.IO.File.Exists(currentAssemblyDirectoryName + "\\MainGrid.lyt"))
// grid.DisplayLayout.Load(currentAssemblyDirectoryName + "\\MainGrid.lyt");
//grid.DisplayLayout.Bands[0].Columns["WorkingID"].Hidden = true;
//grid.DisplayLayout.Bands[0].Columns["ClientID"].Hidden = true;
//grid.DisplayLayout.Bands[0].Columns["Linked"].Hidden = true;
//grid.DisplayLayout.Bands[0].Columns["Client"].Header.Caption = "Invoice";
grid.DisplayLayout.Bands[1].Columns["InvoiceWorkingID"].Hidden = true;
grid.DisplayLayout.Bands[1].Columns["WorkorderID"].Hidden = true;
grid.DisplayLayout.Bands[1].Columns["StatusARGB"].Hidden = true;
grid.DisplayLayout.Bands[1].Columns["Linked"].Hidden = true;
//grid.DisplayLayout.Bands[1].Columns["InvoiceWorkingID"].Hidden = true;
//grid.DisplayLayout.Bands[1].Columns["WorkorderID"].Hidden = true;
//grid.DisplayLayout.Bands[1].Columns["StatusARGB"].Hidden = true;
//grid.DisplayLayout.Bands[1].Columns["Linked"].Hidden = true;
}
private void grid_InitializeRow(object sender, Infragistics.Win.UltraWinGrid.InitializeRowEventArgs e)
{
if (e.Row.Band.Index == 0)
{
//Prepare invoice row
if ((bool)e.Row.Cells["Linked"].Value == true)
{
e.Row.Cells["Client"].Appearance.Image = Util.AyaImage("OK16");//Util.Image("OK16.png");
}
else
{
e.Row.Cells["Client"].Appearance.Image = Util.AyaImage("Cancel16");//Util.Image("Cancel16.png");
}
}
else
{
//prepare workorder row
//private void grid_InitializeRow(object sender, Infragistics.Win.UltraWinGrid.InitializeRowEventArgs e)
//{
// if (e.Row.Band.Index == 0)
// {
// //Prepare invoice row
// if ((bool)e.Row.Cells["Linked"].Value == true)
// {
// e.Row.Cells["Client"].Appearance.Image = Util.AyaImage("OK16");//Util.Image("OK16.png");
// }
// else
// {
// e.Row.Cells["Client"].Appearance.Image = Util.AyaImage("Cancel16");//Util.Image("Cancel16.png");
// }
// }
// else
// {
// //prepare workorder row
//if backcolor==0 that means no color was set
int nColor = (int)e.Row.Cells["StatusARGB"].Value;
if (nColor != 0)
{
e.Row.Cells["Status"].Appearance.BackColor = Color.FromArgb(nColor);
e.Row.Cells["Status"].Appearance.ForeColor = Util.InvertColor(Color.FromArgb(nColor));
// //if backcolor==0 that means no color was set
// int nColor = (int)e.Row.Cells["StatusARGB"].Value;
// if (nColor != 0)
// {
// e.Row.Cells["Status"].Appearance.BackColor = Color.FromArgb(nColor);
// e.Row.Cells["Status"].Appearance.ForeColor = Util.InvertColor(Color.FromArgb(nColor));
}
// }
//flag whether billable (linked) or not
if ((bool)e.Row.Cells["Linked"].Value == true)
{
e.Row.Cells["ServiceNumber"].Appearance.Image = Util.AyaImage("OK16");
}
else
{
e.Row.Cells["ServiceNumber"].Appearance.Image = Util.AyaImage("Cancel16");
}
}
// //flag whether billable (linked) or not
// if ((bool)e.Row.Cells["Linked"].Value == true)
// {
// e.Row.Cells["ServiceNumber"].Appearance.Image = Util.AyaImage("OK16");
// }
// else
// {
// e.Row.Cells["ServiceNumber"].Appearance.Image = Util.AyaImage("Cancel16");
// }
// }
}
//}
#endregion