1
This commit is contained in:
947
iMES.Bi.API/API/Class1.cs
Normal file
947
iMES.Bi.API/API/Class1.cs
Normal file
@@ -0,0 +1,947 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace QJY.API.API
|
||||
{
|
||||
class Class1
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
#region 添加评论
|
||||
/// <summary>
|
||||
/// 添加评论
|
||||
/// </summary>
|
||||
/// <param name="context"></param>
|
||||
/// <param name="msg"></param>
|
||||
/// <param name="strParamData"></param>
|
||||
/// <param name="strUserName"></param>
|
||||
public void ADDCOMENT(JObject context, Msg_Result msg, string P1, string P2, JH_Auth_UserB.UserInfo UserInfo)
|
||||
{
|
||||
string strMsgType = context.Request["MsgType"] ?? "";
|
||||
string strMsgLYID = context.Request["MsgLYID"] ?? "";
|
||||
string strPoints = context.Request["Points"] ?? "0";
|
||||
string strfjID = context.Request["fjID"] ?? "";
|
||||
string strTLID = context.Request["TLID"] ?? "";
|
||||
|
||||
|
||||
if (!string.IsNullOrEmpty(P1) && APIHelp.TestWB(P1) != "0")
|
||||
{
|
||||
msg.ErrorMsg = "您得发言涉及违规内容,请完善后再发";
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
JH_Auth_TL Model = new JH_Auth_TL();
|
||||
Model.CRDate = DateTime.Now;
|
||||
Model.CRUser = UserInfo.User.UserName;
|
||||
Model.CRUserName = UserInfo.User.UserRealName;
|
||||
Model.MSGContent = P1;
|
||||
Model.ComId = UserInfo.User.ComId;
|
||||
Model.MSGTLYID = strMsgLYID;
|
||||
Model.MSGType = strMsgType;
|
||||
Model.MSGisHasFiles = strfjID;
|
||||
Model.Remark1 = P1;
|
||||
|
||||
if (strTLID != "")
|
||||
{
|
||||
int TLID = Int32.Parse(strTLID);
|
||||
var tl = new JH_Auth_TLB().GetEntity(p => p.ID == TLID);
|
||||
if (tl != null)
|
||||
{
|
||||
Model.TLID = TLID;
|
||||
Model.ReUser = tl.CRUserName;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
int record = 0;
|
||||
int.TryParse(strPoints, out record);
|
||||
Model.Points = record;
|
||||
new JH_Auth_TLB().Insert(Model);
|
||||
if (Model.MSGType == "GZBG" || Model.MSGType == "RWGL" || Model.MSGType == "TSSQ")
|
||||
{
|
||||
int modelId = int.Parse(Model.MSGTLYID);
|
||||
string CRUser = "";
|
||||
string Content = UserInfo.User.UserRealName + "评论了您的";
|
||||
|
||||
|
||||
if (CRUser != UserInfo.User.UserName)
|
||||
{
|
||||
SZHL_TXSX CSTX = new SZHL_TXSX();
|
||||
CSTX.Date = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
|
||||
CSTX.APIName = "XTGL";
|
||||
CSTX.ComId = UserInfo.User.ComId;
|
||||
CSTX.FunName = "SENDPLMSG";
|
||||
CSTX.CRUserRealName = UserInfo.User.UserRealName;
|
||||
CSTX.MsgID = modelId.ToString();
|
||||
|
||||
CSTX.TXContent = Content;
|
||||
CSTX.ISCS = "N";
|
||||
CSTX.TXUser = CRUser;
|
||||
CSTX.TXMode = Model.MSGType;
|
||||
CSTX.CRUser = UserInfo.User.UserName;
|
||||
|
||||
TXSX.TXSXAPI.AddALERT(CSTX); //时间为发送时间
|
||||
}
|
||||
}
|
||||
|
||||
msg.Result = Model;
|
||||
if (Model.MSGisHasFiles == "")
|
||||
Model.MSGisHasFiles = "0";
|
||||
msg.Result1 = new FT_FileB().GetEntities(" ID in (" + Model.MSGisHasFiles + ")");
|
||||
}
|
||||
public void SENDPLMSG(JObject context, Msg_Result msg, string P1, string P2, JH_Auth_UserB.UserInfo UserInfo)
|
||||
{
|
||||
SZHL_TXSX TX = JsonConvert.DeserializeObject<SZHL_TXSX>(P1);
|
||||
Article ar0 = new Article();
|
||||
ar0.Title = TX.TXContent;
|
||||
ar0.Description = "";
|
||||
ar0.Url = TX.MsgID;
|
||||
List<Article> al = new List<Article>();
|
||||
al.Add(ar0);
|
||||
if (!string.IsNullOrEmpty(TX.TXUser))
|
||||
{
|
||||
try
|
||||
{
|
||||
//发送PC消息
|
||||
UserInfo = new JH_Auth_UserB().GetUserInfo(TX.ComId.Value, TX.CRUser);
|
||||
WXHelp wx = new WXHelp(UserInfo.QYinfo);
|
||||
wx.SendTH(al, TX.TXMode, "A", TX.TXUser);
|
||||
new JH_Auth_User_CenterB().SendMsg(UserInfo, TX.TXMode, TX.TXContent, TX.MsgID, TX.TXUser);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
}
|
||||
//发送微信消息
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 获取评论列表
|
||||
/// </summary>
|
||||
/// <param name="context"></param>
|
||||
/// <param name="msg"></param>
|
||||
/// <param name="P1"></param>
|
||||
/// <param name="P2"></param>
|
||||
/// <param name="UserInfo"></param>
|
||||
public void GETPLLIST(JObject context, Msg_Result msg, string P1, string P2, JH_Auth_UserB.UserInfo UserInfo)
|
||||
{
|
||||
string userName = UserInfo.User.UserName;
|
||||
string strWhere = " JH_Auth_TL.ComId=" + UserInfo.User.ComId;
|
||||
if (P1 != "")
|
||||
{
|
||||
strWhere += string.Format(" And JH_Auth_TL.MSGContent like '%{0}%'", P1);
|
||||
}
|
||||
int page = 0;
|
||||
int pagecount = 8;
|
||||
int.TryParse(context["p"] == null ? "0" : context["p"].ToString(), out page);
|
||||
int.TryParse(context["pagecount"] == null ? "8" : context["pagecount"].ToString(), out pagecount);//页数
|
||||
page = page == 0 ? 1 : page;
|
||||
int total = 0;
|
||||
DataTable dt = new JH_Auth_TLB().GetDataPager(" JH_Auth_TL LEFT JOIN SZHL_TSSQ ON JH_Auth_TL.MSGTLYID=SZHL_TSSQ.ID ", " JH_Auth_TL.*,SZHL_TSSQ.HTNR ", pagecount, page, " JH_Auth_TL.CRDate desc", strWhere, ref total);
|
||||
msg.Result = dt;
|
||||
msg.Result1 = total;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
|
||||
public void UPLOADFILE(JObject context, Msg_Result msg, string P1, string P2, JH_Auth_UserB.UserInfo UserInfo)
|
||||
{
|
||||
try
|
||||
{
|
||||
int fid = 3;
|
||||
if (!string.IsNullOrEmpty(P1))
|
||||
{
|
||||
fid = Int32.Parse(P1);
|
||||
}
|
||||
|
||||
List<FT_File> ls = new List<FT_File>();
|
||||
for (int i = 0; i < context.Request.Files.Count; i++)
|
||||
{
|
||||
HttpPostedFile uploadFile = context.Request.Files[i];
|
||||
|
||||
|
||||
string originalName = uploadFile.FileName;
|
||||
|
||||
|
||||
|
||||
string[] temp = uploadFile.FileName.Split('.');
|
||||
|
||||
//保存图片
|
||||
|
||||
string filename = System.Guid.NewGuid() + "." + temp[temp.Length - 1].ToLower();
|
||||
string md5 = new CommonHelp().SaveFile(UserInfo.QYinfo, filename, uploadFile);
|
||||
|
||||
//MP4上传阿里云
|
||||
if (Path.GetExtension(originalName).ToLower() == ".mp4")
|
||||
{
|
||||
md5 = md5.Replace("\"", "").Split(',')[0];
|
||||
AliyunHelp.UploadToOSS(md5, "mp4", uploadFile.InputStream);
|
||||
}
|
||||
|
||||
FT_File newfile = new FT_File();
|
||||
newfile.ComId = UserInfo.User.ComId;
|
||||
newfile.Name = uploadFile.FileName.Substring(0, uploadFile.FileName.LastIndexOf('.'));
|
||||
newfile.FileMD5 = md5.Replace("\"", "").Split(',')[0];
|
||||
newfile.zyid = md5.Split(',').Length == 2 ? md5.Split(',')[1] : md5.Split(',')[0];
|
||||
newfile.FileSize = uploadFile.InputStream.Length.ToString();
|
||||
newfile.FileVersin = 0;
|
||||
newfile.CRDate = DateTime.Now;
|
||||
newfile.CRUser = UserInfo.User.UserName;
|
||||
newfile.UPDDate = DateTime.Now;
|
||||
newfile.UPUser = UserInfo.User.UserName;
|
||||
newfile.FileExtendName = temp[temp.Length - 1].ToLower();
|
||||
newfile.FolderID = fid;
|
||||
if (new List<string>() { "txt", "html", "doc", "mp4", "flv", "ogg", "jpg", "gif", "png", "bmp", "jpeg" }.Contains(newfile.FileExtendName.ToLower()))
|
||||
{
|
||||
newfile.ISYL = "Y";
|
||||
}
|
||||
if (new List<string>() { "pdf", "doc", "docx", "ppt", "pptx", "xls", "xlsx" }.Contains(newfile.FileExtendName.ToLower()))
|
||||
{
|
||||
newfile.ISYL = "Y";
|
||||
//newfile.YLUrl = UserInfo.QYinfo.FileServerUrl + "/document/YL/" + newfile.zyid;
|
||||
newfile.YLUrl = "https://www.txywpx.com/ViewV5/Base/doc.html?zyid=" + newfile.zyid;
|
||||
}
|
||||
|
||||
if (P2 != "")
|
||||
{
|
||||
newfile.Name = P2.Substring(0, P2.LastIndexOf('.')); //文件名
|
||||
}
|
||||
|
||||
new FT_FileB().Insert(newfile);
|
||||
|
||||
int filesize = 0;
|
||||
int.TryParse(newfile.FileSize, out filesize);
|
||||
new FT_FileB().AddSpace(UserInfo.User.ComId.Value, filesize);
|
||||
//msg.Result = newfile;
|
||||
ls.Add(newfile);
|
||||
}
|
||||
msg.Result = ls;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
msg.ErrorMsg = "上传图片";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 上传文件
|
||||
/// </summary>
|
||||
/// <param name="context"></param>
|
||||
/// <param name="msg"></param>
|
||||
/// <param name="P1"></param>
|
||||
/// <param name="P2"></param>
|
||||
/// <param name="UserInfo"></param>
|
||||
public void UPLOADFILEV1(JObject context, Msg_Result msg, string P1, string P2, JH_Auth_UserB.UserInfo UserInfo)
|
||||
{
|
||||
try
|
||||
{
|
||||
int fid = 3;
|
||||
if (!string.IsNullOrEmpty(P1))
|
||||
{
|
||||
fid = Int32.Parse(P1);
|
||||
}
|
||||
CommonHelp.WriteLOG("文件数量" + context.Request.Files.Count);
|
||||
|
||||
List<FT_File> ls = new List<FT_File>();
|
||||
for (int i = 0; i < context.Request.Files.Count; i++)
|
||||
{
|
||||
HttpPostedFile uploadFile = context.Request.Files[i];
|
||||
string originalName = uploadFile.FileName;
|
||||
string[] temp = uploadFile.FileName.Split('.');
|
||||
|
||||
//保存图片
|
||||
|
||||
string filename = System.Guid.NewGuid() + "." + temp[temp.Length - 1].ToLower();
|
||||
string md5 = new CommonHelp().SaveFile(UserInfo.QYinfo, filename, uploadFile);
|
||||
|
||||
string json = "[{filename:'" + uploadFile.FileName + "',md5:'" + md5.Split(',')[0] + "',zyid:'" + md5.Split(',')[1] + "',filesize:'" + uploadFile.InputStream.Length.ToString() + "'}]";
|
||||
QYWDManage qywd = new QYWDManage();
|
||||
|
||||
//MP4上传阿里云
|
||||
//if (Path.GetExtension(originalName).ToLower() == ".mp4")
|
||||
//{
|
||||
// md5 = md5.Replace("\"", "").Split(',')[0];
|
||||
// AliyunHelp.UploadToOSS(md5, "mp4", uploadFile.InputStream);
|
||||
//}
|
||||
|
||||
CommonHelp.WriteLOG("调用参数" + fid.ToString());
|
||||
qywd.ADDFILE(context, msg, json, fid.ToString(), UserInfo);
|
||||
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
msg.ErrorMsg = "上传图片";
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 上传文件(文档中心)
|
||||
/// </summary>
|
||||
/// <param name="context"></param>
|
||||
/// <param name="msg"></param>
|
||||
/// <param name="P1"></param>
|
||||
/// <param name="P2"></param>
|
||||
/// <param name="UserInfo"></param>
|
||||
public void UPLOADFILES(JObject context, Msg_Result msg, string P1, string P2, JH_Auth_UserB.UserInfo UserInfo)
|
||||
{
|
||||
try
|
||||
{
|
||||
HttpPostedFile uploadFile = context.Request.Files["upFile"];
|
||||
string originalName = uploadFile.FileName;
|
||||
string[] temp = uploadFile.FileName.Split('.');
|
||||
|
||||
//保存图片
|
||||
string filename = System.Guid.NewGuid() + "." + temp[temp.Length - 1].ToLower();
|
||||
string md5 = new CommonHelp().SaveFile(UserInfo.QYinfo, filename, uploadFile);
|
||||
string json = "[{filename:'" + uploadFile.FileName + "',md5:" + md5 + ",filesize:'" + uploadFile.InputStream.Length.ToString() + "'}]";
|
||||
|
||||
QYWDManage qywd = new QYWDManage();
|
||||
qywd.ADDFILE(context, msg, json, P1, UserInfo);
|
||||
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
msg.ErrorMsg = "上传图片";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
#region excel转换为table
|
||||
|
||||
/// <summary>
|
||||
/// excel转换为table
|
||||
/// </summary>
|
||||
/// <param name="context"></param>
|
||||
/// <param name="msg"></param>
|
||||
/// <param name="P1"></param>
|
||||
/// <param name="P2"></param>
|
||||
/// <param name="UserInfo"></param>
|
||||
public void EXCELTOTABLE(JObject context, Msg_Result msg, string P1, string P2, JH_Auth_UserB.UserInfo UserInfo)
|
||||
{
|
||||
try
|
||||
{
|
||||
DataTable dt = new DataTable();
|
||||
HttpPostedFile _upfile = context.Request.Files["upFile"];
|
||||
string headrow = context.Request["headrow"] ?? "0";//头部开始行下标
|
||||
if (_upfile == null)
|
||||
{
|
||||
msg.ErrorMsg = "请选择要上传的文件 ";
|
||||
}
|
||||
else
|
||||
{
|
||||
string fileName = _upfile.FileName;/*获取文件名: C:\Documents and Settings\Administrator\桌面\123.jpg*/
|
||||
string suffix = fileName.Substring(fileName.LastIndexOf(".") + 1).ToLower();/*获取后缀名并转为小写: jpg*/
|
||||
int bytes = _upfile.ContentLength;//获取文件的字节大小
|
||||
if (suffix == "xls" || suffix == "xlsx")
|
||||
{
|
||||
IWorkbook workbook = null;
|
||||
|
||||
Stream stream = _upfile.InputStream;
|
||||
|
||||
if (suffix == "xlsx") // 2007版本
|
||||
{
|
||||
workbook = new XSSFWorkbook(stream);
|
||||
}
|
||||
else if (suffix == "xls") // 2003版本
|
||||
{
|
||||
workbook = new HSSFWorkbook(stream);
|
||||
}
|
||||
|
||||
//获取excel的第一个sheet
|
||||
ISheet sheet = workbook.GetSheetAt(0);
|
||||
|
||||
//获取sheet的第一行
|
||||
IRow headerRow = sheet.GetRow(int.Parse(headrow));
|
||||
|
||||
//一行最后一个方格的编号 即总的列数
|
||||
int cellCount = headerRow.LastCellNum;
|
||||
//最后一列的标号 即总的行数
|
||||
int rowCount = sheet.LastRowNum;
|
||||
if (rowCount <= int.Parse(headrow))
|
||||
{
|
||||
msg.ErrorMsg = "文件中无数据! ";
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
List<JH_Auth_ExtendDataB.IMPORTYZ> yz = new List<JH_Auth_ExtendDataB.IMPORTYZ>();
|
||||
yz = new JH_Auth_ExtendDataB().GetTable(P1, UserInfo.QYinfo.ComId);//获取字段
|
||||
string str1 = string.Empty;//验证字段是否包含列名
|
||||
//列名
|
||||
for (int i = 0; i < cellCount; i++)
|
||||
{
|
||||
string strlm = headerRow.GetCell(i).ToString().Trim();
|
||||
if (yz.Count > 0)
|
||||
{
|
||||
#region 字段是否包含列名验证
|
||||
var l = yz.Where(p => p.Name == strlm);//验证字段是否包含列名
|
||||
if (l.Count() == 0)
|
||||
{
|
||||
if (string.IsNullOrEmpty(str1))
|
||||
{
|
||||
str1 = "文件中的【" + strlm + "】";
|
||||
}
|
||||
else
|
||||
{
|
||||
str1 = str1 + "、【" + strlm + "】";
|
||||
}
|
||||
|
||||
strlm = strlm + "<span style='color:red;'>不会导入</span>";
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
dt.Columns.Add(strlm);//添加列名
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(str1))
|
||||
{
|
||||
str1 = str1 + " 不属于当前导入的字段!<br>";
|
||||
}
|
||||
|
||||
dt.Columns.Add("status", Type.GetType("System.String"));
|
||||
|
||||
string str2 = string.Empty;//验证必填字段是否存在
|
||||
|
||||
#region 必填字段在文件中存不存在验证
|
||||
foreach (var v in yz.Where(p => p.IsNull == 1))
|
||||
{
|
||||
if (!dt.Columns.Contains(v.Name))
|
||||
{
|
||||
if (string.IsNullOrEmpty(str2))
|
||||
{
|
||||
str2 = "当前导入的必填字段:【" + v.Name + "】";
|
||||
}
|
||||
else
|
||||
{
|
||||
str2 = str2 + "、【" + v.Name + "】";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(str2))
|
||||
{
|
||||
str2 = str2 + " 在文件中不存在!<br>";
|
||||
}
|
||||
#endregion
|
||||
|
||||
string str3 = string.Empty;//验证必填字段是否有值
|
||||
string str4 = string.Empty;//验证字段是否重复
|
||||
string str5 = string.Empty;//验证字段是否存在
|
||||
|
||||
for (int i = (sheet.FirstRowNum + int.Parse(headrow) + 1); i <= sheet.LastRowNum; i++)
|
||||
{
|
||||
string str31 = string.Empty;
|
||||
string str41 = string.Empty;
|
||||
string str42 = string.Empty;
|
||||
string str51 = string.Empty;
|
||||
|
||||
DataRow dr = dt.NewRow();
|
||||
bool bl = false;
|
||||
IRow row = sheet.GetRow(i);
|
||||
|
||||
dr["status"] = "0";
|
||||
|
||||
for (int j = row.FirstCellNum; j < cellCount; j++)
|
||||
{
|
||||
string strsj = row.GetCell(j) != null ? row.GetCell(j).ToString().Trim() : "";
|
||||
if (strsj != "")
|
||||
{
|
||||
bl = true;
|
||||
}
|
||||
|
||||
foreach (var v in yz.Where(p => p.Name == headerRow.GetCell(j).ToString().Trim()))
|
||||
{
|
||||
if (strsj == "")
|
||||
{
|
||||
#region 必填字段验证
|
||||
if (v.IsNull == 1)
|
||||
{
|
||||
//strsj = "<span style='color:red;'>必填</span>";
|
||||
|
||||
if (string.IsNullOrEmpty(str31))
|
||||
{
|
||||
str31 = "第" + (i + 1) + "行的必填字段:【" + v.Name + "】";
|
||||
}
|
||||
else
|
||||
{
|
||||
str31 = str31 + "、【" + v.Name + "】";
|
||||
}
|
||||
dr["status"] = "2";
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
else
|
||||
{
|
||||
#region 长度验证
|
||||
if (v.Length != 0)
|
||||
{
|
||||
if (Encoding.Default.GetBytes(strsj).Length > v.Length)
|
||||
{
|
||||
strsj = strsj + "<span style='color:red;'>长度不能超过" + v.Length + "</span>";
|
||||
dr["status"] = "2";
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
#region 重复验证
|
||||
if (!string.IsNullOrEmpty(v.IsRepeat))
|
||||
{
|
||||
#region 与现有数据比较是否重复
|
||||
string[] strRS = v.IsRepeat.Split('|');
|
||||
|
||||
var cf = new JH_Auth_UserB().GetDTByCommand("select * from " + strRS[0] + " where " + strRS[1] + "= '" + strsj + "' and ComId='" + UserInfo.QYinfo.ComId + "'");
|
||||
if (cf.Rows.Count > 0)
|
||||
{
|
||||
if (string.IsNullOrEmpty(str41))
|
||||
{
|
||||
str41 = "第" + (i + 1) + "行的字段:【" + v.Name + "】" + strsj;
|
||||
}
|
||||
else
|
||||
{
|
||||
str41 = str41 + "、【" + v.Name + "】:" + strsj;
|
||||
}
|
||||
dr["status"] = "2";
|
||||
}
|
||||
#endregion
|
||||
#region 与Excel中数据比较是否重复
|
||||
DataRow[] drs = dt.Select(headerRow.GetCell(j).ToString().Trim() + "='" + strsj + "'");
|
||||
if (drs.Length > 0)
|
||||
{
|
||||
if (string.IsNullOrEmpty(str42))
|
||||
{
|
||||
str42 = "第" + (i + 1) + "行的字段:【" + v.Name + "】" + strsj;
|
||||
}
|
||||
else
|
||||
{
|
||||
str42 = str42 + "、【" + v.Name + "】" + strsj;
|
||||
}
|
||||
dr["status"] = "2";
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
#endregion
|
||||
#region 存在验证
|
||||
if (!string.IsNullOrEmpty(v.IsExist))
|
||||
{
|
||||
string[] strES = v.IsExist.Split('|');
|
||||
|
||||
var cz = new JH_Auth_UserB().GetDTByCommand("select * from " + strES[0] + " where " + strES[1] + "= '" + strsj + "' and ComId='" + UserInfo.QYinfo.ComId + "'");
|
||||
if (cz.Rows.Count == 0)
|
||||
{
|
||||
if (string.IsNullOrEmpty(str51))
|
||||
{
|
||||
str51 = "第" + (i + 1) + "行的字段:【" + v.Name + "】" + strsj;
|
||||
}
|
||||
else
|
||||
{
|
||||
str51 = str51 + "、【" + v.Name + "】" + strsj;
|
||||
}
|
||||
dr["status"] = "2";
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
dr[j] = strsj;
|
||||
}
|
||||
if (!string.IsNullOrEmpty(str31))
|
||||
{
|
||||
str31 = str31 + " 不能为空!<br>";
|
||||
str3 = str3 + str31;
|
||||
}
|
||||
if (!string.IsNullOrEmpty(str41))
|
||||
{
|
||||
str41 = str41 + " 已经存在!<br>";
|
||||
str4 = str4 + str41;
|
||||
}
|
||||
if (!string.IsNullOrEmpty(str42))
|
||||
{
|
||||
str42 = str42 + " 在文件中已经存在!<br>";
|
||||
str4 = str4 + str42;
|
||||
}
|
||||
if (!string.IsNullOrEmpty(str51))
|
||||
{
|
||||
str51 = str51 + " 不存在!<br>";
|
||||
str5 = str5 + str51;
|
||||
}
|
||||
|
||||
if (bl)
|
||||
{
|
||||
dt.Rows.Add(dr);
|
||||
}
|
||||
}
|
||||
if (string.IsNullOrEmpty(str2) && string.IsNullOrEmpty(str3) && string.IsNullOrEmpty(str4) && string.IsNullOrEmpty(str5))
|
||||
{
|
||||
msg.Result = dt;
|
||||
}
|
||||
|
||||
msg.Result1 = str1 + str2 + str3 + str4 + str5;
|
||||
}
|
||||
|
||||
sheet = null;
|
||||
workbook = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
msg.ErrorMsg = "请上传excel文件 ";
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
//msg.ErrorMsg = ex.ToString();
|
||||
msg.ErrorMsg = "导入失败!";
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 导出模板excel
|
||||
|
||||
/// <summary>
|
||||
/// 导出模板excel
|
||||
/// </summary>
|
||||
/// <param name="context"></param>
|
||||
/// <param name="msg"></param>
|
||||
/// <param name="P1"></param>
|
||||
/// <param name="P2"></param>
|
||||
/// <param name="UserInfo"></param>
|
||||
public void EXPORTTOEXCEL(JObject context, Msg_Result msg, string P1, string P2, JH_Auth_UserB.UserInfo UserInfo)
|
||||
{
|
||||
try
|
||||
{
|
||||
List<JH_Auth_ExtendDataB.IMPORTYZ> yz = new List<JH_Auth_ExtendDataB.IMPORTYZ>();
|
||||
yz = new JH_Auth_ExtendDataB().GetTable(P1, UserInfo.QYinfo.ComId);//获取字段
|
||||
if (yz.Count > 0)
|
||||
{
|
||||
HSSFWorkbook workbook = new HSSFWorkbook();
|
||||
ISheet sheet = workbook.CreateSheet("Sheet1");
|
||||
|
||||
ICellStyle HeadercellStyle = workbook.CreateCellStyle();
|
||||
HeadercellStyle.BorderBottom = BorderStyle.Thin;
|
||||
HeadercellStyle.BorderLeft = BorderStyle.Thin;
|
||||
HeadercellStyle.BorderRight = BorderStyle.Thin;
|
||||
HeadercellStyle.BorderTop = BorderStyle.Thin;
|
||||
HeadercellStyle.Alignment = HorizontalAlignment.Center;
|
||||
HeadercellStyle.FillForegroundColor = NPOI.HSSF.Util.HSSFColor.SkyBlue.Index;
|
||||
HeadercellStyle.FillPattern = FillPattern.SolidForeground;
|
||||
HeadercellStyle.FillBackgroundColor = NPOI.HSSF.Util.HSSFColor.SkyBlue.Index;
|
||||
|
||||
//字体
|
||||
NPOI.SS.UserModel.IFont headerfont = workbook.CreateFont();
|
||||
headerfont.Boldweight = (short)FontBoldWeight.Bold;
|
||||
headerfont.FontHeightInPoints = 12;
|
||||
HeadercellStyle.SetFont(headerfont);
|
||||
|
||||
|
||||
//用column name 作为列名
|
||||
int icolIndex = 0;
|
||||
IRow headerRow = sheet.CreateRow(0);
|
||||
foreach (var l in yz)
|
||||
{
|
||||
ICell cell = headerRow.CreateCell(icolIndex);
|
||||
cell.SetCellValue(l.Name);
|
||||
cell.CellStyle = HeadercellStyle;
|
||||
icolIndex++;
|
||||
}
|
||||
|
||||
ICellStyle cellStyle = workbook.CreateCellStyle();
|
||||
|
||||
//为避免日期格式被Excel自动替换,所以设定 format 为 『@』 表示一率当成text來看
|
||||
cellStyle.DataFormat = HSSFDataFormat.GetBuiltinFormat("@");
|
||||
cellStyle.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
|
||||
cellStyle.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
|
||||
cellStyle.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
|
||||
cellStyle.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
|
||||
|
||||
|
||||
NPOI.SS.UserModel.IFont cellfont = workbook.CreateFont();
|
||||
cellfont.Boldweight = (short)FontBoldWeight.Normal;
|
||||
cellStyle.SetFont(cellfont);
|
||||
|
||||
string strDataJson = new JH_Auth_ExtendDataB().GetExcelData(P1);
|
||||
if (strDataJson != "")
|
||||
{
|
||||
string[] strs = strDataJson.Split(',');
|
||||
|
||||
//建立内容行
|
||||
|
||||
int iCellIndex = 0;
|
||||
|
||||
IRow DataRow = sheet.CreateRow(1);
|
||||
for (int i = 0; i < strs.Length; i++)
|
||||
{
|
||||
|
||||
ICell cell = DataRow.CreateCell(iCellIndex);
|
||||
cell.SetCellValue(strs[i]);
|
||||
cell.CellStyle = cellStyle;
|
||||
iCellIndex++;
|
||||
}
|
||||
}
|
||||
|
||||
//自适应列宽度
|
||||
for (int i = 0; i < icolIndex; i++)
|
||||
{
|
||||
sheet.AutoSizeColumn(i);
|
||||
}
|
||||
|
||||
using (MemoryStream ms = new MemoryStream())
|
||||
{
|
||||
workbook.Write(ms);
|
||||
|
||||
object curContext = object.Current;
|
||||
|
||||
string strName = string.Empty;
|
||||
|
||||
|
||||
// 设置编码和附件格式
|
||||
curContext.Response.ContentType = "application/vnd.ms-excel";
|
||||
curContext.Response.ContentEncoding = Encoding.UTF8;
|
||||
curContext.Response.Charset = "";
|
||||
curContext.Response.AppendHeader("Content-Disposition",
|
||||
"attachment;filename=" + HttpUtility.UrlEncode("CRM_" + strName + "_模板文件.xls", Encoding.UTF8));
|
||||
|
||||
curContext.Response.BinaryWrite(ms.GetBuffer());
|
||||
curContext.Response.End();
|
||||
|
||||
workbook = null;
|
||||
ms.Close();
|
||||
ms.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
catch
|
||||
{
|
||||
msg.ErrorMsg = "导入失败!";
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 下载模板excel(弃用)
|
||||
/// </summary>
|
||||
/// <param name="context"></param>
|
||||
/// <param name="msg"></param>
|
||||
/// <param name="P1"></param>
|
||||
/// <param name="P2"></param>
|
||||
/// <param name="UserInfo"></param>
|
||||
public void DOWNLOADEXCEL(JObject context, Msg_Result msg, string P1, string P2, JH_Auth_UserB.UserInfo UserInfo)
|
||||
{
|
||||
try
|
||||
{
|
||||
string strName = string.Empty;
|
||||
if (P1 == "KHGL")
|
||||
{
|
||||
strName = "CRM_客户_导入模板.xls";
|
||||
}
|
||||
else if (P1 == "KHLXR")
|
||||
{
|
||||
strName = "CRM_客户联系人_导入模板.xls";
|
||||
}
|
||||
else if (P1 == "HTGL")
|
||||
{
|
||||
strName = "CRM_合同_导入模板.xls";
|
||||
}
|
||||
object curContext = object.Current;
|
||||
string headrow = context.Request["headrow"] ?? "0";//头部开始行下标
|
||||
string path = curContext.Server.MapPath(@"/ViewV5/base/" + strName);
|
||||
FileStream file = new FileStream(path, FileMode.Open, FileAccess.Read);
|
||||
string suffix = path.Substring(path.LastIndexOf(".") + 1).ToLower();
|
||||
|
||||
IWorkbook workbook = null;
|
||||
|
||||
if (suffix == "xlsx") // 2007版本
|
||||
{
|
||||
workbook = new XSSFWorkbook(file);
|
||||
}
|
||||
else if (suffix == "xls") // 2003版本
|
||||
{
|
||||
workbook = new HSSFWorkbook(file);
|
||||
}
|
||||
ISheet sheet = workbook.GetSheetAt(0);
|
||||
|
||||
IRow headerRow = sheet.GetRow(int.Parse(headrow));
|
||||
IRow oneRow = sheet.GetRow(int.Parse(headrow) + 1);
|
||||
|
||||
int icolIndex = headerRow.Cells.Count;
|
||||
|
||||
DataTable dtExtColumn = new JH_Auth_ExtendModeB().GetExtColumnAll(UserInfo.QYinfo.ComId, P1);
|
||||
foreach (DataRow drExt in dtExtColumn.Rows)
|
||||
{
|
||||
ICell cell = headerRow.CreateCell(icolIndex);
|
||||
cell.SetCellValue(drExt["TableFiledName"].ToString());
|
||||
cell.CellStyle = headerRow.Cells[icolIndex - 1].CellStyle;
|
||||
|
||||
ICell onecell = oneRow.CreateCell(icolIndex);
|
||||
onecell.SetCellValue("");
|
||||
onecell.CellStyle = oneRow.Cells[icolIndex - 1].CellStyle;
|
||||
|
||||
icolIndex++;
|
||||
}
|
||||
|
||||
//自适应列宽度
|
||||
for (int i = 0; i < icolIndex; i++)
|
||||
{
|
||||
sheet.AutoSizeColumn(i);
|
||||
}
|
||||
|
||||
if (P1 == "KHGL")
|
||||
{
|
||||
//表头样式
|
||||
ICellStyle HeadercellStyle = workbook.CreateCellStyle();
|
||||
HeadercellStyle.BorderBottom = BorderStyle.Thin;
|
||||
HeadercellStyle.BorderLeft = BorderStyle.Thin;
|
||||
HeadercellStyle.BorderRight = BorderStyle.Thin;
|
||||
HeadercellStyle.BorderTop = BorderStyle.Thin;
|
||||
HeadercellStyle.Alignment = HorizontalAlignment.Center;
|
||||
|
||||
//字体
|
||||
NPOI.SS.UserModel.IFont headerfont = workbook.CreateFont();
|
||||
headerfont.Boldweight = (short)FontBoldWeight.Bold;
|
||||
headerfont.FontHeightInPoints = 12;
|
||||
HeadercellStyle.SetFont(headerfont);
|
||||
|
||||
//单元格样式
|
||||
ICellStyle cellStyle = workbook.CreateCellStyle();
|
||||
|
||||
//为避免日期格式被Excel自动替换,所以设定 format 为 『@』 表示一率当成text來看
|
||||
cellStyle.DataFormat = HSSFDataFormat.GetBuiltinFormat("@");
|
||||
cellStyle.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
|
||||
cellStyle.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
|
||||
cellStyle.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
|
||||
cellStyle.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
|
||||
|
||||
|
||||
NPOI.SS.UserModel.IFont cellfont = workbook.CreateFont();
|
||||
cellfont.Boldweight = (short)FontBoldWeight.Normal;
|
||||
headerfont.FontHeightInPoints = 10;
|
||||
cellStyle.SetFont(cellfont);
|
||||
|
||||
for (int i = 10; i < 15; i++)
|
||||
{
|
||||
string strZTName = string.Empty;
|
||||
if (i == 10) { strZTName = "客户类型"; }
|
||||
if (i == 11) { strZTName = "跟进状态"; }
|
||||
if (i == 12) { strZTName = "客户来源"; }
|
||||
if (i == 13) { strZTName = "所属行业"; }
|
||||
if (i == 14) { strZTName = "人员规模"; }
|
||||
ISheet sheet1 = workbook.CreateSheet(strZTName);
|
||||
IRow headerRow1 = sheet1.CreateRow(0);
|
||||
ICell cell1 = headerRow1.CreateCell(0);
|
||||
cell1.SetCellValue(strZTName);
|
||||
cell1.CellStyle = HeadercellStyle;
|
||||
|
||||
int rowindex1 = 1;
|
||||
|
||||
foreach (var l in new JH_Auth_ZiDianB().GetEntities(p => p.ComId == UserInfo.QYinfo.ComId && p.Class == i))
|
||||
{
|
||||
IRow DataRow = sheet1.CreateRow(rowindex1);
|
||||
ICell cell = DataRow.CreateCell(0);
|
||||
cell.SetCellValue(l.TypeName);
|
||||
cell.CellStyle = cellStyle;
|
||||
rowindex1++;
|
||||
}
|
||||
|
||||
sheet1.AutoSizeColumn(0);
|
||||
}
|
||||
}
|
||||
if (P1 == "HTGL")
|
||||
{
|
||||
//表头样式
|
||||
ICellStyle HeadercellStyle = workbook.CreateCellStyle();
|
||||
HeadercellStyle.BorderBottom = BorderStyle.Thin;
|
||||
HeadercellStyle.BorderLeft = BorderStyle.Thin;
|
||||
HeadercellStyle.BorderRight = BorderStyle.Thin;
|
||||
HeadercellStyle.BorderTop = BorderStyle.Thin;
|
||||
HeadercellStyle.Alignment = HorizontalAlignment.Center;
|
||||
|
||||
//字体
|
||||
NPOI.SS.UserModel.IFont headerfont = workbook.CreateFont();
|
||||
headerfont.Boldweight = (short)FontBoldWeight.Bold;
|
||||
headerfont.FontHeightInPoints = 12;
|
||||
HeadercellStyle.SetFont(headerfont);
|
||||
|
||||
//单元格样式
|
||||
ICellStyle cellStyle = workbook.CreateCellStyle();
|
||||
|
||||
//为避免日期格式被Excel自动替换,所以设定 format 为 『@』 表示一率当成text來看
|
||||
cellStyle.DataFormat = HSSFDataFormat.GetBuiltinFormat("@");
|
||||
cellStyle.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
|
||||
cellStyle.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
|
||||
cellStyle.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
|
||||
cellStyle.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
|
||||
|
||||
|
||||
NPOI.SS.UserModel.IFont cellfont = workbook.CreateFont();
|
||||
cellfont.Boldweight = (short)FontBoldWeight.Normal;
|
||||
headerfont.FontHeightInPoints = 10;
|
||||
cellStyle.SetFont(cellfont);
|
||||
|
||||
for (int i = 16; i < 18; i++)
|
||||
{
|
||||
string strZTName = string.Empty;
|
||||
if (i == 16) { strZTName = "合同类型"; }
|
||||
if (i == 17) { strZTName = "付款方式"; }
|
||||
ISheet sheet1 = workbook.CreateSheet(strZTName);
|
||||
IRow headerRow1 = sheet1.CreateRow(0);
|
||||
ICell cell1 = headerRow1.CreateCell(0);
|
||||
cell1.SetCellValue(strZTName);
|
||||
cell1.CellStyle = HeadercellStyle;
|
||||
|
||||
int rowindex1 = 1;
|
||||
|
||||
foreach (var l in new JH_Auth_ZiDianB().GetEntities(p => p.ComId == UserInfo.QYinfo.ComId && p.Class == i))
|
||||
{
|
||||
IRow DataRow = sheet1.CreateRow(rowindex1);
|
||||
ICell cell = DataRow.CreateCell(0);
|
||||
cell.SetCellValue(l.TypeName);
|
||||
cell.CellStyle = cellStyle;
|
||||
rowindex1++;
|
||||
}
|
||||
|
||||
sheet1.AutoSizeColumn(0);
|
||||
}
|
||||
}
|
||||
|
||||
using (MemoryStream ms = new MemoryStream())
|
||||
{
|
||||
workbook.Write(ms);
|
||||
|
||||
//object curContext = object.Current;
|
||||
|
||||
// 设置编码和附件格式
|
||||
curContext.Response.ContentType = "application/vnd.ms-excel";
|
||||
curContext.Response.ContentEncoding = Encoding.UTF8;
|
||||
curContext.Response.Charset = "";
|
||||
curContext.Response.AppendHeader("Content-Disposition",
|
||||
"attachment;filename=" + HttpUtility.UrlEncode(strName, Encoding.UTF8));
|
||||
|
||||
curContext.Response.BinaryWrite(ms.GetBuffer());
|
||||
curContext.Response.End();
|
||||
|
||||
workbook = null;
|
||||
ms.Close();
|
||||
ms.Dispose();
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
msg.ErrorMsg = "下载失败!";
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
298
iMES.Bi.API/API/DATABI/BIbus.cs
Normal file
298
iMES.Bi.API/API/DATABI/BIbus.cs
Normal file
@@ -0,0 +1,298 @@
|
||||
using iMES.Bi.Data;
|
||||
using SqlSugar;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
|
||||
namespace iMES.Bi.API
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#region 数据BI模块
|
||||
|
||||
public class BI_DB_DimB : BaseEFDao<BI_DB_Dim> { }
|
||||
public class BI_DB_SetB : BaseEFDao<BI_DB_Set>
|
||||
{
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 获取Data得经纬度
|
||||
/// </summary>
|
||||
/// <param name="dt"></param>
|
||||
/// <returns></returns>
|
||||
public List<BI_DB_Dim> getCType(DataTable dt)
|
||||
{
|
||||
|
||||
List<BI_DB_Dim> ListDIM = new List<BI_DB_Dim>();
|
||||
for (int i = 0; i < dt.Columns.Count; i++)
|
||||
{
|
||||
BI_DB_Dim DIM = new BI_DB_Dim();
|
||||
DIM.Name = dt.Columns[i].ColumnName;
|
||||
DIM.ColumnName = dt.Columns[i].ColumnName;
|
||||
DIM.ColumnSource = "0";
|
||||
string strType = dt.Columns[i].DataType.Name.ToLower();
|
||||
if (strType.Contains("int"))
|
||||
{
|
||||
DIM.ColumnType = "Num";
|
||||
DIM.Dimension = "2";
|
||||
}
|
||||
else if (strType.Contains("decimal") || strType.Contains("float") || strType.Contains("Double"))
|
||||
{
|
||||
DIM.ColumnType = "float";
|
||||
DIM.Dimension = "2";
|
||||
|
||||
}
|
||||
else if (strType.Contains("datetime"))
|
||||
{
|
||||
DIM.ColumnType = "Date";
|
||||
DIM.Dimension = "1";
|
||||
}
|
||||
else
|
||||
{
|
||||
DIM.ColumnType = "Str";
|
||||
DIM.Dimension = "1";
|
||||
|
||||
}
|
||||
ListDIM.Add(DIM);
|
||||
}
|
||||
return ListDIM;
|
||||
}
|
||||
}
|
||||
public class BI_DB_SourceB : BaseEFDao<BI_DB_Source>
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// 获取数据源
|
||||
/// </summary>
|
||||
/// <param name="intSID"></param>
|
||||
/// <returns></returns>
|
||||
public DBFactory GetDB(int intSID)
|
||||
{
|
||||
DBFactory db = new DBFactory();
|
||||
if (intSID == 0)//本地数据库
|
||||
{
|
||||
string strCon = new BI_DB_SetB().GetDBString();
|
||||
db = new DBFactory(strCon);
|
||||
}
|
||||
else
|
||||
{
|
||||
var tt = new BI_DB_SourceB().GetEntity(p => p.ID == intSID);
|
||||
if (tt != null)
|
||||
{
|
||||
db = new DBFactory(tt.DBType, tt.DBIP, tt.Port, tt.DBName, tt.DBUser, tt.DBPwd);
|
||||
}
|
||||
}
|
||||
return db;
|
||||
|
||||
}
|
||||
}
|
||||
public class BI_DB_YBPB : BaseEFDao<BI_DB_YBP>
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
|
||||
public class BI_DB_TableB : BaseEFDao<BI_DB_Table>
|
||||
{
|
||||
public bool ReTabName(int tabid, string strNewName)
|
||||
{
|
||||
|
||||
BI_DB_Table model = new BI_DB_TableB().GetEntity(D => D.ID == tabid);
|
||||
DBFactory dbccgc = new BI_DB_SourceB().GetDB(model.DSID);
|
||||
dbccgc.GetDBClient().DbMaintenance.RenameTable(model.TableName, strNewName);
|
||||
model.TableName = strNewName;
|
||||
return new BI_DB_TableB().Update(model);
|
||||
}
|
||||
public List<DbColumnInfo> CreateLogicTable(BI_DB_Table model)
|
||||
{
|
||||
string strTableName = model.TableName;
|
||||
DBFactory dbccgc = new BI_DB_SourceB().GetDB(model.DSID);
|
||||
List<DbColumnInfo> ListC = new List<DbColumnInfo>();
|
||||
DbColumnInfo colID = new DbColumnInfo();
|
||||
colID.DataType = "int";
|
||||
colID.DbColumnName = "ID";
|
||||
colID.IsPrimarykey = true;
|
||||
colID.IsIdentity = true;
|
||||
colID.IsNullable = false;
|
||||
ListC.Add(colID);
|
||||
|
||||
DbColumnInfo colCRUser = new DbColumnInfo();
|
||||
colCRUser.DataType = "varchar";
|
||||
colCRUser.DbColumnName = "CRUser";
|
||||
colCRUser.ColumnDescription = "创建人";
|
||||
colCRUser.Length = 255;
|
||||
colCRUser.IsNullable = true;
|
||||
ListC.Add(colCRUser);
|
||||
|
||||
|
||||
DbColumnInfo colDCode = new DbColumnInfo();
|
||||
colDCode.DataType = "varchar";
|
||||
colDCode.DbColumnName = "DCode";
|
||||
colDCode.ColumnDescription = "机构代码";
|
||||
colDCode.Length = 255;
|
||||
colDCode.IsNullable = true;
|
||||
ListC.Add(colDCode);
|
||||
|
||||
DbColumnInfo colDName = new DbColumnInfo();
|
||||
colDName.DataType = "varchar";
|
||||
colDName.DbColumnName = "DName";
|
||||
colDName.ColumnDescription = "机构名称";
|
||||
colDName.Length = 255;
|
||||
colDName.IsNullable = true;
|
||||
ListC.Add(colDName);
|
||||
|
||||
DbColumnInfo colCRUserName = new DbColumnInfo();
|
||||
colCRUserName.DataType = "varchar";
|
||||
colCRUserName.DbColumnName = "CRUserName";
|
||||
colCRUserName.ColumnDescription = "真实姓名";
|
||||
colCRUserName.Length = 255;
|
||||
colCRUserName.IsNullable = true;
|
||||
ListC.Add(colCRUserName);
|
||||
|
||||
DbColumnInfo colCRDate = new DbColumnInfo();
|
||||
colCRDate.DataType = "datetime";
|
||||
colCRDate.DbColumnName = "CRDate";
|
||||
colCRDate.IsNullable = true;
|
||||
|
||||
ListC.Add(colCRDate);
|
||||
|
||||
|
||||
DbColumnInfo colINPID = new DbColumnInfo();
|
||||
colINPID.DataType = "int";
|
||||
colINPID.DbColumnName = "intProcessStanceid";
|
||||
colINPID.ColumnDescription = "流程ID";
|
||||
colINPID.IsNullable = true;
|
||||
colINPID.DefaultValue = "0";
|
||||
|
||||
ListC.Add(colINPID);
|
||||
|
||||
DbColumnInfo colComID = new DbColumnInfo();
|
||||
colComID.DataType = "int";
|
||||
colComID.DbColumnName = "ComID";
|
||||
colComID.IsNullable = true;
|
||||
ListC.Add(colComID);
|
||||
|
||||
dbccgc.GetDBClient().DbMaintenance.CreateTable(strTableName, ListC);
|
||||
return ListC;
|
||||
}
|
||||
|
||||
public void DelLogicTable(int tabid)
|
||||
{
|
||||
|
||||
BI_DB_Table model = this.GetEntity(D => D.ID == tabid);
|
||||
DBFactory dbccgc = new BI_DB_SourceB().GetDB(model.DSID);
|
||||
string strTableName = model.TableName;
|
||||
dbccgc.GetDBClient().DbMaintenance.DropTable(strTableName);
|
||||
|
||||
var result = this.Db.Ado.UseTran(() =>
|
||||
{
|
||||
new BI_DB_TableB().Delete(D => D.ID == tabid);
|
||||
new BI_DB_TablefiledB().Delete(D => D.TableID == tabid);
|
||||
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public class BI_DB_TablefiledB : BaseEFDao<BI_DB_Tablefiled>
|
||||
{
|
||||
public void AddCol(BI_DB_Tablefiled col)
|
||||
{
|
||||
|
||||
BI_DB_Table model = new BI_DB_TableB().GetEntity(D => D.ID == col.TableID);
|
||||
DBFactory dbccgc = new BI_DB_SourceB().GetDB(model.DSID);
|
||||
DbColumnInfo filed = new DbColumnInfo();
|
||||
filed.DataType = col.DataType;
|
||||
filed.DbColumnName = col.DbColumnName;
|
||||
filed.IsPrimarykey = false;
|
||||
filed.IsIdentity = false;
|
||||
filed.ColumnDescription = col.ColumnDescription;
|
||||
filed.IsNullable = col.IsNullable == "0" ? true : false;
|
||||
filed.DefaultValue = col.DefaultValue;
|
||||
if (dbccgc.GetDBType() == "SqlServer" && col.DataType == "int")
|
||||
{
|
||||
filed.Length = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
filed.Length = col.Length == -1 ? int.MaxValue : col.Length;
|
||||
|
||||
}
|
||||
filed.DecimalDigits = int.Parse(col.DecimalDigits);
|
||||
|
||||
dbccgc.GetDBClient().DbMaintenance.AddColumn(model.TableName, filed);
|
||||
}
|
||||
|
||||
public bool upCol(BI_DB_Tablefiled col)
|
||||
{
|
||||
|
||||
BI_DB_Table model = new BI_DB_TableB().GetEntity(D => D.ID == col.TableID);
|
||||
DBFactory dbccgc = new BI_DB_SourceB().GetDB(model.DSID);
|
||||
DbColumnInfo filed = new DbColumnInfo();
|
||||
filed.DataType = col.DataType;
|
||||
filed.DbColumnName = col.DbColumnName;
|
||||
filed.ColumnDescription = col.ColumnDescription;
|
||||
filed.IsNullable = col.IsNullable == "0" ? true : false;
|
||||
filed.DefaultValue = col.DefaultValue;
|
||||
if (dbccgc.GetDBType() == "SqlServer" && col.DataType == "int")
|
||||
{
|
||||
filed.Length = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
filed.Length = col.Length;
|
||||
|
||||
}
|
||||
filed.DecimalDigits = int.Parse(col.DecimalDigits);
|
||||
|
||||
return dbccgc.GetDBClient().DbMaintenance.UpdateColumn(model.TableName, filed);
|
||||
}
|
||||
|
||||
public bool DelCol(BI_DB_Tablefiled col)
|
||||
{
|
||||
|
||||
BI_DB_Table model = new BI_DB_TableB().GetEntity(D => D.ID == col.TableID);
|
||||
DBFactory dbccgc = new BI_DB_SourceB().GetDB(model.DSID);
|
||||
return dbccgc.GetDBClient().DbMaintenance.DropColumn(model.TableName, col.DbColumnName);
|
||||
}
|
||||
|
||||
|
||||
public bool ReColName(BI_DB_Tablefiled col, string strOldName)
|
||||
{
|
||||
|
||||
BI_DB_Table model = new BI_DB_TableB().GetEntity(D => D.ID == col.TableID);
|
||||
DBFactory dbccgc = new BI_DB_SourceB().GetDB(model.DSID);
|
||||
return dbccgc.GetDBClient().DbMaintenance.RenameColumn(model.TableName, strOldName, col.DbColumnName);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
1310
iMES.Bi.API/API/DATABI/DATABIManage.cs
Normal file
1310
iMES.Bi.API/API/DATABI/DATABIManage.cs
Normal file
File diff suppressed because it is too large
Load Diff
18
iMES.Bi.API/APIHelp.cs
Normal file
18
iMES.Bi.API/APIHelp.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
namespace iMES.Bi.API
|
||||
{
|
||||
class APIHelp
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
public static class APIExtensions
|
||||
{
|
||||
public static string Request(this JObject JData, string strPro, string strDefault = null)
|
||||
{
|
||||
return JData[strPro] != null ? JData[strPro].ToString() : strDefault;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
913
iMES.Bi.API/CommonHelp.cs
Normal file
913
iMES.Bi.API/CommonHelp.cs
Normal file
@@ -0,0 +1,913 @@
|
||||
using NPOI.HSSF.UserModel;
|
||||
using NPOI.SS.UserModel;
|
||||
using NPOI.XSSF.UserModel;
|
||||
using iMES.Bi.Data;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
using System.Reflection;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Web;
|
||||
|
||||
namespace iMES.Bi.API
|
||||
{
|
||||
public class CommonHelp
|
||||
{
|
||||
|
||||
public static T DeepCopyByReflect<T>(T obj)
|
||||
{
|
||||
//如果是字符串或值类型则直接返回
|
||||
if (obj is string || obj.GetType().IsValueType) return obj;
|
||||
|
||||
object retval = Activator.CreateInstance(obj.GetType());
|
||||
FieldInfo[] fields = obj.GetType().GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static);
|
||||
foreach (FieldInfo field in fields)
|
||||
{
|
||||
try { field.SetValue(retval, DeepCopyByReflect(field.GetValue(obj))); }
|
||||
catch { }
|
||||
}
|
||||
return (T)retval;
|
||||
}
|
||||
/// <summary>
|
||||
/// 从html中提取纯文本
|
||||
/// </summary>
|
||||
/// <param name="strHtml"></param>
|
||||
/// <returns></returns>
|
||||
public string StripHT(string strHtml) //从html中提取纯文本
|
||||
{
|
||||
Regex regex = new Regex("<.+?>", RegexOptions.IgnoreCase);
|
||||
string strOutput = regex.Replace(strHtml, "");//替换掉"<"和">"之间的内容
|
||||
strOutput = strOutput.Replace("<", "");
|
||||
strOutput = strOutput.Replace(">", "");
|
||||
strOutput = strOutput.Replace(" ", "");
|
||||
return strOutput;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 移除html标签
|
||||
/// </summary>
|
||||
/// <param name="html"></param>
|
||||
/// <returns></returns>
|
||||
public static string RemoveHtml(string html)
|
||||
{
|
||||
if (string.IsNullOrEmpty(html)) return html;
|
||||
|
||||
Regex regex = new Regex("<.+?>");
|
||||
var matches = regex.Matches(html);
|
||||
|
||||
foreach (Match match in matches)
|
||||
{
|
||||
html = html.Replace(match.Value, "");
|
||||
}
|
||||
return html;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public static string PostWebRequest(string postUrl, string paramData, Encoding dataEncode)
|
||||
{
|
||||
string ret = string.Empty;
|
||||
try
|
||||
{
|
||||
byte[] byteArray = dataEncode.GetBytes(paramData); //转化
|
||||
HttpWebRequest webReq = (HttpWebRequest)WebRequest.Create(new Uri(postUrl));
|
||||
webReq.Method = "POST";
|
||||
webReq.ContentType = "application/json; charset=UTF-8";
|
||||
|
||||
webReq.ContentLength = byteArray.Length;
|
||||
Stream newStream = webReq.GetRequestStream();
|
||||
newStream.Write(byteArray, 0, byteArray.Length);//写入参数
|
||||
newStream.Close();
|
||||
HttpWebResponse response = (HttpWebResponse)webReq.GetResponse();
|
||||
StreamReader sr = new StreamReader(response.GetResponseStream(), Encoding.Default);
|
||||
ret = sr.ReadToEnd();
|
||||
sr.Close();
|
||||
response.Close();
|
||||
newStream.Close();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return ex.Message;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static HttpWebResponse CreateHttpResponse(string url, IDictionary<string, string> parameters, int timeout, string userAgent, CookieCollection cookies, string strType = "POST")
|
||||
{
|
||||
HttpWebRequest request = null;
|
||||
//如果是发送HTTPS请求
|
||||
if (url.StartsWith("https", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
//ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(CheckValidationResult);
|
||||
request = WebRequest.Create(url) as HttpWebRequest;
|
||||
//request.ProtocolVersion = HttpVersion.Version10;
|
||||
}
|
||||
else
|
||||
{
|
||||
request = WebRequest.Create(url) as HttpWebRequest;
|
||||
}
|
||||
request.Method = strType;
|
||||
request.ContentType = "application/x-www-form-urlencoded";
|
||||
|
||||
//设置代理UserAgent和超时
|
||||
//request.UserAgent = userAgent;
|
||||
//request.Timeout = timeout;
|
||||
|
||||
if (cookies != null)
|
||||
{
|
||||
request.CookieContainer = new CookieContainer();
|
||||
request.CookieContainer.Add(cookies);
|
||||
}
|
||||
//发送POST数据
|
||||
if (!(parameters == null || parameters.Count == 0))
|
||||
{
|
||||
StringBuilder buffer = new StringBuilder();
|
||||
int i = 0;
|
||||
foreach (string key in parameters.Keys)
|
||||
{
|
||||
if (i > 0)
|
||||
{
|
||||
buffer.AppendFormat("&{0}={1}", key, parameters[key]);
|
||||
}
|
||||
else
|
||||
{
|
||||
buffer.AppendFormat("{0}={1}", key, parameters[key]);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
byte[] data = Encoding.UTF8.GetBytes(buffer.ToString());
|
||||
using (Stream stream = request.GetRequestStream())
|
||||
{
|
||||
stream.Write(data, 0, data.Length);
|
||||
}
|
||||
}
|
||||
string[] values = request.Headers.GetValues("Content-Type");
|
||||
return request.GetResponse() as HttpWebResponse;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 创建POST方式的HTTP请求
|
||||
/// </summary>
|
||||
public static HttpWebResponse CreatePostHttpResponse(string url, IDictionary<string, string> parameters, int timeout, string userAgent, CookieCollection cookies, string strType = "POST")
|
||||
{
|
||||
HttpWebRequest request = null;
|
||||
//如果是发送HTTPS请求
|
||||
if (url.StartsWith("https", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
//ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(CheckValidationResult);
|
||||
request = WebRequest.Create(url) as HttpWebRequest;
|
||||
//request.ProtocolVersion = HttpVersion.Version10;
|
||||
}
|
||||
else
|
||||
{
|
||||
request = WebRequest.Create(url) as HttpWebRequest;
|
||||
}
|
||||
request.Method = strType;
|
||||
request.ContentType = "application/x-www-form-urlencoded";
|
||||
|
||||
//设置代理UserAgent和超时
|
||||
//request.UserAgent = userAgent;
|
||||
//request.Timeout = timeout;
|
||||
|
||||
if (cookies != null)
|
||||
{
|
||||
request.CookieContainer = new CookieContainer();
|
||||
request.CookieContainer.Add(cookies);
|
||||
}
|
||||
//发送POST数据
|
||||
if (!(parameters == null || parameters.Count == 0))
|
||||
{
|
||||
StringBuilder buffer = new StringBuilder();
|
||||
int i = 0;
|
||||
foreach (string key in parameters.Keys)
|
||||
{
|
||||
if (i > 0)
|
||||
{
|
||||
buffer.AppendFormat("&{0}={1}", key, parameters[key]);
|
||||
}
|
||||
else
|
||||
{
|
||||
buffer.AppendFormat("{0}={1}", key, parameters[key]);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
byte[] data = Encoding.UTF8.GetBytes(buffer.ToString());
|
||||
using (Stream stream = request.GetRequestStream())
|
||||
{
|
||||
stream.Write(data, 0, data.Length);
|
||||
}
|
||||
}
|
||||
string[] values = request.Headers.GetValues("Content-Type");
|
||||
return request.GetResponse() as HttpWebResponse;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取请求的数据
|
||||
/// </summary>
|
||||
public static string GetResponseString(HttpWebResponse webresponse)
|
||||
{
|
||||
using (Stream s = webresponse.GetResponseStream())
|
||||
{
|
||||
StreamReader reader = new StreamReader(s, Encoding.Default);
|
||||
return reader.ReadToEnd();
|
||||
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 导出Excel
|
||||
/// </summary>
|
||||
/// <param name="table"></param>
|
||||
/// <param name="fileName"></param>
|
||||
public static MemoryStream RenderToExcel(DataTable table)
|
||||
{
|
||||
MemoryStream ms = new MemoryStream();
|
||||
|
||||
using (table)
|
||||
{
|
||||
IWorkbook workbook = new HSSFWorkbook();
|
||||
ISheet sheet = workbook.CreateSheet();
|
||||
IRow headerRow = sheet.CreateRow(0);
|
||||
|
||||
// handling header.
|
||||
foreach (DataColumn column in table.Columns)
|
||||
headerRow.CreateCell(column.Ordinal).SetCellValue(column.Caption);//If Caption not set, returns the ColumnName value
|
||||
|
||||
// handling value.
|
||||
int rowIndex = 1;
|
||||
|
||||
foreach (DataRow row in table.Rows)
|
||||
{
|
||||
IRow dataRow = sheet.CreateRow(rowIndex);
|
||||
|
||||
foreach (DataColumn column in table.Columns)
|
||||
{
|
||||
dataRow.CreateCell(column.Ordinal).SetCellValue(row[column].ToString());
|
||||
}
|
||||
|
||||
rowIndex++;
|
||||
}
|
||||
|
||||
workbook.Write(ms);
|
||||
ms.Flush();
|
||||
ms.Position = 0;
|
||||
}
|
||||
|
||||
//using (FileStream fs = new FileStream(fileName, FileMode.Create, FileAccess.Write))
|
||||
//{
|
||||
// byte[] data = ms.ToArray();
|
||||
|
||||
// fs.Write(data, 0, data.Length);
|
||||
// fs.Flush();
|
||||
// data = null;
|
||||
//}
|
||||
return ms;
|
||||
}
|
||||
|
||||
//
|
||||
public static bool HasData(Stream excelFileStream)
|
||||
{
|
||||
using (excelFileStream)
|
||||
{
|
||||
IWorkbook workbook = new HSSFWorkbook(excelFileStream);
|
||||
if (workbook.NumberOfSheets > 0)
|
||||
{
|
||||
ISheet sheet = workbook.GetSheetAt(0);
|
||||
return sheet.PhysicalNumberOfRows > 0;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static string SendDX(string Mobile, string Content, string SendTime)
|
||||
{
|
||||
try
|
||||
{
|
||||
string returnData = "";
|
||||
// string url = CommonHelp.GetConfig("DXURL") + "&Mobile=" + Mobile + "&Content=" + Content;
|
||||
if (CommonHelp.GetConfig("DXURL") != "")
|
||||
{
|
||||
string url = CommonHelp.GetConfig("DXURL") + "&phone=" + Mobile + "&msg=" + Content;
|
||||
CommonHelp.WriteLOG(url);
|
||||
WebClient WC = new WebClient();
|
||||
WC.Headers.Add("Content-Type", "application/x-www-form-urlencoded");
|
||||
int p = url.IndexOf("?");
|
||||
string sData = url.Substring(p + 1);
|
||||
url = url.Substring(0, p);
|
||||
byte[] postData = Encoding.GetEncoding("gb2312").GetBytes(sData);
|
||||
byte[] responseData = WC.UploadData(url, "POST", postData);
|
||||
returnData = Encoding.GetEncoding("gb2312").GetString(responseData);
|
||||
}
|
||||
return returnData;
|
||||
|
||||
|
||||
}
|
||||
catch (Exception Ex)
|
||||
{
|
||||
return Ex.Message;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static HSSFWorkbook ExportToExcel(DataTable dt)
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
HSSFWorkbook workbook = new HSSFWorkbook();
|
||||
if (dt.Rows.Count > 0)
|
||||
{
|
||||
ISheet sheet = workbook.CreateSheet("Sheet1");
|
||||
|
||||
ICellStyle HeadercellStyle = workbook.CreateCellStyle();
|
||||
HeadercellStyle.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
|
||||
HeadercellStyle.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
|
||||
HeadercellStyle.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
|
||||
HeadercellStyle.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
|
||||
HeadercellStyle.Alignment = HorizontalAlignment.Center;
|
||||
HeadercellStyle.FillForegroundColor = NPOI.HSSF.Util.HSSFColor.SkyBlue.Index;
|
||||
HeadercellStyle.FillPattern = FillPattern.SolidForeground;
|
||||
HeadercellStyle.FillBackgroundColor = NPOI.HSSF.Util.HSSFColor.SkyBlue.Index;
|
||||
|
||||
//字体
|
||||
NPOI.SS.UserModel.IFont headerfont = workbook.CreateFont();
|
||||
headerfont.Boldweight = (short)FontBoldWeight.Bold;
|
||||
headerfont.FontHeightInPoints = 12;
|
||||
HeadercellStyle.SetFont(headerfont);
|
||||
|
||||
|
||||
//用column name 作为列名
|
||||
int icolIndex = 0;
|
||||
IRow headerRow = sheet.CreateRow(0);
|
||||
foreach (DataColumn dc in dt.Columns)
|
||||
{
|
||||
ICell cell = headerRow.CreateCell(icolIndex);
|
||||
cell.SetCellValue(dc.ColumnName);
|
||||
cell.CellStyle = HeadercellStyle;
|
||||
icolIndex++;
|
||||
}
|
||||
|
||||
ICellStyle cellStyle = workbook.CreateCellStyle();
|
||||
|
||||
//为避免日期格式被Excel自动替换,所以设定 format 为 『@』 表示一率当成text來看
|
||||
cellStyle.DataFormat = HSSFDataFormat.GetBuiltinFormat("@");
|
||||
cellStyle.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
|
||||
cellStyle.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
|
||||
cellStyle.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
|
||||
cellStyle.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
|
||||
|
||||
|
||||
NPOI.SS.UserModel.IFont cellfont = workbook.CreateFont();
|
||||
cellfont.Boldweight = (short)FontBoldWeight.Normal;
|
||||
cellStyle.SetFont(cellfont);
|
||||
|
||||
//建立内容行
|
||||
int iRowIndex = 0;
|
||||
foreach (DataRow dr in dt.Rows)
|
||||
{
|
||||
int iCellIndex = 0;
|
||||
IRow irow = sheet.CreateRow(iRowIndex + 1);
|
||||
for (int i = 0; i < dt.Columns.Count; i++)
|
||||
{
|
||||
string strsj = string.Empty;
|
||||
if (dr[i] != null)
|
||||
{
|
||||
strsj = dr[i].ToString();
|
||||
}
|
||||
ICell cell = irow.CreateCell(iCellIndex);
|
||||
cell.SetCellValue(strsj);
|
||||
cell.CellStyle = cellStyle;
|
||||
iCellIndex++;
|
||||
}
|
||||
iRowIndex++;
|
||||
}
|
||||
|
||||
//自适应列宽度
|
||||
for (int i = 0; i < icolIndex; i++)
|
||||
{
|
||||
sheet.AutoSizeColumn(i);
|
||||
}
|
||||
|
||||
//using (MemoryStream ms = new MemoryStream())
|
||||
//{
|
||||
// workbook.Write(ms);
|
||||
|
||||
// HttpContext curContext = HttpContext.Current;
|
||||
|
||||
|
||||
// // 设置编码和附件格式
|
||||
// curContext.Response.ContentType = "application/vnd.ms-excel";
|
||||
// curContext.Response.ContentEncoding = Encoding.UTF8;
|
||||
// curContext.Response.Charset = "";
|
||||
// curContext.Response.AppendHeader("Content-Disposition",
|
||||
// "attachment;filename=" + HttpUtility.UrlEncode(Name + "_导出文件_" + DateTime.Now.Ticks + ".xls", Encoding.UTF8));
|
||||
|
||||
// curContext.Response.BinaryWrite(ms.GetBuffer());
|
||||
|
||||
// workbook = null;
|
||||
// ms.Close();
|
||||
// ms.Dispose();
|
||||
|
||||
// curContext.Response.End();
|
||||
//}
|
||||
}
|
||||
return workbook;
|
||||
|
||||
}
|
||||
public DataTable ExcelToTable(Stream stream, int headrow, string suffix)
|
||||
{
|
||||
DataTable dt = new DataTable();
|
||||
|
||||
IWorkbook workbook = null;
|
||||
if (suffix == "xlsx") // 2007版本
|
||||
{
|
||||
workbook = new XSSFWorkbook(stream);
|
||||
}
|
||||
else if (suffix == "xls") // 2003版本
|
||||
{
|
||||
workbook = new HSSFWorkbook(stream);
|
||||
}
|
||||
|
||||
//获取excel的第一个sheet
|
||||
ISheet sheet = workbook.GetSheetAt(0);
|
||||
|
||||
//获取sheet的第一行
|
||||
IRow headerRow = sheet.GetRow(headrow);
|
||||
|
||||
//一行最后一个方格的编号 即总的列数
|
||||
int cellCount = headerRow.LastCellNum;
|
||||
//最后一列的标号 即总的行数
|
||||
int rowCount = sheet.LastRowNum;
|
||||
//列名
|
||||
for (int i = 0; i < cellCount; i++)
|
||||
{
|
||||
dt.Columns.Add(headerRow.GetCell(i).ToString());
|
||||
}
|
||||
|
||||
for (int i = (sheet.FirstRowNum + headrow + 1); i <= sheet.LastRowNum; i++)
|
||||
{
|
||||
DataRow dr = dt.NewRow();
|
||||
|
||||
IRow row = sheet.GetRow(i);
|
||||
for (int j = row.FirstCellNum; j < cellCount; j++)
|
||||
{
|
||||
if (row.GetCell(j) != null)
|
||||
{
|
||||
dr[j] = row.GetCell(j).ToString();
|
||||
}
|
||||
}
|
||||
|
||||
dt.Rows.Add(dr);
|
||||
}
|
||||
|
||||
sheet = null;
|
||||
workbook = null;
|
||||
|
||||
return dt;
|
||||
}
|
||||
|
||||
public static string HttpGet(string Url)
|
||||
{
|
||||
|
||||
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(Url);
|
||||
request.Method = "GET";
|
||||
request.ContentType = "text/html;charset=UTF-8";
|
||||
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
|
||||
Stream myResponseStream = response.GetResponseStream();
|
||||
StreamReader myStreamReader = new StreamReader(myResponseStream, Encoding.GetEncoding("utf-8"));
|
||||
string retString = myStreamReader.ReadToEnd();
|
||||
myStreamReader.Close();
|
||||
myResponseStream.Close();
|
||||
|
||||
return retString;
|
||||
}
|
||||
public static string GetAPIData(string strUrl)
|
||||
{
|
||||
string strReturn = "";
|
||||
string strHost = GetConfig("APITX");
|
||||
strHost = strHost.Substring(0, strHost.IndexOf("/api"));
|
||||
strReturn = CommonHelp.HttpGet(strUrl.Replace("$API_HOST", strHost));
|
||||
return strReturn;
|
||||
}
|
||||
|
||||
private int rep = 0;
|
||||
|
||||
/// <summary>
|
||||
/// 生成随机不重复的字符串(分享码用)
|
||||
/// </summary>
|
||||
/// <param name="codeCount"></param>
|
||||
/// <returns></returns>
|
||||
public string GenerateCheckCode(int codeCount)
|
||||
{
|
||||
string str = string.Empty;
|
||||
long num2 = DateTime.Now.Ticks + this.rep;
|
||||
this.rep++;
|
||||
Random random = new Random(((int)(((ulong)num2) & 0xffffffffL)) | ((int)(num2 >> this.rep)));
|
||||
for (int i = 0; i < codeCount; i++)
|
||||
{
|
||||
char ch;
|
||||
int num = random.Next();
|
||||
if ((num % 2) == 0)
|
||||
{
|
||||
ch = (char)(0x30 + ((ushort)(num % 10)));
|
||||
}
|
||||
else
|
||||
{
|
||||
ch = (char)(0x41 + ((ushort)(num % 0x1a)));
|
||||
}
|
||||
str = str + ch.ToString();
|
||||
}
|
||||
return str;
|
||||
}
|
||||
/// <summary>
|
||||
/// MD5加密
|
||||
/// </summary>
|
||||
/// <param name="content"></param>
|
||||
/// <returns></returns>
|
||||
public static string GetMD5(string content)
|
||||
{
|
||||
using (var md5 = MD5.Create())
|
||||
{
|
||||
var result = md5.ComputeHash(Encoding.ASCII.GetBytes(content));
|
||||
var strResult = BitConverter.ToString(result);
|
||||
return strResult.Replace("-", "");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static string GetConfig(string strKey, string strDefault = "")
|
||||
{
|
||||
return Appsettings.app(strKey) ?? strDefault;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取数字验证码
|
||||
/// </summary>
|
||||
/// <param name="codenum"></param>
|
||||
/// <returns></returns>
|
||||
public static string numcode(int codenum)
|
||||
{
|
||||
string Vchar = "0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9";
|
||||
string[] VcArray = Vchar.Split(',');
|
||||
string[] stray = new string[codenum];
|
||||
Random random = new Random();
|
||||
for (int i = 0; i < codenum; i++)
|
||||
{
|
||||
int iNum = 0;
|
||||
while ((iNum = Convert.ToInt32(VcArray.Length * random.NextDouble())) == VcArray.Length)
|
||||
{
|
||||
iNum = Convert.ToInt32(VcArray.Length * random.NextDouble());
|
||||
}
|
||||
stray[i] = VcArray[iNum];
|
||||
}
|
||||
|
||||
string identifycode = string.Empty;
|
||||
foreach (string s in stray)
|
||||
{
|
||||
identifycode += s;
|
||||
}
|
||||
return identifycode;
|
||||
}
|
||||
/// <summary>
|
||||
/// 登录验证码
|
||||
/// </summary>
|
||||
/// <param name="codenum"></param>
|
||||
/// <returns></returns>
|
||||
public static string yzmcode(int codenum)
|
||||
{
|
||||
string Vchar = "0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,W,X,Y,Z";
|
||||
string[] VcArray = Vchar.Split(',');
|
||||
string[] stray = new string[codenum];
|
||||
Random random = new Random();
|
||||
for (int i = 0; i < codenum; i++)
|
||||
{
|
||||
int iNum = 0;
|
||||
while ((iNum = Convert.ToInt32(VcArray.Length * random.NextDouble())) == VcArray.Length)
|
||||
{
|
||||
iNum = Convert.ToInt32(VcArray.Length * random.NextDouble());
|
||||
}
|
||||
stray[i] = VcArray[iNum];
|
||||
}
|
||||
|
||||
string identifycode = string.Empty;
|
||||
foreach (string s in stray)
|
||||
{
|
||||
identifycode += s;
|
||||
}
|
||||
return identifycode;
|
||||
}
|
||||
|
||||
private static bool IsIPAddress(string str1)
|
||||
{
|
||||
if (str1 == null || str1 == string.Empty || str1.Length < 7 || str1.Length > 15) return false;
|
||||
|
||||
string regformat = @"^\d{1,3}[\.]\d{1,3}[\.]\d{1,3}[\.]\d{1,3}$";
|
||||
|
||||
Regex regex = new Regex(regformat, RegexOptions.IgnoreCase);
|
||||
return regex.IsMatch(str1);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public static void WriteLOG(string err)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
string path = AppContext.BaseDirectory;// .NET CORE
|
||||
//string path = HttpContext.Current.Request.MapPath("/");
|
||||
|
||||
if (!Directory.Exists(path + "/log/"))
|
||||
{
|
||||
Directory.CreateDirectory(path + "/log/");
|
||||
}
|
||||
|
||||
string name = DateTime.Now.ToString("yyyy-MM-dd") + ".txt";
|
||||
if (!File.Exists(path + "/log/" + name))
|
||||
{
|
||||
FileInfo myfile = new FileInfo(path + "/log/" + name);
|
||||
FileStream fs = myfile.Create();
|
||||
fs.Close();
|
||||
}
|
||||
|
||||
StreamWriter sw = File.AppendText(path + "/log/" + name);
|
||||
sw.WriteLine(err + "\r\n" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
|
||||
sw.Flush();
|
||||
sw.Close();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine(ex);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public static bool ProcessSqlStr(string Str, int type)
|
||||
{
|
||||
string SqlStr = "";
|
||||
if (type == 1) //Post方法提交
|
||||
{
|
||||
SqlStr = "script|iframe|xp_loginconfig|xp_fixeddrives|Xp_regremovemultistring|Xp_regread|Xp_regwrite|xp_cmdshell|xp_dirtree|count(|substring(|mid(|master|truncate|char(|declare|replace(|varchar(|cast(";
|
||||
}
|
||||
else if (type == 2) //Get方法提交
|
||||
{
|
||||
SqlStr = "'|script|iframe|xp_loginconfig|xp_fixeddrives|Xp_regremovemultistring|Xp_regread|Xp_regwrite|xp_cmdshell|xp_dirtree|count(|*|asc(|chr(|substring(|mid(|master|truncate|char(|declare|replace(|;|varchar(|cast(";
|
||||
}
|
||||
else if (type == 3) //Cookie提交
|
||||
{
|
||||
SqlStr = "script|iframe|xp_loginconfig|xp_fixeddrives|Xp_regremovemultistring|Xp_regread|Xp_regwrite|xp_cmdshell|xp_dirtree|count(|asc(|chr(|substring(|mid(|master|truncate|char(|declare";
|
||||
}
|
||||
else //默认Post方法提交
|
||||
{
|
||||
SqlStr = "script|iframe|xp_loginconfig|xp_fixeddrives|Xp_regremovemultistring|Xp_regread|Xp_regwrite|xp_cmdshell|xp_dirtree|count(|asc(|chr(|substring(|mid(|master|truncate|char(|declare|replace(";
|
||||
}
|
||||
|
||||
bool ReturnValue = true;
|
||||
try
|
||||
{
|
||||
if (Str != "")
|
||||
{
|
||||
string[] anySqlStr = SqlStr.ToUpper().Split('|'); ;
|
||||
foreach (string ss in anySqlStr)
|
||||
{
|
||||
if (Str.ToUpper().IndexOf(ss) >= 0)
|
||||
{
|
||||
ReturnValue = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
ReturnValue = false;
|
||||
}
|
||||
return ReturnValue;
|
||||
}
|
||||
|
||||
|
||||
public static string Filter(string str)
|
||||
{
|
||||
string[] pattern = { "insert ", "delete", "count\\(", "drop table", "update", "truncate", "xp_cmdshell", "exec master", "netlocalgroup administrators", "net use " };
|
||||
for (int i = 0; i < pattern.Length; i++)
|
||||
{
|
||||
str = str.Replace(pattern[i].ToString(), "");
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public static string CreateqQsql(string strQFiled, string strQtype, string strQvalue)
|
||||
{
|
||||
string strSQL = " AND ";
|
||||
strSQL = strSQL + strQFiled;
|
||||
if (strQtype == "0")
|
||||
{
|
||||
strSQL = strSQL + " = ";
|
||||
|
||||
}
|
||||
strSQL = strSQL + "'" + strQvalue + "'";
|
||||
return strSQL.FilterSpecial();
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 生成流水号格式:8位日期加3位顺序号,如20100302001。
|
||||
/// </summary>
|
||||
public static string GetWFNumber(string serialNumber, string ywcode, string strWFQZ)
|
||||
{
|
||||
if (serialNumber.Length < 13)
|
||||
{
|
||||
strWFQZ = "1";
|
||||
//没法子,只能曲线救国
|
||||
}
|
||||
string strLSTemp = strWFQZ == "0" ? "yyyyMMdd" : "yyyy";
|
||||
if (serialNumber != "0" && serialNumber != "")
|
||||
{
|
||||
string headDate = serialNumber.Substring(ywcode.Length + 1, strLSTemp.Length);
|
||||
int lastNumber = int.Parse(serialNumber.Substring(ywcode.Length + 1 + strLSTemp.Length));
|
||||
//如果数据库最大值流水号中日期和生成日期在同一天,则顺序号加1
|
||||
if (headDate == DateTime.Now.ToString(strLSTemp))
|
||||
{
|
||||
lastNumber++;
|
||||
return ywcode + "-" + headDate + lastNumber.ToString("000");
|
||||
}
|
||||
}
|
||||
return ywcode + "-" + DateTime.Now.ToString(strLSTemp) + "001";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 转化时分秒
|
||||
/// </summary>
|
||||
/// <param name="strSFM"></param>
|
||||
/// <returns></returns>
|
||||
public static int GetSencond(string strSFM)
|
||||
{
|
||||
int[] ListTemp = strSFM.SplitTOInt(':');
|
||||
|
||||
return ListTemp[0] * 3600 + ListTemp[1] * 60 + ListTemp[2];
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 在DataTable末尾添加合计行,最后一个参数设置需要合计的列,Tools.dbDataTableSumRowsWithColList(dt,"车号",new string[]{"个人产值","节油(元)","超油(元)"});
|
||||
/// </summary>
|
||||
/// <param name="dt"></param>
|
||||
/// <param name="nColHeJi">需要显示‘合计’字段的列</param>
|
||||
/// <param name="colsHeJi">需要合计的列</param>
|
||||
public static DataRow dbDataTableSumRowsWithColList(DataTable dt, string sColHeJi, string[] colsHeJi)
|
||||
{
|
||||
DataRow dr = dt.NewRow();
|
||||
dr[sColHeJi] = "合计";
|
||||
dt.Rows.Add(dr);
|
||||
//初始化合计数组
|
||||
decimal[] arrDec = new decimal[colsHeJi.Length];
|
||||
for (int i = 0; i < colsHeJi.Length; i++)
|
||||
{
|
||||
arrDec[i] = decimal.Zero;
|
||||
}
|
||||
//合计
|
||||
for (int i = 0; i < dt.Rows.Count - 1; i++)
|
||||
{
|
||||
for (int j = 0; j < colsHeJi.Length; j++)
|
||||
{
|
||||
string cName = colsHeJi[j];
|
||||
if (Convert.IsDBNull(dt.Rows[i][cName])) continue;
|
||||
arrDec[j] += decimal.Parse(dt.Rows[i][cName] + "");
|
||||
}
|
||||
}
|
||||
//赋值
|
||||
for (int i = 0; i < colsHeJi.Length; i++)
|
||||
{
|
||||
string cName = colsHeJi[i];
|
||||
if (arrDec[i] == decimal.Zero) dr[cName] = "0";
|
||||
else dr[cName] = arrDec[i];
|
||||
}
|
||||
return dr;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 分类小计,并有合计行,
|
||||
/// </summary>
|
||||
/// <param name="dt"></param>
|
||||
/// <param name="nColHeJi">需要显示‘合计’字段的列</param>
|
||||
/// <param name="colsHeJi">需要合计的列</param>
|
||||
public static DataRow dbDataTableSubSumRowsWithColList(DataTable dt, string sColHeJi, string strGroupName, string[] colsHeJi)
|
||||
{
|
||||
DataRow dr = dt.NewRow();
|
||||
dr[sColHeJi] = "合计";
|
||||
dt.Rows.Add(dr);
|
||||
//初始化合计数组
|
||||
decimal[] arrDec = new decimal[colsHeJi.Length];
|
||||
for (int i = 0; i < colsHeJi.Length; i++)
|
||||
{
|
||||
arrDec[i] = decimal.Zero;
|
||||
}
|
||||
//合计
|
||||
for (int i = 0; i < dt.Rows.Count - 1; i++)
|
||||
{
|
||||
for (int j = 0; j < colsHeJi.Length; j++)
|
||||
{
|
||||
string cName = colsHeJi[j];
|
||||
if (Convert.IsDBNull(dt.Rows[i][cName])) continue;
|
||||
arrDec[j] += decimal.Parse(dt.Rows[i][cName] + "");
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < colsHeJi.Length; i++)
|
||||
{
|
||||
string cName = colsHeJi[i];
|
||||
if (arrDec[i] == decimal.Zero) dr[cName] = 0;
|
||||
else dr[cName] = arrDec[i];
|
||||
}
|
||||
if (dt.Rows.Count <= 1) return dr;
|
||||
//小计
|
||||
string sRate = "";
|
||||
int currSubSumCol = dt.Rows.Count - 2;
|
||||
ArrayList ar = new ArrayList();
|
||||
for (int i = dt.Rows.Count - 2; i >= 0; i--)
|
||||
{
|
||||
string currRate = dt.Rows[i][strGroupName] + "";
|
||||
if (sRate != currRate)
|
||||
{
|
||||
if (i != dt.Rows.Count - 2)
|
||||
{
|
||||
dr = dt.NewRow();
|
||||
dr[sColHeJi] = "小计";
|
||||
for (int j = 0; j < colsHeJi.Length; j++)
|
||||
{
|
||||
string cName = colsHeJi[j];
|
||||
if (arrDec[j] == decimal.Zero) dr[cName] = 0;
|
||||
else dr[cName] = arrDec[j];
|
||||
}
|
||||
dt.Rows.InsertAt(dr, currSubSumCol + 1);
|
||||
}
|
||||
currSubSumCol = i;
|
||||
sRate = currRate;
|
||||
for (int j = 0; j < colsHeJi.Length; j++)
|
||||
{ //归零
|
||||
arrDec[j] = decimal.Zero;
|
||||
}
|
||||
}
|
||||
for (int j = 0; j < colsHeJi.Length; j++)
|
||||
{
|
||||
string cName = colsHeJi[j];
|
||||
if (Convert.IsDBNull(dt.Rows[i][cName])) continue;
|
||||
arrDec[j] += decimal.Parse(dt.Rows[i][cName] + "");
|
||||
}
|
||||
if (i == 0)
|
||||
{
|
||||
dr = dt.NewRow();
|
||||
dr[sColHeJi] = "小计";
|
||||
for (int j = 0; j < colsHeJi.Length; j++)
|
||||
{
|
||||
string cName = colsHeJi[j];
|
||||
if (arrDec[j] == decimal.Zero) dr[cName] = 0;
|
||||
else dr[cName] = arrDec[j];
|
||||
}
|
||||
dt.Rows.InsertAt(dr, currSubSumCol + 1);
|
||||
}
|
||||
}
|
||||
|
||||
return dr;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
535
iMES.Bi.API/ExtensionMethods.cs
Normal file
535
iMES.Bi.API/ExtensionMethods.cs
Normal file
@@ -0,0 +1,535 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
|
||||
namespace iMES.Bi.API
|
||||
{
|
||||
public static class MyExtensions
|
||||
{
|
||||
public static int[] SplitTOInt(this string strs, char ch)
|
||||
{
|
||||
string[] arrstr = strs.Split(ch);
|
||||
int[] arrint = new int[arrstr.Length];
|
||||
for (int i = 0; i < arrstr.Length; i++)
|
||||
{
|
||||
arrint[i] = int.Parse(arrstr[i].ToString());
|
||||
}
|
||||
return arrint;
|
||||
}
|
||||
|
||||
public static List<string> SplitTOList(this string strs, char ch)
|
||||
{
|
||||
List<string> Lstr = new List<string>();
|
||||
string[] arrstr = strs.Split(ch);
|
||||
int[] arrint = new int[arrstr.Length];
|
||||
for (int i = 0; i < arrstr.Length; i++)
|
||||
{
|
||||
Lstr.Add(arrstr[i].ToString());
|
||||
}
|
||||
return Lstr;
|
||||
}
|
||||
|
||||
public static Dictionary<string, string> SplitTODictionary(this string strs, char ch, string strKey)
|
||||
{
|
||||
Dictionary<string, string> Lstr = new Dictionary<string, string>();
|
||||
string[] arrstr = strs.Split(ch);
|
||||
int[] arrint = new int[arrstr.Length];
|
||||
for (int i = 0; i < arrstr.Length; i++)
|
||||
{
|
||||
Lstr.Add(arrstr[i].ToString(), strKey);
|
||||
}
|
||||
return Lstr;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 将List转化为String
|
||||
/// </summary>
|
||||
/// <param name="Lists"></param>
|
||||
/// <param name="ch"></param>
|
||||
/// <returns></returns>
|
||||
public static string ListTOString(this List<string> Lists, char ch)
|
||||
{
|
||||
string strReturn = "";
|
||||
foreach (var item in Lists)
|
||||
{
|
||||
strReturn = strReturn + item.ToString() + ch;
|
||||
}
|
||||
return strReturn.TrimEnd(ch);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 将List(int)转化为String
|
||||
/// </summary>
|
||||
/// <param name="Lists"></param>
|
||||
/// <param name="ch"></param>
|
||||
/// <returns></returns>
|
||||
public static string ListTOString(this List<int> Lists, char ch)
|
||||
{
|
||||
string strReturn = "";
|
||||
foreach (var item in Lists)
|
||||
{
|
||||
strReturn = strReturn + item.ToString() + ch;
|
||||
}
|
||||
return strReturn.TrimEnd(ch);
|
||||
}
|
||||
/// <summary>
|
||||
/// 获取需要IN的格式
|
||||
/// </summary>
|
||||
/// <param name="strKys"></param>
|
||||
/// <returns></returns>
|
||||
public static string ToFormatLike(this string strKys)
|
||||
{
|
||||
StringBuilder sbKeys = new StringBuilder();
|
||||
foreach (var item in strKys.Split(','))
|
||||
{
|
||||
sbKeys.AppendFormat("'" + item.ToString() + "',");
|
||||
}
|
||||
return sbKeys.Length > 0 ? sbKeys.ToString().TrimEnd(',').Trim('\'') : "";
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 获取需要IN的格式
|
||||
/// </summary>
|
||||
/// <param name="strKys"></param>
|
||||
/// <returns></returns>
|
||||
public static string ToFormatLike(this string strKys, char ch)
|
||||
{
|
||||
StringBuilder sbKeys = new StringBuilder();
|
||||
foreach (var item in strKys.Split(ch))
|
||||
{
|
||||
sbKeys.AppendFormat("'" + item.ToString() + "',");
|
||||
}
|
||||
return sbKeys.Length > 0 ? sbKeys.ToString().TrimEnd(',').Trim('\'') : "";
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 取前N个字符,后面的用省略号代替
|
||||
/// </summary>
|
||||
/// <param name="strKys"></param>
|
||||
/// <returns></returns>
|
||||
public static string ToMangneStr(this string strKys, int intLenght)
|
||||
{
|
||||
|
||||
return strKys.Length > intLenght ? strKys.Substring(0, intLenght) + "…………" : strKys;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static DataTable ToDataTable<T>(this IEnumerable<T> varlist)
|
||||
{
|
||||
DataTable dtReturn = new DataTable();
|
||||
|
||||
// column names
|
||||
PropertyInfo[] oProps = null;
|
||||
|
||||
if (varlist == null) return dtReturn;
|
||||
|
||||
foreach (T rec in varlist)
|
||||
{
|
||||
if (oProps == null)
|
||||
{
|
||||
oProps = ((Type)rec.GetType()).GetProperties();
|
||||
foreach (PropertyInfo pi in oProps)
|
||||
{
|
||||
Type colType = pi.PropertyType;
|
||||
|
||||
if ((colType.IsGenericType) && (colType.GetGenericTypeDefinition()
|
||||
== typeof(Nullable<>)))
|
||||
{
|
||||
colType = colType.GetGenericArguments()[0];
|
||||
}
|
||||
|
||||
dtReturn.Columns.Add(new DataColumn(pi.Name, colType));
|
||||
}
|
||||
}
|
||||
|
||||
DataRow dr = dtReturn.NewRow();
|
||||
|
||||
foreach (PropertyInfo pi in oProps)
|
||||
{
|
||||
dr[pi.Name] = pi.GetValue(rec, null) == null ? DBNull.Value : pi.GetValue
|
||||
(rec, null);
|
||||
}
|
||||
|
||||
dtReturn.Rows.Add(dr);
|
||||
}
|
||||
return dtReturn;
|
||||
}
|
||||
|
||||
public static DataTable OrderBy(this DataTable dt, string orderBy)
|
||||
{
|
||||
dt.DefaultView.Sort = orderBy;
|
||||
return dt.DefaultView.ToTable();
|
||||
}
|
||||
public static DataTable Where(this DataTable dt, string where)
|
||||
{
|
||||
DataTable resultDt = dt.Clone();
|
||||
DataRow[] resultRows = dt.Select(where);
|
||||
foreach (DataRow dr in resultRows) resultDt.Rows.Add(dr.ItemArray);
|
||||
return resultDt;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Datatable转换为Json
|
||||
/// </summary>
|
||||
/// <param name="table">Datatable对象</param>
|
||||
/// <returns>Json字符串</returns>
|
||||
public static string ToJson(this DataTable dt)
|
||||
{
|
||||
StringBuilder jsonString = new StringBuilder();
|
||||
jsonString.Append("[");
|
||||
DataRowCollection drc = dt.Rows;
|
||||
for (int i = 0; i < drc.Count; i++)
|
||||
{
|
||||
jsonString.Append("{");
|
||||
for (int j = 0; j < dt.Columns.Count; j++)
|
||||
{
|
||||
string strKey = dt.Columns[j].ColumnName;
|
||||
string strValue = drc[i][j].ToString();
|
||||
Type type = dt.Columns[j].DataType;
|
||||
jsonString.Append("\"" + strKey + "\":");
|
||||
strValue = StringFormat(strValue, type);
|
||||
if (j < dt.Columns.Count - 1)
|
||||
{
|
||||
jsonString.Append(strValue + ",");
|
||||
}
|
||||
else
|
||||
{
|
||||
jsonString.Append(strValue);
|
||||
}
|
||||
}
|
||||
jsonString.Append("},");
|
||||
}
|
||||
jsonString.Remove(jsonString.Length - 1, 1);
|
||||
if (jsonString.Length != 0)
|
||||
{
|
||||
jsonString.Append("]");
|
||||
}
|
||||
return jsonString.ToString();
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static int ToInt32(this Object obj)
|
||||
{
|
||||
return Convert.ToInt32(obj);
|
||||
}
|
||||
|
||||
|
||||
public static DateTime ToDateTime(this Object obj)
|
||||
{
|
||||
return Convert.ToDateTime(obj);
|
||||
}
|
||||
|
||||
public static T GetProperty<T>(this object obj, string propertyName)
|
||||
{
|
||||
var property = obj.GetType().GetProperty(propertyName);
|
||||
if (property != null)
|
||||
{
|
||||
return (T)property.GetValue(obj, null);
|
||||
}
|
||||
throw new ArgumentNullException(propertyName);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// DataTable转成Json
|
||||
/// </summary>
|
||||
/// <param name="jsonName"></param>
|
||||
/// <param name="dt"></param>
|
||||
/// <returns></returns>
|
||||
public static string ToJson(this DataTable dt, string jsonName)
|
||||
{
|
||||
StringBuilder Json = new StringBuilder();
|
||||
if (string.IsNullOrEmpty(jsonName))
|
||||
jsonName = dt.TableName;
|
||||
Json.Append("{\"" + jsonName + "\":[");
|
||||
if (dt.Rows.Count > 0)
|
||||
{
|
||||
for (int i = 0; i < dt.Rows.Count; i++)
|
||||
{
|
||||
Json.Append("{");
|
||||
for (int j = 0; j < dt.Columns.Count; j++)
|
||||
{
|
||||
Type type = dt.Rows[i][j].GetType();
|
||||
Json.Append("\"" + dt.Columns[j].ColumnName.ToString() + "\":" + StringFormat(dt.Rows[i][j].ToString(), type));
|
||||
if (j < dt.Columns.Count - 1)
|
||||
{
|
||||
Json.Append(",");
|
||||
}
|
||||
}
|
||||
Json.Append("}");
|
||||
if (i < dt.Rows.Count - 1)
|
||||
{
|
||||
Json.Append(",");
|
||||
}
|
||||
}
|
||||
}
|
||||
Json.Append("]}");
|
||||
return Json.ToString();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 过滤特殊字符
|
||||
/// </summary>
|
||||
/// <param name="s"></param>
|
||||
/// <returns></returns>
|
||||
public static string String2Json(String s)
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i = 0; i < s.Length; i++)
|
||||
{
|
||||
char c = s.ToCharArray()[i];
|
||||
switch (c)
|
||||
{
|
||||
case '\"':
|
||||
sb.Append("\\\""); break;
|
||||
case '\\':
|
||||
sb.Append("\\\\"); break;
|
||||
case '/':
|
||||
sb.Append("\\/"); break;
|
||||
case '\b':
|
||||
sb.Append("\\b"); break;
|
||||
case '\f':
|
||||
sb.Append("\\f"); break;
|
||||
case '\n':
|
||||
sb.Append("\\n"); break;
|
||||
case '\r':
|
||||
sb.Append("\\r"); break;
|
||||
case '\t':
|
||||
sb.Append("\\t"); break;
|
||||
default:
|
||||
sb.Append(c); break;
|
||||
}
|
||||
}
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 格式化字符型、日期型、布尔型
|
||||
/// </summary>
|
||||
/// <param name="str"></param>
|
||||
/// <param name="type"></param>
|
||||
/// <returns></returns>
|
||||
public static string StringFormat(string str, Type type)
|
||||
{
|
||||
if (type == typeof(string))
|
||||
{
|
||||
str = String2Json(str);
|
||||
str = "\"" + str + "\"";
|
||||
}
|
||||
else if (type == typeof(DateTime))
|
||||
{
|
||||
str = "\"" + str + "\"";
|
||||
}
|
||||
else if (type == typeof(Int32))
|
||||
{
|
||||
if (str.Trim() == "")
|
||||
{
|
||||
str = "\"" + str + "\"";
|
||||
}
|
||||
}
|
||||
else if (type == typeof(bool))
|
||||
{
|
||||
str = str.ToLower();
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 过滤特殊字符
|
||||
/// 如果字符串为空,直接返回。
|
||||
/// </summary>
|
||||
/// <param name="str">需要过滤的字符串</param>
|
||||
/// <returns>过滤好的字符串</returns>
|
||||
public static string FilterSpecial(this string str)
|
||||
{
|
||||
if (str == "")
|
||||
{
|
||||
return str;
|
||||
}
|
||||
else
|
||||
{
|
||||
str = str.Replace("'", "");
|
||||
str = str.Replace("<", "");
|
||||
str = str.Replace(">", "");
|
||||
str = str.Replace("%", "");
|
||||
str = str.ToLower().Replace("'delete", "");
|
||||
str = str.ToLower().Replace("'truncate", "");
|
||||
str = str.Replace("''", "");
|
||||
str = str.Replace("\"\"", "");
|
||||
str = str.Replace(",", "");
|
||||
str = str.Replace(".", "");
|
||||
str = str.Replace(">=", "");
|
||||
str = str.Replace("=<", "");
|
||||
str = str.Replace(";", "");
|
||||
str = str.Replace("||", "");
|
||||
str = str.Replace("[", "");
|
||||
str = str.Replace("]", "");
|
||||
str = str.Replace("&", "");
|
||||
str = str.Replace("#", "");
|
||||
str = str.Replace("/", "");
|
||||
str = str.Replace("|", "");
|
||||
str = str.Replace("?", "");
|
||||
str = str.Replace(">?", "");
|
||||
str = str.Replace("?<", "");
|
||||
return str;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删除列
|
||||
/// </summary>
|
||||
/// <param name="dt"></param>
|
||||
/// <param name="sCol">保存的列,其他删除</param>
|
||||
/// <returns></returns>
|
||||
public static DataTable DelTableCol(this DataTable dt, string sCol)
|
||||
{
|
||||
|
||||
if (sCol == "")
|
||||
return dt;
|
||||
string[] sp = sCol.Split(',');
|
||||
string sqldd = "";
|
||||
for (int n = 0; n < sp.Length; n++)
|
||||
{
|
||||
sqldd += sp[n].Split('|')[0] + ',';
|
||||
}
|
||||
for (int i = 0; i < dt.Columns.Count; i++)
|
||||
{
|
||||
if (!sqldd.Split(',').Contains(dt.Columns[i].ColumnName))
|
||||
{
|
||||
dt.Columns.RemoveAt(i);
|
||||
i = i - 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int j = 0; j < sp.Length; j++)
|
||||
{
|
||||
string[] sg = sp[j].Split('|');
|
||||
if (sg.Length > 1 && sg[0] == dt.Columns[i].ColumnName)
|
||||
{
|
||||
dt.Columns[i].ColumnName = sg[1];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return dt;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 根据条件过滤表
|
||||
/// </summary>
|
||||
/// <param name="dt">未过滤之前的表</param>
|
||||
/// <param name="filter">过滤条件</param>
|
||||
/// <returns>返回过滤后的表</returns>
|
||||
public static DataTable FilterTable(this DataTable dt, string filter, string isSJ = "N")
|
||||
{
|
||||
|
||||
DataTable newTable = dt.Clone();
|
||||
DataRow[] drs = dt.Select(filter);
|
||||
foreach (DataRow dr in drs)
|
||||
{
|
||||
newTable.Rows.Add(dr.ItemArray);
|
||||
}
|
||||
|
||||
return newTable;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 随机排序
|
||||
/// </summary>
|
||||
/// <param name="newTable"></param>
|
||||
/// <returns></returns>
|
||||
public static DataTable SJTable(this DataTable newTable)
|
||||
{
|
||||
|
||||
Random ran = new Random();
|
||||
newTable.Columns.Add("sort", typeof(int));
|
||||
for (int i = 0; i < newTable.Rows.Count; i++)
|
||||
{
|
||||
newTable.Rows[i]["sort"] = ran.Next(0, 100);
|
||||
}
|
||||
DataView dv = newTable.DefaultView;
|
||||
dv.Sort = "sort asc";
|
||||
newTable = dv.ToTable();
|
||||
return newTable;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 处理生成的DataTable
|
||||
/// </summary>
|
||||
/// <param name="newTable"></param>
|
||||
/// <param name="addclName">添加的列</param>
|
||||
/// <param name="clNames">需要合并的列</param>
|
||||
/// <returns></returns>
|
||||
public static DataTable AddColum(this DataTable DTTable,string addclName, char strChar,params string[] clNames)
|
||||
{
|
||||
|
||||
DTTable.Columns.Add(addclName);
|
||||
for (int i = 0; i < DTTable.Rows.Count; i++)
|
||||
{
|
||||
string strTemp = "";
|
||||
for (int m = 0; m < clNames.Length; m++)
|
||||
{
|
||||
strTemp = strTemp + DTTable.Rows[i][clNames[m]].ToString() + strChar;
|
||||
}
|
||||
DTTable.Rows[i][addclName] = strTemp.TrimEnd(strChar);
|
||||
|
||||
}
|
||||
|
||||
return DTTable;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// dataTable分页
|
||||
/// </summary>
|
||||
/// <param name="dt"></param>
|
||||
/// <param name="PageIndex"></param>
|
||||
/// <param name="PageSize"></param>
|
||||
/// <returns></returns>
|
||||
public static DataTable SplitDataTable(this DataTable dt, int PageIndex, int PageSize)
|
||||
{
|
||||
if (PageIndex == 0)
|
||||
return dt;
|
||||
DataTable newdt = dt.Clone();
|
||||
//newdt.Clear();
|
||||
int rowbegin = (PageIndex - 1) * PageSize;
|
||||
int rowend = PageIndex * PageSize;
|
||||
|
||||
if (rowbegin >= dt.Rows.Count)
|
||||
return newdt;
|
||||
|
||||
if (rowend > dt.Rows.Count)
|
||||
rowend = dt.Rows.Count;
|
||||
for (int i = rowbegin; i <= rowend - 1; i++)
|
||||
{
|
||||
DataRow newdr = newdt.NewRow();
|
||||
DataRow dr = dt.Rows[i];
|
||||
foreach (DataColumn column in dt.Columns)
|
||||
{
|
||||
newdr[column.ColumnName] = dr[column.ColumnName];
|
||||
}
|
||||
newdt.Rows.Add(newdr);
|
||||
}
|
||||
|
||||
return newdt;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
51
iMES.Bi.API/Msg_Result.cs
Normal file
51
iMES.Bi.API/Msg_Result.cs
Normal file
@@ -0,0 +1,51 @@
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace iMES.Bi.API
|
||||
{
|
||||
/// <summary>
|
||||
/// 返回消息类
|
||||
/// </summary>
|
||||
public class Msg_Result
|
||||
{
|
||||
[JsonProperty("Action")]
|
||||
public string Action { get; set; }
|
||||
|
||||
[JsonProperty("ErrorMsg")]
|
||||
public string ErrorMsg { get; set; }
|
||||
public int DataLength { get; set; }
|
||||
public string ResultType { get; set; }
|
||||
|
||||
[JsonProperty("Result")]
|
||||
public dynamic Result { get; set; }
|
||||
|
||||
|
||||
[JsonProperty("Result1")]
|
||||
public dynamic Result1 { get; set; }
|
||||
|
||||
|
||||
[JsonProperty("Result2")]
|
||||
public dynamic Result2 { get; set; }
|
||||
|
||||
|
||||
[JsonProperty("Result3")]
|
||||
public dynamic Result3 { get; set; }
|
||||
|
||||
[JsonProperty("Result4")]
|
||||
public dynamic Result4 { get; set; }
|
||||
|
||||
|
||||
[JsonProperty("Result5")]
|
||||
public dynamic Result5 { get; set; }
|
||||
|
||||
|
||||
[JsonProperty("Result6")]
|
||||
public dynamic Result6 { get; set; }
|
||||
|
||||
[JsonProperty("uptoken")]
|
||||
public dynamic uptoken { get; set; }
|
||||
}
|
||||
}
|
||||
25
iMES.Bi.API/iMES.Bi.API.csproj
Normal file
25
iMES.Bi.API/iMES.Bi.API.csproj
Normal file
@@ -0,0 +1,25 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Remove="API\Class1.cs" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Aspose.Words" Version="18.7.0" />
|
||||
<PackageReference Include="DotNetCore.NPOI" Version="1.2.1" />
|
||||
<PackageReference Include="Senparc.Weixin" Version="6.7.401" />
|
||||
<PackageReference Include="Senparc.Weixin.MP" Version="16.10.401" />
|
||||
<PackageReference Include="Senparc.Weixin.Work" Version="3.3.5" />
|
||||
<PackageReference Include="Senparc.Weixin.WxOpen" Version="3.8.401" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\iMES.Bi.Data\iMES.Bi.Data.csproj" />
|
||||
<ProjectReference Include="..\iMES.Core\iMES.Core.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
Reference in New Issue
Block a user