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

📄 wf_sys_para.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_SYS_PARA : 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;
		protected System.Web.UI.WebControls.Label lblMessage;
		protected System.Web.UI.WebControls.DataGrid DataGrid1;
		protected System.Web.UI.WebControls.TextBox txtPageSize;
		protected System.Web.UI.WebControls.Label lblCurrentPage;
		protected System.Web.UI.WebControls.Button btnRefresh;
		protected System.Web.UI.WebControls.Label Label1;
		protected System.Web.UI.WebControls.Label Label2;

		private string selectstr;

		private void Page_Load(object sender, System.EventArgs e)
		{
			// 在此处放置用户代码以初始化页面
			dataSet1 =new DataSet() ;
			if (!IsPostBack)
			{
				if (!Global.CheckUserValidation((string)Session["strRole"], Global.MENU_PARA))
				{
					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.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.DataGrid1.SelectedIndexChanged += new System.EventHandler(this.DataGrid1_SelectedIndexChanged);
			this.btnRefresh.Click += new System.EventHandler(this.btnRefresh_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 para_id, `desc`, `value` from  T_sys_para order by disporder";
			odbcDataAdapter1 =new System.Data.Odbc.OdbcDataAdapter (selectstr ,odbcConnection1 ) ;
			odbcDataAdapter1.Fill ( dataSet1 , "T_SYS_PARA" ) ;
			DataView dataView1 = dataSet1.Tables [ "T_SYS_PARA" ].DefaultView ;
			DataGrid1.DataSource = dataView1 ;
			DataGrid1.HeaderStyle.Height=30;
			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;
		 	 selectdata();
			 PageIndexNbr();
		}


		private void btnRefresh_Click(object sender, System.EventArgs e)
		{
			lblMessage.Text = "";
			select();
		}

		private void DataGrid1_EditCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
		{
			lblMessage.Text = "";
			DataGrid1.EditItemIndex = e.Item.ItemIndex;
			select();
		}

		private void DataGrid1_UpdateCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
		{
			string strParaID = e.Item.Cells[1].Text ;
			TextBox txtValue = (TextBox)e.Item.Cells[3].Controls[1];
			string strValue = txtValue.Text ;
			strValue.Replace ("'", "");
			strValue.Replace ("\"", "");
			strValue.Replace ("--", "");

			string strUpdate;
			strUpdate = "UPDATE t_sys_para set " + 
							"`value` = '" + strValue + "' " +
							"where para_id = '" + strParaID + "'";

			connectionDB();
			odbcCommand1 = new System.Data.Odbc.OdbcCommand (strUpdate, odbcConnection1);
			int i = odbcCommand1.ExecuteNonQuery ();
			if (i != 1)
			{
				lblMessage.Text = "更新数据库时出现错误!请检查。";
			}
			Global.WriteLog(ref odbcConnection1, (string)Session["strUser"], Global.MENU_PARA, Global.ACTION_UPDATE, strUpdate);
			//exit edit mode
			DataGrid1.EditItemIndex = -1;
			select();
		}

		private void DataGrid1_CancelCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
		{
			DataGrid1.EditItemIndex = -1;
			select();
		}

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

	}
}

⌨️ 快捷键说明

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