private void btnCapNhat_Click(object sender, EventArgs e) { try { if (dataGridViewDS.Rows.Count < 1) { HoTro.baoLoi("Nhập dữ liệu để cập nhật"); return; } HoTro ht = new HoTro() ; SqlConnection conn = ht.KetNoi(); conn.Open(); SqlCommand command = new SqlCommand(); int maNguoiDung = DangNhap.idNguoiDung; for (int i = 0; i < dataGridViewDS.Rows.Count; i++) { DataGridViewRow row = dataGridViewDS.Rows[i]; // insert PhieuXuatKho command = new SqlCommand("select CustomerId from Customer where CusTomerName=@Cusname", conn); command.Parameters.Add("@CusNAme", row.Cells[1].Value.ToString()); int cusId = Int32.Parse(command.ExecuteScalar().ToString()) ; command = new SqlCommand("insert into BillSale values(@ngaythang, @nguoiMua, @manguoiDung)"); command.Parameters.Add("@ngaythang", ht.toSQLDateTime(txtNgayThang.Text)); command.Parameters.Add("@nguoiMua", cusId); command.Parameters.Add("@manguoiDung", maNguoiDung); ht.CapNhatDuLieu(command); // update Product Int64 billSaleId = ht.LayGiaTriTruongKhoaVuaChen2("BillSale", "BillSaleId"); command = new SqlCommand("update Product set StatusId = 2, billSaleId=@billSaleId where ProductId = @id"); command.Parameters.Add("@id", Int64.Parse(row.Cells[0].Value.ToString())); command.Parameters.Add("@billSaleId", billSaleId); ht.CapNhatDuLieu(command); } HoTro.thongBao("Đã cập nhật !"); conn.Close(); dataGridViewDS.Rows.Clear(); } catch (Exception ex) { //MessageBox.Show(ex.StackTrace); HoTro.baoLoi(ex.Message); } }
private void btnCapNhat_Click_1(object sender, EventArgs e) { try { ht = new HoTro(); SqlCommand command = new SqlCommand(); int maNguoiDung = DangNhap.idNguoiDung; for (int i = 0; i < dataGridViewDanhSach.Rows.Count; i++) { DataGridViewRow row = dataGridViewDanhSach.Rows[i]; // insert PhieuNhapKho int maNhaCungCap = ht.LayVeKhoa("Provider", "ProviderId", "ProviderName", row.Cells[8].Value.ToString()); command = new SqlCommand("insert into BillPurchase values(@ngaythang, @giaohang, @maNhacungcap, @manguoiDung)"); command.Parameters.Add("@ngaythang", ht.toSQLDateTime(txtNgayThang.Text)); command.Parameters.Add("@giaohang", row.Cells[9].Value.ToString()); command.Parameters.Add("@maNhacungcap", maNhaCungCap); command.Parameters.Add("@manguoiDung", maNguoiDung); ht.CapNhatDuLieu(command); int soLuong = Int32.Parse(row.Cells[1].Value.ToString()); int donvi = ht.LayVeKhoa("Units", "UnitId", "UnitName", row.Cells[4].Value.ToString()); Int64 billPurchaseId = ht.LayGiaTriTruongKhoaVuaChen2("BillPurchase", "BillPurchaseId"); for (int j = 0; j < soLuong; j++) { // insert SanPham int IdtenSp = ht.LayVeKhoa("ProductName", "ProductNameId", "ProdName", row.Cells[0].Value.ToString()); command = new SqlCommand("insert into Product values(" + "@ngaysx, @ngayHetHan, @IdtenSP, @PurchasePrice, null," + "null, @statusId, @billPurchaseId, null, @UnitId, @mota)"); command.Parameters.Add("@ngaysx", row.Cells[2].Value.ToString()); command.Parameters.Add("@ngayHetHan", row.Cells[3].Value.ToString()); command.Parameters.Add("@IdtenSP", IdtenSp); command.Parameters.Add("@PurchasePrice", Int32.Parse(row.Cells[7].Value.ToString())); //VietLH change string to int on 9 Dec 2009 command.Parameters.Add("@statusId", 1); command.Parameters.Add("@billPurchaseId", billPurchaseId); command.Parameters.Add("@UnitId", donvi); command.Parameters.Add("@mota", richTextBoxMota.Text); ht.CapNhatDuLieu(command); } } HoTro.thongBao("Nhập hàng thành công !"); dataGridViewDanhSach.Rows.Clear(); } catch (Exception ex) { HoTro.baoLoi(ex.Message); } }
private void btnTimKiemQuanLy_Click(object sender, EventArgs e) { try { dataGridViewHangHoa.DataSource = null; } catch (Exception ex) { MessageBox.Show(ex.Message); } if (txtTimKiemQuanLy.Text.Length == 0) { HoTro.baoLoi("Nhập thông tin để tìm kiếm") ; return ; } if (!checkBoxMaPhieu.Checked && !chkNhanviengh.Checked && !cbngaytao.Checked && !chkNguoiLapPhieu.Checked) { HoTro.baoLoi("Chọn trường để tìm kiếm"); return; } HoTro ht = new HoTro(); string caulenh = "select BillSaleId as 'Mã phiếu', createDate as 'Ngày tạo',Customername as 'Tên khách hàng', FullName as 'Người lập phiếu' " + "from BillSale join Customer" + " on BillSale.CustomerId = Customer.CustomerId" + " inner join Users " + "on BillSale.UserId = Users.UserId"; StringBuilder builder = new StringBuilder(); if (checkBoxMaPhieu.Checked) { try { builder.Append("BillSale.BillSaleId = " + Int64.Parse(txtTimKiemQuanLy.Text)); } catch (Exception ex) { } } if (chkNhanviengh.Checked) { if (builder.Length > 0) builder.Append(" or ") ; builder.Append("Customer.Customername like '%" + txtTimKiemQuanLy.Text + "%' " ); } if (cbngaytao.Checked && ht.toSQLDateTime(txtTimKiemQuanLy.Text) != null) { if (builder.Length > 0) builder.Append(" or "); builder.Append("BillSale.createDate ='" + ht.toSQLDateTime(txtTimKiemQuanLy.Text).ToShortDateString() + "' " ); } if (chkNguoiLapPhieu.Checked) { if (builder.Length > 0) builder.Append(" or "); builder.Append("Users.FullName like '%" + txtTimKiemQuanLy.Text + "%' "); } if (builder.Length > 0) { builder.Insert(0, " where "); } caulenh += builder.ToString(); ht.HienThiVaoDataGridView(dataGridViewDSPhieuBan, caulenh); }
private void btnTimKiemQuanLy_Click(object sender, EventArgs e) { if (txtTimKiemQuanLy.Text.Length == 0) { HoTro.baoLoi("Nhập thông tin để tìm kiếm"); return; } if (!checkBoxMaPhieu.Checked && !chkNhanviengh.Checked && !cbngaytao.Checked && !chkNguoiLapPhieu.Checked && !chkNhacungcap.Checked) { HoTro.baoLoi("Chọn trường để tìm kiếm"); return; } HoTro ht = new HoTro(); string caulenh = "select BillPurchaseId as 'Mã phiếu', createDate as 'Ngày tạo', DeliveryStaff as 'Nhân viên giao hàng', ProviderName as 'Nhà cung cấp', FullName as 'Người lập phiếu' " + "from BillPurchase join Provider" + " on BillPurchase.ProviderId = Provider.ProviderId" + " inner join Users " + "on BillPurchase.UserId = Users.UserId"; StringBuilder builder = new StringBuilder(); if (checkBoxMaPhieu.Checked) { try { builder.Append("BillPurchase.BillPurchaseId = " + Int64.Parse(txtTimKiemQuanLy.Text)); } catch (Exception ex) { } } if (chkNhanviengh.Checked) { if (builder.Length > 0) builder.Append(" or "); builder.Append("BillPurchase.DeliveryStaff like '%" + txtTimKiemQuanLy.Text + "%' "); } if (cbngaytao.Checked && ht.toSQLDateTime(txtTimKiemQuanLy.Text) != null) { if (builder.Length > 0) builder.Append(" or "); builder.Append("BillPurchase.createDate ='" + ht.toSQLDateTime(txtTimKiemQuanLy.Text).ToShortDateString() + "' "); } if (chkNhacungcap.Checked) { if (builder.Length > 0) builder.Append(" or "); builder.Append("Provider.ProviderName like '%" + txtTimKiemQuanLy.Text + "%' "); } if (chkNguoiLapPhieu.Checked) { if (builder.Length > 0) builder.Append(" or "); builder.Append("Users.FullName like '%" + txtTimKiemQuanLy.Text + "%' "); } if (builder.Length > 0) { builder.Insert(0, " where "); } caulenh += builder.ToString(); ht.HienThiVaoDataGridView(dataGridViewPhieuNhapHAng, caulenh); }