public static string GetProductsAdmin()
        {
            JavaScriptSerializer jsonSerialiser = new JavaScriptSerializer();
            var json = jsonSerialiser.Serialize(Sp_BUS.GetAll());

            return(json);
        }
        public static string GetPages()
        {
            var     sbTrang = new StringBuilder();
            decimal kq      = (_spList ?? Sp_BUS.GetAll()).Count / (ProductOnPage == 0 ? 1 : ProductOnPage) + 1;
            var     pageNo  = Math.Ceiling(kq);

            if (pageNo != 1)
            {
                for (var i = 1; i <= pageNo; i++)
                {
                    sbTrang.Append(string.Format(@"<li><a href='#' page='{0}' id='page'>{0}</a></li>", i));
                }
            }
            return(sbTrang.ToString());
        }
        public static string GetProducts(FilterClass fc)
        {
            var sb = new StringBuilder();

            _spList = Sp_BUS.GetAll();
            if (!string.IsNullOrEmpty(fc.CatId.ToString()))
            {
                _spList = _spList.Where(sp => sp.MaLoaiSp == fc.CatId).ToList();
            }
            if (!string.IsNullOrEmpty(fc.BrandId.ToString()))
            {
                _spList = _spList.Where(sp => sp.MaNcc == fc.BrandId).ToList();
            }
            if (!string.IsNullOrEmpty(fc.SearchKey))
            {
                _spList = _spList.Where(sp => sp.TenSp.Contains(fc.SearchKey)).ToList();
            }
            var spListPaged = _spList.Skip(ProductOnPage * ((fc.PageId ?? 1) - 1)).Take(ProductOnPage).ToList();


            foreach (var sp in spListPaged)
            {
                sb.Append($@"
            <div class='col-md-4'>
							<div class='panel panel-info'>
								<div class='panel-heading'>{sp.TenSp}</div>
								<div class='panel-body'>
									<img src='/product_images/{sp.HinhSp}' style='width:160px; height:250px;'/>
								</div>
								<div class='panel-heading'>{sp.DonGia}
									<button pid='{sp.MaSp}' style='float:right;' id='product' class='btn btn-danger btn-xs'>Thêm giở hàng</button>
								</div>
							</div>
						</div>

            ");
            }


            return(string.IsNullOrEmpty(sb.ToString()) ? "Không có sản phẩm" : sb.ToString());
        }
Exemplo n.º 4
0
        public static string LapHoaDon(string data, int phanTram, string tienGiam)
        {
            JavaScriptSerializer json     = new JavaScriptSerializer();
            List <string[]>      mystring = json.Deserialize <List <string[]> >(data);

            PhieuHd phd = new PhieuHd()
            {
                NgayLap      = DateTime.Now,
                PhanTramGiam = phanTram,
                TienGiam     = tienGiam
            };

            PhieuHd_BUS.Insert(phd);
            int maPhieuHd = PhieuHd_BUS.GetAll().ToList().Last().MaPhieuHd;

            for (int i = 0; i < mystring.Count; i++)
            {
                int            maSp   = int.Parse(mystring[i][0]);
                int            sL     = int.Parse(mystring[i][1]);
                PhieuHdChiTiet phd_ct = new PhieuHdChiTiet();
                phd_ct.MaPhieuHd = maPhieuHd;
                phd_ct.MaSp      = maSp;
                phd_ct.SoLuong   = sL;
                phd_ct.ThanhTien = maSp * sL;
                Sp sp = Sp_BUS.GetById(maSp);
                sp.SoLuongTonKho -= sL;
                if (sp.SoLuongTonKho < 0)
                {
                    sp.SoLuongTonKho = 0;
                }
                Sp_BUS.Update(sp);
                PhieuHdChiTiet_BUS.Insert(phd_ct);
            }

            return("");
        }
        public static string GetCartItems(FilterClass fc, ActionClass ac)
        {
            var sb     = new StringBuilder();
            var result = HttpContext.Current.Session["uid"] == null
                ? from p in Sp_BUS.GetAll()
                         join g in GioHangBus.GetAll()
                         on p.MaSp equals g.MaSp
                         where g.DiaChiIp == Cart.IpAddress
                         select new
            {
                MaSanPham   = p.MaSp,
                TenSanPham  = p.TenSp,
                GiaSanPham  = p.DonGia,
                HinhSanPham = p.HinhSp,
                g.MaGioHang,
                g.SoLuong,
                g.DiaChiIp,
                g.MaKh
            }
                : GioHangBus.GetAll().Join(Sp_BUS.GetAll(), c => c.MaSp, p => p.MaSp,
                                           (gioHang, sanPham) => new
            {
                MaSanPham   = sanPham.MaSp,
                TenSanPham  = sanPham.TenSp,
                GiaSanPham  = sanPham.DonGia,
                HinhSanPham = sanPham.HinhSp,
                gioHang.MaGioHang,
                gioHang.SoLuong,
                gioHang.DiaChiIp,
                gioHang.MaKh
            }).Where(m => m.MaKh == int.Parse(HttpContext.Current.Session["uid"].ToString()));

            var enumerable = result.ToList();

            if (ac.LaySanPhamGioHang)
            {
                var n = 0;
                foreach (var x in enumerable)
                {
                    sb.Append($@"
                    <div class='row'>
                        <div class='col-md-3'>{++n}</div>
						<div class='col-md-3'><img class='img-responsive' src='product_images/{x.HinhSanPham}' /></div>
						<div class='col-md-3'>{x.TenSanPham}</div>
						<div class='col-md-3'>{x.GiaSanPham}</div>
					</div>
                    ");
                }
                sb.Append(
                    "<a style='float:right; ' href='/GioHang' class='btn btn-warning'>Edit&nbsp;&nbsp;<span class='glyphicon glyphicon-edit'></span></a>");
            }

            if (ac.LaySanPhamGioHangCheckOut)
            {
                foreach (var x in enumerable)
                {
                    sb.Append($@"<div class='row'>
                        <div class='col-md-2'>
                        <div class='btn-group'>
                        <a href = '#' remove_id='{x.MaSanPham}' class='btn btn-danger remove'><span class='glyphicon glyphicon-trash'></span></a>
                        <a href = '#' update_id='{x.MaSanPham}' class='btn btn-primary update'><span class='glyphicon glyphicon-ok-sign'></span></a>
                        </div>
                        </div>
                        <input type = 'hidden' name='product_id[]' value='{x.MaSanPham}'/>
                        <input type = 'hidden' name='' value='{x.MaGioHang}'/>
                        <div class='col-md-2'><img class='img-responsive' src='product_images/{x.HinhSanPham}'></div>
                        <div class='col-md-2'>{x.TenSanPham}</div>
                        <div class='col-md-2'><input type = 'text' class='form-control qty' value='{x.SoLuong}' ></div>
                        <div class='col-md-2'><input type = 'text' class='form-control price' value='{x.GiaSanPham}' readonly='readonly'></div>
                        <div class='col-md-2'><input type = 'text' class='form-control total' value='{x.GiaSanPham}' readonly='readonly'></div>
                        </div>");
                }
                sb.Append(@"<div class='row'>
                    <div class='col-md-8'></div>
                    <div class='col-md-4'>
                    <b class='net_total' style='font-size:20px;'> </b>
                    </div>");

                if (HttpContext.Current.Session["uid"] == null)
                {
                    sb.Append(
                        "<input type='submit' style='float:right; ' name='login_user_with_product' onclick='submit()' class='btn btn-info btn-lg' value='Ready to Checkout' >");
                }
                else
                {
                    sb.Append(@"
                        <input type = 'hidden' name = 'cmd' value='_cart'>
                        <input type = 'hidden' name = 'business' value = '*****@*****.**' >
                        <input type = 'hidden' name = 'upload' value = '1' > ");

                    var collections = from p in Sp_BUS.GetAll()
                                      join g in GioHangBus.GetAll()
                                      on p.MaSp equals g.MaSp
                                      where g.MaKh == int.Parse(HttpContext.Current.Session["uid"].ToString())
                                      select new
                    {
                        MaSanPham   = p.MaSp,
                        TenSanPham  = p.TenSp,
                        GiaSanPham  = p.DonGia,
                        HinhSanPham = p.HinhSp,
                        g.MaGioHang,
                        g.SoLuong,
                        g.DiaChiIp,
                        g.MaKh
                    };
                    var i = 0;
                    foreach (var x in collections)
                    {
                        i++;
                        sb.Append($@"
                            <input type='hidden' name='item_name_{i}' value='{x.TenSanPham}'>
                            <input type = 'hidden' name = 'item_number_{i}' value = '{i}' >
                            <input type = 'hidden' name = 'amount_{i}' value = '{x.GiaSanPham}' >
                            <input type = 'hidden' name = 'quantity_{i}' value = '{x.SoLuong}' > ");
                    }

                    sb.Append(
                        $@"<input type='hidden' name='return' value='/GiaoDichThanhCong'/>

                        <input type = 'hidden' name = 'notify_url' value = '/GiaoDichThanhCong' >
     
                        <input type = 'hidden' name = 'cancel_return' value = '/GiaoDichThatBai' />
          
                        <input type = 'hidden' name = 'currency_code' value = 'USD' />
               
                        <input type = 'hidden' name = 'custom' value = '{HttpContext.Current.Session["uid"]}' />
                      
                        <input style = 'float:right;margin-right:80px;' type = 'image' name = 'submit'

                    src = 'https://www.paypalobjects.com/webstatic/en_US/i/btn/png/blue-rect-paypalcheckout-60px.png' alt = 'PayPal Checkout'

                    alt = 'PayPal - The safer, easier way to pay online' > ");
                }
            }


            return(sb.ToString());
        }