예제 #1
0
        public void DeleteDiscount(Discount discount, bool isImmediateSave)
        {
            try
            {
                /*IDiscountItemRepository discountItemRepository = new DiscountItemRepository();
                var discountItems = discountItemRepository.GetDiscountItems().Where(discountItem => discountItem.discountID == discount.discountID);

                foreach (DiscountItem discountItem in discountItems)
                {
                    discountItemRepository.DeleteDiscountItem(discountItem, false);
                }

                discountItemRepository.Dispose();*/

                mContext.Discounts.Attach(discount);
                mContext.Discounts.DeleteObject(discount);

                if (isImmediateSave)
                {
                    mContext.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                // TODO: Add exception handling code here.
                throw ex;
            }
        }
예제 #2
0
 public void UpdateDiscount(Discount discount, Discount origDiscount)
 {
     try
     {
         mRepository.UpdateDiscount(discount, origDiscount, true);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
예제 #3
0
 public void InsertDiscount(Discount discount)
 {
     try
     {
         mRepository.InsertDiscount(discount, true);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
예제 #4
0
 public void DeleteDiscount(Discount discount)
 {
     try
     {
         mRepository.DeleteDiscount(discount, true);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
예제 #5
0
        public void InsertDiscount(Discount discount, bool isImmediateSave)
        {
            try
            {
                mContext.Discounts.AddObject(discount);

                if (isImmediateSave)
                {
                    mContext.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                // TODO: Add exception handling code here.
                throw ex;
            }
        }
예제 #6
0
        public void UpdateDiscount(Discount newDiscount, Discount origDiscount, bool isImmediateSave)
        {
            try
            {
                mContext.Discounts.Attach(origDiscount);
                mContext.ApplyCurrentValues("Discounts", newDiscount);

                if (isImmediateSave)
                {
                    mContext.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                // TODO: Add exception handling code here.
                throw ex;
            }
        }
예제 #7
0
        protected void OnOperateItem(Object sender, CommandEventArgs e)
        {
            DataTable source = (DataTable)ViewState["DataSource"];
            DataTable filteredSource = (DataTable)ViewState["FilteredDataSource"];

            if(e.CommandName == "DeleteItem")
            {
                // Mark the deleting row's status as "D" and remove this row from the filtered source.
                foreach (DataRow row in source.Rows)
                {
                    if ((string)row["id"] == (string)e.CommandArgument)
                    {
                        row["status"] = "D";
                        foreach (DataRow tempRow in filteredSource.Rows)
                        {
                            if ((string)tempRow["id"] == (string)e.CommandArgument)
                            {
                                filteredSource.Rows.Remove(tempRow);

                                break;
                            }
                        }

                        break;
                    }
                }
            }
            else if (e.CommandName == "EditItem")
            {
                // Mark the deleting row's status as "M" and jump to the item editing page.
                foreach (DataRow row in source.Rows)
                {
                    if ((string)row["id"] == (string)e.CommandArgument)
                    {
                        // Change its status to "M" only when this item is not a new inserted item.
                        if ((string)row["status"] != "I")
                        {
                            row["status"] = "M";
                        }

                        // Store the data in the ViewState into the SessionState temporarily.
                        Session.Add("DataSource", source);
                        Session.Add("FilteredDataSource", filteredSource);

                        // Add a variable in the SessionState to indicate the current mode.
                        Session.Add("IsEditMode", !mIsNew);

                        // Store the current editing state into the SessionState temporarily.
                        Discount discount = new Discount();

                        discount.discountID = Convert.ToInt32(DiscountIDLabel.Text);
                        discount.description = DiscountDescriptionTextBox.Text;
                        discount.startDate = Convert.ToDateTime(DateDown.Text);
                        discount.endDate = Convert.ToDateTime(DateUp.Text);

                        Session.Add("CurrentState", discount);

                        // Jump to the discount item editing page.
                        Response.Redirect("~/WebPages/DiscountItemEdit.aspx?isNew=false&discountItemID=" + (string)row["id"]);
                    }
                }
            }
            else if (e.CommandName == "InsertItem")
            {
                // Store the data in the ViewState into the SessionState temporarily.
                Session.Add("DataSource", source);
                Session.Add("FilteredDataSource", filteredSource);

                // Add a variable in the SessionState to indicate the current mode.
                Session.Add("IsEditMode", !mIsNew);

                // Store the current editing state into the SessionState temporarily.
                Discount discount = new Discount();

                if (!mIsNew)
                {
                    discount.discountID = Convert.ToInt32(DiscountIDLabel.Text);
                }
                else
                {
                    discount.discountID = -1;
                }

                discount.description = DiscountDescriptionTextBox.Text;
                discount.startDate = Convert.ToDateTime(DateDown.Text);
                discount.endDate = Convert.ToDateTime(DateUp.Text);

                Session.Add("CurrentState", discount);

                // Jump to the discount item editing page.
                Response.Redirect("~/WebPages/DiscountItemEdit.aspx?isNew=true");
            }

            // Data binding.
            DiscountItemsGridView.DataSource = filteredSource;
            DiscountItemsGridView.DataBind();
        }
예제 #8
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");
        }
예제 #9
0
 /// <summary>
 /// 创建新的 Discount 对象。
 /// </summary>
 /// <param name="discountID">discountID 属性的初始值。</param>
 /// <param name="description">description 属性的初始值。</param>
 /// <param name="startDate">startDate 属性的初始值。</param>
 /// <param name="endDate">endDate 属性的初始值。</param>
 public static Discount CreateDiscount(global::System.Int32 discountID, global::System.String description, global::System.DateTime startDate, global::System.DateTime endDate)
 {
     Discount discount = new Discount();
     discount.discountID = discountID;
     discount.description = description;
     discount.startDate = startDate;
     discount.endDate = endDate;
     return discount;
 }
예제 #10
0
 /// <summary>
 /// 用于向 Discounts EntitySet 添加新对象的方法,已弃用。请考虑改用关联的 ObjectSet&lt;T&gt; 属性的 .Add 方法。
 /// </summary>
 public void AddToDiscounts(Discount discount)
 {
     base.AddObject("Discounts", discount);
 }