Пример #1
0
        override protected void Show(IDialogVisualizerService windowService, IVisualizerObjectProvider objectProvider)
        {
            string     json = objectProvider.GetObject() as string;
            MDataTable dt   = MDataTable.CreateFrom(JsonHelper.ToJson(json));

            FormCreate.BindTable(windowService, dt, null);
        }
Пример #2
0
        static void TestListDictionary()
        {
            string        abc = "aaaaaaaaaabc";
            List <string> s   = "2,2,3,2,4,3,1,2".Split(',').OrderBy(p => p).Distinct().ToList();
            Dictionary <string, object> dic = new Dictionary <string, object>();

            dic.Add("1", "a");
            dic.Add("2", s);
            dic.Add("3", "a");
            dic.Add("4", "a");
            string     json = abc;
            MDataTable dt   = MDataTable.CreateFrom(dic);
            Entity     e    = new Entity();

            e.ID   = 1111;
            e.Name = "b";
            object o = e;

            System.Object ooo = new object();
            ooo = e;
            MDataRow row = MDataRow.CreateFrom(e);
            ObservableCollection <string> sa = new ObservableCollection <string>(s);

            Console.Read();
        }
Пример #3
0
        /// <summary>
        /// Get MDataTables
        /// </summary>
        public List <MDataTable> ExeMDataTableList()
        {
            CheckDisposed();
            AopResult aopResult = SetAopResult(AopEnum.ExeMDataTableList);

            if (aopResult == AopResult.Return)
            {
                return(_aop.Para.TableList);
            }
            else
            {
                if (aopResult != AopResult.Break)
                {
                    List <MDataTable> dtList = new List <MDataTable>();
                    switch (dalHelper.DataBaseType)
                    {
                    case DataBaseType.Txt:
                    case DataBaseType.Xml:
                    case DataBaseType.Oracle:
                        if (_isProc && dalHelper.DataBaseType == DataBaseType.Oracle)
                        {
                            goto isProc;
                        }
                        foreach (string sql in _procName.TrimEnd(';').Split(';'))
                        {
                            MDataTable dt = dalHelper.ExeDataReader(sql, false);
                            if (dt != null)
                            {
                                dtList.Add(dt);
                            }
                        }
                        break;

                    default:
isProc:
                        DbDataReader reader = dalHelper.ExeDataReader(_procName, _isProc);
                        if (reader != null)
                        {
                            do
                            {
                                dtList.Add(MDataTable.CreateFrom(reader));
                            }while (reader.NextResult());
                            reader.Close();
                            reader.Dispose();
                            reader = null;
                        }
                        break;
                    }
                    _aop.Para.TableList = dtList;
                    _aop.Para.IsSuccess = dtList.Count > 0;
                }
                if (aopResult != AopResult.Default)
                {
                    _aop.End(AopEnum.ExeMDataTableList);
                }
                return(_aop.Para.TableList);
            }
        }
Пример #4
0
        /// <summary>
        /// 批量向数据库写入瓦片数据xyz信息
        /// </summary>
        /// <param name="listdata"></param>
        /// <returns></returns>
        public static bool insertDatas(List <DiTu_DB> listdata)
        {
            using (MDataTable dt2 = MDataTable.CreateFrom(listdata))
            {
                dt2.TableName = TableNames.dt.ToString();

                dt2.Conn = ConnectStr;

                return(dt2.AcceptChanges(AcceptOp.InsertWithID));
            }
        }
Пример #5
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);
        }
Пример #6
0
        /// <summary>
        /// 保存目录列表
        /// </summary>
        /// <param name="menulist"></param>
        /// <returns></returns>
        public bool SaveNovelContents(List <NovelContent> menulist)
        {
            int maxid = GetNovelContentMaxId();

            foreach (var menu in menulist)
            {
                menu.Id = maxid++;
            }
            var dt = MDataTable.CreateFrom(menulist);

            dt.TableName = menulist[0].TableName;
            return(dt.AcceptChanges(AcceptOp.Insert));
        }
