public static Coupon FindCouponInfo(string couponId) { provider.connect(); string sqlCommand = "sp_FindCouponInfo"; string sqlCommand1 = "sp_CountOrderCoupon"; List<SqlParameter> list = new List<SqlParameter>(); list.Add(new SqlParameter("@couponId", couponId)); Coupon[] cpArray = new Coupon[0]; try { DataTable table = provider.executeQueryDataTableProcedure(sqlCommand, list); if (table != null && table.Rows.Count > 0) { cpArray = TransFerToCouponArray(sqlCommand1, cpArray, table); return cpArray[0]; } } catch (Exception e) { } finally { provider.disconnect(); } return new Coupon(); }
public static Coupon[] FindCoupons(string productName,DateTime startDate,DateTime endDate,int minPrice,int maxPrice) { provider.connect(); string sqlCommand = "sp_FindCoupons"; string sqlCommand1 = "sp_CountOrderCoupon"; List<SqlParameter> list = new List<SqlParameter>(); list.Add(new SqlParameter("@productName", productName)); list.Add(new SqlParameter("@startDate", startDate)); list.Add(new SqlParameter("@endDate", endDate)); list.Add(new SqlParameter("@minPrice", minPrice)); list.Add(new SqlParameter("@maxPrice", maxPrice)); Coupon[] cpArray = new Coupon[0]; try { DataTable table = provider.executeQueryDataTableProcedure(sqlCommand, list); if (table != null && table.Rows.Count > 0) { cpArray = TransFerToCouponArray(sqlCommand1, cpArray, table); } } catch (Exception e) { } finally { provider.disconnect(); } return cpArray; }
private static Coupon[] TransFerToCouponArray(string sqlCommand1, Coupon[] cpArray, DataTable table) { int n = table.Rows.Count; cpArray = new Coupon[n]; for (int i = 0; i < n; i++) { cpArray[i] = new Coupon(); DataRow row = table.Rows[i]; cpArray[i].DieuKienSuDung = row["DIEUKIENSD"].ToString(); cpArray[i].DonViTien = row["DVTIENTE"].ToString(); cpArray[i].GiaHangKhiChuaGiam = row["GIAGOC"].ToString(); cpArray[i].GiaHangSauKhiGiam = row["GIASGIAM"].ToString(); cpArray[i].LinkHinhAnh = new string[1]; cpArray[i].LinkHinhAnh[0] = "http://www.beatifulhouse.somee.com/Content/images/products/" + row["HINHANH"].ToString(); cpArray[i].MaCoupon = row["MACP"].ToString(); cpArray[i].MaMatHang = row["MASP"].ToString(); cpArray[i].MaNhaCungCap = "BIZ"; cpArray[i].NgayBatDau = DateTime.Parse(row["THOIGIANBD"].ToString()); cpArray[i].NgayCouponBatDauDuocSuDung = cpArray[i].NgayBatDau; cpArray[i].NgayKetThuc = DateTime.Parse(row["THOIGIANKT"].ToString()); cpArray[i].NgayCouponHetHan = cpArray[i].NgayKetThuc; List<SqlParameter> sql = new List<SqlParameter>(); sql.Add(new SqlParameter("@macp", cpArray[i].MaCoupon)); SqlParameter output = new SqlParameter("@count", SqlDbType.Int); output.Direction = ParameterDirection.Output; sql.Add(output); provider.executeNonQueryProcedure(sqlCommand1, sql); cpArray[i].SoLuongDaDat = (int)output.Value; cpArray[i].SoLuongMuaLonNhat = int.Parse(row["SLCPMAX"].ToString()); cpArray[i].SoLuongThoaCoupon = int.Parse(row["SLCPMINGIAMGIA"].ToString()); cpArray[i].TenMatHang = row["TENSP"].ToString(); cpArray[i].TenNhaCungCap = "BeatifulhouseGroup"; cpArray[i].ThongTinMoTa = row["MOTA"].ToString(); } return cpArray; }
private static void TransformToCouponList(string sqlCommand1, DataTable table, List<Coupon> cpArray) { int n = table.Rows.Count; for (int i = 0; i < n; i++) { Coupon cp = new Coupon(); DataRow row = table.Rows[i]; cp.DieuKienSuDung = row["DIEUKIENSD"].ToString(); cp.DonViTien = row["DVTIENTE"].ToString(); cp.GiaHangKhiChuaGiam = row["GIAGOC"].ToString(); cp.GiaHangSauKhiGiam = row["GIASGIAM"].ToString(); cp.LinkHinhAnh = new string[1]; //pArray[i].LinkHinhAnh[0] = "http://www.beatifulhouse.somee.com/Content/images/products/" + row["HINHANH"].ToString(); // cp.LinkHinhAnh[0] = ConfigurationManager.AppSettings.GetValues("image")[0].ToString() + row["HINHANH"].ToString(); cp.LinkHinhAnh[0] ="../../Content/images/products/" +row["HINHANH"].ToString(); cp.MaCoupon = row["MACP"].ToString(); cp.MaMatHang = row["MASP"].ToString(); cp.MaNhaCungCap = "BIZ"; cp.NgayBatDau = DateTime.Parse(row["THOIGIANBD"].ToString()); cp.NgayCouponBatDauDuocSuDung = cp.NgayBatDau; cp.NgayKetThuc = DateTime.Parse(row["THOIGIANKT"].ToString()); cp.NgayCouponHetHan = cp.NgayKetThuc; List<SqlParameter> sql = new List<SqlParameter>(); sql.Add(new SqlParameter("@macp", cp.MaCoupon)); SqlParameter output = new SqlParameter("@count", SqlDbType.Int); output.Direction = ParameterDirection.Output; sql.Add(output); helper.executeNonQueryProcedure(sqlCommand1, sql); cp.SoLuongDaDat = (int)output.Value; float slcl = float.Parse(row["SLCONLAI"].ToString()); int slspmin = int.Parse(row["SLSPMIN"].ToString()); cp.SoLuongMuaLonNhat = (int)slcl / slspmin; cp.SoLuongThoaCoupon = int.Parse(row["SLCPMINGIAMGIA"].ToString()); cp.TenMatHang = row["TENSP"].ToString(); cp.TenNhaCungCap = "BeatifulhouseGroup"; cp.ThongTinMoTa = row["MOTA"].ToString(); cp.DieuKienSuDung = row["DIEUKIENSD"].ToString() + " .Mỗi coupon gồm " + slspmin.ToString() + " " + row["DVTINH"].ToString(); cp.Title = "Xem chi tiết"; if (row["TINHTRANGCP"].ToString() == "1" && cp.NgayKetThuc>=DateTime.Today) { cp.TinhTrang = "Còn hiệu lực"; } else { cp.TinhTrang = "Hết hạn"; } cpArray.Add(cp); } }