using
System; using
System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
namespace work_VCnet
{
///
<summary>
///
Summary description for book_search.
///
</summary>
public
class
book_search : System.Windows.Forms.Form
{
internal
System.Windows.Forms.ImageList ImageList1;
internal
System.Windows.Forms.Panel Panel11;
private
System.Windows.Forms.DataGridTableStyle
dataGridTableStyle1;
private
System.Windows.Forms.DataGridTextBoxColumn
dataGridTextBoxColumn1;
private
System.Windows.Forms.DataGridTextBoxColumn
dataGridTextBoxColumn2;
private
System.Windows.Forms.DataGridTextBoxColumn
dataGridTextBoxColumn3;
private
System.Windows.Forms.DataGridTextBoxColumn
dataGridTextBoxColumn4;
private
System.Windows.Forms.DataGridTextBoxColumn
dataGridTextBoxColumn5;
internal
System.Windows.Forms.DataGrid DataGrid1;
internal
System.Windows.Forms.Label lbfound;
internal
System.Windows.Forms.Label lsearch1;
internal
System.Windows.Forms.Panel Panel111;
internal
System.Windows.Forms.CheckBox chk_allbook;
internal
System.Windows.Forms.Label lbook;
internal
System.Windows.Forms.Panel Panel113;
internal
System.Windows.Forms.TextBox txtsearch1;
internal
System.Windows.Forms.Button Btnsearch;
internal
System.Windows.Forms.Panel Panel112;
internal
System.Windows.Forms.CheckBox chk_condition;
internal
System.Windows.Forms.Label lcondition;
internal
System.Windows.Forms.ComboBox cmbfather;
internal
System.Windows.Forms.ComboBox cmbfirst;
internal
System.Windows.Forms.ComboBox cmbname;
internal
System.Windows.Forms.ComboBox cmbcountry;
internal
System.Windows.Forms.ComboBox cmbcity;
internal
System.Windows.Forms.TextBox txtphone;
internal
System.Windows.Forms.Label lcity1;
internal
System.Windows.Forms.Label lphone1;
internal
System.Windows.Forms.Label lcountry1;
internal
System.Windows.Forms.Label lfirst1;
internal
System.Windows.Forms.Label lfather1;
internal
System.Windows.Forms.Button btnclear;
internal
System.Windows.Forms.Label lname1;
internal
System.Windows.Forms.Panel Panel114;
internal
System.Windows.Forms.PictureBox Pic_line013;
internal
System.Windows.Forms.PictureBox Pic_line011;
internal
System.Windows.Forms.PictureBox Pic_line012;
internal
System.Windows.Forms.Button Btnok;
internal
System.Windows.Forms.Button Btncancel;
private
System.ComponentModel.IContainer components;
//variable
//Select command
System.Data.OleDb.OleDbCommand
vselect;
//Dataadapter
System.Data.OleDb.OleDbDataAdapter vda;
System.Data.DataSet vdset;
string
vitem_grid;
bool
searchflg;
private
System.Data.OleDb.OleDbConnection oleDbConnection1;
bool
s_flag;
public
book_search()
{
//
// Required for
Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any
constructor code after InitializeComponent call
//
}
///
<summary>
///
Clean up any resources being used.
///
</summary>
protected
override
void
Dispose( bool
disposing )
{
if(
disposing )
{
if(components
!= null)
{
components.Dispose();
}
}
base.Dispose(
disposing );
}
Windows Form Designer
generated code |
// public variables
public
class
book_search_cl
{
public
static
int
book_recno;
public
static
string
findedit_Flag;
}
private
void
book_search_Load(object
sender, System.EventArgs e)
{
int
vleft;
int
vtop;
book_note Fbook_note =
new
book_note();
// Move
vleft =
work_VCnet.book_note.book_note_cl.booknote_left +
work_VCnet.book_note.book_note_cl.booknote_width -
this.Width;
vtop =
work_VCnet.book_note.book_note_cl.booknote_top;
this.Location
= new
System.Drawing.Point(vleft, vtop);
//resize
this.Btnsearch.Left
= (this.Panel113.Width
- this.Btnsearch.Width)
/ 2;
this.Btnok.Top
= (this.Panel114.Height
- this.Btnok.Height)
/ 2;
this.Btncancel.Top
= this.Btnok.Top;
this.Pic_line011.Top
= this.Btnok.Top
+ ((this.Btnok.Height
- (this.Pic_line011.Height
* 3)) / 4);
this.Pic_line012.Top
= this.Pic_line011.Top
+ this.Pic_line011.Height
+ ((this.Btnok.Height
- (this.Pic_line011.Height
* 3)) / 4);
this.Pic_line013.Top
= this.Pic_line012.Top
+ this.Pic_line012.Height
+ ((this.Btnok.Height
- (this.Pic_line011.Height
* 3)) / 4);
this.Pic_line011.Left
= (this.Btnok.Left
- this.Pic_line011.Width)
/ 2;
this.Pic_line012.Left
= this.Pic_line011.Left;
this.Pic_line013.Left
= this.Pic_line011.Left;
s_flag =
false;
searchflg =
false;
sub_clearall();
switch(work_VCnet.book_note.book_note_cl.booknote_type)
{
case
"find":
this.Text
= "search, book note ...";
break;
case
"edit":
this.Text
= "edit, book note ...";
break;
}
this.chk_allbook.Checked
= true;
sub_load("name");
sub_load("first");
sub_load("father");
sub_load("city");
sub_search("", "", "", "", "",
"");
}
//add data to comboboxes
private
void
sub_load(string
v_field)
{
int
i;
switch(v_field)
{
case
"name":
vselect =
new
System.Data.OleDb.OleDbCommand("SELECT DISTINCT Trim(name)
AS vname FROM book WHERE (Trim(name) <> '') ORDER BY
Trim(name)");
break;
case
"first":
vselect =
new
System.Data.OleDb.OleDbCommand("SELECT DISTINCT
Trim(first_name) AS vfirst FROM book WHERE (Trim(first_name)
<>'')ORDER BY Trim(first_name)");
break;
case
"father":
vselect =
new
System.Data.OleDb.OleDbCommand("SELECT DISTINCT
Trim(father_name) AS vfather FROM book WHERE (Trim(father_name)
<>'')ORDER BY Trim(father_name)");
break;
case
"city":
vselect =
new
System.Data.OleDb.OleDbCommand("SELECT DISTINCT Trim(city)
AS vcity FROM book WHERE (Trim(city)<>'')ORDER BY
Trim(city)");
break;
}
vda =
new
System.Data.OleDb.OleDbDataAdapter(vselect);
vdset =
new
System.Data.DataSet();
vselect.Connection =
this.oleDbConnection1;
vdset.EnforceConstraints =
false;
try
{
this.oleDbConnection1.Open();
vda.Fill(vdset, "book");
}
catch
(System.Exception fillException)
{
System.Windows.Forms.MessageBox.Show(fillException.Message);
}
vdset.EnforceConstraints =
true;
this.oleDbConnection1.Close();
if
(vdset.Tables["book"].Rows.Count > 0)
{
for
(i = 0 ; i <= (vdset.Tables["book"].Rows.Count - 1); i++)
{
switch(v_field)
{
case
"name":
this.cmbname.Items.Add(vdset.Tables["book"].Rows[i]["vname"].ToString().Trim());
break;
case
"first":
this.cmbfirst.Items.Add(vdset.Tables["book"].Rows[i]["vfirst"].ToString().Trim());
break;
case
"father":
this.cmbfather.Items.Add(vdset.Tables["book"].Rows[i]["vfather"].ToString().Trim());
break;
case
"city":
this.cmbcity.Items.Add(vdset.Tables["book"].Rows[i]["vcity"].ToString().Trim());
break;
}
}
}
}
private
void
cmbname_SelectedIndexChanged(object
sender, System.EventArgs e)
{
if
(s_flag == true)
sub_check();
}
private
void
sub_check()
{
if
(this.chk_allbook.Checked
== true)
this.chk_allbook.Checked
= false;
if
(this.Btnsearch.Enabled
== false)
this.Btnsearch.Enabled
= true;
}
private
void
cmbfirst_SelectedIndexChanged(object
sender, System.EventArgs e)
{
if
(s_flag == true)
sub_check();
}
private
void
cmbfather_SelectedIndexChanged(object
sender, System.EventArgs e)
{
if
(s_flag == true)
sub_check();
}
private
void
cmbcountry_SelectedIndexChanged(object
sender, System.EventArgs e)
{
if
(s_flag == true)
sub_check();
}
private
void
cmbcity_SelectedIndexChanged(object
sender, System.EventArgs e)
{
if
(s_flag == true)
sub_check();
}
private
void
txtphone_KeyPress(object
sender, System.Windows.Forms.KeyPressEventArgs e)
{
if
(s_flag == true)
sub_check();
}
private
void
chk_condition_CheckedChanged(object
sender, System.EventArgs e)
{
if
(this.chk_condition.Checked
== true)
this.lcondition.Text
= "condition - Or";
if
(this.chk_condition.Checked
== false)
this.lcondition.Text
= "condition - And";
}
private
void
chk_allbook_CheckedChanged(object
sender, System.EventArgs e)
{
if
((s_flag == true)
&& (this.chk_allbook.Checked
== true))
{
if
(this.Btnsearch.Enabled
== false)
this.Btnsearch.Enabled
= true;
}
}
private
void
btnclear_Click(object
sender, System.EventArgs e)
{
sub_clearall();
}
private
void
sub_clearall()
{
this.cmbname.SelectedIndex
= -1;
this.cmbfirst.SelectedIndex
= -1;
this.cmbfather.SelectedIndex
= -1;
this.cmbcountry.SelectedIndex
= -1;
this.cmbcity.SelectedIndex
= -1;
this.txtphone.Text
= "";
if
(this.Btnsearch.Enabled
== true)
this.Btnsearch.Enabled
= false;
}
private
void
Btnsearch_Click(object
sender, System.EventArgs e)
{
searchflg =
true;
switch(this.chk_allbook.Checked)
{
case
true:
sub_search("", "", "", "", "",
"");
break;
case
false:
sub_search(this.cmbname.Text.Trim(),
this.cmbfirst.Text.Trim(),
this.cmbfather.Text.Trim(),
this.cmbcountry.Text.Trim(),
this.cmbcity.Text.Trim(),
this.txtphone.Text.Trim());
break;
}
}
private
void
sub_search(string
v_name, string
v_firstname, string
v_fathername, string
v_country, string
v_city, string
v_phone)
{
int
vfound;
switch(this.chk_allbook.Checked)
{
case
true:
vselect =
new
System.Data.OleDb.OleDbCommand("SELECT
bookid,alternativePhone, city, country, father_name, fax,
first_name, homephone, mobilephone, name, sex, workphone
FROM book WHERE (name <> '') ORDER BY name, first_name,
father_name");
break;
case
false:
vselect =
new
System.Data.OleDb.OleDbCommand("SELECT
bookid,alternativePhone, city, country, father_name, fax,
first_name, homephone, mobilephone, name, sex, workphone
FROM book WHERE ((name <> '') And (Trim(name) = '" +
v_name + "') Or (Trim(first_name) = '" + v_firstname + "')
Or (Trim(father_name) = '" + v_fathername + "') Or (Trim(country)
= '" + v_country + "') Or (Trim(city) = '" + v_city + "')
Or ((Trim(homephone) = '" + v_phone + "') Or (Trim(workphone)
= '" + v_phone + "') Or (Trim(mobilephone) = '" + v_phone
+ "') Or (Trim(alternativePhone) = '" + v_phone + "') Or (Trim(fax)
= '" + v_phone + "'))) ORDER BY name, first_name,
father_name");
break;
}
vda =
new
System.Data.OleDb.OleDbDataAdapter(vselect);
vdset =
new
System.Data.DataSet();
vselect.Connection =
this.oleDbConnection1;
vdset.EnforceConstraints =
false;
try
{
this.oleDbConnection1.Open();
vda.Fill(vdset, "book");
}
catch
(System.Exception fillException)
{
System.Windows.Forms.MessageBox.Show(fillException.Message);
}
vdset.EnforceConstraints =
true;
this.oleDbConnection1.Close();
vfound =
vdset.Tables["book"].Rows.Count;
this.DataGrid1.DataSource
= vdset;
this.DataGrid1.DataMember
= "book";
if
(searchflg == true)
{
this.Btnsearch.Enabled
= true;
this.btnclear_Click(btnclear,
null);
searchflg =
false;
}
switch(this.chk_allbook.Checked)
{
case
true:
this.lbfound.Text
= vfound.ToString() + " - item(s) found, selected: all
book(s)";
break;
case
false:
this.lbfound.Text
= vfound.ToString() + " - item(s) found";
break;
}
s_flag =
true;
this.lbfound.Focus();
}
private
void
sub_select()
{
int
vvrec;
vselect =
new
System.Data.OleDb.OleDbCommand("SELECT bookid, country,
father_name, first_name, name, sex FROM book WHERE (name
<> '') ORDER BY bookid");
vda =
new
System.Data.OleDb.OleDbDataAdapter(vselect);
vdset =
new
System.Data.DataSet();
vselect.Connection =
this.oleDbConnection1;
vdset.EnforceConstraints =
false;
try
{
this.oleDbConnection1.Open();
vda.Fill(vdset, "book");
}
catch
(System.Exception fillException)
{
System.Windows.Forms.MessageBox.Show(fillException.Message);
}
vdset.EnforceConstraints =
true;
this.oleDbConnection1.Close();
if
(vdset.Tables["book"].Rows.Count > 0)
{
for
(vvrec = 0 ; vvrec <= (vdset.Tables["book"].Rows.Count -
1); vvrec++)
{
if
(vdset.Tables["book"].Rows[vvrec]["bookid"].ToString().Trim()
== vitem_grid.Trim())
{
book_search_cl.book_recno = vvrec;
}
}
}
}
private
void
DataGrid1_Click(object
sender, System.EventArgs e)
{
vitem_grid =
this.DataGrid1[this.DataGrid1.CurrentRowIndex,
0].ToString();
this.Btnok.Enabled
= true;
}
private
void
DataGrid1_MouseUp(object
sender, System.Windows.Forms.MouseEventArgs e)
{
vitem_grid =
this.DataGrid1[this.DataGrid1.CurrentRowIndex,
0].ToString();
this.Btnok.Enabled
= true;
}
private
void
Btnok_Click(object
sender, System.EventArgs e)
{
sub_select();
book_search_cl.findedit_Flag =
"ok";
switch(work_VCnet.book_note.book_note_cl.booknote_type)
{
case
"find":
this.Close();
work_VCnet.book_note.ActiveForm.Refresh();
work_VCnet.book_note.ActiveForm.Activate();
//fbooknote.sub_findok();
break;
case
"edit":
this.Close();
work_VCnet.book_note.ActiveForm.Refresh();
work_VCnet.book_note.ActiveForm.Activate();
//fbooknote.sub_modifyok();
break;
}
}
private
void
Btncancel_Click(object
sender, System.EventArgs e)
{
book_search_cl.findedit_Flag =
"cancel";
this.Close();
work_VCnet.book_note.ActiveForm.Refresh();
work_VCnet.book_note.ActiveForm.Activate();
}
}
}
|