private void LoadJob() { int jobID = int.Parse(Request.QueryString["jID"]); Orchestrator.Entities.Job job = null; Orchestrator.Facade.IJob facJob = new Orchestrator.Facade.Job(); job = facJob.GetJob(jobID); Facade.IBusinessType facBusinessType = new Facade.BusinessType(); Entities.BusinessType businessType = facBusinessType.GetForBusinessTypeID(job.BusinessTypeID); if (businessType != null) { lblBusinessType.Text = businessType.Description; } else { lblBusinessType.Text = "No Business Type Set"; } DataSet dsTypes = facBusinessType.GetAll(); cboBusinessType.DataSource = dsTypes; cboBusinessType.DataTextField = "Description"; cboBusinessType.DataValueField = "BusinessTypeID"; cboBusinessType.DataBind(); if (businessType != null) { cboBusinessType.FindItemByValue(businessType.BusinessTypeID.ToString()).Selected = true; this.CurrentBusinessTypeID = businessType.BusinessTypeID; } }
/// <summary> /// Offer the user creating the job a choice of which business type the job should be. /// The default value is the business type which has the most pallets (based on the /// individual pallet count and business type of each order being added to the job). /// </summary> /// <param name="orders">The data set containing the order information.</param> private void ConfigureBusinessTypeChoices(DataSet orders) { // Clear the current business type options down. cboBusinessType.ClearSelection(); cboBusinessType.Items.Clear(); // Store a list of key value pairs that represents the total pallets involved for each business type. // In each item in the list the Key is the Business Type ID, and the Value is the pallet count for that // business type. List <KeyValuePair <int, int> > btCounts = new List <KeyValuePair <int, int> >(); if (orders != null && orders.Tables.Count > 0 && orders.Tables[0] != null) { foreach (DataRow order in orders.Tables[0].Rows) { int businessTypeID = (int)order["BusinessTypeID"]; int palletCount = (int)order["NoPallets"]; // The business type has already been encountered, increase the pallet count. // As the value property is read only, we need to remove the item and then // cause it to be recreated with the new total. if (btCounts.Exists(btCount => btCount.Key == businessTypeID)) { palletCount += btCounts.Find(btCount => btCount.Key == businessTypeID).Value; btCounts.RemoveAll(btCount => btCount.Key == businessTypeID); } // Record the entry. btCounts.Add(new KeyValuePair <int, int>(businessTypeID, palletCount)); } // Sort the different key value pairs based on their value properties (i.e. their pallet count). // The result of the value compare is multiplied by -1 to effectively reverse the sort direction as: // -1 * -1 = 1 // 1 * -1 = -1 // 0 * -1 = 0 btCounts.Sort((x, y) => x.Value.CompareTo(y.Value) * -1); } // Create the dropdown items that match the business type information. Facade.IBusinessType facBusinessType = new Facade.BusinessType(); foreach (KeyValuePair <int, int> btCount in btCounts) { ListItem li = new ListItem(); li.Value = btCount.Key.ToString(); Entities.BusinessType businessType = facBusinessType.GetForBusinessTypeID(btCount.Key); li.Text = string.Format("{0} ({1})", businessType.Description, btCount.Value); cboBusinessType.Items.Add(li); } }