public static List<OrderDetail> OrderDetailList(int OrderID)
        {
            //Copied code from Nwind.cs VVVV
            List<OrderDetail> OrdDetList = new List<OrderDetail>();

            sqlCon = new SqlConnection(connectionString);
            sqlCon.Open();

            SqlDataAdapter da;
            DataTable dt = new DataTable();
            SqlCommand cmd = new SqlCommand(PROC_ORD_DETAILS, sqlCon);
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.Add(new SqlParameter("@OrderID", OrderID));

            da = new SqlDataAdapter(cmd);
            da.FillSchema(dt, SchemaType.Source);
            da.Fill(dt);

            sqlCon.Close();
            //Copied code^^^^
            foreach (DataRow row in dt.Rows)
            {
                //int OrderID = (int)row["OrderID"];
                //string ProductName = (string)row["ProductName"];
                int ProductID = (int)row["ProductID"];
                decimal UnitPrice = (decimal)row["UnitPrice"];
                short Quantity = (short)row["Quantity"];
                float Discount = (float)row["Discount"];

                OrderDetail OrD = new OrderDetail(OrderID,ProductID,UnitPrice,Quantity,Discount);
                OrdDetList.Add(OrD);
            }
      /*put code here */
            return OrdDetList;
        }
        private void btnSaveOrder_Click(object sender, EventArgs e)
        {
            try
            {
                for (int i = 0; i < pnlList.Count; i++)
                {
                    int ProductID = (int)cmbList[i].SelectedValue;
                    decimal UnitPrice = Convert.ToDecimal(txtPriceList[i].Text);
                    short Quantity = Convert.ToInt16(txtQuantityList[i].Text);
                    float Discount = Convert.ToSingle(txtDiscountList[i].Text) / 100;
                    OrderDetail od = new OrderDetail(OrderID, ProductID, UnitPrice, Quantity, Discount);
                    DetailList.Add(od);
                }
                Business.SaveDetails(OrderID, DetailList);
                MessageBox.Show("Products saved Properly, or is it?");
                DetailList.RemoveRange(0, DetailList.Count);//is it changing or not?
            }
            catch (Exception ex)
            {

                MessageBox.Show(ex.Message);
            }

        }
        private void btnAddtoOrder_Click(object sender, EventArgs e)
        {
          
          
                int ProductId = (int)cbProducts.SelectedValue;
                ProductList = Business.ProductList();
                Product tmp = ProductList[ProductId];
                OrderDetail Detail = new OrderDetail(Test.OrderID, tmp.ProductID, tmp.UnitPrice, Convert.ToInt16(txtQuantity.Text), Convert.ToInt32(txtDisc.Text));
                Detail.ProductName = cbProducts.Text;
                DetailsList.Add(Detail);
                cbProducts.SelectedValue = -1;
                lblFin.Text = (Convert.ToDecimal(lblFin.Text) + (tmp.UnitPrice * Convert.ToInt32(txtQuantity.Text))).ToString();
                lsDetails.Items.Add(Detail.ProductName + " " + Detail.UnitPrice.ToString("c"));
                txtDisc.Text = "0";
                txtQuantity.Text = "0";

        }
 private void AddBtn_Click(object sender, EventArgs e)
 {
     int InStock = Convert.ToInt16(InStockBox.Text);
     //Still need to make it check for multiple things with the same product but different discounts
     if (InStock <= 0)
         return;
     string AddToOrder = "";
     AddToOrder += ProductBox.SelectedItem.ToString();
     for (int j = 0; j < OrderList.Items.Count; j++)
     {
         if (BetterNameThanFer[j].ProductName == ProductBox.SelectedItem.ToString())
         {
             if (BetterNameThanFer[j].Discount == Convert.ToSingle(DiscountUpDown.Value))
             {
                 if (Convert.ToInt16(QuantityUpdown.Value) <= InStock)
                 {
                     BetterNameThanFer[j].Quantity += Convert.ToInt16(QuantityUpdown.Value);
                     AddToOrder += " (" + BetterNameThanFer[j].Quantity + ")";
                     InStockBox.Text = (InStock - (Convert.ToInt16(QuantityUpdown.Value))).ToString();
                     if (QuantityUpdown.Value > Convert.ToDecimal(InStockBox.Text))
                     {
                         QuantityUpdown.Value = Convert.ToDecimal(InStockBox.Text);
                         if (QuantityUpdown.Value == 0)
                             AddBtn.Enabled = false;
                     }
                     if (DiscountUpDown.Value != 0)
                     {
                         AddToOrder += " [" + ((DiscountUpDown.Value) * 100).ToString("#") + "% Discount]";
                     }
                     decimal garb = fer[ProductBox.SelectedIndex].UnitPrice;
                     garb = garb * (BetterNameThanFer[j].Quantity * (1 - DiscountUpDown.Value));
                     AddToOrder += " : " + garb.ToString("c");
                     OrderList.Items[j] = AddToOrder;
                     decimal TooLazyToRenameThem = fer[ProductBox.SelectedIndex].UnitPrice;
                     BetterNameThanFer[j].UnitPrice = (TooLazyToRenameThem * BetterNameThanFer[j].Quantity) * (1 - DiscountUpDown.Value);
                     //TooLazyToRenameThem = TooLazyToRenameThem * QuantityUpdown.Value * (1 - DiscountUpDown.Value);
                     
                     return;
                 }
                 else
                     return;
             }
         }
     }
     AddToOrder += " (" + QuantityUpdown.Value + ")";
     if (DiscountUpDown.Value != 0)
     {
         AddToOrder += " [" + ((DiscountUpDown.Value) * 100).ToString("#") + "% Discount]";
     }
     AddToOrder += " : " + PriceBox.Text;
     OrderList.Items.Add(AddToOrder);
     //Order Detail code
     int Das = ProductBox.SelectedIndex;
     //Need to make it so the Unit Price is properly calculated before entering it.  Ask Larry if I should do that, or calculate it during the finalize
     OrderDetail ThisPart = new OrderDetail(0, fer[Das].ProductID, fer[Das].UnitPrice, Convert.ToInt16(QuantityUpdown.Value), Convert.ToSingle(DiscountUpDown.Value));
     ThisPart.ProductName = ProductBox.SelectedItem.ToString();
     BetterNameThanFer.Add(ThisPart);
     InStockBox.Text = (InStock - (Convert.ToInt16(QuantityUpdown.Value))).ToString();
     if (QuantityUpdown.Value > Convert.ToDecimal(InStockBox.Text))
     {
         QuantityUpdown.Value = Convert.ToDecimal(InStockBox.Text);
         if (QuantityUpdown.Value == 0)
             AddBtn.Enabled = false;
     }
 }
Exemplo n.º 5
0
        public void GenerateProductPanel(OrderDetail generatedOrder)
        {
            ProductPanel temp = new ProductPanel(panelProducts, 4, productList);
            temp.BringToFront();
            listProductPanel.Add(temp);

            foreach (ProductPanel item in listProductPanel)
            {
                if (item.comboProduct.SelectedItem != null)
                {
                    temp.productListInternal.Remove((Product)item.comboProduct.SelectedItem);
                }
            }
            temp.txtDiscount.Text = generatedOrder.Discount.ToString();
            temp.txtPrice.Text = generatedOrder.UnitPrice.ToString();
            temp.txtQuantity.Text = generatedOrder.Quantity.ToString();
            temp.comboProduct.DataSource = temp.productListInternal;
            temp.comboProduct.SelectedItem = generatedOrder.ProductID;
            temp.comboProduct.SelectedIndexChanged += comboProduct_SelectedIndexChanged;
            temp.updPrice += temp_updPrice;
            temp.updPercent += temp_updPercent;
            temp.btnDelete.Click += btnDelete_Click;
            updatepanelLocation();
            temp_updPercent();

        }
 private void AddPanel(OrderDetail detail)
 {
     BrettProductPanel BPP = new BrettProductPanel(pnlList, productList, pnlContainer.Width, pnlContainer.Height, pnlContainer.Left, detail.ProductID, detail.Quantity, detail.Discount, detail.UnitPrice);
     SetupPanel(BPP);
 }
