private void SearchProjectOnC_Name(object sender, KeyEventArgs e) { string filter = tstxtb_Projects_CuName.Text; if (e.KeyCode == Keys.Return) { dbh.OpenConnection(); projectsPanel.Controls.Clear(); DataTable dt = dbh.FilterProjects(filter, "tbl_customers.first_name", "tbl_customers.last_name"); int amount = dt.Rows.Count; ProjectPanel[] projectInfoPanel = new ProjectPanel[amount]; for (int i = 0; i < projectInfoPanel.Length; i++) { projectInfoPanel[i] = new ProjectPanel(i, dt); projectInfoPanel[i].BorderStyle = BorderStyle.FixedSingle; projectInfoPanel[i].Dock = DockStyle.Top; projectInfoPanel[i].btn_Edit.Click += new System.EventHandler(this.FillEditProjectItems); projectInfoPanel[i].btn_Edit.AccessibleName = projectInfoPanel[i].lbl_Project_Id.Text; projectInfoPanel[i].lbl_Customer_Name.AccessibleName = dt.Rows[i]["customer_id"].ToString(); projectInfoPanel[i].lbl_Customer_Name.Click += new System.EventHandler(this.FillCustomerData); projectsPanel.Controls.Add(projectInfoPanel[i]); } dbh.CloseConnection(); tcp_Main.SelectedIndex = 1; } }
private void ShowProjects() { try { dbh.OpenConnection(); } catch (Exception ex) { MessageBox.Show("An error occured: \n\n" + ex); } projectsPanel.Controls.Clear(); DataTable dt = dbh.GetProjects(); int amount = dt.Rows.Count; if (!showallProjects && amount > 5) { amount = 5; Button btn_showAllProjects = new Button(); btn_showAllProjects.Text = "Show all projects"; btn_showAllProjects.Dock = DockStyle.Bottom; btn_showAllProjects.Click += new System.EventHandler(this.showAllProjects); projectsPanel.Controls.Add(btn_showAllProjects); dbh.CloseConnection(); } ProjectPanel[] projectInfoPanel = new ProjectPanel[amount]; for (int i = 0; i < projectInfoPanel.Length; i++) { projectInfoPanel[i] = new ProjectPanel(i, dt); projectInfoPanel[i].BorderStyle = BorderStyle.FixedSingle; projectInfoPanel[i].Dock = DockStyle.Top; projectInfoPanel[i].btn_Edit.Click += new System.EventHandler(this.FillEditProjectItems); projectInfoPanel[i].btn_Edit.AccessibleName = projectInfoPanel[i].lbl_Project_Id.Text; projectInfoPanel[i].lbl_Customer_Name.AccessibleName = dt.Rows[i]["customer_id"].ToString(); projectInfoPanel[i].lbl_Customer_Name.Click += new System.EventHandler(this.FillCustomerData); projectsPanel.Controls.Add(projectInfoPanel[i]); } dbh.CloseConnection(); }