📄 module.aspx.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;
using System.Data.SqlClient ;
using ZHENGYI;
using OI.DatabaseOper ;
namespace OI.Manage
{
/// <summary>
/// module 的摘要说明。
/// 设计人:蒲丰
/// 日期2003.10.31
/// 功能说明:模块增加,修改,删除
/// </summary>
public class module : OI.PageBase
{
protected System.Web.UI.WebControls.DataGrid dg;
protected System.Web.UI.WebControls.TextBox Txt_model_name;
protected System.Web.UI.WebControls.TextBox Txt_path;
protected System.Web.UI.WebControls.DropDownList Dst_ifuse;
protected System.Web.UI.WebControls.TextBox Txt_Description;
protected System.Web.UI.WebControls.Label Lbl_Parentmodel;
string Parentid ;
protected System.Web.UI.WebControls.ImageButton Btn_save;
protected System.Web.UI.WebControls.ImageButton Btn_modify;
protected System.Web.UI.WebControls.ImageButton Btn_ifuse;
protected System.Web.UI.WebControls.ImageButton Btn_del;
protected System.Web.UI.WebControls.ImageButton Btn_add;
protected System.Web.UI.WebControls.ImageButton Btn_cancer;
protected DatabaseConnect Dbc=new DatabaseConnect ();
private void Page_Load(object sender, System.EventArgs e)
{
// if (Session["userid"]==null)
// {
// Response.Write ("<script>alert('超时,请重新登录!');top.location.href='../userpass.aspx';</script>");
// return ;
// }
Parentid=Request.QueryString ["Parentid"];
if (Parentid==null)
{
Parentid="0";
}
if (Page.IsPostBack)
{
}
else
{
DataTable dt=new DataTable ();
dt =CreateDataSource(Parentid);
Displaydg(dt);
if (Parentid != "0")
{
FindParentNmae(Parentid);
}
}
// if (Btn_save.Visible )
Btn_save.Attributes["onclick"]="return check()";
}
private void FindParentNmae(string parentid) //根据id 得到父模块名称
{
string strsql="select modulename ,ParentModuleID, ModuleID from models where ModuleID ='" +parentid +"'";
DataSet ds=new DataSet ();
ds=Dbc.getBinding(strsql,"S");
string href="<a href=\"module.aspx?parentid="+ds.Tables[0].Rows[0]["ParentModuleID"].ToString ()+"\">";
string name=ds.Tables[0].Rows[0]["modulename"].ToString ();
if (ds.Tables[0].Rows[0]["ParentModuleID"].ToString () !="0")
{
Lbl_Parentmodel.Text =" -->" +href+name+"</a> "+ Lbl_Parentmodel.Text ;
FindParentNmae( ds.Tables[0].Rows[0]["ParentModuleID"].ToString ());
}
else
{
Lbl_Parentmodel.Text =href+name+"</a> "+ Lbl_Parentmodel.Text ;
}
}
private DataTable CreateDataSource( string Parentid)
{
string strsql= " select moduleid,modulename, showmenu, case showmenu when 1 then '启用' else '<font color=red>禁用</font>' end as ifuse ";
strsql +=" ,menupath,parentmoduleid,description from models where parentmoduleid ='" +Parentid +"'order by ModuleID";
DataSet ds=new DataSet ();
ds=Dbc.getBinding (strsql,"s");
DataColumn col=new DataColumn ("modulenames",typeof(String));
col.Expression ="'<a href=\"module.aspx?Parentid='+moduleid+'\">'+modulename+'</a>'";
ds.Tables[0].Columns.Add (col);
return ds.Tables[0];
}
private void Displaydg(DataTable table)
{
dg.DataSource =table;
dg.DataBind ();
}
#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.dg.ItemCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.dg_ItemCommand);
this.Btn_add.Click += new System.Web.UI.ImageClickEventHandler(this.Btn_add_Click);
this.Btn_save.Click += new System.Web.UI.ImageClickEventHandler(this.Btn_save_Click);
this.Btn_modify.Click += new System.Web.UI.ImageClickEventHandler(this.Btn_modify_Click);
this.Btn_ifuse.Click += new System.Web.UI.ImageClickEventHandler(this.Btn_ifuse_Click);
this.Btn_del.Click += new System.Web.UI.ImageClickEventHandler(this.Btn_del_Click);
this.Btn_cancer.Click += new System.Web.UI.ImageClickEventHandler(this.Btn_cancer_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void Btn_save_Click(object sender, System.Web.UI.ImageClickEventArgs e)//保存数据
{
Btn_save.Visible =false;
Txt_Description.Text=Txt_Description.Text.Replace ("'","'");
if (ViewState["who"].ToString ()=="add") //保存新增
{
if (Txt_model_name.Text !="")
{
string sqlstr="insert into models values (newid(),"+Dst_ifuse.SelectedValue +",'"+ Txt_model_name.Text+"','" +Txt_path.Text +"','"+Parentid+"','"+Txt_Description.Text+"')";
try
{
Dbc.ExecuteSQL (sqlstr);
}
catch
{
return;
}
Response.Redirect ("module.aspx?Parentid="+Parentid);
}
}
if (ViewState["who"].ToString ()=="modify") //保存修改
{
try
{
string sqlstr="update models set modulename='"+Txt_model_name.Text +"',showmenu="+Dst_ifuse.SelectedValue +",menupath='" +Txt_path.Text +"',description='"+Txt_Description.Text+"' where moduleid='" +ViewState["moduleid"] +"'";
Dbc.ExecuteSQL (sqlstr);
Response.Redirect ("module.aspx?Parentid="+Parentid);
}
catch
{
}
}
}
private void Btn_modify_Click(object sender, System.Web.UI.ImageClickEventArgs e)//修改模块
{
ViewState["who"]="modify";
Btn_modify.Visible =false;
Btn_add.Visible =false;
Btn_save.Visible =true;
Btn_cancer.Visible =true;
if (ViewState["moduleid"]==null)
{
Page.RegisterStartupScript ("","<script>alert('请先选择你要操作的项!')</script>");
return ;
}
Btn_save.Visible =true; //置保存,取消为可用。
Btn_cancer.Visible =true;
DataTable dt=new DataTable() ;
string strsql="select * from models where moduleid='"+ViewState["moduleid"] +"'";
dt=GetDataTable(strsql);
if (dt.Rows.Count <1)
{
Page.RegisterStartupScript ("","<script>alert('数据错误,请重新生成此模块')</script>");
return ;
}
Txt_model_name.Text =dt.Rows[0]["modulename"].ToString ();
Txt_path.Text =dt.Rows [0]["menupath"].ToString ();
int ifuse ;
if (dt.Rows[0]["showmenu"].ToString() =="True")
{
ifuse=1;
}
else
{
ifuse=0;
}
Dst_ifuse.Items.FindByValue (Dst_ifuse.SelectedValue.ToString ()).Selected =false;
Dst_ifuse.Items.FindByValue(ifuse.ToString ()).Selected =true;
Txt_Description.Text =dt.Rows[0]["description"].ToString();
string javastr ="<script>mode_display.style.display=''</script>" ;
Page.RegisterStartupScript ("",javastr);
}
private void Btn_del_Click(object sender, System.Web.UI.ImageClickEventArgs e)
{
if (ViewState["moduleid"]==null)
{
Page.RegisterStartupScript ("","<script>alert('请先选择你要操作的项!')</script>");
return ;
}
Del_model(ViewState["moduleid"].ToString ());
Response.Redirect ("module.aspx?Parentid="+Parentid);
}
private void Btn_cancer_Click(object sender, System.Web.UI.ImageClickEventArgs e)
{
Clear();
Btn_save.Visible =false;
Btn_cancer.Visible =false;
Btn_add.Visible =true;
}
private void Btn_ifuse_Click(object sender, System.Web.UI.ImageClickEventArgs e)
{
if (ViewState["moduleid"]==null)
{
Page.RegisterStartupScript ("","<script>alert('请先选择你要操作的项!')</script>");
}
else
{
string Sqlstr;
if (Btn_ifuse.ImageUrl.ToString().Trim()=="../images/qy.gif")
{
Sqlstr="update models set showmenu =1 where moduleid='"+ViewState["moduleid"] +"'";
Dbc.ExecuteSQL (Sqlstr);
}
if (Btn_ifuse.ImageUrl.ToString().Trim()=="../images/jy.gif")
{
Sqlstr="update models set showmenu =0 where moduleid='"+ViewState["moduleid"] +"'";
Dbc.ExecuteSQL (Sqlstr);
}
Response.Redirect ("module.aspx?Parentid="+Parentid);
}
}
/// <summary>
/// 根据Sql返回一张数据表
/// </summary>
/// <param name="strsql"></param>
/// <returns></returns>
private DataTable GetDataTable(string strsql)
{
//SqlDataAdapter da=new SqlDataAdapter (strsql,Conn);
DataSet ds=new DataSet ();
//da.Fill (ds);
ds=Dbc.getBinding (strsql,"s");
return ds.Tables[0];
}
private void Clear() //元素清空
{
Txt_model_name.Text ="";
Txt_path.Text ="";
Txt_Description.Text ="";
Dst_ifuse.Items.FindByValue (Dst_ifuse.SelectedValue).Selected =false;
Dst_ifuse.Items.FindByValue ("1").Selected =true;
}
private void Dst_ifuse_SelectedIndexChanged(object sender, System.EventArgs e)
{
}
private void dg_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
if( e.Item.ItemType !=ListItemType.Header &&e.Item.ItemType !=ListItemType.Footer )
{
HyperLink Link_ifuser=(HyperLink)e.Item.FindControl ("Link_ifuser");
Response.Write (e.Item.Cells[1].Text );
}
}
/// <summary>
///选取中某一项时,只能作修改,禁用,起用两种功能.
/// </summary>
/// <param name="source"></param>
/// <param name="e"></param>
private void dg_ItemCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
if(e.CommandName =="select")
{
ViewState["moduleid"]=e.Item.Cells[0].Text ;
Btn_ifuse.Visible =true;
Btn_modify.Visible =true;
Btn_del.Visible =true;
foreach (DataGridItem item in dg.Items )
{
item.BackColor =Color.White ;
}
e.Item.BackColor=Color.Silver ;
if (e.Item.Cells [1].Text =="True")
{
Btn_ifuse.Attributes ["onclick"]="return confirm('你确定要禁用此模块吗?')";
Btn_ifuse.ImageUrl ="../images/jy.gif ";
}
else
{
Btn_ifuse.Attributes ["onclick"]="return true";
Btn_ifuse.ImageUrl =" ../images/qy.gif ";
}
}
}
private void Del_model(string CurrentModelID)
{
string strsql="select moduleid from models where parentmoduleid='"+CurrentModelID +"'";
DataSet ds=new DataSet ();
ds=Dbc.getBinding (strsql,"s");
for (int i=0;i< ds.Tables[0].Rows.Count ;i++) //(DataRow dr in ds.Tables [0])
{
Del_model(ds.Tables[0].Rows[i]["moduleid"].ToString ());
}
string Strsql ="delete from models where parentmoduleid='"+CurrentModelID +"' or moduleid='"+CurrentModelID+"'";
Dbc.ExecuteSQL (Strsql);
}
private void Btn_add_Click(object sender, System.Web.UI.ImageClickEventArgs e)//新增模块;
{
Btn_add.Visible =false;
Btn_save.Visible =true;
Btn_cancer.Visible =true;
ViewState["who"]="add";
Clear(); //保持数据的清洁
string javastr ="<script>mode_display.style.display=''</script>" ;
Page.RegisterStartupScript ("",javastr);
}
private void dg_ItemCommand_1(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -