private void SearchInvoiceOnCoName(object sender, KeyEventArgs e) { string filter = tstxtb_Invoices_CoName.Text; if (e.KeyCode == Keys.Return) { dbh.OpenConnection(); invoicesPanel.Controls.Clear(); DataTable dt = dbh.FilterInvoices(filter, "tbl_customers.company_name"); int amount = dt.Rows.Count; if (!showAllInvoices && amount > 5) { amount = 5; } InvoicePanel[] invoiceInfoPanel = new InvoicePanel[amount]; for (int i = 0; i < invoiceInfoPanel.Length; i++) { invoiceInfoPanel[i] = new InvoicePanel(i, dt); invoiceInfoPanel[i].BorderStyle = BorderStyle.FixedSingle; invoiceInfoPanel[i].Dock = DockStyle.Top; invoiceInfoPanel[i].btn_Paid.AccessibleName = dt.Rows[i]["invoice_id"].ToString(); invoiceInfoPanel[i].btn_Paid.Click += new EventHandler(this.PayInvoice); invoicesPanel.Controls.Add(invoiceInfoPanel[i]); } dbh.CloseConnection(); } }
private void ShowInvoices() { dbh = new DatabaseHandler(); dbh.OpenConnection(); invoicesPanel.Controls.Clear(); DataTable dt = dbh.GetInvoices(); int amount = dt.Rows.Count; if (!showAllInvoices && amount > 5) { amount = 5; Button btn_showAllInvoices = new Button(); btn_showAllInvoices.Text = "Show all invoices"; btn_showAllInvoices.Dock = DockStyle.Bottom; btn_showAllInvoices.Click += new System.EventHandler(this.ShowAllInvoices); invoicesPanel.Controls.Add(btn_showAllInvoices); dbh.CloseConnection(); } InvoicePanel[] invoiceInfoPanel = new InvoicePanel[amount]; for (int i = 0; i < invoiceInfoPanel.Length; i++) { invoiceInfoPanel[i] = new InvoicePanel(i, dt); invoiceInfoPanel[i].BorderStyle = BorderStyle.FixedSingle; invoiceInfoPanel[i].Dock = DockStyle.Top; invoiceInfoPanel[i].btn_Paid.AccessibleName = dt.Rows[i]["invoice_id"].ToString(); invoiceInfoPanel[i].btn_Paid.Click += new EventHandler(this.PayInvoice); invoicesPanel.Controls.Add(invoiceInfoPanel[i]); } dbh.CloseConnection(); }