protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { int parentID = 0; int selected = 0; if (string.IsNullOrEmpty(QS("selected")) || string.IsNullOrEmpty(QS("parent")) || QS("selected", 0) == 0 || QS("parent", 0) == 0) { this.ShowArgumentErrorMessageToClient(); return; } else { parentID = QS("parent", 0); selected = QS("selected", 0); ModulesEntity parent = userApp.GetModule(parentID); parentID = parent.ParentID; } ModulesEntity model = userApp.GetModule(selected); List <ModulesEntity> listparent = userApp.GetAllModules(parentID, 1, 1000, out recordCount); foreach (ModulesEntity m in listparent) { ListItem item = new ListItem(string.Format("{0} [{1}]", m.ModuleTitle, m.ModulePath), m.ID.ToString()); ddlParentModule.Items.Add(item); } InitContorls(model); Page.Title = string.Format("Edit Module({0},{1})", model.ModuleTitle, model.ModulePath); } }
private string GetTemplate(ModulesEntity parent) { string temp = string.Empty; if (parent.IsModule) { temp = tempFirstParent; } else { if (parent.ParentID == ParentID) { temp = tempFirstChild; if (!parent.ShowInMenu) { temp = string.Empty; } } else { temp = tempSecondChild; if (!parent.ShowInMenu) { temp = string.Empty; } } } return(temp); }
// // UPDATE // public bool updateModule(ModulesEntity module) { using (var context = new MADERA_V1Entities()) { MDR_Modules addModule = (from m in context.MDR_Modules where m.Mod_Index == module.Mod_Index select m).SingleOrDefault(); addModule.Mod_Actif = module.Mod_Actif; addModule.Mod_Date = module.Mod_Date; addModule.Mod_Nom = module.Mod_Nom; addModule.Mod_Prix = module.Mod_Prix; addModule.Mod_Index = module.Mod_Index; try { context.SaveChanges(); return(true); } catch (Exception e) { return(false); } } }
/// <summary> /// Get an object entity /// </summary> public ModulesEntity Get(int ModuleID) { StringBuilder strSql = new StringBuilder(); strSql.Append("select * from Modules "); strSql.Append(" where ModuleID=@ModuleID "); Database db = DatabaseFactory.CreateDatabase(); using (DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString())) { try { db.AddInParameter(dbCommand, "ModuleID", DbType.Int32, ModuleID); ModulesEntity model = null; using (IDataReader dataReader = db.ExecuteReader(dbCommand)) { if (dataReader.Read()) { model = ModulesEntity.ReaderBind(dataReader); } } return(model); } catch (Exception ex) { WebLogAgent.Write(string.Format("[SQLText:{0},{1}Messages:\r\n{2}]", strSql.ToString(), base.FormatParameters(dbCommand.Parameters), ex.Message)); return(null); } } }
public int AddModule(ModulesEntity module) { this.ClearBrokenRuleMessages(); int mid = mgr.AddModule(module); this.AddBrokenRuleMessages(mgr.BrokenRuleMessages); return(mid); }
public bool UpdateModule(ModulesEntity module, int roleID) { this.ClearBrokenRuleMessages(); bool update = mgr.UpdateModule(module, roleID); this.AddBrokenRuleMessages(mgr.BrokenRuleMessages); return(update); }
public ModulesEntity GetModule(int moduleID) { this.ClearBrokenRuleMessages(); ModulesEntity module = mgr.GetModule(moduleID); this.AddBrokenRuleMessages(mgr.BrokenRuleMessages); return(module); }
protected void InitContorls(ModulesEntity model) { ddlParentModule.SelectedValue = model.ParentID.ToString(); this.txtModulePath.Text = model.ModulePath; this.txtModuleTitle.Text = model.ModuleTitle; this.txtDefaultPage.Text = model.DefaultPage; this.txtClickFunction.Text = model.ClickFunctioin; this.txtOrders.Text = model.Orders.ToString(); this.chkShow.Checked = model.ShowInMenu; }
// Create Modules tree private string GetTree(List <ModulesEntity> list, int parentID) { StringBuilder strTree = new StringBuilder(); ModulesEntity parent = list.Find(m => m.ID == parentID); if (null == parent) { return(string.Empty); } var children = list.FindAll(m => m.ParentID == parent.ID); StringBuilder strChildren = new StringBuilder(); string className = GetClassName(parent); if (children.Count <ModulesEntity>() > 0) { List <ModulesEntity> listChildren = children.ToList <ModulesEntity>(); foreach (ModulesEntity model in listChildren) { strChildren.Append(GetTree(list, model.ID)); } } else { string temp = GetTemplate(parent); string child = temp.Replace("{ID}", parent.ID.ToString()) .Replace("{Href}", parent.ModulePath) .Replace("{Text}", parent.ModuleTitle) .Replace("{ClassName}", className) .Replace("{Click}", parent.ClickFunctioin) .Replace("{Children}", strChildren.ToString()); return(child); } string _this = string.Empty; if (parent.ID != ParentID) { _this = tempFirstParent.Replace("{ID}", parent.ID.ToString()) .Replace("{ID}", parent.ID.ToString()) .Replace("{Click}", parent.ClickFunctioin) .Replace("{Href}", string.Format("{0}{1}", parent.ModulePath, parent.DefaultPage)) .Replace("{Text}", parent.ModuleTitle) .Replace("{Children}", strChildren.ToString()) .Replace("{ClassName}", className); } else { _this = strChildren.ToString(); } strTree.Append(_this); return(strTree.ToString()); }
/// <summary> /// Update a record /// </summary> public bool Update(ModulesEntity model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update Modules set "); strSql.Append("ModuleTitle=@ModuleTitle,"); strSql.Append("ModulePath=@ModulePath,"); strSql.Append("DefaultPage=@DefaultPage,"); strSql.Append("Status=@Status,"); strSql.Append("Orders=@Orders,"); strSql.Append("ShowInMenu=@ShowInMenu,"); strSql.Append("PageOrModule=@PageOrModule,"); strSql.Append("ClickFunctioin=@ClickFunctioin,"); strSql.Append("ParentID=@ParentID"); strSql.Append(" where ModuleID=@ModuleID and ModuleID=@ModuleID "); Database db = DatabaseFactory.CreateDatabase(); using (DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString())) { try { db.AddInParameter(dbCommand, "ModuleID", DbType.Int32, model.ModuleID); db.AddInParameter(dbCommand, "ModuleTitle", DbType.String, model.ModuleTitle); db.AddInParameter(dbCommand, "ModulePath", DbType.String, model.ModulePath); db.AddInParameter(dbCommand, "DefaultPage", DbType.String, model.DefaultPage); db.AddInParameter(dbCommand, "Status", DbType.Int32, model.Status); db.AddInParameter(dbCommand, "Orders", DbType.Int32, model.Orders); db.AddInParameter(dbCommand, "ShowInMenu", DbType.Boolean, model.ShowInMenu); db.AddInParameter(dbCommand, "PageOrModule", DbType.Int32, model.PageOrModule); db.AddInParameter(dbCommand, "ClickFunctioin", DbType.String, model.ClickFunctioin); db.AddInParameter(dbCommand, "ParentID", DbType.Int32, model.ParentID); int rows = db.ExecuteNonQuery(dbCommand); if (rows > 0) { return(true); } else { return(false); } } catch (Exception ex) { WebLogAgent.Write(string.Format("[SQLText:{0},{1}Messages:\r\n{2}]", strSql.ToString(), base.FormatParameters(dbCommand.Parameters), ex.Message)); return(false); } } }
private ModulesEntity GetEntity() { ModulesEntity model = UsersFactory.CreateModulesEntity(0, ObjectFactory.GetInstance <ISystemDateTime>()); model.ModuleTitle = txtModuleTitle.Text.Trim().NoHTML(); model.ModulePath = txtModulePath.Text.Trim(); model.DefaultPage = txtDefaultPage.Text.Trim(); model.ClickFunctioin = txtClickFunction.Text.Trim(); model.ShowInMenu = chkShow.Checked; model.PageOrModule = txtModulePath.Text.IndexOf(".") > 0 ? 0 : 1; model.Orders = int.Parse(txtOrders.Text.Trim()); model.ParentID = int.Parse(ddlParentModule.SelectedValue); return(model); }
private ModulesEntity GetEntity() { ModulesEntity model = userApp.GetModule(QS("selected", 0)); model.ModuleTitle = txtModuleTitle.Text.Trim().NoHTML(); model.ModulePath = txtModulePath.Text.Trim(); model.DefaultPage = txtDefaultPage.Text.Trim(); model.ClickFunctioin = txtClickFunction.Text.Trim(); model.ShowInMenu = chkShow.Checked; model.PageOrModule = txtModulePath.Text.IndexOf(".") > 0 ? 0 : 1; model.Orders = int.Parse(txtOrders.Text.Trim()); model.ParentID = int.Parse(ddlParentModule.SelectedValue); return(model); }
protected void Page_Load(object sender, EventArgs e) { TopMenu1.ParentID = 1; UserApplication userApp = new UserApplication(); string keyPath = "/sunnet/"; string url = Request.Url.AbsolutePath.ToLower(); string topModule = url.Replace(keyPath, ""); topModule = topModule.Substring(0, topModule.IndexOf("/") + 1); topModule = keyPath + topModule; ModulesEntity moduleTop = userApp.GetModule(topModule); if (moduleTop != null) { if (UserInfo.Role == RolesEnum.CLIENT && moduleTop.ModuleTitle.Trim().ToLower() == "clients") { moduleTop.ModuleTitle = "Tickets"; } this.TopSelectedIndex = moduleTop.ID; ltlCurrentModule.Text = moduleTop.ModuleTitle; } //url += Request.Url.Query; ModulesEntity moduleCurrent = userApp.GetModule(url); if (moduleCurrent != null) { this.LeftSelectedIndex = moduleCurrent.ParentID; this.LeftSecondSelectedIndex = moduleCurrent.ID; } //CateGory CateGoryApplication cgApp = new CateGoryApplication(); List <CateGoryEntity> listCC = cgApp.GetCateGroyListByUserID(UserInfo.ID); rptCategory.DataSource = listCC; rptCategory.DataBind(); rptCateGory2.DataSource = listCC; rptCateGory2.DataBind(); // Client Or Sunnet topMenu_category.Visible = UserInfo.Role != RolesEnum.CLIENT; InitCompanyInfo(); }
// Create Modules tree private string GetTree(List <ModulesEntity> list, int parentID) { StringBuilder strTree = new StringBuilder(); ModulesEntity parent = list.First <ModulesEntity>(m => m.ID == parentID); if (null == parent) { return(string.Empty); } var children = list.FindAll(m => m.ParentID == parent.ID); StringBuilder strChildren = new StringBuilder(); if (children.Count <ModulesEntity>() > 0) { List <ModulesEntity> listChildren = children.ToList <ModulesEntity>(); foreach (ModulesEntity model in listChildren) { strChildren.Append(GetTree(list, model.ID)); } } else { string child = templateChild.Replace("{ID}", parent.ID.ToString()) .Replace("{ID}", parent.ID.ToString()) .Replace("{Text}", parent.ModuleTitle); return(child); } string _this = string.Empty; if (parent.IsPage) { _this = templateP2C.Replace("{ID}", parent.ID.ToString()) .Replace("{ID}", parent.ID.ToString()) .Replace("{Text}", parent.ModuleTitle); } else { _this = templateParent.Replace("{ID}", parent.ID.ToString()) .Replace("{ID}", parent.ID.ToString()) .Replace("{Text}", parent.ModuleTitle) .Replace("{Children}", strChildren.ToString()); _this = string.Format("<ul>{0}</ul>", _this); } strTree.Append(_this); return(strTree.ToString()); }
private void InitControl() { List <ModulesEntity> list = userApp.GetRoleModules(RoleID, true); List <ModulesEntity> listTop = list.FindAll(m => m.ParentID == ParentID && m.ShowInMenu); if (UserInfo.Role == RolesEnum.CLIENT) // if current role is client then change Clients modules' module name to Tickets { ModulesEntity modulesEntity = listTop.Find(r => r.ModuleTitle.Trim().ToLower() == "clients"); if (modulesEntity != null) { modulesEntity.ModuleTitle = "Tickets"; } } rptTop.DataSource = listTop; rptTop.DataBind(); }
public string GetClientTopMenu(int userId) { UsersEntity userInfo = new UserApplication().GetUser(userId); UserApplication userApp = new UserApplication(); List <ModulesEntity> list = userApp.GetRoleModules(userInfo.RoleID, true); List <ModulesEntity> listTop = list.FindAll(m => m.ParentID == 1 && m.ShowInMenu); if (userInfo.Role == RolesEnum.CLIENT) // if current role is client then change Clients modules' module name to Tickets { ModulesEntity modulesEntity = listTop.Find(r => r.ModuleTitle.Trim().ToLower() == "clients"); if (modulesEntity != null) { modulesEntity.ModuleTitle = "Tickets"; } } return(Newtonsoft.Json.JsonConvert.SerializeObject(listTop)); }
private string GetPath(int currentParent) { string parentHtml = string.Empty; ModulesEntity module = userApp.GetModule(currentParent); if (module == null) { return(""); } parentHtml = template.Replace("{parent}", module.ParentID.ToString()) .Replace("{Text}", module.ModuleTitle) .Replace("{selected}", module.ID.ToString()); if (module.ParentID != 0) { return(GetPath(module.ParentID) + " > " + parentHtml); } return(parentHtml); }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { int parentID = QS("parent", 0); BindControl(); if (QS("selected", 1) == 1) { ltlMenu.Text = "> <strong>Root</strong>"; } else { ModulesEntity module = userApp.GetModule(QS("selected", 1)); ltlMenu.Text = GetPath(parentID) + string.Format(" > <strong>{0}</strong>", module.ModuleTitle); } } }
public List <ModulesEntity> GetModulesList(int roleID) { StringBuilder strSql = new StringBuilder(); strSql.Append("IF(@RoleID=0)"); strSql.Append(" BEGIN"); strSql.Append(" SELECT m.*"); strSql.Append(" FROM [Modules] m "); strSql.Append(" WHERE [Status] =0 OR [Status] =1"); strSql.Append(" ORDER BY Orders DESC ,ModuleID DESC"); strSql.Append(" END "); strSql.Append("ELSE"); strSql.Append(" BEGIN"); strSql.Append(" SELECT m.*"); strSql.Append(" FROM [Modules] m,RoleModules rm"); strSql.Append(" WHERE rm.RoleID=@RoleID AND m.ModuleID=rm.ModuleID"); strSql.Append(" ORDER BY Orders DESC ,ModuleTitle ASC"); strSql.Append(" END"); List <ModulesEntity> list = new List <ModulesEntity>(); Database db = DatabaseFactory.CreateDatabase(); using (DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString())) { try { db.AddInParameter(dbCommand, "RoleID", DbType.Int32, roleID); using (IDataReader dataReader = db.ExecuteReader(dbCommand)) { while (dataReader.Read()) { list.Add(ModulesEntity.ReaderBind(dataReader)); } } } catch (Exception ex) { WebLogAgent.Write(string.Format("[SQLText:{0},{1}Messages:\r\n{2}]", strSql.ToString(), base.FormatParameters(dbCommand.Parameters), ex.Message)); } } return(list); }
protected void btnSave_Click(object sender, EventArgs e) { if (!CheckInput()) { this.ShowMessageToClient("Input Error,please select a parent module and you must input a number for Priority field", 2, false, false); return; } ModulesEntity model = GetEntity(); int id = userApp.AddModule(model); if (id > 0) { Redirect(QS("returnurl")); } else { this.ShowFailMessageToClient(userApp.BrokenRuleMessages); } }
private string GetClassName(ModulesEntity parent) { string className = string.Empty; if (parent.ParentID == ParentID) { if (parent.IsPage) { if (parent.ID == CurrentSecondIndex) { className = classFirstSelected; } else { className = classFirstUnSelectedChild; } } else if (parent.IsModule) { if (parent.ID == CurrentIndex) { className = classFirstSelected; } else { className = classFirstUnSelectedParent; } } } else { if (parent.ID == CurrentSecondIndex) { className = classSecondSelected; } else { className = classSecondUnSelected; } } return(className); }
/// <summary> /// Add a record /// </summary> public int Insert(ModulesEntity model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into Modules("); strSql.Append("ModuleTitle,ModulePath,DefaultPage,Status,Orders,ShowInMenu,PageOrModule,ClickFunctioin,ParentID)"); strSql.Append(" values ("); strSql.Append("@ModuleTitle,@ModulePath,@DefaultPage,@Status,@Orders,@ShowInMenu,@PageOrModule,@ClickFunctioin,@ParentID)"); strSql.Append(";select ISNULL( SCOPE_IDENTITY(),0);"); Database db = DatabaseFactory.CreateDatabase(); using (DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString())) { try { db.AddInParameter(dbCommand, "ModuleTitle", DbType.String, model.ModuleTitle); db.AddInParameter(dbCommand, "ModulePath", DbType.String, model.ModulePath); db.AddInParameter(dbCommand, "DefaultPage", DbType.String, model.DefaultPage); db.AddInParameter(dbCommand, "Status", DbType.Int32, model.Status); db.AddInParameter(dbCommand, "Orders", DbType.Int32, model.Orders); db.AddInParameter(dbCommand, "ShowInMenu", DbType.Boolean, model.ShowInMenu); db.AddInParameter(dbCommand, "PageOrModule", DbType.Int32, model.PageOrModule); db.AddInParameter(dbCommand, "ClickFunctioin", DbType.String, model.ClickFunctioin); db.AddInParameter(dbCommand, "ParentID", DbType.Int32, model.ParentID); int result; object obj = db.ExecuteScalar(dbCommand); if (!int.TryParse(obj.ToString(), out result)) { return(0); } return(result); } catch (Exception ex) { WebLogAgent.Write(string.Format("[SQLText:{0},{1}Messages:\r\n{2}]" , strSql.ToString(), base.FormatParameters(dbCommand.Parameters), ex.Message)); return(0); } } }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { int parentID = QS("parent", -1); int selected = QS("selected", -1); if (selected < 0) { this.ShowFailMessageToClient(); return; } if (parentID >= 0) { List <ModulesEntity> list = userApp.GetAllModules(parentID, 1, 1000, out recordCount); foreach (ModulesEntity model in list) { ListItem item = new ListItem(string.Format("{0} [{1}]", model.ModuleTitle, model.ModulePath), model.ID.ToString()); ddlParentModule.Items.Add(item); if (model.ID == selected) { InitControls(model); } } ddlParentModule.SelectedValue = selected.ToString(); } else { int id = UtilFactory.Helpers.CommonHelper.ToInt(Request.QueryString["selected"]); ModulesEntity model = userApp.GetModule(id); if (!(model == null)) { ListItem item = new ListItem(string.Format("{0} [{1}]", model.ModuleTitle, model.ModulePath), model.ID.ToString()); ddlParentModule.Items.Add(item); ddlParentModule.Enabled = false; } InitControls(model); } } }
public List <ModulesEntity> GetAllModules(int parentID, int page, int pageCount) { int start = page * pageCount + 1 - pageCount; int end = page * pageCount; StringBuilder strSql = new StringBuilder(); strSql.Append(@"SELECT * FROM ("); strSql.Append("SELECT ROW_NUMBER() OVER(Order BY ParentID ASC, Orders DESC,ModuleTitle ASC) AS INDEX_ID,* "); strSql.Append("FROM [Modules] "); strSql.Append(@"WHERE [ParentID]=@ParentID AND ([Status] =0 OR [Status] =1 ) ) NEW_TB WHERE INDEX_ID BETWEEN @Strat AND @End; "); List <ModulesEntity> list = new List <ModulesEntity>(); Database db = DatabaseFactory.CreateDatabase(); using (DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString())) { try { db.AddInParameter(dbCommand, "ParentID", DbType.Int32, parentID); db.AddInParameter(dbCommand, "Strat", DbType.Int32, start); db.AddInParameter(dbCommand, "End", DbType.Int32, end); using (IDataReader dataReader = db.ExecuteReader(dbCommand)) { while (dataReader.Read()) { list.Add(ModulesEntity.ReaderBind(dataReader)); } } } catch (Exception ex) { WebLogAgent.Write(string.Format("[SQLText:{0},{1}Messages:\r\n{2}]", strSql.ToString(), base.FormatParameters(dbCommand.Parameters), ex.Message)); } } return(list); }
// // CREATE // public bool createModule(ModulesEntity module) { using (var context = new MADERA_V1Entities()) { MDR_Modules addModule = new MDR_Modules(); addModule.Mod_Actif = 1; addModule.Mod_Date = module.Mod_Date; addModule.Mod_Nom = module.Mod_Nom; addModule.Mod_Prix = module.Mod_Prix; try { context.MDR_Modules.Add(addModule); context.SaveChanges(); return(true); } catch (Exception e) { return(false); } } }
protected void btnSave_Click(object sender, EventArgs e) { Page.Validate("AddModule"); if (!IsValid) { return; } if (!CheckInput()) { this.ShowMessageToClient("Input Error,please select a parent module and you must input a number for Priority field", 2, false, false); return; } ModulesEntity model = GetEntity(); if (userApp.UpdateModule(model, UserInfo.RoleID)) { this.ShowSuccessMessageToClient(false, true); } else { this.ShowFailMessageToClient(userApp.BrokenRuleMessages); } }
private void InitControls(ModulesEntity parent) { txtModulePath.Text = parent.ModulePath; }