private void AddBtn_Click(object sender, EventArgs e) { if (listView1.Items.Count > 0) { SellDao selldao = new SellDao(); SqlConnection Conn = Connection.getConnection(); String query = "Insert INTO Sales(PartNo, SellingPrice, DateSold, CustomerType, PartyId, Qty) VALUES(@PartNo, @SellingPrice, @DateSold, @CustomerType, @PartyId, @Qty)"; using (Conn) { 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("@SellingPrice", decimal.Parse(listView1.Items[i].SubItems[1].Text)); cmd.Parameters.AddWithValue("@DateSold", DateTime.Parse(listView1.Items[i].SubItems[2].Text)); cmd.Parameters.AddWithValue("@CustomerType", listView1.Items[i].SubItems[3].Text); if (listView1.Items[i].SubItems[3].Text.Equals("Customer")) { cmd.Parameters.AddWithValue("@PartyId", DBNull.Value); } else { cmd.Parameters.AddWithValue("@PartyId", int.Parse(listView1.Items[i].SubItems[4].Text)); } cmd.Parameters.AddWithValue("@Qty", int.Parse(listView1.Items[i].SubItems[5].Text)); cmd.ExecuteNonQuery(); selldao.DecreaseQuanity(listView1.Items[i].SubItems[0].Text, int.Parse(listView1.Items[i].SubItems[5].Text)); } } MessageBox.Show("Transaction Done!"); Form1.PublicMainForm.showSales(); Form1.PublicMainForm.DisplayStockEndingAlert(); this.Close(); } else { MessageBox.Show("Select items and payment amount."); } }
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."); } }