📄 default.aspx.cs
字号:
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.OleDb;
using System.Data.SqlClient;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void ButtonYes_Click(object sender, EventArgs e)
{
string connStr = "provider=Microsoft.Jet.OLEDB.4.0;Data Source =D:\\C++test1\\App_Data\\Animal.mdb";
OleDbConnection con;
OleDbCommand cmd;
OleDbDataReader myDataReader;
con=new OleDbConnection(connStr);
int j = 0,Num;
string[] a = new string[20];
for (int i = 0; i < CheckBoxList1.Items.Count; i++)
{
a[i] = "";
if (CheckBoxList1.Items[i].Selected)
{
a[j]=CheckBoxList1.Items[i].Text;
j++;
}
}
for (int i = 0; i < CheckBoxList2.Items.Count; i++)
{
a[j] = "";
if (CheckBoxList2.Items[i].Selected)
{
a[j] = CheckBoxList2.Items[i].Text;
j++;
}
}
Num = j;
for (int i = 0; i < Num; i++)
{
string selectCmd = "select * from FIRST1 where Num='"+a[i]+"' ";
con.Open();
cmd = new OleDbCommand(selectCmd, con);
myDataReader = cmd.ExecuteReader();
if (myDataReader.HasRows)
{
myDataReader.Read();
int k;
for ( k = 0; k < j; k++)
{
if (a[k] == myDataReader.GetString(2))
break;
}
if (k == j)
{
a[i] = myDataReader.GetString(2);
}
}
else if (j <= 1)
{
Label1.Text ="你描述的动物不存在,请重新选择动物特征!";
return;
}
con.Close();
}
diaoyong:
for(int i=0;i<Num-1;i++)
for (int m = i + 1; m < Num; m++)
{
string selectCmd = "select * from SECOND1 where (Num1= '" + a[i] + "' and Num2='" + a[m] + "') or( Num1='" + a[m] + "' and Num2='" + a[i]+"')";
con.Open();
cmd = new OleDbCommand(selectCmd, con);
myDataReader = cmd.ExecuteReader();
if (myDataReader.HasRows)
{
myDataReader.Read();
if (myDataReader.GetString(4) == "Yes" && m == 1 && i == 0 && a[2]=="")
{
Label1.Text = "你描述的动物应该是:" + myDataReader.GetString(3);
con.Close();
return;
}
else
{
int k;
for (k = 0; k < j; k++)
{
if (a[k] == myDataReader.GetString(3))
break;
}
if (k == j)
{
int b;
a[i] = myDataReader.GetString(3);
for (b = m; b <= j-1; b++)
a[b] = a[b + 1];
a[b] = "";
j--;
con.Close();
goto diaoyong;
}
}
}
else if (j <= 2)
{
Label1.Text = "你描述的动物不存在,请重新选择动物特征!";
con.Close();
return;
}
con.Close();
}
for(int i=0;i<Num-2;i++)
for(int m=i+1;m<Num-1;m++)
for(int n=m+1;n<Num;n++)
{
string selectCmd = "select * from THIRD1 where (Num1=' " + a[i] + "' and Num2='" + a[m] + "' and Num3='"+a[n]+"') or( Num1='" + a[m] + "' and Num2='" + a[i]+"' and Num3='"+a[n]+"') or (Num1= '" + a[i] + "' and Num2='" + a[n] + "' and Num3='"+a[m]+"') or (Num1=' " + a[n] + "' and Num2=' " + a[m] + "' and Num3='"+a[i]+"') or(Num1=' " + a[n] + "' and Num2=' " + a[i] + "' and Num3=' "+a[m]+"') or (Num1=' " + a[m] + "' and Num2='" + a[n] + "'and Num3='"+a[i]+"')";
con.Open();
cmd = new OleDbCommand(selectCmd, con);
myDataReader = cmd.ExecuteReader();
if (myDataReader.HasRows)
{
myDataReader.Read();
if (myDataReader.GetString(5) == "Yes" && n == 2 && m == 1 && i == 0 && a[3]=="" )
{
Label1.Text ="你描述的动物应该是:" + myDataReader.GetString(4);
con.Close();
return;
}
else
{
int k;
for (k = 0; k < j; k++)
{
if (a[k] == myDataReader.GetString(4))
break;
}
if (k == j)
{
int b;
a[i] = myDataReader.GetString(4);
for (b = m; b <= j - 1; b++)
a[b] = a[b + 1];
a[b] = "";
j--;
for (b = n; b <= j - 1; b++)
a[b] = a[b + 1];
a[b] = "";
j--;
con.Close();
goto diaoyong;
}
}
}
else if(j<=3)
{
Label1.Text ="你描述的动物不存在,请重新选择动物特征!";
con.Close();
return;
}
con.Close();
}
for (int i = 0; i < Num - 3; i++)
{
for (int m = i + 1; m < Num - 2; m++)
for (int n = m + 1; n < Num - 1; n++)
for (int q = n + 1; q < Num; q++)
{
string selectCmd = "select * from FOURTH1 where (Num1='" + a[i] + "' and Num2='" + a[m] + "' and Num3='" + a[n] + "' and Num4='" + a[q] + "') or( Num1='" + a[m] + "' and Num2='" + a[i] + "' and Num3='" + a[n] + "' and Num4='" + a[q] + "') or (Num1='" + a[i] + "' and Num2='" + a[n] + "' and Num3='" + a[m] + "' and Num4='" + a[q] + "') or (Num1='" + a[n] + "' and Num2='" + a[m] + "' and Num3='" + a[i] + "' and Num4='" + a[q] + "') or(Num1='" + a[n] + "' and Num2='" + a[i] + "' and Num3='" + a[m] + "' and Num4='" + a[q] + "') or (Num1='" + a[m] + "' and Num2='" + a[n] + "' and Num3='" + a[i] + "' and Num4='" + a[q] + "')"
+ "or (Num1='" + a[q] + "' and Num2='" + a[m] + "' and Num3='" + a[n] + "' and Num4='" + a[i] + "') or( Num1='" + a[q] + "' and Num2='" + a[i] + "' and Num3='" + a[n] + "' and Num4='" + a[m] + "') or (Num1='" + a[q] + "' and Num2='" + a[n] + "' and Num3='" + a[m] + "' and Num4='" + a[i] + "') or (Num1='" + a[q] + "' and Num2='" + a[m] + "' and Num3='" + a[i] + "' and Num4='" + a[n] + "') or(Num1='" + a[q] + "' and Num2='" + a[i] + "' and Num3='" + a[m] + "' and Num4='" + a[n] + "') or (Num1='" + a[q] + "' and Num2='" + a[n] + "' and Num3='" + a[i] + "' and Num4='" + a[m] + "')"
+ "or (Num1='" + a[i] + "' and Num2='" + a[q] + "' and Num3='" + a[n] + "' and Num4='" + a[m] + "') or( Num1='" + a[m] + "' and Num2='" + a[q] + "' and Num3='" + a[n] + "' and Num4='" + a[i] + "') or (Num1='" + a[i] + "' and Num2='" + a[q] + "' and Num3='" + a[m] + "' and Num4='" + a[n] + "') or (Num1='" + a[n] + "' and Num2='" + a[q] + "' and Num3='" + a[i] + "' and Num4='" + a[m] + "') or(Num1='" + a[n] + "' and Num2='" + a[q] + "' and Num3='" + a[m] + "' and Num4='" + a[i] + "') or (Num1='" + a[m] + "' and Num2='" + a[q] + "' and Num3='" + a[i] + "' and Num4='" + a[n] + "')"
+ "or (Num1='" + a[i] + "' and Num2='" + a[m] + "' and Num3='" + a[q] + "' and Num4='" + a[n] + "') or( Num1='" + a[m] + "' and Num2='" + a[i] + "' and Num3='" + a[q] + "' and Num4='" + a[n] + "') or (Num1='" + a[i] + "' and Num2='" + a[n] + "' and Num3='" + a[q] + "' and Num4='" + a[m] + "') or (Num1='" + a[n] + "' and Num2='" + a[m] + "' and Num3='" + a[q] + "' and Num4='" + a[i] + "') or(Num1='" + a[n] + "' and Num2='" + a[i] + "' and Num3='" + a[q] + "' and Num4='" + a[m] + "') or (Num1='" + a[m] + "' and Num2='" + a[n] + "' and Num3='" + a[q] + "' and Num4='" + a[i] + "')";
con.Open();
cmd = new OleDbCommand(selectCmd, con);
myDataReader = cmd.ExecuteReader();
if (myDataReader.HasRows)
{
myDataReader.Read();
if (myDataReader.GetString(6) == "Yes" && q==3 && n==2 && m==1 && i==0 && a[4]=="")
{
Label1.Text ="你描述的动物应该是:" + myDataReader.GetString(5);
con.Close();
return;
}
else
{
int k;
for (k = 0; k < j; k++)
{
if (a[k] == myDataReader.GetString(5))
break;
}
if (k == j)
{
int b;
a[i] = myDataReader.GetString(5);
for (b = m; b <= j - 1; b++)
a[b] = a[b + 1];
a[b] = "";
j--;
for (b = n; b <= j - 1; b++)
a[b] = a[b + 1];
a[b] = "";
j--;
for (b = q; b <= j - 1; b++)
a[b] = a[b + 1];
a[b] = "";
j--;
con.Close();
goto diaoyong;
}
}
}
else if (j <= 4)
{
Label1.Text ="你描述的动物不存在,请重新选择动物特征!";
con.Close();
return;
}
con.Close();
}
}
Label1.Text ="你描述的动物不存在,请重新选择动物特征!";
return;
}
protected void ButtonCancel_Click(object sender, EventArgs e)
{
for (int i = 0; i < CheckBoxList1.Items.Count; i++)
{
CheckBoxList1.Items[i].Selected=false;
}
for (int i = 0; i < CheckBoxList2.Items.Count; i++)
{
CheckBoxList2.Items[i].Selected=false;
}
}
protected void ButtonAdd_Click(object sender, EventArgs e)
{
string connStr = "provider=Microsoft.Jet.OLEDB.4.0;Data Source =D:\\C++test1\\App_Data\\Animal.mdb";
OleDbConnection con;
OleDbCommand cmd;
con = new OleDbConnection(connStr);
string insertCmd;
if (TextBoxCon4.Text.Trim() == "")
{
if (TextBoxCon3.Text.Trim() == "")
{
if (TextBoxCon2.Text.Trim() == "")
insertCmd = "insert into FIRST1 ( Num, Result1, Finally1) values (" + TextBoxCon1.Text.Trim() + "," + TextBoxRes.Text.Trim() + "," + DropDownList1.SelectedItem.Text + ")";
else
insertCmd = "insert into SECOND1 ( Num1,Num2, Result, Finally) values (" + TextBoxCon1.Text.Trim() + "," + TextBoxCon2.Text.Trim() + "," + TextBoxRes.Text.Trim() + "," + DropDownList1.SelectedItem.Text + ")";
}
else
{
insertCmd = "insert into THIRD1 ( Num1,Num2,Num3, Result, Finally) values (" + TextBoxCon1.Text.Trim() + "," + TextBoxCon2.Text.Trim() + "," + TextBoxCon3.Text.Trim() + "," + TextBoxRes.Text.Trim() + "," + DropDownList1.SelectedItem.Text + ")";
}
}
else
insertCmd = "insert into FOURTH1 ( Num1,Num2,Num3,Num4, Result, Finally) values (" + TextBoxCon1.Text.Trim() + "," + TextBoxCon2.Text.Trim() + "," + TextBoxCon3.Text.Trim() + "," + TextBoxCon4.Text.Trim() + "," + TextBoxRes.Text.Trim() + "," + DropDownList1.SelectedItem.Text + ")";
con.Open();
cmd = new OleDbCommand(insertCmd, con);
cmd.ExecuteNonQuery();
TextBoxCon1.Text = "";
TextBoxCon2.Text = "";
TextBoxCon3.Text = "";
TextBoxCon4.Text = "";
TextBoxRes.Text = "";
DropDownList1.SelectedIndex = 0;
}
protected void ButtonCancel2_Click(object sender, EventArgs e)
{
TextBoxCon1.Text="";
TextBoxCon2.Text="";
TextBoxCon3.Text="";
TextBoxCon4.Text="";
TextBoxRes.Text="";
DropDownList1.SelectedIndex=0;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -