Exemplo n.º 1
0
        protected void SubmitButton_Click(object sender, EventArgs e)
        {
            // Submit all the changes.
            Discount origDiscount = GetDiscount();
            Discount discount = new Discount();
            DiscountItemBL discountItemBL = new DiscountItemBL();
            DataTable source = (DataTable)ViewState["DataSource"];

            // First, the discount.
            discount.description = DiscountDescriptionTextBox.Text;
            discount.startDate = Convert.ToDateTime(DateDown.Text);
            discount.endDate = Convert.ToDateTime(DateUp.Text);

            if (mIsNew)
            {
                mDiscounts.InsertDiscount(discount);
            }
            else
            {
                discount.discountID = origDiscount.discountID;
                mDiscounts.UpdateDiscount(discount, origDiscount);
            }

            // Then, the corresponding discount items.
            foreach (DataRow row in source.Rows)
            {
                DiscountItem item = new DiscountItem();
                DiscountItem origItem = discountItemBL.GetDiscountItem(Convert.ToInt32(row["id"]));

                if ((string)row["status"] == "D")
                {
                    // Delete this row.
                    discountItemBL.DeleteDiscountItem(origItem);
                }
                else if ((string)row["status"] == "M")
                {
                    // Update this row.
                    item.id = origItem.id;
                    item.productID = Convert.ToInt32(row["productID"]);
                    item.description = row["description"].ToString();
                    item.discountID = discount.discountID;
                    item.discountPercent = (float)Convert.ToDouble(row["discountPercent"]);

                    discountItemBL.UpdateDiscountItem(item, origItem);
                }
                else if ((string)row["status"] == "I")
                {
                    // Insert this row.
                    item.productID = Convert.ToInt32(row["productID"]);
                    item.description = row["description"].ToString();
                    item.discountID = discount.discountID;
                    item.discountPercent = (float)Convert.ToDouble(row["discountPercent"]);

                    discountItemBL.InsertDiscountItem(item);
                }
            }

            // Jump back to the discount list page.
            Response.Redirect("~/WebPages/Discounts.aspx");
        }
 public List<DiscountItem> FindDiscountItemsByDiscountID(Int32 discountID)
 {
     DiscountItemBL bl = new DiscountItemBL();
     return bl.GetDiscountItemsByDiscountID(discountID).ToList();
 }