2025-03-28 09:49:56 +08:00

285 lines
10 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using GetHttpData.SDK;
using GetHttpData.SDK.ThreadPool;
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Lib = ESSupport.Lib;
namespace GetMembership
{
public partial class LodData : Form
{
ClientThread _ClientThread = new ClientThread();
QualityHelper _QualityHelper = new QualityHelper();
ConfigThread _ConfigThread = null; //配置类
Timer _Timer = new Timer();
Timer _TimingStart = new Timer();
bool isDeBug = false;
//Lib.OracleHelper oracleHelper;
bool isReplaceColumnName = false;
// string ServerIP;
public LodData()
{
InitializeComponent();
}
private void LodData_Load(object sender, EventArgs e)
{
this.Visible = false;
try
{
string serverpartcode = _QualityHelper.serverpartcode;
if (serverpartcode != "520030" && serverpartcode != "520040" && serverpartcode != "520200")
{
Close();
}
_ClientThread.UploadStringEvent += new ClientThread.OutputResultsUploadArg(UploadStringEvent);//监听上传事件
//数据传输定时器
_Timer.Interval = 60 * 1000;
_Timer.Tick += new EventHandler(this.timer1_Tick);
_Timer.Start();
//指定任务定时器
_TimingStart.Interval = 60 * 1000;
_TimingStart.Tick += new EventHandler(this.timer2_Tick);
_TimingStart.Start();
//TableDataService、DataServices
StringBuilder _ConfigSql = new StringBuilder();
_ConfigSql.Append("http://" + _QualityHelper.dbip + ":" + _QualityHelper.DataServicePort + "/DataServices/Service.asmx").Append(" ");
_ConfigSql.Append(_QualityHelper.authorization).Append(" ");
_ConfigSql.Append(_QualityHelper.serverpartcode).Append(" ");
_ConfigSql.Append(_QualityHelper.serverpartshop_id).Append(" ");
_ConfigSql.Append(_QualityHelper.shopcode).Append(" ");
_ConfigSql.Append(_QualityHelper.macaddress).Append(" ");
_ConfigSql.Append(_QualityHelper.machinecode);
LogHelper.WriteServiceLog(_ConfigSql.ToString());
}
catch (Exception ex)
{
try
{
LogHelper.WriteServiceLog("初始化失败:" + ex.Message);
}
catch { }
}
}
private void button1_Click(object sender, EventArgs e)
{
bool falg = _ClientThread.onState();
}
#region ->
/// <summary>
/// 上传回调结果
/// </summary>
/// <param name="uploadResultInfo"></param>
/// <param name="resultString"></param>
private void UploadStringEvent(UploadResultInfo uploadResultInfo, string resultString)
{
try
{
//结束前
if (!uploadResultInfo.StartToEnd && (uploadResultInfo.InterfaceError != null || uploadResultInfo.Error != null))
{
string serverpartcode = _QualityHelper.serverpartcode;
string shopcode = _QualityHelper.shopcode;
string machinecode = _QualityHelper.machinecode;
string macaddress = _QualityHelper.macaddress;
//记录接口错误信息到文本日志中,供后续排查
if (!string.IsNullOrWhiteSpace(uploadResultInfo.InterfaceError))
{
Lib.LogHelper.WriteServiceLog("接口错误:" + uploadResultInfo.InterfaceError +
$"\n{uploadResultInfo.TableDesc}数据上传错误:[{uploadResultInfo.TableName.Replace("HIGHWAY_EXCHANGE.", "")}]" +
$"耗时:{uploadResultInfo.Elapsed.TotalSeconds.ToString("F2") + ""}");
Lib.LogHelper.WriteServiceLog("///--------------------------------------记录结束-------------------------------------///");
}
//记录本地错误信息到文本日志中,供后续排查
if (!string.IsNullOrWhiteSpace(uploadResultInfo.Error))
{
Lib.LogHelper.WriteServiceLog("本地错误:" + uploadResultInfo.Error +
$"\n{uploadResultInfo.TableDesc}数据上传错误:[{uploadResultInfo.TableName.Replace("HIGHWAY_EXCHANGE.", "")}]" +
$"耗时:{uploadResultInfo.Elapsed.TotalSeconds.ToString("F2") + ""}");
Lib.LogHelper.WriteServiceLog("///--------------------------------------记录结束-------------------------------------///");
}
}
}
catch
{
}
}
#endregion
#region -> 线
private void ThreadConfigure()
{
try
{
if (_ConfigThread == null)
{
_ConfigThread = new ConfigThread(_QualityHelper.serverpartcode, isReplaceColumnName);
}
_ClientThread.setConfiguration("http://" + _QualityHelper.dbip + ":" + _QualityHelper.DataServicePort + "/DataServices/Service.asmx",
_QualityHelper.authorization, _QualityHelper.serverpartcode, _QualityHelper.serverpartshop_id,
_QualityHelper.shopcode, _QualityHelper.macaddress, _QualityHelper.machinecode, int.Parse(_QualityHelper.maxdataquantity), 3);
_ClientThread.IsDownload(false);
_ClientThread.IsUpload(true, new List<string> { "T_SELLMASTER", "T_SELLDETAILS", "T_SELLDATA" });
_ClientThread.setConfigThread(_ConfigThread);
}
catch
{
}
}
#endregion
#region -> 线
private void timer1_Tick(object sender, EventArgs e)
{
try
{
ThreadConfigure();//线程配置
if (!_ClientThread.onState())
{
LogHelper.WriteServiceLog("传输预启动失败");
}
}
catch
{
}
}
#endregion
#region ->
private void timer2_Tick(object sender, EventArgs e)
{
try
{
//重启程序
onRestartFrom();
//获取时间
DateTime _DateTime = DateTime.Now;
int intHour = _DateTime.Hour;
int intMinute = _DateTime.Minute;
//int intSecond = _DateTime.Second;
if (intMinute != 0)
{
return;
}
//启动清除表数据线程
StartClearThread();
}
catch { }
}
#endregion
#region -> 线
private void StartClearThread()
{
//线程启动
System.Threading.Thread threadClear = new System.Threading.Thread(new System.Threading.ThreadStart(delegate ()
{
try
{
Lib.SyBaseHelper.ExecuteSqlTran(new List<string> { "DELETE FROM T_TRANSMISSIONERROR WHERE (RECORD_DATE < GETDATE() - 7)" });
}
catch (Exception ex)
{
try
{
if (isDeBug)
{
LogHelper.WriteServiceLog(ex.Message.ToString());
}
}
catch { }
}
}));
threadClear.IsBackground = true;
threadClear.Start();
}
#endregion
#region ->
private void onRestartFrom()
{
try
{
Process CurrentProcess = Process.GetCurrentProcess();
double _Working = CurrentProcess.WorkingSet64 / 1024 / 1024;
if (isDeBug)
{
LogHelper.WriteServiceLog("内存占用:" + _Working.ToString());
}
//大于500M内存占用重启当前传输工具
if (_Working > 500)
{
if (isDeBug)
{
LogHelper.WriteServiceLog("---------------程序重启----------------");
}
System.Windows.Forms.Application.Restart(); //重启当前程序
return;
}
}
catch { }
}
#endregion
#region ->
/// <summary>
/// luhn计算校验位
/// </summary>
/// <param name="time">时间</param>
/// <returns></returns>
public string GetCheckNumber(string serverpartcode, string shopcode, string machinecode)
{
try
{
Random _random = new Random();
string code = serverpartcode + shopcode + machinecode + DateTime.Now.ToString("yyyyMMddHHmmssfff")
+ RandomNum.getRandomNum(1, 0, 100)[0].ToString().PadLeft(2, '0');
int i, checkSum = 0;
for (i = code.Length - 1; i >= 0; i--)
{
if (i % 2 == 0)
{
int val = ((code[i] - '0') * 2);
while (val > 0)
{
checkSum += (val % 10);
val /= 10;
}
}
else
{
checkSum += (code[i] - '0');
}
}
checkSum = checkSum % 10;
return code + (10 - checkSum).ToString();
}
catch
{
return "";
}
}
#endregion
}
}