formbase.aspx.cs
来自「ASP.NET的一些开发实例,有论坛管理系统等」· CS 代码 · 共 639 行 · 第 1/2 页
CS
639 行
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;
using System.Xml;
using System.IO;
namespace BDStudioBase
{
/// <summary>
/// FormBase 的摘要说明。
/// </summary>
public class FormBase : System.Web.UI.Page
{
protected string o_str_FormName="";//窗体名称
protected string o_str_FormUrl="";//窗体链接
protected string o_str_FormStatusData="";//窗体当前状态值
protected string o_str_FormValue="";//从状态数据集中取出当前窗口状态值
protected string o_str_TableName1="";//窗体数据表1
protected string o_str_TableName2="";//窗体数据表2
protected string o_str_TableName3="";//窗体数据表3
protected string o_str_InputFile1="";//增加窗口1
protected string o_str_InputFile2="";//增加窗口2
protected string o_str_InputFile3="";//增加窗口3
protected string o_str_ModifyFile1="";//修改窗口1
protected string o_str_ModifyFile2="";//修改窗口2
protected string o_str_ModifyFile3="";//修改窗口3
protected string o_str_DisplayFile1="";//显示窗口1
protected string o_str_DisplayFile2="";//显示窗口2
protected string o_str_DisplayFile3="";//显示窗口3
protected string o_str_Pk1="";//窗体数据表1主键名称
protected string o_str_Pk2="";//窗体数据表2主键名称
protected string o_str_Pk3="";//窗体数据表3主键名称
protected int o_int_ColumnCount1=0;//窗体的dbGrid_Main1固定列数
protected int o_int_ColumnCount2=0;//窗体的dbGrid_Main2固定列数
protected int o_int_ColumnCount3=0;//窗体的dbGrid_Main3固定列数
protected DataSet o_ds_FormData;//窗体表格数据集
protected int o_int_PageNum=0;
protected int item_cou=0;//数据表列数
protected COMInterface COMInterface=new COMInterface();
protected Gfunction COMGfunction=new Gfunction();
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
if(Session["userid"]==null)
{
// Session["userid"]="WWW";
Response.Redirect("/WhiteForum/error.aspx");
}
else
{
if(!verifyUser())
{
Response.Redirect("/WhiteForum/error.aspx");
}
}
CommonButtonInit();
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN:该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
//检测用户权限
protected bool verifyUser()
{
bool isok = false;
//当前用户编号。
string userid = (string)Session["userid"];
//管理员特权
if (userid!=null)
{
if (userid.Equals("004"))
{
return true;
}
}
//获取当前页面虚拟路径。
string thispageUrl = Page.Request.Url.ToString();
int i_index=thispageUrl.IndexOf("/WhiteForum/");
thispageUrl = thispageUrl.Substring(i_index+12);
string SysRole="";
//从访问表中查询当前用户和页面。
string SqlString="select * from system_module where m_type='3' and m_name='Enter' and m_up=(select m_num from system_module where m_url='"+thispageUrl+"')";
DataSet ds=this.COMInterface.CreateDataSetFromSql(SqlString);
foreach(DataRow row in ds.Tables[0].Rows)
{
SysRole=row["enable_role"].ToString();
}
if(SysRole!=""&&SysRole!=null)
{
DataSet dsUserRole=(DataSet)Session["DsUserRole"];
foreach(DataRow row1 in dsUserRole.Tables[0].Rows)
{
// Response.Write("'R0011','R0012'".IndexOf("'R0012'")+",");
if(SysRole.IndexOf(row1["role_num"].ToString())>-1)
{
isok=true;
break;
}
}
}
else
{
isok=true;
}
return isok;
}
/*读取数据集*/
protected void DataRead(DataSet ds,string sSessionName)
{
DataTable dt=ds.Tables[0];
DataView dv=new DataView(dt);
Session[sSessionName]=null;
Session[sSessionName]=dv;;
}
/*DataGrid数据填充*/
protected void DbGridInit(DataGrid dg,DataSet ds,int DataGridColumnCou,string DataKey,ref DataView datadv)
{
if(dg.Columns.Count==DataGridColumnCou)
{
DataTable dt=new DataTable();
dt=ds.Tables[0];
BoundColumn NumberColumn;
int i=1;
foreach(DataRow row in dt.Rows)
{
NumberColumn = new BoundColumn();
NumberColumn.HeaderText=row["t_title"].ToString();
NumberColumn.DataField=row["t_name"].ToString();
NumberColumn.SortExpression=row["t_name"].ToString();
NumberColumn.HeaderStyle.ForeColor=Color.Black;
dg.Columns.AddAt(i,NumberColumn);
if(row["t_visible"].ToString()=="2")
{
dg.Columns[i].Visible=false;
}
i=i+1;
}
item_cou=i-1;
}
dg.DataKeyField=DataKey;
dg.AllowSorting=true;
int row_count=datadv.Count;
int page_count;
if (row_count%dg.PageSize>0)
{
page_count=row_count/dg.PageSize+1;
}
else
{
page_count=row_count/dg.PageSize;
}
if(this.o_int_PageNum>page_count)
{
this.o_int_PageNum=page_count;
}
dg.DataSource=datadv;
dg.CurrentPageIndex=this.o_int_PageNum;
dg.DataBind();
}
/*DataGrid数据排序*/
protected void DbGridSort(DataGrid dg,System.Web.UI.WebControls.DataGridSortCommandEventArgs e,ref DataView dvData)
{
if(Session["i_sort"]==null)
{
Session["i_sort"]="0";
}
if((string)Session["i_sort"]=="0")
{
Session["i_sort"]="1";
dvData.Sort=e.SortExpression+" desc";
}
else
{
Session["i_sort"]="0";
dvData.Sort=e.SortExpression;
}
dg.DataSource=dvData;
dg.DataBind();
}
protected void PageLabelShow(ref Label l_lab_Page,int l_int_CurrentPage,int l_int_PageCount)
{
l_lab_Page.Text="第"+l_int_CurrentPage.ToString()+"页/共"+l_int_PageCount.ToString()+"页";
}
//初始化参数传递
protected void Param_Open(string param_win_name)
{
Session["mess_window"]=param_win_name;
Session["mess_on"]=1;
Session["mess_string"]="<xmldata></xmldata>";
}
//关闭参数传递
protected void Param_Close()
{
Session["mess_window"]="";
Session["mess_on"]=0;
Session["mess_string"]="";
}
//判断是否要接收参数
protected int Param_check(string param_win_name)
{
int s_return=0;
string str1 = Session["mess_window"].ToString();
string str2 = param_win_name;
int i = (int)(Session["mess_on"]);
if (Session["mess_window"].ToString()==param_win_name && (int)(Session["mess_on"])==1)
{
s_return=1;
}
return s_return;
}
//设置窗体传递参数
protected void Param_set(string param_name,string param_value)
{
string XmlData=Session["mess_string"].ToString();
if(param_value==" ")
{
param_value="";
}
XmlData=XmlData.Replace("</xmldata>","<"+param_name+">"+param_value+"</"+param_name+"></xmldata>");
Session["mess_string"]=XmlData;
}
//检索窗体传递参数
protected string Param_get(string param_name)
{
string s_value="";
string XmlData=Session["mess_string"].ToString();
XmlTextReader r = new XmlTextReader(new StringReader(XmlData));
DataSet ds=new DataSet();
ds.ReadXml(r);
foreach(DataRow row in ds.Tables[0].Rows)
{
s_value=row[param_name].ToString();
}
return s_value;
}
protected void ReturnToParent(string sWindowName)
{
string sParentWindowName=this.GetParentWindowValueFromUserLog(sWindowName);
if(sParentWindowName!="W")
{
Response.Redirect(sParentWindowName);
}
}
//建立用户日志数据集
protected void CreatUserLog()
{
DataTable dt=new DataTable();
dt.Columns.Add(new DataColumn("inc_num",typeof(int)));
dt.Columns.Add(new DataColumn("user_num",typeof(string)));
dt.Columns.Add(new DataColumn("window_status",typeof(string)));
dt.Columns.Add(new DataColumn("window_name",typeof(string)));
dt.Columns.Add(new DataColumn("window_value",typeof(string)));
dt.Columns.Add(new DataColumn("window_parent",typeof(string)));
DataSet ds=new DataSet();
ds.Tables.Add(dt);
Application["user_log"]=ds;
}
//插入用户日志表
protected void InsertUserLog(string[] sLogData)
{
if(Application["user_log"]==null)
{
CreatUserLog();
}
DataSet ds=(DataSet)Application["user_log"];
int inc_num=ds.Tables[0].Rows.Count+1;
DataTable dt=ds.Tables[0];
DataRow dr=dt.NewRow();
dr["inc_num"]=inc_num;
dr["user_num"]=sLogData[0];
dr["window_status"]=sLogData[1];
dr["window_name"]=sLogData[2];
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?