Esempio n. 1
0
    protected void Page_Load(object sender, EventArgs e)
    {
        string act = Request["act"];
        string _ID = Request["ID"];
        string _SoLuong = Request["SoLuong"];
        string _Ten = Request["Ten"];
        string _Gia = Request["Gia"];
        string _Img = Request["Img"];
        string _Email = Request["Email"];
        string _Mobile = Request["Mobile"];
        string _DiaChi = Request["DiaChi"];
        string _GhiChu = Request["GhiChu"];
        var gh = new GioHang();
        var item = new HangHoa();
        var _dele = new SendEmailDele(sendmailThongbao);
        var sb = new StringBuilder();

        switch (act)
        {
            case "add":
            #region add
                item = HangHoaDal.SelectById(new Guid(_ID));
                gh.Add(item, _SoLuong);
                break;
            #endregion
            case "save":
                #region save

                var itemDh = new DatHang
                                 {
                                     ID=Guid.NewGuid(),
                                     GiaoHang = false,
                                     GiaTri = gh.Total,
                                     KH_DiaChi = _DiaChi,
                                     KH_Email = _Email,
                                     KH_Mobile = _Mobile,
                                     KH_Ten = _Ten,
                                     NgayTao = DateTime.Now,
                                     PhiVanChuyen = gh.ShipCost,
                                     Readed = false,
                                     Tong = gh.Total + gh.ShipCost,
                                     NgayGiao = DateTime.Now
                                 };
                itemDh = DatHangDal.Insert(itemDh);
                var itemDhCt = new DatHangChiTiet();
                var sbDh = new System.Text.StringBuilder();
                sbDh.AppendFormat(@"Khách hàng: {0}<br/>Email: {1}<br/>Mobile: {2}<br/>Địa chỉ: {3}<br/>Ghi chú: {4}<br/>Ngày đặt hàng: {5}<br/><h3>Chi tiết</h3>"
                    ,_Ten,_Email,_Mobile,_DiaChi, _GhiChu,DateTime.Now);
                foreach (GioHangItem ghItem in gh.List.Values)
                {
                    itemDhCt = new DatHangChiTiet();
                    itemDhCt.ID = Guid.NewGuid();
                    itemDhCt.DH_ID = itemDh.ID;
                    itemDhCt.HH_Gia = ghItem.Gia;
                    itemDhCt.HH_SoLuong = ghItem.SoLuong;
                    itemDhCt.HH_Ten = ghItem.Ten;
                    itemDhCt.HH_Tong = ghItem.Gia * ghItem.SoLuong;
                    itemDhCt.NgayTao = DateTime.Now;
                    DatHangChiTietDal.Insert(itemDhCt);
                    sbDh.AppendFormat("Món:{0} - {1}<br/>Số lượng: {2}<br/>Tổng: {3}<hr/>", ghItem.Ten, ghItem.Gia, ghItem.SoLuong, ghItem.Gia * ghItem.SoLuong);
                }
                sbDh.AppendFormat(@"Tổng:{0}<br/>Phí vận chuyển: {1}<br/>Tổng cộng: {2}"
                    , gh.Total, gh.ShipCost, gh.Total + gh.ShipCost);
                _dele.BeginInvoke("*****@*****.**"
                            , string.Format("mamvui.com - Đặt hàng mới: {0}  {1} [{2}.000đ]", _Ten, DateTime.Now.ToString("hh:mm-dd/MM/yy"),gh.Total + gh.ShipCost)
                            , sbDh.ToString()
                            , null, null);
                gh.Clear();
                break;
                #endregion
            case "UpSl":
                #region UpSl
                item = HangHoaDal.SelectById(new Guid(_ID));
                gh.UpdateSl(item, _SoLuong);
                break;
                #endregion
            case "del":
                #region add
                gh.Remove(_ID);
                break;
                #endregion
            case "clear":
                #region add
                gh.Clear();
                break;
                #endregion
            case "get":
                #region get
                break;
            #endregion
            default:
                break;
        }
        //sb.Append(format_gioHang(gh));
        sb.AppendFormat("({0})", JavaScriptConvert.SerializeObject(gh));
        rendertext(sb, "text/plain");
    }
