📄 searchform.cs
字号:
// SearchForm
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(776, 469);
this.Controls.Add(this.label1);
this.Controls.Add(this.groupBox3);
this.Controls.Add(this.button3);
this.Controls.Add(this.button2);
this.Controls.Add(this.button_search);
this.Controls.Add(this.groupBox2);
this.Name = "SearchForm";
this.Text = "查询";
this.Load += new System.EventHandler(this.SearchForm_Load);
this.groupBox2.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.dg_result)).EndInit();
this.groupBox3.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
private void process1_Exited(object sender, System.EventArgs e)
{
}
private void SearchForm_Load(object sender, System.EventArgs e)
{
// SearchForm2 frm=new SearchForm2();
// frm.MdiParent=this.MdiParent;
// frm.SetFriendForm(this);
// frm.Show();
string sqlstr;
OleDbCommand command=new OleDbCommand();
DataSet dataset=new DataSet();
connection.Open();
command.Connection=connection;
////////////////////////////
sqlstr="select LANNAME from LanguageInfo";
OleDbDataAdapter oleAdapter=new OleDbDataAdapter(sqlstr,connection);
//查询现有属性信息
//oleAdapter.SelectCommand=sqlstr;
oleAdapter.Fill(dataset,"t_lan");
this.comboBox_lan.DisplayMember="LANNAME" ;
this.comboBox_lan.DataSource=dataset.Tables["t_lan"];
/////////////;
sqlstr="select PLATFORMNAME from PlatformInfo";
command.CommandText=sqlstr;
oleAdapter.SelectCommand=command;
oleAdapter.Fill(dataset,"t_plat");
this.comboBox_plat.DisplayMember="PLATFORMNAME";
this.comboBox_plat.DataSource=dataset.Tables["t_plat"];
////////////////
sqlstr="select FORMNAME from FormInfo";
command.CommandText=sqlstr;
oleAdapter.SelectCommand=command;
oleAdapter.Fill(dataset,"t_Form");
this.comboBox_form.DisplayMember="FORMNAME";
this.comboBox_form.DataSource=dataset.Tables["t_Form"];
////////////////
sqlstr="select CLASSNAME from CLASSINFO";
command.CommandText=sqlstr;
oleAdapter.SelectCommand=command;
oleAdapter.Fill(dataset,"t_class");
this.comboBox_class.DisplayMember="CLASSNAME";
this.comboBox_class.DataSource=dataset.Tables["t_class"];
///////
this.comboBox1_l.SelectedIndex=0;
this.comboBox2_p.SelectedIndex=0;
this.comboBox3_c.SelectedIndex=0;
this.comboBox4_f.SelectedIndex=0;
this.comboBox5_k.SelectedIndex=0;
this.comboBox6_f.SelectedIndex=0;
//////
oleAdapter.Dispose();
connection.Close();
}
public void SetConnection(OleDbConnection conn)
{
connection=conn;
}
private void button2_Click(object sender, System.EventArgs e)
{
int row=this.dg_result.CurrentRowIndex;
DataTable t=(DataTable)this.dg_result.DataSource;
string appPath=Application.StartupPath;
if(row!=-1)
{
string path=(string)t.Rows[row]["DIRECTORY"];
appPath+="\\Source"+path;
process1.StartInfo.Arguments =appPath;
process1.Start();
}
}
private void button3_Click(object sender, System.EventArgs e)
{
this.Close();
}
public void Search()
{
MessageBox.Show("aa");
}
private void groupBox3_Enter(object sender, System.EventArgs e)
{
}
private void button_search_Click(object sender, System.EventArgs e)
{
//分析查询状态
string sqlstr,sqlstr1,str="";
string lanid="",platid="",formid="",classid="",func="",keyword="";
bool whereflag=false;
OleDbCommand command=new OleDbCommand() ;
command.Connection=connection;
OleDbDataReader DataReader;
#region 分析并产生查询语句
sqlstr="select SourceInfo.SCRNUM,CLASSINFO.CLASSNAME,FormInfo.FORMNAME,LanguageInfo.LANNAME,CDATA,FUNCDSC,KEYWORD,PlatformInfo.PLATFORMNAME,DIRECTORY from SourceInfo,FormInfo,PlatformInfo,CLASSINFO,LanguageInfo";
connection.Open();
if(this.checkBox_lan.Checked)
{
whereflag=true;
sqlstr1="select LANID from LanguageInfo where LANNAME='"+comboBox_lan.Text+"'";
command.CommandText=sqlstr1;
DataReader=command.ExecuteReader();
try
{
if(DataReader.Read())
lanid=DataReader.GetString(0);
}
catch(OleDbException ee)
{
MessageBox.Show (ee.Message,"错误!");
connection.Close();
return;
}
finally
{
DataReader.Close();
}
str+=this.comboBox1_l.Text+" SourceInfo.LANID='"+lanid+"' ";
}
if(this.checkBox_plat.Checked)
{
whereflag=true;
sqlstr1="select PLATFORMID from PlatformInfo where PLATFORMNAME='"+comboBox_plat.Text+"'";
command.CommandText=sqlstr1;
DataReader=command.ExecuteReader();
try
{
if(DataReader.Read())
platid=DataReader.GetString(0);
}
catch(OleDbException ee)
{
MessageBox.Show (ee.Message,"错误!");
connection.Close();
return;
}
finally
{
DataReader.Close();
}
str+=this.comboBox2_p.Text+" SourceInfo.PLATFORMID='"+platid+"' ";
}
if(this.checkBox_form.Checked)
{
whereflag=true;
sqlstr1="select FORMID from FormInfo where FORMNAME='"+comboBox_form.Text+"'";
command.CommandText=sqlstr1;
DataReader=command.ExecuteReader();
try
{
if(DataReader.Read())
formid=DataReader.GetString(0);
}
catch(OleDbException ee)
{
MessageBox.Show (ee.Message,"错误!");
connection.Close();
return;
}
finally
{
DataReader.Close();
}
str+=this.comboBox4_f.Text+" SourceInfo.FORMID='"+formid+"' ";
}
if(this.checkBox_func.Checked)
{
whereflag=true;
func=this.textBox_func.Text;
str+=this.comboBox6_f.Text+" SourceInfo.FUNCDSC like '%"+func+"%' ";
}
if(this.checkBox_class.Checked)
{
whereflag=true;
sqlstr1="select CLASSID from CLASSINFO where CLASSNAME='"+comboBox_class.Text+"'";
command.CommandText=sqlstr1;
DataReader=command.ExecuteReader();
try
{
if(DataReader.Read())
classid=DataReader.GetString(0);
}
catch(OleDbException ee)
{
MessageBox.Show (ee.Message,"错误!");
connection.Close();
return;
}
finally
{
DataReader.Close();
}
str+=this.comboBox3_c.Text+" SourceInfo.CLASSID='"+classid+"' ";
}
if(this.checkBox_keyword.Checked)
{
whereflag=true;
keyword=this.textBox_keyword.Text;
str+=this.comboBox5_k.Text+" SourceInfo.KEYWORD like '%"+keyword+"%' ";
}
//产生语句
sqlstr=sqlstr+" where ";
// if(whereflag)
// {
// char []a=str.ToCharArray();
// if(a[0]=='A')
// str=str.Substring(4);
// else
// str=str.Substring(3);
// //sqlstr=sqlstr+str+" AND SourceInfo.CLASSID=CLASSINFO.CLASSID AND SourceInfo.FORMID=FormInfo.FORMID AND SourceInfo.LANID=LanguageInfo.LANID AND SourceInfo.PLATFORMID=PlatformInfo.PLATFORMID";
// }
sqlstr=sqlstr+" SourceInfo.CLASSID=CLASSINFO.CLASSID AND SourceInfo.FORMID=FormInfo.FORMID AND SourceInfo.LANID=LanguageInfo.LANID AND SourceInfo.PLATFORMID=PlatformInfo.PLATFORMID ";
sqlstr+=str;
////////执行查询////////
///
OleDbDataAdapter oleAdapter=new OleDbDataAdapter();
command.CommandText=sqlstr;
oleAdapter.SelectCommand=command;
DataSet dataset=new DataSet();
bool flag=false;
try
{
oleAdapter.Fill(dataset,"tmp");
}
catch(OleDbException ee)
{
MessageBox.Show (ee.Message,"错误!");
flag=true;
}
finally
{
connection.Close();
}
if(!flag)
{
dg_result.DataSource=dataset.Tables["tmp"];
}
#endregion
}
private void checkBox_lan_CheckedChanged(object sender, System.EventArgs e)
{
this.comboBox_lan.Enabled=this.checkBox_lan.Checked;
this.comboBox1_l.Enabled= this.checkBox_lan.Checked;
}
private void checkBox_plat_CheckedChanged(object sender, System.EventArgs e)
{
this.comboBox_plat.Enabled=this.checkBox_plat.Checked;
this.comboBox2_p.Enabled= this.checkBox_plat.Checked;
}
private void checkBox_class_CheckedChanged(object sender, System.EventArgs e)
{
this.comboBox_class.Enabled=this.checkBox_class.Checked;
this.comboBox3_c.Enabled=this.checkBox_class.Checked;
}
private void checkBox_form_CheckedChanged(object sender, System.EventArgs e)
{
this.comboBox_form.Enabled=this.checkBox_form.Checked;
this.comboBox4_f.Enabled= this.checkBox_form.Checked;
}
private void checkBox_keyword_CheckedChanged(object sender, System.EventArgs e)
{
this.textBox_keyword.Enabled=this.checkBox_keyword.Checked;
this.comboBox5_k .Enabled=this.checkBox_keyword.Checked;
}
private void checkBox_func_CheckedChanged(object sender, System.EventArgs e)
{
this.textBox_func.Enabled=this.checkBox_func.Checked;
this.comboBox6_f.Enabled=this.checkBox_func.Checked;
}
private void dg_result_Navigate(object sender, System.Windows.Forms.NavigateEventArgs ne)
{
}
private void myDataGrid_MouseDown(object sender,System.Windows.Forms.MouseEventArgs e)
{
System.Windows.Forms.DataGrid.HitTestInfo hti;
hti = this.dg_result.HitTest(e.X,e.Y);
Point pt=new Point(e.X,e.Y);
if(e.Button==MouseButtons.Right)
{
if(hti.Type== System.Windows.Forms.DataGrid.HitTestType.Cell)
{
contextMenu1.Show(this.dg_result,pt);
}
}
}
private void menuItem1_Click(object sender, System.EventArgs e)
{
if(MessageBox.Show("确认删除吗?","警告",MessageBoxButtons.YesNo)==DialogResult.No)
{
return;
}
//删除记录
int row;
int num;
string sqlstr;
DataTable dt=new DataTable();
row=this.dg_result.CurrentRowIndex;
dt=(DataTable)this.dg_result.DataSource;
num=(int)dt.Rows[row][0];
/////////
OleDbCommand command=new OleDbCommand();
OleDbDataReader Datareader;
command.Connection=connection;
sqlstr="delete from SourceInfo where SCRNUM="+num.ToString();
try
{
connection.Open();
command.CommandText=sqlstr;
command.ExecuteNonQuery();
}
catch (OleDbException ee)
{
MessageBox.Show("错误:"+ee.ToString(),"错误");
connection.Close();
return;
}
finally
{
connection.Close();
}
////////////
//删除文件
string path;
path=(string)dt.Rows[row]["DIRECTORY"];
if(File.Exists(Application.StartupPath+"\\source"+path))
{
try
{
File.Delete(Application.StartupPath+"\\source"+path);
}
catch(Exception ee)
{
MessageBox.Show("错误:"+ee.ToString(),"错误");
}
}
dt.Rows.RemoveAt(row);
this.dg_result.Refresh();
}
private void menuItem2_Click(object sender, System.EventArgs e)
{
//////
DataTable dt=(DataTable)this.dg_result.DataSource;
DataRow row=dt.Rows[this.dg_result.CurrentRowIndex];
//修改记录
UpdateForm frm=new UpdateForm();
frm.SetConnection(connection);
frm.SetCurrentUpdateRow(row);
frm.ShowDialog();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -