protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                DTOKhachHang dto = new DTOKhachHang();
                DAO_Entity daokh = new DAO_Entity();

                XuLy_TiepNhanDonHang control = new XuLy_TiepNhanDonHang();
                control.LayDSKhachHang();

                List<DTOKhachHang> Dskh = daokh.TaoDSKH();
                GridDSKH.DataSource = Dskh;
                GridDSKH.DataBind();
            }
            catch (Exception)
            {

                Response.Write("<script>alert('Loi tai du lieu!')</script>");
            }
            ThemKH.Visible = false;


            if (IsPostBack == false)
            {
                List<DTOLoaiKH> dsLKH = new List<DTOLoaiKH>();
                DAO_Entity daoKH = new DAO_Entity();
                dsLKH = daoKH.LayDSLKH();
                //hien thi ten loai KH ra dropdownlist
                ddLoaiKH.DataTextField = "TenLKH";//TenLKH la thuoc tinh trong DTOLoaiKH
                //truyen dl theo ma loai 
                ddLoaiKH.DataValueField = "MaLKH";//MaLKH la thuoc tinh trong DTOLoaiKH
                ddLoaiKH.DataSource = dsLKH;
                ddLoaiKH.DataBind();
            }
        }
        protected void btbLuu_Click(object sender, EventArgs e)
        {
            DTOThanhToan dtocn = new DTOThanhToan();
            dtocn.MaDH = txtMaDH.Text;
            dtocn.MaNV = int.Parse(txtNhanVien.Text);
            dtocn.NgayThanhToan = Convert.ToDateTime(txtNgayThanhToan.Text);
            dtocn.Sotien = int.Parse(txtDatCoc.Text);
            dtocn.HanTT = Convert.ToDateTime(txtHanTT.Text);



            DAO_Entity daokh = new DAO_Entity();

            XuLy_TiepNhanDonHang control = new XuLy_TiepNhanDonHang();
            control.themdatcoc(dtocn);

            DTODonDatHang dtodh = new DTODonDatHang();
            dtodh.MaDH = txtMaDH.Text;
            int tong = int.Parse(txtTong.Text);
            int no = int.Parse(txtDatCoc.Text);
            dtodh.CongNoDH = tong - no;
            daokh.CapNhatCongNo(dtodh);


            Response.Redirect("~/QLBoPhan_TiepXucKH/TaoDonHang.aspx?MaKH=" + int.Parse(txtMaKH.Text));
        }
        public void LayDSCN_BH()
        {
            //DanhsachCongNoBH
            DAO_Entity dao = new DAO_Entity();
            dao.LayDSCongNoBH();

        }
        protected void btnLuu_Click(object sender, EventArgs e)
        {
            DTOCongNoBanHang dto = new DTOCongNoBanHang();
            dto.MaDH = lbMaDH.Text;
            dto.MaKH = int.Parse(lbMaKH.Text);
            dto.MaNV = int.Parse(txtMaNV.Text);
            dto.NgayTraNo = Convert.ToDateTime(lbNgayTra.Text);
            dto.TienTT = int.Parse(txtTienTT.Text);

            DAO_Entity dao = new DAO_Entity();
            dao.ThemCongNoBH(dto);

            DTODonDatHang dtodh = new DTODonDatHang();
            dtodh.MaDH = lbMaDH.Text;
            int tong = int.Parse(lbTienTra.Text);
            int no = int.Parse(txtTienTT.Text);
            dtodh.CongNoDH = tong - no;
            dao.CapNhatCongNo(dtodh);

            if (dtodh.CongNoDH == 0)
            {
                dao.CapNhatTrangThaisauThanhToan(dtodh);
            }

            Response.Redirect("~/QLBoPhan_ThanhPham/QuanLyQuanNo_BH/DanhSachCongNo_BH.aspx");
        }
        protected void btnLuuUser_Click(object sender, EventArgs e)
        {
            DTOUser dtond = new DTOUser();

            dtond.ID = txtID.Text;
            dtond.MK = txtMK.Text;
            dtond.HTuser = txtHoTen.Text;

            DTONhomQuyen dtonq = new DTONhomQuyen();
            dtonq.MaNQ = int.Parse(ddlNhomQ.SelectedValue);
            dtonq.NhomQ = ddlNhomQ.SelectedItem.ToString();
            dtond.dtoNhomQ = dtonq;

            DAO_Entity daond = new DAO_Entity();
            if (KiemTraNhap() == "")
            {
                daond.ThemUser(dtond);
                Response.Redirect("~/QLBophan_Admin/QLUser/User.aspx");
            }
            else
            {
                ThemUser.Visible = true;
                lbLoi.Text = KiemTraNhap();
            }
        }
 protected void btnTim_Click(object sender, EventArgs e)
 {
     DAO_Entity dao = new DAO_Entity();
     string tendetim = txtTimTen.Text;
     List<DTOKhachHang> kqTim = dao.TimTheoTenKH(tendetim);
     GridKH.DataSource = kqTim;
     GridKH.DataBind();
 }
 private string KiemTraNhap()
 {
     string kq = "";
     DAO_Entity daoKH = new DAO_Entity();
     if (txtTenTT.Text.Trim() == "")
     {
         kq += "Vui lòng nhập tên!";
     }
     return kq;
 }
        protected void btnTim_Click(object sender, EventArgs e)
        {
            DAO_Entity daoKH = new DAO_Entity();

            XuLy_TiepNhanDonHang control = new XuLy_TiepNhanDonHang();
            control.TimtenKH(txtTim.Text.Trim());

            List<DTOKhachHang> kqTim = daoKH.TimTheoTenKH(txtTim.Text.Trim());
            GridDSKH.DataSource = kqTim;
            GridDSKH.DataBind();
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {              

                hienThanhPhamChon();

                if (Session["dsThanhPhamChon"] == null)
                {
                    lbDSChon.Visible = false;
                    lbTextTongTien.Visible = false;
                    lbTongTien.Visible = false;
                    lbDSSanpham.Visible = false;
                    grDSSanPham.Visible = false;
                    gridDSChon.Visible = false;
                }
                else
                {
                    lbDSChon.Visible = true;
                    lbTextTongTien.Visible = true;
                    lbTongTien.Visible = true;
                    lbDSSanpham.Visible = true;
                    grDSSanPham.Visible = true;
                    gridDSChon.Visible = true;
                }
            }
            catch (Exception)
            {
                Response.Write("<script>alert('Loi tai du lieu!')</script>");
            }

            if (IsPostBack == false)//postback=false: chưa có sự kiện click trên web
            {
                // request: yeu cau. QueryString: lay gia tri cua chuoi tren duong dan
                string makh = Request.QueryString["MaKH"].ToString();
                DAO_Entity daoEntities = new DAO_Entity();
                DTOKhachHang dtoKH = daoEntities.LayTTKHTheoMa(makh);

                XuLy_TiepNhanDonHang control = new XuLy_TiepNhanDonHang();
                control.LayttKH(makh);

                lbMaKH.Text = dtoKH.MaKH.ToString();
                txtTen.Text = dtoKH.TenKH;
                txtNgayTaoDH.Text = DateTime.Now.ToShortDateString();

                
                List<DTODonDatHang> dsdh = daoEntities.LayDSDHTheoMa(makh);
                GridViewDH.DataSource = dsdh;
                GridViewDH.DataBind();
                grDSSanPham.DataSource = daoEntities.TaoDSSP();
                grDSSanPham.DataBind();
            }
        }
 protected void GridDSKH_RowCommand(object sender, GridViewCommandEventArgs e)
 {
     if (e.CommandName == "cmdXoa")
     {
         LinkButton btnXoa = (LinkButton)e.CommandSource;
         string MaKH = btnXoa.CommandArgument;
         DAO_Entity daoKH = new DAO_Entity();
         if (daoKH.XoaKhachHang(int.Parse(MaKH)) == true)
         {
             Response.Redirect("~/QLKhachHang/KhachHang.aspx");
         }
     }
 }
 protected void Page_Load(object sender, EventArgs e)
 {
     if (IsPostBack == false)
     {
         string maPD = Request.QueryString["MaPDVLCC"].ToString();
         DAO_Entity daoPD = new DAO_Entity();
         DTOPhieuDatVatLieuCC dtoDH = daoPD.LayTTPhieuDatTheoMa(maPD);
         lbMPD.Text = dtoDH.MaPDVLCC.ToString();
         lbNCC.Text = dtoDH.dtoncc.MaNCC.ToString();
         lbTenNCC.Text = dtoDH.TenNCC.ToString();
         lbNTT.Text = DateTime.Now.ToShortDateString();
         lbTong.Text = dtoDH.CongNoNCC.ToString();
     }
 }
 protected void Page_Load(object sender, EventArgs e)
 {
     try
     {
         DAO_Entity daokh = new DAO_Entity();
         List<DTOPhieuDatVatLieuCC> dsdh = daokh.LayDSCongNoNCC();
         GridView1.DataSource = dsdh;
         GridView1.DataBind();
     }
     catch (Exception)
     {
         Response.Write("<script>alert('Loi tai du lieu!')</script>");
     }
 }
        protected void btLuuCt_Click(object sender, EventArgs e)
        {
            int ma = int.Parse(lbMadh.Text);
            DAO_Entity daokh = new DAO_Entity();
            DTODonDatHang dtodh = new DTODonDatHang();
            DTOChiTietDonHang dtoct = daokh.LayTongTien(ma);
            
            dtodh.TongTien = int.Parse(dtoct.ThanhTien.ToString());
            dtodh.CongNoDH = dtodh.TongTien;
            daokh.CapNhatTongTien(dtodh);
            
            Response.Redirect("~/QLBoPhan_TiepXucKH/TaoDonHang.aspx?MaKH="+lbMaKH.Text);

        }
        protected void Page_Load(object sender, EventArgs e)
        {

             if (IsPostBack == false)
             {
                 string maDH = Request.QueryString["MaDH"].ToString();
                 DAO_Entity daoDH = new DAO_Entity();
                 DTODonDatHang dtoDH = daoDH.LayDHTheoMa(maDH);
                 txtMaDH.Text = dtoDH.MaDH.ToString();
                 txtMaKH.Text = dtoDH.MaKH.ToString();
                 txtTenKH.Text = dtoDH.TenKH.ToString();
                 txtTong.Text = dtoDH.TongTien.ToString();
                 txtNgayThanhToan.Text = DateTime.Now.ToShortDateString();
             }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                DAO_Entity daokh = new DAO_Entity();
                List<DTOKhachHang> dsKH = daokh.TaoDSKH();
                GridKH.DataSource = dsKH;
                GridKH.DataBind();
            }
            catch (Exception)
            {

                Response.Write("<script>alert('Loi tai du lieu!')</script>");
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (IsPostBack == false)
            {
                string maDH = Request.QueryString["MaDH"].ToString();

                Xuly_PhanboThanhPham control = new Xuly_PhanboThanhPham();
                control.LayDonHangTheoMa(maDH);

                DAO_Entity daoDH = new DAO_Entity();
                DTODonDatHang dtoDH = daoDH.LayDHTheoMa(maDH);
                lbMaDH.Text = dtoDH.MaDH.ToString();
                lbKH.Text = dtoDH.MaKH.ToString();
            }


            try
            {
                
                string madh = Request.QueryString["MaDH"].ToString();

                Xuly_PhanboThanhPham control = new Xuly_PhanboThanhPham();
                control.LayCTDH(madh);


                DAO_Entity daokh = new DAO_Entity();
                List<DTOChiTietDH> dtoct = daokh.LayDSChiTietDH(madh);
                GridView1.DataSource = dtoct;
                GridView1.DataBind();

                List<DTOXuLyPhieuGiao> dto = daokh.LayDSPhieuGiao(madh);
                GridView3.DataSource = dto;
                GridView3.DataBind();

                control.LayDSkhosp();

                List<DTOKhoSP> dtok = daokh.LayDSKhoSP();
                GridView2.DataSource = dtok;
                GridView2.DataBind();

            }
            catch
            {
                Response.Write("<script>alert('Loi tai du lieu!')</script>");
            }
           
        }
 private string KiemTraNhap()
 {
     string kq = "";
     DAO_Entity daoKH = new DAO_Entity();
     if (txtTen.Text.Trim() == "")
     {
         kq += "Vui lòng nhập tên!";
     }
     if (txtSDT.Text.Trim() == "")
     {
         kq += "Vui Lòng nhập SDT!";
     }
     if (txtDiaChi.Text.Trim() == "")
     {
         kq += "Vui Lòng nhập địa chỉ!";
     }
     return kq;
 }
 private string KiemTraNhap()
 {
     string kq = "";
     DAO_Entity daoKH = new DAO_Entity();
     if (txtID.Text.Trim() == "")
     {
         kq += "Vui lòng nhập ID!";
     }
     if (txtMK.Text.Trim() == "")
     {
         kq += "<br>Vui lòng nhập Mật Khẩu!";
     }
     if (txtHoTen.Text.Trim() == "")
     {
         kq += "Vui lòng nhập Họ Tên!";
     }
     return kq;
 }
        protected void btnLuuKH_Click(object sender, EventArgs e)
        {
            DTOLoaiKH dtoLKH = new DTOLoaiKH();
            dtoLKH.TenLKH = txtTenLKH.Text;

            DAO_Entity daoLKH = new DAO_Entity();
            if (KiemTraNhap() == "")
            {
                daoLKH.ThemLoaiKH(dtoLKH);
                Response.Redirect("~/QLBophan_Admin/QLCauHinhLoaiKH/LoaiKH.aspx");
            }
            else
            {
                ThemLoaiKH.Visible = true;
                lbLoi.Text = KiemTraNhap();
            }

        }
        protected void btnLuuSP_Click(object sender, EventArgs e)
        {
            DTOLoaiSP dtoLSP = new DTOLoaiSP();
            dtoLSP.TenLSP = txtLSP.Text;

            DAO_Entity daoLSP = new DAO_Entity();
            if (KiemTraNhap() == "")
            {
                daoLSP.ThemLoaiSP(dtoLSP);
                Response.Redirect("~/QLBophan_Admin/QLCauHinhLoaiSP/LoaiSP.aspx");
            }
            else
            {
                ThemLoaiSP.Visible = true;
                lbLoi.Text = KiemTraNhap();
            }

        }
        protected void btnThem_Click(object sender, EventArgs e)
        {
            ThemUser.Visible = true;
            //Response.Redirect("~/QLUser/ThemUser.aspx");

            if (IsPostBack == false)
            {
                List<DTONhomQuyen> dsnq = new List<DTONhomQuyen>();
                DAO_Entity daond = new DAO_Entity();
              //  dsnq = daond.LayDSNhomQuyen();

                ddlNhomQ.DataTextField = "NhomQuyen";

                ddlNhomQ.DataValueField = "MaNhomQ";
                ddlNhomQ.DataSource = dsnq;
                ddlNhomQ.DataBind();
            }

        }
        protected void btnLu_Click(object sender, EventArgs e)
        {
            
            DTONhacungcap dtoncc = new DTONhacungcap();
            dtoncc.TenNCC = txtTen.Text;
            dtoncc.Sdt = txtSDT.Text;
            dtoncc.Diachi = txtDiaChi.Text;

            DAO_Entity daoncc = new DAO_Entity();
             if (KiemTraNhap() == "")
            {
                daoncc.ThemNhaCungCap(dtoncc);
                Response.Redirect("~/QLBophan_Admin/QLCauHinhNCC/NCC.aspx");
            }
            else
            {
                ThemNCC.Visible = true;
                lbLoi.Text = KiemTraNhap();
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                if (IsPostBack == false)
                {

                    XuLy_NhapTP control = new XuLy_NhapTP();
                    control.LayDHdangXL();

                    DAO_Entity entities = new DAO_Entity();
                    gridDSDonHang.DataSource = entities.LayDSDonHangDangXuLy();
                    gridDSDonHang.DataBind();
                }
            }
            catch (Exception)
            {
                
                throw;
            }
        }
        protected void btnLuuTT_Click(object sender, EventArgs e)
        {
            

            DTOTrangThai dtott = new DTOTrangThai();
            dtott.TenTT = txtTenTT.Text;

            DAO_Entity daott = new DAO_Entity();

            if (KiemTraNhap() == "")
            {
                daott.ThemTT(dtott);
                Response.Redirect("~/QLBophan_Admin/QLCauHinhTrangThai/TrangThai.aspx");
            }
            else
            {
                ThemTT.Visible = true;
                lbLoi.Text = KiemTraNhap();
            }

        }
        protected void btnLuu_Click(object sender, EventArgs e)
        {
            
            DTOCongNoVatLieu dtovl = new DTOCongNoVatLieu();
            dtovl.MaPDVLCC = int.Parse(lbMPD.Text);
            dtovl.MaNCC = int.Parse(lbNCC.Text);
            dtovl.MaNV = int.Parse(TextBox1.Text);
            dtovl.NgayTraNo = Convert.ToDateTime(lbNTT.Text);
            dtovl.Sotien = int.Parse(TextBox2.Text);

            DAO_Entity dao = new DAO_Entity();
            dao.ThemCongNoNCC(dtovl);


            DTOPhieuDatVatLieuCC dtopd = new DTOPhieuDatVatLieuCC();
            dtopd.MaPDVLCC = lbMPD.Text;
            int tong = int.Parse(lbTong.Text);
            int no = int.Parse(TextBox2.Text);
            dtopd.CongNoNCC = tong - no;
            dao.CapNhatCongNoNCC(dtopd);

            Response.Redirect("~/QLBoPhan_VatLieu/QLCongNoNCC/DanhSachCongNo.aspx");
        }
 public void xuatpgiao(DTOXuLyPhieuGiao dtoCtDH)
 {
     DAO_Entity dao = new DAO_Entity();
     dao.ThemPhieuGiaoHang(dtoCtDH);
 }
 public void LayDSkhosp()
 {
     DAO_Entity dao = new DAO_Entity();
     dao.LayDSKhoSP();
 }
 public void LayCTDH(string ma)
 {
     DAO_Entity dao = new DAO_Entity();
     dao.LayDSChiTietDH(ma);
 }
 public void LayDonHangTheoMa(string ma)
 {
     DAO_Entity dao = new DAO_Entity();
     dao.LayDHTheoMa(ma);
 }
 public void Themgiaohang(DTOHoaDonBH dto)
 {
     DAO_Entity dao = new DAO_Entity();
     dao.ThemPhieuGiaoHang(dto);
 }