Exemple #1
0
        //[ActionKey("View")]
        /// <summary>
        /// 获取下拉框Json结果集(统一处理)
        /// </summary>
        /// <returns></returns>
        public void GetCombobox()
        {
            string itemJson = Query <string>("sys_json");

            if (!string.IsNullOrEmpty(itemJson))
            {
                List <ComboboxItem> boxes = JsonHelper.ToList <ComboboxItem>(itemJson);
                JsonHelper          json  = new JsonHelper();
                if (boxes.Count > 0)
                {
                    List <MDataTable> dtList = new List <MDataTable>();
                    StringBuilder     sb     = new StringBuilder();
                    string            value  = null;
                    for (int i = 0; i < boxes.Count; i++)
                    {
                        ComboboxItem item = boxes[i];
                        string       code = SqlCode.GetCode(item.ObjName);
                        if (code != item.ObjName)
                        {
                            #region 核心处理
                            var sql = SqlCode.GetCode(item.ObjName).ToLower();
                            //格式化请求参数
                            string key   = "@text";
                            int    index = sql.IndexOf(key);
                            if (index > -1)
                            {
                                value = Query <string>("q");                                            //easyui远程传递参数
                                if (string.IsNullOrEmpty(value) && sql.IndexOf('=', index - 5, 5) > -1) //处理成1=1,同时有=号
                                {
                                    int    end   = index + key.Length;
                                    string temp  = sql.Substring(0, index - 5);
                                    int    start = temp.LastIndexOf(' ');
                                    sql = sql.Replace(sql.Substring(start + 1, end - start - 1), "1=1");
                                }
                                else
                                {
                                    sql = sql.Replace(key, value);
                                }
                            }
                            sb.Append(sql + ";");
                            #endregion
                        }
                        else
                        {
                            #region 找不到,则移除。
                            boxes.RemoveAt(i);
                            //从程序里找。
                            MDataTable dt = Combobox.Get(item.ObjName, Query <string>("q"));
                            if (dt != null)
                            {
                                dtList.Insert(0, dt);
                                boxes.Insert(0, item);
                            }
                            else
                            {
                                i--;
                            }
                            #endregion
                        }
                    }
                    if (sb.Length > 0)
                    {
                        string sql = sb.ToString().TrimEnd(';');
                        using (MProc proc = new MProc(null, CrossDb.GetConn(sql)))
                        {
                            if (proc.DalType == DalType.MsSql)
                            {
                                proc.ResetProc(sql);
                                dtList.AddRange(proc.ExeMDataTableList());
                            }
                            else
                            {
                                string[] items = sql.Split(';');
                                foreach (string item in items)
                                {
                                    proc.ResetProc(item);
                                    dtList.Add(proc.ExeMDataTable());
                                }
                            }
                        }
                    }
                    if (dtList.Count == 1 && Query <string>("q", null) != null)
                    {
                        jsonResult = dtList[0].ToJson(false, false, true);
                        return;
                    }
                    for (int i = 0; i < dtList.Count; i++)
                    {
                        json.Add(boxes[i].ObjName, dtList[i].Rows.Count > 0 ? dtList[i].ToJson(false, false, true) : "[]", true);
                        if (!string.IsNullOrEmpty(boxes[i].Parent))
                        {
                            json.Add("Target", boxes[i].Parent);
                        }
                        json.AddBr();
                    }
                }
                jsonResult = json.ToString(true);
            }
        }
Exemple #2
0
        //[ActionKey("View")]
        /// <summary>
        /// 获取下拉框Json结果集(统一处理)
        /// </summary>
        /// <returns></returns>
        public void GetCombobox()
        {
            string itemJson = Query <string>("sys_json");

            if (!string.IsNullOrEmpty(itemJson))
            {
                List <ComboboxItem> boxes = JsonHelper.ToList <ComboboxItem>(itemJson);
                JsonHelper          json  = new JsonHelper();
                if (boxes.Count > 0)
                {
                    List <MDataTable> dtList = new List <MDataTable>();
                    StringBuilder     sb     = new StringBuilder();
                    for (int i = 0; i < boxes.Count; i++)
                    {
                        ComboboxItem item = boxes[i];
                        string       code = SqlCode.GetCode(item.ObjName);
                        if (code != item.ObjName)
                        {
                            #region 核心处理
                            var sql = SqlCode.GetCode(item.ObjName);//已经处理过系统参数和Post参数
                            sql = WebHelper.ReplacePara(sql, "@para", item.Para);
                            sql = WebHelper.ReplacePara(sql, "@parent", item.Parent);

                            sb.Append(sql + ";");
                            #endregion
                        }
                        else
                        {
                            #region 找不到,则移除。
                            boxes.RemoveAt(i);
                            //从程序里找。
                            MDataTable dt = Combobox.Get(item.ObjName, Query <string>("q", item.Para));
                            if (dt != null)
                            {
                                dtList.Insert(0, dt);
                                boxes.Insert(0, item);
                            }
                            else
                            {
                                i--;
                            }
                            #endregion
                        }
                    }
                    if (sb.Length > 0)
                    {
                        string sql = sb.ToString().TrimEnd(';');
                        using (MProc proc = new MProc(null, CrossDb.GetConn(sql)))
                        {
                            if (proc.DalType == DalType.MsSql)
                            {
                                proc.ResetProc(sql);
                                dtList.AddRange(proc.ExeMDataTableList());
                            }
                            else
                            {
                                string[] items = sql.Split(';');
                                foreach (string item in items)
                                {
                                    proc.ResetProc(item);
                                    dtList.Add(proc.ExeMDataTable());
                                }
                            }
                        }
                    }
                    if (dtList.Count == 1 && Query <string>("q", null) != null)
                    {
                        jsonResult = dtList[0].ToJson(false, false, RowOp.None, true);
                        return;
                    }
                    for (int i = 0; i < dtList.Count; i++)
                    {
                        json.Add(boxes[i].ObjName, dtList[i].Rows.Count > 0 ? dtList[i].ToJson(false, false, RowOp.None, true) : "[]", true);
                    }
                    json.AddBr();
                }
                jsonResult = json.ToString();
            }
        }