Esempio n. 2
0
    protected void Page_Load(object sender, EventArgs e)
    {
        string act = Request["act"];
        string _ID = Request["ID"];
        string _SoLuong = Request["SoLuong"];
        string _Ten = Request["Ten"];
        string _Gia = Request["Gia"];
        string _Img = Request["Img"];
        string _Email = Request["Email"];
        string _Mobile = Request["Mobile"];
        string _DiaChi = Request["DiaChi"];
        string _GhiChu = Request["GhiChu"];
        var gh = new GioHang();
        var item = new HangHoa();
        var _dele = new SendEmailDele(sendmailThongbao);
        var sb = new StringBuilder();

        switch (act)
        {
            case "add":
            #region add
                item = HangHoaDal.SelectById(new Guid(_ID));
                gh.Add(item, _SoLuong);
                break;
            #endregion
            case "addWishList":
                #region add

                if(Security.IsAuthenticated())
                {
                    var yt = new YeuThich()
                                 {
                                     HH_ID = new Guid(_ID)
                                     , ID = Guid.NewGuid()
                                     , NgayTao = DateTime.Now
                                     , Username = Security.Username
                                 };
                    YeuThichDal.Insert(yt);
                    sb.Append("1");
                }
                else
                {
                    sb.Append("0");
                }
                break;
                #endregion
            case "save":
                #region save

                var itemDh = new DatHang
                                 {
                                     ID=Guid.NewGuid(),
                                     GiaoHang = false,
                                     GiaTri = gh.Total,
                                     KH_DiaChi = _DiaChi,
                                     KH_Email = _Email,
                                     KH_Mobile = _Mobile,
                                     KH_Ten = _Ten,
                                     NgayTao = DateTime.Now,
                                     PhiVanChuyen = gh.ShipCost,
                                     Readed = false,
                                     Tong = gh.Total + gh.ShipCost,
                                     NgayGiao = DateTime.Now,
                                     Username = Security.Username
                                 };
                itemDh = DatHangDal.Insert(itemDh);
                var itemDhCt = new DatHangChiTiet();
                var sbDh = new System.Text.StringBuilder();
                sbDh.AppendFormat(@"Customer: {0}<br/>Email: {1}<br/>Mobile: {2}<br/>Address: {3}<br/>Note: {4}<br/>Date of purchase: {5}<br/><h3>Chi tiết</h3>"
                    ,_Ten,_Email,_Mobile,_DiaChi, _GhiChu,DateTime.Now);
                foreach (var _ghItem in gh.List)
                {
                    var ghItem = _ghItem.Value;
                    itemDhCt = new DatHangChiTiet();
                    itemDhCt.ID = Guid.NewGuid();
                    itemDhCt.DH_ID = itemDh.ID;
                    itemDhCt.HH_ID = new Guid(_ghItem.Key);
                    itemDhCt.HH_Gia = ghItem.Gia;
                    itemDhCt.HH_SoLuong = ghItem.SoLuong;
                    itemDhCt.HH_Ten = ghItem.Ten;
                    itemDhCt.HH_Tong = ghItem.Gia * ghItem.SoLuong;
                    itemDhCt.NgayTao = DateTime.Now;
                    DatHangChiTietDal.Insert(itemDhCt);
                    sbDh.AppendFormat("Item:{0} - {1}<br/>Quality: {2}<br/>Sub total: {3}<hr/>", ghItem.Ten, ghItem.Gia, ghItem.SoLuong, ghItem.Gia * ghItem.SoLuong);
                }
                sbDh.AppendFormat(@"Total:{0}<br/>Shipping cost: {1}<br/>Total amout: {2}"
                    , gh.Total, gh.ShipCost, gh.Total + gh.ShipCost);
                _dele.BeginInvoke("*****@*****.**"
                            , string.Format("Leenaa - New Order: {0}  {1} [{2}.000]", _Ten, DateTime.Now.ToString("hh:mm-dd/MM/yy"),gh.Total + gh.ShipCost)
                            , sbDh.ToString()
                            , null, null);
                gh.Clear();
                if(itemDh.Tong != 0)
                {
                    itemDh.Tong = itemDh.Tong/1141;
                }
                sb.AppendFormat("({0})",JavaScriptConvert.SerializeObject(itemDh));
                rendertext(sb, "text/plain");
                break;
                #endregion
            case "UpSl":
                #region UpSl
                item = HangHoaDal.SelectById(new Guid(_ID));
                gh.UpdateSl(item, _SoLuong);
                break;
                #endregion
            case "del":
                #region add
                gh.Remove(_ID);
                break;
                #endregion
            case "delWishList":
                #region delWishList
                if (Security.IsAuthenticated())
                {
                    YeuThichDal.DeleteById(new Guid(_ID));
                }
                break;
                #endregion
            case "clear":
                #region add
                gh.Clear();
                break;
                #endregion
            case "get":
                #region get
                break;
            #endregion
            default:
                break;
        }
        //sb.Append(format_gioHang(gh));
        sb.AppendFormat("({0})", JavaScriptConvert.SerializeObject(gh));
        rendertext(sb, "text/plain");
    }