diff --git a/.gitignore b/.gitignore
index a923dc3..afdaa65 100644
--- a/.gitignore
+++ b/.gitignore
@@ -8,4 +8,5 @@ packages
.user
bin
.zip
-.rar
\ No newline at end of file
+.rar
+*.zip
diff --git a/AllBase/AllBase.csproj b/AllBase/AllBase.csproj
index b1dff4f..e244cee 100644
--- a/AllBase/AllBase.csproj
+++ b/AllBase/AllBase.csproj
@@ -189,6 +189,7 @@
+
diff --git a/AllBase/Model/Result/ShopLoginInfo.cs b/AllBase/Model/Result/ShopLoginInfo.cs
index 49f990a..b06d2ee 100644
--- a/AllBase/Model/Result/ShopLoginInfo.cs
+++ b/AllBase/Model/Result/ShopLoginInfo.cs
@@ -110,7 +110,7 @@ namespace AllBase.Model.Result
///
public AuthInfo BuyApiAuth { get; set; } = new AuthInfo();
///
- /// 子账户
+ /// 主账户
///
public string UserName { get; set; }
///
diff --git a/AllBase/Model/Result/TemuDBProductSelect.cs b/AllBase/Model/Result/TemuDBProductSelect.cs
new file mode 100644
index 0000000..bc6770e
--- /dev/null
+++ b/AllBase/Model/Result/TemuDBProductSelect.cs
@@ -0,0 +1,38 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace AllBase.Model.Result
+{
+ ///
+ /// 用户选品结果
+ ///
+ public class TemuDBProductSelect
+ {
+ public int id { get; set; }
+ public string out_product_Id { get; set; }
+ public string shop_id { get; set; }
+ public string shop_account { get; set; }
+ public string user_name { get; set; }
+ public string sub_user_name { get; set; }
+ public string notes { get; set; }
+ public string status { get; set; }
+ public string draft_id { get; set; }
+ public DateTime add_time { get; set; }
+ public DateTime mdy_time { get; set; }
+
+ #region 外键连接属性
+
+ public string cat_id { get; set; }
+ public string cat_name { get; set; }
+ public string ext_code { get; set; }
+ public string product_name { get; set; }
+ public string main_img { get; set; }
+ public string spu_id { get; set; }
+ public string skc_id { get; set; }
+
+ #endregion
+ }
+}
diff --git a/KJDService/KJD_WebService/BLL/ProductManage.cs b/KJDService/KJD_WebService/BLL/ProductManage.cs
index 55111d2..2aef65d 100644
--- a/KJDService/KJD_WebService/BLL/ProductManage.cs
+++ b/KJDService/KJD_WebService/BLL/ProductManage.cs
@@ -1,6 +1,7 @@
using KJD_Web.Model;
using KJD_Web.Utils;
using MySql.Data.MySqlClient;
+using NaiBa.Util.Extension;
using System;
using System.Collections.Generic;
using System.Data;
@@ -62,12 +63,11 @@ namespace KJD_Web.BLL
return "{\"code\":19999,\"msg\":\"输入为空\"}";
}
- public string GetProductList(string inputData, bool isAdmin = false)
+ public string GetProductList(string inputData, bool isDetail = false)
{
if (!string.IsNullOrEmpty(inputData))
{
- var time = 0;
- int.TryParse(RegexUtils.GetStringQuery(ref inputData, "time"), out time);
+ var time = RegexUtils.GetStringQuery(ref inputData, "time").ParseToInt();
string time1 = RegexUtils.GetStringQuery(ref inputData, "code");
if (time1 != EncrypUtil.Encryption(time))
return "{\"code\":20000,\"msg\":\"校验失败\"}";
@@ -80,14 +80,10 @@ namespace KJD_Web.BLL
var search_ext_code = RegexUtils.GetStringQuery(ref inputData, "search_ext_code")?.Replace("'", "\\'");
var search_prod_name = RegexUtils.GetStringQuery(ref inputData, "search_prod_name")?.Replace("'", "\\'");
var search_notes = RegexUtils.GetStringQuery(ref inputData, "search_notes")?.Replace("'", "\\'");
- var s_page = RegexUtils.GetStringQuery(ref inputData, "page");
- int page = 0;
- int.TryParse(s_page, out page);
- var s_page_size = RegexUtils.GetStringQuery(ref inputData, "page_size");
- int page_size;
- int.TryParse(s_page_size, out page_size);
- if (page_size == 0)
- page_size = 50;
+ var search_db_ids = RegexUtils.GetStringQuery(ref inputData, "search_db_ids")?.Replace("'", "\\'");
+
+ int page = RegexUtils.GetStringQuery(ref inputData, "page").ParseToInt();
+ int page_size= RegexUtils.GetStringQuery(ref inputData, "page_size").ParseToInt(50);
string conn = System.Configuration.ConfigurationManager.ConnectionStrings["ConnKJD"].ConnectionString;
MysqlUtils mySql = new MysqlUtils(conn);
@@ -105,6 +101,8 @@ namespace KJD_Web.BLL
sql += " and product_name like '%" + search_prod_name + "%'";
if (!string.IsNullOrWhiteSpace(search_notes))
sql += " and notes like '%" + search_notes + "%'";
+ if (!string.IsNullOrEmpty(search_db_ids))
+ sql += " and id in (" + search_db_ids + ")";
var count = mySql.ExecuteRowCount(sql);
DataTable dt;
@@ -114,7 +112,11 @@ namespace KJD_Web.BLL
}
else
{
- sql = "select id,spu_id,skc_id,cat_id,cat_name,ext_code,product_name,main_img,notes,add_time,mdy_time from kjd.product where 1=1";
+ if (isDetail)
+ sql = "select * from kjd.product where 1=1";
+ else
+ sql = "select id,spu_id,skc_id,cat_id,cat_name,ext_code,product_name,main_img,notes,add_time,mdy_time from kjd.product where 1=1";
+
if (!string.IsNullOrWhiteSpace(search_spu))
sql += " and spu_id like '%" + search_spu + "%'";
if (!string.IsNullOrWhiteSpace(search_skc))
@@ -127,6 +129,8 @@ namespace KJD_Web.BLL
sql += " and product_name like '%" + search_prod_name + "%'";
if (!string.IsNullOrWhiteSpace(search_notes))
sql += " and notes like '%" + search_notes + "%'";
+ if (!string.IsNullOrEmpty(search_db_ids))
+ sql += " and id in (" + search_db_ids + ")";
sql += " order by id desc";
sql += " limit " + Math.Max(page - 1, 0) * page_size + "," + page_size;
dt = mySql.ExecuteDataTable(sql);
@@ -156,6 +160,11 @@ namespace KJD_Web.BLL
mdy_time = Convert.ToDateTime(row["mdy_time"]),
notes = row["notes"].ToString(),
};
+ if (isDetail)
+ {
+ prod.product_json = row["product_json"].ToString();
+ prod.size_json = row["size_json"].ToString();
+ }
productLst.Add(prod);
}
var data = JsonUtils.SerializerObjectToString(productLst);
@@ -163,12 +172,12 @@ namespace KJD_Web.BLL
}
catch (Exception ex)
{
- return "{\"code\":200,\"msg\":\"" + ex.Message + "\",\"data\":[],\"count\":" + 0 + "}";
+ return "{\"code\":500,\"msg\":\"" + ex.Message + "\",\"data\":[],\"count\":" + 0 + "}";
}
}
else
{
- return "{\"code\":200,\"msg\":\"" + mySql.Message + "\",\"data\":[],\"count\":" + 0 + "}";
+ return "{\"code\":500,\"msg\":\"" + mySql.Message + "\",\"data\":[],\"count\":" + 0 + "}";
}
}
return "{\"code\":19999,\"msg\":\"输入为空\"}";
@@ -178,8 +187,7 @@ namespace KJD_Web.BLL
{
if (!string.IsNullOrEmpty(inputData))
{
- var time = 0;
- int.TryParse(RegexUtils.GetStringQuery(ref inputData, "time"), out time);
+ var time = RegexUtils.GetStringQuery(ref inputData, "time").ParseToInt();
string time1 = RegexUtils.GetStringQuery(ref inputData, "code");
if (time1 != EncrypUtil.Encryption(time))
return "{\"code\":20000,\"msg\":\"校验失败\"}";
@@ -208,8 +216,7 @@ namespace KJD_Web.BLL
{
if (!string.IsNullOrEmpty(inputData))
{
- var time = 0;
- int.TryParse(RegexUtils.GetStringQuery(ref inputData, "time"), out time);
+ var time = RegexUtils.GetStringQuery(ref inputData, "time").ParseToInt();
string time1 = RegexUtils.GetStringQuery(ref inputData, "code");
if (time1 != EncrypUtil.Encryption(time))
return "{\"code\":20000,\"msg\":\"校验失败\"}";
@@ -250,8 +257,7 @@ namespace KJD_Web.BLL
{
if (!string.IsNullOrEmpty(inputData))
{
- var time = 0;
- int.TryParse(RegexUtils.GetStringQuery(ref inputData, "time"), out time);
+ var time = RegexUtils.GetStringQuery(ref inputData, "time").ParseToInt();
string time1 = RegexUtils.GetStringQuery(ref inputData, "code");
if (time1 != EncrypUtil.Encryption(time))
return "{\"code\":20000,\"msg\":\"校验失败\"}";
@@ -270,7 +276,7 @@ namespace KJD_Web.BLL
}
if (string.IsNullOrEmpty(shop_id))
{
- return "{\"code\":500,\"msg\":\"店铺信息\"}";
+ return "{\"code\":500,\"msg\":\"没有店铺信息\"}";
}
@@ -294,5 +300,190 @@ namespace KJD_Web.BLL
}
return "{\"code\":19999,\"msg\":\"输入为空\"}";
}
+
+ public string MdyUserSelectProductStatus(string inputData, bool isAdmin = false)
+ {
+ if (!string.IsNullOrEmpty(inputData))
+ {
+ var time = RegexUtils.GetStringQuery(ref inputData, "time").ParseToInt();
+ string time1 = RegexUtils.GetStringQuery(ref inputData, "code");
+ if (time1 != EncrypUtil.Encryption(time))
+ return "{\"code\":20000,\"msg\":\"校验失败\"}";
+
+ var id = RegexUtils.GetStringQuery(ref inputData, "db_id");
+ var draft_id = RegexUtils.GetStringQuery(ref inputData, "draft_id");
+ var status = RegexUtils.GetStringQuery(ref inputData, "status");
+
+ string conn = System.Configuration.ConfigurationManager.ConnectionStrings["ConnKJD"].ConnectionString;
+ MysqlUtils mySql = new MysqlUtils(conn);
+ string sql = "update kjd.product_select set";
+ if (draft_id != null)
+ sql += " draft_id='" + draft_id + "',";
+ if (status != null)
+ sql += " status='" + status + "',";
+ sql += " mdy_time='" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "',";
+ sql = sql.TrimEnd(',');
+ sql += " where id=" + id + ";";
+ var rst = mySql.ExecuteNonQuery(sql);
+ mySql.Close();
+ if (rst)
+ {
+ return "{\"code\":200,\"msg\":\"success\"}";
+ }
+ else
+ {
+ return "{\"code\":500,\"msg\":\"" + mySql.Message + "\"}";
+ }
+ }
+ return "{\"code\":19999,\"msg\":\"输入为空\"}";
+ }
+
+ public string GetUserSelectProductList(string inputData, bool isAdmin = false)
+ {
+ if (!string.IsNullOrEmpty(inputData))
+ {
+ var time = RegexUtils.GetStringQuery(ref inputData, "time").ParseToInt();
+ string time1 = RegexUtils.GetStringQuery(ref inputData, "code");
+ if (time1 != EncrypUtil.Encryption(time))
+ return "{\"code\":20000,\"msg\":\"校验失败\"}";
+
+ var user_name = RegexUtils.GetStringQuery(ref inputData, "user_name")?.Replace("'", "\\'");
+ var shop_ids = RegexUtils.GetStringQuery(ref inputData, "shop_ids")?.Replace("'", "\\'");
+ var search_shop_id = RegexUtils.GetStringQuery(ref inputData, "search_shop_id")?.Replace("'", "\\'");
+ var search_shop_account = RegexUtils.GetStringQuery(ref inputData, "search_shop_account")?.Replace("'", "\\'");
+ var search_spu = RegexUtils.GetStringQuery(ref inputData, "search_spu")?.Replace("'", "\\'");
+ var search_skc = RegexUtils.GetStringQuery(ref inputData, "search_skc")?.Replace("'", "\\'");
+ var search_cat = RegexUtils.GetStringQuery(ref inputData, "search_cat")?.Replace("'", "\\'");
+ var search_ext_code = RegexUtils.GetStringQuery(ref inputData, "search_ext_code")?.Replace("'", "\\'");
+ var search_prod_name = RegexUtils.GetStringQuery(ref inputData, "search_prod_name")?.Replace("'", "\\'");
+ var search_notes = RegexUtils.GetStringQuery(ref inputData, "search_notes")?.Replace("'", "\\'");
+ var search_db_ids = RegexUtils.GetStringQuery(ref inputData, "search_db_ids")?.Replace("'", "\\'");
+ var status = RegexUtils.GetStringQuery(ref inputData, "status")?.Replace("'", "\\'");
+
+ int page = RegexUtils.GetStringQuery(ref inputData, "page").ParseToInt();
+ int page_size = RegexUtils.GetStringQuery(ref inputData, "page_size").ParseToInt(50);
+
+ string conn = System.Configuration.ConfigurationManager.ConnectionStrings["ConnKJD"].ConnectionString;
+ MysqlUtils mySql = new MysqlUtils(conn);
+
+ string sql = "select count(s.id) from kjd.product_select s left join kjd.product p on s.out_product_id=p.id" +
+ " where 1=1";
+ if (!isAdmin)
+ sql += " and (s.user_name='" + user_name + "' or s.sub_user_name like'%" + user_name + "%')";
+ if (!string.IsNullOrEmpty(search_db_ids))
+ sql += " and s.id in (" + search_db_ids + ")";
+ if (!string.IsNullOrEmpty(shop_ids))
+ sql += " and s.shop_id in (" + shop_ids + ")";
+ if (!string.IsNullOrWhiteSpace(status))
+ sql += " and s.status = '" + status + "'";
+ if (!string.IsNullOrWhiteSpace(search_shop_id))
+ sql += " and s.shop_id like '%" + search_shop_id + "%'";
+ if (!string.IsNullOrWhiteSpace(search_shop_account))
+ sql += " and s.shop_account like '%" + search_shop_account + "%'";
+ if (!string.IsNullOrWhiteSpace(search_notes))
+ sql += " and s.notes like '%" + search_notes + "%'";
+ if (!string.IsNullOrWhiteSpace(search_spu))
+ sql += " and p.spu_id like '%" + search_spu + "%'";
+ if (!string.IsNullOrWhiteSpace(search_skc))
+ sql += " and p.skc_id like '%" + search_skc + "%'";
+ if (!string.IsNullOrWhiteSpace(search_cat))
+ sql += " and p.cat_name like '%" + search_cat + "%'";
+ if (!string.IsNullOrWhiteSpace(search_ext_code))
+ sql += " and p.ext_code like '%" + search_ext_code + "%'";
+ if (!string.IsNullOrWhiteSpace(search_prod_name))
+ sql += " and p.product_name like '%" + search_prod_name + "%'";
+ var count = mySql.ExecuteRowCount(sql);
+
+ DataTable dt;
+ if (count == 0)
+ {
+ dt = new DataTable();
+ }
+ else
+ {
+ //if (isDetail)
+ //sql = "select * from kjd.product_select where 1=1";
+ //else
+ sql = "select s.id,s.out_product_id,s.shop_id,s.shop_account,s.user_name," +
+ "s.sub_user_name,s.notes,s.status,s.draft_id,s.add_time,s.mdy_time," +
+ "p.spu_id,p.skc_id,p.cat_id,p.cat_name,p.ext_code,p.product_name,p.main_img " +
+ "from kjd.product_select s left join kjd.product p on s.out_product_id=p.id where 1=1";
+ if (!isAdmin)
+ sql += " and (s.user_name='" + user_name + "' or s.sub_user_name like'%" + user_name + "%')";
+ if (!string.IsNullOrEmpty(search_db_ids))
+ sql += " and s.id in (" + search_db_ids + ")";
+ if (!string.IsNullOrEmpty(shop_ids))
+ sql += " and s.shop_id in (" + shop_ids + ")";
+ if (!string.IsNullOrWhiteSpace(status))
+ sql += " and s.status = '" + status + "'";
+ if (!string.IsNullOrWhiteSpace(search_shop_id))
+ sql += " and s.shop_id like '%" + search_shop_id + "%'";
+ if (!string.IsNullOrWhiteSpace(search_shop_account))
+ sql += " and s.shop_account like '%" + search_shop_account + "%'";
+ if (!string.IsNullOrWhiteSpace(search_notes))
+ sql += " and s.notes like '%" + search_notes + "%'";
+ if (!string.IsNullOrWhiteSpace(search_spu))
+ sql += " and p.spu_id like '%" + search_spu + "%'";
+ if (!string.IsNullOrWhiteSpace(search_skc))
+ sql += " and p.skc_id like '%" + search_skc + "%'";
+ if (!string.IsNullOrWhiteSpace(search_cat))
+ sql += " and p.cat_name like '%" + search_cat + "%'";
+ if (!string.IsNullOrWhiteSpace(search_ext_code))
+ sql += " and p.ext_code like '%" + search_ext_code + "%'";
+ if (!string.IsNullOrWhiteSpace(search_prod_name))
+ sql += " and p.product_name like '%" + search_prod_name + "%'";
+ sql += " order by id desc";
+ sql += " limit " + Math.Max(page - 1, 0) * page_size + "," + page_size;
+ dt = mySql.ExecuteDataTable(sql);
+ }
+
+ mySql.Close();
+ if (dt != null)
+ {
+ try
+ {
+ List productLst = new List();
+ foreach (DataRow row in dt.Rows)
+ {
+ ProductSelectResultParam prodSelect = new ProductSelectResultParam()
+ {
+ id = row["id"].ParseToInt(),
+ out_product_Id = row["out_product_Id"].ParseToString(),
+ shop_account = row["shop_account"].ParseToString(),
+ shop_id = row["shop_id"].ParseToString(),
+ status = row["status"].ParseToString(),
+ sub_user_name = row["sub_user_name"].ParseToString(),
+ user_name = row["user_name"].ParseToString(),
+ cat_id = row["cat_id"].ParseToString(),
+ cat_name = row["cat_name"].ParseToString(),
+ product_name = row["product_name"].ParseToString(),
+ main_img = row["main_img"].ParseToString(),
+ ext_code = row["ext_code"].ParseToString(),
+ add_time = Convert.ToDateTime(row["add_time"]),
+ mdy_time = Convert.ToDateTime(row["mdy_time"]),
+ notes = row["notes"].ParseToString(),
+ draft_id = row["draft_id"].ParseToString(),
+ skc_id = row["skc_id"].ToString(),
+ spu_id = row["spu_id"].ToString(),
+ //product_json = row["product_json"].ToString(),
+ //size_json = row["size_json"].ToString(),
+ };
+ productLst.Add(prodSelect);
+ }
+ var data = JsonUtils.SerializerObjectToString(productLst);
+ return "{\"code\":200,\"msg\":\"success\",\"data\":" + data + ",\"count\":" + count + "}";
+ }
+ catch (Exception ex)
+ {
+ return "{\"code\":500,\"msg\":\"" + ex.Message + "\",\"data\":[],\"count\":" + 0 + "}";
+ }
+ }
+ else
+ {
+ return "{\"code\":500,\"msg\":\"" + mySql.Message + "\",\"data\":[],\"count\":" + 0 + "}";
+ }
+ }
+ return "{\"code\":19999,\"msg\":\"输入为空\"}";
+ }
}
}
\ No newline at end of file
diff --git a/KJDService/KJD_WebService/KJD_WebService.csproj b/KJDService/KJD_WebService/KJD_WebService.csproj
index e347eae..fdc7126 100644
--- a/KJDService/KJD_WebService/KJD_WebService.csproj
+++ b/KJDService/KJD_WebService/KJD_WebService.csproj
@@ -115,6 +115,15 @@
Component
+
+
+
+
+
+
+
+
+
diff --git a/KJDService/KJD_WebService/Model/ProductSelectResultParam.cs b/KJDService/KJD_WebService/Model/ProductSelectResultParam.cs
index 7c981a4..d68ac04 100644
--- a/KJDService/KJD_WebService/Model/ProductSelectResultParam.cs
+++ b/KJDService/KJD_WebService/Model/ProductSelectResultParam.cs
@@ -19,7 +19,20 @@ namespace KJD_Web.Model
public string sub_user_name { get; set; }
public string notes { get; set; }
public string status { get; set; }
+ public string draft_id { get; set; }
public DateTime add_time { get; set; }
public DateTime mdy_time { get; set; }
+
+ #region 外键连接属性
+
+ public string cat_id { get; set; }
+ public string cat_name { get; set; }
+ public string ext_code { get; set; }
+ public string product_name { get; set; }
+ public string main_img { get; set; }
+ public string spu_id { get; set; }
+ public string skc_id { get; set; }
+
+ #endregion
}
}
\ No newline at end of file
diff --git a/KJDService/KJD_WebService/ProductService.asmx.cs b/KJDService/KJD_WebService/ProductService.asmx.cs
index 100ae5b..c3ed1b6 100644
--- a/KJDService/KJD_WebService/ProductService.asmx.cs
+++ b/KJDService/KJD_WebService/ProductService.asmx.cs
@@ -60,6 +60,18 @@ namespace KJD_Web
Context.Response.End();
}
+ [WebMethod]
+ public void get_product_detail_list()
+ {
+ string jsontext = GetRequestJsonString();
+
+ var result = jsontext;
+ result = new ProductManage().GetProductList(jsontext, true);
+
+ Context.Response.Write(result);
+ Context.Response.End();
+ }
+
[WebMethod]
public void add_product()
{
@@ -120,5 +132,42 @@ namespace KJD_Web
Context.Response.Write(result);
Context.Response.End();
}
+
+ [WebMethod]
+ public void mdy_user_select_product_status()
+ {
+ string jsontext = GetRequestJsonString();
+
+ var result = jsontext;
+ result = new ProductManage().MdyUserSelectProductStatus(jsontext);
+
+ Context.Response.Write(result);
+ Context.Response.End();
+ }
+
+ [WebMethod]
+ public void get_user_select_product_list()
+ {
+ string jsontext = GetRequestJsonString();
+
+ var result = jsontext;
+ result = new ProductManage().GetUserSelectProductList(jsontext);
+
+ Context.Response.Write(result);
+ Context.Response.End();
+ }
+
+
+ [WebMethod]
+ public void admin_get_user_select_product_list()
+ {
+ string jsontext = GetRequestJsonString();
+
+ var result = jsontext;
+ result = new ProductManage().GetUserSelectProductList(jsontext, true);
+
+ Context.Response.Write(result);
+ Context.Response.End();
+ }
}
}
diff --git a/KJDService/KJD_WebService/Utils/Extension/Extension.Convert.cs b/KJDService/KJD_WebService/Utils/Extension/Extension.Convert.cs
new file mode 100644
index 0000000..74a41c5
--- /dev/null
+++ b/KJDService/KJD_WebService/Utils/Extension/Extension.Convert.cs
@@ -0,0 +1,573 @@
+using System;
+using System.Collections;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using System.Runtime.Serialization.Formatters.Binary;
+using System.Text;
+using System.Threading.Tasks;
+using NaiBa.Util.Helper;
+using Newtonsoft.Json;
+
+namespace NaiBa.Util.Extension
+{
+ public static partial class Extensions
+ {
+ #region 转换为long
+ ///
+ /// 将object转换为long,若转换失败,则返回0。不抛出异常。
+ ///
+ ///
+ ///
+ public static long ParseToLong(this object obj)
+ {
+ try
+ {
+ string str = obj.ParseToString();
+ if (string.IsNullOrEmpty(str))
+ {
+ return 0;
+ }
+ return long.Parse(str);
+ }
+ catch
+ {
+ return 0L;
+ }
+ }
+
+ ///
+ /// 将object转换为long,若转换失败,则返回指定值。不抛出异常。
+ ///
+ ///
+ ///
+ ///
+ public static long ParseToLong(this string str, long defaultValue)
+ {
+ try
+ {
+ return long.Parse(str);
+ }
+ catch
+ {
+ return defaultValue;
+ }
+ }
+ #endregion
+
+ #region 转换为int
+ ///
+ /// 将object转换为int,若转换失败,则返回0。不抛出异常。
+ ///
+ ///
+ ///
+ public static int ParseToInt(this object str)
+ {
+ try
+ {
+ return Convert.ToInt32(str);
+ }
+ catch
+ {
+ return 0;
+ }
+ }
+
+ public static int DecimalPointParseToInt(this object str)
+ {
+ try
+ {
+ string temp = str.ParseToString();
+ int i = temp.IndexOf('.');
+ if (i > 0)
+ {
+ temp = temp.Substring(0, i);
+ }
+ return Convert.ToInt32(temp);
+ }
+ catch
+ {
+ return 0;
+ }
+ }
+
+ ///
+ /// 将object转换为int,若转换失败,则返回指定值。不抛出异常。
+ /// null返回默认值
+ ///
+ ///
+ ///
+ ///
+ public static int ParseToInt(this object str, int defaultValue)
+ {
+ if (str == null)
+ {
+ return defaultValue;
+ }
+ try
+ {
+ return Convert.ToInt32(str);
+ }
+ catch
+ {
+ return defaultValue;
+ }
+ }
+ #endregion
+
+ #region 转换为short
+ ///
+ /// 将object转换为short,若转换失败,则返回0。不抛出异常。
+ ///
+ ///
+ ///
+ public static short ParseToShort(this object obj)
+ {
+ try
+ {
+ return short.Parse(obj.ToString());
+ }
+ catch
+ {
+ return 0;
+ }
+ }
+
+ ///
+ /// 将object转换为short,若转换失败,则返回指定值。不抛出异常。
+ ///
+ ///
+ ///
+ public static short ParseToShort(this object str, short defaultValue)
+ {
+ try
+ {
+ return short.Parse(str.ToString());
+ }
+ catch
+ {
+ return defaultValue;
+ }
+ }
+ #endregion
+
+ #region 转换为demical
+ ///
+ /// 将object转换为demical,若转换失败,则返回指定值。不抛出异常。
+ ///
+ ///
+ ///
+ public static decimal ParseToDecimal(this object str, decimal defaultValue)
+ {
+ try
+ {
+ return decimal.Parse(str.ToString());
+ }
+ catch
+ {
+ return defaultValue;
+ }
+ }
+
+ ///
+ /// 将object转换为demical,若转换失败,则返回0。不抛出异常。
+ ///
+ ///
+ ///
+ public static decimal ParseToDecimal(this object str)
+ {
+ try
+ {
+ return decimal.Parse(str.ToString());
+ }
+ catch
+ {
+ return 0;
+ }
+ }
+ #endregion
+
+ #region 转化为bool
+ ///
+ /// 将object转换为bool,若转换失败,则返回false。不抛出异常。
+ ///
+ ///
+ ///
+ public static bool ParseToBool(this object str)
+ {
+ try
+ {
+ return bool.Parse(str.ToString());
+ }
+ catch
+ {
+ return false;
+ }
+ }
+
+ ///
+ /// 将object转换为bool,若转换失败,则返回指定值。不抛出异常。
+ ///
+ ///
+ ///
+ public static bool ParseToBool(this object str, bool result)
+ {
+ try
+ {
+ return bool.Parse(str.ToString());
+ }
+ catch
+ {
+ return result;
+ }
+ }
+ #endregion
+
+ #region 转换为float
+ ///
+ /// 将object转换为float,若转换失败,则返回0。不抛出异常。
+ ///
+ ///
+ ///
+ public static float ParseToFloat(this object str)
+ {
+ try
+ {
+ return float.Parse(str.ToString());
+ }
+ catch
+ {
+ return 0;
+ }
+ }
+
+ ///
+ /// 将object转换为float,若转换失败,则返回指定值。不抛出异常。
+ ///
+ ///
+ ///
+ public static float ParseToFloat(this object str, float result)
+ {
+ try
+ {
+ return float.Parse(str.ToString());
+ }
+ catch
+ {
+ return result;
+ }
+ }
+ #endregion
+
+ #region 转换为Guid
+ ///
+ /// 将string转换为Guid,若转换失败,则返回Guid.Empty。不抛出异常。
+ ///
+ ///
+ ///
+ public static Guid ParseToGuid(this string str)
+ {
+ try
+ {
+ return new Guid(str);
+ }
+ catch
+ {
+ return Guid.Empty;
+ }
+ }
+ #endregion
+
+ #region 转换为DateTime
+ ///
+ /// 将string转换为DateTime,若转换失败,则返回日期最小值。不抛出异常。
+ ///
+ ///
+ ///
+ public static DateTime ParseToDateTime(this string str)
+ {
+ try
+ {
+ if (string.IsNullOrWhiteSpace(str))
+ {
+ return DateTime.MinValue;
+ }
+ if (str.Contains("-") || str.Contains("/"))
+ {
+ return DateTime.Parse(str);
+ }
+ else
+ {
+ int length = str.Length;
+ switch (length)
+ {
+ case 4:
+ return DateTime.ParseExact(str, "yyyy", System.Globalization.CultureInfo.CurrentCulture);
+ case 6:
+ return DateTime.ParseExact(str, "yyyyMM", System.Globalization.CultureInfo.CurrentCulture);
+ case 8:
+ return DateTime.ParseExact(str, "yyyyMMdd", System.Globalization.CultureInfo.CurrentCulture);
+ case 10:
+ return DateTime.ParseExact(str, "yyyyMMddHH", System.Globalization.CultureInfo.CurrentCulture);
+ case 12:
+ return DateTime.ParseExact(str, "yyyyMMddHHmm", System.Globalization.CultureInfo.CurrentCulture);
+ case 14:
+ return DateTime.ParseExact(str, "yyyyMMddHHmmss", System.Globalization.CultureInfo.CurrentCulture);
+ default:
+ return DateTime.ParseExact(str, "yyyyMMddHHmmss", System.Globalization.CultureInfo.CurrentCulture);
+ }
+ }
+ }
+ catch
+ {
+ return DateTime.MinValue;
+ }
+ }
+
+ ///
+ /// 将string转换为DateTime,若转换失败,则返回默认值。
+ ///
+ ///
+ ///
+ ///
+ public static DateTime ParseToDateTime(this string str, DateTime? defaultValue)
+ {
+ try
+ {
+ if (string.IsNullOrWhiteSpace(str))
+ {
+ return defaultValue.GetValueOrDefault();
+ }
+ if (str.Contains("-") || str.Contains("/"))
+ {
+ return DateTime.Parse(str);
+ }
+ else
+ {
+ int length = str.Length;
+ switch (length)
+ {
+ case 4:
+ return DateTime.ParseExact(str, "yyyy", System.Globalization.CultureInfo.CurrentCulture);
+ case 6:
+ return DateTime.ParseExact(str, "yyyyMM", System.Globalization.CultureInfo.CurrentCulture);
+ case 8:
+ return DateTime.ParseExact(str, "yyyyMMdd", System.Globalization.CultureInfo.CurrentCulture);
+ case 10:
+ return DateTime.ParseExact(str, "yyyyMMddHH", System.Globalization.CultureInfo.CurrentCulture);
+ case 12:
+ return DateTime.ParseExact(str, "yyyyMMddHHmm", System.Globalization.CultureInfo.CurrentCulture);
+ case 14:
+ return DateTime.ParseExact(str, "yyyyMMddHHmmss", System.Globalization.CultureInfo.CurrentCulture);
+ default:
+ return DateTime.ParseExact(str, "yyyyMMddHHmmss", System.Globalization.CultureInfo.CurrentCulture);
+ }
+ }
+ }
+ catch
+ {
+ return defaultValue.GetValueOrDefault();
+ }
+ }
+ #endregion
+
+ #region 转换为string
+ ///
+ /// 将object转换为string,若转换失败,则返回""。不抛出异常。
+ ///
+ ///
+ ///
+ public static string ParseToString(this object obj)
+ {
+ try
+ {
+ if (obj == null)
+ {
+ return string.Empty;
+ }
+ else
+ {
+ return obj.ToString();
+ }
+ }
+ catch
+ {
+ return string.Empty;
+ }
+ }
+
+ public static string ParseToStrings(this object obj, string split = ",")
+ {
+ try
+ {
+ var list = obj as IEnumerable;
+ if (list != null)
+ {
+ return string.Join(split, list);
+ }
+ else
+ {
+ return obj.ToString();
+ }
+ }
+ catch
+ {
+ return string.Empty;
+ }
+ }
+ #endregion
+
+ #region 转换为double
+ ///
+ /// 将object转换为double,若转换失败,则返回0。不抛出异常。
+ ///
+ ///
+ ///
+ public static double ParseToDouble(this object obj)
+ {
+ try
+ {
+ return double.Parse(obj.ToString());
+ }
+ catch
+ {
+ return 0;
+ }
+ }
+
+ ///
+ /// 将object转换为double,若转换失败,则返回指定值。不抛出异常。
+ ///
+ ///
+ ///
+ ///
+ public static double ParseToDouble(this object str, double defaultValue)
+ {
+ try
+ {
+ return double.Parse(str.ToString());
+ }
+ catch
+ {
+ return defaultValue;
+ }
+ }
+ #endregion
+
+ #region 字符串转指定类型Array
+ public static T[] SplitToArray(this string value, string split = ",")
+ {
+ if (string.IsNullOrEmpty(value))
+ {
+ return default(T[]);
+ }
+ var arr = value.Split(new string[] { split }, StringSplitOptions.RemoveEmptyEntries).CastSuper().ToArray();
+ return arr;
+ }
+
+ public static T[] SplitToArray(this string value, string[] split)
+ {
+ if (string.IsNullOrEmpty(value))
+ {
+ return default(T[]);
+ }
+ var arr = value.Split(split, StringSplitOptions.RemoveEmptyEntries).CastSuper().ToArray();
+ return arr;
+ }
+ #endregion
+
+ #region 字符串转指定类型List
+ public static List SplitToList(this string value, string split = ",")
+ {
+ if (string.IsNullOrEmpty(value))
+ {
+ return new List();
+ }
+ var list = value.Split(new string[] { split }, StringSplitOptions.RemoveEmptyEntries).CastSuper().ToList();
+ return list;
+ }
+
+ public static List SplitToList(this string value, string[] split)
+ {
+ if (string.IsNullOrEmpty(value))
+ {
+ return new List();
+ }
+ var list = value.Split(split, StringSplitOptions.RemoveEmptyEntries).CastSuper().ToList();
+ return list;
+ }
+ #endregion
+
+ #region 强制转换类型
+ ///
+ /// 强制转换类型
+ ///
+ ///
+ ///
+ ///
+ public static IEnumerable CastSuper(this IEnumerable source)
+ {
+ foreach (object item in source)
+ {
+ yield return (TResult)Convert.ChangeType(item, typeof(TResult));
+ }
+ }
+ #endregion
+
+ #region Object转换为Json
+ public static string ParseToJson(this object obj)
+ {
+ return JsonConvert.SerializeObject(obj);
+ }
+ #endregion
+
+ #region Json转为Object
+ public static T ParseToObject(this string json)
+ {
+ if (string.IsNullOrEmpty(json))
+ {
+ return Activator.CreateInstance();
+ }
+ return JsonConvert.DeserializeObject(json);
+ }
+ #endregion
+
+ #region 深拷贝(克隆出一个新对象,拷贝对象里面的数据和子对象)
+ public static T DeepClone(this T o)
+ {
+ return o.ParseToJson().ParseToObject();
+ // 这种方式在用 Obfuscator 的时候有问题
+ //using (MemoryStream stream = new MemoryStream())
+ //{
+ // BinaryFormatter formatter = new BinaryFormatter();
+ // formatter.Serialize(stream, o);
+ // stream.Position = 0;
+ // return (T)formatter.Deserialize(stream);
+ //}
+ }
+ #endregion
+
+ #region 浅拷贝(拷贝对象里面的数据[property and field],但不拷贝对象里面的子对象)
+ public static void ShadowClone(this T1 source, ref T2 destination)
+ {
+ var sourceMembers = ReflectionHelper.GetMembers(source.GetType());
+ var destinationMembers = ReflectionHelper.GetMembers(destination.GetType());
+
+ // Copy data from source to destination
+ foreach (var sourceMember in sourceMembers)
+ {
+ if (!ReflectionHelper.CanRead(sourceMember))
+ {
+ continue;
+ }
+ var destinationMember = destinationMembers.FirstOrDefault(x => x.Name.ToLower() == sourceMember.Name.ToLower());
+ if (destinationMember == null || !ReflectionHelper.CanWrite(destinationMember))
+ {
+ continue;
+ }
+ ReflectionHelper.SetObjectValue(ref destination, destinationMember, ReflectionHelper.GetMemberValue(source, sourceMember));
+ }
+ }
+ #endregion
+ }
+}
diff --git a/KJDService/KJD_WebService/Utils/Extension/Extension.Enum.cs b/KJDService/KJD_WebService/Utils/Extension/Extension.Enum.cs
new file mode 100644
index 0000000..707f49a
--- /dev/null
+++ b/KJDService/KJD_WebService/Utils/Extension/Extension.Enum.cs
@@ -0,0 +1,114 @@
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Linq;
+using System.Reflection;
+using System.Text;
+using System.Threading.Tasks;
+using Newtonsoft.Json;
+
+namespace NaiBa.Util.Extension
+{
+ public static partial class Extensions
+ {
+ #region 枚举成员转成dictionary类型
+ ///
+ /// 转成dictionary类型
+ ///
+ ///
+ ///
+ public static Dictionary EnumToDictionary(this Type enumType)
+ {
+ Dictionary dictionary = new Dictionary();
+ Type typeDescription = typeof(DescriptionAttribute);
+ FieldInfo[] fields = enumType.GetFields();
+ int sValue = 0;
+ string sText = string.Empty;
+ foreach (FieldInfo field in fields)
+ {
+ if (field.FieldType.IsEnum)
+ {
+ sValue = ((int)enumType.InvokeMember(field.Name, BindingFlags.GetField, null, null, null));
+ object[] arr = field.GetCustomAttributes(typeDescription, true);
+ if (arr.Length > 0)
+ {
+ DescriptionAttribute da = (DescriptionAttribute)arr[0];
+ sText = da.Description;
+ }
+ else
+ {
+ sText = field.Name;
+ }
+ dictionary.Add(sValue, sText);
+ }
+ }
+ return dictionary.OrderBy(p => p.Key).ToDictionary(p => p.Key, p => p.Value);
+ }
+
+ ///
+ /// 枚举成员转成键值对Json字符串
+ ///
+ ///
+ ///
+ public static string EnumToDictionaryString(this Type enumType)
+ {
+ List> dictionaryList = EnumToDictionary(enumType).ToList();
+ var sJson = JsonConvert.SerializeObject(dictionaryList);
+ return sJson;
+ }
+ #endregion
+
+ #region 根据类型获取枚举的描述
+ ///
+ /// 获取枚举值对应的描述
+ ///
+ ///
+ ///
+ public static string GetDescription(this System.Enum enumType)
+ {
+ FieldInfo EnumInfo = enumType.GetType().GetField(enumType.ToString());
+ if (EnumInfo != null)
+ {
+ DescriptionAttribute[] EnumAttributes = (DescriptionAttribute[])EnumInfo.GetCustomAttributes(typeof(DescriptionAttribute), false);
+ if (EnumAttributes.Length > 0)
+ {
+ return EnumAttributes[0].Description;
+ }
+ }
+ return enumType.ToString();
+ }
+ #endregion
+
+ #region 根据值获取枚举的描述
+ public static string GetDescriptionByEnum(this object obj)
+ {
+ var tEnum = System.Enum.Parse(typeof(T), obj.ParseToString()) as System.Enum;
+ var description = tEnum.GetDescription();
+ return description;
+ }
+ #endregion
+
+ #region 根据描述获取枚举值
+ public static int GetEnumValueByDescription(this string description)
+ {
+ Dictionary dict = typeof(T).EnumToDictionary();
+ int value = dict.Where(p => p.Value == description).Select(p => p.Key).FirstOrDefault();
+ return value;
+ }
+ #endregion
+
+ #region 根据枚举名称获取值
+ public static int GetEnumValueByName(this string name)
+ {
+ return (int)System.Enum.Parse(typeof(T), name);
+ }
+ #endregion
+
+ #region 根据枚举值获取名称
+ public static object GetEnumNameByValue(this int value)
+ {
+ return System.Enum.ToObject(typeof(T), value);
+ }
+ #endregion
+ }
+}
diff --git a/KJDService/KJD_WebService/Utils/Extension/Extension.Exception.cs b/KJDService/KJD_WebService/Utils/Extension/Extension.Exception.cs
new file mode 100644
index 0000000..11447f3
--- /dev/null
+++ b/KJDService/KJD_WebService/Utils/Extension/Extension.Exception.cs
@@ -0,0 +1,18 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace NaiBa.Util.Extension
+{
+ public static partial class Extensions
+ {
+ public static Exception GetOriginalException(this Exception ex)
+ {
+ if (ex.InnerException == null) return ex;
+
+ return ex.InnerException.GetOriginalException();
+ }
+ }
+}
diff --git a/KJDService/KJD_WebService/Utils/Extension/Extension.Linq.cs b/KJDService/KJD_WebService/Utils/Extension/Extension.Linq.cs
new file mode 100644
index 0000000..4eadb77
--- /dev/null
+++ b/KJDService/KJD_WebService/Utils/Extension/Extension.Linq.cs
@@ -0,0 +1,110 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Linq.Expressions;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace NaiBa.Util.Extension
+{
+ public static class LinqExtensions
+ {
+ public static Expression Property(this Expression expression, string propertyName)
+ {
+ return Expression.Property(expression, propertyName);
+ }
+ public static Expression AndAlso(this Expression left, Expression right)
+ {
+ return Expression.AndAlso(left, right);
+ }
+ public static Expression Call(this Expression instance, string methodName, params Expression[] arguments)
+ {
+ return Expression.Call(instance, instance.Type.GetMethod(methodName), arguments);
+ }
+ public static Expression GreaterThan(this Expression left, Expression right)
+ {
+ return Expression.GreaterThan(left, right);
+ }
+ public static Expression ToLambda(this Expression body, params ParameterExpression[] parameters)
+ {
+ return Expression.Lambda(body, parameters);
+ }
+
+ public static Expression> True() { return param => true; }
+
+ public static Expression> False() { return param => false; }
+
+ ///
+ /// 组合And
+ ///
+ ///
+ public static Expression> And(this Expression> first, Expression> second)
+ {
+ return first.Compose(second, Expression.AndAlso);
+ }
+ ///
+ /// 组合Or
+ ///
+ ///
+ public static Expression> Or(this Expression> first, Expression> second)
+ {
+ return first.Compose(second, Expression.OrElse);
+ }
+
+ ///
+ /// Combines the first expression with the second using the specified merge function.
+ ///
+ static Expression Compose(this Expression first, Expression second, Func merge)
+ {
+ var map = first.Parameters
+ .Select((f, i) => new { f, s = second.Parameters[i] })
+ .ToDictionary(p => p.s, p => p.f);
+ var secondBody = ParameterRebinder.ReplaceParameters(map, second.Body);
+ return Expression.Lambda(merge(first.Body, secondBody), first.Parameters);
+ }
+
+ ///
+ /// ParameterRebinder
+ ///
+ private class ParameterRebinder : ExpressionVisitor
+ {
+ ///
+ /// The ParameterExpression map
+ ///
+ readonly Dictionary map;
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// The map.
+ ParameterRebinder(Dictionary map)
+ {
+ this.map = map ?? new Dictionary();
+ }
+ ///
+ /// Replaces the parameters.
+ ///
+ /// The map.
+ /// The exp.
+ /// Expression
+ public static Expression ReplaceParameters(Dictionary map, Expression exp)
+ {
+ return new ParameterRebinder(map).Visit(exp);
+ }
+ ///
+ /// Visits the parameter.
+ ///
+ /// The p.
+ /// Expression
+ protected override Expression VisitParameter(ParameterExpression p)
+ {
+ ParameterExpression replacement;
+
+ if (map.TryGetValue(p, out replacement))
+ {
+ p = replacement;
+ }
+ return base.VisitParameter(p);
+ }
+ }
+ }
+}
diff --git a/KJDService/KJD_WebService/Utils/Extension/Extension.Validate.cs b/KJDService/KJD_WebService/Utils/Extension/Extension.Validate.cs
new file mode 100644
index 0000000..52db466
--- /dev/null
+++ b/KJDService/KJD_WebService/Utils/Extension/Extension.Validate.cs
@@ -0,0 +1,117 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Web;
+using NaiBa.Util.Helper;
+using Newtonsoft.Json.Linq;
+
+namespace NaiBa.Util.Extension
+{
+ public static partial class Extensions
+ {
+ public static bool IsNullOrEmpty(this object value)
+ {
+ if (value != null && !string.IsNullOrEmpty(value.ParseToString()))
+ {
+ return false;
+ }
+ else
+ {
+ return true;
+ }
+ }
+
+ public static bool IsNullOrZero(this object value)
+ {
+ if (value == null || string.IsNullOrEmpty(value.ParseToString()) || value.ParseToString().Trim() == "0")
+ {
+ return true;
+ }
+ else
+ {
+ return false;
+ }
+ }
+
+ public static bool IsNumericType(this object value)
+ {
+ if (value == null)
+ {
+ return false;
+ }
+ switch (Type.GetTypeCode(value.GetType()))
+ {
+ case TypeCode.Byte:
+ case TypeCode.SByte:
+ case TypeCode.UInt16:
+ case TypeCode.UInt32:
+ case TypeCode.UInt64:
+ case TypeCode.Int16:
+ case TypeCode.Int32:
+ case TypeCode.Int64:
+ case TypeCode.Decimal:
+ case TypeCode.Double:
+ case TypeCode.Single:
+ return true;
+ default:
+ return false;
+ }
+ }
+
+ public static bool IsStringType(this object value)
+ {
+ if (value == null)
+ {
+ return false;
+ }
+ switch (Type.GetTypeCode(value.GetType()))
+ {
+ case TypeCode.String:
+ return true;
+ default:
+ return false;
+ }
+ }
+
+ public static bool IsNumber(this string value)
+ {
+ return RegexHelper.IsNumber(value);
+ }
+
+ public static bool IsAlphabet(this string value)
+ {
+ return RegexHelper.IsAlphabet(value);
+ }
+
+ public static bool IsAlphabetOrNumber(this string value)
+ {
+ return RegexHelper.IsAlphabetOrNumber(value);
+ }
+
+ public static bool IsJson(this string value)
+ {
+ return JsonHelper.IsJson(value);
+ }
+
+ public static bool IsJTokenNullOrEmpty(this JToken token)
+ {
+ return (token == null) ||
+ (token.Type == JTokenType.Array && !token.HasValues) ||
+ (token.Type == JTokenType.Object && !token.HasValues) ||
+ (token.Type == JTokenType.String && token.ToString() == string.Empty) ||
+ (token.Type == JTokenType.Null);
+ }
+
+ public static bool IsAjaxRequest(this HttpRequest request)
+ {
+ if (request == null)
+ throw new ArgumentNullException("request");
+
+ if (request.Headers != null)
+ return request.Headers["X-Requested-With"] == "XMLHttpRequest";
+ return false;
+ }
+ }
+}
diff --git a/KJDService/KJD_WebService/Utils/Helper/HtmlHelper.cs b/KJDService/KJD_WebService/Utils/Helper/HtmlHelper.cs
new file mode 100644
index 0000000..db9f242
--- /dev/null
+++ b/KJDService/KJD_WebService/Utils/Helper/HtmlHelper.cs
@@ -0,0 +1,215 @@
+using System;
+using System.Collections.Generic;
+using System.Globalization;
+using System.Linq;
+using System.Net;
+using System.Text;
+using System.Text.RegularExpressions;
+using System.Threading.Tasks;
+using System.Web;
+using NaiBa.Util.Extension;
+
+namespace NaiBa.Util.Helper
+{
+ public class HtmlHelper
+ {
+ public static string HtmlEncode(string html)
+ {
+ if (string.IsNullOrEmpty(html))
+ {
+ return string.Empty;
+ }
+ else
+ {
+ return HttpUtility.HtmlEncode(html);
+ }
+ }
+
+ public static string HtmlDecode(string url)
+ {
+ if (string.IsNullOrEmpty(url))
+ {
+ return string.Empty;
+ }
+ else
+ {
+ return HttpUtility.HtmlDecode(url);
+ }
+ }
+
+ ///
+ /// Unicode解码
+ ///
+ ///
+ ///
+ public static string UnicodeDecode(string html)
+ {
+ html = WebUtility.HtmlDecode(html);
+
+ Regex reUnicode = new Regex(@"\\u([0-9a-fA-F]{4})", RegexOptions.Compiled);
+ return reUnicode.Replace(html, m =>
+ {
+ short c;
+ if (short.TryParse(m.Groups[1].Value, NumberStyles.HexNumber, CultureInfo.InvariantCulture, out c))
+ {
+ return "" + (char)c;
+ }
+ return m.Value;
+ });
+ }
+
+ #region Resove
+ public static string Resove(string html, string prefix, string subfix = "")
+ {
+ int inl = html.IndexOf(prefix);
+ if (inl == -1)
+ {
+ prefix = prefix.Replace("\"", "'");
+ subfix = subfix.Replace("\"", "'");
+ inl = html.IndexOf(prefix);
+ }
+ if (inl == -1)
+ {
+ return null;
+ }
+ inl += prefix.Length;
+ if (!string.IsNullOrEmpty(subfix))
+ {
+ int inl2 = html.IndexOf(subfix, inl);
+ if (inl2 == -1)
+ {
+ return null;
+ }
+ string result = html.Substring(inl, inl2 - inl);
+ return result;
+ }
+ else
+ {
+ string result = html.Substring(inl);
+ return result;
+ }
+ }
+ #endregion
+
+ #region ResoveReverse
+ public static string ResoveReverse(string html, string subfix, string prefix)
+ {
+ int inl = html.IndexOf(subfix);
+ if (inl == -1)
+ {
+ return null;
+ }
+ string subString = html.Substring(0, inl);
+ int inl2 = subString.LastIndexOf(prefix);
+ if (inl2 == -1)
+ {
+ return null;
+ }
+ string s = subString.Substring(inl2 + prefix.Length, subString.Length - inl2 - prefix.Length);
+ return s;
+ }
+ #endregion
+
+ #region ResoveList
+ public static List ResoveList(string html, string prefix, string subfix)
+ {
+ List list = new List();
+ int index = 0;
+ do
+ {
+ index = html.IndexOf(prefix, index);
+ if (index == -1)
+ {
+ break;
+ }
+ index += prefix.Length;
+ int indexEnd = html.IndexOf(subfix, index);
+ if (indexEnd > 0)
+ {
+ string content = html.Substring(index, indexEnd - index);
+ list.Add(content);
+ }
+ index = indexEnd;
+ }
+ while (index > -1);
+ return list;
+ }
+ #endregion
+
+ #region ResoveListByAT
+ public static List ResoveListByAT(string html)
+ {
+ List list = new List();
+
+ int index = html.IndexOf('@');
+ while (index > 0)
+ {
+ int indexx = html.LastIndexOf("'", index); //向前一个单引号
+ int indexy = html.IndexOf("'", index + 1); //向后一个单引号
+ string s78 = html.Substring(indexx, indexy - indexx);
+ s78 = s78.Replace("'", "");
+ list.Add(s78);
+ index = html.IndexOf('@', indexy);
+ }
+ return list;
+ }
+ #endregion
+
+ ///
+ /// 清除HTML代码
+ ///
+ ///
+ public static string ClearHtml(string html)
+ {
+ html = html.ParseToString();
+ html = Regex.Replace(html, @"(|