protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { NorthwindAccess.FillCustomersDDL(_DDL_Comapnies, ""); } }
/// <summary> /// Updates the DDL with filter /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void CustBut_Click(object sender, EventArgs e) { if (!string.IsNullOrEmpty(CustTB.Text)) { NorthwindAccess.FillCustomersDDL(CustTB.Text, CustDDL); } }
protected void _DDL_Comapnies_Index(object sender, EventArgs e) { if (_DDL_Comapnies.SelectedIndex < 1) { return; } Table1.Rows.Clear(); List <List <string> > Data = NorthwindAccess.GetProducts(_DDL_Comapnies.SelectedValue); TableHeaderRow THR = new TableHeaderRow(); foreach (string s in Data[0]) { TableHeaderCell THC = new TableHeaderCell(); THC.Text = s; THC.Font.Size = 50; THR.BorderStyle = BorderStyle.Solid; THR.Cells.Add(THC); } THR.Height = 50; THR.BackColor = System.Drawing.Color.Lavender; Table1.Rows.Add(THR); for (int i = 1; i < Data.Count; i++) { TableRow TR = new TableRow(); foreach (string s in Data[i]) { TableCell TC = new TableCell(); TC.Text = s; TC.BorderStyle = BorderStyle.Solid; TC.HorizontalAlign = HorizontalAlign.Center; TR.Cells.Add(TC); } Table1.Rows.Add(TR); } }
protected void ButtonInsertRecord_Click(object sender, EventArgs e) { short quantity; //If we don't get an OrderID or a number, just return if (TextBoxOrderIDInsert.Text.Length == 0 || !short.TryParse(TextBoxQuantity.Text, out quantity)) { return; } int OrderID, ProductID; try { //Get the integers for IDs OrderID = int.Parse(TextBoxOrderIDInsert.Text); ProductID = int.Parse(DropDownListProductList.SelectedValue); } catch { //Couldn't parse out the OrderID and the ProductID return; } //Insert the record and update the status bar LabelStatusInsert.Text = $"Inserted {NorthwindAccess.InsertOrderDetails(OrderID, ProductID,quantity)} records"; //Update the gridview GridViewOrderDetails.DataBind(); }
/// <summary> /// Update the gridview when the /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void SupplierDDL_SelectedIndexChanged(object sender, EventArgs e) { if (SupplierDDL.SelectedIndex <= 0) { return; } List <List <string> > results = NorthwindAccess.GetProducts(SupplierDDL.SelectedValue); if (results.Count <= 0) { return; } TableHeaderRow header = new TableHeaderRow(); results[0].ForEach(x => header.Cells.Add(new TableHeaderCell() { Text = x })); ProductT.Rows.Add(header); foreach (List <string> item in results.Skip(1)) { TableRow row = new TableRow(); item.ForEach(x => row.Cells.Add(new TableCell() { Text = x })); ProductT.Rows.Add(row); } }
/// <summary> /// Page load handler, will make sure DDL has all customers /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { NorthwindAccess.FillCustomersDDL("", CustDDL); } else { } }
protected void FillDDL(DropDownList ddl, string sFilter) { ddl.AppendDataBoundItems = true; ddl.DataSource = NorthwindAccess.GetSuppliersSDS(sFilter); // binds the SDS ddl.DataTextField = "CompanyName"; ddl.DataValueField = "SupplierID"; ddl.Items.Clear(); // clear any existing items ddl.DataBind(); ddl.Items.Insert(0, new ListItem("Now Pick a Company form [" + ddl.Items.Count + "]", "")); ddl.AutoPostBack = true; }
private void FillDDL(DropDownList ddl, string filter) { ddl.AppendDataBoundItems = true; ddl.DataSource = NorthwindAccess.GetSupplierSDS(filter); // binds the SDS ddl.DataTextField = "CompanyName"; ddl.DataValueField = "SupplierID"; ddl.Items.Clear(); // clear any existing items ddl.DataBind(); ddl.Items.Insert(0, new ListItem($"Please Pick a Company from [{ddl.Items.Count}]", "")); ddl.AutoPostBack = true; }
protected void _Bu_Insert_Click(object sender, EventArgs e) { int OID; short Qty; if (!(int.TryParse(_TB_OrderID.Text, out OID) && short.TryParse(_TB_Qty.Text, out Qty))) { return; } _La_Status2.Text = NorthwindAccess.InsertOrderDetails(OID, int.Parse(_DDL_Pro.SelectedValue), Qty); _GW_.DataBind(); }
protected void _DDL_Comapnies_Index(object sender, EventArgs e) { if (_DDL_Comapnies.SelectedIndex < 1) { return; } _GW_.DataSource = NorthwindAccess.CustomerCategorySummary(_DDL_Comapnies.SelectedValue); _GW_.DataBind(); _GW_.HeaderStyle.BackColor = System.Drawing.Color.Black; _GW_.HeaderStyle.ForeColor = System.Drawing.Color.White; _GW_.HeaderStyle.Font.Size = 50; }
/// <summary> /// Fills the DDL on a filter input /// </summary> /// <param name="input"></param> protected void FillDropList(string input) { SqlDataSource result = NorthwindAccess.GetSuppliersSDS(input); SupplierDDL.AppendDataBoundItems = true; SupplierDDL.DataSource = result; SupplierDDL.DataTextField = "CompanyName"; SupplierDDL.DataValueField = "SupplierID"; SupplierDDL.Items.Clear(); SupplierDDL.DataBind(); SupplierDDL.Items.Insert(0, new ListItem("Now pick a company from[" + SupplierDDL.Items.Count + "]")); SupplierDDL.AutoPostBack = true; }
/// <summary> /// When the selected index changes, update GV, make sure the first index clears the GV /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void CustDDL_SelectedIndexChanged(object sender, EventArgs e) { if (CustDDL.SelectedIndex > 0) { CustGV.DataSource = NorthwindAccess.CustomerCategorySummary(CustDDL.SelectedValue); CustGV.DataBind(); } else { CustGV.DataSource = null; CustGV.DataBind(); } }
protected void _Bu_Delete_Click(object sender, EventArgs e) { if (_GW_.SelectedIndex == -1) { _La_Status.Text = "Status : Failed No index was selected"; return; } int OID = int.Parse(_GW_.SelectedDataKey.Values["OrderID"].ToString()); int PID = int.Parse(_GW_.SelectedDataKey.Values["ProductID"].ToString()); _La_Status.Text = "Status : " + NorthwindAccess.DeleteOrderDetails(OID, PID); _GW_.DataBind(); _GW_.SelectedIndex = -1; }
protected void ButtonDelete_Click(object sender, EventArgs e) { //Get the orderID and productID of the selected item int orderID, productID; try { orderID = int.Parse(GridViewOrderDetails.SelectedDataKey.Values["OrderID"].ToString()); productID = int.Parse(GridViewOrderDetails.SelectedDataKey.Values["ProductID"].ToString()); } catch { return; } //Delete the row LabelStatus.Text = NorthwindAccess.DeleteOrderDetails(orderID, productID); //Update the gridview GridViewOrderDetails.DataBind(); }
/// <summary> /// Handle insertions, calls northwindaccess static function, handles errors in case it catches an exception /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void Part2Button_Click(object sender, EventArgs e) { if (!string.IsNullOrEmpty(Part2TBOrderID.Text) && !string.IsNullOrEmpty(Part2TBQuantity.Text)) { try { Part2Label.Text = "Status: " + NorthwindAccess.InsertOrderDetails(int.Parse(Part2TBOrderID.Text), int.Parse(Part2DDL.SelectedValue), short.Parse(Part2TBQuantity.Text)); Part1TB.Text = Part2TBOrderID.Text; Part1GV.DataBind(); } catch (Exception error) { Part2Label.Text = "Status " + error.Message; } } }
protected void DropDownListSuppliers_SelectedIndexChanged(object sender, EventArgs e) { BuildTable(NorthwindAccess.GetProducts(DropDownListSuppliers.SelectedValue)); }
protected void DropDownListCustomers_SelectedIndexChanged(object sender, EventArgs e) { GridViewCustomerCategory.DataSource = NorthwindAccess.CustomerCategorySummary(DropDownListCustomers.SelectedValue); GridViewCustomerCategory.DataBind(); }
protected void _Bu_Filter_Click(object sender, EventArgs e) { NorthwindAccess.FillCustomersDDL(_DDL_Comapnies, _TB_Filter.Text); }