Пример #1
0
        private static void FillTable(string objName, MDataTable dt)
        {
            string formatObjName = objName.Contains(" ") ? objName.Substring(objName.LastIndexOf(' ')).Trim() : objName;
            Dictionary <string, string> fieldTitleDic = GridConfig.FieldTitle;
            MDataColumn mdc  = DBTool.GetColumns(CrossDb.GetEnum(objName));
            MCellStruct cell = null;

            for (int i = 0; i < mdc.Count; i++)
            {
                cell = mdc[i];
                MDataRow row = dt.NewRow();
                row["ObjName"].Value   = formatObjName;
                row["Field"].Value     = cell.ColumnName;
                row["Title"].Value     = fieldTitleDic.ContainsKey(cell.ColumnName) ? fieldTitleDic[cell.ColumnName] : cell.ColumnName;
                row["Hidden"].Value    = i == 0;//隐藏主键
                row["Formatter"].Value = i == 0 ? "#" : "";
                row["OrderNum"].Value  = (i + 1) * 10;
                row["Width"].Value     = 100;//第一个主键列<10,则由图标个数*36 自动控制。
                row["Sortable"].Value  = i > 0;
                row["Import"].Value    = i > 0 && !cell.IsCanNull;
                row["Export"].Value    = true;
                row["Edit"].Value      = i > 0;
                row["Frozen"].Value    = i < 4;
                row["Align"].Value     = "center";
                row["DataType"].Value  = DataType.GetType(cell.SqlType).Name.ToLower() + "," + cell.MaxSize + "," + cell.Scale + "," + (cell.IsCanNull ? 0 : 1);
                if (i > 0)
                {
                    switch (DataType.GetGroup(cell.SqlType))
                    {
                    //case 1:
                    //    row["DataType"].Value = "int";
                    //    break;
                    case 2:
                        //row["DataType"].Value = "datetime";
                        row["Formatter"].Value = "dateFormatter";
                        break;

                    case 3:
                        //row["DataType"].Value = "bool";
                        row["Formatter"].Value = "boolFormatter";
                        break;

                    default:
                        //row["DataType"].Value = "string";
                        if (cell.MaxSize > 50)
                        {
                            row["Formatter"].Value = "stringFormatter";
                        }
                        break;
                    }
                }
                dt.Rows.Add(row);
            }
        }
Пример #2
0
        /// <summary>
        /// 读取数据库所有表
        /// </summary>
        /// <param name="key">关键字</param>
        /// <param name="filter">过滤条件值</param>
        /// <returns></returns>
        public static MDataTable Get(string key, string filter)
        {
            MDataTable dt = null;
            SortedDictionary <string, string> newDic = new SortedDictionary <string, string>();

            switch (key)
            {
            case "C_SYS_Table":
                if (!string.IsNullOrEmpty(filter))
                {
                    if (CrossDb.DbTables.ContainsKey(filter))
                    {
                        foreach (var item in CrossDb.DbTables[filter])
                        {
                            newDic.Add(item.Key, item.Key);
                        }
                    }
                }
                else
                {
                    foreach (var tableDic in CrossDb.DbTables)
                    {
                        foreach (var item in tableDic.Value)
                        {
                            newDic.Add(item.Key, item.Key);
                        }
                    }
                }
                break;

            case "C_SYS_Column":
                if (!string.IsNullOrEmpty(filter))
                {
                    MDataColumn mdc = DBTool.GetColumns(CrossDb.GetEnum(filter));
                    foreach (var item in mdc)
                    {
                        newDic.Add(item.ColumnName, item.ColumnName);
                    }
                }
                break;
            }
            dt = MDataTable.CreateFrom(newDic);
            if (dt != null)
            {
                dt.Columns[0].ColumnName = "value";
                dt.Columns[1].ColumnName = "text";
                if (dt.Columns.Count > 2)
                {
                    dt.Columns[2].ColumnName = "parent";
                }
            }
            return(dt);
        }
