protected void btnThemKhachHang_Click(object sender, EventArgs e)
 {
     if (cmbNhomKhachHang.Text != "" && txtTenKhachHang.Text != "" && cmbChietKhau.Text != "")
     {
         int         IDNhom      = Int32.Parse(cmbNhomKhachHang.Value.ToString());
         string      TenKH       = txtTenKhachHang.Text;
         string      SDT         = txtSoDienThoai.Text == null ? "" : txtSoDienThoai.Text;
         string      DC          = txtDiaChi.Text == null ? "" : txtDiaChi.Text;
         string      IDChietKhau = cmbChietKhau.Value.ToString();
         dtKhachHang dtkh        = new dtKhachHang();
         string      MaKh        = "";
         string      Barcode     = "";
         object      ID          = dtkh.ThemKhachHang(IDNhom, MaKh, TenKH, DateTime.Now, "", DC, SDT, "", Barcode, "", Session["IDKho"].ToString(), IDChietKhau);
         if (ID != null)
         {
             dtkh = new dtKhachHang();
             dtkh.CapNhatMaKhachHang(ID, (Session["IDKho"].ToString() + "." + ID).ToString(), (Session["IDKho"].ToString() + "." + ID).Replace(".", ""));
         }
         DanhSachKhachHang();
         txtTenKhachHang.Text  = "";
         cmbNhomKhachHang.Text = "";
         txtSoDienThoai.Text   = "";
         txtDiaChi.Text        = "";
         cmbChietKhau.Text     = "";
         HienThiThongBao("Thêm khách hàng thành công !!");
         popupThemKhachHang.ShowOnPageLoad = false; return;
     }
     else
     {
         HienThiThongBao("Vui lòng nhập thông tin đầy đủ (*) !!"); return;
     }
 }
Ejemplo n.º 2
0
        protected void gridKhachHang_RowInserting(object sender, DevExpress.Web.Data.ASPxDataInsertingEventArgs e)
        {
            data = new dtKhachHang();
            int      IDNhomKhachHang = Int32.Parse(e.NewValues["IDNhomKhachHang"].ToString());
            string   TenKhachHang    = e.NewValues["TenKhachHang"].ToString();
            DateTime NgaySinh        = DateTime.Parse(e.NewValues["NgaySinh"] == null ? DateTime.Today.ToString() : e.NewValues["NgaySinh"].ToString());
            string   CMND            = e.NewValues["CMND"] == null ? "" : e.NewValues["CMND"].ToString();
            string   DiaChi          = e.NewValues["DiaChi"] == null ? "" : e.NewValues["DiaChi"].ToString();
            string   DienThoai       = e.NewValues["DienThoai"] == null ? "" : e.NewValues["DienThoai"].ToString();
            string   Email           = e.NewValues["Email"] == null ? "" : e.NewValues["Email"].ToString();
            string   MaKh            = "";
            string   Barcode         = "";
            object   ID;
            string   IDChietKhau = "2";
            string   GhiChu      = e.NewValues["GhiChu"] == null ? "" : e.NewValues["GhiChu"].ToString();

            if (DienThoai != "")
            {
                if (dtKhachHang.KT_SDT_KH(DienThoai.Trim()) != -1)
                {
                    throw new Exception("Lỗi: Số điện thoại đã tồn tại?");
                }
                else
                {
                    ID = data.ThemKhachHang(IDNhomKhachHang, MaKh, TenKhachHang, NgaySinh, CMND, DiaChi, DienThoai, Email, Barcode, GhiChu, Session["IDKho"].ToString(), IDChietKhau);
                    if (ID != null)
                    {
                        if (e.NewValues["MaKhachHang"] == null)
                        {
                            data = new dtKhachHang();
                            data.CapNhatMaKhachHang(ID, (dtSetting.LayMaKho(Session["IDKho"].ToString()) + "." + (Int32.Parse(ID.ToString()) * 0.0001).ToString().Replace(".", "")).ToString(), (Session["IDKho"].ToString() + "." + (Int32.Parse(ID.ToString()) * 0.0001)).Replace(".", ""));
                            dtLichSuTruyCap.ThemLichSu(Session["IDNhanVien"].ToString(), Session["IDNhom"].ToString(), "Khách hàng:" + TenKhachHang, Session["IDKho"].ToString(), "Danh Mục", "Thêm");
                        }
                    }
                }
            }
            else
            {
                ID = data.ThemKhachHang(IDNhomKhachHang, MaKh, TenKhachHang, NgaySinh, CMND, DiaChi, DienThoai, Email, Barcode, GhiChu, Session["IDKho"].ToString(), IDChietKhau);
                if (ID != null)
                {
                    if (e.NewValues["MaKhachHang"] == null)
                    {
                        data = new dtKhachHang();
                        data.CapNhatMaKhachHang(ID, (Session["IDKho"].ToString() + "." + (Int32.Parse(ID.ToString()) * 0.0001).ToString().Replace(".", "")).ToString(), (Session["IDKho"].ToString() + "." + (Int32.Parse(ID.ToString()) * 0.0001)).Replace(".", ""));
                        dtLichSuTruyCap.ThemLichSu(Session["IDNhanVien"].ToString(), Session["IDNhom"].ToString(), "Khách hàng:" + TenKhachHang, Session["IDKho"].ToString(), "Danh Mục", "Thêm");
                    }
                }
            }
            e.Cancel = true;
            gridKhachHang.CancelEdit();
            LoadGrid();
        }