Пример #7
0
        /// <summary>
        /// 批量更新瓦片数据
        /// </summary>
        /// <param name="listdata"></param>
        /// <returns></returns>
        public static bool updateDatas(List <DiTu_DB> listdata)
        {
            using (MDataTable dt2 = MDataTable.CreateFrom(listdata))
            {
                dt2.SetState(2);

                dt2.TableName = TableNames.dt.ToString();

                dt2.Conn = ConnectStr;

                return(dt2.AcceptChanges(AcceptOp.Update));
            }
        }
Пример #8
0
        /// <summary>
        /// 执行的语句有多个结果集返回(库此方法不支持文本数据和AOP)
        /// </summary>
        /// <returns></returns>
        public List <MDataTable> ExeMDataTableList()
        {
            CheckDisposed();
            AopResult aopResult = SetAopResult(AopEnum.ExeMDataTableList);

            if (aopResult == AopResult.Return)
            {
                return(_aop.Para.TableList);
            }
            else
            {
                if (aopResult != AopResult.Break)
                {
                    List <MDataTable> dtList = new List <MDataTable>();
                    switch (dalHelper.dalType)
                    {
                    case DalType.Txt:
                    case DalType.Xml:
                        foreach (string sql in _procName.Split(';'))
                        {
                            _noSqlCommand.CommandText = sql;
                            dtList.Add(_noSqlCommand.ExeMDataTable());
                        }
                        break;

                    default:
                        DbDataReader reader = dalHelper.ExeDataReader(_procName, _isProc);

                        if (reader != null)
                        {
                            do
                            {
                                dtList.Add(MDataTable.CreateFrom(reader));
                            }while (reader.NextResult());
                            reader.Close();
                            reader.Dispose();
                            reader = null;
                        }
                        break;
                    }
                    _aop.Para.TableList = dtList;
                }
                if (aopResult != AopResult.Default)
                {
                    _aop.End(AopEnum.ExeMDataTableList);
                }
                return(_aop.Para.TableList);
            }
        }
Пример #9
0
        /// <summary>
        /// 类型转换(精准强大)
        /// </summary>
        /// <param name="value">值处理</param>
        /// <param name="t">类型</param>
        /// <returns></returns>
        public static object ChangeType(object value, Type t)
        {
            if (t == null)
            {
                return(null);
            }
            string strValue = Convert.ToString(value);

            if (t.IsGenericType && t.Name.StartsWith("Nullable"))
            {
                t = Nullable.GetUnderlyingType(t);
                if (strValue == "")
                {
                    return(null);
                }
            }
            if (t.Name == "String")
            {
                return(strValue);
            }
            if (strValue == "")
            {
                return(Activator.CreateInstance(t));
            }
            else if (t.IsValueType)
            {
                if (t.Name == "Guid")
                {
                    return(new Guid(strValue));
                }
                else if (t.Name.StartsWith("Int") && strValue.IndexOf('.') > -1)
                {
                    strValue = strValue.Split('.')[0];
                }
                return(Convert.ChangeType(strValue, t));
            }
            else
            {
                switch (GetSystemType(ref t))
                {
                case SysType.Custom:
                    return(MDataRow.CreateFrom(strValue).ToEntity(t));

                case SysType.Generic:
                    return(MDataTable.CreateFrom(strValue).ToList(t));
                }
                return(Convert.ChangeType(value, t));
            }
        }
Пример #10
0
        /// <summary>
        /// 接收Post过来的Json权限
        /// </summary>
        /// <returns></returns>
        private MDataTable GetTable(string roleID)
        {
            MDataTable rowAction = new MDataTable(TableNames.Sys_RoleAction.ToString());

            rowAction.Columns.Add("RoleID", SqlDbType.NVarChar);
            rowAction.Columns.Add("MenuID", SqlDbType.NVarChar);
            rowAction.Columns.Add("ActionID", SqlDbType.NVarChar);
            MDataTable dt;

            if (Query <string>("all") == "1")
            {
                if (UserAuth.IsSuperAdmin)
                {
                    dt = SysMenu.MenuTable;
                }
                else
                {
                    dt = SysMenu.GetUserMenu(true);
                }
            }
            else
            {
                dt = MDataTable.CreateFrom(Query <string>("data"));
            }
            if (dt != null && dt.Rows.Count > 0)
            {
                string menuID = string.Empty;
                foreach (MDataRow row in dt.Rows)
                {
                    menuID = row.Get <string>("MenuID");
                    if (!string.IsNullOrEmpty(menuID))
                    {
                        string[] ActionIDs = row.Get <string>("ActionIDs", "").Split(',');
                        foreach (string actionID in ActionIDs)
                        {
                            if (!string.IsNullOrEmpty(actionID))
                            {
                                rowAction.NewRow(true).Set(0, roleID).Set(1, menuID).Set(2, actionID);
                            }
                        }
                    }
                }
            }
            return(rowAction);
        }
