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

📄 materialfind.aspx.cs

📁 用Visual C#.net开发企业材料采购管理系统数据库使用的是SqlServer2000
💻 CS
字号:
using System;
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;

namespace WebApplication5
{
	/// <summary>
	/// MaterialFind 的摘要说明。
	/// </summary>
	public class MaterialFind : System.Web.UI.Page
	{
		protected System.Web.UI.WebControls.ImageButton Img_save;
		protected System.Web.UI.WebControls.ImageButton Img_search;
		protected System.Web.UI.WebControls.ImageButton Img_clear;
		protected System.Web.UI.WebControls.ImageButton Img_delete;
		protected System.Web.UI.WebControls.Label Label1;
		protected System.Web.UI.WebControls.Label Label2;
		protected System.Web.UI.WebControls.Label Label3;
		protected System.Web.UI.WebControls.DropDownList DDList1;
		protected System.Web.UI.WebControls.DropDownList DDList2;
		protected System.Web.UI.WebControls.TextBox Txt_value;
		protected System.Web.UI.WebControls.DropDownList DDList3;
		protected System.Web.UI.WebControls.ListBox ListBox1;
		protected System.Web.UI.WebControls.DataGrid DataGrid1;
		protected System.Web.UI.WebControls.Panel Panel1;
	    protected DataBase Data=new DataBase();
		protected Resource Res=new Resource(); 
		private void Page_Load(object sender, System.EventArgs e)
		{
			Data.AddEvent("确定是否删除?",Img_delete,"onclick"); 
			// 在此处放置用户代码以初始化页面
			if (!Page.IsPostBack)
			{
				Label1.Text="c_id";
				Label2.Text=" and "; 
				InitData();
			}

		}
		private void InitData()
		{
			for (int i=0;i<Res.FIELD_NAME1.Length;i++)
			{
                 DDList1.Items.Add(Res.FIELD_NAME1[i]);  
			}
			for (int i=0;i<Res.OPERATEOR_NAME.Length;i++)
			{
				DDList2.Items.Add(Res.OPERATEOR_NAME[i]);  
			}
			DDList3.Items.Add("并且");
			DDList3.Items.Add("或者"); 
		}

		#region Web 窗体设计器生成的代码
		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
			//
			InitializeComponent();
			base.OnInit(e);
		}
		
