private void btntimkiem_Click(object sender, EventArgs e) { if (txtTenNCU.Text == string.Empty && txtSĐT.Text == string.Empty && cbQuymoNCU.Text == string.Empty) { MessageBox.Show("Bạn phải nhập điều kiện tìm kiếm!", "Warning!", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } DTO_NCU ncu = new DTO_NCU(); ncu.Tenncu = txtTenNCU.Text; ncu.Sdt = txtSĐT.Text; ncu.Quymoncu = cbQuymoNCU.Text; DataTable dt = BUS_NCU.timkiemNCU(ncu.Tenncu, ncu.Sdt, ncu.Quymoncu); DGVNCU.DataSource = dt; if (dt.Rows.Count == 0) { lblkqtkncu.Text = "Không có nhà cung ứng nào thoả mãn điều kiện tìm kiếm!"; } else { lblkqtkncu.Text = "Có " + dt.Rows.Count + " nhà cung ứng nào thoả mãn điều kiện tìm kiếm!"; } DANGNHAP.thaotac += "Tìm kiếm, "; }
private void LoadDataGridView() { ncu = BUS_NCU.hienthiNCU(); //Lấy dữ liệu từ bảng DGVNCU.DataSource = ncu; DGVNCU.AllowUserToAddRows = false; DGVNCU.EditMode = DataGridViewEditMode.EditProgrammatically; }
private void cbMaNCU_Leave(object sender, EventArgs e) { if (cbMaNCU.Text.Trim().Length != 0) { DataTable dt = BUS_NCU.hienthiNCU(); if (dt != null) { if (dt.Rows.Count > 0) { bool flag = false; DataRow dr; for (int i = 0; i < dt.Rows.Count; ++i) { dr = dt.Rows[i]; if (cbMaNCU.Text.Trim() == dr[0].ToString()) { flag = true; break; } else { flag = false; } } if (flag == false) { MessageBox.Show("Mã nhà cung ứng không tồn tại. Hãy kiểm tra lại và chọn mã khác!", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error); cbMaNCU.Focus(); return; } } } } }
private void btnSua_Click(object sender, EventArgs e) { if (ncu.Rows.Count == 0) { MessageBox.Show("Không còn dữ liệu", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } if (txtMaNCU.Text == "Mã nhà cung ứng sẽ tự động thêm!") { MessageBox.Show("Bạn chưa chọn bản ghi nào", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } if (txtTenNCU.Text.Trim().Length == 0) { MessageBox.Show("Bạn phải nhập tên nhà cung ứng", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); txtTenNCU.Focus(); return; } if (txtDiaChi.Text.Trim().Length == 0) { MessageBox.Show("Bạn phải nhập địa chỉ", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); txtDiaChi.Focus(); return; } if (txtSĐT.Text.Trim().Length == 0) { MessageBox.Show("Bạn phải nhập điện thoại", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); txtSĐT.Focus(); return; } if (cbQuymoNCU.Text.Trim().Length == 0) { MessageBox.Show("Bạn phải nhập quy mô NCƯ", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); cbQuymoNCU.Focus(); return; } DTO_NCU NCU = new DTO_NCU(txtMaNCU.Text, txtTenNCU.Text, txtDiaChi.Text, txtSĐT.Text, cbQuymoNCU.Text, txtconnoncu.Text); BUS_NCU.suaNCU(NCU); LoadDataGridView(); ResetValues(); DANGNHAP.thaotac += "Sửa, "; }
private void btnXoa_Click(object sender, EventArgs e) { if (ncu.Rows.Count == 0) { MessageBox.Show("Không còn dữ liệu!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } if (txtMaNCU.Text == "Mã nhà cung ứng sẽ tự động thêm!") { MessageBox.Show("Bạn chưa chọn bản ghi nào", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } if (MessageBox.Show("Xoá nhà cung ứng sẽ xoá tất cả dữ liệu của nhà cung ứng và tất cả các thông tin về nhà cung ứng trên bảng sản phẩm, bảng hoá đơn nhập, bảng hoá đơn bán và bảng thống kê công nợ. Bạn có chắc chắn muốn xóa không?", "Thông báo", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK) { //Lấy mã nhà cung ứng trên bảng thống kê công nợ và xoá thông tin của NCƯ trên bảng thống kê công nợ. List <string> id = new List <string>(); DataTable dt; DataRow dr; dt = BUS_CNCT.hienthiCNCT(); if (dt.Rows.Count > 0) { for (int i = 0; i < dt.Rows.Count; ++i) { dr = dt.Rows[i]; if (dr[1].ToString() == txtMaNCU.Text) { id.Add(dr["IdCN"].ToString()); } } } //Xóa trên bảng công nợ chi tiết foreach (string item in id) { BUS_CN.RunDelSQLOnCNCT(item); } id.Clear(); //xóa nhà cung ứng trên bảng hóa đơn nhập //Lấy mã hóa đơn nhập trên bảng hóa đơn nhập dt = BUS_HDN.hienthiHDN(); if (dt.Rows.Count > 0) { for (int i = 0; i < dt.Rows.Count; ++i) { dr = dt.Rows[i]; if (dr[2].ToString() == txtMaNCU.Text) { id.Add(dr["IdHDN"].ToString()); } } } //Xóa trên bảng hóa đơn nhập chi tiết foreach (string item in id) { BUS_HDN.RunDelSQLOnHDNCT(item); BUS_HDN.RunDelSQL(item); } id.Clear(); //Lấy mã sản phẩm trên bảng sản phẩm để xóa sản phẩm dt = BUS_SP.hienthisp(); if (dt.Rows.Count > 0) { for (int i = 0; i < dt.Rows.Count; ++i) { dr = dt.Rows[i]; if (dr[1].ToString() == txtMaNCU.Text) { id.Add(dr["IdSP"].ToString()); } } } //Xóa trên bảng sản phẩm foreach (string item in id) { BUS_SP.RunDelSQLOnHTCT(item); BUS_SP.RunDelSQLOnHDBCT(item); BUS_SP.RunDelSQLOnHDNCT(item); BUS_SP.RunDelSQL(item); } BUS_NCU.RunDelSQL(txtMaNCU.Text); LoadDataGridView(); ResetValues(); //Cập nhật lại mã nhà cung ứng trên combobx mã nhà cung ứng trên form sản phẩm. CapnhatCB_NCU(); DANGNHAP.thaotac += "Xoá, "; } }
private void btnThem_Click(object sender, EventArgs e) { if (txtTenNCU.Text.Trim().Length == 0) { MessageBox.Show("Bạn phải nhập tên nhà cung ứng", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); txtTenNCU.Focus(); return; } if (txtDiaChi.Text.Trim().Length == 0) { MessageBox.Show("Bạn phải nhập địa chỉ", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); txtDiaChi.Focus(); return; } if (txtSĐT.Text.Trim().Length == 0) { MessageBox.Show("Bạn phải nhập điện thoại", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); txtSĐT.Focus(); return; } if (cbQuymoNCU.Text.Trim().Length == 0) { MessageBox.Show("Bạn phải nhập quy mô NCƯ", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); cbQuymoNCU.Focus(); return; } //tạo mã ngẫu nhiên int value; bool kt = false; Random rand = new Random(); value = rand.Next(100000000, 999999999); string mancu = "NCU" + value; DataRow dr; if (BUS_NCU.hienthiNCU().Rows.Count > 0) { while (kt == false) { for (int i = 0; i < BUS_NCU.hienthiNCU().Rows.Count; ++i) { dr = BUS_NCU.hienthiNCU().Rows[i]; if (mancu == dr["IdNCU"].ToString()) { kt = false; value = rand.Next(100000000, 999999999); mancu = "NCU" + value; break; } else { kt = true; } } } } //Kiểm tra đã tồn tại mã nhà cung ứng chưa if (!BUS_NCU.ktncutrung(mancu)) { MessageBox.Show("Mã nhà cung ứng này đã tồn tại", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); txtMaNCU.Focus(); return; } //Chèn thêm DTO_NCU ncu = new DTO_NCU(mancu, txtTenNCU.Text, txtDiaChi.Text, txtSĐT.Text, cbQuymoNCU.Text, txtconnoncu.Text); BUS_NCU.themNCU(ncu); LoadDataGridView(); ResetValues(); //Cập nhật lại mã nhà cung ứng trên combobx mã nhà cung ứng trên form sản phẩm. CapnhatCB_NCU(); DANGNHAP.thaotac += "Thêm, "; }
private void btnThem_Click(object sender, EventArgs e) { if (cbmanv.Text.Trim().Length == 0) { MessageBox.Show("Bạn phải nhập mã nhân viên!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); cbmanv.Focus(); return; } string manv = cbmanv.Text; //Kiểm tra có bảng thống kê nào rỗng hay không nếu là rỗng thì xóa đi và cập nhật lại combobox tương ứng DataTable table = BUS_CN.hienthiCN(); if (table.Rows.Count > 0) { for (int i = 0; i < table.Rows.Count; ++i) { DataRow r = table.Rows[0]; if (BUS_CNCT.hienthiCNCTcuthe(r[0].ToString()).Rows.Count == 0) { BUS_CN.RunDelSQL(r[0].ToString()); } } BUS_CN.FillComboMaTKCN(cbmatkcn, "IdCN", "IdCN"); cbmatkcn.SelectedIndex = -1; } //Kiểm tra xem có thống kê nào trong tháng được tạo chưa để cập nhật mới DataTable dt = BUS_CN.KiemtraTKCNTonTai(DateTime.Now.Month.ToString(), DateTime.Now.Year.ToString()); if (dt.Rows.Count == 1) { DataRow row = dt.Rows[0]; //Cập nhật thống kê hàng tồn chi tiết dt = BUS_NCU.hienthiNCU(); if (dt.Rows.Count > 0) { for (int i = 0; i < dt.Rows.Count; ++i) { DataRow r = dt.Rows[i]; //Cập nhật lại nợ nhà cung ứng, nếu nợ = 0 thì xóa nhà cung ứng ra khỏi danh sách nợ BUS_CNCT.CapnhatTKCNCT(row[0].ToString(), r[0].ToString()); } //Nếu nhà cung ứng bị xóa khỏi danh sách nhưng sau đó có thêm nợ thì thêm nhà cung ứng vào danh sách nợ DataTable DT = BUS_CNCT.hienthiCNCTcuthe(row[0].ToString()); //Lập danh sách các nhà cung ứng không có trong danh sách nợ List <string> idncu = new List <string>(); for (int i = 0; i < dt.Rows.Count; ++i) { bool flag = false; DataRow r = dt.Rows[i]; for (int j = 0; j < DT.Rows.Count; ++j) { DataRow dr = DT.Rows[j]; if (r[0].ToString() == dr[1].ToString()) { flag = true; break; } } if (flag == false) { idncu.Add(r[0].ToString()); } } foreach (string item in idncu) { DataRow r = BUS_NCU.hienthiNCUcuthe(item).Rows[0]; //Thêm thống kê công nợ chi tiết DTO_CNCT CNCT = new DTO_CNCT(row[0].ToString(), r[0].ToString(), r[1].ToString(), r[3].ToString(), r[2].ToString(), r[5].ToString()); BUS_CNCT.themCNCT(CNCT); } } //Cập nhật ngày thống kê BUS_CN.CapnhatNgayTK(row[0].ToString(), DateTime.Now.ToString()); BUS_CN.FillComboMaTKCN(cbmatkcn, "IdCN", "IdCN"); cbmatkcn.SelectedIndex = -1; ResetValues(); LoadDataGridView(); DANGNHAP.thaotac += "Thêm, "; MessageBox.Show("Đã thống kê xong!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } else { //tạo mã ngẫu nhiên int value; bool kt = false; Random rand = new Random(); value = rand.Next(100000000, 999999999); string macn = "CN" + value; DataRow dr; if (BUS_CN.hienthiCN().Rows.Count > 0) { while (kt == false) { for (int i = 0; i < BUS_CN.hienthiCN().Rows.Count; ++i) { dr = BUS_CN.hienthiCN().Rows[i]; if (macn == dr["IdCN"].ToString()) { kt = false; value = rand.Next(100000000, 999999999); macn = "CN" + value; break; } else { kt = true; } } } } //Kiểm tra đã tồn tại mã thống kê hàng tồn if (!BUS_CN.ktCNtrung(macn)) { MessageBox.Show("Mã công nợ đã tồn tại! Hãy nhấn Thêm lần nữa để lấy mã khác!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); btnThem.Focus(); return; } //Chèn thêm //Thêm thống kê công nợ DTO_CN CN = new DTO_CN(macn, manv, DateTime.Now.ToString()); BUS_CN.themCN(CN); //Thêm thống kê công nợ chi tiết dt = BUS_NCU.hienthiNCU(); DTO_CNCT CNCT; if (dt.Rows.Count > 0) { for (int i = 0; i < dt.Rows.Count; ++i) { DataRow r = dt.Rows[i]; CNCT = new DTO_CNCT(macn, r[0].ToString(), r[1].ToString(), r[3].ToString(), r[2].ToString(), r[5].ToString()); BUS_CNCT.themCNCT(CNCT); } } //giữ thông tin chung của thống kê vừa thêm trên các control dt = BUS_CN.hienthiCNcuthe(macn); if (dt.Rows.Count == 1) { DataRow r = dt.Rows[0]; cbmatkcn.Text = r[0].ToString(); cbmanv.Text = r[1].ToString(); dtpngaytk.Text = r[2].ToString(); } BUS_CN.FillComboMaTKCN(cbmatkcn, "IdCN", "IdCN"); cbmatkcn.SelectedIndex = -1; ResetValues(); LoadDataGridView(); DANGNHAP.thaotac += "Thêm, "; MessageBox.Show("Đã thống kê xong!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } }