private void btnCapnhat_Click(object sender, EventArgs e)
        {
            string sql;

            if (txtTenNCC.Text.Trim().Length == 0)
            {
                MessageBox.Show("Bạn Chưa Điền Tên Nhà Cung Cấp", "Thông báo");
                txtTenNCC.Focus();
                return;
            }
            if (txtDiachi.Text.Trim().Length == 0)
            {
                MessageBox.Show("Bạn Chưa Điền Địa Chỉ Nhà Cung Cấp", "Thông báo");
                txtDiachi.Focus();
                return;
            }
            if (txtSdt.Text.Trim().Length == 0)
            {
                MessageBox.Show("Bạn Chưa Điền SĐT Nhà Cung Cấp", "Thông báo");
                txtSdt.Focus();
                return;
            }
            sql = "UPDATE NhaCungCap Set TenNCC =N'" + txtTenNCC.Text + "',DiaChi=N'" + txtDiachi.Text + "',SDT=N'" + txtSdt.Text + "' where MaNCC = N'" + txtMaNCC.Text + "'";
            ThucThiSQL.CapNhatDuLieu(sql);
            MessageBox.Show("Bạn Sửa Thành Công", "Success");
            this.Close();
        }
        private void dataGridView1_DoubleClick(object sender, EventArgs e)
        {
            if (dataGridView1.Rows.Count == 0)
            {
                MessageBox.Show("Không có dữ liệu!", "Thông báo");
                return;
            }
            if (MessageBox.Show("Bạn có chắc chắn xóa không?", "Thông Báo", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
            {
                string sql;
                ThucThiSQL.CapNhatDuLieu("Delete ChiTietPN where MaMH='" + dataGridView1.CurrentRow.Cells["MaMH"].Value.ToString() + "'");            // đầu tiên xóa chi tiết phiếu nhập theo mã mặt hàng
                ThucThiSQL.CapNhatDuLieu("Delete MatHang where MaMH=N'" + dataGridView1.CurrentRow.Cells["MaMH"].Value.ToString() + "'");             // r xóa mặt hàng đó luôn
                ThucThiSQL.CapNhatDuLieu("Delete Hang where MaMH=N'" + dataGridView1.CurrentRow.Cells["MaMH"].Value.ToString() + "'");                // r xóa các hàng của mặt hàng đó

                MessageBox.Show("Hủy thành công");
                HienThi_Luoi();
                double tong = 0;
                for (int i = 0; i < dataGridView1.Rows.Count; i++)
                {
                    tong += Convert.ToDouble(dataGridView1.Rows[i].Cells[5].Value.ToString());
                }

                txtTongtien.Text = tong.ToString();           //set textbox tổng tiền bằng tổng vừa tính
                sql = "Update PhieuNhapHang Set TongTien =N'" + txtTongtien.Text + "' where MaPN='" + txtMaphieu.Text + "'";
                ThucThiSQL.CapNhatDuLieu(sql);                // cập nhật tổng tiền của phiếu mua hàng
            }
        }
        private void btnLuuHD_Click(object sender, EventArgs e)
        {
            if (cboMaNV.Text == "")
            {
                MessageBox.Show("Bạn phải chọn Mã NV!!!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            if (cboMaNCC.Text == "")
            {
                MessageBox.Show("Bạn phải chọn Nhà cung cấp!!!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            string sql;

            sql = "INSERT INTO tblHDNhap (MaHDNhap,MaNV,MaNCC,NgayNhap,TongTien) " +
                  "VALUES (N'" + txtMaHD.Text + "',N'" + cboMaNV.Text + "',N'" + cboMaNCC.Text + "',N'" + dtpNgayNhap.Value.ToString("yyyy/MM/dd") + "'," + txtTongTien.Text + ")";
            ThucThiSQL.CapNhatDuLieu(sql);
            btnLuuHD.Enabled    = false;
            btnHuyHD.Enabled    = true;
            btnThemHD.Enabled   = true;
            btnThemSP.Enabled   = true;
            grbThongtin.Enabled = true;
            grbChitiet.Enabled  = true;
            btnSua.Enabled      = true;
        }
        private void btnLuu_Click(object sender, EventArgs e)
        {
            string sql;

            if (txtLoaiMH.Text.Trim().Length == 0)
            {
                MessageBox.Show("Bạn Chưa Điền Tên Loại Mặt Hàng", "Thông báo");
                txtMaMH.Focus();
                return;
            }
            if (txtTenMH.Text.Trim().Length == 0)
            {
                MessageBox.Show("Bạn Chưa Điền Tên Mặt Hàng", "Thông báo");
                txtTenMH.Focus();
                return;
            }
            if (txtDongia.Text.Trim().Length == 0)
            {
                MessageBox.Show("Bạn Chưa Điền Đơn Giá Mặt Hàng", "Thông báo");
                txtDongia.Focus();
                return;
            }
            if (txtSL.Text.Trim().Length == 0)
            {
                MessageBox.Show("Bạn Chưa Điền Số Lượng Mặt Hàng", "Thông báo");
                txtSL.Focus();
                return;
            }
            sql = "UPDATE MatHang Set TenMH =N'" + txtTenMH.Text + "',LoaiMH=N'" + txtLoaiMH.Text + "' where MaMH = N'" + txtMaMH.Text + "'";
            ThucThiSQL.CapNhatDuLieu(sql);
            MessageBox.Show("Bạn Sửa Thành Công", "Success");
            this.Close();
        }
示例#5
0
        public void DelUpdateHang(string mahangxoa, double slxoa)
        {
            double sl    = Convert.ToDouble(ThucThiSQL.DocBang("SELECT SoLuongTon FROM tblSP WHERE MaSP=N'" + mahangxoa + "'").Rows[0][0].ToString());
            double slmoi = sl + slxoa;

            ThucThiSQL.CapNhatDuLieu("UPDATE tblSP SET SoLuongTon =" + slmoi + " WHERE MaSP=N'" + mahangxoa + "'");
        }
示例#6
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            if (cboMaHD.Text.Trim().Length == 0)
            {
                MessageBox.Show("Bạn phải nhập mã hóa đơn!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                cboMaHD.Focus();
                return;
            }

            if (cboMaSP.Text.Trim().Length == 0)
            {
                MessageBox.Show("Bạn phải nhập mã sản phẩm !", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                cboMaSP.Focus();
                return;
            }
            if (txtSoluong.Text.Trim().Length == 0 || (txtSoluong.Text == "0"))
            {
                MessageBox.Show("Bạn phải nhập số lượng !", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                txtSoluong.Focus();
                return;
            }
            if (txtDonGia.Text.Trim().Length == 0)
            {
                MessageBox.Show("Bạn phải nhập đơn giá !", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                txtDonGia.Focus();
                return;
            }
            //if (txtGiamgia.Text.Trim().Length == 0)
            //{
            //    MessageBox.Show("Bạn phải nhập giảm giá !", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            //    txtGiamgia.Focus();
            //    return;
            //}
            string sql = "SELECT MaSP FROM tblChitietHDN WHERE MaSP=N'" + cboMaSP.Text + "'AND MaHDN=N'" + txtMahoadon.Text.Trim() + "'";

            if (ThucThiSQL.DocBang(sql).Rows.Count > 0)
            {
                MessageBox.Show("Mã sản phẩm này đã có, bạn phải nhập mã khác !", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                ResetValuesHang();
                cboMaSP.Focus();
                return;
            }
            sql = "INSERT INTO tblChitietHDN(MaHDN,MaSP,SoLuong,DonGia,ThanhTien,KhuyenMai) VALUES(N'" + cboMaHD.Text.Trim() + "',N'" + cboMaSP.Text.ToString() + "'," + txtSoluong.Text + "," + txtDonGia.Text.Trim() + "," + txtThanhtien.Text + ", " + txtGiamgia.Text + ")";
            ThucThiSQL.CapNhatDuLieu(sql);
            Hienthi_Luoi();
            // Cập nhật số lượng mới vào bảng theo công thức
            double sl = Convert.ToDouble(ThucThiSQL.DocBang("SELECT SoLuong FROM tblSanPham WHERE MaSP = N'"
                                                            + cboMaSP.Text + "'").Rows[0][0].ToString());
            double slmoi = sl + Convert.ToDouble(txtSoluong.Text);

            sql = "UPDATE tblSanPham SET SoLuong = " + slmoi + "WHERE MaSP = N'" + cboMaSP.Text + "'";
            ThucThiSQL.CapNhatDuLieu(sql);
            //Cập nhật giá nhập vào bảng sản phẩm
            double dg = Convert.ToDouble(ThucThiSQL.DocBang("Select GiaNhap from tblSanPham where MaSP = N'"
                                                            + cboMaSP.Text + "'").Rows[0][0].ToString());
            double dgmoi = dg + Convert.ToDouble(txtDonGia.Text);

            sql            = "update tblSanPham Set GiaNhap = " + dgmoi + "Where MaSP = N'" + cboMaSP.Text + "'";
            btnHuy.Enabled = true;
        }
 private void btnHuyHD_Click(object sender, EventArgs e)
 {
     if (MessageBox.Show("Bạn có chắc chắn muốn xóa không?", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
     {
         // Lấy thông tin các mặt hàng sẽ bị xóa
         string    sql = "SELECT MaSP, SoLuong, DonGia FROM tblChitietHDNhap WHERE MaHDNhap = N'" + txtMaHD.Text + "'";
         DataTable tbl = ThucThiSQL.DocBang(sql);
         //xóa chi tiết hóa đơn
         sql = "DELETE tblChiTietHDNhap WHERE MaHDNhap=N'" + txtMaHD.Text + "'";
         ThucThiSQL.CapNhatDuLieu(sql);
         //xóa hóa đơn
         sql = "DELETE tblHDNhap WHERE MaHDNhap=N'" + txtMaHD.Text + "'";
         ThucThiSQL.CapNhatDuLieu(sql);
         ResetValues();
         Hienthi_luoi();
         // cập nhật lại số lượng,đơn giá nhập, đơn giá bán
         for (int i = 0; i < tbl.Rows.Count; i++)
         {
             DelUpdateHang(tbl.Rows[i][0].ToString(), Convert.ToDouble(tbl.Rows[i][1]), Convert.ToDouble(tbl.Rows[i][2]));
         }
         btnThemHD.Enabled   = true;
         btnHuyHD.Enabled    = false;
         btnInHD.Enabled     = false;
         btnThemSP.Enabled   = false;
         btnXoaSP.Enabled    = false;
         grbThongtin.Enabled = false;
         grbChitiet.Enabled  = false;
         dgvCT.DataSource    = null;
         dgvCT.Rows.Clear();
     }
 }
示例#8
0
        private void dataGridView1_DoubleClick(object sender, EventArgs e)
        {
            string sql = "Select * from tblChitietHDN where MaHDN=N'" + cboMaHD.Text + "'";

            if (ThucThiSQL.DocBang(sql).Rows.Count == 0)
            {
                MessageBox.Show("Không có dữ liệu!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            if (MessageBox.Show("Bạn có chắc chắn muốn xóa không?", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
            {
                //Lấy thông tin Mã hóa đơn, mã hàng, số lượng, giá nhập, thành tiền của dòng dl muốn xóa
                string mahdxoa      = dataGridView1.CurrentRow.Cells["MaHDN"].Value.ToString();
                string mahangxoa    = dataGridView1.CurrentRow.Cells["MaSP"].Value.ToString();
                double slxoa        = Convert.ToDouble(dataGridView1.CurrentRow.Cells["SoLuong"].Value.ToString());
                double dongiaxoa    = Convert.ToDouble(dataGridView1.CurrentRow.Cells["DonGia"].Value.ToString());
                double thanhtienxoa = Convert.ToDouble(dataGridView1.CurrentRow.Cells["ThanhTien"].Value.ToString());
                //Xóa hàng trong bảng Chi tiết HDN
                sql = "Delete tblChitietHDN where MaHDN=N'" + cboMaHD.Text + "'AND MaSP=N'" + mahangxoa + "'";
                ThucThiSQL.CapNhatDuLieu(sql);
                Hienthi_Luoi();
                //Cập nhật lại số lượng hàng, đơn giá nhập, đơn giá bán
                DelUpdateHang(mahangxoa, slxoa, dongiaxoa);
                //Cập nhật lại tổng tiền cho hóa đơn nhập
                //DelUpdateTongtien(txtMahoadon.Text, thanhtienxoa);
            }
        }
示例#9
0
        private void btnLuu_Click(object sender, EventArgs e)
        {
            string sql;

            if (txtMahoadon.Text.Length == 0)
            {
                MessageBox.Show("Bạn phải nhập mã hóa đơn!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                txtMahoadon.Focus();
                return;
            }
            if (txtNgaynhap.Text.Length == 0)
            {
                MessageBox.Show("Bạn phải nhập ngày nhập!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                txtNgaynhap.Focus();
                return;
            }
            if (cboMaNCC.Text.Length == 0)
            {
                MessageBox.Show("Bạn phải nhập mã nhà cung cấp!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                cboMaNCC.Focus();
                return;
            }
            if (cboManhanvien.Text.Length == 0)
            {
                MessageBox.Show("Bạn phải nhập mã nhân viên!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                cboManhanvien.Focus();
                return;
            }
            sql = "Insert into tblHoaDonNhap(MaHDN, NgayNhap, MaNV, MaNCC, TongTien) values ( N'" + txtMahoadon.Text.Trim() + "', '" + ThucThiSQL.ConvertDateTime(txtNgaynhap.Text) + "', N'" + cboManhanvien.Text.Trim() + "', N'" + cboMaNCC.Text.Trim() + "', N'" + Convert.ToDouble(txtThanhtien.Text) + "')";
            ThucThiSQL.CapNhatDuLieu(sql);
            btnLuu.Enabled        = false;
            grbChitietHDN.Enabled = true;
            Hienthi_Luoi();
        }
        private void btnXoa_Click(object sender, EventArgs e)
        {
            string sql = "SELECT * FROM tblChitietHDNhap WHERE MaHDNhap = N'" + txtMaHD.Text + "'";

            if (ThucThiSQL.DocBang(sql).Rows.Count == 0)
            {
                MessageBox.Show("Không có dữ liệu!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            if ((MessageBox.Show("Bạn có chắc chắn muốn xóa không?", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes))
            {
                string mahangxoa    = dgvCT.CurrentRow.Cells["MaSP"].Value.ToString();
                double slxoa        = Convert.ToDouble(dgvCT.CurrentRow.Cells["SoLuong"].Value.ToString());
                double gianhapxoa   = Convert.ToDouble(dgvCT.CurrentRow.Cells["DonGia"].Value.ToString());
                double thanhtienxoa = Convert.ToDouble(dgvCT.CurrentRow.Cells["ThanhTien"].Value.ToString());
                sql = "DELETE tblChitietHDNhap WHERE MaHDNhap=N'" + txtMaHD.Text + "' AND MaSP=N'" + mahangxoa + "'";
                ThucThiSQL.CapNhatDuLieu(sql);
                Hienthi_luoi();
                DelUpdateHang(mahangxoa, slxoa, gianhapxoa);
                DelUpdateTongTien(txtMaHD.Text, thanhtienxoa);
                resetValueHang();
            }
            btnThemSP.Enabled = true;
            if (dgvCT.Rows.Count == 0)
            {
                btnInHD.Enabled = false;
            }
            else
            {
                btnInHD.Enabled = true;
            }
        }
示例#11
0
 private void btnXoa_Click(object sender, EventArgs e)
 {
     if (MessageBox.Show("Bạn có chắc chắn muốn xóa không?", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
     {
         // Lấy thông tin các mặt hàng sẽ bị xóa
         string    sql = "SELECT MaSP, SoLuong, DonGia FROM tblChitietHDNhap WHERE MaHDNhap = N'" + dgvDanhsach.CurrentRow.Cells["MaHDNhap"].Value.ToString() + "'";
         DataTable tbl = ThucThiSQL.DocBang(sql);
         //xóa chi tiết hóa đơn
         sql = "DELETE tblChiTietHDNhap WHERE MaHDNhap=N'" + dgvDanhsach.CurrentRow.Cells["MaHDNhap"].Value.ToString() + "'";
         ThucThiSQL.CapNhatDuLieu(sql);
         //xóa hóa đơn
         sql = "DELETE tblHDNhap WHERE MaHDNhap=N'" + dgvDanhsach.CurrentRow.Cells["MaHDNhap"].Value.ToString() + "'";
         ThucThiSQL.CapNhatDuLieu(sql);
         Hienthi_luoi();
         // cập nhật lại số lượng,đơn giá nhập, đơn giá bán
         for (int i = 0; i < tbl.Rows.Count; i++)
         {
             DelUpdateHang(tbl.Rows[i][0].ToString(), Convert.ToDouble(tbl.Rows[i][1]), Convert.ToDouble(tbl.Rows[i][2]));
         }
     }
     if (dgvDanhsach.Rows.Count == 0)
     {
         btnSua.Enabled  = false;
         btnXoa.Enabled  = false;
         btnInHD.Enabled = false;
     }
 }
        private void btnXoa_Click(object sender, EventArgs e)
        {
            try
            {
                string sql;
                if (dgvLoai.Rows.Count == 0)
                {
                    MessageBox.Show("KHÔNG CÓ DỮ LIỆU");
                    return;
                }
                string ma = dgvLoai.CurrentRow.Cells["MaLoai"].Value.ToString();

                if (MessageBox.Show("Bạn có muốn xóa không? ", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    sql = "DELETE FROM tblLoai WHERE MaLoai =N'" + ma + "' ";
                    ThucThiSQL.CapNhatDuLieu(sql);
                    HienThi_Luoi();
                    txtMaloai.Text = "";
                    SemiReset();
                    txtTenloai.Enabled = false;
                }
            }
            catch
            {
                MessageBox.Show("Đã xảy ra lỗi, xin thử lại sau");
            }
        }
        private void btnSua_Click_1(object sender, EventArgs e)
        {
            string    sql;
            DataTable tblNhanHieu;

            sql         = "SELECT MaNhanHieu, TenNhanHieu FROM tblNhanHieu";
            tblNhanHieu = ThucThiSQL.DocBang(sql);
            if (tblNhanHieu.Rows.Count == 0)
            {
                MessageBox.Show("Không có dữ liệu !", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            if (txtMaNhanHieu.Text == "")
            {
                MessageBox.Show("Bạn chưa chọn bản ghi nào!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            if (txtTenNhanHieu.Text.Trim().Length == 0)
            {
                MessageBox.Show("Bạn phải nhập tên nhãn hiệu!", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                txtTenNhanHieu.Focus();
                return;
            }
            sql = "UPDATE tblNhanHieu SET TenNhanHieu=N'" + txtTenNhanHieu.Text.Trim() + "' WHERE MaNhanHieu = N'" + txtMaNhanHieu.Text.Trim() + "'";
            ThucThiSQL.CapNhatDuLieu(sql);
            Hienthi_Luoi();
            ResetValues();
            btnLuu.Enabled        = false;
            btnXoa.Enabled        = false;
            btnThem.Enabled       = false;
            txtMaNhanHieu.Enabled = false;
        }
示例#14
0
 private void dataGridView1_DoubleClick(object sender, EventArgs e)
 {
     if (MessageBox.Show("Bạn có chắc chắn xóa không?", "Thông Báo", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
     {
         ThucThiSQL.CapNhatDuLieu("Delete Hang where MaHang='" + dataGridView1.CurrentRow.Cells["MaHang"].Value.ToString() + "'");                 // đầu tiên xóa chi tiết hóa đơn theo mã hàng
         MessageBox.Show("Hủy thành công");
         HienThi_Luoi();
     }
 }
        private void DelUpdateTongTien(string mahoadonxoa, double thanhtienxoa)
        {
            double tong    = Convert.ToDouble(ThucThiSQL.DocBang("SELECT TongTien FROM tblHDNhap WHERE MaHDNhap=N'" + mahoadonxoa + "'").Rows[0][0].ToString());
            double tongmoi = tong - thanhtienxoa;

            ThucThiSQL.CapNhatDuLieu("UPDATE tblHDNhap SET TongTien=" + tongmoi + " WHERE MaHDNhap =N'" + mahoadonxoa + "'");
            txtTongTien.Text = tongmoi.ToString();
            lblBangchu.Text  = "Bằng chữ: " + ThucThiSQL.ChuyenSoSangChu(tongmoi.ToString());
        }
示例#16
0
        private void DelUpdateHang(string mahangxoa, double slxoa, double dongiaxoa)
        {
            //Cập nhật sl hàng vào bảng hàng theo công thức slmoi=sl trong bảng hàng-sl đã bị xóa
            double sl    = Convert.ToDouble(ThucThiSQL.DocBang("select SoLuong from tblSanPham where MaSP=N'" + mahangxoa + "'").Rows[0][0].ToString());
            double slmoi = sl - slxoa;
            string sql   = "update tblSanPham set SoLuong=" + slmoi + "where MaSP=N'" + mahangxoa + "'";

            ThucThiSQL.CapNhatDuLieu(sql);
        }
示例#17
0
        private void btnCapnhat_Click(object sender, EventArgs e)
        {
            string sql;

            if (txtSize.Text.Trim().Length == 0)
            {
                MessageBox.Show("Bạn Chưa Điền Size Hàng", "Thông báo");
                txtSize.Focus();
                return;
            }
            if (txtMausac.Text.Trim().Length == 0)
            {
                MessageBox.Show("Bạn Chưa Điền Màu Sắc Hàng", "Thông báo");
                txtMausac.Focus();
                return;
            }
            if (txtSLNhap.Text.Trim().Length == 0)
            {
                MessageBox.Show("Bạn Chưa Điền Số Lượng Nhập Hàng", "Thông báo");
                txtSLNhap.Focus();
                return;
            }
            if (txtSLconlai.Text.Trim().Length == 0)
            {
                MessageBox.Show("Bạn Chưa Điền Số Lượng Hàng Còn Lại", "Thông báo");
                txtSLconlai.Focus();
                return;
            }
            if (Convert.ToDouble(txtSLconlai.Text) > Convert.ToDouble(txtSLNhap.Text))            // kiểm tra xem số lượng còn lại có vượt quá số lượng nhập vào hay không
            {
                MessageBox.Show("Số Lượng Còn Lại Vượt Quá Số Lượng Nhập", "Thông báo");
                txtSLconlai.Focus();
                txtSLconlai.Text = "";
                return;
            }

            double    total = 0;
            DataTable sl    = ThucThiSQL.DocBang("Select Sum(SLNhap) from Hang where MaMH=N'" + txtMaMH.Text + "' Group by MaMH");

            total = Convert.ToDouble(sl.Rows[0][0].ToString()) + Convert.ToDouble(txtSLNhap.Text) - Convert.ToDouble(ThucThiSQL.DocBang("select SLNhap from Hang where MaHang=N'" + txtMahang.Text + "'").Rows[0][0].ToString());        // số lượng đã tồn tại cộng thêm với số lượng của hàng đang nhập để kiểm tra xem có vượt quá tổng cho phép không


            if (total > Convert.ToDouble(txtSLTong.Text))             // nếu vượt thì báo lỗi bắt nhập lại
            {
                MessageBox.Show("Đã vượt quá số lượng cho phép , mời nhập lại", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                txtSLNhap.Text = "";
                txtSLNhap.Focus();
                return;
            }
            // nếu qua hết thì update lại hàng
            sql = "UPDATE Hang Set Size =N'" + txtSize.Text + "',MauSac=N'" + txtMausac.Text + "',SLNhap=N'" + txtSLNhap.Text + "',SLConLai=N'" + txtSLconlai.Text + "' where MaHang = N'" + txtMahang.Text + "'";
            ThucThiSQL.CapNhatDuLieu(sql);
            MessageBox.Show("Bạn Sửa Thành Công", "Success");
            this.Close();
        }
        private void btnSuaSP_Click(object sender, EventArgs e)
        {
            DataTable dt = ThucThiSQL.DocBang("SELECT GioiHanTon,SoLuongTon FROM tblSP WHERE MaSP=N'" + cboMahang.Text + "'");

            if ((Convert.ToInt64(txtSoluong.Text) - Convert.ToInt64(dgvCT.CurrentRow.Cells["SoLuong"].Value.ToString()) + (Convert.ToInt64(dt.Rows[0][1].ToString()))) > Convert.ToInt64(dt.Rows[0][0].ToString()))
            {
                MessageBox.Show("Số lượng nhập vượt quá giới hạn, Vui lòng nhập lại", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                txtSoluong.Text = "";
                txtSoluong.Focus();
                return;
            }
            string mahangxoa    = cboMahang.Text;
            double slxoa        = double.Parse(dgvCT.CurrentRow.Cells["SoLuong"].Value.ToString());
            double gianhapxoa   = double.Parse(dgvCT.CurrentRow.Cells["DonGia"].Value.ToString());
            double thanhtienxoa = double.Parse(dgvCT.CurrentRow.Cells["ThanhTien"].Value.ToString());

            DelUpdateHang(mahangxoa, slxoa, gianhapxoa);
            DelUpdateTongTien(txtMaHD.Text, thanhtienxoa);
            string sql = "DELETE tblChitietHDNhap WHERE MaHDNhap=N'" + txtMaHD.Text + "' AND MaSP=N'" + mahangxoa + "'";

            ThucThiSQL.CapNhatDuLieu(sql);

            //cập nhật dữ liệu cho tblChitietHDN
            sql = "INSERT INTO tblChitietHDNhap (MaHDNhap,MaSP,SoLuong,DonGia,KhuyenMai,ThanhTien) " +
                  "VALUES (N'" + txtMaHD.Text + "',N'" + cboMahang.Text + "'," + txtSoluong.Text + "," + txtDonGia.Text + "," + txtGiamGia.Text + "," + txtThanhtien.Text + ")";
            ThucThiSQL.CapNhatDuLieu(sql);
            //cập nhật tổng tiền mới cho tblHDNhap
            double tong    = Convert.ToDouble(txtThanhtien.Text);
            double tongmoi = tong + Convert.ToDouble(ThucThiSQL.DocBang("SELECT TongTien FROM tblHDNhap WHERE MaHDNhap=N'" + txtMaHD.Text + "'").Rows[0][0].ToString());

            ThucThiSQL.CapNhatDuLieu("UPDATE tblHDNhap SET TongTien=" + tongmoi + " WHERE MaHDNhap =N'" + txtMaHD.Text + "'");
            //cập nhật đơn giá nhập mới của Mahang cho bảng hàng
            double dgnmoi, dgbmoi;

            dt     = ThucThiSQL.DocBang("SELECT SoLuongTon,DonGiaNhap FROM tblSP WHERE MaSP=N'" + cboMahang.Text + "'");
            dgnmoi = (Convert.ToDouble(dt.Rows[0][0].ToString()) * Convert.ToDouble(dt.Rows[0][1].ToString())
                      + Convert.ToDouble(txtSoluong.Text) * Convert.ToDouble(txtDonGia.Text)) /
                     (Convert.ToDouble(txtSoluong.Text) + Convert.ToDouble(dt.Rows[0][0].ToString()));
            ThucThiSQL.CapNhatDuLieu("UPDATE tblSP SET DonGiaNhap=" + dgnmoi + " WHERE MaSP=N'" + cboMahang.Text + "'");
            //cập nhật số lượng mới của Mahang cho bảng hàng
            double sl, slmoi;

            sl    = Convert.ToDouble(txtSoluong.Text);
            slmoi = sl + Convert.ToDouble(ThucThiSQL.DocBang("SELECT SoLuongTon FROM tblSP WHERE MaSP=N'" + cboMahang.Text + "'").Rows[0][0].ToString());
            ThucThiSQL.CapNhatDuLieu("UPDATE tblSP SET SoLuongTon =" + slmoi + " WHERE MaSP=N'" + cboMahang.Text + "'");
            //cập nhật đơn giá bán mới của Mahang cho bảng hàng
            dgbmoi = dgnmoi * 1.2;
            ThucThiSQL.CapNhatDuLieu("UPDATE tblSP SET DonGiaBan=" + dgbmoi + " WHERE MaSP=N'" + cboMahang.Text + "'");
            Hienthi_luoi();
            //the end
            txtTongTien.Text = string.Format("{0:0,0 VNĐ}", tongmoi);
            lblBangchu.Text  = "Bằng chữ: " + ThucThiSQL.ChuyenSoSangChu(tongmoi.ToString());
            resetValueHang();
            btnSua.Enabled = false;
        }
示例#19
0
 private void btnSua_Click(object sender, EventArgs e)
 {
     try
     {
         string sql;
         if (txtTenNCC.Text.Trim() == "")
         {
             MessageBox.Show("Bạn phải nhập TÊN NCC", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
             txtTenNCC.Focus();
             return;
         }
         if (txtDiachi.Text.Trim() == "")
         {
             MessageBox.Show("Bạn phải nhập Địa chỉ", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
             txtDiachi.Focus();
             return;
         }
         if (txtSDT.Text.Trim() == "")
         {
             MessageBox.Show("Bạn phải nhập SDT", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
             label.Focus();
             return;
         }
         sql = "SELECT * FROM tblNCC WHERE SDT ='" + txtSDT.Text + "' AND MaNCC <> '" + txtMaNCC.Text + "'";
         DataTable dt = ThucThiSQL.DocBang(sql);
         if (dt.Rows.Count > 0)
         {
             MessageBox.Show("Bạn đã nhập trùng SDT NCC", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
             txtSDT.Text = "";
             txtSDT.Focus();
             return;
         }
         sql = "SELECT * FROM tblNCC WHERE TenNCC ='" + txtTenNCC.Text + "' AND MaNCC <> '" + txtMaNCC.Text + "'";
         dt  = ThucThiSQL.DocBang(sql);
         if (dt.Rows.Count > 0)
         {
             MessageBox.Show("Bạn đã nhập trùng Tên NCC", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
             txtTenNCC.Text = "";
             txtTenNCC.Focus();
             return;
         }
         sql = "UPDATE tblNCC SET TenNCC = N'" + txtTenNCC.Text + "'," +
               "DiaChi = N'" + txtDiachi.Text + "',SDT = N'" + txtSDT.Text + "' WHERE " +
               "MaNCC= N'" + txtMaNCC.Text + "'";
         ThucThiSQL.CapNhatDuLieu(sql);
         HienThi_Luoi();
         Reset();
         Disable();
         SemiReset();
     }
     catch
     {
         MessageBox.Show("Đã xảy ra lỗi, xin thử lại sau");
     }
 }
        private void btnLuu_Click(object sender, EventArgs e)
        {
            string sql;

            if (txtMaNCC.Text.Trim().Length == 0)
            {
                MessageBox.Show("Bạn phải nhập mã nhà cung cấp !", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                txtMaNCC.Focus();
                return;
            }
            if (txtTenNCC.Text.Trim().Length == 0)
            {
                MessageBox.Show("Bạn phải nhập tên nhà cung cấp!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                txtTenNCC.Focus();
                return;
            }
            if (txtDiaChi.Text.Trim().Length == 0)
            {
                MessageBox.Show("Bạn phải nhập địa chỉ!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                txtDiaChi.Focus();
                return;
            }
            if (txtSDT.Text.Trim().Length == 0)
            {
                MessageBox.Show("Bạn phải nhập số điện thoại!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                txtSDT.Focus();
                return;
            }

            sql = "SELECT MaNCC FROM tblNCC WHERE MaNCC=N'" + txtMaNCC.Text + "'";
            DataTable tblNCC = ThucThiSQL.DocBang(sql);

            if (tblNCC.Rows.Count > 0)
            {
                MessageBox.Show("Mã nhà cung cấp này đã có, bạn phải nhập mã khác !", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                txtMaNCC.Focus();
                txtMaNCC.Text = "";
                return;
            }

            sql = "INSERT INTO tblNhaCungCap(MaNCC,TenNCC, DiaChi, SDT) VALUES(N'" + txtMaNCC.Text.Trim() + "', N'" + txtTenNCC.Text.Trim() + "', N'" + txtDiaChi.Text.Trim() + "', N'" + txtSDT.Text.Trim() + "')";


            ThucThiSQL.CapNhatDuLieu(sql);

            Hienthi_Luoi();

            btnThem.Enabled  = true;
            btnSua.Enabled   = true;
            btnXoa.Enabled   = true;
            btnHuy.Enabled   = false;
            btnLuu.Enabled   = false;
            txtMaNCC.Enabled = false;
        }
示例#21
0
        private void btnSua_Click(object sender, EventArgs e)
        {
            string sql;

            if (txtTenKH.Text.Trim() == "")
            {
                MessageBox.Show("Bạn phải nhập TÊN KH", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                txtTenKH.Focus();
                return;
            }
            if (txtDiachi.Text.Trim() == "")
            {
                MessageBox.Show("Bạn phải nhập Địa chỉ", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                txtDiachi.Focus();
                return;
            }
            if (txtSDT.Text.Trim() == "")
            {
                MessageBox.Show("Bạn phải nhập SDT", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                txtSDT.Focus();
                return;
            }
            if (DateTime.TryParse(dtpNgaySinh.Text, out DateTime dDate) == false)
            {
                MessageBox.Show("Bạn nhập sai Ngày sinh", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                dtpNgaySinh.Text = "";
                dtpNgaySinh.Focus();
                return;
            }
            sql = "SELECT * FROM tblKH WHERE SDT ='" + txtSDT.Text + "' AND MaKH <> '" + txtMaKH.Text + "'";
            DataTable dt = ThucThiSQL.DocBang(sql);

            if (dt.Rows.Count > 0)
            {
                MessageBox.Show("Bạn đã nhập trùng SDT khách hàng", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                txtSDT.Text = "";
                txtSDT.Focus();
                return;
            }
            sql = "UPDATE tblKH SET TenKH = N'" + txtTenKH.Text + "'," +
                  "DiaChi = N'" + txtDiachi.Text + "'," +
                  "NgaySinh = N'" + dtpNgaySinh.Value.ToString("MM/dd/yyyy") + "'," +
                  "SDT = N'" + txtSDT.Text + "' WHERE " +
                  "MaKH= N'" + txtMaKH.Text + "'";
            ThucThiSQL.CapNhatDuLieu(sql);
            HienThi_Luoi();
            Reset();
            Disable();
            SemiReset();
        }
示例#22
0
        private void btnLuu_Click(object sender, EventArgs e)
        {
            string sql;

            if (txtMaKH.Text.Trim() == "")
            {
                MessageBox.Show("Bạn phải nhập Mã KH", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            if (txtTenKH.Text.Trim() == "")
            {
                MessageBox.Show("Bạn phải nhập Tên KH", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                txtTenKH.Focus();
                return;
            }
            if (DateTime.TryParse(dtpNgaySinh.Text, out DateTime dDate) == false)
            {
                MessageBox.Show("Bạn nhập sai Ngày sinh", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                dtpNgaySinh.Text = "";
                dtpNgaySinh.Focus();
                return;
            }

            sql = "SELECT * FROM tblKH WHERE MaKH ='" + txtMaKH.Text + "'";
            DataTable dt = ThucThiSQL.DocBang(sql);

            if (dt.Rows.Count > 0)
            {
                MessageBox.Show("Bạn đã nhập trùng MÃ KH", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                txtMaKH.Text = "";
                txtMaKH.Focus();
                return;
            }
            sql = "SELECT * FROM tblKH WHERE TenKH ='" + txtTenKH.Text + "'";
            dt  = ThucThiSQL.DocBang(sql);
            if (dt.Rows.Count > 0)
            {
                MessageBox.Show("Bạn đã nhập trùng Tên KH", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                txtTenKH.Text = "";
                txtTenKH.Focus();
                return;
            }
            sql = "INSERT INTO tblKH(MaKH,TenKH,DiaChi,NgaySinh,SDT) " +
                  "VALUES (N'" + txtMaKH.Text + "',N'" + txtTenKH.Text + "',N'" + txtDiachi.Text + "',N'" + dtpNgaySinh.Value.ToString("MM/dd/yyyy") + "',N'" + txtSDT.Text + "')";
            ThucThiSQL.CapNhatDuLieu(sql);
            HienThi_Luoi();
            Reset();
            btnLuu.Enabled   = false;
            txtTenKH.Enabled = false;
        }
示例#23
0
        private void btnLuu_Click(object sender, EventArgs e)
        {
            string sql;             // đầu tiên phải kiểm tra xem các trường có rỗng hay không

            if (txtMaHD.Text.Trim().Length == 0)
            {
                MessageBox.Show("Bạn phải nhập mã hóa đơn", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                txtMaHD.Focus();
                return;
            }
            if (txtNgaylap.Text.Trim().Length == 0)
            {
                MessageBox.Show("Bạn phải nhập ngày lập", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                txtNgaylap.Focus();
                return;
            }
            if (txtTenkhach.Text.Trim().Length == 0)
            {
                MessageBox.Show("Bạn phải nhập tên khách", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                txtTenkhach.Focus();
                return;
            }
            if (txtSdtkhach.Text.Trim().Length == 0)
            {
                MessageBox.Show("Bạn phải nhập SĐT khách", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                txtSdtkhach.Focus();
                return;
            }
            if (cbxMaNV.Text.Trim().Length == 0)
            {
                MessageBox.Show("Bạn phải nhập mã nhân viên", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                cbxMaNV.Focus();
                return;
            }

            sql = "select MaHD from HoaDon where MaHD='" + txtMaHD.Text + "'";
            if (ThucThiSQL.DocBang(sql).Rows.Count > 0)             // sau đó check xem mã phiếu có bị trùng hay không
            {
                MessageBox.Show("Mã hóa đơn bị trùng, mời nhập mã khác", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                txtMaHD.Text = "";
                txtMaHD.Focus();
                return;
            }

            sql = "Insert into HoaDon Values(N'" + txtMaHD.Text + "',N'" + txtSdtkhach.Text + "',N'" + txtTenkhach.Text + "'," + txtNgaylap.Text + ",N'" + cbxMaNV.Text + "','" + 0 + "')";
            ThucThiSQL.CapNhatDuLieu(sql);             // cập nhật dữ liệu vào phiếu nhập trước sau đó bật thêm chi tiết phiếu nhập
            MessageBox.Show("Lập Hóa Đơn Thành Công, Mời Nhập Chi Tiết");
            btnLuu.Enabled     = false;
            grbChitiet.Enabled = true;
        }
 private void btnLuu_Click(object sender, EventArgs e)
 {
     try
     {
         string sql;
         if (txtMaloai.Text.Trim() == "")
         {
             MessageBox.Show("Bạn phải nhập Mã loại", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
             return;
         }
         if (txtTenloai.Text.Trim() == "")
         {
             MessageBox.Show("Bạn phải nhập Tên loại", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
             txtTenloai.Focus();
             return;
         }
         sql = "SELECT * FROM tblLoai WHERE MaLoai ='" + txtMaloai.Text + "'";
         DataTable dt = ThucThiSQL.DocBang(sql);
         if (dt.Rows.Count > 0)
         {
             MessageBox.Show("Bạn đã nhập trùng Mã Loại", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
             txtMaloai.Text = "";
             txtMaloai.Focus();
             return;
         }
         sql = "SELECT * FROM tblLoai WHERE TenLoai ='" + txtTenloai.Text + "'";
         dt  = ThucThiSQL.DocBang(sql);
         if (dt.Rows.Count > 0)
         {
             MessageBox.Show("Bạn đã nhập trùng Tên loại", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
             txtTenloai.Text = "";
             txtTenloai.Focus();
             return;
         }
         sql = "INSERT INTO tblLoai(MaLoai,TenLoai) " +
               "VALUES (N'" + txtMaloai.Text + "',N'" + txtTenloai.Text + "')";
         ThucThiSQL.CapNhatDuLieu(sql);
         HienThi_Luoi();
         txtMaloai.Text     = "";
         txtTenloai.Text    = "";
         btnLuu.Enabled     = false;
         txtTenloai.Enabled = false;
         btnThem.Enabled    = true;
     }
     catch
     {
         MessageBox.Show("Đã xảy ra lỗi, xin thử lại sau");
     }
 }
示例#25
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            string sql;

            if (cbxMahang.Text.Trim().Length == 0)             // trước hết kiểm tra xem các trường có rỗng hay không
            {
                MessageBox.Show("Bạn phải nhập mã mặt hàng", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                cbxMahang.Focus();
                return;
            }
            if (txtSL.Text.Trim().Length == 0)
            {
                MessageBox.Show("Bạn phải nhập số lượng mặt hàng", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                txtSL.Focus();
                return;
            }



            double slconlai    = Convert.ToDouble(ThucThiSQL.DocBang("Select SLConLai from Hang where MaHang=N'" + cbxMahang.Text + "'").Rows[0][0].ToString()); // lấy ra số lượng đang còn lại của sản phẩm trước khi bán
            double slsaukhiban = slconlai - Convert.ToDouble(txtSL.Text);                                                                                        // số lượng sau khi bán bằng số lượng trước khi bán trừ đi số lượng mua

            if (slsaukhiban < 0)                                                                                                                                 // kiểm tra xem số lượng bán có vượt quá số lượng còn không , nếu có báo lỗi , không có thì thực thi tiếp
            {
                MessageBox.Show("Số lượng hàng chỉ còn '" + slconlai + "'", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                txtSL.Text = "";
                txtSL.Focus();
                return;
            }
            else
            {
                sql = "insert into ChiTietHD values(N'" + txtMaHD.Text + "',N'" + cbxMahang.Text + "',N'" + txtSL.Text + "')";
                ThucThiSQL.CapNhatDuLieu(sql);                 // Thêm thông tin vào chi tiết Hóa đơn
                sql = "Update Hang Set SLConLai ='" + slsaukhiban + "' where MaHang=N'" + cbxMahang.Text + "'";
                ThucThiSQL.CapNhatDuLieu(sql);                 // cập nhật lại cột số lượng còn lại của hàng
            }

            double tong    = Convert.ToDouble(txtSL.Text) * Convert.ToDouble(txtDongia.Text); // gán tổng tiền bằng đơn giá nhân số lượng
            double tongmoi = tong + Convert.ToDouble(txtTongtien.Text);                       // tổng mới sẽ bằng tổng cũ và cộng với đơn giá và số lượng của mặt hàng đang nhập

            txtTongtien.Text = tongmoi.ToString();                                            //set textbox tổng tiền bằng tổng vừa tính
            sql = "Update HoaDon Set TongTien =N'" + txtTongtien.Text + "' where MaHD='" + txtMaHD.Text + "'";
            ThucThiSQL.CapNhatDuLieu(sql);                                                    // cập nhật tổng tiền của Hóa Đơn

            HienThi_Luoi();                                                                   // hiển thị danh sách mặt hàng của phiếu nhập lên
            ResetValueHang();                                                                 // sau khi thêm 1 mặt hàng thì reset giá trị các ô textbox về rỗng

            MessageBox.Show("CapNhatThanhCong");
        }
示例#26
0
        private void btnLuu_Click(object sender, EventArgs e)
        {
            txtSoLuongTon.Text = "0";
            txtDongiaBan.Text  = "0";
            txtDongiaNhap.Text = "0";
            string    sql;
            DataTable dt;

            if (txtMaSP.Text.Trim() == "")
            {
                MessageBox.Show("Bạn phải nhập Mã SP", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                txtMaSP.Focus();
                return;
            }
            if (txtTenSP.Text.Trim() == "")
            {
                MessageBox.Show("Bạn phải nhập Tên SP", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                txtTenSP.Focus();
                return;
            }
            sql = "SELECT * FROM tblSP WHERE MaSP ='" + txtMaSP.Text + "'";
            dt  = ThucThiSQL.DocBang(sql);
            if (dt.Rows.Count > 0)
            {
                MessageBox.Show("Bạn đã nhập trùng MÃ SP", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                txtMaSP.Text = "";
                txtMaSP.Focus();
                return;
            }
            sql = "SELECT * FROM tblSP WHERE TenSP ='" + txtTenSP.Text + "'";
            dt  = ThucThiSQL.DocBang(sql);
            if (dt.Rows.Count > 0)
            {
                MessageBox.Show("Bạn đã nhập trùng Tên SP", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                txtTenSP.Text = "";
                txtTenSP.Focus();
                return;
            }
            sql = "INSERT INTO tblSP (MaSP,TenSP,MaLoai,DonViTinh,DonGiaNhap,DonGiaBan,SoLuongTon,GioiHanTon) " +
                  "VALUES (N'" + txtMaSP.Text + "',N'" + txtTenSP.Text + "',N'" + cboMaLoai.Text + "',N'" + txtDonViTinh.Text + "'," +
                  "" + txtDongiaNhap.Text + "," + txtDongiaBan.Text + "," + txtSoLuongTon.Text + "," +
                  "" + txtGioiHanTon.Text + ")";
            ThucThiSQL.CapNhatDuLieu(sql);
            HienThi_Luoi();
            Reset();
            btnLuu.Enabled   = false;
            txtTenSP.Enabled = false;
        }
示例#27
0
        private void btnSua_Click(object sender, EventArgs e)
        {
            string sql;

            if (txtTenSP.Text.Trim() == "")
            {
                MessageBox.Show("Bạn phải nhập Tên SP", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                txtTenSP.Focus();
                return;
            }
            if (cboMaLoai.Text.Trim() == "")
            {
                MessageBox.Show("Bạn phải chọn Mã loại", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                cboMaLoai.Focus();
                return;
            }
            if (txtGioiHanTon.Text.Trim() == "")
            {
                MessageBox.Show("Bạn phải nhập Giới hạn tồn", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                txtGioiHanTon.Focus();
                return;
            }
            if (txtDonViTinh.Text.Trim() == "")
            {
                MessageBox.Show("Bạn phải nhập Đơn vị tính", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                txtDonViTinh.Focus();
                return;
            }
            sql = "SELECT * FROM tblSP WHERE TenSP ='" + txtTenSP.Text + "' AND MaSP <> '" + txtMaSP.Text + "'";
            DataTable dt = ThucThiSQL.DocBang(sql);

            if (dt.Rows.Count > 0)
            {
                MessageBox.Show("Bạn đã nhập trùng Tên SP", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                txtTenSP.Text = "";
                txtTenSP.Focus();
                return;
            }
            sql = "UPDATE tblSP SET TenSP=N'" + txtTenSP.Text + "',MaLoai=N'" + cboMaLoai.Text + "',DonViTinh=N'" + txtDonViTinh.Text + "'," +
                  "DonGiaNhap=" + txtDongiaNhap.Text + ",DonGiaBan=" + txtDongiaBan.Text + ",SoLuongTon=" + txtSoLuongTon.Text + "," +
                  "GioiHanTon=" + txtGioiHanTon.Text + " WHERE " +
                  "MaSP= N'" + txtMaSP.Text + "'";
            ThucThiSQL.CapNhatDuLieu(sql);
            HienThi_Luoi();
            Reset();
            Disable();
            SemiReset();
        }
示例#28
0
        private void btnLuu_Click(object sender, EventArgs e)
        {
            string sql;

            if (txtMaNCC.Text.Trim().Length == 0)
            {
                MessageBox.Show("Bạn Chưa Điền Mã Nhân Viên", "Thông báo");
                txtMaNCC.Focus();
                return;
            }
            if (txtTenNCC.Text.Trim().Length == 0)
            {
                MessageBox.Show("Bạn Chưa Điền Tên Nhân Viên", "Thông báo");
                txtTenNCC.Focus();
                return;
            }
            if (txtDiachi.Text.Trim().Length == 0)
            {
                MessageBox.Show("Bạn Chưa Điền Địa Chỉ Nhân Viên", "Thông báo");
                txtDiachi.Focus();
                return;
            }
            if (txtSdt.Text.Trim().Length == 0)
            {
                MessageBox.Show("Bạn Chưa Điền SĐT Nhân Viên", "Thông báo");
                txtSdt.Focus();
                return;
            }

            sql = "Select MaNCC From NhaCungCap where MaNCC = N'" + txtMaNCC.Text.Trim() + "'";
            DataTable tblNCC = ThucThiSQL.DocBang(sql);

            if (tblNCC.Rows.Count > 0)
            {
                MessageBox.Show("Mã nhà cung cấp này đã có , bạn phải nhập mã khác", "Thông báo");
                txtMaNCC.Focus();
                txtMaNCC.Text = "";
                return;
            }
            else
            {
                sql = "Insert into NhaCungCap VALUES(N'" + txtMaNCC.Text + "',N'" + txtTenNCC.Text + "',N'" + txtDiachi.Text + "',N'" + txtSdt.Text + "')";
                ThucThiSQL.CapNhatDuLieu(sql);
                MessageBox.Show("Bạn Thêm Thành Công", "Success");
                this.Close();
            }
        }
        private void btnLuu_Click(object sender, EventArgs e)
        {
            string sql;

            if (txtHoten.Text.Trim().Length == 0)
            {
                MessageBox.Show("Bạn Chưa Điền Tên Nhân Viên", "Thông báo");
                txtHoten.Focus();
                return;
            }
            if (txtDiachi.Text.Trim().Length == 0)
            {
                MessageBox.Show("Bạn Chưa Điền Địa Chỉ Nhân Viên", "Thông báo");
                txtDiachi.Focus();
                return;
            }
            if (txtSdt.Text.Trim().Length == 0)
            {
                MessageBox.Show("Bạn Chưa Điền SĐT Nhân Viên", "Thông báo");
                txtSdt.Focus();
                return;
            }
            if (txtGioitinh.Text.Trim().Length == 0)
            {
                MessageBox.Show("Bạn Chưa Điền Giới Tính Nhân Viên", "Thông báo");
                txtGioitinh.Focus();
                return;
            }
            if (txtHocvan.Text.Trim().Length == 0)
            {
                MessageBox.Show("Bạn Chưa Điền Học Vấn Nhân Viên", "Thông báo");
                txtHocvan.Focus();
                return;
            }
            if (txtNgaysinh.Text.Trim().Length == 0)
            {
                MessageBox.Show("Bạn Chưa Điền Ngày Sinh Nhân Viên", "Thông báo");
                txtNgaysinh.Focus();
                return;
            }
            sql = "UPDATE NhanVien Set TenNV =N'" + txtHoten.Text + "',NgaySinh = N'" + txtNgaysinh.Text + "',GioiTinh =N'" + txtGioitinh.Text + "',DiaChi=N'" + txtDiachi.Text + "',HocVan=N'" + txtHocvan.Text + "',SDT=N'" + txtSdt.Text + "' where MaNV = N'" + txtMaNV.Text + "'";
            ThucThiSQL.CapNhatDuLieu(sql);
            MessageBox.Show("Bạn Sửa Thành Công", "Success");
            this.Close();
        }
示例#30
0
        private void btnLuu_Click(object sender, EventArgs e)
        {
            string    sql = "SELECT * FROM tblTK WHERE MaNV ='" + txtMaNV.Text + "'";
            DataTable dt  = ThucThiSQL.DocBang(sql);

            if (txtMaNV.Text.Trim() == "")
            {
                MessageBox.Show("Bạn chưa nhập mã NV", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                txtMaNV.Focus();
                return;
            }
            if (dt.Rows.Count == 0)
            {
                MessageBox.Show("Nhân viên không tồn tại", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                txtMaNV.Text = "";
                txtMaNV.Focus();
                return;
            }
            if (dt.Rows.Count > 0)
            {
                MessageBox.Show("Nhân viên đã có tài khoản", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                txtMaNV.Text = "";
                txtMaNV.Focus();
                return;
            }
            sql = "SELECT * FROM tblTK WHERE ID ='" + txtID.Text + "'";
            dt  = ThucThiSQL.DocBang(sql);
            if (txtID.Text.Trim() == "")
            {
                MessageBox.Show("Bạn chưa nhập ID", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                txtID.Focus();
                return;
            }
            if (dt.Rows.Count > 0)
            {
                MessageBox.Show("Tên tài khoản đã có người đặt", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                txtID.Text = "";
                txtID.Focus();
                return;
            }
            sql = "INSERT INTO tblTK(MaNV,ID,Pass) " +
                  "VALUES (N'" + txtMaNV.Text + "',N'" + txtID.Text + "',N'" + txtPass.Text + "')";
            ThucThiSQL.CapNhatDuLieu(sql);
            MessageBox.Show("Đăng kí thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }