private void btnTransaction_Click(object sender, EventArgs e) { using (var conn = new SqlConnection(conStr)) { var cmd = conn.CreateCommand(); cmd.CommandType = CommandType.Text; cmd.CommandText = "Select * from Transactions"; conn.Open(); DataTable dt = new DataTable(); SqlDataAdapter da = new SqlDataAdapter(cmd); da.Fill(dt); List <TransactionCls> transactions = new List <TransactionCls>(); for (int i = 0; i < dt.Rows.Count; i++) { TransactionCls obj = new TransactionCls(); obj.TransID = Convert.ToInt32(dt.Rows[i]["TransactionID"].ToString()); obj.AccNO = Convert.ToInt32(dt.Rows[i]["AccountNo"].ToString()); obj.BranchID = Convert.ToInt32(dt.Rows[i]["BranchID"].ToString()); obj.Deposit = Convert.ToDecimal(dt.Rows[i]["Deposit"].ToString()); obj.Withdraw = Convert.ToDecimal(dt.Rows[i]["Withdraw"].ToString()); obj.TransacDate = Convert.ToDateTime(dt.Rows[i]["TransactionDate"].ToString()); transactions.Add(obj); } using (TransactionPrintReport prForm = new TransactionPrintReport(transactions)) { prForm.ShowDialog(); } } }
private void btnAdd_Click(object sender, EventArgs e) { using (var conn = new SqlConnection(conStr)) { TransactionCls transaction = new TransactionCls(); try { transaction.TransID = Convert.ToInt32(textTranID.Text); } catch (Exception) { MessageBox.Show("Transaction ID occured error"); } try { transaction.AccNO = Convert.ToInt32(textAccNo.Text); } catch (Exception) { MessageBox.Show("Account no. occured error"); } try { transaction.BranchID = Convert.ToInt32(textBranchID.SelectedValue); } catch (Exception) { MessageBox.Show("Branch occured error"); } try { transaction.Deposit = Convert.ToDecimal(textDeposit.Text); } catch (Exception) { MessageBox.Show("Money occured error"); } try { transaction.Withdraw = Convert.ToDecimal(textWithdraw.Text); } catch (Exception) { MessageBox.Show("Money occured error"); } try { transaction.TransacDate = Convert.ToDateTime(dtTransDate.Text); } catch (Exception) { MessageBox.Show("Invalid date format"); } int count = 0; var cmd = conn.CreateCommand(); cmd.CommandType = CommandType.Text; cmd.CommandText = "Insert into Transactions (TransactionID,AccountNo,BranchID,Deposit, Withdraw,TransactionDate) " + "values ('" + transaction.TransID + "','" + transaction.AccNO + "','" + transaction.BranchID + "','" + transaction.Deposit + "','" + transaction.Withdraw + "','" + transaction.TransacDate + "')"; conn.Open(); count = cmd.ExecuteNonQuery(); if (count > 0) { MessageBox.Show("INSERTED..."); } else { MessageBox.Show("ERROR!!!"); } } LoadDataInGrid(); ClearTextBox(); }
private void btnDelete_Click(object sender, EventArgs e) { using (var conn = new SqlConnection(conStr)) { TransactionCls transaction = new TransactionCls(); try { transaction.TransID = Convert.ToInt32(textTranID.Text); } catch (Exception ex) { MessageBox.Show(ex.Message); } try { transaction.AccNO = Convert.ToInt32(textAccNo.Text); } catch (Exception ex) { MessageBox.Show(ex.Message); } try { transaction.BranchID = Convert.ToInt32(textBranchID.SelectedValue); } catch (Exception ex) { MessageBox.Show(ex.Message); } try { transaction.Deposit = Convert.ToDecimal(textDeposit.Text); } catch (Exception) { MessageBox.Show("Invalid money input"); } try { transaction.Withdraw = Convert.ToDecimal(textWithdraw.Text); } catch (Exception) { MessageBox.Show("Invalid money input"); } try { transaction.TransacDate = Convert.ToDateTime(dtTransDate.Text); } catch (Exception) { MessageBox.Show("Invalid date format"); } int count = 0; var cmd = conn.CreateCommand(); cmd.CommandType = CommandType.Text; cmd.CommandText = "Delete from Transactions where AccountNo=" + transaction.AccNO + " and TransactionID='" + transaction.TransID + "'"; conn.Open(); count = cmd.ExecuteNonQuery(); if (count > 0) { MessageBox.Show("DELETED..."); } else { MessageBox.Show("ERROR!!!"); } } LoadDataInGrid(); ClearTextBox(); }