		/// <summary>
		/// 设计器支持所需的方法 - 不要使用代码编辑器修改
		/// 此方法的内容。
		/// </summary>
		private void InitializeComponent()
		{    
			this.Img_save.Click += new System.Web.UI.ImageClickEventHandler(this.Img_save_Click);
			this.Img_search.Click += new System.Web.UI.ImageClickEventHandler(this.Img_search_Click);
			this.Img_clear.Click += new System.Web.UI.ImageClickEventHandler(this.Img_clear_Click);
			this.Img_delete.Click += new System.Web.UI.ImageClickEventHandler(this.Img_delete_Click);
			this.DDList1.SelectedIndexChanged += new System.EventHandler(this.DDList1_SelectedIndexChanged);
			this.DDList3.SelectedIndexChanged += new System.EventHandler(this.DDList3_SelectedIndexChanged);
			this.DataGrid1.CancelCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.DataGrid1_CancelCommand);
			this.DataGrid1.EditCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.DataGrid1_EditCommand);
			this.DataGrid1.UpdateCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.DataGrid1_UpdateCommand);
			this.Load += new System.EventHandler(this.Page_Load);

		}
		#endregion

		private void Img_save_Click(object sender, System.Web.UI.ImageClickEventArgs e)
		{
			if ((Txt_value.Text).Trim()=="")
			{
				Data.ShowMessage("查询值不能为空!",Page); 
				return;
			}
			string strSql=Label1.Text+DDList2.SelectedItem.Value+"'"+Txt_value.Text+"'"+Label2.Text; 
			 
			ListBox1.Items.Add(strSql);  
		}

		private void DDList1_SelectedIndexChanged(object sender, System.EventArgs e)
		{
			///Label1.Text=DDList1.SelectedItem.Value; 
			switch (DDList1.SelectedItem.Value)
			{
				case "序号":
					
					Label1.Text="c_id"; 
					break;
				case "年":
					
					Label1.Text="m_year"; 
					break;
				case "月":
					
					Label1.Text="m_month"; 
					break;
				case "供应商":
					
					Label1.Text="m_provider"; 
					break;
				case "材料名称":
					
					Label1.Text="m_material"; 
					break;
				case "单价":
					
					Label1.Text="m_price"; 
					break;
				case "数量":
					
					Label1.Text="m_amount"; 
					break;
				case "类别":
					
					Label1.Text="m_catagory"; 
					break;
                case "金额":
                    Label1.Text="m_money";
					break;
				case "计量单位":
					Label1.Text="m_unit"; 
					break;
             }
		}

		private void DDList3_SelectedIndexChanged(object sender, System.EventArgs e)
		{
			switch (DDList3.SelectedItem.Value)
			{
				case "并且":
                    Label2.Text=" and ";
					break;
                case "或者":
					Label2.Text=" or ";
					break;
			}

		}

		private void Img_search_Click(object sender, System.Web.UI.ImageClickEventArgs e)
		{
			if (ListBox1.Items.Count==0)
			{  
				Data.BindData(DataGrid1,"select * from material_info","material_info"); 
				//Data.ShowMessage("请添加查询条件...",Page);
				return;
			}
			string strSql=null;////得到listbox控件索引值连接起来的字符串 
			string strSql1=null;////得到去掉or或者and后的字符串
			string strSql2=null;////得到查询字符串
			for (int i=0;i<ListBox1.Items.Count;i++)
			{
				strSql+=ListBox1.Items[i].Value;
			}
			
			bool at;
			int IndexPos=0;
			at=strSql.EndsWith(" or "); ///查找or最后出现在strSql中的索引位置,如果存在返回true否者false
			if (at) ////如果为真
			{
				IndexPos=strSql.LastIndexOf("or");///得到or的索引位置  
				strSql1=strSql.Substring(0,IndexPos-1);///去掉最后位置的or 
			}
			else
			{
				IndexPos=strSql.LastIndexOf("and");////得到and的索引位置   
				strSql1=strSql.Substring(0,IndexPos-1);///去掉最后位置的and    
			}
			
			strSql2="SELECT * FROM material_info  WHERE  "+strSql1;
			Label3.Text=strSql2;
			Data.BindData(DataGrid1,strSql2,"material_info"); 
		}

		private void Img_clear_Click(object sender, System.Web.UI.ImageClickEventArgs e)
		{
			ListBox1.Items.Clear(); 
		}

		private void DataGrid1_EditCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
		{
			DataGrid1.EditItemIndex=(int)e.Item.ItemIndex;
            Data.BindData(DataGrid1,Label3.Text,"material_info");
		}

		private void DataGrid1_CancelCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
		{
			DataGrid1.EditItemIndex=-1;
            Data.BindData(DataGrid1,Label3.Text,"material_info");
		}

		private void DataGrid1_UpdateCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
		{
			int c_id=Int32.Parse(e.Item.Cells[1].Text);
			string m_year=((TextBox)e.Item.Cells[2].Controls[1]).Text;
    
			string m_month=((TextBox)e.Item.Cells[3].Controls[1]).Text;
			string m_provider=((TextBox)e.Item.Cells[4].Controls[1]).Text;
			string m_material=((TextBox)e.Item.Cells[5].Controls[1]).Text;
			int m_price=Int32.Parse(((TextBox)e.Item.Cells[6].Controls[1]).Text);
			int m_amount=Int32.Parse(((TextBox)e.Item.Cells[7].Controls[1]).Text);
            int m_money=Int32.Parse(((TextBox)e.Item.Cells[8].Controls[1]).Text);
			string m_unit=((TextBox)e.Item.Cells[9].Controls[1]).Text;
			string m_catagory=((TextBox)e.Item.Cells[10].Controls[1]).Text;
			string m_remark=((TextBox)e.Item.Cells[11].Controls[1]).Text;
			string strUpdate="UPDATE material_info  set  m_year='"+m_year+"',m_month='"+m_month+"',m_provider='"+m_provider+"',m_material='"+m_material+"',m_price="+m_price+",m_amount="+m_amount+",m_unit='"+m_unit+"',m_catagory='"+m_catagory+"',m_remark='"+"'   where  c_id="+c_id;
			Data.runNonSql(strUpdate);////执行更改命令
			//////下面重新绑丁到数据源/////
			DataGrid1.EditItemIndex=-1;
			Data.BindData(DataGrid1,Label3.Text,"material_info");
		}

		private void Img_delete_Click(object sender, System.Web.UI.ImageClickEventArgs e)
		{
			ArrayList isChecked=Data.GetChecked("chk",DataGrid1);
			string strSql;
			for (int i=0;i<isChecked.Count;i++)
			{
				strSql="delete from material_info where c_id="+isChecked[i].ToString();
				//Data.ShowMessage(strSql,Page);
				Data.runNonSql(strSql);
				
			}
			////重新绑定数据源////////
			Data.BindData(DataGrid1,"select *  from material_info","material_info");  
		}

	}////类结束
}///命名空间结束

⌨️ 快捷键说明

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