protected void btnThem_Click(object sender, EventArgs e)
        {
            data = new dtKhachHang();
            DataTable db = data.DanhSachKhachHang_Import_Temp();

            if (db.Rows.Count != 0)
            {
                foreach (DataRow dr in db.Rows)
                {
                    string IDNhomKhachHang = dr["IDNhomKhachHang"].ToString();
                    string MaKhachHang     = dr["MaKhachHang"].ToString();
                    string TenKhachHang    = dr["TenKhachHang"].ToString();
                    string NgaySinh        = dr["NgaySinh"].ToString();
                    string DiaChi          = dr["DiaChi"].ToString();
                    string CMND            = dr["CMND"].ToString();
                    string DienThoai       = dr["DienThoai"].ToString();
                    string DiemTichLuy     = dr["DiemTichLuy"].ToString();

                    string GhiChu = dr["GhiChu"].ToString();

                    if (data.KiemTraSDTKhachHang(DienThoai) == 0)
                    {
                        data.ThemKhachHang(Int32.Parse(IDNhomKhachHang), MaKhachHang, TenKhachHang, DateTime.Parse(NgaySinh), CMND, DiaChi, DienThoai, GhiChu);
                        LoadGrid();
                    }
                }

                Response.Redirect("KhachHang.aspx");
            }
            else
            {
                Response.Write("<script language='JavaScript'> alert('Dữ liệu trống? Vui lòng kiểm tra lại.'); </script>");
            }
        }
Esempio 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"] == null ? "" : e.NewValues["TenKhachHang"].ToString();
            DateTime NgaySinh        = DateTime.Parse(e.NewValues["NgaySinh"] == null ? "" : 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();

            DateTime date  = DateTime.Now;
            string   sDate = date.ToString("MMddyyyy");
            int      MaKh  = 0;
            Random   dr    = new Random();

            while (MaKh == 0)
            {
                int sR = dr.Next(10000, 99999);
                int kt = data.KiemTraMaKhachHang(sDate + sR);
                if (kt == 0)
                {
                    MaKh = sR;
                }
            }

            string GhiChu = e.NewValues["GhiChu"] == null ? "" : e.NewValues["GhiChu"].ToString();

            if (data.KiemTraSDTKhachHang(DienThoai) == 0)
            {
                data.ThemKhachHang(IDNhomKhachHang, sDate + MaKh, TenKhachHang, NgaySinh, CMND, DiaChi, DienThoai, GhiChu);
                e.Cancel = true;
                KhachHangExport.CancelEdit();
                LoadGrid();
            }
            else
            {
                throw new Exception("Số điện thoại này đã được đăng ký.");
            }
        }