1338 lines
58 KiB
C#
1338 lines
58 KiB
C#
using System;
|
||
using System.Collections.Generic;
|
||
using System.Data;
|
||
using System.Diagnostics;
|
||
using System.IO;
|
||
using System.Net;
|
||
using System.Reflection;
|
||
using System.Text;
|
||
using System.Threading.Tasks;
|
||
using System.Web;
|
||
using SuperMap.RealEstate.ServiceModel;
|
||
using Business = SuperMap.RealEstate.FrameWork.Platform.Business;
|
||
using Newtonsoft.Json.Linq;
|
||
using HZQR.Common;
|
||
|
||
namespace CodeBuilderApi
|
||
{
|
||
/// <summary>
|
||
/// 公共方法
|
||
/// </summary>
|
||
public class CommonHelper
|
||
{
|
||
/// <summary>
|
||
/// 数字数组
|
||
/// </summary>
|
||
public const string charSet = "0,1,2,3,4,5,6,7,8,9";
|
||
|
||
#region 方法 -> 将DateTime类型转换为long类型
|
||
/// <summary>
|
||
/// 将DateTime类型转换为long类型
|
||
/// </summary>
|
||
/// <param name="dt">时间</param>
|
||
/// <returns></returns>
|
||
public static long ConvertDataTimeLong(DateTime dt)
|
||
{
|
||
DateTime dtStart = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1));
|
||
TimeSpan toNow = dt.Subtract(dtStart);
|
||
long timeStamp = toNow.Ticks;
|
||
timeStamp = long.Parse(timeStamp.ToString().Substring(0, timeStamp.ToString().Length - 7));
|
||
return timeStamp;
|
||
}
|
||
#endregion
|
||
|
||
#region 方法 -> 将Long类型转换为DateTime类型
|
||
/// <summary>
|
||
/// 将Long类型转换为DateTime类型
|
||
/// </summary>
|
||
/// <param name="d">long</param>
|
||
/// <returns></returns>s
|
||
public static DateTime ConvertLongDateTime(long d)
|
||
{
|
||
DateTime dtStart = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1));
|
||
long lTime = long.Parse(d + "0000000");
|
||
TimeSpan toNow = new TimeSpan(lTime);
|
||
DateTime dtResult = dtStart.Add(toNow);
|
||
return dtResult;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 时间戳(毫秒值)String转换为DateTime类型转换
|
||
/// </summary>
|
||
/// <param name="time">毫秒时间戳</param>
|
||
/// <returns></returns>
|
||
public static DateTime TicksToDate(string time)
|
||
{
|
||
return new DateTime((Convert.ToInt64(time) * 10000) + 621355968000000000);
|
||
}
|
||
#endregion
|
||
|
||
#region 方法 -> 枚举参数过滤处理
|
||
/// <summary>
|
||
/// 枚举参数过滤处理,解决麻烦的SQL拼接
|
||
/// (对照数据表给定添加、更新的参数枚举类型ValueType)
|
||
/// </summary>
|
||
/// <param name="_Type">数据类型</param>
|
||
/// <param name="_String">数据值</param>
|
||
/// <returns></returns>
|
||
public static string IsArrayType(ValueType _Type, object _String = null)
|
||
{
|
||
if (_String != null && _String.ToString() != "")
|
||
{
|
||
switch (_Type)
|
||
{
|
||
case ValueType.String:
|
||
return string.Format("'{0}'", _String.ToString().Replace("'", " "));
|
||
case ValueType.Int:
|
||
case ValueType.Double:
|
||
case ValueType.Boolean:
|
||
return _String.ToString();
|
||
case ValueType.DateTime:
|
||
return string.Format("TO_DATE('{0}','YYYY/MM/DD HH24:MI:SS')", _String);
|
||
}
|
||
}
|
||
return "null";
|
||
}
|
||
|
||
/// <summary>
|
||
/// 枚举参数过滤处理,解决麻烦的SQL拼接
|
||
/// (对照数据表给定添加、更新的参数枚举类型ValueType)
|
||
/// </summary>
|
||
/// <param name="_Type">数据类型</param>
|
||
/// <param name="_DefaultValue">是否使用缺省值</param>
|
||
/// <returns></returns>
|
||
private static string IsArrayType(ValueType _Type, bool _DefaultValue = false)
|
||
{
|
||
if (_DefaultValue)
|
||
{
|
||
switch (_Type)
|
||
{
|
||
case ValueType.String:
|
||
return "''";
|
||
case ValueType.Int:
|
||
case ValueType.Double:
|
||
case ValueType.Boolean:
|
||
return "0";
|
||
case ValueType.DateTime:
|
||
return string.Format("TO_DATE('{0}','YYYY/MM/DD HH24:MI:SS')", DateTime.Now.ToString());
|
||
}
|
||
}
|
||
return "null";
|
||
}
|
||
#endregion
|
||
|
||
#region 方法 -> 定义5个类型的枚举
|
||
/// <summary>
|
||
/// 定义5个类型的枚举
|
||
/// </summary>
|
||
public enum ValueType
|
||
{
|
||
/// <summary>
|
||
/// 字符串
|
||
/// </summary>
|
||
String = 0,
|
||
/// <summary>
|
||
/// 整型
|
||
/// </summary>
|
||
Int = 1,
|
||
/// <summary>
|
||
/// 双精度
|
||
/// </summary>
|
||
Double = 2,
|
||
/// <summary>
|
||
/// true或false
|
||
/// </summary>
|
||
Boolean = 3,
|
||
/// <summary>
|
||
/// 日期
|
||
/// </summary>
|
||
DateTime = 4
|
||
}
|
||
#endregion
|
||
|
||
#region 方法 -> SQL语句分页
|
||
/// <summary>
|
||
/// SQL语句分页
|
||
/// </summary>
|
||
/// <param name="sql">SQL语句</param>
|
||
/// <param name="rn">开始的行号</param>
|
||
/// <param name="rowNum">结束的行号</param>
|
||
/// <returns></returns>
|
||
public static string GetPageSql(string sql, int? rn = null, int? rowNum = null)
|
||
{
|
||
if (rn != null && rowNum != null)
|
||
{
|
||
//分页查询
|
||
sql = string.Format(@"
|
||
SELECT * FROM (
|
||
SELECT ROWNUM RN,N.* FROM ({0}) N WHERE ROWNUM<={1}
|
||
) M WHERE M.RN>={2}", sql, rowNum, rn);
|
||
}
|
||
|
||
return sql;
|
||
}
|
||
#endregion
|
||
|
||
#region 方法 -> 为属性赋值
|
||
/// <summary>
|
||
/// 为属性赋值
|
||
/// </summary>
|
||
/// <typeparam name="T">源单类</typeparam>
|
||
/// <typeparam name="S">需要转换的实体类</typeparam>
|
||
/// <param name="source"></param>
|
||
/// <returns></returns>
|
||
public static S EntityConvert<T, S>(T source)
|
||
{
|
||
S target = Activator.CreateInstance<S>();
|
||
var sType = source.GetType();
|
||
var dType = typeof(S);
|
||
foreach (PropertyInfo now in sType.GetProperties())
|
||
{
|
||
var name = dType.GetProperty(now.Name);
|
||
if (name == null)
|
||
continue;
|
||
dType.GetProperty(now.Name).SetValue(target, now.GetValue(source));
|
||
}
|
||
return target;
|
||
}
|
||
#endregion
|
||
|
||
#region 方法 -> 获取指定页码Datatable数据
|
||
/// <summary>
|
||
/// 获取指定页码Datatable数据
|
||
/// </summary>
|
||
/// <param name="dtOrigin">源数据</param>
|
||
/// <param name="pageSize">每页返回的数量</param>
|
||
/// <param name="pageIndex">返回第几页数据</param>
|
||
/// <returns>Datatable数据格式</returns>
|
||
public static DataTable GetDataTableWithPageSize(DataTable dtOrigin, int pageSize, int pageIndex)
|
||
{
|
||
if (pageIndex == 0)
|
||
{
|
||
pageIndex = 1;
|
||
}
|
||
if (pageSize == 0)
|
||
{
|
||
pageSize = 10;
|
||
}
|
||
//克隆数据源
|
||
DataTable dtClone = dtOrigin.Clone();
|
||
dtClone.Columns.Add("RN", typeof(int));
|
||
//开始插入数据源
|
||
for (int RowCount = 0; RowCount < pageSize; RowCount++)
|
||
{
|
||
//获取当前数据源行数
|
||
int RN = pageSize * (pageIndex - 1) + RowCount;
|
||
//如果行数大于数据源实际数量,则直接跳过
|
||
if (RN >= dtOrigin.Rows.Count)
|
||
{
|
||
break;
|
||
}
|
||
//获取当前数据源内容
|
||
DataRow EndAccountDataRow = dtOrigin.Rows[RN];
|
||
//创建一个新 System.Data.DataRow 具有与表相同的架构
|
||
DataRow _DataRow = dtClone.NewRow();
|
||
//开始插入数据
|
||
for (int ColumnsCount = 0; ColumnsCount < dtOrigin.Columns.Count; ColumnsCount++)
|
||
{
|
||
_DataRow[ColumnsCount] = EndAccountDataRow[ColumnsCount];
|
||
}
|
||
_DataRow["RN"] = RN + 1;
|
||
//将数据加入到克隆的DataTable中
|
||
dtClone.Rows.Add(_DataRow);
|
||
}
|
||
|
||
return dtClone;
|
||
}
|
||
#endregion
|
||
|
||
#region 方法 -> 合并Datatable中某个字符串的值
|
||
/// <summary>
|
||
/// 合并Datatable中某个字符串的值,返回list
|
||
/// </summary>
|
||
/// <param name="dataTable">数据源</param>
|
||
/// <param name="FieldName">字段名称</param>
|
||
/// <param name="SortStr">排序字段</param>
|
||
/// <returns></returns>
|
||
public static List<string> JoinListFromDataTable(DataTable dataTable, string FieldName, string SortStr = "")
|
||
{
|
||
List<string> JoinStr = new List<string>();
|
||
|
||
foreach (DataRow dataRow in dataTable.DefaultView.ToTable(true, FieldName).Select("", SortStr))
|
||
{
|
||
if (dataRow[FieldName].ToString() != "")
|
||
{
|
||
JoinStr.Add(dataRow[FieldName].ToString());
|
||
}
|
||
}
|
||
|
||
return JoinStr;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 合并Datatable中某个字符串的值,返回string
|
||
/// </summary>
|
||
/// <param name="dataTable">数据源</param>
|
||
/// <param name="FieldName">字段名称</param>
|
||
/// <param name="SeparateStr">分隔符,默认为,</param>
|
||
/// <param name="SortStr">排序字段</param>
|
||
/// <returns></returns>
|
||
public static string JoinStrFromDataTable(DataTable dataTable, string FieldName,
|
||
string SeparateStr = ",", string SortStr = "")
|
||
{
|
||
string JoinStr = "";
|
||
|
||
foreach (DataRow dataRow in dataTable.DefaultView.ToTable(true, FieldName).Select("", SortStr))
|
||
{
|
||
if (dataRow[FieldName].ToString() != "")
|
||
{
|
||
JoinStr += (JoinStr == "" ? "" : SeparateStr) + dataRow[FieldName];
|
||
}
|
||
}
|
||
|
||
return JoinStr;
|
||
}
|
||
#endregion
|
||
|
||
//------------------以下是低代码平台的相关方法--------------------------//
|
||
|
||
#region 方法 -> 获取接口类对象名称 <- GetInterfaceClassName
|
||
/// <summary>
|
||
/// 获取接口表相关类名称
|
||
/// </summary>
|
||
/// <param name="transaction">事务管理器</param>
|
||
/// <param name="InterfaceId">接口加密内码</param>
|
||
/// <returns></returns>
|
||
public static string GetInterfaceClassName(Transaction transaction, int InterfaceId)
|
||
{
|
||
string ClassName = "";
|
||
//根据接口内码查询接口对象
|
||
Model.INTERFACEModel interfaceModel = GeneralMethod.INTERFACEHelper.GetINTERFACEDetail(transaction, InterfaceId);
|
||
if (interfaceModel != null && interfaceModel.INTERFACE_ID != null)
|
||
{
|
||
ClassName = GetInterfaceClassName(interfaceModel.INTERFACE_TYPE.Value, interfaceModel.INTERFACE_ROUTE);
|
||
}
|
||
|
||
return ClassName;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 获取接口表相关类名称
|
||
/// </summary>
|
||
/// <param name="InterfaceType">接口类型:0【标准接口】</param>
|
||
/// <param name="InterfaceRoute">接口路由</param>
|
||
/// <returns></returns>
|
||
public static string GetInterfaceClassName(int InterfaceType, string InterfaceRoute)
|
||
{
|
||
string ClassName = "";
|
||
//判断是不是标准接口,如果是标准接口,直接返回路由名称(里面存储的就是表的类名称)
|
||
if (InterfaceType == 0)
|
||
{
|
||
ClassName = InterfaceRoute;
|
||
}
|
||
else
|
||
{
|
||
//从接口路由中截取类名称,接口路由格式:/XX/GetXX,要取出Get之后的字段
|
||
if (InterfaceRoute.Split('/').Length > 0)
|
||
{
|
||
ClassName = InterfaceRoute.Split('/')[InterfaceRoute.Split('/').Length - 1];
|
||
}
|
||
}
|
||
|
||
return ClassName;
|
||
}
|
||
#endregion
|
||
|
||
#region 方法 -> 初始化列表【GridViewEx】内容
|
||
/// <summary>
|
||
/// 初始化接口列表内容
|
||
/// </summary>
|
||
/// <param name="dtInterfaceModel">接口参数对象</param>
|
||
public static void InitialInterfaceGridViewEx(DataTable dtInterfaceModel)
|
||
{
|
||
dtInterfaceModel.Columns.Add("ShowParams", typeof(int)); //是否是入参
|
||
dtInterfaceModel.Columns.Add("ParamsFormat", typeof(int)); //入参格式
|
||
dtInterfaceModel.Columns.Add("ParamsDefaultValue", typeof(string)); //入参默认值
|
||
dtInterfaceModel.Columns.Add("ColumnParamsIndex", typeof(int)); //入参顺序
|
||
dtInterfaceModel.Columns.Add("ColumnParamsRename", typeof(string)); //重命名入参名字
|
||
dtInterfaceModel.Columns.Add("ShowResponse", typeof(int)); //是否是返参
|
||
dtInterfaceModel.Columns.Add("ColumnResponseIndex", typeof(int)); //返参顺序
|
||
dtInterfaceModel.Columns.Add("ColumnResponseRename", typeof(string)); //重命名返参名字
|
||
dtInterfaceModel.Columns.Add("ModelDataType", typeof(int)); //数据类型:1【主表】,2【附表】,3【自定义字段】
|
||
dtInterfaceModel.Columns.Add("DateFormat", typeof(int)); //日期字段格式:1【日期】,2【月份】,3【年份】
|
||
dtInterfaceModel.Columns.Add("DataSummary", typeof(int)); //合计字段:1【是】,0【否】
|
||
dtInterfaceModel.Columns.Add("OrderByType", typeof(string)); //排序选项:1【正序】,2【倒序】
|
||
}
|
||
|
||
#region 方法 -> 初始化前端页面列表
|
||
/// <summary>
|
||
/// 初始化前端页面列表
|
||
/// </summary>
|
||
/// <param name="dtInterfaceModel">接口返参列表字段数据源</param>
|
||
/// <param name="dtInterfaceOtherModel">接口返参其他对象列表字段数据源</param>
|
||
/// <param name="dtEditModel">编辑页列表字段数据源</param>
|
||
/// <param name="ContainIndex">是否添加序号字段</param>
|
||
public static void InitialIndexGridViewEx(DataTable dtInterfaceModel,
|
||
DataTable dtInterfaceOtherModel, DataTable dtEditModel = null, bool ContainIndex = true)
|
||
{
|
||
//补充返参数据列表字段
|
||
InitialIndexGridViewEx(dtInterfaceModel);
|
||
if (ContainIndex)
|
||
{
|
||
//列表页面布局增加“序号”的设置
|
||
DataRow drInterfaceModel = dtInterfaceModel.NewRow();
|
||
drInterfaceModel["INTERFACEMODEL_ID"] = 0;
|
||
drInterfaceModel["INTERFACEMODEL_NAME"] = "index";
|
||
drInterfaceModel["INTERFACEMODEL_COMMENT"] = "序号";
|
||
drInterfaceModel["INTERFACEMODEL_FORMAT"] = 1;
|
||
drInterfaceModel["INTERFACEMODEL_STATE"] = 1;
|
||
drInterfaceModel["MULTI_SEARCH"] = 0;
|
||
dtInterfaceModel.Rows.InsertAt(drInterfaceModel, 0);
|
||
}
|
||
//补充返参其他对象数据列表字段
|
||
if (dtInterfaceOtherModel != null)
|
||
{
|
||
InitialIndexGridViewEx(dtInterfaceOtherModel);
|
||
}
|
||
|
||
//补充编辑列表字段
|
||
if (dtEditModel != null)
|
||
{
|
||
InitialEditGridViewEx(dtEditModel);
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 补充列表页面字段
|
||
/// </summary>
|
||
/// <param name="_DataTable">列表页字段数据源</param>
|
||
public static void InitialIndexGridViewEx(DataTable _DataTable)
|
||
{
|
||
_DataTable.Columns.Add("ShowList", typeof(int)); //是否显示在列表上
|
||
_DataTable.Columns.Add("ShowDrawer", typeof(int)); //是否显示在抽屉中
|
||
_DataTable.Columns.Add("ColumnWidth", typeof(string)); //列表宽度
|
||
_DataTable.Columns.Add("ColumnIndex", typeof(int)); //显示顺序
|
||
_DataTable.Columns.Add("OrderByType", typeof(string)); //排序选项
|
||
_DataTable.Columns.Add("ContentAlign", typeof(string)); //单元格位置
|
||
_DataTable.Columns.Add("DefaultValue", typeof(string)); //默认值
|
||
_DataTable.Columns.Add("FieldExplainField", typeof(string)); //枚举字典
|
||
_DataTable.Columns.Add("ModelDataType", typeof(int)); //数据类型:1【主表】,2【附表】,3【自定义字段】
|
||
_DataTable.Columns.Add("DateFormat", typeof(int)); //日期字段格式:1【日期】,2【月份】,3【年份】
|
||
_DataTable.Columns.Add("DataSummary", typeof(int)); //合计字段:1【是】,0【否】
|
||
}
|
||
|
||
/// <summary>
|
||
/// 补充编辑页字段
|
||
/// </summary>
|
||
/// <param name="_DataTable">编辑页面字段数据源</param>
|
||
public static void InitialEditGridViewEx(DataTable _DataTable)
|
||
{
|
||
_DataTable.Columns.Add("ControlType", typeof(int)); //控件类型
|
||
_DataTable.Columns.Add("ShowColumn", typeof(int)); //是否显示详情中
|
||
_DataTable.Columns.Add("ColumnIndex", typeof(int)); //显示顺序
|
||
_DataTable.Columns.Add("Required", typeof(int)); //是否必填项
|
||
_DataTable.Columns.Add("DefaultValue", typeof(string)); //默认值
|
||
_DataTable.Columns.Add("FieldExplainField", typeof(string));//枚举字典
|
||
_DataTable.Columns.Add("CBEditable", typeof(int)); //是否编辑:1【是】,0【否】
|
||
}
|
||
#endregion
|
||
|
||
#region 方法 -> 初始化小程序详情页列表
|
||
/// <summary>
|
||
/// 初始化小程序详情页列表
|
||
/// </summary>
|
||
/// <param name="dtInterfaceModel"></param>
|
||
public static void InitialMinProGridViewEx(DataTable dtInterfaceModel)
|
||
{
|
||
dtInterfaceModel.Columns.Add("ShowList", typeof(int)); //是否显示在列表上
|
||
dtInterfaceModel.Columns.Add("ColumnIndex", typeof(int)); //显示顺序
|
||
dtInterfaceModel.Columns.Add("ContentAlign", typeof(string)); //单元格位置
|
||
dtInterfaceModel.Columns.Add("FieldExplainField", typeof(string)); //枚举字典
|
||
dtInterfaceModel.Columns.Add("ParamsField", typeof(string)); //详情页面对应的入参字段
|
||
}
|
||
#endregion
|
||
|
||
#endregion
|
||
|
||
#region 方法 -> 文本内容增加空格,数量由入参控制
|
||
/// <summary>
|
||
/// 文本内容增加空格,数量由入参控制
|
||
/// </summary>
|
||
/// <param name="TabCount">空格数量</param>
|
||
/// <returns></returns>
|
||
public static string GetTabChar(int TabCount)
|
||
{
|
||
StringBuilder _TabChar = new StringBuilder();
|
||
int _Count = TabCount * 4;
|
||
for (int i = 0; i < _Count; i++)
|
||
{
|
||
_TabChar.Append(" ");
|
||
}
|
||
return _TabChar.ToString(); ;
|
||
}
|
||
#endregion
|
||
|
||
#region 方法 -> 增加代码注解
|
||
/// <summary>
|
||
/// 增加代码注解<br/>
|
||
/// 在代码里面生成的中文释义
|
||
/// </summary>
|
||
/// <param name="stringBuilder">字符串</param>
|
||
/// <param name="SummaryContent">注解内容</param>
|
||
/// <param name="StartIndex">内容缩进格数</param>
|
||
/// <param name="parameters">方法中的参数注解,可以为空</param>
|
||
public static void BuildCodeSummary(StringBuilder stringBuilder, string SummaryContent,
|
||
int StartIndex = 0, Dictionary<string, string> parameters = null)
|
||
{
|
||
stringBuilder.AppendLine(GetTabChar(StartIndex) + "/// <summary>");
|
||
stringBuilder.AppendLine(GetTabChar(StartIndex) + "/// " + SummaryContent);
|
||
stringBuilder.AppendLine(GetTabChar(StartIndex) + "/// </summary>");
|
||
|
||
if (parameters != null)
|
||
{
|
||
foreach (string key in parameters.Keys)
|
||
{
|
||
stringBuilder.AppendLine(GetTabChar(2) + "/// <param name=\"" + key + "\">" + parameters[key] + "</param>");
|
||
}
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 方法 -> 增加catch方法代码
|
||
/// <summary>
|
||
/// 增加catch方法代码
|
||
/// </summary>
|
||
/// <param name="stringBuilder">字符串</param>
|
||
/// <param name="FailName">失败命名:例如“查询”失败</param>
|
||
/// <param name="LogName">日志名称</param>
|
||
/// <param name="StartIndex">内容缩进格数</param>
|
||
public static void BuildCatchCode(StringBuilder stringBuilder, string FailName, string LogName, int StartIndex = 0)
|
||
{
|
||
stringBuilder.AppendLine(GetTabChar(StartIndex) + "catch (Exception ex)");
|
||
stringBuilder.AppendLine(GetTabChar(StartIndex) + "{");
|
||
stringBuilder.AppendLine(GetTabChar(StartIndex + 1) + "//事务回滚");
|
||
stringBuilder.AppendLine(GetTabChar(StartIndex + 1) + "transaction.Rollback();");
|
||
//记录异常日志
|
||
stringBuilder.AppendLine(GetTabChar(StartIndex + 1) + "LogUtil.WriteLog(null, " +
|
||
"\"" + FailName + "失败!失败原因:\" + ex.Message + \"\\r\\n\" + Parameter,");
|
||
stringBuilder.AppendLine(GetTabChar(StartIndex + 2) + "DateTime.Now.ToString(\"yyyyMMdd\") + \"_" + LogName + "\");");
|
||
stringBuilder.AppendLine(GetTabChar(StartIndex + 1) + "return Ok(Method.Common.ReturnJson(999, \"查询失败\" + ex.Message));");
|
||
stringBuilder.AppendLine(GetTabChar(StartIndex) + "}");
|
||
}
|
||
#endregion
|
||
|
||
#region 方法 -> 获取命名空间简写
|
||
/// <summary>
|
||
/// 获取命名空间简写
|
||
/// </summary>
|
||
/// <param name="WholeNameSpace">命名空间全称</param>
|
||
/// <returns></returns>
|
||
public static string GetNameSpaceShortName(string WholeNameSpace)
|
||
{
|
||
string ShortName = "";
|
||
|
||
foreach (string NameSpace in WholeNameSpace.Split('.'))
|
||
{
|
||
ShortName += NameSpace.Substring(0, 1);
|
||
}
|
||
|
||
return ShortName;
|
||
}
|
||
#endregion
|
||
|
||
#region 方法 -> 转换字符串大小写
|
||
/// <summary>
|
||
/// 返回首字母大写、其余字符小写的字符串model对象
|
||
/// </summary>
|
||
/// <param name="className">字符串</param>
|
||
/// <returns>原字符串CLASS_NAME,返回Class_nameModel</returns>
|
||
public static string GetClassModelName(string className)
|
||
{
|
||
return className + "Model";
|
||
}
|
||
|
||
/// <summary>
|
||
/// 返回首字母大写、其余字符小写的字符串
|
||
/// </summary>
|
||
/// <param name="className">字符串</param>
|
||
/// <returns>原字符串CLASS_NAME,返回Class_name</returns>
|
||
public static string GetULClassName(string className)
|
||
{
|
||
return className.Substring(0, 1).ToUpper() + className.Substring(1, className.Length - 1).ToLower();
|
||
}
|
||
|
||
/// <summary>
|
||
/// 返回小写字符串,如果有_,则_后面的第一个字符大写
|
||
/// </summary>
|
||
/// <param name="className">字符串</param>
|
||
/// <returns>原字符串CLASS_NAME,返回class_Name</returns>
|
||
public static string GetLUName(string className)
|
||
{
|
||
string resName = className.Split('_')[0].ToLower();
|
||
//以_分割字符串,从第一个_之后的字符串开始遍历,每段字符串首字母大写其余字母小写
|
||
for (int SplitLength = 1; SplitLength < className.Split('_').Length; SplitLength++)
|
||
{
|
||
resName += GetULClassName(className.Split('_')[SplitLength]);
|
||
}
|
||
|
||
return resName;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 返回首字母小写的字符串
|
||
/// 如原字符串CLASS_NAME,返回cLASS_NAME
|
||
/// </summary>
|
||
/// <param name="name">字符串</param>
|
||
/// <returns></returns>
|
||
public static string GetFLName(string name)
|
||
{
|
||
return name.Substring(0, 1).ToLower() + name.Substring(1, name.Length - 1);
|
||
}
|
||
#endregion
|
||
|
||
#region 方法 -> 设置时间参数默认值
|
||
/// <summary>
|
||
/// 设置时间参数默认值
|
||
/// </summary>
|
||
/// <param name="stringBuilder">字符串</param>
|
||
/// <param name="DefaultDateValueType">时间参数默认值</param>
|
||
/// <param name="DateFormat">时间参数格式</param>
|
||
/// <param name="IsDateRange">是否是时间段选择</param>
|
||
public static void SetDateInitialValue(StringBuilder stringBuilder, string DefaultDateValueType, string DateFormat, bool IsDateRange)
|
||
{
|
||
switch (DefaultDateValueType)
|
||
{
|
||
case "1": //默认显示最近一天
|
||
stringBuilder.AppendLine(GetTabChar(3) + "initialValue: " + (!IsDateRange ?
|
||
"moment().add(-1, 'day').format('" + DateFormat + "')" : "[moment().add(-1, 'day').format('" +
|
||
DateFormat + "'), moment().add(-1, 'day').format('" + DateFormat + "')],"));
|
||
break;
|
||
case "2": //默认显示最近一周
|
||
stringBuilder.AppendLine(GetTabChar(3) + "initialValue: " + (!IsDateRange ?
|
||
"moment().add(-1, 'week').format('" + DateFormat + "')" : "[moment().add(-1, 'week').format('" +
|
||
DateFormat + "'), moment().add(-1, 'day').format('" + DateFormat + "')],"));
|
||
break;
|
||
case "3": //默认显示最近一月
|
||
stringBuilder.AppendLine(GetTabChar(3) + "initialValue: " + (!IsDateRange ?
|
||
"moment().add(-1, 'month').format('" + DateFormat + "')" : "[moment().add(-1, 'month').format('" +
|
||
DateFormat + "'), moment().add(-1, 'day').format('" + DateFormat + "')],"));
|
||
break;
|
||
case "4": //默认显示最近三月
|
||
stringBuilder.AppendLine(GetTabChar(3) + "initialValue: " + (!IsDateRange ?
|
||
"moment().add(-3, 'month').format('" + DateFormat + "')" : "[moment().add(-3, 'month').format('" +
|
||
DateFormat + "'), moment().add(-1, 'day').format('" + DateFormat + "')],"));
|
||
break;
|
||
case "5": //默认显示最近半年
|
||
stringBuilder.AppendLine(GetTabChar(3) + "initialValue: " + (!IsDateRange ?
|
||
"moment().add(-6, 'month').format('" + DateFormat + "')" : "[moment().add(-6, 'month').format('" +
|
||
DateFormat + "'), moment().add(-1, 'day').format('" + DateFormat + "')],"));
|
||
break;
|
||
case "6": //默认显示最近一年
|
||
stringBuilder.AppendLine(GetTabChar(3) + "initialValue: " + (!IsDateRange ?
|
||
"moment().add(-1, 'year').format('" + DateFormat + "')" : "[moment().add(-1, 'year').format('" +
|
||
DateFormat + "'), moment().add(-1, 'day').format('" + DateFormat + "')],"));
|
||
break;
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 方法 -> 设置字段默认排序
|
||
/// <summary>
|
||
/// 设置字段默认排序
|
||
/// </summary>
|
||
/// <param name="stringBuilder">生成代码的字符串</param>
|
||
/// <param name="dataRow">字段数据源</param>
|
||
/// <param name="StartIndex">代码缩进格数</param>
|
||
public static void SetFieldSort(StringBuilder stringBuilder, DataRow dataRow, int StartIndex = 3)
|
||
{
|
||
string _INTERFACEMODEL_NAME = dataRow["INTERFACEMODEL_NAME"].ToString();
|
||
|
||
switch (dataRow["INTERFACEMODEL_FORMAT"].ToString())
|
||
{
|
||
case "1":
|
||
switch (dataRow["OrderByType"].ToString())
|
||
{
|
||
case "1":
|
||
stringBuilder.AppendLine(GetTabChar(StartIndex) + "(a, b) => a." +
|
||
_INTERFACEMODEL_NAME + " - b." + _INTERFACEMODEL_NAME + ",");
|
||
break;
|
||
case "2":
|
||
stringBuilder.AppendLine(GetTabChar(StartIndex) + "(a, b) => a." +
|
||
_INTERFACEMODEL_NAME + " - b." + _INTERFACEMODEL_NAME + ",");
|
||
stringBuilder.AppendLine(GetTabChar(StartIndex) + "defaultSortOrder: 'ascend',");
|
||
break;
|
||
case "3":
|
||
stringBuilder.AppendLine(GetTabChar(StartIndex) + "(a, b) => a." +
|
||
_INTERFACEMODEL_NAME + " - b." + _INTERFACEMODEL_NAME + ",");
|
||
stringBuilder.AppendLine(GetTabChar(StartIndex) + "defaultSortOrder: 'descend',");
|
||
break;
|
||
}
|
||
break;
|
||
default:
|
||
switch (dataRow["OrderByType"].ToString())
|
||
{
|
||
case "1":
|
||
stringBuilder.AppendLine(GetTabChar(StartIndex) + "(a, b) => a." +
|
||
_INTERFACEMODEL_NAME + ".localeCompare(b." + _INTERFACEMODEL_NAME + "),");
|
||
break;
|
||
case "2":
|
||
stringBuilder.AppendLine(GetTabChar(StartIndex) + "(a, b) => a." +
|
||
_INTERFACEMODEL_NAME + ".localeCompare(b." + _INTERFACEMODEL_NAME + "),");
|
||
stringBuilder.AppendLine(GetTabChar(StartIndex) + "defaultSortOrder: 'ascend',");
|
||
break;
|
||
case "3":
|
||
stringBuilder.AppendLine(GetTabChar(StartIndex) + "(a, b) => a." +
|
||
_INTERFACEMODEL_NAME + ".localeCompare(b." + _INTERFACEMODEL_NAME + "),");
|
||
stringBuilder.AppendLine(GetTabChar(StartIndex) + "defaultSortOrder: 'descend',");
|
||
break;
|
||
}
|
||
break;
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 设置字段默认排序
|
||
/// </summary>
|
||
/// <param name="stringBuilder">生成代码的字符串</param>
|
||
/// <param name="OrderByType">排序方式</param>
|
||
/// <param name="StartIndex">代码缩进格数</param>
|
||
public static void SetFieldSort(StringBuilder stringBuilder, string OrderByType, int StartIndex = 3)
|
||
{
|
||
switch (OrderByType)
|
||
{
|
||
case "1"://增加排序效果,但不设置默认排序
|
||
stringBuilder.AppendLine(GetTabChar(StartIndex) + "sorter: true,");
|
||
break;
|
||
case "2"://增加排序效果,默认按正序显示
|
||
stringBuilder.AppendLine(GetTabChar(StartIndex) + "sorter: true,");
|
||
stringBuilder.AppendLine(GetTabChar(StartIndex) + "defaultSortOrder: 'ascend',");
|
||
break;
|
||
case "3"://增加排序效果,默认按倒序显示
|
||
stringBuilder.AppendLine(GetTabChar(StartIndex) + "sorter: true,");
|
||
stringBuilder.AppendLine(GetTabChar(StartIndex) + "defaultSortOrder: 'descend',");
|
||
break;
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 方法 -> 保存文件至指定路径
|
||
/// <summary>
|
||
/// 保存本地文件
|
||
/// </summary>
|
||
/// <param name="fileName">文件绝对路径</param>
|
||
/// <param name="fileText">文件内容</param>
|
||
public static void SaveFile(string fileName, string fileText)
|
||
{
|
||
while (File.Exists(fileName))
|
||
{
|
||
File.Delete(fileName);
|
||
}
|
||
if (fileName.ToLower().EndsWith(".bat"))
|
||
{
|
||
File.WriteAllText(fileName, fileText, Encoding.ASCII);
|
||
}
|
||
else
|
||
{
|
||
File.WriteAllText(fileName, fileText, new UTF8Encoding(false));
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 保存文件至指定服务器
|
||
/// </summary>
|
||
/// <param name="fileDir">文件路径</param>
|
||
/// <param name="fileName">文件名称</param>
|
||
/// <param name="fileText">文件内容</param>
|
||
/// <param name="resMsg">保存结果</param>
|
||
/// <param name="postUrl">传输地址</param>
|
||
public static bool SaveFile(string fileDir, string fileName, string fileText,
|
||
ref string resMsg, string postUrl = "http://10.104.1.8:8010/publish/FileUpload.ashx")
|
||
{
|
||
if (string.IsNullOrWhiteSpace(postUrl))
|
||
{
|
||
//目标路径文件夹不存在,则先新建文件夹
|
||
if (!Directory.Exists(fileDir))
|
||
{
|
||
Directory.CreateDirectory(fileDir);
|
||
}
|
||
SaveFile(fileDir + "\\" + fileName, fileText);
|
||
return true;
|
||
}
|
||
else
|
||
{
|
||
string fileType = "text/plain";
|
||
byte[] data = Encoding.UTF8.GetBytes(fileText);
|
||
string fileSize = data.Length.ToString();
|
||
|
||
HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(postUrl);
|
||
myRequest.Method = "POST";
|
||
myRequest.ContentType = fileType;
|
||
myRequest.ContentLength = data.Length;
|
||
myRequest.Headers.Add("FileName", HttpContext.Current.Server.UrlEncode(fileName));
|
||
myRequest.Headers.Add("FileDir", HttpContext.Current.Server.UrlEncode(fileDir));
|
||
myRequest.Headers.Add("FileType", HttpContext.Current.Server.UrlEncode(fileType));
|
||
myRequest.Headers.Add("FileSize", fileSize);
|
||
|
||
using (Stream newStream = myRequest.GetRequestStream())
|
||
{
|
||
newStream.Write(data, 0, data.Length);
|
||
newStream.Close();
|
||
}
|
||
HttpWebResponse myResponse = (HttpWebResponse)myRequest.GetResponse();
|
||
StreamReader reader = new StreamReader(myResponse.GetResponseStream(), Encoding.UTF8);
|
||
string res = reader.ReadToEnd();
|
||
|
||
LogUtil.WriteLog(null, res, DateTime.Now.ToString("yyyyMMdd") + "_SaveFile");
|
||
|
||
JObject keyValuePairs = JObject.Parse(res);
|
||
resMsg = keyValuePairs["Result_Desc"].ToString();
|
||
|
||
return keyValuePairs["Result_Code"].TryParseToInt() == 100;
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 方法 -> 复制文件夹
|
||
/// <summary>
|
||
/// 复制文件夹
|
||
/// </summary>
|
||
/// <param name="srcDir">原文件夹路径</param>
|
||
/// <param name="destDir">目标文件夹路径</param>
|
||
/// <param name="CoverFile">是否覆盖目标文件</param>
|
||
public static void CopyFilesAndDirs(string srcDir, string destDir, bool CoverFile)
|
||
{
|
||
string newPath;
|
||
FileInfo fileInfo;
|
||
if (!Directory.Exists(destDir))
|
||
{
|
||
//若目标文件夹不存在,则创建目标文件夹
|
||
Directory.CreateDirectory(destDir);
|
||
}
|
||
//获取源文件夹中的所有文件完整路径
|
||
string[] files = Directory.GetFiles(srcDir);
|
||
//遍历文件
|
||
foreach (string path in files)
|
||
{
|
||
fileInfo = new FileInfo(path);
|
||
newPath = destDir + fileInfo.Name;
|
||
File.Copy(path, newPath, CoverFile);
|
||
}
|
||
|
||
//遍历子文件夹
|
||
string[] dirs = Directory.GetDirectories(srcDir);
|
||
foreach (string path in dirs)
|
||
{
|
||
DirectoryInfo directory = new DirectoryInfo(path);
|
||
string newDir = destDir + directory.Name;
|
||
CopyFilesAndDirs(path + "\\", newDir + "\\", CoverFile);
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 方法 -> 删除指定路径的文件
|
||
/// <summary>
|
||
/// 删除本地文件
|
||
/// </summary>
|
||
/// <param name="fileName">文件绝对路径</param>
|
||
public static void DeleteFile(string fileName)
|
||
{
|
||
while (File.Exists(fileName))
|
||
{
|
||
File.Delete(fileName);
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 删除指定服务器下的文件
|
||
/// </summary>
|
||
/// <param name="fileDir">文件路径</param>
|
||
/// <param name="fileName">文件名称</param>
|
||
/// <param name="fileText">文件内容</param>
|
||
/// <param name="resMsg">删除结果</param>
|
||
/// <param name="postUrl">传输地址</param>
|
||
public static bool DeleteFile(string fileDir, string fileName, string fileText,
|
||
ref string resMsg, string postUrl = "http://10.104.1.8:8010/publish/FileUpload.ashx")
|
||
{
|
||
if (string.IsNullOrWhiteSpace(postUrl))
|
||
{
|
||
DeleteFile(fileDir + "\\" + fileName);
|
||
|
||
return true;
|
||
}
|
||
else
|
||
{
|
||
string fileType = "text/plain";
|
||
byte[] data = Encoding.UTF8.GetBytes(fileText);
|
||
string fileSize = data.Length.ToString();
|
||
|
||
HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(postUrl);
|
||
myRequest.Method = "POST";
|
||
myRequest.ContentType = fileType;
|
||
myRequest.ContentLength = data.Length;
|
||
myRequest.Headers.Add("FileName", HttpContext.Current.Server.UrlEncode(fileName));
|
||
myRequest.Headers.Add("FileDir", HttpContext.Current.Server.UrlEncode(fileDir));
|
||
myRequest.Headers.Add("FileType", HttpContext.Current.Server.UrlEncode(fileType));
|
||
myRequest.Headers.Add("FileSize", fileSize);
|
||
myRequest.Headers.Add("FileDelete", "1");//请求头删除的标识
|
||
|
||
using (Stream newStream = myRequest.GetRequestStream())
|
||
{
|
||
newStream.Write(data, 0, data.Length);
|
||
newStream.Close();
|
||
}
|
||
HttpWebResponse myResponse = (HttpWebResponse)myRequest.GetResponse();
|
||
StreamReader reader = new StreamReader(myResponse.GetResponseStream(), Encoding.UTF8);
|
||
string res = reader.ReadToEnd();
|
||
|
||
LogUtil.WriteLog(null, res, DateTime.Now.ToString("yyyyMMdd") + "_DeleteFile");
|
||
|
||
JObject keyValuePairs = JObject.Parse(res);
|
||
resMsg = keyValuePairs["Result_Desc"].ToString();
|
||
|
||
return keyValuePairs["Result_Code"].TryParseToInt() == 100;
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 方法 -> 移动文件夹/文件
|
||
/// <summary>
|
||
/// 移动文件夹/文件
|
||
/// </summary>
|
||
/// <param name="fileName">原文件的名称</param>
|
||
/// <param name="destFileName">目标路径的名称</param>
|
||
/// <param name="fileDir">要移动文件所在目录的绝对路径。</param>
|
||
/// <param name="destDir">目标路径所在目录的绝对路径</param>
|
||
/// <param name="coverDir">覆盖文件(1:覆盖 0:不覆盖)</param>
|
||
/// <param name="resMsg">移动结果</param>
|
||
/// <param name="postUrl">传输地址</param>
|
||
public static bool MoveDirectory(string fileDir, string fileName, string destDir, string destFileName,
|
||
string coverDir, ref string resMsg, string postUrl)
|
||
{
|
||
//传输地址为空则移动本地文件
|
||
if (string.IsNullOrEmpty(postUrl))
|
||
{
|
||
return MoveDirectory(fileDir, fileName, destDir, destFileName, coverDir, ref resMsg);
|
||
}
|
||
else
|
||
{
|
||
string fileType = "text/plain";
|
||
byte[] data = Encoding.UTF8.GetBytes("");
|
||
string fileSize = data.Length.ToString();
|
||
|
||
HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(postUrl);
|
||
myRequest.Method = "POST";
|
||
myRequest.ContentType = fileType;
|
||
myRequest.ContentLength = data.Length;
|
||
myRequest.Headers.Add("FileName", HttpContext.Current.Server.UrlEncode(fileName));
|
||
myRequest.Headers.Add("DestFileName", HttpContext.Current.Server.UrlEncode(destFileName));
|
||
myRequest.Headers.Add("FileDir", HttpContext.Current.Server.UrlEncode(fileDir));
|
||
myRequest.Headers.Add("FileType", HttpContext.Current.Server.UrlEncode(fileType));
|
||
myRequest.Headers.Add("FileSize", fileSize);
|
||
myRequest.Headers.Add("DestDir", HttpContext.Current.Server.UrlEncode(destDir));//
|
||
myRequest.Headers.Add("DirMove", "1");//移动文件
|
||
myRequest.Headers.Add("coverDir", coverDir);//是否覆盖文件
|
||
|
||
using (Stream newStream = myRequest.GetRequestStream())
|
||
{
|
||
newStream.Write(data, 0, data.Length);
|
||
newStream.Close();
|
||
}
|
||
HttpWebResponse myResponse = (HttpWebResponse)myRequest.GetResponse();
|
||
StreamReader reader = new StreamReader(myResponse.GetResponseStream(), Encoding.UTF8);
|
||
string res = reader.ReadToEnd();
|
||
|
||
LogUtil.WriteLog(null, res, DateTime.Now.ToString("yyyyMMdd") + "_MoveDirectory");
|
||
|
||
JObject keyValuePairs = JObject.Parse(res);
|
||
resMsg = keyValuePairs["Result_Desc"].ToString();
|
||
|
||
return keyValuePairs["Result_Code"].TryParseToInt() == 100;
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 移动本地文件
|
||
/// </summary>
|
||
/// <param name="fileName">原文件的名称</param>
|
||
/// <param name="destFileName">目标路径的名称</param>
|
||
/// <param name="fileDir">要移动文件所在目录的绝对路径。</param>
|
||
/// <param name="destDir">目标路径所在目录的绝对路径</param>
|
||
/// <param name="coverDir">覆盖文件(1:覆盖 0:不覆盖)</param>
|
||
/// <param name="resMsg">移动结果</param>
|
||
/// <returns></returns>
|
||
public static bool MoveDirectory(string fileDir, string fileName,
|
||
string destDir, string destFileName, string coverDir, ref string resMsg)
|
||
{
|
||
string destFileAbsUrl = destDir + "\\" + (string.IsNullOrWhiteSpace(destFileName) ? fileName : destFileName);
|
||
|
||
//文件是否存在
|
||
if ((!string.IsNullOrWhiteSpace(fileName) && File.Exists(destFileAbsUrl)) || Directory.Exists(destDir))
|
||
{
|
||
//覆盖文件
|
||
if (coverDir.TryParseToInt() == 1)
|
||
{
|
||
//目标路径文件夹不存在,则先新建文件夹
|
||
if (!Directory.Exists(destDir))
|
||
{
|
||
Directory.CreateDirectory(destDir);
|
||
}
|
||
|
||
if (!string.IsNullOrWhiteSpace(fileName))//移动文件
|
||
{
|
||
//目标路径已存在文件,则先删除文件,然后再迁移
|
||
if (File.Exists(destFileAbsUrl))
|
||
{
|
||
File.Delete(destFileAbsUrl);
|
||
}
|
||
|
||
File.Move(fileDir + "\\" + fileName, destFileAbsUrl);
|
||
|
||
LogUtil.WriteLog(null, "移动文件:" + fileDir + "\\" + fileName + "至" + destFileAbsUrl,
|
||
DateTime.Now.ToString("yyyyMMdd") + "_MoveDirectory");
|
||
|
||
return true;
|
||
}
|
||
|
||
foreach (FileInfo fileInfo in new DirectoryInfo(fileDir).GetFiles())
|
||
{
|
||
//目标路径已存在文件,则先删除文件,然后再迁移
|
||
if (File.Exists(destDir + "\\" + fileInfo.Name))
|
||
{
|
||
File.Delete(destDir + "\\" + fileInfo.Name);
|
||
}
|
||
|
||
File.Move(fileInfo.FullName, destDir + "\\" + fileInfo.Name);
|
||
|
||
LogUtil.WriteLog(null, "移动文件:" + fileDir + "\\" + fileName + "至" + destFileAbsUrl,
|
||
DateTime.Now.ToString("yyyyMMdd") + "_MoveDirectory");
|
||
}
|
||
|
||
return true;
|
||
}
|
||
else
|
||
{
|
||
if (!string.IsNullOrWhiteSpace(fileName))
|
||
{
|
||
if (File.Exists(destFileAbsUrl))
|
||
{
|
||
resMsg = "目标路径已存在相同文件,请确认是否覆盖!";
|
||
|
||
return false;
|
||
}
|
||
else
|
||
{
|
||
File.Move(fileDir + "\\" + fileName, destFileAbsUrl);
|
||
return true;
|
||
}
|
||
}
|
||
|
||
resMsg = "目标路径已存在相同文件,请确认是否覆盖!";
|
||
|
||
return false;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
//如果移动的是文件,则直接迁移过去
|
||
if (!string.IsNullOrEmpty(fileName))
|
||
{
|
||
//目标路径文件夹不存在,则先新建文件夹
|
||
if (!Directory.Exists(destDir))
|
||
{
|
||
Directory.CreateDirectory(destDir);
|
||
}
|
||
File.Move(fileDir + "\\" + fileName, destFileAbsUrl);
|
||
}
|
||
else
|
||
{
|
||
//把新文件移动到目标目录下
|
||
Directory.Move(fileDir, destDir);
|
||
}
|
||
|
||
return true;
|
||
}
|
||
}
|
||
|
||
//public static bool MoveDirectory(string fileDir, string fileName,
|
||
// string destDir, string destFileName, string coverDir, ref string resMsg)
|
||
//{
|
||
|
||
//}
|
||
|
||
#endregion
|
||
|
||
#region 方法 -> 执行重新生成解决方案
|
||
/// <summary>
|
||
/// 执行重新生成解决方案
|
||
/// </summary>
|
||
/// <param name="msbuildPath">msbuild路径</param>
|
||
/// <param name="slnPath">解决方案路径</param>
|
||
/// <param name="InterfaceName">接口名称</param>
|
||
public static void Rebuildsln(string msbuildPath, string slnPath, string InterfaceName)
|
||
{
|
||
Rebuildsln(msbuildPath, slnPath, "Debug", InterfaceName);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 执行重新生成解决方案
|
||
/// </summary>
|
||
/// <param name="msbuildPath">msbuild路径</param>
|
||
/// <param name="slnPath">解决方案路径</param>
|
||
/// <param name="BuildType">编译方式:Debug/Release</param>
|
||
/// <param name="InterfaceName">接口名称</param>
|
||
public static void Rebuildsln(string msbuildPath, string slnPath, string BuildType, string InterfaceName)
|
||
{
|
||
//Task task = Task.Factory.StartNew(() =>
|
||
//{
|
||
//以Debug方式编译解决方案文件
|
||
ProcessStartInfo info = new ProcessStartInfo(@msbuildPath, @slnPath + " /t:rebuild /p:configuration=" + BuildType);
|
||
//将控制台输出重定向至StandardOutput,如果为false,就无法得到控制台输出结果
|
||
info.RedirectStandardOutput = true;
|
||
info.RedirectStandardError = true;
|
||
info.UseShellExecute = false;
|
||
info.CreateNoWindow = true;
|
||
Process p = Process.Start(info);
|
||
//控制台输出结果
|
||
if (string.IsNullOrWhiteSpace(InterfaceName))
|
||
{
|
||
InterfaceName = DateTime.Now.ToString("yyyyMMddHHmmss") + "_slnDebug";
|
||
}
|
||
LogUtil.WriteLog(null, p.StandardOutput.ReadToEnd().Replace("\n", "<br/>"), InterfaceName,
|
||
Config.AppSettings.CodeBuilderLogAbsUrl);
|
||
//记录异常日志
|
||
string ErrorLog = p.StandardError.ReadToEnd().Replace("\n", "<br/>");
|
||
if (!string.IsNullOrWhiteSpace(ErrorLog))
|
||
{
|
||
LogUtil.WriteLog(null, ErrorLog, InterfaceName + "Error");
|
||
}
|
||
|
||
p.WaitForExit();
|
||
p.Close();
|
||
//});
|
||
}
|
||
|
||
/// <summary>
|
||
/// 运行批处理
|
||
/// </summary>
|
||
/// <param name="batPath">批处理文件路径</param>
|
||
public static void RunBat(string batPath)
|
||
{
|
||
Task task = Task.Factory.StartNew(() =>
|
||
{
|
||
using (Process process = new Process())
|
||
{
|
||
FileInfo file = new FileInfo(@batPath);
|
||
if (file.Directory != null)
|
||
{
|
||
process.StartInfo.WorkingDirectory = file.Directory.FullName;
|
||
}
|
||
process.StartInfo.FileName = @batPath;
|
||
process.StartInfo.RedirectStandardOutput = true;
|
||
process.StartInfo.RedirectStandardError = true;
|
||
process.StartInfo.UseShellExecute = false;
|
||
process.StartInfo.CreateNoWindow = true;
|
||
process.Start();
|
||
|
||
//控制台输出结果
|
||
LogUtil.WriteLog(null, process.StandardOutput.ReadToEnd().Replace("\n", "<br/>"),
|
||
DateTime.Now.ToString("yyyyMMddHHmmss") + "_RunBat");
|
||
//记录异常日志
|
||
string ErrorLog = process.StandardError.ReadToEnd().Replace("\n", "<br/>");
|
||
if (!string.IsNullOrWhiteSpace(ErrorLog))
|
||
{
|
||
LogUtil.WriteLog(null, ErrorLog, DateTime.Now.ToString("yyyyMMddHHmmss") + "_RunBatError");
|
||
}
|
||
|
||
process.WaitForExit();
|
||
process.Close();
|
||
}
|
||
});
|
||
}
|
||
#endregion
|
||
|
||
#region 方法 -> 获取文件夹下文件的内容
|
||
/// <summary>
|
||
/// 获取文件夹内文件内容
|
||
/// </summary>
|
||
/// <param name="fliePath"></param>
|
||
/// <returns></returns>
|
||
public static List<Model.FilesReturnModel> GetFileContent(string fliePath)
|
||
{
|
||
List<Model.FilesReturnModel> fileList = new List<Model.FilesReturnModel>();
|
||
|
||
string path = Config.AppSettings.SolutionPath + "\\" + fliePath;
|
||
//拿到当前路径下所有文件
|
||
string[] files = Directory.GetFiles(path);
|
||
foreach (string filePath in files)
|
||
{
|
||
Model.FilesReturnModel file = new Model.FilesReturnModel();
|
||
string[] oldFile = filePath.Split('\\');
|
||
file.fileName = oldFile[oldFile.Length - 1];//文件名
|
||
file.fileText = File.ReadAllText(filePath, Encoding.UTF8);//文件内容
|
||
fileList.Add(file);
|
||
}
|
||
return fileList;
|
||
}
|
||
#endregion
|
||
|
||
#region 方法 -> 重新发布前端页面文件
|
||
/// <summary>
|
||
/// 重新发布前端页面文件
|
||
/// </summary>
|
||
/// <param name="FileList"></param>
|
||
/// <returns></returns>
|
||
public static bool RepublishFiles(Model.FilesParamsModel FileList)
|
||
{
|
||
bool result = false;
|
||
foreach (Model.FilesReturnModel file in FileList.files)
|
||
{
|
||
//保存文件
|
||
string path = Config.AppSettings.SolutionPath + "\\" + FileList.filepath + "\\" + file.fileName;
|
||
if (File.Exists(path))
|
||
{
|
||
DeleteFile(path);
|
||
SaveFile(path, file.fileText);
|
||
}
|
||
else
|
||
{
|
||
SaveFile(path, file.fileText);
|
||
}
|
||
result = true;
|
||
}
|
||
return result;
|
||
}
|
||
#endregion
|
||
|
||
#region 方法 -> 根据所在数据库,获取执行SQL语句需要实例化的对象
|
||
/// <summary>
|
||
/// 根据所在数据库,获取执行SQL语句需要实例化的对象
|
||
/// </summary>
|
||
/// <param name="OwnerNameSpace">命名空间</param>
|
||
/// <returns></returns>
|
||
public static string GetExcuteClassName(string OwnerNameSpace)
|
||
{
|
||
string ExcuteClassName = "";
|
||
|
||
switch (OwnerNameSpace)
|
||
{
|
||
//合同管理相关数据库
|
||
case "SuperMap.RealEstate.Contract.History.Business":
|
||
case "SuperMap.RealEstate.Contract.Running.Business":
|
||
case "SuperMap.RealEstate.Contract.Storage.Business":
|
||
ExcuteClassName = "BUSINESSPROJECT";
|
||
break;
|
||
//合作商户管理相关数据库
|
||
case "SuperMap.RealEstate.Coop.Merchant.Business":
|
||
ExcuteClassName = "OWNERUNIT";
|
||
break;
|
||
//交互数据库
|
||
case "SuperMap.RealEstate.ExchangeData.Business":
|
||
ExcuteClassName = "ABNORMALITY";
|
||
break;
|
||
//商业经营基础业务库
|
||
case "SuperMap.RealEstate.HighWay.History.Business":
|
||
case "SuperMap.RealEstate.HighWay.Running.Business":
|
||
case "SuperMap.RealEstate.HighWay.Storage.Business":
|
||
ExcuteClassName = "HIGHWAYPROINST";
|
||
break;
|
||
//商业经营营收数据库
|
||
case "SuperMap.RealEstate.HighWay.SellData.Business":
|
||
ExcuteClassName = "ENDACCOUNT";
|
||
break;
|
||
//综合办公相关数据库
|
||
case "SuperMap.RealEstate.Finance.History.Business":
|
||
case "SuperMap.RealEstate.Finance.Running.Business":
|
||
case "SuperMap.RealEstate.Finance.Storage.Business":
|
||
ExcuteClassName = "FINANCEPROINST";
|
||
break;
|
||
//服务区成本管控相关数据库
|
||
case "SuperMap.RealEstate.SendRec.History.Business":
|
||
case "SuperMap.RealEstate.SendRec.Storage.Business":
|
||
ExcuteClassName = "SENDRECPROINST";
|
||
break;
|
||
//进销存调相关数据库
|
||
case "SuperMap.RealEstate.SaleStore.History.Business":
|
||
case "SuperMap.RealEstate.SaleStore.Running.Business":
|
||
case "SuperMap.RealEstate.SaleStore.Storage.Business":
|
||
ExcuteClassName = "SALESTOREPROINST";
|
||
break;
|
||
//总仓统一配送相关数据库
|
||
case "SuperMap.RealEstate.Seller.History.Business":
|
||
case "SuperMap.RealEstate.Seller.Running.Business":
|
||
case "SuperMap.RealEstate.Seller.Storage.Business":
|
||
ExcuteClassName = "SELLERPROINST";
|
||
break;
|
||
//人力资源相关数据库
|
||
case "SuperMap.RealEstate.Personnel.History.Business":
|
||
case "SuperMap.RealEstate.Personnel.Storage.Business":
|
||
ExcuteClassName = "STAFF";
|
||
break;
|
||
//综管平台框架库
|
||
case "SuperMap.RealEstate.FrameWork.Platform.Business":
|
||
ExcuteClassName = "PERMISSIONAPPLY";
|
||
break;
|
||
//移动业务相关数据库
|
||
case "SuperMap.RealEstate.MobileServicePlatform.Business":
|
||
ExcuteClassName = "APPMANAGE";
|
||
break;
|
||
//促销、内部会员相关数据库
|
||
case "SuperMap.RealEstate.MemberShip.History.Business":
|
||
case "SuperMap.RealEstate.MemberShip.Storage.Business":
|
||
ExcuteClassName = "MEMBERSHIP";
|
||
break;
|
||
//内部会员相关业务运行库
|
||
case "SuperMap.RealEstate.MemberShip.Running.Business":
|
||
ExcuteClassName = "MEMBERPROINST";
|
||
break;
|
||
//商业经营仪表盘
|
||
case "SuperMap.RealEstate.PlatForm.Dashboard.Business":
|
||
ExcuteClassName = "CATERINGGROSSMARGIN";
|
||
break;
|
||
//测试数据库
|
||
case "SuperMap.RealEstate.FrameWork.Test.Business":
|
||
ExcuteClassName = "TEST";
|
||
break;
|
||
}
|
||
|
||
return ExcuteClassName;
|
||
}
|
||
#endregion
|
||
|
||
#region 方法 -> 根据字段的数据类型,获取Datatable中字段对应的属性
|
||
/// <summary>
|
||
/// 根据字段的数据类型,获取Datatable中字段对应的属性
|
||
/// </summary>
|
||
/// <param name="FieldName">字段名称</param>
|
||
/// <param name="dtModel">字段所在数据源</param>
|
||
/// <returns></returns>
|
||
public static string GetFieldTypeName(string FieldName, DataTable dtModel)
|
||
{
|
||
string TypeName = "";
|
||
|
||
if (dtModel.Select("INTERFACEMODEL_NAME = '" + FieldName + "'").Length > 0)
|
||
{
|
||
DataRow drModel = dtModel.Select("INTERFACEMODEL_NAME = '" + FieldName + "'")[0];
|
||
switch (drModel["INTERFACEMODEL_FORMAT"].ToString())
|
||
{
|
||
//合同管理相关数据库
|
||
case "1":
|
||
TypeName = "decimal?";
|
||
break;
|
||
case "2":
|
||
TypeName = "DateTime?";
|
||
break;
|
||
case "3":
|
||
TypeName = "bool?";
|
||
break;
|
||
default:
|
||
TypeName = "string";
|
||
break;
|
||
}
|
||
}
|
||
|
||
return TypeName;
|
||
}
|
||
#endregion
|
||
}
|
||
}
|