public static void Insert(PhieuHangGiaCongDTO phgc) { string sql = "insert into PHIEUHANGGIACONG(MaTho, NgayGiaCong, NgayNhanHangGiaCong, TongCong) values('" + phgc.MaTho + "','" + phgc.NgayGiaCong + "','" + phgc.NgayNhanHangGiaCong + "','" + phgc.TongCong + "')"; DataBase.ExcuNonQuery(sql); }
public static void Delete(PhieuHangGiaCongDTO phgc) { string sql = "delete from PHIEUHANGGIACONG where MaPhieuHangGiaCong = " + phgc.MaPhieuHangGiaCong + ""; DataBase.ExcuNonQuery(sql); }
private void btn_LapPhieu_Click(object sender, EventArgs e) { bool ktra_lapphieuhanggiacong = false; PhieuHangGiaCongDTO phgc = new PhieuHangGiaCongDTO(); ChiTietPhieuHangGiaCongDTO ctphgc = new ChiTietPhieuHangGiaCongDTO(); phgc.NgayGiaCong = dateTimePicker_NgayGiaCong.Value; phgc.NgayNhanHangGiaCong = dateTimePicker_NgayNhanHangGiaCong.Value; phgc.NgayThanhToan = dateTimePicker_NgayThanhToan.Value; phgc.TongCong = uint.Parse(txt_TongCong.Text); try { phgc.MaTho = uint.Parse(txt_MaTho.Text); } catch { MessageBox.Show("Mã thợ không hợp lệ, vui lòng kiểm tra lại!!"); return; } if (PhieuHangGiaCongBUS.ThemPhieuHangGiaCong(phgc) == false) MessageBox.Show("Thêm thất bại!!"); else { DataTable dt = PhieuHangGiaCongDAO.GetAllPhieuHangGiaCong(); phgc.MaPhieuHangGiaCong = Convert.ToUInt32(dt.Rows[dt.Rows.Count - 1]["MaPhieuHangGiaCong"]); ctphgc.MaPhieuHangGiaCong = phgc.MaPhieuHangGiaCong; for (int i = 0; i < dgv_ChiTietPhieuHangGiaCong.Rows.Count - 1; i++) { try { ctphgc.MaHangGiaCong = Convert.ToUInt32(dgv_ChiTietPhieuHangGiaCong.Rows[i].Cells[1].Value); } catch { MessageBox.Show("Mã hàng gia công trong danh sách không hợp lệ, vui lòng kiểm tra lại!!"); return; } try { ctphgc.SoLuong = Convert.ToUInt32(dgv_ChiTietPhieuHangGiaCong.Rows[i].Cells[3].Value); } catch { MessageBox.Show("Số lượng trong danh sách không hợp lệ, vui lòng kiểm tra lại!!"); return; } ctphgc.ThanhTien = Convert.ToUInt32(dgv_ChiTietPhieuHangGiaCong.Rows[i].Cells[5].Value); if (ChiTietPhieuHangGiaCongBUS.ThemChiTietPhieuHangGiaCong(ctphgc) == false) MessageBox.Show("Thêm thất bại!!"); else ktra_lapphieuhanggiacong = true; } if (ktra_lapphieuhanggiacong) { txt_MaPhieu.Text = phgc.MaPhieuHangGiaCong.ToString(); txt_MaTho.ReadOnly = true; dgv_ChiTietPhieuHangGiaCong.ReadOnly = true; btn_LapPhieu.Enabled = false; btn_XoaPhieu.Enabled = true; MessageBox.Show("Lập phiếu hàng gia công thành công!!"); } } }
private void btn_XoaPhieu_Click(object sender, EventArgs e) { DataTable dt = PhieuHangGiaCongDAO.GetAllPhieuHangGiaCong(); PhieuHangGiaCongDTO phgc = new PhieuHangGiaCongDTO(); phgc.MaPhieuHangGiaCong = Convert.ToUInt32(dt.Rows[dt.Rows.Count - 1]["MaPhieuHangGiaCong"]); if (PhieuHangGiaCongBUS.XoaPhieuHangGiaCong(phgc) == false) MessageBox.Show("Xóa thất bại!!"); else { ChiTietPhieuHangGiaCongDTO ctphgc = new ChiTietPhieuHangGiaCongDTO(); ctphgc.MaPhieuHangGiaCong = phgc.MaPhieuHangGiaCong; if (ChiTietPhieuHangGiaCongBUS.XoaChiTietPhieuHangGiaCong(ctphgc) == false) MessageBox.Show("Xóa thất bại!!"); else { btn_XoaPhieu.Enabled = false; TaoPhieuHangGiaCongMoi(); MessageBox.Show("Xóa phiếu hàng gia công thành công!!"); } } }
public static bool XoaPhieuHangGiaCong(PhieuHangGiaCongDTO phgc) { PhieuHangGiaCongDAO.Delete(phgc); return true; }
public static bool ThemPhieuHangGiaCong(PhieuHangGiaCongDTO phgc) { PhieuHangGiaCongDAO.Insert(phgc); return true; }