コード例 #1
0
        // DAOKhachHang

        public List<DTOKhachHang> TaoDSKH()
        {
            List<DTOKhachHang> ds = new List<DTOKhachHang>();
            string lenh = "Select * from KhachHang kh, LoaiKH lkh where kh.malkh=lkh.malkh";
            ketnoi.TaoKetNoi();
            DataTable bang = new DataTable();
            try
            {
                ketnoi.LenhKetNoi = new SqlCommand(lenh, ketnoi.KetNoi);
                //dong bo lenh ket noi voi du lieu trong database
                ketnoi.TichHopCSDL = new SqlDataAdapter(ketnoi.LenhKetNoi);
                ketnoi.TichHopCSDL.Fill(bang);
                foreach (DataRow dongDL in bang.Rows)
                {
                    DTOKhachHang dtoKH = new DTOKhachHang(dongDL);
                    ds.Add(dtoKH);
                }
            }
            catch (Exception)
            {

                throw;
            }
            finally
            {
                ketnoi.DongKetNoi();
            }
            return ds;
        }
コード例 #2
0
        public bool ThemKhachHang(DTOKhachHang dtoKH)
        {
            bool ketqua = false;
            ketnoi.TaoKetNoi();
            try
            {
                string lenh = "insert into KhachHang(TenKH, DiaChi, Sdt, MaLKH) values (@tenkh, @diachi, @sdt, @malkh)";
                ketnoi.LenhKetNoi = new SqlCommand(lenh, ketnoi.KetNoi);

                //ketnoi.LenhKetNoi.Parameters.Add("@makh", SqlDbType.Int);
                ketnoi.LenhKetNoi.Parameters.Add("@tenkh", SqlDbType.NVarChar);
                ketnoi.LenhKetNoi.Parameters.Add("@diachi", SqlDbType.NVarChar);
                ketnoi.LenhKetNoi.Parameters.Add("@sdt", SqlDbType.VarChar);
                ketnoi.LenhKetNoi.Parameters.Add("@malkh", SqlDbType.Int);

                //ketnoi.LenhKetNoi.Parameters["@makh"].Value = dtoKH.MaKH;
                ketnoi.LenhKetNoi.Parameters["@tenkh"].Value = dtoKH.TenKH;
                ketnoi.LenhKetNoi.Parameters["@diachi"].Value = dtoKH.DiaChiKH;
                ketnoi.LenhKetNoi.Parameters["@sdt"].Value = dtoKH.SdtKH;
                ketnoi.LenhKetNoi.Parameters["@malkh"].Value = dtoKH.dtoLoaiKH.MaLKH;

                if (ketnoi.LenhKetNoi.ExecuteNonQuery() != 0)
                    ketqua = true;
            }
            catch (Exception)
            {


            }
            finally
            {
                ketnoi.DongKetNoi();
            }
            return ketqua;
        }
コード例 #3
0
        protected void btnLuu_Click(object sender, EventArgs e)
        {
            DTOKhachHang dtoKH = new DTOKhachHang();

            dtoKH.TenKH = txtTenKH.Text;
            dtoKH.DiaChiKH = txtDiaChi.Text;
            dtoKH.SdtKH = txtSdt.Text;

            DTOLoaiKH dtoLoaiKH = new DTOLoaiKH();
            dtoLoaiKH.MaLKH = int.Parse(ddLoaiKH.SelectedValue);
            dtoLoaiKH.TenLKH = ddLoaiKH.SelectedItem.ToString();
            dtoKH.dtoLoaiKH = dtoLoaiKH;

            XuLy_TiepNhanDonHang control = new XuLy_TiepNhanDonHang();
    //        DAO_Entity daoKH = new DAO_Entity();
            if (KiemTraNhap() == "")
            {
                control.ThemKH(dtoKH);
                Response.Redirect("~/QLBoPhan_TiepXucKH/DSKhachHang.aspx");
            }
            else
            {
                ThemKH.Visible = true;
                lbLoi.Text = KiemTraNhap();
            }
        }
コード例 #4
0
        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();
            }
        }
