protected virtual void button_act() { String sql_t0 = "select staf_ref,c_name,e_name,id_no from sa_stafinfo "; Regex rgx_stafref = new Regex(@"^[0-9][0-9][0-9][0-9]-[a-zA-Z0-9][0-9][0-9]$"); Regex rgx_dsejref = new Regex(@"^[0-9][0-9][0-9][0-9][0-9][0-9][0-9]-[a-zA-Z0-9]$"); Regex rgx_ename = new Regex(@"[a-zA-Z]"); Form_Search_Res s_res_frm = new Form_Search_Res(); s_res_frm.MdiParent = _parentForm; int res_count = 0; if (textBox1.Text.Length > 1) { if (rgx_stafref.IsMatch(textBox1.Text)) { sql_t0 += "where staf_ref='" + textBox1.Text + "' limit 30;"; } else if (rgx_dsejref.IsMatch(textBox1.Text)) { sql_t0 += "where dsej_ref='" + textBox1.Text + "' or dsej_sref='" + textBox1.Text + "' limit 30;"; } else if (rgx_ename.IsMatch(textBox1.Text)) { sql_t0 += "where e_name like '%" + textBox1.Text + "%' limit 30;"; } else { sql_t0 += "where C_name like '%" + textBox1.Text + "%' limit 30;"; } res_count += AddRESBTN(sql_t0, s_res_frm); } if (textBox2.Text.Length > 0) { sql_t0 += "where id_no ='" + textBox2.Text + "' limit 30;"; res_count += AddRESBTN(sql_t0, s_res_frm); } if (textBox3.Text.Length > 0) { sql_t0 += "where nlid_no ='" + textBox2.Text + "' limit 30;"; res_count += AddRESBTN(sql_t0, s_res_frm); } if (res_count > 0) { s_res_frm.Show(); } else { s_res_frm.Dispose(); } }
private int AddRESBTN(String sql_t0, Form_Search_Res s_res_frm) { Font btnfont = new Font("新細明體", 12.0f); System.Drawing.Size btnsize = new System.Drawing.Size(300, 60); int res_count = 0; OdbcDataReader dr = new OdbcCommand(sql_t0, conn).ExecuteReader(); while (dr.Read()) { string btntxt = format_btntext(dr); Button btn = new Button(); btn.Text = btntxt; btn.Size = btnsize; btn.Font = btnfont; btn.Click += btn_Click; s_res_frm.flowLayoutPanel1.Controls.Add(btn); res_count++; } dr.Close(); dr.Dispose(); return(res_count++); }