public static void ThemCT_PhieuNhap(CT_PHIEUNHAP_DTO p, PHIEUNHAP_DTO q) { SqlConnection connection = new SqlConnection(); connection.ConnectionString = KetNoi.Instance.conn; connection.Open(); SqlCommand cmd = new SqlCommand("ThemCT_PhieuNhap", connection); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add("@NgayNhap", SqlDbType.SmallDateTime); cmd.Parameters.Add("@TongTienNhap", SqlDbType.Int); cmd.Parameters.Add("@MaVTPT", SqlDbType.Int); cmd.Parameters.Add("@DonGia", SqlDbType.Int); cmd.Parameters.Add("@SoLuong", SqlDbType.Int); cmd.Parameters.Add("@ThanhTien", SqlDbType.Int); cmd.Parameters["@NgayNhap"].Value = q.NgayNhap; cmd.Parameters["@TongTienNhap"].Value = q.TongTien; cmd.Parameters["@MaVTPT"].Value = p.MaVTPT; cmd.Parameters["@DonGia"].Value = p.DonGia; cmd.Parameters["@SoLuong"].Value = p.SoLuong; cmd.Parameters["@ThanhTien"].Value = p.ThanhTien; int count = cmd.ExecuteNonQuery(); if (count > 0) { } connection.Close(); }
public static void ThemPhieuSuaChua(PHIEUNHAP_DTO p) { SqlConnection connection = new SqlConnection(); connection.ConnectionString = KetNoi.Instance.conn; connection.Open(); SqlCommand cmd = new SqlCommand("ThemPhieuNhap", connection); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add("@NgayNhap", SqlDbType.SmallDateTime); cmd.Parameters.Add("@TongTienNhap", SqlDbType.Int); cmd.Parameters["@NgayNhap"].Value = p.NgayNhap; cmd.Parameters["@TongTienNhap"].Value = p.TongTien; int count = cmd.ExecuteNonQuery(); if (count > 0) { } connection.Close(); }
private void btnSave_Click(object sender, EventArgs e) { DialogResult dr; dr = MessageBox.Show("Bạn có muốn lưu Phiếu nhập VTPT không ?", "Xác nhận", MessageBoxButtons.OKCancel, MessageBoxIcon.Question); if (dr == DialogResult.OK) { //gán thông tin Phiếu nhập cho đối tượng PHIEUNHAP_DTO PHIEUNHAP_DTO pn = new PHIEUNHAP_DTO(dtpNgayNhap.Value.Date, Convert.ToInt32(txtTongTienNhap.Text)); PHIEUNHAP_DAO.ThemPhieuSuaChua(pn);// lưu phiếu nhập xuống csdl for (int i = 0; i < dgvNhapVTPT.Rows.Count - 1; i++) { //// gán thông tin chi tiết phiếu nhập cho đối tượng CT_PHIEUNHAP_DTO CT_PHIEUNHAP_DTO ct = new CT_PHIEUNHAP_DTO(Convert.ToInt32(dgvNhapVTPT.Rows[i].Cells[1].Value), Convert.ToInt32(dgvNhapVTPT.Rows[i].Cells[2].Value), Convert.ToInt32(dgvNhapVTPT.Rows[i].Cells[3].Value), Convert.ToInt32(dgvNhapVTPT.Rows[i].Cells[4].Value)); CT_PHIEUNHAP_DAO.ThemCT_PhieuNhap(ct, pn);//lưu chi tiết phiếu nhập xuống csdl; } MessageBox.Show("Thêm thành công"); dgvNhapVTPT.ReadOnly = true; } }