none
An unhandled exception of type 'System.StackOverflowException' occurred in mscorlib.dll RRS feed

  • Question

  • using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Data;
    using System.Windows.Forms;
    using MySql.Data.MySqlClient;
    namespace PayrollSystem
    {
       public class EmployeeForm_Class
       {
          MySqlConnection con = new MySqlConnection("datasource = localhost; username = root; password=; database = payrollsystem");
          EmployeesForm obj_EmpForm = new EmployeesForm();
          UpdateEmployee obj_UpForm = new UpdateEmployee();
          public void Display()
          {
             //To display all employees data
             MySqlDataAdapter adapter = new MySqlDataAdapter("SELECT id_emp as 'ID', date_hired as 'Date Hired', department as 'Department', name as 'Name',birthdate as 'Birthdate', contact_no as 'Contact No.', position as 'Position', rate as 'Rate', working_days as 'Working Days', working_timein as 'Time In', working_timeout as 'Time Out', balance as 'Balance' from tbl_employees ORDER BY id_emp DESC", con);
             con.Open();
             DataSet ds = new DataSet();
             adapter.Fill(ds, "tbl_employees");
             obj_EmpForm.display_employees.DataSource = ds.Tables["tbl_employees"];
             con.Close();
          }
          public void Update()
          {
             if (obj_EmpForm.display_employees.SelectedRows.Count == 0)
             {
                MessageBox.Show("None is Selected", "", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
             }
             else
             {
                //Passing the contents of the selected row to the UpdateEmployee Form
                obj_UpForm.txtId.Text = obj_EmpForm.display_employees.CurrentRow.Cells[0].Value.ToString();
                obj_UpForm.txtDateHired.Text = obj_EmpForm.display_employees.CurrentRow.Cells[1].Value.ToString();
                obj_UpForm.oldDept.Text = obj_EmpForm.display_employees.CurrentRow.Cells[2].Value.ToString();
                obj_UpForm.oldName.Text = obj_EmpForm.display_employees.CurrentRow.Cells[3].Value.ToString();
                obj_UpForm.oldBirthdate.Text = obj_EmpForm.display_employees.CurrentRow.Cells[4].Value.ToString();
                obj_UpForm.oldContactNumber.Text = obj_EmpForm.display_employees.CurrentRow.Cells[5].Value.ToString();
                obj_UpForm.oldPosition.Text = obj_EmpForm.display_employees.CurrentRow.Cells[6].Value.ToString();
                obj_UpForm.oldRate.Text = obj_EmpForm.display_employees.CurrentRow.Cells[7].Value.ToString();
                obj_UpForm.oldDays.Text = obj_EmpForm.display_employees.CurrentRow.Cells[8].Value.ToString();
                obj_UpForm.oldIn.Text = obj_EmpForm.display_employees.CurrentRow.Cells[9].Value.ToString();
                obj_UpForm.oldOut.Text = obj_EmpForm.display_employees.CurrentRow.Cells[10].Value.ToString();
                obj_UpForm.Show();
                obj_EmpForm.Hide();
             }
          }
          public void Delete()
          {
             string id_emp = obj_EmpForm.display_employees.CurrentRow.Cells[0].Value.ToString();
             string name = obj_EmpForm.display_employees.CurrentRow.Cells[3].Value.ToString();
             if (obj_EmpForm.display_employees.SelectedRows.Count == 0)
             {
                MessageBox.Show("None is Selected", "", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
             }
             else
             {
                DialogResult Validation = MessageBox.Show("Are you sure you want to delete " + name + "?", "Delete Account", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                if (Validation == DialogResult.Yes)
                {
                   string command_update = string.Format("UPDATE `tbl_employees` SET `statuts`= 'Inactive' where id_emp = '" + id_emp + "'");
                   con.Open();
                   MySqlCommand cmd_update = new MySqlCommand(command_update, con);
                   if (cmd_update.ExecuteNonQuery() == 1)
                   {
                      MessageBox.Show("Data deleted");
                   }
                   else
                   {
                      MessageBox.Show("Data not deleted");
                   }
                   con.Close();
                   obj_EmpForm.txtSearchBox.Clear();
                }
                return;
             }
         
          }
          public void Search()
          {
             if (obj_EmpForm.txtSearchBox.Text.Length == 0)
             {
                MessageBox.Show("None inputted", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
             }
             else
             {
                string command_searching = string.Format("SELECT id_emp as 'ID', date_hired as 'Date Hired', department as 'Department', name as 'Name',birthdate as 'Birthdate', contact_no as 'Contact No.', position as 'Position', rate as 'Rate', working_days as 'Working Days', working_timein as 'Time In', working_timeout as 'Time Out', balance as 'Balance' FROM tbl_employees WHERE CONCAT(`id_emp`, `date_hired`, `department`, `name`, `birthdate`, `contact_no`, `position`, `rate`, `working_days`, `working_timein`, `working_timeout`, `balance`) LIKE '%" + obj_EmpForm.txtSearchBox.Text + "%'");
                con.Open();
                MySqlCommand cmd_searching = new MySqlCommand(command_searching, con);
                MySqlDataAdapter adapter_searching = new MySqlDataAdapter(cmd_searching);
                DataTable table = new DataTable();
                adapter_searching.Fill(table);
                if (table.Rows.Count != 0)
                {
                   obj_EmpForm.display_employees.DataSource = table;
                }
                else
                {
                   MessageBox.Show("Account doesn't Exist", "", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                con.Close();
                obj_EmpForm.txtSearchBox.Clear();
             }
             return;
          }
          public void Logout()
          {
             DialogResult Sure = MessageBox.Show("Are you sure you want to Sign Out?", "Sign Out", MessageBoxButtons.YesNo);
             if (Sure == DialogResult.Yes)
             {
                Application.Exit();
             }
          }
       }
    }

    Sunday, January 27, 2019 8:53 PM