Code QuanLyMuaBanSach

Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 244

ng nhp vo, ng username v pass th ok, khng th hin thng bo sai username hoc pass.

using using using using using using using using System; System.Collections.Generic; System.ComponentModel; System.Data; System.Drawing; System.Linq; System.Text; System.Windows.Forms;

namespace NL2 { public partial class frmDangNhap : Form { public frmDangNhap() { InitializeComponent(); } private void btnDangNhap_Click(object sender, EventArgs e) { Login lgin = new Login(); if (lgin.checkLogin(txtUsername.Text, txtPassword.Text)) { this.Visible = false; frmMain obj = new frmMain(); obj.Show(); } lbUserPass.Visible = true; } private void btnLamLai_Click(object sender, EventArgs e) { txtUsername.Text = null; txtPassword.Text = null; lbUserPass.Visible = false; } private void btnHuy_Click(object sender, EventArgs e) { Logout lgout = new Logout(); lgout.goLogout(); Application.Exit(); } private void frmDangNhap_Load(object sender, EventArgs e) { //set default button //go to Property //AcceptionButton

//then choose button you want } } }

Trn l FormMain. Sau khi kim tra quyn s hin ln FormMain. Quyn no th nt cng vic tng ng s hin ln.
namespace NL2 { public partial class frmMain : Form { private OleDbConnection con; private OleDbDataAdapter adapter; //Nhapsach private string sophieunhap, sohdm, manpps, tensach, tacgia, giaban, lanxb, cknhap, ckxuat, maloai, manxb, soluong, dongia, makho; private DateTime ngaylappn, ngaylaphdm; //Ban sach private string sohoadon, loaihd, thuesuat, makh, tensachban, sluongban, dgiaban; private DateTime ngaylaphdb; //phan quyen private string manv, manhom, timManv, timManhom; //private OleDbCommand cmd; BindingSource nhanvienBindingSource = new BindingSource(); BindingSource thuocnhomBindingSource = new BindingSource(); BindingSource nhomBindingSource = new BindingSource(); public frmMain() { InitializeComponent(); con = new OleDbConnection(); ConnectDB conDB = new ConnectDB(); con = conDB.getConn(); con.Open(); } /********************* Thuoc tinh Visible cua Textbox phai la true thi moi lay gia tri cua textbox duoc * Tu do, moi co the dung truy xuat co so du lieu duoc * Enable thi true hay false cung duoc *********************/ private void populateNPPS()

{ try { OleDbCommand cmd = new OleDbCommand(); cmd.CommandType = CommandType.Text; cmd.CommandText = "select * from NHAPPS"; cmd.Connection = con; adapter = new OleDbDataAdapter(); adapter.SelectCommand = cmd; adapter.SelectCommand.Connection = con; //adapter.TableMappings.Add("Table", "NHAPPS"); //OleDbCommandBuilder cb = new OleDbCommandBuilder(adapter); dataSet1 = new DataSet(); adapter.Fill(dataSet1, "NHAPPS"); DataTable dataTableNHAPPS = new DataTable(); dataTableNHAPPS = dataSet1.Tables["NHAPPS"]; this.cbo_nhapps.SelectedIndexChanged -= new System.EventHandler(this.cbo_nhapps_SelectedIndexChanged_1); cbo_nhapps.DataSource = dataTableNHAPPS; cbo_nhapps.DisplayMember = "TENNPPS"; cbo_nhapps.ValueMember = "MANPPS"; this.cbo_nhapps.SelectedIndexChanged += new System.EventHandler(this.cbo_nhapps_SelectedIndexChanged_1); txtManpps.DataBindings.Clear(); txtManpps.DataBindings.Add("Text", dataTableNHAPPS, "MANPPS"); } catch (Exception ex) { MessageBox.Show(ex.Message); } } private void populateKHOSACH() { try { OleDbCommand cmd = new OleDbCommand(); cmd.CommandType = CommandType.Text; cmd.CommandText = "select * from KHOSACH"; cmd.Connection = con; adapter = new OleDbDataAdapter(); adapter.SelectCommand = cmd; adapter.SelectCommand.Connection = con; //adapter.TableMappings.Add("Table", "NHAPPS"); //OleDbCommandBuilder cb = new OleDbCommandBuilder(adapter); dataSet1 = new DataSet(); adapter.Fill(dataSet1, "KHOSACH"); DataTable dataTableKHOSACH = new DataTable(); dataTableKHOSACH= dataSet1.Tables["KHOSACH"]; cboMakhoabc.DataSource = dataTableKHOSACH; cboMakhoabc.DisplayMember = "MAKHO"; cboMakhoabc.ValueMember = "MAKHO"; txtMakho.DataBindings.Clear(); txtMakho.DataBindings.Add("Text", dataTableKHOSACH, "MAKHO"); txtSLtoida.DataBindings.Clear(); txtSLtoida.DataBindings.Add("Text", dataTableKHOSACH, "SOLUONGTOIDA"); } catch (Exception ex) { MessageBox.Show(ex.Message); } } private void populateLOAISACH() { try

{ OleDbCommand cmd = new OleDbCommand(); cmd.CommandType = CommandType.Text; cmd.CommandText = "SELECT * FROM LOAISACH"; cmd.Connection = con; adapter = new OleDbDataAdapter(); adapter.SelectCommand = cmd; adapter.SelectCommand.Connection = con; //adapter.TableMappings.Add("Table", "LOAISACH"); //OleDbCommandBuilder cb = new OleDbCommandBuilder(adapter); dataSet1 = new DataSet(); adapter.Fill(dataSet1, "LOAISACH"); DataTable datatableLoaisach = new DataTable(); datatableLoaisach = dataSet1.Tables["LOAISACH"]; this.cboLoaiSach.SelectedIndexChanged -= new System.EventHandler(this.cboLoaiSach_SelectedIndexChanged_1); cboLoaiSach.DataSource = datatableLoaisach; cboLoaiSach.DisplayMember = "TENLOAI"; cboLoaiSach.ValueMember = "MALOAI"; this.cboLoaiSach.SelectedIndexChanged += new System.EventHandler(this.cboLoaiSach_SelectedIndexChanged_1); txtMaloai.DataBindings.Clear(); txtMaloai.DataBindings.Add("Text", datatableLoaisach, "MALOAI"); } catch (Exception ex) { MessageBox.Show(ex.Message); } } private void populateNHAXUATBAN() { try { OleDbCommand cmd = new OleDbCommand(); cmd.CommandType = CommandType.Text; cmd.CommandText = "SELECT * FROM NHAXUATBAN"; cmd.Connection = con; adapter = new OleDbDataAdapter(); adapter.SelectCommand = cmd; adapter.SelectCommand.Connection = con; //adapter.TableMappings.Add("Table", "NHAXUATBAN"); //OleDbCommandBuilder cb = new OleDbCommandBuilder(adapter); dataSet1 = new DataSet(); adapter.Fill(dataSet1, "NHAXUATBAN"); DataTable datatableNhaXB = new DataTable(); datatableNhaXB = dataSet1.Tables["NHAXUATBAN"]; this.cboTenNXB.SelectedIndexChanged -= new System.EventHandler(this.cboTenNXB_SelectedIndexChanged_1); cboTenNXB.DataSource = datatableNhaXB; cboTenNXB.DisplayMember = "TENNXB"; cboTenNXB.ValueMember = "MANXB"; this.cboTenNXB.SelectedIndexChanged += new System.EventHandler(this.cboTenNXB_SelectedIndexChanged_1); txtManxb.DataBindings.Clear(); txtManxb.DataBindings.Add("Text", datatableNhaXB, "MANXB"); } catch (Exception ex) { MessageBox.Show(ex.Message); } } private void populateKHACHHANG() { try

{ OleDbCommand cmd = new OleDbCommand(); cmd.CommandType = CommandType.Text; cmd.CommandText = "SELECT * FROM KHACHHANG"; cmd.Connection = con; adapter = new OleDbDataAdapter(); adapter.SelectCommand = cmd; adapter.SelectCommand.Connection = con; //adapter.TableMappings.Add("Table", "NHAXUATBAN"); //OleDbCommandBuilder cb = new OleDbCommandBuilder(adapter); dataSet1 = new DataSet(); adapter.Fill(dataSet1, "KHACHHANG"); DataTable datatableKHACHHANG = new DataTable(); datatableKHACHHANG = dataSet1.Tables["KHACHHANG"]; this.cboMakh.SelectedIndexChanged -= new System.EventHandler(this.cboMakh_SelectedIndexChanged); cboMakh.DataSource = datatableKHACHHANG; cboMakh.DisplayMember = "MAKH"; cboMakh.ValueMember = "MAKH"; this.cboMakh.SelectedIndexChanged += new System.EventHandler(this.cboMakh_SelectedIndexChanged); txtTenKH.DataBindings.Clear(); txtTenKH.DataBindings.Add("Text", datatableKHACHHANG, "TENKH"); } catch (Exception ex) { MessageBox.Show(ex.Message); } } public void formatDatetimepicker() { //dateTimePicker1.CustomFormat = "MMMM dd, yyyy - dddd"; //dateTimePicker1.Format = DateTimePickerFormat.Custom; //dateTimePicker2.CustomFormat = "MMMM dd, yyyy - dddd"; //dateTimePicker2.Format = DateTimePickerFormat.Custom; } private void btnBangTinh_Click(object sender, EventArgs e) { Process.Start("calc.exe"); } private void btnInternet_Click(object sender, EventArgs e) { ProcessStartInfo startInfo = new ProcessStartInfo("IExplore.exe"); startInfo.WindowStyle = ProcessWindowStyle.Minimized; Process.Start(startInfo); //startInfo.Arguments = "www.google.com"; //Process.Start(startInfo); } private void panelNhapSach_Paint(object sender, PaintEventArgs e) { } private void btnDangXuat_Click(object sender, EventArgs e) { Logout lgout = new Logout(); lgout.goLogout(); this.Close(); frmDangNhap obj2 = new frmDangNhap(); obj2.Visible = true; }

private void btnThoat__Click(object sender, EventArgs e) { Logout lgout = new Logout(); lgout.goLogout(); Application.Exit(); } private void btnNhapSach_Click(object sender, EventArgs e) { gbNhapSach.Visible = true; gbNhapSach.Enabled = true; gbBanSach1.Visible = false; gbBanSach1.Enabled = false; gbPhanQuyen.Visible = false; gbPhanQuyen.Enabled = false; } private void frmMain_Load(object sender, EventArgs e) { DisableGroupbox(); txtDangDangNhap.Text = Login.UserName.ToString(); cboNhapSach.SelectedIndex = 0; cboBanSach.SelectedIndex = 0; cboLoaiHDB.SelectedIndex = 0; cboPhanQuyen.SelectedIndex = 0; populateLOAISACH(); populateNHAXUATBAN(); populateNPPS(); populateKHOSACH(); populateKHACHHANG(); NhapTenSach(); phanQuyen(); } public void DisableGroupbox() { gbNhapSach.Visible = false; gbNhapSach.Enabled = false; gbBanSach1.Enabled = false; gbBanSach1.Visible = false; gbPhanQuyen.Visible = false; gbPhanQuyen.Enabled = false; } private void phanQuyen() { int nhom; PhanQuyen thuocnhom = new PhanQuyen(); nhom = thuocnhom.PhanNhom(int.Parse(Login.NoUser.ToString())); if (nhom == 1)//quan ly { btnNhapSach.Enabled = true; btnBanSach.Enabled = true; btnKiemKe.Enabled = true; btnThongKe.Enabled = true; btnBaoCao.Enabled = true; btnPhanQuyen.Enabled = true; btnChiTien.Enabled = true; } else if (nhom == 2)//nhap sach { btnNhapSach.Enabled = true; btnBanSach.Enabled = false; btnKiemKe.Enabled = false; btnThongKe.Enabled = false;

btnBaoCao.Enabled = false; btnPhanQuyen.Enabled = false; btnChiTien.Enabled = false; } else if (nhom == 3)//ban sach { btnNhapSach.Enabled = false; btnBanSach.Enabled = true; btnKiemKe.Enabled = false; btnThongKe.Enabled = false; btnBaoCao.Enabled = false; btnPhanQuyen.Enabled = false; btnChiTien.Enabled = false; } else if (nhom == 4)//kiem ke { btnNhapSach.Enabled = false; btnBanSach.Enabled = false; btnKiemKe.Enabled = true; btnThongKe.Enabled = false; btnBaoCao.Enabled = false; btnPhanQuyen.Enabled = false; btnChiTien.Enabled = false; } else if (nhom == 5)//thong ke { btnNhapSach.Enabled = false; btnBanSach.Enabled = false; btnKiemKe.Enabled = false; btnThongKe.Enabled = true; btnBaoCao.Enabled = false; btnPhanQuyen.Enabled = false; btnChiTien.Enabled = false; } else if (nhom == 6)//bao cao { btnNhapSach.Enabled = false; btnBanSach.Enabled = false; btnKiemKe.Enabled = false; btnThongKe.Enabled = false; btnBaoCao.Enabled = true; btnPhanQuyen.Enabled = false; btnChiTien.Enabled = false; } else if (nhom == 7)//Phan quyen { btnNhapSach.Enabled = false; btnBanSach.Enabled = false; btnKiemKe.Enabled = false; btnThongKe.Enabled = false; btnBaoCao.Enabled = false; btnPhanQuyen.Enabled = true; btnChiTien.Enabled = false; } else if (nhom == 8)//chi tien { btnNhapSach.Enabled = false; btnBanSach.Enabled = false; btnKiemKe.Enabled = false; btnThongKe.Enabled = false; btnBaoCao.Enabled = false; btnPhanQuyen.Enabled = false; btnChiTien.Enabled = true; } else //chua gan nhom {

btnNhapSach.Enabled = false; btnBanSach.Enabled = false; btnKiemKe.Enabled = false; btnThongKe.Enabled = false; btnBaoCao.Enabled = false; btnPhanQuyen.Enabled = false; btnChiTien.Enabled = false; } }

private void cboLoaiSach_SelectedIndexChanged_1(object sender, EventArgs e) { } private void cboTenNXB_SelectedIndexChanged_1(object sender, EventArgs e) { } private void panelNhapSach1_Paint(object sender, PaintEventArgs e) { } private void cbo_nhapps_SelectedIndexChanged_1(object sender, EventArgs e) { } private void txtDangDangNhap_TextChanged(object sender, EventArgs e) { } private string Sopn { get { return sophieunhap; } set { sophieunhap = value; } } private DateTime Ngaylappn { get { return ngaylappn; } set { ngaylappn = value; } } private string Sohdm { get { return sohdm; } set { sohdm = value; }

} private DateTime Ngaylaphdm { get { return ngaylaphdm; } set { ngaylaphdm = value; } } private string Manpps { get { return manpps; } set { manpps = value; } } private string Tensach { get { return tensach; } set { tensach = value; } } private string Tacgia { get { return tacgia; } set { tacgia = value; } } private string Giaban { get { return giaban; } set { giaban = value; } } private string Lanxb { get {

return lanxb; } set { } }

lanxb = value;

private string Cknhap { get { return cknhap; } set { cknhap = value; } } private string Ckxuat { get { return ckxuat; } set { ckxuat = value; } } private string Maloai { get { return maloai; } set { maloai = value; } } private string Manxb { get { return manxb; } set { manxb = value; } } private string Soluong { get { return soluong; } set { soluong = value; }

} private string Dongia { get { return dongia; } set { dongia = value; } } private string Makho { get { return makho; } set { makho = value; } } private string SoHDB { get { return sohoadon; } set { sohoadon = value; } } private string LoaiHDB { get { return loaihd; } set { loaihd = value; } } private string Thuesuat { get { return thuesuat; } set { thuesuat = value; } } private string MaKH { get {

return makh; } set { } }

makh = value;

private DateTime Ngaylaphdb { get { return ngaylaphdb; } set { ngaylaphdb = value; } } private string Tensachban { get { return tensachban; } set { tensachban = value; } } private string SLuongban { get { return sluongban; } set { sluongban = value; } } private string DGiaban { get { return dgiaban; } set { dgiaban = value; } } private string Manv { get { return manv; } set { manv = value; }

} private string Manhom { get { return manhom; } set { manhom = value; } } private string TimManv { get { return timManv; } set { timManv = value; } } private string TimManhom { get { return timManhom; } set { timManhom = value; } } private void dtpNgaylapPN_ValueChanged_1(object sender, EventArgs e) { //DateTime d1 = dtpNgaylapPN.Value; //this.Ngaylappn = d1.ToShortDateString(); this.Ngaylappn = this.dtpNgaylapPN.Value.Date; //dtpNgaylapPN.Format = DateTimePickerFormat.Custom; //dtpNgaylapPN.CustomFormat = "MM/dd/yyyy"; //MessageBox.Show(dtpNgaylapPN.Value.Date.ToString()); } private void txtSohdm_TextChanged_1(object sender, EventArgs e) { this.Sohdm = txtSohdm.Text; } private void dtpNgaylapHDM_ValueChanged_1(object sender, EventArgs e) { this.Ngaylaphdm = dtpNgaylapHDM.Value.Date; } private void txtManpps_TextChanged_1(object sender, EventArgs e) { this.Manpps = txtManpps.Text; } private void txtTenSach_TextChanged_1(object sender, EventArgs e) { this.Tensach = txtTenSach.Text;

} private void txtTacgia_TextChanged_1(object sender, EventArgs e) { this.Tacgia = txtTacgia.Text; } private void txtMaloai_TextChanged_1(object sender, EventArgs e) { this.Maloai = txtMaloai.Text; } private void txtManxb_TextChanged_1(object sender, EventArgs e) { this.Manxb = txtManxb.Text; } private void txtLanXB_TextChanged_1(object sender, EventArgs e) { this.Lanxb = txtLanXB.Text; } private void txtGiaban_TextChanged_1(object sender, EventArgs e) { this.Giaban = txtGiaban.Text; } private void txtCKnhap_TextChanged_1(object sender, EventArgs e) { this.Cknhap = txtCKnhap.Text; } private void txtCKxuat_TextChanged_1(object sender, EventArgs e) { this.Ckxuat = txtCKxuat.Text; } private void txtSLNhap_TextChanged_1(object sender, EventArgs e) { this.Soluong = txtSLNhap.Text; } private void txtdongia_TextChanged_1(object sender, EventArgs e) { this.Dongia = txtdongia.Text; } private void btnLapPN_Click(object sender, EventArgs e) { //public void insertTablePhieuNhap(DateTime ngaylap_pn, //string sohdm, DateTime ngaylap_hdm, int manv, int manpps) try { this.Ngaylappn = dtpNgaylapPN.Value.Date; this.Ngaylaphdm = dtpNgaylapHDM.Value.Date; int temp; temp = int.Parse(Login.NoUser); NhapSach ns = new NhapSach(); ns.insertTablePhieuNhap(this.Ngaylappn, this.Sohdm.ToString(), this.Ngaylaphdm, temp, int.Parse(this.Manpps)); lbThongbao.Text = "Da lap phieu nhap"; lbThongbao.Enabled = true; lbThongbao.Visible = true; groupBox7.Enabled = true; groupBox7.Visible = true;

groupBox2.Enabled = false; } catch (Exception ex) { MessageBox.Show(ex.Message + " Khong chap nhan rong."); }

private void txtCapNhat_Click(object sender, EventArgs e) { getVariableNS(); try { KhoSach kiemtra = new KhoSach(); int sl, mk; sl = int.Parse(this.Soluong); mk = int.Parse(this.Makho); if (kiemtra.CheckSoluong(sl, mk)) { NhapSach ktradongianhap = new NhapSach(); if (ktradongianhap.checkDongianhap(int.Parse(this.Soluong), decimal.Parse(this.Giaban.ToString()), double.Parse(this.Cknhap.ToString()), decimal.Parse(this.Dongia.ToString()))) { Sach s = new Sach(); s.insertTableSach(this.Tensach, this.Tacgia, decimal.Parse(this.Giaban.ToString()), int.Parse(this.Lanxb.ToString()), double.Parse(this.Cknhap.ToString()), double.Parse(this.Ckxuat.ToString()), int.Parse(this.Maloai.ToString()), int.Parse(this.Manxb.ToString())); KhoSach tonkho = new KhoSach(); tonkho.insertTableTon_Kho(int.Parse(this.Makho.ToString()), int.Parse(this.Soluong.ToString())); NhapSach ns = new NhapSach(); ns.insertTableNhap_Sach(int.Parse(this.Soluong), decimal.Parse(this.Dongia)); NhapSach themThanhtien = new NhapSach(); themThanhtien.updateNHAP_SACH_THANHTIENNHAP(int.Parse(this.Soluon g.ToString()), decimal.Parse(this.Dongia.ToString())); lbThongbao.Text = "Da cap nhat"; lbThongbao.Enabled = true; lbThongbao.Visible = true; //MessageBox.Show("OK"); resetFieldNhapSach(); btnTinhTienNhap.Enabled = true; } else { MessageBox.Show("Xem lai don gia nhap, chiet khau nhap, gia ban, so luong nhap", "Thong bao", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } else { MessageBox.Show("Vuot qua so luong toi da trong kho"); } } catch (Exception ex) { MessageBox.Show(ex.Message + " Khong chap nhan rong."); } } private void btnHuyLapPN_Click(object sender, EventArgs e) { resetFieldLapPN(); lbThongbao.Enabled = false;

lbThongbao.Visible = false; } private void txtHuycapnhat_Click(object sender, EventArgs e) { txtTenSach.Text = null; txtTacgia.Text = null; cboLoaiSach.SelectedIndex = 0; cboTenNXB.SelectedIndex = 0; txtLanXB.Text = null; txtGiaban.Text = null; txtCKnhap.Text = null; txtCKxuat.Text = null; txtSLNhap.Text = null; txtdongia.Text = null; lbThongbao.Enabled = false; lbThongbao.Visible = false; } private void cboMakho_SelectedIndexChanged(object sender, EventArgs e) { } private void btnKetThuc_Click(object sender, EventArgs e) { btnXuatPN.Enabled = false; btnTinhTienNhap.Enabled = false; groupBox7.Enabled = false; groupBox7.Visible = false; groupBox2.Enabled = true; groupBox2.Visible = true; lbThongbao.Enabled = false; lbThongbao.Visible = false; resetFieldNhapSach(); resetFieldLapPN(); } private void txtSLtoida_TextChanged(object sender, EventArgs e) { } private void groupBox1_Enter(object sender, EventArgs e) { } private void txtMakho_TextChanged(object sender, EventArgs e) { this.Makho = txtMakho.Text; } public void resetFieldNhapSach() { try { txtTenSach.Text = null; txtTacgia.Text = null; cboLoaiSach.SelectedIndex = 0; cboTenNXB.SelectedIndex = 0; txtLanXB.Text = null; txtGiaban.Text = null; txtCKnhap.Text = null; txtCKxuat.Text = null; txtSLNhap.Text = null;

} catch (Exception ex) { MessageBox.Show(ex.Message); } }

txtdongia.Text = null; cboMakhoabc.SelectedIndex = 0;

public void resetFieldLapPN() { dtpNgaylapPN.Value = DateTime.Today; dtpNgaylapHDM.Value = DateTime.Today; txtSohdm.Text = null; cbo_nhapps.SelectedIndex = 0; } private void txtdongia_AcceptsTabChanged(object sender, EventArgs e) { //int abc; //abc = (int.Parse(this.Giaban) * int.Parse(this.Soluong)) (int.Parse(this.Giaban) * int.Parse(this.Soluong) * int.Parse(this.cknhap)); //txtdongia.Text = abc.ToString(); } private void getVariablePN() { this.Ngaylappn = this.dtpNgaylapPN.Value.Date; this.Sohdm = txtSohdm.Text; this.Ngaylaphdm = dtpNgaylapHDM.Value.Date; this.Manpps = txtManpps.Text; } private void getVariableNS() { this.Tensach = txtTenSach.Text; this.Tacgia = txtTacgia.Text; this.Maloai = txtMaloai.Text; this.Manxb = txtManxb.Text; this.Lanxb = txtLanXB.Text; this.Giaban = txtGiaban.Text; this.Cknhap = txtCKnhap.Text; this.Ckxuat = txtCKxuat.Text; this.Soluong = txtSLNhap.Text; this.Dongia = txtdongia.Text; this.Makho = txtMakho.Text; } private void txtLanXB_KeyPress_1(object sender, KeyPressEventArgs e) { if ((e.KeyChar < '0') || (e.KeyChar > '9')) { e.Handled = true; } } private void txtTacgia_KeyPress_1(object sender, KeyPressEventArgs e) { if ((e.KeyChar >= '0') && (e.KeyChar <= '9')) { e.Handled = true; } } private void txtGiaban_KeyPress_1(object sender, KeyPressEventArgs e) {

if ((e.KeyChar < '0') || (e.KeyChar > '9')) { e.Handled = true; }

private void txtSLNhap_KeyPress_1(object sender, KeyPressEventArgs e) { if ((e.KeyChar < '0') || (e.KeyChar > '9')) { e.Handled = true; } } private void txtdongia_KeyPress_1(object sender, KeyPressEventArgs e) { if ((e.KeyChar < '0') || (e.KeyChar > '9')) { e.Handled = true; } } private void txtCKnhap_KeyPress_1(object sender, KeyPressEventArgs e) { if ((e.KeyChar < '0') || (e.KeyChar > '9')) { e.Handled = true; } if((e.KeyChar=='.')) { e.Handled = false; } } private void txtCKxuat_KeyPress_1(object sender, KeyPressEventArgs e) { if ((e.KeyChar < '0') || (e.KeyChar > '9')) { e.Handled = true; } if ((e.KeyChar == '.')) { e.Handled = false; } } private void btnBanSach_Click(object sender, EventArgs e) { gbNhapSach.Visible = false; gbNhapSach.Enabled = false; gbBanSach1.Visible = true; gbBanSach1.Enabled = true; gbPhanQuyen.Visible = false; gbPhanQuyen.Enabled = false; } //private void btnThuchien_Click(object sender, EventArgs e) //{ // switch (cboBanSach.SelectedIndex) // { // case 0: // { // gbLapHDB.Visible = true; // gbLapHDB.Enabled = true; // break; // }

// // // // // // // // // // // // // //}

case 1: {

frm_BanSach_HoaDonBan obj = new frm_BanSach_HoaDonBan(); obj.Show(); break;

} case 2: {

frm_BanSach_TTKhachHang obj = new frm_BanSach_TTKhachHang(); obj.Show(); break;

public void resetFieldsHDB() { cboMakh.SelectedIndex = 0; dtpNgayLapHDB.Value = DateTime.Today; cboLoaiHDB.SelectedIndex = 0; txtThuesuat.Text = null; } private void getVariableHDB() { this.MaKH = Convert.ToString(cboMakh.Text); this.LoaiHDB = Convert.ToString(cboLoaiHDB.Text); this.Thuesuat = txtThuesuat.Text; } private void NhapTenSach() { //thu: good //+ " order by MASACH asc AutoCompleteStringCollection namesCollection = new AutoCompleteStringCollection(); OleDbCommand cmd = new OleDbCommand(); cmd.Connection = con; cmd.CommandType = CommandType.Text; cmd.CommandText = "select * from SACH"; adapter = new OleDbDataAdapter(); adapter.SelectCommand = cmd; adapter.SelectCommand.Connection = con; dataSet1 = new DataSet(); adapter.Fill(dataSet1, "SACH"); DataTable dataTableSACH = new DataTable(); dataTableSACH = dataSet1.Tables["SACH"]; //DataColumn co; //co = dataTableSACH.Columns["TENSACH"]; int i; for (i = 0; i < dataTableSACH.Rows.Count; i++) { namesCollection.Add(dataTableSACH.Rows[i]["TENSACH"].ToString()); } //cmd.CommandText = "Select TENSACH from SACH"; //OleDbDataReader re = cmd.ExecuteReader(); //if (re.HasRows == true) //{ // while (re.Read()) // namesCollection.Add(re["TENSACH"].ToString()); //} //else //{ // MessageBox.Show("Data not found"); //}

//re.Close(); txtTenSachban.AutoCompleteMode = AutoCompleteMode.Suggest; txtTenSachban.AutoCompleteSource = AutoCompleteSource.CustomSource; txtTenSachban.AutoCompleteCustomSource = namesCollection; txtTenSachban.DataBindings.Clear(); txtTenSachban.DataBindings.Add("Text", dataTableSACH, "TENSACH"); //textBox2.DataBindings.Clear(); //textBox2.DataBindings.Add("Text", dataTableSACH, "MASACH"); } public void getVariableBanSach() { this.Tensachban = txtTenSachban.Text; this.SLuongban = txtSLuongsachBan.Text; this.DGiaban = txtDgiaBan.Text; } public void resetFieldsBanSach() { txtTenSachban.Text = null; txtSLuongsachBan.Text = null; txtDgiaBan.Text = null; } public void TinhTien() { int so_hdb, tong_sl, ma_sach;// so_luong; decimal don_gia; decimal tong_dg = 0; decimal thanh_tien = 0; double thue_suat, ck_xuat; string loai_hd; OleDbConnection con = new OleDbConnection(); ConnectDB conDB = new ConnectDB(); con = conDB.getConn(); con.Open(); string so_hd = "SELECT MAX(SOHOADON)FROM HOADONBAN"; OleDbCommand cmdso_hd = new OleDbCommand(so_hd, con); so_hdb = Convert.ToInt32(cmdso_hd.ExecuteScalar()); cmdso_hd.Dispose(); string str_tongsl = @"SELECT SUM(SLUONGBAN) FROM BAN_SACH WHERE SOHOADON = "+so_hdb+""; OleDbCommand cmd_tongsl = new OleDbCommand(str_tongsl, con); tong_sl = Convert.ToInt32(cmd_tongsl.ExecuteScalar()); cmd_tongsl.Dispose(); string str_loai_hd = @"SELECT LOAIHD FROM HOADONBAN WHERE SOHOADON = " + so_hdb + ""; OleDbCommand cmd_loaihd = new OleDbCommand(str_loai_hd, con); loai_hd = Convert.ToString(cmd_loaihd.ExecuteScalar()); cmd_loaihd.Dispose(); string str_thuesuat = @"SELECT THUESUAT FROM HOADONBAN WHERE SOHOADON = "+so_hdb+""; OleDbCommand cmd_thuesuat = new OleDbCommand(str_thuesuat, con); thue_suat = Convert.ToDouble(cmd_thuesuat.ExecuteScalar()); cmd_thuesuat.Dispose(); string str_masach = @"SELECT MASACH FROM BAN_SACH WHERE SOHOADON = "+so_hdb+""; OleDbCommand cmd_masach = new OleDbCommand(str_masach, con); OleDbDataReader re = cmd_masach.ExecuteReader(); if (re.HasRows == true)

{ while (re.Read()) { ma_sach = Convert.ToInt32(re["MASACH"].ToString()); string str_ckxuat = @"SELECT CHIETKHAUXUAT FROM SACH WHERE MASACH = " + ma_sach + ""; OleDbCommand cmd_ckxuat = new OleDbCommand(str_ckxuat, con); ck_xuat = Convert.ToDouble(cmd_ckxuat.ExecuteScalar()); cmd_ckxuat.Dispose(); string str_dongia = @"SELECT DGIABAN FROM BAN_SACH WHERE SOHOADON = " + so_hdb + "AND MASACH = "+ma_sach+""; OleDbCommand cmd_dongia = new OleDbCommand(str_dongia, con); don_gia = Convert.ToDecimal(cmd_dongia.ExecuteScalar()); cmd_dongia.Dispose(); // // // // // string str_soluong = @"SELECT SLUONGBAN FROM BAN_SACH WHERE SOHOADON = " + so_hdb + "AND MASACH = " + ma_sach + ""; OleDbCommand cmd_soluong = new OleDbCommand(str_soluong, con); so_luong = Convert.ToInt32(cmd_soluong.ExecuteScalar()); cmd_soluong.Dispose();

if (loai_hd.ToString() == "Si".ToString()) { tong_dg = tong_dg + (don_gia - (don_gia * decimal.Parse(ck_xuat.ToString()))); //tong_dg = tong_dg - (tong_dg * (decimal.Parse(ck_xuat.ToString()))); } else { tong_dg = tong_dg + (don_gia); } } } thanh_tien = tong_dg + (tong_dg*(decimal.Parse(thue_suat.ToString()))); txtTongSLBan.Text = tong_sl.ToString(); txtTongDgia.Text = tong_dg.ToString(); txtThanhtien.Text = thanh_tien.ToString(); txtSoHDB.Text = so_hdb.ToString(); HoaDonBan capnhatThanhtien = new HoaDonBan(); capnhatThanhtien.updateTableHOADONBAN_ThanhTien(so_hdb,tong_sl, tong_dg,

thanh_tien);

string str_query = @"SELECT HOADONBAN.SOHOADON, HOADONBAN.NGAYLAPHD, HOADONBAN.LOAIHD, HOADONBAN.THUESUAT, HOADONBAN.MAKH, HOADONBAN.MANV, BAN_SACH.MASACH, BAN_SACH.SLUONGBAN, BAN_SACH.DGIABAN FROM HOADONBAN, BAN_SACH WHERE HOADONBAN.SOHOADON = "+so_hdb+" AND HOADONBAN.SOHOADON = BAN_SACH.SOHOADON"; OleDbCommand cmdQuery = new OleDbCommand(str_query, con); adapter = new OleDbDataAdapter(); adapter.SelectCommand = cmdQuery; adapter.SelectCommand.Connection = con; dataSet1 = new DataSet(); DataTable datatableQuery = new DataTable(); adapter.Fill(dataSet1, "Query"); datatableQuery = dataSet1.Tables["Query"]; DataRow dr = datatableQuery.NewRow(); dr["LOAIHD"] = "Tong cong".ToString(); dr["SLUONGBAN"] = dataSet1.Tables["Query"].Compute("Sum(SLUONGBAN)", null);

dr["DGIABAN"] = dataSet1.Tables["Query"].Compute("Sum(DGIABAN)", null); datatableQuery.Rows.Add(dr); dgvHDB_BanS.DataSource = datatableQuery; //Nho reset fields, ham nay dat trong form } private void txtThuesuat_KeyPress_1(object sender, KeyPressEventArgs e) { if ((e.KeyChar < '0') || (e.KeyChar > '9')) { e.Handled = true; } if ((e.KeyChar == '.')) { e.Handled = false; } } private void txtSLuongsachBan_KeyPress_1(object sender, KeyPressEventArgs e) { if ((e.KeyChar < '0') || (e.KeyChar > '9')) { e.Handled = true; } } private void txtDgiaBan_KeyPress_1(object sender, KeyPressEventArgs e) { if ((e.KeyChar < '0') || (e.KeyChar > '9')) { e.Handled = true; } } private void btnPhanQuyen_Click(object sender, EventArgs e) { gbNhapSach.Visible = false; gbNhapSach.Enabled = false; gbBanSach1.Visible = false; gbBanSach1.Enabled = false; gbPhanQuyen.Visible = true; gbPhanQuyen.Enabled = true; } private void btnThuchienPQ_Click(object sender, EventArgs e) { switch (cboPhanQuyen.SelectedIndex) { case 0: { GetDataPhanQuyen(); gbGanNhom.Enabled = true; gbGanNhom.Visible = true; break; } case 1: { frm_PhanQuyen_TTNhanVien obj = new frm_PhanQuyen_TTNhanVien(); obj.Show(); break; } case 2: { frm_PhanQuyen_DinhDanh obj = new frm_PhanQuyen_DinhDanh(); obj.Show();

break; } } private void GetDataPhanQuyen() { try { //create dataset DataSet data = new DataSet(); data.Locale = System.Globalization.CultureInfo.InvariantCulture; // Add data from the NHANVIEN table to the DataSet. OleDbDataAdapter masterDataAdapter = new OleDbDataAdapter("select * from NHANVIEN", con); masterDataAdapter.Fill(data, "NHANVIEN"); // Add data from the THUOCNHOM table to the DataSet. OleDbDataAdapter detailsDataAdapter = new OleDbDataAdapter("select * from THUOCNHOM", con); detailsDataAdapter.Fill(data, "THUOCNHOM"); THUOCNHOM // Establish a relationship between the two tables: NHANVIEN ANd DataRelation relation = new DataRelation("Thuocnhom_nhanvien", data.Tables["NHANVIEN"].Columns["MANV"], data.Tables["THUOCNHOM"].Columns["MANV"], false); data.Relations.Add(relation); // Add data from the NHOM table to the DataSet. OleDbDataAdapter sachDataadapter = new OleDbDataAdapter("select * from NHOM", con); sachDataadapter.Fill(data, "NHOM"); // Bind the master data connector to the Customers table. thuocnhomBindingSource.DataSource = data; thuocnhomBindingSource.DataMember = "NHANVIEN"; // Bind the details data connector to the master data connector, // using the DataRelation name to filter the information in the // details table based on the current row in the master table. nhanvienBindingSource.DataSource = thuocnhomBindingSource; nhanvienBindingSource.DataMember = "Thuocnhom_nhanvien"; cboMaNV.DataSource = thuocnhomBindingSource; cboMaNV.DisplayMember = "MANV"; dgvNhanvien.DataSource = thuocnhomBindingSource; dgvThuocNhom.DataSource = nhanvienBindingSource; dgvNhom.DataSource = data.Tables["NHOM"]; txtMaNhom.DataBindings.Clear(); txtMaNhom.DataBindings.Add("Text", nhanvienBindingSource, "MANHOM"); }

} catch (Exception ex) { MessageBox.Show(ex.Message); } }

private void btnSua_Click(object sender, EventArgs e) { getVariablesPhanQ(); try { PhanQuyen ktranNhom = new PhanQuyen(); if (ktranNhom.checkManhom(int.Parse(this.Manhom.ToString())))

{ PhanQuyen ktradatontai = new PhanQuyen(); if (ktradatontai.checkInsertThuocnhom(int.Parse(this.Manv.ToString()), int.Parse(this.Manhom.ToString()))) { PhanQuyen suaThuocnhom = new PhanQuyen(); suaThuocnhom.updateRowOfTHUOCNHOM(int.Parse(this.Manv.ToString() ), int.Parse(this.Manhom.ToString()), int.Parse(this.TimManv.ToString()), int.Parse(this.TimManhom.ToString())); lbThongbaoPQ.Text = "Da sua"; lbThongbaoPQ.Visible = true; lbThongbaoPQ.Enabled = true; } else { MessageBox.Show("Da ton tai roi."); } } else { MessageBox.Show("Khong co ma nhom nay."); } } catch (Exception ex) { MessageBox.Show(ex.Message); } } public void getVariablesPhanQ() { this.TimManv = Convert.ToString(cboMaNV.Text); this.TimManhom = txtMaNhom.Text; this.Manv = txtManv_Sua.Text; this.Manhom = txtManhom_Sua.Text; } private void cboMaNV_SelectedIndexChanged(object sender, EventArgs e) { this.TimManv = Convert.ToString(cboMaNV.Text); } private void txtMaNhom_TextChanged(object sender, EventArgs e) { this.TimManhom = txtMaNhom.Text; } private void txtSopn_TextChanged_1(object sender, EventArgs e) { this.Sopn = txtSopn.Text; } private void lbThongbao_Click(object sender, EventArgs e) { } private void cboMakhoabc_SelectedIndexChanged(object sender, EventArgs e) { } private void txtMakho_TextChanged_1(object sender, EventArgs e) {

} private void txtSLtoida_TextChanged_1(object sender, EventArgs e) { } private void btnThuchienNS_Click(object sender, EventArgs e) { //DateTime d = dateTimePicker1.Value; //string a = d.ToShortDateString(); //DateTime ab = Convert.ToDateTime(a.ToString()); //MessageBox.Show(a.ToString()); switch (cboNhapSach.SelectedIndex) { case 0: { groupBox2.Enabled = true; groupBox2.Visible = true; break; } case 1: { frmNhapSach_PhieuNhap obj = new frmNhapSach_PhieuNhap(); obj.Show(); break; } case 2: { frmNhapSach_Sach obj = new frmNhapSach_Sach(); obj.Show(); break; } case 3: { frmNhapSach_LoaiSach obj = new frmNhapSach_LoaiSach(); obj.Show(); break; } case 4: { frmNhapSach_NPPS obj = new frmNhapSach_NPPS(); obj.Show(); break; } case 5: { frmNhapSach_NXB obj = new frmNhapSach_NXB(); obj.Show(); break; } case 6: { frmNhapSach_KhoSach obj = new frmNhapSach_KhoSach(); obj.Show(); break; } } } private void btnThucHienBS_Click(object sender, EventArgs e) { switch (cboBanSach.SelectedIndex) { case 0: {

gbLapHDB.Visible = true; gbLapHDB.Enabled = true; break; } case 1: {

frm_BanSach_HoaDonBan obj = new frm_BanSach_HoaDonBan(); obj.Show(); break;

} case 2: {

frm_BanSach_TTKhachHang obj = new frm_BanSach_TTKhachHang(); obj.Show(); break;

} }

private void btnLapHDB_Click(object sender, EventArgs e) { //public void insertTableHoaDonBan(DateTime ngaylap_hd, //string loaihoadon, float thuesuat, int makh, int manv) getVariableHDB(); try { this.Ngaylaphdb = dtpNgayLapHDB.Value.Date; int temp; temp = int.Parse(Login.NoUser); HoaDonBan laphd = new HoaDonBan(); laphd.insertTableHoaDonBan(this.Ngaylaphdb, this.LoaiHDB.ToString(), float.Parse(this.Thuesuat.ToString()), int.Parse(this.MaKH.ToString()), temp); lbThongbaoBS.Text = "Da lap hoa don ban"; lbThongbaoBS.Enabled = true; lbThongbaoBS.Visible = true; gbBanSach.Enabled = true; gbBanSach.Visible = true; gbLapHDB.Enabled = false; resetFieldsHDB();

} catch (Exception ex) { MessageBox.Show(ex.Message + " Khong chap nhan rong."); } } private void btnHuyHDB_Click(object sender, EventArgs e) { resetFieldsHDB(); } private void cboMakh_SelectedIndexChanged(object sender, EventArgs e) { this.MaKH = Convert.ToString(cboMakh.Text); } private void dtpNgayLapHDB_ValueChanged(object sender, EventArgs e) { this.Ngaylaphdb = this.dtpNgayLapHDB.Value.Date; } private void cboLoaiHDB_SelectedIndexChanged(object sender, EventArgs e) { this.LoaiHDB = Convert.ToString(cboLoaiHDB.Text); }

private void txtThuesuat_TextChanged(object sender, EventArgs e) { this.Thuesuat = txtThuesuat.Text; } private void txtTenSachban_TextChanged(object sender, EventArgs e) { this.Tensachban = txtTenSachban.Text; } private void txtSLuongsachBan_TextChanged(object sender, EventArgs e) { this.SLuongban = txtSLuongsachBan.Text; } private void txtDgiaBan_TextChanged(object sender, EventArgs e) { this.DGiaban = txtDgiaBan.Text; } private void btnThemvaoHD_Click(object sender, EventArgs e) { int sltonkho; getVariableBanSach(); try { Sach ktra = new Sach(); if (ktra.checkTenSach(this.Tensachban.ToString())) { int masach; Sach s = new Sach(); masach = s.searchMaSachOfSACH(this.Tensachban.ToString()); KhoSach ktratonkho = new KhoSach(); if (ktratonkho.checkTON_KHO_khibansach(masach, int.Parse(this.SLuongban.ToString()))) //if (ktratonkho.checkTON_KHO_khibansach_tensach(this.Tensachban.ToString(), int.Parse(this.SLuongban.ToString()))) //if(masach != 0) { BanSach themvao = new BanSach(); //themvao.insertTableBan_Sach(); themvao.insertTableBan_Sach(masach, int.Parse(this.SLuongban.ToString()), decimal.Parse(this.DGiaban.ToString())); KhoSach capnhaKho = new KhoSach(); //capnhaKho.updateRowOfTON_KHO_khibansach(this.Tensachban .ToString(), int.Parse(this.SLuongban.ToString()), decimal.Parse(this.DGiaban.ToString())); capnhaKho.updateRowOfTON_KHO_khibansach(masach, int.Parse(this.SLuongban.ToString())); lbThongbaoBS.Text = "Da them vao"; lbThongbaoBS.Enabled = true; lbThongbaoBS.Visible = true; } else { resetFieldsBanSach();

KhoSach layslg = new KhoSach(); sltonkho = layslg.laySLTON_KHO(masach); MessageBox.Show("Vuot qua so luong sach trong kho, trong kho dang co " + sltonkho.ToString() + " quyen mang ma so nay."); } } else

{ } MessageBox.Show("Khong co sach nay"); } catch (Exception ex) { MessageBox.Show(ex.Message + " Khong chap nhan rong."); }

private void btnTinhtien_Click(object sender, EventArgs e) { lbThongbaoBS.Enabled = false; lbThongbaoBS.Visible = false; gbChitietHDB.Visible = true; gbChitietHDB.Enabled = true; btnKetThucBS.Enabled = true; TinhTien(); } private void cboPhanQuyen_SelectedIndexChanged(object sender, EventArgs e) { } private void txtManv_Sua_TextChanged(object sender, EventArgs e) { this.Manv = txtManv_Sua.Text; } private void txtManhom_Sua_TextChanged(object sender, EventArgs e) { this.Manhom = txtManhom_Sua.Text; } private void btnXoa_Click(object sender, EventArgs e) { this.TimManv = Convert.ToString(cboMaNV.Text); this.TimManhom = txtMaNhom.Text; try { DialogResult result; result = MessageBox.Show("Co chac ban muon xoa?", "Thong bao", MessageBoxButtons.YesNoCancel); if (result == DialogResult.No) { } else if (result == DialogResult.Yes) { //public void deleteRowOfNHAPPS(int manhapps) PhanQuyen xoaThuocnhom = new PhanQuyen(); xoaThuocnhom.deleteRowOfTHUOCNHOM(int.Parse(this.TimManv.ToString()), int.Parse(this.TimManhom.ToString())); MessageBox.Show("Da xoa", "Thong Bao"); } else { } } catch (Exception ex) { MessageBox.Show(ex.Message); } } private void btnThem_Click(object sender, EventArgs e) { this.Manv = txtManv_Sua.Text;

this.Manhom = txtManhom_Sua.Text; try {

PhanQuyen ktranNhom = new PhanQuyen(); if (ktranNhom.checkManhom(int.Parse(this.Manhom.ToString()))) { PhanQuyen ktradatontai = new PhanQuyen(); if (ktradatontai.checkInsertThuocnhom(int.Parse(this.Manv.ToString()), int.Parse(this.Manhom.ToString()))) { PhanQuyen themThuocnhom = new PhanQuyen(); themThuocnhom.insertTableTHUOCNHOM(int.Parse(this.Manv.ToString() ), int.Parse(this.Manhom.ToString())); lbThongbaoPQ.Text = "Da them"; lbThongbaoPQ.Visible = true; lbThongbaoPQ.Enabled = true; } else { MessageBox.Show("Da ton tai roi."); } } else { MessageBox.Show("Khong co ma nhom nay."); } } catch (Exception ex) { MessageBox.Show(ex.Message); } } private void btnKetthucPQ_Click(object sender, EventArgs e) { txtManv_Sua.Text = null; txtManhom_Sua.Text = null; cboMaNV.SelectedIndex = 0; gbGanNhom.Visible = false; gbGanNhom.Enabled = false; } private void cboBanSach_SelectedIndexChanged(object sender, EventArgs e) { } private void txtTenKH_TextChanged(object sender, EventArgs e) { } private void btnKetThucBS_Click(object sender, EventArgs e) { gbLapHDB.Enabled = true; gbBanSach.Visible = false; gbBanSach.Enabled = false; gbChitietHDB.Visible = false; gbChitietHDB.Enabled = false; } private void txtManhom_Sua_KeyPress(object sender, KeyPressEventArgs e) { if ((e.KeyChar < '0') || (e.KeyChar > '9'))

{ } } private void txtManv_Sua_KeyPress(object sender, KeyPressEventArgs e) { if ((e.KeyChar < '0') || (e.KeyChar > '9')) { e.Handled = true; } } private void btnChiTien_Click(object sender, EventArgs e) { frm_ChiTien_LapPhieuChi obj = new frm_ChiTien_LapPhieuChi(); obj.Show(); } private void btnKiemKe_Click(object sender, EventArgs e) { frm_XuatTraSach obj = new frm_XuatTraSach(); obj.Show(); } private void btnTinhTienNhap_Click(object sender, EventArgs e) { int soluong_; decimal thanhtien_; NhapSach laysoluong = new NhapSach(); NhapSach laythanhtien = new NhapSach(); soluong_ = laysoluong.getTongSLNhap_SoPN(); thanhtien_ = laythanhtien.getThanhTienNhap_SoPN(); txtTongSLNhap.Text = soluong_.ToString(); txtThanhtienNhap.Text = thanhtien_.ToString(); btnXuatPN.Enabled = true; try { int temp; temp = int.Parse(Login.NoUser); ChiTien themPhieuchi = new ChiTien(); themPhieuchi.insertTablePhieuchi_SauKhiLapPN(temp); btnKetThuc.Enabled = true; } catch (Exception ex) { MessageBox.Show(ex.Message); } } private void btnThongKe_Click(object sender, EventArgs e) { frm_ThongKe obj = new frm_ThongKe(); obj.Show(); } private void btnBaoCao_Click(object sender, EventArgs e) { frm_BaoCao obj = new frm_BaoCao(); obj.Show(); } private void btnTroGiup_Click(object sender, EventArgs e) { e.Handled = true;

//Help.ShowHelp(this, "C:\\Documents and Settings\\Administrator\\My Documents\\Visual Studio 2008\\Projects\\NL2\\Trogiup.chm", HelpNavigator.TableOfContents, ""); frm_TroGiup obj = new frm_TroGiup(); obj.Show(); } private void btnXuatPN_Click(object sender, EventArgs e) { frm_XuatPhieuNhap obj = new frm_XuatPhieuNhap(); obj.Show(); } private void btnXuatHDB_Click(object sender, EventArgs e) { frm_XuatHoaDonBan obj = new frm_XuatHoaDonBan(); obj.Show(); }

} }

Nt nhp sch c nhn:

Chn chc nng nhp sch trong nhp sch, Chng trnh lp phiu nhp hin ra:

Sau khi lp phiu nhp xong, ca s hin ra:

Cp nht vo cc sch, nhn xong nt cp nht, nt tnh tin s hin ln cho php tnh tng tin v tng s lng nhp, sau khi nt tnh tin c nhn, nt xut phiu nhp s hin ln v cho php xut phiu nhp. (xut phiu nhp bng cch to report ri cho in report!):

Chn chc nng cp nht phiu nhp trong nhp sch, form mi hin ra:

Code:
namespace NL2 { public partial class frmNhapSach_PhieuNhap : Form { private OleDbConnection con; private string sophieunhap, sohdm, manpps; private DateTime ngaylappn, ngaylaphdm; //DataGridView masterDataGridView = new DataGridView();

BindingSource masterBindingSource = new BindingSource(); BindingSource detailsBindingSource = new BindingSource(); BindingSource sachBindingSource = new BindingSource(); BindingSource nppsBindingSource = new BindingSource(); private OleDbDataAdapter adapter; public frmNhapSach_PhieuNhap() { InitializeComponent(); con = new OleDbConnection(); ConnectDB conDB = new ConnectDB(); con = conDB.getConn(); con.Open(); } private void populatePhieuNhap_NhapSach() { } private string Sophieunhap { get { return sophieunhap; } set { sophieunhap = value; } } private DateTime Ngaylappn { get { return ngaylappn; } set { ngaylappn = value; } } private string Sohdm { get { return sohdm; } set { sohdm = value; } } private DateTime Ngaylaphdm { get { return ngaylaphdm; } set { ngaylaphdm = value; }

} private string Manpps { get { return manpps; } set { manpps = value; } } private void cboSophieunhap_SelectedIndexChanged(object sender, EventArgs e) { this.Sophieunhap = Convert.ToString(cboSophieunhap.Text); lbThongbao.Enabled = false; lbThongbao.Visible = false; } private void dtpNgaylappn_ValueChanged(object sender, EventArgs e) { this.Ngaylappn = dtpNgaylappn.Value.Date; } private void txtSohdm_TextChanged(object sender, EventArgs e) { this.Sohdm = txtSohdm.Text; } private void dtpNgaylaphdm_ValueChanged(object sender, EventArgs e) { this.Ngaylaphdm = dtpNgaylaphdm.Value.Date; } private void txtMaNPPS_TextChanged(object sender, EventArgs e) { this.Manpps = txtMaNPPS.Text; } private void NhapSach_PhieuNhap_Load(object sender, EventArgs e) { populateNPPS(); txtMaNV.Text = Login.NoUser.ToString(); //dataGridView1.DataSource = masterBindingSource; //dataGridView2.DataSource = detailsBindingSource; //To AutoResize colunm in the datagridview //set AutoSizeColumn = AllCells in the datagridview property GetData(); } private void GetData() { try { // Specify a connection string. Replace the given value with a // valid connection string for a Northwind SQL Server sample // database accessible to your system. // Create a DataSet. DataSet data = new DataSet(); data.Locale = System.Globalization.CultureInfo.InvariantCulture; // Add data from the Customers table to the DataSet. OleDbDataAdapter masterDataAdapter = new

OleDbDataAdapter("select * from PHIEUNHAP", con); masterDataAdapter.Fill(data, "PHIEUNHAP"); // Add data from the Orders table to the DataSet. OleDbDataAdapter detailsDataAdapter = new OleDbDataAdapter("select * from NHAP_SACH", con); detailsDataAdapter.Fill(data, "NHAP_SACH"); // Establish a relationship between the two tables: PHIEUNHAP ANd NHAP_SACH DataRelation relation = new DataRelation("CustomersOrders", data.Tables["PHIEUNHAP"].Columns["SOPHIEUNHAP"], data.Tables["NHAP_SACH"].Columns["SOPHIEUNHAP"], false); data.Relations.Add(relation); // Add data from the SACH table to the DataSet. OleDbDataAdapter sachDataadapter = new OleDbDataAdapter("select * from SACH", con); sachDataadapter.Fill(data, "SACH"); // Establish a relationship between the two tables: NHAP_SACH and SACH DataRelation relation2 = new DataRelation("NhapsachSach", data.Tables["NHAP_SACH"].Columns["MASACH"], data.Tables["SACH"].Columns["MASACH"], false); data.Relations.Add(relation2); // Bind the master data connector to the Customers table. masterBindingSource.DataSource = data; masterBindingSource.DataMember = "PHIEUNHAP"; // Bind the details data connector to the master data connector, // using the DataRelation name to filter the information in the // details table based on the current row in the master table. detailsBindingSource.DataSource = masterBindingSource; detailsBindingSource.DataMember = "CustomersOrders"; // Bind data sachBindingSource.DataSource = detailsBindingSource; sachBindingSource.DataMember = "NhapsachSach"; cboSophieunhap.DataSource = masterBindingSource; cboSophieunhap.DisplayMember = "SOPHIEUNHAP"; dataGridView1.DataSource = masterBindingSource; dataGridView2.DataSource = detailsBindingSource; dataGridView3.DataSource = sachBindingSource; txtSohdm.DataBindings.Clear(); txtSohdm.DataBindings.Add("Text", masterBindingSource, "SOHDM"); txtMaNPPS.DataBindings.Clear(); txtMaNPPS.DataBindings.Add("Text", masterBindingSource, "MANPPS"); dtpNgaylaphdm.DataBindings.Clear(); dtpNgaylaphdm.DataBindings.Add("Value", masterBindingSource, "NGAYLAPHDM"); dtpNgaylappn.DataBindings.Clear(); dtpNgaylappn.DataBindings.Add("Value", masterBindingSource, "NGAYLAPPN");

} catch (Exception ex) { MessageBox.Show(ex.Message); } }

public void searchRowOfPHIEUNHAP_ngaylap(DateTime ngaylap) { this.Ngaylappn = this.dtpNgaylappn.Value.Date; ngaylap = this.Ngaylappn; try

{ int kiemtrarong; OleDbCommand cmd1 = new OleDbCommand(); cmd1.CommandType = CommandType.Text; cmd1.CommandText = "SELECT count(*) FROM PHIEUNHAP WHERE NGAYLAPPN=#" + ngaylap + "#"; cmd1.Connection = con; kiemtrarong = Convert.ToInt32(cmd1.ExecuteScalar()); cmd1.Dispose(); if (kiemtrarong == 0) { lbThongbao.Text = "(*) khong ton tai phieu nhap nay "; lbThongbao.Enabled = true; lbThongbao.Visible = true; } else { lbThongbao.Text = "(*) co ton tai phieu nhap nay "; lbThongbao.Enabled = true; lbThongbao.Visible = true; }

} catch (Exception ex) { MessageBox.Show(ex.Message); }

private void populateNPPS() { try { //int kiemtrarong; OleDbCommand cmd1 = new OleDbCommand(); cmd1.CommandType = CommandType.Text; cmd1.CommandText = "SELECT * FROM NHAPPS"; cmd1.Connection = con; object result = cmd1.ExecuteScalar(); if (result == null && result == DBNull.Value) { } else {

OleDbCommand cmd = new OleDbCommand(); cmd.CommandType = CommandType.Text; cmd.CommandText = "select * from NHAPPS"; cmd.Connection = con; adapter = new OleDbDataAdapter(); adapter.SelectCommand = cmd; adapter.SelectCommand.Connection = con; dataSet1 = new DataSet(); adapter.Fill(dataSet1, "NHAPPS"); DataTable dataTable1 = new DataTable(); dataTable1 = dataSet1.Tables["NHAPPS"]; cboManpps.DataSource = dataTable1; cboManpps.DisplayMember = "MANPPS"; txtTennpps.DataBindings.Clear(); txtTennpps.DataBindings.Add("Text", dataTable1, "TENNPPS");

} } catch (Exception ex) { MessageBox.Show(ex.Message); } }

private void btnSua_Click(object sender, EventArgs e) { getVariable(); try { NhapSach ns = new NhapSach(); ns.updateRowOfPHIEUNHAP(int.Parse(this.Sophieunhap), this.Ngaylappn, this.Sohdm, this.Ngaylaphdm, int.Parse(this.Manpps)); //Error: No value given for one or more required parameters //because the name of the variable is set wrongly lbThongbao.Text = "Da cap nhat"; lbThongbao.Visible = true; lbThongbao.Enabled = true; //resetField(); } catch (Exception ex) { MessageBox.Show(ex.Message); } } //private void btnTimkiem_Click(object sender, EventArgs e) //{ // searchRowOfPHIEUNHAP_ngaylap(this.Ngaylappn); //} private void btnThoat_Click(object sender, EventArgs e) { con.Close(); this.Close(); } private void btnXoa_Click(object sender, EventArgs e) { this.Sophieunhap = Convert.ToString(cboSophieunhap.Text); NhapSach kiemtra = new NhapSach(); try { if (kiemtra.checkXoaPhieunhap(int.Parse(this.Sophieunhap))) { DialogResult result; result = MessageBox.Show("Co chac ban muon xoa?", "Thong bao", MessageBoxButtons.YesNoCancel); if (result == DialogResult.No) { } else if (result == DialogResult.Yes) { NhapSach xoa = new NhapSach(); xoa.deleteRowOfPHIEUNHAP_NHAPSACH_SACH(int.Parse(this.Sophieunhap )); MessageBox.Show("Da xoa", "Thong Bao"); resetField(); } else { } } else { MessageBox.Show("Khong xoa duoc khi sach chua ban het", "thong bao", MessageBoxButtons.OK); } } catch (Exception ex) { MessageBox.Show(ex.Message);

} } private void getVariable() { this.Sophieunhap = Convert.ToString(cboSophieunhap.Text); this.Ngaylappn = dtpNgaylappn.Value.Date; this.Sohdm = txtSohdm.Text; this.Ngaylaphdm = dtpNgaylaphdm.Value.Date; this.Manpps = txtMaNPPS.Text; } private void txtMaNV_TextChanged(object sender, EventArgs e) { } public void resetField() { dtpNgaylappn.Value = DateTime.Today; dtpNgaylaphdm.Value = DateTime.Today; txtSohdm.Text = null; txtMaNPPS.Text = null; txtMaNV.Text = null; } //private void btnSuaNS_Click(object sender, EventArgs e) //{ // getVariable(); // try // { // NhapSach ns2 = new NhapSach(); // ns2.updateRowOfNHAP_SACH(int.Parse(this.Sophieunhap), int.Parse(this.Masach), int.Parse(this.Soluong), decimal.Parse(this.Dongia)); // lbThongbao.Text = "Da cap nhat"; // lbThongbao.Visible = true; // lbThongbao.Enabled = true; // } // catch (Exception ex) // { // MessageBox.Show(ex.Message); // } //} private void btnTongsl_Click(object sender, EventArgs e) { int sum = 0; for (int i = 0; i < dataGridView2.Rows.Count; ++i) { sum += Convert.ToInt32(dataGridView2.Rows[i].Cells[3].Value); } txtSL.Text = sum.ToString(); } private void btnTongdg_Click(object sender, EventArgs e) { int sum = 0; for (int i = 0; i < dataGridView2.Rows.Count; ++i) { sum += Convert.ToInt32(dataGridView2.Rows[i].Cells[4].Value); } txtDG.Text = sum.ToString(); } private void btnTongsosach_Click(object sender, EventArgs e)

{ int i = Convert.ToInt32(dataGridView2.Rows.Count); i = i - 1;//bo dong trong trong datagridview txtTongsach.Text = i.ToString();

private void txtMaNPPS_KeyPress(object sender, KeyPressEventArgs e) { if ((e.KeyChar < '0') || (e.KeyChar > '9')) { e.Handled = true; } } private void txtSoluong_KeyPress(object sender, KeyPressEventArgs e) { if ((e.KeyChar < '0') || (e.KeyChar > '9')) { e.Handled = true; } } private void txtDongia_KeyPress(object sender, KeyPressEventArgs e) { if ((e.KeyChar < '0') || (e.KeyChar > '9')) { e.Handled = true; } } } }

Chn chc nng cp nht sch, form mi hin ra:

Code:

namespace NL2 { public partial class frmNhapSach_Sach : Form { private OleDbConnection con; private OleDbDataAdapter adapter; private string masach, tensach, tacgia, giaban, lanxuatban, cknhap, ckxuat, maloai, manxb; public frmNhapSach_Sach() { InitializeComponent(); con = new OleDbConnection(); ConnectDB conDB = new ConnectDB(); con = conDB.getConn(); con.Open(); } private void populateSach() { try { //int kiemtrarong;

OleDbCommand cmd1 = new OleDbCommand(); cmd1.CommandType = CommandType.Text; cmd1.CommandText = "SELECT * FROM SACH"; cmd1.Connection = con; object result = cmd1.ExecuteScalar(); if (result == null && result == DBNull.Value) { } else { OleDbCommand cmd = new OleDbCommand(); cmd.CommandType = CommandType.Text; cmd.CommandText = "select * from SACH"; cmd.Connection = con; adapter = new OleDbDataAdapter(); adapter.SelectCommand = cmd; adapter.SelectCommand.Connection = con; dataSet1 = new DataSet(); adapter.Fill(dataSet1, "SACH"); DataTable dataTable1 = new DataTable(); dataTable1 = dataSet1.Tables["SACH"]; cbomasach.DataSource = dataTable1; cbomasach.DisplayMember = "MASACH"; txttensach.DataBindings.Clear(); txttensach.DataBindings.Add("Text", dataTable1, "TENSACH"); txttacgia.DataBindings.Clear(); txttacgia.DataBindings.Add("Text", dataTable1, "TACGIA"); txtgiaban.DataBindings.Clear(); txtgiaban.DataBindings.Add("Text", dataTable1, "GIABAN"); txtlanxb.DataBindings.Clear(); txtlanxb.DataBindings.Add("Text", dataTable1, "LANXUATBAN"); txtcknhap.DataBindings.Clear(); txtcknhap.DataBindings.Add("Text", dataTable1, "CHIETKHAUNHAP"); txtckxuat.DataBindings.Clear(); txtckxuat.DataBindings.Add("Text", dataTable1, "CHIETKHAUXUAT"); txtMaLoai.DataBindings.Clear(); txtMaLoai.DataBindings.Add("Text", dataTable1, "MALOAI"); txtMaNXB.DataBindings.Clear(); txtMaNXB.DataBindings.Add("Text", dataTable1, "MANXB"); dgvSach.DataSource = dataTable1; cmd.Dispose();

} } catch (Exception ex) { MessageBox.Show(ex.Message); }

private void populateLoaiSach() { try { OleDbCommand cmd2 = new OleDbCommand(); cmd2.CommandType = CommandType.Text; cmd2.CommandText = "select * from LOAISACH"; cmd2.Connection = con; adapter = new OleDbDataAdapter(); adapter.SelectCommand = cmd2; adapter.SelectCommand.Connection = con; dataSet1 = new DataSet(); adapter.Fill(dataSet1, "LOAISACH"); DataTable dataTable2 = new DataTable(); dataTable2 = dataSet1.Tables["LOAISACH"]; cbomaloai.DataSource = dataTable2;

} catch (Exception ex) { MessageBox.Show(ex.Message); } }

cbomaloai.DisplayMember = "MALOAI"; txttenloai.DataBindings.Clear(); txttenloai.DataBindings.Add("Text", dataTable2, "TENLOAI"); cmd2.Dispose();

private void populatehNXB() { try { OleDbCommand cmd3 = new OleDbCommand(); cmd3.CommandType = CommandType.Text; cmd3.CommandText = "select * from NHAXUATBAN"; cmd3.Connection = con; adapter = new OleDbDataAdapter(); adapter.SelectCommand = cmd3; adapter.SelectCommand.Connection = con; dataSet1 = new DataSet(); adapter.Fill(dataSet1, "NHAXUATBAN"); DataTable dataTable3 = new DataTable(); dataTable3 = dataSet1.Tables["NHAXUATBAN"]; cbomanxb.DataSource = dataTable3; cbomanxb.DisplayMember = "MANXB"; txttennxb.DataBindings.Clear(); txttennxb.DataBindings.Add("Text", dataTable3, "TENNXB"); cmd3.Dispose(); } catch (Exception ex) { MessageBox.Show(ex.Message); } } public void searchRowOfSACH_tensach(string ten_sach) { ten_sach = Convert.ToString(txttensach.Text); ten_sach.ToUpper();//convert to upper try { int kiemtrarong; OleDbCommand cmd1 = new OleDbCommand(); cmd1.CommandType = CommandType.Text; cmd1.CommandText = "SELECT count(*) FROM SACH WHERE TENSACH='" + ten_sach cmd1.Connection = con; kiemtrarong = Convert.ToInt32(cmd1.ExecuteScalar()); cmd1.Dispose(); if (kiemtrarong == 0) { lbtimkhiem2.Text = "(*) khong tim thay " + ten_sach; lbtimkhiem2.Enabled = true; lbtimkhiem2.Visible = true; resetFields2(); } else { //OleDbDataReader reader; OleDbCommand command = new OleDbCommand(); command.CommandType = CommandType.Text; command.CommandText = @"SELECT * FROM SACH WHERE TENSACH='" + ten_sach + "'";

+ "'";

command.Connection = con; adapter = new OleDbDataAdapter(); adapter.SelectCommand = command; adapter.SelectCommand.Connection = con; dataSet1 = new DataSet(); adapter.Fill(dataSet1, "SearchSACH"); DataTable dataTable4 = new DataTable(); dataTable4 = dataSet1.Tables["SearchSACH"]; txttacgia.Text = dataTable4.Rows[0]["TACGIA"].ToString(); txtgiaban.Text = dataTable4.Rows[0]["GIABAN"].ToString(); txtlanxb.Text = dataTable4.Rows[0]["LANXUATBAN"].ToString(); txtcknhap.Text = dataTable4.Rows[0]["CHIETKHAUNHAP"].ToString(); txtckxuat.Text = dataTable4.Rows[0]["CHIETKHAUXUAT"].ToString(); txtMaLoai.Text = dataTable4.Rows[0]["MALOAI"].ToString(); txtMaNXB.Text = dataTable4.Rows[0]["MANXB"].ToString(); command.Dispose(); lbtimkhiem2.Text = "Da tim duoc"; lbtimkhiem2.Enabled = true; lbtimkhiem2.Visible = true; } } catch (Exception ex) { MessageBox.Show(ex.Message); } } public void resetFields2() { txttacgia.Text = null; txtgiaban.Text = null; txtlanxb.Text = null; txtcknhap.Text = null; txtckxuat.Text = null; txttenloai.Text = null; txttennxb.Text = null; } private void NhapSach_Sach_Load(object sender, EventArgs e) { populateSach(); populatehNXB(); populateLoaiSach(); } private string Masach { get { return masach; } set { masach = value; } } private string Tensach { get { return tensach; } set { tensach = value; } }

private string Tacgia { get { return tacgia; } set { tacgia = value; } } private string Giaban { get { return giaban; } set { giaban = value; } } private string Lanxb { get { return lanxuatban; } set { lanxuatban = value; } } private string Cknhap { get { return cknhap; } set { cknhap = value; } } private string Ckxuat { get { return ckxuat; } set { ckxuat = value; } } private string Maloai { get { return maloai; } set { maloai = value; } }

private string Manxb { get { return manxb; } set { manxb = value; } } private void cbomasach_SelectedIndexChanged(object sender, EventArgs e) { this.Masach = Convert.ToString(cbomasach.Text); lbtimkhiem2.Enabled = false; lbtimkhiem2.Visible = false; } private void txttensach_TextChanged(object sender, EventArgs e) { this.Tensach = txttensach.Text; } private void txttacgia_TextChanged(object sender, EventArgs e) { this.Tacgia = txttacgia.Text; } private void txtgiaban_TextChanged(object sender, EventArgs e) { this.Giaban = txtgiaban.Text; } private void txtlanxb_TextChanged(object sender, EventArgs e) { this.Lanxb = txtlanxb.Text; } private void txtcknhap_TextChanged(object sender, EventArgs e) { this.Cknhap = txtcknhap.Text; } private void txtckxuat_TextChanged(object sender, EventArgs e) { this.Ckxuat = txtckxuat.Text; } private void cbomaloai_SelectedIndexChanged(object sender, EventArgs e) { } private void cbomanxb_SelectedIndexChanged(object sender, EventArgs e) { } //private void btnTimKiem_Click(object sender, EventArgs e) //{ // if (txttensach.Text == null) // { // lbtimkhiem2.Text = "Chua nhap ten sach"; // lbtimkhiem2.Enabled = true; // lbtimkhiem2.Visible = true; // } // else

// // // // //}

{ //goi ham tim kiem searchRowOfSACH_tensach(txttensach.Text); }

private void txtMaLoai_TextChanged(object sender, EventArgs e) { this.Maloai = txtMaLoai.Text; } private void txtMaNXB_TextChanged(object sender, EventArgs e) { this.Manxb = txtMaNXB.Text; } //private void btnthem_Click(object sender, EventArgs e) //{ // //public void insertTableSach(string tensach, string tacgia, // //decimal giaban, int lanxb, double cknhap, double ckxuat, int maloai, int

manxb)

// try // { // Sach s = new Sach(); // s.insertTableSach(this.Tensach.ToString(), this.Tacgia.ToString(), decimal.Parse(this.Giaban), int.Parse(this.Lanxb), double.Parse(this.Cknhap), double.Parse(this.Ckxuat), int.Parse(this.Maloai), int.Parse(this.Manxb)); // lbtimkhiem2.Text = "Da cap nhat"; // lbtimkhiem2.Enabled = true; // lbtimkhiem2.Visible = true; // } // catch (Exception ex) // { // MessageBox.Show(ex.Message); // } //} private void btnsua_Click(object sender, EventArgs e) { //public void updateRowOfSACH(int masach, string tensach, string tacgia, //decimal giaban, int lanxb, double cknhap, double ckxuat, int maloai, int manxb) try {

Sach s = new Sach(); int temp; temp = int.Parse(this.Masach); s.updateRowOfSACH(temp, this.Tensach.ToString(), this.Tacgia.ToString(), decimal.Parse(this.Giaban), int.Parse(this.Lanxb), double.Parse(this.Cknhap), double.Parse(this.Ckxuat), int.Parse(this.Maloai), int.Parse(this.Manxb)); lbtimkhiem2.Text = "Da cap nhat"; lbtimkhiem2.Enabled = true; lbtimkhiem2.Visible = true; } catch (Exception ex) { MessageBox.Show(ex.Message+" Khong chap nhan rong."); } } private void btnxoa_Click(object sender, EventArgs e) { try { this.Masach = Convert.ToString(cbomasach.Text); Sach ktra = new Sach();

if (ktra.checkXoasach(int.Parse(this.Masach.ToString()))) { DialogResult result; result = MessageBox.Show("Co chac ban muon xoa?", "Thong bao", MessageBoxButtons.YesNoCancel); if (result == DialogResult.No) { } else if (result == DialogResult.Yes) { // public void deleteRowOfSACH(int masach) int temp; temp = int.Parse(this.Masach); Sach s = new Sach(); s.deleteRowOfSACH(temp); MessageBox.Show("Da xoa", "Thong bao"); } else { } } else { MessageBox.Show("Con can thong tin sach nay, chua xoa duoc!"); } } catch (Exception ex) { MessageBox.Show(ex.Message + " Khong chap nhan rong."); } } private void btnthoat_Click(object sender, EventArgs e) { con.Close(); this.Close(); } private void txttacgia_KeyPress(object sender, KeyPressEventArgs e) { if ((e.KeyChar >= '0') && (e.KeyChar <= '9')) { e.Handled = true; } } private void txtgiaban_KeyPress(object sender, KeyPressEventArgs e) { if ((e.KeyChar < '0') || (e.KeyChar > '9')) { e.Handled = true; } } private void txtlanxb_KeyPress(object sender, KeyPressEventArgs e) { if ((e.KeyChar < '0') || (e.KeyChar > '9')) { e.Handled = true; } } private void txtMaLoai_KeyPress(object sender, KeyPressEventArgs e) { if ((e.KeyChar < '0') || (e.KeyChar > '9')) { e.Handled = true; }

} private void txtMaNXB_KeyPress(object sender, KeyPressEventArgs e) { if ((e.KeyChar < '0') || (e.KeyChar > '9')) { e.Handled = true; } } private void txtckxuat_KeyPress(object sender, KeyPressEventArgs e) { if ((e.KeyChar < '0') || (e.KeyChar > '9')) { e.Handled = true; } if ((e.KeyChar == '.')) { e.Handled = false; } } private void txtcknhap_KeyPress(object sender, KeyPressEventArgs e) { if ((e.KeyChar < '0') || (e.KeyChar > '9')) { e.Handled = true; } if ((e.KeyChar == '.')) { e.Handled = false; } } } }

Chn chc nng cp nht loi sch, form mi hin ra:

Code:

namespace NL2 { public partial class frmNhapSach_LoaiSach : Form { private OleDbConnection con; private OleDbDataAdapter adapter; private string maloai, tenloai; public frmNhapSach_LoaiSach() { InitializeComponent(); con = new OleDbConnection(); ConnectDB conDB = new ConnectDB(); con = conDB.getConn(); con.Open(); } private void populateLOAISACH() { try { //int kiemtrarong; OleDbCommand cmd1 = new OleDbCommand(); cmd1.CommandType = CommandType.Text; cmd1.CommandText = "SELECT * FROM LOAISACH"; cmd1.Connection = con; object result = cmd1.ExecuteScalar(); if (result == null && result == DBNull.Value) { } else {

OleDbCommand cmd = new OleDbCommand(); cmd.CommandType = CommandType.Text; cmd.CommandText = "select * from LOAISACH"; cmd.Connection = con;

} } catch (Exception ex) { MessageBox.Show(ex.Message); }

adapter = new OleDbDataAdapter(); adapter.SelectCommand = cmd; adapter.SelectCommand.Connection = con; dataSet1 = new DataSet(); adapter.Fill(dataSet1, "LOAISACH"); DataTable dataTable1 = new DataTable(); dataTable1 = dataSet1.Tables["LOAISACH"]; cboMaLoai.DataSource = dataTable1; cboMaLoai.DisplayMember = "MALOAI"; txttenloai.DataBindings.Clear(); txttenloai.DataBindings.Add("Text", dataTable1, "TENLOAI"); dgvLoaisach.DataSource = dataTable1;

public void searchRowOfLOAISACH_tenloai(string ten_loai) { ten_loai = Convert.ToString(txttenloai.Text); ten_loai.ToUpper();//convert to upper try { int kiemtrarong; OleDbCommand cmd1 = new OleDbCommand(); cmd1.CommandType = CommandType.Text; cmd1.CommandText = "SELECT count(*) FROM LOAISACH WHERE TENLOAI='" + ten_loai + "'"; cmd1.Connection = con; kiemtrarong = Convert.ToInt32(cmd1.ExecuteScalar()); cmd1.Dispose(); if (kiemtrarong == 0) { lbThongbao.Text = "(*) khong tim thay " + ten_loai; lbThongbao.Enabled = true; lbThongbao.Visible = true; //resetFields2(); } else { //OleDbDataReader reader; OleDbCommand command = new OleDbCommand(); command.CommandType = CommandType.Text; command.CommandText = @"SELECT * FROM LOAISACH WHERE TENLOAI='" + ten_loai + "'"; command.Connection = con; adapter = new OleDbDataAdapter(); adapter.SelectCommand = command; adapter.SelectCommand.Connection = con; dataSet1 = new DataSet(); adapter.Fill(dataSet1, "SearchTENLOAI"); DataTable dataTable2 = new DataTable(); dataTable2 = dataSet1.Tables["SearchTENLOAI"]; command.Dispose(); lbThongbao.Text = "Da tim duoc"; lbThongbao.Enabled = false; lbThongbao.Visible = false; } } catch (Exception ex) { MessageBox.Show(ex.Message); }

} private void NhapSach_LoaiSach_Load(object sender, EventArgs e) { populateLOAISACH(); } private string Maloai { get { return maloai; } set { maloai = value; } } private string Tenloai { get { return tenloai; } set { tenloai = value; } } private void cboMaLoai_SelectedIndexChanged(object sender, EventArgs e) { this.Maloai = Convert.ToString(cboMaLoai.Text); lbThongbao.Enabled = false; lbThongbao.Visible = false; } private void txttenloai_TextChanged(object sender, EventArgs e) { this.Tenloai = txttenloai.Text; } //private void btnTimKiem_Click(object sender, EventArgs e) //{ // if (txttenloai.Text == null) // { // lbThongbao.Text = "Chua nhap ten loai"; // lbThongbao.Enabled = false; // lbThongbao.Visible = false; // } // else // { // //Goi ham tim kiem // searchRowOfLOAISACH_tenloai(txttenloai.Text); // } //} private void btnThem_Click(object sender, EventArgs e) { this.Tenloai = txttenloai.Text; try { Sach ktraLoaisach = new Sach(); if (ktraLoaisach.checkTenLoaiSach(this.Tenloai.ToString())) {

} else { }

NhapSach ns = new NhapSach(); ns.insertTableLoaiSach(this.Tenloai.ToString()); lbThongbao.Text = "Da cap nhat"; txttenloai.Text = null; lbThongbao.Enabled = true; lbThongbao.Visible = true;

MessageBox.Show("Ten loai sach nay da ton tai");

} catch (Exception ex) { MessageBox.Show(ex.Message + " Khong chap nhan rong."); }

private void btnSua_Click(object sender, EventArgs e) { //public void updateRowOfLOAISACH(int maloai, string tenloai) try { int temp; temp=int.Parse(this.Maloai); NhapSach ns = new NhapSach(); ns.updateRowOfLOAISACH(temp,this.Tenloai); lbThongbao.Text = "Da cap nhat"; lbThongbao.Enabled = true; lbThongbao.Visible = true; } catch(Exception ex) { MessageBox.Show(ex.Message); } } private void btnXoa_Click(object sender, EventArgs e) { // public void deleteRowOfLOAISACH(int maloai) this.Maloai = Convert.ToString(cboMaLoai.Text); try { Sach ktra = new Sach(); if (ktra.checkXoaLoaisach(int.Parse(this.Maloai.ToString()))) { DialogResult result; result = MessageBox.Show("Co chac ban muon xoa?", "Thong bao", MessageBoxButtons.YesNoCancel); if (result == DialogResult.No) { } else if (result == DialogResult.Yes) { //public void deleteRowOfNHAPPS(int manhapps) int temp; temp = int.Parse(this.Maloai); NhapSach ns = new NhapSach(); ns.deleteRowOfLOAISACH(temp); MessageBox.Show("Da xoa", "Thong Bao"); } else { } } else { MessageBox.Show("Thong tin ma loai nay con can thiet, chua xoa duoc");

} } catch(Exception ex) { MessageBox.Show(ex.Message); }

private void btnThoat_Click(object sender, EventArgs e) { con.Close(); this.Close(); } public void resetField() { txttenloai.Text = null; }

} }

Chn chc nng cp nht nh phn phi sch, form mi hin ra:

Code:
namespace NL2 { public partial class frmNhapSach_NPPS : Form { private OleDbConnection con; private OleDbDataAdapter adapter; private int insert_manpps; private string tennpps, diachi, nguoidaidien, dienthoai, fax, mobile, email, masothue; private string manpps; public frmNhapSach_NPPS() { InitializeComponent(); con = new OleDbConnection(); ConnectDB conDB = new ConnectDB(); con = conDB.getConn(); con.Open(); } private void populateNPPS() { try { //int kiemtrarong; OleDbCommand cmd1 = new OleDbCommand();

cmd1.CommandType = CommandType.Text; cmd1.CommandText = "SELECT * FROM NHAPPS"; cmd1.Connection = con; object result = cmd1.ExecuteScalar(); if (result == null && result == DBNull.Value) { } //else //{ // masach = 0; //} //kiemtrarong = Convert.ToInt32(cmd1.ExecuteScalar()); //cmd1.Dispose(); //if (kiemtrarong == 0) //{ //} else {

} } catch (Exception ex) { MessageBox.Show(ex.Message); }

OleDbCommand cmd = new OleDbCommand(); cmd.CommandType = CommandType.Text; cmd.CommandText = "select * from NHAPPS"; cmd.Connection = con; adapter = new OleDbDataAdapter(); adapter.SelectCommand = cmd; adapter.SelectCommand.Connection = con; //adapter.TableMappings.Add("Table", "NHAPPS"); //OleDbCommandBuilder cb = new OleDbCommandBuilder(adapter); dataSet1 = new DataSet(); adapter.Fill(dataSet1, "NHAPPS"); DataTable dataTable1 = new DataTable(); dataTable1 = dataSet1.Tables["NHAPPS"]; cbomanpps.DataSource = dataTable1; cbomanpps.DisplayMember = "MANPPS"; txttennpps.DataBindings.Clear(); txttennpps.DataBindings.Add("Text", dataTable1, "TENNPPS"); txtdiachi.DataBindings.Clear(); txtdiachi.DataBindings.Add("Text", dataTable1, "DIACHI"); txtnguoidaidien.DataBindings.Clear(); txtnguoidaidien.DataBindings.Add("Text", dataTable1, "NGUOIDAIDIEN"); txtdienthoai.DataBindings.Clear(); txtdienthoai.DataBindings.Add("Text", dataTable1, "DIENTHOAI"); txtFax.DataBindings.Clear(); txtFax.DataBindings.Add("Text", dataTable1, "FAX"); txtmobile.DataBindings.Clear(); txtmobile.DataBindings.Add("Text", dataTable1, "MOBILE"); txtemail.DataBindings.Clear(); txtemail.DataBindings.Add("Text", dataTable1, "EMAIL"); txtmasothue.DataBindings.Clear(); txtmasothue.DataBindings.Add("Text", dataTable1, "MASOTHUE"); dgvNPPS.DataSource = dataTable1;

public void searchRowOfNHAPPS_tennpps(string tennhapps) { tennhapps = Convert.ToString(txttennpps.Text); tennhapps.ToUpper();//convert to upper try {

tennhapps + "'";

int kiemtrarong; OleDbCommand cmd1 = new OleDbCommand(); cmd1.CommandType = CommandType.Text; cmd1.CommandText = "SELECT count(*) FROM NHAPPS WHERE TENNPPS='" + cmd1.Connection = con; kiemtrarong = Convert.ToInt32(cmd1.ExecuteScalar()); cmd1.Dispose(); if (kiemtrarong == 0) { lbTimKiem.Text = "(*) khong tim thay " + tennhapps; lbTimKiem.Enabled = true; lbTimKiem.Visible = true; resetFields2(); } else { //OleDbDataReader reader; OleDbCommand command = new OleDbCommand(); command.CommandType = CommandType.Text; command.CommandText = @"SELECT * FROM NHAPPS WHERE TENNPPS='" +

tennhapps + "'";

} } catch (Exception ex) { MessageBox.Show(ex.Message); }

command.Connection = con; adapter = new OleDbDataAdapter(); adapter.SelectCommand = command; adapter.SelectCommand.Connection = con; dataSet1 = new DataSet(); adapter.Fill(dataSet1, "SearchNHAPPS"); DataTable dataTable2 = new DataTable(); dataTable2 = dataSet1.Tables["SearchNHAPPS"]; txtdiachi.Text = dataTable2.Rows[0]["DIACHI"].ToString(); txtnguoidaidien.Text = dataTable2.Rows[0]["NGUOIDAIDIEN"].ToString(); txtdienthoai.Text = dataTable2.Rows[0]["DIENTHOAI"].ToString(); txtFax.Text = dataTable2.Rows[0]["FAX"].ToString(); txtmobile.Text = dataTable2.Rows[0]["MOBILE"].ToString(); txtemail.Text = dataTable2.Rows[0]["EMAIL"].ToString(); txtmasothue.Text = dataTable2.Rows[0]["MASOTHUE"].ToString(); command.Dispose(); lbTimKiem.Enabled = false; lbTimKiem.Visible = false;

private void frmNhapSach_NPPS_Load(object sender, EventArgs e) { populateNPPS(); } //private void btntimkiem1_Click(object sender, EventArgs e) //{ // if (txttennpps.Text == null) // { // lbTimKiem.Text = "Chua nhap ten nha phan phoi"; // lbTimKiem.Enabled = true; // lbTimKiem.Visible = true; // } // else // { // searchRowOfNHAPPS_tennpps(txttennpps.Text); // } //}

//private void cbomanpps_SelectedIndexChanged(object sender, EventArgs e) //{ // try // { // this.Manpps = Convert.ToInt32(cbomanpps.SelectedItem.ToString()); // } // catch (Exception ex) // { // MessageBox.Show(ex.Message); // } //} private void btnThoat1_Click(object sender, EventArgs e) { con.Close(); this.Close(); } private void txttennpps_TextChanged(object sender, EventArgs e) { this.Tennpps = txttennpps.Text; } private void txtdiachi_TextChanged(object sender, EventArgs e) { this.Diachi = txtdiachi.Text; } private void txtnguoidaidien_TextChanged(object sender, EventArgs e) { this.Nguoidaidien = txtnguoidaidien.Text; } private void txtdienthoai_TextChanged(object sender, EventArgs e) { this.Dienthoai = txtdienthoai.Text; } private void txtFax_TextChanged(object sender, EventArgs e) { this.Fax = txtFax.Text; } private void txtmobile_TextChanged(object sender, EventArgs e) { this.Mobile = txtmobile.Text; } private void txtemail_TextChanged(object sender, EventArgs e) { this.Email = txtemail.Text; } private void txtmasothue_TextChanged(object sender, EventArgs e) { this.Masothue = txtmasothue.Text; } private string Manpps { get { return manpps; } set

{ } manpps = value; } private int Insert_Manpps { get { return insert_manpps; } set { insert_manpps = value; } } private string Tennpps { get { return tennpps; } set { tennpps = value; } } private string Diachi { get { return diachi; } set { diachi = value; } } private string Nguoidaidien { get { return nguoidaidien; } set { nguoidaidien = value; } } private string Dienthoai { get { return dienthoai; } set { dienthoai = value; } } private string Fax { get { return fax; } set

{ } fax = value; } private string Mobile { get { return mobile; } set { mobile = value; } } private string Email { get { return email; } set { email = value; } } private string Masothue { get { return masothue; } set { masothue = value; } } private void btnThem1_Click(object sender, EventArgs e) { //public void insertTableNHAPPS(string tennhapps, string diachi, string nguoidaidien, //string dienthoai, string fax, string mobile, string email, string masothue) try { NhapSach ns = new NhapSach(); ns.insertTableNHAPPS(this.Tennpps.ToString(), this.Diachi.ToString(), this.Nguoidaidien.ToString(), this.Dienthoai.ToString(), this.Fax.ToString(), this.Mobile.ToString(), this.Email.ToString(), this.Masothue.ToString()); //MessageBox.Show("Da them."); //resetFields(); lbTimKiem.Text = "Da cap nhat"; lbTimKiem.Enabled = true; lbTimKiem.Visible = true; } catch (Exception ex) { MessageBox.Show(ex.Message+" Khong chap nhan rong."); } } private void btnSua1_Click(object sender, EventArgs e) { //public void updateRowOfNHAPPS(int manpps, string tennpps, string diachi, string nguoidaidien, //string dienthoai, string fax, string mobile, string email, string masothue)

NhapSach ns = new NhapSach(); int temp; temp = int.Parse(this.Manpps); ns.updateRowOfNHAPPS(temp, this.Tennpps, this.Diachi, this.Nguoidaidien, this.Dienthoai, this.Fax, this.Mobile, this.Email, this.Masothue); lbTimKiem.Text = "Da cap nhat"; lbTimKiem.Enabled = true; lbTimKiem.Visible = true; } catch (Exception ex) { MessageBox.Show(ex.Message+" Khong chap nhan rong."); } } private void btnXoa1_Click(object sender, EventArgs e) { this.Manpps = Convert.ToString(cbomanpps.Text); try { int temp; temp = int.Parse(this.Manpps); NhapSach ktra = new NhapSach(); if (ktra.checkXoaNPPS(temp)) { DialogResult result; result = MessageBox.Show("Co chac ban muon xoa?", "Thong bao", MessageBoxButtons.YesNoCancel); if (result == DialogResult.No) { } else if (result == DialogResult.Yes) { //public void deleteRowOfNHAPPS(int manhapps) NhapSach ns = new NhapSach(); ns.deleteRowOfNHAPPS(temp); MessageBox.Show("Da xoa", "Thong Bao"); } else { } } else { MessageBox.Show("Khong xoa duoc khi cac phieu nhap con can thong tin", "Thong bao", MessageBoxButtons.OK); } } catch (Exception ex) { MessageBox.Show(ex.Message); } } public void resetFields() { txttennpps.Text = null; txtdiachi.Text = null; txtnguoidaidien.Text = null; txtdienthoai.Text = null; txtFax.Text = null; txtmobile.Text = null; txtemail.Text = null; txtmasothue.Text = null; }

try {

public void resetFields2() { txtdiachi.Text = null; txtnguoidaidien.Text = null; txtdienthoai.Text = null; txtFax.Text = null; txtmobile.Text = null; txtemail.Text = null; txtmasothue.Text = null; } private void cbomanpps_SelectedIndexChanged(object sender, EventArgs e) { this.Manpps = Convert.ToString(cbomanpps.Text); lbTimKiem.Enabled = false; lbTimKiem.Visible = false; } private void txtnguoidaidien_KeyPress(object sender, KeyPressEventArgs e) { if ((e.KeyChar >= '0') && (e.KeyChar <= '9')) { e.Handled = true; } } private void txtdienthoai_KeyPress(object sender, KeyPressEventArgs e) { if ((e.KeyChar < '0') || (e.KeyChar > '9')) { e.Handled = true; } if ((e.KeyChar == '.')) { e.Handled = false; } if ((e.KeyChar == '-')) { e.Handled = false; } if ((e.KeyChar == '(')) { e.Handled = false; } if ((e.KeyChar == ')')) { e.Handled = false; } } private void txtFax_KeyPress(object sender, KeyPressEventArgs e) { if ((e.KeyChar < '0') || (e.KeyChar > '9')) { e.Handled = true; } if ((e.KeyChar == '.')) { e.Handled = false; } if ((e.KeyChar == '-')) { e.Handled = false; } if ((e.KeyChar == '(')) {

e.Handled = false; } if ((e.KeyChar == ')')) { e.Handled = false; }

private void txtmobile_KeyPress(object sender, KeyPressEventArgs e) { if ((e.KeyChar < '0') || (e.KeyChar > '9')) { e.Handled = true; } if ((e.KeyChar == '.')) { e.Handled = false; } if ((e.KeyChar == '-')) { e.Handled = false; } if ((e.KeyChar == '(')) { e.Handled = false; } if ((e.KeyChar == ')')) { e.Handled = false; } } } }

Chn chc nng cp nht nh xut bn, form mi hin ra:

Code:
namespace NL2 { public partial class frmNhapSach_NXB : Form { private OleDbConnection con; private OleDbDataAdapter adapter; private string manxb, tennxb; public frmNhapSach_NXB() { InitializeComponent(); con = new OleDbConnection(); ConnectDB conDB = new ConnectDB(); con = conDB.getConn(); con.Open(); } private void populateNXB() { try { //int kiemtrarong; OleDbCommand cmd1 = new OleDbCommand(); cmd1.CommandType = CommandType.Text; cmd1.CommandText = "SELECT * FROM NHAXUATBAN"; cmd1.Connection = con; object result = cmd1.ExecuteScalar(); if (result == null && result == DBNull.Value) { } else { OleDbCommand cmd = new OleDbCommand(); cmd.CommandType = CommandType.Text; cmd.CommandText = "select * from NHAXUATBAN"; cmd.Connection = con; adapter = new OleDbDataAdapter(); adapter.SelectCommand = cmd;

} } catch (Exception ex) { MessageBox.Show(ex.Message); }

adapter.SelectCommand.Connection = con; dataSet1 = new DataSet(); adapter.Fill(dataSet1, "NXB"); DataTable dataTable1 = new DataTable(); dataTable1 = dataSet1.Tables["NXB"]; cboManxb.DataSource = dataTable1; cboManxb.DisplayMember = "MANXB"; txtTennxb.DataBindings.Clear(); txtTennxb.DataBindings.Add("Text", dataTable1, "TENNXB"); dgvNXB.DataSource = dataTable1;

public void searchRowOfNXB_tennxb(string ten_nxb) { ten_nxb = Convert.ToString(txtTennxb.Text); ten_nxb.ToUpper();//convert to upper try { int kiemtrarong; OleDbCommand cmd1 = new OleDbCommand(); cmd1.CommandType = CommandType.Text; cmd1.CommandText = "SELECT count(*) FROM NHAXUATBAN WHERE TENNXB='" + ten_nxb + "'"; cmd1.Connection = con; kiemtrarong = Convert.ToInt32(cmd1.ExecuteScalar()); cmd1.Dispose(); if (kiemtrarong == 0) { lbThongbao.Text = "(*) khong tim thay " + ten_nxb; lbThongbao.Enabled = true; lbThongbao.Visible = true; //resetFields2(); } else { //OleDbDataReader reader; OleDbCommand command = new OleDbCommand(); command.CommandType = CommandType.Text; command.CommandText = @"SELECT * FROM NHAXUATBAN WHERE TENNXB='" + ten_nxb + "'"; command.Connection = con; adapter = new OleDbDataAdapter(); adapter.SelectCommand = command; adapter.SelectCommand.Connection = con; dataSet1 = new DataSet(); adapter.Fill(dataSet1, "SearchTENNXB"); DataTable dataTable2 = new DataTable(); dataTable2 = dataSet1.Tables["SearchTENNXB"]; command.Dispose(); lbThongbao.Text = "Da tim duoc"; lbThongbao.Enabled = true; lbThongbao.Visible = true; } } catch (Exception ex) { MessageBox.Show(ex.Message); } }

private void NhapSach_NXB_Load(object sender, EventArgs e) { populateNXB(); } private string Manxb { get { return manxb; } set { manxb = value; } } private string Tennxb { get { return tennxb; } set { tennxb = value; } } private void cboManxb_SelectedIndexChanged(object sender, EventArgs e) { this.Manxb = Convert.ToString(cboManxb.Text); lbThongbao.Enabled = false; lbThongbao.Visible = false; } private void txtTennxb_TextChanged(object sender, EventArgs e) { this.Tennxb = txtTennxb.Text; } private void btnTimkiem_Click(object sender, EventArgs e) { if (txtTennxb.Text == null) { lbThongbao.Text = "Chua nhap ten loai"; lbThongbao.Enabled = false; lbThongbao.Visible = false; } else { //Goi ham tim kiem searchRowOfNXB_tennxb(txtTennxb.Text); } } private void btnThem_Click(object sender, EventArgs e) { //public void insertTableNXB(string tenNXB) try { NhapSach ns = new NhapSach(); ns.insertTableNXB(this.Tennxb.ToString()); lbThongbao.Text = "Da cap nhat"; lbThongbao.Enabled = true; lbThongbao.Visible = true; } catch (Exception ex)

{ } } private void btnSua_Click(object sender, EventArgs e) { //public void updateRowOfNXB(int manxb, string tennxb) try { int temp; temp = int.Parse(this.Manxb); NhapSach ns = new NhapSach(); ns.updateRowOfNXB(temp, this.Tennxb); lbThongbao.Text = "Da cap nhat"; lbThongbao.Enabled = true; lbThongbao.Visible = true; } catch (Exception ex) { MessageBox.Show(ex.Message); } } private void btnXoa_Click(object sender, EventArgs e) { this.Manxb = Convert.ToString(cboManxb.Text); //public void deleteRowOfNXB(int manxb) try { int temp; temp = int.Parse(this.Manxb); NhapSach ktranxb = new NhapSach(); if (ktranxb.checkXoaNXB(temp)) { DialogResult result; result = MessageBox.Show("Co chac ban muon xoa?", "Thong bao", MessageBoxButtons.YesNoCancel); if (result == DialogResult.No) { } else if (result == DialogResult.Yes) { //public void deleteRowOfNHAPPS(int manhapps) NhapSach ns = new NhapSach(); ns.deleteRowOfNXB(temp); MessageBox.Show("Da xoa", "Thong Bao"); } else { } } else { MessageBox.Show("Thong tin NXB dang can cho thong tin mot so quyen sach", "Thong bao", MessageBoxButtons.OK); } } catch (Exception ex) { MessageBox.Show(ex.Message); } } private void btnThoat_Click(object sender, EventArgs e) { con.Close(); this.Close(); MessageBox.Show(ex.Message);

} public void resetField() { txtTennxb.Text = null; }

} }

Chn chc nng cp nht kho, form mi hin ra:

Code:

namespace NL2 {

public partial class frmNhapSach_KhoSach : Form { private OleDbConnection con; private OleDbDataAdapter adapter; private string makho, tenkho, soluongtoida; BindingSource khosachBindingSource = new BindingSource(); BindingSource tonkhoBindingSource = new BindingSource(); BindingSource sachBindingSource = new BindingSource(); public frmNhapSach_KhoSach() { InitializeComponent(); con = new OleDbConnection(); ConnectDB conDB = new ConnectDB(); con = conDB.getConn(); con.Open(); } private void frmNhapSach_KhoSach_Load(object sender, EventArgs e) { //populateKHOSACH(); GetData(); } private void GetData() { try { // Specify a connection string. Replace the given value with a // valid connection string for a Northwind SQL Server sample // database accessible to your system. // Create a DataSet. DataSet data = new DataSet(); data.Locale = System.Globalization.CultureInfo.InvariantCulture; // Add data from the Customers table to the DataSet. OleDbDataAdapter khosachDataAdapter = new OleDbDataAdapter("select * from KHOSACH", con); khosachDataAdapter.Fill(data, "KHOSACH"); // Add data from the Orders table to the DataSet. OleDbDataAdapter tonkhoDataAdapter = new OleDbDataAdapter("select * from TON_KHO", con); tonkhoDataAdapter.Fill(data, "TON_KHO"); // Establish a relationship between the two tables: PHIEUNHAP ANd NHAP_SACH DataRelation relation = new DataRelation("KhosachTonkho", data.Tables["KHOSACH"].Columns["MAKHO"], data.Tables["TON_KHO"].Columns["MAKHO"], false); data.Relations.Add(relation); // Add data from the SACH table to the DataSet. OleDbDataAdapter sachDataadapter = new OleDbDataAdapter("select * from SACH", con); sachDataadapter.Fill(data, "SACH"); //DataRow drow = data.Tables["SACH"].NewRow(); //drow["TENSACH"] = "tensach".ToString(); //data.Tables["SACH"].Rows.Add(drow); // Establish a relationship between the two tables: NHAP_SACH and SACH DataRelation relation2 = new DataRelation("TonkhoSach", data.Tables["TON_KHO"].Columns["MASACH"], data.Tables["SACH"].Columns["MASACH"], false);

data.Relations.Add(relation2); // Bind the master data connector to the Customers table. khosachBindingSource.DataSource = data; khosachBindingSource.DataMember = "KHOSACH"; // Bind the details data connector to the master data connector, // using the DataRelation name to filter the information in the // details table based on the current row in the master table. tonkhoBindingSource.DataSource = khosachBindingSource; tonkhoBindingSource.DataMember = "KhosachTonkho"; // Bind data sachBindingSource.DataSource = tonkhoBindingSource; sachBindingSource.DataMember = "TonkhoSach"; cboMakho.DataSource = khosachBindingSource; cboMakho.DisplayMember = "MAKHO"; txtTenkho.DataBindings.Clear(); txtTenkho.DataBindings.Add("Text", khosachBindingSource, "TENKHO"); txtSoluong.DataBindings.Clear(); txtSoluong.DataBindings.Add("Text", khosachBindingSource, dgvTonkho.DataSource = tonkhoBindingSource; dgvSachtonkho.DataSource = sachBindingSource;

"SOLUONGTOIDA");

} catch (Exception ex) { MessageBox.Show(ex.Message); } }

private void populateKHOSACH() { try { //int kiemtrarong; OleDbCommand cmd1 = new OleDbCommand(); cmd1.CommandType = CommandType.Text; cmd1.CommandText = "SELECT * FROM KHOSACH"; cmd1.Connection = con; object result = cmd1.ExecuteScalar(); if (result == null && result == DBNull.Value) { } else { OleDbCommand cmd = new OleDbCommand(); cmd.CommandType = CommandType.Text; cmd.CommandText = "select * from KHOSACH"; cmd.Connection = con; adapter = new OleDbDataAdapter(); adapter.SelectCommand = cmd; adapter.SelectCommand.Connection = con; dataSet1 = new DataSet(); adapter.Fill(dataSet1, "KHOSACH"); DataTable dataTable1 = new DataTable(); dataTable1 = dataSet1.Tables["KHOSACH"]; cboMakho.DataSource = dataTable1; cboMakho.DisplayMember = "MAKHO"; cboMakho.ValueMember = "MAKHO"; txtTenkho.DataBindings.Clear(); txtTenkho.DataBindings.Add("Text", dataTable1, "TENKHO"); txtSoluong.DataBindings.Clear();

txtSoluong.DataBindings.Add("Text", dataTable1, "SOLUONGTOIDA"); } cmd1.Dispose(); } catch (Exception ex) { MessageBox.Show(ex.Message); }

public void searchRowOfKHOSACH_tenkho(string ten_kho) { ten_kho = Convert.ToString(txtTenkho.Text); ten_kho.ToUpper();//convert to upper try { int kiemtrarong; OleDbCommand cmd1 = new OleDbCommand(); cmd1.CommandType = CommandType.Text; cmd1.CommandText = "SELECT count(*) FROM KHOSACH WHERE TENKHO='" + ten_kho + "'"; cmd1.Connection = con; kiemtrarong = Convert.ToInt32(cmd1.ExecuteScalar()); cmd1.Dispose(); if (kiemtrarong == 0) { lbThongbao.Text = "(*) khong tim thay " + ten_kho; lbThongbao.Enabled = true; lbThongbao.Visible = true; resetFields2(); } else { //OleDbDataReader reader; OleDbCommand command = new OleDbCommand(); command.CommandType = CommandType.Text; command.CommandText = @"SELECT * FROM KHOSACH WHERE TENKHO='" + ten_kho + "'"; command.Connection = con; adapter = new OleDbDataAdapter(); adapter.SelectCommand = command; adapter.SelectCommand.Connection = con; dataSet1 = new DataSet(); adapter.Fill(dataSet1, "SearchKHOSACH"); DataTable dataTable4 = new DataTable(); dataTable4 = dataSet1.Tables["SearchKHOSACH"]; txtSoluong.Text = dataTable4.Rows[0]["SOLUONGTOIDA"].ToString(); txtSoluong.Text = dataTable4.Rows[0]["SOLUONGTOIDA"].ToString(); command.Dispose(); lbThongbao.Text = "Da tim duoc"; lbThongbao.Enabled = true; lbThongbao.Visible = true; } } catch (Exception ex) { MessageBox.Show(ex.Message); } } public void resetFields2() { txtSoluong.Text = null; } private string Makho

{ get { } set { } } private string Tenkho { get { return tenkho; } set { tenkho = value; } } private string Soluongtoida { get { return soluongtoida; } set { soluongtoida = value; } } private void cboMakho_SelectedIndexChanged(object sender, EventArgs e) { lbThongbao.Enabled = false; lbThongbao.Visible = false; this.Makho = Convert.ToString(cboMakho.Text); } private void txtTenkho_TextChanged(object sender, EventArgs e) { this.Tenkho = txtTenkho.Text; } private void txtSoluong_TextChanged(object sender, EventArgs e) { this.Soluongtoida = txtSoluong.Text; } //private void btnTimkiem_Click(object sender, EventArgs e) //{ // searchRowOfKHOSACH_tenkho(this.Tenkho); //} private void btnThem_Click(object sender, EventArgs e) { try { KhoSach ks = new KhoSach(); ks.insertTableKhoSach(this.Tenkho, int.Parse(this.Soluongtoida.ToString())); lbThongbao.Text = "Da cap nhat"; lbThongbao.Enabled = true; return makho;

makho = value;

lbThongbao.Visible = true; } catch (Exception ex) { MessageBox.Show(ex.Message); }

private void btnSua_Click(object sender, EventArgs e) { try { int temp1, temp2; temp1 = int.Parse(this.Makho.ToString()); temp2=int.Parse(this.Soluongtoida.ToString()); KhoSach ktra = new KhoSach(); if (ktra.CheckSoluongKhisua(temp2, temp1)) { KhoSach ks = new KhoSach(); ks.updateRowOfKHOSACH(int.Parse(this.Makho.ToString()), this.Tenkho, int.Parse(this.Soluongtoida.ToString())); lbThongbao.Text = "Da cap nhat"; lbThongbao.Visible = true; lbThongbao.Enabled = true; } else { MessageBox.Show("Tong so luong ton trong kho dang vuot qua " + temp2, "Thong bao", MessageBoxButtons.OK); } } catch (Exception ex) { MessageBox.Show(ex.Message); } } private void btnXoa_Click(object sender, EventArgs e) { this.Makho = Convert.ToString(cboMakho.Text); try { int temp; temp = int.Parse(this.Makho); KhoSach ktra = new KhoSach(); if (ktra.CheckKhotrongTonkho(temp)) { DialogResult result; result = MessageBox.Show("Co chac ban muon xoa?", "Thong bao", MessageBoxButtons.YesNoCancel); if (result == DialogResult.No) { } else if (result == DialogResult.Yes) { //public void deleteRowOfNHAPPS(int manhapps) KhoSach ks = new KhoSach(); ks.deleteRowOfKHOSACH(temp); MessageBox.Show("Da xoa", "Thong Bao"); } else { } } else { MessageBox.Show("Thong tin kho van con su dung trong 'ton kho'", "Thong bao", MessageBoxButtons.OK);

} } catch (Exception ex) { MessageBox.Show(ex.Message); }

private void btnThoat_Click(object sender, EventArgs e) { con.Close(); this.Close(); } private void btnTinhtong_Click(object sender, EventArgs e) { lbSLuong.Enabled = true; lbSLuong.Visible = true; int sum = 0; for (int i = 0; i < dgvTonkho.Rows.Count; ++i) { sum += Convert.ToInt32(dgvTonkho.Rows[i].Cells[3].Value); } lbSLuong.Text = sum.ToString(); } private void txtSoluong_KeyPress(object sender, KeyPressEventArgs e) { if ((e.KeyChar < '0') || (e.KeyChar > '9')) { e.Handled = true; } } } }

Nt bn sch c nhn:

Chn mc bn sch v nhn nt thc hin, ca s lp ha n:

Sau khi lp ha n bn, cho nhp thng tin cc sch bn, mi ln nhp nhn vo nt thm vo Hn, cho php tnh tin:

Sau khi nt tnh tin c nhn:

Nhn nt kt thc, cc ca s t gi s bin mt. nhn nt xut ha n bn th ha n bn s xut ra thng qua report!

Chn mc cp nht ha n bn v nhn nt thc hin, form mi hin ra:

Code:
namespace NL2 { public partial class frm_BanSach_HoaDonBan : Form { private OleDbConnection con; private OleDbDataAdapter adapter; private string tensach, dongiaban; public frm_BanSach_HoaDonBan() { InitializeComponent(); con = new OleDbConnection(); ConnectDB conDB = new ConnectDB(); con = conDB.getConn(); con.Open(); } private string Tensach { get { return tensach; } set { tensach = value; } } private string Dgiaban { get { return dongiaban; } set { dongiaban = value; } } private void BanSach_HoaDonBan_Load(object sender, EventArgs e) {

NhapTenSach(); } private void txtTensachBan_TextChanged(object sender, EventArgs e) { this.Tensach = txtTensachBan.Text; } private void txtDGiaBan_TextChanged(object sender, EventArgs e) { this.Dgiaban = txtDGiaBan.Text; } public void getVariables() { this.Tensach = txtTensachBan.Text; this.Dgiaban = txtDGiaBan.Text; } private void NhapTenSach() { int id; OleDbConnection con = new OleDbConnection(); ConnectDB conDB = new ConnectDB(); con = conDB.getConn(); con.Open(); string ma_id = "SELECT MAX(ID) FROM BAN_SACH"; OleDbCommand cmdma_id = new OleDbCommand(ma_id, con); object result = cmdma_id.ExecuteScalar(); if (result != null && result != DBNull.Value) { id = Convert.ToInt32(result); } else { id = 0; } cmdma_id.Dispose(); OleDbCommand cmd = new OleDbCommand(); cmd.Connection = con; cmd.CommandType = CommandType.Text; cmd.CommandText = @"select TENSACH from SACH, BAN_SACH WHERE SACH.MASACH=BAN_SACH.MASACH AND BAN_SACH.ID="+id+""; adapter = new OleDbDataAdapter(); adapter.SelectCommand = cmd; adapter.SelectCommand.Connection = con; dataSet1 = new DataSet(); adapter.Fill(dataSet1, "SACH"); DataTable dataTableSACH = new DataTable(); dataTableSACH = dataSet1.Tables["SACH"]; // namesCollection.Add(dataTableSACH.Rows[i]["TENSACH"].ToString()); txtTensachBan.DataBindings.Clear(); txtTensachBan.DataBindings.Add("Text", dataTableSACH, "TENSACH"); } //private void NhapTenSach() //{ // //thu: good // //+ " order by MASACH asc // AutoCompleteStringCollection namesCollection = new AutoCompleteStringCollection(); // OleDbCommand cmd = new OleDbCommand(); // cmd.Connection = con; // cmd.CommandType = CommandType.Text;

// // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // //}

cmd.CommandText = "select * from SACH"; adapter = new OleDbDataAdapter(); adapter.SelectCommand = cmd; adapter.SelectCommand.Connection = con; dataSet1 = new DataSet(); adapter.Fill(dataSet1, "SACH"); DataTable dataTableSACH = new DataTable(); dataTableSACH = dataSet1.Tables["SACH"]; //DataColumn co; //co = dataTableSACH.Columns["TENSACH"]; int i; for (i = 0; i < dataTableSACH.Rows.Count; i++) { namesCollection.Add(dataTableSACH.Rows[i]["TENSACH"].ToString()); } //cmd.CommandText = "Select TENSACH from SACH"; //OleDbDataReader re = cmd.ExecuteReader(); //if (re.HasRows == true) //{ // while (re.Read()) // namesCollection.Add(re["TENSACH"].ToString()); //} //else //{ // MessageBox.Show("Data not found"); //} //re.Close(); txtTensachBan.AutoCompleteMode = AutoCompleteMode.Suggest; txtTensachBan.AutoCompleteSource = AutoCompleteSource.CustomSource; txtTensachBan.AutoCompleteCustomSource = namesCollection; txtTensachBan.DataBindings.Clear(); txtTensachBan.DataBindings.Add("Text", dataTableSACH, "TENSACH");

public void resetFieldsBanSach() { txtTensachBan.Text = null; txtDGiaBan.Text = null; } private void button1_Click(object sender, EventArgs e) { getVariables(); try { Sach ktra = new Sach(); if (ktra.checkTenSach(this.Tensach.ToString())) { BanSach capnhat = new BanSach(); //capnhat.updateTableBan_Sach_dg(this.Tensach.ToString(), decimal.Parse(this.Dgiaban.ToString())); capnhat.updateTableBan_Sach_dg(decimal.Parse(this.Dgiaban.ToString()) ); lbThongBao.Text = "Da cap nhat"; lbThongBao.Enabled = true; lbThongBao.Visible = true; } else { } } resetFieldsBanSach();

MessageBox.Show("Khong co sach nay");

catch (Exception ex) { MessageBox.Show(ex.Message + " Khong chap nhan rong."); }

private void btnThoat_Click(object sender, EventArgs e) { con.Close(); this.Close(); } private void txtSLuongBan_KeyPress(object sender, KeyPressEventArgs e) { if ((e.KeyChar < '0') || (e.KeyChar > '9')) { e.Handled = true; } } private void txtDGiaBan_KeyPress(object sender, KeyPressEventArgs e) { if ((e.KeyChar < '0') || (e.KeyChar > '9')) { e.Handled = true; } } } }

Chn mc cp nht thng tin khch hng v nhn nt thc hin, form mi hin ra:

Code:
namespace NL2 { public partial class frm_BanSach_TTKhachHang : Form { private OleDbConnection con; private OleDbDataAdapter adapter; private string tenkh, diachi, nguoidaidien, dienthoai, fax, mobile, email, masothue; private string makh; public frm_BanSach_TTKhachHang() { InitializeComponent(); con = new OleDbConnection(); ConnectDB conDB = new ConnectDB(); con = conDB.getConn(); con.Open(); } private string Tenkh { get { return tenkh; } set { tenkh = value; }

} private string Diachi { get { return diachi; } set { diachi = value; } } private string Nguoidaidien { get { return nguoidaidien; } set { nguoidaidien = value; } } private string Dienthoai { get { return dienthoai; } set { dienthoai = value; } } private string Fax { get { return fax; } set { fax = value; } } private string Mobile { get { return mobile; } set { mobile = value; } } private string Email { get {

return email; } set { } }

email = value;

private string Masothue { get { return masothue; } set { masothue = value; } } private string Makh { get { return makh; } set { makh = value; } } private void populateKH() { try { //int kiemtrarong; OleDbCommand cmd1 = new OleDbCommand(); cmd1.CommandType = CommandType.Text; cmd1.CommandText = "SELECT * FROM KHACHHANG"; cmd1.Connection = con; object result = cmd1.ExecuteScalar(); if (result == null && result == DBNull.Value) { } else {

OleDbCommand cmd = new OleDbCommand(); cmd.CommandType = CommandType.Text; cmd.CommandText = "select * from KHACHHANG"; cmd.Connection = con; adapter = new OleDbDataAdapter(); adapter.SelectCommand = cmd; adapter.SelectCommand.Connection = con; dataSet1 = new DataSet(); adapter.Fill(dataSet1, "KHACHHANG"); DataTable dataTablekh = new DataTable(); dataTablekh = dataSet1.Tables["KHACHHANG"]; cboMaKH.DataSource = dataTablekh; cboMaKH.DisplayMember = "MAKH"; cboMaKH.ValueMember = "MAKH"; txtTenKH.DataBindings.Clear(); txtTenKH.DataBindings.Add("Text", dataTablekh, "TENKH"); txtDiaChi.DataBindings.Clear(); txtDiaChi.DataBindings.Add("Text", dataTablekh, "DIACHI");

"NGUOIDAIDIEN");

txtNguoiDaiDien.DataBindings.Clear(); txtNguoiDaiDien.DataBindings.Add("Text", dataTablekh, txtEmail.DataBindings.Clear(); txtEmail.DataBindings.Add("Text", dataTablekh, "EMAIL"); txtFax.DataBindings.Clear(); txtFax.DataBindings.Add("Text", dataTablekh, "FAX"); txtMobile.DataBindings.Clear(); txtMobile.DataBindings.Add("Text", dataTablekh, "MOBILE"); txtDienThoai.DataBindings.Clear(); txtDienThoai.DataBindings.Add("Text", dataTablekh, "DIENTHOAI"); txtMasothue.DataBindings.Clear(); txtMasothue.DataBindings.Add("Text", dataTablekh, "MASOTHUE"); dgvTTKhachHang.DataSource = dataTablekh;

} } catch (Exception ex) { MessageBox.Show(ex.Message); }

private void BanSach_TTKhachHang_Load(object sender, EventArgs e) { populateKH(); } private void btnThem_Click(object sender, EventArgs e) { getVariable1(); try { KhachHang themkh = new KhachHang(); themkh.insertTableKHACHHANG(this.Tenkh.ToString(), this.Diachi.ToString(), this.Nguoidaidien.ToString(), this.Dienthoai.ToString(), this.Fax.ToString(), this.Mobile.ToString(), this.Email.ToString(), this.Masothue.ToString()); lbThongBao.Text = "Da them"; lbThongBao.Visible = true; lbThongBao.Enabled = true; } catch (Exception ex) { MessageBox.Show(ex.Message + " Khong chap nhan rong."); } } public void getVariable() { this.Makh = Convert.ToString(cboMaKH.Text); this.Tenkh = txtTenKH.Text; this.Diachi = txtDiaChi.Text; this.Nguoidaidien = txtNguoiDaiDien.Text; this.Email = txtEmail.Text; this.Masothue = txtMasothue.Text; this.Dienthoai = txtDienThoai.Text; this.Fax = txtFax.Text; this.Mobile = txtMobile.Text; } public void getVariable1() { this.Tenkh = txtTenKH.Text; this.Diachi = txtDiaChi.Text; this.Nguoidaidien = txtNguoiDaiDien.Text; this.Email = txtEmail.Text;

this.Masothue = txtMasothue.Text; this.Dienthoai = txtDienThoai.Text; this.Fax = txtFax.Text; this.Mobile = txtMobile.Text;

private void cboMaKH_SelectedIndexChanged(object sender, EventArgs e) { this.Makh = Convert.ToString(cboMaKH.Text); lbThongBao.Visible = false; lbThongBao.Enabled = false; } private void txtTenKH_TextChanged(object sender, EventArgs e) { this.Tenkh = txtTenKH.Text; } private void txtDiaChi_TextChanged(object sender, EventArgs e) { this.Diachi = txtDiaChi.Text; } private void txtNguoiDaiDien_TextChanged(object sender, EventArgs e) { this.Nguoidaidien = txtNguoiDaiDien.Text; } private void txtEmail_TextChanged(object sender, EventArgs e) { this.Email = txtEmail.Text; } private void txtMasothue_TextChanged(object sender, EventArgs e) { this.Masothue = txtMasothue.Text; } private void txtDienThoai_TextChanged(object sender, EventArgs e) { this.Dienthoai = txtDienThoai.Text; } private void txtFax_TextChanged(object sender, EventArgs e) { this.Fax = txtFax.Text; } private void txtMobile_TextChanged(object sender, EventArgs e) { this.Mobile = txtMobile.Text; } private void button2_Click(object sender, EventArgs e) { getVariable(); try { KhachHang capnhat = new KhachHang(); int temp; temp = int.Parse(this.Makh); capnhat.updateRowOfKHACHHANG(temp, this.Tenkh, this.Diachi, this.Nguoidaidien, this.Dienthoai, this.Fax, this.Mobile, this.Email, this.Masothue); lbThongBao.Text = "Da cap nhat"; lbThongBao.Enabled = true; lbThongBao.Visible = true;

} catch (Exception ex) { MessageBox.Show(ex.Message+" Khong chap nhan rong."); } } private void btnXoa_Click(object sender, EventArgs e) { this.Makh = Convert.ToString(cboMaKH.Text); try { int temp; temp = int.Parse(this.Makh); if (temp == 1) { MessageBox.Show("Khong xoa KHle"); } else { KhachHang ktra = new KhachHang(); if (ktra.checkXoaKHACHHANG(temp)) { DialogResult result; result = MessageBox.Show("Co chac ban muon xoa?", "Thong bao", MessageBoxButtons.YesNoCancel); if (result == DialogResult.No) { } else if (result == DialogResult.Yes) { //public void deleteRowOfNHAPPS(int manhapps) KhachHang xoakh = new KhachHang(); xoakh.deleteRowOfKHACHHANG(temp); MessageBox.Show("Da xoa", "Thong Bao"); } else { } } else { MessageBox.Show("Khong xoa duoc khi thong tin KH con luu trong cac hoa don", "Thong bao", MessageBoxButtons.OK); } } } catch (Exception ex) { MessageBox.Show(ex.Message); } } private void btnThoat_Click(object sender, EventArgs e) { con.Close(); this.Close(); } private void txtDienThoai_KeyPress(object sender, KeyPressEventArgs e) { if ((e.KeyChar < '0') || (e.KeyChar > '9')) { e.Handled = true; } if ((e.KeyChar == '.')) { e.Handled = false;

} if ((e.KeyChar == '-')) { e.Handled = false; } if ((e.KeyChar == '(')) { e.Handled = false; } if ((e.KeyChar == ')')) { e.Handled = false; } } private void txtFax_KeyPress(object sender, KeyPressEventArgs e) { if ((e.KeyChar < '0') || (e.KeyChar > '9')) { e.Handled = true; } if ((e.KeyChar == '.')) { e.Handled = false; } if ((e.KeyChar == '-')) { e.Handled = false; } if ((e.KeyChar == '(')) { e.Handled = false; } if ((e.KeyChar == ')')) { e.Handled = false; } } private void txtMobile_KeyPress(object sender, KeyPressEventArgs e) { if ((e.KeyChar < '0') || (e.KeyChar > '9')) { e.Handled = true; } if ((e.KeyChar == '.')) { e.Handled = false; } if ((e.KeyChar == '-')) { e.Handled = false; } if ((e.KeyChar == '(')) { e.Handled = false; } if ((e.KeyChar == ')')) { e.Handled = false; } } private void txtNguoiDaiDien_KeyPress(object sender, KeyPressEventArgs e) { if ((e.KeyChar >= '0') && (e.KeyChar <= '9'))

{ } } } } e.Handled = true;

Nt xut tr c nhn, form mi hin ra:

Mc cp nht phiu xut tr c chn:

Code:
namespace NL2 { public partial class frm_XuatTraSach : Form { private OleDbConnection con; private OleDbDataAdapter adapter; private string manpps, masach, sluongxuattra, lidoxuattra; private string sophieuxuattra1, manpps1, masach1, sluongxuattra1, lidoxuattra1; private DateTime ngaylappxt, ngaylappxt1; private string tensach; BindingSource masterBindingSource = new BindingSource(); BindingSource detailsBindingSource = new BindingSource(); public frm_XuatTraSach() { InitializeComponent(); con = new OleDbConnection(); ConnectDB conDB = new ConnectDB(); con = conDB.getConn(); con.Open(); } private void frm_XuatTraSach_Load(object sender, EventArgs e) { NhapTenSach(); populateNPPS(); GetData(); } private void GetData()

{ try { // Specify a connection string. Replace the given value with a // valid connection string for a Northwind SQL Server sample // database accessible to your system. // Create a DataSet. DataSet data = new DataSet(); data.Locale = System.Globalization.CultureInfo.InvariantCulture; // Add data from the Phieuxuattra table to the DataSet. OleDbDataAdapter masterDataAdapter = new OleDbDataAdapter("select * from PHIEUXUATTRA", con); masterDataAdapter.Fill(data, "PHIEUXUATTRA"); // Add data from the xuat_tra table to the DataSet. OleDbDataAdapter detailsDataAdapter = new OleDbDataAdapter("select * from XUAT_TRA", con); detailsDataAdapter.Fill(data, "XUAT_TRA"); XUAT_TRA // Establish a relationship between the two tables: PHIEUXUATTRA ANd DataRelation relation = new DataRelation("Phieuxuattra_Xuattra", data.Tables["PHIEUXUATTRA"].Columns["SOPHIEUXUATTRA"], data.Tables["XUAT_TRA"].Columns["SOPHIEUXUATTRA"], false); data.Relations.Add(relation); // Bind the master data connector to the Customers table. masterBindingSource.DataSource = data; masterBindingSource.DataMember = "PHIEUXUATTRA"; // Bind the details data connector to the master data connector, // using the DataRelation name to filter the information in the // details table based on the current row in the master table. detailsBindingSource.DataSource = masterBindingSource; detailsBindingSource.DataMember = "Phieuxuattra_Xuattra"; cboSoPXT1.DataSource = masterBindingSource; cboSoPXT1.DisplayMember = "SOPHIEUXUATTRA"; cboSoPXT1.ValueMember = "SOPHIEUXUATTRA"; dtpNgayLapPXT1.DataBindings.Clear(); dtpNgayLapPXT1.DataBindings.Add("Value", masterBindingSource, "NGAYLAPPXT"); txtManpps1.DataBindings.Clear(); txtManpps1.DataBindings.Add("Text", masterBindingSource, "MANPPS"); cboMaSach1.DataSource = detailsBindingSource; cboMaSach1.DisplayMember = "MASACH"; cboMaSach1.ValueMember = "MASACH"; txtSLuongxuattra1.DataBindings.Clear(); txtSLuongxuattra1.DataBindings.Add("Text", detailsBindingSource, "SLUONGXUATTRA"); txtLidoXT1.DataBindings.Clear(); txtLidoXT1.DataBindings.Add("Text", detailsBindingSource, "LIDOXUATTRA"); dgvPhieuxuattra1.DataSource = masterBindingSource; dgvXuattra1.DataSource = detailsBindingSource; } catch (Exception ex) { MessageBox.Show(ex.Message); } } private void NhapTenSach() { //thu: good

//+ " order by MASACH asc AutoCompleteStringCollection namesCollection = new AutoCompleteStringCollection(); OleDbCommand cmd = new OleDbCommand(); cmd.Connection = con; cmd.CommandType = CommandType.Text; cmd.CommandText = "select * from SACH"; adapter = new OleDbDataAdapter(); adapter.SelectCommand = cmd; adapter.SelectCommand.Connection = con; dataSet1 = new DataSet(); adapter.Fill(dataSet1, "SACH"); DataTable dataTableSACH = new DataTable(); dataTableSACH = dataSet1.Tables["SACH"]; //DataColumn co; //co = dataTableSACH.Columns["TENSACH"]; int i; for (i = 0; i < dataTableSACH.Rows.Count; i++) { namesCollection.Add(dataTableSACH.Rows[i]["TENSACH"].ToString()); } //cmd.CommandText = "Select TENSACH from SACH"; //OleDbDataReader re = cmd.ExecuteReader(); //if (re.HasRows == true) //{ // while (re.Read()) // namesCollection.Add(re["TENSACH"].ToString()); //} //else //{ // MessageBox.Show("Data not found"); //} //re.Close(); txtTenSach.AutoCompleteMode = AutoCompleteMode.Suggest; txtTenSach.AutoCompleteSource = AutoCompleteSource.CustomSource; txtTenSach.AutoCompleteCustomSource = namesCollection; txtTenSach.DataBindings.Clear(); txtTenSach.DataBindings.Add("Text", dataTableSACH, "TENSACH"); //textBox2.DataBindings.Clear(); //textBox2.DataBindings.Add("Text", dataTableSACH, "MASACH");

private DateTime Ngaylappxt { get { return ngaylappxt; } set { ngaylappxt = value; } } private DateTime Ngaylappxt1 { get { return ngaylappxt1; } set { ngaylappxt1 = value; } } private string Tensach

{ get { return tensach; } set { tensach = value; } } private string Manpps { get { return manpps; } set { manpps = value; } } private string Masach { get { return masach; } set { masach = value; } } private string Sluongxuattra { get { return sluongxuattra; } set { sluongxuattra = value; } } private string Lidoxuattra { get { return lidoxuattra; } set { lidoxuattra = value; } } private string Sophieuxuattra1 { get { return sophieuxuattra1; } set { sophieuxuattra1 = value; } } private string Manpps1 { get { return manpps1; } set

{ } } private string Masach1 { get { return masach1; } set { masach1 = value; } } private string Sluongxuattra1 { get { return sluongxuattra1; } set { sluongxuattra1 = value; } } private string Lidoxuattra1 { get { return lidoxuattra1; } set { lidoxuattra1 = value; } } private void btnLapPXT_Click(object sender, EventArgs e) { btnCapnhapPXT.Enabled = true; getVariablesPXT(); int temp; temp = Convert.ToInt32(Login.NoUser.ToString()); try { XuatTra lapPXT = new XuatTra(); lapPXT.insertTablePHIEUXUATTRA(this.Ngaylappxt, temp, int.Parse(this.Manpps.ToString())); lbThongbao.Text = "Da lap phieu nhap"; lbThongbao.Enabled = true; lbThongbao.Visible = true; gbLapPXT.Enabled = false; } catch (Exception ex) { MessageBox.Show(ex.Message + " Khong chap nhan rong."); } manpps1 = value;

private void btnTimMaSach_Click(object sender, EventArgs e) {

TimMaSach(); } private void TimMaSach() { try { //thu: good //+ " order by MASACH asc AutoCompleteStringCollection namesCollection = new AutoCompleteStringCollection(); OleDbCommand cmd = new OleDbCommand(); cmd.Connection = con; cmd.CommandType = CommandType.Text; cmd.CommandText = @"select SACH.MASACH, SACH.TENSACH, NHAP_SACH.SLUONG, NHAP_SACH.DONGIA, NHAPPS.TENNPPS, SACH.TACGIA, SACH.GIABAN, SACH.LANXUATBAN, SACH.CHIETKHAUNHAP, SACH.CHIETKHAUXUAT, SACH.MALOAI, SACH.MANXB from SACH, NHAP_SACH, PHIEUNHAP, NHAPPS WHERE SACH.TENSACH = '" + this.Tensach.ToString() + @"' AND SACH.MASACH=NHAP_SACH.MASACH AND NHAP_SACH.SOPHIEUNHAP=PHIEUNHAP.SOPHIEUNHAP AND PHIEUNHAP.MANPPS=NHAPPS.MANPPS AND NHAPPS.MANPPS="+int.Parse(this.manpps.ToString())+""; adapter = new OleDbDataAdapter(); adapter.SelectCommand = cmd; adapter.SelectCommand.Connection = con; dataSet1 = new DataSet(); adapter.Fill(dataSet1, "MASACH"); DataTable dataTableMASACH = new DataTable(); dataTableMASACH = dataSet1.Tables["MASACH"]; this.cboMaSach.SelectedIndexChanged -= new System.EventHandler(this.cboMaSach_SelectedIndexChanged); cboMaSach.DataSource = dataTableMASACH; cboMaSach.DisplayMember = "MASACH"; cboMaSach.ValueMember = "MASACH"; this.cboMaSach.SelectedIndexChanged -= new System.EventHandler(this.cboMaSach_SelectedIndexChanged); dgvSach.DataSource = dataTableMASACH; } catch (Exception ex) { MessageBox.Show(ex.Message); } } private void populateNPPS() { try { OleDbCommand cmd = new OleDbCommand(); cmd.CommandType = CommandType.Text; cmd.CommandText = "select * from NHAPPS"; cmd.Connection = con; adapter = new OleDbDataAdapter(); adapter.SelectCommand = cmd; adapter.SelectCommand.Connection = con; //adapter.TableMappings.Add("Table", "NHAPPS"); //OleDbCommandBuilder cb = new OleDbCommandBuilder(adapter); dataSet1 = new DataSet(); adapter.Fill(dataSet1, "NHAPPS"); DataTable dataTableNHAPPS = new DataTable(); dataTableNHAPPS = dataSet1.Tables["NHAPPS"]; this.cboNhaPPS.SelectedIndexChanged -= new System.EventHandler(this.cboNhaPPS_SelectedIndexChanged); cboNhaPPS.DataSource = dataTableNHAPPS;

cboNhaPPS.DisplayMember = "TENNPPS"; cboNhaPPS.ValueMember = "MANPPS"; this.cboNhaPPS.SelectedIndexChanged += new System.EventHandler(this.cboNhaPPS_SelectedIndexChanged); tstMaNPPS.DataBindings.Clear(); tstMaNPPS.DataBindings.Add("Text", dataTableNHAPPS, "MANPPS"); } catch (Exception ex) { MessageBox.Show(ex.Message); } } private void dtpNgaylappxt_ValueChanged(object sender, EventArgs e) { this.Ngaylappxt = dtpNgaylappxt.Value.Date; } private void tstMaNPPS_TextChanged(object sender, EventArgs e) { this.Manpps = tstMaNPPS.Text; } private void cboMaSach_SelectedIndexChanged(object sender, EventArgs e) { this.Masach = Convert.ToString(cboMaSach.Text); lbThongbaocapnhat.Enabled = false; lbThongbaocapnhat.Visible = false; } private void txtSLuongXT_TextChanged(object sender, EventArgs e) { this.Sluongxuattra = txtSLuongXT.Text; } private void txtTenSach_TextChanged(object sender, EventArgs e) { this.Tensach = txtTenSach.Text; } private void btnThoat_Click(object sender, EventArgs e) { con.Close(); this.Close(); } private void txtLidoXT_TextChanged(object sender, EventArgs e) { this.Lidoxuattra = txtLidoXT.Text; } private void btnCapnhapPXT_Click(object sender, EventArgs e) { getVariablesXuattra(); try { //XuatTra ktranpps = new XuatTra(); //if (ktranpps.checkMANPPS_masach(int.Parse(this.Masach.ToString()))) //{ XuatTra ktra = new XuatTra(); if (ktra.checkXuattra(int.Parse(this.Masach.ToString()), int.Parse(this.Sluongxuattra.ToString()))) { KhoSach ktraTonkho = new KhoSach();

if (ktraTonkho.checkTON_KHO_khibansach(int.Parse(this.Masach.ToString()), int.Parse(this.Sluongxuattra.ToString()))) { XuatTra themXuattra = new XuatTra(); themXuattra.insertTableXUAT_TRA(int.Parse(this.Masach.ToString()) , int.Parse(this.Sluongxuattra.ToString()), this.Lidoxuattra.ToString()); XuatTra capnhattienthu = new XuatTra(); capnhattienthu.updatePHIEUXUATTRA_Tienthu(int.Parse(this.Masach.T oString()), int.Parse(this.Sluongxuattra.ToString())); KhoSach capnhatTonkho = new KhoSach(); capnhatTonkho.updateRowOfTON_KHO_khibansach(int.Parse(this.Masach .ToString()), int.Parse(this.Sluongxuattra.ToString())); btnTinhTien.Enabled = true; resetCapnhatPXT(); lbThongbaocapnhat.Text = "Da cap nhat"; lbThongbaocapnhat.Visible = true; lbThongbaocapnhat.Enabled = true; } else { int soluongtonkho; KhoSach laySLtong = new KhoSach(); soluongtonkho = laySLtong.laySLTON_KHO(int.Parse(this.Masach.ToString())); MessageBox.Show("Vout qua so luong ton trong kho, hien trong kho dang co " + soluongtonkho.ToString()); } } else {

khac NPPS");

MessageBox.Show("So luong xuat tra vuot qua so luong nhap"); } //} //else //{ // MessageBox.Show("Phieu xuat tra chi lap cho mot nha phan phoi sach, //} } catch (Exception ex) { MessageBox.Show(ex.Message + " Khong chap nhan rong"); }

} private void cboNhaPPS_SelectedIndexChanged(object sender, EventArgs e) { } private void btnKetthuc_Click(object sender, EventArgs e) { btnCapnhapPXT.Enabled = false; btnTinhTien.Enabled = false; gbLapPXT.Enabled = true; lbThongbao.Enabled = false; lbThongbao.Visible = false; } private void getVariablesPXT() { this.Ngaylappxt = dtpNgaylappxt.Value.Date; this.Manpps = tstMaNPPS.Text; }

private void getVariablesXuattra() { this.Masach = Convert.ToString(cboMaSach.Text); this.Sluongxuattra = txtSLuongXT.Text; this.Lidoxuattra = txtLidoXT.Text; } private void btnTinhTien_Click(object sender, EventArgs e) { XuatTra sluog = new XuatTra(); int togslxt; togslxt = sluog.getTongsoluongxuattra(); XuatTra tienthu = new XuatTra(); decimal togtienthu; togtienthu = tienthu.getTongtienthu(); txtTongSLxuattra.Text = togslxt.ToString(); txtTongtienThuvao.Text = togtienthu.ToString(); } public void resetCapnhatPXT() { txtSLuongXT.Text = null ; txtLidoXT.Text = null; } private void btnThoat1_Click(object sender, EventArgs e) { con.Close(); this.Close(); } private void getVariablesPXT_1() { this.Sophieuxuattra1 = Convert.ToString(cboSoPXT1.Text); this.Ngaylappxt1 = dtpNgayLapPXT1.Value.Date; this.Manpps1 = txtManpps1.Text; } private void cboSoPXT1_SelectedIndexChanged(object sender, EventArgs e) { this.Sophieuxuattra1 = Convert.ToString(cboSoPXT1.Text); lbthongbaoPXT1.Visible = false; lbthongbaoPXT1.Enabled = false; } private void dtpNgayLapPXT1_ValueChanged(object sender, EventArgs e) { this.Ngaylappxt1 = dtpNgayLapPXT1.Value.Date; } private void txtManpps1_TextChanged(object sender, EventArgs e) { this.Manpps1 = txtManpps1.Text; } private void btnCapNhatNgayLap_Click(object sender, EventArgs e) { this.Sophieuxuattra1 = Convert.ToString(cboSoPXT1.Text); this.Ngaylappxt1 = dtpNgayLapPXT1.Value.Date; try { XuatTra capnhatNgaylap = new XuatTra(); capnhatNgaylap.updatePHIEUXUATTRA_MgayLappxt(int.Parse(this.Sophieuxuattr a1.ToString()), this.Ngaylappxt1); lbthongbaoPXT1.Text = "Da cap nhat ngay";

} catch (Exception ex) { MessageBox.Show(ex.Message + " Khong chap nhan rong"); } } private void btnCapNhatMaNPPS_Click(object sender, EventArgs e) { this.Sophieuxuattra1 = Convert.ToString(cboSoPXT1.Text); this.Manpps1 = txtManpps1.Text; try { XuatTra ktracapnhatPXT_Manpps = new XuatTra(); if (ktracapnhatPXT_Manpps.checkUpdatePhieuxuattra_MANPPS(int.Parse(this.Sophieuxuattra1.ToSt ring()))) { XuatTra capnhatPXT_manpps = new XuatTra(); capnhatPXT_manpps.updatePHIEUXUATTRA_MANPPS(int.Parse(this.Sophieuxua ttra1.ToString()), int.Parse(this.Manpps1.ToString())); lbthongbaoPXT1.Text = "Da cap nhat ma nha phan phoi sach"; lbthongbaoPXT1.Visible = true; lbthongbaoPXT1.Enabled = true; } else { MessageBox.Show("Khong duoc chinh ma nha phan phoi sach khi da ton tai sach xuat tra tong phieu nay"); } } catch (Exception ex) { MessageBox.Show(ex.Message + " Khong chap nhan rong"); } } private void btnXoa1_Click(object sender, EventArgs e) { this.Sophieuxuattra1 = Convert.ToString(cboSoPXT1.Text); XuatTra ktraxoa = new XuatTra(); try { if (ktraxoa.checkXoaPhieuxuattra(int.Parse(this.Sophieuxuattra1.ToString()))) { DialogResult result; result = MessageBox.Show("Co chac ban muon xoa?", "Thong bao", MessageBoxButtons.YesNoCancel); if (result == DialogResult.No) { } else if (result == DialogResult.Yes) { XuatTra xoaPXT = new XuatTra(); xoaPXT.deleteRowOfPHIEUXUATTRA_XUAT_TRA(int.Parse(this.Sophieuxua ttra1.ToString())); MessageBox.Show("Da xoa", "Thong Bao"); } else { } } else {

lbthongbaoPXT1.Visible = true; lbthongbaoPXT1.Enabled = true;

MessageBox.Show("Khong xoa duoc khi sach chua ban het", "thong bao", MessageBoxButtons.OK); } } catch (Exception ex) { MessageBox.Show(ex.Message); } } private void btnCapnhatXT1_Click(object sender, EventArgs e) { this.Masach1 = Convert.ToString(cboMaSach1.Text); this.Sluongxuattra1 = txtSLuongxuattra1.Text; this.Lidoxuattra1 = txtLidoXT1.Text; this.Sophieuxuattra1 = Convert.ToString(cboSoPXT1.Text); try { XuatTra ktra = new XuatTra(); if (ktra.checkXuattra(int.Parse(this.Masach1.ToString()), int.Parse(this.Sluongxuattra1.ToString()))) { KhoSach ktraTonkho = new KhoSach(); if (ktraTonkho.checkTON_KHO_khibansach(int.Parse(this.Masach1.ToString()), int.Parse(this.Sluongxuattra1.ToString()))) { XuatTra capnhatXuattra = new XuatTra(); capnhatXuattra.updateRowOfXUAT_TRA(int.Parse(this.Sophieuxuattra1 .ToString()), int.Parse(this.Masach1.ToString()), int.Parse(this.Sluongxuattra1.ToString()), this.Lidoxuattra1.ToString()); XuatTra capnhattienthu = new XuatTra(); capnhattienthu.updatePHIEUXUATTRA_Tienthu_sopxt(int.Parse(this.So phieuxuattra1.ToString()), int.Parse(this.Masach1.ToString()), int.Parse(this.Sluongxuattra1.ToString())); KhoSach capnhatTonkho = new KhoSach(); capnhatTonkho.updateRowOfTON_KHO_khibansach(int.Parse(this.Masach 1.ToString()), int.Parse(this.Sluongxuattra1.ToString())); lbThogbaoCapnhatXT1.Text = "Da cap nhat"; lbThogbaoCapnhatXT1.Visible = true; lbThogbaoCapnhatXT1.Enabled = true; } else { int soluongtonkho; KhoSach laySLtong = new KhoSach(); soluongtonkho = laySLtong.laySLTON_KHO(int.Parse(this.Masach1.ToString())); MessageBox.Show("Vout qua so luong ton trong kho, hien trong kho dang co " + soluongtonkho.ToString()); } } else { } MessageBox.Show("So luong xuat tra vuot qua so luong nhap"); } catch (Exception ex) { MessageBox.Show(ex.Message + " Khong chap nhan rong"); }

private void cboMaSach1_SelectedIndexChanged(object sender, EventArgs e) {

this.Masach1 = Convert.ToString(cboMaSach1.Text); lbThogbaoCapnhatXT1.Enabled = false; lbThogbaoCapnhatXT1.Visible = false; } private void txtSLuongxuattra1_TextChanged(object sender, EventArgs e) { this.Sluongxuattra1 = txtSLuongxuattra1.Text; } private void txtLidoXT1_TextChanged(object sender, EventArgs e) { this.Lidoxuattra1 = txtLidoXT1.Text; } private void btnTinhTien1_Click(object sender, EventArgs e) { int togsl; XuatTra laytogsl = new XuatTra(); togsl = laytogsl.getTongsoluongxuattra_sophieuxt(int.Parse(this.Sophieuxuattra1.ToString())); txtTongSLtra1.Text = togsl.ToString(); decimal togtienthu; XuatTra laytogtienthu = new XuatTra(); togtienthu = laytogtienthu.getTongtienthu_sophieuxt(int.Parse(this.Sophieuxuattra1.ToString())); txtTongtienthu1.Text = togtienthu.ToString(); } private void txtSLuongXT_KeyPress(object sender, KeyPressEventArgs e) { if ((e.KeyChar < '0') || (e.KeyChar > '9')) { e.Handled = true; } }

} }

Nt thng k c nhn:

Mc sch nhp c chn:

Mc sch tn kho c chn:

Mc sch xut tr c chn:

Thu tin mt:

Mc chi tin mt v n tn c chn:

Code:
namespace NL2 { public partial class frm_ThongKe : Form { private OleDbConnection con; private OleDbDataAdapter adapter; private string tensach, maloaisach, manxb, makh; private DateTime tungay, denngay; private string manpps_1, cknhap_1, manxb_1; private DateTime tungay_1, denngay_1;

private string maloaisach_2, manxb_2, tensach_2; private DateTime tungay_2, denngay_2; private string manv_4, makh_4; private DateTime tungay_4, denngay_4; private string manpps_5; private string manpps_3; public frm_ThongKe() { InitializeComponent(); con = new OleDbConnection(); ConnectDB conDB = new ConnectDB(); con = conDB.getConn(); con.Open(); dataSet1 = new DataSet(); } private string Manpps_5 { get { return manpps_5; } set { manpps_5 = value; } } private DateTime Tungay_4 { get { return tungay_4; } set { tungay_4 = value; } } private DateTime Denngay_4 { get { return denngay_4; } set { denngay_4 = value; } } private string Makh_4 { get { return makh_4; } set { makh_4 = value; } } private string Manv_4 { get { return manv_4; } set {

manv_4 = value; } }

private string Manpps_3 { get { return manpps_3; } set { manpps_3 = value; } } private DateTime Tungay_2 { get { return tungay_2; } set { tungay_2 = value; } } private DateTime Denngay_2 { get { return denngay_2; } set { denngay_2 = value; } } private string Tensach_2 { get { return tensach_2; } set { tensach_2 = value; } } private string Maloaisach_2 { get { return maloaisach_2; } set { maloaisach_2 = value; } } private string Manxb_2 { get { return manxb_2; } set { manxb_2 = value; } } private DateTime Tungay_1 {

get { return tungay_1; } set { tungay_1 = value; }

private DateTime Denngay_1 { get { return denngay_1; } set { denngay_1 = value; } } private string Manpps_1 { get { return manpps_1; } set { manpps_1 = value; } } private string Cknhap_1 { get { return cknhap_1; } set { cknhap_1 = value; } } private string Manxb_1 { get { return manxb_1; } set { manxb_1 = value; } } private string Tensach { get { return tensach; } set { tensach = value; } } private string Maloaisach { get { return maloaisach; } set { maloaisach = value;

} } private string Manxb { get { return manxb; } set { manxb = value; } } private string Makh { get { return makh; } set { makh = value; } } private DateTime Tungay { get { return tungay; } set { tungay = value; } } private DateTime Denngay { get { return denngay; } set { denngay = value; } } private void rbtnSach_CheckedChanged(object sender, EventArgs e) { this.Validate(); txtTensach.Enabled = true; dtpTuNgay.Enabled = false; dtpDenNgay.Enabled = false; cboMaloaisach.Enabled = false; txtTenloaisach.Enabled = false; cboMaNXB.Enabled = false; txtTenNXB.Enabled = false; cboMaKH.Enabled = false; txtTenKH.Enabled = false; } private void rbtnNgaythang_CheckedChanged(object sender, EventArgs e) { this.Validate(); txtTensach.Enabled = false; dtpTuNgay.Enabled = true; dtpDenNgay.Enabled = true; cboMaloaisach.Enabled = false; txtTenloaisach.Enabled = false; cboMaNXB.Enabled = false;

txtTenNXB.Enabled = false; cboMaKH.Enabled = false; txtTenKH.Enabled = false; } private void rbtnLoaisach_CheckedChanged(object sender, EventArgs e) { this.Validate(); txtTensach.Enabled = false; dtpTuNgay.Enabled = false; dtpDenNgay.Enabled = false; cboMaloaisach.Enabled = true; txtTenloaisach.Enabled = true; cboMaNXB.Enabled = false; txtTenNXB.Enabled = false; cboMaKH.Enabled = false; txtTenKH.Enabled = false; } private void rbtnNhaXB_CheckedChanged(object sender, EventArgs e) { this.Validate(); txtTensach.Enabled = false; dtpTuNgay.Enabled = false; dtpDenNgay.Enabled = false; cboMaloaisach.Enabled = false; txtTenloaisach.Enabled = false; cboMaNXB.Enabled = true; txtTenNXB.Enabled = true; cboMaKH.Enabled = false; txtTenKH.Enabled = false; } private void cboKH_CheckedChanged(object sender, EventArgs e) { this.Validate(); txtTensach.Enabled = false; dtpTuNgay.Enabled = false; dtpDenNgay.Enabled = false; cboMaloaisach.Enabled = false; txtTenloaisach.Enabled = false; cboMaNXB.Enabled = false; txtTenNXB.Enabled = false; cboMaKH.Enabled = true; txtTenKH.Enabled = true; } private void btnThogkeSachban_Click(object sender, EventArgs e) { if (rbtnSach.Checked == true) { this.Tensach = txtTensach.Text; thongke_theoTENSACH(); } else if (rbtnNgaythang.Checked == true) { thongke_theoNGAY(); } else if (rbtnLoaisach.Checked == true) { thongke_theoLOAISACH(); } else if (rbtnNhaXB.Checked == true) { thongke_theoNHAXUATBAN(); } else if (rbtnKH.Checked == true)

{ thongke_theoKHACHHANG(); } else if (rbtnTatca.Checked == true) { thongke_theoTATCA(); } } private void frm_ThongKe_Load(object sender, EventArgs e) { NhapTenSach(); populateLOAISACH(); populateNXB(); populateKHACHHANG(); populateNHAPPS_1(); populateCHIETKHAUNHAP_1(); populateNHANVIEN_4(); //populateNXB_1(); //populateLOAISACH_2(); //populateNXB_2(); } private void populateNHANVIEN_4() { try { OleDbCommand cmd = new OleDbCommand(); cmd.CommandType = CommandType.Text; cmd.CommandText = "select * from NHANVIEN"; cmd.Connection = con; adapter = new OleDbDataAdapter(); adapter.SelectCommand = cmd; adapter.SelectCommand.Connection = con; //adapter.TableMappings.Add("Table", "NHAPPS"); //OleDbCommandBuilder cb = new OleDbCommandBuilder(adapter); dataSet1 = new DataSet(); adapter.Fill(dataSet1, "NHANVIEN"); DataTable dataTableNHANVIEN = new DataTable(); dataTableNHANVIEN = dataSet1.Tables["NHANVIEN"]; this.cboMaNV_4.SelectedIndexChanged -= new System.EventHandler(this.cboMaNV_4_SelectedIndexChanged); cboMaNV_4.DataSource = dataTableNHANVIEN; cboMaNV_4.DisplayMember = "MANV"; cboMaNV_4.ValueMember = "MANV"; this.cboMaNV_4.SelectedIndexChanged += new System.EventHandler(this.cboMaNV_4_SelectedIndexChanged); txtTenNV_4.DataBindings.Clear(); txtTenNV_4.DataBindings.Add("Text", dataTableNHANVIEN, "TENNV"); } catch (Exception ex) { MessageBox.Show(ex.Message); } } //private //{ // try // { // // // // // void populateNXB_2()

OleDbCommand cmd = new OleDbCommand(); cmd.CommandType = CommandType.Text; cmd.CommandText = "select * from NHAXUATBAN"; cmd.Connection = con; adapter = new OleDbDataAdapter();

// adapter.SelectCommand = cmd; // adapter.SelectCommand.Connection = con; // //adapter.TableMappings.Add("Table", "NHAPPS"); // //OleDbCommandBuilder cb = new OleDbCommandBuilder(adapter); // dataSet1 = new DataSet(); // adapter.Fill(dataSet1, "NHAXUATBAN"); // DataTable dataTableNHAXUATBAN = new DataTable(); // dataTableNHAXUATBAN = dataSet1.Tables["NHAXUATBAN"]; // this.cboManxb_2.SelectedIndexChanged -= new System.EventHandler(this.cboManxb_2_SelectedIndexChanged); // cboManxb_2.DataSource = dataTableNHAXUATBAN; // cboManxb_2.DisplayMember = "MANXB"; // cboManxb_2.ValueMember = "MANXB"; // this.cboManxb_2.SelectedIndexChanged += new System.EventHandler(this.cboManxb_2_SelectedIndexChanged); // txtTenNXB_2.DataBindings.Clear(); // txtTenNXB_2.DataBindings.Add("Text", dataTableNHAXUATBAN, "TENNXB"); // } // catch (Exception ex) // { // MessageBox.Show(ex.Message); // } //} //private void populateLOAISACH_2() //{ // try // { // OleDbCommand cmd = new OleDbCommand(); // cmd.CommandType = CommandType.Text; // cmd.CommandText = "select * from LOAISACH"; // cmd.Connection = con; // adapter = new OleDbDataAdapter(); // adapter.SelectCommand = cmd; // adapter.SelectCommand.Connection = con; // //adapter.TableMappings.Add("Table", "NHAPPS"); // //OleDbCommandBuilder cb = new OleDbCommandBuilder(adapter); // dataSet1 = new DataSet(); // adapter.Fill(dataSet1, "LOAISACH"); // DataTable dataTableLOAISACH = new DataTable(); // dataTableLOAISACH = dataSet1.Tables["LOAISACH"]; // this.cboMaloai_2.SelectedIndexChanged -= new System.EventHandler(this.cboMaloai_2_SelectedIndexChanged); // cboMaloai_2.DataSource = dataTableLOAISACH; // cboMaloai_2.DisplayMember = "MALOAI"; // cboMaloai_2.ValueMember = "MALOAI"; // this.cboMaloai_2.SelectedIndexChanged += new System.EventHandler(this.cboMaloai_2_SelectedIndexChanged); // txtTenloai_2.DataBindings.Clear(); // txtTenloai_2.DataBindings.Add("Text", dataTableLOAISACH, "TENLOAI"); // } // catch (Exception ex) // { // MessageBox.Show(ex.Message); // } //} //private //{ // try // { // // // // // void populateNXB_1()

OleDbCommand cmd = new OleDbCommand(); cmd.CommandType = CommandType.Text; cmd.CommandText = "select * from NHAXUATBAN"; cmd.Connection = con; adapter = new OleDbDataAdapter();

// adapter.SelectCommand = cmd; // adapter.SelectCommand.Connection = con; // //adapter.TableMappings.Add("Table", "NHAPPS"); // //OleDbCommandBuilder cb = new OleDbCommandBuilder(adapter); // dataSet1 = new DataSet(); // adapter.Fill(dataSet1, "NHAXUATBAN"); // DataTable dataTableNHAXUATBAN = new DataTable(); // dataTableNHAXUATBAN = dataSet1.Tables["NHAXUATBAN"]; // this.cboMaNXB_1.SelectedIndexChanged -= new System.EventHandler(this.cboMaNXB_1_SelectedIndexChanged); // cboMaNXB_1.DataSource = dataTableNHAXUATBAN; // cboMaNXB_1.DisplayMember = "MANXB"; // cboMaNXB_1.ValueMember = "MANXB"; // this.cboMaNXB_1.SelectedIndexChanged += new System.EventHandler(this.cboMaNXB_1_SelectedIndexChanged); // txtTenNXB_1.DataBindings.Clear(); // txtTenNXB_1.DataBindings.Add("Text", dataTableNHAXUATBAN, "TENNXB"); // } // catch (Exception ex) // { // MessageBox.Show(ex.Message); // } //} private void populateCHIETKHAUNHAP_1() { try { OleDbCommand cmd = new OleDbCommand(); cmd.CommandType = CommandType.Text; cmd.CommandText = "select DISTINCT CHIETKHAUNHAP from SACH"; cmd.Connection = con; adapter = new OleDbDataAdapter(); adapter.SelectCommand = cmd; adapter.SelectCommand.Connection = con; //adapter.TableMappings.Add("Table", "NHAPPS"); //OleDbCommandBuilder cb = new OleDbCommandBuilder(adapter); dataSet1 = new DataSet(); adapter.Fill(dataSet1, "CHIETKHAUNHAP"); DataTable dataTableCHIETKHAUNHAP = new DataTable(); dataTableCHIETKHAUNHAP = dataSet1.Tables["CHIETKHAUNHAP"]; this.cboChietkhaunhap_1.SelectedIndexChanged -= new System.EventHandler(this.cboChietkhaunhap_1_SelectedIndexChanged); cboChietkhaunhap_1.DataSource = dataTableCHIETKHAUNHAP; cboChietkhaunhap_1.DisplayMember = "CHIETKHAUNHAP"; cboChietkhaunhap_1.ValueMember = "CHIETKHAUNHAP"; this.cboChietkhaunhap_1.SelectedIndexChanged += new System.EventHandler(this.cboChietkhaunhap_1_SelectedIndexChanged); } catch (Exception ex) { MessageBox.Show(ex.Message); }

private void populateNHAPPS_1() { try { OleDbCommand cmd = new OleDbCommand(); cmd.CommandType = CommandType.Text; cmd.CommandText = "select * from NHAPPS"; cmd.Connection = con; adapter = new OleDbDataAdapter(); adapter.SelectCommand = cmd;

adapter.SelectCommand.Connection = con; //adapter.TableMappings.Add("Table", "NHAPPS"); //OleDbCommandBuilder cb = new OleDbCommandBuilder(adapter); dataSet1 = new DataSet(); adapter.Fill(dataSet1, "NHAPPS_1"); DataTable dataTableNHAPPS_1 = new DataTable(); dataTableNHAPPS_1 = dataSet1.Tables["NHAPPS_1"]; this.cboMaNPPS_1.SelectedIndexChanged -= new System.EventHandler(this.cboMaNPPS_1_SelectedIndexChanged); cboMaNPPS_1.DataSource = dataTableNHAPPS_1; cboMaNPPS_1.DisplayMember = "MANPPS"; cboMaNPPS_1.ValueMember = "MANPPS"; this.cboMaNPPS_1.SelectedIndexChanged += new System.EventHandler(this.cboMaNPPS_1_SelectedIndexChanged); txtTenNPPS_1.DataBindings.Clear(); txtTenNPPS_1.DataBindings.Add("Text", dataTableNHAPPS_1, "TENNPPS"); this.cboManpps_3.SelectedIndexChanged -= new System.EventHandler(this.cboManpps_3_SelectedIndexChanged); cboManpps_3.DataSource = dataTableNHAPPS_1; cboManpps_3.DisplayMember = "MANPPS"; cboManpps_3.ValueMember = "MANPPS"; this.cboManpps_3.SelectedIndexChanged += new System.EventHandler(this.cboManpps_3_SelectedIndexChanged); txtTennpps_3.DataBindings.Clear(); txtTennpps_3.DataBindings.Add("Text", dataTableNHAPPS_1, "TENNPPS"); this.cboManpps_5.SelectedIndexChanged -= new System.EventHandler(this.cboManpps_5_SelectedIndexChanged); cboManpps_5.DataSource = dataTableNHAPPS_1; cboManpps_5.DisplayMember = "MANPPS"; cboManpps_5.ValueMember = "MANPPS"; this.cboManpps_5.SelectedIndexChanged += new System.EventHandler(this.cboManpps_5_SelectedIndexChanged); txtTennpps_5.DataBindings.Clear(); txtTennpps_5.DataBindings.Add("Text", dataTableNHAPPS_1, "TENNPPS"); } catch (Exception ex) { MessageBox.Show(ex.Message); } } private void thongke_theoTATCA() { try { string str_dgvSach = @"SELECT SACH.MASACH, SACH.TENSACH, BAN_SACH.SLUONGBAN, BAN_SACH.DGIABAN, BAN_SACH.SOHOADON, LOAISACH.TENLOAI, NHAXUATBAN.TENNXB FROM SACH, BAN_SACH, LOAISACH, NHAXUATBAN, HOADONBAN, KHACHHANG WHERE SACH.MASACH=BAN_SACH.MASACH AND SACH.MALOAI=LOAISACH.MALOAI AND SACH.MANXB=NHAXUATBAN.MANXB AND HOADONBAN.SOHOADON=BAN_SACH.SOHOADON AND KHACHHANG.MAKH=HOADONBAN.MAKH"; OleDbCommand cmddgvSach = new OleDbCommand(str_dgvSach, con); adapter = new OleDbDataAdapter(); adapter.SelectCommand = cmddgvSach; adapter.SelectCommand.Connection = con; dataSet1 = new DataSet(); DataTable datatabledgvSach = new DataTable(); adapter.Fill(dataSet1, "dgvSach"); datatabledgvSach = dataSet1.Tables["dgvSach"]; DataRow dr = datatabledgvSach.NewRow(); dr["TENSACH"] = "Tong cong".ToString(); dr["SLUONGBAN"] = dataSet1.Tables["dgvSach"].Compute("Sum(SLUONGBAN)", null);

dr["DGIABAN"] = dataSet1.Tables["dgvSach"].Compute("Sum(DGIABAN)", null); datatabledgvSach.Rows.Add(dr); dgvSach.RowsDefaultCellStyle.BackColor = Color.WhiteSmoke; dgvSach.AlternatingRowsDefaultCellStyle.BackColor = Color.White; dgvSach.DataSource = datatabledgvSach; string str_dgvHoadonban = @"SELECT HOADONBAN.LOAIHD, KHACHHANG.TENKH, HOADONBAN.TONGDGIACHUATHUE, HOADONBAN.THANHTIENDATHUE, HOADONBAN.SOHOADON, HOADONBAN.NGAYLAPHD FROM HOADONBAN, SACH, BAN_SACH, KHACHHANG WHERE HOADONBAN.SOHOADON=BAN_SACH.SOHOADON AND BAN_SACH.MASACH=SACH.MASACH AND KHACHHANG.MAKH=HOADONBAN.MAKH"; OleDbCommand cmddgvHoadonban = new OleDbCommand(str_dgvHoadonban, con); adapter = new OleDbDataAdapter(); adapter.SelectCommand = cmddgvHoadonban; adapter.SelectCommand.Connection = con; dataSet1 = new DataSet(); DataTable datatabledgvHoadonban = new DataTable(); adapter.Fill(dataSet1, "dgvHoadonban"); datatabledgvHoadonban = dataSet1.Tables["dgvHoadonban"]; DataRow drdgvHoadonban = datatabledgvHoadonban.NewRow(); drdgvHoadonban["LOAIHD"] = "Tong cong".ToString(); drdgvHoadonban["TONGDGIACHUATHUE"] = dataSet1.Tables["dgvHoadonban"].Compute("Sum(TONGDGIACHUATHUE)", null); drdgvHoadonban["THANHTIENDATHUE"] = dataSet1.Tables["dgvHoadonban"].Compute("Sum(THANHTIENDATHUE)", null); datatabledgvHoadonban.Rows.Add(drdgvHoadonban); dgvHoadonban.RowsDefaultCellStyle.BackColor = Color.WhiteSmoke; dgvHoadonban.AlternatingRowsDefaultCellStyle.BackColor = Color.White; dgvHoadonban.DataSource = datatabledgvHoadonban; } catch (Exception ex) { MessageBox.Show(ex.Message); } } private void thongke_theoKHACHHANG() { this.Makh = Convert.ToString(cboMaKH.Text); try { string str_dgvSach = @"SELECT SACH.MASACH, SACH.TENSACH, BAN_SACH.SLUONGBAN, BAN_SACH.DGIABAN, BAN_SACH.SOHOADON, LOAISACH.TENLOAI, NHAXUATBAN.TENNXB FROM SACH, BAN_SACH, LOAISACH, NHAXUATBAN, HOADONBAN, KHACHHANG WHERE SACH.MASACH=BAN_SACH.MASACH AND SACH.MALOAI=LOAISACH.MALOAI AND SACH.MANXB=NHAXUATBAN.MANXB AND HOADONBAN.SOHOADON=BAN_SACH.SOHOADON AND KHACHHANG.MAKH=HOADONBAN.MAKH AND KHACHHANG.MAKH=" + Int32.Parse(this.Makh.ToString()) + ""; OleDbCommand cmddgvSach = new OleDbCommand(str_dgvSach, con); adapter = new OleDbDataAdapter(); adapter.SelectCommand = cmddgvSach; adapter.SelectCommand.Connection = con; dataSet1 = new DataSet(); DataTable datatabledgvSach = new DataTable(); adapter.Fill(dataSet1, "dgvSach"); datatabledgvSach = dataSet1.Tables["dgvSach"]; DataRow dr = datatabledgvSach.NewRow(); dr["TENSACH"] = "Tong cong".ToString(); dr["SLUONGBAN"] = dataSet1.Tables["dgvSach"].Compute("Sum(SLUONGBAN)", null); dr["DGIABAN"] = dataSet1.Tables["dgvSach"].Compute("Sum(DGIABAN)", null); datatabledgvSach.Rows.Add(dr); dgvSach.RowsDefaultCellStyle.BackColor = Color.WhiteSmoke; dgvSach.AlternatingRowsDefaultCellStyle.BackColor = Color.White; dgvSach.DataSource = datatabledgvSach;

string str_dgvHoadonban = @"SELECT HOADONBAN.LOAIHD, KHACHHANG.TENKH, HOADONBAN.TONGDGIACHUATHUE, HOADONBAN.THANHTIENDATHUE, HOADONBAN.SOHOADON, HOADONBAN.NGAYLAPHD FROM HOADONBAN, SACH, BAN_SACH, KHACHHANG WHERE HOADONBAN.SOHOADON=BAN_SACH.SOHOADON AND BAN_SACH.MASACH=SACH.MASACH AND KHACHHANG.MAKH=HOADONBAN.MAKH AND KHACHHANG.MAKH=" + Int32.Parse(this.Makh.ToString()) + ""; OleDbCommand cmddgvHoadonban = new OleDbCommand(str_dgvHoadonban, con); adapter = new OleDbDataAdapter(); adapter.SelectCommand = cmddgvHoadonban; adapter.SelectCommand.Connection = con; dataSet1 = new DataSet(); DataTable datatabledgvHoadonban = new DataTable(); adapter.Fill(dataSet1, "dgvHoadonban"); datatabledgvHoadonban = dataSet1.Tables["dgvHoadonban"]; DataRow drdgvHoadonban = datatabledgvHoadonban.NewRow(); drdgvHoadonban["LOAIHD"] = "Tong cong".ToString(); drdgvHoadonban["TONGDGIACHUATHUE"] = dataSet1.Tables["dgvHoadonban"].Compute("Sum(TONGDGIACHUATHUE)", null); drdgvHoadonban["THANHTIENDATHUE"] = dataSet1.Tables["dgvHoadonban"].Compute("Sum(THANHTIENDATHUE)", null); datatabledgvHoadonban.Rows.Add(drdgvHoadonban); dgvHoadonban.RowsDefaultCellStyle.BackColor = Color.WhiteSmoke; dgvHoadonban.AlternatingRowsDefaultCellStyle.BackColor = Color.White; dgvHoadonban.DataSource = datatabledgvHoadonban; } catch (Exception ex) { MessageBox.Show(ex.Message); } } private void thongke_theoNHAXUATBAN() { this.Manxb = Convert.ToString(cboMaNXB.Text); try { string str_dgvSach = @"SELECT SACH.MASACH, SACH.TENSACH, BAN_SACH.SLUONGBAN, BAN_SACH.DGIABAN, BAN_SACH.SOHOADON, LOAISACH.TENLOAI, NHAXUATBAN.TENNXB FROM SACH, BAN_SACH, LOAISACH, NHAXUATBAN WHERE SACH.MASACH=BAN_SACH.MASACH AND SACH.MALOAI=LOAISACH.MALOAI AND SACH.MANXB=NHAXUATBAN.MANXB AND NHAXUATBAN.MANXB=" + Int32.Parse(this.Manxb.ToString()) + ""; OleDbCommand cmddgvSach = new OleDbCommand(str_dgvSach, con); adapter = new OleDbDataAdapter(); adapter.SelectCommand = cmddgvSach; adapter.SelectCommand.Connection = con; dataSet1 = new DataSet(); DataTable datatabledgvSach = new DataTable(); adapter.Fill(dataSet1, "dgvSach"); datatabledgvSach = dataSet1.Tables["dgvSach"]; DataRow dr = datatabledgvSach.NewRow(); dr["TENSACH"] = "Tong cong".ToString(); dr["SLUONGBAN"] = dataSet1.Tables["dgvSach"].Compute("Sum(SLUONGBAN)", null); dr["DGIABAN"] = dataSet1.Tables["dgvSach"].Compute("Sum(DGIABAN)", null); datatabledgvSach.Rows.Add(dr); dgvSach.RowsDefaultCellStyle.BackColor = Color.WhiteSmoke; dgvSach.AlternatingRowsDefaultCellStyle.BackColor = Color.White; dgvSach.DataSource = datatabledgvSach; string str_dgvHoadonban = @"SELECT HOADONBAN.LOAIHD, HOADONBAN.TONGDGIACHUATHUE, HOADONBAN.THANHTIENDATHUE,

HOADONBAN.SOHOADON, HOADONBAN.NGAYLAPHD FROM HOADONBAN, SACH, BAN_SACH, NHAXUATBAN WHERE HOADONBAN.SOHOADON=BAN_SACH.SOHOADON AND BAN_SACH.MASACH=SACH.MASACH AND NHAXUATBAN.MANXB=SACH.MANXB AND NHAXUATBAN.MANXB=" + Int32.Parse(this.Manxb.ToString()) + ""; OleDbCommand cmddgvHoadonban = new OleDbCommand(str_dgvHoadonban, con); adapter = new OleDbDataAdapter(); adapter.SelectCommand = cmddgvHoadonban; adapter.SelectCommand.Connection = con; dataSet1 = new DataSet(); DataTable datatabledgvHoadonban = new DataTable(); adapter.Fill(dataSet1, "dgvHoadonban"); datatabledgvHoadonban = dataSet1.Tables["dgvHoadonban"]; DataRow drdgvHoadonban = datatabledgvHoadonban.NewRow(); drdgvHoadonban["LOAIHD"] = "Tong cong".ToString(); drdgvHoadonban["TONGDGIACHUATHUE"] = dataSet1.Tables["dgvHoadonban"].Compute("Sum(TONGDGIACHUATHUE)", null); drdgvHoadonban["THANHTIENDATHUE"] = dataSet1.Tables["dgvHoadonban"].Compute("Sum(THANHTIENDATHUE)", null); datatabledgvHoadonban.Rows.Add(drdgvHoadonban); dgvHoadonban.RowsDefaultCellStyle.BackColor = Color.WhiteSmoke; dgvHoadonban.AlternatingRowsDefaultCellStyle.BackColor = Color.White; dgvHoadonban.DataSource = datatabledgvHoadonban; } catch (Exception ex) { MessageBox.Show(ex.Message); } } private void thongke_theoLOAISACH() { this.Maloaisach = Convert.ToString(cboMaloaisach.Text); try { string str_dgvSach = @"SELECT SACH.MASACH, SACH.TENSACH, BAN_SACH.SLUONGBAN, BAN_SACH.DGIABAN, BAN_SACH.SOHOADON, LOAISACH.TENLOAI, NHAXUATBAN.TENNXB FROM SACH, BAN_SACH, LOAISACH, NHAXUATBAN WHERE SACH.MASACH=BAN_SACH.MASACH AND SACH.MALOAI=LOAISACH.MALOAI AND SACH.MANXB=NHAXUATBAN.MANXB AND LOAISACH.MALOAI=" + Int32.Parse(this.Maloaisach.ToString()) + ""; OleDbCommand cmddgvSach = new OleDbCommand(str_dgvSach, con); adapter = new OleDbDataAdapter(); adapter.SelectCommand = cmddgvSach; adapter.SelectCommand.Connection = con; dataSet1 = new DataSet(); DataTable datatabledgvSach = new DataTable(); adapter.Fill(dataSet1, "dgvSach"); datatabledgvSach = dataSet1.Tables["dgvSach"]; DataRow dr = datatabledgvSach.NewRow(); dr["TENSACH"] = "Tong cong".ToString(); dr["SLUONGBAN"] = dataSet1.Tables["dgvSach"].Compute("Sum(SLUONGBAN)", null); dr["DGIABAN"] = dataSet1.Tables["dgvSach"].Compute("Sum(DGIABAN)", null); datatabledgvSach.Rows.Add(dr); dgvSach.RowsDefaultCellStyle.BackColor = Color.WhiteSmoke; dgvSach.AlternatingRowsDefaultCellStyle.BackColor = Color.White; dgvSach.DataSource = datatabledgvSach; string str_dgvHoadonban = @"SELECT HOADONBAN.LOAIHD, HOADONBAN.TONGDGIACHUATHUE, HOADONBAN.THANHTIENDATHUE, HOADONBAN.SOHOADON, HOADONBAN.NGAYLAPHD FROM HOADONBAN, SACH, BAN_SACH, LOAISACH WHERE HOADONBAN.SOHOADON=BAN_SACH.SOHOADON AND BAN_SACH.MASACH=SACH.MASACH AND LOAISACH.MALOAI=SACH.MALOAI AND LOAISACH.MALOAI=" + Int32.Parse(this.Maloaisach.ToString()) + "";

OleDbCommand cmddgvHoadonban = new OleDbCommand(str_dgvHoadonban, con); adapter = new OleDbDataAdapter(); adapter.SelectCommand = cmddgvHoadonban; adapter.SelectCommand.Connection = con; dataSet1 = new DataSet(); DataTable datatabledgvHoadonban = new DataTable(); adapter.Fill(dataSet1, "dgvHoadonban"); datatabledgvHoadonban = dataSet1.Tables["dgvHoadonban"]; DataRow drdgvHoadonban = datatabledgvHoadonban.NewRow(); drdgvHoadonban["LOAIHD"] = "Tong cong".ToString(); drdgvHoadonban["TONGDGIACHUATHUE"] = dataSet1.Tables["dgvHoadonban"].Compute("Sum(TONGDGIACHUATHUE)", null); drdgvHoadonban["THANHTIENDATHUE"] = dataSet1.Tables["dgvHoadonban"].Compute("Sum(THANHTIENDATHUE)", null); datatabledgvHoadonban.Rows.Add(drdgvHoadonban); dgvHoadonban.RowsDefaultCellStyle.BackColor = Color.WhiteSmoke; dgvHoadonban.AlternatingRowsDefaultCellStyle.BackColor = Color.White; dgvHoadonban.DataSource = datatabledgvHoadonban; } catch (Exception ex) { MessageBox.Show(ex.Message); } } private void thongke_theoNGAY() { try { this.Tungay = this.dtpTuNgay.Value.Date; this.Denngay = this.dtpDenNgay.Value.Date; string str_dgvSach = @"SELECT SACH.MASACH, SACH.TENSACH, BAN_SACH.SLUONGBAN, BAN_SACH.DGIABAN, BAN_SACH.SOHOADON, LOAISACH.TENLOAI, NHAXUATBAN.TENNXB FROM SACH, BAN_SACH, LOAISACH, NHAXUATBAN, HOADONBAN WHERE SACH.MASACH=BAN_SACH.MASACH AND SACH.MALOAI=LOAISACH.MALOAI AND SACH.MANXB=NHAXUATBAN.MANXB AND HOADONBAN.SOHOADON=BAN_SACH.SOHOADON AND (HOADONBAN.NGAYLAPHD BETWEEN #" + this.Tungay + "# AND #" + this.Denngay + "#)"; OleDbCommand cmddgvSach = new OleDbCommand(str_dgvSach, con); adapter = new OleDbDataAdapter(); adapter.SelectCommand = cmddgvSach; adapter.SelectCommand.Connection = con; dataSet1 = new DataSet(); DataTable datatabledgvSach = new DataTable(); adapter.Fill(dataSet1, "dgvSach"); datatabledgvSach = dataSet1.Tables["dgvSach"]; DataRow dr = datatabledgvSach.NewRow(); dr["TENSACH"] = "Tong cong".ToString(); dr["SLUONGBAN"] = dataSet1.Tables["dgvSach"].Compute("Sum(SLUONGBAN)", null); dr["DGIABAN"] = dataSet1.Tables["dgvSach"].Compute("Sum(DGIABAN)", null); datatabledgvSach.Rows.Add(dr); dgvSach.RowsDefaultCellStyle.BackColor = Color.WhiteSmoke; dgvSach.AlternatingRowsDefaultCellStyle.BackColor = Color.White; dgvSach.DataSource = datatabledgvSach; string str_dgvHoadonban = @"SELECT HOADONBAN.LOAIHD, HOADONBAN.TONGDGIACHUATHUE, HOADONBAN.THANHTIENDATHUE, HOADONBAN.SOHOADON, HOADONBAN.NGAYLAPHD FROM HOADONBAN, SACH, BAN_SACH WHERE HOADONBAN.SOHOADON=BAN_SACH.SOHOADON AND BAN_SACH.MASACH=SACH.MASACH AND (HOADONBAN.NGAYLAPHD BETWEEN #" + this.Tungay + "# AND #" + this.Denngay + "#)"; OleDbCommand cmddgvHoadonban = new OleDbCommand(str_dgvHoadonban, con); adapter = new OleDbDataAdapter(); adapter.SelectCommand = cmddgvHoadonban;

adapter.SelectCommand.Connection = con; dataSet1 = new DataSet(); DataTable datatabledgvHoadonban = new DataTable(); adapter.Fill(dataSet1, "dgvHoadonban"); datatabledgvHoadonban = dataSet1.Tables["dgvHoadonban"]; DataRow drdgvHoadonban = datatabledgvHoadonban.NewRow(); drdgvHoadonban["LOAIHD"] = "Tong cong".ToString(); drdgvHoadonban["TONGDGIACHUATHUE"] = dataSet1.Tables["dgvHoadonban"].Compute("Sum(TONGDGIACHUATHUE)", null); drdgvHoadonban["THANHTIENDATHUE"] = dataSet1.Tables["dgvHoadonban"].Compute("Sum(THANHTIENDATHUE)", null); datatabledgvHoadonban.Rows.Add(drdgvHoadonban); dgvHoadonban.RowsDefaultCellStyle.BackColor = Color.WhiteSmoke; dgvHoadonban.AlternatingRowsDefaultCellStyle.BackColor = Color.White; dgvHoadonban.DataSource = datatabledgvHoadonban; } catch (Exception ex) { MessageBox.Show(ex.Message); } } private void timSachban_it() { try { // string str_sachbanit = @"SELECT SACH.TENSACH, SUM(BAN_SACH.SLUONGBAN) AS TONGSLBAN // FROM BAN_SACH, SACH // WHERE BAN_SACH.MASACH=SACH.MASACH // GROUP BY SACH.TENSACH // HAVING SUM(BAN_SACH.SLUONGBAN)=(SELECT MIN(SL) FROM ( // SELECT SUM(BAN_SACH.SLUONGBAN) AS SL FROM BAN_SACH, SACH WHERE BAN_SACH.MASACH=SACH.MASACH GROUP BY SACH.TENSACH))"; string str_sachbanit = @"SELECT * FROM (SELECT SACH.TENSACH, SUM(BAN_SACH.SLUONGBAN) AS TONGSLBAN FROM BAN_SACH, SACH WHERE BAN_SACH.MASACH=SACH.MASACH GROUP BY SACH.TENSACH ORDER BY SUM(BAN_SACH.SLUONGBAN) ASC)"; OleDbCommand cmd_timsachbanit = new OleDbCommand(str_sachbanit, con); adapter = new OleDbDataAdapter(); adapter.SelectCommand = cmd_timsachbanit; adapter.SelectCommand.Connection = con; dataSet1 = new DataSet(); DataTable datatableSachbanit = new DataTable(); adapter.Fill(dataSet1, "Sachbanit"); datatableSachbanit = dataSet1.Tables["Sachbanit"]; //DataRow dr = datatableSachbanit.NewRow(); dgvTimsach.RowsDefaultCellStyle.BackColor = Color.WhiteSmoke; dgvTimsach.AlternatingRowsDefaultCellStyle.BackColor = Color.White; dgvTimsach.DataSource = datatableSachbanit; } catch (Exception ex) { MessageBox.Show(ex.Message); }

private void timSachban_nhieu() { try { // string str_sachbannhieu = @"SELECT SACH.TENSACH, SUM(BAN_SACH.SLUONGBAN) AS TONGSLBAN

// FROM BAN_SACH, SACH // WHERE BAN_SACH.MASACH=SACH.MASACH // GROUP BY SACH.TENSACH // HAVING SUM(BAN_SACH.SLUONGBAN)=(SELECT MAX(SL) FROM ( // SELECT SUM(BAN_SACH.SLUONGBAN) AS SL FROM BAN_SACH, SACH WHERE BAN_SACH.MASACH=SACH.MASACH GROUP BY SACH.TENSACH))"; string str_sachbannhieu = @"SELECT * FROM (SELECT SACH.TENSACH, SUM(BAN_SACH.SLUONGBAN) AS TONGSLBAN FROM BAN_SACH, SACH WHERE BAN_SACH.MASACH=SACH.MASACH GROUP BY SACH.TENSACH ORDER BY SUM(BAN_SACH.SLUONGBAN) DESC)"; OleDbCommand cmd_timsachbannhieu = new OleDbCommand(str_sachbannhieu, adapter = new OleDbDataAdapter(); adapter.SelectCommand = cmd_timsachbannhieu; adapter.SelectCommand.Connection = con; dataSet1 = new DataSet(); DataTable datatableSachbannhieu = new DataTable(); adapter.Fill(dataSet1, "Sachbannhieu"); datatableSachbannhieu = dataSet1.Tables["Sachbannhieu"]; //DataRow dr = datatableSachbanit.NewRow(); dgvTimsach.RowsDefaultCellStyle.BackColor = Color.WhiteSmoke; dgvTimsach.AlternatingRowsDefaultCellStyle.BackColor = Color.White; dgvTimsach.DataSource = datatableSachbannhieu;

con);

} catch (Exception ex) { MessageBox.Show(ex.Message); } }

private void thongke_theoTENSACH() { try { string str_dgvSach = @"SELECT SACH.MASACH, SACH.TENSACH, BAN_SACH.SLUONGBAN, BAN_SACH.DGIABAN, BAN_SACH.SOHOADON, LOAISACH.TENLOAI, NHAXUATBAN.TENNXB FROM SACH, BAN_SACH, LOAISACH, NHAXUATBAN WHERE SACH.MASACH=BAN_SACH.MASACH AND SACH.MALOAI=LOAISACH.MALOAI AND SACH.MANXB=NHAXUATBAN.MANXB AND SACH.TENSACH='" + this.Tensach.ToString() + "'"; OleDbCommand cmddgvSach = new OleDbCommand(str_dgvSach, con); adapter = new OleDbDataAdapter(); adapter.SelectCommand = cmddgvSach; adapter.SelectCommand.Connection = con; dataSet1 = new DataSet(); DataTable datatabledgvSach = new DataTable(); adapter.Fill(dataSet1, "dgvSach"); datatabledgvSach = dataSet1.Tables["dgvSach"]; DataRow dr = datatabledgvSach.NewRow(); dr["TENSACH"] = "Tong cong".ToString(); dr["SLUONGBAN"] = dataSet1.Tables["dgvSach"].Compute("Sum(SLUONGBAN)", null); dr["DGIABAN"] = dataSet1.Tables["dgvSach"].Compute("Sum(DGIABAN)", null); datatabledgvSach.Rows.Add(dr); dgvSach.RowsDefaultCellStyle.BackColor = Color.WhiteSmoke; dgvSach.AlternatingRowsDefaultCellStyle.BackColor = Color.White; dgvSach.DataSource = datatabledgvSach; string str_dgvHoadonban = @"SELECT HOADONBAN.LOAIHD, HOADONBAN.TONGDGIACHUATHUE, HOADONBAN.THANHTIENDATHUE, HOADONBAN.SOHOADON, HOADONBAN.NGAYLAPHD FROM HOADONBAN, SACH, BAN_SACH WHERE HOADONBAN.SOHOADON=BAN_SACH.SOHOADON AND BAN_SACH.MASACH=SACH.MASACH

AND SACH.TENSACH='" + this.Tensach.ToString() + "'"; OleDbCommand cmddgvHoadonban = new OleDbCommand(str_dgvHoadonban, con); adapter = new OleDbDataAdapter(); adapter.SelectCommand = cmddgvHoadonban; adapter.SelectCommand.Connection = con; dataSet1 = new DataSet(); DataTable datatabledgvHoadonban = new DataTable(); adapter.Fill(dataSet1, "dgvHoadonban"); datatabledgvHoadonban = dataSet1.Tables["dgvHoadonban"]; DataRow drdgvHoadonban = datatabledgvHoadonban.NewRow(); drdgvHoadonban["LOAIHD"] = "Tong cong".ToString(); drdgvHoadonban["TONGDGIACHUATHUE"] = dataSet1.Tables["dgvHoadonban"].Compute("Sum(TONGDGIACHUATHUE)", null); drdgvHoadonban["THANHTIENDATHUE"] = dataSet1.Tables["dgvHoadonban"].Compute("Sum(THANHTIENDATHUE)", null); datatabledgvHoadonban.Rows.Add(drdgvHoadonban); dgvHoadonban.RowsDefaultCellStyle.BackColor = Color.WhiteSmoke; dgvHoadonban.AlternatingRowsDefaultCellStyle.BackColor = Color.White; dgvHoadonban.DataSource = datatabledgvHoadonban; } catch (Exception ex) { MessageBox.Show(ex.Message); } } private void populateKHACHHANG() { try { OleDbCommand cmd = new OleDbCommand(); cmd.CommandType = CommandType.Text; cmd.CommandText = "select * from KHACHHANG"; cmd.Connection = con; adapter = new OleDbDataAdapter(); adapter.SelectCommand = cmd; adapter.SelectCommand.Connection = con; //adapter.TableMappings.Add("Table", "NHAPPS"); //OleDbCommandBuilder cb = new OleDbCommandBuilder(adapter); dataSet1 = new DataSet(); adapter.Fill(dataSet1, "KHACHHANG"); DataTable dataTableKHACHHANG = new DataTable(); dataTableKHACHHANG = dataSet1.Tables["KHACHHANG"]; this.cboMaKH.SelectedIndexChanged -= new System.EventHandler(this.cboMaKH_SelectedIndexChanged); cboMaKH.DataSource = dataTableKHACHHANG; cboMaKH.DisplayMember = "MAKH"; cboMaKH.ValueMember = "MAKH"; this.cboMaKH.SelectedIndexChanged += new System.EventHandler(this.cboMaKH_SelectedIndexChanged); txtTenKH.DataBindings.Clear(); txtTenKH.DataBindings.Add("Text", dataTableKHACHHANG, "TENKH"); this.cboMaKH_4.SelectedIndexChanged -= new System.EventHandler(this.cboMaKH_4_SelectedIndexChanged); cboMaKH_4.DataSource = dataTableKHACHHANG; cboMaKH_4.DisplayMember = "MAKH"; cboMaKH_4.ValueMember = "MAKH"; this.cboMaKH_4.SelectedIndexChanged += new System.EventHandler(this.cboMaKH_4_SelectedIndexChanged); txtTenKH_4.DataBindings.Clear(); txtTenKH_4.DataBindings.Add("Text", dataTableKHACHHANG, "TENKH"); } catch (Exception ex) { MessageBox.Show(ex.Message);

} } private void populateNXB() { try { OleDbCommand cmd = new OleDbCommand(); cmd.CommandType = CommandType.Text; cmd.CommandText = "select * from NHAXUATBAN"; cmd.Connection = con; adapter = new OleDbDataAdapter(); adapter.SelectCommand = cmd; adapter.SelectCommand.Connection = con; //adapter.TableMappings.Add("Table", "NHAPPS"); //OleDbCommandBuilder cb = new OleDbCommandBuilder(adapter); dataSet1 = new DataSet(); adapter.Fill(dataSet1, "NHAXUATBAN"); DataTable dataTableNHAXUATBAN = new DataTable(); dataTableNHAXUATBAN = dataSet1.Tables["NHAXUATBAN"]; this.cboMaNXB.SelectedIndexChanged -= new System.EventHandler(this.cboMaNXB_SelectedIndexChanged); cboMaNXB.DataSource = dataTableNHAXUATBAN; cboMaNXB.DisplayMember = "MANXB"; cboMaNXB.ValueMember = "MANXB"; this.cboMaNXB.SelectedIndexChanged += new System.EventHandler(this.cboMaNXB_SelectedIndexChanged); txtTenNXB.DataBindings.Clear(); txtTenNXB.DataBindings.Add("Text", dataTableNHAXUATBAN, "TENNXB"); this.cboMaNXB_1.SelectedIndexChanged -= new System.EventHandler(this.cboMaNXB_1_SelectedIndexChanged); cboMaNXB_1.DataSource = dataTableNHAXUATBAN; cboMaNXB_1.DisplayMember = "MANXB"; cboMaNXB_1.ValueMember = "MANXB"; this.cboMaNXB_1.SelectedIndexChanged += new System.EventHandler(this.cboMaNXB_1_SelectedIndexChanged); txtTenNXB_1.DataBindings.Clear(); txtTenNXB_1.DataBindings.Add("Text", dataTableNHAXUATBAN, "TENNXB"); this.cboManxb_2.SelectedIndexChanged -= new System.EventHandler(this.cboManxb_2_SelectedIndexChanged); cboManxb_2.DataSource = dataTableNHAXUATBAN; cboManxb_2.DisplayMember = "MANXB"; cboManxb_2.ValueMember = "MANXB"; this.cboManxb_2.SelectedIndexChanged += new System.EventHandler(this.cboManxb_2_SelectedIndexChanged); txtTenNXB_2.DataBindings.Clear(); txtTenNXB_2.DataBindings.Add("Text", dataTableNHAXUATBAN, "TENNXB"); } catch (Exception ex) { MessageBox.Show(ex.Message); } } private void populateLOAISACH() { try { OleDbCommand cmd = new OleDbCommand(); cmd.CommandType = CommandType.Text; cmd.CommandText = "select * from LOAISACH"; cmd.Connection = con; adapter = new OleDbDataAdapter(); adapter.SelectCommand = cmd;

adapter.SelectCommand.Connection = con; //adapter.TableMappings.Add("Table", "NHAPPS"); //OleDbCommandBuilder cb = new OleDbCommandBuilder(adapter); dataSet1 = new DataSet(); adapter.Fill(dataSet1, "LOAISACH"); DataTable dataTableLOAISACH = new DataTable(); dataTableLOAISACH = dataSet1.Tables["LOAISACH"]; this.cboMaloaisach.SelectedIndexChanged -= new System.EventHandler(this.cboMaloaisach_SelectedIndexChanged); cboMaloaisach.DataSource = dataTableLOAISACH; cboMaloaisach.DisplayMember = "MALOAI"; cboMaloaisach.ValueMember = "MALOAI"; this.cboMaloaisach.SelectedIndexChanged += new System.EventHandler(this.cboMaloaisach_SelectedIndexChanged); txtTenloaisach.DataBindings.Clear(); txtTenloaisach.DataBindings.Add("Text", dataTableLOAISACH, "TENLOAI"); this.cboMaloai_2.SelectedIndexChanged -= new System.EventHandler(this.cboMaloai_2_SelectedIndexChanged); cboMaloai_2.DataSource = dataTableLOAISACH; cboMaloai_2.DisplayMember = "MALOAI"; cboMaloai_2.ValueMember = "MALOAI"; this.cboMaloai_2.SelectedIndexChanged += new System.EventHandler(this.cboMaloai_2_SelectedIndexChanged); txtTenloai_2.DataBindings.Clear(); txtTenloai_2.DataBindings.Add("Text", dataTableLOAISACH, "TENLOAI"); } catch (Exception ex) { MessageBox.Show(ex.Message); } } private void NhapTenSach() { try { //thu: good //+ " order by MASACH asc AutoCompleteStringCollection namesCollection = new AutoCompleteStringCollection(); OleDbCommand cmd = new OleDbCommand(); cmd.Connection = con; cmd.CommandType = CommandType.Text; cmd.CommandText = "select * from SACH"; adapter = new OleDbDataAdapter(); adapter.SelectCommand = cmd; adapter.SelectCommand.Connection = con; dataSet1 = new DataSet(); adapter.Fill(dataSet1, "SACH"); DataTable dataTableSACH = new DataTable(); dataTableSACH = dataSet1.Tables["SACH"]; //DataColumn co; //co = dataTableSACH.Columns["TENSACH"]; int i; for (i = 0; i < dataTableSACH.Rows.Count; i++) { namesCollection.Add(dataTableSACH.Rows[i]["TENSACH"].ToString()); } //cmd.CommandText = "Select TENSACH from SACH"; //OleDbDataReader re = cmd.ExecuteReader(); //if (re.HasRows == true) //{ // while (re.Read()) // namesCollection.Add(re["TENSACH"].ToString());

//} //else //{ // MessageBox.Show("Data not found"); //} //re.Close(); txtTensach.AutoCompleteMode = AutoCompleteMode.Suggest; txtTensach.AutoCompleteSource = AutoCompleteSource.CustomSource; txtTensach.AutoCompleteCustomSource = namesCollection; txtTensach.DataBindings.Clear(); txtTensach.DataBindings.Add("Text", dataTableSACH, "TENSACH"); txtTensach_2.AutoCompleteMode = AutoCompleteMode.Suggest; txtTensach_2.AutoCompleteSource = AutoCompleteSource.CustomSource; txtTensach_2.AutoCompleteCustomSource = namesCollection; txtTensach_2.DataBindings.Clear(); txtTensach_2.DataBindings.Add("Text", dataTableSACH, "TENSACH"); } catch (Exception ex) { MessageBox.Show(ex.Message); }

private void rbtnTatca_CheckedChanged(object sender, EventArgs e) { this.Validate(); txtTensach.Enabled = false; dtpTuNgay.Enabled = false; dtpDenNgay.Enabled = false; cboMaloaisach.Enabled = false; txtTenloaisach.Enabled = false; cboMaNXB.Enabled = false; txtTenNXB.Enabled = false; cboMaKH.Enabled = false; txtTenKH.Enabled = false; } private void cboMaloaisach_SelectedIndexChanged(object sender, EventArgs e) { } private void cboMaNXB_SelectedIndexChanged(object sender, EventArgs e) { } private void cboMaKH_SelectedIndexChanged(object sender, EventArgs e) { } private void btnThoat_Click(object sender, EventArgs e) { con.Close(); this.Close(); } private void txtTensach_TextChanged(object sender, EventArgs e) { this.Tensach = txtTensach.Text; } private void btnTim_Click(object sender, EventArgs e) {

if (rbtnBannhieunhat.Checked == true) { timSachban_nhieu(); } else if (rbtnBanitnhat.Checked == true) { timSachban_it(); }

private void dtpTuNgay_ValueChanged(object sender, EventArgs e) { this.Tungay = dtpTuNgay.Value.Date; } private void dtpDenNgay_ValueChanged(object sender, EventArgs e) { this.Denngay = dtpDenNgay.Value.Date; } private void rbtnNhaPPS_1_CheckedChanged(object sender, EventArgs e) { this.Validate(); cboMaNPPS_1.Enabled = true; txtTenNPPS_1.Enabled = true; cboChietkhaunhap_1.Enabled = false; cboMaNXB_1.Enabled = false; txtTenNXB_1.Enabled = false; dtpDenngay_1.Enabled = false; dtpTungay_1.Enabled = false; } private void rbtnChietkhaunhap_1_CheckedChanged(object sender, EventArgs e) { this.Validate(); cboMaNPPS_1.Enabled = false; txtTenNPPS_1.Enabled = false; cboChietkhaunhap_1.Enabled = true; cboMaNXB_1.Enabled = false; txtTenNXB_1.Enabled = false; dtpDenngay_1.Enabled = false; dtpTungay_1.Enabled = false; } private void rbtnNhaxuatban_1_CheckedChanged(object sender, EventArgs e) { this.Validate(); cboMaNPPS_1.Enabled = false; txtTenNPPS_1.Enabled = false; cboChietkhaunhap_1.Enabled = false; cboMaNXB_1.Enabled = true; txtTenNXB_1.Enabled = true; dtpDenngay_1.Enabled = false; dtpTungay_1.Enabled = false; } private void rbtnTatca_1_CheckedChanged(object sender, EventArgs e) { this.Validate(); cboMaNPPS_1.Enabled = false; txtTenNPPS_1.Enabled = false; cboChietkhaunhap_1.Enabled = false; cboMaNXB_1.Enabled = false; txtTenNXB_1.Enabled = false; dtpDenngay_1.Enabled = false; dtpTungay_1.Enabled = false;

} private void btnThongke_1_Click(object sender, EventArgs e) { if (rbtnNhaPPS_1.Checked == true) { thongke_theoNHAPPS_1(); } else if (rbtnChietkhaunhap_1.Checked == true) { thongke_theoCHIETKHAUNHAP_1(); } else if (rbtnNhaxuatban_1.Checked == true) { thongke_theoNXB_1(); } else if (rbtnNgaythang_1.Checked == true) { thongke_theoNGAYTHANG_1(); } else if (rbtnTatca_1.Checked == true) { thongke_theoTATCA_1(); } } private void thongke_theoTATCA_1() { this.Tungay_1 = dtpTungay_1.Value.Date; this.Denngay_1 = dtpDenngay_1.Value.Date; try { string str_dgvSach = @"SELECT SACH.MASACH, SACH.TENSACH, SACH.CHIETKHAUNHAP, NHAP_SACH.SLUONG, NHAP_SACH.DONGIA, NHAPPS.TENNPPS, NHAXUATBAN.TENNXB FROM SACH, NHAP_SACH, NHAPPS, NHAXUATBAN, PHIEUNHAP WHERE SACH.MASACH=NHAP_SACH.MASACH AND NHAP_SACH.SOPHIEUNHAP=PHIEUNHAP.SOPHIEUNHAP AND PHIEUNHAP.MANPPS=NHAPPS.MANPPS AND SACH.MANXB=NHAXUATBAN.MANXB"; OleDbCommand cmddgvSach = new OleDbCommand(str_dgvSach, con); adapter = new OleDbDataAdapter(); adapter.SelectCommand = cmddgvSach; adapter.SelectCommand.Connection = con; dataSet1 = new DataSet(); DataTable datatabledgvSach = new DataTable(); adapter.Fill(dataSet1, "dgvSach"); datatabledgvSach = dataSet1.Tables["dgvSach"]; DataRow dr = datatabledgvSach.NewRow(); dr["TENSACH"] = "Tong cong".ToString(); dr["SLUONG"] = dataSet1.Tables["dgvSach"].Compute("Sum(SLUONG)", null); dr["DONGIA"] = dataSet1.Tables["dgvSach"].Compute("Sum(DONGIA)", null); datatabledgvSach.Rows.Add(dr); dgvSach_1.RowsDefaultCellStyle.BackColor = Color.WhiteSmoke; dgvSach_1.AlternatingRowsDefaultCellStyle.BackColor = Color.White; dgvSach_1.DataSource = datatabledgvSach; string str_dgvHoadonban = @"SELECT PHIEUNHAP.SOPHIEUNHAP,PHIEUNHAP.SOHDM,PHIEUNHAP.THANHTIENNHAP, NHAPPS.TENNPPS, PHIEUNHAP.NGAYLAPPN,PHIEUNHAP.NGAYLAPHDM FROM PHIEUNHAP, NHAPPS WHERE PHIEUNHAP.MANPPS=NHAPPS.MANPPS"; OleDbCommand cmddgvHoadonban = new OleDbCommand(str_dgvHoadonban, con); adapter = new OleDbDataAdapter(); adapter.SelectCommand = cmddgvHoadonban; adapter.SelectCommand.Connection = con; dataSet1 = new DataSet();

DataTable datatabledgvHoadonban = new DataTable(); adapter.Fill(dataSet1, "dgvHoadonban"); datatabledgvHoadonban = dataSet1.Tables["dgvHoadonban"]; DataRow drdgvHoadonban = datatabledgvHoadonban.NewRow(); drdgvHoadonban["SOHDM"] = "Tong cong".ToString(); drdgvHoadonban["THANHTIENNHAP"] = dataSet1.Tables["dgvHoadonban"].Compute("Sum(THANHTIENNHAP)", null); datatabledgvHoadonban.Rows.Add(drdgvHoadonban); dgvPhieunhap_1.RowsDefaultCellStyle.BackColor = Color.WhiteSmoke; dgvPhieunhap_1.AlternatingRowsDefaultCellStyle.BackColor = Color.White; dgvPhieunhap_1.DataSource = datatabledgvHoadonban; } catch (Exception ex) { MessageBox.Show(ex.Message); } } private void thongke_theoNGAYTHANG_1() { this.Tungay_1 = dtpTungay_1.Value.Date; this.Denngay_1 = dtpDenngay_1.Value.Date; try { string str_dgvSach = @"SELECT SACH.MASACH, SACH.TENSACH, SACH.CHIETKHAUNHAP, NHAP_SACH.SLUONG, NHAP_SACH.DONGIA, NHAPPS.TENNPPS, NHAXUATBAN.TENNXB FROM SACH, NHAP_SACH, NHAPPS, NHAXUATBAN, PHIEUNHAP WHERE SACH.MASACH=NHAP_SACH.MASACH AND NHAP_SACH.SOPHIEUNHAP=PHIEUNHAP.SOPHIEUNHAP AND PHIEUNHAP.MANPPS=NHAPPS.MANPPS AND SACH.MANXB=NHAXUATBAN.MANXB AND PHIEUNHAP.NGAYLAPPN BETWEEN #" + this.Tungay_1 + "# AND #"+this.Denngay_1+"#"; OleDbCommand cmddgvSach = new OleDbCommand(str_dgvSach, con); adapter = new OleDbDataAdapter(); adapter.SelectCommand = cmddgvSach; adapter.SelectCommand.Connection = con; dataSet1 = new DataSet(); DataTable datatabledgvSach = new DataTable(); adapter.Fill(dataSet1, "dgvSach"); datatabledgvSach = dataSet1.Tables["dgvSach"]; DataRow dr = datatabledgvSach.NewRow(); dr["TENSACH"] = "Tong cong".ToString(); dr["SLUONG"] = dataSet1.Tables["dgvSach"].Compute("Sum(SLUONG)", null); dr["DONGIA"] = dataSet1.Tables["dgvSach"].Compute("Sum(DONGIA)", null); datatabledgvSach.Rows.Add(dr); dgvSach_1.RowsDefaultCellStyle.BackColor = Color.WhiteSmoke; dgvSach_1.AlternatingRowsDefaultCellStyle.BackColor = Color.White; dgvSach_1.DataSource = datatabledgvSach; string str_dgvHoadonban = @"SELECT PHIEUNHAP.SOPHIEUNHAP,PHIEUNHAP.SOHDM,PHIEUNHAP.THANHTIENNHAP, NHAPPS.TENNPPS, PHIEUNHAP.NGAYLAPPN,PHIEUNHAP.NGAYLAPHDM FROM PHIEUNHAP, NHAPPS WHERE PHIEUNHAP.MANPPS=NHAPPS.MANPPS AND PHIEUNHAP.NGAYLAPPN BETWEEN #" + this.Tungay_1 + "# AND #" + this.Denngay_1 + "#"; OleDbCommand cmddgvHoadonban = new OleDbCommand(str_dgvHoadonban, con); adapter = new OleDbDataAdapter(); adapter.SelectCommand = cmddgvHoadonban; adapter.SelectCommand.Connection = con; dataSet1 = new DataSet(); DataTable datatabledgvHoadonban = new DataTable(); adapter.Fill(dataSet1, "dgvHoadonban"); datatabledgvHoadonban = dataSet1.Tables["dgvHoadonban"]; DataRow drdgvHoadonban = datatabledgvHoadonban.NewRow();

drdgvHoadonban["SOHDM"] = "Tong cong".ToString(); drdgvHoadonban["THANHTIENNHAP"] = dataSet1.Tables["dgvHoadonban"].Compute("Sum(THANHTIENNHAP)", null); datatabledgvHoadonban.Rows.Add(drdgvHoadonban); dgvPhieunhap_1.RowsDefaultCellStyle.BackColor = Color.WhiteSmoke; dgvPhieunhap_1.AlternatingRowsDefaultCellStyle.BackColor = Color.White; dgvPhieunhap_1.DataSource = datatabledgvHoadonban; } catch (Exception ex) { MessageBox.Show(ex.Message); } } private void thongke_theoNXB_1() { this.Manxb_1 = Convert.ToString(cboMaNXB_1.Text); try { string str_dgvSach = @"SELECT SACH.MASACH, SACH.TENSACH, SACH.CHIETKHAUNHAP, NHAP_SACH.SLUONG, NHAP_SACH.DONGIA, NHAPPS.TENNPPS, NHAXUATBAN.TENNXB FROM SACH, NHAP_SACH, NHAPPS, NHAXUATBAN, PHIEUNHAP WHERE SACH.MASACH=NHAP_SACH.MASACH AND NHAP_SACH.SOPHIEUNHAP=PHIEUNHAP.SOPHIEUNHAP AND PHIEUNHAP.MANPPS=NHAPPS.MANPPS AND SACH.MANXB=NHAXUATBAN.MANXB AND NHAXUATBAN.MANXB=" + int.Parse(this.Manxb_1.ToString()) + ""; OleDbCommand cmddgvSach = new OleDbCommand(str_dgvSach, con); adapter = new OleDbDataAdapter(); adapter.SelectCommand = cmddgvSach; adapter.SelectCommand.Connection = con; dataSet1 = new DataSet(); DataTable datatabledgvSach = new DataTable(); adapter.Fill(dataSet1, "dgvSach"); datatabledgvSach = dataSet1.Tables["dgvSach"]; DataRow dr = datatabledgvSach.NewRow(); dr["TENSACH"] = "Tong cong".ToString(); dr["SLUONG"] = dataSet1.Tables["dgvSach"].Compute("Sum(SLUONG)", null); dr["DONGIA"] = dataSet1.Tables["dgvSach"].Compute("Sum(DONGIA)", null); datatabledgvSach.Rows.Add(dr); dgvSach_1.RowsDefaultCellStyle.BackColor = Color.WhiteSmoke; dgvSach_1.AlternatingRowsDefaultCellStyle.BackColor = Color.White; dgvSach_1.DataSource = datatabledgvSach; string str_dgvHoadonban = @"SELECT PHIEUNHAP.SOPHIEUNHAP,PHIEUNHAP.SOHDM,PHIEUNHAP.THANHTIENNHAP, NHAPPS.TENNPPS, PHIEUNHAP.NGAYLAPPN,PHIEUNHAP.NGAYLAPHDM FROM PHIEUNHAP, NHAPPS, NHAP_SACH, SACH WHERE PHIEUNHAP.MANPPS=NHAPPS.MANPPS AND PHIEUNHAP.SOPHIEUNHAP=NHAP_SACH.SOPHIEUNHAP AND SACH.MASACH=NHAP_SACH.MASACH AND SACH.MANXB="+int.Parse(this.Manxb_1.ToString())+""; OleDbCommand cmddgvHoadonban = new OleDbCommand(str_dgvHoadonban, con); adapter = new OleDbDataAdapter(); adapter.SelectCommand = cmddgvHoadonban; adapter.SelectCommand.Connection = con; dataSet1 = new DataSet(); DataTable datatabledgvHoadonban = new DataTable(); adapter.Fill(dataSet1, "dgvHoadonban"); datatabledgvHoadonban = dataSet1.Tables["dgvHoadonban"]; DataRow drdgvHoadonban = datatabledgvHoadonban.NewRow(); drdgvHoadonban["SOHDM"] = "Tong cong".ToString(); drdgvHoadonban["THANHTIENNHAP"] = dataSet1.Tables["dgvHoadonban"].Compute("Sum(THANHTIENNHAP)", null); datatabledgvHoadonban.Rows.Add(drdgvHoadonban); dgvPhieunhap_1.RowsDefaultCellStyle.BackColor = Color.WhiteSmoke; dgvPhieunhap_1.AlternatingRowsDefaultCellStyle.BackColor = Color.White;

dgvPhieunhap_1.DataSource = datatabledgvHoadonban; } catch (Exception ex) { MessageBox.Show(ex.Message); }

private void thongke_theoCHIETKHAUNHAP_1() { this.Cknhap_1 = Convert.ToString(cboChietkhaunhap_1.Text); try { string str_dgvSach = @"SELECT SACH.MASACH, SACH.TENSACH, SACH.CHIETKHAUNHAP, NHAP_SACH.SLUONG, NHAP_SACH.DONGIA, NHAPPS.TENNPPS, NHAXUATBAN.TENNXB FROM SACH, NHAP_SACH, NHAPPS, NHAXUATBAN, PHIEUNHAP WHERE SACH.MASACH=NHAP_SACH.MASACH AND NHAP_SACH.SOPHIEUNHAP=PHIEUNHAP.SOPHIEUNHAP AND PHIEUNHAP.MANPPS=NHAPPS.MANPPS AND SACH.MANXB=NHAXUATBAN.MANXB AND SACH.CHIETKHAUNHAP=" +double.Parse(this.Cknhap_1.ToString()) + ""; OleDbCommand cmddgvSach = new OleDbCommand(str_dgvSach, con); adapter = new OleDbDataAdapter(); adapter.SelectCommand = cmddgvSach; adapter.SelectCommand.Connection = con; dataSet1 = new DataSet(); DataTable datatabledgvSach = new DataTable(); adapter.Fill(dataSet1, "dgvSach"); datatabledgvSach = dataSet1.Tables["dgvSach"]; DataRow dr = datatabledgvSach.NewRow(); dr["TENSACH"] = "Tong cong".ToString(); dr["SLUONG"] = dataSet1.Tables["dgvSach"].Compute("Sum(SLUONG)", null); dr["DONGIA"] = dataSet1.Tables["dgvSach"].Compute("Sum(DONGIA)", null); datatabledgvSach.Rows.Add(dr); dgvSach_1.RowsDefaultCellStyle.BackColor = Color.WhiteSmoke; dgvSach_1.AlternatingRowsDefaultCellStyle.BackColor = Color.White; dgvSach_1.DataSource = datatabledgvSach; string str_dgvHoadonban = @"SELECT PHIEUNHAP.SOPHIEUNHAP,PHIEUNHAP.SOHDM,PHIEUNHAP.THANHTIENNHAP, NHAPPS.TENNPPS, PHIEUNHAP.NGAYLAPPN,PHIEUNHAP.NGAYLAPHDM FROM PHIEUNHAP, NHAPPS , SACH, NHAP_SACH WHERE PHIEUNHAP.MANPPS=NHAPPS.MANPPS AND SACH.MASACH=NHAP_SACH.MASACH AND NHAP_SACH.SOPHIEUNHAP=PHIEUNHAP.SOPHIEUNHAP AND SACH.CHIETKHAUNHAP=" + double.Parse(this.Cknhap_1.ToString()) + ""; OleDbCommand cmddgvHoadonban = new OleDbCommand(str_dgvHoadonban, con); adapter = new OleDbDataAdapter(); adapter.SelectCommand = cmddgvHoadonban; adapter.SelectCommand.Connection = con; dataSet1 = new DataSet(); DataTable datatabledgvHoadonban = new DataTable(); adapter.Fill(dataSet1, "dgvHoadonban"); datatabledgvHoadonban = dataSet1.Tables["dgvHoadonban"]; DataRow drdgvHoadonban = datatabledgvHoadonban.NewRow(); drdgvHoadonban["SOHDM"] = "Tong cong".ToString(); drdgvHoadonban["THANHTIENNHAP"] = dataSet1.Tables["dgvHoadonban"].Compute("Sum(THANHTIENNHAP)", null); datatabledgvHoadonban.Rows.Add(drdgvHoadonban); dgvPhieunhap_1.RowsDefaultCellStyle.BackColor = Color.WhiteSmoke; dgvPhieunhap_1.AlternatingRowsDefaultCellStyle.BackColor = Color.White; dgvPhieunhap_1.DataSource = datatabledgvHoadonban; } catch (Exception ex) { MessageBox.Show(ex.Message); }

} private void thongke_theoNHAPPS_1() { this.Manpps_1 = Convert.ToString(cboMaNPPS_1.Text); try { string str_dgvSach = @"SELECT SACH.MASACH, SACH.TENSACH, SACH.CHIETKHAUNHAP, NHAP_SACH.SLUONG, NHAP_SACH.DONGIA, NHAPPS.TENNPPS, NHAXUATBAN.TENNXB FROM SACH, NHAP_SACH, NHAPPS, NHAXUATBAN, PHIEUNHAP WHERE SACH.MASACH=NHAP_SACH.MASACH AND NHAP_SACH.SOPHIEUNHAP=PHIEUNHAP.SOPHIEUNHAP AND PHIEUNHAP.MANPPS=NHAPPS.MANPPS AND SACH.MANXB=NHAXUATBAN.MANXB AND NHAPPS.MANPPS="+int.Parse(this.Manpps_1.ToString())+""; OleDbCommand cmddgvSach = new OleDbCommand(str_dgvSach, con); adapter = new OleDbDataAdapter(); adapter.SelectCommand = cmddgvSach; adapter.SelectCommand.Connection = con; dataSet1 = new DataSet(); DataTable datatabledgvSach = new DataTable(); adapter.Fill(dataSet1, "dgvSach"); datatabledgvSach = dataSet1.Tables["dgvSach"]; DataRow dr = datatabledgvSach.NewRow(); dr["TENSACH"] = "Tong cong".ToString(); dr["SLUONG"] = dataSet1.Tables["dgvSach"].Compute("Sum(SLUONG)", null); dr["DONGIA"] = dataSet1.Tables["dgvSach"].Compute("Sum(DONGIA)", null); datatabledgvSach.Rows.Add(dr); dgvSach_1.RowsDefaultCellStyle.BackColor = Color.WhiteSmoke; dgvSach_1.AlternatingRowsDefaultCellStyle.BackColor = Color.White; dgvSach_1.DataSource = datatabledgvSach; string str_dgvHoadonban = @"SELECT PHIEUNHAP.SOPHIEUNHAP,PHIEUNHAP.SOHDM,PHIEUNHAP.THANHTIENNHAP, NHAPPS.TENNPPS, PHIEUNHAP.NGAYLAPPN,PHIEUNHAP.NGAYLAPHDM FROM PHIEUNHAP, NHAPPS WHERE PHIEUNHAP.MANPPS=NHAPPS.MANPPS AND NHAPPS.MANPPS="+int.Parse(this.Manpps_1.ToString())+""; OleDbCommand cmddgvHoadonban = new OleDbCommand(str_dgvHoadonban, con); adapter = new OleDbDataAdapter(); adapter.SelectCommand = cmddgvHoadonban; adapter.SelectCommand.Connection = con; dataSet1 = new DataSet(); DataTable datatabledgvHoadonban = new DataTable(); adapter.Fill(dataSet1, "dgvHoadonban"); datatabledgvHoadonban = dataSet1.Tables["dgvHoadonban"]; DataRow drdgvHoadonban = datatabledgvHoadonban.NewRow(); drdgvHoadonban["SOHDM"] = "Tong cong".ToString(); drdgvHoadonban["THANHTIENNHAP"] = dataSet1.Tables["dgvHoadonban"].Compute("Sum(THANHTIENNHAP)", null); datatabledgvHoadonban.Rows.Add(drdgvHoadonban); dgvPhieunhap_1.RowsDefaultCellStyle.BackColor = Color.WhiteSmoke; dgvPhieunhap_1.AlternatingRowsDefaultCellStyle.BackColor = Color.White; dgvPhieunhap_1.DataSource = datatabledgvHoadonban; } catch (Exception ex) { MessageBox.Show(ex.Message); } } private void cboMaNPPS_1_SelectedIndexChanged(object sender, EventArgs e) { this.Manpps_1 = Convert.ToString(cboMaNPPS_1.Text); }

private void btnThoat_1_Click(object sender, EventArgs e) { con.Close(); this.Close(); } private void cboChietkhaunhap_1_SelectedIndexChanged(object sender, EventArgs e) { this.Cknhap_1 = Convert.ToString(cboChietkhaunhap_1.Text); } private void cboMaNXB_1_SelectedIndexChanged(object sender, EventArgs e) { this.Manxb_1 = Convert.ToString(cboMaNXB_1.Text); } private void rbtnNgaythang_1_CheckedChanged(object sender, EventArgs e) { this.Validate(); cboMaNPPS_1.Enabled = false; txtTenNPPS_1.Enabled = false; cboChietkhaunhap_1.Enabled = false; cboMaNXB_1.Enabled = false; txtTenNXB_1.Enabled = false; dtpDenngay_1.Enabled = true; dtpTungay_1.Enabled = true; } private void dtpTungay_1_ValueChanged(object sender, EventArgs e) { this.Tungay_1 = dtpDenngay_1.Value.Date; } private void dtpDenngay_1_ValueChanged(object sender, EventArgs e) { this.Denngay_1 = dtpDenngay_1.Value.Date; } private void timSachnhap_it_1() { try { // string str_sachbanit = @"SELECT SACH.TENSACH, SUM(NHAP_SACH.SLUONG) AS TONGSLNHAP // FROM NHAP_SACH, SACH // WHERE NHAP_SACH.MASACH=SACH.MASACH // GROUP BY SACH.TENSACH // HAVING SUM(NHAP_SACH.SLUONG)=(SELECT MIN(SL) FROM ( // SELECT SUM(NHAP_SACH.SLUONG) AS SL FROM NHAP_SACH, SACH WHERE NHAP_SACH.MASACH=SACH.MASACH GROUP BY SACH.TENSACH))"; string str_sachbanit = @"SELECT * FROM (SELECT SACH.TENSACH, SUM(NHAP_SACH.SLUONG) AS TONGSLNHAP FROM NHAP_SACH, SACH WHERE NHAP_SACH.MASACH=SACH.MASACH GROUP BY SACH.TENSACH ORDER BY SUM(NHAP_SACH.SLUONG) ASC)"; OleDbCommand cmd_timsachbanit = new OleDbCommand(str_sachbanit, con); adapter = new OleDbDataAdapter(); adapter.SelectCommand = cmd_timsachbanit; adapter.SelectCommand.Connection = con; dataSet1 = new DataSet(); DataTable datatableSachbanit = new DataTable(); adapter.Fill(dataSet1, "Sachbanit"); datatableSachbanit = dataSet1.Tables["Sachbanit"]; //DataRow dr = datatableSachbanit.NewRow();

dgvTimSach_1.RowsDefaultCellStyle.BackColor = Color.WhiteSmoke; dgvTimSach_1.AlternatingRowsDefaultCellStyle.BackColor = Color.White; dgvTimSach_1.DataSource = datatableSachbanit; } catch (Exception ex) { MessageBox.Show(ex.Message); }

private void timSachnhap_nhieu_1() { try { // string str_sachbanit = @"SELECT SACH.TENSACH, SUM(NHAP_SACH.SLUONG) AS TONGSLNHAP // FROM NHAP_SACH, SACH // WHERE NHAP_SACH.MASACH=SACH.MASACH // GROUP BY SACH.TENSACH // HAVING SUM(NHAP_SACH.SLUONG)=(SELECT MAX(SL) FROM ( // SELECT SUM(NHAP_SACH.SLUONG) AS SL FROM NHAP_SACH, SACH WHERE NHAP_SACH.MASACH=SACH.MASACH GROUP BY SACH.TENSACH))"; string str_sachbanit = @"SELECT * FROM (SELECT SACH.TENSACH, SUM(NHAP_SACH.SLUONG) AS TONGSLNHAP FROM NHAP_SACH, SACH WHERE NHAP_SACH.MASACH=SACH.MASACH GROUP BY SACH.TENSACH ORDER BY SUM(NHAP_SACH.SLUONG) DESC)"; OleDbCommand cmd_timsachbanit = new OleDbCommand(str_sachbanit, con); adapter = new OleDbDataAdapter(); adapter.SelectCommand = cmd_timsachbanit; adapter.SelectCommand.Connection = con; dataSet1 = new DataSet(); DataTable datatableSachbanit = new DataTable(); adapter.Fill(dataSet1, "Sachbanit"); datatableSachbanit = dataSet1.Tables["Sachbanit"]; //DataRow dr = datatableSachbanit.NewRow(); dgvTimSach_1.RowsDefaultCellStyle.BackColor = Color.WhiteSmoke; dgvTimSach_1.AlternatingRowsDefaultCellStyle.BackColor = Color.White; dgvTimSach_1.DataSource = datatableSachbanit; } catch (Exception ex) { MessageBox.Show(ex.Message); }

private void btnTim_1_Click(object sender, EventArgs e) { if (rbtnSachnhapit_1.Checked == true) { timSachnhap_it_1(); } else if (rbtnSachnhapnhieu_1.Checked == true) { timSachnhap_nhieu_1(); } } private void cboMaloai_2_SelectedIndexChanged(object sender, EventArgs e) { this.Maloaisach_2 = Convert.ToString(cboMaloai_2.Text); } private void rbtnTatca_2_CheckedChanged(object sender, EventArgs e) {

this.Validate(); cboMaloai_2.Enabled = false; txtTenloai_2.Enabled = false; dtpTungay_2.Enabled = false; dtpDenngay_2.Enabled = false; cboManxb_2.Enabled = false; txtTenNXB_2.Enabled = false; txtTensach_2.Enabled = false;

private void rbtnLoaisach_2_CheckedChanged(object sender, EventArgs e) { this.Validate(); cboMaloai_2.Enabled = true; txtTenloai_2.Enabled = true; dtpTungay_2.Enabled = false; dtpDenngay_2.Enabled = false; cboManxb_2.Enabled = false; txtTenNXB_2.Enabled = false; txtTensach_2.Enabled = false; } private void rbtnNgaynhap_2_CheckedChanged(object sender, EventArgs e) { this.Validate(); cboMaloai_2.Enabled = false; txtTenloai_2.Enabled = false; dtpTungay_2.Enabled = true; dtpDenngay_2.Enabled = true; cboManxb_2.Enabled = false; txtTenNXB_2.Enabled = false; txtTensach_2.Enabled = false; } private void rbtnNhaxuatban_2_CheckedChanged(object sender, EventArgs e) { this.Validate(); cboMaloai_2.Enabled = false; txtTenloai_2.Enabled = false; dtpTungay_2.Enabled = false; dtpDenngay_2.Enabled = false; cboManxb_2.Enabled = true; txtTenNXB_2.Enabled = true; txtTensach_2.Enabled = false; } private void rbtnSach_2_CheckedChanged(object sender, EventArgs e) { this.Validate(); cboMaloai_2.Enabled = false; txtTenloai_2.Enabled = false; dtpTungay_2.Enabled = false; dtpDenngay_2.Enabled = false; cboManxb_2.Enabled = false; txtTenNXB_2.Enabled = false; txtTensach_2.Enabled = true; } private void btnThongKe_2_Click(object sender, EventArgs e) { if (rbtnLoaisach_2.Checked == true) { thongke_theoLOAISACH_2(); } if (rbtnNgaynhap_2.Checked == true) {

thongke_theoNGAYNHAP_2(); } if (rbtnNhaxuatban_2.Checked == true) { thongke_theoNHAXUATBAN_2(); } if (rbtnSach_2.Checked == true) { thongke_theoTENSACH_2(); } if (rbtnTatca_2.Checked == true) { thongke_theoTATCA_2(); }

private void thongke_theoTATCA_2() { try { string str_dgvSach = @"SELECT SACH.MASACH, SACH.TENSACH, LOAISACH.TENLOAI, TON_KHO.SOLUONGTON, KHOSACH.TENKHO, PHIEUNHAP.NGAYLAPPN, NHAXUATBAN.TENNXB FROM KHOSACH,LOAISACH,NHAP_SACH,NHAXUATBAN,PHIEUNHAP,SACH,TON_KHO WHERE KHOSACH.MAKHO=TON_KHO.MAKHO AND TON_KHO.MASACH=SACH.MASACH AND LOAISACH.MALOAI=SACH.MALOAI AND NHAP_SACH.MASACH=SACH.MASACH AND NHAP_SACH.SOPHIEUNHAP=PHIEUNHAP.SOPHIEUNHAP AND NHAXUATBAN.MANXB=SACH.MANXB"; OleDbCommand cmddgvSach = new OleDbCommand(str_dgvSach, con); adapter = new OleDbDataAdapter(); adapter.SelectCommand = cmddgvSach; adapter.SelectCommand.Connection = con; dataSet1 = new DataSet(); DataTable datatabledgvSach = new DataTable(); adapter.Fill(dataSet1, "dgvSach"); datatabledgvSach = dataSet1.Tables["dgvSach"]; DataRow dr = datatabledgvSach.NewRow(); dr["TENSACH"] = "Tong cong".ToString(); dr["SOLUONGTON"] = dataSet1.Tables["dgvSach"].Compute("Sum(SOLUONGTON)", null); datatabledgvSach.Rows.Add(dr); dgvSach_2.RowsDefaultCellStyle.BackColor = Color.WhiteSmoke; dgvSach_2.AlternatingRowsDefaultCellStyle.BackColor = Color.White; dgvSach_2.DataSource = datatabledgvSach; } catch (Exception ex) { MessageBox.Show(ex.Message); } } private void thongke_theoTENSACH_2() { this.Tensach_2 = txtTensach_2.Text; try { string str_dgvSach = @"SELECT SACH.MASACH, SACH.TENSACH, LOAISACH.TENLOAI, TON_KHO.SOLUONGTON, KHOSACH.TENKHO, PHIEUNHAP.NGAYLAPPN, NHAXUATBAN.TENNXB FROM KHOSACH,LOAISACH,NHAP_SACH,NHAXUATBAN,PHIEUNHAP,SACH,TON_KHO WHERE KHOSACH.MAKHO=TON_KHO.MAKHO AND TON_KHO.MASACH=SACH.MASACH AND LOAISACH.MALOAI=SACH.MALOAI AND NHAP_SACH.MASACH=SACH.MASACH AND NHAP_SACH.SOPHIEUNHAP=PHIEUNHAP.SOPHIEUNHAP AND NHAXUATBAN.MANXB=SACH.MANXB AND SACH.TENSACH='" + this.Tensach_2.ToString() + "'"; OleDbCommand cmddgvSach = new OleDbCommand(str_dgvSach, con); adapter = new OleDbDataAdapter(); adapter.SelectCommand = cmddgvSach;

null);

adapter.SelectCommand.Connection = con; dataSet1 = new DataSet(); DataTable datatabledgvSach = new DataTable(); adapter.Fill(dataSet1, "dgvSach"); datatabledgvSach = dataSet1.Tables["dgvSach"]; DataRow dr = datatabledgvSach.NewRow(); dr["TENSACH"] = "Tong cong".ToString(); dr["SOLUONGTON"] = dataSet1.Tables["dgvSach"].Compute("Sum(SOLUONGTON)", datatabledgvSach.Rows.Add(dr); dgvSach_2.RowsDefaultCellStyle.BackColor = Color.WhiteSmoke; dgvSach_2.AlternatingRowsDefaultCellStyle.BackColor = Color.White; dgvSach_2.DataSource = datatabledgvSach; } catch (Exception ex) { MessageBox.Show(ex.Message); }

private void thongke_theoNHAXUATBAN_2() { this.Manxb_2 = Convert.ToString(cboManxb_2.Text); try { string str_dgvSach = @"SELECT SACH.MASACH, SACH.TENSACH, LOAISACH.TENLOAI, TON_KHO.SOLUONGTON, KHOSACH.TENKHO, PHIEUNHAP.NGAYLAPPN, NHAXUATBAN.TENNXB FROM KHOSACH,LOAISACH,NHAP_SACH,NHAXUATBAN,PHIEUNHAP,SACH,TON_KHO WHERE KHOSACH.MAKHO=TON_KHO.MAKHO AND TON_KHO.MASACH=SACH.MASACH AND LOAISACH.MALOAI=SACH.MALOAI AND NHAP_SACH.MASACH=SACH.MASACH AND NHAP_SACH.SOPHIEUNHAP=PHIEUNHAP.SOPHIEUNHAP AND NHAXUATBAN.MANXB=SACH.MANXB AND NHAXUATBAN.MANXB="+int.Parse(this.Manxb_2.ToString())+""; OleDbCommand cmddgvSach = new OleDbCommand(str_dgvSach, con); adapter = new OleDbDataAdapter(); adapter.SelectCommand = cmddgvSach; adapter.SelectCommand.Connection = con; dataSet1 = new DataSet(); DataTable datatabledgvSach = new DataTable(); adapter.Fill(dataSet1, "dgvSach"); datatabledgvSach = dataSet1.Tables["dgvSach"]; DataRow dr = datatabledgvSach.NewRow(); dr["TENSACH"] = "Tong cong".ToString(); dr["SOLUONGTON"] = dataSet1.Tables["dgvSach"].Compute("Sum(SOLUONGTON)", null); datatabledgvSach.Rows.Add(dr); dgvSach_2.RowsDefaultCellStyle.BackColor = Color.WhiteSmoke; dgvSach_2.AlternatingRowsDefaultCellStyle.BackColor = Color.White; dgvSach_2.DataSource = datatabledgvSach; } catch (Exception ex) { MessageBox.Show(ex.Message); } } private void thongke_theoNGAYNHAP_2() { this.Tungay_2 = dtpTungay_2.Value.Date; this.Denngay_2 = dtpDenngay_2.Value.Date; try { string str_dgvSach = @"SELECT SACH.MASACH, SACH.TENSACH, LOAISACH.TENLOAI, TON_KHO.SOLUONGTON, KHOSACH.TENKHO, PHIEUNHAP.NGAYLAPPN, NHAXUATBAN.TENNXB FROM KHOSACH,LOAISACH,NHAP_SACH,NHAXUATBAN,PHIEUNHAP,SACH,TON_KHO

WHERE KHOSACH.MAKHO=TON_KHO.MAKHO AND TON_KHO.MASACH=SACH.MASACH AND LOAISACH.MALOAI=SACH.MALOAI AND NHAP_SACH.MASACH=SACH.MASACH AND NHAP_SACH.SOPHIEUNHAP=PHIEUNHAP.SOPHIEUNHAP AND NHAXUATBAN.MANXB=SACH.MANXB AND PHIEUNHAP.NGAYLAPPN BETWEEN #"+this.Tungay_2+"# AND #"+this.Denngay_2+"#"; OleDbCommand cmddgvSach = new OleDbCommand(str_dgvSach, con); adapter = new OleDbDataAdapter(); adapter.SelectCommand = cmddgvSach; adapter.SelectCommand.Connection = con; dataSet1 = new DataSet(); DataTable datatabledgvSach = new DataTable(); adapter.Fill(dataSet1, "dgvSach"); datatabledgvSach = dataSet1.Tables["dgvSach"]; DataRow dr = datatabledgvSach.NewRow(); dr["TENSACH"] = "Tong cong".ToString(); dr["SOLUONGTON"] = dataSet1.Tables["dgvSach"].Compute("Sum(SOLUONGTON)", null); datatabledgvSach.Rows.Add(dr); dgvSach_2.RowsDefaultCellStyle.BackColor = Color.WhiteSmoke; dgvSach_2.AlternatingRowsDefaultCellStyle.BackColor = Color.White; dgvSach_2.DataSource = datatabledgvSach;

} catch (Exception ex) { MessageBox.Show(ex.Message); } }

private void thongke_theoLOAISACH_2() { this.Maloaisach_2= Convert.ToString(cboMaloai_2.Text); try { string str_dgvSach = @"SELECT SACH.MASACH, SACH.TENSACH, LOAISACH.TENLOAI, TON_KHO.SOLUONGTON, KHOSACH.TENKHO, PHIEUNHAP.NGAYLAPPN, NHAXUATBAN.TENNXB FROM KHOSACH,LOAISACH,NHAP_SACH,NHAXUATBAN,PHIEUNHAP,SACH,TON_KHO WHERE KHOSACH.MAKHO=TON_KHO.MAKHO AND TON_KHO.MASACH=SACH.MASACH AND LOAISACH.MALOAI=SACH.MALOAI AND NHAP_SACH.MASACH=SACH.MASACH AND NHAP_SACH.SOPHIEUNHAP=PHIEUNHAP.SOPHIEUNHAP AND NHAXUATBAN.MANXB=SACH.MANXB AND LOAISACH.MALOAI="+int.Parse(this.Maloaisach_2.ToString())+""; OleDbCommand cmddgvSach = new OleDbCommand(str_dgvSach, con); adapter = new OleDbDataAdapter(); adapter.SelectCommand = cmddgvSach; adapter.SelectCommand.Connection = con; dataSet1 = new DataSet(); DataTable datatabledgvSach = new DataTable(); adapter.Fill(dataSet1, "dgvSach"); datatabledgvSach = dataSet1.Tables["dgvSach"]; DataRow dr = datatabledgvSach.NewRow(); dr["TENSACH"] = "Tong cong".ToString(); dr["SOLUONGTON"] = dataSet1.Tables["dgvSach"].Compute("Sum(SOLUONGTON)", null); datatabledgvSach.Rows.Add(dr); dgvSach_2.RowsDefaultCellStyle.BackColor = Color.WhiteSmoke; dgvSach_2.AlternatingRowsDefaultCellStyle.BackColor = Color.White; dgvSach_2.DataSource = datatabledgvSach; } catch (Exception ex) { MessageBox.Show(ex.Message); } } private void dtpTungay_2_ValueChanged(object sender, EventArgs e) { this.Tungay_2 = dtpTungay_2.Value.Date;

} private void dtpDenngay_2_ValueChanged(object sender, EventArgs e) { this.Denngay_2 = dtpDenngay_2.Value.Date; } private void cboManxb_2_SelectedIndexChanged(object sender, EventArgs e) { this.Manxb_2 = Convert.ToString(cboManxb_2.Text); } private void txtTensach_2_TextChanged(object sender, EventArgs e) { this.Tensach_2 = txtTensach_2.Text; } private void btnThoat_2_Click(object sender, EventArgs e) { con.Close(); this.Close(); } private void btnTim_2_Click(object sender, EventArgs e) { if (rbtnSachtonnhieu_2.Checked == true) { timSachton_nhieu_2(); } if (rbtnSachtonit_2.Checked == true) { timSachton_it_2(); } } private void timSachton_it_2() { try { // string str_sachbanit = @"SELECT SACH.TENSACH, SUM(NHAP_SACH.SLUONG) AS TONGSLNHAP // FROM NHAP_SACH, SACH // WHERE NHAP_SACH.MASACH=SACH.MASACH // GROUP BY SACH.TENSACH // HAVING SUM(NHAP_SACH.SLUONG)=(SELECT MAX(SL) FROM ( // SELECT SUM(NHAP_SACH.SLUONG) AS SL FROM NHAP_SACH, SACH WHERE NHAP_SACH.MASACH=SACH.MASACH GROUP BY SACH.TENSACH))"; string str_sachbanit = @"SELECT * FROM (SELECT SACH.TENSACH, SUM(TON_KHO.SOLUONGTON) AS TONGSLTON FROM TON_KHO, SACH WHERE TON_KHO.MASACH=SACH.MASACH GROUP BY SACH.TENSACH ORDER BY SUM(TON_KHO.SOLUONGTON) ASC)"; OleDbCommand cmd_timsachbanit = new OleDbCommand(str_sachbanit, con); adapter = new OleDbDataAdapter(); adapter.SelectCommand = cmd_timsachbanit; adapter.SelectCommand.Connection = con; dataSet1 = new DataSet(); DataTable datatableSachbanit = new DataTable(); adapter.Fill(dataSet1, "Sachbanit"); datatableSachbanit = dataSet1.Tables["Sachbanit"]; //DataRow dr = datatableSachbanit.NewRow(); dgvTimsach_2.RowsDefaultCellStyle.BackColor = Color.WhiteSmoke; dgvTimsach_2.AlternatingRowsDefaultCellStyle.BackColor = Color.White; dgvTimsach_2.DataSource = datatableSachbanit;

} catch (Exception ex) { MessageBox.Show(ex.Message); } } private void timSachton_nhieu_2() { try { // string str_sachbanit = @"SELECT SACH.TENSACH, SUM(NHAP_SACH.SLUONG) AS TONGSLNHAP // FROM NHAP_SACH, SACH // WHERE NHAP_SACH.MASACH=SACH.MASACH // GROUP BY SACH.TENSACH // HAVING SUM(NHAP_SACH.SLUONG)=(SELECT MAX(SL) FROM ( // SELECT SUM(NHAP_SACH.SLUONG) AS SL FROM NHAP_SACH, SACH WHERE NHAP_SACH.MASACH=SACH.MASACH GROUP BY SACH.TENSACH))"; string str_sachbanit = @"SELECT * FROM (SELECT SACH.TENSACH, SUM(TON_KHO.SOLUONGTON) AS TONGSLTON FROM TON_KHO, SACH WHERE TON_KHO.MASACH=SACH.MASACH GROUP BY SACH.TENSACH ORDER BY SUM(TON_KHO.SOLUONGTON) DESC)"; OleDbCommand cmd_timsachbanit = new OleDbCommand(str_sachbanit, con); adapter = new OleDbDataAdapter(); adapter.SelectCommand = cmd_timsachbanit; adapter.SelectCommand.Connection = con; dataSet1 = new DataSet(); DataTable datatableSachbanit = new DataTable(); adapter.Fill(dataSet1, "Sachbanit"); datatableSachbanit = dataSet1.Tables["Sachbanit"]; //DataRow dr = datatableSachbanit.NewRow(); dgvTimsach_2.RowsDefaultCellStyle.BackColor = Color.WhiteSmoke; dgvTimsach_2.AlternatingRowsDefaultCellStyle.BackColor = Color.White; dgvTimsach_2.DataSource = datatableSachbanit;

} catch (Exception ex) { MessageBox.Show(ex.Message); } }

private void cboManpps_3_SelectedIndexChanged(object sender, EventArgs e) { this.Manpps_3 = Convert.ToString(cboManpps_3.Text); } private void btnThoat_3_Click(object sender, EventArgs e) { con.Close(); this.Close(); } private void btnThongke_3_Click(object sender, EventArgs e) { if (rbtnNhapps_3.Checked == true) { thongke_theoNHAPPS_3(); } if (rbtnTatca_3.Checked == true) { }

} private void thongke_theoTATCA_3() { try { string str_dgvSach = @"SELECT SACH.MASACH, SACH.TENSACH, NHAPPS.TENNPPS, XUAT_TRA.SLUONGXUATTRA, XUAT_TRA.SLUONGNHAPTHUCSU, XUAT_TRA.LIDOXUATTRA FROM SACH, NHAPPS, PHIEUXUATTRA,XUAT_TRA WHERE SACH.MASACH=XUAT_TRA.MASACH AND XUAT_TRA.SOPHIEUXUATTRA=PHIEUXUATTRA.SOPHIEUXUATTRA AND PHIEUXUATTRA.MANPPS=NHAPPS.MANPPS"; OleDbCommand cmddgvSach = new OleDbCommand(str_dgvSach, con); adapter = new OleDbDataAdapter(); adapter.SelectCommand = cmddgvSach; adapter.SelectCommand.Connection = con; dataSet1 = new DataSet(); DataTable datatabledgvSach = new DataTable(); adapter.Fill(dataSet1, "dgvSach"); datatabledgvSach = dataSet1.Tables["dgvSach"]; DataRow dr = datatabledgvSach.NewRow(); dr["TENSACH"] = "Tong cong".ToString(); dr["SLUONGXUATTRA"] = dataSet1.Tables["dgvSach"].Compute("Sum(SLUONGXUATTRA)", null); dr["SLUONGNHAPTHUCSU"] = dataSet1.Tables["dgvSach"].Compute("Sum(SLUONGNHAPTHUCSU)", null); datatabledgvSach.Rows.Add(dr); dgvSach_3.RowsDefaultCellStyle.BackColor = Color.WhiteSmoke; dgvSach_3.AlternatingRowsDefaultCellStyle.BackColor = Color.White; dgvSach_3.DataSource = datatabledgvSach; string str_dgvHoadonban = @"SELECT PHIEUXUATTRA.SOPHIEUXUATTRA, NHAPPS.TENNPPS, PHIEUXUATTRA.TIENTHU, PHIEUXUATTRA.NGAYLAPPXT FROM PHIEUXUATTRA, NHAPPS WHERE PHIEUXUATTRA.MANPPS=NHAPPS.MANPPS"; OleDbCommand cmddgvHoadonban = new OleDbCommand(str_dgvHoadonban, con); adapter = new OleDbDataAdapter(); adapter.SelectCommand = cmddgvHoadonban; adapter.SelectCommand.Connection = con; dataSet1 = new DataSet(); DataTable datatabledgvHoadonban = new DataTable(); adapter.Fill(dataSet1, "dgvHoadonban"); datatabledgvHoadonban = dataSet1.Tables["dgvHoadonban"]; DataRow drdgvHoadonban = datatabledgvHoadonban.NewRow(); drdgvHoadonban["TENNPPS"] = "Tong cong".ToString(); drdgvHoadonban["TIENTHU"] = dataSet1.Tables["dgvHoadonban"].Compute("Sum(TIENTHU)", null); datatabledgvHoadonban.Rows.Add(drdgvHoadonban); dgvXuattra_3.RowsDefaultCellStyle.BackColor = Color.WhiteSmoke; dgvXuattra_3.AlternatingRowsDefaultCellStyle.BackColor = Color.White; dgvXuattra_3.DataSource = datatabledgvHoadonban; } catch (Exception ex) { MessageBox.Show(ex.Message); } } private void thongke_theoNHAPPS_3() { this.Manpps_3 = Convert.ToString(cboManpps_3.Text); try {

string str_dgvSach = @"SELECT SACH.MASACH, SACH.TENSACH, NHAPPS.TENNPPS, XUAT_TRA.SLUONGXUATTRA, XUAT_TRA.SLUONGNHAPTHUCSU, XUAT_TRA.LIDOXUATTRA FROM SACH, NHAPPS, PHIEUXUATTRA,XUAT_TRA WHERE SACH.MASACH=XUAT_TRA.MASACH AND XUAT_TRA.SOPHIEUXUATTRA=PHIEUXUATTRA.SOPHIEUXUATTRA AND PHIEUXUATTRA.MANPPS=NHAPPS.MANPPS AND NHAPPS.MANPPS="+int.Parse(this.Manpps_3.ToString())+""; OleDbCommand cmddgvSach = new OleDbCommand(str_dgvSach, con); adapter = new OleDbDataAdapter(); adapter.SelectCommand = cmddgvSach; adapter.SelectCommand.Connection = con; dataSet1 = new DataSet(); DataTable datatabledgvSach = new DataTable(); adapter.Fill(dataSet1, "dgvSach"); datatabledgvSach = dataSet1.Tables["dgvSach"]; DataRow dr = datatabledgvSach.NewRow(); dr["TENSACH"] = "Tong cong".ToString(); dr["SLUONGXUATTRA"] = dataSet1.Tables["dgvSach"].Compute("Sum(SLUONGXUATTRA)", null); dr["SLUONGNHAPTHUCSU"] = dataSet1.Tables["dgvSach"].Compute("Sum(SLUONGNHAPTHUCSU)", null); datatabledgvSach.Rows.Add(dr); dgvSach_3.RowsDefaultCellStyle.BackColor = Color.WhiteSmoke; dgvSach_3.AlternatingRowsDefaultCellStyle.BackColor = Color.White; dgvSach_3.DataSource = datatabledgvSach; string str_dgvHoadonban = @"SELECT PHIEUXUATTRA.SOPHIEUXUATTRA, NHAPPS.TENNPPS, PHIEUXUATTRA.TIENTHU, PHIEUXUATTRA.NGAYLAPPXT FROM PHIEUXUATTRA, NHAPPS WHERE PHIEUXUATTRA.MANPPS=NHAPPS.MANPPS AND NHAPPS.MANPPS=" + int.Parse(this.Manpps_3.ToString()) + ""; OleDbCommand cmddgvHoadonban = new OleDbCommand(str_dgvHoadonban, con); adapter = new OleDbDataAdapter(); adapter.SelectCommand = cmddgvHoadonban; adapter.SelectCommand.Connection = con; dataSet1 = new DataSet(); DataTable datatabledgvHoadonban = new DataTable(); adapter.Fill(dataSet1, "dgvHoadonban"); datatabledgvHoadonban = dataSet1.Tables["dgvHoadonban"]; DataRow drdgvHoadonban = datatabledgvHoadonban.NewRow(); drdgvHoadonban["TENNPPS"] = "Tong cong".ToString(); drdgvHoadonban["TIENTHU"] = dataSet1.Tables["dgvHoadonban"].Compute("Sum(TIENTHU)", null); datatabledgvHoadonban.Rows.Add(drdgvHoadonban); dgvXuattra_3.RowsDefaultCellStyle.BackColor = Color.WhiteSmoke; dgvXuattra_3.AlternatingRowsDefaultCellStyle.BackColor = Color.White; dgvXuattra_3.DataSource = datatabledgvHoadonban; } catch (Exception ex) { MessageBox.Show(ex.Message); } } private void btnTim_3_Click(object sender, EventArgs e) { if (rbtnSachtrait_3.Checked == true) { timSachtra_it_3(); } if (rbtnSachtranhieu_3.Checked == true) { timSachtra_nhieu_3(); }

} private void timSachtra_nhieu_3() { try { // string str_sachbanit = @"SELECT SACH.TENSACH, SUM(BAN_SACH.SLUONGBAN) AS TONGSLBAN // FROM BAN_SACH, SACH // WHERE BAN_SACH.MASACH=SACH.MASACH // GROUP BY SACH.TENSACH // HAVING SUM(BAN_SACH.SLUONGBAN)=(SELECT MIN(SL) FROM ( // SELECT SUM(BAN_SACH.SLUONGBAN) AS SL FROM BAN_SACH, SACH WHERE BAN_SACH.MASACH=SACH.MASACH GROUP BY SACH.TENSACH))"; string str_sachbanit = @"SELECT * FROM (SELECT SACH.TENSACH, SUM(XUAT_TRA.SLUONGXUATTRA) AS TONGSLXUATTRA FROM XUAT_TRA, SACH WHERE XUAT_TRA.MASACH=SACH.MASACH GROUP BY SACH.TENSACH ORDER BY SUM(XUAT_TRA.SLUONGXUATTRA) DESC)"; OleDbCommand cmd_timsachbanit = new OleDbCommand(str_sachbanit, con); adapter = new OleDbDataAdapter(); adapter.SelectCommand = cmd_timsachbanit; adapter.SelectCommand.Connection = con; dataSet1 = new DataSet(); DataTable datatableSachbanit = new DataTable(); adapter.Fill(dataSet1, "Sachbanit"); datatableSachbanit = dataSet1.Tables["Sachbanit"]; //DataRow dr = datatableSachbanit.NewRow(); dgvTimsach_3.RowsDefaultCellStyle.BackColor = Color.WhiteSmoke; dgvTimsach_3.AlternatingRowsDefaultCellStyle.BackColor = Color.White; dgvTimsach_3.DataSource = datatableSachbanit; } catch (Exception ex) { MessageBox.Show(ex.Message); }

private void timSachtra_it_3() { try { // string str_sachbanit = @"SELECT SACH.TENSACH, SUM(BAN_SACH.SLUONGBAN) AS TONGSLBAN // FROM BAN_SACH, SACH // WHERE BAN_SACH.MASACH=SACH.MASACH // GROUP BY SACH.TENSACH // HAVING SUM(BAN_SACH.SLUONGBAN)=(SELECT MIN(SL) FROM ( // SELECT SUM(BAN_SACH.SLUONGBAN) AS SL FROM BAN_SACH, SACH WHERE BAN_SACH.MASACH=SACH.MASACH GROUP BY SACH.TENSACH))"; string str_sachbanit = @"SELECT * FROM (SELECT SACH.TENSACH, SUM(XUAT_TRA.SLUONGXUATTRA) AS TONGSLXUATTRA FROM XUAT_TRA, SACH WHERE XUAT_TRA.MASACH=SACH.MASACH GROUP BY SACH.TENSACH ORDER BY SUM(XUAT_TRA.SLUONGXUATTRA) ASC)"; OleDbCommand cmd_timsachbanit = new OleDbCommand(str_sachbanit, con); adapter = new OleDbDataAdapter(); adapter.SelectCommand = cmd_timsachbanit; adapter.SelectCommand.Connection = con; dataSet1 = new DataSet(); DataTable datatableSachbanit = new DataTable(); adapter.Fill(dataSet1, "Sachbanit");

datatableSachbanit = dataSet1.Tables["Sachbanit"]; //DataRow dr = datatableSachbanit.NewRow(); dgvTimsach_3.RowsDefaultCellStyle.BackColor = Color.WhiteSmoke; dgvTimsach_3.AlternatingRowsDefaultCellStyle.BackColor = Color.White; dgvTimsach_3.DataSource = datatableSachbanit; } catch (Exception ex) { MessageBox.Show(ex.Message); }

private void radioButton1_CheckedChanged(object sender, EventArgs e) { this.Validate(); cboManpps_3.Enabled = true; txtTennpps_3.Enabled = true; } private void radioButton2_CheckedChanged(object sender, EventArgs e) { this.Validate(); cboManpps_3.Enabled = false; txtTennpps_3.Enabled = false; } private void cboMaNV_4_SelectedIndexChanged(object sender, EventArgs e) { this.Manv_4 = Convert.ToString(cboMaNV_4.Text); } private void dtpTungay_4_ValueChanged(object sender, EventArgs e) { this.Tungay_4 = dtpTungay_4.Value.Date; } private void dtpDenngay_4_ValueChanged(object sender, EventArgs e) { this.Denngay_4 = dtpDenngay_4.Value.Date; } private void cboMaKH_4_SelectedIndexChanged(object sender, EventArgs e) { this.Makh_4 = Convert.ToString(cboMaKH_4.Text); } private void btnThoat_4_Click(object sender, EventArgs e) { con.Close(); this.Close(); } private void rbtnNhanvien_4_CheckedChanged(object sender, EventArgs e) { this.Validate(); cboMaNV_4.Enabled = true; txtTenNV_4.Enabled = true; cboMaKH_4.Enabled = false; txtTenKH_4.Enabled = false; dtpTungay_4.Enabled = false; dtpDenngay_4.Enabled = false; } private void rbtnTatca_4_CheckedChanged(object sender, EventArgs e) { this.Validate();

cboMaNV_4. Enabled = false; txtTenNV_4.Enabled = false; cboMaKH_4.Enabled = false; txtTenKH_4.Enabled = false; dtpTungay_4.Enabled = false; dtpDenngay_4.Enabled = false; } private void rbtnNgaythang_4_CheckedChanged(object sender, EventArgs e) { this.Validate(); cboMaNV_4.Enabled = false; txtTenNV_4.Enabled = false; cboMaKH_4.Enabled = false; txtTenKH_4.Enabled = false; dtpTungay_4.Enabled = true; dtpDenngay_4.Enabled = true; } private void rbtnKhachhang_4_CheckedChanged(object sender, EventArgs e) { this.Validate(); cboMaNV_4.Enabled = false; txtTenNV_4.Enabled = false; cboMaKH_4.Enabled = true; txtTenKH_4.Enabled = true; dtpTungay_4.Enabled = false; dtpDenngay_4.Enabled = false; } private void btnThongke_4_Click(object sender, EventArgs e) { if (rbtnNhanvien_4.Checked == true) { thongke_theoNHANVIEN_4(); } if (rbtnNgaythang_4.Checked == true) { thongke_theoNGAYTHANG_4(); } if (rbtnKhachhang_4.Checked == true) { thongke_theoKHACHHANG_4(); } if (rbtnTatca_4.Checked == true) { thongke_theoTATCA_4(); } } private void thongke_theoTATCA_4() { this.Makh_4 = Convert.ToString(cboMaKH_4.Text); try { string str_dgvSach = @"SELECT NHANVIEN.MANV, NHANVIEN.TENNV, HOADONBAN.SOHOADON, HOADONBAN.NGAYLAPHD, HOADONBAN.TONGDGIACHUATHUE, HOADONBAN.THANHTIENDATHUE,KHACHHANG.TENKH, PHIEUXUATTRA.SOPHIEUXUATTRA, PHIEUXUATTRA.NGAYLAPPXT, PHIEUXUATTRA.TIENTHU FROM HOADONBAN, KHACHHANG, NHANVIEN, PHIEUXUATTRA WHERE HOADONBAN.MANV=NHANVIEN.MANV AND NHANVIEN.MANV=PHIEUXUATTRA.MANV AND HOADONBAN.MAKH=KHACHHANG.MAKH"; OleDbCommand cmddgvSach = new OleDbCommand(str_dgvSach, con); adapter = new OleDbDataAdapter(); adapter.SelectCommand = cmddgvSach;

adapter.SelectCommand.Connection = con; dataSet1 = new DataSet(); DataTable datatabledgvSach = new DataTable(); adapter.Fill(dataSet1, "dgvSach"); datatabledgvSach = dataSet1.Tables["dgvSach"]; DataRow dr = datatabledgvSach.NewRow(); dr["TENNV"] = "Tong cong".ToString(); dr["TONGDGIACHUATHUE"] = dataSet1.Tables["dgvSach"].Compute("Sum(TONGDGIACHUATHUE)", null); dr["THANHTIENDATHUE"] = dataSet1.Tables["dgvSach"].Compute("Sum(THANHTIENDATHUE)", null); dr["TIENTHU"] = dataSet1.Tables["dgvSach"].Compute("Sum(TIENTHU)", null); datatabledgvSach.Rows.Add(dr); dgvThutienmat_4.RowsDefaultCellStyle.BackColor = Color.WhiteSmoke; dgvThutienmat_4.AlternatingRowsDefaultCellStyle.BackColor = Color.White; dgvThutienmat_4.DataSource = datatabledgvSach; } catch (Exception ex) { MessageBox.Show(ex.Message); } } private void thongke_theoKHACHHANG_4() { this.Makh_4 = Convert.ToString(cboMaKH_4.Text); try { string str_dgvSach = @"SELECT NHANVIEN.MANV, NHANVIEN.TENNV, HOADONBAN.SOHOADON, HOADONBAN.NGAYLAPHD, HOADONBAN.TONGDGIACHUATHUE, HOADONBAN.THANHTIENDATHUE,KHACHHANG.TENKH, PHIEUXUATTRA.SOPHIEUXUATTRA, PHIEUXUATTRA.NGAYLAPPXT, PHIEUXUATTRA.TIENTHU FROM HOADONBAN, KHACHHANG, NHANVIEN, PHIEUXUATTRA WHERE HOADONBAN.MANV=NHANVIEN.MANV AND NHANVIEN.MANV=PHIEUXUATTRA.MANV AND HOADONBAN.MAKH=KHACHHANG.MAKH AND KHACHHANG.MAKH="+int.Parse(this.Makh_4.ToString())+""; OleDbCommand cmddgvSach = new OleDbCommand(str_dgvSach, con); adapter = new OleDbDataAdapter(); adapter.SelectCommand = cmddgvSach; adapter.SelectCommand.Connection = con; dataSet1 = new DataSet(); DataTable datatabledgvSach = new DataTable(); adapter.Fill(dataSet1, "dgvSach"); datatabledgvSach = dataSet1.Tables["dgvSach"]; DataRow dr = datatabledgvSach.NewRow(); dr["TENNV"] = "Tong cong".ToString(); dr["TONGDGIACHUATHUE"] = dataSet1.Tables["dgvSach"].Compute("Sum(TONGDGIACHUATHUE)", null); dr["THANHTIENDATHUE"] = dataSet1.Tables["dgvSach"].Compute("Sum(THANHTIENDATHUE)", null); dr["TIENTHU"] = dataSet1.Tables["dgvSach"].Compute("Sum(TIENTHU)", null); datatabledgvSach.Rows.Add(dr); dgvThutienmat_4.RowsDefaultCellStyle.BackColor = Color.WhiteSmoke; dgvThutienmat_4.AlternatingRowsDefaultCellStyle.BackColor = Color.White; dgvThutienmat_4.DataSource = datatabledgvSach; } catch (Exception ex) { MessageBox.Show(ex.Message); } } private void thongke_theoNGAYTHANG_4() { this.Tungay_4 = dtpTungay_4.Value.Date;

this.Denngay_4 = dtpDenngay_4.Value.Date; try { string str_dgvSach = @"SELECT NHANVIEN.MANV, NHANVIEN.TENNV, HOADONBAN.SOHOADON, HOADONBAN.NGAYLAPHD, HOADONBAN.TONGDGIACHUATHUE, HOADONBAN.THANHTIENDATHUE,KHACHHANG.TENKH, PHIEUXUATTRA.SOPHIEUXUATTRA, PHIEUXUATTRA.NGAYLAPPXT, PHIEUXUATTRA.TIENTHU FROM HOADONBAN, KHACHHANG, NHANVIEN, PHIEUXUATTRA WHERE HOADONBAN.MANV=NHANVIEN.MANV AND NHANVIEN.MANV=PHIEUXUATTRA.MANV AND HOADONBAN.MAKH=KHACHHANG.MAKH AND ((HOADONBAN.NGAYLAPHD BETWEEN #"+this.Tungay_4+"# AND #"+this.Denngay_4+@"#) AND (PHIEUXUATTRA.NGAYLAPPXT BETWEEN #"+this.Tungay_4+"# AND #"+this.Denngay_4+"#))"; OleDbCommand cmddgvSach = new OleDbCommand(str_dgvSach, con); adapter = new OleDbDataAdapter(); adapter.SelectCommand = cmddgvSach; adapter.SelectCommand.Connection = con; dataSet1 = new DataSet(); DataTable datatabledgvSach = new DataTable(); adapter.Fill(dataSet1, "dgvSach"); datatabledgvSach = dataSet1.Tables["dgvSach"]; DataRow dr = datatabledgvSach.NewRow(); dr["TENNV"] = "Tong cong".ToString(); dr["TONGDGIACHUATHUE"] = dataSet1.Tables["dgvSach"].Compute("Sum(TONGDGIACHUATHUE)", null); dr["THANHTIENDATHUE"] = dataSet1.Tables["dgvSach"].Compute("Sum(THANHTIENDATHUE)", null); dr["TIENTHU"] = dataSet1.Tables["dgvSach"].Compute("Sum(TIENTHU)", null); datatabledgvSach.Rows.Add(dr); dgvThutienmat_4.RowsDefaultCellStyle.BackColor = Color.WhiteSmoke; dgvThutienmat_4.AlternatingRowsDefaultCellStyle.BackColor = Color.White; dgvThutienmat_4.DataSource = datatabledgvSach; } catch (Exception ex) { MessageBox.Show(ex.Message); } } private void thongke_theoNHANVIEN_4() { this.Manv_4 = Convert.ToString(cboMaNV_4.Text); try { string str_dgvSach = @"SELECT NHANVIEN.MANV, NHANVIEN.TENNV, HOADONBAN.SOHOADON, HOADONBAN.NGAYLAPHD, HOADONBAN.TONGDGIACHUATHUE, HOADONBAN.THANHTIENDATHUE,KHACHHANG.TENKH, PHIEUXUATTRA.SOPHIEUXUATTRA, PHIEUXUATTRA.TIENTHU FROM HOADONBAN, KHACHHANG, NHANVIEN, PHIEUXUATTRA WHERE HOADONBAN.MANV=NHANVIEN.MANV AND NHANVIEN.MANV=PHIEUXUATTRA.MANV AND HOADONBAN.MAKH=KHACHHANG.MAKH AND NHANVIEN.MANV=" + int.Parse(this.Manv_4.ToString())+""; OleDbCommand cmddgvSach = new OleDbCommand(str_dgvSach, con); adapter = new OleDbDataAdapter(); adapter.SelectCommand = cmddgvSach; adapter.SelectCommand.Connection = con; dataSet1 = new DataSet(); DataTable datatabledgvSach = new DataTable(); adapter.Fill(dataSet1, "dgvSach"); datatabledgvSach = dataSet1.Tables["dgvSach"]; DataRow dr = datatabledgvSach.NewRow(); dr["TENNV"] = "Tong cong".ToString(); dr["TONGDGIACHUATHUE"] = dataSet1.Tables["dgvSach"].Compute("Sum(TONGDGIACHUATHUE)", null);

dr["THANHTIENDATHUE"] = dataSet1.Tables["dgvSach"].Compute("Sum(THANHTIENDATHUE)", null); dr["TIENTHU"] = dataSet1.Tables["dgvSach"].Compute("Sum(TIENTHU)", null); datatabledgvSach.Rows.Add(dr); dgvThutienmat_4.RowsDefaultCellStyle.BackColor = Color.WhiteSmoke; dgvThutienmat_4.AlternatingRowsDefaultCellStyle.BackColor = Color.White; dgvThutienmat_4.DataSource = datatabledgvSach; } catch (Exception ex) { MessageBox.Show(ex.Message); } } private void btnTim_4_Click(object sender, EventArgs e) { if (rbtnTienthunhieu_4.Checked == true) { timTienthu_nhieu_4(); } if (rbtnTienthuit_4.Checked == true) { timTienthu_it_4(); } } private void timTienthu_it_4() { try { // string str_sachbanit = @"SELECT SACH.TENSACH, SUM(BAN_SACH.SLUONGBAN) AS TONGSLBAN // FROM BAN_SACH, SACH // WHERE BAN_SACH.MASACH=SACH.MASACH // GROUP BY SACH.TENSACH // HAVING SUM(BAN_SACH.SLUONGBAN)=(SELECT MIN(SL) FROM ( // SELECT SUM(BAN_SACH.SLUONGBAN) AS SL FROM BAN_SACH, SACH WHERE BAN_SACH.MASACH=SACH.MASACH GROUP BY SACH.TENSACH))"; string str_sachbanit = @"SELECT * FROM (SELECT NHANVIEN.TENNV, SUM(HOADONBAN.TONGDGIACHUATHUE) AS TONGDGIACHUATHUE, SUM(HOADONBAN.THANHTIENDATHUE) AS THANHTIENDATHUE FROM NHANVIEN, HOADONBAN WHERE NHANVIEN.MANV=HOADONBAN.MANV GROUP BY NHANVIEN.TENNV ORDER BY SUM(HOADONBAN.TONGDGIACHUATHUE) ASC)"; OleDbCommand cmd_timsachbanit = new OleDbCommand(str_sachbanit, con); adapter = new OleDbDataAdapter(); adapter.SelectCommand = cmd_timsachbanit; adapter.SelectCommand.Connection = con; dataSet1 = new DataSet(); DataTable datatableSachbanit = new DataTable(); adapter.Fill(dataSet1, "Sachbanit"); datatableSachbanit = dataSet1.Tables["Sachbanit"]; dgvTimNV_4.RowsDefaultCellStyle.BackColor = Color.WhiteSmoke; dgvTimNV_4.AlternatingRowsDefaultCellStyle.BackColor = Color.White; //DataRow dr = datatableSachbanit.NewRow(); dgvTimNV_4.DataSource = datatableSachbanit; string str_sachbanit_2 = @"SELECT * FROM (SELECT NHANVIEN.TENNV, SUM(PHIEUXUATTRA.TIENTHU) AS TONGTIENTHU FROM NHANVIEN, PHIEUXUATTRA WHERE PHIEUXUATTRA.MANV=NHANVIEN.MANV GROUP BY NHANVIEN.TENNV ORDER BY SUM(PHIEUXUATTRA.TIENTHU) ASC)";

} catch (Exception ex) { MessageBox.Show(ex.Message); } }

OleDbCommand cmd_timsachbanit_2 = new OleDbCommand(str_sachbanit_2, con); adapter = new OleDbDataAdapter(); adapter.SelectCommand = cmd_timsachbanit_2; adapter.SelectCommand.Connection = con; dataSet1 = new DataSet(); DataTable datatableSachbanit_2 = new DataTable(); adapter.Fill(dataSet1, "Sachbanit_2"); datatableSachbanit_2 = dataSet1.Tables["Sachbanit_2"]; //DataRow dr = datatableSachbanit.NewRow(); dgvTienthu_pxt_4.RowsDefaultCellStyle.BackColor = Color.WhiteSmoke; dgvTienthu_pxt_4.AlternatingRowsDefaultCellStyle.BackColor = Color.White; dgvTienthu_pxt_4.DataSource = datatableSachbanit_2;

private void timTienthu_nhieu_4() { try { // string str_sachbanit = @"SELECT SACH.TENSACH, SUM(BAN_SACH.SLUONGBAN) AS TONGSLBAN // FROM BAN_SACH, SACH // WHERE BAN_SACH.MASACH=SACH.MASACH // GROUP BY SACH.TENSACH // HAVING SUM(BAN_SACH.SLUONGBAN)=(SELECT MIN(SL) FROM ( // SELECT SUM(BAN_SACH.SLUONGBAN) AS SL FROM BAN_SACH, SACH WHERE BAN_SACH.MASACH=SACH.MASACH GROUP BY SACH.TENSACH))"; string str_sachbanit = @"SELECT * FROM (SELECT NHANVIEN.TENNV, SUM(HOADONBAN.TONGDGIACHUATHUE) AS TONGDGIACHUATHUE, SUM(HOADONBAN.THANHTIENDATHUE) AS THANHTIENDATHUE FROM NHANVIEN, HOADONBAN WHERE NHANVIEN.MANV=HOADONBAN.MANV GROUP BY NHANVIEN.TENNV ORDER BY SUM(HOADONBAN.TONGDGIACHUATHUE) DESC)"; OleDbCommand cmd_timsachbanit = new OleDbCommand(str_sachbanit, con); adapter = new OleDbDataAdapter(); adapter.SelectCommand = cmd_timsachbanit; adapter.SelectCommand.Connection = con; dataSet1 = new DataSet(); DataTable datatableSachbanit = new DataTable(); adapter.Fill(dataSet1, "Sachbanit"); datatableSachbanit = dataSet1.Tables["Sachbanit"]; //DataRow dr = datatableSachbanit.NewRow(); dgvTimNV_4.RowsDefaultCellStyle.BackColor = Color.WhiteSmoke; dgvTimNV_4.AlternatingRowsDefaultCellStyle.BackColor = Color.White; dgvTimNV_4.DataSource = datatableSachbanit; string str_sachbanit_2 = @"SELECT * FROM (SELECT NHANVIEN.TENNV, SUM(PHIEUXUATTRA.TIENTHU) AS TONGTIENTHU FROM NHANVIEN, PHIEUXUATTRA WHERE PHIEUXUATTRA.MANV=NHANVIEN.MANV GROUP BY NHANVIEN.TENNV ORDER BY SUM(PHIEUXUATTRA.TIENTHU) DESC)"; OleDbCommand cmd_timsachbanit_2 = new OleDbCommand(str_sachbanit_2, con); adapter = new OleDbDataAdapter(); adapter.SelectCommand = cmd_timsachbanit_2; adapter.SelectCommand.Connection = con; dataSet1 = new DataSet(); DataTable datatableSachbanit_2 = new DataTable(); adapter.Fill(dataSet1, "Sachbanit_2");

datatableSachbanit_2 = dataSet1.Tables["Sachbanit_2"]; //DataRow dr = datatableSachbanit.NewRow(); dgvTienthu_pxt_4.RowsDefaultCellStyle.BackColor = Color.WhiteSmoke; dgvTienthu_pxt_4.AlternatingRowsDefaultCellStyle.BackColor = Color.White; dgvTienthu_pxt_4.DataSource = datatableSachbanit_2; } catch (Exception ex) { MessageBox.Show(ex.Message); }

private void cboManpps_5_SelectedIndexChanged(object sender, EventArgs e) { this.Manpps_5 = Convert.ToString(cboManpps_5.Text); } private void rbtnTatca_5_CheckedChanged(object sender, EventArgs e) { cboManpps_5.Enabled = false; txtTennpps_5.Enabled = false; } private void rbtnNhaPPS_5_CheckedChanged(object sender, EventArgs e) { cboManpps_5.Enabled = true; txtTennpps_5.Enabled = true; } private void btnThongke_5_Click(object sender, EventArgs e) { if (rbtnNhaPPS_5.Checked == true) { thongke_theoNHAPPS_5(); } if (rbtnTatca_5.Checked == true) { thongke_theoTATCA_5(); } } private void thongke_theoTATCA_5() { try { string str_dgvSach = @"SELECT NHAPPS.MANPPS, TENNPPS, PHIEUNHAP.SOPHIEUNHAP, PHIEUNHAP.NGAYLAPPN, PHIEUNHAP.THANHTIENNHAP FROM NHAPPS, PHIEUNHAP WHERE NHAPPS.MANPPS=PHIEUNHAP.MANPPS"; OleDbCommand cmddgvSach = new OleDbCommand(str_dgvSach, con); adapter = new OleDbDataAdapter(); adapter.SelectCommand = cmddgvSach; adapter.SelectCommand.Connection = con; dataSet1 = new DataSet(); DataTable datatabledgvSach = new DataTable(); adapter.Fill(dataSet1, "dgvSach"); datatabledgvSach = dataSet1.Tables["dgvSach"]; DataRow dr = datatabledgvSach.NewRow(); dr["TENNPPS"] = "Tong cong".ToString(); dr["THANHTIENNHAP"] = dataSet1.Tables["dgvSach"].Compute("Sum(THANHTIENNHAP)", null); datatabledgvSach.Rows.Add(dr); dgvChitien_5.RowsDefaultCellStyle.BackColor = Color.WhiteSmoke; dgvChitien_5.AlternatingRowsDefaultCellStyle.BackColor = Color.White; dgvChitien_5.DataSource = datatabledgvSach;

string str_dgvHoadonban = @"SELECT PHIEUCHI.SOPHIEUNHAP,NHAPPS.TENNPPS, SUM(PHIEUCHI.SOTIENCHI) AS SOTIENDACHI, MIN(PHIEUCHI.NOTON) AS NOTON FROM PHIEUCHI, PHIEUNHAP, NHAPPS WHERE PHIEUCHI.SOPHIEUNHAP=PHIEUNHAP.SOPHIEUNHAP AND NHAPPS.MANPPS=PHIEUNHAP.MANPPS GROUP BY PHIEUCHI.SOPHIEUNHAP, NHAPPS.TENNPPS"; OleDbCommand cmddgvHoadonban = new OleDbCommand(str_dgvHoadonban, con); adapter = new OleDbDataAdapter(); adapter.SelectCommand = cmddgvHoadonban; adapter.SelectCommand.Connection = con; dataSet1 = new DataSet(); DataTable datatabledgvHoadonban = new DataTable(); adapter.Fill(dataSet1, "dgvHoadonban"); datatabledgvHoadonban = dataSet1.Tables["dgvHoadonban"]; DataRow drdgvHoadonban = datatabledgvHoadonban.NewRow(); drdgvHoadonban["TENNPPS"] = "Tong cong".ToString(); drdgvHoadonban["SOTIENDACHI"] = dataSet1.Tables["dgvHoadonban"].Compute("Sum(SOTIENDACHI)", null); drdgvHoadonban["NOTON"] = dataSet1.Tables["dgvHoadonban"].Compute("Sum(NOTON)", null); datatabledgvHoadonban.Rows.Add(drdgvHoadonban); dgvPhieuchi_5.RowsDefaultCellStyle.BackColor = Color.WhiteSmoke; dgvPhieuchi_5.AlternatingRowsDefaultCellStyle.BackColor = Color.White; dgvPhieuchi_5.DataSource = datatabledgvHoadonban; } catch (Exception ex) { MessageBox.Show(ex.Message); } } private void thongke_theoNHAPPS_5() { this.Manpps_5 = Convert.ToString(cboManpps_5.Text); try { string str_dgvSach = @"SELECT NHAPPS.MANPPS, TENNPPS, PHIEUNHAP.SOPHIEUNHAP, PHIEUNHAP.NGAYLAPPN, PHIEUNHAP.THANHTIENNHAP FROM NHAPPS, PHIEUNHAP WHERE NHAPPS.MANPPS=PHIEUNHAP.MANPPS AND NHAPPS.MANPPS="+int.Parse(this.Manpps_5.ToString())+""; OleDbCommand cmddgvSach = new OleDbCommand(str_dgvSach, con); adapter = new OleDbDataAdapter(); adapter.SelectCommand = cmddgvSach; adapter.SelectCommand.Connection = con; dataSet1 = new DataSet(); DataTable datatabledgvSach = new DataTable(); adapter.Fill(dataSet1, "dgvSach"); datatabledgvSach = dataSet1.Tables["dgvSach"]; DataRow dr = datatabledgvSach.NewRow(); dr["TENNPPS"] = "Tong cong".ToString(); dr["THANHTIENNHAP"] = dataSet1.Tables["dgvSach"].Compute("Sum(THANHTIENNHAP)", null); datatabledgvSach.Rows.Add(dr); dgvChitien_5.RowsDefaultCellStyle.BackColor = Color.WhiteSmoke; dgvChitien_5.AlternatingRowsDefaultCellStyle.BackColor = Color.White; dgvChitien_5.DataSource = datatabledgvSach; string str_dgvHoadonban = @"SELECT PHIEUCHI.SOPHIEUNHAP,NHAPPS.TENNPPS, SUM(PHIEUCHI.SOTIENCHI) AS SOTIENDACHI, MIN(PHIEUCHI.NOTON) AS NOTON FROM PHIEUCHI, PHIEUNHAP, NHAPPS

WHERE PHIEUCHI.SOPHIEUNHAP=PHIEUNHAP.SOPHIEUNHAP AND NHAPPS.MANPPS=PHIEUNHAP.MANPPS AND NHAPPS.MANPPS="+int.Parse(this.Manpps_5.ToString())+@" GROUP BY PHIEUCHI.SOPHIEUNHAP, NHAPPS.TENNPPS"; OleDbCommand cmddgvHoadonban = new OleDbCommand(str_dgvHoadonban, con); adapter = new OleDbDataAdapter(); adapter.SelectCommand = cmddgvHoadonban; adapter.SelectCommand.Connection = con; dataSet1 = new DataSet(); DataTable datatabledgvHoadonban = new DataTable(); adapter.Fill(dataSet1, "dgvHoadonban"); datatabledgvHoadonban = dataSet1.Tables["dgvHoadonban"]; DataRow drdgvHoadonban = datatabledgvHoadonban.NewRow(); drdgvHoadonban["TENNPPS"] = "Tong cong".ToString(); drdgvHoadonban["SOTIENDACHI"] = dataSet1.Tables["dgvHoadonban"].Compute("Sum(SOTIENDACHI)", null); drdgvHoadonban["NOTON"] = dataSet1.Tables["dgvHoadonban"].Compute("Sum(NOTON)", null); datatabledgvHoadonban.Rows.Add(drdgvHoadonban); dgvPhieuchi_5.RowsDefaultCellStyle.BackColor = Color.WhiteSmoke; dgvPhieuchi_5.AlternatingRowsDefaultCellStyle.BackColor = Color.White; dgvPhieuchi_5.DataSource = datatabledgvHoadonban; } catch (Exception ex) { MessageBox.Show(ex.Message); } } private void btnThoat_5_Click(object sender, EventArgs e) { con.Close(); this.Close(); } private void btnTim_5_Click(object sender, EventArgs e) { if (rbtnChitienitnhat_5.Checked == true) { timChitien_it_5(); } if (rbtnChitiennhiaunhat_5.Checked == true) { timChitien_nhieu_5(); } } private void timChitien_nhieu_5() { try { // string str_sachbanit = @"SELECT SACH.TENSACH, SUM(BAN_SACH.SLUONGBAN) AS TONGSLBAN // FROM BAN_SACH, SACH // WHERE BAN_SACH.MASACH=SACH.MASACH // GROUP BY SACH.TENSACH // HAVING SUM(BAN_SACH.SLUONGBAN)=(SELECT MIN(SL) FROM ( // SELECT SUM(BAN_SACH.SLUONGBAN) AS SL FROM BAN_SACH, SACH WHERE BAN_SACH.MASACH=SACH.MASACH GROUP BY SACH.TENSACH))"; string str_sachbanit = @"SELECT NHAPPS.TENNPPS, SUM(PHIEUCHI.SOTIENCHI) AS TONGSOTIENCHI, MIN(PHIEUCHI.NOTON) AS NOTON FROM NHAPPS, PHIEUCHI, PHIEUNHAP WHERE NHAPPS.MANPPS=PHIEUNHAP.MANPPS AND PHIEUNHAP.SOPHIEUNHAP=PHIEUCHI.SOPHIEUNHAP GROUP BY NHAPPS.TENNPPS ORDER BY SUM(PHIEUCHI.SOTIENCHI) DESC";

} catch (Exception ex) { MessageBox.Show(ex.Message); } }

OleDbCommand cmd_timsachbanit = new OleDbCommand(str_sachbanit, con); adapter = new OleDbDataAdapter(); adapter.SelectCommand = cmd_timsachbanit; adapter.SelectCommand.Connection = con; dataSet1 = new DataSet(); DataTable datatableSachbanit = new DataTable(); adapter.Fill(dataSet1, "Sachbanit"); datatableSachbanit = dataSet1.Tables["Sachbanit"]; //DataRow dr = datatableSachbanit.NewRow(); dgvTimchitien_5.RowsDefaultCellStyle.BackColor = Color.WhiteSmoke; dgvTimchitien_5.AlternatingRowsDefaultCellStyle.BackColor = Color.White; dgvTimchitien_5.DataSource = datatableSachbanit;

private void timChitien_it_5() { try { // string str_sachbanit = @"SELECT SACH.TENSACH, SUM(BAN_SACH.SLUONGBAN) AS TONGSLBAN // FROM BAN_SACH, SACH // WHERE BAN_SACH.MASACH=SACH.MASACH // GROUP BY SACH.TENSACH // HAVING SUM(BAN_SACH.SLUONGBAN)=(SELECT MIN(SL) FROM ( // SELECT SUM(BAN_SACH.SLUONGBAN) AS SL FROM BAN_SACH, SACH WHERE BAN_SACH.MASACH=SACH.MASACH GROUP BY SACH.TENSACH))"; string str_sachbanit = @"SELECT NHAPPS.TENNPPS, SUM(PHIEUCHI.SOTIENCHI) AS TONGSOTIENCHI, MIN(PHIEUCHI.NOTON) AS NOTON FROM NHAPPS, PHIEUCHI, PHIEUNHAP WHERE NHAPPS.MANPPS=PHIEUNHAP.MANPPS AND PHIEUNHAP.SOPHIEUNHAP=PHIEUCHI.SOPHIEUNHAP GROUP BY NHAPPS.TENNPPS ORDER BY SUM(PHIEUCHI.SOTIENCHI) ASC"; OleDbCommand cmd_timsachbanit = new OleDbCommand(str_sachbanit, con); adapter = new OleDbDataAdapter(); adapter.SelectCommand = cmd_timsachbanit; adapter.SelectCommand.Connection = con; dataSet1 = new DataSet(); DataTable datatableSachbanit = new DataTable(); adapter.Fill(dataSet1, "Sachbanit"); datatableSachbanit = dataSet1.Tables["Sachbanit"]; //DataRow dr = datatableSachbanit.NewRow(); dgvTimchitien_5.RowsDefaultCellStyle.BackColor = Color.WhiteSmoke; dgvTimchitien_5.AlternatingRowsDefaultCellStyle.BackColor = Color.White; dgvTimchitien_5.DataSource = datatableSachbanit; } catch (Exception ex) { MessageBox.Show(ex.Message); } } } }

Nt bo co c chn:

Code:
namespace NL2 { public partial class frm_BaoCao : Form { private OleDbConnection con; private OleDbDataAdapter adapter; private DateTime tungay, denngay; public frm_BaoCao() { InitializeComponent(); con = new OleDbConnection(); ConnectDB conDB = new ConnectDB(); con = conDB.getConn(); con.Open(); } private DateTime Tungay { get { return tungay;

} set { tungay = value; }

private DateTime Denngay { get { return denngay; } set { denngay = value; } } private void btnLapBaoCao_Click(object sender, EventArgs e) { if (rbtnSachban.Checked == true) { // OleDbCommand cmd = new OleDbCommand(); // cmd.CommandType = CommandType.Text; // cmd.CommandText = @"select SACH.TENSACH, SUM(BAN_SACH.SLUONGBAN) AS SL, SUM(BAN_SACH.DGIABAN) AS DG from SACH, BAN_SACH // WHERE SACH.MASACH=BAN_SACH.MASACH // GROUP BY SACH.TENSACH"; // cmd.Connection = con; // adapter = new OleDbDataAdapter(); // adapter.SelectCommand = cmd; // adapter.SelectCommand.Connection = con; // DataSet ds = new DataSet(); // adapter.Fill(ds, "SACHBAN"); // DataTable dataTable1 = new DataTable(); // dataTable1 = ds.Tables["SACHBAN"]; CrystalReport1 obj = new CrystalReport1(); //obj.SetDataSource(dataTable1); crystalReportViewer1.ReportSource = obj; crystalReportViewer1.Refresh(); } if (rbtnDoanhthutheongay.Checked == true) { try { //this.Tungay = dtpTungay.Value.Date; //this.Denngay = dtpDenngay.Value.Date; // OleDbCommand cmd = new OleDbCommand(); // cmd.CommandType = CommandType.Text; // cmd.CommandText = @"select NGAYLAPHD, TONGSLBAN, TONGDGIACHUATHUE, THANHTIENDATHUE FROM HOADONBAN // WHERE NGAYLAPHD between #" + this.Tungay + "# and #" + this.Denngay + "#"; // cmd.Connection = con; // adapter = new OleDbDataAdapter(); // adapter.SelectCommand = cmd; // adapter.SelectCommand.Connection = con; // DataSet ds = new DataSet(); // adapter.Fill(ds, "SACHBAN"); // DataTable dataTable1 = new DataTable(); // dataTable1 = ds.Tables["SACHBAN"]; //ReportDocument cryRpt = new ReportDocument(); //cryRpt.Load("C:\\Documents and Settings\\Administrator\\My Documents\\Visual Studio 2008\\Projects\\NL2\\NL2\\CrystalReport2.rpt"); //ParameterFieldDefinitions crParameterFieldDefinitions; //ParameterFieldDefinition crParameterFieldDefinition; //ParameterValues crParameterValues=new ParameterValues();

//ParameterDiscreteValue crParameterDiscreteValue=new ParameterDiscreteValue(); //crParameterDiscreteValue.Value=this.Tungay; //crParameterFieldDefinitions=cryRpt.DataDefinition.ParameterFields; //crParameterFieldDefinition =crParameterFieldDefinitions["start"]; //crParameterValues=crParameterFieldDefinition.CurrentValues; //crParameterValues.Clear(); //crParameterValues.Add(crParameterDiscreteValue); //crParameterFieldDefinition.ApplyCurrentValues(crParameterValues); //crParameterDiscreteValue.Value=this.Denngay; //crParameterFieldDefinitions=cryRpt.DataDefinition.ParameterFields; //crParameterFieldDefinition=crParameterFieldDefinitions["end"]; //crParameterValues=crParameterFieldDefinition.CurrentValues; //crParameterValues.Add(crParameterDiscreteValue); //crParameterFieldDefinition.ApplyCurrentValues(crParameterValues);

CrystalReport2 obj = new CrystalReport2(); crystalReportViewer1.ReportSource = obj; crystalReportViewer1.Refresh(); } catch (Exception ex) { MessageBox.Show(ex.Message); }

} if (rbtnDoanhthutheoKH.Checked == true) { // OleDbCommand cmd = new OleDbCommand(); // cmd.CommandType = CommandType.Text; // cmd.CommandText = @"select KHACHHANG.TENKH, HOADONBAN.TONGSLBAN, HOADONBAN.TONGDGIACHUATHUE, HOADONBAN.THANHTIENDATHUE // FROM HOADONBAN, KHACHHANG // WHERE KHACHHANG.MAKH=HOADONBAN.MAKH"; // cmd.Connection = con; // adapter = new OleDbDataAdapter(); // adapter.SelectCommand = cmd; // adapter.SelectCommand.Connection = con; // DataSet ds = new DataSet(); // adapter.Fill(ds, "SACHBAN"); // DataTable dataTable1 = new DataTable(); // dataTable1 = ds.Tables["SACHBAN"]; CrystalReport3 obj = new CrystalReport3(); // obj.SetDataSource(dataTable1); crystalReportViewer1.ReportSource = obj; crystalReportViewer1.Refresh(); } if (rbtnSachnhap.Checked == true) { // OleDbCommand cmd = new OleDbCommand(); // cmd.CommandType = CommandType.Text; // cmd.CommandText = @"select SACH.TENSACH, NHAP_SACH.SLUONG, NHAP_SACH.DONGIA // FROM NHAP_SACH, SACH // WHERE NHAP_SACH.MASACH=SACH.MASACH"; // cmd.Connection = con; // adapter = new OleDbDataAdapter(); // adapter.SelectCommand = cmd; // adapter.SelectCommand.Connection = con; // DataSet ds = new DataSet(); // adapter.Fill(ds, "SACHBAN"); // DataTable dataTable1 = new DataTable(); // dataTable1 = ds.Tables["SACHBAN"]; CrystalReport4 obj = new CrystalReport4(); // obj.SetDataSource(dataTable1);

} if (rbtnNhapsachtheongay.Checked == true) { // OleDbCommand cmd = new OleDbCommand(); // cmd.CommandType = CommandType.Text; // cmd.CommandText = @"select NGAYLAPPN, TONGSLNHAP, THANHTIENNHAP // FROM PHIEUNHAP"; // cmd.Connection = con; // adapter = new OleDbDataAdapter(); // adapter.SelectCommand = cmd; // adapter.SelectCommand.Connection = con; // DataSet ds = new DataSet(); // adapter.Fill(ds, "SACHBAN"); // DataTable dataTable1 = new DataTable(); // dataTable1 = ds.Tables["SACHBAN"]; CrystalReport5 obj = new CrystalReport5(); //obj.SetDataSource(dataTable1); crystalReportViewer1.ReportSource = obj; crystalReportViewer1.Refresh(); } if (rbtnNhapsachtheoNPPS.Checked == true) { // OleDbCommand cmd = new OleDbCommand(); // cmd.CommandType = CommandType.Text; // cmd.CommandText = @"select NHAPPS.TENNPPS, PHIEUNHAP.TONGSLNHAP, PHIEUNHAP.THANHTIENNHAP // FROM PHIEUNHAP, NHAPPS // WHERE PHIEUNHAP.MANPPS=NHAPPS.MANPPS"; // cmd.Connection = con; // adapter = new OleDbDataAdapter(); // adapter.SelectCommand = cmd; // adapter.SelectCommand.Connection = con; // DataSet ds = new DataSet(); // adapter.Fill(ds, "SACHBAN"); // DataTable dataTable1 = new DataTable(); // dataTable1 = ds.Tables["SACHBAN"]; CrystalReport6 obj = new CrystalReport6(); //obj.SetDataSource(dataTable1); crystalReportViewer1.ReportSource = obj; crystalReportViewer1.Refresh(); } if (rbtnSachxuattra.Checked == true) { // OleDbCommand cmd = new OleDbCommand(); // cmd.CommandType = CommandType.Text; // cmd.CommandText = @"select SACH.TENSACH, XUAT_TRA.SLUONGXUATTRA, XUAT_TRA.SLUONGNHAPTHUCSU // FROM SACH, XUAT_TRA // WHERE SACH.MASACH=XUAT_TRA.MASACH"; // cmd.Connection = con; // adapter = new OleDbDataAdapter(); // adapter.SelectCommand = cmd; // adapter.SelectCommand.Connection = con; // DataSet ds = new DataSet(); // adapter.Fill(ds, "SACHBAN"); // DataTable dataTable1 = new DataTable(); // dataTable1 = ds.Tables["SACHBAN"]; CrystalReport7 obj = new CrystalReport7(); //obj.SetDataSource(dataTable1); crystalReportViewer1.ReportSource = obj; crystalReportViewer1.Refresh(); } if (rbtnTienthutusachxuattra.Checked == true) {

crystalReportViewer1.ReportSource = obj; crystalReportViewer1.Refresh();

// // // // // // // // // // // //

OleDbCommand cmd = new OleDbCommand(); cmd.CommandType = CommandType.Text; cmd.CommandText = @"select NGAYLAPPXT, TIENTHU FROM PHIEUXUATTRA"; cmd.Connection = con; adapter = new OleDbDataAdapter(); adapter.SelectCommand = cmd; adapter.SelectCommand.Connection = con; DataSet ds = new DataSet(); adapter.Fill(ds, "SACHBAN"); DataTable dataTable1 = new DataTable(); dataTable1 = ds.Tables["SACHBAN"]; CrystalReport8 obj = new CrystalReport8(); // obj.SetDataSource(dataTable1); crystalReportViewer1.ReportSource = obj; crystalReportViewer1.Refresh(); } if (rbtnChitien_noton.Checked == true) { // OleDbCommand cmd = new OleDbCommand(); // cmd.CommandType = CommandType.Text; // cmd.CommandText = @"select NHAPPS.TENNPPS, PHIEUCHI.SOTIENCHI, PHIEUCHI.NOTON // FROM PHIEUCHI, NHAPPS, PHIEUNHAP // WHERE PHIEUCHI.SOPHIEUNHAP=PHIEUNHAP.SOPHIEUNHAP AND PHIEUNHAP.MANPPS=NHAPPS.MANPPS"; // cmd.Connection = con; // adapter = new OleDbDataAdapter(); // adapter.SelectCommand = cmd; // adapter.SelectCommand.Connection = con; // DataSet ds = new DataSet(); // adapter.Fill(ds, "SACHBAN"); // DataTable dataTable1 = new DataTable(); // dataTable1 = ds.Tables["SACHBAN"]; CrystalReport9 obj = new CrystalReport9(); // obj.SetDataSource(dataTable1); crystalReportViewer1.ReportSource = obj; crystalReportViewer1.Refresh(); } crystalReportViewer1.Show(); } private void frm_BaoCao_Load(object sender, EventArgs e) { crystalReportViewer1.Hide(); //dtpTungay.Enabled = false; //dtpDenngay.Enabled = false; } private void rbtnDoanhthutheongay_CheckedChanged(object sender, EventArgs e) { //dtpDenngay.Enabled = true; //dtpTungay.Enabled = true; } private void rbtnSachban_CheckedChanged(object sender, EventArgs e) { //dtpTungay.Enabled = false; //dtpDenngay.Enabled = false; } private void rbtnDoanhthutheoKH_CheckedChanged(object sender, EventArgs e) { //dtpTungay.Enabled = false; //dtpDenngay.Enabled = false; }

private void rbtnSachnhap_CheckedChanged(object sender, EventArgs e) { //dtpTungay.Enabled = false; //dtpDenngay.Enabled = false; } private void rbtnNhapsachtheongay_CheckedChanged(object sender, EventArgs e) { //dtpTungay.Enabled = false; //dtpDenngay.Enabled = false; } private void rbtnNhapsachtheoNPPS_CheckedChanged(object sender, EventArgs e) { //dtpTungay.Enabled = false; //dtpDenngay.Enabled = false; } private void rbtnSachxuattra_CheckedChanged(object sender, EventArgs e) { //dtpTungay.Enabled = false; //dtpDenngay.Enabled = false; } private void rbtnChitien_noton_CheckedChanged(object sender, EventArgs e) { //dtpTungay.Enabled = false; //dtpDenngay.Enabled = false; } //private void dtpTungay_ValueChanged(object sender, EventArgs e) //{ // this.Tungay = dtpTungay.Value.Date; //} //private void dtpDenngay_ValueChanged(object sender, EventArgs e) //{ // this.Denngay = dtpDenngay.Value.Date; //} private void rbtnTienthutusachxuattra_CheckedChanged(object sender, EventArgs e) { //dtpTungay.Enabled = false; //dtpDenngay.Enabled = false; } private void btnThoat_Click(object sender, EventArgs e) { con.Close(); crystalReportViewer1.Refresh(); this.Close(); } } }

Cch to Crystal Report bng chng trnh: t Toolbox, chn crystalReportViewer. Trn crystalReportViewer, nhn vo nt c ch trong hnh:

Chn create new crystal reportt, t tn, chn kt ni oledb (nu ang s dng kt ni oledb), chn c s d liu, chn tip cc bng, mi quan h gia cc bng, cc ct hin ra trong bo co, cc iu kin (tng ca ct no , c nhm bi ct no,). Cn biu th thm v, kt thc nhn finish. Nt chi tin c nhn:

Code:
namespace NL2 { public partial class frm_ChiTien_LapPhieuChi : Form { private OleDbConnection con; private OleDbDataAdapter adapter; BindingSource BindingSource BindingSource BindingSource phieunhapBindingSource = new BindingSource(); phieuchiBindingSource = new BindingSource(); nhappsBindingSource = new BindingSource(); nhapsachBindingSource = new BindingSource();

private string sophieuchi, sotienchi, sophieunhap, manpps; private DateTime ngaylappc; public frm_ChiTien_LapPhieuChi() { InitializeComponent(); con = new OleDbConnection(); ConnectDB conDB = new ConnectDB(); con = conDB.getConn(); con.Open(); } private void ChiTien_LapPhieuChi_Load(object sender, EventArgs e) { populateNPPS(); populatePHIEUCHI(); } private void populatePHIEUCHI() { try { OleDbCommand cmd = new OleDbCommand(); cmd.CommandType = CommandType.Text; cmd.CommandText = "select * from PHIEUCHI"; cmd.Connection = con; adapter = new OleDbDataAdapter(); adapter.SelectCommand = cmd; adapter.SelectCommand.Connection = con; //adapter.TableMappings.Add("Table", "NHAPPS"); //OleDbCommandBuilder cb = new OleDbCommandBuilder(adapter); dataSet1 = new DataSet(); adapter.Fill(dataSet1, "PC"); DataTable dataTablePC = new DataTable(); dataTablePC = dataSet1.Tables["PC"]; this.cboSophieuchi.SelectedIndexChanged -= new System.EventHandler(this.cboSophieuchi_SelectedIndexChanged); cboSophieuchi.DataSource = dataTablePC; cboSophieuchi.DisplayMember = "SOPHIEUCHI"; cboSophieuchi.ValueMember = "SOPHIEUCHI"; this.cboSophieuchi.SelectedIndexChanged += new System.EventHandler(this.cboSophieuchi_SelectedIndexChanged); txtSotienchi.DataBindings.Clear(); txtSotienchi.DataBindings.Add("Text", dataTablePC, "SOTIENCHI"); dtpNgayLappc.DataBindings.Clear(); dtpNgayLappc.DataBindings.Add("Value", dataTablePC, "NGAYLAPPC"); txtNoton.DataBindings.Clear(); txtNoton.DataBindings.Add("Text", dataTablePC, "NOTON"); txtSoPN.DataBindings.Clear(); txtSoPN.DataBindings.Add("Text", dataTablePC, "SOPHIEUNHAP"); dgvPhieuChi.DataSource = dataTablePC; } catch (Exception ex) { MessageBox.Show(ex.Message); } } private void populateNPPS() { try { OleDbCommand cmd = new OleDbCommand(); cmd.CommandType = CommandType.Text; cmd.CommandText = "select * from NHAPPS"; cmd.Connection = con;

adapter = new OleDbDataAdapter(); adapter.SelectCommand = cmd; adapter.SelectCommand.Connection = con; //adapter.TableMappings.Add("Table", "NHAPPS"); //OleDbCommandBuilder cb = new OleDbCommandBuilder(adapter); dataSet1 = new DataSet(); adapter.Fill(dataSet1, "NHAPPS"); DataTable dataTableNHAPPS = new DataTable(); dataTableNHAPPS = dataSet1.Tables["NHAPPS"]; this.cboManpps.SelectedIndexChanged -= new System.EventHandler(this.cboManpps_SelectedIndexChanged); cboManpps.DataSource = dataTableNHAPPS; cboManpps.DisplayMember = "MANPPS"; cboManpps.ValueMember = "MANPPS"; this.cboManpps.SelectedIndexChanged += new System.EventHandler(this.cboManpps_SelectedIndexChanged); txtTennpps.DataBindings.Clear(); txtTennpps.DataBindings.Add("Text", dataTableNHAPPS, "TENNPPS"); } catch (Exception ex) { MessageBox.Show(ex.Message); } } private string Manpps { get { return manpps; } set { manpps = value; } } private string Sophieuchi { get { return sophieuchi; } set { sophieuchi = value; } } private string Sotienchi { get { return sotienchi; } set { sotienchi = value; } } private string Sophieunhap { get { return sophieunhap; } set

{ } } private DateTime NgaylapPC { get { return ngaylappc; } set { ngaylappc = value; } } private void cboSophieuchi_SelectedIndexChanged(object sender, EventArgs e) { this.Sophieuchi = Convert.ToString(cboSophieuchi.Text); lbThongbao.Visible = false; lbThongbao.Enabled = false; } private void txtSotienchi_TextChanged(object sender, EventArgs e) { this.Sotienchi = txtSotienchi.Text; } private void dtpNgayLappc_ValueChanged(object sender, EventArgs e) { this.NgaylapPC = dtpNgayLappc.Value.Date; } private void txtSoPN_TextChanged(object sender, EventArgs e) { this.Sophieunhap = txtSoPN.Text; } private void btnThoat_Click(object sender, EventArgs e) { con.Close(); this.Close(); } private void btnLapPC_Click(object sender, EventArgs e) { getVariables(); int temp; temp = int.Parse(Login.NoUser); try { ChiTien ktra = new ChiTien(); if (ktra.checkInsertPhieuchi(int.Parse(this.Sophieunhap.ToString()), decimal.Parse(this.Sotienchi.ToString()))) { ChiTien capnhatPC = new ChiTien(); capnhatPC.insertTablePhieuChi(decimal.Parse(this.Sotienchi.ToString() ), this.NgaylapPC, temp, int.Parse(this.Sophieunhap.ToString())); lbThongbao.Text = "Da lap them phieu chi"; lbThongbao.Visible = true; lbThongbao.Enabled = true; } else { decimal tiendachi; sophieunhap = value;

ChiTien laytiendachi = new ChiTien(); tiendachi = laytiendachi.getTiendachi(int.Parse(this.Sophieunhap.ToString())); decimal togDgianhap; ChiTien laytongDGnhap = new ChiTien(); togDgianhap = laytongDGnhap.getTongDgianhap(int.Parse(this.Sophieunhap.ToString())); MessageBox.Show("Vuot qua so tien can chi." + " Ban da chi "+tiendachi+" va tong don gia nhap la "+togDgianhap+"."); } } catch (Exception ex) { MessageBox.Show(ex.Message + " Va khong chap nhan rong."); }

private void btnHuy_Click(object sender, EventArgs e) { } //private void btnSua_Click(object sender, EventArgs e) //{ // getVariables(); // int temp; // temp = int.Parse(Login.NoUser); // try // { // ChiTien ktra = new ChiTien(); // if (ktra.checkInsertPhieuchi(int.Parse(this.Sophieunhap.ToString()), decimal.Parse(this.Sotienchi.ToString()))) // { // ChiTien suaPC = new ChiTien(); // suaPC.updateRowOfPHIEUCHI(int.Parse(this.Sophieuchi.ToString()), decimal.Parse(this.Sotienchi.ToString()),this.NgaylapPC, temp, int.Parse(this.Sophieunhap.ToString())); // lbThongbao.Text = "Da sua phieu chi"; // lbThongbao.Visible = true; // lbThongbao.Enabled = true; // } // else // { // decimal tiendachi; // ChiTien laytiendachi = new ChiTien(); // tiendachi = laytiendachi.getTiendachi(int.Parse(this.Sophieunhap.ToString())); // decimal togDgianhap; // ChiTien laytongDGnhap = new ChiTien(); // togDgianhap = laytongDGnhap.getTongDgianhap(int.Parse(this.Sophieunhap.ToString())); // MessageBox.Show("Vuot qua so tien can chi." + " Ban da chi " + tiendachi + " va tong don gia nhap la " + togDgianhap + "."); // } // // // // // //} } catch (Exception ex) { MessageBox.Show(ex.Message + " Va khong chap nhan rong."); }

private void btnXoa_Click(object sender, EventArgs e) { this.Sophieuchi = Convert.ToString(cboSophieuchi.Text);

ChiTien ktra = new ChiTien(); try { if (ktra.checkXoaPhieuchi(int.Parse(this.Sophieuchi))) { DialogResult result; result = MessageBox.Show("Co chac ban muon xoa?", "Thong bao", MessageBoxButtons.YesNoCancel); if (result == DialogResult.No) { } else if (result == DialogResult.Yes) { ChiTien xoapc = new ChiTien(); xoapc.deleteRowOfPHIEUCHI(int.Parse(this.Sophieuchi)); MessageBox.Show("Da xoa", "Thong Bao"); resetField(); } else { } } else { MessageBox.Show("Khong xoa duoc thong tin con can cho phieu nhap", "thong bao", MessageBoxButtons.OK); } } catch (Exception ex) { MessageBox.Show(ex.Message); } } public void resetField() { cboSophieuchi.SelectedIndex = 0; txtSotienchi.Text = null; dtpNgayLappc.Value = DateTime.Today; txtNoton.Text = null; txtSoPN.Text = null; } private void getVariables() { this.Sophieuchi = Convert.ToString(cboSophieuchi.Text); this.Sotienchi = txtSotienchi.Text; this.NgaylapPC = dtpNgayLappc.Value.Date; this.Sophieunhap = txtSoPN.Text; } private void txtNoton_TextChanged(object sender, EventArgs e) { } private void txtSotienchi_KeyPress(object sender, KeyPressEventArgs e) { if ((e.KeyChar < '0') || (e.KeyChar > '9')) { e.Handled = true; } } private void txtSoPN_KeyPress(object sender, KeyPressEventArgs e) { if ((e.KeyChar < '0') || (e.KeyChar > '9')) {

e.Handled = true; } }

private void cboManpps_SelectedIndexChanged(object sender, EventArgs e) { this.Manpps = Convert.ToString(cboManpps.Text); } private void btnXemchitiet_Click(object sender, EventArgs e) { xemchitiet_NHAPPS(); } private void xemchitiet_NHAPPS() { this.Manpps = Convert.ToString(cboManpps.Text); try { string str_sachbanit = @"SELECT PHIEUNHAP.SOPHIEUNHAP, PHIEUNHAP.THANHTIENNHAP, NHAPPS.MANPPS, NHAPPS.TENNPPS, NHAPPS.DIACHI, NHAPPS.NGUOIDAIDIEN, NHAPPS.DIENTHOAI, NHAPPS.FAX, NHAPPS.MOBILE, NHAPPS.EMAIL, NHAPPS.MASOTHUE FROM NHAPPS, PHIEUNHAP WHERE NHAPPS.MANPPS=PHIEUNHAP.MANPPS AND NHAPPS.MANPPS="+int.Parse(this.Manpps.ToString())+""; OleDbCommand cmd_timsachbanit = new OleDbCommand(str_sachbanit, con); adapter = new OleDbDataAdapter(); adapter.SelectCommand = cmd_timsachbanit; adapter.SelectCommand.Connection = con; dataSet1 = new DataSet(); DataTable datatableSachbanit = new DataTable(); adapter.Fill(dataSet1, "Sachbanit"); datatableSachbanit = dataSet1.Tables["Sachbanit"]; //DataRow dr = datatableSachbanit.NewRow(); dgvNhaPPS.DataSource = datatableSachbanit; string str_nhap = @"SELECT PHIEUNHAP.SOPHIEUNHAP, NHAPPS.TENNPPS, PHIEUNHAP.THANHTIENNHAP, PHIEUNHAP.NGAYLAPPN, SUM(PHIEUCHI.SOTIENCHI) AS TONGTIENDACHI, MIN(PHIEUCHI.NOTON) AS NOTON, PHIEUCHI.NGAYLAPPC FROM PHIEUNHAP, PHIEUCHI, NHAPPS WHERE NHAPPS.MANPPS=PHIEUNHAP.MANPPS AND PHIEUCHI.SOPHIEUNHAP=PHIEUNHAP.SOPHIEUNHAP AND NHAPPS.MANPPS="+int.Parse(this.Manpps.ToString())+@" GROUP BY PHIEUNHAP.SOPHIEUNHAP, NHAPPS.TENNPPS, PHIEUNHAP.THANHTIENNHAP, PHIEUNHAP.NGAYLAPPN,PHIEUCHI.NGAYLAPPC"; OleDbCommand cmd_nhap = new OleDbCommand(str_nhap, con); adapter = new OleDbDataAdapter(); adapter.SelectCommand = cmd_nhap; adapter.SelectCommand.Connection = con; dataSet1 = new DataSet(); DataTable datatablenhap = new DataTable(); adapter.Fill(dataSet1, "nhap"); datatablenhap = dataSet1.Tables["nhap"]; //DataRow dr = datatableSachbanit.NewRow(); DataRow drnhap = datatablenhap.NewRow(); drnhap["TENNPPS"] = "Tong cong".ToString(); drnhap["TONGTIENDACHI"] = dataSet1.Tables["nhap"].Compute("Sum(TONGTIENDACHI)", null); drnhap["NOTON"] = dataSet1.Tables["nhap"].Compute("Sum(NOTON)", null); datatablenhap.Rows.Add(drnhap);

} } }

dgvNhapSach.DataSource = datatablenhap; } catch (Exception ex) { MessageBox.Show(ex.Message); }

Nt phn quyn c nhn:

Mc gn nhm c chn:

Mc cp nht thng tin nhn vin c chn, form mi hin ra:

Code:

namespace NL2 { public partial class frm_PhanQuyen_TTNhanVien : Form { private OleDbConnection con; private OleDbDataAdapter adapter; private string manv, tennv, dchinv, dthoainv, chucvunv, cmnd, email; public frm_PhanQuyen_TTNhanVien() { InitializeComponent(); con = new OleDbConnection(); ConnectDB conDB = new ConnectDB(); con = conDB.getConn();

con.Open(); } private void PhanQuyen_TTNhanVien_Load(object sender, EventArgs e) { populateNHANVIEN(); } private string Manv { get { return manv; } set { manv = value; } } private string Tennv { get { return tennv; } set { tennv = value; } } private string Dchinv { get { return dchinv; } set { dchinv = value; } } private string Dthoainv { get { return dthoainv; } set { dthoainv = value; } } private string Chucvunv { get { return chucvunv; } set { chucvunv = value; }

} private string Cmnd { get { return cmnd; } set { cmnd = value; } } private string Email { get { return email; } set { email = value; } } private void populateNHANVIEN() { try { //int kiemtrarong; OleDbCommand cmd1 = new OleDbCommand(); cmd1.CommandType = CommandType.Text; cmd1.CommandText = "SELECT * FROM NHANVIEN"; cmd1.Connection = con; object result = cmd1.ExecuteScalar(); if (result == null && result == DBNull.Value) { } else {

OleDbCommand cmd = new OleDbCommand(); cmd.CommandType = CommandType.Text; cmd.CommandText = "select * from NHANVIEN"; cmd.Connection = con; adapter = new OleDbDataAdapter(); adapter.SelectCommand = cmd; adapter.SelectCommand.Connection = con; dataSet1 = new DataSet(); adapter.Fill(dataSet1, "NHANVIEN"); DataTable dataTable1 = new DataTable(); dataTable1 = dataSet1.Tables["NHANVIEN"]; cboManv.DataSource = dataTable1; cboManv.DisplayMember = "MANV"; txtTenNV.DataBindings.Clear(); txtTenNV.DataBindings.Add("Text", dataTable1, "TENNV"); txtDiaChi.DataBindings.Clear(); txtDiaChi.DataBindings.Add("Text", dataTable1, "DCHINV"); txtDienThoai.DataBindings.Clear(); txtDienThoai.DataBindings.Add("Text", dataTable1, "DTHOAINV"); txtChucVu.DataBindings.Clear(); txtChucVu.DataBindings.Add("Text", dataTable1, "CHUCVUNV"); txtCMND.DataBindings.Clear(); txtCMND.DataBindings.Add("Text", dataTable1, "CMND"); txtEmail.DataBindings.Clear();

} } catch (Exception ex) { MessageBox.Show(ex.Message); }

txtEmail.DataBindings.Add("Text", dataTable1, "EMAIL"); dgvNhanVien.DataSource = dataTable1;

private void cboManv_SelectedIndexChanged(object sender, EventArgs e) { this.Manv = Convert.ToString(cboManv.Text); lbThongbao.Visible = false; lbThongbao.Enabled = false; } private void txtTenNV_TextChanged(object sender, EventArgs e) { this.Tennv = txtTenNV.Text; } private void txtDiaChi_TextChanged(object sender, EventArgs e) { this.Dchinv = txtDiaChi.Text; } private void txtDienThoai_TextChanged(object sender, EventArgs e) { this.Dthoainv = txtDienThoai.Text; } private void txtChucVu_TextChanged(object sender, EventArgs e) { this.Chucvunv = txtChucVu.Text; } private void txtCMND_TextChanged(object sender, EventArgs e) { this.Cmnd = txtCMND.Text; } private void txtEmail_TextChanged(object sender, EventArgs e) { this.Email = txtEmail.Text; } private void btnThem_Click(object sender, EventArgs e) { getVariableNhanvien(); try { PhanQuyen themNV = new PhanQuyen(); themNV.insertTableNHANVIEN(this.Tennv.ToString(), this.Dchinv.ToString(), this.Dthoainv.ToString(), this.Chucvunv.ToString(), this.Cmnd.ToString(), this.Email.ToString()); lbThongbao.Text = "Da them"; lbThongbao.Visible = true; lbThongbao.Enabled = true; } catch (Exception ex) { MessageBox.Show(ex.Message+" Khong chap nhan rong."); } }

public void getVariableNhanvien() { this.Manv = Convert.ToString(cboManv.Text); this.Tennv = txtTenNV.Text; this.Dchinv = txtDiaChi.Text; this.Dthoainv = txtDienThoai.Text; this.Chucvunv = txtChucVu.Text; this.Cmnd = txtCMND.Text; this.Email = txtEmail.Text; } private void btnThoat_Click(object sender, EventArgs e) { con.Close(); this.Close(); } private void btnSua_Click(object sender, EventArgs e) { try { PhanQuyen suaTTNV = new PhanQuyen(); suaTTNV.updateRowOfNHANVIEN(int.Parse(this.Manv.ToString()), this.Tennv.ToString(), this.Dchinv.ToString(), this.Dthoainv.ToString(), this.Chucvunv.ToString(), this.Cmnd.ToString(), this.Email.ToString()); lbThongbao.Text = "Da sua"; lbThongbao.Visible = true; lbThongbao.Enabled = true; } catch (Exception ex) { MessageBox.Show(ex.Message + " Khong chap nhan rong"); } } private void btnXoa_Click(object sender, EventArgs e) { try { int temp; temp = int.Parse(this.Manv); PhanQuyen ktra = new PhanQuyen(); if (ktra.checkXoaNHANVIEN(temp)) { DialogResult result; result = MessageBox.Show("Co chac ban muon xoa?", "Thong bao", MessageBoxButtons.YesNoCancel); if (result == DialogResult.No) { } else if (result == DialogResult.Yes) { //public void deleteRowOfNHAPPS(int manhapps) PhanQuyen xoaNV = new PhanQuyen(); xoaNV.deleteRowOfNHANVIEN(temp); MessageBox.Show("Da xoa", "Thong Bao"); } else { } } else { MessageBox.Show("Khong xoa duoc, con can thong tin cua nhan vien nay", "Thong bao", MessageBoxButtons.OK); } } catch (Exception ex)

{ } } private void txtTenNV_KeyPress(object sender, KeyPressEventArgs e) { if ((e.KeyChar >= '0') && (e.KeyChar <= '9')) { e.Handled = true; } } private void txtDienThoai_KeyPress(object sender, KeyPressEventArgs e) { if ((e.KeyChar < '0') || (e.KeyChar > '9')) { e.Handled = true; } if ((e.KeyChar == '.')) { e.Handled = false; } if ((e.KeyChar == '-')) { e.Handled = false; } if ((e.KeyChar == '(')) { e.Handled = false; } if ((e.KeyChar == ')')) { e.Handled = false; } } private void txtCMND_KeyPress(object sender, KeyPressEventArgs e) { if ((e.KeyChar < '0') || (e.KeyChar > '9')) { e.Handled = true; } } MessageBox.Show(ex.Message);

} }

Mc cp nht nh danh (username v password) c chn, form mi hin ra:

Code:

namespace NL2 { public partial class frm_PhanQuyen_DinhDanh : Form { private OleDbConnection con; //private OleDbDataAdapter adapter; BindingSource nhanvienBindingSource = new BindingSource(); BindingSource dinhdanhBindingSource = new BindingSource(); private string manv, username, password; public frm_PhanQuyen_DinhDanh() { InitializeComponent(); con = new OleDbConnection(); ConnectDB conDB = new ConnectDB(); con = conDB.getConn(); con.Open(); } private void PhanQuyen_DinhDanh_Load(object sender, EventArgs e) { GetDataPhanQuyen(); } private string Manv { get { return manv; } set { manv = value; } } private string Username {

get { } set { } }

return username;

username = value;

private string Password { get { return password; } set { password = value; } } private void GetDataPhanQuyen() { try { //create dataset DataSet data = new DataSet(); data.Locale = System.Globalization.CultureInfo.InvariantCulture; // Add data from the NHANVIEN table to the DataSet. OleDbDataAdapter masterDataAdapter = new OleDbDataAdapter("select * from NHANVIEN", con); masterDataAdapter.Fill(data, "NHANVIEN"); // Add data from the THUOCNHOM table to the DataSet. OleDbDataAdapter detailsDataAdapter = new OleDbDataAdapter("select * from DINHDANH", con); detailsDataAdapter.Fill(data, "DINHDANH"); // Establish a relationship between the two tables: NHANVIEN ANd THUOCNHOM DataRelation relation = new DataRelation("Nhanvien_dinhdanh", data.Tables["NHANVIEN"].Columns["MANV"], data.Tables["DINHDANH"].Columns["MANV"], true); data.Relations.Add(relation); // Bind the master data connector to the Customers table. nhanvienBindingSource.DataSource = data; nhanvienBindingSource.DataMember = "NHANVIEN"; // Bind the details data connector to the master data connector, // using the DataRelation name to filter the information in the // details table based on the current row in the master table. dinhdanhBindingSource.DataSource = nhanvienBindingSource; dinhdanhBindingSource.DataMember = "Nhanvien_dinhdanh"; cboMaNV.DataSource = nhanvienBindingSource; cboMaNV.DisplayMember = "MANV"; dgvNhanvien.DataSource = nhanvienBindingSource; txtUsername.DataBindings.Clear(); txtUsername.DataBindings.Add("Text", dinhdanhBindingSource, "USERNAME"); txtPassword.DataBindings.Clear(); txtPassword.DataBindings.Add("Text", dinhdanhBindingSource, "P");

} catch (Exception ex)

{ } } private void getVariablesDinhdanh() { this.Manv = Convert.ToString(cboMaNV.Text); this.Username = txtUsername.Text; this.Password = txtPassword.Text; } private void cboMaNV_SelectedIndexChanged(object sender, EventArgs e) { this.Manv = Convert.ToString(cboMaNV.Text); lbThongbao.Visible = false; lbThongbao.Enabled = false; } private void txtUsername_TextChanged(object sender, EventArgs e) { this.Username = txtUsername.Text; } private void txtPassword_TextChanged(object sender, EventArgs e) { this.Password = txtPassword.Text; } private void btnThoat_Click(object sender, EventArgs e) { con.Close(); this.Close(); } private void btnThem_Click(object sender, EventArgs e) { getVariablesDinhdanh(); try { DinhDanh ktra = new DinhDanh(); if (ktra.checkInsertDinhdanh(int.Parse(this.Manv.ToString()))) { DinhDanh themDinhdanh = new DinhDanh(); themDinhdanh.insertTableDINHDANH(int.Parse(this.Manv.ToString()), this.Username.ToString(), this.Password.ToString()); lbThongbao.Text = "Da them"; lbThongbao.Visible = true; lbThongbao.Enabled = true; } else { MessageBox.Show("Mot nhan vien chi duoc co mot dinh danh"); cboMaNV.SelectedIndex = 0; } } catch (Exception ex) { MessageBox.Show(ex.Message + " Khong chap nhan rong."); } } private void btnSua_Click(object sender, EventArgs e) { getVariablesDinhdanh(); try MessageBox.Show(ex.Message);

{ DinhDanh suaDinhdanh = new DinhDanh(); suaDinhdanh.updateRowOfDINHDANH(int.Parse(this.Manv.ToString()), this.Username.ToString(), this.Password.ToString()); lbThongbao.Text = "Da sua"; lbThongbao.Visible = true; lbThongbao.Enabled = true; } catch (Exception ex) { MessageBox.Show(ex.Message+" Khong nhan gia tri rong."); } } private void btnXoa_Click(object sender, EventArgs e) { this.Manv = Convert.ToString(cboMaNV.Text); try { DialogResult result; result = MessageBox.Show("Co chac ban muon xoa?", "Thong bao", MessageBoxButtons.YesNoCancel); if (result == DialogResult.No) { } else if (result == DialogResult.Yes) { //public void deleteRowOfNHAPPS(int manhapps) DinhDanh xoaDinhdanh=new DinhDanh(); xoaDinhdanh.deleteRowOfDINHDANH(int.Parse(this.Manv.ToString())); MessageBox.Show("Da xoa", "Thong Bao"); } else { } } catch (Exception ex) { MessageBox.Show(ex.Message); } } } }

Cc mc ph trn FormMain:

Cc Class s dng km theo: BanSach.cs


using using using using using

System; System.Collections.Generic; System.Linq; System.Text; System.Data.OleDb;

namespace NL2 { class BanSach { public void insertTableBan_Sach(int masach, int sluog, decimal dongia) { int id; int sohd; OleDbConnection con = new OleDbConnection(); ConnectDB conDB = new ConnectDB(); con = conDB.getConn(); con.Open(); string ma_id = "SELECT MAX(ID) FROM BAN_SACH"; OleDbCommand cmdma_id = new OleDbCommand(ma_id, con); object result = cmdma_id.ExecuteScalar(); if (result != null && result != DBNull.Value) { id = Convert.ToInt32(result); } else { id = 0; } cmdma_id.Dispose(); id = id + 1; string so_hd = "SELECT MAX(SOHOADON)FROM HOADONBAN"; OleDbCommand cmdso_hd = new OleDbCommand(so_hd, con); sohd = Convert.ToInt32(cmdso_hd.ExecuteScalar()); cmdso_hd.Dispose(); dongia = dongia * sluog;

string cmdString = @"INSERT INTO BAN_SACH(ID, MASACH, SOHOADON, SLUONGBAN, DGIABAN) VALUES (" + id + "," + masach + "," + sohd + "," + sluog + "," + dongia + ")"; OleDbCommand cmd = new OleDbCommand(cmdString, con); cmd.ExecuteNonQuery(); //Nho reset fields, ham nay dat trong form } public void updateTableBan_Sach(string tensach, int sluog, decimal dongia) { int id; int masach; OleDbConnection con = new OleDbConnection(); ConnectDB conDB = new ConnectDB(); con = conDB.getConn(); con.Open(); string ma_id = "SELECT MAX(ID) FROM BAN_SACH"; OleDbCommand cmdma_id = new OleDbCommand(ma_id, con); object result = cmdma_id.ExecuteScalar(); if (result != null && result != DBNull.Value) { id = Convert.ToInt32(result); } else { id = 0; } cmdma_id.Dispose(); Sach s = new Sach(); masach = s.searchMaSachOfSACH(tensach); dongia = dongia * sluog; string cmdString = @"UPDATE BAN_SACH SET MASACH = " + masach + ", SLUONGBAN = " + sluog + ", DGIABAN = " + dongia + @" WHERE ID = " + id + ""; OleDbCommand cmd = new OleDbCommand(cmdString, con); cmd.ExecuteNonQuery(); //Nho reset fields, ham nay dat trong form } public void updateTableBan_Sach_dg(decimal dongia) { int id; OleDbConnection con = new OleDbConnection(); ConnectDB conDB = new ConnectDB(); con = conDB.getConn(); con.Open(); string ma_id = "SELECT MAX(ID) FROM BAN_SACH"; OleDbCommand cmdma_id = new OleDbCommand(ma_id, con); object result = cmdma_id.ExecuteScalar(); if (result != null && result != DBNull.Value) { id = Convert.ToInt32(result); } else { id = 0; } cmdma_id.Dispose(); string cmdString = @"UPDATE BAN_SACH SET DGIABAN = " + dongia + @" WHERE ID = " + id + ""; OleDbCommand cmd = new OleDbCommand(cmdString, con);

cmd.ExecuteNonQuery(); cmd.Dispose(); //Nho reset fields, ham nay dat trong form } // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // @" // // // // // // // // // // // // // // // // // public void updateTableBan_Sach_dg(string tensach, decimal dongia) { int id; int masach; OleDbConnection con = new OleDbConnection(); ConnectDB conDB = new ConnectDB(); con = conDB.getConn(); con.Open(); string ma_id = "SELECT MAX(ID) FROM BAN_SACH"; OleDbCommand cmdma_id = new OleDbCommand(ma_id, con); object result = cmdma_id.ExecuteScalar(); if (result != null && result != DBNull.Value) { id = Convert.ToInt32(result); } else { id = 0; } cmdma_id.Dispose(); int sluog; string sl = "SELECT SUM(SLUONGBAN) FROM BAN_SACH WHERE ID="+id+""; OleDbCommand cmdma_sl = new OleDbCommand(sl, con); object resultsl = cmdma_sl.ExecuteScalar(); if (resultsl != null && resultsl != DBNull.Value) { sluog = Convert.ToInt32(resultsl); } else { sluog = 0; } cmdma_sl.Dispose(); Sach s = new Sach(); masach = s.searchMaSachOfSACH(tensach); dongia = dongia * sluog; string cmdString = @"UPDATE BAN_SACH SET MASACH = " + masach + ", SLUONGBAN = " + sluog + ", DGIABAN = " + dongia + WHERE ID = " + id + ""; OleDbCommand cmd = new OleDbCommand(cmdString, con); cmd.ExecuteNonQuery(); //Nho reset fields, ham nay dat trong form } public void updateTableBan_Sach(int masach, int sluog, decimal dongia) { int id; OleDbConnection con = new OleDbConnection(); ConnectDB conDB = new ConnectDB(); con = conDB.getConn(); con.Open(); string ma_id = "SELECT MAX(ID) FROM BAN_SACH"; OleDbCommand cmdma_id = new OleDbCommand(ma_id, con); object result = cmdma_id.ExecuteScalar(); if (result != null && result != DBNull.Value) {

// // // // // // // // // // @" // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // }

id = Convert.ToInt32(result); } else {

id = 0; } cmdma_id.Dispose(); dongia = dongia * sluog; string cmdString = @"UPDATE BAN_SACH SET MASACH = " + masach + ", SLUONGBAN = " + sluog + ", DGIABAN = " + dongia + WHERE ID = " + id + ""; OleDbCommand cmd = new OleDbCommand(cmdString, con); cmd.ExecuteNonQuery(); //Nho reset fields, ham nay dat trong form } public void insertTableBan_Sach() { int id; int sohd; OleDbConnection con = new OleDbConnection(); ConnectDB conDB = new ConnectDB(); con = conDB.getConn(); con.Open(); string ma_id = "SELECT MAX(ID) FROM BAN_SACH"; OleDbCommand cmdma_id = new OleDbCommand(ma_id, con); object result = cmdma_id.ExecuteScalar(); if (result != null && result != DBNull.Value) { id = Convert.ToInt32(result); } else { id = 0; } cmdma_id.Dispose(); id = id + 1; string so_hd = "SELECT MAX(SOHOADON)FROM HOADONBAN"; OleDbCommand cmdso_hd = new OleDbCommand(so_hd, con); sohd = Convert.ToInt32(cmdso_hd.ExecuteScalar()); cmdso_hd.Dispose(); string cmdString = @"INSERT INTO BAN_SACH(ID, SOHOADON) VALUES (" + id + "," + sohd + ")"; OleDbCommand cmd = new OleDbCommand(cmdString, con); cmd.ExecuteNonQuery(); //Nho reset fields, ham nay dat trong form }

ChiTien.cs
using using using using using

System; System.Collections.Generic; System.Linq; System.Text; System.Data.OleDb;

namespace NL2 { class ChiTien {

public void insertTablePhieuChi(decimal sotienchi, DateTime ngaylap_pc, int manv, int sophieunhap) { OleDbConnection con = new OleDbConnection(); ConnectDB conDB = new ConnectDB(); con = conDB.getConn(); con.Open(); int sophieuchi; string ma_sophieuchi = "SELECT MAX(SOPHIEUCHI) FROM PHIEUCHI"; OleDbCommand cmdma_sophieuchi = new OleDbCommand(ma_sophieuchi, con); object result = cmdma_sophieuchi.ExecuteScalar(); if (result != null && result != DBNull.Value) { sophieuchi = Convert.ToInt32(result); } else { sophieuchi = 0; } cmdma_sophieuchi.Dispose(); sophieuchi = sophieuchi + 1; decimal tiendachi; decimal Tongtiendachi; decimal tongDgianhap; decimal noton; tiendachi = getTiendachi(sophieunhap); Tongtiendachi = tiendachi + sotienchi; tongDgianhap = getTongDgianhap(sophieunhap); noton = tongDgianhap - Tongtiendachi; string cmdString = @"INSERT INTO PHIEUCHI(SOPHIEUCHI, SOTIENCHI, NGAYLAPPC, NOTON, MANV, SOPHIEUNHAP) VALUES (" + sophieuchi + "," + sotienchi + ",#" + ngaylap_pc + "#," + noton + "," + manv + "," + sophieunhap + ")"; OleDbCommand cmd = new OleDbCommand(cmdString, con); cmd.ExecuteNonQuery(); cmd.Dispose(); //Nho reset fields, ham nay dat trong form } public void insertTablePhieuchi_SauKhiLapPN(int manv) { OleDbConnection con = new OleDbConnection(); ConnectDB conDB = new ConnectDB(); con = conDB.getConn(); con.Open(); int id; string ma_id = "SELECT MAX(SOPHIEUNHAP) FROM PHIEUNHAP"; OleDbCommand cmdma_id = new OleDbCommand(ma_id, con); object result = cmdma_id.ExecuteScalar(); if (result != null && result != DBNull.Value) { id = Convert.ToInt32(result); } else { id = 0; } cmdma_id.Dispose(); int sophieuchi; string ma_sophieuchi = "SELECT MAX(SOPHIEUCHI) FROM PHIEUCHI"; OleDbCommand cmdma_sophieuchi = new OleDbCommand(ma_sophieuchi, con);

object result_spc = cmdma_sophieuchi.ExecuteScalar(); if (result_spc != null && result_spc != DBNull.Value) { sophieuchi = Convert.ToInt32(result_spc); } else { sophieuchi = 0; } cmdma_sophieuchi.Dispose(); sophieuchi = sophieuchi + 1; DateTime ngaylap; string str_ngaylap = @"SELECT NGAYLAPPN FROM PHIEUNHAP WHERE SOPHIEUNHAP="+id+""; OleDbCommand cmd_ngaylap = new OleDbCommand(str_ngaylap, con); object result_ngaylap = cmd_ngaylap.ExecuteScalar(); if (result_ngaylap != null && result_ngaylap != DBNull.Value) { ngaylap = Convert.ToDateTime(result_ngaylap); } else { ngaylap = DateTime.Today; } cmd_ngaylap.Dispose(); Decimal sotienchi = 0; Decimal noton; string str_noton = @"SELECT THANHTIENNHAP FROM PHIEUNHAP WHERE SOPHIEUNHAP=" + id + ""; OleDbCommand cmd_noton = new OleDbCommand(str_noton, con); object result_noton = cmd_noton.ExecuteScalar(); if (result_noton != null && result_noton != DBNull.Value) { noton = Convert.ToDecimal(result_noton); } else { noton = 0; } cmd_noton.Dispose(); string cmdString = @"INSERT INTO PHIEUCHI(SOPHIEUCHI, SOTIENCHI, NGAYLAPPC, NOTON, MANV, SOPHIEUNHAP) VALUES (" + sophieuchi + "," + sotienchi + ",#" + ngaylap + "#," + noton + "," + manv + "," + id + ")"; OleDbCommand cmd = new OleDbCommand(cmdString, con); cmd.ExecuteNonQuery(); cmd.Dispose(); } public void deleteRowOfPHIEUCHI(int sophieuchi) { OleDbConnection con = new OleDbConnection(); ConnectDB conDB = new ConnectDB(); con = conDB.getConn(); con.Open(); string cmdString = @"DELETE FROM PHIEUCHI WHERE SOPHIEUCHI=" + sophieuchi + ""; OleDbCommand cmd = new OleDbCommand(cmdString, con); cmd.ExecuteNonQuery(); cmd.Dispose(); //Nho reset fields, ham nay dat trong form

} public bool checkXoaPhieuchi(int sophieuchi) { OleDbConnection con = new OleDbConnection(); ConnectDB conDB = new ConnectDB(); con = conDB.getConn(); con.Open(); int sphieunhap; string str_spn = @"SELECT SOPHIEUNHAP FROM PHIEUCHI WHERE SOPHIEUCHI = "+sophieuchi+""; OleDbCommand cmd_spn = new OleDbCommand(str_spn, con); object result_sopn = cmd_spn.ExecuteScalar(); if (result_sopn != null && result_sopn != DBNull.Value) { sphieunhap = Convert.ToInt32(result_sopn); } else { sphieunhap = 0; } int pn; string str_timsoluong = @"SELECT COUNT(SOPHIEUNHAP) FROM PHIEUNHAP WHERE SOPHIEUNHAP=" + sphieunhap + ""; OleDbCommand cmd_timsoluong = new OleDbCommand(str_timsoluong, con); object result_sluong = cmd_timsoluong.ExecuteScalar(); if (result_sluong != null && result_sluong != DBNull.Value) { pn = Convert.ToInt32(result_sluong); } else { pn = 0; } if (pn > 0) { return false; } return true;

public void updateRowOfPHIEUCHI(int sophieuchi, decimal sotienchi, DateTime ngaylap_pc, int manv, int sophieunhap) { OleDbConnection con = new OleDbConnection(); ConnectDB conDB = new ConnectDB(); con = conDB.getConn(); con.Open(); decimal tiendachi; decimal Tongtiendachi; decimal tongDgianhap; decimal noton; tiendachi = getTiendachi(sophieunhap); Tongtiendachi = tiendachi + sotienchi; tongDgianhap = getTongDgianhap(sophieunhap); noton = tongDgianhap - Tongtiendachi; string cmdString = @"UPDATE PHIEUCHI SET SOTIENCHI=" + sotienchi + ", NGAYLAPPC=#"+ngaylap_pc+"#, NOTON="+noton+", MANV="+manv+", SOPHIEUNHAP="+sophieunhap+@" WHERE SOPHIEUCHI=" + sophieuchi + ""; OleDbCommand cmd = new OleDbCommand(cmdString, con);

cmd.ExecuteNonQuery(); //Nho reset fields, ham nay dat trong form

public bool checkInsertPhieuchi(int sophieunhap, decimal sotienchi) { OleDbConnection con = new OleDbConnection(); ConnectDB conDB = new ConnectDB(); con = conDB.getConn(); con.Open(); decimal tongDgianhap; string str_dongia = "SELECT SUM(DONGIA) FROM NHAP_SACH WHERE SOPHIEUNHAP = "+sophieunhap+""; OleDbCommand cmd_dongia = new OleDbCommand(str_dongia, con); object result = cmd_dongia.ExecuteScalar(); if (result != null && result != DBNull.Value) { tongDgianhap = Convert.ToInt32(result); } else { tongDgianhap = 0; } cmd_dongia.Dispose(); decimal tongtiendachi; string str_tiendachi = "SELECT SUM(SOTIENCHI) FROM PHIEUCHI WHERE SOPHIEUNHAP = "+sophieunhap+""; OleDbCommand cmd_tiendachi = new OleDbCommand(str_tiendachi, con); object result_tienchi = cmd_tiendachi.ExecuteScalar(); if (result_tienchi != null && result_tienchi != DBNull.Value) { tongtiendachi = Convert.ToInt32(result_tienchi); } else { tongtiendachi = 0; } cmd_tiendachi.Dispose(); if (sotienchi > (tongDgianhap - tongtiendachi)) { return false; } return true; } public decimal getTiendachi(int sophieunhap) { OleDbConnection con = new OleDbConnection(); ConnectDB conDB = new ConnectDB(); con = conDB.getConn(); con.Open(); decimal tongtiendachi; string str_tiendachi = "SELECT SUM(SOTIENCHI) FROM PHIEUCHI WHERE SOPHIEUNHAP = " + sophieunhap + ""; OleDbCommand cmd_tiendachi = new OleDbCommand(str_tiendachi, con); object result_tienchi = cmd_tiendachi.ExecuteScalar(); if (result_tienchi != null && result_tienchi != DBNull.Value) { tongtiendachi = Convert.ToInt32(result_tienchi); } else

{ tongtiendachi = 0; } return tongtiendachi;

public decimal getTongDgianhap(int sophieunhap) { OleDbConnection con = new OleDbConnection(); ConnectDB conDB = new ConnectDB(); con = conDB.getConn(); con.Open(); decimal tongDgianhap; string str_dongia = "SELECT SUM(THANHTIENNHAP) FROM PHIEUNHAP WHERE SOPHIEUNHAP = " + sophieunhap + ""; OleDbCommand cmd_dongia = new OleDbCommand(str_dongia, con); object result = cmd_dongia.ExecuteScalar(); if (result != null && result != DBNull.Value) { tongDgianhap = Convert.ToInt32(result); } else { tongDgianhap = 0; } cmd_dongia.Dispose(); return tongDgianhap; //Nho reset fields, ham nay dat trong form

} } }

ConnectDB.cs
using using using using using System; System.Collections.Generic; System.Linq; System.Text; System.Data.OleDb;

namespace NL2 { class ConnectDB { public ConnectDB() { } public OleDbConnection getConn() { //string connString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=E:\\H\\NienLuan2\\NL2.mdb"; string connString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\Documents and Settings\\Administrator\\My Documents\\Visual Studio 2008\\Projects\\NL2\\NL2.mdb"; return new OleDbConnection(connString); } } }

DinhDanh.cs
using using using using using

System; System.Collections.Generic; System.Linq; System.Text; System.Data.OleDb;

namespace NL2 { class DinhDanh { public void insertTableDINHDANH(int manv, string username, string password) { OleDbConnection con = new OleDbConnection(); ConnectDB conDB = new ConnectDB(); con = conDB.getConn(); con.Open(); int id; string str_id = @"SELECT MAX(MASO) FROM DINHDANH"; OleDbCommand cmdma_id = new OleDbCommand(str_id, con); object result_id = cmdma_id.ExecuteScalar(); if (result_id != null && result_id != DBNull.Value) { id = Convert.ToInt32(result_id); } else { id = 0; } id = id + 1; string cmdString = @"INSERT INTO DINHDANH (MASO, MANV, USERNAME, P) VALUES (" + id + "," + manv + ",'" + username + "','" + password + "')"; OleDbCommand cmd = new OleDbCommand(cmdString, con); cmd.ExecuteNonQuery(); //Nho reset fields, ham nay dat trong form } public bool checkInsertDinhdanh(int manv) { OleDbConnection con = new OleDbConnection(); ConnectDB conDB = new ConnectDB(); con = conDB.getConn(); con.Open(); int soluong_nv; string str_timnv = @"SELECT COUNT(MANV) FROM DINHDANH WHERE MANV=" + manv + ""; OleDbCommand cmd_timnv = new OleDbCommand(str_timnv, con); object result_nv = cmd_timnv.ExecuteScalar(); if (result_nv != null && result_nv != DBNull.Value) { soluong_nv = Convert.ToInt32(result_nv); } else { soluong_nv = 0; } if (soluong_nv > 0) { return false; } return true; } public void updateRowOfDINHDANH(int manv, string user, string p) { OleDbConnection con = new OleDbConnection(); ConnectDB conDB = new ConnectDB(); con = conDB.getConn(); con.Open(); //mot nhan vien chi co 1 dinh danh

int maso; string str_id = @"SELECT MASO FROM DINHDANH WHERE MANV=" + manv + ""; OleDbCommand cmdma_id = new OleDbCommand(str_id, con); object result_id = cmdma_id.ExecuteScalar(); if (result_id != null && result_id != DBNull.Value) { maso = Convert.ToInt32(result_id); } else { maso = 0; } string cmdString = @"UPDATE DINHDANH SET MANV=" + manv + ", USERNAME='" + user + "',P='" + p + @"' WHERE MASO=" + maso + ""; OleDbCommand cmd = new OleDbCommand(cmdString, con); cmd.ExecuteNonQuery(); //Nho reset fields, ham nay dat trong form } public void deleteRowOfDINHDANH(int manv) { OleDbConnection con = new OleDbConnection(); ConnectDB conDB = new ConnectDB(); con = conDB.getConn(); con.Open(); int maso; string str_id = @"SELECT MASO FROM DINHDANH WHERE MASO=" + manv + ""; OleDbCommand cmdma_id = new OleDbCommand(str_id, con); object result_id = cmdma_id.ExecuteScalar(); if (result_id != null && result_id != DBNull.Value) { maso = Convert.ToInt32(result_id); } else { maso = 0; } //tranh truong hop xoa lung tung string cmdString = @"DELETE FROM DINHDANH WHERE MASO=" + maso + ""; OleDbCommand cmd = new OleDbCommand(cmdString, con); cmd.ExecuteNonQuery(); //Nho reset fields, ham nay dat trong form

} } }

HoaDonBan.cs
using using using using using System; System.Collections.Generic; System.Linq; System.Text; System.Data.OleDb;

namespace NL2 { class HoaDonBan {

public void insertTableHoaDonBan(DateTime ngaylap_hd, string loaihoadon, float thuesuat, int makh, int manv) { int sohoadon; OleDbConnection con = new OleDbConnection(); ConnectDB conDB = new ConnectDB(); con = conDB.getConn(); con.Open(); string ma_sohoadon = "SELECT MAX(SOHOADON) FROM HOADONBAN"; OleDbCommand cmdma_sohoadon = new OleDbCommand(ma_sohoadon, con); object result = cmdma_sohoadon.ExecuteScalar(); if (result != null && result != DBNull.Value) { sohoadon = Convert.ToInt32(result); } else { sohoadon = 0; } cmdma_sohoadon.Dispose(); sohoadon = sohoadon + 1; string cmdString = @"INSERT INTO HOADONBAN(SOHOADON, NGAYLAPHD, LOAIHD, THUESUAT, MAKH, MANV) VALUES (" + sohoadon + ",#" + ngaylap_hd + "#,'" + loaihoadon + "'," + thuesuat + "," + makh + "," + manv + ")"; OleDbCommand cmd = new OleDbCommand(cmdString, con); cmd.ExecuteNonQuery(); //Nho reset fields, ham nay dat trong form } public void updateTableHOADONBAN_ThanhTien(int sohd,int tongslban, decimal tongDgiachuathue, decimal thanhtiendathue) { OleDbConnection con = new OleDbConnection(); ConnectDB conDB = new ConnectDB(); con = conDB.getConn(); con.Open(); string cmdString = @"UPDATE HOADONBAN SET TONGSLBAN="+tongslban+", TONGDGIACHUATHUE = " + tongDgiachuathue + ", THANHTIENDATHUE = " + thanhtiendathue + @" WHERE SOHOADON = " + sohd + ""; OleDbCommand cmd = new OleDbCommand(cmdString, con); cmd.ExecuteNonQuery(); //Nho reset fields, ham nay dat trong form } } }

KhachHang.cs
using using using using using System; System.Collections.Generic; System.Linq; System.Text; System.Data.OleDb;

namespace NL2 { class KhachHang { public void insertTableKHACHHANG(string tenkh, string diachi, string nguoidaidien, string dienthoai, string fax, string mobile, string email, string masothue) { int ma_kh; tenkh.ToUpper(); OleDbConnection con = new OleDbConnection();

ConnectDB conDB = new ConnectDB(); con = conDB.getConn(); con.Open(); string makh = "SELECT MAX(MAKH) FROM KHACHHANG"; OleDbCommand cmdma_makh = new OleDbCommand(makh, con); object result = cmdma_makh.ExecuteScalar(); if (result != null && result != DBNull.Value) { ma_kh = Convert.ToInt32(result); } else { ma_kh = 0; } ma_kh = ma_kh + 1; cmdma_makh.Dispose(); string cmdString = @"INSERT INTO KHACHHANG(MAKH, TENKH, DIACHI, NGUOIDAIDIEN, DIENTHOAI, FAX, MOBILE, EMAIL, MASOTHUE) VALUES (" + ma_kh + ",'" + tenkh + "','" + diachi + "','" + nguoidaidien + "','" + dienthoai + "','" + fax + "','" + mobile + "','" + email + "','" + masothue + "')"; OleDbCommand cmd = new OleDbCommand(cmdString, con); cmd.ExecuteNonQuery(); //Nho reset fields, ham nay dat trong form //Access need ma_npps for auto increase colunm (ID) //SQL don't need it, just INSERT INTO TableName VALUES('','ANOTHER VARIABLE'); } public void updateRowOfKHACHHANG(int makh, string tenkh, string diachi, string nguoidaidien, string dienthoai, string fax, string mobile, string email, string masothue) { OleDbConnection con = new OleDbConnection(); ConnectDB conDB = new ConnectDB(); con = conDB.getConn(); string cmdString = @"UPDATE KHACHHANG SET TENKH='" + tenkh + "', DIACHI='" + diachi + "',NGUOIDAIDIEN='" + nguoidaidien + "',DIENTHOAI='" + dienthoai + "',FAX='" + fax + "',MOBILE='" + mobile + "',EMAIL='" + email + "',MASOTHUE='" + masothue + @"' WHERE MAKH=" + makh + ""; OleDbCommand cmd = new OleDbCommand(cmdString, con); con.Open(); cmd.ExecuteNonQuery(); //Nho reset fields, ham nay dat trong form } public bool checkXoaKHACHHANG(int makh) { OleDbConnection con = new OleDbConnection(); ConnectDB conDB = new ConnectDB(); con = conDB.getConn(); con.Open(); int soluongkh; string str_timkh = @"SELECT COUNT(MAKH) FROM HOADONBAN WHERE MAKH=" + makh + ""; OleDbCommand cmd_timkh = new OleDbCommand(str_timkh, con); object result_kh = cmd_timkh.ExecuteScalar(); if (result_kh != null && result_kh != DBNull.Value) { soluongkh = Convert.ToInt32(result_kh); } else { soluongkh = 0; } if (soluongkh != 0)

{ return false; } return true;

} }

public void deleteRowOfKHACHHANG(int makh) { OleDbConnection con = new OleDbConnection(); ConnectDB conDB = new ConnectDB(); con = conDB.getConn(); string cmdString = @"DELETE FROM KHACHHANG WHERE MAKH=" + makh + ""; OleDbCommand cmd = new OleDbCommand(cmdString, con); con.Open(); cmd.ExecuteNonQuery(); //Nho reset fields, ham nay dat trong form }

KhoSach.cs
using using using using using

System; System.Collections.Generic; System.Linq; System.Text; System.Data.OleDb;

namespace NL2 { class KhoSach { /* *******************************/ public void insertTableKhoSach(string tenkho, int sluongtoida) { int makho; OleDbConnection con = new OleDbConnection(); ConnectDB conDB = new ConnectDB(); con = conDB.getConn(); con.Open(); string ma_kho = "SELECT MAX(MAKHO) FROM KHOSACH"; OleDbCommand cmdma_makho = new OleDbCommand(ma_kho, con); object result = cmdma_makho.ExecuteScalar(); if (result != null && result != DBNull.Value) { makho = Convert.ToInt32(result); } else { makho = 0; } cmdma_makho.Dispose(); makho = makho + 1; string cmdString = @"INSERT INTO KHOSACH(MAKHO, TENKHO, SOLUONGTOIDA) VALUES (" + makho + ",'"+tenkho+"',"+sluongtoida+")"; OleDbCommand cmd = new OleDbCommand(cmdString, con); cmd.ExecuteNonQuery(); //Nho reset fields, ham nay dat trong form } /* *******************************************/ public void insertTableTon_Kho(int makho, int soluongton) { int id, masach; OleDbConnection con = new OleDbConnection(); ConnectDB conDB = new ConnectDB();

con = conDB.getConn(); con.Open(); string ma_id = "SELECT MAX(ID) FROM TON_KHO"; OleDbCommand cmdma_id = new OleDbCommand(ma_id, con); object result = cmdma_id.ExecuteScalar(); if (result != null && result != DBNull.Value) { id = Convert.ToInt32(result); } else { id = 0; } cmdma_id.Dispose(); id = id + 1; string ma_sach = "SELECT MAX(MASACH) FROM SACH"; OleDbCommand cmdma_sach = new OleDbCommand(ma_sach, con); object result2 = cmdma_sach.ExecuteScalar(); if (result2 != null && result2 != DBNull.Value) { masach = Convert.ToInt32(result2); masach = masach + 1; } else { masach = 1; } //masach = Convert.ToInt32(cmdma_sach.ExecuteScalar()); cmdma_sach.Dispose(); string cmdString = @"INSERT INTO TON_KHO(ID, MASACH, MAKHO, SOLUONGTON) VALUES (" + id + "," + masach + ","+makho+","+soluongton+")"; OleDbCommand cmd = new OleDbCommand(cmdString, con); cmd.ExecuteNonQuery(); //Nho reset fields, ham nay dat trong form } public void updateRowOfTON_KHO_khibansach(int masach, int sluongban) { OleDbConnection con = new OleDbConnection(); ConnectDB conDB = new ConnectDB(); con = conDB.getConn(); con.Open(); while (sluongban != 0) { int id; string str_id = @"SELECT ID FROM TON_KHO WHERE MASACH=" + masach + "AND SOLUONGTON>0"; OleDbCommand cmdma_id = new OleDbCommand(str_id, con); object result_id = cmdma_id.ExecuteScalar(); if (result_id != null && result_id != DBNull.Value) { id = Convert.ToInt32(result_id); } else { id = 0; } int sluongton; string str_sluongton = "SELECT SOLUONGTON FROM TON_KHO WHERE ID = " + id + ""; OleDbCommand cmd_sluongton = new OleDbCommand(str_sluongton, con); object result_sluongton = cmd_sluongton.ExecuteScalar();

if (result_sluongton != null && result_sluongton != DBNull.Value) { sluongton = Convert.ToInt32(result_sluongton); } else { sluongton = 0; } sluongton = sluongton - 1; sluongban = sluongban - 1; string cmdString = @"UPDATE TON_KHO SET MASACH=" + masach + ",SOLUONGTON=" + sluongton + @" WHERE ID=" + id + ""; OleDbCommand cmd = new OleDbCommand(cmdString, con); cmd.ExecuteNonQuery(); cmd.Dispose(); cmd_sluongton.Dispose(); cmdma_id.Dispose(); } //Nho reset fields, ham nay dat trong form } // public void updateRowOfTON_KHO_khibansach(string tensach, int sluongban, decimal dongia) // { // OleDbConnection con = new OleDbConnection(); // ConnectDB conDB = new ConnectDB(); // con = conDB.getConn(); // con.Open(); // // // // // // // // // // // // // // // // // // // // id + ""; // // // // // // // // // // while (sluongban != 0) { int masach; Sach ms = new Sach(); masach = ms.searchMaSachOfSACH(tensach); int id; string str_id = @"SELECT ID FROM TON_KHO WHERE MASACH=" + masach + "AND SOLUONGTON>0"; OleDbCommand cmdma_id = new OleDbCommand(str_id, con); object result_id = cmdma_id.ExecuteScalar(); if (result_id != null && result_id != DBNull.Value) { id = Convert.ToInt32(result_id); } else { id = 0; } int sluongton; string str_sluongton = "SELECT SOLUONGTON FROM TON_KHO WHERE ID = " + OleDbCommand cmd_sluongton = new OleDbCommand(str_sluongton, con); object result_sluongton = cmd_sluongton.ExecuteScalar(); if (result_sluongton != null && result_sluongton != DBNull.Value) { sluongton = Convert.ToInt32(result_sluongton); } else { sluongton = 0; }

// // // // // // // // // // // // // // //

sluongton = sluongton - 1; sluongban = sluongban - 1; BanSach capnhatbansach = new BanSach(); capnhatbansach.updateTableBan_Sach(masach, 1, dongia); string cmdString = @"UPDATE TON_KHO SET MASACH=" + masach + ",SOLUONGTON=" + sluongton + @" WHERE ID=" + id + ""; OleDbCommand cmd = new OleDbCommand(cmdString, con); cmd.ExecuteNonQuery(); cmd.Dispose(); cmd_sluongton.Dispose(); cmdma_id.Dispose(); } //Nho reset fields, ham nay dat trong form } public bool checkTON_KHO_khibansach(int masach, int sluongban) { OleDbConnection con = new OleDbConnection(); ConnectDB conDB = new ConnectDB(); con = conDB.getConn(); con.Open(); int tongsluongton; string str_tongsl = @"SELECT SUM(SOLUONGTON) FROM TON_KHO WHERE MASACH = " + masach + ""; OleDbCommand cmd_tongsl = new OleDbCommand(str_tongsl, con); object result_tong = cmd_tongsl.ExecuteScalar(); if (result_tong != null && result_tong != DBNull.Value) { tongsluongton = Convert.ToInt32(result_tong); } else { tongsluongton = 0; } if (tongsluongton >= sluongban) { return true; } return false; }

// // // // // // // // // // // // // // // // // // // //

public bool checkTON_KHO_khibansach_tensach(string tensach, int sluongban) { OleDbConnection con = new OleDbConnection(); ConnectDB conDB = new ConnectDB(); con = conDB.getConn(); con.Open(); int tongsluongton; string str_tongsl = @"SELECT SUM(TON_KHO.SOLUONGTON) FROM TON_KHO, SACH WHERE SACH.MASACH=TON_KHO.MASACH AND SACH.TENSACH = '" + tensach + "'"; OleDbCommand cmd_tongsl = new OleDbCommand(str_tongsl, con); object result_tong = cmd_tongsl.ExecuteScalar(); if (result_tong != null && result_tong != DBNull.Value) { tongsluongton = Convert.ToInt32(result_tong); } else { tongsluongton = 0; } if (tongsluongton >= sluongban)

// // // // //

{ return true; } return false;

public bool checkTON_KHO_khibansach(string tensach, int sluongban) { OleDbConnection con = new OleDbConnection(); ConnectDB conDB = new ConnectDB(); con = conDB.getConn(); con.Open(); int tongsluongton; string str_tongsl = @"SELECT SUM(TON_KHO.SOLUONGTON) FROM TON_KHO, SACH WHERE TON_KHO.MASACH=SACH.MASACH AND SACH.TENSACH='" + tensach + "'"; OleDbCommand cmd_tongsl = new OleDbCommand(str_tongsl, con); object result_tong = cmd_tongsl.ExecuteScalar(); if (result_tong != null && result_tong != DBNull.Value) { tongsluongton = Convert.ToInt32(result_tong); } else { tongsluongton = 0; } if (tongsluongton >= sluongban) { return true; } return false; } public int laySLTON_KHO(int masach) { OleDbConnection con = new OleDbConnection(); ConnectDB conDB = new ConnectDB(); con = conDB.getConn(); con.Open(); int tongsluongton; string str_tongsl = @"SELECT SUM(SOLUONGTON) FROM TON_KHO WHERE MASACH = " + masach + ""; OleDbCommand cmd_tongsl = new OleDbCommand(str_tongsl, con); object result_tong = cmd_tongsl.ExecuteScalar(); if (result_tong != null && result_tong != DBNull.Value) { tongsluongton = Convert.ToInt32(result_tong); } else { tongsluongton = 0; } return tongsluongton; } public int laySLTON_KHO_tensach(string tensach) { OleDbConnection con = new OleDbConnection(); ConnectDB conDB = new ConnectDB(); con = conDB.getConn(); con.Open(); int tongsluongton; string str_tongsl = @"SELECT SUM(TON_KHO.SOLUONGTON) FROM TON_KHO, SACH WHERE TON_KHO.MASACH=SACH.MASACH AND SACH.TENSACH = " + tensach + "";

OleDbCommand cmd_tongsl = new OleDbCommand(str_tongsl, con); object result_tong = cmd_tongsl.ExecuteScalar(); if (result_tong != null && result_tong != DBNull.Value) { tongsluongton = Convert.ToInt32(result_tong); } else { tongsluongton = 0; } return tongsluongton; } /* ************************************/ public bool CheckSoluong(int soluong, int makho) { OleDbConnection con = new OleDbConnection(); ConnectDB conDB = new ConnectDB(); con = conDB.getConn(); con.Open(); int soluongtoida, soluongton; string str_tonkhotoida = "SELECT SOLUONGTOIDA FROM KHOSACH WHERE MAKHO=" + makho + ""; OleDbCommand cmd_tonkhotoida = new OleDbCommand(str_tonkhotoida, con); object result2 = cmd_tonkhotoida.ExecuteScalar(); if (result2 != null && result2 != DBNull.Value) { soluongtoida = Convert.ToInt32(result2); } else { soluongtoida = 100; }

string str_timsoluong = @"SELECT SUM(SOLUONGTON) FROM TON_KHO WHERE MAKHO=" + makho + ""; OleDbCommand cmd_timsoluong = new OleDbCommand(str_timsoluong, con); object result3 = cmd_timsoluong.ExecuteScalar(); if (result3 != null && result3 != DBNull.Value) { soluongton = Convert.ToInt32(result3); } else { soluongton = 0; } soluongton = soluongton + soluong; if (soluongton > soluongtoida) { return false; } return true;

/* ************************************/ public bool CheckSoluongKhisua(int soluongtoida, int makho) { OleDbConnection con = new OleDbConnection(); ConnectDB conDB = new ConnectDB(); con = conDB.getConn(); con.Open(); int soluongton; string str_timsoluong = @"SELECT SUM(SOLUONGTON) FROM TON_KHO

WHERE MAKHO=" + makho + ""; OleDbCommand cmd_timsoluong = new OleDbCommand(str_timsoluong, con); object resultsl = cmd_timsoluong.ExecuteScalar(); if (resultsl != null && resultsl != DBNull.Value) { soluongton = Convert.ToInt32(resultsl); } else { soluongton = 0; } if (soluongton > soluongtoida) { return false; } return true; } /* ***********************88*/ public bool CheckKhotrongTonkho(int makho) { OleDbConnection con = new OleDbConnection(); ConnectDB conDB = new ConnectDB(); con = conDB.getConn(); con.Open(); string str_makho = "SELECT * FROM TON_KHO WHERE MAKHO=" + makho + ""; OleDbCommand cmd_makho = new OleDbCommand(str_makho, con); object resultmk = cmd_makho.ExecuteScalar(); if (resultmk != null && resultmk != DBNull.Value) { return false; } return true; } public void deleteRowOfKHOSACH(int makho) { OleDbConnection con = new OleDbConnection(); ConnectDB conDB = new ConnectDB(); con = conDB.getConn(); string cmdString = @"DELETE FROM KHOSACH WHERE MAKHO=" + makho + ""; OleDbCommand cmd = new OleDbCommand(cmdString, con); con.Open(); cmd.ExecuteNonQuery(); //Nho reset fields, ham nay dat trong form } public void updateRowOfKHOSACH(int makho, string tenkho,int soluongtoida) { OleDbConnection con = new OleDbConnection(); ConnectDB conDB = new ConnectDB(); con = conDB.getConn(); string cmdString = @"UPDATE KHOSACH SET TENKHO='" + tenkho + "',SOLUONGTOIDA="+soluongtoida+@" WHERE MAKHO=" + makho + ""; OleDbCommand cmd = new OleDbCommand(cmdString, con); con.Open(); cmd.ExecuteNonQuery(); //Nho reset fields, ham nay dat trong form } } }

Login.cs

using using using using using

System; System.Collections.Generic; System.Linq; System.Text; System.Data.OleDb;

namespace NL2 { class Login { public static string UserName { get { return user; } //set //{ // user = value; //} } public static string NoUser { get { return nouser; } } public bool checkLogin(string name, string pass) { OleDbConnection con = new OleDbConnection(); ConnectDB conDB = new ConnectDB(); con = conDB.getConn(); string cmdString = "SELECT MANV FROM DINHDANH WHERE USERNAME='"+name+"' AND P='"+pass+"'"; OleDbCommand cmd = new OleDbCommand(cmdString,con); con.Open(); //OleDbDataReader dr = cmd.ExecuteReader(); object result = cmd.ExecuteScalar(); //if (dr.Read() && result != null && result != DBNull.Value) if (result != null && result != DBNull.Value) { nouser=Convert.ToString(result); user = name; con.Close(); return true; } con.Close(); return false; } static public string user; static public string nouser; } }

Logout.cs
using using using using using

System; System.Collections.Generic; System.Linq; System.Text; System.Data.OleDb;

namespace NL2 { class Logout { public void goLogout()

{ OleDbConnection con = new OleDbConnection(); ConnectDB conDB = new ConnectDB(); con = conDB.getConn(); con.Close(); } } }

NhapSach.cs
using using using using using

System; System.Collections.Generic; System.Linq; System.Text; System.Data.OleDb;

namespace NL2 { class NhapSach { public void insertTablePhieuNhap(DateTime ngaylap_pn, string sohdm, DateTime ngaylap_hdm, int manv, int manpps) { int sophieunhap; OleDbConnection con = new OleDbConnection(); ConnectDB conDB = new ConnectDB(); con = conDB.getConn(); con.Open(); string ma_sophieunhap = "SELECT MAX(SOPHIEUNHAP) FROM PHIEUNHAP"; OleDbCommand cmdma_sophieunhap = new OleDbCommand(ma_sophieunhap, con); object result = cmdma_sophieunhap.ExecuteScalar(); if (result != null && result != DBNull.Value) { sophieunhap = Convert.ToInt32(result); } else { sophieunhap = 0; } cmdma_sophieunhap.Dispose(); sophieunhap = sophieunhap + 1; string cmdString = @"INSERT INTO PHIEUNHAP(SOPHIEUNHAP, NGAYLAPPN, SOHDM, NGAYLAPHDM, MANV, MANPPS) VALUES ("+sophieunhap+",#" + ngaylap_pn + "#,'" + sohdm + "',#" + ngaylap_hdm + "#," + manv + "," + manpps + ")"; OleDbCommand cmd = new OleDbCommand(cmdString, con); cmd.ExecuteNonQuery(); //Nho reset fields, ham nay dat trong form } public void insertTableNhap_Sach(int sluog, decimal dongia) { int id; int sopn, masach; OleDbConnection con = new OleDbConnection(); ConnectDB conDB = new ConnectDB(); con = conDB.getConn(); con.Open(); string ma_id = "SELECT MAX(ID) FROM NHAP_SACH"; OleDbCommand cmdma_id = new OleDbCommand(ma_id, con); object result = cmdma_id.ExecuteScalar(); if (result != null && result != DBNull.Value) { id = Convert.ToInt32(result); } else

{ id = 0; } cmdma_id.Dispose(); id = id + 1; string so_pn = "SELECT MAX(SOPHIEUNHAP)FROM PHIEUNHAP"; OleDbCommand cmdso_pn = new OleDbCommand(so_pn, con); sopn = Convert.ToInt32(cmdso_pn.ExecuteScalar()); cmdso_pn.Dispose(); string ma_sach = "SELECT MAX(MASACH) FROM SACH"; OleDbCommand cmdma_sach = new OleDbCommand(ma_sach, con); object result2 = cmdma_sach.ExecuteScalar(); if (result2 != null && result2 != DBNull.Value) { masach = Convert.ToInt32(result2); masach = masach + 1; } else { masach = 1; } //masach = Convert.ToInt32(cmdma_sach.ExecuteScalar()); //masach = masach + 1; string cmdString = @"INSERT INTO NHAP_SACH(ID,SOPHIEUNHAP, MASACH, SLUONG, DONGIA) VALUES ("+id+"," + sopn + "," + masach + "," + sluog + "," + dongia + ")"; OleDbCommand cmd = new OleDbCommand(cmdString, con); cmd.ExecuteNonQuery(); //Nho reset fields, ham nay dat trong form } public void insertTableNXB(string tenNXB) { int manxb; OleDbConnection con = new OleDbConnection(); ConnectDB conDB = new ConnectDB(); con = conDB.getConn(); con.Open(); string ma_nxb = "SELECT MAX(MANXB) FROM NHAXUATBAN"; OleDbCommand cmdma_nxb = new OleDbCommand(ma_nxb, con); object result = cmdma_nxb.ExecuteScalar(); if (result != null && result != DBNull.Value) { manxb = Convert.ToInt32(result); } else { manxb = 0; } cmdma_nxb.Dispose(); manxb = manxb + 1; string cmdString = @"INSERT INTO NHAXUATBAN(MANXB, TENNXB) VALUES ("+manxb+",'" + tenNXB + "')"; OleDbCommand cmd = new OleDbCommand(cmdString, con); cmd.ExecuteNonQuery(); //Nho reset fields, ham nay dat trong form } public void insertTableLoaiSach(string tenloai) { int maloaisach; OleDbConnection con = new OleDbConnection(); ConnectDB conDB = new ConnectDB();

con = conDB.getConn(); con.Open(); string maloai = "SELECT MAX(MALOAI) FROM LOAISACH"; OleDbCommand cmdma_loai = new OleDbCommand(maloai, con); object result = cmdma_loai.ExecuteScalar(); if (result != null && result != DBNull.Value) { maloaisach = Convert.ToInt32(result); } else { maloaisach = 0; } cmdma_loai.Dispose(); maloaisach = maloaisach + 1; string cmdString = @"INSERT INTO LOAISACH(MALOAI, TENLOAI) VALUES ("+maloaisach+",'" + tenloai + "')"; OleDbCommand cmd = new OleDbCommand(cmdString, con); cmd.ExecuteNonQuery(); //Nho reset fields, ham nay dat trong form } public void insertTableNHAPPS(string tennhapps, string diachi, string nguoidaidien, string dienthoai, string fax, string mobile, string email, string masothue) { int ma_npps; tennhapps.ToUpper(); OleDbConnection con = new OleDbConnection(); ConnectDB conDB = new ConnectDB(); con = conDB.getConn(); con.Open(); string manpps = "SELECT MAX(MANPPS) FROM NHAPPS"; OleDbCommand cmdma_npps = new OleDbCommand(manpps, con); object result = cmdma_npps.ExecuteScalar(); if (result != null && result != DBNull.Value) { ma_npps = Convert.ToInt32(result); } else { ma_npps = 0; } //OleDbDataReader reader; //reader = cmdma_npps.ExecuteReader(); //if (!reader.IsDBNull(0)) ma_npps = ma_npps + 1; cmdma_npps.Dispose(); string cmdString = @"INSERT INTO NHAPPS(MANPPS, TENNPPS, DIACHI, NGUOIDAIDIEN, DIENTHOAI, FAX, MOBILE, EMAIL, MASOTHUE) VALUES ("+ma_npps+",'" + tennhapps + "','" + diachi + "','" + nguoidaidien + "','" + dienthoai + "','" + fax + "','" + mobile + "','" + email + "','" + masothue + "')"; OleDbCommand cmd = new OleDbCommand(cmdString, con); cmd.ExecuteNonQuery(); //Nho reset fields, ham nay dat trong form //Access need ma_npps for auto increase colunm (ID) //SQL don't need it, just INSERT INTO TableName VALUES('','ANOTHER VARIABLE'); } public void deleteRowOfNHAPPS(int manhapps) { OleDbConnection con = new OleDbConnection(); ConnectDB conDB = new ConnectDB(); con = conDB.getConn(); string cmdString = @"DELETE FROM NHAPPS WHERE MANPPS="+manhapps+"";

OleDbCommand cmd = new OleDbCommand(cmdString, con); con.Open(); cmd.ExecuteNonQuery(); //Nho reset fields, ham nay dat trong form

public bool checkXoaPhieunhap(int sophieunhap) { OleDbConnection con = new OleDbConnection(); ConnectDB conDB = new ConnectDB(); con = conDB.getConn(); con.Open(); int masach; int soluongton; int tongsoluongton = 0; string str_masach = @"SELECT MASACH FROM NHAP_SACH WHERE SOPHIEUNHAP = "+sophieunhap+""; OleDbCommand cmd_masach = new OleDbCommand(str_masach, con); OleDbDataReader re = cmd_masach.ExecuteReader(); if (re.HasRows == true) { while (re.Read()) { masach = Convert.ToInt32(re["MASACH"].ToString()); string str_timsoluong = @"SELECT SUM(SOLUONGTON) FROM TON_KHO WHERE MASACH=" + masach + ""; OleDbCommand cmd_timsoluong = new OleDbCommand(str_timsoluong, con); object result_sluong = cmd_timsoluong.ExecuteScalar(); if (result_sluong != null && result_sluong != DBNull.Value) { soluongton = Convert.ToInt32(result_sluong); } else { soluongton = 0; } tongsoluongton = tongsoluongton + soluongton; } } if (tongsoluongton > 0) { return false; } return true; } public bool checkDongianhap(int soluongnhap, decimal giaban, double chietkhaunhap, decimal dongianhap) { OleDbConnection con = new OleDbConnection(); ConnectDB conDB = new ConnectDB(); con = conDB.getConn(); con.Open(); decimal sotien; sotien = (soluongnhap * giaban) - (soluongnhap * giaban * decimal.Parse(chietkhaunhap.ToString())); if (sotien == dongianhap) { return true; } return false;

} public bool checkXoaNPPS(int manpps) { OleDbConnection con = new OleDbConnection(); ConnectDB conDB = new ConnectDB(); con = conDB.getConn(); con.Open(); int soluongnpps; string str_timnpps = @"SELECT COUNT(MANPPS) FROM PHIEUNHAP WHERE MANPPS=" + manpps + ""; OleDbCommand cmd_timnpps = new OleDbCommand(str_timnpps, con); object result_npps = cmd_timnpps.ExecuteScalar(); if (result_npps != null && result_npps != DBNull.Value) { soluongnpps = Convert.ToInt32(result_npps); } else { soluongnpps = 0; } if (soluongnpps != 0) { return false; } return true; } /* ***************************************/ public bool checkXoaNXB(int manxb) { OleDbConnection con = new OleDbConnection(); ConnectDB conDB = new ConnectDB(); con = conDB.getConn(); con.Open(); string str_timnxb = @"SELECT * FROM SACH WHERE MANXB=" + manxb + ""; OleDbCommand cmd_timnxb = new OleDbCommand(str_timnxb, con); object result_nxb = cmd_timnxb.ExecuteScalar(); if (result_nxb != null && result_nxb != DBNull.Value) { return false; } return true; } public void deleteRowOfPHIEUNHAP_NHAPSACH_SACH(int sophieunhap) { OleDbConnection con = new OleDbConnection(); ConnectDB conDB = new ConnectDB(); con = conDB.getConn(); con.Open(); //Chu y: thu tu cac cau truy van rat quan trong string cmdString = @"DELETE FROM PHIEUNHAP WHERE SOPHIEUNHAP=" + sophieunhap + ""; OleDbCommand cmd = new OleDbCommand(cmdString, con); cmd.ExecuteNonQuery(); string cmdString3 = @"DELETE FROM SACH WHERE MASACH IN (SELECT MASACH FROM NHAP_SACH WHERE SOPHIEUNHAP LIKE " + sophieunhap + ")"; OleDbCommand cmd3 = new OleDbCommand(cmdString3, con); cmd3.ExecuteNonQuery();

string cmdString2 = @"DELETE FROM NHAP_SACH WHERE SOPHIEUNHAP=" + sophieunhap + ""; OleDbCommand cmd2 = new OleDbCommand(cmdString2, con); cmd2.ExecuteNonQuery(); } //Nho reset fields, ham nay dat trong form

public void deleteRowOfLOAISACH(int maloai) { OleDbConnection con = new OleDbConnection(); ConnectDB conDB = new ConnectDB(); con = conDB.getConn(); string cmdString = @"DELETE FROM LOAISACH WHERE MALOAI=" + maloai + ""; OleDbCommand cmd = new OleDbCommand(cmdString, con); con.Open(); cmd.ExecuteNonQuery(); //Nho reset fields, ham nay dat trong form } public void deleteRowOfNXB(int manxb) { OleDbConnection con = new OleDbConnection(); ConnectDB conDB = new ConnectDB(); con = conDB.getConn(); string cmdString = @"DELETE FROM NHAXUATBAN WHERE MANXB=" + manxb + ""; OleDbCommand cmd = new OleDbCommand(cmdString, con); con.Open(); cmd.ExecuteNonQuery(); //Nho reset fields, ham nay dat trong form } public void updateRowOfNXB(int manxb, string tennxb) { OleDbConnection con = new OleDbConnection(); ConnectDB conDB = new ConnectDB(); con = conDB.getConn(); string cmdString = @"UPDATE NHAXUATBAN SET TENNXB='"+tennxb+@"' WHERE MANXB=" + manxb + ""; OleDbCommand cmd = new OleDbCommand(cmdString, con); con.Open(); cmd.ExecuteNonQuery(); //Nho reset fields, ham nay dat trong form } public void updateRowOfLOAISACH(int maloai, string tenloai) { OleDbConnection con = new OleDbConnection(); ConnectDB conDB = new ConnectDB(); con = conDB.getConn(); string cmdString = @"UPDATE LOAISACH SET TENLOAI='" + tenloai + @"' WHERE MALOAI=" + maloai + ""; OleDbCommand cmd = new OleDbCommand(cmdString, con); con.Open(); cmd.ExecuteNonQuery(); //Nho reset fields, ham nay dat trong form } public void updateRowOfNHAP_SACH(int sophieunhap, int masach, int soluong, decimal dongia) { OleDbConnection con = new OleDbConnection();

ConnectDB conDB = new ConnectDB(); con = conDB.getConn(); con.Open(); int id; string str_id = @"SELECT ID FROM NHAP_SACH WHERE SOPHIEUNHAP=" + sophieunhap + "AND MASACH=" + masach + ""; OleDbCommand cmdma_id = new OleDbCommand(str_id, con); object result_id = cmdma_id.ExecuteScalar(); if (result_id != null && result_id != DBNull.Value) { id = Convert.ToInt32(result_id); } else { id = 0; } //masach = Convert.ToInt32(cmdma_sach.ExecuteScalar()); string cmdString = @"UPDATE NHAP_SACH SET SLUONG=" + soluong + ", DONGIA="+dongia+@" WHERE ID=" + id + ""; OleDbCommand cmd = new OleDbCommand(cmdString, con); cmd.ExecuteNonQuery(); //Nho reset fields, ham nay dat trong form } public void updateNHAP_SACH_THANHTIENNHAP(int soluong,decimal dongianhap) { OleDbConnection con = new OleDbConnection(); ConnectDB conDB = new ConnectDB(); con = conDB.getConn(); con.Open(); int sophieunhap; string str_sophieunhap = @"SELECT MAX(SOPHIEUNHAP) FROM PHIEUNHAP"; OleDbCommand cmd_sopn = new OleDbCommand(str_sophieunhap, con); object result_sopn = cmd_sopn.ExecuteScalar(); if (result_sopn != null && result_sopn != DBNull.Value) { sophieunhap = Convert.ToInt32(result_sopn); } else { sophieunhap = 0; } cmd_sopn.Dispose(); //masach = Convert.ToInt32(cmdma_sach.ExecuteScalar()); decimal thanhtien; string str_thanhtien = @"SELECT SUM(THANHTIENNHAP) FROM PHIEUNHAP WHERE SOPHIEUNHAP=" + sophieunhap + ""; OleDbCommand cmd_thanhtien = new OleDbCommand(str_thanhtien, con); object result_thanhtien = cmd_thanhtien.ExecuteScalar(); if (result_thanhtien != null && result_thanhtien != DBNull.Value) { thanhtien = Convert.ToDecimal(result_thanhtien); } else { thanhtien = 0; } cmd_thanhtien.Dispose(); decimal tongthanhtien = thanhtien + dongianhap; //thanhtien = thanhtien + dongianhap;

int tongsl; string str_tongsl = @"SELECT SUM(TONGSLNHAP) FROM PHIEUNHAP WHERE SOPHIEUNHAP=" + sophieunhap + ""; OleDbCommand cmd_tongsl = new OleDbCommand(str_tongsl, con); object result_tongsl = cmd_tongsl.ExecuteScalar(); if (result_tongsl != null && result_tongsl != DBNull.Value) { tongsl = Convert.ToInt32(result_tongsl); } else { tongsl = 0; } cmd_tongsl.Dispose(); int tongslnhap = tongsl + soluong; string cmdString = @"UPDATE PHIEUNHAP SET TONGSLNHAP="+tongslnhap+", THANHTIENNHAP=" + tongthanhtien + @" WHERE SOPHIEUNHAP=" + sophieunhap + ""; OleDbCommand cmd = new OleDbCommand(cmdString, con); cmd.ExecuteNonQuery(); //Nho reset fields, ham nay dat trong form } public int getTongSLNhap_SoPN() { OleDbConnection con = new OleDbConnection(); ConnectDB conDB = new ConnectDB(); con = conDB.getConn(); con.Open(); int sophieunhap; string str_sophieunhap = @"SELECT MAX(SOPHIEUNHAP) FROM PHIEUNHAP"; OleDbCommand cmd_sopn = new OleDbCommand(str_sophieunhap, con); object result_sopn = cmd_sopn.ExecuteScalar(); if (result_sopn != null && result_sopn != DBNull.Value) { sophieunhap = Convert.ToInt32(result_sopn); } else { sophieunhap = 0; } cmd_sopn.Dispose(); //masach = Convert.ToInt32(cmdma_sach.ExecuteScalar()); int soluongnhap; string str_sluongnhap = @"SELECT SUM(SLUONG) FROM NHAP_SACH WHERE SOPHIEUNHAP=" + sophieunhap + ""; OleDbCommand cmd_sluongnhap = new OleDbCommand(str_sluongnhap, con); object result_sluongnhap = cmd_sluongnhap.ExecuteScalar(); if (result_sluongnhap != null && result_sluongnhap != DBNull.Value) { soluongnhap = Convert.ToInt32(result_sluongnhap); } else { soluongnhap = 0; } cmd_sluongnhap.Dispose(); } return soluongnhap;

public decimal getThanhTienNhap_SoPN() {

OleDbConnection con = new OleDbConnection(); ConnectDB conDB = new ConnectDB(); con = conDB.getConn(); con.Open(); int sophieunhap; string str_sophieunhap = @"SELECT MAX(SOPHIEUNHAP) FROM PHIEUNHAP"; OleDbCommand cmd_sopn = new OleDbCommand(str_sophieunhap, con); object result_sopn = cmd_sopn.ExecuteScalar(); if (result_sopn != null && result_sopn != DBNull.Value) { sophieunhap = Convert.ToInt32(result_sopn); } else { sophieunhap = 0; } cmd_sopn.Dispose(); //masach = Convert.ToInt32(cmdma_sach.ExecuteScalar()); decimal thanhtien; string str_thanhtien = @"SELECT SUM(THANHTIENNHAP) FROM PHIEUNHAP WHERE SOPHIEUNHAP=" + sophieunhap + ""; OleDbCommand cmd_thanhtien = new OleDbCommand(str_thanhtien, con); object result_thanhtien = cmd_thanhtien.ExecuteScalar(); if (result_thanhtien != null && result_thanhtien != DBNull.Value) { thanhtien = Convert.ToInt32(result_thanhtien); } else { thanhtien = 0; } cmd_thanhtien.Dispose(); } return thanhtien;

public void updateRowOfPHIEUNHAP(int sophieunhap, DateTime ngaylappn, string sohdm, DateTime ngaylaphdm, int manpps) { OleDbConnection con = new OleDbConnection(); ConnectDB conDB = new ConnectDB(); con = conDB.getConn(); string cmdString = @"UPDATE PHIEUNHAP SET NGAYLAPPN=#" + ngaylappn + "#, SOHDM='"+sohdm+"',NGAYLAPHDM=#"+ngaylaphdm+"#,MANPPS="+manpps+@" WHERE SOPHIEUNHAP=" + sophieunhap + ""; OleDbCommand cmd = new OleDbCommand(cmdString, con); con.Open(); cmd.ExecuteNonQuery(); //Nho reset fields, ham nay dat trong form } public void updateRowOfNHAPPS(int manpps, string tennpps, string diachi, string nguoidaidien, string dienthoai, string fax, string mobile, string email, string masothue) { OleDbConnection con = new OleDbConnection(); ConnectDB conDB = new ConnectDB(); con = conDB.getConn(); string cmdString = @"UPDATE NHAPPS SET TENNPPS='" + tennpps + "', DIACHI='" + diachi + "',NGUOIDAIDIEN='"+nguoidaidien+"',DIENTHOAI='"+dienthoai+"',FAX='"+fax+"',MOBILE='"+mobi le+"',EMAIL='"+email+"',MASOTHUE='"+masothue+@"' WHERE MANPPS=" + manpps + ""; OleDbCommand cmd = new OleDbCommand(cmdString, con);

con.Open(); cmd.ExecuteNonQuery(); //Nho reset fields, ham nay dat trong form } } }

PhanQuyen.cs
using using using using using

System; System.Collections.Generic; System.Linq; System.Text; System.Data.OleDb;

namespace NL2 { class PhanQuyen { public int PhanNhom(int manv) { int manhom; OleDbConnection con = new OleDbConnection(); ConnectDB conDB = new ConnectDB(); con = conDB.getConn(); string cmdString = "SELECT MANHOM FROM THUOCNHOM WHERE MANV=" + manv + ""; OleDbCommand cmd = new OleDbCommand(cmdString, con); con.Open(); //OleDbDataReader dr = cmd.ExecuteReader(); object result = cmd.ExecuteScalar(); //if (dr.Read() && result != null && result != DBNull.Value) if (result != null && result != DBNull.Value) { manhom = Convert.ToInt32(result); } else { manhom = 0; } con.Close(); return manhom; } public void updateRowOfTHUOCNHOM(int manv, int manhom, int timmanv, int timmanhom) { OleDbConnection con = new OleDbConnection(); ConnectDB conDB = new ConnectDB(); con = conDB.getConn(); con.Open(); int id; string str_id = @"SELECT MAX(ID) FROM THUOCNHOM WHERE MANV = " + timmanv + " AND MANHOM = " + timmanhom + ""; OleDbCommand cmdma_id = new OleDbCommand(str_id, con); object result_id = cmdma_id.ExecuteScalar(); if (result_id != null && result_id != DBNull.Value) { id = Convert.ToInt32(result_id); } else { id = 0; } //masach = Convert.ToInt32(cmdma_sach.ExecuteScalar()); string cmdString = @"UPDATE THUOCNHOM SET MANV = " + manv + ", MANHOM = " + manhom + @" WHERE ID = " + id + "";

OleDbCommand cmd = new OleDbCommand(cmdString, con); cmd.ExecuteNonQuery(); //Nho reset fields, ham nay dat trong form } public void deleteRowOfTHUOCNHOM(int manv, int manhom) { OleDbConnection con = new OleDbConnection(); ConnectDB conDB = new ConnectDB(); con = conDB.getConn(); con.Open(); int id; string str_id = @"SELECT MAX(ID) FROM THUOCNHOM WHERE MANV = " + manv + " AND MANHOM = " + manhom + ""; OleDbCommand cmdma_id = new OleDbCommand(str_id, con); object result_id = cmdma_id.ExecuteScalar(); if (result_id != null && result_id != DBNull.Value) { id = Convert.ToInt32(result_id); } else { id = 0; } string cmdString = @"DELETE FROM THUOCNHOM WHERE ID=" + id + ""; OleDbCommand cmd = new OleDbCommand(cmdString, con); cmd.ExecuteNonQuery(); //Nho reset fields, ham nay dat trong form } public void insertTableTHUOCNHOM(int manv, int manhom) { OleDbConnection con = new OleDbConnection(); ConnectDB conDB = new ConnectDB(); con = conDB.getConn(); con.Open(); int id; string str_id = @"SELECT MAX(ID) FROM THUOCNHOM"; OleDbCommand cmdma_id = new OleDbCommand(str_id, con); object result_id = cmdma_id.ExecuteScalar(); if (result_id != null && result_id != DBNull.Value) { id = Convert.ToInt32(result_id); } else { id = 0; } id = id + 1; string cmdString = @"INSERT INTO THUOCNHOM(ID, MANV, MANHOM) VALUES (" + id + "," + manv + "," + manhom + ")"; OleDbCommand cmd = new OleDbCommand(cmdString, con); cmd.ExecuteNonQuery(); //Nho reset fields, ham nay dat trong form } public bool checkInsertThuocnhom(int manv, int manhom) { OleDbConnection con = new OleDbConnection(); ConnectDB conDB = new ConnectDB(); con = conDB.getConn();

con.Open(); string str_id = @"SELECT MAX(ID) FROM THUOCNHOM WHERE MANV = " + manv + " AND MANHOM = " + manhom + ""; OleDbCommand cmdma_id = new OleDbCommand(str_id, con); object result_id = cmdma_id.ExecuteScalar(); if (result_id != null && result_id != DBNull.Value) { return false; } return true; } public bool checkManhom(int manhom) { OleDbConnection con = new OleDbConnection(); ConnectDB conDB = new ConnectDB(); con = conDB.getConn(); con.Open(); bool kq = false; string str_nhom = "SELECT MANHOM FROM NHOM WHERE MANHOM="+manhom+""; OleDbCommand cmd = new OleDbCommand(str_nhom, con); OleDbDataReader re = cmd.ExecuteReader(); if (re.HasRows == true) { kq = true; } re.Close(); return kq;

public void insertTableNHANVIEN(string tennv, string dchinv, string dthoainv, string chucvunv, string cmnd, string email) { int ma_nv; tennv.ToUpper(); OleDbConnection con = new OleDbConnection(); ConnectDB conDB = new ConnectDB(); con = conDB.getConn(); con.Open(); string str_manv = "SELECT MAX(MANV) FROM NHANVIEN"; OleDbCommand cmdma_nv = new OleDbCommand(str_manv, con); object result = cmdma_nv.ExecuteScalar(); if (result != null && result != DBNull.Value) { ma_nv = Convert.ToInt32(result); } else { ma_nv = 0; } //OleDbDataReader reader; //reader = cmdma_npps.ExecuteReader(); //if (!reader.IsDBNull(0)) ma_nv = ma_nv + 1; cmdma_nv.Dispose(); string cmdString = @"INSERT INTO NHANVIEN(MANV, TENNV, DCHINV, DTHOAINV, CHUCVUNV, CMND, EMAIL) VALUES (" + ma_nv + ",'" + tennv + "','" + dchinv + "','" + dthoainv + "','" + chucvunv + "','" + cmnd + "','" + email + "')"; OleDbCommand cmd = new OleDbCommand(cmdString, con); cmd.ExecuteNonQuery(); //Nho reset fields, ham nay dat trong form //Access need ma_npps for auto increase colunm (ID)

//SQL don't need it, just INSERT INTO TableName VALUES('','ANOTHER VARIABLE'); } public void updateRowOfNHANVIEN(int manv, string tennv, string dchinv, string dthoainv, string chucvunv, string cmnd, string email) { OleDbConnection con = new OleDbConnection(); ConnectDB conDB = new ConnectDB(); con = conDB.getConn(); string cmdString = @"UPDATE NHANVIEN SET TENNV='" + tennv + "', DCHINV='" + dchinv + "',DTHOAINV='" + dthoainv + "',CHUCVUNV='" + chucvunv + "',CMND='" + cmnd + "',EMAIL='" + email + @"' WHERE MANV=" + manv + ""; OleDbCommand cmd = new OleDbCommand(cmdString, con); con.Open(); cmd.ExecuteNonQuery(); //Nho reset fields, ham nay dat trong form } public void deleteRowOfNHANVIEN(int manv) { OleDbConnection con = new OleDbConnection(); ConnectDB conDB = new ConnectDB(); con = conDB.getConn(); string cmdString = @"DELETE FROM NHANVIEN WHERE MANV=" + manv + ""; OleDbCommand cmd = new OleDbCommand(cmdString, con); con.Open(); cmd.ExecuteNonQuery(); //Nho reset fields, ham nay dat trong form } public bool checkXoaNHANVIEN(int manv) { OleDbConnection con = new OleDbConnection(); ConnectDB conDB = new ConnectDB(); con = conDB.getConn(); con.Open(); int soluong_nv_pn; string str_timnv_phieunhap = @"SELECT COUNT(MANV) FROM PHIEUNHAP WHERE MANV=" + manv + ""; OleDbCommand cmd_timnv_phieunhap = new OleDbCommand(str_timnv_phieunhap, object result_nvpn = cmd_timnv_phieunhap.ExecuteScalar(); if (result_nvpn != null && result_nvpn != DBNull.Value) { soluong_nv_pn = Convert.ToInt32(result_nvpn); } else { soluong_nv_pn = 0; } cmd_timnv_phieunhap.Dispose(); int soluong_nv_hdb; string str_timnv_hdonban = @"SELECT COUNT(MANV) FROM HOADONBAN WHERE MANV=" + manv + ""; OleDbCommand cmd_timnv_hdb = new OleDbCommand(str_timnv_hdonban, con); object result_nvhdb = cmd_timnv_hdb.ExecuteScalar(); if (result_nvhdb != null && result_nvhdb != DBNull.Value) { soluong_nv_hdb = Convert.ToInt32(result_nvhdb); } else

con);

{ soluong_nv_hdb = 0; } cmd_timnv_hdb.Dispose(); int soluong_nv_pc; string str_timnv_phieuchi = @"SELECT COUNT(MANV) FROM PHIEUCHI WHERE MANV=" + manv + ""; OleDbCommand cmd_timnv_pchi = new OleDbCommand(str_timnv_phieuchi, con); object result_nvpc = cmd_timnv_pchi.ExecuteScalar(); if (result_nvpc != null && result_nvpc != DBNull.Value) { soluong_nv_pc = Convert.ToInt32(result_nvpc); } else { soluong_nv_pc = 0; } cmd_timnv_pchi.Dispose(); int soluong_nv_pxt; string str_timnv_phieuxuattra = @"SELECT COUNT(MANV) FROM PHIEUXUATTRA WHERE MANV=" + manv + ""; OleDbCommand cmd_timnv_pxt = new OleDbCommand(str_timnv_phieuxuattra, con); object result_nvpxt = cmd_timnv_pxt.ExecuteScalar(); if (result_nvpxt != null && result_nvpxt != DBNull.Value) { soluong_nv_pxt = Convert.ToInt32(result_nvpxt); } else { soluong_nv_pxt = 0; } cmd_timnv_pxt.Dispose(); int tongso; tongso = soluong_nv_hdb + soluong_nv_pn + soluong_nv_pc + soluong_nv_pxt; if (tongso != 0) { return false; } return true;

} } }

Program.cs
using using using using System; System.Collections.Generic; System.Linq; System.Windows.Forms;

namespace NL2 { static class Program { /// <summary> /// The main entry point for the application. /// </summary> [STAThread] static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new frmDangNhap()); } }

Sach.cs
using using using using using System; System.Collections.Generic; System.Linq; System.Text; System.Data.OleDb;

namespace NL2 { class Sach { public void insertTableSach(string tensach, string tacgia, decimal giaban, int lanxb, double cknhap, double ckxuat, int maloai, int manxb) { int masach; OleDbConnection con = new OleDbConnection(); ConnectDB conDB = new ConnectDB(); con = conDB.getConn(); con.Open(); string ma_sach = "SELECT MAX(MASACH) FROM SACH"; OleDbCommand cmdma_sach = new OleDbCommand(ma_sach, con); object result = cmdma_sach.ExecuteScalar(); if (result != null && result != DBNull.Value) { masach = Convert.ToInt32(result); } else { masach = 0; } cmdma_sach.Dispose(); masach = masach + 1; string cmdString = @"INSERT INTO SACH(MASACH, TENSACH, TACGIA, GIABAN, LANXUATBAN, CHIETKHAUNHAP, CHIETKHAUXUAT, MALOAI, MANXB) VALUES (" + masach + ",'" + tensach + "','" + tacgia + "'," + giaban + "," + lanxb + "," + cknhap + "," + ckxuat + "," + maloai + "," + manxb + ")"; OleDbCommand cmd = new OleDbCommand(cmdString, con); cmd.ExecuteNonQuery(); //Nho reset fields, ham nay dat trong form } public void deleteRowOfSACH(int masach) { OleDbConnection con = new OleDbConnection(); ConnectDB conDB = new ConnectDB(); con = conDB.getConn(); string cmdString = @"DELETE FROM SACH WHERE MASACH=" + masach + ""; OleDbCommand cmd = new OleDbCommand(cmdString, con); con.Open(); cmd.ExecuteNonQuery(); //Nho reset fields, ham nay dat trong form } public void updateRowOfSACH(int masach, string tensach, string tacgia, decimal giaban, int lanxb, double cknhap, double ckxuat, int maloai, int manxb) { OleDbConnection con = new OleDbConnection(); ConnectDB conDB = new ConnectDB(); con = conDB.getConn(); string cmdString = @"UPDATE SACH SET TENSACH='" + tensach + "',TACGIA='"+tacgia+"',GIABAN="+giaban+",LANXUATBAN="+lanxb+",CHIETKHAUNHAP="+cknhap+",CH IETKHAUXUAT="+ckxuat+",MALOAI="+maloai+",MANXB="+manxb+@"

WHERE MASACH=" + masach + ""; OleDbCommand cmd = new OleDbCommand(cmdString, con); con.Open(); cmd.ExecuteNonQuery(); //Nho reset fields, ham nay dat trong form } public int searchMaSachOfSACH(string tensach) { int masach; OleDbConnection con = new OleDbConnection(); ConnectDB conDB = new ConnectDB(); con = conDB.getConn(); con.Open(); string cmdString = @"SELECT MIN(SACH.MASACH) FROM SACH, TON_KHO WHERE SACH.TENSACH='" + tensach + "' AND TON_KHO.SOLUONGTON>0 AND SACH.MASACH=TON_KHO.MASACH"; OleDbCommand cmd = new OleDbCommand(cmdString, con); object result = cmd.ExecuteScalar(); if (result != null && result != DBNull.Value) { masach = Convert.ToInt32(result); } else { masach = 0; } cmd.Dispose(); return masach; //Nho reset fields, ham nay dat trong form } public bool checkTenSach(string tensach) { OleDbConnection con = new OleDbConnection(); ConnectDB conDB = new ConnectDB(); con = conDB.getConn(); con.Open(); string cmdString = @"SELECT MASACH FROM SACH WHERE TENSACH='" + tensach + "'"; OleDbCommand cmd = new OleDbCommand(cmdString, con); object result = cmd.ExecuteScalar(); if (result != null && result != DBNull.Value) { return true; } return false; } public bool checkTenLoaiSach(string tenloaisach) { OleDbConnection con = new OleDbConnection(); ConnectDB conDB = new ConnectDB(); con = conDB.getConn(); con.Open(); string cmdString = @"SELECT MALOAI FROM LOAISACH WHERE TENLOAI='" + tenloaisach + "'"; OleDbCommand cmd = new OleDbCommand(cmdString, con); object result = cmd.ExecuteScalar(); if (result != null && result != DBNull.Value) { return false; } return true; }

public bool checkXoasach(int masach) { OleDbConnection con = new OleDbConnection(); ConnectDB conDB = new ConnectDB(); con = conDB.getConn(); con.Open(); string cmdString = @"SELECT MASACH FROM NHAP_SACH WHERE MASACH=" + masach + ""; OleDbCommand cmd = new OleDbCommand(cmdString, con); object result = cmd.ExecuteScalar(); if (result != null && result != DBNull.Value) { return false; } string cmdString1 = @"SELECT MASACH FROM BAN_SACH WHERE MASACH=" + masach + ""; OleDbCommand cmd1 = new OleDbCommand(cmdString1, con); object result1 = cmd1.ExecuteScalar(); if (result1 != null && result1 != DBNull.Value) { return false; } string cmdString2 = @"SELECT MASACH FROM XUAT_TRA WHERE MASACH=" + masach + ""; OleDbCommand cmd2 = new OleDbCommand(cmdString2, con); object result2 = cmd2.ExecuteScalar(); if (result2 != null && result2 != DBNull.Value) { return false; } string cmdString3 = @"SELECT SUM(SOLUONGTON) FROM TON_KHO WHERE MASACH=" + masach + ""; OleDbCommand cmd3 = new OleDbCommand(cmdString3, con); object result3 = cmd3.ExecuteScalar(); if (result3 != null && result3 != DBNull.Value) { return false; } return false; } public bool checkXoaLoaisach(int maloai) { OleDbConnection con = new OleDbConnection(); ConnectDB conDB = new ConnectDB(); con = conDB.getConn(); con.Open(); string cmdString = @"SELECT MALOAI FROM SACH WHERE MALOAI=" + maloai + ""; OleDbCommand cmd = new OleDbCommand(cmdString, con); object result = cmd.ExecuteScalar(); if (result != null && result != DBNull.Value) { return false; } return true; } } }

XuatTra.cs

using using using using using

System; System.Collections.Generic; System.Linq; System.Text; System.Data.OleDb;

namespace NL2 { class XuatTra { public void insertTablePHIEUXUATTRA(DateTime ngaylap_pxt, int manv, int manpps) { OleDbConnection con = new OleDbConnection(); ConnectDB conDB = new ConnectDB(); con = conDB.getConn(); con.Open(); int sophieuxuattra; string ma_sophieuxt = "SELECT MAX(SOPHIEUXUATTRA) FROM PHIEUXUATTRA"; OleDbCommand cmdma_sophieuxt = new OleDbCommand(ma_sophieuxt, con); object result = cmdma_sophieuxt.ExecuteScalar(); if (result != null && result != DBNull.Value) { sophieuxuattra = Convert.ToInt32(result); } else { sophieuxuattra = 0; } cmdma_sophieuxt.Dispose(); sophieuxuattra = sophieuxuattra + 1; decimal tienthu = 0; string cmdString = @"INSERT INTO PHIEUXUATTRA(SOPHIEUXUATTRA, NGAYLAPPXT, TIENTHU, MANV, MANPPS) VALUES (" + sophieuxuattra + ",#" + ngaylap_pxt + "#," + tienthu + "," + manv + "," + manpps + ")"; OleDbCommand cmd = new OleDbCommand(cmdString, con); cmd.ExecuteNonQuery(); //Nho reset fields, ham nay dat trong form } public void insertTableXUAT_TRA(int masach, int sluongxuattra, string lidoxuattra) { int id; int sopxt; OleDbConnection con = new OleDbConnection(); ConnectDB conDB = new ConnectDB(); con = conDB.getConn(); con.Open(); int sluongnhapthucsu; sluongnhapthucsu = getSLnhapthucsu(masach, sluongxuattra); string ma_id = "SELECT MAX(ID) FROM XUAT_TRA"; OleDbCommand cmdma_id = new OleDbCommand(ma_id, con); object result = cmdma_id.ExecuteScalar(); if (result != null && result != DBNull.Value) { id = Convert.ToInt32(result); } else { id = 0; }

cmdma_id.Dispose(); id = id + 1; string so_pxt = "SELECT MAX(SOPHIEUXUATTRA)FROM PHIEUXUATTRA"; OleDbCommand cmdso_pxt = new OleDbCommand(so_pxt, con); sopxt = Convert.ToInt32(cmdso_pxt.ExecuteScalar()); cmdso_pxt.Dispose(); string cmdString = @"INSERT INTO XUAT_TRA(ID,SOPHIEUXUATTRA, MASACH, SLUONGXUATTRA, SLUONGNHAPTHUCSU, LIDOXUATTRA) VALUES (" + id + "," + sopxt + "," + masach + "," + sluongxuattra + ","+sluongnhapthucsu+",'" + lidoxuattra + "')"; OleDbCommand cmd = new OleDbCommand(cmdString, con); cmd.ExecuteNonQuery(); cmd.Dispose(); //Nho reset fields, ham nay dat trong form } public int getSLnhapthucsu(int masach, int sluongxuattra) { OleDbConnection con = new OleDbConnection(); ConnectDB conDB = new ConnectDB(); con = conDB.getConn(); con.Open(); int sluongnhapthucsu; int sluongnhap; string str_SLnhap = "SELECT SUM(SLUONG) FROM NHAP_SACH WHERE MASACH="+masach+""; OleDbCommand cmd_SLnhap = new OleDbCommand(str_SLnhap, con); object result = cmd_SLnhap.ExecuteScalar(); if (result != null && result != DBNull.Value) { sluongnhap = Convert.ToInt32(result); } else { sluongnhap = 0; } cmd_SLnhap.Dispose(); int sluongdaxuattra; string str_SLdaxuattra = "SELECT SUM(SLUONGXUATTRA) FROM XUAT_TRA WHERE MASACH=" + masach + ""; OleDbCommand cmd_SLdaxuattra = new OleDbCommand(str_SLdaxuattra, con); object result_sldaxuattra = cmd_SLdaxuattra.ExecuteScalar(); if (result_sldaxuattra != null && result_sldaxuattra != DBNull.Value) { sluongdaxuattra = Convert.ToInt32(result_sldaxuattra); } else { sluongdaxuattra = 0; } cmd_SLdaxuattra.Dispose(); sluongnhapthucsu = sluongnhap - sluongxuattra - sluongdaxuattra; } return sluongnhapthucsu;

public decimal tinhTienThu(int masach, int soluongxuattra) { OleDbConnection con = new OleDbConnection(); ConnectDB conDB = new ConnectDB();

con = conDB.getConn(); con.Open(); decimal tienthu; //decimal dongianhap; //string str_dongianhap = @"SELECT SUM(DONGIA) FROM NHAP_SACH WHERE MASACH = "+masach+""; //OleDbCommand cmd_dongianhap = new OleDbCommand(str_dongianhap, con); //object result_dongia = cmd_dongianhap.ExecuteScalar(); //if (result_dongia != null && result_dongia != DBNull.Value) //{ // dongianhap = Convert.ToDecimal(result_dongia); //} //else //{ // dongianhap = 0; //} //cmd_dongianhap.Dispose(); decimal giaban; string str_giaban = @"SELECT SUM(GIABAN) FROM SACH WHERE MASACH = OleDbCommand cmd_giaban = new OleDbCommand(str_giaban, con); object result_giaban = cmd_giaban.ExecuteScalar(); if (result_giaban != null && result_giaban != DBNull.Value) { giaban = Convert.ToDecimal(result_giaban); } else { giaban = 0; } cmd_giaban.Dispose(); double chietkhaunhap; string str_chietkhaunhap = @"SELECT SUM(CHIETKHAUNHAP) FROM SACH WHERE MASACH = "+masach+""; OleDbCommand cmd_chietkhaunhap = new OleDbCommand(str_chietkhaunhap, con); object result_chietkhaunhap = cmd_chietkhaunhap.ExecuteScalar(); if (result_chietkhaunhap != null && result_chietkhaunhap != DBNull.Value) { chietkhaunhap = Convert.ToDouble(result_chietkhaunhap); } else { chietkhaunhap = 0; } cmd_chietkhaunhap.Dispose(); tienthu = (soluongxuattra * giaban) - (soluongxuattra * giaban * decimal.Parse(chietkhaunhap.ToString())); return tienthu; } public void updatePHIEUXUATTRA_Tienthu(int masach, int soluongxuattra) { OleDbConnection con = new OleDbConnection(); ConnectDB conDB = new ConnectDB(); con = conDB.getConn(); con.Open(); int sophieuxt; string str_sophieuxt = @"SELECT MAX(SOPHIEUXUATTRA) FROM PHIEUXUATTRA"; OleDbCommand cmd_sophieuxt = new OleDbCommand(str_sophieuxt, con); object result_sophieuxt = cmd_sophieuxt.ExecuteScalar();

"+masach+"";

if (result_sophieuxt != null && result_sophieuxt != DBNull.Value) { sophieuxt = Convert.ToInt32(result_sophieuxt); } else { sophieuxt = 0; } cmd_sophieuxt.Dispose(); decimal tienthu; string str_tienthu = @"SELECT SUM(TIENTHU) FROM PHIEUXUATTRA WHERE SOPHIEUXUATTRA = "+sophieuxt+""; OleDbCommand cmd_tienthu = new OleDbCommand(str_tienthu, con); object result_tienthu = cmd_tienthu.ExecuteScalar(); if (result_tienthu != null && result_tienthu != DBNull.Value) { tienthu = Convert.ToDecimal(result_tienthu); } else { tienthu = 0; } cmd_tienthu.Dispose(); tienthu = tienthu + tinhTienThu(masach, soluongxuattra); string cmdString = @"UPDATE PHIEUXUATTRA SET TIENTHU=" + tienthu + @" WHERE SOPHIEUXUATTRA=" + sophieuxt + ""; OleDbCommand cmd = new OleDbCommand(cmdString, con); cmd.ExecuteNonQuery(); cmd.Dispose(); //Nho reset fields, ham nay dat trong form } public void updatePHIEUXUATTRA_Tienthu_sopxt(int sophieuxt, int masach, int soluongxuattra) { OleDbConnection con = new OleDbConnection(); ConnectDB conDB = new ConnectDB(); con = conDB.getConn(); con.Open(); decimal tienthu; string str_tienthu = @"SELECT SUM(TIENTHU) FROM PHIEUXUATTRA WHERE SOPHIEUXUATTRA = " + sophieuxt + ""; OleDbCommand cmd_tienthu = new OleDbCommand(str_tienthu, con); object result_tienthu = cmd_tienthu.ExecuteScalar(); if (result_tienthu != null && result_tienthu != DBNull.Value) { tienthu = Convert.ToDecimal(result_tienthu); } else { tienthu = 0; } cmd_tienthu.Dispose(); tienthu = tienthu + tinhTienThu(masach, soluongxuattra); string cmdString = @"UPDATE PHIEUXUATTRA SET TIENTHU=" + tienthu + @" WHERE SOPHIEUXUATTRA=" + sophieuxt + ""; OleDbCommand cmd = new OleDbCommand(cmdString, con); cmd.ExecuteNonQuery();

cmd.Dispose(); //Nho reset fields, ham nay dat trong form

public bool checkXuattra(int masach, int sluongxuattra) { OleDbConnection con = new OleDbConnection(); ConnectDB conDB = new ConnectDB(); con = conDB.getConn(); con.Open(); int sluongnhap; string str_SLnhap = "SELECT SUM(SLUONG) FROM NHAP_SACH WHERE MASACH="+masach+""; OleDbCommand cmd_SLnhap = new OleDbCommand(str_SLnhap, con); object result = cmd_SLnhap.ExecuteScalar(); if (result != null && result != DBNull.Value) { sluongnhap = Convert.ToInt32(result); } else { sluongnhap = 0; } cmd_SLnhap.Dispose(); if (sluongxuattra > sluongnhap) { return false; } } // // // // // // return true; public bool checkMANPPS_masach(int masach, int manpps_ktra) { OleDbConnection con = new OleDbConnection(); ConnectDB conDB = new ConnectDB(); con = conDB.getConn(); con.Open();

// int manpps; // string str_manpps = @"SELECT MAX(NHAPPS.MANPPS) FROM NHAPPS, PHIEUNHAP, NHAP_SACH // WHERE NHAP_SACH.MASACH="+masach+" AND NHAP_SACH.SOPHIEUNHAP=PHIEUNHAP.SOPHIEUNHAP AND SOPHIEUNHAP.MANPPS=NHAPPS.MANPPS"; // OleDbCommand cmd_manpps = new OleDbCommand(str_manpps, con); // object result = cmd_manpps.ExecuteScalar(); // if (result != null && result != DBNull.Value) // { // manpps = Convert.ToInt32(result); // } // else // { // manpps = 0; // } // cmd_manpps.Dispose(); // // // // // // // // int sophieuxt; string str_sophieuxt = @"SELECT MAX(SOPHIEUXUATTRA) FROM PHIEUXUATTRA"; OleDbCommand cmd_sophieuxt = new OleDbCommand(str_sophieuxt, con); object result_sophieuxt = cmd_sophieuxt.ExecuteScalar(); if (result_sophieuxt != null && result_sophieuxt != DBNull.Value) { sophieuxt = Convert.ToInt32(result_sophieuxt); }

// // // // // // // // // // // // // // // // // // // // // // // // }

else { }

sophieuxt = 0;

int manpps_ktra; string str_manpps_ktra = @"SELECT MAX(MANPPS) FROM PHIEUXUATTRA WHERE SOPHIEUXUATTRA = " + sophieuxt + ""; OleDbCommand cmd_manpps_ktra = new OleDbCommand(str_manpps, con); object result_ktra = cmd_manpps_ktra.ExecuteScalar(); if (result_ktra != null && result_ktra != DBNull.Value) { manpps_ktra = Convert.ToInt32(result); } else { manpps_ktra = 0; } cmd_manpps_ktra.Dispose(); if (manpps == manpps_ktra) { return true; } return false;

public decimal getTongtienthu() { OleDbConnection con = new OleDbConnection(); ConnectDB conDB = new ConnectDB(); con = conDB.getConn(); con.Open(); int sophieuxt; string str_sophieuxt = @"SELECT MAX(SOPHIEUXUATTRA) FROM PHIEUXUATTRA"; OleDbCommand cmd_sophieuxt = new OleDbCommand(str_sophieuxt, con); object result_sophieuxt = cmd_sophieuxt.ExecuteScalar(); if (result_sophieuxt != null && result_sophieuxt != DBNull.Value) { sophieuxt = Convert.ToInt32(result_sophieuxt); } else { sophieuxt = 0; } cmd_sophieuxt.Dispose(); decimal tienthu; string str_tienthu = @"SELECT SUM(TIENTHU) FROM PHIEUXUATTRA WHERE SOPHIEUXUATTRA = " + sophieuxt + ""; OleDbCommand cmd_tienthu = new OleDbCommand(str_tienthu, con); object result_tienthu = cmd_tienthu.ExecuteScalar(); if (result_tienthu != null && result_tienthu != DBNull.Value) { tienthu = Convert.ToDecimal(result_tienthu); } else { tienthu = 0; } cmd_tienthu.Dispose(); return tienthu; }

public int getTongsoluongxuattra() { OleDbConnection con = new OleDbConnection(); ConnectDB conDB = new ConnectDB(); con = conDB.getConn(); con.Open(); int sophieuxt; string str_sophieuxt = @"SELECT MAX(SOPHIEUXUATTRA) FROM PHIEUXUATTRA"; OleDbCommand cmd_sophieuxt = new OleDbCommand(str_sophieuxt, con); object result_sophieuxt = cmd_sophieuxt.ExecuteScalar(); if (result_sophieuxt != null && result_sophieuxt != DBNull.Value) { sophieuxt = Convert.ToInt32(result_sophieuxt); } else { sophieuxt = 0; } cmd_sophieuxt.Dispose(); int sluongxt; string str_SLxt = "SELECT SUM(SLUONGXUATTRA) FROM XUAT_TRA WHERE SOPHIEUXUATTRA=" + sophieuxt + ""; OleDbCommand cmd_SLxt = new OleDbCommand(str_SLxt, con); object result = cmd_SLxt.ExecuteScalar(); if (result != null && result != DBNull.Value) { sluongxt = Convert.ToInt32(result); } else { sluongxt = 0; } cmd_SLxt.Dispose(); return sluongxt; } //phieu xuat tra chi duoc cap nhat khi chua co quyen sach nao trong do //vi 1 phieu xuat tra chi duoc tra cho 1 nha phan phoi sach public bool checkUpdatePhieuxuattra_MANPPS(int sophieuxuattra) { OleDbConnection con = new OleDbConnection(); ConnectDB conDB = new ConnectDB(); con = conDB.getConn(); con.Open(); int sophieuxt; string str_sophieuxt = @"SELECT COUNT(SOPHIEUXUATTRA) FROM XUAT_TRA"; OleDbCommand cmd_sophieuxt = new OleDbCommand(str_sophieuxt, con); object result_sophieuxt = cmd_sophieuxt.ExecuteScalar(); if (result_sophieuxt != null && result_sophieuxt != DBNull.Value) { sophieuxt = Convert.ToInt32(result_sophieuxt); } else { sophieuxt = 0; } cmd_sophieuxt.Dispose(); if (sophieuxt > 0) { return false; }

return true; } public void updatePHIEUXUATTRA_MANPPS(int sophieuxuattra, int manpps) { OleDbConnection con = new OleDbConnection(); ConnectDB conDB = new ConnectDB(); con = conDB.getConn(); con.Open(); string cmdString = @"UPDATE PHIEUXUATTRA SET MANPPS="+manpps+@" WHERE SOPHIEUXUATTRA=" + sophieuxuattra + ""; OleDbCommand cmd = new OleDbCommand(cmdString, con); cmd.ExecuteNonQuery(); cmd.Dispose(); //Nho reset fields, ham nay dat trong form } public void updatePHIEUXUATTRA_MgayLappxt(int sophieuxuattra, DateTime Ngaylappxt) { OleDbConnection con = new OleDbConnection(); ConnectDB conDB = new ConnectDB(); con = conDB.getConn(); con.Open(); string cmdString = @"UPDATE PHIEUXUATTRA SET NGAYLAPPXT=#" + Ngaylappxt + @"# WHERE SOPHIEUXUATTRA=" + sophieuxuattra + ""; OleDbCommand cmd = new OleDbCommand(cmdString, con); cmd.ExecuteNonQuery(); cmd.Dispose(); //Nho reset fields, ham nay dat trong form } public bool checkXoaPhieuxuattra(int sophieuxuattra) { OleDbConnection con = new OleDbConnection(); ConnectDB conDB = new ConnectDB(); con = conDB.getConn(); con.Open(); int masach; int soluongton; int tongsoluongton = 0; string str_masach = @"SELECT MASACH FROM XUAT_TRA WHERE SOPHIEUXUATTRA = " + sophieuxuattra + ""; OleDbCommand cmd_masach = new OleDbCommand(str_masach, con); OleDbDataReader re = cmd_masach.ExecuteReader(); if (re.HasRows == true) { while (re.Read()) { masach = Convert.ToInt32(re["MASACH"].ToString()); string str_timsoluong = @"SELECT SUM(SOLUONGTON) FROM TON_KHO WHERE MASACH=" + masach + ""; OleDbCommand cmd_timsoluong = new OleDbCommand(str_timsoluong, con); object result_sluong = cmd_timsoluong.ExecuteScalar(); if (result_sluong != null && result_sluong != DBNull.Value) { soluongton = Convert.ToInt32(result_sluong); } else {

soluongton = 0; } tongsoluongton = tongsoluongton + soluongton; } }

if (tongsoluongton > 0) { return false; } return true; } public void deleteRowOfPHIEUXUATTRA_XUAT_TRA(int sophieuxuattra) { OleDbConnection con = new OleDbConnection(); ConnectDB conDB = new ConnectDB(); con = conDB.getConn(); con.Open(); //Chu y: thu tu cac cau truy van rat quan trong string cmdString = @"DELETE FROM PHIEUXUATTRA WHERE SOPHIEUXUATTRA=" + sophieuxuattra + ""; OleDbCommand cmd = new OleDbCommand(cmdString, con); cmd.ExecuteNonQuery(); string cmdString2 = @"DELETE FROM XUAT_TRA WHERE SOPHIEUXUATTRA=" + sophieuxuattra + ""; OleDbCommand cmd2 = new OleDbCommand(cmdString2, con); cmd2.ExecuteNonQuery(); } //Nho reset fields, ham nay dat trong form

public void updateRowOfXUAT_TRA(int sophieuxuattra, int masach, int soluongxuattra, string lidoxuattra) { OleDbConnection con = new OleDbConnection(); ConnectDB conDB = new ConnectDB(); con = conDB.getConn(); con.Open(); int sluongnhapthucsu; sluongnhapthucsu = getSLnhapthucsu(masach, sophieuxuattra); int id; string str_id = @"SELECT ID FROM XUAT_TRA WHERE SOPHIEUXUATTRA=" + sophieuxuattra + "AND MASACH=" + masach + ""; OleDbCommand cmdma_id = new OleDbCommand(str_id, con); object result_id = cmdma_id.ExecuteScalar(); if (result_id != null && result_id != DBNull.Value) { id = Convert.ToInt32(result_id); } else { id = 0; } //masach = Convert.ToInt32(cmdma_sach.ExecuteScalar()); string cmdString = @"UPDATE XUAT_TRA SET SLUONGXUATTRA=" + soluongxuattra + ", SLUONGNHAPTHUCSU=" + sluongnhapthucsu + ", LIDOXUATTRA='"+lidoxuattra+@"' WHERE ID=" + id + ""; OleDbCommand cmd = new OleDbCommand(cmdString, con); cmd.ExecuteNonQuery();

//Nho reset fields, ham nay dat trong form } public int getTongsoluongxuattra_sophieuxt(int sophieuxt) { OleDbConnection con = new OleDbConnection(); ConnectDB conDB = new ConnectDB(); con = conDB.getConn(); con.Open(); int sluongxt; string str_SLxt = "SELECT SUM(SLUONGXUATTRA) FROM XUAT_TRA WHERE SOPHIEUXUATTRA=" + sophieuxt + ""; OleDbCommand cmd_SLxt = new OleDbCommand(str_SLxt, con); object result = cmd_SLxt.ExecuteScalar(); if (result != null && result != DBNull.Value) { sluongxt = Convert.ToInt32(result); } else { sluongxt = 0; } cmd_SLxt.Dispose(); return sluongxt; } public decimal getTongtienthu_sophieuxt(int sophieuxt) { OleDbConnection con = new OleDbConnection(); ConnectDB conDB = new ConnectDB(); con = conDB.getConn(); con.Open(); decimal tienthu; string str_tienthu = @"SELECT SUM(TIENTHU) FROM PHIEUXUATTRA WHERE SOPHIEUXUATTRA = " + sophieuxt + ""; OleDbCommand cmd_tienthu = new OleDbCommand(str_tienthu, con); object result_tienthu = cmd_tienthu.ExecuteScalar(); if (result_tienthu != null && result_tienthu != DBNull.Value) { tienthu = Convert.ToDecimal(result_tienthu); } else { tienthu = 0; } cmd_tienthu.Dispose(); } } } return tienthu;

GIAI ON 1: TM HIU TNG QUT


Gii thiu tng qut v nh sch: Chng trnh qun l mua bn sch ca mt nh sch c thit k phc v cho nh sch tm c trung bnh, chc nng chnh l nhp sch v t nh pht hnh sch (nh cung cp sch), bn l li hoc bn s cho cc nh sch nh hn trong phm vi thnh ph. Tm hiu hot ng ca h thng: H thng c thit k nhm p ng nhu cu nng cao cht lng hot ng mua bn sch ca nh sch. Vic nng cao cht lng ny th hin qua vic tin hc ha cc khu qun l trong nh sch bao gm qun l nhn vin v qun l vic kinh doanh sch. T gip cho ngi qun l nh sch d dng hn trong vic nm bt tnh hnh kinh doanh ca nh sch, thng tin sch mua, bn, li, l, sch tn kho, thng tin khch hng, thng tin nhn vin, thng tin nh pht hnh (nh cung cp sch) mt cch nhanh chng, hiu qu v chnh xc, thay v phi lu v tm kim cc thng tin ny mt cch th cng. Vi cc tnh nng c tch hp sn trong h thng t khu nhp sch vo, kim k, lu tr, phn phi, bn l n thng k bo co v c phn quyn ngi dng trong h thng, h thng m bo ngi qun l nh sch c trong tay cng c tr gip tht ti u nm bt tnh hnh hot ng ca nh sch mt cch ton din nht c th. Ngay lc khi ng, vo c h thng, ngi dng (nhn vin) phi ng nhp bng mt username v password. Trng hp h thng mi c kch hot s dng ln u tin, ngi dng (thng l ngi qun l nh sch) s c cp mt ti khon admin c sn cng vi password tng ng. Sau khi ng nhp, admin ny c tt c cc quyn trong h thng, c quyn thay i username v password ca chnh mnh (l ng nhin, ngi qun l s thay i username v password mc nh ca mnh ri mi lm cc cng vic khc). Ta gi ngi qun l ny l admin trong h thng. cp username v password cho nhn vin ng nhp vo h thng, trc tin, admin s cp nht mi thng tin ca nhn vin ny vo trong h thng. Ty theo chc v ca nhn vin, admin s phn nhm cho nhn vin, sau , admin to mt ti khon gm username v password cho nhn vin h c ng nhp vo h thng v lm cc cng vic ca mnh. Vic phn quyn c s dng nh sau: admin phn quyn cho nhm ngi dng v phn quyn cho mi ngi dng theo nhm ngi dng. Khi thng tin ca nhn vin c thay i, admin s cp nht thng tin mi ca nhn vin vo h thng. Khi c nhn vin thi vic, admin s xa thng tin nhn vin ny trong h thng cng vi ti khon ca h. Sau khi phn nhm nhn vin (tc phn quyn), mi nhn vin c mt nhim v ring v mi ngi s lm vic ca mnh trong h thng. Khi nh sch nhp sch v, nhn vin nhp sch s tin hnh lp phiu nhp sch tng ng vi ha n do nh pht hnh (nh cung cp) sch bn. Ngoi nhng thng tin v tin bc mua bn, nhn vin nhp sch s tin hnh nhp lun thng tin v sch nhp cng vi s lng nhp sch ny vo h thng. (V mi l sch nhp v ch cha cng mt loi sch do mt nh cung cp sch cung cp nn khng cn qun l l sch lm g, ch cn qun l thng tin ca sch, do , nhp trc tip thng tin sch vo h thng). Khi nhp s lng nhp, th s lng tn trong kho ca kho s c cp nht. H thng s lu thng tin v sch mi ny v cp nhp s lng tn kho. Sau khi hon thnh cng vic lp phiu nhp cng vi vic cp nht sch v kho sch, nhn vin chi tin c th tin hnh lp phiu chi chi tin tr cho nh cung cp sch. Nu nh sch hin thi khng c kh nng thanh khon cho lng sch va nhp vo, nhn vin khoan lp phiu chi. Khi no nh sch c kh nng tr, nhn vin s lp phiu chi tin tr cho nh cung cp sch. Khi lp phiu chi, nhn vin cn lu kim tra li trong h thng xem nh sch n bao nhiu v chi tr c bao nhiu. Nu s tin chi vt qu s tin n, h thng s khng cho php nhn vin lp phiu chi trnh trng hp nhn vin nhm ln, chi tin nhiu ln.

Sch sau khi c nhp vo, xp kho nhng cha chc chn l sch s dng c (khng h, rch,). V vy nhn vin cn kim tra sch nhp vo tht k cng. Nu trong qu trnh kim tra, khng pht hin h hng, mt mt, nhn vin khng cn lp phiu xut tr sch. Ngc li, nhn vin s lp phiu xut tr sch ghi r sch h hng, mt mt ri quyt nh xut tr li sch cho nh cung cp. Khi xut tr, s lng sch trong kho s c cp nht li cng vi s tin cn c bi thng tng ng. Khi xut tr nhn vin s thu li tin ngay lp tc, khng cn lp phiu thu rm r. Do , khi nhn vin lp phiu chi tr tin cho nh cung cp sch, nhn vin khng cn phi xem xt xem sch c c xut tr khng chi tin cho ng. H thng s lu li tt c cc giao dch. Mi nh pht hnh sch (hay nh cung cp sch) s bn sch vi mt chit khu c th. Chit khu ny l do nh pht hnh sch quyt nh, nhng n s thay i theo thi gian, v vy chit khu s lu vo lm thuc tnh ca mi quyn sch tng ng. Sch khi c nhp vo h thng s c gn loi (phn loi) sch. Vic phn loi sch ny nhm gip cho vic nm bt tnh hnh kinh doanh cc loi sch tt hn, loi no bn chy, loi no bn chm, vo thi im no, Trng hp sch nhp vo h thng nhng trong h thng cha c sch ny th s cp nht mi sch ng thi xem sch c thuc loi sch no c sn trong h thng khng gn, nu thuc mt loi sch mi, nhn vin s tin hnh cp nht mi loi sch trong h thng. Trng hp thng tin nh pht hnh sch m nh sch hp tc tn ti trong h thng th khng cn thit cp nht g. Nu l nh pht hnh sch mi hp tc mua bn sch ln u th nhn vin cn cp nht mi thng tin nh sch ny vo h thng trc ri mi tin hnh nhp sch ca h. Trng hp ngng hp tc vi mt nh pht hnh sch no th khng nht thit phi xa thng tin nh sch ra khi h thng, phng khi hp tc li, hoc c g cn lin lc Nu tht s khng cn cn thit gi thng tin v nh pht hnh sch na th nhn vin c th xa thng tin nh pht hnh sch ra khi h thng. Khi khch hng n mua sch, nhn vin s lp ha n bn v bn cho khch hng. Trng hp khch hng n mua l khch hng mua l th nhn vin ch cn lp ha n vi cc thng tin n gin ch yu nh: s lng mua, thnh tin, thu. Trng hp khch hng n mua l khch hng mua s, nhn vin cn thm thng tin khch hng vo h thng nu y l ln u tin khch hng n mua. Ngc li, nhn vin lp ha n cho bit r bn cho khch hng no v thm thng tin chit khu bn l cho khch hng . Chit khu ny do nh sch quyt nh, ti mi thi im nh sch s lp mt chit khu khc nhau, v vy khng lu trong h thng m nhp vo ha n bn. Sau khi bn cho khch hng mua s, nhn vin s thu tin v cp nht n thu i vi khch hng mua s ny. N thu ny khi c thu, nhn vin s lp phiu thu tin hnh thu n cho khch hng. Khch hng mua s khng c tr li sch, nh sch khng nhn sch hon li, v vy, khi mua sch, nhn vin s nhc khch hng mua sch kim tra sch tht k trc khi mang v (v y l mt nh sch tm c trung bnh). Mi khi sch c bn, s lng sch s c cp nht li trong kho (s lng tn kho) ngay lp tc. Vic ny gip cho ngi qun l nh sch c thng tin cp nht v nh sch ca mnh mi nht. Trng hp khch hng ln u tin n mua s, nhn vin cp nht mi thng tin khch hng vo trong h thng. Trng hp ngng hon ton hp tc bn sch cho khch hng mua s, nhn vin c th xa thng tin khch hng ra khi h thng. Tm hiu thng tin pht sinh v lun chuyn thng tin trong h thng: Thng tin v nhn vin: nhn vin l tc nhn can thip vo h thng nhiu nht. Ngay khi mi c cp nht mi vo h thng, thng tin nhn vin s gn thm vi thng tin nhm ngi dng v nh danh ngi dng (username v password) gip nhn vin ng nhp vo h thng lm cc cng vic trong gii hn cho php. Thng tin nhn vin (c th l xc nh nhn vin no) lun cn thit trong cc hot ng mua bn sch. Khi nhp sch, cn bit nhn vin no nhp; khi xem thng tin kim tra sch, cn bit nhn vin no kim tra sch; khi chi tin, cn bit nhn vin no lm; khi bn sch, cn bit nhn vin no thc hin cng vic bn sch v lp ha n; kho

sch cng cn c qun l bi mt nhn vin c th ( y l cc nhn vin nhp sch). Thng tin v nhn vin s c lun chuyn xuyn sut trong cc thng tin hot ng ca nh sch. Vic ny gip qun l c nhn vin v cng vic mua bn sch tt hn. Cng vic nhp sch: vic nhp sch vo s c hng lot thng tin mi pht sinh nh: thng tin sch (nu c), thng tin loi sch (nu c), thng tin kho sch (s lng tn trong kho), thng tin nhp sch (ngy nhp, s lng nhp, gi tin nhp), thng tin chi tin (s tin chi, ngy chi, chi cho ai, n tn), thng tin xut tr sch (sch tr, s lng, n gi, l do tr), thng tin v nh pht hnh sch (nu c), thng tin kho sch( s lung sch tn trong kho sau nhp hoc sau xut). Cc thng tin pht sinh ny c cp nht mi vo h thng v c mi lin h cht ch vi nhau. h thng ti u, cc thng tin pht sinh ny s c xut hin ti mt thc th c th v ti a l mt ln, khng xut hin nhiu thc th khc nhau v nhiu ln khc nhau. cc thng tin ny c th ni chuyn vi nhau, h thng s c xy dng m hnh lun chuyn thng tin gia cc thc th da trn thuc tnh kha duy nht ca thc th. Cng vic bn sch: trong qu trnh bn sch, cng c rt nhiu thng tin c pht sinh nh: thng tin ha n bn (ngy lp, s lng sch bn, n gi, bn sch g, bn cho ai, s hay l, nu s th khch hng l ai, chit khu bn l cho h l bao nhiu, c ghi n khng, n bao nhiu), thng tin v kho sch (s lng sch tn trong kho sau khi bn). Tng t nh cng vic nhp sch, cc thng tin ny c cp nht mi lin tc v cng c mi lin h cht ch vi nhau thng qua thuc tnh kha duy nht ca cc thc th. Tm hiu mc tiu ca vic lu tr thng tin pht sinh trong qu trnh hot ng ca h thng: Vic lu tr thng tin pht sinh trong qu trnh hot ng ca h thng nhm mc tiu chnh l qun l cng vic kinh doanh ca nh sch. Cc cng vic kinh doanh c trch lc thnh nhng mc tiu chnh nh sau: Danh sch sch, loi sch: nm r cc sch, loi sch Sch tn kho: t, nhiu, s lng c th. Thng k sch nhp: s sch nhp trong thng, sch nhp t nh pht hnh sch no nhiu nht, t nht, chit khu nhp ca nh pht hnh sch no cao, thp, Thng k sch bn: s sch bn trong thng, ngy, sch bn chy nht trong thng, ngy, Thng k thu tin: tin thu trong theo ngy thng, nhn vin no thu tin mt nhiu nht trong thng, ngy, chi tit Thng k chi tin: tng tin chi theo ngy thng, chi tit chi tin, Thng k n tn: tng n cn tn, n tn nhiu nht i vi mt nh pht hnh sch, n tn lu nht,

GIAI ON 2: PHN TCH V THIT K H THNG


Gii thiu phng php MERISE:
MERISE vit tt t cm t Methode pour Rasembler les Idees Sans Effort (phng php tp hp cc tng khng cn c gng). tng ca phng php phn tch thit k Merise da trn 3 mt c bn sau: 1. Quan tm n chu k sng ca h thng thng tin qua cc giai on: thai nghn nim/quan nim qun tr - cht. Chu k ny c th ko di t 15 n 20 nm i vi cc h thng thng tin ln. 2. cp n chu k c trng ca h thng thng tin, cn gi l chu k tru tng. Mi tng c m t di dng m hnh tp trung bao gm tp hp cc thng s chnh xc. Theo khi nhng thng s ca tng di tng trng, tng ang m t khng bin i v n ch thay i khi cc thng s ca mnh thay i. Mi m hnh c m t thng qua mt hnh thc da trn cc quy tc, nguyn l ng vng, v c php quy nh. C nhng quy tc cho php chuyn t m hnh ny sang m hnh khc mt cch t ng hoc t nhiu.

3. Chu k cc quyt nh cn phi a ra trong cc chu k sng ca sn phm. c trng ca phng php MERISE l tch ri d liu v x l nhm m bo tnh khch quan trong qu trnh phn tch v cung cp y cc m hnh din t cc bc cp nht. H thng bao gm d liu v x l c biu din 3 mc: Mc quan nim: xc nh cc thnh phn ca d liu v x l. Mc t chc (mc logic): chi tit ha nhng quan h gia chng. Mc tc nghip (mc vt l): cc thnh phn c th hin trong thc t nh th no. Trn c s 3 mc bt bin ca h thng thng tin, phng php phn tch thit k Merise s dng cc m hnh tng ng trn cc mc ny phn tch, thit k mt h thng thng tin: Mc Mc quan nim Mc t chc Mc vt l D liu M hnh quan nim v d liu M hnh t chc v d liu M hnh vt l v d liu X l M hnh quan nim v x l M hnh t chc v x l M hnh vt l v x l

u im ca phng php MERISE l c c s khoa hc vng chc, c s dng nhiu cc nc Chu u. Nhc im ca phng php MERISE l cng knh. C th hnh dung cc bc pht trin ca mt h thng thng tin thng qua m hnh 3 chiu: chiu cc thnh phn ca h thng thng tin, chiu cc mc bt bin ca h thng thng tin v chiu cc giai on phn tch thit k mt h thng thng tin.

M hnh d liu mc quan nim MCD:

M hnh d liu mc logic MLD:

Chi tit cc thuc tnh cc bng:

TN BNG

TN THUC TNH

KIU GI TR

DIN GII

NHAXUATBAN SACH

LOAISACH TON_KHO KHO BAN_SACH XUAT_TRA

MANXB TENNXB MASACH TENSACH TACGIA GIABAN LANXUATBAN CHIETKHAUNHAP CHIETKHAUXUAT MALOAI TENLOAI SOLUONGTON MAKHO TENKHO SOLUONGTOIDA SLUONGBAN DGIABAN SLUONGXUATTRA SLUONGNHAPTHUCSU LIDOXUATTRA SLUONG DONGIA SOPHIEUNHAP NGAYLAPPN SOHDM NGAYLAPHDM TONGSLNHAP

Long int Char(30) Long int Char(50) Char(50) Decimal Int Double Double Int Char(50) Long int Long int Char(50) Long int Long int Decimal Long int Long int Text Long int Decimal Long int Date time Char Date time Long int Decimal Long int Char(50) Char(50) Char(20) Char(20) Char(20) Char(20) Char(30) Char Long int Date time Char(5) Double Long int Decimal

NHAP_SACH PHIEUNHAP

NHAPPS

THANHTIENNHAP MANPPS TENNPPS DIACHI NGUOIDAIDIEN DIENTHOAI FAX MOBILE EMAIL MASOTHUE SOHOADON NGAYLAPHD LOAIHD THUESUAT TONGSLBAN TONGDGIACHUATHUE

HOADONBAN

M nh xut bn Tn nh xut bn M sch Tn sch Tc gi Gi bn Ln xut bn Chit khu nhp Chit khu xut M loi Tn loi S lng tn M kho Tn kho S lng ti a S lng bn n gi S lng xut tr S lng nhp thc s L do xut tr S lng n gi S phiu nhp Ngy lp phiu nhp S ha n mua Ngy lp ha n mua Tng s lng nhp Thnh tin nhp M nh phn phi sch Tn nh phn phi sch a ch Ngi i din in thoi Fax Mobile Email M s thu S ha n Ngy lp ha n Loi ha n Thu sut Tng s lng bn Tng n gi cha

PHIEUXUATTRA

THANHTIENDATHUE SOPHIEUXUATTRA NGAYLAPPXT TIENTHU SOPHIEUCHI SOTIENCHI NGAYLAPPC NOTON MAKH TENKH NGUOIDAIDIEN DIENTHOAI FAX MOBILE EMAIL MASOTHUE MANHOM TENNHOM MANV TENNV DCHINV DTHOAINV CHUCVUNV CMND EMAIL MASO USERNAME P

Decimal Long int Date time Decimal Long int Decimal Date time Decimal Long int Char(30) Char(30) Char(20) Char(20) Char(20) Char(30) Char Long int Char(30) Long int Char(50) Char(50) Char(20) Char(10) Char(15) Char(30) Int Char Char

PHIEUCHI

KHACHHANG

NHOM NHANVIEN

DINHDANH

thu Thnh tin thu S phiu xut tr Ngy lp phiu xut tr Tin thu S phiu chi S tin chi Ngy lp phiu chi N tn M khch hng Tn khch hng Ngi i din in thoi Fax Mobile Email M s thu M nhm Tn nhm M nhn vin Tn nhn vin a ch nhn vin in thoi nhn vin Chc v nhn vin Cmnd Email M s Username Password

Cc mi quan h ca cc bng t m hnh MLD: NHAXUATBAN (MANXB, TENNXB) SACH (MASACH, TENSACH, TACGIA, GIABAN, LANXUATBAN, CHIETKHAUNHAP, CHIETKHAUXUAT, MANXB, MALOAI) LOAISACH (MALOAI, TENLOAI) TON_KHO (SOLUONGTON, MAKHO, MASACH) KHOSACH (MAKHO, TENKHO, SOLUONGTOIDA) HOADONBAN (SOHOADON, NGAYLAPHD, LOAIHD, THUESUAT, TONGSLBAN, TONGDGIACHUATHUE, THANHTIENDATHUE) BAN_SACH (SLUONGBAN, DGIABAN, MASACH, SOHOADON) PHIEUXUATTRA (SOPHIEUXUATTRA, NGAYLAPPXT, TIENTHU, MANV, MANPPS) XUAT_TRA (SLUONGXUATTRA, SLUONGNHAPTHUCSU, LIDOXUATTRA, SOPHIEUXUATTRA, MASACH) PHIEUNHAP (SOPHIEUNHAP, NGAYLAPPN, SOHDM, NGAYLAPHDM, TONGSLNHAP, THANHTIENNHAP, MANV, MANPPS) NHAP_SACH (SLUONG, DONGIA, SOPHIEUNHAP, MASACH)

NHAPPS (MANPPS, TENNPPS, DCHI, NGUOIDAIDIEN, DIENTHOAI, FAX, MOBILE, EMAIL, MASOTHUE) PHIEUCHI (SOPHIEUCHI, SOTIENCHI, NGAYLAPPC, NOTON, SOPHIEUNHAP, MANV) NHANVIEN (MANV, TENNV, DCHINV, DTHOAINV, CHUCVUNV, CMND, EMAIL) NHOM (MANHOM, TENNHOM) THUOC_NHOM (MANHOM, MANV) DINHDANH (MASO, USERNAME, P, MANV) KHACHHANG (MAKH, TENKH, NGUOIDAIDIEN, DIENTHOAI, FAX, MOBILE, EMAIL, MASOTHUE) Cc rng buc: SACH (MANXB) NHAXUATBAN(MANXB) SACH (MALOAI) LOAISACH (MALOAI) TON_KHO (MASACH) SACH (MASACH) TON_KHO (MAKHO) KHOSACH (MAKHO) BAN_SACH (MASACH) SACH (MASACH) BAN_SACH (SOHOADON) HOADONBAN (SOHOADON) XUAT_TRA (MASACH) SACH (MASACH) XUAT_TRA (SOPHIEUXUATTRA) PHIEUXUATTRA (SOPHIEUXUATTRA) NHAP_SACH (MASACH) SACH (MASACH) NHAP_SACH (SOPHIEUNHAP) PHIEUNHAP (SOPHIEUNHAP) HOADONBAN (MAKH) KHACHHANG (MAKH) HOADONBAN (MANV) NHANVIEN (MANV) PHIEUXUATTRA (MANV) NHANVIEN (MANV) PHIEUXUATTRA (MANPPS) NHAPPS (MANPPS) PHIEUNHAP (MANV) NHANVIEN (MANV) PHIEUNHAP (MANPPS) NHAPPS (MANPPS) PHIEUCHI (SOPHIEUNHAP) PHIEUNHAP (SOPHIEUNHAP) PHIEUCHI (MANV) NHANVIEN (MANV) DINHDANH (MANV) NHANVIEN (MANV) THUOC_NHOM (MANHOM) NHOM (MANHOM) THUOC_NHOM (MANV) NHANVIEN (MANV) M hnh d liu mc vt l MPD (theo MS Access):

Lu dng d liu DFD:


Mc 0:

Mc 1:

M hnh thit k h thng tng th:

Cc Module:

GIAI ON 3: CHI TIT HA CC CNG VIC


H c s d liu v ngn ng lp trnh: H c s d liu c dng trong ti l Microsoft Access. Gii thiu: Microsoft Access l mt h qun tr c s d liu (HQTCSDL) tng tc ngi dng chy trong mi trng Windows. Microsoft Access cho chng ta mt cng c hiu lc v y sc mnh trong cng tc t chc, tm kim v biu din thng tin. Microsoft Access cho ta cc kh nng thao tc d liu, kh nng lin kt v cng c truy vn mnh m gip qu trnh tm kim thng tin nhanh. Ngi s dng c th ch dng mt truy vn lm vic vi cc dng c s d liu khc nhau. Ngoi ra, c th thay i truy vn bt k lc no v xem nhiu cch hin th d liu khc nhau ch cn ng tc nhp chut. Microsoft Access v kh nng kt xut d liu cho php ngi s dng thit k nhng biu mu v bo co phc tp p ng y cc yu cu qun l, c th vn ng d liu v kt hp cc biu mu v bo co trong mt ti liu v trnh by kt qu theo dng thc chuyn nghip. Microsoft Access l mt cng c y nng lc nng cao hiu sut cng vic. Bng cch dng cc Wizard ca MS Access v cc lnh c sn (macro) ta c th d dng t ng ha cng vic m khng cn lp trnh. i vi nhng nhu cu qun l cao, c th dng Access kt hp vi cc ngn ng lp trnh trn window c h tr lp trnh c s d liu cao. MS Access cung cp mt s kiu d liu c bn sau: Kiu d liu D liu vo Kch thc Text Vn bn Ti a 255 byte Memo Vn bn nhiu dng, trang Ti a 64000 byte Number S 1,2,4 hoc 8 byte Date/time Ngy gi 8 byte Currency Tin t (s) 8 byte
H c s d liu:

Auto number Yes/no OLE object Lookup wizard

S t ng tng thm 1 n v khi thm dng mi Kiu lun l (bool) i tng ca phn mm khc

4 byte 1 bit Ti a 1 gigabyte Trng nhn gi tr do ngi dng chn t mt bng khc hoc mt danh sch gi tr nh trc

Hyper

Lin kt cc URL

Ngn ng lp trnh thc hin ti l Microsoft Visual C Sharp (C#). Gii thiu: C# c pht trin ti Microsoft, i nghin cu do Anders Hejlsberg v Scott Wiltamuth lnh o. Ngn ng C# l mt ngn ng c dn xut t C v C++, nhng n c to ra t nn tng pht trin hn. Microsoft a ra mt s mc ch khi xy dng ngn ng ny nh sau: a. C# l ngn ng n gin b. C# l ngn ng hin i c. C# l ngn ng hng i tng d. C# l ngn ng mnh m v mm do e. C# l ngn ng c t t kha f. C# l ngn ng hng module Chung quy li, C# l mt ngn ng lp trnh thun hng i tng c thit k xy dng cc ng dng chy trn nn tng .NET Framework. Mt m nh trong ngn ng C# l h tr mnh m vic lp trnh Winform vi c s d liu, y l l do chnh ti c thc hin bng ngn ng C#. Chi tit ha cc module: Module ng nhp: Ngi dng nhp vo bng username v password. H thng kim tra username v password c tn ti hay khng, kim tra tnh chnh xc, nu ng th ngi dng c ng nhp vo h thng. Nu sai, ngi dng phi nhp li hoc thot ra khi h thng. Sau khi ng nhp vo h thng, ngi dng s thc hin cc cng vic mnh c php lm. Module phn quyn: phn quyn theo nhm ngi dng. Nhm ngi dng gm c: nhp sch, bn sch, xut tr sch, thng k, bo co, chi tin, phn quyn, qun l. Nhm nhp sch: thc hin chc nng nhp sch, qun l thng tin sch, loi sch, kho sch, lp phiu nhp, nh phn phi sch. Nhm bn sch: thc hin chc nng bn sch, lp ha n bn, qun l thng tin khch hng. Nhm xut tr sch: thc hin chc nng xut tr sch, lp phiu xut tr, kim tra sch cn xut tr. Nhm thng k: thc hin cc chc nng thng k sch nhp, thng k sch bn, sch xut tr, sch tn kho, tin thu, tin chi, n tn. Nhm bo co: thc hin chc nng lp cc bo co: bo co sch bn, bo co sch nhp, Nhm chi tin: thc hin chc nng chi tin.

Ngn ng lp trnh:

Nhm phn quyn: thc hin chc nng phn nhm nhn vin, qun l thng tin nhn vin, cp v xa username v passwoed cho nhn vin. Nhm qun l: bao gm tt c cc nhm trn. Nhn vin c phn quyn da trn nhm nhn vin. Nhn vin thuc nhm no th s c thc hin cc cng vic ca nhm . Qun l v cp nht thng tin ca nhn vin. Cp username v password cho nhn vin dng nhp vo h thng v thc hin cc cng vic mnh c quyn lm. Nhn vin khng c cp username v password th khng c ng nhp vo h thng mc d c gn nhm, nhn vin c cp username v password c ng nhp vo h thng v khng c thc hin cng vic gi khi cha c gn nhm. Module nhp sch: Lp phiu nhp khi nhp sch mi v. Nhp thng tin sch mi nhp v. Cp nht thng tin phiu nhp nu cn thit (chnh sa, xa). Cp nht thng tin nh phn phi sch nu cn thit (thm, sa, xa). Cp nht thng tin loi sch nu cn thit (thm, sa, xa). Cp nht thng tin kho sch nu cn thit (thm, sa, xa). Cp nht thng tin sch nu cn thit (sa, xa). Cn tnh tng lng nhp v n gi nhp (phi ph hp vi s lng, gi bn v chit khu nhp). Module bn sch: Lp ha n bn. Nhp sch bn vo ha n bn (cho php chnh sa n gi sch nhp vo sau cng). Cp nht thng tin khch hng nu cn thit (khch hng mua s).(thm, sa, xa) Cn c chc nng tnh tin (tng s lng mua v tng tin) tng ng vi ha n s (c chit khu xut) v l (khng tnh chit khu xut). Module xut tr sch: Lp phiu xut tr sch, ghi nhn l do xut tr, kim tra s lng xut tr c ph hp vi s lng nhp khng? Module thng k: gm cc thng k sau: Sch bn: Theo tn sch Theo ngy bn (t ngy n ngy) Theo loi sch Theo nh xut bn Theo khch hng Tt c Sch bn nhiu nht, sch bn it nht Sch nhp: Theo nh phn phi sch Theo chit khu nhp Theo nh xut bn Theo ngy thng nhp (t ngy n ngy) Tt c Sch nhp nhiu nht, t nht Sch tn kho: Theo loi sch Theo ngy lp (t ngy n ngy) Theo nh xut bn

Theo sch Tt c Sch tn nhiu nht, sch tn t nht Sch xut tr: Theo nh phn phi sch Tt c Sch tr nhiu nht, sch tr t nht Thu tin mt: Theo nhn vin Theo ngy thng (t ngy n ngy) Theo khch hng Tt c Tin thu nhiu nht, tin thu t nht Chi tin mt v n tn: Theo nh phn phi sch Tt c Chi nhiu nht, chi t nht Module bo co: Bo co sch bn (ni dung bo co gm: tn sch, s lng bn, n gi bn) Bo co doanh thu theo ngy bn (ni dung bo co gm: ngy lp ha n, tng s lng bn, tng n gi cha thu, thnh tin thu) Bo co doanh thu theo khch hng (ni dung bo co gm: tn khch hng, tng n gi cha thu, thnh tin thu) Bo co sch nhp (ni dung bo co gm: tn sch, s lng, n gi) Bo co nhp sch theo ngy nhp (ni dung bo co gm: ngy lp phiu nhp, tng s lng nhp, thnh tin nhp) Bo co nhp sch theo nh phn phi (ni dung bo co gm: tn nh phn phi sch, tng s lng nhp, thnh tin nhp) Bo co sch xut tr (ni dung bo co gm: tn sch, l do xut tr, s lng tr, s lng nhp thc s) Bo co tin thu t sch xut tr (ni dung bo co gm: ngy lp phiu xut tr, tin thu) Bo co tin chi + n tn (ni dung bo co gm: tn nh phn phi sch, s tin chi, n tn) Module chi tin: Lp phiu chi, cp nht n tn, kim tra tin chi khng cho vt qu n gi nhp. Coding: Qu trnh coding c thc hin sau khi thit k MCD, MLD, MPD v c s d liu. Trong qu trnh thc hin, ny sinh mt s li do cc m hnh cha tht s ng nn va chnh li m hnh, va code. Nhn xt: Sau qu trnh coding, nhn thy qu trnh phn tch v thit k kh hn coding rt nhiu v phi c nhiu kinh nghim trong c thit k v coding th mi c th lm tt cng vic phn tch v thit k. Thc hin phn tch v thit k cha tt, dn n va code va cp nht li m hnh. Cn hc hi thc hin cc bi lm nhiu hn c th nm bt c cc bi hc trn lp mt cch hiu qu.

KT QU T C
Chng trnh qun l mua bn sch ca mt nh sch hon thnh, tuy cha tht s chuyn nghip nhng cng p ng c mt s yu cu c bn m chng trnh cn c. C thm kin thc v phn tch thit k h thng v lp trnh i km vi h thng c thit k trn m hnh. Bit cch phn chia thi gian lm cch phn khc nhau.

TI LIU THAM KHO


Cc trang web:
http://www.scribd.com/doc/56379718/14/Ph%C6%B0%C6%A1ng-phap-phan-tich-thi%E1%BA %BFt-k%E1%BA%BF-Merise

v mt s trang khc c tm kim qua google.


TRO GIUP ng nhp:
Nhp vo username v password tng ng. Ty quyn ca ngi dng s c thc hin nhng cng vic tng ng.

Bo co:
Bo co sch nhp, bn, doanh thu, n tn, sch xut tr, tin xut ra,...

Nhp sch:
Lp mi phiu nhp, sau nhp mi thng tin sch. Ch : gi bn nhp vo l gi 1 quyn sch, s lng l s lng nhp sch , chit khu nhp c tnh theo nh phn phi sch, n gi nhp vo theo ha n mua phi ph hp vi gi bn, s lng nhp, chit khu nhp ca sch . Nu c sai xt, c th dng chc nng cp nht phiu nhp chnh sa. C th xa phiu nhp vi iu kin thng tin phiu nhp khng cn thit na. Khi nhp thng tin sch mi, nu c sai xt c th cp nht li bng chc nng cp nht sch. C th xa thng tin sch vi iu kin sch khng cn thit phi lu tr thng tin na. Trong qu trnh nhp mi sch c th cn thit thm mi loi sch. Chc nng cp nht loi sch cho php thc hin vic ny. Ngoi ra c th sa thng tin loi sch, xa loi sch khng cn cn thng tin na,... Khi cn cp nht thm thng tin nh phn phi sch, c th dng chc nng cp nht nh phn phi sch. C th xa thng tin nh phn phi sch vi iu kin thng tin nh phn phi sch khng cn thit na. Khi cn cp nht thng tin nh xut bn c th dng chc nng cp nht nh xut bn. Thng tin nh xut bn ch c xa khi khng cn thit na. Kho sch c qun l bi nhn vin nhp sch. Khi cn cp nht thng tin kho, dng chc nng cp nht kho sch, thng tin kho sch ch c xa khi khng cn thit dng na.

Xut tr sch:
Lp phiu xut tr sch, cp nht cc sch cn xut tr. Nu tr vt qu s lng nhp, h thng s bo.

Khi tr cn thanh tan tin thu ngay lp tc. C th tm kim sch bng cch nhp tn sch, do c trng hp sch trng tn nhng c m s khc nhau nn nhn vin cn ch nhp ng thng tin quyn sch cn tr.

Chi tin:
Chi tin cho phiu nhp, nu s tin chi vt qu s tin nhp, h thng s bo. Sau khi chi, n tn s c cp nht li.

Phn quyn:
Phn quyn nhn vin da theo nhm ngi dng. Khi cn cp nht hay thm mi nhn vin, c th dng chc nng cp nht thng tin nhn vin. Thng tin nhn vin ch c xa khi khng cn cn thit dng na. C th cp nh danh (username) v password cho nhn vin khi nhn vin c gn nhm ng nhp vo h thng lm vic tng ng. Nhm: ging nh chc v. Gm cc nhm sau: nhp sch, bn sch, bo co, thng k, phn quyn, xut tr sch, chi tin, qun l (gm tt c cc nhm).

Thng k:
Cho php thng k sch nhp, sch bn, sch xut tr, tin thu vo, tin n, doanh thu t cc khch hng s, l, thu tin t nhn vin,....

Bn sch:
Lp ha n bn cho khch hng, sau nhp vo sch cc sch cn bn trong ha n . Nu nhp sai n gia sch, c th dng chc nng cp nht n gi sch, nhng khng cho php cp nht s lng. Ch : nu nhp sai phi cp nht li ngay lp tc, v ch cho php cp nht sch nhp vo sau cng ha n bn mi nht. Ch : trng hp sch cng tn, cng ni dung, nhng nhp vo nhng thi im khc nhau th c m s khc nhau. V d: sch A c m s 1 cn 7 quyn, sch A c m s 9 cn 6 quyn, vy khi nhn vin bn 8 quyn h thng s bo sch ny cn 7 quyn, nhn vin cn nhp vo bn 7 quyn, sau nhp thm mt ln na bn sch A vi s lng 1 quyn. (Ch ny cn bt cp, s c gng nng cp li sau). Nu nhp li ln hai (hay khc na) m h thng bo cn 0 quyn ngha l sch ny trong kho ht, cn nhp thm. Khi bn sch cn ch khch hng mua l hay s, nu mua s cn thm thng tin khch hng vo ha n bn. Nu l khch hng mi nhn vin c th thm mi thng tin khch hng. C th cp nht (thay i) thng tin khch hng khi cn thit.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy