public static bool IsEnableCommand(string className, string viewName, string placeName, string commandName, Dictionary <string, string> parameters) { bool flag = true; XmlCommand commandByName = XmlCommand.GetCommandByName(className, viewName, placeName, commandName); if (commandByName == null || string.IsNullOrEmpty(commandByName.EnableHandler)) { return(flag); } object obj = AssemblyUtil.LoadObject(commandByName.EnableHandler); if (!(obj is ICommandEnableHandler)) { return(flag); } CommandParameters commandParameters = new CommandParameters(commandName); commandParameters.CommandArguments = parameters; if (!string.IsNullOrEmpty(commandByName.Params)) { if (commandParameters.CommandArguments == null) { commandParameters.CommandArguments = new Dictionary <string, string>(); } commandParameters.CommandArguments.Add("_commandParamsKey", commandByName.Params); } return(((ICommandEnableHandler)obj).IsEnable((object)null, (object)commandParameters)); }
/// <summary> /// Determines whether [is enable command] [the specified class name]. /// </summary> /// <param name="className">Name of the class.</param> /// <param name="viewName">Name of the view.</param> /// <param name="placeName">Name of the place.</param> /// <param name="commandName">Name of the command.</param> /// <param name="parameters">The parameters.</param> /// <returns> /// <c>true</c> if [is enable command] [the specified class name]; otherwise, <c>false</c>. /// </returns> public static bool IsEnableCommand(string className, string viewName, string placeName, string commandName, Dictionary <string, string> parameters) { bool flag = true; XmlCommand command = XmlCommand.GetCommandByName(className, viewName, placeName, commandName); if ((command == null) || string.IsNullOrEmpty(command.EnableHandler)) { return(flag); } object obj2 = AssemblyUtil.LoadObject(command.EnableHandler); if (!(obj2 is ICommandEnableHandler)) { return(flag); } CommandParameters element = new CommandParameters(commandName); element.CommandArguments = parameters; if (!string.IsNullOrEmpty(command.Params)) { if (element.CommandArguments == null) { element.CommandArguments = new Dictionary <string, string>(); } element.CommandArguments.Add("_commandParamsKey", command.Params); } return(((ICommandEnableHandler)obj2).IsEnable(null, element)); }
private void BackFillOutputArgs(XmlCommand xmlCommand, Dictionary <string, object> args) { foreach (DbParameter p in xmlCommand.Command.Parameters) { if (p.Direction == ParameterDirection.InputOutput) { // 输出参数回写到参数对象上 args[p.ParameterName.TrimStart('@')] = p.Value; } } }
/// <summary> /// 分页查询,返回DataTable /// </summary> /// <param name="command"></param> /// <param name="pageInfo"></param> /// <returns></returns> public static DataTable ToPageTable(this XmlCommand command, PagingInfo pageInfo) { CPQuery query1 = null; CPQuery query2 = null; CreatePagedQuery(command, pageInfo, out query1, out query2); System.Data.DataTable table = query1.ToDataTable(); pageInfo.TotalRows = query2.ExecuteScalar <int>(); return(table); }
/// <summary> /// 分页查询,返回DataTable /// </summary> /// <param name="command"></param> /// <param name="pageInfo"></param> /// <returns></returns> public static async Task <DataTable> ToPageTableAsync(this XmlCommand command, PagingInfo pageInfo) { CPQuery query1 = null; CPQuery query2 = null; CreatePagedQuery(command, pageInfo, out query1, out query2); DataTable table = await query1.ToDataTableAsync(); pageInfo.TotalRows = await query2.ExecuteScalarAsync <int>(); return(table); }
/// <summary> /// 分页查询,返回实体列表 /// </summary> /// <typeparam name="T">实体类型</typeparam> /// <param name="command">XmlCommand实例引用</param> /// <param name="pageInfo">分页信息</param> /// <returns>实体集合</returns> public static async Task <List <T> > ToPageListAsync <T>(this XmlCommand command, PagingInfo pageInfo) where T : class, new() { CPQuery query1 = null; CPQuery query2 = null; CreatePagedQuery(command, pageInfo, out query1, out query2); List <T> list = await query1.ToListAsync <T>(); pageInfo.TotalRows = await query2.ExecuteScalarAsync <int>(); return(list); }
/// <summary> /// 查询最新的备案信息 /// </summary> /// <returns></returns> public ApiResult <List <PostRecordViewModel> > QueryLastTimeRecord() { ApiResult <List <PostRecordViewModel> > result = new ApiResult <List <PostRecordViewModel> >(); result.Result = new List <PostRecordViewModel>(); var list = XmlCommand.From("PoliceRecord:GetLastTimeRecord").ToList <PoliceRecord>(); list.ForEach((e) => { result.Result.Add(JsonHelper.ToJson <PostRecordViewModel>(e.Record)); }); return(result); }
/// <summary> /// 分页查询,返回实体列表 /// </summary> /// <typeparam name="T">实体类型</typeparam> /// <param name="command">XmlCommand实例引用</param> /// <param name="pageInfo">分页信息</param> /// <returns>实体集合</returns> public static List <T> ToPageList <T>(this XmlCommand command, PagingInfo pageInfo) where T : class, new() { CPQuery query1 = null; CPQuery query2 = null; CreatePagedQuery(command, pageInfo, out query1, out query2); // 确保在一个连接中执行二次数据库操作 using (ConnectionScope scope = ConnectionScope.GetExistOrCreate()) { List <T> list = query1.ToList <T>(); pageInfo.TotalRows = query2.ExecuteScalar <int>(); return(list); } }
/// <summary> /// Clears the cache. /// </summary> /// <param name="profileId">The profile id.</param> /// <param name="principalId">The principal id.</param> private static void ClearCache(PrimaryKeyId?profileId, PrimaryKeyId?principalId) { // user if (principalId.HasValue) { DataCache.RemoveByUser(principalId.Value.ToString()); } // profile else if (profileId.HasValue) { ProfileManager.ClearCacheForProfileUsers(profileId.Value); } XmlCommand.ClearCache(); XmlBuilder.ClearCache(); }
/// <summary> /// 分页查询,返回DataTable /// </summary> /// <param name="command"></param> /// <param name="pageInfo"></param> /// <returns></returns> public static System.Data.DataTable ToPageTable(this XmlCommand command, PagingInfo pageInfo) { CPQuery query1 = null; CPQuery query2 = null; CreatePagedQuery(command, pageInfo, out query1, out query2); // 确保在一个连接中执行二次数据库操作 using (ConnectionScope scope = ConnectionScope.GetExistOrCreate()) { System.Data.DataTable table = query1.ToDataTable(); pageInfo.TotalRows = query2.ExecuteScalar <int>(); return(table); } }
private void BindFullTree() { List <JsonTreeNode> nodes = new List <JsonTreeNode>(); XmlBuilder.GetCustomizableXml2(StructureType.View, 1 != 0, new Selector(new string[1] { "LeftMenu" })); Navigation navigation = XmlModelHelper.GetNavigation("LeftMenu", string.Empty); if (navigation == null || navigation.Tabs == null) { return; } if (navigation.Commands.Command != null) { foreach (Mediachase.BusinessFoundation.XmlObjectModel.Command command in navigation.Commands.Command) { XmlCommand.GetCommandByName("", "LeftMenu", "", command.id); } } foreach (Tab tab in navigation.Tabs.Tab) { JsonTreeNode jsonTreeNode = new JsonTreeNode(); jsonTreeNode.id = tab.id; jsonTreeNode.text = UtilHelper.GetResFileString(tab.text); jsonTreeNode.cls = "nodeCls"; if (!string.IsNullOrEmpty(tab.imageUrl)) { jsonTreeNode.icon = this.ResolveUrl(tab.imageUrl); } jsonTreeNode.children = new List <JsonTreeNode>(); int num = 0; if (tab.Items != null) { num = this.BindRecursiveNoAsync(jsonTreeNode.children, tab.Items); } if (num == 0) { jsonTreeNode.leaf = true; jsonTreeNode.children = (List <JsonTreeNode>)null; } nodes.Add(jsonTreeNode); } this.WriteArray(nodes); }
/// <summary> /// 查询岗位列表信息 /// </summary> /// <returns></returns> public ApiResult <List <DutyPostViewModel> > PostQuery(QueryCondition condition) { ApiResult <List <DutyPostViewModel> > apiResult = new ApiResult <List <DutyPostViewModel> >(); //using (CommonDbContext db = new CommonDbContext()) //{ // //var result = db.PageQuery<Entity.FrontendDevice>(condition); // //apiResult.Result = result.Data; // //apiResult.TotalCount = result.Total; // //apiResult.TotalPage = result.TotalPage; //} //var list = XmlCommand.From("AAA:CCC").ToList<Entity.FrontendDevice>(); try { List <DutyPostViewModel> viewModels = new List <DutyPostViewModel>(); var result = Pagination.QueryBase <DutyPost>("select * from DUTY_POST", condition); var dic = new Dictionary <string, string>(); if (result.Data.Count == 0) { dic.Add("$PostIds", "''"); } else { dic.Add("$PostIds", string.Join(",", result.Data.Select(p => "'" + p.PostId + "'"))); } var onDutys = XmlCommand.From("PoliceRecord:GetPoliceOnDuty", null, dic).ToList <PostPoliceOnduty>(); foreach (var item in result.Data) { var viewModel = item.MapTo <DutyPostViewModel>(); viewModel.PostPoliceOnDutys = onDutys.Where(p => p.PostId == item.PostId).ToList(); viewModels.Add(viewModel); } apiResult.Result = viewModels; apiResult.TotalCount = result.Total; apiResult.TotalPage = result.TotalPage; apiResult.Code = ResultCode.Success; } catch (Exception e) { apiResult.Code = ResultCode.SystemError; apiResult.Message = e.ToString(); } return(apiResult); }
public object Query(string x_name, [FromRequest] NameValueCollection form) { XmlCommandItem command = GetXmlCommand(x_name); Dictionary <string, object> args = null; if (command.Parameters != null || command.Parameters.Count > 0) { args = GetCommandParameters(command, form); } XmlCommand xmlCommand = XmlCommand.Create(x_name, args); DataTable table = xmlCommand.ToDataTable(); // 处理输出参数,回填到参数字典中返回给前端 BackFillOutputArgs(xmlCommand, args); return(new { args = args, data = table }); }
public void Test_BaseCommand_CloneParameters() { var newCustomer = new { CustomerName = s_newName, ContactName = Guid.NewGuid().ToString(), Address = "111111 Address", PostalCode = "111111", Tel = "123456789" }; using (ConnectionScope scope = ConnectionScope.Create()) { XmlCommand command = XmlCommand.Create("InsertCustomer", newCustomer); DbParameter[] parameters1 = command.Command.Parameters.Cast <DbParameter>().ToArray(); DbParameter[] parameters2 = command.CloneParameters(); AssertAreEqual_DbParameterArray(parameters1, parameters2); } }
public void Test_ConnectionScope事务中使用StoreProcedure_XmlCommand_CPQuery() { using (ConnectionScope scope = ConnectionScope.Create()) { scope.BeginTransaction(); var newCustomer = new { // 下行代码创建一个输出参数 CustomerID = scope.Context.CreateOutParameter(DbType.Int32), CustomerName = Guid.NewGuid().ToString(), ContactName = Guid.NewGuid().ToString(), Address = "111111 Address", PostalCode = "111111", Tel = "123456789" }; // 插入一条记录 StoreProcedure.Create("InsertCustomer", newCustomer).ExecuteNonQuery(); // 获取输出参数的返回值 int newCustomerId = (int)newCustomer.CustomerID.Value; var queryArgument = new { CustomerID = newCustomerId }; Customer customer1 = XmlCommand.Create("GetCustomerById", queryArgument).ToSingle <Customer>(); Customer customer2 = StoreProcedure.Create("GetCustomerById", queryArgument).ToSingle <Customer>(); string sql = CPQueryTest.GetSql("GetCustomerById"); Customer customer3 = CPQuery.Create(sql, queryArgument).ToSingle <Customer>(); Assert.AreEqual(customer1.CustomerID, customer2.CustomerID); Assert.AreEqual(customer1.CustomerID, customer3.CustomerID); Assert.AreEqual(customer1.CustomerName, customer2.CustomerName); Assert.AreEqual(customer1.CustomerName, customer3.CustomerName); Assert.AreEqual(customer1.Address, customer2.Address); Assert.AreEqual(customer1.Address, customer3.Address); scope.Commit(); } }
public void Test_XmlCommand_SubQuery() { using (ConnectionScope scope = ConnectionScope.Create()) { CPQuery subQuery = CPQuery.Create() + "Tel like " + "021%".AsQueryParameter(); int[] customerIdArray = { 1, 2, 3, 4, 5 }; // 注意:下面二个参数名,它们只是SQL语句中的占位符,在替换时是区分大小写的。 var queryArgument = new { table = "dbo.Customers", CustomerID = customerIdArray, filter = subQuery }; XmlCommand query = XmlCommand.Create("FindCustomers", queryArgument); string commandText = query.Command.CommandText; Console.WriteLine(commandText); // 断言占位符已被替换 Assert.AreEqual( "select * from dbo.Customers where CustomerID in (1,2,3,4,5) and Tel like @p1", commandText ); // 断言参数已产生 Assert.AreEqual(1, query.Command.Parameters.Count); List <Customer> list = query.ToList <Customer>(); // 这里不需要检查 list 的结果,因为结果不重要,只要能正确拼接成有效的SQL就行了。 Assert.IsNotNull(list); Console.WriteLine("list.Count: " + list.Count); foreach (Customer c in list) { Assert.IsTrue(c.CustomerID <= 5); } } }
public object Execute(string x_name, [FromRequest] NameValueCollection form) { // name 这个参数名太常见,所以就改成 x_name XmlCommandItem command = GetXmlCommand(x_name); Dictionary <string, object> args = null; if (command.Parameters != null || command.Parameters.Count > 0) { args = GetCommandParameters(command, form); } XmlCommand xmlCommand = XmlCommand.Create(x_name, args); int result = xmlCommand.ExecuteNonQuery(); // 处理输出参数,回填到参数字典中返回给前端 BackFillOutputArgs(xmlCommand, args); return(new { args = args, data = result }); }
public void Test_XmlCommand_StringArray() { string[] customerIdArray = { "1", "2", "3", "4", "5" }; // 注意:下面二个参数名,它们只是SQL语句中的占位符,在替换时是区分大小写的。 var queryArgument = new { table = "dbo.Customers", CustomerID = customerIdArray }; using (ConnectionScope scope = ConnectionScope.Create()) { XmlCommand query = XmlCommand.Create("GetCustomerListById", queryArgument); string commandText = query.Command.CommandText; Console.WriteLine(commandText); // 断言占位符已被替换 Assert.AreEqual( "select * from dbo.Customers where CustomerID in (@x1,@x2,@x3,@x4,@x5)", commandText ); // 断言参数已产生 Assert.AreEqual(5, query.Command.Parameters.Count); } }
public object Paging(string x_name, int pageIndex, int pageSize, [FromRequest] NameValueCollection form) { XmlCommandItem command = GetXmlCommand(x_name); Dictionary <string, object> args = null; if (command.Parameters != null || command.Parameters.Count > 0) { args = GetCommandParameters(command, form); } PagingInfo info = new PagingInfo { PageIndex = pageIndex, PageSize = pageSize }; XmlCommand xmlCommand = XmlCommand.Create(x_name, args); DataTable table = xmlCommand.ToPageTable(info); // 处理输出参数,回填到参数字典中返回给前端 BackFillOutputArgs(xmlCommand, args); return(new { args = args, paging = info, data = table }); }
public void Test_XmlCommand_IntArray() { int[] customerIdArray = { 1, 2, 3, 4, 5 }; // 注意:下面二个参数名,它们只是SQL语句中的占位符,在替换时是区分大小写的。 var queryArgument = new { table = "dbo.Customers", CustomerID = customerIdArray }; using (ConnectionScope scope = ConnectionScope.Create()) { XmlCommand query = XmlCommand.Create("GetCustomerListById", queryArgument); string commandText = query.Command.CommandText; Console.WriteLine(commandText); // 断言占位符已被替换 Assert.AreEqual( // 注意:int[] 不会生成命令参数,将直接输出到SQL中 "select * from dbo.Customers where CustomerID in (1,2,3,4,5)", commandText ); // 断言参数已产生 Assert.AreEqual(0, query.Command.Parameters.Count); } }
/// <summary> /// 查询警员信息 /// </summary> /// <param name="condition"></param> /// <returns></returns> public ApiResult <List <PoliceMan> > QueryPoliceMan(QueryCondition condition) { ApiResult <List <PoliceMan> > result = new ApiResult <List <PoliceMan> >(); //得到警员信息 var policeman = XmlCommand.From("PoliceOnDuty:GetPoliceMan").ToList <PoliceMan>(); //得到警员排班信息 var fileter = condition.FilterList.Where(p => p.FieldName == "DutyDate").FirstOrDefault(); if (fileter != null) { DateTime Time; condition.FilterList.Remove(fileter); if (DateTime.TryParse(fileter.FieldValue, out Time)) { string whereSql = $"where to_char(ONDUTYSTARTTIME,'yyyy-MM-dd')='{Time.ToString("yyyy-MM-dd")}' or (PPNREPEATTYPE!='0' and EFFECTSTARTTIME<=to_date('{Time.ToString("yyyy-MM-dd HH:mm:ss")}','yyyy-MM-dd HH24:mi:ss') and (EFFECTENDTIME=null or (EFFECTENDTIME!=null and EFFECTENDTIME>=to_date('{Time.ToString("yyyy-MM-dd HH:mm:ss")}','yyyy-MM-dd HH24:mi:ss'))))"; var dic = new Dictionary <string, string>(); dic.Add("$Where", whereSql); var list = XmlCommand.From("PoliceOnDuty:GetPoliceOnDuty", null, dic).ToList <PostPoliceOnduty>(); foreach (var item in policeman) { var dutyInfo = list.Where(p => p.PoliceManid == item.PoliceManID && p.PPNRepeatType == "0").FirstOrDefault(); if (dutyInfo != null) { item.IsOnDuty = true; } var dutyinfoList = list.Where(p => p.PoliceManid == item.PoliceManID).ToList(); foreach (var duty in dutyinfoList) { //判断重复类型 } } } } result.Result = policeman; return(result); }
private void AssertCommands(string expectedType, string expectedCaption, int expectedOrder, XmlCommand command) { Assert.AreEqual(expectedType, command.Type); Assert.AreEqual(expectedCaption, command.Caption); Assert.AreEqual(expectedOrder, command.Order); }
public object Args(String argName) { if (_currentCell == null) { return(null); } switch (argName) { case "ColumnIndex": return(_currentCell.ColumnIndex); case "RowIndex": return(_currentCell.RowIndex); case "CurrentCell": return(_currentCell); case "CellValue": return(_currentCell.Value); case "Text": return(_textChangedArgs.Text); case "BeforeText": return(_textChangedArgs.BeforeText); case "TextChangedArgs": return(_textChangedArgs); case "StartRowIndex": return(_checkboxChangedArg.StartRowIndex); case "EndRowIndex": return(_checkboxChangedArg.EndRowIndex); case "IsChecked": return(_checkboxChangedArg.Checked); case "Packet.CommandHeader": { XmlCommand packet = Row(_currentCell.RowIndex).RelativeObject["XmlCommand"] as XmlCommand; return(packet.CommandHeader); } case "Packet.CommandData": { XmlCommand packet = Row(_currentCell.RowIndex).RelativeObject["XmlCommand"] as XmlCommand; return(packet.CommandHeader); } case "Packet.ResponseHeader": { XmlCommand packet = Row(_currentCell.RowIndex).RelativeObject["XmlCommand"] as XmlCommand; return(packet.ResponseHeader); } case "Packet.ResponseData": { XmlCommand packet = Row(_currentCell.RowIndex).RelativeObject["XmlCommand"] as XmlCommand; return(packet.ResponseData); } case "Packet": { XmlCommand packet = Row(_currentCell.RowIndex).RelativeObject["XmlCommand"] as XmlCommand; return(packet); } default: return(null); } }
/// <summary> /// 获取个数 /// </summary> /// <param name="argsObject">参数</param> /// <param name="filter">过滤条件(参数化sql的过滤条件语句)</param> /// <returns>个数</returns> public virtual int GetCount(object argsObject, string filter) { return(XmlCommand.From <T>(XmlCommandType.GetCount, argsObject, filter).ExecuteScalar <int>()); }
/// <summary> /// 通过Id字符串获取列表 /// </summary> /// <param name="oids">Id字符串,以","分隔</param> /// <returns>实体列表</returns> public List <T> GetListByIds(string oids) { return(XmlCommand.From <T>(XmlCommandType.GetListByIds, new { oids = oids }).ToList()); }
/// <summary> /// 获取实体列表 /// </summary> /// <param name="argsObject">参数</param> /// <param name="filter">过滤条件(参数化sql的过滤条件语句)</param> /// <returns>实体列表</returns> public virtual List <T> GetList(object argsObject, string filter) { return(XmlCommand.From <T>(XmlCommandType.GetList, argsObject, filter).ToList()); }
private void 一般用法介绍() { string connectionName = "default"; IsolationLevel isolation = IsolationLevel.ReadCommitted; string name = "command1"; string sql = "select * from table1 where ....."; object args = new { a = 1, b = 2 }; // 基本数据库操作 using (DbContext db = DbContext.Create(connectionName)) { db.BeginTransaction(isolation); // 开启事务,并允许设置事务隔离级别(可选) db.XmlCommand.Create(name, args).ExecuteNonQuery(); db.CPQuery.Create(sql, args).ExecuteNonQuery(); db.StoreProcedure.Create(name, args).ExecuteNonQuery(); db.Commit(); } // 封装 DbContext ,允许跨方法调用 using (ConnectionScope scope = ConnectionScope.Create(connectionName)) { scope.BeginTransaction(isolation); // 开启事务,并允许设置事务隔离级别(可选) // 下面三个调用,调用了三个静态工厂方法, // 因此可以放在不同的方法中,不必传递 scope 变量 XmlCommand.Create(name, args).ExecuteNonQuery(); CPQuery.Create(sql, args).ExecuteNonQuery(); StoreProcedure.Create(name, args).ExecuteNonQuery(); scope.Commit(); } // DbContext/ConnectionScope 其它创建方法 DbContext c1 = DbContext.Create("connectionString", "providerName"); ConnectionScope c2 = ConnectionScope.Create("connectionString", "providerName"); // 甚至可以由显式转换来实现: DbContext c3 = (DbContext)"connectionString"; // 嵌套使用(一段代码访问不同数据源) using (ConnectionScope scope = ConnectionScope.Create("connectionName_1")) { XmlCommand.Create(name, args).ExecuteNonQuery(); using (DbContext db = DbContext.Create("connectionName_2")) { db.XmlCommand.Create(name, args).ExecuteNonQuery(); } } /* * Execute 包含的操作 * * abstract class BaseCommand { * ExecuteNonQuery() * ExecuteScalar<T>() * ToScalarList<T>() * ToSingle<T>() * ToList<T>() * ToDataTable() * ToDataSet() * * ExecuteNonQueryAsync() * ExecuteScalarAsync<T>() * ToScalarListAsync<T>() * ToSingleAsync<T>() * ToListAsync<T>() * ToDataTableAsync() * ToDataSetAsync() * } */ /* * // 从DataTable中加载数据 * class TableExtensions{ * ToList<T>(DataTable); * ToSingle<T>(DataRow); * } */ // 嵌套使用,允许:XmlCommnad 包含 CPQuery, CPQuery 包含 CPQuery using (DbContext db = DbContext.Create(connectionName)) { CPQuery subQuery1 = db.CPQuery.Create(name, args); CPQuery subQuery2 = db.CPQuery.Create(name, args); db.XmlCommand.Create( "select * from t1 where id=@id and {filter1} and {filter2}", new { id = 2, filter1 = subQuery1, filter2 = subQuery2 } ).ExecuteNonQuery(); db.XmlCommand.Create( "select * from t1 where id=@id and {filter1} and {filter2}", new { id = 2, filter1 = CPQuery.Create(name, args), filter2 = CPQuery.Create(name, args) } ).ExecuteNonQuery(); } }
protected void Page_Load(object sender, EventArgs e) { DataTable dt = new DataTable(); dt.Columns.Add(new DataColumn("Title", typeof(string))); dt.Columns.Add(new DataColumn("ImageUrl", typeof(string))); DataRow dr; IXPathNavigable navigable; // Selector: ClassName.ViewName.PlaceName.ProfileId.UserId Selector selector = new Selector(string.Empty, string.Empty, string.Empty, ProfileManager.GetProfileIdByUser().ToString(), Mediachase.IBN.Business.Security.UserID.ToString()); // don't hide items for administrator if (Mediachase.IBN.Business.Security.IsUserInGroup(Mediachase.IBN.Business.InternalSecureGroups.Administrator)) { navigable = XmlBuilder.GetCustomizationXml(null, StructureType.Navigation, selector); } else { navigable = XmlBuilder.GetXml(StructureType.Navigation, selector); } XPathNavigator tabs = navigable.CreateNavigator().SelectSingleNode("Navigation/Tabs"); foreach (XPathNavigator tabItem in tabs.SelectChildren(string.Empty, string.Empty)) { dr = dt.NewRow(); string title = UtilHelper.GetResFileString(tabItem.GetAttribute("text", string.Empty)); string id = tabItem.GetAttribute("id", string.Empty); string enableHandler = tabItem.GetAttribute("enableHandler", string.Empty); if (!string.IsNullOrEmpty(enableHandler)) { ICommandEnableHandler enHandler = (ICommandEnableHandler)AssemblyUtil.LoadObject(enableHandler); if (enHandler != null && !enHandler.IsEnable(sender, id)) { continue; } } string imageUrl = tabItem.GetAttribute("imageUrl", string.Empty); if (string.IsNullOrEmpty(imageUrl)) { imageUrl = "~/Images/ext/default/s.gif"; } string type = tabItem.GetAttribute("contentType", string.Empty).ToLower(); if (string.IsNullOrEmpty(type)) { type = "default"; } string configUrl = tabItem.GetAttribute("configUrl", string.Empty); string checkUrl = configUrl; if (checkUrl.IndexOf("?") >= 0) { checkUrl = checkUrl.Substring(0, checkUrl.IndexOf("?")); } if (type.Equals("default") && string.IsNullOrEmpty(checkUrl)) { checkUrl = "~/Apps/Shell/Pages/TreeSource.aspx"; configUrl = "~/Apps/Shell/Pages/TreeSource.aspx?tab=" + id; } if (File.Exists(Server.MapPath(checkUrl))) { switch (type) { case "default": ClientScript.RegisterStartupScript(this.Page, this.Page.GetType(), Guid.NewGuid().ToString("N"), string.Format("leftTemplate_AddMenuTab('{0}', '{1}', '{2}');", id, title, ResolveClientUrl(configUrl)), true); break; case "custom": break; default: break; } } dr["Title"] = title; dr["ImageUrl"] = imageUrl; dt.Rows.Add(dr); } TabItems.DataSource = dt.DefaultView; TabItems.DataBind(); RegisterScripts(); //Register navigation commands string profileId = ProfileManager.GetProfileIdByUser().ToString(); string userId = Mediachase.IBN.Business.Security.UserID.ToString(); IList <XmlCommand> list = XmlCommand.GetListNavigationCommands("", "", "", profileId, userId); CommandManager cm = CommandManager.GetCurrent(this.Page); foreach (XmlCommand cmd in list) { cm.AddCommand("", "", "", profileId, userId, cmd.CommandName); } }
/// <summary> /// 获取单个实体信息 /// </summary> /// <param name="oid">主键</param> /// <returns>单个实体信息</returns> public T GetSingle(Guid oid) { return(XmlCommand.From <T>(XmlCommandType.GetSingle, new { oid = oid }).ToSingle()); }
/// <summary> /// Handles the Load event of the Page control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param> protected void Page_Load(object sender, EventArgs e) { DataTable dt = new DataTable(); dt.Columns.Add(new DataColumn("Title", typeof(string))); dt.Columns.Add(new DataColumn("ImageUrl", typeof(string))); DataRow dr; IXPathNavigable navigable = XmlBuilder.GetXml(StructureType.Navigation); XPathNavigator tabs = navigable.CreateNavigator().SelectSingleNode("Navigation/Tabs"); foreach (XPathNavigator tabItem in tabs.SelectChildren(string.Empty, string.Empty)) { dr = dt.NewRow(); string title = UtilHelper.GetResFileString(tabItem.GetAttribute("text", string.Empty)); string id = tabItem.GetAttribute("id", string.Empty); CommandParameters param = new CommandParameters(id); param.CommandArguments = new Dictionary <string, string>(); param.CommandArguments.Add("permissions", tabItem.GetAttribute("permissions", string.Empty)); string enableHandler = String.Empty; if (!ProfileConfiguration.Instance.EnablePermissions) { enableHandler = tabItem.GetAttribute("enableHandler", string.Empty); } else { enableHandler = tabItem.GetAttribute("enableHandler2", string.Empty); } if (!String.IsNullOrEmpty(enableHandler)) { ICommandEnableHandler enHandler = (ICommandEnableHandler)AssemblyUtil.LoadObject(enableHandler); if (enHandler != null && !enHandler.IsEnable(sender, param)) { continue; } } string imageUrl = tabItem.GetAttribute("imageUrl", string.Empty); if (String.IsNullOrEmpty(imageUrl)) { imageUrl = "~/App_Themes/Default/Images/ext/default/s.gif"; } string type = tabItem.GetAttribute("contentType", string.Empty).ToLower(); if (String.IsNullOrEmpty(type)) { type = "default"; } string configUrl = tabItem.GetAttribute("configUrl", string.Empty); string checkUrl = configUrl; if (checkUrl.IndexOf("?") >= 0) { checkUrl = checkUrl.Substring(0, checkUrl.IndexOf("?")); } if (type.Equals("default") && String.IsNullOrEmpty(checkUrl)) { checkUrl = "~/Apps/Shell/Pages/TreeSource.aspx"; configUrl = "~/Apps/Shell/Pages/TreeSource.aspx?tab=" + id; } if (File.Exists(Server.MapPath(checkUrl))) { switch (type) { case "default": ClientScript.RegisterStartupScript(this.Page, this.Page.GetType(), Guid.NewGuid().ToString("N"), String.Format("leftTemplate_ECFAddMenuTab('{0}', '{1}', '{2}');", id, title, ResolveClientUrl(configUrl)), true); break; case "custom": break; default: break; } } dr["Title"] = title; dr["ImageUrl"] = imageUrl; dt.Rows.Add(dr); } TabItems.DataSource = dt.DefaultView; TabItems.DataBind(); RegisterScripts(); //Register navigation commands IList <XmlCommand> list = XmlCommand.GetListNavigationCommands("", "", ""); CommandManager cm = CommandManager.GetCurrent(this.Page); foreach (XmlCommand cmd in list) { cm.AddCommand("", "", "", cmd.CommandName); } }