コード例 #1
0
        protected void accAddDetailsButton_Click(object sender, EventArgs e)
        {
            CustomersAccInfoTbl _NewAccInfo = GetAccDataFromForm();

            if (_NewAccInfo.CustomersAccInfoID == 0) // it should be otherwise this button should have been disabled
            {
                string _err = _NewAccInfo.Insert(_NewAccInfo);

                if (string.IsNullOrEmpty(_err))
                {
                    showMessageBox _msg = new showMessageBox(this.Page, "Insert", "Customer Account Info Inserted");
                    accAddDetailsButton.Enabled = false;
                    accUpdateButton.Enabled     = true;
                    dvCustomersAccInfoUpdatePanel.Update();
                }
                else
                {
                    // we got an error, have they been added by someone else?  The the Customer ID exists.
                    CustomersAccInfoTbl _CustomersAccInfo = _NewAccInfo.GetByCustomerID(_NewAccInfo.CustomerID);
                    if (!_CustomersAccInfo.CustomersAccInfoID.Equals(0))
                    {
                        _NewAccInfo.CustomersAccInfoID = _CustomersAccInfo.CustomersAccInfoID;
                        UpdateAccountInfo(_NewAccInfo);
                    }
                    else
                    {
                        showMessageBox _msg = new showMessageBox(this.Page, "Insert", "Error inserting: " + _err);
                    }
                }
            }
        }
コード例 #2
0
        protected void accPaymentTermsDropDownList_DataBound(object sender, EventArgs e)
        {
            DropDownList _list = (DropDownList)sender;

            if (_list != null)
            {
                if (string.IsNullOrEmpty(_list.SelectedValue))
                {
                    long _CustID = GetCustomerIDFromRequest();
                    if (_CustID > 0)
                    {
                        CustomersAccInfoTbl _CustomerPaymentTerms = new CustomersAccInfoTbl();
                        _CustomerPaymentTerms.GetByPaymentTypeIDByCustomerID(_CustID);
                    }
                    else
                    {
                        _list.SelectedIndex = 1; // set it to first option
                    }
                }
                //if (_list.Items.FindByValue(_list.SelectedValue) == null)
                //{
                //  if (_list.Items.Count > 0)
                //    _list.SelectedValue = _list.Items[0].Value;
                //}
            }
        }
コード例 #3
0
        private void PutAccDataOnForm(long pCustomerID)
        {
            CustomersAccInfoTbl _CustomersAccInfo = new CustomersAccInfoTbl();

            if (pCustomerID > 0)
            {
                _CustomersAccInfo = _CustomersAccInfo.GetByCustomerID(pCustomerID);
                pCustomerID       = _CustomersAccInfo.CustomerID; // if 0 does not exist
            }

            string[] _UserRoles = Roles.GetRolesForUser();

            bool _EnableEdit = !((Roles.IsUserInRole("repair")) && (_UserRoles.Length == 1)); // they are only in repair

            if ((_CustomersAccInfo.CustomersAccInfoID == 0))
            {
                accAddDetailsButton.Enabled = _EnableEdit; // records are not there so can insert
                accUpdateButton.Enabled     = false;
            }
            else
            {
                accAddDetailsButton.Enabled = false; // cannot insert records already there
                accUpdateButton.Enabled     = _EnableEdit;

                PlaceAccDataOnForm(_CustomersAccInfo);
            }
            dvCustomersAccInfoUpdatePanel.Update();
        }