コード例 #5
0
 public DTODonDatHang(DataRow dongDL)
 {
     MaDH      = dongDL["MaDH"].ToString();
     MaKH      = (int)dongDL["MaKH"];
     TenKH     = dongDL["TenKH"].ToString();
     dtoKH     = new DTOKhachHang(dongDL);
     NgayTaoDH = (DateTime)dongDL["NgayTaoDH"];
     NgayGH    = (DateTime)dongDL["NgayGH"];
     TongTien  = (int)dongDL["TongTien"];
     CongNoDH  = (int)dongDL["CongNoDH"];
     TrangThai = dongDL["TrangThai"].ToString();
 }
コード例 #6
0
        public DTODonDatHang(DataRow dongDL)
        {
            MaDH = dongDL["MaDH"].ToString();
            MaKH = (int)dongDL["MaKH"];
            TenKH = dongDL["TenKH"].ToString();
            dtoKH = new DTOKhachHang(dongDL);           
            NgayTaoDH = (DateTime)dongDL["NgayTaoDH"];
            NgayGH = (DateTime)dongDL["NgayGH"];
            TongTien = (int)dongDL["TongTien"];            
            CongNoDH = (int)dongDL["CongNoDH"];
            TrangThai = dongDL["TrangThai"].ToString();

        }
コード例 #7
0
 public DTODSDonHang(DataRow dongDL)
 {
     MaDH          = dongDL["MaDH"].ToString();
     MaKH          = (int)dongDL["MaKH"];
     TenKH         = dongDL["TenKH"].ToString();
     dtoKH         = new DTOKhachHang(dongDL);
     NgayTaoDH     = (DateTime)dongDL["NgayTaoDH"];
     NgayGH        = (DateTime)dongDL["NgayGH"];
     TongTien      = (int)dongDL["TongTien"];
     CongNoDH      = (int)dongDL["CongNoDH"];
     TrangThai     = dongDL["TrangThai"].ToString();
     HanTT         = (DateTime)dongDL["HanTT"];
     NgayThanhToan = (DateTime)dongDL["NgayThanhToan"];
     //   Sotien = (int)dongDL["Sotien"];
     //   TongTienPG = (int)dongDL["TongTienPG"];
 }
コード例 #8
0
 public DTODSDonHang(DataRow dongDL)
 {
     MaDH = dongDL["MaDH"].ToString();
     MaKH = (int)dongDL["MaKH"];
     TenKH = dongDL["TenKH"].ToString();
     dtoKH = new DTOKhachHang(dongDL);
     NgayTaoDH = (DateTime)dongDL["NgayTaoDH"];
     NgayGH = (DateTime)dongDL["NgayGH"];
     TongTien = (int)dongDL["TongTien"];
     CongNoDH = (int)dongDL["CongNoDH"];
     TrangThai = dongDL["TrangThai"].ToString();
     HanTT = (DateTime)dongDL["HanTT"];
     NgayThanhToan = (DateTime)dongDL["NgayThanhToan"];
  //   Sotien = (int)dongDL["Sotien"];
  //   TongTienPG = (int)dongDL["TongTienPG"];
 }
コード例 #9
0
 public void ThemKH(DTOKhachHang dtoKH)
 {
     DAO_Entity dao = new DAO_Entity();
     dao.ThemKhachHang(dtoKH);
 }
コード例 #10
0
        // Sua TT khach hang
        public bool CapNhatKhachHang(DTOKhachHang dtoKH)
        {
            bool ketqua = false;
            ketnoi.TaoKetNoi();
            try
            {
                string lenh = "update KhachHang set TenKH= @tenkh, DiaChi = @diachi, Sdt = @sdt, MaLKH = @malkh where MaKH=@makh";
                ketnoi.LenhKetNoi = new SqlCommand(lenh, ketnoi.KetNoi);

                ketnoi.LenhKetNoi.Parameters.Add("@makh", SqlDbType.Int);
                ketnoi.LenhKetNoi.Parameters.Add("@tenkh", SqlDbType.NVarChar);
                ketnoi.LenhKetNoi.Parameters.Add("@diachi", SqlDbType.NVarChar);
                ketnoi.LenhKetNoi.Parameters.Add("@sdt", SqlDbType.VarChar);
                ketnoi.LenhKetNoi.Parameters.Add("@malkh", SqlDbType.Int);

                ketnoi.LenhKetNoi.Parameters["@makh"].Value = dtoKH.MaKH;
                ketnoi.LenhKetNoi.Parameters["@tenkh"].Value = dtoKH.TenKH;
                ketnoi.LenhKetNoi.Parameters["@diachi"].Value = dtoKH.DiaChiKH;
                ketnoi.LenhKetNoi.Parameters["@sdt"].Value = dtoKH.SdtKH;
                ketnoi.LenhKetNoi.Parameters["@malkh"].Value = dtoKH.dtoLoaiKH.MaLKH;//@malkh thi phai gan vao "MaLKH", sao lai gan cho dtoLoaiKh

                if (ketnoi.LenhKetNoi.ExecuteNonQuery() != 0)
                    ketqua = true;
            }
            catch (Exception)
            {

            }
            finally
            {
                ketnoi.DongKetNoi();
            }
            return ketqua;
        }
