private void Dash_Click(object sender, EventArgs e) { //[CONNECTION STRINGS] var connectionString = ConfigurationManager.ConnectionStrings["EmployeeManagement"].ConnectionString; SqlConnection con = new SqlConnection(connectionString); //Update all relevant dgvs con.Open(); SqlCommand HolidayData = con.CreateCommand(); HolidayData.CommandType = CommandType.Text; HolidayData.CommandText = "select * from HolidayLeave"; HolidayData.ExecuteNonQuery(); DataTable HolidayDataTable = new DataTable(); SqlDataAdapter HolidayDataAdapter = new SqlDataAdapter(HolidayData); HolidayDataAdapter.Fill(HolidayDataTable); DashHolidayData.DataSource = HolidayDataTable; con.Close(); DashHolidayData.Refresh(); con.Open(); SqlCommand Taskcmd = con.CreateCommand(); Taskcmd.CommandType = CommandType.Text; Taskcmd.CommandText = "select * from TaskSchedule"; Taskcmd.ExecuteNonQuery(); DataTable dataTask = new DataTable(); SqlDataAdapter tasksAdapt = new SqlDataAdapter(Taskcmd); tasksAdapt.Fill(dataTask); DashTaskDataGrid.DataSource = dataTask; con.Close(); DashTaskDataGrid.Refresh(); con.Open(); SqlCommand ListOfUsers = con.CreateCommand(); ListOfUsers.CommandType = CommandType.Text; ListOfUsers.CommandText = "select * from Employees"; ListOfUsers.ExecuteNonQuery(); DataTable employeeTask = new DataTable(); SqlDataAdapter usersAdapt = new SqlDataAdapter(ListOfUsers); usersAdapt.Fill(employeeTask); dataGridView1.DataSource = employeeTask; con.Close(); dataGridView1.Refresh(); Dashboard.Visible = true; AddPanel.Visible = false; tasksPanel.Visible = false; ListOfUsersPanel.Visible = false; holidayListPanel.Visible = false; }
private void AdminDashboard_Load(object sender, EventArgs e) { //set the opacity of the form to 0 Opacity = 0; //set the interval of the timer t1.Interval = 15; //tick the timer t1.Tick += new EventHandler(fadeIn); //start the timer t1.Start(); //filling data grids etc // TODO: This line of code loads data into the 'registerdUsersDataSet1.HolidayLeave' table. You can move, or remove it, as needed. this.holidayLeaveTableAdapter3.Fill(this.registerdUsersDataSet1.HolidayLeave); // TODO: This line of code loads data into the 'holidayLeaveApproval.HolidayLeave' table. You can move, or remove it, as needed. this.holidayLeaveTableAdapter2.Fill(this.holidayLeaveApproval.HolidayLeave); // TODO: This line of code loads data into the 'holidayDataDash.HolidayLeave' table. You can move, or remove it, as needed. this.holidayLeaveTableAdapter1.Fill(this.holidayDataDash.HolidayLeave); // TODO: This line of code loads data into the 'dashTasks.TaskSchedule' table. You can move, or remove it, as needed. this.taskScheduleTableAdapter1.Fill(this.dashTasks.TaskSchedule); // TODO: This line of code loads data into the 'departmentTableData1.Departments' table. You can move, or remove it, as needed. this.departmentsTableAdapter.Fill(this.departmentTableData1.Departments); // TODO: This line of code loads data into the 'employeesTableData.Employees' table. You can move, or remove it, as needed. this.employeesTableAdapter.Fill(this.employeesTableData.Employees); // TODO: This line of code loads data into the 'holidayTableData.HolidayLeave' table. You can move, or remove it, as needed. this.holidayLeaveTableAdapter.Fill(this.holidayTableData.HolidayLeave); // TODO: This line of code loads data into the 'taskTableData.TaskSchedule' table. You can move, or remove it, as needed. this.taskScheduleTableAdapter.Fill(this.taskTableData.TaskSchedule); // TODO: This line of code loads data into the 'rolesTableData.Roles' table. You can move, or remove it, as needed. this.rolesTableAdapter.Fill(this.rolesTableData.Roles); //gets the connection var connectionString = ConfigurationManager.ConnectionStrings["EmployeeManagement"].ConnectionString; SqlConnection con = new SqlConnection(connectionString); //Opens connection to the database con.Open(); //creates a new sql command SqlCommand cmd = con.CreateCommand(); cmd.CommandType = CommandType.Text; //Sets the sql query cmd.CommandText = "select * from Roles"; //executes the query cmd.ExecuteNonQuery(); //creates a new datatable DataTable dt = new DataTable(); //creates a new adapter SqlDataAdapter da = new SqlDataAdapter(cmd); //fills the adapater with the data from the cmd da.Fill(dt); //closes connection con.Close(); //refreshes datagridview // TODO : RolesData.Refresh(); //opens connection con.Open(); //Creates a new command SqlCommand Taskscmd = con.CreateCommand(); cmd.CommandType = CommandType.Text; //creates the query cmd.CommandText = "select * from TaskSchedule"; //Excutes the created query cmd.ExecuteNonQuery(); //creates datatable DataTable TasksData = new DataTable(); //creates adapter SqlDataAdapter TasksAdapter = new SqlDataAdapter(cmd); //fills adapter da.Fill(TasksData); DashTaskDataGrid.DataSource = TasksData; con.Close(); //all the below code selects the correct data for each datagrid view and applys it to the datatable and then to the dgv con.Open(); SqlCommand ListOfUsers = con.CreateCommand(); ListOfUsers.CommandType = CommandType.Text; ListOfUsers.CommandText = "select * from Employees"; ListOfUsers.ExecuteNonQuery(); DataTable employeeTask = new DataTable(); SqlDataAdapter usersAdapt = new SqlDataAdapter(ListOfUsers); usersAdapt.Fill(employeeTask); dataGridView1.DataSource = employeeTask; con.Close(); dataGridView1.Refresh(); con.Open(); SqlCommand HolidayData = con.CreateCommand(); HolidayData.CommandType = CommandType.Text; HolidayData.CommandText = "select * from HolidayLeave"; HolidayData.ExecuteNonQuery(); DataTable HolidayDataTable = new DataTable(); SqlDataAdapter HolidayDataAdapter = new SqlDataAdapter(HolidayData); HolidayDataAdapter.Fill(HolidayDataTable); DashHolidayData.DataSource = HolidayDataTable; con.Close(); // refreshes the datagridview DashHolidayData.Refresh(); con.Open(); SqlCommand Taskcmd = con.CreateCommand(); Taskcmd.CommandType = CommandType.Text; Taskcmd.CommandText = "select * from TaskSchedule"; Taskcmd.ExecuteNonQuery(); DataTable dataTask = new DataTable(); SqlDataAdapter tasksAdapt = new SqlDataAdapter(Taskcmd); tasksAdapt.Fill(dataTask); DashTaskDataGrid.DataSource = dataTask; con.Close(); // refreshes the datagridview DashTaskDataGrid.Refresh(); //setting the panels to visible if neccasary Dashboard.Visible = true; AddPanel.Visible = false; tasksPanel.Visible = false; ListOfUsersPanel.Visible = false; holidayListPanel.Visible = false; }