Beispiel #1
0
        /// <summary>
        /// 获取框架文件对应的SQL语句 By CYQ
        /// </summary>
        public void GetSQL()
        {
            string sql    = SQLCode.GetSourceCode(ObjName);
            bool   result = !string.IsNullOrEmpty(sql);

            jsonResult = JsonHelper.OutResult(result, sql);
        }
Beispiel #2
0
        /// <summary>
        /// 保存框架文件对应的SQL语句 By CYQ
        /// </summary>
        public void SaveSQL()
        {
            string msg;
            bool   result = SQLCode.SaveSourceCode(ObjName, Query <string>("sys_code"), out msg);

            jsonResult = JsonHelper.OutResult(result, result ? "保存成功!" : "保存失败!" + msg);
        }
Beispiel #3
0
 /// <summary>
 /// 导入时,把中文列头翻译成英文列头。
 /// </summary>
 public static Dictionary <string, string> FormatterTitle(MDataTable dt, MDataRow info, string objName)
 {
     if (info == null)
     {
         return(GridConfig.SetHeaderField(dt, objName));
     }
     else
     {
         Dictionary <string, string> formatDic = new Dictionary <string, string>();
         MDataTable config = GetExcelInfo(info.Get <string>(0));
         if (config != null)
         {
             //附加自定义列。
             foreach (var configRow in config.Rows)
             {
                 string formatter = configRow.Get <string>(Config_ExcelInfo.Formatter);
                 if (!string.IsNullOrEmpty(formatter) && formatter[0] != '#')//增加默认值的列。
                 {
                     string excelName = configRow.Get <string>(Config_ExcelInfo.ExcelName);
                     if (!dt.Columns.Contains(excelName))
                     {
                         MCellStruct ms = new MCellStruct(excelName, System.Data.SqlDbType.NVarChar);
                         ms.TableName = configRow.Get <string>("TableName");
                         dt.Columns.Insert(dt.Columns.Count - 1, ms);
                     }
                 }
             }
             MDataRow row;
             foreach (MCellStruct item in dt.Columns)
             {
                 row = config.FindRow("ExcelName='" + item.ColumnName + "'");
                 if (row == null && item.ColumnName.IndexOf('_') > 0) // 兼容只找一级的映射列。
                 {
                     string columnName = item.ColumnName.Split('_')[0];
                     row = config.FindRow("ExcelName='" + columnName + "'");
                 }
                 if (row != null)
                 {
                     string field = row.Get <string>("Field");
                     if (string.IsNullOrEmpty(field))
                     {
                         continue;
                     }
                     if (string.Compare(item.ColumnName, field, StringComparison.OrdinalIgnoreCase) != 0)
                     {
                         item.Description = item.ColumnName;//把中文列名放到描述里。
                         item.TableName   = row.Get <string>("TableName");
                         int index = dt.Columns.GetIndex(field);
                         if (index < 0)
                         {
                             item.ColumnName = field;//
                         }
                         else // 字段同名
                         {
                             item.ColumnName = item.TableName + "." + field;
                             //修改上一个,也增加表名。
                             dt.Columns[index].ColumnName = dt.Columns[index].TableName + "." + dt.Columns[index].ColumnName;
                         }
                     }
                     string formatter = row.Get <string>("Formatter");
                     if (!string.IsNullOrEmpty(formatter)) // 需要格式化的项
                     {
                         if (formatter.Length > 2 && formatter[0] == '#')
                         {
                             //item.SqlType = System.Data.SqlDbType.NVarChar;//重置数据类型(int数据将格式成文本)
                             formatDic.Add(item.ColumnName, formatter.Substring(1).Split(new string[] { "=>" }, StringSplitOptions.None)[0]);
                         }
                         else
                         {
                             item.DefaultValue = SQLCode.FormatPara(formatter);//如果不是#开头的,设置为默认值。
                         }
                     }
                 }
             }
         }
         return(formatDic);
     }
 }
Beispiel #4
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(sql, CrossDb.GetConn(sql)))
                        {
                            if (proc.DalType == DalType.MsSql)
                            {
                                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 = string.IsNullOrEmpty(json.ToString()) ? "[]" : json.ToString(true);
            }
        }