protected void gridHangHoa_RowInserting(object sender, DevExpress.Web.Data.ASPxDataInsertingEventArgs e)
        {
            data = new dtHangHoa();
            string MaHangHoa   = dtHangHoa.Dem_Max();
            string TenHangHoa  = e.NewValues["TenHangHoa"].ToString();
            string GiaBan      = e.NewValues["GiaBan"].ToString();
            string IDDonViTinh = e.NewValues["IDDonViTinh"].ToString();
            string IDNhomHang  = e.NewValues["IDNhomHang"].ToString();
            string GhiChu      = e.NewValues["GhiChu"] == null ? "" : e.NewValues["GhiChu"].ToString();
            string IDChiNhanh  = Session["IDChiNhanh"].ToString();
            object ID          = data.ThemHangHoa(MaHangHoa, TenHangHoa, GiaBan, IDDonViTinh, IDNhomHang, GhiChu, IDChiNhanh);

            if (ID != null)
            {
                //thêm vào all bảng giá
                dtBangGia bg  = new dtBangGia();
                DataTable dbt = bg.DanhSach(IDChiNhanh);
                foreach (DataRow dr in dbt.Rows)
                {
                    string IDBangGia = dr["ID"].ToString();
                    bg.ThemIDHangHoaVaoChiTietGia(ID.ToString(), IDBangGia, GiaBan, IDChiNhanh);
                }
            }
            e.Cancel = true;
            gridHangHoa.CancelEdit();
            LoadGrid();

            dtLichSuTruyCap.ThemLichSu(Session["IDChiNhanh"].ToString(), Session["IDNhom"].ToString(), Session["IDNhanVien"].ToString(), "Quản lý hàng hóa", "Thêm hàng hóa: " + TenHangHoa);
        }