Пример #11
0
        public override void GetData(object target, System.IO.Stream outgoingData)
        {
            MDataTable dt = null;

            if (target is MDataTable)
            {
                dt = target as MDataTable;
            }
            else if (target is NameObjectCollectionBase)
            {
                dt = MDataTable.CreateFrom(target as NameObjectCollectionBase);
            }
            else if (target is IEnumerable)
            {
                dt = MDataTable.CreateFrom(target as IEnumerable);
            }
            base.GetData(Format(dt), outgoingData);
        }
Пример #12
0
        private void btnTo_Click(object sender, EventArgs e)
        {
            StringBuilder sb   = new StringBuilder();
            string        json = dt.ToJson();

            sb.AppendLine("ToJson:" + json);
            MDataTable t = MDataTable.CreateFrom(json);

            sb.AppendLine("从Josn还原了------------------");
            string xml = t.ToXml();

            sb.AppendLine("ToXml:" + xml);
            t = MDataTable.CreateFrom(xml);
            sb.AppendLine("从Xml还原了--------------------");

            sb.AppendLine("还可以和List<T>,Dictionary,ArrayList,HasTable等几乎所有的常用类或数组交互");

            rtxtText.Text = sb.ToString();
        }
Пример #13
0
        public string GetExcelMapping()
        {
            MDataRow row     = ExcelConfig.GetExcelRow(Query <string>("ID"));
            string   objName = row.Get <string>(Config_Excel.ExcelName);

            string[] TableNames             = row.Get <string>(Config_Excel.TableNames).Split(',');
            Dictionary <string, string> dic = new Dictionary <string, string>();
            JsonHelper js = new JsonHelper();

            foreach (string name in TableNames)
            {
                MDataColumn mdc = DBTool.GetColumns(name);
                js.Add(name, GetJson(mdc), true);
                dic.Add(name, name);
            }
            JsonHelper jh = new JsonHelper();

            jh.Add("objName", objName);
            jh.Add("arrColumns", js.ToString(false));
            jh.Add("arrTables", MDataTable.CreateFrom(dic).ToJson(false, false));
            return(jh.ToString());
        }
Пример #14
0
        /// <summary>
        /// 下载完成事件
        /// </summary>
        /// <param name="menu"></param>
        private void CompleteEvent(NovelContent menu)
        {
            if (!IsDownCompleted && (waitingList.Count == CompletedCount))
            {
                IsDownCompleted = true;
                Console.WriteLine(string.Format("下载完成-> {0}//{1}", waitingList.Count, CompletedCount));

                if (successList.Count > 0)
                {
                    //更新已下载的章节
                    var dt = MDataTable.CreateFrom(successList);
                    dt.TableName = successList[0].TableName;
                    dt.AcceptChanges(AcceptOp.Update);
                    Console.WriteLine(string.Format("更新保存-> {0}//{1}", successList.Count, CompletedCount));
                    this.Invoke(new EventHandler(delegate { UpdateResult(menu.Id, string.Format("更新保存 {0}", menu.Title, Thread.CurrentThread.Name)); }));
                    //this.Invoke(new Action<int, string>(UpdateResult), menu.Id, string.Format("更新保存 {0}", menu.Title, Thread.CurrentThread.Name));
                    //eventX.Set();
                }

                //MessageBox.Show(arg2, "提示");
            }
        }
Пример #15
0
        /// <summary>
        /// 类型转换(精准强大)
        /// </summary>
        /// <param name="value">值处理</param>
        /// <param name="t">类型</param>
        /// <returns></returns>
        public static object ChangeType(object value, Type t)
        {
            if (t == null)
            {
                return(null);
            }
            if (t.FullName == "System.Type")
            {
                return((Type)value);
            }
            string strValue = Convert.ToString(value);

            if (t.IsGenericType && t.Name.StartsWith("Nullable"))
            {
                t = Nullable.GetUnderlyingType(t);
                if (strValue == "")
                {
                    return(null);
                }
            }
            if (t.Name == "String")
            {
                if (value is byte[])
                {
                    return(Convert.ToBase64String((byte[])value));
                }
                return(strValue);
            }
            if (t.FullName == "System.Text.StringBuilder")
            {
                return(value as StringBuilder);
            }
            if (t.FullName == "System.Text.Encoding")
            {
                return(value as Encoding);
            }
            if (strValue == "")
            {
                return(Activator.CreateInstance(t));
            }
            else if (t.IsValueType)
            {
                if (t.Name == "DateTime")
                {
                    switch (strValue.ToLower().TrimEnd(')', '('))
                    {
                    case "now":
                    case "getdate":
                    case "current_timestamp":
                        return(DateTime.Now);
                    }
                    if (DateTime.Parse(strValue) == DateTime.MinValue)
                    {
                        return((DateTime)SqlDateTime.MinValue);
                    }
                    return(Convert.ChangeType(value, t));//这里用value,避免丢失毫秒
                }
                if (t.Name == "Guid")
                {
                    if (strValue == SqlValue.Guid || strValue.StartsWith("newid"))
                    {
                        return(Guid.NewGuid());
                    }
                    return(new Guid(strValue));
                }
                else if (t.Name.StartsWith("Int"))
                {
                    switch (strValue.ToLower())
                    {
                    case "true":
                        return(1);

                    case "false":
                        return(0);
                    }
                    if (strValue.IndexOf('.') > -1)
                    {
                        strValue = strValue.Split('.')[0];
                    }
                    else if (value.GetType().IsEnum)
                    {
                        return((int)value);
                    }
                }
                else if (t.Name == "Double" || t.Name == "Single")
                {
                    switch (strValue.ToLower())
                    {
                    case "infinity":
                    case "正无穷大":
                        return(double.PositiveInfinity);

                    case "-infinity":
                    case "负无穷大":
                        return(double.NegativeInfinity);
                    }
                }
                else if (t.Name == "Boolean")
                {
                    switch (strValue.ToLower())
                    {
                    case "yes":
                    case "true":
                    case "1":
                    case "on":
                    case "是":
                        return(true);

                    case "no":
                    case "false":
                    case "0":
                    case "":
                    case "否":
                    default:
                        return(false);
                    }
                }
                else if (t.IsEnum)
                {
                    return(Enum.Parse(t, strValue, true));
                }
                return(Convert.ChangeType(strValue, t));
            }
            else
            {
                Type valueType = value.GetType();
                //if(valueType.IsEnum && t.is)

                if (valueType.FullName != t.FullName)
                {
                    switch (ReflectTool.GetSystemType(ref t))
                    {
                    case SysType.Custom:

                        return(MDataRow.CreateFrom(strValue).ToEntity(t));

                    case SysType.Generic:
                        if (t.Name.StartsWith("List"))
                        {
                            return(MDataTable.CreateFrom(strValue).ToList(t));
                        }
                        break;

                    case SysType.Array:
                        if (t.Name == "Byte[]")
                        {
                            if (valueType.Name == "String")
                            {
                                return(Convert.FromBase64String(strValue));
                            }
                            using (MemoryStream ms = new MemoryStream())
                            {
                                new BinaryFormatter().Serialize(ms, value);
                                return(ms.ToArray());
                            }
                        }
                        break;
                    }
                }
                return(Convert.ChangeType(value, t));
            }
        }
Пример #16
0
        private static CacheManage _MemCache = CacheManage.Instance;   //有可能使用MemCache操作

        internal static bool GetCache(AopEnum action, AopInfo aopInfo) //Begin
        {
            switch (action)
            {
            case AopEnum.ExeNonQuery:
            case AopEnum.Insert:
            case AopEnum.Update:
            case AopEnum.Delete:
                return(false);
            }
            if (!IsCanOperateCache(aopInfo))
            {
                return(false);
            }
            string baseKey = GetBaseKey(aopInfo);
            //查看是否通知我移除
            string key = GetKey(action, aopInfo, baseKey);
            object obj = _MemCache.Get(key);

            switch (action)
            {
            case AopEnum.ExeMDataTableList:
                if (obj != null)
                {
                    List <MDataTable>           list = new List <MDataTable>();
                    Dictionary <string, string> jd   = JsonHelper.Split(obj.ToString());
                    if (jd != null && jd.Count > 0)
                    {
                        foreach (KeyValuePair <string, string> item in jd)
                        {
                            list.Add(MDataTable.CreateFrom(item.Value));
                        }
                    }
                    aopInfo.TableList = list;
                }
                break;

            case AopEnum.Select:
            case AopEnum.ExeMDataTable:
                if (obj != null)
                {
                    aopInfo.Table = MDataTable.CreateFrom(obj.ToString());
                }
                break;

            case AopEnum.ExeScalar:
                if (obj != null)
                {
                    aopInfo.ExeResult = obj;
                }
                break;

            case AopEnum.Fill:
                if (obj != null)
                {
                    MDataRow row = obj as MDataRow;
                    if (_MemCache.CacheType == CacheType.LocalCache)
                    {
                        row = row.Clone();
                    }
                    aopInfo.Row       = row;
                    aopInfo.IsSuccess = true;
                }
                break;

            case AopEnum.GetCount:
                if (obj != null)
                {
                    aopInfo.RowCount = int.Parse(obj.ToString());
                }
                break;

            case AopEnum.Exists:
                if (obj != null)
                {
                    aopInfo.ExeResult = obj;
                }
                break;
            }
            baseKey = key = null;
            return(obj != null);
        }
Пример #17
0
        /// <summary>
        /// 类型转换(精准强大)
        /// </summary>
        /// <param name="value">值处理</param>
        /// <param name="t">类型</param>
        /// <returns></returns>
        public static object ChangeType(object value, Type t)
        {
            if (t == null)
            {
                return(null);
            }
            if (t.FullName == "System.Type")
            {
                return((Type)value);
            }
            string strValue = Convert.ToString(value);

            if (t.IsGenericType && t.Name.StartsWith("Nullable"))
            {
                t = Nullable.GetUnderlyingType(t);
                if (strValue == "")
                {
                    return(null);
                }
            }
            if (t.Name == "String")
            {
                return(strValue);
            }
            if (t.FullName == "System.Text.StringBuilder")
            {
                return(value as StringBuilder);
            }
            if (t.FullName == "System.Text.Encoding")
            {
                return(value as Encoding);
            }
            if (strValue == "")
            {
                return(Activator.CreateInstance(t));
            }
            else if (t.IsValueType)
            {
                if (t.Name == "DateTime")
                {
                    return(Convert.ChangeType(value, t));//这里用value,避免丢失毫秒
                }
                if (t.Name == "Guid")
                {
                    return(new Guid(strValue));
                }
                else if (t.Name.StartsWith("Int") && strValue.IndexOf('.') > -1)
                {
                    strValue = strValue.Split('.')[0];
                }
                else if (t.Name == "Boolean")
                {
                    switch (strValue.ToLower())
                    {
                    case "yes":
                    case "true":
                    case "1":
                    case "on":
                    case "是":
                        return(true);

                    case "no":
                    case "false":
                    case "0":
                    case "":
                    case "否":
                    default:
                        return(false);
                    }
                }
                return(Convert.ChangeType(strValue, t));
            }
            else
            {
                if (strValue != t.FullName)
                {
                    switch (GetSystemType(ref t))
                    {
                    case SysType.Custom:
                        return(MDataRow.CreateFrom(strValue).ToEntity(t));

                    case SysType.Generic:
                        if (t.Name.StartsWith("List"))
                        {
                            return(MDataTable.CreateFrom(strValue).ToList(t));
                        }
                        break;

                    case SysType.Array:
                        if (t.Name == "Byte[]" && value.GetType().Name != t.Name)
                        {
                            using (MemoryStream ms = new MemoryStream())
                            {
                                new BinaryFormatter().Serialize(ms, value);
                                return(ms.ToArray());
                            }
                        }
                        break;
                    }
                }
                return(Convert.ChangeType(value, t));
            }
        }