コード例 #11
0
        public List<DTOKhachHang> TimTheoTenKH(string tenTim)
        {
            List<DTOKhachHang> dsTim = new List<DTOKhachHang>();
            string lenh = "select * from KhachHang KH, LoaiKH LKH where KH.MaLKH = LKH.MaLKH and KH.TenKH like @ten";
            ketnoi.TaoKetNoi();
            DataTable bang = new DataTable();
            try
            {
                ketnoi.LenhKetNoi = new SqlCommand(lenh, ketnoi.KetNoi);
                ketnoi.LenhKetNoi.Parameters.Add("@ten", SqlDbType.NVarChar);
                ketnoi.LenhKetNoi.Parameters["@ten"].Value = "%" + tenTim + "%";

                ketnoi.TichHopCSDL = new SqlDataAdapter(ketnoi.LenhKetNoi);
                ketnoi.TichHopCSDL.Fill(bang);
                foreach (DataRow dongDL in bang.Rows)
                {
                    DTOKhachHang dtoKH = new DTOKhachHang(dongDL);
                    dsTim.Add(dtoKH);
                }
            }
            catch (Exception)
            {

            }
            finally
            {
                ketnoi.DongKetNoi();
            }
            return dsTim;
        }
コード例 #12
0
        //public bool XoaKhachHang(DTOKhachHang dtoKH)
        //{
        //    bool ketqua = false;
        //    ketnoi.TaoKetNoi();
        //    try
        //    {
        //        string lenh = "delete from KhachHang where MaKH = @makh";
        //        ketnoi.LenhKetNoi = new SqlCommand(lenh, ketnoi.KetNoi);

        //        ketnoi.LenhKetNoi.Parameters.Add("@makh", SqlDbType.Int);
        //        ketnoi.LenhKetNoi.Parameters["@makh"].Value = dtoKH.MaKH;

        //        if (ketnoi.LenhKetNoi.ExecuteNonQuery() != 0)
        //            ketqua = true;
        //    }
        //    catch (Exception) 
        //    {

        //    }
        //    finally
        //    {
        //        ketnoi.DongKetNoi();
        //    }
        //    return ketqua;
        //}

        //Lay TTKH tu ma de qua tranh Sua
        public DTOKhachHang LayTTKHTheoMa(string ma)
        {
            ketnoi.TaoKetNoi();
            DTOKhachHang dtoKH = null;
            try
            {
                string lenh = "select L.MaLKH,L.TenLKH,KH.MaKH,KH.TenKH,KH.Sdt,KH.Diachi from KhachHang KH,LoaiKH L where KH.MaKH = " + ma + " and KH.MaLKH=L.MaLKH ";
                ketnoi.LenhKetNoi = new SqlCommand(lenh, ketnoi.KetNoi);

                //ketnoi.LenhKetNoi.Parameters.Add("@makh", SqlDbType.Int);
                //ketnoi.LenhKetNoi.Parameters["@makh"].Value = maSua;

                DataTable bang = new DataTable();
                ketnoi.TichHopCSDL = new SqlDataAdapter(ketnoi.LenhKetNoi);
                ketnoi.TichHopCSDL.Fill(bang);
                DataRow dong = bang.Rows[0];
                dtoKH = new DTOKhachHang(dong);
            }
            catch (Exception)
            {

                throw;
            }
            finally
            {
                ketnoi.DongKetNoi();
            }
            return dtoKH;
        }