Exemple #2
0
        protected void gridHangHoa_RowInserting(object sender, DevExpress.Web.Data.ASPxDataInsertingEventArgs e)
        {
            data = new dataHangHoa();
            string    MaHang = e.NewValues["MaHang"].ToString();
            DataTable dd     = data.KiemTraHangHoa(MaHang);

            if (dd.Rows.Count == 0)
            {
                string IDNhomHang    = e.NewValues["IDNhomHang"].ToString();
                string TenHangHoa    = e.NewValues["TenHangHoa"].ToString();
                string IDDonViTinhLe = e.NewValues["IDDonViTinhLe"].ToString();
                string IDDonViTinhSi = e.NewValues["IDDonViTinhSi"].ToString();
                double GiaMua        = Double.Parse(e.NewValues["GiaMua"].ToString());
                double GiaBan        = Double.Parse(e.NewValues["GiaBan"].ToString());
                double DoDay         = Double.Parse(e.NewValues["DoDay"].ToString());
                double ChieuDai      = Double.Parse(e.NewValues["ChieuDai"].ToString());
                string GhiChu        = e.NewValues["GhiChu"] != null ? e.NewValues["GhiChu"].ToString() : "";
                object IDHangHoa     = data.ThemHangHoa(IDNhomHang, MaHang, TenHangHoa, IDDonViTinhLe, IDDonViTinhSi, GiaMua, GiaBan, GhiChu, DoDay.ToString(), ChieuDai.ToString());
                if (IDHangHoa != null)
                {
                    //thêm vào tồn kho
                    DataTable dta = data.LayDanhSachCuaHang();
                    for (int i = 0; i < dta.Rows.Count; i++)
                    {
                        DataRow dr    = dta.Rows[i];
                        int     IDKho = Int32.Parse(dr["ID"].ToString());
                        data.ThemHangVaoTonKho(IDKho, (int)IDHangHoa, 0);
                    }

                    //thêm vào all bảng giá
                    dtBangGia bg  = new dtBangGia();
                    DataTable dbt = bg.DanhSach();
                    foreach (DataRow dr in dbt.Rows)
                    {
                        string IDBangGia = dr["ID"].ToString();
                        bg.ThemIDHangHoaVaoChiTietGia(IDHangHoa, IDBangGia, GiaBan.ToString());
                    }
                }
                e.Cancel = true;
                gridHangHoa.CancelEdit();
                LoadGrid(cmbSoLuongXem.Value.ToString());
            }
            else
            {
                Response.Write("<script language='JavaScript'> alert('Mã hàng đã tồn tại.'); </script>");
            }
        }
        protected void gridBangGia_RowInserting(object sender, DevExpress.Web.Data.ASPxDataInsertingEventArgs e)
        {
            string TenBangGia = e.NewValues["TenBangGia"].ToString();

            data = new dtBangGia();
            object ID = data.ThemMoi(TenBangGia);

            if (ID != null)
            {
                dtHangHoa hh = new dtHangHoa();
                DataTable db = hh.LayDanhSachHangHoa();
                foreach (DataRow dr in db.Rows)
                {
                    string IDHangHoa = dr["ID"].ToString();
                    string GiaBan    = dr["GiaBan"].ToString();
                    data = new dtBangGia();
                    data.ThemIDHangHoaVaoChiTietGia(IDHangHoa, ID, GiaBan);
                }
            }
            e.Cancel = true;
            gridBangGia.CancelEdit();
            LoadGrid();
        }
        protected void gridChiNhanh_RowInserting(object sender, DevExpress.Web.Data.ASPxDataInsertingEventArgs e)
        {
            string   MaChiNhanh  = dtChiNhanh.Dem_Max();
            string   TenChiNhanh = e.NewValues["TenChiNhanh"].ToString();
            string   DienThoai   = e.NewValues["DienThoai"] == null ? "" : e.NewValues["DienThoai"].ToString();
            string   Email       = e.NewValues["Email"] == null ? "" : e.NewValues["Email"].ToString();
            string   DiaChi      = e.NewValues["DiaChi"] == null ? "" : e.NewValues["DiaChi"].ToString();
            DateTime NgayMo      = DateTime.Parse(e.NewValues["NgayMo"].ToString());
            string   DuLieuMau   = e.NewValues["DuLieuMau"] == null ? "0" : "1";
            string   Key         = RandomString(5) + "-" + RandomString(5) + "-" + RandomString(5) + "-" + RandomString(5) + "-" + RandomString(5);

            data = new dtChiNhanh();
            object ID = data.ThemChiNhanh(MaChiNhanh, TenChiNhanh, DienThoai, DiaChi, NgayMo, DuLieuMau, Key, Email);

            if (ID != null)
            {
                // tạo key kích hoạt
                data = new dtChiNhanh();
                data.ThemKeyKichHoat(Key, ID.ToString());

                // Tạo bảng giá
                dtBangGia dtBangGia = new dtBangGia();
                object    IDBangGia = dtBangGia.ThemMoi("Bảng Giá Thường", ID.ToString());

                // tạo khu vực
                dtKhuVuc dtKhuVuc = new dtKhuVuc();
                object   IDKhuVuc = dtKhuVuc.Them("", "Khu A", "0", ID.ToString(), TenChiNhanh, "A", IDBangGia.ToString());

                //tạo tài khoản
                dtQuanTriNguoiDung dtNguoiDung = new dtQuanTriNguoiDung();
                if (dtQuanTriNguoiDung.KiemTraNguoiDung(DienThoai.Trim()) != -1)
                {
                    throw new Exception("Lỗi: Tên đăng nhập đã tồn tại");
                }
                else
                {
                    dtNguoiDung.ThemNguoiDung(dtQuanTriNguoiDung.Dem_Max(), "Quản trị", DienThoai, 1, DienThoai, dtSetting.GetSHA1HashData(DienThoai), Email, ID.ToString());
                    dtNguoiDung.ThemNguoiDung(dtQuanTriNguoiDung.Dem_Max(), "Thu ngân", "BH." + DienThoai, 2, DienThoai, dtSetting.GetSHA1HashData(DienThoai), Email, ID.ToString());
                }


                if (DuLieuMau == "1")
                {
                    //tạo dữ liệu mẫu, lấy Chi Nhánh 1 ra làm

                    //thêm đVT
                    dtDonViTinh dtDVT = new dtDonViTinh();
                    DataTable   tbdvt = dtDVT.LayDanhSachDonViTinh("1");
                    foreach (DataRow dr in tbdvt.Rows)
                    {
                        dtDVT.ThemDonViTinh(dr["TenDonViTinh"].ToString(), ID.ToString());
                    }

                    //Thêm nhóm hàng
                    dtNhomHangHoa dtNhomHang = new dtNhomHangHoa();
                    DataTable     tbNhomHang = dtNhomHang.DanhSach("1");
                    foreach (DataRow dr1 in tbNhomHang.Rows)
                    {
                        object IDNhomHangMoi = dtNhomHang.Them(dtNhomHangHoa.Dem_Max(), dr1["TenNhom"].ToString(), "", ID.ToString());
                        //Thêm hàng hóa
                        dtHangHoa dtHH = new dtHangHoa();
                        DataTable tbHH = dtHH.DanhSachHangHoa_IDnhomHang(dr1["ID"].ToString(), "1");
                        foreach (DataRow dr in tbHH.Rows)
                        {
                            string IDDVTCU = dr["IDDonViTinh"].ToString();

                            object IDHH = dtHH.ThemHangHoa(dtHangHoa.Dem_Max(), dr["TenHangHoa"].ToString(), dr["GiaBan"].ToString(), dtDonViTinh.LayIDDVT_Moi(IDDVTCU, ID.ToString()), IDNhomHangMoi.ToString(), dr["GhiChu"].ToString(), ID.ToString());
                            if (IDHH != null)
                            {
                                //thêm vào bảng giá
                                dtBangGia bg = new dtBangGia();
                                bg.ThemIDHangHoaVaoChiTietGia(IDHH.ToString(), IDBangGia, dr["GiaBan"].ToString(), ID.ToString());
                            }
                        }
                    }

                    //thêm  30 bàn mẫu
                    for (int i = 1; i <= 30; i++)
                    {
                        dtBan dtB = new dtBan();
                        dtB.Them("", "A - " + i, IDKhuVuc.ToString(), ID.ToString());
                    }
                }
            }
            e.Cancel = true;
            gridChiNhanh.CancelEdit();
            LoadGrid();

            dtLichSuTruyCap.ThemLichSu(Session["IDChiNhanh"].ToString(), Session["IDNhom"].ToString(), Session["IDNhanVien"].ToString(), "Chi nhánh", "Thêm chi nhánh: " + TenChiNhanh);
        }