// void BuildDeliveryTable(OleDbDataReader pDataReader, bool pPrintForm) void BuildDeliveryTable(IDataReader pDataReader, bool pPrintForm) { // delete the old data while (1 < tblDeliveries.Rows.Count) { tblDeliveries.Rows.RemoveAt(1); } tblTotals.Rows.Clear(); //casting null check int iSortOrder; // string lists to store the company names and the items to be delivered to them List <deliveryItems> deliveryDetailsList = new List <DeliverySheet.deliveryItems>(); // Delivery Persons list, we use a dictionary for easy of use SortedDictionary <string, string> ListOfDeliveryBy = new SortedDictionary <string, string>(); // The Totals Table stuff string _strItemID = ""; string _strItemDesc = ""; string _strTotalItemDesc = ""; bool _isUnknownClient = false; Dictionary <string, ItemTotals> sumItemTotals = new Dictionary <string, ItemTotals>(); /// InvoiceType - shoudl add to search of orderstbl nut in the meantime int _PatchInvoiceType = 0; string[] _PatchInvoicePrefix = { "", "dN", "d#", "g$", "cS", "s@", "!!", "??" }; CustomersAccInfoTbl _PatchCAI = new CustomersAccInfoTbl(); // how many items will be deliverred, this will be the counter int numDeliveryItems = 0; // read the data from the SQL query and add data to delivery list while (pDataReader.Read()) { _isUnknownClient = false; // for each line read the data, and then if the company name has changed add that line to the table deliveryItems _tDeliveryItem = new deliveryItems(); _tDeliveryItem.ContactID = pDataReader["CustomerId"].ToString(); // ID is used for link to ediot of customer _tDeliveryItem.ContactCompany = pDataReader["CoName"].ToString(); // do some basic manipluation of names depending on what is selected, add notes. if (_tDeliveryItem.ContactCompany.StartsWith("ZZName")) { // add the ZZname but check if there is a ":" which is the end of name delimiter _tDeliveryItem.ContactID = CONST_IS_ZZNAME; _isUnknownClient = true; var _strNotes = pDataReader["Notes"].ToString(); if (_strNotes.Contains(":")) { _strNotes = _strNotes.Remove(_strNotes.IndexOf(":")).Trim(); } _strNotes = StripEmailOut(_strNotes); _tDeliveryItem.ContactCompany = CONST_ZZNAME_PREFIX + " " + _strNotes; } else if (_tDeliveryItem.ContactCompany.StartsWith("Stock")) { _tDeliveryItem.ContactCompany = "STK: " + pDataReader["Notes"].ToString(); } // if the notes have a "+" to start with append that to the name if (pDataReader["Notes"].ToString().StartsWith("+")) { _tDeliveryItem.ContactCompany += "[" + pDataReader["Notes"].ToString() + "]"; } // temporary check invoice type if (!_tDeliveryItem.ContactID.Equals(CONST_IS_ZZNAME)) { long _ID = 0; if (long.TryParse(_tDeliveryItem.ContactID, out _ID)) { _PatchInvoiceType = _PatchCAI.GetCustomersInvoiceType(_ID); if (_PatchInvoiceType > InvoiceTypeTbl.CONST_DEFAULT_INVOICETYPEID) { _tDeliveryItem.ContactCompany = _PatchInvoicePrefix[_PatchInvoiceType - 1] + "]> " + _tDeliveryItem.ContactCompany; } } } // Check if the deliver is done, and mark it so _tDeliveryItem.Done = (pDataReader["Done"] == DBNull.Value) ? false : (bool)pDataReader["Done"]; if (_tDeliveryItem.Done) { _tDeliveryItem.ContactCompany = "<b>DONE</b>-> " + _tDeliveryItem.ContactCompany; } // get delivery person, and store them for the ddl only if not printing if (!pPrintForm) { if (!ListOfDeliveryBy.ContainsKey(pDataReader["ToBeDeliveredBy"].ToString())) { ListOfDeliveryBy[pDataReader["ToBeDeliveredBy"].ToString()] = pDataReader["Abreviation"].ToString(); } /// add url _tDeliveryItem.OrderDetailURL = ResolveUrl("~/Pages/OrderDetail.aspx") + "?" + String.Format("CustomerID={0}&DeliveryDate={1:d}&Notes={2}", HttpContext.Current.Server.UrlEncode(pDataReader["CustomerID"].ToString()), pDataReader["RequiredByDate"], HttpContext.Current.Server.UrlEncode(pDataReader["Notes"].ToString())); } // add delivery details _tDeliveryItem.Details = String.Format("{0:d}, {1}", pDataReader["RequiredByDate"], pDataReader["Abreviation"]); // add invoiuce and PO stuff _tDeliveryItem.InvoiceDone = (pDataReader["InvoiceDone"] == DBNull.Value) ? false : (bool)pDataReader["InvoiceDone"]; _tDeliveryItem.PurchaseOrder = (pDataReader["PurchaseOrder"] == DBNull.Value) ? string.Empty : pDataReader["PurchaseOrder"].ToString(); // get the item Description, may need to do some replacement calculation here _strItemID = pDataReader["ItemTypeID"].ToString(); _strItemDesc = ((pDataReader["ItemShortName"].ToString().Length > 0) ? pDataReader["ItemShortName"].ToString() : pDataReader["ItemDesc"].ToString()); _strTotalItemDesc = _strItemDesc; // check to see if item available if not added error colours if (!Boolean.Parse(pDataReader["ItemEnabled"].ToString())) { _strItemDesc = "<span style='background-color: RED; color: WHITE'>SOLD OUT</span> " + _strItemDesc; _strTotalItemDesc = ">" + _strTotalItemDesc + "<"; } // now add description if required iSortOrder = (pDataReader["SortOrder"] == DBNull.Value) ? 0 : (int)pDataReader["SortOrder"]; if (iSortOrder == ItemTypeTbl.CONST_NEEDDESCRIPTION_SORT_ORDER) { // if we are already use the notes field for name, check if there is a ":" seperator, and then only use what is after var _strNotes = pDataReader["Notes"].ToString(); if ((_isUnknownClient) && (_strNotes.Contains(":"))) { _strNotes = _strNotes.Substring(_strNotes.IndexOf(":") + 1).Trim(); } _strNotes = StripEmailOut(_strNotes); _strItemDesc += ": " + _strNotes; } if (pDataReader["PackDesc"].ToString().Length > 0) { _tDeliveryItem.Items += String.Format("<span style='background-color:{0}; padding-top: 1px; padding-bottom:2px'>{1}X{2} ({3})</span>", pDataReader["BGColour"], pDataReader["QuantityOrdered"], _strItemDesc, pDataReader["PackDesc"]); } else { _tDeliveryItem.Items += String.Format("<span style='background-color:{0}'>{1}X{2}</span>", pDataReader["BGColour"], pDataReader["QuantityOrdered"], _strItemDesc); } // if Item needs to be added and ID exists the increment the total, otherwise add new item if (iSortOrder != ItemTypeTbl.CONST_NEEDDESCRIPTION_SORT_ORDER) { if (sumItemTotals.ContainsKey(_strItemID)) { sumItemTotals[_strItemID].TotalsQty += Convert.ToDouble(pDataReader["QuantityOrdered"]); } else { // Remove notes if (_strItemDesc.Contains(":")) { _strItemDesc = _strItemDesc.Remove(_strItemDesc.IndexOf(":")); } sumItemTotals[_strItemID] = new ItemTotals { ItemID = _strItemID, ItemDesc = _strTotalItemDesc, TotalsQty = Convert.ToDouble(pDataReader["QuantityOrdered"].ToString()), ItemOrder = (pDataReader["SortOrder"] == DBNull.Value) ? 0 : Convert.ToInt32(pDataReader["SortOrder"].ToString()) }; } } // add to list of deliveries deliveryDetailsList.Add(_tDeliveryItem); // increment deliveries now numDeliveryItems++; } pDataReader.Close(); // Do a bubble sort on the ZZnames, so that they are all together for (int idx1 = 0; idx1 < numDeliveryItems; idx1++) { if (deliveryDetailsList[idx1].ContactCompany.StartsWith(CONST_ZZNAME_PREFIX)) { for (int idx2 = idx1 + 2; idx2 < numDeliveryItems; idx2++) { if (deliveryDetailsList[idx2].ContactCompany.Equals(deliveryDetailsList[idx1].ContactCompany)) { // this equals the last one so move it to just below the last one deliveryItems thisItem = deliveryDetailsList[idx2]; deliveryDetailsList.RemoveAt(idx2); deliveryDetailsList.Insert(idx1 + 1, thisItem); } } } } // sort the deliveries to make sure that we have all the company names one after the other int _items = 0; int _PatchPos = 0; string _PatchNAME = ""; string _strURL = ""; while (_items < numDeliveryItems) { TableRow _tblRow = new TableRow(); // now add details // add delivery and date TableCell _tblCellBy = new TableCell(); _tblCellBy.Text = deliveryDetailsList[_items].Details; if (pPrintForm) { _tblCellBy.Font.Size = FontUnit.XSmall; _tblCellBy.Text = _tblCellBy.Text.Remove(0, _tblCellBy.Text.IndexOf(",") + 1); } else // add a hyperlink to edit { _tblCellBy.Text = String.Format("<a class='plain' href='{0}'>{1}</a>", deliveryDetailsList[_items].OrderDetailURL, _tblCellBy.Text.Trim()); } _tblRow.Cells.Add(_tblCellBy); // add company name and a link to the customer edit form. TableCell _tblCell = new TableCell(); if (pPrintForm) { _PatchNAME = deliveryDetailsList[_items].ContactCompany; if (_PatchNAME.Contains("]>")) { _PatchPos = _PatchNAME.IndexOf("]>"); _PatchNAME = _PatchNAME.Substring(_PatchPos + 3); } _tblCell.Text = _PatchNAME; } else if (deliveryDetailsList[_items].ContactID == CONST_IS_ZZNAME) { _tblCell.Text = deliveryDetailsList[_items].ContactCompany; } else { _PatchNAME = deliveryDetailsList[_items].ContactCompany; if (_PatchNAME.Contains("]>")) { _PatchPos = _PatchNAME.IndexOf("]>"); _tblCell.Text = String.Format("{0} - <a href='./CustomerDetails.aspx?ID={1}&'>{2}</a>", _PatchNAME.Substring(0, _PatchPos), deliveryDetailsList[_items].ContactID, _PatchNAME.Substring(_PatchPos + 3)); } else { _tblCell.Text = String.Format("<a href='./CustomerDetails.aspx?ID={0}&'>{1}</a>", deliveryDetailsList[_items].ContactID, _PatchNAME); } } _tblRow.Cells.Add(_tblCell); // Add received and signed by if (pPrintForm) { TableCell _tcReceviedBy = new TableCell(); _tcReceviedBy.BorderStyle = BorderStyle.Solid; _tcReceviedBy.BorderWidth = Unit.Pixel(1); _tcReceviedBy.BorderColor = System.Drawing.Color.Green; _tblRow.Cells.Add(_tcReceviedBy); TableCell _tcSignature = new TableCell(); _tcSignature.BorderStyle = BorderStyle.Solid; _tcSignature.BorderWidth = Unit.Pixel(1); _tcSignature.BorderColor = System.Drawing.Color.Green; _tblRow.Cells.Add(_tcSignature); } // Now the items TableCell _tblCellItems = new TableCell(); // prefix PO and invoice stuff if (!string.IsNullOrWhiteSpace(deliveryDetailsList[_items].PurchaseOrder)) { _tblCellItems.Text = string.Format("<b>[PO: {0}]</b>", deliveryDetailsList[_items].PurchaseOrder); } if ((!pPrintForm) && (deliveryDetailsList[_items].InvoiceDone)) { _tblCellItems.Text += ((string.IsNullOrEmpty(_tblCellItems.Text)) ? "" : " ") + "<span style='background-color:green; color: white'>$Invcd$</span>"; } _strURL = "<span style='vertical-align:middle'> <a href='{0}' class='plain'><img src='../images/imgButtons/EditButton.gif' alt='edit' /></a>"; if (!deliveryDetailsList[_items].InvoiceDone) { _strURL += " <a href='{0}&" + OrderDetail.CONST_QRYSTR_INVOICED + "=Y' class='plain'><img src='../images/imgButtons/InvoicedButton.gif' alt='invcd' /></a></span>"; } if (!deliveryDetailsList[_items].Done) { _strURL += " <a href='{0}&" + OrderDetail.CONST_QRYSTR_DELIVERED + "=Y' class='plain'><img src='../images/imgButtons/DoneButton.gif' alt='dlvrd' /></a></span>"; } _strURL = String.Format(_strURL, deliveryDetailsList[_items].OrderDetailURL); // add all items to the row do { _tblCellItems.Text += ((string.IsNullOrEmpty(_tblCellItems.Text)) ? "" : "; ") + deliveryDetailsList[_items].Items.ToString(); _items++; } while ((_items < numDeliveryItems) && (deliveryDetailsList[_items - 1].ContactCompany == deliveryDetailsList[_items].ContactCompany)); // add items _tblRow.Cells.Add(_tblCellItems); // Add in stock if (pPrintForm) { _tblRow.Cells.Add(new TableCell()); } // now add edit url bool _RunningOnMobile = (bool)Session[CheckBrowser.CONST_SESSION_RUNNINGONMOBILE]; if (!pPrintForm && !_RunningOnMobile) { _tblRow.Cells.Add(new TableCell { Text = _strURL }); } tblDeliveries.Rows.Add(_tblRow); } // while we have delivery items // set hieght of table depending on the nubmer of rows Style _NewStyle = new Style(); if (tblDeliveries.Rows.Count < CONST_ONLYAFEWDELIVERIES) { _NewStyle.Height = new Unit(4.5, UnitType.Em); } else if (tblDeliveries.Rows.Count > CONST_ALOTOFDELIVERIES) { _NewStyle.Height = new Unit(.3, UnitType.Em); _NewStyle.Font.Size = new FontUnit(11, UnitType.Pixel); } else { _NewStyle.Height = new Unit(2, UnitType.Em); } foreach (TableRow _tblRow in tblDeliveries.Rows) { _tblRow.Cells[0].ApplyStyle(_NewStyle); } tblDeliveries.Rows[0].Cells[1].Text = String.Format("To ({0})", tblDeliveries.Rows.Count - 1); //Display the totals table now Dictionary <string, ItemTotals> sortedItemTotals = (from entry in sumItemTotals orderby entry.Value.ItemOrder ascending select entry).ToDictionary(pair => pair.Key, pair => pair.Value); // now do the totals table TableRow _tblItemsNameRow = new TableHeaderRow(); TableRow _tblItemsTotalRow = new TableRow(); // add headers TableHeaderCell _tblItemHdr1 = new TableHeaderCell(); _tblItemHdr1.Text = "Item"; _tblItemHdr1.Font.Bold = true; _tblItemsNameRow.Cells.Add(_tblItemHdr1); TableCell _tblItemHdr2 = new TableCell(); _tblItemHdr2.Text = "Total"; _tblItemHdr2.Font.Bold = true; _tblItemsTotalRow.Cells.Add(_tblItemHdr2); // for each item in the totals table add a column and value foreach (KeyValuePair <string, ItemTotals> _pair in sortedItemTotals) { // _tblItemsNameRow.Cells.Add(new TableCell()); // add the description TableHeaderCell _tblCellItemDesc = new TableHeaderCell(); _tblCellItemDesc.Text = _pair.Value.ItemDesc; _tblCellItemDesc.Font.Bold = true; _tblItemsNameRow.Cells.Add(_tblCellItemDesc); // add the total TableCell _tblCellItemTotal = new TableCell(); _tblCellItemTotal.Text = String.Format("{0:0.00}", _pair.Value.TotalsQty); _tblCellItemTotal.HorizontalAlign = System.Web.UI.WebControls.HorizontalAlign.Right; _tblItemsTotalRow.Cells.Add(_tblCellItemTotal); } //now add Theme total rows. tblTotals.Rows.Add(_tblItemsNameRow); tblTotals.Rows.Add(_tblItemsTotalRow); if (pPrintForm) { tblTotals.CssClass = tblTotals.CssClass + " small"; } else { // now add the drop down list items for delivery person bool bShowDeilveryBy = ListOfDeliveryBy.Count > 1; ddlDeliveryBy.Items.Clear(); ddlDeliveryBy.Visible = bShowDeilveryBy; lblDeliveryBy.Visible = bShowDeilveryBy; if (bShowDeilveryBy) { ddlDeliveryBy.Items.Add(new ListItem { Text = "--- All ---", Value = "%", Selected = true }); foreach (KeyValuePair <string, string> _deliveryByPair in ListOfDeliveryBy) { ddlDeliveryBy.Items.Add(new ListItem { Text = _deliveryByPair.Value, Value = _deliveryByPair.Key }); } } } upnlDeliveryItems.Update(); }
void BuildDeliveryTable(OleDbDataReader oleData, bool pPrintForm) { // delete the old data while (1 < tblDeliveries.Rows.Count) { tblDeliveries.Rows.RemoveAt(1); } tblTotals.Rows.Clear(); //casting null check int iSortOrder; // string lists to store the company names and the items to be delivered to them List <deliveryItems> deliveryDetailsList = new List <DeliverySheet.deliveryItems>(); // Delivery Persons list, we use a dictionary for easy of use SortedDictionary <string, string> ListOfDeliveryBy = new SortedDictionary <string, string>(); // The Totals Table stuff string _strItemID = ""; string _strItemDesc = ""; string _strTotalItemDesc = ""; bool _isUnknownClient = false; Dictionary <string, ItemTotals> sumItemTotals = new Dictionary <string, ItemTotals>(); // how many items will be deliverred, this will be the counter int numDeliveryItems = 0; // read the data from the SQL query and add data to delivery list while (oleData.Read()) { _isUnknownClient = false; // for each line read the data, and then if the compnay name has changed add that line to the table deliveryItems _tDeliveryItem = new deliveryItems(); _tDeliveryItem.ContactID = oleData["CustomerId"].ToString(); // ID is used for link to ediot of customer _tDeliveryItem.ContactCompany = oleData["CoName"].ToString(); // do some basic manipluation of names depending on what is selected, add notes. if (_tDeliveryItem.ContactCompany.StartsWith("ZZName")) { // add the ZZname but check if there is a ":" which is the end of name delimiter _tDeliveryItem.ContactID = CONST_IS_ZZNAME; _isUnknownClient = true; var _strNotes = oleData["Notes"].ToString(); if (_strNotes.Contains(":")) { _strNotes = _strNotes.Remove(_strNotes.IndexOf(":")).Trim(); } _tDeliveryItem.ContactCompany = CONST_ZZNAME_PREFIX + " " + _strNotes; } else if (_tDeliveryItem.ContactCompany.StartsWith("Stock")) { _tDeliveryItem.ContactCompany = "STK: " + oleData["Notes"].ToString(); } // if the notes have a "+" to start with append that to the name if (oleData["Notes"].ToString().StartsWith("+")) { _tDeliveryItem.ContactCompany += "[" + oleData["Notes"].ToString() + "]"; } // Check if the deliver is done, and mark it so if (Boolean.Parse(oleData["Done"].ToString())) { _tDeliveryItem.ContactCompany = "<b>DONE</b>-> " + _tDeliveryItem.ContactCompany; } // get delivery person, and store them for the ddl only if not printing if (!pPrintForm) { if (!ListOfDeliveryBy.ContainsKey(oleData["ToBeDeliveredBy"].ToString())) { ListOfDeliveryBy[oleData["ToBeDeliveredBy"].ToString()] = oleData["Abreviation"].ToString(); } /// add url _tDeliveryItem.OrderDetailURL = ResolveUrl("~/Pages/OrderDetail.aspx") + "?" + String.Format("CustomerID={0}&DeliveryDate={1:d}&Notes={2}", HttpContext.Current.Server.UrlEncode(oleData["CustomerID"].ToString()), oleData["RequiredByDate"], HttpContext.Current.Server.UrlEncode(oleData["Notes"].ToString())); } // add delviery details _tDeliveryItem.Details = String.Format("{0:d}, {1}", oleData["RequiredByDate"], oleData["Abreviation"]); // get the item Description, may need to do some replaceme3nt calculation here _strItemID = oleData["ItemTypeID"].ToString(); _strItemDesc = ((oleData["ItemShortName"].ToString().Length > 0) ? oleData["ItemShortName"].ToString() : oleData["ItemDesc"].ToString()); _strTotalItemDesc = _strItemDesc; // check to see if item available if not added error colours if (!Boolean.Parse(oleData["ItemEnabled"].ToString())) { _strItemDesc = "<span style='background-color: RED; color: WHITE'>SOLD OUT</span> " + _strItemDesc; _strTotalItemDesc = ">" + _strTotalItemDesc + "<"; } // now add description if required iSortOrder = (oleData["SortOrder"] == DBNull.Value) ? 0 : (int)oleData["SortOrder"]; if (iSortOrder == CONST_NEEDDESCRIPTION_SORT_ORDER) { // if we are already use the notes field for name, check if there is a ":" seperator, and then only use what is after var _strNotes = oleData["Notes"].ToString(); if ((_isUnknownClient) && (_strNotes.Contains(":"))) { _strNotes = _strNotes.Substring(_strNotes.IndexOf(":") + 1).Trim(); } _strItemDesc += ": " + _strNotes; } if (oleData["PackDesc"].ToString().Length > 0) { _tDeliveryItem.Items = String.Format("<span style='background-color:{0}; padding-top: 1px; padding-bottom:2px'>{1}X{2} ({3})</span>", oleData["BGColour"], oleData["QuantityOrdered"], _strItemDesc, oleData["PackDesc"]); } else { _tDeliveryItem.Items = String.Format("<span style='background-color:{0}'>{1}X{2}</span>", oleData["BGColour"], oleData["QuantityOrdered"], _strItemDesc); } // if Item needs to be added and ID exists the increment the total, otherwise add new item if (iSortOrder != CONST_NEEDDESCRIPTION_SORT_ORDER) { if (sumItemTotals.ContainsKey(_strItemID)) { sumItemTotals[_strItemID].TotalsQty += Convert.ToDouble(oleData["QuantityOrdered"]); } else { // Remove notes if (_strItemDesc.Contains(":")) { _strItemDesc = _strItemDesc.Remove(_strItemDesc.IndexOf(":")); } sumItemTotals[_strItemID] = new ItemTotals { ItemID = _strItemID, ItemDesc = _strTotalItemDesc, TotalsQty = Convert.ToDouble(oleData["QuantityOrdered"].ToString()), ItemOrder = (oleData["SortOrder"] == DBNull.Value) ? 0 : Convert.ToInt32(oleData["SortOrder"].ToString()) }; } } // add to list of deliveries deliveryDetailsList.Add(_tDeliveryItem); // increment deliveries now numDeliveryItems++; } oleData.Close(); // Do a bubble sort on the ZZnames, so that they are all together for (int idx1 = 0; idx1 < numDeliveryItems; idx1++) { if (deliveryDetailsList[idx1].ContactCompany.StartsWith(CONST_ZZNAME_PREFIX)) { for (int idx2 = idx1 + 2; idx2 < numDeliveryItems; idx2++) { if (deliveryDetailsList[idx2].ContactCompany.Equals(deliveryDetailsList[idx1].ContactCompany)) { // this equals the last one so move it to just below the last one deliveryItems thisItem = deliveryDetailsList[idx2]; deliveryDetailsList.RemoveAt(idx2); deliveryDetailsList.Insert(idx1 + 1, thisItem); } } } } // sort the deliveries to make sure that we have all the company names one after the other int _items = 0; string _strURL = ""; while (_items < numDeliveryItems) { TableRow _tblRow = new TableRow(); // now add details // add delivery and date TableCell _tblCellBy = new TableCell(); _tblCellBy.Text = deliveryDetailsList[_items].Details; if (pPrintForm) { _tblCellBy.Font.Size = FontUnit.XSmall; _tblCellBy.Text = _tblCellBy.Text.Remove(0, _tblCellBy.Text.IndexOf(",") + 1); } else // add a hyoerlink to edit { _tblCellBy.Text = String.Format("<a class='plain' href='{0}'>{1}</a>", deliveryDetailsList[_items].OrderDetailURL, _tblCellBy.Text.Trim()); } _tblRow.Cells.Add(_tblCellBy); // add company name and a link to the customer edit form. TableCell _tblCell = new TableCell(); if ((pPrintForm) || (deliveryDetailsList[_items].ContactID == CONST_IS_ZZNAME)) { _tblCell.Text = deliveryDetailsList[_items].ContactCompany; } else { _tblCell.Text = String.Format("<a href='./CustomerDetails.aspx?ID={0}&'>{1}</a>", deliveryDetailsList[_items].ContactID, deliveryDetailsList[_items].ContactCompany); } _tblRow.Cells.Add(_tblCell); // Add received and signed by _tblRow.Cells.Add(new TableCell()); _tblRow.Cells.Add(new TableCell()); // Now the items TableCell _tblCellItems = new TableCell(); _strURL = String.Format("<a href='{0}'>Edit</a>", deliveryDetailsList[_items].OrderDetailURL); do { if (_tblCellItems.Text.Length == 0) { _tblCellItems.Text = deliveryDetailsList[_items].Items.ToString(); } else { _tblCellItems.Text = _tblCellItems.Text + "; " + deliveryDetailsList[_items].Items.ToString(); } _items++; } while ((_items < numDeliveryItems) && (deliveryDetailsList[_items - 1].ContactCompany == deliveryDetailsList[_items].ContactCompany)); // add items _tblRow.Cells.Add(_tblCellItems); // Add in stock _tblRow.Cells.Add(new TableCell()); // now add edit url if (!pPrintForm) { _tblRow.Cells.Add(new TableCell { Text = _strURL }); } tblDeliveries.Rows.Add(_tblRow); } // while we have delivery items //Display the totals table now Dictionary <string, ItemTotals> sortedItemTotals = (from entry in sumItemTotals orderby entry.Value.ItemOrder ascending select entry).ToDictionary(pair => pair.Key, pair => pair.Value); // now do the totals table TableRow _tblItemsNameRow = new TableHeaderRow(); TableRow _tblItemsTotalRow = new TableRow(); // add headers TableHeaderCell _tblItemHdr1 = new TableHeaderCell(); _tblItemHdr1.Text = "Item"; _tblItemHdr1.Font.Bold = true; _tblItemsNameRow.Cells.Add(_tblItemHdr1); TableCell _tblItemHdr2 = new TableCell(); _tblItemHdr2.Text = "Total"; _tblItemHdr2.Font.Bold = true; _tblItemsTotalRow.Cells.Add(_tblItemHdr2); // for each item in the totals table add a column and value foreach (KeyValuePair <string, ItemTotals> _pair in sortedItemTotals) { // _tblItemsNameRow.Cells.Add(new TableCell()); // add the description TableHeaderCell _tblCellItemDesc = new TableHeaderCell(); _tblCellItemDesc.Text = _pair.Value.ItemDesc; _tblCellItemDesc.Font.Bold = true; _tblItemsNameRow.Cells.Add(_tblCellItemDesc); // add the total TableCell _tblCellItemTotal = new TableCell(); _tblCellItemTotal.Text = String.Format("{0:0.00}", _pair.Value.TotalsQty); _tblCellItemTotal.HorizontalAlign = System.Web.UI.WebControls.HorizontalAlign.Right; _tblItemsTotalRow.Cells.Add(_tblCellItemTotal); } //now add Theme total rows. tblTotals.Rows.Add(_tblItemsNameRow); tblTotals.Rows.Add(_tblItemsTotalRow); if (pPrintForm) { tblTotals.CssClass = tblTotals.CssClass + " small"; } else { // now add the drop down list items for delivery person bool bShowDeilveryBy = ListOfDeliveryBy.Count > 1; ddlDeliveryBy.Items.Clear(); ddlDeliveryBy.Visible = bShowDeilveryBy; lblDeliveryBy.Visible = bShowDeilveryBy; if (bShowDeilveryBy) { ddlDeliveryBy.Items.Add(new ListItem { Text = "--- All ---", Value = "%", Selected = true }); foreach (KeyValuePair <string, string> _deliveryByPair in ListOfDeliveryBy) { ddlDeliveryBy.Items.Add(new ListItem { Text = _deliveryByPair.Value, Value = _deliveryByPair.Key }); } } } upnlDeliveryItems.Update(); }