コード例 #4
0
 private void PlaceAccDataOnForm(CustomersAccInfoTbl pCustomersAccInfo)
 {
     accFullCoNameTextBox.Text    = pCustomersAccInfo.FullCoName;
     accCustomerVATNoTextBox.Text = pCustomersAccInfo.CustomerVATNo;
     accInvoiceTypesDropDownList.SelectedValue = pCustomersAccInfo.InvoiceTypeID.ToString();
     accRequiresPurchOrderCheckBox.Checked     = pCustomersAccInfo.RequiresPurchOrder;
     accEnabledCheckBox.Checked  = pCustomersAccInfo.Enabled;
     accBillAddr1TextBox.Text    = pCustomersAccInfo.BillAddr1;
     accBillAddr2TextBox.Text    = pCustomersAccInfo.BillAddr2;
     accBillAddr3TextBox.Text    = pCustomersAccInfo.BillAddr3;
     accBillAddr4TextBox.Text    = pCustomersAccInfo.BillAddr4;
     accBillAddr5TextBox.Text    = pCustomersAccInfo.BillAddr5;
     accShipAddr1TextBox.Text    = pCustomersAccInfo.ShipAddr1;
     accShipAddr2TextBox.Text    = pCustomersAccInfo.ShipAddr2;
     accShipAddr3TextBox.Text    = pCustomersAccInfo.ShipAddr3;
     accShipAddr4TextBox.Text    = pCustomersAccInfo.ShipAddr4;
     accShipAddr5TextBox.Text    = pCustomersAccInfo.ShipAddr5;
     accFirstNameTextBox.Text    = pCustomersAccInfo.AccFirstName;
     accLastNameTextBox.Text     = pCustomersAccInfo.AccLastName;
     getaccAccEmailTextBox.Text  = pCustomersAccInfo.AccEmail;
     accAltFirstNameTextBox.Text = pCustomersAccInfo.AltAccFirstName;
     accAltLastNameTextBox.Text  = pCustomersAccInfo.AltAccLastName;
     accAltEmailTextBox.Text     = pCustomersAccInfo.AltAccEmail;
     accPaymentTermsDropDownList.SelectedValue = pCustomersAccInfo.PaymentTermID.ToString();
     accPriceLevelsDropDownList.SelectedValue  = pCustomersAccInfo.PriceLevelID.ToString();
     accRegNoTextBox.Text         = pCustomersAccInfo.RegNo;
     accLimitTextBox.Text         = string.Format("{0:0.00}", pCustomersAccInfo.Limit);
     accBankAccNoTextBox.Text     = pCustomersAccInfo.BankAccNo;
     accBankBranchTextBox.Text    = pCustomersAccInfo.BankBranch;
     accNotesTextBox.Text         = pCustomersAccInfo.Notes;
     CustomersAccInfoIDLabel.Text = pCustomersAccInfo.CustomersAccInfoID.ToString();
 }
コード例 #5
0
        protected void accUpdateButton_Click(object sender, EventArgs e)
        {
            /* was try to sort out update the accinfo id was not being used so we nede to reimport and deliver the data asn use new data.*/

            CustomersAccInfoTbl _UpdatedAccInfo = GetAccDataFromForm();

            UpdateAccountInfo(_UpdatedAccInfo);
        }
コード例 #6
0
        protected void btnCopy2AccInfo_Click(object sender, EventArgs e)
        {
            CustomersTbl        _customerData     = GetDataFromForm();
            CustomersAccInfoTbl _CustomersAccInfo = CopyCompanyData2AccInfo(_customerData);

            PlaceAccDataOnForm(_CustomersAccInfo);
            uppnlTabContainer.Update();
            dvCustomersAccInfoUpdatePanel.Update();
        }
