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

📄

📁 一个工厂流程图显示的系统。他可以显示工厂各个车间的流程图
💻
字号:
using System;
using System.IO;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;

namespace WebApplication4
{
	/// <summary>
	/// 单元管理 的摘要说明。
	/// </summary>
	public class 单元管理 : System.Web.UI.Page
	{
		protected System.Web.UI.WebControls.Label Label2;
		protected System.Web.UI.WebControls.DropDownList DropDownList2;
		protected System.Web.UI.WebControls.Label Label3;
		protected System.Web.UI.WebControls.Button Button1;
		protected System.Web.UI.WebControls.Label Label4;
		protected System.Web.UI.WebControls.DropDownList DropDownList3;
		protected System.Web.UI.WebControls.Button Button2;
		protected System.Web.UI.WebControls.Button Button3;
		protected System.Web.UI.WebControls.ListBox ListBox1;
		protected System.Web.UI.WebControls.ListBox ListBox2;
		protected System.Web.UI.WebControls.Button Button4;
		protected System.Web.UI.WebControls.Label Info;
		protected System.Web.UI.WebControls.Button Button5;
		protected System.Web.UI.HtmlControls.HtmlInputFile WebFile;
		protected System.Web.UI.WebControls.TextBox TextBox1;
		protected System.Web.UI.WebControls.Label Label1;
		protected System.Web.UI.WebControls.Button Button6;
		protected System.Web.UI.WebControls.Label Label6;
		protected System.Web.UI.WebControls.Label Label7;
		protected System.Web.UI.WebControls.Button Button7;
		protected System.Web.UI.WebControls.TextBox TextBox2;
		protected System.Web.UI.WebControls.Label Label5;
		protected System.Web.UI.WebControls.Button Button8;
		private static string CurrentPath;
	
