Esempio n. 1
0
        /// <summary>
        /// 把一个业务逻辑键设置到 DataSet 里
        /// </summary>
        /// <param name="dataSet"></param>
        /// <param name="businessKey"></param>
        /// <returns></returns>
        public static DataSet SetKey(ref DataSet dataSet, BusinessKey businessKey)
        {
            Type type = businessKey.GetType();
            string tableName = type.Name;
            DataTable table;
            if (dataSet.Tables.Contains("BusinessKey"))
            {
                table = dataSet.Tables["BusinessKey"];
                table.Clear();
            }
            else
            {
                table = dataSet.Tables[type.Name];
                if (table == null)
                {
                    table = new DataTable(tableName);
                    dataSet.Tables.Add(table);
                    foreach (PropertyInfo pInfo in type.GetProperties())
                    {
                        if (pInfo.PropertyType.Name.StartsWith("Nullable"))
                        {
                            table.Columns.Add(pInfo.Name, pInfo.PropertyType.GetGenericArguments()[0]);
                        }
                        else
                        {
                            table.Columns.Add(pInfo.Name, pInfo.PropertyType);
                        }
                    }
                }
            }
            DataRow row = table.NewRow();
            foreach (PropertyInfo pInfo in type.GetProperties())
            {
                string columnName = pInfo.Name;
                if (table.Columns.Contains(columnName))
                {
                    row[columnName] = pInfo.GetValue(businessKey, null);
                }
            }
            table.Rows.Add(row);

            return dataSet;
        }
Esempio n. 2
0
 /// <summary>
 /// 创建立一个业务逻辑键
 /// </summary>
 /// <param name="key"></param>
 /// <param name="mode"></param>
 /// <returns></returns>
 public static BusinessKey CreateKey(string name, TransactionMode mode)
 {
     BusinessKey businessKey = new BusinessKey();
     businessKey.Name = name;
     businessKey.TransactionMode = mode.ToString();
     return businessKey;
 }
Esempio n. 3
0
 /// <summary>
 /// 从 DataSet 里获取一个业务逻辑键, 并决定是否要在 DataSet 删除他
 /// </summary>
 /// <param name="dataSet"></param>
 /// <param name="isRemove"></param>
 /// <returns></returns>
 public static BusinessKey GetKey(DataSet dataSet, bool isRemove)
 {
     BusinessKey businessKey = new BusinessKey();
     DataTable table = dataSet.Tables["BusinessKey"];
     try
     {
         DataRow row = table.Rows[0];
         Type classType = typeof(BusinessKey);
         foreach (PropertyInfo propertyInfo in classType.GetProperties())
         {
             object value = row[propertyInfo.Name];
             if (value != null && value != System.DBNull.Value)
             {
                 propertyInfo.SetValue(businessKey, value, null);
             }
         }
         if (isRemove)
         {
             dataSet.Tables.Remove("BusinessKey");
         }
     }
     catch
     {
         return null;
     }
     return businessKey;
 }
Esempio n. 4
0
 /// <summary>
 /// 创建立一个业务逻辑键
 /// </summary>
 /// <param name="key"></param>
 /// <param name="mode"></param>
 /// <param name="dbName"></param>
 /// <param name="className"></param>
 /// <returns></returns>
 public static BusinessKey CreateKey(string name, TransactionMode mode, string dbName, string provider)
 {
     BusinessKey businessKey = new BusinessKey();
     businessKey.Name = name;
     businessKey.TransactionMode = mode.ToString();
     businessKey.DbName = dbName;
     businessKey.Provider = provider;
     return businessKey;
 }