protected void grDSSanPham_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == "themThanhPham")
            {
                //TextBox txt1 = (TextBox)grDSSanPham.Rows[Convert.ToInt32(e.CommandArgument)].FindControl("txtSLThuc");

                GridViewRow row        = (GridViewRow)(((LinkButton)e.CommandSource).NamingContainer);
                int         rowindex   = row.RowIndex;
                TextBox     txtSoluong = (TextBox)row.FindControl("txtSLThuc");
                Label       lbTenTP    = (Label)row.FindControl("lbTenSP");
                Label       lbGia      = (Label)row.FindControl("lbGia");

                int maThanhPham = int.Parse(e.CommandArgument.ToString());
                int soluong     = 0;
                int.TryParse(txtSoluong.Text, out soluong);
                int    gia   = int.Parse(lbGia.Text);
                string tenTP = lbTenTP.Text;

                lbDSChon.Visible       = true;
                lbTextTongTien.Visible = true;
                lbTongTien.Visible     = true;
                lbDSSanpham.Visible    = true;
                grDSSanPham.Visible    = true;
                gridDSChon.Visible     = true;

                if (Session["dsThanhPhamChon"] == null)
                {
                    dsThanhPhamChon            = new List <DTOChiTietDH>();
                    Session["dsThanhPhamChon"] = dsThanhPhamChon;
                }
                else
                {
                    dsThanhPhamChon = (List <DTOChiTietDH>)Session["dsThanhPhamChon"];
                }

                bool trangthai = false;
                foreach (DTOChiTietDH t in dsThanhPhamChon)
                {
                    if (t.dtoSP.MaSP == maThanhPham)
                    {
                        t.SoLuong += soluong;
                        trangthai  = true;
                        break;
                    }
                }
                if (trangthai == false)
                {
                    DTOChiTietDH tp    = new DTOChiTietDH();
                    DTOSanPham   dtoSP = daoEntities.TimTheoMaSP(maThanhPham);
                    tp.dtoSP     = dtoSP;
                    tp.SoLuong   = soluong;
                    tp.ThanhTien = gia * soluong;
                    dsThanhPhamChon.Add(tp);
                }

                hienThanhPhamChon();
                TongTien();
            }
        }
예제 #2
0
        protected void btnLuu_Click(object sender, EventArgs e)
        {
            if (Session["dsThanhPhamTra"] != null)
            {
                dsThanhPhamTra = (List <DTOChiTietDH>)Session["dsThanhPhamTra"];
                int    dem  = 0;
                string maDH = lbMaDH.Text;
                foreach (DTOChiTietDH dtoCTDH in dsThanhPhamTra)
                {
                    DTOXLSC_HDBH dtoct = new DTOXLSC_HDBH();
                    dtoct.MaDH      = lbMaDH.Text;
                    dtoct.MaSP      = dtoCTDH.dtoSP.MaSP;
                    dtoct.Soluong   = dtoCTDH.SoLuong;
                    dtoct.ThanhTien = dtoCTDH.ThanhTien;
                    if (daoEntities.ThemXuLyTraHang(dtoct))
                    {
                        DTOChiTietDH dtoChiTietDHTra      = new DTOChiTietDH();
                        DTOChiTietDH dtoChiTietDonHangDat = daoEntities.LayChiTietDonHangTheoMaDHMaSP(maDH, dtoCTDH.dtoSP.MaSP);
                        dtoChiTietDHTra.MaDH      = lbMaDH.Text;
                        dtoChiTietDHTra.MaSP      = dtoCTDH.dtoSP.MaSP;
                        dtoChiTietDHTra.SoLuong   = dtoChiTietDonHangDat.SoLuong - dtoCTDH.SoLuong;
                        dtoChiTietDHTra.ThanhTien = dtoChiTietDonHangDat.ThanhTien - dtoCTDH.ThanhTien;

                        if (daoEntities.CapNhatChiTietDH(dtoChiTietDHTra))
                        {
                            dem++;
                        }
                    }
                }

                if (dem == dsThanhPhamTra.Count)
                {
                    DTODonDatHang dtoDonHang    = daoEntities.LayDHTheoMa(maDH);
                    int           tongTienTra   = int.Parse(lbTongTien.Text),
                                  tongTienDaDat = dtoDonHang.TongTien,
                                  congnoCu = dtoDonHang.CongNoDH,
                                  tongTienPhaiTra = 0, congnoConLai = 0;
                    tongTienPhaiTra = tongTienDaDat - tongTienTra;
                    congnoConLai    = congnoCu - tongTienTra;
                    daoEntities.CapNhatDonHang(maDH, tongTienPhaiTra, congnoConLai);
                }

                Response.Redirect(Request.RawUrl);
            }
        }
        public void themct(DTOChiTietDH dtoCTDH)
        {
            DAO_Entity dao = new DAO_Entity();

            dao.ThemChiTietDH(dtoCTDH);
        }