コード例 #7
0
        protected void btnInsert_Click(object sender, EventArgs e)
        {
            string       _ErrorStr     = String.Empty;
            CustomersTbl _customerData = GetDataFromForm();

            //CustomersTbl _ctd = new CustomersTbl();
            //      ClientScriptManager _csm = Page.ClientScript;

            if (_customerData.InsertCustomer(_customerData, ref _ErrorStr))
            {
                _customerData = _customerData.GetCustomerByName(_customerData.CompanyName);

                if (_customerData.CustomerID > 0)
                {
                    CustomersAccInfoTbl _CustomersAccInfo = CopyCompanyData2AccInfo(_customerData);

                    _CustomersAccInfo.Enabled = true;

                    string _msg = _CustomersAccInfo.Insert(_CustomersAccInfo);
                    if (string.IsNullOrEmpty(_msg))
                    {
                        showMessageBox _showMsg = new showMessageBox(this.Page, "Insert", "Customer account info added, please edit.");

                        Response.Redirect(String.Format("{0}?{1}={2}&{3}=Y", Page.ResolveUrl("~/Pages/CustomerDetails.aspx"), CONST_URL_REQUEST_CUSTOMERID,
                                                        _customerData.CustomerID, CONST_URL_REQUEST_CUSTOMERACCFOCUS));

                        /*
                         *          SetButtonStatus(true);
                         *          tabcCustomer.Visible = true;
                         *          tabcCustomer.ActiveTabIndex = 0;
                         *          lblCustomerID.Text = _CustomersAccInfo.CustomerID.ToString();
                         *          PlaceAccDataOnForm(_CustomersAccInfo);
                         *          this.Page.SetFocus(accFullCoNameTextBox);
                         *          uppnlTabContainer.Update();
                         */
                    }
                    else
                    {
                        showMessageBox _showErrMsg = new showMessageBox(this.Page, "Insert", "Error inserting customer account info");
                    }

                    ltrlStatus.Text = "Customer Added";
                }
                else
                {
                    string _ScriptToRun = "redirect('" + String.Format("{0}?CompanyName={1}", Page.ResolveUrl("~/Pages/Customers.aspx"), _customerData.CompanyName) + "');";
                    ScriptManager.RegisterStartupScript(Page, Page.GetType(), "CustomerInserted", _ScriptToRun, true);
                }
            }
            else
            {
                //        _msgBox.ShowSuccess("Error " + _ErrorStr + ". Customer not added.");

                ltrlStatus.Text = "ERROR: " + _ErrorStr;
            }
        }
コード例 #8
0
        protected void UpdateAccountInfo(CustomersAccInfoTbl pUpdateAccInfo)
        {
            string _err = pUpdateAccInfo.Update(pUpdateAccInfo);

            if (string.IsNullOrEmpty(_err))
            {
                showMessageBox _msg = new showMessageBox(this.Page, "Update", "Customer Account Info Updated");
            }
            else
            {
                showMessageBox _msg = new showMessageBox(this.Page, "Update", "Error updating: " + _err);
            }
        }
コード例 #9
0
        private CustomersAccInfoTbl GetAccDataFromForm()
        {
            CustomersAccInfoTbl _CustomersAccInfo = new CustomersAccInfoTbl();

            if (!string.IsNullOrEmpty(CustomersAccInfoIDLabel.Text))
            {
                _CustomersAccInfo.CustomersAccInfoID = StringToInt32(CustomersAccInfoIDLabel.Text);
            }
            _CustomersAccInfo.CustomerID         = StringToInt64(CompanyIDLabel.Text);
            _CustomersAccInfo.FullCoName         = accFullCoNameTextBox.Text;
            _CustomersAccInfo.CustomerVATNo      = accCustomerVATNoTextBox.Text;
            _CustomersAccInfo.InvoiceTypeID      = StringToInt32(accInvoiceTypesDropDownList.SelectedValue);
            _CustomersAccInfo.RequiresPurchOrder = accRequiresPurchOrderCheckBox.Checked;
            _CustomersAccInfo.Enabled            = accEnabledCheckBox.Checked;
            _CustomersAccInfo.BillAddr1          = accBillAddr1TextBox.Text;
            _CustomersAccInfo.BillAddr2          = accBillAddr2TextBox.Text;
            _CustomersAccInfo.BillAddr3          = accBillAddr3TextBox.Text;
            _CustomersAccInfo.BillAddr4          = accBillAddr4TextBox.Text;
            _CustomersAccInfo.BillAddr5          = accBillAddr5TextBox.Text;
            _CustomersAccInfo.ShipAddr1          = accShipAddr1TextBox.Text;
            _CustomersAccInfo.ShipAddr2          = accShipAddr2TextBox.Text;
            _CustomersAccInfo.ShipAddr3          = accShipAddr3TextBox.Text;
            _CustomersAccInfo.ShipAddr4          = accShipAddr4TextBox.Text;
            _CustomersAccInfo.ShipAddr5          = accShipAddr5TextBox.Text;
            _CustomersAccInfo.AccFirstName       = accFirstNameTextBox.Text;
            _CustomersAccInfo.AccLastName        = accLastNameTextBox.Text;
            _CustomersAccInfo.AccEmail           = accAccEmailTextBox.Text;
            _CustomersAccInfo.AltAccFirstName    = accAltFirstNameTextBox.Text;
            _CustomersAccInfo.AltAccLastName     = accAltLastNameTextBox.Text;
            _CustomersAccInfo.AltAccEmail        = accAltEmailTextBox.Text;
            _CustomersAccInfo.PaymentTermID      = StringToInt32(accPaymentTermsDropDownList.SelectedValue);
            _CustomersAccInfo.PriceLevelID       = StringToInt32(accPriceLevelsDropDownList.SelectedValue);
            _CustomersAccInfo.RegNo      = accRegNoTextBox.Text;
            _CustomersAccInfo.Limit      = StringToDouble(accLimitTextBox.Text);
            _CustomersAccInfo.BankAccNo  = accBankAccNoTextBox.Text;
            _CustomersAccInfo.BankBranch = accBankBranchTextBox.Text;
            _CustomersAccInfo.Notes      = accNotesTextBox.Text;
            return(_CustomersAccInfo);
        }