Exemplo n.º 7
0
        public KateDetailPanel(Panel MotherPanel, int locationy, int OrderID, List<Product> productlist)
        {
            mMotherPanel = MotherPanel;
            OD = new OrderDetail(OrderID, 0, 0, 1, 0);
            mProductList = productlist;
            //
            // comboProduct
            //
            comboProduct = new ComboBox();
            comboProduct.FormattingEnabled = true;
            comboProduct.Location = new System.Drawing.Point(4, 4);
            comboProduct.Name = "comboBox1";
            comboProduct.Size = new System.Drawing.Size(200, 21);
            comboProduct.TabIndex = 0;
            comboProduct.DataSource = productlist;
            comboProduct.DisplayMember = "ProductName";
            comboProduct.ValueMember = "ProductID";
            comboProduct.SelectedIndex = -1;
            comboProduct.SelectedIndexChanged += comboProduct_SelectedIndexChanged;
            // 
            // txtQuantityPerUnit
            // 
            txtQuantityPerUnit = new TextBox();
            txtQuantityPerUnit.Location = new System.Drawing.Point(220, 4);
            txtQuantityPerUnit.Name = "txtQuantityPerUnit";
            txtQuantityPerUnit.Size = new System.Drawing.Size(120, 20);
            txtQuantityPerUnit.TabStop = false;
            txtQuantityPerUnit.ReadOnly = true;

            // 
            // txtPrice
            // 
            txtPrice = new TextBox();
            txtPrice.Location = new System.Drawing.Point(360, 4);
            txtPrice.Name = "txtPrice";
            txtPrice.Size = new System.Drawing.Size(70, 20);
            txtPrice.TabIndex = 1;
            txtPrice.TextChanged += txtPrice_TextChanged;
            txtPrice.Validating += txtPrice_Validating;
            // 
            // txtQuantity
            // 
            txtQuantity = new TextBox();
            txtQuantity.Location = new System.Drawing.Point(450, 4);
            txtQuantity.Name = "txtQuantity";
            txtQuantity.Text = "1";
            txtQuantity.Size = new System.Drawing.Size(40, 20);
            txtQuantity.TabIndex = 2;
            txtQuantity.Validating += txtQuantity_Validating;
            txtQuantity.TextChanged += txtQuantity_TextChanged;



            // 
            // txtDiscount
            // 
            txtDiscount = new TextBox();
            txtDiscount.Location = new System.Drawing.Point(510, 4);
            txtDiscount.Name = "txtDiscount";
            txtDiscount.Size = new System.Drawing.Size(40, 20);
            txtDiscount.TabIndex = 3;
            txtDiscount.TextChanged += txtDiscount_TextChanged;
            txtDiscount.Validating += txtDiscount_Validating;
            // 
            // txtLineTotal
            // 
            txtLineTotal = new TextBox();
            txtLineTotal.Location = new System.Drawing.Point(570, 4);
            txtLineTotal.Name = "txtLineTotal";
            txtLineTotal.Size = new System.Drawing.Size(40, 20);
            txtLineTotal.ReadOnly = true;
            txtLineTotal.TabIndex = 3;

            // 
            // btnDelete
            // 
            btnDelete = new Button();
            btnDelete.Location = new System.Drawing.Point(630, 4);
            btnDelete.Name = "btnDelete";
            btnDelete.Size = new System.Drawing.Size(50, 20);
            btnDelete.TabIndex = 4;
            btnDelete.Text = "Delete";
            btnDelete.UseVisualStyleBackColor = true;
            btnDelete.BackColor = System.Drawing.Color.LightBlue;
            btnDelete.TabStop = false;
            btnDelete.FlatStyle = FlatStyle.Flat;
            btnDelete.FlatAppearance.BorderSize = 0;
            btnDelete.Click += btnDelete_Click;

            this.Controls.Add(comboProduct);
            this.Controls.Add(txtQuantityPerUnit);
            this.Controls.Add(txtPrice);
            this.Controls.Add(txtQuantity);
            this.Controls.Add(txtDiscount);
            this.Controls.Add(txtLineTotal);
            this.Controls.Add(btnDelete);
            this.Location = new System.Drawing.Point(4, locationy);
            this.Name = "KateDetailPanel";
            this.Size = new System.Drawing.Size(700, 28);
            this.BackColor = Color.LightYellow;
            MotherPanel.Controls.Add(this);
            comboProduct.SelectedIndex = -1;

        }