private void Import_Temp(DataTable datatable)
        {
            int intRow = datatable.Rows.Count;

            if (intRow != 0)
            {
                for (int i = 0; i <= intRow - 1; i++)
                {
                    DataRow dr = datatable.Rows[i];

                    DateTime date  = DateTime.Now;
                    string   sDate = date.ToString("MMddyyyy");
                    int      MaKh  = 0;
                    Random   rdom  = new Random();
                    while (MaKh == 0)
                    {
                        int sR = rdom.Next(10000, 99999);
                        int kt = data.KiemTraMaKhachHang(sDate + sR);
                        if (kt == 0)
                        {
                            MaKh = sR;
                        }
                    }
                    string maKHang = sDate + MaKh;

                    dtNhomKhachHang dtNhomKH        = new dtNhomKhachHang();
                    int             IDNhomKhachHang = dtNhomKH.LayIDNhomKhachHang_Ten("Nhóm khách hàng");

                    string TenKhachHang = dr["Tên khách hàng"].ToString();
                    string NgaySinh     = dr["Ngày sinh"] == null ? "" : dr["Ngày sinh"].ToString();
                    string CMND         = dr["CMND"] == null ? "" : dr["CMND"].ToString();
                    string DiaChi       = dr["Địa chỉ"] == null ? "" : dr["Địa chỉ"].ToString();
                    string DienThoai    = dr["SĐT"].ToString();
                    string GhiChu       = dr["Ghi chú"] == null ? "" : dr["Ghi chú"].ToString();

                    data = new dtKhachHang();
                    data.ThemKhachHang_Temp(IDNhomKhachHang, maKHang, TenKhachHang, DateTime.Parse(NgaySinh), CMND, DiaChi, DienThoai, GhiChu);
                    LoadGrid();
                }
            }
        }
Exemple #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ý.");
            }
        }