学无止境,精益求精

十年河东,十年河西,莫欺少年穷

用于基础返回值类型,如下:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text; namespace Data.DataCommon
{
public class BaseResponse
{
public BaseResponse()
{
this.IsSuccess = false;
this.ResultCode = -;
this.ResultMessage = "请求失败...";
}
/// <summary>
/// 返回信息
/// </summary>
public string ResultMessage { get; set; }
/// <summary>
/// 返回编码 -1 代表失败 0代表成功
/// </summary>
public int ResultCode { get; set; }
/// <summary>
/// 处理是否成功
/// </summary>
public bool IsSuccess { get; set; }
} public class BaseResponse<T> : BaseResponse
{
public T Data { get; set; } //public List<T> DataList { get; set; } public BaseResponse()
{
this.IsSuccess = false;
this.ResultCode = -;
this.ResultMessage = "请求失败...";
} public BaseResponse(T data)
{
this.Data = data;
}
} public class CommonBaseResponse
{
#region 重置Response
public static BaseResponse<T> SetResponse<T>(T Data, bool bol, string Msg = "", int cord = )
{
BaseResponse<T> response = new BaseResponse<T>();
response.Data = Data;
response.IsSuccess = bol;
response.ResultCode = bol == true ? : -;
if (cord != )
{
response.ResultCode = cord;
}
response.ResultMessage = bol == true ? "请求成功..." : "请求失败...";
if (!string.IsNullOrEmpty(Msg))
{
response.ResultMessage = Msg;
}
return response;
}
public static BaseResponse SetResponse(bool bol, string Msg = "", int cord = )
{
BaseResponse response = new BaseResponse();
response.IsSuccess = bol;
response.ResultCode = bol == true ? : -;
if (cord != )
{
response.ResultCode = cord;
}
response.ResultMessage = bol == true ? "请求成功..." : "请求失败...";
if (!string.IsNullOrEmpty(Msg))
{
response.ResultMessage = Msg;
}
return response;
}
#endregion
}
}

下面我们用GET,POST请求如下:

        [HttpPost]
public ActionResult GetData(DataModel model)
{
var result = CommonBaseResponse.SetResponse(true);
return Json(result, JsonRequestBehavior.DenyGet);
} [HttpGet]
public ActionResult GetData(string userId)
{
var result=CommonBaseResponse.SetResponse(true);
return Json(result, JsonRequestBehavior.AllowGet);
}

Ajax 请求如下:

<script src="~/Scripts/jquery-1.10.2.min.js"></script>
<script type="text/javascript">
$(function () {
$.get("/Home/GetData?userId=chen", function (result) {
console.log(result)
})
})
</script>

返回值如下:

Post请求类似,在此不再累述。

如果返回值中带有数据集合,怎么处理?

C#如下:

        [HttpGet]
public ActionResult GetData(string userId)
{
List<DataModel> list = new List<DataModel>();
list.Add(new DataModel() { userId = "", userName = "Jack.Chen", userNo = "", userSex = "男" });
list.Add(new DataModel() { userId = "", userName = "LiLi.Chen", userNo = "", userSex = "女" });
var result = CommonBaseResponse.SetResponse<List<DataModel>>(list,true);
return Json(result, JsonRequestBehavior.AllowGet);
}

返回值如下:

综上所述,如此简单。

顺便一个格式化类

    public class CommonModelFunc
{ public static string FormatDate(Nullable<System.DateTime> date)
{
try
{
string dateString = Convert.ToDateTime(date).ToString("yyyy-MM-dd");
if (dateString != "0001-01-01")
{
return Convert.ToDateTime(date).ToString("yyyy-MM-dd");
}
else
{
return "";
}
}
catch
{
return "";
}
} public static string FormatDate(Nullable<System.DateTime> date,string format)
{
try
{
string dateString = Convert.ToDateTime(date).ToString("yyyy-MM-dd");
if (dateString != "0001-01-01")
{
return Convert.ToDateTime(date).ToString(format);
}
else
{
return "";
}
}
catch
{
return "";
}
} public static string FormatStringDate(string date)
{
try
{
string dateString = Convert.ToDateTime(date).ToString("yyyy-MM-dd");
if (dateString != "0001-01-01")
{
return Convert.ToDateTime(date).ToString("yyyy-MM-dd");
}
else
{
return "";
}
}
catch
{
return "";
}
} public static string FormatStringDate(string date,string format)
{
try
{
string dateString = Convert.ToDateTime(date).ToString("yyyy-MM-dd");
if (dateString != "0001-01-01")
{
return Convert.ToDateTime(date).ToString(format);
}
else
{
return "";
}
}
catch
{
return "";
}
} public static string FormatMoney(Nullable<decimal> Money)
{
if (Money.HasValue)
{
return Convert.ToDouble(Money).ToString("0.00");
}
else
{
return "";
}
} public static string FormatDateHMS(Nullable<System.DateTime> date)
{
try
{
string dateString = Convert.ToDateTime(date).ToString("yyyy-MM-dd");
if (dateString != "0001-01-01")
{
return Convert.ToDateTime(date).ToString("yyyy-MM-dd HH:mm:ss");
}
else
{
return "";
} }
catch
{
return "";
}
} public static string FormatDateChineseHMS(Nullable<System.DateTime> date)
{
try
{
string dateString = Convert.ToDateTime(date).ToString("yyyy-MM-dd");
if (dateString != "0001-01-01")
{
return Convert.ToDateTime(date).ToString("yyyy年MM月dd日 HH时mm分");
}
else
{
return "";
} }
catch
{
return "";
}
}
}

在此,顺便介绍一个ConvertHelper的类,如下:

using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Reflection;
using System.Text;
using System.Linq;
using System.Text.RegularExpressions;
namespace Movit.ZhaoCai.DataCommon
{
public static class ConvertHelper
{ /// <summary>
/// datatow 转换Datatable
/// </summary>
/// <param name="drArr"></param>
/// <returns></returns>
public static DataTable GetDataTableByDataRows(DataRow[] drArr)
{
if (drArr == null || drArr.Length == ) return null;
DataTable tmp = drArr[].Table.Clone(); // 复制DataRow的表结构
foreach (DataRow row in drArr)
tmp.Rows.Add(row.ItemArray); // 将DataRow添加到DataTable中
return tmp; } public static string ToString(object value)
{
if (value != null)
{
return value.ToString();
}
else
{
return string.Empty;
}
} public static int ToInt(object value)
{
int result = -;
if (value != null)
{
int.TryParse(value.ToString(), out result);
}
return result;
} public static decimal ToDecimal(object value)
{
decimal val = ;
if (value == null || string.IsNullOrEmpty(value.ToString()))
{ }
else
{
if (value != null && IsNumber(value.ToString()))
{ decimal.TryParse(value.ToString(), out val); } }
return Math.Round(val, );
}
public static decimal? ToEngineeringquantityDecimal(object value)
{
decimal val = ;
if (value == null || string.IsNullOrEmpty(value.ToString()))
{
return null;
}
else
{
if (value != null && IsNumber(value.ToString()))
{ decimal.TryParse(value.ToString(), out val); } }
return Math.Round(val, );
}
public static DateTime ToDateTime(object value)
{
DateTime val = DateTime.Now;
if (value != null)
{
DateTime.TryParse(value.ToString(), out val);
}
return val;
}
public static double ToDouble(object value)
{
double val = ;
if (value != null)
{
double.TryParse(value.ToString(), out val);
}
return val;
} /// <summary>
/// Add by Allen.Yang,2017年11月20日 17:24:11
/// </summary>
/// <param name="str"></param>
/// <returns></returns>
public static decimal ConvertToDecimal(this string str)
{
decimal d = ;
decimal.TryParse(str, out d);
return d;
} /// <summary>
/// 金额转换成大写金额
/// </summary>
/// <param name="money"></param>
/// <returns></returns>
public static string ConvertNumToUpper(string LowerMoney)
{
string functionReturnValue = null;
bool IsNegative = false; // 是否是负数
if (LowerMoney.Trim().Substring(, ) == "-")
{
// 是负数则先转为正数
LowerMoney = LowerMoney.Trim().Remove(, );
IsNegative = true;
}
string strLower = null;
string strUpart = null;
string strUpper = null;
int iTemp = ;
// 保留两位小数 123.489→123.49  123.4→123.4
LowerMoney = Math.Round(double.Parse(LowerMoney), ).ToString();
if (LowerMoney.IndexOf(".") > )
{
if (LowerMoney.IndexOf(".") == LowerMoney.Length - )
{
LowerMoney = LowerMoney + "";
}
}
else
{
LowerMoney = LowerMoney + ".00";
}
strLower = LowerMoney;
iTemp = ;
strUpper = "";
while (iTemp <= strLower.Length)
{
switch (strLower.Substring(strLower.Length - iTemp, ))
{
case ".":
strUpart = "圆";
break;
case "":
strUpart = "零";
break;
case "":
strUpart = "壹";
break;
case "":
strUpart = "贰";
break;
case "":
strUpart = "叁";
break;
case "":
strUpart = "肆";
break;
case "":
strUpart = "伍";
break;
case "":
strUpart = "陆";
break;
case "":
strUpart = "柒";
break;
case "":
strUpart = "捌";
break;
case "":
strUpart = "玖";
break;
} switch (iTemp)
{
case :
strUpart = strUpart + "分";
break;
case :
strUpart = strUpart + "角";
break;
case :
strUpart = strUpart + "";
break;
case :
strUpart = strUpart + "";
break;
case :
strUpart = strUpart + "拾";
break;
case :
strUpart = strUpart + "佰";
break;
case :
strUpart = strUpart + "仟";
break;
case :
strUpart = strUpart + "万";
break;
case :
strUpart = strUpart + "拾";
break;
case :
strUpart = strUpart + "佰";
break;
case :
strUpart = strUpart + "仟";
break;
case :
strUpart = strUpart + "亿";
break;
case :
strUpart = strUpart + "拾";
break;
case :
strUpart = strUpart + "佰";
break;
case :
strUpart = strUpart + "仟";
break;
case :
strUpart = strUpart + "万";
break;
default:
strUpart = strUpart + "";
break;
} strUpper = strUpart + strUpper;
iTemp = iTemp + ;
} strUpper = strUpper.Replace("零拾", "零");
strUpper = strUpper.Replace("零佰", "零");
strUpper = strUpper.Replace("零仟", "零");
strUpper = strUpper.Replace("零零零", "零");
strUpper = strUpper.Replace("零零", "零");
strUpper = strUpper.Replace("零角零分", "整");
strUpper = strUpper.Replace("零分", "整");
strUpper = strUpper.Replace("零角", "零");
strUpper = strUpper.Replace("零亿零万零圆", "亿圆");
strUpper = strUpper.Replace("亿零万零圆", "亿圆");
strUpper = strUpper.Replace("零亿零万", "亿");
strUpper = strUpper.Replace("零万零圆", "万圆");
strUpper = strUpper.Replace("零亿", "亿");
strUpper = strUpper.Replace("零万", "万");
strUpper = strUpper.Replace("零圆", "圆");
strUpper = strUpper.Replace("零零", "零"); // 对壹圆以下的金额的处理
if (strUpper.Substring(, ) == "圆")
{
strUpper = strUpper.Substring(, strUpper.Length - );
}
if (strUpper.Substring(, ) == "零")
{
strUpper = strUpper.Substring(, strUpper.Length - );
}
if (strUpper.Substring(, ) == "角")
{
strUpper = strUpper.Substring(, strUpper.Length - );
}
if (strUpper.Substring(, ) == "分")
{
strUpper = strUpper.Substring(, strUpper.Length - );
}
if (strUpper.Substring(, ) == "整")
{
strUpper = "零圆整";
}
functionReturnValue = strUpper; if (IsNegative == true)
{
return "负" + functionReturnValue;
}
else
{
return functionReturnValue;
}
} /// <summary>
/// BPM加密字符串key生产规则
/// </summary>
/// <param name="str">BPM流程号</param>
/// <returns></returns>
public static string NewGetEnCodeStr(string str)
{
string enStr = "";
if (str != null && str.Length > )
{
str = (((long.Parse(str) * - ) + ) * ).ToString();
int l = str.ToString().Length;
if (l % == )//当字符长度为偶数时
{
enStr = str.Remove(l / , );
}
else
{
enStr = str.Remove(l / + , );//从字符中间+1的位置移除2个字符
}
}
return enStr;
} /// <summary>
/// 加密字符串2生产规则
/// </summary>
/// <param name="content">当前查看用户账号</param>
/// <returns></returns>
public static string Encrypt(string content)
{
byte[] enData = Encoding.UTF8.GetBytes(content);
return Convert.ToBase64String(enData);
} /// <summary>
/// 转换成Datatable
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="items"></param>
/// <returns></returns>
public static DataTable ToDataTable<T>(List<T> items)
{
var tb = new DataTable(typeof(T).Name); PropertyInfo[] props = typeof(T).GetProperties(BindingFlags.Public | BindingFlags.Instance); foreach (PropertyInfo prop in props)
{
Type t = GetCoreType(prop.PropertyType);
tb.Columns.Add(prop.Name, t);
} foreach (T item in items)
{
var values = new object[props.Length]; for (int i = ; i < props.Length; i++)
{
values[i] = props[i].GetValue(item, null);
} tb.Rows.Add(values);
} return tb;
} /// <summary>
/// 确定指定的类型为空。
/// </summary>
private static bool IsNullable(Type t)
{
return !t.IsValueType || (t.IsGenericType && t.GetGenericTypeDefinition() == typeof(Nullable<>));
} /// <summary>
/// 如果类型为Nullable,返回底层类型,否则返回类型。
/// </summary>
private static Type GetCoreType(Type t)
{
if (t != null && IsNullable(t))
{
if (!t.IsValueType)
{
return t;
}
else
{
return Nullable.GetUnderlyingType(t);
}
}
else
{
return t;
}
} /// <summary>
/// 金额转换成中文大写金额
/// </summary>
/// <param name="LowerMoney">eg:10.74</param>
/// <returns></returns>
public static string MoneyToUpper(string LowerMoney)
{
string functionReturnValue = null;
bool IsNegative = false; // 是否是负数
if (LowerMoney.Trim().Substring(, ) == "-")
{
// 是负数则先转为正数
LowerMoney = LowerMoney.Trim().Remove(, );
IsNegative = true;
}
string strLower = null;
string strUpart = null;
string strUpper = null;
int iTemp = ;
// 保留两位小数 123.489→123.49  123.4→123.4
LowerMoney = Math.Round(double.Parse(LowerMoney), ).ToString();
if (LowerMoney.IndexOf(".") > )
{
if (LowerMoney.IndexOf(".") == LowerMoney.Length - )
{
LowerMoney = LowerMoney + "";
}
}
else
{
LowerMoney = LowerMoney + ".00";
}
strLower = LowerMoney;
iTemp = ;
strUpper = "";
while (iTemp <= strLower.Length)
{
switch (strLower.Substring(strLower.Length - iTemp, ))
{
case ".":
strUpart = "圆";
break;
case "":
strUpart = "零";
break;
case "":
strUpart = "壹";
break;
case "":
strUpart = "贰";
break;
case "":
strUpart = "叁";
break;
case "":
strUpart = "肆";
break;
case "":
strUpart = "伍";
break;
case "":
strUpart = "陆";
break;
case "":
strUpart = "柒";
break;
case "":
strUpart = "捌";
break;
case "":
strUpart = "玖";
break;
} switch (iTemp)
{
case :
strUpart = strUpart + "分";
break;
case :
strUpart = strUpart + "角";
break;
case :
strUpart = strUpart + "";
break;
case :
strUpart = strUpart + "";
break;
case :
strUpart = strUpart + "拾";
break;
case :
strUpart = strUpart + "佰";
break;
case :
strUpart = strUpart + "仟";
break;
case :
strUpart = strUpart + "万";
break;
case :
strUpart = strUpart + "拾";
break;
case :
strUpart = strUpart + "佰";
break;
case :
strUpart = strUpart + "仟";
break;
case :
strUpart = strUpart + "亿";
break;
case :
strUpart = strUpart + "拾";
break;
case :
strUpart = strUpart + "佰";
break;
case :
strUpart = strUpart + "仟";
break;
case :
strUpart = strUpart + "万";
break;
default:
strUpart = strUpart + "";
break;
} strUpper = strUpart + strUpper;
iTemp = iTemp + ;
} strUpper = strUpper.Replace("零拾", "零");
strUpper = strUpper.Replace("零佰", "零");
strUpper = strUpper.Replace("零仟", "零");
strUpper = strUpper.Replace("零零零", "零");
strUpper = strUpper.Replace("零零", "零");
strUpper = strUpper.Replace("零角零分", "整");
strUpper = strUpper.Replace("零分", "整");
strUpper = strUpper.Replace("零角", "零");
strUpper = strUpper.Replace("零亿零万零圆", "亿圆");
strUpper = strUpper.Replace("亿零万零圆", "亿圆");
strUpper = strUpper.Replace("零亿零万", "亿");
strUpper = strUpper.Replace("零万零圆", "万圆");
strUpper = strUpper.Replace("零亿", "亿");
strUpper = strUpper.Replace("零万", "万");
strUpper = strUpper.Replace("零圆", "圆");
strUpper = strUpper.Replace("零零", "零"); // 对壹圆以下的金额的处理
if (strUpper.Substring(, ) == "圆")
{
strUpper = strUpper.Substring(, strUpper.Length - );
}
if (strUpper.Substring(, ) == "零")
{
strUpper = strUpper.Substring(, strUpper.Length - );
}
if (strUpper.Substring(, ) == "角")
{
strUpper = strUpper.Substring(, strUpper.Length - );
}
if (strUpper.Substring(, ) == "分")
{
strUpper = strUpper.Substring(, strUpper.Length - );
}
if (strUpper.Substring(, ) == "整")
{
strUpper = "零圆整";
}
functionReturnValue = strUpper; if (IsNegative == true)
{
return "负" + functionReturnValue;
}
else
{
return functionReturnValue;
}
} #region 泛型集合和DataSet互转 请注意,使用此方法时请确保实体集合里没有索引属性
public static IList<T> DataTableToIList<T>(DataTable p_Data)
{
// 返回值初始化
IList<T> result = new List<T>(); if (p_Data == null)
return result; for (int j = ; j < p_Data.Rows.Count; j++)
{
T _t = (T)Activator.CreateInstance(typeof(T));
System.Reflection.PropertyInfo[] propertys = _t.GetType().GetProperties();
foreach (System.Reflection.PropertyInfo pi in propertys)
{
for (int i = ; i < p_Data.Columns.Count; i++)
{
// 属性与字段名称一致的进行赋值
string columnName = p_Data.Columns[i].ColumnName.ToUpper();
//try
//{ if (pi.Name.ToUpper().Equals(columnName) || pi.Name.ToUpper().Equals(columnName.Replace("_", string.Empty)))
{
// 数据库NULL值单独处理
if (p_Data.Rows[j][i] != DBNull.Value && p_Data.Rows[j][i] != null)
{
if (pi.PropertyType == typeof(Boolean))
{
pi.SetValue(_t, Convert.ToBoolean(p_Data.Rows[j][i]), null);
}
else if (pi.PropertyType == typeof(Int16))
{
pi.SetValue(_t, Convert.ToInt16(p_Data.Rows[j][i]), null);
}
else if (pi.PropertyType == typeof(Int32))
{
pi.SetValue(_t, Convert.ToInt32(p_Data.Rows[j][i]), null);
}
else if (pi.PropertyType == typeof(Decimal))
{
pi.SetValue(_t, Convert.ToDecimal(p_Data.Rows[j][i]), null);
}
else if (pi.PropertyType == typeof(Int32?))
{
pi.SetValue(_t, Convert.ToInt32(p_Data.Rows[j][i]), null);
}
else if (pi.PropertyType == typeof(DateTime))
{
pi.SetValue(_t, Convert.ToDateTime(p_Data.Rows[j][i]), null);
}
else
{
pi.SetValue(_t, p_Data.Rows[j][i], null);
}
}
else
pi.SetValue(_t, null, null);
break;
}
//}
//catch(Exception ex)
//{
// string s= columnName;
//}
}
}
result.Add(_t);
} return result;
}
/// <summary>
/// 集合装换DataSet
/// </summary>
/// <param name="list">集合</param>
/// <returns></returns>
public static DataSet ToDataSet(IList p_List)
{
DataSet result = new DataSet();
DataTable _DataTable = new DataTable();
if (p_List.Count > )
{
PropertyInfo[] propertys = p_List[].GetType().GetProperties();
foreach (PropertyInfo pi in propertys)
{
_DataTable.Columns.Add(pi.Name, pi.PropertyType);
} for (int i = ; i < p_List.Count; i++)
{
ArrayList tempList = new ArrayList();
foreach (PropertyInfo pi in propertys)
{
object obj = pi.GetValue(p_List[i], null);
tempList.Add(obj);
}
object[] array = tempList.ToArray();
_DataTable.LoadDataRow(array, true);
}
}
result.Tables.Add(_DataTable);
return result;
} /// <summary>
/// 泛型集合转换DataSet
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="p_List">泛型集合</param>
/// <param name="p_PropertyName">待转换属性名数组</param>
/// <returns></returns>
public static DataSet ToDataSet<T>(List<T> p_List)
{
DataSet result = new DataSet();
DataTable _DataTable = ToDataTable<T>(p_List); result.Tables.Add(_DataTable);
return result;
} /// <summary>
/// DataSet装换为泛型集合
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="p_DataSet">DataSet</param>
/// <param name="p_TableIndex">待转换数据表索引</param>
/// <returns></returns>
public static IList<T> DataSetToIList<T>(DataSet p_DataSet, int p_TableIndex)
{
if (p_DataSet == null || p_DataSet.Tables.Count < )
return null;
if (p_TableIndex > p_DataSet.Tables.Count - )
return null;
if (p_TableIndex < )
p_TableIndex = ; DataTable p_Data = p_DataSet.Tables[p_TableIndex];
// 返回值初始化
IList<T> result = new List<T>();
for (int j = ; j < p_Data.Rows.Count; j++)
{
T _t = (T)Activator.CreateInstance(typeof(T));
PropertyInfo[] propertys = _t.GetType().GetProperties();
foreach (PropertyInfo pi in propertys)
{
for (int i = ; i < p_Data.Columns.Count; i++)
{
// 属性与字段名称一致的进行赋值
if (pi.Name.Equals(p_Data.Columns[i].ColumnName))
{
// 数据库NULL值单独处理
if (p_Data.Rows[j][i] != DBNull.Value)
pi.SetValue(_t, p_Data.Rows[j][i], null);
else
pi.SetValue(_t, null, null);
break;
}
}
}
result.Add(_t);
}
return result;
} /// <summary>
/// DataSet装换为泛型集合
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="p_DataSet">DataSet</param>
/// <param name="p_TableName">待转换数据表名称</param>
/// <returns></returns>
public static IList<T> DataSetToIList<T>(DataSet p_DataSet, string p_TableName)
{
int _TableIndex = ;
if (p_DataSet == null || p_DataSet.Tables.Count < )
return null;
if (string.IsNullOrEmpty(p_TableName))
return null;
for (int i = ; i < p_DataSet.Tables.Count; i++)
{
// 获取Table名称在Tables集合中的索引值
if (p_DataSet.Tables[i].TableName.Equals(p_TableName))
{
_TableIndex = i;
break;
}
}
return DataSetToIList<T>(p_DataSet, _TableIndex);
} /// <summary>
/// 将数值税率转换成显示模式(0.05=>5%)
/// </summary>
/// <returns></returns>
public static string RateForShow(string rate)
{
string result = string.Empty;
if (string.IsNullOrEmpty(rate))
{
return result;
}
rate = rate.Replace("%", "");
decimal? i = ToDecimal(rate) * ;
if (i.HasValue)
{
if (i.Value <= )
{
return "其它";
} else
{
return i.Value.ToString("#0") + "%";
}
}
else
{
return "";
}
} /// <summary>
/// 将金额转换为千分位个是(100,000.12)
/// </summary>
/// <param name="value"></param>
/// <returns></returns>
public static string DecimalToStringN2(object value)
{
decimal val = ;
if (value != null)
{
val = StringN2ToDecimal(value.ToString());
} return string.Format("{0:N2}", val);
} /// <summary>
/// 将千分位显示的金额字符转换为金额(100,000.12)
/// </summary>
/// <param name="value"></param>
/// <returns></returns>
public static decimal StringN2ToDecimal(string value)
{
decimal val = ;
if (!string.IsNullOrEmpty(value))
{
value = value.Replace(",", "");
Decimal.TryParse(value, out val);
}
return val;
} #endregion /// <summary>
/// 验证是否是数字
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
public static bool IsNumber(string input)
{
string pattern = "^-?\\d+$|^(-?\\d+)(\\.\\d+)?$";
Regex regex = new Regex(pattern);
return regex.IsMatch(input);
} /// <summary>
/// 将阿拉伯数字转换成中文数字
/// </summary>
/// <param name="value"></param>
/// <returns></returns>
public static string ConvertArabicNumToChineseNum(object value)
{
if (value != null)
{
string res = string.Empty;
switch (value.ToString())
{
case "":
res = "一";
break;
case "":
res = "二";
break;
case "":
res = "三";
break;
case "":
res = "四";
break;
case "":
res = "五";
break;
case "":
res = "六";
break;
case "":
res = "七";
break;
case "":
res = "八";
break;
case "":
res = "九";
break;
case "":
res = "十";
break;
}
return res;
}
else { return string.Empty; }
}
}
}

@陈卧龙的博客

C# 构造基础返回值类型-BaseResponse的更多相关文章

  1. C#进阶系列——WebApi 接口返回值不困惑:返回值类型详解

    前言:已经有一个月没写点什么了,感觉心里空落落的.今天再来篇干货,想要学习Webapi的园友们速速动起来,跟着博主一起来学习吧.之前分享过一篇 C#进阶系列——WebApi接口传参不再困惑:传参详解  ...

  2. WebApi 接口返回值类型详解 ( 转 )

    使用过Webapi的园友应该都知道,Webapi的接口返回值主要有四种类型 void无返回值 IHttpActionResult HttpResponseMessage 自定义类型 此篇就围绕这四块分 ...

  3. WebApi接口返回值不困惑:返回值类型详解

    前言:已经有一个月没写点什么了,感觉心里空落落的.今天再来篇干货,想要学习Webapi的园友们速速动起来,跟着博主一起来学习吧.作为程序猿,我们都知道参数和返回值是编程领域不可分割的两大块,此前分享了 ...

  4. 第18课 类型萃取(2)_获取返回值类型的traits

    1. 获取可调用对象返回类型 (1)decltype:获取变量或表达式的类型(见第2课) (2)declval及原型 ①原型:template<class T> T&& d ...

  5. WebApi 接口返回值不困惑:返回值类型详解。IHttpActionResult、void、HttpResponseMessage、自定义类型

    首先声明,我还没有这么强大的功底,只是感觉博主写的很好,就做了一个复制,请别因为这个鄙视我,博主网址:http://www.cnblogs.com/landeanfen/p/5501487.html ...

  6. (转)C# WebApi 接口返回值不困惑:返回值类型详解

    原文地址:http://www.cnblogs.com/landeanfen/p/5501487.html 正文 前言:已经有一个月没写点什么了,感觉心里空落落的.今天再来篇干货,想要学习Webapi ...

  7. [转]C#进阶系列——WebApi 接口返回值不困惑:返回值类型详解

    本文转自:http://www.cnblogs.com/landeanfen/p/5501487.html 阅读目录 一.void无返回值 二.IHttpActionResult 1.Json(T c ...

  8. C#进阶系列——WebApi接口返回值类型详解

    阅读目录 一.void无返回值 二.IHttpActionResult 1.Json(T content) 2.Ok(). Ok(T content) 3.NotFound() 4.其他 5.自定义I ...

  9. Web Api 接口返回值不困惑:返回值类型详解

    前言:已经有一个月没写点什么了,感觉心里空落落的.今天再来篇干货,想要学习Webapi的园友们速速动起来,跟着博主一起来学习吧.之前分享过一篇 WebApi 接口参数:传参详解,这篇博文内容本身很基础 ...

随机推荐

  1. 2019 China Collegiate Programming Contest Qinhuangdao Onsite

    传送门 D - Decimal 题意: 询问\(\frac{1}{n}\)是否为有限小数. 思路: 拆质因子,看是不是只包含2和5即可,否则除不尽. Code #include <bits/st ...

  2. linux(03)基础系统优化

    Linux之基础系统优化 Linux基础系统优化 >>> https://www.cnblogs.com/pyyu/p/9355477.html Linux的网络功能相当强悍,一时之 ...

  3. E05 【餐厅】What kind of coffee or tea would you like?

    核心句型 What  kind  of  coffee or tea would you like? 你想喝什么咖啡或者茶? What  would  you like? 你喜欢什么?/你想要什么? ...

  4. python实验脚本

    day1 1.  任性猜数字 需求 : 猜数字, 猜3次.如果对了 就直接退出. 如果3次都错了 ,就询问 要不要继续. 实现点: 使用 whie 循环. count 进行计数.如果count > ...

  5. 201871010133-赵永军《面向对象程序设计(java)》第八周学习总结

    201871010133-赵永军<面向对象程序设计(java)>第八周学习总结 项目 内容 这个作业属于哪个课程 https://www.cnblogs.com/nwnu-daizh/ 这 ...

  6. 添加ssh密钥

    直接运行ssh-keygen,可以不输入密码 $ ssh-keygen Generating public/private rsa key pair. Enter file in which to s ...

  7. 虚拟机安装后配置IP地址

    BOOTPROTO=static   #启动的方式,dhcp表示自动获取,static表示静态ONBOOT=yes   #是否开机启动,yes表示开机启动IPADDR  #设置IP,和vmware在同 ...

  8. Computer Network Chapter3 solution

    1.校验和:各数值相加,将溢出位加到最低位,之后将结果取反.若校验和全为0,则说明接收数据正确. 2.停等协议及计算信道利用率:利用率=(L/C)/(L/C+2*传输时延) 3.回退N帧协议(协议5) ...

  9. [LeetCode] 264. Ugly Number II 丑陋数之二

    Write a program to find the n-th ugly number. Ugly numbers are positive numbers whose prime factors ...

  10. [LeetCode] 28. Implement strStr() 实现strStr()函数

    Implement strStr(). Return the index of the first occurrence of needle in haystack, or -1 if needle ...