Exemple #1
0
 public BeeDataAdapter(BeeDataAdapter dataAdapter)
     : this()
 {
     if (dataAdapter != null)
     {
         foreach (string key in dataAdapter.Keys)
         {
             Add(key, dataAdapter[key]);
         }
     }
 }
Exemple #2
0
        public BeeDataAdapter Merge(BeeDataAdapter dataAdapter, bool overrideFlag)
        {
            foreach (string key in dataAdapter.Keys)
            {
                if (overrideFlag)
                {
                    this[key] = dataAdapter[key];
                }
                else
                {
                    if (!this.ContainsKey(key))
                    {
                        this[key] = dataAdapter[key];
                    }
                }
            }

            return(this);
        }
Exemple #3
0
        /// <summary>
        /// 从一个对象实例中构造一个DataAdapter.
        /// 若是String的话, 则采用简单Json构造。
        /// 符合正则: "(?<name>.*?)":"(?<value>.*?)"
        /// </summary>
        /// <typeparam name="T">对象类型</typeparam>
        /// <param name="value">对象值</param>
        /// <returns>DataAdapter实例</returns>
        public static BeeDataAdapter From <T>(T value) where T : class
        {
            BeeDataAdapter dataAdapter = new BeeDataAdapter();

            if (value != null)
            {
                if (value is string)
                {
                    string temp = value.ToString();
                    if (!string.IsNullOrEmpty(temp))
                    {
                        Dictionary <string, object> dict = SerializeUtil.FromJson <Dictionary <string, object> >(temp);
                        foreach (string item in dict.Keys)
                        {
                            dataAdapter[item] = dict[item];
                        }
                    }
                }
                else if (value is DataRow)
                {
                    var dataRow = value as DataRow;

                    if (dataRow != null)
                    {
                        foreach (DataColumn column in dataRow.Table.Columns)
                        {
                            object dbValue = dataRow[column];
                            if (dbValue == DBNull.Value)
                            {
                                continue;
                            }
                            dataAdapter.Add(column.ColumnName, dataRow[column]);
                        }
                    }
                }
                else
                {
                    IEntityProxy entityProxy = EntityProxyManager.Instance.GetEntityProxyFromType(value.GetType());
                    foreach (PropertySchema item in entityProxy.GetPropertyList())
                    {
                        object propertyValue =
                            entityProxy.GetPropertyValue(value, item.Name);
                        if (ReflectionUtil.IsNullableType(item.PropertyType) && propertyValue == null)
                        {
                            continue;
                        }

                        if (propertyValue is Enum)
                        {
                            propertyValue = ((Enum)propertyValue).ToString("D");
                        }

                        if (item.PropertyType.UnderlyingSystemType == typeof(DateTime))
                        {
                            if (string.Compare("modifytime", item.Name, true) == 0 ||
                                string.Compare("updatetime", item.Name, true) == 0)
                            {
                                propertyValue = DateTime.Now;
                            }

                            if ((DateTime)propertyValue == DateTime.MinValue)
                            {
                                if (string.Compare("createtime", item.Name, true) == 0)
                                {
                                    propertyValue = DateTime.Now;
                                }
                                else
                                {
                                    continue;
                                }
                            }
                        }

                        dataAdapter.Add(item.Name, propertyValue);
                    }
                }
            }

            return(dataAdapter);
        }