Пример #3
0
 public virtual void Delete()
 {
     using (MAction action = new MAction(CrossTableName))
     {
         action.BeginTransation();
         //dg.foreignKeys="TableA.ColumnNameA,TableB.ColumnNameB";
         string foreignKeys = Query <string>("foreignKeys");
         bool   result      = true;
         if (!string.IsNullOrEmpty(foreignKeys))//增加了外键删除
         {
             string[] items = foreignKeys.Split(',');
             foreach (string item in items)
             {
                 string[] kv = item.Split('.');
                 if (kv.Length == 2)
                 {
                     action.ResetTable(CrossDb.GetEnum(kv[0]));
                     result = action.Delete(GetWhereIn(kv[1]));
                     if (!result)
                     {
                         break;
                     }
                 }
             }
             if (result)
             {
                 action.ResetTable(CrossTableName);
             }
         }
         if (result)
         {
             result = action.Delete(GetID);//!string.IsNullOrEmpty(where) &&
         }
         if (!result)
         {
             action.RollBack();
         }
         action.EndTransation();
         if (result)
         {
             SetSuccess(LangConst.DelSuccess);
         }
         else
         {
             if (AppConfig.Debug.OpenDebugInfo)
             {
                 Log.WriteLogToTxt("Delete(): " + action.DebugInfo);
             }
             SetError(LangConst.DelError, action.DebugInfo);
         }
     }
 }
Пример #4
0
        public static Dictionary <string, string> GetTitleField(string tableName)
        {
            Dictionary <string, string> dic = new Dictionary <string, string>();
            MDataColumn mdc = DBTool.GetColumns(CrossDb.GetEnum(tableName));

            if (mdc.Count > 0)
            {
                foreach (MCellStruct item in mdc)
                {
                    string des = Convert.ToString(item.Description);
                    if (!string.IsNullOrEmpty(des))
                    {
                        des = des.Split(new char[] { ' ', ',', '(' })[0];
                        if (!dic.ContainsKey(des))
                        {
                            dic.Add(des, item.ColumnName);
                        }
                    }
                }
            }
            return(dic);
        }
Пример #5
0
        public virtual void Delete()
        {
            string ids = GetID;

            string[] values = null;
            string where = string.Empty;
            string     parentField = Query <string>("parentField");
            string     idField     = Query <string>("idField");
            MDataTable dt          = null;

            using (MAction action = new MAction(CrossTableName))
            {
                action.BeginTransation();

delChild:       //删除子节点循环处。

                //dg.foreignKeys="TableA.ColumnNameA,TableB.ColumnNameB";
                string foreignKeys = Query <string>("foreignKeys");
                bool result = true;
                if (!string.IsNullOrEmpty(foreignKeys))//增加了外键删除
                {
                    string[] items = foreignKeys.Split(',');
                    foreach (string item in items)
                    {
                        string[] kv = item.Split('.');
                        if (kv.Length == 2)
                        {
                            action.ResetTable(CrossDb.GetEnum(kv[0]));
                            result = action.Delete(GetWhereIn(kv[1], null, values));
                            if (!result)
                            {
                                break;
                            }
                        }
                    }
                    if (result)
                    {
                        action.ResetTable(CrossTableName);
                    }
                }
                if (result)
                {
                    //第一次,需要将ID转为idField指定的上级关联字段。
                    string pkName = action.Data.Columns.FirstPrimary.ColumnName;
                    if (string.IsNullOrEmpty(idField))
                    {
                        idField = pkName;
                    }
                    where = values == null ? ids : GetWhereIn(idField, null, values);

                    if (values == null && !string.IsNullOrEmpty(idField) && pkName.ToLower() != idField.ToLower())
                    {
                        action.SetSelectColumns(idField);
                        dt = action.Select(where);
                        if (dt.Rows.Count > 0)
                        {
                            values = dt.GetColumnItems <string>(0).ToArray();
                        }
                    }

                    result = action.Delete(where);
                }
                if (!result)
                {
                    action.RollBack();
                }
                else if (!string.IsNullOrEmpty(parentField) && !string.IsNullOrEmpty(idField))
                {
                    action.SetSelectColumns(idField);
                    dt = action.Select(GetWhereIn(parentField, null, values));
                    if (dt.Rows.Count > 0)
                    {
                        values = dt.GetColumnItems <string>(0).ToArray();
                        goto delChild;
                    }
                }
                action.EndTransation();
                if (result)
                {
                    SetSuccess(LangConst.DeleteSuccess);
                }
                else
                {
                    if (AppConfig.Debug.OpenDebugInfo)
                    {
                        Log.WriteLogToTxt("Delete(): " + action.DebugInfo);
                    }
                    SetError(LangConst.DeleteError, action.DebugInfo);
                }
            }
        }