public static void DoIt(QuickGrid grid,Control parent) { grid.Location = new Point(0,0); grid.Visible = true; grid.Dock = DockStyle.Fill; grid.Parent = parent; }
public static void DoIt(QuickGrid grid, PictureBox picture,Control parent, AnchorStyles anchor) { picture.Visible = false; grid.Location = picture.Location; grid.Visible = true; grid.Size = picture.Size; grid.Dock = picture.Dock; grid.Parent = parent; grid.Anchor = anchor; }
public static void GridWizard(QuickGrid grid, DataTable table,bool isMetric,IsNewAllowed isNewAllowed, IsReadOnly isReadOnly, string sortingField,GetFieldDelegate getField, HelperFunctions.DataGridClientInterface face,params string[] fieldsIn) { // When you get the field properties than the leading "*" is stripped string[] fields = (string[])fieldsIn.Clone(); fieldsIn.CopyTo(fields,0); HelperFunctions.FieldProperties[] fieldProperties = HelperFunctions.GetProperties(ref fields,isMetric); DataTable newTable = new DataTable(); for (int i=0;i<fields.Length;i++) { newTable.Columns.Add(fields[i],fieldProperties[i].type); } for (int i=0;i<table.Rows.Count;i++) { if (!DataInterface.IsRowAlive(table.Rows[i])) continue; DataRow targetRow = newTable.NewRow(); foreach (string fieldName in fields) { object o = getField(table.Rows[i],isMetric,fieldName); targetRow[fieldName] = o; } newTable.Rows.Add(targetRow); } DataView view = new DataView(newTable,"",sortingField, DataViewRowState.CurrentRows); HelperFunctions.UpdateGrid(view,grid,face,isMetric, isNewAllowed,isReadOnly,fieldsIn); }
public static void SetupContainerItemSummaryGrid(EMDataSet emDataSet,QuickGrid grid,int poItemNumber,int bundleIDNumber) { EMDataSet.ContBundleTblRow[] rows = (EMDataSet.ContBundleTblRow[]) emDataSet.ContBundleTbl.Select("POItemNumber = " + poItemNumber.ToString()); DataTable newTable = new DataTable(); string[] fields = new string[]{"ContNumber","BundleSeqNumber","EnglishShipQty","MetricShipQty","ContID","ContainerBundleID"}; HelperFunctions.FieldProperties[] fieldProperties = HelperFunctions.GetProperties(ref fields,false); for (int i =0;i<fields.Length;i++) { newTable.Columns.Add(fields[i],fieldProperties[i].type); } int selectedIndex = -1; for (int i = 0; i < rows.Length; i++) { EMDataSet.ContBundleTblRow row = rows[i]; if (!DataInterface.IsRowAlive(row)) continue; if (row.ContainerBundleID == bundleIDNumber) selectedIndex = i; DataRow targetRow = newTable.NewRow(); targetRow["ContNumber"] = row.ContainerTblRow.ContNumber; targetRow["BundleSeqNumber"] = row.BundleSeqNumber; targetRow["EnglishShipQty"] = row["EnglishShipQty"]; targetRow["MetricShipQty"] = row["MetricShipQty"]; targetRow["ContID"] = row.ContID; targetRow["ContainerBundleID"] = row.ContainerBundleID; newTable.Rows.Add(targetRow); } DataView view = new DataView(newTable,"","ContNumber",DataViewRowState.CurrentRows); HelperFunctions.UpdateGrid(view,grid,null,false,IsNewAllowed.No,IsReadOnly.Yes,fields); if (selectedIndex != -1) grid.SetNewFocus(selectedIndex, 0); }
public static void SetupContainerItemSummaryGrid(EMDataSet emDataSet, QuickGrid grid, int poItemNumber) { SetupContainerItemSummaryGrid(emDataSet, grid, poItemNumber, 0); }
public static void SetupContainerGrids(EMDataSet emDataSet, int contID,QuickGrid bundleGrid, QuickGrid weightGrid, HelperFunctions.DataGridClientInterface face,IsReadOnly isReadOnly, out decimal totalLbs,out decimal totalKgs, GetBillOfLadingNumberFunc func) { string[] bolFieldList = {"*BundleSeqNumber","*PONumber", "*ItemName","*SizeOfItem","MetricShipQty", "EnglishShipQty","Heat", "BayNumber","InvoiceNumber","MillInvoiceDate","BundleAlloySurcharge", "BundleScrapSurcharge", "EMInvoiceNumber", "PickupDate","PickupTerminal","ProofOfDelivery","*CancelDate", "ContainerBundleID"}; EMDataSet.ContainerTblRow contRow = emDataSet.ContainerTbl.FindByContID(contID); bool showLessFields = !contRow.IsApplyClosingToEntireContainerNull() && contRow.ApplyClosingToEntireContainer!=0; if (showLessFields) { bolFieldList = new string[]{"*BundleSeqNumber","*PONumber", "*ItemName","*SizeOfItem","MetricShipQty", "EnglishShipQty","Heat", "BayNumber","InvoiceNumber","MillInvoiceDate", "BundleAlloySurcharge","BundleScrapSurcharge","EMInvoiceNumber", "*CancelDate", "ContainerBundleID"}; } BundleFieldHelper bundleFieldHelper = new BundleFieldHelper(); bundleFieldHelper.m_getter = func; GridWizard(bundleGrid,emDataSet.ContBundleTbl,false, IsNewAllowed.No,isReadOnly,"BundleSeqNumber", new GetFieldDelegate(bundleFieldHelper.GetBundleField), face,bolFieldList); bundleGrid.SetCancelColumn("CancelDate"); DataTable weightTable = new DataTable(); weightTable.Clear(); weightTable.Columns.Clear(); weightTable.Columns.Add("PONumber",typeof(string)); weightTable.Columns.Add("ItemName",typeof(string)); weightTable.Columns.Add("ItemDesc",typeof(string)); weightTable.Columns.Add("SizeOfItem",typeof(string)); weightTable.Columns.Add("MetricShipQty",typeof(decimal)); weightTable.Columns.Add("EnglishShipQty",typeof(decimal)); weightTable.Columns.Add("POItemNumber",typeof(int)); totalKgs = 0; totalLbs = 0; foreach (EMDataSet.ContBundleTblRow sourceRow in emDataSet.ContBundleTbl.Rows) { if (!DataInterface.IsRowAlive(sourceRow)) continue; EMDataSet.POItemTblRow itemRow = sourceRow.POItemTblRow; EMDataSet.POHeaderTblRow poRow = itemRow.POHeaderTblRow; DataRow weightRow = weightTable.NewRow(); weightRow["PONumber"] = poRow.PONumber; weightRow["ItemName"] = itemRow.ItemTblRow.ItemName; weightRow["ItemDesc"] = itemRow["ItemDesc"]; weightRow["EnglishShipQty"] = sourceRow["EnglishShipQty"]; if (!sourceRow.IsNull("EnglishShipQty")) { totalLbs += (decimal)sourceRow["EnglishShipQty"]; } weightRow["MetricShipQty"] = sourceRow["MetricShipQty"]; if (!sourceRow.IsNull("MetricShipQty")) { totalKgs += (decimal)sourceRow["MetricShipQty"]; } weightRow["SizeOfItem"] = itemRow["SizeOfItem"]; weightRow["POItemNumber"] = itemRow.POItemNumber; weightTable.Rows.Add(weightRow); } // Collapse the weightTable for (int i=0;i<weightTable.Rows.Count;i++) { DataRow masterRow = weightTable.Rows[i]; if (!DataInterface.IsRowAlive(masterRow)) continue; int poItemNumber = (int)masterRow["POItemNumber"]; for (int j=i+1;j<weightTable.Rows.Count;j++) { DataRow compareRow = weightTable.Rows[j]; if (!DataInterface.IsRowAlive(compareRow)) continue; if (((int)compareRow["POItemNumber"]) == poItemNumber) // same item { if (masterRow.IsNull("MetricShipQty")) masterRow["MetricShipQty"] = (decimal)0; if (masterRow.IsNull("EnglishShipQty")) masterRow["EnglishShipQty"] = (decimal)0; decimal metricShipQty = (decimal)masterRow["MetricShipQty"]; decimal englishShipQty = (decimal)masterRow["EnglishShipQty"]; if (!compareRow.IsNull("MetricShipQty")) metricShipQty += (decimal)compareRow["MetricShipQty"]; if (!compareRow.IsNull("EnglishShipQty")) englishShipQty += (decimal)compareRow["EnglishShipQty"]; masterRow["MetricShipQty"] = metricShipQty; masterRow["EnglishShipQty"] = englishShipQty; compareRow.Delete(); j--; } } } DataView weightView = new DataView(weightTable,"","ItemName",DataViewRowState.CurrentRows); HelperFunctions.UpdateGrid(weightView,weightGrid,null,false,IsNewAllowed.No, IsReadOnly.Yes,"PONumber","ItemName","ItemDesc","SizeOfItem", "MetricShipQty","EnglishShipQty"); }
public static void DoIt(QuickGrid grid, PictureBox picture,Control parent) { DoIt(grid,picture,parent,AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Top); }
public static void DoIt(QuickGrid grid,int poid,bool isMetric,EMDataSet emDataSet) { int[] finishKeys = HelperFunctions.GetFinishKeys("Finish"); decimal[] totalWeight = new decimal[finishKeys.Length+1];// Last one has no key decimal[] totalAmount = new decimal[finishKeys.Length+1]; foreach (EMDataSet.POItemTblRow itemRow in emDataSet.POItemTbl) { if (!DataInterface.IsRowAlive(itemRow)) continue; decimal currentWeight; if (itemRow.IsQtyNull()) currentWeight = 0; else currentWeight = itemRow.Qty; decimal currentAmount; if (itemRow.IsCustAmountNull()) currentAmount = 0; else currentAmount = itemRow.CustAmount; if (itemRow.IsFinishIDNull()) { totalWeight[totalWeight.Length-1] += currentWeight; totalAmount[totalAmount.Length-1] += currentAmount; } else { int index = Array.IndexOf(finishKeys,itemRow.FinishID); totalWeight[index] += currentWeight; totalAmount[index] += currentAmount; } } DataTable dataTable = new DataTable(); dataTable.Columns.Add("Heading",typeof(string)); dataTable.Columns.Add("FinishWeight",typeof(decimal)); dataTable.Columns.Add("FinishAmount",typeof(decimal)); for (int i=0;i<totalWeight.Length;i++) { DataRow weightRow = dataTable.NewRow(); weightRow["FinishWeight"] = totalWeight[i]; weightRow["FinishAmount"] = totalAmount[i]; if (i == finishKeys.Length) // should just happen here { weightRow["Heading"] = "Unknown"; } else weightRow["Heading"] = HelperFunctions.GetFinishType("Finish",finishKeys[i]); dataTable.Rows.Add(weightRow); } DataRow totalRow = dataTable.NewRow(); totalRow["Heading"] = "Total"; decimal totalTotal = 0; foreach (decimal current in totalWeight) { totalTotal += current; } decimal totalAmountTotal =0; foreach (decimal current in totalAmount) { totalAmountTotal += current; } totalRow["FinishAmount"] = totalAmountTotal; totalRow["FinishWeight"] = totalTotal; dataTable.Rows.Add(totalRow); HelperFunctions.UpdateGrid(dataTable.DefaultView,grid,null, isMetric,IsNewAllowed.No,IsReadOnly.Yes, "Heading","FinishWeight","FinishAmount"); }
public static void UpdateGrid(DataView itemTable, QuickGrid grid, DataGridClientInterface face,bool isKg, IsNewAllowed allowNew, IsReadOnly readOnly, params string[] fieldNames) { fieldNames = (string[])fieldNames.Clone(); FieldProperties[] properties = GetProperties(ref fieldNames,isKg); int numberOfFields = fieldNames.Length; DataTable table = new DataTable(); for (int i = 0;i<numberOfFields;i++) { System.Type type = properties[i].type; table.Columns.Add(fieldNames[i],type); } HelperFunctions.DataGridClientBridge bridge = null; if (face != null) bridge = new DataGridClientBridge(face); foreach (DataRowView rowView in itemTable) { DataRow row = rowView.Row; if (!DataInterface.IsRowAlive(row)) continue; DataRow newRow = table.NewRow(); for (int i = 0;i<numberOfFields;i++) { string fieldName = fieldNames[i]; if (!row.IsNull(fieldName) && row[fieldName].GetType() == typeof(System.DateTime)) { DateTime d = (DateTime)row[fieldName]; newRow[fieldName] = d.ToShortDateString(); } else newRow[fieldName] = row[fieldName]; } table.Rows.Add(newRow); } table.AcceptChanges(); grid.ClearAllHandlers(); ArrayList listOfColumnProperties = new ArrayList(); for (int i=0;i<properties.Length;i++) { FieldProperties props = properties[i]; if (props.isKeyField == true) continue; if (IsReadOnly.Yes == readOnly) props.readOnly = true; QuickGrid.ColumnProperties coll = new QuickGrid.ColumnProperties(); switch (props.columnStyle) { case ColumnStyle.Text: coll.formatString = props.formatString; break; case ColumnStyle.Date: coll.formatString = "d"; grid.AddButtonHandler(i,".",new EventHandler(OnDateClick)); break; case ColumnStyle.Item: { if (!props.readOnly) { // since we are not allowing the user // to actually edit the field props.readOnly = true; if (face == null) throw new Exception("Oops, you need a handler for the item clicker"); grid.AddButtonHandler(i,".",new EventHandler(bridge.OnItemClick)); } break; } default: throw new Exception("Ahh no case statement"); } if (props.columnHeading == "Description") { coll.multiline = true; coll.variable = true; } if (props.columnHeading == "Comments") { coll.multiline = true; } coll.comboBoxValues = props.comboBoxItems; coll.heading = props.columnHeading; coll.size = props.width; coll.alignment = props.alignment; coll.readOnly = props.readOnly; listOfColumnProperties.Add(coll); } table.ColumnChanged +=new DataColumnChangeEventHandler(DataGridColumnChanged); if (bridge != null) table.ColumnChanged +=new DataColumnChangeEventHandler(bridge.DataGridColumnChanged); QuickGrid.ColumnProperties[] columnProperties = (QuickGrid.ColumnProperties[])listOfColumnProperties.ToArray (typeof(QuickGrid.ColumnProperties)); grid.Setup(table,columnProperties,allowNew==IsNewAllowed.Yes?true:false); }
public static int GetPosition(QuickGrid grid) { return grid.GetCurrentIndex().row; }
public static EMDataSet.POItemTblRow GetCurrentRow(QuickGrid grid,EMDataSet.POItemTblDataTable table) { int seqNumber = GetPosition(grid)+1; return GetRowFromSeqNumber(table,seqNumber); }
// This is pretty big function. It converts the information from a the DataGrid back to the // item table. // Then it matches up the existing items by using the poitem number keyword // Then it adds new items public static void FromGrid(int poid,EMDataSet emDataSet, QuickGrid generalGrid,bool commitItemName) { EMDataSet.POItemTblDataTable itemTable = emDataSet.POItemTbl; // All the new rows are at the end, but with no poitemnumber DataTable grid = (DataTable)generalGrid.GetTable(); // Only work on a temporary copy of the datatable. That way // the one that is bound to the datagrid doesn't change grid = grid.Copy(); // At this point, the entire datatable should be collapsed. // There will be some items with poitemnumbers, and some without int maxSeqNumber = GetMaxSeqNumber(grid); ArrayList poidNumbersInGrid = new ArrayList(); for (int i=0;i<grid.Rows.Count;i++) { DataRow sourceRow = grid.Rows[i]; if (!DataInterface.IsRowAlive(sourceRow)) continue; // Changed row if (!sourceRow.IsNull("POItemNumber")) { int poItemNumber = (int)sourceRow["POItemNumber"]; EMDataSet.POItemTblRow targetRow = itemTable.FindByPOItemNumber(poItemNumber); foreach (DataColumn column in grid.Columns) { string columnName = column.ColumnName; if (columnName == "Finish") { if (commitItemName) TransferFinish("Finish", sourceRow, targetRow); continue; } if (columnName == "Treatment") { if (commitItemName) TransferFinish("Treatment",sourceRow,targetRow); continue; } if (columnName == "ItemName") { if (commitItemName) targetRow["ItemID"] = GetItemID(emDataSet,targetRow,sourceRow["ItemName"]); continue; } targetRow[columnName] = sourceRow[columnName]; } poidNumbersInGrid.Add(poItemNumber); } else // new row { EMDataSet.POItemTblRow targetRow = itemTable.NewPOItemTblRow(); sourceRow["POItemNumber"] = DataInterface.GetNextKeyNumber("tblPOItem2"); sourceRow["SeqNumber"] = (int)(maxSeqNumber+1); maxSeqNumber++; targetRow.POID = poid; foreach (DataColumn column in grid.Columns) { string columnName = column.ColumnName; if (columnName == "Finish") { TransferFinish("Finish",sourceRow,targetRow); continue; } if (columnName == "Treatment") { TransferFinish("Treatment",sourceRow,targetRow); continue; } if (columnName == "ItemName") { targetRow["ItemID"] = GetItemID(emDataSet,targetRow,sourceRow["ItemName"]); continue; } targetRow[columnName] = sourceRow[columnName]; } DataInterface.ConformMetric(itemTable,targetRow); itemTable.AddPOItemTblRow(targetRow); poidNumbersInGrid.Add(sourceRow["POItemNumber"]); } } // Look to see if we need to check any of the items // as being deleted // We have to delete rows // after the iteration so that // the iteration doesn't get screwed // up. This arraylist keeps track of them ArrayList listOfRowsToDelete = new ArrayList(); foreach (EMDataSet.POItemTblRow row in itemTable) { if (!DataInterface.IsRowAlive(row)) continue; bool poidFound = false; int poidNumber = row.POItemNumber; foreach (int gridPOID in poidNumbersInGrid) { if (poidNumber == gridPOID) { poidFound = true; break; } } if (!poidFound) listOfRowsToDelete.Add(row); } foreach (DataRow row in listOfRowsToDelete) row.Delete(); // Test for good seqnumbers ArrayList listOfSeqNumbers = new ArrayList(); foreach (EMDataSet.POItemTblRow row in itemTable) { if (!DataInterface.IsRowAlive(row)) continue; listOfSeqNumbers.Add(row.SeqNumber); } listOfSeqNumbers.Sort(); int [] arrayOfSeqNumbers = (int[])listOfSeqNumbers.ToArray(typeof(int)); for (int i=0;i<listOfSeqNumbers.Count;i++) { if ((i+1) != arrayOfSeqNumbers[i]) throw new Exception("BUG: bad seq number setup"); } }
public void quick_grid_works_correctly(string value, LengthCollection expected) { QuickGrid.SetColumns(_grid, value); expected.Compare(_grid); }