Пример #18
0
        /// <summary>
        /// 类型转换(精准强大)
        /// </summary>
        /// <param name="value">值处理</param>
        /// <param name="t">类型</param>
        /// <returns></returns>
        public static object ChangeType(object value, Type t)
        {
            if (t == null)
            {
                return(null);
            }
            string strValue = Convert.ToString(value);

            if (t.IsGenericType && t.Name.StartsWith("Nullable"))
            {
                t = Nullable.GetUnderlyingType(t);
                if (strValue == "")
                {
                    return(null);
                }
            }
            if (t.Name == "String")
            {
                return(strValue);
            }
            if (strValue == "")
            {
                return(Activator.CreateInstance(t));
            }
            else if (t.IsValueType)
            {
                if (t.Name == "Guid")
                {
                    return(new Guid(strValue));
                }
                else if (t.Name.StartsWith("Int") && strValue.IndexOf('.') > -1)
                {
                    strValue = strValue.Split('.')[0];
                }
                return(Convert.ChangeType(strValue, t));
            }
            else
            {
                switch (GetSystemType(ref t))
                {
                case SysType.Custom:
                    return(MDataRow.CreateFrom(strValue).ToEntity(t));

                case SysType.Generic:
                    if (t.Name.StartsWith("List"))
                    {
                        return(MDataTable.CreateFrom(strValue).ToList(t));
                    }
                    break;

                case SysType.Array:
                    if (t.Name == "Byte[]" && value.GetType().Name != t.Name)
                    {
                        using (MemoryStream ms = new MemoryStream())
                        {
                            new BinaryFormatter().Serialize(ms, value);
                            return(ms.ToArray());
                        }
                    }
                    break;
                }
                return(Convert.ChangeType(value, t));
            }
        }
