⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sysmain.cs

📁 简易专家系统程序
💻 CS
📖 第 1 页 / 共 4 页
字号:
						cn1.Open();
						cm3.ExecuteNonQuery();
						cn1.Close();
					}
					catch
					{
						if(MessageBox.Show("临时表修改错误!","错误提示",MessageBoxButtons.RetryCancel)==DialogResult.Cancel)
							Application.Exit();
						cn1.Close();
					}
				}
				else
				{
					cm3.CommandText="update cs_tempfact set flag=0 where inruleno='"+dt1.Rows[i]["inruleno"].ToString()+"'";
					try
					{
						cn1.Open();
						cm3.ExecuteNonQuery();
						cn1.Close();
					}
					catch
					{
						if(MessageBox.Show("临时表修改错误!","错误提示",MessageBoxButtons.RetryCancel)==DialogResult.Cancel)
							Application.Exit();
						cn1.Close();
					}
				}
					//a=1;
			}
			cm1.CommandText="select distinct inruleno from cs_tempfact where flag=1";
			adp1.SelectCommand=cm1;
			dt2.Clear();
			adp1.Fill(dt2);
			int t=0;
			if(dt2.Rows.Count==0)
				textBox1.Text="推理不成功,有可能数据重复,请点刷新或重新选择,如不想继续请点退出!";
			else
			{
				for(i=0;i<dt2.Rows.Count;i++)
				{
						//if(dt2.Rows[i]["InRuleNo"].ToString()==dt2.Rows[i+1]["InRuleNo"].ToString())
						//continue;
						//else
						//{
					cm2.CommandText="select * from rules where ruleno='"+dt2.Rows[i]["InRuleNo"]+"'";
					adp1.SelectCommand=cm2;
					dt1.Clear();
					adp1.Fill(dt1);
					cm3.CommandText="select * from fact where factno='"+dt1.Rows[0]["conno"]+"'";
					adp1.SelectCommand=cm3;
					dt3.Clear();
					adp1.Fill(dt3);
					listBox3.Items.Add(dt3.Rows[0]["facttx"].ToString());
					t++;
						//}
				}
			}
		}

		private void button1_Click(object sender, System.EventArgs e)
		{
			SqlConnection cn=new SqlConnection(conn.con);
			SqlCommand com1=new SqlCommand("delete  from cs_tempfact",cn);
			try
			{
				cn.Open();
				com1.ExecuteNonQuery();
				cn.Close();
			}
			catch
			{
				if(MessageBox.Show("数据清空出现问题","错误提示",MessageBoxButtons.RetryCancel)==DialogResult.Cancel)
					Application.Exit();
			}
		}

		private void button3_Click(object sender, System.EventArgs e)
		{
			this.Close();
		}

		private void button5_Click(object sender, System.EventArgs e)
		{
			SqlConnection cn2=new SqlConnection(conn.con);
			SqlCommand cm2=new SqlCommand("update fact set facttx='"+textBox4.Text+"',Factpos='"+textBox3.Text+"' where factno='"+textBox2.Text+"'",cn2);
			try
			{
				cn2.Open();
				cm2.ExecuteNonQuery();
				cn2.Close();
			}
			catch
			{
				if(MessageBox.Show("数据修改错误!","错误提示",MessageBoxButtons.RetryCancel)==DialogResult.Cancel)
					Application.Exit();
				cn2.Close();
			}
		}

		private void button6_Click(object sender, System.EventArgs e)
		{
			textBox2.Text="";
			textBox3.Text="";
			textBox4.Text="";
		}

		private void button7_Click(object sender, System.EventArgs e)
		{
			SqlConnection cn3=new SqlConnection(conn.con);
			SqlCommand cm3=new SqlCommand("insert into fact (factno,facttx,factpos)values('"+textBox2.Text+"','"+textBox4.Text+"','"+textBox3.Text+"')",cn3);
			try
			{
				cn3.Open();
				cm3.ExecuteNonQuery();
				cn3.Close();
			}
			catch
			{
				if(MessageBox.Show("数据插入错误!","错误提示",MessageBoxButtons.RetryCancel)==DialogResult.Cancel)
					Application.Exit();
				cn3.Close();
			}
		}

		private void button8_Click(object sender, System.EventArgs e)
		{
			SqlConnection cn4=new SqlConnection(conn.con);
			SqlCommand cm4=new SqlCommand("delete fact where factno='"+textBox2.Text+"'",cn4);
			SqlCommand cm5=new SqlCommand("delete rules where preno='"+textBox2.Text+"'",cn4);
			SqlCommand cm6=new SqlCommand("delete rules where conno='"+textBox2.Text+"'",cn4);
			if (textBox3.Text=="0")
			{
				
				try
				{
					cn4.Open();
					cm5.ExecuteNonQuery();
					cm4.ExecuteNonQuery();
					cn4.Close();
				}
				catch
				{
					if(MessageBox.Show("数据删除错误!","错误提示",MessageBoxButtons.RetryCancel)==DialogResult.Cancel)
						Application.Exit();
					cn4.Close();
				}
			}
								 
			else
			{
				try
				{
					cn4.Open();
					cm6.ExecuteNonQuery();
					cm4.ExecuteNonQuery();
					cn4.Close();
				}
				catch
				{
					if(MessageBox.Show("数据删除错误!","错误提示",MessageBoxButtons.RetryCancel)==DialogResult.Cancel)
						Application.Exit();
					cn4.Close();
				}
			}
		}

		private void button9_Click(object sender, System.EventArgs e)
		{
			SqlConnection cn=new SqlConnection(conn.con);
			string cm="select * from fact where Factno='"+comboBox1.SelectedItem.ToString()+"'";
			SqlCommand com=new SqlCommand(cm,cn);
			SqlDataAdapter adp=new SqlDataAdapter(com);
			DataTable dt=new DataTable("myt");
			adp.Fill(dt);
			textBox2.Text=dt.Rows[0]["factno"].ToString();
			textBox4.Text=dt.Rows[0]["facttx"].ToString();
			textBox3.Text=dt.Rows[0]["factpos"].ToString();
		}

		private void button10_Click(object sender, System.EventArgs e)
		{
			int i;
			SqlConnection cn6=new SqlConnection(conn.con);
			SqlCommand cm6=new SqlCommand("",cn6);
			string com="select * from fact where facttx like '"+'%'+textBox5.Text+'%'+"'";
			cm6.CommandText=com;
			SqlDataAdapter adp=new SqlDataAdapter(cm6);
			DataTable dt=new DataTable("myt");
			adp.Fill(dt);
			if(dt.Rows.Count==0)
				textBox6.Text="没有可显示信息!!";
			else
			{
				for(i=0;i<dt.Rows.Count;i++)
				{
					textBox2.Text=dt.Rows[i]["factno"].ToString();
					textBox4.Text=dt.Rows[i]["facttx"].ToString();
					textBox3.Text=dt.Rows[i]["factpos"].ToString();
				}
			}
		}

		private void button11_Click(object sender, System.EventArgs e)
		{
		    SqlConnection cn=new SqlConnection(conn.con);
			SqlCommand com=new SqlCommand("select * from fact ",cn);
			SqlDataAdapter adp=new SqlDataAdapter(com);
			DataTable dt=new DataTable("mydt");
			adp.Fill(dt);
			dataGrid1.DataSource=dt;
		}

		private void button12_Click(object sender, System.EventArgs e)
		{
			listBox1.Items.Clear();
			listBox6.Items.Clear();
			listBox5.Items.Clear();
	        SqlConnection cn=new SqlConnection(conn.con);
			SqlCommand com=new SqlCommand("select * from rules where ruleno='"+comboBox2.SelectedItem.ToString()+"'",cn);
			SqlDataAdapter adp=new SqlDataAdapter(com);
			DataTable dt=new DataTable("mydt4");
			adp.Fill(dt);
			int i;
			for(i=0;i<dt.Rows.Count;i++)
			{
				listBox1.Items.Add(dt.Rows[i]["preno"].ToString());
			}
			textBox7.Text=dt.Rows[0]["conno"].ToString();
			listBox6.Items.Add(comboBox2.SelectedItem.ToString());
			textBox8.Text=dt.Rows[0]["trust"].ToString();
			
		}

		private void tabPage4_Click(object sender, System.EventArgs e)
		{
		
		}

		private void button13_Click(object sender, System.EventArgs e)
		{
			int i;
			for(i=0;i<listBox2.SelectedItems.Count;i++)
			{
				listBox5.Items.Add(listBox2.SelectedItems[i].ToString());
			}
		}

		private void button14_Click(object sender, System.EventArgs e)
		{
			int i;
			SqlConnection cn=new SqlConnection(conn.con);
			SqlCommand com=new SqlCommand("delete from rules where ruleno='"+listBox6.Items[0].ToString()+"'",cn);
			SqlDataAdapter adp=new SqlDataAdapter();
			try
			{
				cn.Open();
				com.ExecuteNonQuery();
				cn.Close();
			}
			catch
			{
				if(MessageBox.Show("数据修改错误!","错误提示",MessageBoxButtons.RetryCancel)==DialogResult.Cancel)
					Application.Exit();
				cn.Close();
			}
			SqlCommand com1=new SqlCommand("",cn);
			//SqlCommand com1=new SqlCommand("insert into rules (ruleno,preno,conno) values ('"+comboBox2.SelectedItem.ToString()+"','"+listBox5.Items[i].ToString()+"','"+textBox7.Text+"')",cn);
			for(i=0;i<listBox5.Items.Count;i++)
			{
				com1.CommandText="insert into rules (ruleno,preno,conno,trust) values ('"+comboBox2.SelectedItem.ToString()+"','"+listBox5.Items[i].ToString()+"','"+textBox7.Text+"','"+textBox8.Text+"')";
				try
				{
					cn.Open();
					//com.ExecuteNonQuery();
					com1.ExecuteNonQuery();
					cn.Close();
				}
				catch
				{
					if(MessageBox.Show("数据修改错误!","错误提示",MessageBoxButtons.RetryCancel)==DialogResult.Cancel)
						Application.Exit();
					cn.Close();
				}
			}

		}

		private void button15_Click(object sender, System.EventArgs e)
		{
			SqlConnection cn=new SqlConnection(conn.con);
			SqlCommand comtt=new SqlCommand("select * from rules",cn);
			SqlDataAdapter adp=new SqlDataAdapter(comtt);
			DataTable dt=new DataTable("mydt5");
			adp.Fill(dt);
			SqlCommand com=new SqlCommand("select distinct ruleno from rules",cn);
			adp.SelectCommand=com;
			DataTable dt1=new DataTable("mydt6");
			adp.Fill(dt1);
			dataGrid3.DataSource=dt;
			listBox5.Items.Clear();
			comboBox2.Items.Clear();
			comboBox4.Items.Clear();
			int i;
			for(i=0;i<dt1.Rows.Count;i++)
			{
				comboBox2.Items.Add(dt1.Rows[i]["ruleno"].ToString());
			}
			for(i=0;i<dt1.Rows.Count;i++)
			{
				comboBox4.Items.Add(dt1.Rows[i]["ruleno"].ToString());
			}
		}

		private void button18_Click(object sender, System.EventArgs e)
		{
			SqlConnection cn=new SqlConnection(conn.con);
			SqlCommand com=new SqlCommand("",cn);
			int i;
			for(i=0;i<listBox7.SelectedItems.Count;i++)
			{
				com.CommandText="insert into rules (ruleno,preno,conno,trust) values ('"+textBox9.Text+"','"+listBox7.SelectedItems[i].ToString()+"','"+comboBox3.SelectedItem.ToString()+"','"+textBox10.Text+"')";
				try
				{
					cn.Open();
					com.ExecuteNonQuery();
					cn.Close();
				}
				catch
				{
					if(MessageBox.Show("数据插入错误!","错误提示",MessageBoxButtons.RetryCancel)==DialogResult.Cancel)
						Application.Exit();
					cn.Close();
				}
			}
		}

		private void button19_Click(object sender, System.EventArgs e)
		{
			SqlConnection cn=new SqlConnection(conn.con);
			SqlCommand com=new SqlCommand("delete from rules where ruleno='"+comboBox4.SelectedItem.ToString()+"'",cn);
			if(MessageBox.Show("是否确定删除?","删除提示",MessageBoxButtons.RetryCancel)!=DialogResult.Cancel)
			{
				try
				{
					cn.Open();
					com.ExecuteNonQuery();
					cn.Close();
				}
				catch
				{
					if(MessageBox.Show("数据删除错误!","错误提示",MessageBoxButtons.RetryCancel)==DialogResult.Cancel)
						Application.Exit();
					cn.Close();
				}
			}
			//else
				//Application.Exit();
		}

		private void button20_Click(object sender, System.EventArgs e)
		{
			comboBox4.Items.Clear();
			SqlConnection cn=new SqlConnection(conn.con);
			SqlCommand com=new SqlCommand("select distinct ruleno from rules",cn);
			SqlDataAdapter adp=new SqlDataAdapter(com);
			DataTable dt=new DataTable("mydt");
			adp.Fill(dt);
			int i;
			for(i=0;i<dt.Rows.Count;i++)
			{
				comboBox4.Items.Add(dt.Rows[i]["ruleno"].ToString());
			}
		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -