接口调用逻辑类
2016-02-01 17:10:39 访问(1506) 赞(0) 踩(0)
// 枚举 //
/*
成功= 1
失败
异常
*/
using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Reflection;
namespace eKing.AodbLib.Enums
{
/// <summary>
/// 调用结果
/// </summary>
[Serializable]
public partial class CallResult
{
/// <summary>
/// $Em.CallResult
/// </summary>
public const string _SortClassName = "$Em.CallResult";
#region 枚举显示表达式
/// <summary>
/// 显示表达式
/// </summary>
public enum EmShowExpress
{
/// <summary>
/// 默认
/// </summary>
默认= 1
}
#endregion 枚举显示表达式
#region Enum
/// <summary>
/// 调用结果
/// </summary>
public enum EmCallResult
{
/// <summary>
/// 成功
/// </summary>
成功= 1,
/// <summary>
/// 失败
/// </summary>
失败,
/// <summary>
/// 异常
/// </summary>
异常
}
#endregion Enum
/// <summary>
/// 构造函数
/// </summary>
public CallResult()
{
}
/// <summary>
/// 数组
/// </summary>
public readonly static EmCallResult[] EmArray = new EmCallResult[]
{
EmCallResult.成功,
EmCallResult.失败,
EmCallResult.异常
};
/// <summary>
/// typeof(CallResult) 当前CallResult的type值
/// </summary>
public readonly static Type curType = typeof(CallResult);
/// <summary>
/// typeof(CallResult).FullName
/// </summary>
public readonly static string curTypeFullName = curType.FullName;
/// <summary>
/// typeof(EmCallResult) 当前枚举EmCallResult的type值
/// </summary>
public readonly static Type curEnumType = typeof(EmCallResult);
/// <summary>
/// typeof(EmCallResult).FullName
/// </summary>
public readonly static string curEnumTypeFullName = curEnumType.FullName;
/// <summary>
/// 默认的枚举值
/// </summary>
public static readonly EmCallResult defaultEm = EmCallResult.成功;
/// <summary>
/// 默认的枚举值
/// </summary>
private static Dictionary<EmShowExpress, DataTable> dictionaryDataTableValue = CreateDataTable();
/// <summary>
/// 获得Text的数组
/// </summary>
/// <returns></returns>
public static string[] GetTextArray()
{
EmCallResult[] emA = EmArray;
int iLen = emA.Length;
string[] theResult = new string[iLen];
for (int i = 0; i < iLen; ++i)
{
theResult[i] = emA[i].ToString();
}
return theResult;
}
/// <summary>
/// 获得显示名称
/// </summary>
/// <param name="em"></param>
/// <returns></returns>
public static string GetShowName
(
EmCallResult em
)
{
return em.ToString();
}
/// <summary>
///
/// </summary>
/// <param name="em"></param>
/// <param name="curEmShowExpress"></param>
/// <returns></returns>
public static string GetShowName
(
EmCallResult em,
EmShowExpress curEmShowExpress
)
{
if (curEmShowExpress == EmShowExpress.默认)
return em.ToString();
else
return em.ToString();
}
/// <summary>
///
/// </summary>
/// <param name="strValues"></param>
/// <param name="valueLinkChar"></param>
/// <param name="textLinkChar"></param>
/// <returns></returns>
public static string GetShowNames
(
string strValues,
string valueLinkChar,
string textLinkChar
)
{
if (strValues == null || strValues.Length == 0)
return "";
string[] sArray = strValues.Split(valueLinkChar.ToCharArray());
StringBuilder theResult = new StringBuilder();
bool isFirst = true;
foreach (string s in sArray)
{
if (s == null || s.Length == 0)
continue;
if (isFirst)
{
isFirst = false;
}
else
{
theResult.Append(textLinkChar);
}
theResult.Append
(
GetShowName
(
GetEmByString(s)
)
);
}
return theResult.ToString();
}
/// <summary>
///
/// </summary>
/// <param name="strValues"></param>
/// <param name="valueLinkChar"></param>
/// <param name="textLinkChar"></param>
/// <returns></returns>
public static string GetShowNames
(
string strValues,
string valueLinkChar,
string textLinkChar,
EmShowExpress curEmShowExpress
)
{
if (strValues == null || strValues.Length == 0)
return "";
string[] sArray = strValues.Split(valueLinkChar.ToCharArray());
StringBuilder theResult = new StringBuilder();
bool isFirst = true;
foreach (string s in sArray)
{
if (s == null || s.Length == 0)
continue;
if (isFirst)
{
isFirst = false;
}
else
{
theResult.Append(textLinkChar);
}
theResult.Append
(
GetShowName
(
GetEmByString(s),
curEmShowExpress
)
);
}
return theResult.ToString();
}
/// <summary>
/// 创建数据表
/// </summary>
/// <returns></returns>
private static Dictionary<EmShowExpress, DataTable> CreateDataTable()
{
Dictionary<EmShowExpress, DataTable> theResult = new Dictionary<EmShowExpress, DataTable>();
theResult.Add(EmShowExpress.默认, CreateDataTableByEmShowExpress(EmShowExpress.默认));
return theResult;
}
/// <summary>
/// 创建数据表
/// </summary>
/// <param name="curEmShowExpress"></param>
/// <returns></returns>
private static DataTable CreateDataTableByEmShowExpress(EmShowExpress curEmShowExpress)
{
DataTable dt = new DataTable();
dt.Columns.Add("ID", typeof(int));
dt.Columns.Add("TheName");
EmCallResult[] emA = EmArray;
DataRow dr = null;
foreach (EmCallResult em in emA)
{
dr = dt.NewRow();
dt.Rows.Add(dr);
dr["ID"] = (int)em;
dr["TheName"] = GetShowName(em, curEmShowExpress);
}
return dt;
}
/// <summary>
/// 获得DataTable
/// </summary>
/// <returns></returns>
public static DataTable ReturnDataTable()
{
return dictionaryDataTableValue[EmShowExpress.默认];
}
/// <summary>
/// 获得DataTable
/// </summary>
/// <returns></returns>
public static DataTable GetDataTable()
{
return dictionaryDataTableValue[EmShowExpress.默认];
}
/// <summary>
/// 获得DataTable
/// </summary>
/// <param name="curEmShowExpress"></param>
/// <returns></returns>
public static DataTable GetDataTable(EmShowExpress curEmShowExpress)
{
return dictionaryDataTableValue[curEmShowExpress];
}
/// <summary>
/// 获得数据集
/// </summary>
/// <param name="fromCache"></param>
/// <returns></returns>
public static DataTable GetDataTable(bool fromCache)
{
if (fromCache)
return dictionaryDataTableValue[EmShowExpress.默认];
else
return CreateDataTableByEmShowExpress(EmShowExpress.默认);
}
/// <summary>
/// 获得数据集
/// </summary>
/// <param name="curEmShowExpress"></param>
/// <param name="fromCache"></param>
/// <returns></returns>
public static DataTable GetDataTable(EmShowExpress curEmShowExpress,bool fromCache)
{
if (fromCache)
return dictionaryDataTableValue[curEmShowExpress];
else
return CreateDataTableByEmShowExpress(curEmShowExpress);
}
/// <summary>
/// 获得枚举
/// </summary>
/// <param name="theValue"></param>
/// <returns></returns>
public static EmCallResult GetEmByInt(int theValue)
{
EmCallResult[] emA = EmArray;
foreach (EmCallResult em in emA)
{
if (theValue == (int)em)
return em;
}
MethodBase methodBaseValue = MethodBase.GetCurrentMethod();
throw new Exception("Method :==> " + methodBaseValue.ReflectedType.FullName + " ~ " + methodBaseValue.ToString() + " Exception :==> " + "theValue = " + theValue.ToString() + "没有找到对应的枚举值。");
}
/// <summary>
/// 获得枚举
/// </summary>
/// <param name="theValue"></param>
/// <returns></returns>
public static EmCallResult GetEmByLong(long theValue)
{
EmCallResult[] emA = EmArray;
foreach (EmCallResult em in emA)
{
if (theValue == (long)em)
return em;
}
MethodBase methodBaseValue = MethodBase.GetCurrentMethod();
throw new Exception("Method :==> " + methodBaseValue.ReflectedType.FullName + " ~ " + methodBaseValue.ToString() + " Exception :==> " + "theValue = " + theValue.ToString() + "没有找到对应的枚举值。");
}
/// <summary>
/// 获得枚举
/// </summary>
/// <param name="theValue"></param>
/// <returns></returns>
public static EmCallResult GetEmByString(string theValue)
{
EmCallResult[] emA = EmArray;
foreach (EmCallResult em in emA)
{
if (theValue == ((int)em).ToString())
return em;
}
MethodBase methodBaseValue = MethodBase.GetCurrentMethod();
throw new Exception("Method :==> " + methodBaseValue.ReflectedType.FullName + " ~ " + methodBaseValue.ToString() + " Exception :==> " + "theValue = " + theValue.ToString() + "没有找到对应的枚举值。");
}
/// <summary>
/// 获得枚举
/// </summary>
/// <param name="theValue"></param>
/// <returns></returns>
public static EmCallResult GetEmByObj(object theValue)
{
MethodBase methodBaseValue = null;
if (theValue == null)
{
methodBaseValue = MethodBase.GetCurrentMethod();
throw new Exception("Method :==> " + methodBaseValue.ReflectedType.FullName + " ~ " + methodBaseValue.ToString() + " Exception :==> " + "theValue为null,没有找到对应的枚举值。");
}
if (theValue is EmCallResult)
return (EmCallResult)theValue;
string strValue = theValue.ToString();
if (strValue.Length == 0)
{
methodBaseValue = MethodBase.GetCurrentMethod();
throw new Exception("Method :==> " + methodBaseValue.ReflectedType.FullName + " ~ " + methodBaseValue.ToString() + " Exception :==> " + "theValue为空,没有找到对应的枚举值。");
}
EmCallResult[] emA = EmArray;
foreach (EmCallResult em in emA)
{
if (strValue == ((int)em).ToString())
return em;
}
methodBaseValue = MethodBase.GetCurrentMethod();
throw new Exception("Method :==> " + methodBaseValue.ReflectedType.FullName + " ~ " + methodBaseValue.ToString() + " Exception :==> " + "theValue = " + strValue.ToString() + "没有找到对应的枚举值。");
}
/// <summary>
/// 获得枚举
/// </summary>
/// <param name="theValue"></param>
/// <returns></returns>
public static EmCallResult GetDefaultEmByInt(int theValue)
{
EmCallResult[] emA = EmArray;
foreach (EmCallResult em in emA)
{
if (theValue == (int)em)
return em;
}
return defaultEm;
}
/// <summary>
/// 获得枚举
/// </summary>
/// <param name="theValue"></param>
/// <returns></returns>
public static EmCallResult GetDefaultEmByLong(long theValue)
{
EmCallResult[] emA = EmArray;
foreach (EmCallResult em in emA)
{
if (theValue == (long)em)
return em;
}
return defaultEm;
}
/// <summary>
/// 获得枚举
/// </summary>
/// <param name="theValue"></param>
/// <returns></returns>
public static EmCallResult GetDefaultEmByString(string theValue)
{
EmCallResult[] emA = EmArray;
foreach (EmCallResult em in emA)
{
if (theValue == ((int)em).ToString())
return em;
}
return defaultEm;
}
/// <summary>
/// 获得枚举
/// </summary>
/// <param name="theValue"></param>
/// <returns></returns>
public static EmCallResult GetDefaultEmByObj(object theValue)
{
if (theValue == null)
return defaultEm;
if (theValue is EmCallResult)
return (EmCallResult)theValue;
string strValue = theValue.ToString();
if (strValue.Length == 0)
return defaultEm;
EmCallResult[] emA = EmArray;
foreach (EmCallResult em in emA)
{
if (strValue == ((int)em).ToString())
return em;
}
return defaultEm;
}
/// <summary>
/// 获得枚举
/// </summary>
/// <param name="theValue"></param>
/// <param name="defaultValue"></param>
/// <returns></returns>
public static EmCallResult GetDefaultEmByInt(int theValue, EmCallResult defaultValue)
{
EmCallResult[] emA = EmArray;
foreach (EmCallResult em in emA)
{
if (theValue == (int)em)
return em;
}
return defaultValue;
}
/// <summary>
/// 获得枚举
/// </summary>
/// <param name="theValue"></param>
/// <param name="defaultValue"></param>
/// <returns></returns>
public static EmCallResult GetDefaultEmByLong(long theValue, EmCallResult defaultValue)
{
EmCallResult[] emA = EmArray;
foreach (EmCallResult em in emA)
{
if (theValue == (long)em)
return em;
}
return defaultValue;
}
/// <summary>
/// 获得枚举
/// </summary>
/// <param name="theValue"></param>
/// <param name="defaultValue"></param>
/// <returns></returns>
public static EmCallResult GetDefaultEmByString(string theValue, EmCallResult defaultValue)
{
EmCallResult[] emA = EmArray;
foreach (EmCallResult em in emA)
{
if (theValue == ((int)em).ToString())
return em;
}
return defaultValue;
}
/// <summary>
/// 获得枚举
/// </summary>
/// <param name="theValue"></param>
/// <param name="defaultValue"></param>
/// <returns></returns>
public static EmCallResult GetDefaultEmByObj(object theValue, EmCallResult defaultValue)
{
if (theValue == null)
return defaultValue;
string strValue = theValue.ToString();
if (strValue.Length == 0)
return defaultValue;
EmCallResult[] emA = EmArray;
foreach (EmCallResult em in emA)
{
if (strValue == ((int)em).ToString())
return em;
}
return defaultValue;
}
/// <summary>
/// 获得Text 获得EmCallResult
/// </summary>
/// <param name="theText"></param>
/// <returns></returns>
public static EmCallResult GetEmByText(string theText)
{
MethodBase methodBaseValue = null;
if (theText == null)
{
methodBaseValue = MethodBase.GetCurrentMethod();
throw new Exception("Method :==> " + methodBaseValue.ReflectedType.FullName + " ~ " + methodBaseValue.ToString() + " Exception :==> " + "theText为null,没有找到对应的枚举值。");
}
if (theText.Length == 0)
{
methodBaseValue = MethodBase.GetCurrentMethod();
throw new Exception("Method :==> " + methodBaseValue.ReflectedType.FullName + " ~ " + methodBaseValue.ToString() + " Exception :==> " + "theText为空,没有找到对应的枚举值。");
}
EmCallResult[] emA = EmArray;
foreach (EmCallResult em in emA)
{
if (theText == (em).ToString())
return em;
}
methodBaseValue = MethodBase.GetCurrentMethod();
throw new Exception("Method :==> " + methodBaseValue.ReflectedType.FullName + " ~ " + methodBaseValue.ToString() + " Exception :==> " + "theText = " + theText.ToString() + "没有找到对应的枚举值。");
}
/// <summary>
/// 获得Text 获得EmCallResult
/// </summary>
/// <param name="theText"></param>
/// <param name="defaultValue"></param>
/// <returns></returns>
public static EmCallResult GetDefaultEmByText(string theText, EmCallResult defaultValue)
{
if (theText == null)
return defaultValue;
if (theText.Length == 0)
return defaultValue;
EmCallResult[] emA = EmArray;
foreach (EmCallResult em in emA)
{
if (theText == (em).ToString())
return em;
}
return defaultValue;
}
/// <summary>
/// 获得枚举
/// </summary>
/// <param name="theValue"></param>
/// <returns></returns>
public static EmCallResult GetEmByAllObj(object theValue)
{
MethodBase methodBaseValue = null;
if (theValue == null)
{
methodBaseValue = MethodBase.GetCurrentMethod();
throw new Exception("Method :==> " + methodBaseValue.ReflectedType.FullName + " ~ " + methodBaseValue.ToString() + " Exception :==> " + "theValue为null,没有找到对应的枚举值。");
}
if (theValue is EmCallResult)
return (EmCallResult)theValue;
string strValue = theValue.ToString();
if (strValue.Length == 0)
{
methodBaseValue = MethodBase.GetCurrentMethod();
throw new Exception("Method :==> " + methodBaseValue.ReflectedType.FullName + " ~ " + methodBaseValue.ToString() + " Exception :==> " + "theValue为空,没有找到对应的枚举值。");
}
EmCallResult[] emA = EmArray;
foreach (EmCallResult em in emA)
{
if (strValue == ((int)em).ToString() || strValue == em.ToString())
return em;
}
methodBaseValue = MethodBase.GetCurrentMethod();
throw new Exception("Method :==> " + methodBaseValue.ReflectedType.FullName + " ~ " + methodBaseValue.ToString() + " Exception :==> " + "theValue = " + strValue.ToString() + "没有找到对应的枚举值。");
}
/// <summary>
/// 获得枚举
/// </summary>
/// <param name="theValue"></param>
/// <param name="defaultValue"></param>
/// <returns></returns>
public static EmCallResult GetDefaultEmByAllObj(object theValue, EmCallResult defaultValue)
{
if (theValue == null)
return defaultValue;
string strValue = theValue.ToString();
if (strValue.Length == 0)
return defaultValue;
EmCallResult[] emA = EmArray;
foreach (EmCallResult em in emA)
{
if (strValue == ((int)em).ToString() || strValue == em.ToString())
return em;
}
return defaultValue;
}
}
}
// 接口调用逻辑类 //
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace eKing.AodbLib.Classes.Results
{
/// <summary>
///
/// </summary>
[Serializable]
public class CallResult
{
/// <summary>
///
/// </summary>
/// <param name="_ResultText"></param>
public CallResult(string _ResultText)
{
m_EmCallResultV = eKing.AodbLib.Enums.CallResult.EmCallResult.成功;
m_ResultText = _ResultText;
}
public CallResult
(
eKing.AodbLib.Enums.CallResult.EmCallResult _EmCallResultV,
string _ResultText
)
{
m_EmCallResultV = _EmCallResultV;
m_ResultText = _ResultText;
}
#region EmCallResultV ~ 调用结果
/// <summary>
/// EmCallResultV ~ 调用结果
/// </summary>
protected eKing.AodbLib.Enums.CallResult.EmCallResult m_EmCallResultV
=
eKing.AodbLib.Enums.CallResult.EmCallResult.成功;
/// <summary>
/// EmCallResultV ~ 调用结果
/// </summary>
public eKing.AodbLib.Enums.CallResult.EmCallResult EmCallResultV
{
get
{
return m_EmCallResultV;
}
set
{
m_EmCallResultV = value;
}
}
#endregion EmCallResultV ~ 调用结果
#region ResultText ~ 内容
/// <summary>
/// ResultText ~ 内容
/// </summary>
protected string m_ResultText = null;
/// <summary>
/// ResultText ~ 内容
/// </summary>
public string ResultText
{
get
{
return m_ResultText;
}
set
{
m_ResultText = value;
}
}
#endregion ResultText ~ 内容
/// <summary>
///
/// </summary>
/// <param name="theValue"></param>
/// <returns></returns>
public static CallResult ToSucc(string theValue)
{
return new CallResult(eKing.AodbLib.Enums.CallResult.EmCallResult.成功, theValue);
}
/// <summary>
///
/// </summary>
/// <param name="theValue"></param>
/// <returns></returns>
public static CallResult ToError(string theValue)
{
return new CallResult(eKing.AodbLib.Enums.CallResult.EmCallResult.失败, theValue);
}
/// <summary>
///
/// </summary>
/// <param name="theValue"></param>
/// <returns></returns>
public static CallResult ToException(string theValue)
{
return new CallResult(eKing.AodbLib.Enums.CallResult.EmCallResult.异常, theValue);
}
}
}
标签:
接口调用逻辑类 


上一条:
下一条:
相关评论
发表评论