コード例 #10
0
        protected CustomersAccInfoTbl CopyCompanyData2AccInfo(CustomersTbl pCustomer)
        {
            CustomersAccInfoTbl _CustomersAccInfo = new CustomersAccInfoTbl();

            _CustomersAccInfo.CustomerID = pCustomer.CustomerID;

            string[] _BillAddress = pCustomer.BillingAddress.Split(new[] { ",", ";" }, StringSplitOptions.RemoveEmptyEntries);

            _CustomersAccInfo.BillAddr1 = (_BillAddress.Length > 0) ? _BillAddress[0].Trim() : string.Empty;
            _CustomersAccInfo.BillAddr2 = (_BillAddress.Length > 1) ? _BillAddress[1].Trim() : string.Empty;
            _CustomersAccInfo.BillAddr3 = (_BillAddress.Length > 2) ? _BillAddress[2].Trim() : string.Empty;
            for (int i = 3; i < _BillAddress.Length; i++)
            {
                _CustomersAccInfo.BillAddr4 = _BillAddress[i].Trim(); //add all the rest to the last line
                if (i + 1 < _BillAddress.Length)
                {
                    _CustomersAccInfo.BillAddr4 += ";";
                }
            }
            _CustomersAccInfo.BillAddr5 = pCustomer.PostalCode;

            _CustomersAccInfo.ShipAddr1 = _CustomersAccInfo.BillAddr1;
            _CustomersAccInfo.ShipAddr2 = _CustomersAccInfo.BillAddr2;
            _CustomersAccInfo.ShipAddr3 = _CustomersAccInfo.BillAddr3;
            _CustomersAccInfo.ShipAddr4 = _CustomersAccInfo.BillAddr4;
            _CustomersAccInfo.ShipAddr5 = _CustomersAccInfo.BillAddr5;

            _CustomersAccInfo.AccEmail        = pCustomer.EmailAddress;
            _CustomersAccInfo.AltAccEmail     = pCustomer.AltEmailAddress;
            _CustomersAccInfo.FullCoName      = pCustomer.CompanyName;
            _CustomersAccInfo.AccFirstName    = pCustomer.ContactFirstName;
            _CustomersAccInfo.AccLastName     = pCustomer.ContactLastName;
            _CustomersAccInfo.AltAccFirstName = pCustomer.ContactAltFirstName;
            _CustomersAccInfo.AltAccLastName  = pCustomer.ContactAltLastName;

            return(_CustomersAccInfo);
        }
コード例 #11
0
//    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 += "&nbsp<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 += "&nbsp<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();
        }