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();
            }
        }
 public DTOKhachHang(DataRow dongDL)
 {
     MaKH = (int)dongDL["makh"];
     //int.Parse(dongDL["makh"].ToString());
     TenKH     = dongDL["tenkh"].ToString();
     DiaChiKH  = dongDL["diachi"].ToString();
     SdtKH     = dongDL["sdt"].ToString();
     dtoLoaiKH = new DTOLoaiKH(dongDL);
 }
 public DTOKhachHang(DataRow dongDL)
 {
     MaKH = (int)dongDL["makh"]; 
     //int.Parse(dongDL["makh"].ToString());
     TenKH = dongDL["tenkh"].ToString();
     DiaChiKH = dongDL["diachi"].ToString();
     SdtKH = dongDL["sdt"].ToString();
     dtoLoaiKH = new DTOLoaiKH(dongDL);
 } 
        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();
            }

        }
        //Lay thong tin loai khach hang do vao ListBox 29/03/2015
        public List<DTOLoaiKH> LayDSLKH()
        {
            List<DTOLoaiKH> dsLKH = new List<DTOLoaiKH>();
            string lenh = "select * from LoaiKH";
            ketnoi.TaoKetNoi();
            DataTable bang = new DataTable();
            try
            {
                ketnoi.LenhKetNoi = new SqlCommand(lenh, ketnoi.KetNoi);
                ketnoi.TichHopCSDL = new SqlDataAdapter(ketnoi.LenhKetNoi);
                ketnoi.TichHopCSDL.Fill(bang);
                foreach (DataRow dongDL in bang.Rows)
                {
                    DTOLoaiKH dtoLKH = new DTOLoaiKH(dongDL);
                    dsLKH.Add(dtoLKH);
                }
            }
            catch (Exception)
            {

                throw;
            }
            finally
            {
                ketnoi.DongKetNoi();
            }
            return dsLKH;
        }
        public DTOLoaiKH LayThongTinLoaiKH(string maSua)
        {
            ketnoi.TaoKetNoi();
            DTOLoaiKH dtoloaikh = null;
            try
            {
                string lenh = "select * from LoaiKH where MaLKH = @maSua ";
                ketnoi.LenhKetNoi = new SqlCommand(lenh, ketnoi.KetNoi);

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

                DataTable bang = new DataTable();
                ketnoi.TichHopCSDL = new SqlDataAdapter(ketnoi.LenhKetNoi);
                ketnoi.TichHopCSDL.Fill(bang);
                DataRow dong = bang.Rows[0];
                dtoloaikh = new DTOLoaiKH(dong);

            }
            catch (Exception)
            { }
            finally
            {
                ketnoi.DongKetNoi();
            }
            return dtoloaikh;
        }
        //Xoa LoaiKH
        public bool XoaLoaiKH(DTOLoaiKH dtoloaikh)
        {
            bool kq = false;
            ketnoi.TaoKetNoi();
            try
            {
                string lenh = "delete from LoaiKH where MaLKH = @malkh";
                ketnoi.LenhKetNoi = new SqlCommand(lenh, ketnoi.KetNoi);

                ketnoi.LenhKetNoi.Parameters.Add("@malkh", SqlDbType.Int);
                ketnoi.LenhKetNoi.Parameters["@malkh"].Value = dtoloaikh.MaLKH;

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

            }
            finally
            {
                ketnoi.DongKetNoi();
            }
            return kq;
        }
        //Them LoaiKH
        public bool ThemLoaiKH(DTOLoaiKH dtoloaikh)
        {
            bool kq = false;
            ketnoi.TaoKetNoi();
            try
            {
                string lenh = " insert into LoaiKH (TenLKH) values (@tenlkh)";
                ketnoi.LenhKetNoi = new SqlCommand(lenh, ketnoi.KetNoi);

                //ketnoi.LenhKetNoi.Parameters.Add("@malkh", SqlDbType.Int);
                ketnoi.LenhKetNoi.Parameters.Add("@tenlkh", SqlDbType.NVarChar);


                //ketnoi.LenhKetNoi.Parameters["@malkh"].Value = dtoloaikh.MaLKH;
                ketnoi.LenhKetNoi.Parameters["@tenlkh"].Value = dtoloaikh.TenLKH;


                if (ketnoi.LenhKetNoi.ExecuteNonQuery() != 0)
                {
                    kq = true;

                }

            }
            catch (Exception)
            {

            }
            finally
            {
                ketnoi.DongKetNoi();
            }
            return kq;
        }