private void Build_btn_Click(object sender, System.EventArgs e) { try { if (Activity_Name_txt.Text == "") { MessageBox.Show("Activity Name is empty", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); Activity_Name_txt.Focus(); } else if (Location_txt.Text == "") { MessageBox.Show("Location is empty", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); Location_txt.Focus(); } else if (School_Term_txt.Text == "") { MessageBox.Show("School Term is empty", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); School_Term_txt.Focus(); } else if (Activity_Description_txt.Text == "") { MessageBox.Show(" Activity Description is empty", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); Activity_Description_txt.Focus(); } else if (Cash_txt.Value == 0) { MessageBox.Show("Cash Payment is empty", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); Cash_txt.Focus(); } else { connection.Open(); OleDbCommand command = connection.CreateCommand(); command.CommandType = CommandType.Text; command.CommandText = "insert into [Activity_Managment_tbl] (Activity_Name,Location,School_Term,From_Date,To_Date,Activity_Description,Cash_Fees,Accountant) values ('" + Activity_Name_txt.Text.Trim() + "','" + Location_txt.Text.Trim() + "','" + School_Term_txt.Text.Trim() + "','" + From_Date_dateTimePicker.Text.Trim() + "','" + To_Date_dateTimePicker.Text.Trim() + "','" + Activity_Description_txt.Text.Trim() + "','" + Cash_txt.Value + "','" + User_txt.Text.Trim() + "')"; command.ExecuteNonQuery(); connection.Close(); MessageBox.Show(Activity_Name_txt.Text.Trim() + " will be at " + Location_txt.Text.Trim() + ".\nFrom ;\t\t" + From_Date_dateTimePicker.Value + "\nTo ;\t\t" + To_Date_dateTimePicker.Value + "\n\n\t*****Enjoy Yourself :)*****", "Successful", MessageBoxButtons.OK, MessageBoxIcon.Information); Activity_Name_txt.Text = ""; Location_txt.Text = ""; School_Term_txt.Text = ""; Activity_Description_txt.Text = ""; Cash_txt.Value = 0; Activity_Name_txt.Focus(); } } catch (Exception ex) { connection.Close(); MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); MessageBox.Show(ex.StackTrace, "Error Location", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } }
private void Add_Expense_btn_Click(object sender, EventArgs e) { #region Previous Values try { string Uniform_Query = "Select [Total_Cash_Expenses],[Total_Transfer_Expenses],[Total_Bank_Expenses],[Total_Other_Expenses],[Total_Expenses],[Total_Profit] FROM [Activity_Managment_tbl] WHERE Activity_Name = '" + Activity_Name_txt.Text.Trim() + "' and School_Term = '" + School_Term_txt.Text.Trim() + "'"; OleDbDataAdapter Uniform_Adapt = new OleDbDataAdapter(Uniform_Query, connection); DataTable Uniform_Tbl = new DataTable(); Uniform_Adapt.Fill(Uniform_Tbl); Total_Cash_Expense_Before_Expense = Convert.ToDecimal(Uniform_Tbl.Rows[(Uniform_Tbl.Rows.Count) - 1][0].ToString()); Total_Transfer_Expense_Before_Expense = Convert.ToDecimal(Uniform_Tbl.Rows[(Uniform_Tbl.Rows.Count) - 1][1].ToString()); Total_Bank_Expense_Before_Expense = Convert.ToDecimal(Uniform_Tbl.Rows[(Uniform_Tbl.Rows.Count) - 1][2].ToString()); Total_Other_Expense_Before_Expense = Convert.ToDecimal(Uniform_Tbl.Rows[(Uniform_Tbl.Rows.Count) - 1][3].ToString()); Total_Expenses_Before_Expense = Convert.ToDecimal(Uniform_Tbl.Rows[(Uniform_Tbl.Rows.Count) - 1][4].ToString()); } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); MessageBox.Show(ex.StackTrace, "Error Location", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } #endregion #region Cash if (Cash_radioButton.Checked == true) { Expense_Method = Cash_radioButton.Text; Total_Cash_Expenses_After_Expense = Total_Cash_Expense_Before_Expense + Expense_Amount_txt.Value; Total_Expense_After_Expense = Total_Expenses_Before_Expense + Expense_Amount_txt.Value; Total_Profit_After_Expense = Total_Cash_Before_Expense - Total_Expense_After_Expense; #region Uniform Update try { connection.Open(); OleDbCommand Total_Cash_Expense_Command = connection.CreateCommand(); Total_Cash_Expense_Command.CommandType = CommandType.Text; Total_Cash_Expense_Command.CommandText = "update [Activity_Managment_tbl] set Total_Cash_Expenses = '" + Total_Cash_Expenses_After_Expense + "' WHERE Activity_Name = '" + Activity_Name_txt.Text.Trim() + "' and School_Term = '" + School_Term_txt.Text.Trim() + "'"; Total_Cash_Expense_Command.ExecuteNonQuery(); OleDbCommand Total_Expense_Command = connection.CreateCommand(); Total_Expense_Command.CommandType = CommandType.Text; Total_Expense_Command.CommandText = "update [Activity_Managment_tbl] set Total_Expenses = '" + Total_Expense_After_Expense + "' WHERE Activity_Name = '" + Activity_Name_txt.Text.Trim() + "' and School_Term = '" + School_Term_txt.Text.Trim() + "'"; Total_Expense_Command.ExecuteNonQuery(); OleDbCommand Total_Profit_Command = connection.CreateCommand(); Total_Profit_Command.CommandType = CommandType.Text; Total_Profit_Command.CommandText = "update [Activity_Managment_tbl] set Total_Profit = '" + Total_Profit_After_Expense + "' WHERE Activity_Name = '" + Activity_Name_txt.Text.Trim() + "' and School_Term = '" + School_Term_txt.Text.Trim() + "'"; Total_Profit_Command.ExecuteNonQuery(); connection.Close(); } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); MessageBox.Show(ex.StackTrace, "Error Location", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } #endregion } #endregion #region Transfer else if (Transfer_radioButton.Checked == true) { Expense_Method = Transfer_radioButton.Text; Total_Transfer_Expenses_After_Expense = Total_Transfer_Expense_Before_Expense + Expense_Amount_txt.Value; Total_Expense_After_Expense = Total_Expenses_Before_Expense + (Expense_Amount_txt.Value * Convert.ToDecimal(Transfer_Rate_lbl.Text)); Total_Profit_After_Expense = Total_Cash_Before_Expense - Total_Expense_After_Expense; #region Uniform Update try { connection.Open(); OleDbCommand Total_Transfer_Expense_Command = connection.CreateCommand(); Total_Transfer_Expense_Command.CommandType = CommandType.Text; Total_Transfer_Expense_Command.CommandText = "update [Activity_Managment_tbl] set Total_Transfer_Expenses = '" + Total_Transfer_Expenses_After_Expense + "' WHERE Activity_Name = '" + Activity_Name_txt.Text.Trim() + "' and School_Term = '" + School_Term_txt.Text.Trim() + "'"; Total_Transfer_Expense_Command.ExecuteNonQuery(); OleDbCommand Total_Expense_Command = connection.CreateCommand(); Total_Expense_Command.CommandType = CommandType.Text; Total_Expense_Command.CommandText = "update [Activity_Managment_tbl] set Total_Expenses = '" + Total_Expense_After_Expense + "' WHERE Activity_Name = '" + Activity_Name_txt.Text.Trim() + "' and School_Term = '" + School_Term_txt.Text.Trim() + "'"; Total_Expense_Command.ExecuteNonQuery(); OleDbCommand Total_Profit_Command = connection.CreateCommand(); Total_Profit_Command.CommandType = CommandType.Text; Total_Profit_Command.CommandText = "update [Activity_Managment_tbl] set Total_Profit = '" + Total_Profit_After_Expense + "' WHERE Activity_Name = '" + Activity_Name_txt.Text.Trim() + "' and School_Term = '" + School_Term_txt.Text.Trim() + "'"; Total_Profit_Command.ExecuteNonQuery(); connection.Close(); } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); MessageBox.Show(ex.StackTrace, "Error Location", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } #endregion } #endregion #region Bank else if (Bank_radioButton.Checked == true) { Expense_Method = Bank_radioButton.Text; Total_Bank_Expenses_After_Expense = Total_Bank_Expense_Before_Expense + Expense_Amount_txt.Value; Total_Expense_After_Expense = Total_Expenses_Before_Expense + (Expense_Amount_txt.Value * Convert.ToDecimal(Bank_Rate_lbl.Text)); Total_Profit_After_Expense = Total_Cash_Before_Expense - Expense_Amount_txt.Value; #region Uniform Update try { connection.Open(); OleDbCommand Total_Bank_Expense_Command = connection.CreateCommand(); Total_Bank_Expense_Command.CommandType = CommandType.Text; Total_Bank_Expense_Command.CommandText = "update [Activity_Managment_tbl] set Total_Bank_Expenses = '" + Total_Bank_Expenses_After_Expense + "' WHERE Activity_Name = '" + Activity_Name_txt.Text.Trim() + "' and School_Term = '" + School_Term_txt.Text.Trim() + "'"; Total_Bank_Expense_Command.ExecuteNonQuery(); OleDbCommand Total_Expense_Command = connection.CreateCommand(); Total_Expense_Command.CommandType = CommandType.Text; Total_Expense_Command.CommandText = "update [Activity_Managment_tbl] set Total_Expenses = '" + Total_Expense_After_Expense + "' WHERE Activity_Name = '" + Activity_Name_txt.Text.Trim() + "' and School_Term = '" + School_Term_txt.Text.Trim() + "'"; Total_Expense_Command.ExecuteNonQuery(); OleDbCommand Total_Profit_Command = connection.CreateCommand(); Total_Profit_Command.CommandType = CommandType.Text; Total_Profit_Command.CommandText = "update [Activity_Managment_tbl] set Total_Profit = '" + Total_Profit_After_Expense + "' WHERE Activity_Name = '" + Activity_Name_txt.Text.Trim() + "' and School_Term = '" + School_Term_txt.Text.Trim() + "'"; Total_Profit_Command.ExecuteNonQuery(); connection.Close(); } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); MessageBox.Show(ex.StackTrace, "Error Location", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } #endregion } #endregion #region Other else if (Other_radioButton.Checked == true) { Expense_Method = Other_radioButton.Text; Total_Other_Expenses_After_Expense = Total_Other_Expense_Before_Expense + Expense_Amount_txt.Value; Total_Expense_After_Expense = Total_Expenses_Before_Expense + (Expense_Amount_txt.Value * Convert.ToDecimal(Other_Rate_lbl.Text)); Total_Profit_After_Expense = Total_Cash_Before_Expense - Total_Expense_After_Expense; #region Uniform Update try { connection.Open(); OleDbCommand Total_Other_Expense_Command = connection.CreateCommand(); Total_Other_Expense_Command.CommandType = CommandType.Text; Total_Other_Expense_Command.CommandText = "update [Activity_Managment_tbl] set Total_Other_Expenses = '" + Total_Other_Expenses_After_Expense + "' WHERE Activity_Name = '" + Activity_Name_txt.Text.Trim() + "' and School_Term = '" + School_Term_txt.Text.Trim() + "'"; Total_Other_Expense_Command.ExecuteNonQuery(); OleDbCommand Total_Expense_Command = connection.CreateCommand(); Total_Expense_Command.CommandType = CommandType.Text; Total_Expense_Command.CommandText = "update [Activity_Managment_tbl] set Total_Expenses = '" + Total_Expense_After_Expense + "' WHERE Activity_Name = '" + Activity_Name_txt.Text.Trim() + "' and School_Term = '" + School_Term_txt.Text.Trim() + "'"; Total_Expense_Command.ExecuteNonQuery(); OleDbCommand Total_Profit_Command = connection.CreateCommand(); Total_Profit_Command.CommandType = CommandType.Text; Total_Profit_Command.CommandText = "update [Activity_Managment_tbl] set Total_Profit = '" + Total_Profit_After_Expense + "' WHERE Activity_Name = '" + Activity_Name_txt.Text.Trim() + "' and School_Term = '" + School_Term_txt.Text.Trim() + "'"; Total_Profit_Command.ExecuteNonQuery(); connection.Close(); } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); MessageBox.Show(ex.StackTrace, "Error Location", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } #endregion } #endregion #region Insert Into Expense Record try { OleDbCommand Activity_Command = new OleDbCommand { CommandType = CommandType.Text, CommandText = "INSERT INTO [Activity_Directed_Expenses_tbl] ([Activity_Name],[School_Term],[Activity_Date],[Expense_Description],[Expense_Type],[Expense_Amount],[Accountant])" + "VALUES (?,?,?,?,?,?,?)" }; Activity_Command.Parameters.AddWithValue("@Activity_Name", Activity_Name_txt.Text.Trim()); Activity_Command.Parameters.AddWithValue("@School_Term", School_Term_txt.Text.Trim()); Activity_Command.Parameters.AddWithValue("@Activity_Date", Expense_Date_dateTimePicker.Text.Trim()); Activity_Command.Parameters.AddWithValue("@Expense_Description", Expense_Description_txt.Text.Trim()); Activity_Command.Parameters.AddWithValue("@Expense_Type", Expense_Method.Trim()); Activity_Command.Parameters.AddWithValue("@Expense_Amount", Expense_Amount_txt.Value); Activity_Command.Parameters.AddWithValue("@Accountant", User_txt.Text.Trim()); Activity_Command.Connection = connection; connection.Open(); Activity_Command.ExecuteNonQuery(); connection.Close(); } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); MessageBox.Show(ex.StackTrace, "Error Location", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } #endregion #region Table Load try { connection.Open(); OleDbCommand Table_Load_command = connection.CreateCommand(); Table_Load_command.CommandType = CommandType.Text; Table_Load_command.CommandText = "select * from [Activity_Directed_Expenses_tbl]"; Table_Load_command.ExecuteNonQuery(); DataTable dta = new DataTable(); OleDbDataAdapter adapt = new OleDbDataAdapter(Table_Load_command); adapt.Fill(dta); Expense_Managment_dataGridView.DataSource = dta; connection.Close(); } catch (Exception ex) { MessageBox.Show(ex.Message); } #endregion Expense_Description_txt.Text = ""; School_Term_txt.Text = ""; Activity_Name_txt.Text = ""; School_Term_txt.Focus(); Expense_Amount_txt.Value = 0; Total_Received_txt.Value = Total_Cash_Before_Expense; Total_Expenses_txt.Value = Total_Expense_After_Expense; Activity_Profit_txt.Text = Total_Profit_After_Expense.ToString(); }