Example #1
0
        protected void gridHangHoa_RowInserting(object sender, DevExpress.Web.Data.ASPxDataInsertingEventArgs e)
        {
            data = new dataHangHoa();
            List <string> ListBarCode = GetListBarCode();
            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 IDDonViTinh = e.NewValues["IDDonViTinh"].ToString();
                float  GiaMua      = float.Parse(e.NewValues["GiaMua"].ToString());
                float  GiaBan      = float.Parse(e.NewValues["GiaBan"].ToString());
                string GhiChu      = e.NewValues["GhiChu"] != null ? e.NewValues["GhiChu"].ToString() : "";
                e.NewValues["HinhAnh"] = Session["UploadImages"];
                string HinhAnh = e.NewValues["HinhAnh"] != null ? e.NewValues["HinhAnh"].ToString() : "";
                int    KT      = 0;
                if (ListBarCode.Count == 0)
                {
                    KT = 1;
                    throw new Exception("Lỗi:Vui lòng nhập Barcode cho hàng hóa !!");
                    return;
                }
                foreach (string barCode in ListBarCode)
                {
                    if (dataHangHoa.KiemTraBarcode(barCode) == false)
                    {
                        KT = 1;
                        throw new Exception("Lỗi:Barcode đã tồn tại !!");
                        return;
                    }
                }
                if (KT == 0)
                {
                    object IDHangHoa = data.ThemHangHoa(IDNhomHang, MaHang, TenHangHoa, IDDonViTinh, GiaMua, GiaBan, GhiChu, HinhAnh);
                    if (IDHangHoa != null)
                    {
                        Session["UploadImages"] = "";
                        data.ThemDanhSachBarCode(IDHangHoa, ListBarCode);
                        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);
                        }
                    }
                    e.Cancel = true;
                    gridHangHoa.CancelEdit();
                    LoadGrid(cmbSoLuongXem.Value.ToString());
                }
            }
            else
            {
                Response.Write("<script language='JavaScript'> alert('Mã hàng đã tồn tại.'); </script>");
            }
        }
Example #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>");
            }
        }