private void button1_Click(object sender, EventArgs e) { DebtDao debtdao = new DebtDao(); //InsertDebt(DateTimePicker dtpdealdate, Label GrantTotal, Label PayedAmount, ComboBox Party, DateTimePicker LastPaymentDate) int debtId = debtdao.InsertDebt(dtpDealDate, lblGrandTotal, txtPayment, cbParty, dtpLastPaymentDate); MessageBox.Show(debtId.ToString()); }
private void btnAddDept_Click(object sender, EventArgs e) { if (listView1.Items.Count > 0 && txtPayment.Text != "") { DebtDao debtdao = new DebtDao(); debtId = debtdao.InsertDebt(dtpDealDate, lblGrandTotal, txtPayment, cbParty, dtpLastPaymentDate); SellDao selldao = new SellDao(); String query = "INSERT INTO DebtDetails(PartNo, DebtId, Qty, SellPrice) VALUES(@PartNo, @DeptId, @Qty, @SellPrice)"; using (SqlConnection Conn = Connection.getConnection()) { SqlCommand cmd = new SqlCommand(query, Conn); cmd.CommandType = CommandType.Text; Conn.Open(); for (int i = 0; i < listView1.Items.Count; i++) { cmd.Parameters.Clear(); cmd.Parameters.AddWithValue("@PartNo", listView1.Items[i].SubItems[0].Text); cmd.Parameters.AddWithValue("@SellPrice", listView1.Items[i].SubItems[1].Text); cmd.Parameters.AddWithValue("@Qty", listView1.Items[i].SubItems[3].Text); cmd.Parameters.AddWithValue("@DeptId", debtId); cmd.ExecuteNonQuery(); selldao.DecreaseQuanity(listView1.Items[i].SubItems[0].Text, int.Parse(listView1.Items[i].SubItems[3].Text)); } } MessageBox.Show("Debt Transaction Done!"); Form1.PublicMainForm.DisplayStockEndingAlert(); this.Close(); } else { MessageBox.Show("Select items and payment amount."); } }