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

📄 wf_select_order.aspx.cs

📁 某大型国企试用的网上订餐管理系统完整源代码
💻 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 WebApplication1

{
	/// <summary>
	/// WebForm1 的摘要说明。
	/// </summary>
	public class WF_select_Order : System.Web.UI.Page
	{
		protected System.Data.DataView dataView1;
		protected System.Data.DataSet dataSet1;
		protected System.Data.Odbc.OdbcCommand odbcSelectCommand1;
		protected System.Data.Odbc.OdbcCommand odbcInsertCommand1;
		protected System.Data.Odbc.OdbcCommand odbcUpdateCommand1;
		protected System.Data.Odbc.OdbcCommand odbcDeleteCommand1;
		protected System.Data.Odbc.OdbcDataAdapter odbcDataAdapter1;
		protected System.Data.Odbc.OdbcConnection odbcConnection1;
		protected System.Data.Odbc.OdbcCommand odbcCommand1;
		public static int pageCount;
		protected System.Web.UI.WebControls.Label Label4;
		protected System.Web.UI.WebControls.Label Label7; //总页面数 
		public static int curPageIndex=1;
		protected System.Web.UI.WebControls.Button btnQuery;
		protected System.Web.UI.WebControls.LinkButton lbtnPrev;
		protected System.Web.UI.WebControls.LinkButton lbtnNext;
		protected System.Web.UI.WebControls.TextBox txtStartDate;
		protected System.Web.UI.WebControls.TextBox txtEndDate;
		protected System.Data.DataSet dsUser;
		protected System.Web.UI.WebControls.Label Label2; //当前页面 

		private string strUser ;     
		private string strUserName;  
		private string strDept;
		private string strDeptName; 

		private  string strCurDate;
		private  string strCurTime;
		protected System.Web.UI.WebControls.TextBox TextBox1;
		protected System.Web.UI.WebControls.RangeValidator RangeValidator2;
		protected System.Web.UI.WebControls.Label Label5;
		protected System.Web.UI.WebControls.DataGrid DataGrid2;
		protected System.Web.UI.WebControls.DataGrid DGFind;
		protected System.Web.UI.WebControls.Label Label1;
		protected System.Web.UI.WebControls.RangeValidator RangeValidator1; 

		private void Page_Load(object sender, System.EventArgs e)
		{
			strUser =(string)Session["strUser"];          
			strUserName = (string)Session["strUserName"];  
			strDept = (string)Session["strDept"];          
			strDeptName = (string)Session["strDeptName"];  

			if (!Page.IsPostBack)
			{
				strCurDate = DateTime.Now.ToString("yyyy'-'MM'-'dd");
				strCurTime = DateTime.Now.ToString("HH':'mm");

				txtStartDate.Text=strCurDate;
				txtEndDate.Text=strCurDate;

				if (!Global.CheckUserValidation((string)Session["strRole"], Global.MENU_ORDERHISTORY))
				{
					//Response.Redirect("err_session.htm", true);
				}
				Findselectdata();
			}
		}

		#region Web 窗体设计器生成的代码
		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
			//
			InitializeComponent();
			base.OnInit(e);
		}
		
		/// <summary>
		/// 设计器支持所需的方法 - 不要使用代码编辑器修改
		/// 此方法的内容。
		/// </summary>
		private void InitializeComponent()
		{    
			this.dataView1 = new System.Data.DataView();
			this.odbcSelectCommand1 = new System.Data.Odbc.OdbcCommand();
			this.odbcInsertCommand1 = new System.Data.Odbc.OdbcCommand();
			this.odbcUpdateCommand1 = new System.Data.Odbc.OdbcCommand();
			this.odbcDeleteCommand1 = new System.Data.Odbc.OdbcCommand();
			this.odbcDataAdapter1 = new System.Data.Odbc.OdbcDataAdapter();
			this.odbcConnection1 = new System.Data.Odbc.OdbcConnection();
			this.odbcCommand1 = new System.Data.Odbc.OdbcCommand();
			((System.ComponentModel.ISupportInitialize)(this.dataView1)).BeginInit();
			this.btnQuery.Click += new System.EventHandler(this.btnQuery_Click);
			this.lbtnPrev.Click += new System.EventHandler(this.lbtnPrev_Click);
			this.lbtnNext.Click += new System.EventHandler(this.lbtnNext_Click);
			this.DGFind.PageIndexChanged += new System.Web.UI.WebControls.DataGridPageChangedEventHandler(this.DataGrid1_PageIndexChanged);
			this.DGFind.SelectedIndexChanged += new System.EventHandler(this.DGFind_SelectedIndexChanged);
			this.DataGrid2.SelectedIndexChanged += new System.EventHandler(this.DataGrid2_SelectedIndexChanged);
			// 
			// odbcDataAdapter1
			// 
			this.odbcDataAdapter1.DeleteCommand = this.odbcDeleteCommand1;
			this.odbcDataAdapter1.InsertCommand = this.odbcInsertCommand1;
			this.odbcDataAdapter1.SelectCommand = this.odbcSelectCommand1;
			this.odbcDataAdapter1.UpdateCommand = this.odbcUpdateCommand1;
			this.Load += new System.EventHandler(this.Page_Load);
			((System.ComponentModel.ISupportInitialize)(this.dataView1)).EndInit();

		}
		#endregion

		private void connectionDB()
		{
			Global.OpenConnection(ref odbcConnection1);
		}		
		

		private void closeDB()
		{
			odbcConnection1.Close();	
		}	

		private void btnQuery_Click(object sender, System.EventArgs e)
		{	
			if ((!RangeValidator2.IsValid)||(txtStartDate.Text==""))
			{
				Page.RegisterStartupScript("alert", @"<script language=""javascript"">window.alert(""错误:起始日期格式不对!"")</script>");
				return;
			}
			else

			{
				if ((!RangeValidator1.IsValid)||(txtEndDate.Text==""))
				{
					Page.RegisterStartupScript("alert", @"<script language=""javascript"">window.alert(""错误:结束日期格式不对!"")</script>");
					return;
				}
				else
				{

					Findselectdata();
					DGFind.CurrentPageIndex=0;
					DGFind.HeaderStyle.Height=30;
				}
			}
		}

		private void Findselectdata()
		{
			string wherestr="",selectstr="";

			if (txtStartDate.Text!="")
			{	
				wherestr=" Date >= '"+txtStartDate.Text+" 00:00:00"+"' and ";
			}
			if (txtEndDate.Text!="")
			{
				wherestr+="Date <= '"+txtEndDate.Text+" 59:59:59"+"' and ";
			}
	   	wherestr+= "user_id='"+strUser+"'";

			connectionDB();
         dataSet1 =new DataSet();

			selectstr = "select Order_id ,Date ,Kind ,Send_dest,"+
				"Name ,Department_id ,Department,TRUNCATE(Totel_price/100.0,2) as Totel_price,Free ,Memo ,User_id  from T_order  where "+
				 wherestr +" order by Order_id  desc";		
			odbcDataAdapter1 =new System.Data.Odbc.OdbcDataAdapter (selectstr,odbcConnection1 ) ;
			odbcDataAdapter1.Fill ( dataSet1 , "T_order" ) ;
			DataView dataView1 = dataSet1.Tables [ "T_order" ].DefaultView ;
			DGFind.DataSource = dataView1 ;
			DGFind.DataBind();
			closeDB();	
			PageIndexNbr();
			DGFind.HeaderStyle.Height=30;
			if (DGFind.Items.Count>0)
			{
			DGFind.SelectedIndex =0;
			DataGrid2_Select();
			}

		}
		private void DataGrid1_PageIndexChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
		{
             DGFind.CurrentPageIndex=e.NewPageIndex;
             Findselectdata();
		         PageIndexNbr();

		}


		private void PageIndexNbr()
		{
			Label7.Text = "第 " + (DGFind.CurrentPageIndex + 1).ToString() + " 页/共 " + DGFind.PageCount.ToString() + " 页"; 

		}

		private void lbtnNext_Click(object sender, System.EventArgs e)
		{
			if(DGFind.CurrentPageIndex< (DGFind.PageCount - 1)) 
			{ 
 				DGFind.CurrentPageIndex += 1; 
 				curPageIndex +=1; 
			} 
			Findselectdata();
			PageIndexNbr();
			odbcConnection1.Close();
		}

		private void lbtnPrev_Click(object sender, System.EventArgs e)
		{
			if(DGFind.CurrentPageIndex >0) 
			{ 
 				DGFind.CurrentPageIndex -= 1; 
 				curPageIndex -=1; 
			} 
			Findselectdata();
			PageIndexNbr();
			odbcConnection1.Close();
		}

		private void DGFind_SelectedIndexChanged(object sender, System.EventArgs e)
		{
     
			DataGrid2_Select();
		
		}
		private void DataGrid2_Select()
		{
			string str_order_id="";
			string selectstr="";
			str_order_id = DGFind.SelectedItem.Cells[1].Text ;

			connectionDB();
			dataSet1 =new DataSet();

			selectstr ="select a.Order_id , a.food_id ,b.Style ,b.name , a.Quantity "+
				"from t_order_detail a,t_total_menu b   where a.food_id = b.food_id  and a.Order_id= '"+str_order_id +"' order by a.food_id  desc";
			//TextBox2.Text = selectstr;
			
			///*
			odbcDataAdapter1 =new System.Data.Odbc.OdbcDataAdapter (selectstr,odbcConnection1 ) ;
			odbcDataAdapter1.Fill ( dataSet1 , "t_order_detail" ) ;
			DataView dataView1 = dataSet1.Tables [ "t_order_detail" ].DefaultView ;
			DataGrid2.DataSource = dataView1 ;
			
			DataGrid2.DataBind();
			///*/
			closeDB();	
		}


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

	}
}

⌨️ 快捷键说明

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