using System; using System.Collections; using System.Configuration; using System.Data; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.HtmlControls; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Data.SqlClient; using DSWeb.Models; using DSWeb.EntityDA; namespace DSWeb.Modules { public partial class Edit : System.Web.UI.Page { private string strModuleGID; private string strHandle; private string strUserID; protected void Page_Load(object sender, EventArgs e) { if(Session["USERID"] != null) { strUserID = Session["USERID"].ToString(); } if (Request.QueryString["handle"] != null) { strHandle = Request.QueryString["handle"].ToString(); this.h_handle.Value = strHandle; } if (Request.QueryString["id"] != null) { strModuleGID = Request.QueryString["id"].ToString(); this.h_moduleid.Value = strModuleGID; } if (strHandle == "edit") { if (h_posttype.Value.Trim().Equals("1")) { SaveModule(); } else { GetModuleInfo(strModuleGID); } } if (strHandle == "add") { if (h_posttype.Value.Trim().Equals("1")) { SaveModule(); } } } #region 保存模块信息 /// /// 保存模块信息 /// private void SaveModule() { int iResult = 0; ModuleDA moduleDA = new ModuleDA(); ModuleEntity moduleEntity = new ModuleEntity(); ActionEntity actionEntity = new ActionEntity(); if (this.h_handle.Value.Trim().ToLower().Equals("add")) { moduleEntity.Gid = Guid.NewGuid().ToString(); moduleEntity.ModuleName = this.txt_sysname.Value.Trim(); moduleEntity.ModuleDescription = this.txt_description.Value.Trim(); moduleEntity.ModuleUrl = this.txt_url.Value.Trim(); moduleEntity.ModuleIcon = this.txt_imgurl.Value.Trim(); //moduleEntity.ParentID = ""; moduleEntity.ModuleSort = this.txt_sort.Value.Trim().Equals("") ? 0 : int.Parse(this.txt_sort.Value.Trim()); moduleEntity.ModuleType = int.Parse(this.sel_type.Items[sel_type.SelectedIndex].Value); moduleEntity.ModuleState = this.ck_state.Checked ? 1 : 0; moduleEntity.ShowRootState = 0; moduleEntity.CreateUser = strUserID; moduleEntity.ParentID = this.h_parentid.Value.Trim().Equals("") ? "" : this.h_parentid.Value.Trim(); actionEntity.GID = Guid.NewGuid().ToString(); actionEntity.ActionName = this.txt_sysname.Value.Trim(); actionEntity.Description = this.txt_description.Value.Trim(); actionEntity.ModuleID = moduleEntity.Gid; actionEntity.CreateUserID = strUserID; iResult = moduleDA.InsertModule(moduleEntity, actionEntity); } else { moduleEntity = moduleDA.GetModuleByID(strModuleGID); if (moduleEntity.Gid != null) { //如果存在记录,则更新模块信息 moduleEntity.ModuleName = this.txt_sysname.Value.Trim(); moduleEntity.ModuleDescription = this.txt_description.Value.Trim(); moduleEntity.ModuleUrl = this.txt_url.Value.Trim(); moduleEntity.ModuleIcon = this.txt_imgurl.Value.Trim(); moduleEntity.ParentID = this.h_parentid.Value.Trim().Equals("") ? "" : this.h_parentid.Value.Trim(); moduleEntity.ModuleSort = this.txt_sort.Value.Trim().Equals("") ? 0 : int.Parse(this.txt_sort.Value.Trim()); moduleEntity.ModuleType = int.Parse(this.sel_type.Items[sel_type.SelectedIndex].Value); moduleEntity.ModuleState = this.ck_state.Checked ? 1 : 0; moduleEntity.ShowRootState = 0; moduleEntity.ModifiedUser = strUserID; iResult = moduleDA.UpdateModule(moduleEntity); } else { //如果不存在记录,则添加模块信息 moduleEntity.Gid = Guid.NewGuid().ToString(); moduleEntity.ModuleName = this.txt_sysname.Value.Trim(); moduleEntity.ModuleDescription = this.txt_description.Value.Trim(); moduleEntity.ModuleUrl = this.txt_url.Value.Trim(); moduleEntity.ModuleIcon = this.txt_imgurl.Value.Trim(); moduleEntity.ParentID = this.h_parentid.Value.Trim().Equals("") ? "" : this.h_parentid.Value.Trim(); moduleEntity.ModuleSort = this.txt_sort.Value.Trim().Equals("") ? 0 : int.Parse(this.txt_sort.Value.Trim()); moduleEntity.ModuleType = int.Parse(this.sel_type.Items[sel_type.SelectedIndex].Value); moduleEntity.ModuleState = this.ck_state.Checked ? 1 : 0; moduleEntity.ShowRootState = 0; moduleEntity.CreateUser = strUserID; actionEntity.GID = Guid.NewGuid().ToString(); actionEntity.ActionName = this.txt_sysname.Value.Trim(); actionEntity.Description = this.txt_description.Value.Trim(); actionEntity.ModuleID = moduleEntity.Gid; actionEntity.CreateUserID = strUserID; iResult = moduleDA.InsertModule(moduleEntity, actionEntity); } } this.h_poststate.Value = iResult.ToString(); } #endregion #region 获取模块信息 /// /// 获取模块信息 /// /// 模块GID private void GetModuleInfo(string tempModuleGID) { ModuleDA moduleDA = new ModuleDA(); ModuleEntity moduleEntity = new ModuleEntity(); ModuleEntity parentEntity = new ModuleEntity(); moduleEntity = moduleDA.GetModuleByID(tempModuleGID); if (moduleEntity.Gid != null) { this.txt_sysname.Value = moduleEntity.ModuleName; this.txt_description.Value = moduleEntity.ModuleDescription; this.txt_url.Value = moduleEntity.ModuleUrl; this.txt_imgurl.Value = moduleEntity.ModuleIcon; if(!moduleEntity.ParentID.Trim().Equals("")) { parentEntity = moduleDA.GetModuleByID(moduleEntity.ParentID); if (parentEntity.Gid != null) { this.txt_parent.Value = parentEntity.ModuleDescription; } this.h_parentid.Value = moduleEntity.ParentID; } this.txt_sort.Value = moduleEntity.ModuleSort.ToString(); this.ck_state.Checked = moduleEntity.ModuleState == 0 ? true : false; this.sel_type.Value = moduleEntity.ModuleType.ToString(); } } #endregion } }