chore: 初始化东安动力外部数据接口工程
This commit is contained in:
46
SlMesDbIterface/MessageHanlder/ApiTools.cs
Normal file
46
SlMesDbIterface/MessageHanlder/ApiTools.cs
Normal file
@@ -0,0 +1,46 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Web.Http;
|
||||
using System.Net.Http;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace WebApi
|
||||
{
|
||||
public enum ResponseCode
|
||||
{
|
||||
Fail = 00000,
|
||||
Success = 00200,
|
||||
}
|
||||
|
||||
public class ApiTools
|
||||
{
|
||||
private string msgModel = "{{\"code\":{0},\"message\":\"{1}\",\"result\":{2}}}";
|
||||
public ApiTools()
|
||||
{
|
||||
}
|
||||
public HttpResponseMessage MsgFormat(ResponseCode code, string explanation, string result)
|
||||
{
|
||||
string r = @"^(\-|\+)?\d+(\.\d+)?$";
|
||||
string json = string.Empty;
|
||||
if (Regex.IsMatch(result, r) || result.ToLower() == "true" || result.ToLower() == "false" || result == "[]" || result.Contains('{'))
|
||||
{
|
||||
json = string.Format(msgModel, (int)code, explanation, result);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (result.Contains('"'))
|
||||
{
|
||||
json = string.Format(msgModel, (int)code, explanation, result);
|
||||
}
|
||||
else
|
||||
{
|
||||
json = string.Format(msgModel, (int)code, explanation, "\"" + result + "\"");
|
||||
}
|
||||
}
|
||||
return new HttpResponseMessage { Content = new StringContent(json, System.Text.Encoding.UTF8, "application/json") };
|
||||
}
|
||||
}
|
||||
}
|
||||
148
SlMesDbIterface/MessageHanlder/CallWebApi.cs
Normal file
148
SlMesDbIterface/MessageHanlder/CallWebApi.cs
Normal file
@@ -0,0 +1,148 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SlMesDbIterface
|
||||
{
|
||||
public partial class MyHttpRequest {
|
||||
|
||||
public static string MyPost(string url,string jsonStr)
|
||||
{
|
||||
string result = "";
|
||||
|
||||
try
|
||||
{
|
||||
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
|
||||
req.Method = "POST";
|
||||
req.ContentType = "text/html, application/xhtml+xml, application/json, */*";
|
||||
req.Proxy = null;
|
||||
req.KeepAlive = false;
|
||||
|
||||
byte[] data = Encoding.UTF8.GetBytes(jsonStr);
|
||||
req.ContentLength = data.Length;
|
||||
using (Stream reqStream = req.GetRequestStream())
|
||||
{
|
||||
reqStream.Write(data, 0, data.Length);
|
||||
reqStream.Close();
|
||||
}
|
||||
|
||||
HttpWebResponse resp = (HttpWebResponse)req.GetResponse();
|
||||
Stream stream = resp.GetResponseStream();
|
||||
|
||||
|
||||
//获取响应内容
|
||||
using (StreamReader reader = new StreamReader(stream, Encoding.UTF8))
|
||||
{
|
||||
result = reader.ReadToEnd();
|
||||
}
|
||||
Console.WriteLine(result);
|
||||
|
||||
|
||||
}
|
||||
catch (Exception err)
|
||||
{
|
||||
Console.WriteLine("<Error> " + err.Message);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public static string MyPost(string url,Dictionary<string,string> paramDict, string jsonStr)
|
||||
{
|
||||
string result = "";
|
||||
|
||||
try
|
||||
{
|
||||
StringBuilder builder = new StringBuilder();
|
||||
|
||||
builder.Append(url);
|
||||
if (paramDict.Count > 0)
|
||||
{
|
||||
builder.Append("?");
|
||||
int i = 0;
|
||||
foreach (var item in paramDict)
|
||||
{
|
||||
if (i > 0)
|
||||
builder.Append("&");
|
||||
builder.AppendFormat("{0}={1}", item.Key, item.Value);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(builder.ToString());
|
||||
req.Method = "POST";
|
||||
req.ContentType = "text/html, application/xhtml+xml, application/json, */*";
|
||||
req.Proxy = null;
|
||||
req.KeepAlive = false;
|
||||
|
||||
byte[] data = Encoding.UTF8.GetBytes(jsonStr);
|
||||
req.ContentLength = data.Length;
|
||||
using (Stream reqStream = req.GetRequestStream())
|
||||
{
|
||||
reqStream.Write(data, 0, data.Length);
|
||||
reqStream.Close();
|
||||
}
|
||||
|
||||
HttpWebResponse resp = (HttpWebResponse)req.GetResponse();
|
||||
Stream stream = resp.GetResponseStream();
|
||||
|
||||
|
||||
//获取响应内容
|
||||
using (StreamReader reader = new StreamReader(stream, Encoding.UTF8))
|
||||
{
|
||||
result = reader.ReadToEnd();
|
||||
}
|
||||
Console.WriteLine(result);
|
||||
|
||||
|
||||
}
|
||||
catch (Exception err)
|
||||
{
|
||||
Console.WriteLine("<Error> " + err.Message);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public static string MyGet(string url, Dictionary<string,string> paramDict)
|
||||
{
|
||||
string result = "";
|
||||
|
||||
StringBuilder builder = new StringBuilder();
|
||||
|
||||
builder.Append(url);
|
||||
if (paramDict.Count > 0)
|
||||
{
|
||||
builder.Append("?");
|
||||
int i = 0;
|
||||
foreach (var item in paramDict)
|
||||
{
|
||||
if (i > 0)
|
||||
builder.Append("&");
|
||||
builder.AppendFormat("{0}={1}", item.Key, item.Value);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(builder.ToString());
|
||||
req.Method = "GET";
|
||||
req.ContentType = "text/html, application/xhtml+xml, application/json, */*";
|
||||
req.Proxy = null;
|
||||
req.KeepAlive = false;
|
||||
|
||||
HttpWebResponse response = (HttpWebResponse)req.GetResponse();
|
||||
Stream rs = response.GetResponseStream();
|
||||
StreamReader sr = new StreamReader(rs, Encoding.UTF8);
|
||||
result = sr.ReadToEnd();
|
||||
sr.Close();
|
||||
rs.Close();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
313
SlMesDbIterface/MessageHanlder/DeviceTools.cs
Normal file
313
SlMesDbIterface/MessageHanlder/DeviceTools.cs
Normal file
@@ -0,0 +1,313 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Data.SqlClient;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using TECSharpFunction;
|
||||
|
||||
namespace SlMesDbIterface
|
||||
{
|
||||
public class DeviceTools
|
||||
{
|
||||
public static void GetToolExcel(string FtpServer, string FtpUser,string FtpPassWord, string FtpFileList)
|
||||
{
|
||||
FTPHelper ftpClient = new FTPHelper(FtpServer, @"", FtpUser, FtpPassWord);
|
||||
//ListType=1代表获取文件列表,ListType=2代表获取文件夹列表,ListType=3代表获取文件和文件夹列表。
|
||||
//Detail=true时获文件或文件夹详细信息,Detail=false时只获取文件或文件夹名称。
|
||||
//Keyword是只需list名称包含Keyword的文件或文件夹,若要list所有文件或文件夹,则该参数为空。若ListType=3,则该参数无效。
|
||||
|
||||
int ListType = 1;
|
||||
bool Detail = false;
|
||||
string Keyword = "";
|
||||
|
||||
var fileList = ftpClient.GetFileDirctoryList(ListType, Detail, Keyword);
|
||||
|
||||
foreach (string itemFileName in fileList)
|
||||
{
|
||||
string tableName = itemFileName.Substring(0, itemFileName.LastIndexOf("."));
|
||||
if (FtpFileList.Contains(itemFileName))
|
||||
{
|
||||
ftpClient.Download(itemFileName, itemFileName, null);
|
||||
ExcelToDataTable(itemFileName, tableName);
|
||||
}
|
||||
else
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void ExcelToDataTable(string excelPath, string tableName)
|
||||
{
|
||||
////判断是否包含当前日期的记录
|
||||
//int excelSheetindex = 0;
|
||||
//var dt = NPOITest.ExeclHelper.ExcelToDataTable(excelPath, excelSheetindex, true);
|
||||
//switch (tableName)
|
||||
//{
|
||||
// case "刀具柜-库存明细":
|
||||
// {
|
||||
// string str1 = "delete from[刀具柜-库存明细] where[导入日期] = '" + DateTime.Now.ToShortDateString() + "'";
|
||||
// DataLinkMesWork.SQLCommon.ExecuteSql(str1, Program.ConnectionString_MES, out string errorMessage1);
|
||||
// var dt_DB = GetToolDetail(dt);
|
||||
// SqlBulkCopyByDatatable(Program.ConnectionString_MES, tableName, dt_DB);
|
||||
// }
|
||||
// break;
|
||||
// case "刀具领用记录":
|
||||
// {
|
||||
// string str2 = "delete from[刀具领用记录] where[导入日期] = '" + DateTime.Now.ToShortDateString() + "'";
|
||||
// DataLinkMesWork.SQLCommon.ExecuteSql(str2, Program.ConnectionString_MES, out string errorMessage2);
|
||||
// var dt_DB = GetToolRecoder(dt);
|
||||
// SqlBulkCopyByDatatable(Program.ConnectionString_MES, tableName, dt_DB);
|
||||
// }
|
||||
// break;
|
||||
//}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 刀具领用记录
|
||||
/// </summary>
|
||||
private static DataTable GetToolRecoder(DataTable dtData)
|
||||
{
|
||||
//刀具领用记录.xls
|
||||
|
||||
DataTable dt = new DataTable();
|
||||
dt.Columns.Add("物料名称", typeof(System.String));
|
||||
dt.Columns.Add("物料编号", typeof(System.String));
|
||||
dt.Columns.Add("物料型号", typeof(System.String));
|
||||
dt.Columns.Add("供应商", typeof(System.String));//品牌(供应商)
|
||||
dt.Columns.Add("领取来源", typeof(System.String));
|
||||
dt.Columns.Add("领取数量", typeof(System.Int32));
|
||||
dt.Columns.Add("实领数量", typeof(System.Int32));
|
||||
dt.Columns.Add("领取单位", typeof(System.String));
|
||||
dt.Columns.Add("包装数量", typeof(System.Int32));
|
||||
dt.Columns.Add("包装单位", typeof(System.String));
|
||||
dt.Columns.Add("领用类型", typeof(System.String));
|
||||
dt.Columns.Add("单价", typeof(System.Double));//单价(元)
|
||||
dt.Columns.Add("金额", typeof(System.Double));
|
||||
dt.Columns.Add("部门", typeof(System.String));
|
||||
dt.Columns.Add("领用人员", typeof(System.String));
|
||||
dt.Columns.Add("已归还数量", typeof(System.Int32));
|
||||
dt.Columns.Add("是否归还", typeof(System.String));
|
||||
dt.Columns.Add("领用时间", typeof(System.DateTime));
|
||||
DataRow dr = dt.NewRow();
|
||||
for (int i = 0; i < dtData.Rows.Count; i++)
|
||||
{
|
||||
dr = dt.NewRow();
|
||||
var 物料名称 = dtData.Rows[i][0].ToString();
|
||||
if (物料名称 == "合计")
|
||||
{
|
||||
continue;
|
||||
}
|
||||
dr["物料名称"] = 物料名称;
|
||||
dr["物料编号"] = dtData.Rows[i][1].ToString();
|
||||
dr["物料型号"] = dtData.Rows[i][2].ToString();
|
||||
dr["供应商"] = dtData.Rows[i][3].ToString();
|
||||
dr["领取来源"] = dtData.Rows[i][4].ToString();
|
||||
try
|
||||
{
|
||||
dr["领取数量"] = Convert.ToInt32(dtData.Rows[i][5]);
|
||||
}
|
||||
catch
|
||||
{
|
||||
dr["领取数量"] = 0;
|
||||
}
|
||||
try
|
||||
{
|
||||
dr["实领数量"] = Convert.ToInt32(dtData.Rows[i][6]);
|
||||
}
|
||||
catch
|
||||
{
|
||||
dr["实领数量"] = 0;
|
||||
}
|
||||
dr["领取单位"] = dtData.Rows[i][7].ToString();
|
||||
try
|
||||
{
|
||||
dr["包装数量"] = Convert.ToInt32(dtData.Rows[i][8]);
|
||||
}
|
||||
catch
|
||||
{
|
||||
dr["包装数量"] = 0;
|
||||
}
|
||||
|
||||
|
||||
dr["包装单位"] = dtData.Rows[i][9].ToString();
|
||||
dr["领用类型"] = dtData.Rows[i][10].ToString();
|
||||
try
|
||||
{
|
||||
dr["单价"] = Convert.ToDouble(dtData.Rows[i][11]);
|
||||
}
|
||||
catch
|
||||
{
|
||||
dr["单价"] = 0;
|
||||
}
|
||||
try
|
||||
{
|
||||
dr["金额"] = Convert.ToDouble(dtData.Rows[i][12]);
|
||||
}
|
||||
catch
|
||||
{
|
||||
dr["金额"] = 0;
|
||||
}
|
||||
dr["部门"] = dtData.Rows[i][13].ToString();
|
||||
dr["领用人员"] = dtData.Rows[i][14].ToString();
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
dr["已归还数量"] = Convert.ToInt32(dtData.Rows[i][15]);
|
||||
}
|
||||
catch
|
||||
{
|
||||
dr["已归还数量"] = 0;
|
||||
}
|
||||
dr["是否归还"] = dtData.Rows[i][16].ToString();
|
||||
try
|
||||
{
|
||||
dr["领用时间"] = Convert.ToDateTime(dtData.Rows[i][17]);
|
||||
// dr["领用时间"] = dtData.Rows[i][17].ToString();
|
||||
}
|
||||
catch
|
||||
{
|
||||
dr["领用时间"] = DBNull.Value;
|
||||
}
|
||||
|
||||
dt.Rows.Add(dr);
|
||||
}
|
||||
|
||||
|
||||
return dt;
|
||||
|
||||
}
|
||||
/// <summary>
|
||||
/// 刀具柜-库存明细
|
||||
/// </summary>
|
||||
private static DataTable GetToolDetail(DataTable dtData)
|
||||
{
|
||||
//刀具柜 - 库存明细.xls
|
||||
|
||||
DataTable dt = new DataTable();
|
||||
dt.Columns.Add("刀具柜名称", typeof(System.String));
|
||||
dt.Columns.Add("行号", typeof(System.Int32));
|
||||
dt.Columns.Add("列号", typeof(System.Int32));
|
||||
dt.Columns.Add("物料名称", typeof(System.String));
|
||||
dt.Columns.Add("物料编号", typeof(System.String));
|
||||
dt.Columns.Add("物料型号", typeof(System.String));
|
||||
dt.Columns.Add("当前数量", typeof(System.Double));
|
||||
dt.Columns.Add("包装单位", typeof(System.String));
|
||||
dt.Columns.Add("单价", typeof(System.Double));
|
||||
dt.Columns.Add("金额", typeof(System.Double));
|
||||
dt.Columns.Add("最大存储", typeof(System.Int32));
|
||||
dt.Columns.Add("警告阀值", typeof(System.Int32));
|
||||
dt.Columns.Add("最后上架时间", typeof(System.DateTime));
|
||||
DataRow dr = dt.NewRow();
|
||||
for (int i = 0; i < dtData.Rows.Count; i++)
|
||||
{
|
||||
dr = dt.NewRow();
|
||||
dr["刀具柜名称"] = dtData.Rows[i]["刀具柜名称"].ToString();
|
||||
try
|
||||
{
|
||||
dr["行号"] = Convert.ToInt32(dtData.Rows[i]["行号"]);
|
||||
}
|
||||
catch
|
||||
{
|
||||
dr["行号"] = 0;
|
||||
}
|
||||
try
|
||||
{
|
||||
dr["列号"] = Convert.ToInt32(dtData.Rows[i]["列号"]);
|
||||
}
|
||||
catch
|
||||
{
|
||||
dr["列号"] = 0;
|
||||
}
|
||||
dr["物料名称"] = dtData.Rows[i]["物料名称"].ToString();
|
||||
dr["物料编号"] = dtData.Rows[i]["物料编号"].ToString();
|
||||
dr["物料型号"] = dtData.Rows[i]["物料型号"].ToString();
|
||||
try
|
||||
{
|
||||
dr["当前数量"] = Convert.ToDouble(dtData.Rows[i]["当前数量"]);
|
||||
}
|
||||
catch
|
||||
{
|
||||
dr["当前数量"] = 0;
|
||||
}
|
||||
dr["包装单位"] = dtData.Rows[i]["包装单位"].ToString();
|
||||
try
|
||||
{
|
||||
dr["单价"] = Convert.ToDouble(dtData.Rows[i]["单价"]);
|
||||
}
|
||||
catch
|
||||
{
|
||||
dr["单价"] = 0;
|
||||
}
|
||||
try
|
||||
{
|
||||
dr["金额"] = Convert.ToDouble(dtData.Rows[i]["金额"]);
|
||||
}
|
||||
catch
|
||||
{
|
||||
dr["金额"] = 0;
|
||||
}
|
||||
try
|
||||
{
|
||||
dr["最大存储"] = Convert.ToDouble(dtData.Rows[i]["最大存储"]);
|
||||
}
|
||||
catch
|
||||
{
|
||||
dr["最大存储"] = 0;
|
||||
}
|
||||
try
|
||||
{
|
||||
dr["警告阀值"] = Convert.ToDouble(dtData.Rows[i]["警告阀值"]);
|
||||
}
|
||||
catch
|
||||
{
|
||||
dr["警告阀值"] = 0;
|
||||
}
|
||||
try
|
||||
{
|
||||
dr["最后上架时间"] = Convert.ToDateTime(dtData.Rows[i]["最后上架时间"]);
|
||||
}
|
||||
catch
|
||||
{
|
||||
dr["警告阀值"] = DBNull.Value;
|
||||
}
|
||||
dt.Rows.Add(dr);
|
||||
}
|
||||
|
||||
|
||||
return dt;
|
||||
|
||||
}
|
||||
|
||||
static void SqlBulkCopyByDatatable(string connectionString, string TableName, DataTable dt)
|
||||
{
|
||||
using (SqlConnection conn = new SqlConnection(connectionString))
|
||||
{
|
||||
using (SqlBulkCopy sqlbulkcopy =
|
||||
new SqlBulkCopy(connectionString, SqlBulkCopyOptions.UseInternalTransaction))
|
||||
{
|
||||
try
|
||||
{
|
||||
sqlbulkcopy.DestinationTableName = "[" + TableName + "]";
|
||||
dt.TableName = TableName;
|
||||
for (int i = 0; i < dt.Columns.Count; i++)
|
||||
{
|
||||
sqlbulkcopy.ColumnMappings.Add(dt.Columns[i].ColumnName.Trim(), "[" + dt.Columns[i].ColumnName + "]");
|
||||
}
|
||||
sqlbulkcopy.WriteToServer(dt);
|
||||
}
|
||||
catch (System.Exception ex)
|
||||
{
|
||||
//throw ex;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
332
SlMesDbIterface/MessageHanlder/FTPHelper.cs
Normal file
332
SlMesDbIterface/MessageHanlder/FTPHelper.cs
Normal file
@@ -0,0 +1,332 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
using System.Collections.Generic;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace TECSharpFunction
|
||||
{
|
||||
/// <summary>
|
||||
/// FTP操作
|
||||
/// </summary>
|
||||
public class FTPHelper
|
||||
{
|
||||
#region FTPConfig
|
||||
string ftpURI;
|
||||
string ftpUserID;
|
||||
string ftpServerIP;
|
||||
string ftpPassword;
|
||||
string ftpRemotePath;
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// 连接FTP服务器
|
||||
/// </summary>
|
||||
/// <param name="FtpServerIP">FTP连接地址</param>
|
||||
/// <param name="FtpRemotePath">指定FTP连接成功后的当前目录, 如果不指定即默认为根目录</param>
|
||||
/// <param name="FtpUserID">用户名</param>
|
||||
/// <param name="FtpPassword">密码</param>
|
||||
public FTPHelper(string FtpServerIP, string FtpRemotePath, string FtpUserID, string FtpPassword)
|
||||
{
|
||||
ftpServerIP = FtpServerIP;
|
||||
ftpRemotePath = FtpRemotePath;
|
||||
ftpUserID = FtpUserID;
|
||||
ftpPassword = FtpPassword;
|
||||
ftpURI = "ftp://" + ftpServerIP + "/" + ftpRemotePath + "/";
|
||||
}
|
||||
|
||||
public bool CheckFtp()
|
||||
{
|
||||
try
|
||||
{
|
||||
FtpWebRequest ftprequest = (FtpWebRequest)FtpWebRequest.Create(new Uri(ftpURI));
|
||||
// ftp用户名和密码
|
||||
ftprequest.Credentials = new NetworkCredential(ftpUserID, ftpPassword);
|
||||
ftprequest.Method = WebRequestMethods.Ftp.ListDirectory;
|
||||
ftprequest.Timeout = 3000;
|
||||
FtpWebResponse ftpResponse = (FtpWebResponse)ftprequest.GetResponse();
|
||||
|
||||
ftpResponse.Close();
|
||||
return true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
// 参数localfile为要上传的本地文件,ftpfile为上传到FTP的文件名称,ProgressBar为显示上传进度的滚动条,适用于WinForm。若应用于控制台程序,只要重写该函数,将参数ProgressBar去掉即可,同时将函数实现里所有涉及ProgressBar的地方都删掉。
|
||||
//————————————————
|
||||
//版权声明:本文为CSDN博主「只会搬运的小菜鸟」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
|
||||
//原文链接:https://blog.csdn.net/u011465910/article/details/126563124
|
||||
public void Upload(string localfile, string ftpfile, System.Windows.Forms.ProgressBar pb)
|
||||
{
|
||||
FileInfo fileInf = new FileInfo(localfile);
|
||||
FtpWebRequest reqFTP;
|
||||
reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri(ftpURI + ftpfile));
|
||||
reqFTP.Credentials = new NetworkCredential(ftpUserID, ftpPassword);
|
||||
reqFTP.Method = WebRequestMethods.Ftp.UploadFile;
|
||||
reqFTP.KeepAlive = false;
|
||||
reqFTP.UseBinary = true;
|
||||
reqFTP.ContentLength = fileInf.Length;
|
||||
if (pb != null)
|
||||
{
|
||||
pb.Maximum = Convert.ToInt32(reqFTP.ContentLength / 2048);
|
||||
pb.Maximum = pb.Maximum + 1;
|
||||
pb.Minimum = 0;
|
||||
pb.Value = 0;
|
||||
}
|
||||
int buffLength = 2048;
|
||||
byte[] buff = new byte[buffLength];
|
||||
int contentLen;
|
||||
FileStream fs = fileInf.OpenRead();
|
||||
try
|
||||
{
|
||||
Stream strm = reqFTP.GetRequestStream();
|
||||
contentLen = fs.Read(buff, 0, buffLength);
|
||||
while (contentLen != 0)
|
||||
{
|
||||
strm.Write(buff, 0, contentLen);
|
||||
if (pb != null)
|
||||
{
|
||||
if (pb.Value != pb.Maximum)
|
||||
pb.Value = pb.Value + 1;
|
||||
}
|
||||
contentLen = fs.Read(buff, 0, buffLength);
|
||||
System.Windows.Forms.Application.DoEvents();
|
||||
}
|
||||
if (pb != null)
|
||||
pb.Value = pb.Maximum;
|
||||
System.Windows.Forms.Application.DoEvents();
|
||||
strm.Close();
|
||||
fs.Close();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new Exception(ex.Message);
|
||||
}
|
||||
}
|
||||
//参数localfilename为将下载到本地的文件名称,ftpfilename为要下载的FTP上文件名称,
|
||||
// ProcessBar为用于显示下载进度的进度条。该函数用于WinForm,若用于控制台,只要重写该函数,删除所有涉及ProcessBar的代码即可。
|
||||
public void Download(string localfilename, string ftpfileName, System.Windows.Forms.ProgressBar pb)
|
||||
{
|
||||
long fileSize = GetFileSize(ftpfileName);
|
||||
if (fileSize > 0)
|
||||
{
|
||||
if (pb != null)
|
||||
{
|
||||
pb.Maximum = Convert.ToInt32(fileSize / 2048);
|
||||
pb.Maximum = pb.Maximum + 1;
|
||||
pb.Minimum = 0;
|
||||
pb.Value = 0;
|
||||
}
|
||||
try
|
||||
{
|
||||
FileStream outputStream = new FileStream(localfilename, FileMode.Create);
|
||||
FtpWebRequest reqFTP;
|
||||
reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri(ftpURI + ftpfileName));
|
||||
reqFTP.Credentials = new NetworkCredential(ftpUserID, ftpPassword);
|
||||
reqFTP.Method = WebRequestMethods.Ftp.DownloadFile;
|
||||
reqFTP.UseBinary = true;
|
||||
FtpWebResponse response = (FtpWebResponse)reqFTP.GetResponse();
|
||||
Stream ftpStream = response.GetResponseStream();
|
||||
int bufferSize = 2048;
|
||||
|
||||
int readCount;
|
||||
byte[] buffer = new byte[bufferSize];
|
||||
readCount = ftpStream.Read(buffer, 0, bufferSize);
|
||||
while (readCount > 0)
|
||||
{
|
||||
outputStream.Write(buffer, 0, readCount);
|
||||
if (pb != null)
|
||||
{
|
||||
if (pb.Value != pb.Maximum)
|
||||
pb.Value = pb.Value + 1;
|
||||
}
|
||||
readCount = ftpStream.Read(buffer, 0, bufferSize);
|
||||
System.Windows.Forms.Application.DoEvents();
|
||||
}
|
||||
if (pb != null)
|
||||
pb.Value = pb.Maximum;
|
||||
System.Windows.Forms.Application.DoEvents();
|
||||
ftpStream.Close();
|
||||
outputStream.Close();
|
||||
response.Close();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
File.Delete(localfilename);
|
||||
//throw new Exception(ex.Message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void Delete(string fileName)
|
||||
{
|
||||
try
|
||||
{
|
||||
FtpWebRequest reqFTP;
|
||||
reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri(ftpURI + fileName));
|
||||
reqFTP.Credentials = new NetworkCredential(ftpUserID, ftpPassword);
|
||||
reqFTP.Method = WebRequestMethods.Ftp.DeleteFile;
|
||||
reqFTP.KeepAlive = false;
|
||||
string result = String.Empty;
|
||||
FtpWebResponse response = (FtpWebResponse)reqFTP.GetResponse();
|
||||
long size = response.ContentLength;
|
||||
Stream datastream = response.GetResponseStream();
|
||||
StreamReader sr = new StreamReader(datastream);
|
||||
result = sr.ReadToEnd();
|
||||
sr.Close();
|
||||
datastream.Close();
|
||||
response.Close();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new Exception(ex.Message);
|
||||
}
|
||||
}
|
||||
//ListType=1代表获取文件列表,ListType=2代表获取文件夹列表,ListType=3代表获取文件和文件夹列表。
|
||||
//Detail=true时获文件或文件夹详细信息,Detail=false时只获取文件或文件夹名称。
|
||||
//Keyword是只需list名称包含Keyword的文件或文件夹,若要list所有文件或文件夹,则该参数为空。若ListType=3,则该参数无效。
|
||||
//————————————————
|
||||
//版权声明:本文为CSDN博主「只会搬运的小菜鸟」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
|
||||
public List<string> GetFileDirctoryList(int ListType, bool Detail, string Keyword)
|
||||
{
|
||||
List<string> strs = new List<string>();
|
||||
try
|
||||
{
|
||||
FtpWebRequest reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri(ftpURI));
|
||||
// ftp用户名和密码
|
||||
reqFTP.Credentials = new NetworkCredential(ftpUserID, ftpPassword);
|
||||
if (Detail)
|
||||
reqFTP.Method = WebRequestMethods.Ftp.ListDirectoryDetails;
|
||||
else
|
||||
reqFTP.Method = WebRequestMethods.Ftp.ListDirectory;
|
||||
WebResponse response = reqFTP.GetResponse();
|
||||
|
||||
|
||||
StreamReader reader = new StreamReader(response.GetResponseStream(), System.Text.Encoding.Default);//中文文件名
|
||||
string line = reader.ReadLine();
|
||||
while (line != null)
|
||||
{
|
||||
if (ListType == 1)
|
||||
{
|
||||
if (line.Contains("."))
|
||||
{
|
||||
if (Keyword.Trim() == "*.*" || Keyword.Trim() == "")
|
||||
{
|
||||
strs.Add(line);
|
||||
}
|
||||
else if (line.IndexOf(Keyword.Trim()) > -1)
|
||||
{
|
||||
strs.Add(line);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (ListType == 2)
|
||||
{
|
||||
if (!line.Contains("."))
|
||||
{
|
||||
if (Keyword.Trim() == "*" || Keyword.Trim() == "")
|
||||
{
|
||||
strs.Add(line);
|
||||
}
|
||||
else if (line.IndexOf(Keyword.Trim()) > -1)
|
||||
{
|
||||
strs.Add(line);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (ListType == 3)
|
||||
{
|
||||
strs.Add(line);
|
||||
}
|
||||
line = reader.ReadLine();
|
||||
}
|
||||
reader.Close();
|
||||
response.Close();
|
||||
return strs;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new Exception(ex.Message);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
public void MakeDir(string dirName)
|
||||
{
|
||||
FtpWebRequest reqFTP;
|
||||
try
|
||||
{
|
||||
reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri(ftpURI + dirName));
|
||||
reqFTP.Method = WebRequestMethods.Ftp.MakeDirectory;
|
||||
reqFTP.UseBinary = true;
|
||||
reqFTP.Credentials = new NetworkCredential(ftpUserID, ftpPassword);
|
||||
FtpWebResponse response = (FtpWebResponse)reqFTP.GetResponse();
|
||||
Stream ftpStream = response.GetResponseStream();
|
||||
ftpStream.Close();
|
||||
response.Close();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new Exception(ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
public long GetFileSize(string ftpfileName)
|
||||
{
|
||||
long fileSize = 0;
|
||||
try
|
||||
{
|
||||
FtpWebRequest reqFTP;
|
||||
reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri(ftpURI + ftpfileName));
|
||||
reqFTP.Credentials = new NetworkCredential(ftpUserID, ftpPassword);
|
||||
reqFTP.Method = WebRequestMethods.Ftp.GetFileSize;
|
||||
reqFTP.UseBinary = true;
|
||||
FtpWebResponse response = (FtpWebResponse)reqFTP.GetResponse();
|
||||
Stream ftpStream = response.GetResponseStream();
|
||||
fileSize = response.ContentLength;
|
||||
ftpStream.Close();
|
||||
response.Close();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new Exception(ex.Message);
|
||||
}
|
||||
return fileSize;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void ReName(string currentFilename, string newFilename)
|
||||
{
|
||||
FtpWebRequest reqFTP;
|
||||
try
|
||||
{
|
||||
reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri(ftpURI + currentFilename));
|
||||
reqFTP.Method = WebRequestMethods.Ftp.Rename;
|
||||
reqFTP.RenameTo = newFilename;
|
||||
reqFTP.UseBinary = true;
|
||||
reqFTP.Credentials = new NetworkCredential(ftpUserID, ftpPassword);
|
||||
FtpWebResponse response = (FtpWebResponse)reqFTP.GetResponse();
|
||||
Stream ftpStream = response.GetResponseStream();
|
||||
ftpStream.Close();
|
||||
response.Close();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new Exception(ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
public void MovieFile(string currentFilename, string newDirectory)
|
||||
{
|
||||
ReName(currentFilename, newDirectory);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
69
SlMesDbIterface/MessageHanlder/GetVal.cs
Normal file
69
SlMesDbIterface/MessageHanlder/GetVal.cs
Normal file
@@ -0,0 +1,69 @@
|
||||
using Newtonsoft.Json.Linq;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace RecData
|
||||
{
|
||||
public class GetVal
|
||||
{
|
||||
|
||||
public static string JObject_Value(JObject jObj,string name)
|
||||
{
|
||||
var objVal = "NULL";
|
||||
if (jObj[name] != null)
|
||||
{
|
||||
objVal = jObj[name].ToString();
|
||||
}
|
||||
return objVal;
|
||||
}
|
||||
public static string JObject_Value_Int(JObject jObj, string name)
|
||||
{
|
||||
var objVal = "-1";
|
||||
if (jObj[name] != null)
|
||||
{
|
||||
objVal = jObj[name].ToString();
|
||||
}
|
||||
return objVal;
|
||||
}
|
||||
public static string JToken_Value(JToken jToken, string name)
|
||||
{
|
||||
var objVal = "NULL";
|
||||
var jTokenStr = jToken.ToString();
|
||||
if (!jTokenStr.Contains(name))
|
||||
{
|
||||
return objVal;
|
||||
}
|
||||
|
||||
if (jToken[name] != null)
|
||||
{
|
||||
objVal = jToken[name].ToString();
|
||||
}
|
||||
return objVal;
|
||||
|
||||
}
|
||||
public static string JToken_Value_Int(JToken jToken, string name)
|
||||
{
|
||||
var objVal = "-1";
|
||||
if (jToken[name] != null)
|
||||
{
|
||||
objVal = jToken[name].ToString();
|
||||
}
|
||||
return objVal;
|
||||
|
||||
}
|
||||
public static JArray JObject_JArray(JObject jObj, string name)
|
||||
{
|
||||
var jArray = new JArray();
|
||||
if (jObj[name] != null)
|
||||
{
|
||||
jArray = (JArray)jObj[name];
|
||||
}
|
||||
return jArray;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
349
SlMesDbIterface/MessageHanlder/HttpCli.cs
Normal file
349
SlMesDbIterface/MessageHanlder/HttpCli.cs
Normal file
@@ -0,0 +1,349 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace PLMTEST
|
||||
{
|
||||
public class HttpCli
|
||||
{
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 指定Url地址使用Get 方式获取全部字符串
|
||||
/// </summary>
|
||||
/// <param name="url">请求链接地址</param>
|
||||
/// <returns></returns>
|
||||
public static string Get(string url)
|
||||
{
|
||||
string result = "";
|
||||
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
|
||||
HttpWebResponse resp = (HttpWebResponse)req.GetResponse();
|
||||
Stream stream = resp.GetResponseStream();
|
||||
try
|
||||
{
|
||||
//获取内容
|
||||
using (StreamReader reader = new StreamReader(stream))
|
||||
{
|
||||
result = reader.ReadToEnd();
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
stream.Close();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static void GetFile(string url,string path)
|
||||
{
|
||||
WebRequest request = WebRequest.Create(url);
|
||||
WebResponse response = request.GetResponse();
|
||||
if (response.ContentType.ToLower().Length > 0)
|
||||
{
|
||||
using (Stream reader = response.GetResponseStream())
|
||||
{
|
||||
using (FileStream writer = new FileStream(path, FileMode.OpenOrCreate, FileAccess.Write))
|
||||
{
|
||||
byte[] buffer = new byte[1024];
|
||||
int c = 0;
|
||||
while ((c = reader.Read(buffer, 0, buffer.Length)) > 0)
|
||||
{
|
||||
writer.Write(buffer, 0, c);
|
||||
}
|
||||
}
|
||||
}
|
||||
//HttpContext
|
||||
}
|
||||
}
|
||||
|
||||
public static byte[] GetFile_Bytes(string url)
|
||||
{
|
||||
byte[] bytesAll = null;
|
||||
WebRequest request = WebRequest.Create(url);
|
||||
WebResponse response = request.GetResponse();
|
||||
if (response.ContentType.ToLower().Length > 0)
|
||||
{
|
||||
using (Stream reader = response.GetResponseStream())
|
||||
{
|
||||
MemoryStream ms = new MemoryStream();
|
||||
byte[] buffer = new byte[1024];
|
||||
while (true)
|
||||
{
|
||||
int sz = reader.Read(buffer, 0, 1024);
|
||||
if (sz == 0) break;
|
||||
ms.Write(buffer, 0, sz);
|
||||
}
|
||||
bytesAll = ms.ToArray();
|
||||
}
|
||||
}
|
||||
|
||||
//如是图片
|
||||
//System.Drawing.Image img = System.Drawing.Image.FromStream(ms);
|
||||
|
||||
return bytesAll;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public void FGHJ()
|
||||
{
|
||||
|
||||
// Create a 'WebRequest' object with the specified url.
|
||||
WebRequest myWebRequest = WebRequest.Create("http://www.contoso.com");
|
||||
|
||||
// Send the 'WebRequest' and wait for response.
|
||||
WebResponse myWebResponse = myWebRequest.GetResponse();
|
||||
|
||||
// Obtain a 'Stream' object associated with the response object.
|
||||
Stream ReceiveStream = myWebResponse.GetResponseStream();
|
||||
|
||||
Encoding encode = System.Text.Encoding.GetEncoding("utf-8");
|
||||
|
||||
// Pipe the stream to a higher level stream reader with the required encoding format.
|
||||
StreamReader readStream = new StreamReader(ReceiveStream, encode);
|
||||
Console.WriteLine("\nResponse stream received");
|
||||
Char[] read = new Char[256];
|
||||
|
||||
// Read 256 charcters at a time.
|
||||
int count = readStream.Read(read, 0, 256);
|
||||
Console.WriteLine("HTML...\r\n");
|
||||
|
||||
while (count > 0)
|
||||
{
|
||||
// Dump the 256 characters on a string and display the string onto the console.
|
||||
String str = new String(read, 0, count);
|
||||
Console.Write(str);
|
||||
count = readStream.Read(read, 0, 256);
|
||||
}
|
||||
|
||||
Console.WriteLine("");
|
||||
// Release the resources of stream object.
|
||||
readStream.Close();
|
||||
|
||||
// Release the resources of response object.
|
||||
myWebResponse.Close();
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 发送Get请求
|
||||
/// </summary>
|
||||
/// <param name="url">地址</param>
|
||||
/// <param name="dic">请求参数定义</param>
|
||||
/// <returns></returns>
|
||||
public static string Get(string url, Dictionary<string, string> dic)
|
||||
{
|
||||
string result = "";
|
||||
StringBuilder builder = new StringBuilder();
|
||||
builder.Append(url);
|
||||
if (dic.Count > 0)
|
||||
{
|
||||
builder.Append("?");
|
||||
int i = 0;
|
||||
foreach (var item in dic)
|
||||
{
|
||||
if (i > 0)
|
||||
builder.Append("&");
|
||||
builder.AppendFormat("{0}={1}", item.Key, item.Value);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(builder.ToString());
|
||||
//添加参数
|
||||
HttpWebResponse resp = (HttpWebResponse)req.GetResponse();
|
||||
Stream stream = resp.GetResponseStream();
|
||||
try
|
||||
{
|
||||
//获取内容
|
||||
using (StreamReader reader = new StreamReader(stream))
|
||||
{
|
||||
result = reader.ReadToEnd();
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
stream.Close();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 指定Post地址使用Get 方式获取全部字符串
|
||||
/// </summary>
|
||||
/// <param name="url">请求后台地址</param>
|
||||
/// <returns></returns>
|
||||
public static string Post(string url)
|
||||
{
|
||||
string result = "";
|
||||
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
|
||||
req.Method = "POST";
|
||||
HttpWebResponse resp = (HttpWebResponse)req.GetResponse();
|
||||
Stream stream = resp.GetResponseStream();
|
||||
//获取内容
|
||||
using (StreamReader reader = new StreamReader(stream, Encoding.UTF8))
|
||||
{
|
||||
result = reader.ReadToEnd();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 指定Post地址使用Get 方式获取全部字符串
|
||||
/// </summary>
|
||||
/// <param name="url">请求后台地址</param>
|
||||
/// <returns></returns>
|
||||
public static string Post(string url, Dictionary<string, string> dic)
|
||||
{
|
||||
string result = "";
|
||||
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
|
||||
req.Method = "POST";
|
||||
req.ContentType = "application/x-www-form-urlencoded";
|
||||
#region 添加Post 参数
|
||||
StringBuilder builder = new StringBuilder();
|
||||
int i = 0;
|
||||
foreach (var item in dic)
|
||||
{
|
||||
if (i > 0)
|
||||
builder.Append("&");
|
||||
builder.AppendFormat("{0}={1}", item.Key, item.Value);
|
||||
i++;
|
||||
}
|
||||
byte[] data = Encoding.UTF8.GetBytes(builder.ToString());
|
||||
req.ContentLength = data.Length;
|
||||
using (Stream reqStream = req.GetRequestStream())
|
||||
{
|
||||
reqStream.Write(data, 0, data.Length);
|
||||
reqStream.Close();
|
||||
}
|
||||
#endregion
|
||||
HttpWebResponse resp = (HttpWebResponse)req.GetResponse();
|
||||
Stream stream = resp.GetResponseStream();
|
||||
//获取响应内容
|
||||
using (StreamReader reader = new StreamReader(stream, Encoding.UTF8))
|
||||
{
|
||||
result = reader.ReadToEnd();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 指定Post地址使用Get 方式获取全部字符串
|
||||
/// </summary>
|
||||
/// <param name="url">请求后台地址</param>
|
||||
/// <param name="content">Post提交数据内容(utf-8编码的)</param>
|
||||
/// <returns></returns>
|
||||
public static string Post(string url, string content)
|
||||
{
|
||||
string result = "";
|
||||
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
|
||||
req.Method = "POST";
|
||||
req.ContentType = "application/json";
|
||||
|
||||
#region 添加Post 参数
|
||||
byte[] data = Encoding.UTF8.GetBytes(content);
|
||||
req.ContentLength = data.Length;
|
||||
using (Stream reqStream = req.GetRequestStream())
|
||||
{
|
||||
reqStream.Write(data, 0, data.Length);
|
||||
reqStream.Close();
|
||||
}
|
||||
#endregion
|
||||
|
||||
HttpWebResponse resp = (HttpWebResponse)req.GetResponse();
|
||||
Stream stream = resp.GetResponseStream();
|
||||
//获取响应内容
|
||||
using (StreamReader reader = new StreamReader(stream, Encoding.UTF8))
|
||||
{
|
||||
result = reader.ReadToEnd();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Http下载文件
|
||||
/// </summary>
|
||||
/// <param name="uri">下载地址</param>
|
||||
/// <param name="filefullpath">存放完整路径(含文件名)</param>
|
||||
/// <param name="size">每次多的大小</param>
|
||||
/// <returns>下载操作是否成功</returns>
|
||||
|
||||
public static bool DownLoadFiles(string uri, string filefullpath, int size = 1000000)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (File.Exists(filefullpath))
|
||||
{
|
||||
try
|
||||
{
|
||||
File.Delete(filefullpath);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
string fileDirectory = System.IO.Path.GetDirectoryName(filefullpath);
|
||||
|
||||
if (!Directory.Exists(fileDirectory))
|
||||
{
|
||||
Directory.CreateDirectory(fileDirectory);
|
||||
}
|
||||
|
||||
FileStream fs = new FileStream(filefullpath, FileMode.Create);
|
||||
|
||||
byte[] buffer = new byte[size];
|
||||
|
||||
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(uri);
|
||||
|
||||
request.Timeout = 100000;
|
||||
|
||||
request.AddRange((int)fs.Length);
|
||||
|
||||
Stream ns = request.GetResponse().GetResponseStream();
|
||||
|
||||
long contentLength = request.GetResponse().ContentLength;
|
||||
|
||||
int length = ns.Read(buffer, 0, buffer.Length);
|
||||
|
||||
while (length > 0)
|
||||
{
|
||||
fs.Write(buffer,0 , length);
|
||||
buffer = new byte[size];
|
||||
length = ns.Read(buffer, 0, buffer.Length);
|
||||
}
|
||||
|
||||
fs.Close();
|
||||
|
||||
return true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
68
SlMesDbIterface/MessageHanlder/IOrderController.cs
Normal file
68
SlMesDbIterface/MessageHanlder/IOrderController.cs
Normal file
@@ -0,0 +1,68 @@
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Linq;
|
||||
using System.Net.Http;
|
||||
using System.Text;
|
||||
using System.Web;
|
||||
using System.Web.Http;
|
||||
using System.Collections.Concurrent;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using System.Threading;
|
||||
using SlMesDbIterface;
|
||||
using PLMTEST;
|
||||
using System.Net;
|
||||
using System.Net.Http.Headers;
|
||||
using System.IO;
|
||||
using ExternalDataSync;
|
||||
|
||||
|
||||
/////http://127.0.0.1:9981/api/IOrder/InsertOrder
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
namespace WebApi
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[RoutePrefix("api/IOrder")]
|
||||
public class IOrderController : ApiController
|
||||
{
|
||||
readonly string headUrl = "Project/";
|
||||
|
||||
/// <summary>
|
||||
/// 上传测试接收
|
||||
/// </summary>
|
||||
/// <param name="jobj"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public HttpResponseMessage test([FromBody] JObject jobj)
|
||||
{
|
||||
string JsonStr = jobj.ToString();
|
||||
|
||||
return new HttpResponseMessage
|
||||
{
|
||||
Content = new StringContent(AnalysisMsg.ProductionCalendarData(headUrl + System.Reflection.MethodBase.GetCurrentMethod().Name, jobj.ToString()), Encoding.GetEncoding("UTF-8"), "application/json")
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 生产建模基础数据
|
||||
/// </summary>
|
||||
/// <param name="jobj"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public HttpResponseMessage productCalendar([FromBody] JObject jobj)
|
||||
{
|
||||
return new HttpResponseMessage
|
||||
{
|
||||
Content = new StringContent(AnalysisMsg.ProductionCalendarData(headUrl + System.Reflection.MethodBase.GetCurrentMethod().Name, jobj.ToString()), Encoding.GetEncoding("UTF-8"), "application/json")
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
151
SlMesDbIterface/MessageHanlder/InitServer.cs
Normal file
151
SlMesDbIterface/MessageHanlder/InitServer.cs
Normal file
@@ -0,0 +1,151 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
using System.Net.Http.Formatting;
|
||||
using System.Net.Http.Headers;
|
||||
using System.Text;
|
||||
using System.Web.Http;
|
||||
using System.Web.Http.Cors;
|
||||
using System.Web.Http.SelfHost;
|
||||
|
||||
namespace WebApi
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public class InitServer
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
HttpSelfHostConfiguration config = null;
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
HttpSelfHostServer server = null;
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="port"></param>
|
||||
public InitServer(int port)
|
||||
{
|
||||
config = new HttpSelfHostConfiguration($"http://0.0.0.0:{port}");
|
||||
|
||||
config.EnableCors(new EnableCorsAttribute("*", "*", "*"));
|
||||
|
||||
config.MapHttpAttributeRoutes();
|
||||
|
||||
//config.Routes.MapHttpRoute(
|
||||
// name: "DefaultApi",
|
||||
// routeTemplate: "api/{controller}/{id}",
|
||||
// defaults: new { id = RouteParameter.Optional }
|
||||
//);
|
||||
|
||||
// 自定义路由匹配到action
|
||||
config.Routes.MapHttpRoute(
|
||||
name: "API Default",
|
||||
routeTemplate: "api/{controller}/{action}/{id}",
|
||||
defaults: new { id = RouteParameter.Optional }
|
||||
);
|
||||
|
||||
server = new HttpSelfHostServer(config);
|
||||
|
||||
server.OpenAsync().Wait();
|
||||
|
||||
}
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="port"></param>
|
||||
public void Init(int port)
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
public void Close()
|
||||
{
|
||||
server.CloseAsync();
|
||||
}
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public class JsonContentNegotiator : IContentNegotiator
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
private readonly JsonMediaTypeFormatter _jsonFormatter;
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="formatter"></param>
|
||||
public JsonContentNegotiator(JsonMediaTypeFormatter formatter)
|
||||
{
|
||||
_jsonFormatter = formatter;
|
||||
}
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="type"></param>
|
||||
/// <param name="request"></param>
|
||||
/// <param name="formatters"></param>
|
||||
/// <returns></returns>
|
||||
public ContentNegotiationResult Negotiate(Type type, HttpRequestMessage request, IEnumerable<MediaTypeFormatter> formatters)
|
||||
{
|
||||
var result = new ContentNegotiationResult(_jsonFormatter, new MediaTypeHeaderValue("application/json"));
|
||||
return result;
|
||||
}
|
||||
|
||||
public static string Postring1(string url, string token, Dictionary<string, string> dic)
|
||||
{
|
||||
string results = "";
|
||||
//url = "http://172.16.22.15:8000/" + url;
|
||||
|
||||
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
|
||||
req.Method = "POST";
|
||||
req.ContentType = "application/x-www-form-urlencoded";
|
||||
req.Headers.Add("Authorization", "Bearer " + token);
|
||||
|
||||
StringBuilder builder = new StringBuilder();
|
||||
int i = 0;
|
||||
foreach (var item in dic)
|
||||
{
|
||||
if (i > 0)
|
||||
builder.Append("&");
|
||||
builder.AppendFormat("{0}={1}", item.Key, item.Value);
|
||||
i++;
|
||||
}
|
||||
byte[] data = Encoding.UTF8.GetBytes(builder.ToString());
|
||||
req.ContentLength = data.Length;
|
||||
try
|
||||
{
|
||||
using (Stream reqStream = req.GetRequestStream())
|
||||
{
|
||||
reqStream.Write(data, 0, data.Length);
|
||||
reqStream.Close();
|
||||
}
|
||||
HttpWebResponse resp = (HttpWebResponse)req.GetResponse();
|
||||
Stream stream = resp.GetResponseStream();
|
||||
//获取响应内容
|
||||
using (StreamReader reader = new StreamReader(stream, Encoding.UTF8))
|
||||
{
|
||||
results = reader.ReadToEnd();
|
||||
}
|
||||
return results;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine(e.Message);
|
||||
return e.Message;
|
||||
throw;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
20
SlMesDbIterface/MessageHanlder/InterfaceUpLoad.cs
Normal file
20
SlMesDbIterface/MessageHanlder/InterfaceUpLoad.cs
Normal file
@@ -0,0 +1,20 @@
|
||||
using Newtonsoft.Json;
|
||||
using PLMTEST;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ExternalDataSync
|
||||
{
|
||||
public class InterfaceUpLoad
|
||||
{
|
||||
public static msgResHeader RequestPost(string url, msg m_msg)
|
||||
{
|
||||
return JsonConvert.DeserializeObject<msgResHeader>(HttpCli.Post(url, JsonConvert.SerializeObject(m_msg)));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
517
SlMesDbIterface/MessageHanlder/OExcel.cs
Normal file
517
SlMesDbIterface/MessageHanlder/OExcel.cs
Normal file
@@ -0,0 +1,517 @@
|
||||
using NPOI.HPSF;
|
||||
using NPOI.HSSF.UserModel;
|
||||
using NPOI.SS.UserModel;
|
||||
using NPOI.XSSF.UserModel;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace NPOITest
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Execl工具辅助类
|
||||
/// </summary>
|
||||
public class ExeclHelper
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// 读取Execl数据到DataTable中
|
||||
/// </summary>
|
||||
/// <param name="filePath">指定Execl文件路径</param>
|
||||
/// <param name="isColumnName">设置第一行是否是列名</param>
|
||||
/// <returns>返回一个DataTable数据集</returns>
|
||||
public static DataTable ExcelToDataTable(string filePath, string sheetName, bool isColumnName)
|
||||
{
|
||||
DataTable dataTable = null;
|
||||
FileStream fs = null;
|
||||
DataColumn column = null;
|
||||
DataRow dataRow = null;
|
||||
IWorkbook workbook = null;
|
||||
ISheet sheet = null;
|
||||
IRow row = null;
|
||||
ICell cell = null;
|
||||
int startRow = 0;
|
||||
try
|
||||
{
|
||||
using (fs = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
|
||||
{
|
||||
// 2007版本
|
||||
if (filePath.IndexOf(".xlsx") > 0)
|
||||
workbook = new XSSFWorkbook(fs);
|
||||
// 2003版本
|
||||
else if (filePath.IndexOf(".xls") > 0)
|
||||
workbook = new HSSFWorkbook(fs);
|
||||
if (workbook != null)
|
||||
{
|
||||
sheet = workbook.GetSheet(sheetName);//读取第一个sheet,当然也可以循环读取每个sheet
|
||||
dataTable = new DataTable();
|
||||
if (sheet != null)
|
||||
{
|
||||
int rowCount = sheet.LastRowNum;//总行数
|
||||
if (rowCount > 0)
|
||||
{
|
||||
IRow firstRow = sheet.GetRow(0);//第一行
|
||||
int cellCount = firstRow.LastCellNum;//列数
|
||||
|
||||
//构建datatable的列
|
||||
if (isColumnName)
|
||||
{
|
||||
startRow = 1;//如果第一行是列名,则从第二行开始读取
|
||||
for (int i = firstRow.FirstCellNum; i < cellCount; ++i)
|
||||
{
|
||||
cell = firstRow.GetCell(i);
|
||||
if (cell != null)
|
||||
{
|
||||
if (cell.StringCellValue != null)
|
||||
{
|
||||
column = new DataColumn(cell.StringCellValue);
|
||||
dataTable.Columns.Add(column);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i = firstRow.FirstCellNum; i < cellCount; ++i)
|
||||
{
|
||||
column = new DataColumn("column" + (i + 1));
|
||||
dataTable.Columns.Add(column);
|
||||
}
|
||||
}
|
||||
|
||||
//填充行
|
||||
for (int i = startRow; i <= rowCount; ++i)
|
||||
{
|
||||
row = sheet.GetRow(i);
|
||||
if (row == null) continue;
|
||||
|
||||
dataRow = dataTable.NewRow();
|
||||
for (int j = row.FirstCellNum; j < cellCount; ++j)
|
||||
{
|
||||
cell = row.GetCell(j);
|
||||
if (cell == null)
|
||||
{
|
||||
dataRow[j] = "";
|
||||
}
|
||||
else
|
||||
{
|
||||
//CellType(Unknown = -1,Numeric = 0,String = 1,Formula = 2,Blank = 3,Boolean = 4,Error = 5,)
|
||||
switch (cell.CellType)
|
||||
{
|
||||
case CellType.Blank:
|
||||
dataRow[j] = "";
|
||||
break;
|
||||
case CellType.Numeric:
|
||||
short format = cell.CellStyle.DataFormat;
|
||||
//对时间格式(2015.12.5、2015/12/5、2015-12-5等)的处理
|
||||
if (format == 14 || format == 31 || format == 57 || format == 58)
|
||||
dataRow[j] = cell.DateCellValue;
|
||||
else
|
||||
dataRow[j] = cell.NumericCellValue;
|
||||
break;
|
||||
case CellType.String:
|
||||
dataRow[j] = cell.StringCellValue;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
dataTable.Rows.Add(dataRow);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return dataTable;
|
||||
}
|
||||
catch (Exception err)
|
||||
{
|
||||
if (fs != null)
|
||||
{
|
||||
fs.Close();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static DataTable ExcelToDataTable(string filePath,int sheetIndex, bool isColumnName)
|
||||
{
|
||||
DataTable dataTable = null;
|
||||
FileStream fs = null;
|
||||
DataColumn column = null;
|
||||
DataRow dataRow = null;
|
||||
IWorkbook workbook = null;
|
||||
ISheet sheet = null;
|
||||
IRow row = null;
|
||||
ICell cell = null;
|
||||
int startRow = 0;
|
||||
try
|
||||
{
|
||||
using (fs = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
|
||||
{
|
||||
// 2007版本
|
||||
if (filePath.IndexOf(".xlsx") > 0)
|
||||
workbook = new XSSFWorkbook(fs);
|
||||
// 2003版本
|
||||
else if (filePath.IndexOf(".xls") > 0)
|
||||
workbook = new HSSFWorkbook(fs);
|
||||
if (workbook != null)
|
||||
{
|
||||
sheet = workbook.GetSheetAt(sheetIndex);//读取第一个sheet,当然也可以循环读取每个sheet
|
||||
dataTable = new DataTable();
|
||||
if (sheet != null)
|
||||
{
|
||||
int rowCount = sheet.LastRowNum;//总行数
|
||||
if (rowCount > 0)
|
||||
{
|
||||
IRow firstRow = sheet.GetRow(0);//第一行
|
||||
int cellCount = firstRow.LastCellNum;//列数
|
||||
|
||||
//构建datatable的列
|
||||
if (isColumnName)
|
||||
{
|
||||
startRow = 1;//如果第一行是列名,则从第二行开始读取
|
||||
for (int i = firstRow.FirstCellNum; i < cellCount; ++i)
|
||||
{
|
||||
cell = firstRow.GetCell(i);
|
||||
if (cell != null)
|
||||
{
|
||||
if (cell.StringCellValue != null)
|
||||
{
|
||||
column = new DataColumn(cell.StringCellValue);
|
||||
dataTable.Columns.Add(column);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i = firstRow.FirstCellNum; i < cellCount; ++i)
|
||||
{
|
||||
column = new DataColumn("column" + (i + 1));
|
||||
dataTable.Columns.Add(column);
|
||||
}
|
||||
}
|
||||
|
||||
//填充行
|
||||
for (int i = startRow; i <= rowCount; ++i)
|
||||
{
|
||||
row = sheet.GetRow(i);
|
||||
if (row == null) continue;
|
||||
|
||||
dataRow = dataTable.NewRow();
|
||||
for (int j = row.FirstCellNum; j < cellCount; ++j)
|
||||
{
|
||||
cell = row.GetCell(j);
|
||||
if (cell == null)
|
||||
{
|
||||
dataRow[j] = "";
|
||||
}
|
||||
else
|
||||
{
|
||||
//CellType(Unknown = -1,Numeric = 0,String = 1,Formula = 2,Blank = 3,Boolean = 4,Error = 5,)
|
||||
switch (cell.CellType)
|
||||
{
|
||||
case CellType.Blank:
|
||||
dataRow[j] = "";
|
||||
break;
|
||||
case CellType.Numeric:
|
||||
short format = cell.CellStyle.DataFormat;
|
||||
//对时间格式(2015.12.5、2015/12/5、2015-12-5等)的处理
|
||||
if (format == 14 || format == 31 || format == 57 || format == 58 || format == 22)
|
||||
dataRow[j] = cell.DateCellValue;
|
||||
else
|
||||
dataRow[j] = cell.NumericCellValue;
|
||||
break;
|
||||
case CellType.String:
|
||||
dataRow[j] = cell.StringCellValue;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
dataTable.Rows.Add(dataRow);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return dataTable;
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
if (fs != null)
|
||||
{
|
||||
fs.Close();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 将DataTable导出到Execl文档
|
||||
/// </summary>
|
||||
/// <param name="dt">传入一个DataTable数据集</param>
|
||||
/// <returns>返回一个Bool类型的值,表示是否导出成功</returns>
|
||||
/// True表示导出成功,Flase表示导出失败
|
||||
public static bool DataTableToExcel(DataTable dt, string sheetName, string Outpath)
|
||||
{
|
||||
bool result = false;
|
||||
IWorkbook workbook = null;
|
||||
FileStream fs = null;
|
||||
IRow row = null;
|
||||
ISheet sheet = null;
|
||||
ICell cell = null;
|
||||
try
|
||||
{
|
||||
if (dt != null && dt.Rows.Count > 0)
|
||||
{
|
||||
workbook = new HSSFWorkbook();
|
||||
sheet = workbook.CreateSheet(sheetName);//创建一个名称为Sheet0的表
|
||||
int rowCount = dt.Rows.Count;//行数
|
||||
int columnCount = dt.Columns.Count;//列数
|
||||
|
||||
//设置列头
|
||||
row = sheet.CreateRow(0);//excel第一行设为列头
|
||||
for (int c = 0; c < columnCount; c++)
|
||||
{
|
||||
cell = row.CreateCell(c);
|
||||
cell.SetCellValue(dt.Columns[c].ColumnName);
|
||||
}
|
||||
|
||||
//设置每行每列的单元格,
|
||||
for (int i = 0; i < rowCount; i++)
|
||||
{
|
||||
row = sheet.CreateRow(i + 1);
|
||||
for (int j = 0; j < columnCount; j++)
|
||||
{
|
||||
cell = row.CreateCell(j);//excel第二行开始写入数据
|
||||
cell.SetCellValue(dt.Rows[i][j].ToString());
|
||||
}
|
||||
}
|
||||
//向outPath输出数据
|
||||
using (fs = File.OpenWrite(Outpath))
|
||||
{
|
||||
workbook.Write(fs);//向打开的这个xls文件中写入数据
|
||||
result = true;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
if (fs != null)
|
||||
{
|
||||
fs.Close();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 读取Execl数据到DataTable(DataSet)中
|
||||
/// </summary>
|
||||
/// <param name="filePath">指定Execl文件路径</param>
|
||||
/// <param name="isFirstLineColumnName">设置第一行是否是列名</param>
|
||||
/// <returns>返回一个DataTable数据集</returns>
|
||||
public static DataSet ExcelToDataSet(string filePath, bool isFirstLineColumnName)
|
||||
{
|
||||
DataSet dataSet = new DataSet();
|
||||
int startRow = 0;
|
||||
try
|
||||
{
|
||||
using (FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
|
||||
{
|
||||
IWorkbook workbook = null;
|
||||
// 如果是2007+的Excel版本
|
||||
if (filePath.IndexOf(".xlsx") > 0)
|
||||
{
|
||||
workbook = new XSSFWorkbook(fs);
|
||||
}
|
||||
// 如果是2003-的Excel版本
|
||||
else if (filePath.IndexOf(".xls") > 0)
|
||||
{
|
||||
workbook = new HSSFWorkbook(fs);
|
||||
}
|
||||
if (workbook != null)
|
||||
{
|
||||
//循环读取Excel的每个sheet,每个sheet页都转换为一个DataTable,并放在DataSet中
|
||||
for (int p = 0; p < workbook.NumberOfSheets; p++)
|
||||
{
|
||||
ISheet sheet = workbook.GetSheetAt(p);
|
||||
DataTable dataTable = new DataTable();
|
||||
dataTable.TableName = sheet.SheetName;
|
||||
if (sheet != null)
|
||||
{
|
||||
int rowCount = sheet.LastRowNum;//获取总行数
|
||||
if (rowCount > 0)
|
||||
{
|
||||
IRow firstRow = sheet.GetRow(0);//获取第一行
|
||||
int cellCount = firstRow.LastCellNum;//获取总列数
|
||||
|
||||
//构建datatable的列
|
||||
if (isFirstLineColumnName)
|
||||
{
|
||||
startRow = 1;//如果第一行是列名,则从第二行开始读取
|
||||
for (int i = firstRow.FirstCellNum; i < cellCount; ++i)
|
||||
{
|
||||
ICell cell = firstRow.GetCell(i);
|
||||
if (cell != null)
|
||||
{
|
||||
if (cell.StringCellValue != null)
|
||||
{
|
||||
DataColumn column = new DataColumn(cell.StringCellValue);
|
||||
dataTable.Columns.Add(column);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i = firstRow.FirstCellNum; i < cellCount; ++i)
|
||||
{
|
||||
DataColumn column = new DataColumn("column" + (i + 1));
|
||||
dataTable.Columns.Add(column);
|
||||
}
|
||||
}
|
||||
|
||||
//填充行
|
||||
for (int i = startRow; i <= rowCount; ++i)
|
||||
{
|
||||
IRow row = sheet.GetRow(i);
|
||||
if (row == null) continue;
|
||||
|
||||
DataRow dataRow = dataTable.NewRow();
|
||||
for (int j = row.FirstCellNum; j < cellCount; ++j)
|
||||
{
|
||||
ICell cell = row.GetCell(j);
|
||||
if (cell == null)
|
||||
{
|
||||
dataRow[j] = "";
|
||||
}
|
||||
else
|
||||
{
|
||||
//CellType(Unknown = -1,Numeric = 0,String = 1,Formula = 2,Blank = 3,Boolean = 4,Error = 5,)
|
||||
switch (cell.CellType)
|
||||
{
|
||||
case CellType.Blank:
|
||||
dataRow[j] = "";
|
||||
break;
|
||||
case CellType.Numeric:
|
||||
short format = cell.CellStyle.DataFormat;
|
||||
//对时间格式(2015.12.5、2015/12/5、2015-12-5等)的处理
|
||||
if (format == 14 || format == 31 || format == 57 || format == 58)
|
||||
dataRow[j] = cell.DateCellValue;
|
||||
else
|
||||
dataRow[j] = cell.NumericCellValue;
|
||||
break;
|
||||
case CellType.String:
|
||||
dataRow[j] = cell.StringCellValue;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
dataTable.Rows.Add(dataRow);
|
||||
}
|
||||
}
|
||||
}
|
||||
dataSet.Tables.Add(dataTable);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
return dataSet;
|
||||
}
|
||||
catch (Exception err)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 将DataTable(DataSet)导出到Execl文档
|
||||
/// </summary>
|
||||
/// <param name="dataSet">传入一个DataSet</param>
|
||||
/// <param name="Outpath">导出路径(可以不加扩展名,不加默认为.xls)</param>
|
||||
/// <returns>返回一个Bool类型的值,表示是否导出成功</returns>
|
||||
/// True表示导出成功,Flase表示导出失败
|
||||
public static bool DataSetToExcel(DataSet dataSet, string Outpath)
|
||||
{
|
||||
bool result = false;
|
||||
try
|
||||
{
|
||||
if (dataSet == null || dataSet.Tables == null || dataSet.Tables.Count == 0 || string.IsNullOrEmpty(Outpath))
|
||||
throw new Exception("输入的DataSet或路径异常");
|
||||
int sheetIndex = 0;
|
||||
//根据输出路径的扩展名判断workbook的实例类型
|
||||
IWorkbook workbook = null;
|
||||
string pathExtensionName = Outpath.Trim().Substring(Outpath.Length - 5);
|
||||
if (pathExtensionName.Contains(".xlsx"))
|
||||
{
|
||||
workbook = new XSSFWorkbook();
|
||||
}
|
||||
else if (pathExtensionName.Contains(".xls"))
|
||||
{
|
||||
workbook = new HSSFWorkbook();
|
||||
}
|
||||
else
|
||||
{
|
||||
Outpath = Outpath.Trim() + ".xls";
|
||||
workbook = new HSSFWorkbook();
|
||||
}
|
||||
//将DataSet导出为Excel
|
||||
foreach (DataTable dt in dataSet.Tables)
|
||||
{
|
||||
sheetIndex++;
|
||||
if (dt != null && dt.Rows.Count > 0)
|
||||
{
|
||||
ISheet sheet = workbook.CreateSheet(string.IsNullOrEmpty(dt.TableName) ? ("sheet" + sheetIndex) : dt.TableName);//创建一个名称为Sheet0的表
|
||||
int rowCount = dt.Rows.Count;//行数
|
||||
int columnCount = dt.Columns.Count;//列数
|
||||
|
||||
//设置列头
|
||||
IRow row = sheet.CreateRow(0);//excel第一行设为列头
|
||||
for (int c = 0; c < columnCount; c++)
|
||||
{
|
||||
ICell cell = row.CreateCell(c);
|
||||
cell.SetCellValue(dt.Columns[c].ColumnName);
|
||||
}
|
||||
|
||||
//设置每行每列的单元格,
|
||||
for (int i = 0; i < rowCount; i++)
|
||||
{
|
||||
row = sheet.CreateRow(i + 1);
|
||||
for (int j = 0; j < columnCount; j++)
|
||||
{
|
||||
ICell cell = row.CreateCell(j);//excel第二行开始写入数据
|
||||
cell.SetCellValue(dt.Rows[i][j].ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
//向outPath输出数据
|
||||
using (FileStream fs = File.OpenWrite(Outpath))
|
||||
{
|
||||
workbook.Write(fs);//向打开的这个xls文件中写入数据
|
||||
result = true;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
173
SlMesDbIterface/MessageHanlder/Re.cs
Normal file
173
SlMesDbIterface/MessageHanlder/Re.cs
Normal file
@@ -0,0 +1,173 @@
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using RecData;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace PLMTEST
|
||||
{
|
||||
public class Re
|
||||
{
|
||||
|
||||
|
||||
public static DataTable Analysis_DataObject(string jsonStr)
|
||||
{
|
||||
/*
|
||||
{
|
||||
"list": [
|
||||
{
|
||||
"errcode": 0,
|
||||
"errmsg": null,
|
||||
"objId": "01_18AC913FCA4A4DA99BDF01A99C232219",
|
||||
"objNo": "0100045006",
|
||||
"fname": null,
|
||||
"suffix": null,
|
||||
"hasAffine": null,
|
||||
"name": "油泵轴油封",
|
||||
"fsize": null,
|
||||
"fsizeStr": "未知",
|
||||
"type": "D",
|
||||
"tablename": "MPART",
|
||||
"smemo": null,
|
||||
"ctimestr": "2017-07-11 16:03",
|
||||
"mtimestr": "2020-12-21 15:36",
|
||||
"creator": "5914洪杰",
|
||||
"modifier": "11458戚亚克",
|
||||
"ver": "1",
|
||||
"stimestr": null,
|
||||
"etimestr": null,
|
||||
"extra": null,//这里加了俩字段:PTYPE(小类)、DTYPE(大类)
|
||||
"searchText": null
|
||||
}
|
||||
],
|
||||
"errcode": 0,
|
||||
"errmsg": null,
|
||||
"total": 1
|
||||
}
|
||||
*/
|
||||
|
||||
DataTable dt = new DataTable();
|
||||
dt.Columns.Add("errcode");
|
||||
dt.Columns.Add("errmsg");
|
||||
dt.Columns.Add("objId");
|
||||
dt.Columns.Add("objNo");
|
||||
dt.Columns.Add("fname");
|
||||
dt.Columns.Add("suffix");
|
||||
dt.Columns.Add("hasAffine");
|
||||
dt.Columns.Add("name");
|
||||
dt.Columns.Add("fsize");
|
||||
dt.Columns.Add("fsizeStr");
|
||||
dt.Columns.Add("type");
|
||||
dt.Columns.Add("tablename");
|
||||
dt.Columns.Add("smemo");
|
||||
dt.Columns.Add("ctimestr");
|
||||
dt.Columns.Add("mtimestr");
|
||||
dt.Columns.Add("creator");
|
||||
dt.Columns.Add("modifier");
|
||||
dt.Columns.Add("ver");
|
||||
dt.Columns.Add("stimestr");
|
||||
dt.Columns.Add("etimestr");
|
||||
dt.Columns.Add("extra");
|
||||
dt.Columns.Add("PTYPE");
|
||||
dt.Columns.Add("DTYPE");
|
||||
dt.Columns.Add("searchText");
|
||||
|
||||
|
||||
|
||||
var json = JsonConvert.DeserializeObject<JObject>(jsonStr);
|
||||
var errcode = json["errcode"].ToString();
|
||||
var errmsg = json["errmsg"].ToString();
|
||||
// var total = json["total"].ToString();
|
||||
if (errcode != "0")
|
||||
{
|
||||
dt = new DataTable();
|
||||
dt.Columns.Add("errcode");
|
||||
dt.Columns.Add("errmsg");
|
||||
// dt.Columns.Add("total");
|
||||
var dr = dt.NewRow();
|
||||
dr["errcode"] = errcode;
|
||||
dr["errmsg"] = errmsg;
|
||||
//dr["total"] = total;
|
||||
dt.Rows.Add(dr);
|
||||
return dt;
|
||||
}
|
||||
var array = json["list"];
|
||||
foreach (var a in array)
|
||||
{
|
||||
var _errcode = a["errcode"].ToString();
|
||||
var _errmsg = a["errmsg"].ToString();
|
||||
var objId = a["objId"].ToString();
|
||||
var objNo = a["objNo"].ToString();
|
||||
var fname = a["fname"].ToString();
|
||||
var suffix = a["suffix"].ToString();
|
||||
var hasAffine = a["hasAffine"].ToString();
|
||||
var name = a["name"].ToString();
|
||||
var fsize = a["fsize"].ToString();
|
||||
var fsizeStr = a["fsizeStr"].ToString();
|
||||
var type = a["type"].ToString();
|
||||
var tablename = a["tablename"].ToString();
|
||||
var smemo = a["smemo"].ToString();
|
||||
var ctimestr = a["ctimestr"].ToString();
|
||||
var mtimestr = a["mtimestr"].ToString();
|
||||
var creator = a["creator"].ToString();
|
||||
var modifier = a["modifier"].ToString();
|
||||
var ver = a["ver"].ToString();
|
||||
var stimestr = a["stimestr"].ToString();
|
||||
var etimestr = a["etimestr"].ToString();
|
||||
var extra_O = a["extra"];
|
||||
var extra = "-1";
|
||||
if (a["extra"] != null)
|
||||
{
|
||||
extra = a["extra"].ToString();
|
||||
}
|
||||
var PTYPE = GetVal.JToken_Value(extra_O, "PTYPE");
|
||||
var DTYPE = GetVal.JToken_Value(extra_O, "DTYPE");
|
||||
|
||||
var searchText = a["searchText"].ToString();
|
||||
|
||||
var dr = dt.NewRow();
|
||||
dr["errcode"] = _errcode;
|
||||
dr["errmsg"] = _errmsg;
|
||||
dr["objId"] = objId;
|
||||
dr["objNo"] = objNo;
|
||||
dr["fname"] = fname;
|
||||
dr["suffix"] = suffix;
|
||||
dr["hasAffine"] = hasAffine;
|
||||
dr["name"] = name;
|
||||
dr["fsize"] = fsize;
|
||||
dr["fsizeStr"] = fsizeStr;
|
||||
dr["type"] = type;
|
||||
dr["tablename"] = tablename;
|
||||
dr["smemo"] = smemo;
|
||||
|
||||
dr["ctimestr"] = ctimestr;
|
||||
dr["mtimestr"] = mtimestr;
|
||||
dr["creator"] = creator;
|
||||
dr["modifier"] = modifier;
|
||||
dr["ver"] = ver;
|
||||
|
||||
dr["stimestr"] = stimestr;
|
||||
dr["etimestr"] = etimestr;
|
||||
dr["extra"] = extra;
|
||||
dr["PTYPE"] = PTYPE;
|
||||
dr["DTYPE"] = DTYPE;
|
||||
dr["searchText"] = searchText;
|
||||
|
||||
dt.Rows.Add(dr);
|
||||
}
|
||||
|
||||
return dt;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
131
SlMesDbIterface/MessageHanlder/WCController.cs
Normal file
131
SlMesDbIterface/MessageHanlder/WCController.cs
Normal file
@@ -0,0 +1,131 @@
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Linq;
|
||||
using System.Net.Http;
|
||||
using System.Text;
|
||||
using System.Web;
|
||||
using System.Web.Http;
|
||||
using System.Collections.Concurrent;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using System.Threading;
|
||||
|
||||
namespace WebApi
|
||||
{
|
||||
|
||||
[RoutePrefix("api/WC")] //定义路由前缀
|
||||
public class WCController : ApiController
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// 插入数据库
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
public HttpResponseMessage ReportUp()
|
||||
{
|
||||
string pp = @"{\""Result\"":\""OK\""}";
|
||||
try
|
||||
{
|
||||
// pp = jObject.ToString();
|
||||
}
|
||||
catch (Exception err)
|
||||
{
|
||||
}
|
||||
return new HttpResponseMessage { Content = new StringContent(pp, Encoding.GetEncoding("UTF-8"), "application/json") };
|
||||
}
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
public HttpResponseMessage ReportUpCancel()
|
||||
{
|
||||
string pp = @"{\""Result\"":\""别试了,就不好用,试了也不好用\""}";
|
||||
try
|
||||
{
|
||||
// pp = jObject.ToString();
|
||||
}
|
||||
catch (Exception err)
|
||||
{
|
||||
}
|
||||
return new HttpResponseMessage { Content = new StringContent(pp, Encoding.GetEncoding("UTF-8"), "application/json") };
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
[HttpPost]
|
||||
public HttpResponseMessage SelectPage([FromBody]JObject jobj)
|
||||
{
|
||||
string pp = "";
|
||||
|
||||
try
|
||||
{
|
||||
var OpName = jobj["OpName"].ToString();
|
||||
var StartTime = jobj["StartTime"].ToString();
|
||||
var EndTime = jobj["EndTime"].ToString();
|
||||
var PageCurrent = jobj["PageCurrent"].ToString();
|
||||
var PageSize = jobj["PageSize"].ToString();
|
||||
|
||||
|
||||
string sql = "SELECT * FROM z_save_tag " +
|
||||
"WHERE(OperationTime BETWEEN '" + StartTime + "' AND '" + EndTime + "') AND OpName like '" + OpName + "%' " +
|
||||
"ORDER BY OperationTime;\n";
|
||||
// var res = GlobalVar.dbClient.ExecQuery(sql);
|
||||
|
||||
// var zSavePersonList = Z_Save_Position.DataTableToClass(res);
|
||||
|
||||
// var newZSaveList = DatabaseClient.DBClient.SplitePage<Z_Save_Position>(zSavePersonList, Convert.ToInt32(PageSize), Convert.ToInt32(PageCurrent));
|
||||
//var tableData = (JArray)JsonConvert.DeserializeObject(JsonConvert.SerializeObject(newZSaveList));
|
||||
//JObject resjobj = new JObject() {
|
||||
// new JProperty("ItemCount", zSavePersonList.Count.ToString()),
|
||||
// new JProperty("TableData",tableData)
|
||||
//};
|
||||
|
||||
//pp = resjobj.ToString()
|
||||
// //.Replace("\r\n","")
|
||||
// ;
|
||||
|
||||
}
|
||||
catch (Exception err)
|
||||
{
|
||||
//GlobalVar.log.Error(err.Message);
|
||||
// Console.WriteLine(err.Message);
|
||||
}
|
||||
HttpResponseMessage result = new HttpResponseMessage { Content = new StringContent(pp, Encoding.GetEncoding("UTF-8"), "application/json") };
|
||||
return result;
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public HttpResponseMessage Select([FromBody] JObject jobj)
|
||||
{
|
||||
string pp = "";
|
||||
try
|
||||
{
|
||||
string OpName = jobj["OpName"].ToString();
|
||||
string StartTime = jobj["StartTime"].ToString();
|
||||
string EndTime = jobj["EndTime"].ToString();
|
||||
|
||||
string sql = "SELECT * FROM z_save_tag " +
|
||||
"WHERE(OperationTime BETWEEN '"+StartTime+"' AND '"+EndTime+"') AND OpName like '"+OpName+"%' " +
|
||||
"ORDER BY OperationTime;\n";
|
||||
// var res = GlobalVar.dbClient.ExecQuery(sql);
|
||||
|
||||
//var zSavePersonList = Z_Save_Position.DataTableToClass(res);
|
||||
|
||||
//var zSavePersonListStr = JsonConvert.SerializeObject(zSavePersonList);
|
||||
|
||||
//pp = zSavePersonListStr.ToString();
|
||||
}
|
||||
catch (Exception err)
|
||||
{
|
||||
// GlobalVar.log.Error(err.Message);
|
||||
// Console.WriteLine(err.Message);
|
||||
}
|
||||
HttpResponseMessage result = new HttpResponseMessage { Content = new StringContent(pp, Encoding.GetEncoding("UTF-8"), "application/json") };
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
119
SlMesDbIterface/MessageHanlder/ZSavePositionController.cs
Normal file
119
SlMesDbIterface/MessageHanlder/ZSavePositionController.cs
Normal file
@@ -0,0 +1,119 @@
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Linq;
|
||||
using System.Net.Http;
|
||||
using System.Text;
|
||||
using System.Web;
|
||||
using System.Web.Http;
|
||||
using System.Collections.Concurrent;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
|
||||
namespace WebApi
|
||||
{
|
||||
|
||||
[RoutePrefix("api/ZSavePosition")] //定义路由前缀
|
||||
public class ZSavePositionController : ApiController
|
||||
{
|
||||
/// <summary>
|
||||
/// 插入数据库
|
||||
/// </summary>
|
||||
/// <param name="jObject"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public void Insert(JObject jObject)
|
||||
{
|
||||
string pp = "";
|
||||
try
|
||||
{
|
||||
var z_Save_Position = JsonConvert.DeserializeObject<Z_Save_Position>(JsonConvert.SerializeObject(jObject));
|
||||
|
||||
//z_Save_Position.OpName = "a1";
|
||||
//z_Save_Position.Value = "asd";
|
||||
//z_Save_Position.OperationTime = "2022/06/29 16:40:43";
|
||||
//z_Save_Position.ProjectCode = "123";
|
||||
|
||||
string sql = "INSERT INTO z_save_position(OpName, Value, OperationTime, ProjectCode) VALUES('" + z_Save_Position.OpName + "', '" + z_Save_Position.Value + "', '" + z_Save_Position.OperationTime + "', '" + z_Save_Position.ProjectCode + "');\n";
|
||||
// var res = GlobalVar.dbClient.ExecNonQuery(sql);
|
||||
|
||||
// pp = res.ToString();
|
||||
|
||||
}
|
||||
catch (Exception err)
|
||||
{
|
||||
// GlobalVar.log.Error(err.Message);
|
||||
// Console.WriteLine(err.Message);
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public HttpResponseMessage SelectPage([FromBody] JObject jobj)
|
||||
{
|
||||
string pp = "";
|
||||
try
|
||||
{
|
||||
var OpName = jobj["OpName"].ToString();
|
||||
var StartTime = jobj["StartTime"].ToString();
|
||||
var EndTime = jobj["EndTime"].ToString();
|
||||
var PageCurrent = jobj["PageCurrent"].ToString();
|
||||
var PageSize = jobj["PageSize"].ToString();
|
||||
|
||||
string sql = "SELECT * FROM z_save_position " +
|
||||
"WHERE(OperationTime BETWEEN '" + StartTime + "' AND '" + EndTime + "') AND OpName like '" + OpName + "%' " +
|
||||
"ORDER BY OperationTime;\n";
|
||||
// var res = GlobalVar.dbClient.ExecQuery(sql);
|
||||
|
||||
//var zSavePersonList = Z_Save_Position.DataTableToClass(res);
|
||||
|
||||
// var newZSaveList = DatabaseClient.DBClient.SplitePage<Z_Save_Position>(zSavePersonList, Convert.ToInt32(PageSize), Convert.ToInt32(PageCurrent));
|
||||
// var tableData = (JArray)JsonConvert.DeserializeObject(JsonConvert.SerializeObject(newZSaveList));
|
||||
//JObject resjobj = new JObject() {
|
||||
// new JProperty("ItemCount", zSavePersonList.Count.ToString()),
|
||||
// new JProperty("TableData",tableData)
|
||||
//};
|
||||
|
||||
// pp = resjobj.ToString();
|
||||
|
||||
}
|
||||
catch (Exception err)
|
||||
{
|
||||
// GlobalVar.log.Error(err.Message);
|
||||
// Console.WriteLine(err.Message);
|
||||
}
|
||||
HttpResponseMessage result = new HttpResponseMessage { Content = new StringContent(pp, Encoding.GetEncoding("UTF-8"), "application/json") };
|
||||
return result;
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public HttpResponseMessage Select([FromBody] JObject jobj)
|
||||
{
|
||||
string pp = "";
|
||||
try
|
||||
{
|
||||
var OpName = jobj["OpName"].ToString();
|
||||
var StartTime = jobj["StartTime"].ToString();
|
||||
var EndTime = jobj["EndTime"].ToString();
|
||||
|
||||
string sql = "SELECT * FROM z_save_position " +
|
||||
"WHERE(OperationTime BETWEEN '"+StartTime+"' AND '"+EndTime+"') AND OpName like '"+OpName+"%' " +
|
||||
"ORDER BY OperationTime;\n";
|
||||
//var res = GlobalVar.dbClient.ExecQuery(sql);
|
||||
|
||||
// var zSavePersonList = Z_Save_Position.DataTableToClass(res);
|
||||
|
||||
// var zSavePersonListStr = JsonConvert.SerializeObject(zSavePersonList);
|
||||
|
||||
// pp = zSavePersonListStr.ToString();
|
||||
}
|
||||
catch (Exception err)
|
||||
{
|
||||
//GlobalVar.log.Error(err.Message);
|
||||
// Console.WriteLine (err.Message);
|
||||
}
|
||||
HttpResponseMessage result = new HttpResponseMessage { Content = new StringContent(pp, Encoding.GetEncoding("UTF-8"), "application/json") };
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
122
SlMesDbIterface/MessageHanlder/ZSaveTagController.cs
Normal file
122
SlMesDbIterface/MessageHanlder/ZSaveTagController.cs
Normal file
@@ -0,0 +1,122 @@
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Linq;
|
||||
using System.Net.Http;
|
||||
using System.Text;
|
||||
using System.Web;
|
||||
using System.Web.Http;
|
||||
using System.Collections.Concurrent;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
|
||||
namespace WebApi
|
||||
{
|
||||
|
||||
[RoutePrefix("api/ZSaveTag")] //定义路由前缀
|
||||
public class ZSaveTagController : ApiController
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// 插入数据库
|
||||
/// </summary>
|
||||
/// <param name="jObject"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public void Insert(JObject jObject)
|
||||
{
|
||||
string pp = "";
|
||||
try
|
||||
{
|
||||
var z_Save_Tag = JsonConvert.DeserializeObject<Z_Save_Tag>(JsonConvert.SerializeObject(jObject));
|
||||
|
||||
string sql = "" +
|
||||
"INSERT INTO z_save_tag (OpName, TagID, Value, KeepTime, OperationTime, ProjectCode) " +
|
||||
" VALUES('"+ z_Save_Tag.OpName+ "', '"+ z_Save_Tag.TagID+ "', '"+ z_Save_Tag.Value+ "', '"+ z_Save_Tag .KeepTime+ "', '"+ z_Save_Tag .OperationTime+ "', '"+ z_Save_Tag .ProjectCode+ "'); \n";
|
||||
//var res = GlobalVar.dbClient.ExecNonQuery(sql);
|
||||
|
||||
// pp = res.ToString();
|
||||
|
||||
}
|
||||
catch (Exception err)
|
||||
{
|
||||
//GlobalVar.log.Error(err.Message);
|
||||
}
|
||||
// HttpResponseMessage result = new HttpResponseMessage { Content = new StringContent(pp, Encoding.GetEncoding("UTF-8"), "application/json") };
|
||||
// return result;
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public HttpResponseMessage SelectPage([FromBody]JObject jobj)
|
||||
{
|
||||
string pp = "";
|
||||
|
||||
try
|
||||
{
|
||||
var OpName = jobj["OpName"].ToString();
|
||||
var StartTime = jobj["StartTime"].ToString();
|
||||
var EndTime = jobj["EndTime"].ToString();
|
||||
var PageCurrent = jobj["PageCurrent"].ToString();
|
||||
var PageSize = jobj["PageSize"].ToString();
|
||||
|
||||
|
||||
string sql = "SELECT * FROM z_save_tag " +
|
||||
"WHERE(OperationTime BETWEEN '" + StartTime + "' AND '" + EndTime + "') AND OpName like '" + OpName + "%' " +
|
||||
"ORDER BY OperationTime;\n";
|
||||
// var res = GlobalVar.dbClient.ExecQuery(sql);
|
||||
|
||||
// var zSavePersonList = Z_Save_Position.DataTableToClass(res);
|
||||
|
||||
// var newZSaveList = DatabaseClient.DBClient.SplitePage<Z_Save_Position>(zSavePersonList, Convert.ToInt32(PageSize), Convert.ToInt32(PageCurrent));
|
||||
//var tableData = (JArray)JsonConvert.DeserializeObject(JsonConvert.SerializeObject(newZSaveList));
|
||||
//JObject resjobj = new JObject() {
|
||||
// new JProperty("ItemCount", zSavePersonList.Count.ToString()),
|
||||
// new JProperty("TableData",tableData)
|
||||
//};
|
||||
|
||||
//pp = resjobj.ToString()
|
||||
// //.Replace("\r\n","")
|
||||
// ;
|
||||
|
||||
}
|
||||
catch (Exception err)
|
||||
{
|
||||
//GlobalVar.log.Error(err.Message);
|
||||
// Console.WriteLine(err.Message);
|
||||
}
|
||||
HttpResponseMessage result = new HttpResponseMessage { Content = new StringContent(pp, Encoding.GetEncoding("UTF-8"), "application/json") };
|
||||
return result;
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public HttpResponseMessage Select([FromBody] JObject jobj)
|
||||
{
|
||||
string pp = "";
|
||||
try
|
||||
{
|
||||
string OpName = jobj["OpName"].ToString();
|
||||
string StartTime = jobj["StartTime"].ToString();
|
||||
string EndTime = jobj["EndTime"].ToString();
|
||||
|
||||
string sql = "SELECT * FROM z_save_tag " +
|
||||
"WHERE(OperationTime BETWEEN '"+StartTime+"' AND '"+EndTime+"') AND OpName like '"+OpName+"%' " +
|
||||
"ORDER BY OperationTime;\n";
|
||||
// var res = GlobalVar.dbClient.ExecQuery(sql);
|
||||
|
||||
//var zSavePersonList = Z_Save_Position.DataTableToClass(res);
|
||||
|
||||
//var zSavePersonListStr = JsonConvert.SerializeObject(zSavePersonList);
|
||||
|
||||
//pp = zSavePersonListStr.ToString();
|
||||
}
|
||||
catch (Exception err)
|
||||
{
|
||||
// GlobalVar.log.Error(err.Message);
|
||||
// Console.WriteLine(err.Message);
|
||||
}
|
||||
HttpResponseMessage result = new HttpResponseMessage { Content = new StringContent(pp, Encoding.GetEncoding("UTF-8"), "application/json") };
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
40
SlMesDbIterface/MessageHanlder/Z_Save_Position.cs
Normal file
40
SlMesDbIterface/MessageHanlder/Z_Save_Position.cs
Normal file
@@ -0,0 +1,40 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using System.Data;
|
||||
|
||||
namespace WebApi
|
||||
{
|
||||
class Z_Save_Position
|
||||
{
|
||||
public int ID;
|
||||
public string OpName;
|
||||
public string Value;
|
||||
public string OperationTime;
|
||||
public string ProjectCode;
|
||||
|
||||
public Z_Save_Position() { }
|
||||
|
||||
public static List<Z_Save_Position> DataTableToClass(DataTable dt_Z_Save_Position)
|
||||
{
|
||||
List<Z_Save_Position> z_Save_PositionList = new List<Z_Save_Position>();
|
||||
Z_Save_Position z_Save_Position;
|
||||
for (int i = 0; i < dt_Z_Save_Position.Rows.Count; i++)
|
||||
{
|
||||
z_Save_Position = new Z_Save_Position();
|
||||
var row = dt_Z_Save_Position.Rows[i];
|
||||
z_Save_Position.ID = Convert.ToInt32(row["ID"]);
|
||||
z_Save_Position.OpName = row["OpName"].ToString();
|
||||
z_Save_Position.Value = row["Value"].ToString();
|
||||
z_Save_Position.OperationTime = row["OperationTime"].ToString();
|
||||
z_Save_Position.ProjectCode = row["ProjectCode"].ToString();
|
||||
z_Save_PositionList.Add(z_Save_Position);
|
||||
}
|
||||
|
||||
return z_Save_PositionList;
|
||||
}
|
||||
}
|
||||
}
|
||||
46
SlMesDbIterface/MessageHanlder/Z_Save_Tag.cs
Normal file
46
SlMesDbIterface/MessageHanlder/Z_Save_Tag.cs
Normal file
@@ -0,0 +1,46 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace WebApi
|
||||
{
|
||||
class Z_Save_Tag
|
||||
{
|
||||
public int ID;
|
||||
public string OpName;
|
||||
public string TagID;
|
||||
public string Value;
|
||||
public string KeepTime;
|
||||
public string OperationTime;
|
||||
public string ProjectCode;
|
||||
public Z_Save_Tag()
|
||||
{
|
||||
|
||||
}
|
||||
public static List<Z_Save_Tag> DataTableToClass(DataTable dt_Z_Save_Tag)
|
||||
{
|
||||
List<Z_Save_Tag> z_Save_TagList = new List<Z_Save_Tag>();
|
||||
Z_Save_Tag z_Save_Tag;
|
||||
for (int i = 0; i < dt_Z_Save_Tag.Rows.Count; i++)
|
||||
{
|
||||
z_Save_Tag = new Z_Save_Tag();
|
||||
|
||||
var row = dt_Z_Save_Tag.Rows[i];
|
||||
z_Save_Tag.ID = Convert.ToInt32(row["ID"]);
|
||||
z_Save_Tag.OpName = row["OpName"].ToString();
|
||||
z_Save_Tag.TagID = row["TagID"].ToString();
|
||||
z_Save_Tag.Value = row["Value"].ToString();
|
||||
z_Save_Tag.KeepTime = row["KeepTime"].ToString();
|
||||
z_Save_Tag.OperationTime = row["OperationTime"].ToString();
|
||||
z_Save_Tag.ProjectCode = row["ProjectCode"].ToString();
|
||||
|
||||
z_Save_TagList.Add(z_Save_Tag);
|
||||
}
|
||||
|
||||
return z_Save_TagList;
|
||||
}
|
||||
}
|
||||
}
|
||||
36
SlMesDbIterface/MessageHanlder/msgHeader.cs
Normal file
36
SlMesDbIterface/MessageHanlder/msgHeader.cs
Normal file
@@ -0,0 +1,36 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ExternalDataSync
|
||||
{
|
||||
public class msgHeader
|
||||
{
|
||||
/// <summary>
|
||||
/// 协议版本,默认1.0
|
||||
/// </summary>
|
||||
public int version
|
||||
{
|
||||
get;
|
||||
set;
|
||||
} = 1;
|
||||
/// <summary>
|
||||
/// 消息ID
|
||||
/// </summary>
|
||||
public string taskId
|
||||
{
|
||||
get;
|
||||
set;
|
||||
} = "1";
|
||||
/// <summary>
|
||||
/// 事务号
|
||||
/// </summary>
|
||||
public string taskType
|
||||
{
|
||||
get;
|
||||
set;
|
||||
} = "";
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user