Пример #19
0
        /// <summary>
        /// 类型转换(精准强大)
        /// </summary>
        /// <param name="value">值处理</param>
        /// <param name="t">类型</param>
        /// <returns></returns>
        public static object ChangeType(object value, Type t)
        {
            if (t == null)
            {
                return(null);
            }
            string strValue = Convert.ToString(value);

            if (t.IsEnum)
            {
                if (strValue != "")
                {
                    if (Enum.IsDefined(t, strValue))
                    {
                        return(Enum.Parse(t, strValue));
                    }
                    int v = 0;
                    if (int.TryParse(strValue, out v))
                    {
                        object v1 = Enum.Parse(t, strValue);
                        if (v1.ToString() != strValue)
                        {
                            return(v1);
                        }
                    }
                    string[] names = Enum.GetNames(t);
                    string   lower = strValue.ToLower();
                    foreach (string name in names)
                    {
                        if (name.ToLower() == lower)
                        {
                            return(Enum.Parse(t, name));
                        }
                    }
                }

                //取第一个值。
                string firstKey = Enum.GetName(t, -1);
                if (!string.IsNullOrEmpty(firstKey))
                {
                    return(Enum.Parse(t, firstKey));
                }
                return(Enum.Parse(t, Enum.GetNames(t)[0]));
            }
            if (value == null)
            {
                return(null);
            }
            if (t.FullName == "System.Object")
            {
                return(value);
            }
            if (t.FullName == "System.Type")
            {
                return((Type)value);
            }
            if (t.FullName == "System.IO.Stream" && value is HttpPostedFile)
            {
                return(((HttpPostedFile)value).InputStream);
            }

            if (t.IsGenericType && t.Name.StartsWith("Nullable"))
            {
                t = Nullable.GetUnderlyingType(t);
                if (strValue == "")
                {
                    return(null);
                }
            }
            if (t.Name == "String")
            {
                if (value is byte[])
                {
                    return(Convert.ToBase64String((byte[])value));
                }
                return(strValue);
            }
            if (t.FullName == "System.Text.StringBuilder")
            {
                return(value as StringBuilder);
            }
            if (t.FullName == "System.Text.Encoding")
            {
                return(value as Encoding);
            }
            if (strValue == "")
            {
                if (t.Name.EndsWith("[]"))
                {
                    return(null);
                }
                return(Activator.CreateInstance(t));
            }
            else if (t.IsValueType)
            {
                if (t.Name == "DateTime")
                {
                    switch (strValue.ToLower().TrimEnd(')', '('))
                    {
                    case "now":
                    case "getdate":
                    case "current_timestamp":
                        return(DateTime.Now);
                    }
                    if (DateTime.Parse(strValue) == DateTime.MinValue)
                    {
                        return((DateTime)SqlDateTime.MinValue);
                    }
                    return(Convert.ChangeType(value, t));//这里用value,避免丢失毫秒
                }
                else if (t.Name == "Guid")
                {
                    if (strValue == SqlValue.Guid || strValue.StartsWith("newid"))
                    {
                        return(Guid.NewGuid());
                    }
                    return(new Guid(strValue));
                }
                else
                {
                    switch (strValue.ToLower())
                    {
                    case "yes":
                    case "true":
                    case "1":
                    case "on":
                    case "是":
                        if (t.Name == "Boolean")
                        {
                            return(true);
                        }
                        else
                        {
                            strValue = "1";
                        }
                        break;

                    case "no":
                    case "false":
                    case "0":
                    case "":
                    case "否":
                        if (t.Name == "Boolean")
                        {
                            return(false);
                        }
                        else
                        {
                            strValue = "0";
                        }
                        break;

                    case "infinity":
                    case "正无穷大":
                        if (t.Name == "Double" || t.Name == "Single")
                        {
                            return(double.PositiveInfinity);
                        }
                        break;

                    case "-infinity":
                    case "负无穷大":
                        if (t.Name == "Double" || t.Name == "Single")
                        {
                            return(double.NegativeInfinity);
                        }
                        break;

                    default:
                        if (t.Name == "Boolean")
                        {
                            return(false);
                        }
                        break;
                    }

                    if (t.Name.StartsWith("Int") || t.Name == "Byte")
                    {
                        if (strValue.IndexOf('.') > -1)//11.22
                        {
                            strValue = strValue.Split('.')[0];
                        }
                        else if (value.GetType().IsEnum)
                        {
                            return((int)value);
                        }
                    }
                }
                return(Convert.ChangeType(strValue, t));
            }
            else
            {
                Type valueType = value.GetType();
                //if(valueType.IsEnum && t.is)

                if (valueType.FullName != t.FullName)
                {
                    switch (ReflectTool.GetSystemType(ref t))
                    {
                    case SysType.Custom:

                        return(MDataRow.CreateFrom(strValue).ToEntity(t));

                    case SysType.Generic:
                        if (t.Name.StartsWith("List"))
                        {
                            return(MDataTable.CreateFrom(strValue).ToList(t));
                        }
                        break;

                    case SysType.Array:
                        if (t.Name == "Byte[]")
                        {
                            if (valueType.Name == "String")
                            {
                                return(Convert.FromBase64String(strValue));
                            }
                            using (MemoryStream ms = new MemoryStream())
                            {
                                new BinaryFormatter().Serialize(ms, value);
                                return(ms.ToArray());
                            }
                        }
                        break;
                    }
                }
                return(Convert.ChangeType(value, t));
            }
        }
Пример #20
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))      // 有过滤条件
                {
                    string[] items = filter.Split(','); //指定数据库链接条件
                    foreach (string item in items)
                    {
                        if (item.EndsWith("Conn"))    //当成链接处理
                        {
                            int dbHash = DBInfo.GetHashCode(item);
                            if (DBTool.DataBases.ContainsKey(dbHash))
                            {
                                foreach (var table in DBTool.DataBases[dbHash].Tables)
                                {
                                    newDic.Add(table.Value.Name, table.Value.Name);
                                }
                            }
                        }
                        else    //当成普通表名处理
                        {
                            newDic.Add(item, item);
                        }
                    }
                }
                else
                {
                    foreach (var db in DBTool.DataBases)
                    {
                        foreach (var table in db.Value.Tables)
                        {
                            newDic.Add(table.Value.Name, table.Value.Name);
                        }
                    }
                }
                break;

            case "C_SYS_Column":
                if (!string.IsNullOrEmpty(filter))
                {
                    dt = new MDataTable(key);
                    dt.Columns.Add("value");
                    dt.Columns.Add("text");
                    dt.Columns.Add("parent");
                    string[] items = filter.Split(',');
                    foreach (string item in items)
                    {
                        MDataColumn mdc = DBTool.GetColumns(item);
                        foreach (MCellStruct ms in mdc)
                        {
                            dt.NewRow(true).Set(0, ms.ColumnName).Set(1, ms.ColumnName).Set(2, item);
                        }
                    }
                }

                break;
            }
            if (dt == null)
            {
                dt = MDataTable.CreateFrom(newDic);
                dt.Columns[0].ColumnName = "value";
                dt.Columns[1].ColumnName = "text";
                if (dt.Columns.Count > 2)
                {
                    dt.Columns[2].ColumnName = "parent";
                }
            }
            return(dt);
        }
