public void EditRebate(int id, Rebate rebate) { using (SqlConnection con = new SqlConnection(conString)) { con.Open(); using (SqlCommand com = new SqlCommand()) { string query = String.Format("UPDATE Rebate SET Name='{0}', ProductId='{1}', Discount='{2}', ", rebate.Name, rebate.Product.Id, (decimal)rebate.Discount); if (rebate.GetType() == typeof(VolumeBasedRebate)) { VolumeBasedRebate r = (VolumeBasedRebate)rebate; query += String.Format("Volume='{0}', StartDate='{1}', EndDate='{2}', RebateType='{3}' WHERE Id={4}", r.Volume, DateTime.Now.AddYears(-1).ToString(), DateTime.Now.AddYears(10).ToString(), "VOLUME", id); } else if (rebate.GetType() == typeof(SeasonalRebate)) { SeasonalRebate r = (SeasonalRebate)rebate; query += String.Format("Volume='{0}', StartDate='{1}', EndDate='{2}', RebateType='{3}' WHERE Id={4}", 1, r.Start, r.End, "SEASONAL", id); } else { SpecialRebate r = (SpecialRebate)rebate; query += String.Format("Volume='{0}', StartDate='{1}', EndDate='{2}', RebateType='{3}' WHERE Id={4}", r.Volume, r.Start, r.End, "SPECIAL", id); } com.CommandText = query; com.Connection = con; com.ExecuteNonQuery(); } } }
private void SetExistingRebateValues() { if (!IsNew() && cmbRebName.SelectedItem != null) { Rebate item = (Rebate)cmbRebName.SelectedItem; for (int i = 0; i < cmbRebProduct.Items.Count; i++) { Product p = (Product)cmbRebProduct.Items[i]; if (p.Id == item.Product.Id) { cmbRebProduct.SelectedIndex = i; } } txtRebDiscount.Text = item.Discount.ToString(); if (item.GetType() == typeof(VolumeBasedRebate)) { rdbRebVolume.Checked = true; VolumeBasedRebate r = (VolumeBasedRebate)item; txtRebVolQuantity.Text = r.Volume.ToString(); } else if (item.GetType() == typeof(SeasonalRebate)) { rdbRebSeasonal.Checked = true; SeasonalRebate r = (SeasonalRebate)item; dateRebSeasonalStart.Value = r.Start; dateRebSeasonalEnd.Value = r.End; } else { rdbRebSpecial.Checked = true; SpecialRebate r = (SpecialRebate)item; txtRebSpecialQuantity.Text = r.Volume.ToString(); dateRebSpecialStart.Value = r.Start; dateRebSpecialEnd.Value = r.End; } } else { cmbRebProduct.SelectedItem = null; txtRebDiscount.Text = ""; rdbRebVolume.Checked = true; txtRebVolQuantity.Text = ""; dateRebSeasonalStart.Value = DateTime.Now; dateRebSeasonalEnd.Value = DateTime.Now; txtRebSpecialQuantity.Text = ""; dateRebSpecialStart.Value = DateTime.Now; dateRebSpecialEnd.Value = DateTime.Now; } }
public BLRebate(IUnityContainer container) { this.ContainerService = container; Loader = new BusinessEntityLoader <Rebate>(); Rebate item = new Rebate(); Loader.EntityType = item.GetType(); }
public void AddRebate(Rebate rebate) { using (SqlConnection con = new SqlConnection(conString)) { con.Open(); using (SqlCommand com = new SqlCommand("INSERT INTO Rebate(Name, ProductId, Discount, Volume, StartDate, EndDate, RebateType) VALUES(@Name, @ProductId, @Discount, @Volume, @StartDate, @EndDate, @RebateType)", con)) { com.Parameters.AddWithValue("@Name", rebate.Name); com.Parameters.AddWithValue("@ProductId", rebate.Product.Id); com.Parameters.AddWithValue("@Discount", (decimal)rebate.Discount); if (rebate.GetType() == typeof(VolumeBasedRebate)) { VolumeBasedRebate r = (VolumeBasedRebate)rebate; com.Parameters.AddWithValue("@Volume", r.Volume); com.Parameters.AddWithValue("@StartDate", DateTime.Now.AddYears(-1).ToString()); com.Parameters.AddWithValue("@EndDate", DateTime.Now.AddYears(10).ToString()); com.Parameters.AddWithValue("@RebateType", "VOLUME"); } else if (rebate.GetType() == typeof(SeasonalRebate)) { SeasonalRebate r = (SeasonalRebate)rebate; com.Parameters.AddWithValue("@Volume", 1); com.Parameters.AddWithValue("@StartDate", r.Start); com.Parameters.AddWithValue("@EndDate", r.End); com.Parameters.AddWithValue("@RebateType", "SEASONAL"); } else { SpecialRebate r = (SpecialRebate)rebate; com.Parameters.AddWithValue("@Volume", r.Volume); com.Parameters.AddWithValue("@StartDate", r.Start); com.Parameters.AddWithValue("@EndDate", r.End); com.Parameters.AddWithValue("@RebateType", "SPECIAL"); } com.ExecuteNonQuery(); } } }