protected void btnSelectVendor_Click(object sender, EventArgs e) { if (VendorDDL.SelectedIndex == 0) { pnlInventory.Visible = false; pnlVendorResults.Visible = false; MessageUserControl.ShowInfo("Missing Data", "Select a vendor from the drop down list"); } else { MessageUserControl.TryRun(() => { pnlInventory.Visible = true; pnlVendorResults.Visible = true; txtComments.Text = "Comments"; // Vendors Controller to get orders VendorsController sysmgr = new VendorsController(); OrderDetailsController controller = new OrderDetailsController(); int vendorId = int.Parse(VendorDDL.SelectedValue); var info = sysmgr.Purchasing_Vendor_Get(vendorId); lblVendorName.Text = info.Name; lblVendorContact.Text = info.Contact; lblPhone.Text = info.Phone; //txtComments.Text = info.Orders.Comment; // Calculate Total CalculateTotal(controller, vendorId); var data = controller.Get_Active_Order(int.Parse(VendorDDL.SelectedValue)); OrderDetailsGridView.DataSource = data; OrderDetailsGridView.DataBind(); }, "Vendors Selection", "Active Order Retrieved"); } }
// THIS METHOD ADD PRODUCTS FROM INVENTORY TO ORDER protected void vendorCategoryCatalog_ItemCommand(object source, RepeaterCommandEventArgs e) { // Collect the required data fo the event OrderDetailsController sysmgr = new OrderDetailsController(); // obtain the productid Selected Inventory Item int productID = int.Parse(e.CommandArgument.ToString()); // obtain the CurrentActive Order ID int orderID = int.Parse(((Label)OrderDetailsGridView.Rows[0].FindControl("lblOrderID")).Text); //txtComments.Text = "Order ID, this is for testing purpose: " + int.Parse(orderID); // Qty should be equal to 1 at first int qty = 1; // Obtain the vendor ID int vendorID = int.Parse(VendorDDL.SelectedValue.ToString()); // Obtain the cost decimal itemPrice = 5; MessageUserControl.TryRun(() => { OrderDetailsController sysm = new OrderDetailsController(); sysm.Add_ProductToOrder(productID, orderID, qty, itemPrice); List <ListVendorOrders> datainfo = sysm.Get_Active_Order(vendorID); OrderDetailsGridView.DataSource = datainfo; OrderDetailsGridView.DataBind(); CalculateTotal(sysm, vendorID); }, "Adding to order", $"Product added to the order"); }
private void UpdateRowIfInEditMode() { if (OrderDetailsGridView.EditIndex >= 0) { // Force validation in case postback was caused by a control that doesn't cause it. Page.Validate(); if (Page.IsValid) { OrderDetailsGridView.UpdateRow(OrderDetailsGridView.EditIndex, false); } } }
protected void btnDelete_Click(object sender, EventArgs e) { int orderID = int.Parse(((Label)OrderDetailsGridView.Rows[0].FindControl("lblOrderID")).Text); MessageUserControl.TryRun(() => { OrderDetailsController controller = new OrderDetailsController(); int vendorId = int.Parse(VendorDDL.SelectedValue); controller.Delete_ProductItem(orderID); List <ListVendorOrders> datainfo = controller.Get_Active_Order(vendorId); OrderDetailsGridView.DataSource = datainfo; OrderDetailsGridView.DataBind(); CalculateTotal(controller, vendorId); }, "Deleting Order", "Order Has been Removed"); }
/// <summary> /// Handles the Order-Details GridView RowCommand event. /// Used to handle a couple of custom command to insert a new Order-Detail /// either from the footer or from the Empty template. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void OrderDetailsGridView_RowCommand(object sender, GridViewCommandEventArgs e) { // AddFromFooter command is issued by an Add button in the GridView's Footer. // To enable inserting from a GridView. if (e.CommandName == "AddFromFooter" && Page.IsValid) { OrderDetailEntity orderDetail = new OrderDetailEntity(); orderDetail.UnitPrice = Convert.ToDecimal(((TextBox)OrderDetailsGridView.FooterRow.FindControl("FooterUnitPrice")).Text); orderDetail.Quantity = Convert.ToInt16(((TextBox)OrderDetailsGridView.FooterRow.FindControl("FooterQuantity")).Text); orderDetail.Discount = Convert.ToSingle(((TextBox)OrderDetailsGridView.FooterRow.FindControl("FooterDiscount")).Text) / 100; orderDetail.ProductId = Convert.ToInt32(((DropDownList)OrderDetailsGridView.FooterRow.FindControl("FooterProducts")).SelectedValue); orderDetail.OrderId = Convert.ToInt32(OrdersFormView.SelectedValue.ToString()); DataAccessAdapter adapter = new DataAccessAdapter(); adapter.SaveEntity(orderDetail); OrderDetailsGridView.DataBind(); } // AddFromEmpty command is issued by an Add button in the GridView's Empty Template. // To enable inserting from a GridView. // The footer is invisible when there are now rows in the GridView, that's why we use the empty template // to insert the first row on the grid. else if (e.CommandName == "AddFromEmpty" && Page.IsValid) { OrderDetailEntity orderDetail = new OrderDetailEntity(); orderDetail.UnitPrice = Convert.ToDecimal(((TextBox)OrderDetailsGridView.Controls[0].Controls[0].FindControl("EmptyUnitPrice")).Text); orderDetail.Quantity = Convert.ToInt16(((TextBox)OrderDetailsGridView.Controls[0].Controls[0].FindControl("EmptyQuantity")).Text); orderDetail.Discount = Convert.ToSingle(((TextBox)OrderDetailsGridView.Controls[0].Controls[0].FindControl("EmptyDiscount")).Text) / 100; orderDetail.ProductId = Convert.ToInt32(((DropDownList)OrderDetailsGridView.Controls[0].Controls[0].FindControl("EmptyProducts")).SelectedValue); orderDetail.OrderId = Convert.ToInt32(OrdersFormView.SelectedValue.ToString()); DataAccessAdapter adapter = new DataAccessAdapter(); adapter.SaveEntity(orderDetail); OrderDetailsGridView.DataBind(); } }
public void ShowOrderInfo(OrderInfo order, IList <OrderItemLine> orderItemLines) { //The order information data will be shown in Label controls, which are not automatically encoded by ASP.NET. //It's a good practice to always encode data that comes from an external/untrusted source (in this case, the database). //The data is explicitly encoded using Microsoft Anti-Cross Site Scripting Library which can be downloaded from: //http://www.microsoft.com/downloads/details.aspx?familyid=efb9c819-53ff-4f82-bfaf-e11625130c25 OrderNo.Text = order.OrderId; OrderName.Text = AntiXss.HtmlEncode(order.OrderName); OrderStatus.Text = AntiXss.HtmlEncode(order.OrderStatus); Description.Text = AntiXss.HtmlEncode(order.Description); Customer.Text = AntiXss.HtmlEncode(order.CustomerName); ApprovedBy.Text = AntiXss.HtmlEncode(order.Approver); Street.Text = AntiXss.HtmlEncode(order.Address); State.Text = AntiXss.HtmlEncode(order.State); City.Text = AntiXss.HtmlEncode(order.City); PostalCode.Text = AntiXss.HtmlEncode(order.PostalCode); _total = order.OrderTotal; OrderDetailsGridView.DataSource = orderItemLines; OrderDetailsGridView.DataBind(); }
protected void OrderDetailsGridView_RowCommand(object sender, GridViewCommandEventArgs e) { OrderDetailsController controller = new OrderDetailsController(); int vendorId = int.Parse(VendorDDL.SelectedValue); if (e.CommandName.Equals("Refresh")) { int OrderDetailID = int.Parse(e.CommandArgument.ToString()); int qty = 0; decimal unitcost = 0; decimal perItemCost = 0; decimal unitSize = 0; Label yourlabel = null; for (int rowIndex = 0; rowIndex < OrderDetailsGridView.Rows.Count; rowIndex++) { if ((OrderDetailsGridView.Rows[rowIndex].FindControl("lblOrderDetailID") as Label).Text == e.CommandArgument.ToString()) { qty = int.Parse((OrderDetailsGridView.Rows[rowIndex].FindControl("txtQuantity") as TextBox).Text); //string z = (OrderDetailsGridView.Rows[rowIndex].FindControl("txtUnitCost") as TextBox).Text; //string zRemove = z.Remove(0, 0); unitcost = decimal.Parse((OrderDetailsGridView.Rows[rowIndex].FindControl("txtUnitCost") as TextBox).Text); string x = (OrderDetailsGridView.Rows[rowIndex].FindControl("lblPerItemCost") as Label).Text; string xRemove = x.Remove(0, 1); perItemCost = decimal.Parse(xRemove); string y = (OrderDetailsGridView.Rows[rowIndex].FindControl("lblUnitSize") as Label).Text; string yRemove = y.Remove(2); unitSize = decimal.Parse(yRemove); // For the warning message yourlabel = (OrderDetailsGridView.Rows[rowIndex].FindControl("lblCostWarning") as Label); //bind your label to data here } } if (qty <= 0) { MessageUserControl.ShowInfo("Quantity can not be a negative number"); } else if (perItemCost > (unitcost / unitSize)) { MessageUserControl.ShowInfo("Per-item cost can not be greater than selling price"); yourlabel.Visible = true; CalculateTotal(controller, vendorId); } else { MessageUserControl.TryRun(() => { controller.Quantity_Refresh(OrderDetailID, qty, unitcost); List <ListVendorOrders> datainfo = controller.Get_Active_Order(vendorId); OrderDetailsGridView.DataSource = datainfo; OrderDetailsGridView.DataBind(); CalculateTotal(controller, vendorId); }, "Refreshing", "Item Quantity Updated"); } } else { int OrderDetailID = int.Parse(e.CommandArgument.ToString()); MessageUserControl.TryRun(() => { controller.Delete_ProductItem(OrderDetailID); List <ListVendorOrders> datainfo = controller.Get_Active_Order(vendorId); OrderDetailsGridView.DataSource = datainfo; OrderDetailsGridView.DataBind(); CalculateTotal(controller, vendorId); }, "Deleting Product", "Item Has been Removed from Order"); } }