public object GetNodes(Dictionary <string, object> dicParas) { try { string errMsg = string.Empty; string merchId = dicParas.ContainsKey("merchId") ? dicParas["merchId"].ToString() : string.Empty; string dictKey = dicParas.ContainsKey("dictKey") ? dicParas["dictKey"].ToString() : string.Empty; XCCloudUserTokenModel userTokenKeyModel = (XCCloudUserTokenModel)dicParas[Constant.XCCloudUserTokenModel]; if (userTokenKeyModel.LogType == (int)RoleType.MerchUser) { merchId = userTokenKeyModel.DataModel.MerchID; } string sql = " exec SP_DictionaryNodes @MerchID,@DictKey,@RootID output "; SqlParameter[] parameters = new SqlParameter[3]; parameters[0] = new SqlParameter("@MerchID", merchId); parameters[1] = new SqlParameter("@DictKey", dictKey); parameters[2] = new SqlParameter("@RootID", 0); parameters[2].Direction = System.Data.ParameterDirection.Output; System.Data.DataSet ds = XCCloudBLL.ExecuteQuerySentence(sql, parameters); if (ds.Tables.Count == 0) { errMsg = "没有找到节点信息"; return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg)); } var dictionaryResponse = Utils.GetModelList <DictionaryResponseModel>(ds.Tables[0]).ToList(); int rootId = 0; int.TryParse(parameters[2].Value.ToString(), out rootId); //实例化一个根节点 DictionaryResponseModel rootRoot = new DictionaryResponseModel(); rootRoot.ID = rootId; TreeHelper.LoopToAppendChildren(dictionaryResponse, rootRoot); return(ResponseModelFactory.CreateSuccessModel(isSignKeyReturn, rootRoot.Children)); } catch (Exception e) { return(ResponseModelFactory.CreateReturnModel(isSignKeyReturn, Return_Code.F, e.Message)); } }
public static void LoopToAppendChildren(List <DictionaryResponseModel> dict_System, DictionaryResponseModel curItem) { var subItems = dict_System.Where(ee => ee.PID.Value == curItem.ID).ToList(); curItem.Children = new List <DictionaryResponseModel>(); curItem.Children.AddRange(subItems); foreach (var subItem in subItems) { LoopToAppendChildren(dict_System, subItem); } }
public object GetMerchInfo(Dictionary <string, object> dicParas) { try { string errMsg = string.Empty; string merchId = dicParas.ContainsKey("merchId") ? dicParas["merchId"].ToString() : string.Empty; XCCloudUserTokenModel userTokenKeyModel = (XCCloudUserTokenModel)dicParas[Constant.XCCloudUserTokenModel]; string currentMerchId = userTokenKeyModel.DataModel.MerchID; #region 商户信息和功能菜单 //返回商户信息 string sql = "select * from Base_MerchantInfo where MerchID=@MerchID"; SqlParameter[] parameters = new SqlParameter[1]; if (string.IsNullOrEmpty(merchId)) { parameters[0] = new SqlParameter("@MerchID", currentMerchId); } else { parameters[0] = new SqlParameter("@MerchID", merchId); } System.Data.DataSet ds = XCCloudBLL.ExecuteQuerySentence(sql, parameters); if (ds.Tables.Count != 1) { errMsg = "获取数据异常"; return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg)); } //返回功能菜单信息 var base_MerchInfoModel = Utils.GetModelList <Base_MerchInfoModel>(ds.Tables[0]).FirstOrDefault() ?? new Base_MerchInfoModel(); sql = " exec SelectMerchFunction @MerchID"; parameters = new SqlParameter[1]; if (string.IsNullOrEmpty(merchId)) { parameters[0] = new SqlParameter("@MerchID", currentMerchId); } else { parameters[0] = new SqlParameter("@MerchID", merchId); } ds = XCCloudBLL.ExecuteQuerySentence(sql, parameters); if (ds.Tables.Count != 1) { errMsg = "获取数据异常"; return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg)); } //实例化一个根节点 Base_MerchFunctionModel rootRoot = new Base_MerchFunctionModel(); rootRoot.ParentID = 0; TreeHelper.LoopToAppendChildren(Utils.GetModelList <Base_MerchFunctionModel>(ds.Tables[0]), rootRoot); base_MerchInfoModel.MerchFunction = rootRoot.Children; #endregion if (string.IsNullOrEmpty(merchId)) { #region 商户类型列表 sql = " exec SP_DictionaryNodes @MerchID,@DictKey,@RootID output "; parameters = new SqlParameter[3]; parameters[0] = new SqlParameter("@MerchID", string.Empty); parameters[1] = new SqlParameter("@DictKey", "商户类别"); parameters[2] = new SqlParameter("@RootID", 0); parameters[2].Direction = System.Data.ParameterDirection.Output; ds = XCCloudBLL.ExecuteQuerySentence(sql, parameters); if (ds.Tables.Count == 0) { errMsg = "没有找到节点信息"; return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg)); } var dictionaryResponse = Utils.GetModelList <DictionaryResponseModel>(ds.Tables[0]); //代理商不能创建代理商 if (base_MerchInfoModel.MerchType == (int)MerchType.Agent) { dictionaryResponse = dictionaryResponse.Where(p => !p.DictValue.Equals(Convert.ToString(MerchType.Agent), StringComparison.OrdinalIgnoreCase)).ToList(); } //实例化一个根节点 int rootId = 0; int.TryParse(parameters[2].Value.ToString(), out rootId); var rootRoot2 = new DictionaryResponseModel(); rootRoot2.ID = rootId; TreeHelper.LoopToAppendChildren(dictionaryResponse, rootRoot2); base_MerchInfoModel.MerchTypes = rootRoot2.Children; #endregion } return(ResponseModelFactory.CreateSuccessModel(isSignKeyReturn, base_MerchInfoModel)); } catch (Exception e) { return(ResponseModelFactory.CreateReturnModel(isSignKeyReturn, Return_Code.F, e.Message)); } }