		private void Page_Load(object sender, System.EventArgs e)
		{
			// 在此处放置用户代码以初始化页面
			TextBox1.Visible=false;
			if( Page.IsPostBack==false)
			{
				CurrentPath= @"c:\UserDir\";  //设置当前目录
				if(Directory.Exists(@"c:\UserDir\")==false) //若该目录不存在,创建该目录
					Directory.CreateDirectory(@"c:\UserDir\");
				LoadDir(CurrentPath);  //初始化装入目录
			}
		}


		private void LoadDir(string FullPath)
		{
			CurrentPath=FullPath;
			ArrayList values = new ArrayList();
			string [] MyFiles,MyDirs;
			MyFiles = Directory.GetFiles(FullPath);  //得到该目录下所有文件
			if(CurrentPath!=@"c:\UserDir")  //若不是顶级目录,增加返回上级目录选项
			{
				values.Add("返回上级目录");
			}
			values.AddRange(MyFiles);  //加入文件
			MyDirs= Directory.GetDirectories(FullPath);  //得到该目录下所有目录
			values.AddRange(MyDirs);  //加入目录

	
		}
		#region Web 窗体设计器生成的代码
		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
			//
			InitializeComponent();
			base.OnInit(e);
		}
		
		/// <summary>
		/// 设计器支持所需的方法 - 不要使用代码编辑器修改
		/// 此方法的内容。
		/// </summary>
		private void InitializeComponent()
		{    
			this.Button5.Click += new System.EventHandler(this.Button5_Click);
			this.Button4.Click += new System.EventHandler(this.Button4_Click);
			this.Button3.Click += new System.EventHandler(this.Button3_Click);
			this.Button2.Click += new System.EventHandler(this.Button2_Click);
			this.DropDownList2.SelectedIndexChanged += new System.EventHandler(this.DropDownList2_SelectedIndexChanged);
			this.Button1.Click += new System.EventHandler(this.Button1_Click);
			this.Button6.Click += new System.EventHandler(this.Button6_Click);
			this.Button7.Click += new System.EventHandler(this.Button7_Click);
			this.Button8.Click += new System.EventHandler(this.Button8_Click);
			this.Load += new System.EventHandler(this.Page_Load);

		}
		#endregion

		private void Button1_Click(object sender, System.EventArgs e)
		{
			if(WebFile.PostedFile.FileName=="")
			{
				Info.Text="请先选择要上传的文件";
				return;
			}

			try
			{
				char[] spliter = {'\\'};
				string [] FileName = WebFile.PostedFile.FileName.Split(spliter,10);

				string FullPath = CurrentPath + @"\" + FileName[FileName.Length-1];  //生成完整文件名
				WebFile.PostedFile.SaveAs(FullPath);  //保存文件
				LoadDir(CurrentPath);  //重新载入当前目录
			}
			catch
			{
				Info.Text="上传文件失败,请与管理员联系";
			}
		}

		private void Button4_Click(object sender, System.EventArgs e)
		{
			if(ListBox1.SelectedIndex!=-1&&ListBox2.Items.FindByValue(ListBox1.SelectedItem.Value)==null)
			{    
					ListBox2.Items.Add(ListBox1.SelectedItem);
					ListBox2.SelectedIndex=-1;			
			    
			}
		
		}

		private void Button5_Click(object sender, System.EventArgs e)
		{
			if(ListBox2.SelectedIndex!=-1)   
			{  
				ListBox2.Items.Remove(ListBox2.SelectedItem);
				
			}   
         	}

		private void Button2_Click(object sender, System.EventArgs e)
		{
			TextBox1.Visible=true;
			
		}

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

		
		private void Button7_Click(object sender, System.EventArgs e)
		{ 
			int t=1;
			SqlConnection con = new SqlConnection("server=localhost;uid=sa;password=123;database=factory");
			string ls="select 车间号 from 车间表 where 车间名称='"+DropDownList2.SelectedItem+"'";			 
			SqlCommand sc=new SqlCommand(ls,con);
			SqlDataReader odr=null;
            con.Open();
			string lss="";
			odr=sc.ExecuteReader();
			while(odr.Read())
			   {
				lss=odr["车间号"].ToString();               
			    }
			  TextBox2.Text=lss;
			odr.Close();
		           
			
            string ls1="select count(工段号) from 工段表 "; 
			SqlCommand sc1=new SqlCommand(ls1,con);
			SqlDataReader odr1=null;			
			string tt="";
			odr1=sc1.ExecuteReader();
			while(odr1.Read())
			{
			 tt=odr1[0].ToString();               
			}
			odr1.Close();
			
			int inum=int.Parse(tt);	

			SqlCommand da = new SqlCommand ("select 工段名称 from 工段表",con);	
			SqlDataReader odr2=null;			
			
			try
			{
				odr2=da.ExecuteReader();
			}
			catch(Exception ex)
			{
				if(ex!=null) {Label5.Visible=true;Label5.Text="执行出错";}
			}
			if(odr2!=null)
			{
				string et="";
				while(odr2.Read())
				{
					et=odr2["工段名称"].ToString(); 
					if(et==TextBox1.Text.Trim())
					{
					   Label5.Visible=true;
                       Label5.Text="已经有此单元,请重新输入";
					   t=0;
					}
				}
				odr2.Close();
			}
			if(TextBox2.Text.Trim()!=""&&t!=0)
			{
				SqlCommand da1 = new SqlCommand ("insert into 工段表 values('"+(inum+1)+"','"+lss+"','"+TextBox1.Text.Trim()+"')",con);			
				int ExeNum=da1.ExecuteNonQuery();
				if(ExeNum==1)
				{
					Label5.Visible=true;
					Label5.Text="新建成功";
				}
				else{
					Label5.Visible=true;
					Label5.Text="新建失败";
				}
			}
            
			con.Close();
				
		}

		private void Button3_Click(object sender, System.EventArgs e)
		{
			SqlConnection con = new SqlConnection("server=localhost;uid=sa;password=123;database=factory");
			string ls="delete from 工段表 where 工段名称='"+DropDownList3.SelectedItem+"'";			 
			SqlCommand da=new SqlCommand(ls,con);
			con.Open();	
			int ExeNum1=da.ExecuteNonQuery();
			if(ExeNum1==1)
			{
				Label5.Visible=true;
				Label5.Text="删除成功";
			}
			else
			{
                Label5.Visible=true;
				Label5.Text="删除失败";
			   }
            
			con.Close();
		}

		private void DropDownList2_SelectedIndexChanged(object sender, System.EventArgs e)
		{
			
				SqlConnection con = new SqlConnection("server=localhost;uid=sa;password=123;database=factory");
				string ss="select 工段名称 from 工段表 where 车间号 in (select 车间号 from 车间表 where 车间名称='"+DropDownList2.SelectedItem+"')";
				SqlDataAdapter da = new SqlDataAdapter(ss,con);
				
				DataSet ds = new DataSet();
				da.Fill(ds);
				
				DropDownList3.DataSource=ds;
                DropDownList3.DataTextField="工段名称";
                DropDownList3.DataValueField="工段名称";
				DropDownList3.DataBind();
				
			
		}

		private void Button8_Click(object sender, System.EventArgs e)
		{
		Label5.Visible=false;
		}
	}
}

⌨️ 快捷键说明

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