public DiscountModel GetDiscount(int id) { DiscountModel model = null; string commandText = @"SELECT d.ID AS DISCOUNT_ID , d.D_NAME , d.VALID_FROM_DATE , d.VALID_TO_DATE , d.DISCOUNT_KIND_ID , dk.DK_NAME , d.D_VALUE FROM DISCOUNT d LEFT JOIN DISCOUNT_KIND dk ON dk.ID = d.DISCOUNT_KIND_ID WHERE d.ID = " + SQLInt(id); using (DataTable dtDiscounts = FillDataTable(commandText)) { if (dtDiscounts.Rows.Count > 0) { DataRow drDiscount = dtDiscounts.Rows[0]; model = new DiscountModel() { DiscountId = TryParse.ToInt32(drDiscount["DISCOUNT_ID"]), Name = TryParse.ToString(drDiscount["D_NAME"]), DiscountKindId = TryParse.ToInt32(drDiscount["DISCOUNT_KIND_ID"]), DiscountKindName = TryParse.ToString(drDiscount["DK_NAME"]), ValidFrom = TryParse.ToDateTime(drDiscount["VALID_FROM_DATE"]), ValidTo = TryParse.ToDateTime(drDiscount["VALID_TO_DATE"]), Value = TryParse.ToDecimal(drDiscount["D_VALUE"]), }; } } return(model); }
public List <DiscountModel> GetDiscounts() { List <DiscountModel> model = new List <DiscountModel>(); string commandText = @"SELECT d.ID AS DISCOUNT_ID , d.D_NAME , d.VALID_FROM_DATE , d.VALID_TO_DATE , d.DISCOUNT_KIND_ID , dk.DK_NAME , d.D_VALUE FROM DISCOUNT d LEFT JOIN DISCOUNT_KIND dk ON dk.ID = d.DISCOUNT_KIND_ID ORDER BY d.D_NAME "; using (DataTable dtDiscounts = FillDataTable(commandText)) { foreach (DataRow drDiscount in dtDiscounts.Rows) { model.Add(new DiscountModel() { DiscountId = TryParse.ToInt32(drDiscount["DISCOUNT_ID"]), Name = TryParse.ToString(drDiscount["D_NAME"]), DiscountKindId = TryParse.ToInt32(drDiscount["DISCOUNT_KIND_ID"]), DiscountKindName = TryParse.ToString(drDiscount["DK_NAME"]), ValidFrom = TryParse.ToDateTime(drDiscount["VALID_FROM_DATE"]), ValidTo = TryParse.ToDateTime(drDiscount["VALID_TO_DATE"]), Value = TryParse.ToDecimal(drDiscount["D_VALUE"]), }); } } return(model); }