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

📄 wf_dest.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>
	/// WFapp 的摘要说明。
	/// </summary>
	public class WF_DEST : System.Web.UI.Page
	{
		protected System.Data.DataView dataView1;
		protected System.Data.Odbc.OdbcConnection odbcConnection1;
		protected System.Data.Odbc.OdbcCommand odbcSelectCommand1;
		internal 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.DataSet dataSet1;
		protected System.Data.Odbc.OdbcCommand odbcCommand1;
		private string Insertstr;
		protected System.Web.UI.WebControls.Label lblMessage;
		protected System.Web.UI.WebControls.TextBox txtPageSize;
		protected System.Web.UI.WebControls.Label lblCurrentPage;
		protected System.Web.UI.WebControls.DataGrid DataGrid1;
		protected System.Web.UI.WebControls.TextBox txtNum;
		protected System.Web.UI.WebControls.DropDownList ddlDest;
		protected System.Web.UI.WebControls.DropDownList ddlEffect;
		protected System.Web.UI.WebControls.TextBox TextBox1;
		protected System.Web.UI.WebControls.RangeValidator valNum;
		protected System.Web.UI.WebControls.TextBox txtDestID;
		protected System.Web.UI.WebControls.RequiredFieldValidator valDestID;
		protected System.Web.UI.WebControls.TextBox txtDestName;
		protected System.Web.UI.WebControls.Button btnAdd;
		protected System.Web.UI.WebControls.Button btnModify;
		protected System.Web.UI.WebControls.Button btnDelete;
		protected System.Web.UI.WebControls.Button btnCancel;
		protected System.Web.UI.WebControls.Label Label2;
		protected System.Web.UI.WebControls.Label Label3;
		protected System.Web.UI.WebControls.Label Label4;
		private string selectstr;


		private void Page_Load(object sender, System.EventArgs e)
		{
			// 在此处放置用户代码以初始化页面
			if (!IsPostBack)
			{
				if (!Global.CheckUserValidation((string)Session["strRole"], Global.MENU_DEST))
				{
					Response.Redirect("err_session.htm", true);
				}

				DataGrid1.CurrentPageIndex=0;
				DataGrid1.PageSize = Convert.ToInt32 (txtPageSize.Text );
				select();
			}
		}

		#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.odbcConnection1 = new System.Data.Odbc.OdbcConnection();
			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.odbcCommand1 = new System.Data.Odbc.OdbcCommand();
			((System.ComponentModel.ISupportInitialize)(this.dataView1)).BeginInit();
			this.DataGrid1.PageIndexChanged += new System.Web.UI.WebControls.DataGridPageChangedEventHandler(this.DataGrid1_PageIndexChanged_1);
			this.DataGrid1.SelectedIndexChanged += new System.EventHandler(this.DataGrid1_SelectedIndexChanged);
			this.btnCancel.Click += new System.EventHandler(this.btnCancel_Click);
			this.btnDelete.Click += new System.EventHandler(this.btnDelete_Click);
			this.btnModify.Click += new System.EventHandler(this.btnModify_Click);
			this.btnAdd.Click += new System.EventHandler(this.btnAdd_Click);
			// 
			// 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 select()
		{
			//connectionDB();
			DataGrid1.CurrentPageIndex=0;
			DataGrid1.PageSize = Convert.ToInt32 (txtPageSize.Text );
         selectdata();
			PageIndexNbr();
		}
		private void selectdata()
		{
			connectionDB();
			selectstr="select dest_id as '地点ID', `desc` as '地点名称' from  T_dest";
			odbcDataAdapter1 =new System.Data.Odbc.OdbcDataAdapter (selectstr ,odbcConnection1 ) ;
			dataSet1 =new DataSet() ;
			odbcDataAdapter1.Fill ( dataSet1 , "T_DEST" ) ;
			DataView dataView1 = dataSet1.Tables [ "T_DEST" ].DefaultView ;
			DataGrid1.DataSource = dataView1 ;
			DataGrid1.HeaderStyle.Height=30;//  .CellPadding=5;//  CellPaddin
			DataGrid1.DataBind() ;
		}

		private void PageIndexNbr()
		{
			lblCurrentPage.Text = "第 " + (DataGrid1.CurrentPageIndex + 1).ToString() + " 页/"; 
			lblCurrentPage.Text += "共 " + DataGrid1.PageCount.ToString() + " 页"; 
		}
		private void DataGrid1_PageIndexChanged_1(object source, System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
		{
			 DataGrid1.CurrentPageIndex=e.NewPageIndex;
           //Button1_Click(source,e);

		 	 selectdata();
			 PageIndexNbr();
		}

		private void btnAdd_Click(object sender, System.EventArgs e)
		{
			lblMessage.Text = "";
			if (!valDestID.IsValid )
			{
				lblMessage.Text = "错误:地点ID不能为空!";
				Page.RegisterStartupScript("alert", @"<script language=""javascript"">window.alert(""错误:地点ID不能为空!"")</script>");
				return;
			}
			
			string str1 = "'" + txtDestID.Text  + "'";
		   str1 += ",'" + txtDestName.Text +"'";
    	   Insertstr="INSERT INTO T_dest(`dest_id` ,`desc`) VALUES ( " + str1 + ")";

			connectionDB();
			odbcInsertCommand1 = new System.Data.Odbc.OdbcCommand(Insertstr,odbcConnection1);
			int i = odbcInsertCommand1.ExecuteNonQuery ();
			closeDB();
			if (i != 1)
			{
				lblMessage.Text = "写入数据库出错!请检查。";
				Page.RegisterStartupScript("alert", @"<script language=""javascript"">window.alert(""写入数据库出错!请检查。"")</script>");
			}
			else
			{
				Global.WriteLog(ref odbcConnection1, (string)Session["strUser"], Global.MENU_DEST, Global.ACTION_ADD, Insertstr);
				DataGrid1.SelectedIndex = -1;
				select();
			}
		}

		private void btnCancel_Click(object sender, System.EventArgs e)
		{
			txtDestID.Text="";
			txtDestName.Text="";
			lblMessage.Text = "";
			Insertstr="";
			DataGrid1.SelectedIndex = -1;
			select();
		}

		//Modify
		private void btnModify_Click(object sender, System.EventArgs e)
		{
			string strUpdate;
			int iUpdateRowCount;

			lblMessage.Text = "";
			if (!valDestID.IsValid )
			{
				lblMessage.Text = "错误:地点ID不能为空!";
				Page.RegisterStartupScript("alert", @"<script language=""javascript"">window.alert(""错误:地点ID不能为空!"")</script>");
				return;
			}

			if (DataGrid1.SelectedIndex < 0) //unselected
			{
				lblMessage.Text = "未选择记录!请先选择一条记录,然后才能对其进行修改。";
				Page.RegisterStartupScript("alert", @"<script language=""javascript"">window.alert(""未选择记录!请先选择一条记录,然后才能对其进行修改。"")</script>");
				return;
			}
			else
			{
				strUpdate = "UPDATE T_dest set " +
					"dest_id = '" + txtDestID.Text + "'," +
					"`desc` = '" + txtDestName.Text + "' " +
					"where dest_id = '";

				strUpdate += DataGrid1.SelectedItem .Cells [1].Text + "'";
			}

			//lblMessage.Text = strUpdate;
			//return;

			connectionDB();
			System.Data.Odbc.OdbcCommand cmdUpdate = new System.Data.Odbc.OdbcCommand (strUpdate, odbcConnection1);
			iUpdateRowCount = cmdUpdate.ExecuteNonQuery ();
			if (iUpdateRowCount != 1)
			{
				lblMessage.Text = "错误!写入数据库出错,请检查。";
				Page.RegisterStartupScript("alert", @"<script language=""javascript"">window.alert(""错误!写入数据库出错,请检查。"")</script>");
			}
			else
			{
				Global.WriteLog(ref odbcConnection1, (string)Session["strUser"], Global.MENU_DEST, Global.ACTION_UPDATE, strUpdate);
				DataGrid1.SelectedIndex = -1;
				select();
			}
		}

		private void DataGrid1_SelectedIndexChanged(object sender, System.EventArgs e)
		{
			txtDestID.Text = DataGrid1.SelectedItem .Cells [1].Text ;  //dest_id
			txtDestName.Text = DataGrid1.SelectedItem .Cells [2].Text ;  //desc
		}

		private void btnDelete_Click(object sender, System.EventArgs e)
		{
			string strUpdate;
			int iUpdateRowCount;

			lblMessage.Text = "";

			if (DataGrid1.SelectedIndex < 0) //unselected
			{
				lblMessage.Text = "未选择记录!请先选择一条记录,然后才能进行删除。";
				Page.RegisterStartupScript("alert", @"<script language=""javascript"">window.alert(""未选择记录!请先选择一条记录,然后才能进行删除。"")</script>");
				return;
			}
			else
			{
				strUpdate = "delete from T_dest " +
					"where dest_id = '";

				strUpdate += DataGrid1.SelectedItem .Cells [1].Text + "'";
			}

			connectionDB();
			System.Data.Odbc.OdbcCommand cmdUpdate = new System.Data.Odbc.OdbcCommand (strUpdate, odbcConnection1);
			iUpdateRowCount = cmdUpdate.ExecuteNonQuery ();
			if (iUpdateRowCount != 1)
			{
				lblMessage.Text = "错误!删除记录时出错,请检查。";
				Page.RegisterStartupScript("alert", @"<script language=""javascript"">window.alert(""错误!删除记录时出错,请检查。"")</script>");
			}
			else
			{
				Global.WriteLog(ref odbcConnection1, (string)Session["strUser"], Global.MENU_DEST, Global.ACTION_DELETE, strUpdate);
				DataGrid1.SelectedIndex = -1;
				select();
			}
		}
	}
}

⌨️ 快捷键说明

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