public void InsertDiscountItem(DiscountItem discountItem) { try { mRepository.InsertDiscountItem(discountItem, true); } catch (Exception ex) { throw ex; } }
public void InsertDiscountItem(DiscountItem discountItem, bool isImmediateSave) { try { mContext.DiscountItems.AddObject(discountItem); if (isImmediateSave) { mContext.SaveChanges(); } } catch (Exception ex) { // TODO: Add exception handling code here. } }
public void UpdateDiscountItem(DiscountItem newDiscountItem, DiscountItem origDiscountItem, bool isImmediateSave) { try { mContext.DiscountItems.Attach(origDiscountItem); mContext.ApplyCurrentValues("DiscountItems", newDiscountItem); if (isImmediateSave) { mContext.SaveChanges(); } } catch (Exception ex) { // TODO: Add exception handling code here. } }
public void DeleteDiscountItem(DiscountItem discountItem, bool isImmediateSave) { try { mContext.DiscountItems.Attach(discountItem); mContext.DiscountItems.DeleteObject(discountItem); if (isImmediateSave) { mContext.SaveChanges(); } } catch (Exception ex) { // TODO: Add exception handling code here. throw ex; } }
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 void UpdateDiscountItem(DiscountItem discountItem, DiscountItem origDiscountItem) { try { mRepository.UpdateDiscountItem(discountItem, origDiscountItem, true); } catch (Exception ex) { throw ex; } }
/// <summary> /// 创建新的 DiscountItem 对象。 /// </summary> /// <param name="id">id 属性的初始值。</param> /// <param name="discountID">discountID 属性的初始值。</param> /// <param name="productID">productID 属性的初始值。</param> /// <param name="discountPercent">discountPercent 属性的初始值。</param> /// <param name="description">description 属性的初始值。</param> public static DiscountItem CreateDiscountItem(global::System.Int32 id, global::System.Int32 discountID, global::System.Int32 productID, global::System.Single discountPercent, global::System.String description) { DiscountItem discountItem = new DiscountItem(); discountItem.id = id; discountItem.discountID = discountID; discountItem.productID = productID; discountItem.discountPercent = discountPercent; discountItem.description = description; return discountItem; }
/// <summary> /// 用于向 DiscountItems EntitySet 添加新对象的方法,已弃用。请考虑改用关联的 ObjectSet<T> 属性的 .Add 方法。 /// </summary> public void AddToDiscountItems(DiscountItem discountItem) { base.AddObject("DiscountItems", discountItem); }