private void dataGridView_DoubleClick(object sender, EventArgs e) { string mahangxoa, sql; Double thanhtienxoa, soluongxoa, sl, slcon, tong, tongmoi; if (dataGridView.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)) { //Xóa hàng và cập nhật lại số lượng hàng mahangxoa = dataGridView.CurrentRow.Cells["Mahang"].Value.ToString(); soluongxoa = Convert.ToDouble(dataGridView.CurrentRow.Cells["Soluong"].Value.ToString()); thanhtienxoa = Convert.ToDouble(dataGridView.CurrentRow.Cells["Thanhtien"].Value.ToString()); sql = "DELETE tblChitietHDN WHERE MaHDN=N'" + txtMahoadon.Text + "' AND Mahang = N'" + mahangxoa + "'"; ThucthiSQL.CapNhatDuLieu(sql); // Cập nhật lại số lượng cho các mặt hàng sl = Convert.ToDouble(ThucthiSQL.DocBang("SELECT Soluongtonkho FROM tblHang WHERE Mahang = N'" + mahangxoa + "'").Rows[0][0].ToString()); slcon = sl - soluongxoa; sql = "UPDATE tblHang SET Soluongtonkho =" + slcon + " WHERE Mahang= N'" + mahangxoa + "'"; ThucthiSQL.CapNhatDuLieu(sql); // Cập nhật lại tổng tiền cho hóa đơn bán tong = Convert.ToDouble(ThucthiSQL.DocBang("SELECT Tongtien FROM tblHoadonnhap WHERE MaHDN = N'" + txtMahoadon.Text + "'").Rows[0][0].ToString()); tongmoi = tong - thanhtienxoa; sql = "UPDATE tblHoadonnhap SET Tongtien =" + tongmoi + " WHERE MaHDN = N'" + txtMahoadon.Text + "'"; ThucthiSQL.CapNhatDuLieu(sql); txtTongtien.Text = tongmoi.ToString(); lblBangchu.Text = "Bằng chữ: " + ThucthiSQL.ChuyenSoSangChu(tongmoi.ToString()); Hienthi_Luoi(); } }
private void DelUpdateTongtien(string madonxoa, double thanhtienxoa) { double tong = Convert.ToDouble(ThucthiSQL.DocBang("Select Tongtien from tblHoadonnhap where MaHDN=N'" + madonxoa + "'").Rows[0][0].ToString()); double tongmoi = tong - thanhtienxoa; string sql = "update tblHoadonnhap SET Tongtien=" + tongmoi + "where MaHDN=N'" + madonxoa + "'"; ThucthiSQL.CapNhatDuLieu(sql); txtTongtien.Text = tongmoi.ToString(); lblBangchu.Text = "Bằng chữ: " + ThucthiSQL.ChuyenSoSangChu(tongmoi.ToString()); }
private void btnThemhang_Click(object sender, EventArgs e) { if (cboMahang.Text.Length == 0) { MessageBox.Show("Bạn phải nhập mã hàng", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning); cboMahang.Focus(); return; } if (txtSoluong.Text.Length == 0) { MessageBox.Show("Bạn phải nhập số lượng", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning); txtSoluong.Text = ""; txtSoluong.Focus(); return; } if (txtGiamgia.Text.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 * FROM tblChitietHDB WHERE Mahang=N'" + cboMahang.Text + "' AND MaHDB=N'" + txtMahoadon.Text + "'"; if (ThucthiSQL.DocBang(sql).Rows.Count > 0) { MessageBox.Show("Mã sách này đã có, bạn phải nhập mã khác", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning); ResetValuesHang(); cboMahang.Focus(); return; } sql = "INSERT INTO tblChitietHDB(MaHDB, Mahang, Soluong, Giaban, Giamgia, Thanhtien) VALUES(N'" + txtMahoadon.Text + "',N'" + cboMahang.Text + "', " + txtSoluong.Text + "," + txtDongia.Text + "," + txtGiamgia.Text + "," + txtThanhtien.Text + ")"; ThucthiSQL.CapNhatDuLieu(sql); Hienthi_Luoi(); double tong = Convert.ToDouble(ThucthiSQL.DocBang("select Tongtien from tblHoadonban where MaHDB=N'" + txtMahoadon.Text + "'").Rows[0][0].ToString()); double tongmoi = tong + Convert.ToDouble(txtThanhtien.Text); sql = "update tblHoadonban set Tongtien=" + tongmoi + "where MaHDB=N'" + txtMahoadon.Text + "'"; ThucthiSQL.CapNhatDuLieu(sql); txtTongtien.Text = tongmoi.ToString(); lblBangchu.Text = "Bằng chữ:" + ThucthiSQL.ChuyenSoSangChu(tongmoi.ToString()); double sl = Convert.ToDouble(ThucthiSQL.DocBang("select Soluongtonkho from tblHang where Mahang=N'" + cboMahang.Text + "'").Rows[0][0].ToString()); double slmoi = sl - Convert.ToDouble(txtSoluong.Text); sql = "update tblHang set Soluongtonkho=" + slmoi + " where Mahang=N'" + cboMahang.Text + "'"; ThucthiSQL.CapNhatDuLieu(sql); ResetValuesHang(); btnHuy.Enabled = true; }
private void dataGridView_DoubleClick(object sender, EventArgs e) { Forms.frmHoadonnhap f = new frmHoadonnhap(); f.StartPosition = FormStartPosition.CenterScreen; if (dataGridView.Rows.Count == 0) { MessageBox.Show("Không có dữ liệu!", "Thông báo"); return; } f.txtMahoadon.Text = dataGridView.CurrentRow.Cells["MaHDN"].Value.ToString(); f.dtpNgaynhap.Text = dataGridView.CurrentRow.Cells["Ngaynhap"].Value.ToString(); f.cboMaNCC.Text = dataGridView.CurrentRow.Cells["MaNCC"].Value.ToString(); f.cboManhanvien.Text = dataGridView.CurrentRow.Cells["MaNV"].Value.ToString(); f.txtTongtien.Text = dataGridView.CurrentRow.Cells["Tongtien"].Value.ToString(); f.lblBangchu.Text = "Bằng chữ:" + ThucthiSQL.ChuyenSoSangChu(dataGridView.CurrentRow.Cells["Tongtien"].Value.ToString()); if (dataGridView.CurrentRow.Cells["Trangthai"].Value.ToString() == "Da thanh toan") { f.chkThanhtoan.Checked = true; } string sql = "select TenNCC, Diachi, SDT from tblNCC where MaNCC=N'" + f.cboMaNCC.Text + "'"; DataTable table = ThucthiSQL.DocBang(sql); if (table.Rows.Count > 0) { f.txtTenNCC.Text = table.Rows[0][0].ToString(); f.txtDiachi.Text = table.Rows[0][1].ToString(); f.txtDienthoai.Text = table.Rows[0][2].ToString(); } sql = "select TenNV from tblNhanvien where MaNV=N'" + f.cboManhanvien.Text + "'"; table = ThucthiSQL.DocBang(sql); if (table.Rows.Count > 0) { f.txtTennhanvien.Text = table.Rows[0][0].ToString(); } f.Hienthi_Luoi(); f.Show(); f.btnThem.Enabled = false; f.grbChitiet.Enabled = true; }
private void btnIn_Click(object sender, EventArgs e) { COMExcel.Application exApp = new COMExcel.Application(); COMExcel.Workbook exBook; COMExcel.Worksheet exSheet; COMExcel.Range exRange; string sql; int hang = 0, cot = 0; DataTable tblThongtinHD, tblThongtinHang; exBook = exApp.Workbooks.Add(COMExcel.XlWBATemplate.xlWBATWorksheet); exSheet = exBook.Worksheets[1]; exRange = exSheet.Cells[1][1]; exRange.Range["A1:B3"].Font.Size = 10; exRange.Range["A1:B3"].Font.Name = "Times new roman"; exRange.Range["A1:B3"].Font.Bold = true; exRange.Range["A1:B3"].Font.ColorIndex = 5; exRange.Range["A1:A1"].ColumnWidth = 7; exRange.Range["B1:B1"].ColumnWidth = 15; exRange.Range["A1:B1"].MergeCells = true; exRange.Range["A1:B1"].HorizontalAlignment = COMExcel.XlHAlign.xlHAlignCenter; exRange.Range["A1:B1"].Value = "Showroom phân phối nội thất Furniland"; exRange.Range["A2:B2"].MergeCells = true; exRange.Range["A2:B2"].HorizontalAlignment = COMExcel.XlHAlign.xlHAlignCenter; exRange.Range["A2:B2"].Value = "92 Mễ Trì Hạ, Mễ Trì, Từ Liêm, Hà Nội"; exRange.Range["A3:B3"].MergeCells = true; exRange.Range["A3:B3"].HorizontalAlignment = COMExcel.XlHAlign.xlHAlignCenter; exRange.Range["A3:B3"].Value = "Điện thoại: 024.7309.0066"; exRange.Range["C2:E2"].Font.Size = 16; exRange.Range["C2:E2"].Font.Name = "Times new roman"; exRange.Range["C2:E2"].Font.Bold = true; exRange.Range["C2:E2"].Font.ColorIndex = 3; exRange.Range["C2:E2"].MergeCells = true; exRange.Range["C2:E2"].HorizontalAlignment = COMExcel.XlHAlign.xlHAlignCenter; exRange.Range["C2:E2"].Value = "HÓA ĐƠN NHẬP"; sql = "select a.MaHDN, a.Tongtien, b.TenNCC, b.Diachi, b.SDT, a.Ngaynhap, c.TenNV from tblHoadonnhap as a, tblNCC as b, tblNhanvien as c where a.MaHDN=N'" + txtMahoadon.Text + "' AND a.MaNCC=b.MaNCC AND a.MaNV=c.MaNV"; tblThongtinHD = ThucthiSQL.DocBang(sql); exRange.Range["B6:C9"].Font.Size = 12; exRange.Range["B6:C9"].Font.Name = "Times new roman"; exRange.Range["B6:B6"].Value = "Mã hóa đơn"; exRange.Range["C6:E6"].MergeCells = true; exRange.Range["C6:E6"].Value = tblThongtinHD.Rows[0][0].ToString(); exRange.Range["B7:B7"].Value = "Nhà cung cấp"; exRange.Range["C7:E7"].MergeCells = true; exRange.Range["C7:E7"].Value = tblThongtinHD.Rows[0][2].ToString(); exRange.Range["B8:B8"].Value = "Địa chỉ"; exRange.Range["C8:E8"].MergeCells = true; exRange.Range["C8:E8"].Value = tblThongtinHD.Rows[0][3].ToString(); exRange.Range["B9:B9"].Value = "Điện thoại"; exRange.Range["C9:E9"].MergeCells = true; exRange.Range["C9:E9"].Value = "0" + tblThongtinHD.Rows[0][4].ToString(); sql = "select b.Tenhang, a.Soluong, a.Gianhap, a.Giamgia, a.Thanhtien from tblChitietHDN as a, tblHang AS b where a.MaHDN=N'" + txtMahoadon.Text + "'AND a.Mahang=b.Mahang"; tblThongtinHang = ThucthiSQL.DocBang(sql); exRange.Range["A11:F11"].Font.Bold = true; exRange.Range["A11:F11"].HorizontalAlignment = COMExcel.XlHAlign.xlHAlignCenter; exRange.Range["C11:F11"].ColumnWidth = 12; exRange.Range["A11:A11"].Value = "STT"; exRange.Range["B11:B11"].Value = "Tên hàng"; exRange.Range["C11:C11"].Value = "Số lượng"; exRange.Range["D11:D11"].Value = "Đơn giá"; exRange.Range["E11:E11"].Value = "Giảm giá"; exRange.Range["F11:F11"].Value = "Thành tiền"; for (hang = 0; hang < tblThongtinHang.Rows.Count; hang++) { exSheet.Cells[1][hang + 12] = hang + 1; for (cot = 0; cot < tblThongtinHang.Columns.Count; cot++) { exSheet.Cells[cot + 2][hang + 12] = tblThongtinHang.Rows[hang][cot].ToString(); } } exRange = exSheet.Cells[cot][hang + 14]; exRange.Font.Bold = true; exRange.Value2 = "Tổng tiền: "; exRange = exSheet.Cells[cot + 1][hang + 14]; exRange.Font.Bold = true; exRange.Value2 = tblThongtinHD.Rows[0][1].ToString(); exRange = exSheet.Cells[1][hang + 15]; exRange.Range["A1:F1"].MergeCells = true; exRange.Range["A1:F1"].Font.Bold = true; exRange.Range["A1:F1"].Font.Italic = true; exRange.Range["A1:F1"].HorizontalAlignment = COMExcel.XlHAlign.xlHAlignCenter; exRange.Range["A1:F1"].Value = "Bằng chữ: " + ThucthiSQL.ChuyenSoSangChu(tblThongtinHD.Rows[0][1].ToString()); exRange = exSheet.Cells[4][hang + 17]; exRange.Range["A1:C1"].MergeCells = true; exRange.Range["A1:C1"].Font.Italic = true; exRange.Range["A1:C1"].HorizontalAlignment = COMExcel.XlHAlign.xlHAlignCenter; DateTime d = Convert.ToDateTime(tblThongtinHD.Rows[0][5]); exRange.Range["A1:C1"].Value = "Hà Nội, ngày " + d.Day + " tháng " + d.Month + " năm " + d.Year; exRange.Range["A2:C2"].MergeCells = true; exRange.Range["A2:C2"].Font.Italic = true; exRange.Range["A2:C2"].HorizontalAlignment = COMExcel.XlHAlign.xlHAlignCenter; exRange.Range["A2:C2"].Value = "Nhân viên nhập hàng"; exRange.Range["A6:C6"].MergeCells = true; exRange.Range["A6:C6"].Font.Italic = true; exRange.Range["A6:C6"].HorizontalAlignment = COMExcel.XlHAlign.xlHAlignCenter; exRange.Range["A6:C6"].Value = tblThongtinHD.Rows[0][6]; exSheet.Name = "Hóa đơn nhập"; exApp.Visible = true; }