Пример #21
0
        override protected void Show(IDialogVisualizerService windowService, IVisualizerObjectProvider objectProvider)
        {
            MDataTable dt = MDataTable.CreateFrom(objectProvider.GetObject() as string);

            FormCreate.BindTable(windowService, dt, null);
        }
Пример #22
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))     // 有过滤条件
                {
                    string[] items = filter.Split(',');

                    if (items.Length == 1 && items[0].EndsWith("Conn"))
                    {
                        if (CrossDb.DbTables.ContainsKey(filter))
                        {
                            foreach (var item in CrossDb.DbTables[filter])
                            {
                                newDic.Add(item.Key, item.Key);
                            }
                        }
                    }
                    else
                    {
                        foreach (string item in items)
                        {
                            newDic.Add(item, item);
                        }
                    }
                }
                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))
                {
                    dt = new MDataTable(key);
                    dt.Columns.Add("value");
                    dt.Columns.Add("text");
                    dt.Columns.Add("parent");
                    string[] items = filter.Split(',');
                    foreach (string item in items)
                    {
                        MDataColumn mdc = DBTool.GetColumns(CrossDb.GetEnum(item));
                        foreach (MCellStruct ms in mdc)
                        {
                            dt.NewRow(true).Set(0, ms.ColumnName).Set(1, ms.ColumnName).Set(2, item);
                        }
                    }
                }

                break;
            }
            if (dt == null)
            {
                dt = MDataTable.CreateFrom(newDic);
                dt.Columns[0].ColumnName = "value";
                dt.Columns[1].ColumnName = "text";
                if (dt.Columns.Count > 2)
                {
                    dt.Columns[2].ColumnName = "parent";
                }
            }
            return(dt);
        }
Пример #23
0
        public override void GetData(object target, System.IO.Stream outgoingData)
        {
            MDataTable dt = null;
            #region 类型判断

           
            if (target is MDataTable)
            {
                dt = target as MDataTable;
            }
            else if (target is MDataRow)
            {
                dt = ((MDataRow)target).ToTable();
            }
            else if (target is MDataColumn)
            {
                dt = ((MDataColumn)target).ToTable();
            }
            else if (target is MDataRowCollection)
            {
                dt = target as MDataRowCollection;
            }
            else if (target is DataRow)
            {
                MDataRow row = target as DataRow;
                dt = row.ToTable();
            }
            else if (target is DataColumnCollection)
            {
                MDataColumn mdc = target as DataColumnCollection;
                dt = mdc.ToTable();
            }
            else if (target is DataRowCollection)
            {
                MDataRowCollection rows = target as DataRowCollection;
                dt = rows;
            }
            else if (target is NameObjectCollectionBase)
            {
                dt = MDataTable.CreateFrom(target as NameObjectCollectionBase);
            }
            else if (target is IEnumerable)
            {
                dt = MDataTable.CreateFrom(target as IEnumerable);
            }
            else
            {
                dt = MDataTable.CreateFrom(target);
                if (dt == null)
                {
                    MDataRow row = MDataRow.CreateFrom(target);
                    if (row != null)
                    {
                        dt = row.ToTable();
                    }
                }
            }
            #endregion
            dt = Format(dt);
            if (dt != null)
            {
                base.GetData(dt.ToDataTable(), outgoingData);
            }
            else
            {

                base.GetData(new DataTable("Empty Table"), outgoingData);
            }
        }