587 lines
21 KiB
C#
587 lines
21 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Data;
|
|
using System.Drawing;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Windows.Forms;
|
|
|
|
namespace AyaNovaQBI
|
|
{
|
|
public partial class Map : Form
|
|
{
|
|
private AyaType _Type = AyaType.Customer;
|
|
private DataTable _aya;
|
|
private DataTable _qb;
|
|
|
|
//private VendorTypes _currentVendorType = 0;
|
|
private viewtypes _currentView = viewtypes.All;
|
|
//private RateTypes _currentRateType = 0;
|
|
//private long _MostLikelyRateUnitChargeDescriptionID = 0;
|
|
|
|
private enum viewtypes
|
|
{
|
|
All,
|
|
Unlinked,
|
|
Linked
|
|
}
|
|
|
|
public Map()
|
|
{
|
|
InitializeComponent();
|
|
this.Icon = AyaNovaQBI.Properties.Resources.logo;
|
|
|
|
_aya = new DataTable("AyaNova");
|
|
_aya.Columns.Add("name", typeof(string));
|
|
_aya.Columns.Add("id", typeof(long));
|
|
_aya.Columns.Add("linked", typeof(bool));
|
|
|
|
//Case 339
|
|
_aya.DefaultView.Sort = "name asc";
|
|
gridAya.DataSource = _aya;
|
|
|
|
_qb = new DataTable("QuickBooks");
|
|
_qb.Columns.Add("name", typeof(string));
|
|
_qb.Columns.Add("id", typeof(string));
|
|
_qb.Columns.Add("linked", typeof(bool));
|
|
|
|
//Case 339
|
|
_qb.DefaultView.Sort = "name asc";
|
|
gridQB.DataSource = _qb;
|
|
}
|
|
|
|
private void Map_Load(object sender, EventArgs e)
|
|
{
|
|
Initialize();
|
|
gridAya.ClearSelection();
|
|
gridQB.ClearSelection();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Determine if row should be added to grid or now
|
|
/// based on current view preferences and if item is already
|
|
/// linked or not
|
|
/// </summary>
|
|
/// <param name="bLinked"></param>
|
|
/// <returns></returns>
|
|
private bool DisplayRow(bool bLinked)
|
|
{
|
|
switch (_currentView)
|
|
{
|
|
case viewtypes.All:
|
|
return true;
|
|
|
|
case viewtypes.Linked:
|
|
return bLinked;
|
|
|
|
case viewtypes.Unlinked:
|
|
return !bLinked;
|
|
|
|
|
|
}
|
|
return true;
|
|
}
|
|
|
|
|
|
private void Initialize()
|
|
{
|
|
|
|
//clear both lists
|
|
_aya.Rows.Clear();
|
|
_qb.Rows.Clear();
|
|
|
|
|
|
|
|
//Case 147
|
|
updateAyaNovaPricesToolStripMenuItem.Visible = false;
|
|
|
|
switch (_Type)
|
|
{
|
|
|
|
case AyaType.Customer:
|
|
#region client
|
|
|
|
|
|
/*
|
|
foreach(ClientPickList.ClientPickListInfo i in Util.AyaClientList)
|
|
{
|
|
if(i.Active)
|
|
{
|
|
bool bLinked=Util.QBI.Maps.Contains(i.ID);
|
|
if(DisplayRow(bLinked))
|
|
_aya.Rows.Add(new object[] {i.ID,i.Name,bLinked});
|
|
|
|
}
|
|
}
|
|
|
|
//Fill QB table with QB Customers from prefetched table
|
|
foreach(DataRow dr in Util.QBClients.Rows)
|
|
{
|
|
bool bLinked=Util.QBI.Maps.Contains(dr["ID"].ToString(),RootObjectTypes.Client);
|
|
if(DisplayRow(bLinked))
|
|
_qb.Rows.Add(new object[] {dr["ID"].ToString(),dr["FullName"].ToString(),bLinked});
|
|
}
|
|
|
|
*/
|
|
|
|
|
|
foreach (var i in util.AyaClientList)
|
|
{
|
|
if (i.Active)
|
|
{
|
|
bool bLinked = util.QBIntegration.Items.Any(z => z.AType == _Type && z.Id == i.Id);
|
|
if (DisplayRow(bLinked))
|
|
{
|
|
var qbItem = util.QBIntegration.Items.FirstOrDefault(z => z.AType == _Type && z.Id == i.Id);
|
|
if (qbItem == null)
|
|
{
|
|
qbItem = new IntegrationItem();
|
|
}
|
|
_aya.Rows.Add(new object[] { i.Name, i.Id, bLinked });
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
//Fill QB table
|
|
foreach (DataRow dr in util.QBClients.Rows)
|
|
{
|
|
bool bLinked = util.QBIntegration.Items.Any(z => z.AType == _Type && z.IntegrationItemId == dr["ID"].ToString());
|
|
if (DisplayRow(bLinked))
|
|
_qb.Rows.Add(new object[] { dr["FullName"].ToString(), dr["ID"].ToString(), bLinked });
|
|
}
|
|
#endregion client
|
|
break;
|
|
case AyaType.Vendor:
|
|
#region Vendor
|
|
|
|
|
|
foreach (var i in util.AyaVendorList)
|
|
{
|
|
if (i.Active)
|
|
{
|
|
bool bLinked = util.QBIntegration.Items.Any(z => z.AType == _Type && z.Id == i.Id);
|
|
if (DisplayRow(bLinked))
|
|
{
|
|
var qbItem = util.QBIntegration.Items.FirstOrDefault(z => z.AType == _Type && z.Id == i.Id);
|
|
_aya.Rows.Add(new object[] { i.Name, i.Id, bLinked });
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
//Fill QB table
|
|
foreach (DataRow dr in util.QBVendors.Rows)
|
|
{
|
|
bool bLinked = util.QBIntegration.Items.Any(z => z.AType == _Type && z.IntegrationItemId == dr["ID"].ToString());
|
|
if (DisplayRow(bLinked))
|
|
_qb.Rows.Add(new object[] { dr["FullName"].ToString(), dr["ID"].ToString(), bLinked });
|
|
}
|
|
#endregion Vendor
|
|
break;
|
|
case AyaType.ServiceRate:
|
|
#region Service rates
|
|
//_MostLikelyRateUnitChargeDescriptionID = 0;
|
|
|
|
|
|
foreach (var i in util.AyaServiceRateList)
|
|
{
|
|
if (i.Active)
|
|
{
|
|
// //Determine the most likely description for purposes
|
|
// //of importing a rate from QB later by picking the first one
|
|
// //in the existing rate list that is non-empty
|
|
// //typically this will just be hours and every rate will
|
|
// //probably use the same one or for travel "miles" or "km's" etc
|
|
// if(_MostLikelyRateUnitChargeDescriptionID==Guid.Empty && i.RateUnitChargeDescriptionID!=Guid.Empty)
|
|
// _MostLikelyRateUnitChargeDescriptionID=i.RateUnitChargeDescriptionID;
|
|
|
|
//After discussion we decided to not us any rate unit charge description
|
|
//so leaving the code in but defaulted to guid.empty for now.
|
|
|
|
bool bLinked = util.QBIntegration.Items.Any(z => z.AType == _Type && z.Id == i.Id);
|
|
if (DisplayRow(bLinked))
|
|
{
|
|
var qbItem = util.QBIntegration.Items.FirstOrDefault(z => z.AType == _Type && z.Id == i.Id);
|
|
_aya.Rows.Add(new object[] { i.Name, i.Id, bLinked });
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
//Fill QB table with QB items from prefetched table
|
|
foreach (DataRow dr in util.QBItems.Rows)
|
|
{
|
|
if ((util.qbitemtype)dr["Type"] == util.qbitemtype.Service || (util.qbitemtype)dr["Type"] == util.qbitemtype.OtherCharge)
|
|
{
|
|
bool bLinked = util.QBIntegration.Items.Any(z => z.AType == _Type && z.IntegrationItemId == dr["ID"].ToString());
|
|
if (DisplayRow(bLinked))
|
|
_qb.Rows.Add(new object[] { dr["FullName"].ToString(), dr["ID"].ToString(), bLinked });
|
|
}
|
|
}
|
|
#endregion Rate
|
|
break;
|
|
|
|
case AyaType.TravelRate:
|
|
#region TravelRate rates
|
|
//_MostLikelyRateUnitChargeDescriptionID = 0;
|
|
|
|
|
|
foreach (var i in util.AyaServiceRateList)
|
|
{
|
|
if (i.Active)
|
|
{
|
|
// //Determine the most likely description for purposes
|
|
// //of importing a rate from QB later by picking the first one
|
|
// //in the existing rate list that is non-empty
|
|
// //typically this will just be hours and every rate will
|
|
// //probably use the same one or for travel "miles" or "km's" etc
|
|
// if(_MostLikelyRateUnitChargeDescriptionID==Guid.Empty && i.RateUnitChargeDescriptionID!=Guid.Empty)
|
|
// _MostLikelyRateUnitChargeDescriptionID=i.RateUnitChargeDescriptionID;
|
|
|
|
//After discussion we decided to not us any rate unit charge description
|
|
//so leaving the code in but defaulted to guid.empty for now.
|
|
|
|
bool bLinked = util.QBIntegration.Items.Any(z => z.AType == _Type && z.Id == i.Id);
|
|
if (DisplayRow(bLinked))
|
|
{
|
|
var qbItem = util.QBIntegration.Items.FirstOrDefault(z => z.AType == _Type && z.Id == i.Id);
|
|
_aya.Rows.Add(new object[] { i.Name, i.Id, bLinked });
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
//Fill QB table with QB items from prefetched table
|
|
foreach (DataRow dr in util.QBItems.Rows)
|
|
{
|
|
if ((util.qbitemtype)dr["Type"] == util.qbitemtype.Service || (util.qbitemtype)dr["Type"] == util.qbitemtype.OtherCharge)
|
|
{
|
|
bool bLinked = util.QBIntegration.Items.Any(z => z.AType == _Type && z.IntegrationItemId == dr["ID"].ToString());
|
|
if (DisplayRow(bLinked))
|
|
_qb.Rows.Add(new object[] { dr["FullName"].ToString(), dr["ID"].ToString(), bLinked });
|
|
}
|
|
}
|
|
#endregion Rate
|
|
break;
|
|
|
|
case AyaType.Part:
|
|
#region Service parts
|
|
//case 632
|
|
//gridQB.DisplayLayout.Rows.TemplateAddRow.Hidden=true;
|
|
|
|
//Case 147
|
|
updateAyaNovaPricesToolStripMenuItem.Visible = true;
|
|
|
|
foreach (var i in util.AyaPartList)
|
|
{
|
|
if (i.Active)
|
|
{
|
|
|
|
bool bLinked = util.QBIntegration.Items.Any(z => z.AType == _Type && z.Id == i.Id);
|
|
if (DisplayRow(bLinked))
|
|
{
|
|
var qbItem = util.QBIntegration.Items.FirstOrDefault(z => z.AType == _Type && z.Id == i.Id);
|
|
_aya.Rows.Add(new object[] { i.Name, i.Id, bLinked });
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
//Fill QB table with QB items from prefetched table
|
|
foreach (DataRow dr in util.QBItems.Rows)
|
|
{
|
|
if ((util.qbitemtype)dr["Type"] == util.qbitemtype.Inventory || (util.qbitemtype)dr["Type"] == util.qbitemtype.NonInventory || (util.qbitemtype)dr["Type"] == util.qbitemtype.Assembly)
|
|
{
|
|
bool bLinked = util.QBIntegration.Items.Any(z => z.AType == _Type && z.IntegrationItemId == dr["ID"].ToString());
|
|
if (DisplayRow(bLinked))
|
|
_qb.Rows.Add(new object[] { dr["FullName"].ToString(), dr["ID"].ToString(), bLinked });
|
|
}
|
|
}
|
|
#endregion Part
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void showSubItemToolStripMenuItem_Click(object sender, EventArgs e)
|
|
{
|
|
// Set the current clicked item to item
|
|
ToolStripMenuItem item = sender as ToolStripMenuItem;
|
|
// Loop through all items in the subMenu and uncheck them but do check the clicked item
|
|
foreach (ToolStripMenuItem tempItemp in showToolStripMenuItem.DropDownItems)
|
|
{
|
|
if (tempItemp == item)
|
|
tempItemp.Checked = true;
|
|
else
|
|
tempItemp.Checked = false;
|
|
}
|
|
}
|
|
|
|
private void mapSelectedItemsToolStripMenuItem_Click(object sender, EventArgs e)
|
|
{
|
|
if (gridAya.SelectedRows.Count == 0) return;
|
|
|
|
//we have selection now get qb item
|
|
MapSelectQBItem s = new MapSelectQBItem();
|
|
|
|
s.QBItems = _qb;
|
|
string SelectedQBItem = string.Empty;
|
|
if (s.ShowDialog() == DialogResult.Cancel)
|
|
return;
|
|
else
|
|
SelectedQBItem = s.SelectedQBItem;
|
|
s.Dispose();
|
|
var selectedAyaNovaIndexes = new List<long>();
|
|
foreach (DataGridViewRow r in gridAya.SelectedRows)
|
|
{
|
|
selectedAyaNovaIndexes.Add((long)r.Cells[0].Value);
|
|
}
|
|
|
|
//todo: here we need to update the linking (and save right away or wait??)
|
|
var v = SelectedQBItem;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void customersToolStripMenuItem_Click(object sender, EventArgs e)
|
|
{
|
|
|
|
}
|
|
|
|
private void serviceRatesToolStripMenuItem_Click(object sender, EventArgs e)
|
|
{
|
|
|
|
}
|
|
|
|
private void travelRatesToolStripMenuItem_Click(object sender, EventArgs e)
|
|
{
|
|
|
|
}
|
|
|
|
private void partsToolStripMenuItem_Click(object sender, EventArgs e)
|
|
{
|
|
|
|
}
|
|
|
|
private void vendorsToolStripMenuItem_Click(object sender, EventArgs e)
|
|
{
|
|
|
|
}
|
|
|
|
private void grid_SelectionChanged(object sender, EventArgs e)
|
|
{
|
|
var hasSelection = gridAya.SelectedRows.Count > 0;
|
|
mapSelectedItemsToolStripMenuItem.Visible = hasSelection;
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#region Drag n drop
|
|
public class QBNameID
|
|
{
|
|
public string Name { get; set; }
|
|
public string ID { get; set; }
|
|
}
|
|
|
|
List<QBNameID> SelectedQBItems = new List<QBNameID>();
|
|
|
|
public class AyaNameID
|
|
{
|
|
public string Name { get; set; }
|
|
public long ID { get; set; }
|
|
}
|
|
List<AyaNameID> SelectedAyaItems = new List<AyaNameID>();
|
|
|
|
|
|
|
|
private bool m_dragging = false;
|
|
Rectangle dragBoxFromMouseDown;
|
|
int rowIndexFromMouseDown;
|
|
int rowIndexOfItemUnderMouseToDrop;
|
|
|
|
#region AyaGrid
|
|
private void gridAya_MouseDown(object sender, MouseEventArgs e)
|
|
{
|
|
if (e.Button != MouseButtons.Left)
|
|
return;
|
|
|
|
|
|
//Only do this if the user is positioned over a row
|
|
rowIndexFromMouseDown = gridAya.HitTest(e.X, e.Y).RowIndex;
|
|
if ((rowIndexFromMouseDown != -1))
|
|
{
|
|
SelectedAyaItems.Clear();
|
|
if (gridAya.SelectedRows.Count > 0 && !gridAya.SelectedRows[0].IsNewRow)
|
|
{
|
|
foreach (DataGridViewRow r in gridAya.SelectedRows)
|
|
{
|
|
SelectedAyaItems.Add(new AyaNameID { Name = (string)r.Cells[0].Value, ID = (long)r.Cells[1].Value });
|
|
}
|
|
//Size dragSize = SystemInformation.DragSize;
|
|
//dragBoxFromMouseDown = new Rectangle(new Point(e.X - (dragSize.Width / 2), e.Y - (dragSize.Height / 2)), dragSize);
|
|
m_dragging = true;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
// dragBoxFromMouseDown = Rectangle.Empty;
|
|
|
|
}
|
|
}
|
|
|
|
private void gridAya_MouseUp(object sender, MouseEventArgs e)
|
|
{
|
|
m_dragging = false;
|
|
}
|
|
|
|
private void gridAya_MouseMove(object sender, MouseEventArgs e)
|
|
{
|
|
if (e.Button == MouseButtons.Left
|
|
&& m_dragging
|
|
&& SelectedAyaItems.Count > 0)
|
|
{
|
|
|
|
gridAya.DoDragDrop(null, DragDropEffects.Link);
|
|
}
|
|
|
|
//if (((e.Button == MouseButtons.Left)))
|
|
//{
|
|
// if (((dragBoxFromMouseDown != Rectangle.Empty)
|
|
// && !dragBoxFromMouseDown.Contains(e.X, e.Y)))
|
|
// {
|
|
// DragDropEffects dropEffect = gridAya.DoDragDrop(gridAya.Rows[rowIndexFromMouseDown], DragDropEffects.Move);
|
|
// }
|
|
//}
|
|
}
|
|
|
|
private void gridAya_DragOver(object sender, DragEventArgs e)
|
|
{
|
|
// e.Effect = DragDropEffects.Move;
|
|
}
|
|
|
|
private void gridAya_DragEnter(object sender, DragEventArgs e)
|
|
{
|
|
if (SelectedQBItems.Count > 0)
|
|
{
|
|
|
|
e.Effect = DragDropEffects.Link;
|
|
}
|
|
else
|
|
e.Effect = DragDropEffects.None;
|
|
}
|
|
|
|
private void gridAya_DragDrop(object sender, DragEventArgs e)
|
|
{
|
|
MessageBox.Show("STUB: aya drop data happened");
|
|
//Point clientPoint = gridAya.PointToClient(new Point(e.X, e.Y));
|
|
//rowIndexOfItemUnderMouseToDrop = gridAya.HitTest(clientPoint.X, clientPoint.Y).RowIndex;
|
|
//if ((e.Effect == DragDropEffects.Move))
|
|
//{
|
|
// DataGridViewRow rowToMove = (DataGridViewRow)e.Data.GetData(typeof(DataGridViewRow));
|
|
// object[] celldata = new object[gridAya.ColumnCount];
|
|
// for (int col = 0; (col
|
|
// <= (rowToMove.Cells.Count - 1)); col++)
|
|
// {
|
|
// celldata[col] = rowToMove.Cells[col].Value;
|
|
// }
|
|
|
|
// //DataRow row = bsPeople.NewRow();
|
|
// //row.ItemArray = celldata;
|
|
// //bsPeople.Rows.InsertAt(row, rowIndexOfItemUnderMouseToDrop);
|
|
// //rowToMove.DataGridView.Rows.Remove(rowToMove);
|
|
|
|
//}
|
|
}
|
|
|
|
private void gridAya_CellClick(object sender, DataGridViewCellEventArgs e)
|
|
{
|
|
|
|
}
|
|
|
|
|
|
#endregion ayagrid
|
|
|
|
#region QBGrid
|
|
|
|
private void gridQB_MouseDown(object sender, MouseEventArgs e)
|
|
{
|
|
|
|
}
|
|
|
|
private void gridQB_MouseUp(object sender, MouseEventArgs e)
|
|
{
|
|
|
|
}
|
|
|
|
private void gridQB_MouseMove(object sender, MouseEventArgs e)
|
|
{
|
|
|
|
}
|
|
|
|
private void gridQB_DragEnter(object sender, DragEventArgs e)
|
|
{
|
|
|
|
}
|
|
|
|
private void gridQB_DragDrop(object sender, DragEventArgs e)
|
|
{
|
|
|
|
}
|
|
|
|
private void gridQB_CellClick(object sender, DataGridViewCellEventArgs e)
|
|
{
|
|
|
|
}
|
|
|
|
|
|
#endregion qbgrid
|
|
|
|
|
|
#endregion drag and drop
|
|
|
|
/*
|
|
* Simplified, no drag and drop just pick and choose with clicks
|
|
* A menu to select the ayanova object type which then populates the ayanova items grid of that type showing:
|
|
A single grid showing all ayanova items of the selected type with their name in the first column and a second column showing what they are mapped to in qb item name, easy peasy, no drag and drop
|
|
User can select one or more items
|
|
when one or more are selected
|
|
a menu item appears saying "MAP Selected items" when they select they can pick a qb item of the type they want and accept in a popup dialog which also shows how many ayanova items are selected
|
|
a menyu tiem apepars saying UNMAP selected items when they select it it removes the mapping after confirmation dialog from all selected items
|
|
|
|
//public static List<InvoiceableItem> GetInvoiceableItems()
|
|
//{
|
|
// var random = new Random();
|
|
// var l = new List<InvoiceableItem>();
|
|
// for (int i = 1; i < random.Next(25, 100); i++)
|
|
// l.Add(new InvoiceableItem { Customer = $"Customer {random.Next(1, 5)}", Linked = random.Next(2) == 1, Project = $"project {i}", ServiceDate = DateTime.Now.ToString("g"), ServiceNumber = (40 + i).ToString(), Status = $"Waiting to be invoiced", StatusColor = "FF00FFAA", WorkorderId = 4 });
|
|
|
|
// return l.OrderBy(x => x.Customer)
|
|
// .ThenBy(x => x.ServiceNumber)
|
|
// .ThenBy(x => x.ServiceDate)
|
|
// .ToList();
|
|
|
|
//}
|
|
|
|
*/
|
|
}
|
|
}
|