package
work_VJnet;
import System.Drawing.*;
import System.Collections.*;
import System.ComponentModel.*;
import System.Windows.Forms.*;
/**
* Summary description for book_search.
*/
public
class
book_search
extends System.Windows.Forms.Form
{
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;
System.Windows.Forms.DataGrid DataGrid1;
System.Windows.Forms.Label lbfound;
System.Windows.Forms.Label lsearch1;
System.Windows.Forms.Panel Panel111;
System.Windows.Forms.CheckBox chk_allbook;
System.Windows.Forms.Label lbook;
System.Windows.Forms.Panel Panel113;
System.Windows.Forms.TextBox txtsearch1;
System.Windows.Forms.Button Btnsearch;
System.Windows.Forms.Panel Panel112;
System.Windows.Forms.CheckBox chk_condition;
System.Windows.Forms.Label lcondition;
System.Windows.Forms.ComboBox cmbfather;
System.Windows.Forms.ComboBox cmbfirst;
System.Windows.Forms.ComboBox cmbname;
System.Windows.Forms.ComboBox cmbcountry;
System.Windows.Forms.ComboBox cmbcity;
System.Windows.Forms.TextBox txtphone;
System.Windows.Forms.Label lcity1;
System.Windows.Forms.Label lphone1;
System.Windows.Forms.Label lcountry1;
System.Windows.Forms.Label lfirst1;
System.Windows.Forms.Label lfather1;
System.Windows.Forms.Button btnclear;
System.Windows.Forms.Label lname1;
System.Windows.Forms.ImageList ImageList1;
System.Windows.Forms.Panel Panel114;
System.Windows.Forms.PictureBox Pic_line013;
System.Windows.Forms.PictureBox Pic_line011;
System.Windows.Forms.PictureBox Pic_line012;
System.Windows.Forms.Button Btnok;
System.Windows.Forms.Button Btncancel;
private
System.Data.OleDb.OleDbConnection oleDbConnection1;
private
System.ComponentModel.IContainer components;
// Variables
//Select
command
System.Data.OleDb.OleDbCommand
vselect;
//Dataadapter
System.Data.OleDb.OleDbDataAdapter vda;
System.Data.DataSet vdset;
String vitem_grid;
boolean
searchflg;
boolean
s_flag;
public
book_search()
{
//
// Required for
Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add
any constructor code after InitializeComponent call
//
}
/**
* Clean up any resources being used.
*/
protected
void
Dispose(boolean
disposing)
{
if
(disposing)
{
if
(components !=
null)
{
components.Dispose();
}
}
super.Dispose(disposing);
}
Windows Form Designer
generated code |
public static class
book_search_cl
{
public static
int
book_recno;
public static
boolean
findedit_Flag;
}
private void
book_search_Load (Object sender, System.EventArgs e)
{
int
vleft;
int
vtop;
// Move
vleft =
work_VJnet.book_note.book_note_cl.booknote_left +
work_VJnet.book_note.book_note_cl.booknote_width -
this.get_Width();
vtop =
work_VJnet.book_note.book_note_cl.booknote_top;
this.set_Location(new
System.Drawing.Point(vleft, vtop));
//resize
this.Btnsearch.set_Left((this.Panel113.get_Width()
-
this.Btnsearch.get_Width()) / 2);
this.Btnok.set_Top((this.Panel114.get_Height()
-
this.Btnok.get_Height()) / 2);
this.Btncancel.set_Top(this.Btnok.get_Top());
this.Pic_line011.set_Top(this.Btnok.get_Top()
+ ((this.Btnok.get_Height()
- (this.Pic_line011.get_Height()
* 3)) / 4));
this.Pic_line012.set_Top(this.Pic_line011.get_Top()
+ this.Pic_line011.get_Height()
+ ((this.Btnok.get_Height()
-
(this.Pic_line011.get_Height()
* 3)) / 4));
this.Pic_line013.set_Top(this.Pic_line012.get_Top()
+ this.Pic_line012.get_Height()
+ ((this.Btnok.get_Height()
-
(this.Pic_line011.get_Height() * 3)) / 4));
this.Pic_line011.set_Left((this.Btnok.get_Left()
- this.Pic_line011.get_Width())
/ 2);
this.Pic_line012.set_Left(this.Pic_line011.get_Left());
this.Pic_line013.set_Left(this.Pic_line011.get_Left());
s_flag =
false;
searchflg =
false;
sub_clearall();
if
(work_VJnet.book_note.book_note_cl.booknote_type.trim().Equals("find"))
{
this.set_Text("search,
book note ...");
}
if
(work_VJnet.book_note.book_note_cl.booknote_type.trim().Equals("edit"))
{
this.set_Text("edit,
book note ...");
}
this.chk_allbook.set_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;
if
(v_field.trim().Equals("name"))
{
vselect =
new
System.Data.OleDb.OleDbCommand("SELECT DISTINCT
Trim(name) AS vname
FROM book WHERE (Trim(name)
<> '') ORDER BY Trim(name)");
}
if
(v_field.trim().Equals("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)");
}
if
(v_field.trim().Equals("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)");
}
if
(v_field.trim().Equals("city"))
{
vselect =
new
System.Data.OleDb.OleDbCommand("SELECT DISTINCT
Trim(city) AS vcity
FROM book WHERE (Trim(city)<>'')ORDER
BY Trim(city)");
}
vda =
new
System.Data.OleDb.OleDbDataAdapter(vselect);
vdset =
new
System.Data.DataSet();
vselect.set_Connection(this.oleDbConnection1);
vdset.set_EnforceConstraints(false);
try
{
this.oleDbConnection1.Open();
vda.Fill(vdset, "book");
}
catch
(System.Exception fillException)
{
System.Windows.Forms.MessageBox.Show(fillException.get_Message());
}
vdset.set_EnforceConstraints(true);
this.oleDbConnection1.Close();
if
(vdset.get_Tables().get_Item("book").get_Rows().get_Count()
> 0)
{
for
(i = 0 ; i <= (vdset.get_Tables().get_Item("book").get_Rows().get_Count()
- 1); i++)
{
if
(v_field.trim().Equals("name"))
{
this.cmbname.get_Items().Add(vdset.get_Tables().get_Item("book").
get_Rows().get_Item(i).get_Item("vname").ToString().Trim());
}
if
(v_field.trim().Equals("first"))
{
this.cmbfirst.get_Items().Add(vdset.get_Tables().get_Item("book").get_Rows().
get_Item(i).get_Item("vfirst").ToString().Trim());
}
if
(v_field.trim().Equals("father"))
{
this.cmbfather.get_Items().Add(vdset.get_Tables().get_Item("book").get_Rows().
get_Item(i).get_Item("vfather").ToString().Trim());
}
if
(v_field.trim().Equals("city"))
{
this.cmbcity.get_Items().Add(vdset.get_Tables().get_Item("book").get_Rows().
get_Item(i).get_Item("vcity").ToString().Trim());
}
}
}
}
private
void
cmbname_SelectedIndexChanged (Object sender,
System.EventArgs e)
{
if
(s_flag == true)
sub_check();
}
private
void
sub_check()
{
if
(this.chk_allbook.get_Checked()
== true)
this.chk_allbook.set_Checked(false);
if
(this.Btnsearch.get_Enabled()
== false)
this.Btnsearch.set_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_allbook_CheckedChanged (Object sender,
System.EventArgs e)
{
if
((s_flag == true)
&& (this.chk_allbook.get_Checked()
== true))
{
if
(this.Btnsearch.get_Enabled()
== false)
this.Btnsearch.set_Enabled(true);
}
}
private
void
chk_condition_CheckedChanged (Object sender,
System.EventArgs e)
{
if
(this.chk_condition.get_Checked()
== true)
{
this.lcondition.set_Text("condition - Or");
}
if
(this.chk_condition.get_Checked()
== false)
{
this.lcondition.set_Text("condition - And");
}
}
private
void
btnclear_Click (Object sender, System.EventArgs e)
{
sub_clearall();
}
private
void
sub_clearall()
{
this.cmbname.set_SelectedIndex(-1);
this.cmbfirst.set_SelectedIndex(-1);
this.cmbfather.set_SelectedIndex(-1);
this.cmbcountry.set_SelectedIndex(-1);
this.cmbcity.set_SelectedIndex(-1);
this.txtphone.set_Text("");
if
(this.Btnsearch.get_Enabled()
== true)
this.Btnsearch.set_Enabled(false);
}
private
void
Btnsearch_Click (Object sender, System.EventArgs e)
{
searchflg =
true;
if
(this.chk_allbook.get_Checked()
== true)
{
sub_search("", "", "", "", "",
"");
}
if
(this.chk_allbook.get_Checked()
== false)
{
sub_search(this.cmbname.get_Text().Trim(),
this.cmbfirst.get_Text().Trim(),
this.cmbfather.get_Text().Trim(),
this.cmbcountry.get_Text().Trim(),
this.cmbcity.get_Text().Trim(),
this.txtphone.get_Text().Trim());
}
}
private
void
sub_search(String v_name, String v_firstname, String
v_fathername, String v_country, String v_city, String
v_phone)
{
int
vfound;
if
(this.chk_allbook.get_Checked()
== 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");
}
if
(this.chk_allbook.get_Checked()
== 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");
}
vda =
new
System.Data.OleDb.OleDbDataAdapter(vselect);
vdset =
new
System.Data.DataSet();
vselect.set_Connection(this.oleDbConnection1);
vdset.set_EnforceConstraints(false);
try
{
this.oleDbConnection1.Open();
vda.Fill(vdset, "book");
}
catch
(System.Exception fillException)
{
System.Windows.Forms.MessageBox.Show(fillException.get_Message());
}
vdset.set_EnforceConstraints(true);
this.oleDbConnection1.Close();
vfound =
vdset.get_Tables().get_Item("book").get_Rows().get_Count();
this.DataGrid1.set_DataSource(vdset);
this.DataGrid1.set_DataMember("book");
if
(searchflg == true)
{
this.Btnsearch.set_Enabled(true);
this.btnclear_Click(btnclear, null);
searchflg =
false;
}
if
(this.chk_allbook.get_Checked()
== true)
{
this.lbfound.set_Text(System.Convert.ToString(vfound) +
" - item(s) found, selected: all book(s)");
}
if
(this.chk_allbook.get_Checked()
== false)
{
this.lbfound.set_Text(System.Convert.ToString(vfound) +
" - item(s) found");
}
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.set_Connection(this.oleDbConnection1);
vdset.set_EnforceConstraints(false);
try
{
this.oleDbConnection1.Open();
vda.Fill(vdset, "book");
}
catch
(System.Exception fillException)
{
System.Windows.Forms.MessageBox.Show(fillException.get_Message());
}
vdset.set_EnforceConstraints(true);
this.oleDbConnection1.Close();
if
(vdset.get_Tables().get_Item("book").get_Rows().get_Count()
> 0)
{
for
(vvrec = 0 ; vvrec <= (vdset.get_Tables().get_Item("book").get_Rows().get_Count()
- 1); vvrec++)
{
if
(vdset.get_Tables().get_Item("book").get_Rows().get_Item(vvrec).get_Item("bookid").ToString().Trim().Equals(vitem_grid.Trim()))
{
book_search_cl.book_recno =
vvrec;
return;
}
}
}
}
private
void
DataGrid1_MouseUp (Object sender,
System.Windows.Forms.MouseEventArgs e)
{
vitem_grid =
this.DataGrid1.get_Item(this.DataGrid1.get_CurrentRowIndex(),
0).ToString();
this.Btnok.set_Enabled(true);
}
private
void
DataGrid1_Click (Object sender, System.EventArgs e)
{
vitem_grid =
this.DataGrid1.get_Item(this.DataGrid1.get_CurrentRowIndex(),
0).ToString();
this.Btnok.set_Enabled(true);
}
private
void
Btnok_Click (Object sender, System.EventArgs e)
{
sub_select();
book_search_cl.findedit_Flag =
true;
if
(work_VJnet.book_note.book_note_cl.booknote_type.trim().Equals("find"))
{
this.Close();
work_VJnet.book_note.get_ActiveForm().Refresh();
work_VJnet.book_note.get_ActiveForm().Activate();
}
if
(work_VJnet.book_note.book_note_cl.booknote_type.trim().Equals("edit"))
{
this.Close();
work_VJnet.book_note.get_ActiveForm().Refresh();
work_VJnet.book_note.get_ActiveForm().Activate();
}
}
private
void
Btncancel_Click (Object sender, System.EventArgs e)
{
book_search_cl.findedit_Flag =
false;
this.Close();
work_VJnet.book_note.get_ActiveForm().Refresh();
work_VJnet.book_note.get_ActiveForm().Activate();
}
}
|