using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ESSupport.Lib;
using ESSupport.Pos;
using ConnectPoint.Common;
using System.Collections;
using Newtonsoft.Json;
using System.Data;
namespace ConnectPoint
{
public class ThreadHelper
{
#region 方法 -> 实时交易数据统计上报
///
/// 实时交易数据统计上报
///
/// 服务URL地址
public static void DataCollectionUpload(string serviceURL)
{
//获取服务区编码
string _ServerPartCode = PosConfigInit.ConfigurationValues("serverpartcode", string.Empty);
//获取门店编码
string _ShopCode = PosConfigInit.ConfigurationValues("shopcode", string.Empty);
//获取收银机号
string _MachineCode = PosConfigInit.ConfigurationValues("machinecode", string.Empty);
//获取新系统标识
bool _NewSystem = PosConfigInit.ConfigurationValues("NewSystem", "0") == "1";
DataStatistics _DataStatistics = new DataStatistics
{
ServerPartCode = _ServerPartCode,
ShopCode = _ShopCode,
MachineCode = _MachineCode
};
//业态营业时间采集
_DataStatistics.BusinessTime(_NewSystem);
try
{
//十分钟实时交易数据统计
Model.DataCollectionModel _DataCollectionModel = _DataStatistics.GetDataCollection(_NewSystem);
if (_DataCollectionModel != null)
{
try
{
//记录上传
SoapWSHelper.QuerySoapWebServiceString(
serviceURL, "FeedbackUpload", new Hashtable
{
{ "feedbackType", "DataCollection" },
{ "jsonData", JsonConvert.SerializeObject(_DataCollectionModel) }
});
}
catch { }
try
{
//本地记录保存
SyBaseHelper.ExecuteSqlTran($@"INSERT INTO T_DATACOLLECTION
(DATACOLLECTION_ID,SERVERPARTCODE,SHOPCODE,MACHINECODE,
MACADDRESS,MACHINENAME,DATACOLLECTION_TYPE,
DATACOLLECTION_DATE,TOTAL_COUNT,TOTALSELL_AMOUNT,
TICKET_COUNT,TICKET_INFO)
VALUES ({_DataCollectionModel.DATACOLLECTION_ID},
'{_DataCollectionModel.SERVERPARTCODE}','{_DataCollectionModel.SHOPCODE}',
'{_DataCollectionModel.MACHINECODE}','{_DataCollectionModel.MACADDRESS}',
'{_DataCollectionModel.MACHINENAME}',2000,
DATETIME('{_DataCollectionModel.DATACOLLECTION_DATE.Value.ToString("yyyy/MM/dd HH:mm:ss")}'),
{_DataCollectionModel.TOTAL_COUNT},{_DataCollectionModel.TOTALSELL_AMOUNT},
{_DataCollectionModel.TICKET_COUNT},'{_DataCollectionModel.TICKET_INFO}')");
}
catch { }
}
}
catch { }
}
#endregion
#region 方法 -> 收银机状态上报
///
/// 收银机状态上报
///
/// 服务URL地址
public static void StateFeedbackUpload(string serviceURL)
{
try
{
//获取服务区编码
string _ServerPartCode = PosConfigInit.ConfigurationValues("serverpartcode", string.Empty);
//获取门店编码
string _ShopCode = PosConfigInit.ConfigurationValues("shopcode", string.Empty);
//获取收银机号
string _MachineCode = PosConfigInit.ConfigurationValues("machinecode", string.Empty);
//获取新系统标识
bool _NewSystem = PosConfigInit.ConfigurationValues("NewSystem", "0") == "1";
DataStatistics _DataStatistics = new DataStatistics
{
ServerPartCode = _ServerPartCode,
ShopCode = _ShopCode,
MachineCode = _MachineCode
};
_DataStatistics.GetSellStatistics(_NewSystem, out decimal _TicketCount,
out decimal _SellCount, out decimal _FactAmount);
Model.StateFeedbackModel _StateFeedbackModel = new Model.StateFeedbackModel
{
STATEFEEDBACK_ID = 1,
CONNECT_DATE = DateTime.Now,
SERVERPARTCODE = _ServerPartCode,
SHOPCODE = _ShopCode,
MACHINECODE = _MachineCode,
MACHINENAME = System.Net.Dns.GetHostName(),
MACHINE_MACADDRESS = PCHelper.GetMacAddressByNetworkInformation(),
CONNECT_IP = PCHelper.GetAddressIP(),
CURRENT_SELLAMOUNT = _FactAmount,
CURRENT_SELLCOUNT = _SellCount,
CURRENT_TICKETCOUNT = _TicketCount,
CURRENT_GOODSCOUNT = _DataStatistics.GetCommodityCount(),
CURRENT_PERSON = _DataStatistics.GetPersonName(_NewSystem),
SELL_CONTENT = $"{_DataStatistics.GetLastTrade(_NewSystem)}|{_DataStatistics.GetLastSellData(_NewSystem)}",
VERSION_NUM = PosConfigInit.ConfigurationValues("version", ""),
CONFIG_CONTENT = _DataStatistics.GetPosConfig(),
STATEFEEDBACK_DESC = _DataStatistics.GetSalesPromote()
};
SoapWSHelper.QuerySoapWebServiceString(
serviceURL, "FeedbackUpload", new Hashtable
{
{ "feedbackType", "StateFeedback" },
{ "jsonData", JsonConvert.SerializeObject(_StateFeedbackModel) }
});
}
catch (Exception ex)
{
LogHelper.WriteServiceLog($"状态反馈上报失败:{ex.Message}");
}
}
#endregion
#region 方法 -> 移动支付交易校验
///
/// 移动支付交易校验
///
/// 服务接口地址
/// 校验起始时间
public static void MobilePayCheck(string payServiceUrl, DateTime payStartDate)
{
//获取服务区编码
string _ServerPartCode = PosConfigInit.ConfigurationValues("serverpartcode", string.Empty);
//获取门店编码
string _ShopCode = PosConfigInit.ConfigurationValues("shopcode", string.Empty);
//获取收银机号
string _MachineCode = PosConfigInit.ConfigurationValues("machinecode", string.Empty);
DataTable _tableMobilePay = SyBaseHelper.QueryOdbc(
$@"SELECT TICKET_CODE FROM T_MOBILE_PAY
WHERE MOBILEPAY_DATE BETWEEN DATETIME('{payStartDate.ToString("yyyy/MM/dd HH:mm:ss")}') AND
DATETIME('{DateTime.Now.AddMinutes(-5).ToString("yyyy/MM/dd HH:mm:ss")}') AND
MOBILEPAY_RESULT NOT IN(1,5,9)").Tables[0];
if (_tableMobilePay.Rows.Count > 0)
{
string _strOrderCode = "";
string _strLeft = _ServerPartCode + _ShopCode + _MachineCode.PadLeft(4, '0');
List _listUpdate = new List();
for (int i = 0; i < _tableMobilePay.Rows.Count; i++)
{
_strOrderCode += (_strOrderCode == "" ? "" : ",") + _tableMobilePay.Rows[i]["TICKET_CODE"].ToString().Replace(_strLeft, "");
if ((i + 1) % 20 == 0 || (i + 1) == _tableMobilePay.Rows.Count)
{
try
{
string _strResult = SoapWSHelper.QuerySoapWebServiceString(
payServiceUrl, "MobilePayCheck", new Hashtable
{
{ "serverPartCode", _ServerPartCode },
{ "shopCode", _ShopCode },
{ "machineCode", _MachineCode },
{ "mobilePayOrderCode", _strOrderCode }
});
if (!string.IsNullOrWhiteSpace(_strResult))
{
DataTable _tableResult = JsonHelper.JsonToDataSet(_strResult).Tables[0];
string _strTicketCode = "";
for (int n = 0; n < _tableResult.Rows.Count; n++)
{
_strTicketCode += (_strTicketCode == "" ? "" : ",") + "'" + _tableResult.Rows[n]["TICKETCODE"].ToString() + "'";
}
if (!String.IsNullOrWhiteSpace(_strTicketCode))
{
_listUpdate.Add(String.Format("UPDATE T_MOBILE_PAY SET MOBILEPAY_RESULT = 5, MOBILEPAY_STATE = 0" +
"WHERE TICKET_CODE IN({0}) AND MOBILEPAY_RESULT NOT IN (1,5,9)", _strTicketCode));
_listUpdate.Add(String.Format("UPDATE T_SELLDATA_PAY SET SELLDATAPAY_STATE = 8 " +
"WHERE ORDERCODE IN ({0}) AND SELLDATAPAY_STATE NOT IN (1,9)", _strTicketCode));
}
}
}
catch
{ }
_strOrderCode = "";
}
}
if (_listUpdate.Count > 0)
{
try
{
SyBaseHelper.ExecuteSqlTran(_listUpdate);
}
catch
{ }
}
}
}
#endregion
#region 方法 -> 获取门店移动支付通道配置
///
/// 获取门店移动支付通道配置
///
/// 接口地址
/// 服务区编码
/// 业态编码
public static void MobilePayConfigUpdate(string paySeviceIP)
{
if (string.IsNullOrWhiteSpace(paySeviceIP))
{
return;
}
//获取服务区编码
string _ServerPartCode = PosConfigInit.ConfigurationValues("serverpartcode", string.Empty);
//获取门店编码
string _ShopCode = PosConfigInit.ConfigurationValues("shopcode", string.Empty);
if (string.IsNullOrWhiteSpace(_ServerPartCode) || string.IsNullOrWhiteSpace(_ShopCode))
{
return;
}
string _BusinessType = SyBaseHelper.QueryOdbc(
$@"SELECT BUSINESSTYPE FROM T_SHOPMESSAGE
WHERE SERVERPARTCODE = '{_ServerPartCode}' AND
SHOPCODE = '{_ShopCode}'").Tables[0].Rows[0]["BUSINESSTYPE"].ToString();
string[] _ServicePort = new string[]
{
PosConfigInit.ConfigurationValues("service_port", "7080"),
PosConfigInit.ConfigurationValues("service_port2", "7080"),
PosConfigInit.ConfigurationValues("DataServicePort", "7080")
};
List _ServiceUrlList = new List();
for (int i = 0; i < _ServicePort.Count(); i++)
{
_ServiceUrlList.Add(string.Format("http://{0}:{1}/Service.asmx", paySeviceIP, _ServicePort[i]));
}
Hashtable hashtable = new Hashtable
{
{ "serverPartCode", _ServerPartCode },
{ "businessType", _BusinessType }
};
foreach (string _strServiceUrl in _ServiceUrlList)
{
try
{
string _strResult = SoapWSHelper.QuerySoapWebServiceString(_strServiceUrl, "MobilePayConfig", hashtable);
if (!string.IsNullOrWhiteSpace(_strResult))
{
DataTable _DateTable = JsonHelper.JsonToDataTable(_strResult);
if (_DateTable != null && _DateTable.Rows.Count > 0)
{
foreach (DataRow _DataRow in _DateTable.Rows)
{
PosConfigInit.UpdateConfigUration(_DataRow["k"].ToString(), _DataRow["v"].ToString());
}
}
}
break;
}
catch (Exception ex)
{
LogHelper.WriteServiceLog("移动支付通道配置下载异常:" + ex.Message);
}
}
}
#endregion
#region 方法 -> 记录系统运行时间日志
///
/// 记录系统运行时间日志
///
/// 最后一次记录时间
///
public static bool RuningLog(DateTime runingTime)
{
if (runingTime == DateTime.MinValue)
{
try
{
runingTime = (DateTime)SyBaseHelper.QueryOdbc(
@"SELECT MAX(LOGGING_DATE) AS LOGGING_DATE
FROM T_ACTIVELOGGING").Tables[0].Rows[0][0];
}
catch
{
return true;
}
}
TimeSpan _TimeSpan = DateTime.Now.Subtract(runingTime);
if ((int)_TimeSpan.TotalSeconds >= 300)
{
//获取服务区编码
string _ServerPartCode = PosConfigInit.ConfigurationValues("serverpartcode", string.Empty);
//获取门店编码
string _ShopCode = PosConfigInit.ConfigurationValues("shopcode", string.Empty);
//获取收银机号
string _MachineCode = PosConfigInit.ConfigurationValues("machinecode", string.Empty);
try
{
SyBaseHelper.ExecuteSqlTran(
$@"INSERT INTO T_ACTIVELOGGING (ACTIVELOGGING_ID,
SERVERPARTCODE, SHOPCODE,MACHINECODE,MACHINENAME,
MACADDRESS,MACHINE_IP,LOGGING_DATE,RUNNING_INTERVAL)
VALUES ( {PosReport.CreateNextSequence("T_ACTIVELOGGING", "ACTIVELOGGING_ID")},
'{_ServerPartCode}','{_ShopCode}','{_MachineCode}','{System.Net.Dns.GetHostName()}',
'{PCHelper.GetMacAddressByNetworkInformation()}','{PCHelper.GetAddressIP()}',
DATETIME('{DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss")}'),{(int)_TimeSpan.TotalSeconds})");
return true;
}
catch { }
}
return false;
}
#endregion
#region 方法 -> 收银机基础数据版本上报
///
/// 收银机基础数据版本上报
///
/// 服务URL地址
public static void BaseInfoFeedbackUpload(string serviceURL)
{
//获取服务区编码
string _ServerPartCode = PosConfigInit.ConfigurationValues("serverpartcode", string.Empty);
//获取门店编码
string _ShopCode = PosConfigInit.ConfigurationValues("shopcode", string.Empty);
//获取收银机号
string _MachineCode = PosConfigInit.ConfigurationValues("machinecode", string.Empty);
try
{
decimal _ServerPartShopID = Convert.ToDecimal(SyBaseHelper.QueryOdbc(
$@"SELECT SERVERPARTSHOP_ID FROM T_SHOPMESSAGE
WHERE SERVERPARTCODE = '{_ServerPartCode}' AND
SHOPCODE = '{_ShopCode}'").Tables[0].Rows[0]["SERVERPARTSHOP_ID"]);
List _BaseInfoList = new List
{
new BaseInfo
{
UploadTable="T_COMMODITY", TableName = "T_COMMODITYEX",
TableColumn = "DOWNLOADDATE", WhereSql = $@" ISVALID = 1 AND
SERVERPARTCODE = '{_ServerPartCode}' AND SERVERPARTSHOP_ID = (
SELECT SERVERPARTSHOP_ID FROM T_SHOPMESSAGE
WHERE SERVERPARTCODE = '{_ServerPartCode}' AND SHOPCODE = '{_ShopCode}')"
},
new BaseInfo
{
UploadTable="T_CASHWORKER", TableName = "T_SELLWORKER",
TableColumn = "DOWNLOADDATE", WhereSql = $"SERVERPARTCODE = '{_ServerPartCode}'"
},
new BaseInfo
{
UploadTable="T_HOTKEYSET", TableName = "T_HOTKEYSET",
TableColumn = "DOWNLOADDATE", WhereSql = $@"VALID = 1 AND
SERVERPARTCODE = '{_ServerPartCode}' AND BUSINESSTYPE = (
SELECT BUSINESSTYPE FROM T_SHOPMESSAGE
WHERE SERVERPARTCODE = '{_ServerPartCode}' AND SHOPCODE = '{_ShopCode}')"
}
};
foreach (var _BaseInfo in _BaseInfoList)
{
Model.BaseInfoFeedbackModel _BaseInfoFeedbackModel = new Model.BaseInfoFeedbackModel
{
BASEINFOFEEDBACK_ID = 1,
SERVERPART_CODE = Convert.ToDecimal(_ServerPartCode),
SERVERPARTSHOP_ID = _ServerPartShopID,
SHOPCODE = _ShopCode,
MACHINECODE = _MachineCode,
MACHINENAME = System.Net.Dns.GetHostName(),
MACHINE_MACADDRESS = PCHelper.GetMacAddressByNetworkInformation(),
MACHINE_IP = PCHelper.GetAddressIP(),
MACHINE_STARTDATE = PosReport.GetDataBaseDate(
_BaseInfo.TableName, _BaseInfo.TableColumn, "MAX", _BaseInfo.WhereSql),
MACHINE_ENDDATE = DateTime.Now,
TABLE_NAME = _BaseInfo.UploadTable
};
SoapWSHelper.QuerySoapWebServiceString(
serviceURL, "FeedbackUpload", new Hashtable
{
{ "feedbackType", "BaseInfoFeedback" },
{ "jsonData", JsonConvert.SerializeObject(_BaseInfoFeedbackModel) }
});
}
}
catch (Exception ex)
{
LogHelper.WriteServiceLog($"基础数据版本上报失败:{ex.Message}");
}
}
#endregion
#region 方法 -> 收银机指令下载
///
/// 收银机指令下载
///
/// 服务URL地址
public static void CommodityMachine(string serviceURL)
{
try
{
FeedbackResult _FeedbackResult =
JsonConvert.DeserializeObject>(
SoapWSHelper.QuerySoapWebServiceString(
serviceURL, "FeedbackDownload", new Hashtable
{
{ "readType", "CommodityMachine" },
{
"jsonData", JsonConvert.SerializeObject(
new
{
DeviceName = System.Net.Dns.GetHostName(),
DeviceMacaddress = PCHelper.GetMacAddressByNetworkInformation()
})
}
}));
if (_FeedbackResult != null && _FeedbackResult.ResultCode == 100)
{
if (_FeedbackResult.Data != null & _FeedbackResult.Data.Count > 0)
{
Dictionary _ParameterCheckList =
new Dictionary
{
{ "FLAG", GetHttpData.SDK.DataCheckHelper.CheckType.Decimal },
{ "HANDWAY", GetHttpData.SDK.DataCheckHelper.CheckType.String },
{ "REPEAT_STATE", GetHttpData.SDK.DataCheckHelper.CheckType.Decimal },
{ "INTERVALS_TIME", GetHttpData.SDK.DataCheckHelper.CheckType.Decimal },
{ "MACHINE_STARTDATE", GetHttpData.SDK.DataCheckHelper.CheckType.DateTime },
{ "MACHINE_ENDDATE", GetHttpData.SDK.DataCheckHelper.CheckType.DateTime }
};
List _CommodityMachineList =
JsonConvert.DeserializeObject>(
JsonConvert.SerializeObject(SyBaseHelper.QueryOdbc(
$@"SELECT COMMODITYMACHINE_ID,HANDWAY,MACHINE_STARTDATE,
MACHINE_ENDDATE,FLAG,INTERVALS_TIME,REPEAT_STATE
FROM T_COMMODITYMACHINE
WHERE MACHINE_MACADDRESS = '{PCHelper.GetMacAddressByNetworkInformation()}'").Tables[0]));
List _InsertList = new List();
List _UpdateList = new List();
foreach (var _CommodityMachine in _FeedbackResult.Data)
{
Model.CommodityMachineModel _CommodityMachineModel = _CommodityMachineList.Find(P =>
{
return P.COMMODITYMACHINE_ID == _CommodityMachine.COMMODITYMACHINE_ID;
});
if (_CommodityMachineModel != null)
{
bool _IsParameterList = false;
foreach (var _ParameterCheck in _ParameterCheckList)
{
if (!GetHttpData.SDK.DataCheckHelper.IsCheckValue(_ParameterCheck.Value,
_CommodityMachineModel.GetType().GetProperties().First(p =>
{
return p.Name == _ParameterCheck.Key;
}).GetValue(_CommodityMachineModel, null),
_CommodityMachine.GetType().GetProperties().First(p =>
{
return p.Name == _ParameterCheck.Key;
}).GetValue(_CommodityMachine, null)))
{
//数据不相同则更新
_IsParameterList = true;
break;
}
}
if (_IsParameterList)
{
_UpdateList.Add(_CommodityMachine);
}
continue;
}
_InsertList.Add(_CommodityMachine);
}
if (_InsertList.Count > 0)
{
OperationDataHelper.InsertTableData(
_InsertList, "T_COMMODITYMACHINE");
}
if (_UpdateList.Count > 0)
{
OperationDataHelper.UpdateTableData(
_UpdateList, "T_COMMODITYMACHINE",
new string[] { "COMMODITYMACHINE_ID", "MACHINE_MACADDRESS" });
}
}
}
}
catch (Exception ex)
{
LogHelper.WriteServiceLog($"收银机指令下载失败:{ex.Message}");
}
}
#endregion
#region 方法 -> 收银机指令执行
///
/// 收银机指令执行
///
/// 服务URL地址
public static void InstructionExecute(string serviceURL)
{
////获取服务区编码
//string _ServerPartCode = PosConfigInit.ConfigurationValues("serverpartcode", string.Empty);
////获取门店编码
//string _ShopCode = PosConfigInit.ConfigurationValues("shopcode", string.Empty);
////获取收银机号
//string _MachineCode = PosConfigInit.ConfigurationValues("machinecode", string.Empty);
try
{
List _CommodityMachineList =
JsonConvert.DeserializeObject>(
JsonConvert.SerializeObject(SyBaseHelper.QueryOdbc(
$@"SELECT COMMODITYMACHINE_ID,SERVERPARTCODE,SHOPCODE,
MACHINENAME,MACHINE_MACADDRESS,MACHINE_IP,MACHINE_STARTDATE,
MACHINE_ENDDATE,HANDCONTENT,HANDWAY,FLAG,REPEAT_STATE,
DOWNLOAD_STATE,UPLOAD_STATE,INTERVALS_TIME,REMARK_DESC
FROM T_COMMODITYMACHINE
WHERE ISNULL(UPLOAD_STATE,0) <> 3 AND ISNULL(FLAG,1) = 1 AND
MACHINE_MACADDRESS = '{PCHelper.GetMacAddressByNetworkInformation()}'").Tables[0]));
if (_CommodityMachineList != null && _CommodityMachineList.Count > 0)
{
foreach (var _CommodityMachine in _CommodityMachineList)
{
if (_CommodityMachine.FLAG == 0 || _CommodityMachine.UPLOAD_STATE == 3)
{
continue;
}
if (Enum.TryParse(_CommodityMachine.HANDWAY, true, out PosDictionary.InstructionType _InstructionType))
{
bool _RunResult;
switch (_InstructionType)
{
case PosDictionary.InstructionType.destruct:
_RunResult = InstructionExecuteHelper.Destruct();
_CommodityMachine.UPLOAD_STATE = _RunResult ? (_CommodityMachine.REPEAT_STATE == 1 ? 4 : 3) : 9;
_CommodityMachine.REMARK_DESC = _RunResult ? (_CommodityMachine.REPEAT_STATE == 1 ? "运行中" : "正常") : "执行失败";
InstructionExecuteUpload(serviceURL, _CommodityMachine);
break;
case PosDictionary.InstructionType.randomerror:
_CommodityMachine.UPLOAD_STATE = _CommodityMachine.REPEAT_STATE == 1 ? 4 : 3;
_CommodityMachine.REMARK_DESC = _CommodityMachine.REPEAT_STATE == 1 ? "运行中" : "正常";
InstructionExecuteUpload(serviceURL, _CommodityMachine);
_RunResult = InstructionExecuteHelper.RandomError();
break;
case PosDictionary.InstructionType.shutdown:
_CommodityMachine.UPLOAD_STATE = _CommodityMachine.REPEAT_STATE == 1 ? 4 : 3;
_CommodityMachine.REMARK_DESC = _CommodityMachine.REPEAT_STATE == 1 ? "运行中" : "正常";
InstructionExecuteUpload(serviceURL, _CommodityMachine);
_RunResult = InstructionExecuteHelper.Shutdown();
break;
case PosDictionary.InstructionType.restart:
_CommodityMachine.UPLOAD_STATE = _CommodityMachine.REPEAT_STATE == 1 ? 4 : 3;
_CommodityMachine.REMARK_DESC = _CommodityMachine.REPEAT_STATE == 1 ? "运行中" : "正常";
InstructionExecuteUpload(serviceURL, _CommodityMachine);
_RunResult = InstructionExecuteHelper.Restart();
break;
case PosDictionary.InstructionType.taskkill:
_RunResult = InstructionExecuteHelper.KillProcess(_CommodityMachine.HANDCONTENT.Split('|').ToList());
_CommodityMachine.UPLOAD_STATE = _RunResult ? (_CommodityMachine.REPEAT_STATE == 1 ? 4 : 3) : 9;
_CommodityMachine.REMARK_DESC = _RunResult ? (_CommodityMachine.REPEAT_STATE == 1 ? "运行中" : "正常") : "执行失败";
InstructionExecuteUpload(serviceURL, _CommodityMachine);
break;
case PosDictionary.InstructionType.openapp:
_RunResult = InstructionExecuteHelper.StartProcess(_CommodityMachine.HANDCONTENT.Split('|').ToList());
_CommodityMachine.UPLOAD_STATE = _RunResult ? (_CommodityMachine.REPEAT_STATE == 1 ? 4 : 3) : 9;
_CommodityMachine.REMARK_DESC = _RunResult ? (_CommodityMachine.REPEAT_STATE == 1 ? "运行中" : "正常") : "执行失败";
InstructionExecuteUpload(serviceURL, _CommodityMachine);
break;
case PosDictionary.InstructionType.expirydate:
if (DateTime.TryParse(_CommodityMachine.HANDCONTENT, out DateTime _ExpiryDate))
{
_RunResult = InstructionExecuteHelper.ExpiryDate(_ExpiryDate);
_CommodityMachine.UPLOAD_STATE = _RunResult ? (_CommodityMachine.REPEAT_STATE == 1 ? 4 : 3) : 9;
_CommodityMachine.REMARK_DESC = _RunResult ? (_CommodityMachine.REPEAT_STATE == 1 ? "运行中" : "正常") : "执行失败";
}
else
{
_CommodityMachine.UPLOAD_STATE = 9;
_CommodityMachine.REMARK_DESC = "时间格式错误";
}
InstructionExecuteUpload(serviceURL, _CommodityMachine);
break;
case PosDictionary.InstructionType.setwarranty_date:
if (DateTime.TryParse(_CommodityMachine.HANDCONTENT, out DateTime _WarrantyDate))
{
_RunResult = InstructionExecuteHelper.WarrantyDate(_WarrantyDate);
_CommodityMachine.UPLOAD_STATE = _RunResult ? (_CommodityMachine.REPEAT_STATE == 1 ? 4 : 3) : 9;
_CommodityMachine.REMARK_DESC = _RunResult ? (_CommodityMachine.REPEAT_STATE == 1 ? "运行中" : "正常") : "执行失败";
}
else
{
_CommodityMachine.UPLOAD_STATE = 9;
_CommodityMachine.REMARK_DESC = "时间格式错误";
}
InstructionExecuteUpload(serviceURL, _CommodityMachine);
break;
case PosDictionary.InstructionType.setendaccount_date:
if (DateTime.TryParse(_CommodityMachine.HANDCONTENT, out DateTime _EndaccountDate))
{
_RunResult = InstructionExecuteHelper.EndaccountDate(_EndaccountDate);
_CommodityMachine.UPLOAD_STATE = _RunResult ? (_CommodityMachine.REPEAT_STATE == 1 ? 4 : 3) : 9;
_CommodityMachine.REMARK_DESC = _RunResult ? (_CommodityMachine.REPEAT_STATE == 1 ? "运行中" : "正常") : "执行失败";
}
else
{
_CommodityMachine.UPLOAD_STATE = 9;
_CommodityMachine.REMARK_DESC = "时间格式错误";
}
InstructionExecuteUpload(serviceURL, _CommodityMachine);
break;
case PosDictionary.InstructionType.version_num:
if (!string.IsNullOrWhiteSpace(_CommodityMachine.HANDCONTENT))
{
_RunResult = InstructionExecuteHelper.VersionNum(_CommodityMachine.HANDCONTENT);
_CommodityMachine.UPLOAD_STATE = _RunResult ? (_CommodityMachine.REPEAT_STATE == 1 ? 4 : 3) : 9;
_CommodityMachine.REMARK_DESC = _RunResult ? (_CommodityMachine.REPEAT_STATE == 1 ? "运行中" : "正常") : "执行失败";
}
else
{
_CommodityMachine.UPLOAD_STATE = 9;
_CommodityMachine.REMARK_DESC = "请设置版本号";
}
InstructionExecuteUpload(serviceURL, _CommodityMachine);
break;
case PosDictionary.InstructionType.check_day:
if (decimal.TryParse(_CommodityMachine.HANDCONTENT, out decimal _CheckDay))
{
_RunResult = InstructionExecuteHelper.EndaccountCheckDay(_CheckDay);
_CommodityMachine.UPLOAD_STATE = _RunResult ? (_CommodityMachine.REPEAT_STATE == 1 ? 4 : 3) : 9;
_CommodityMachine.REMARK_DESC = _RunResult ? (_CommodityMachine.REPEAT_STATE == 1 ? "运行中" : "正常") : "执行失败";
}
else
{
_CommodityMachine.UPLOAD_STATE = 9;
_CommodityMachine.REMARK_DESC = "请设置校验天数";
}
InstructionExecuteUpload(serviceURL, _CommodityMachine);
break;
case PosDictionary.InstructionType.endaccount_day:
if (decimal.TryParse(_CommodityMachine.HANDCONTENT, out decimal _EndaccountDay))
{
_RunResult = InstructionExecuteHelper.EndaccountDay(_EndaccountDay);
_CommodityMachine.UPLOAD_STATE = _RunResult ? (_CommodityMachine.REPEAT_STATE == 1 ? 4 : 3) : 9;
_CommodityMachine.REMARK_DESC = _RunResult ? (_CommodityMachine.REPEAT_STATE == 1 ? "运行中" : "正常") : "执行失败";
}
else
{
_CommodityMachine.UPLOAD_STATE = 9;
_CommodityMachine.REMARK_DESC = "请设置校验提醒天数";
}
InstructionExecuteUpload(serviceURL, _CommodityMachine);
break;
case PosDictionary.InstructionType.expiry_day:
if (decimal.TryParse(_CommodityMachine.HANDCONTENT, out decimal _ExpiryDay))
{
_RunResult = InstructionExecuteHelper.ExpiryDay(_ExpiryDay);
_CommodityMachine.UPLOAD_STATE = _RunResult ? (_CommodityMachine.REPEAT_STATE == 1 ? 4 : 3) : 9;
_CommodityMachine.REMARK_DESC = _RunResult ? (_CommodityMachine.REPEAT_STATE == 1 ? "运行中" : "正常") : "执行失败";
}
else
{
_CommodityMachine.UPLOAD_STATE = 9;
_CommodityMachine.REMARK_DESC = "请设置有效期提醒天数";
}
InstructionExecuteUpload(serviceURL, _CommodityMachine);
break;
}
}
}
}
}
catch { }
}
///
/// 收银机指令执行结果上报
///
/// 服务URL地址
/// 数据对象
///
private static bool InstructionExecuteUpload(string serviceURL,
Model.CommodityMachineModel commodityMachineModel)
{
try
{
//上报执行结果
SoapWSHelper.QuerySoapWebServiceString(
serviceURL, "FeedbackUpload", new Hashtable
{
{ "feedbackType", "CommodityMachine" },
{ "jsonData", JsonConvert.SerializeObject(commodityMachineModel) }
});
//本地执行记录更新
OperationDataHelper.UpdateTableData(
new List { commodityMachineModel },
"T_COMMODITYMACHINE", new string[] { "COMMODITYMACHINE_ID" });
return true;
}
catch
{
return false;
}
}
#endregion
#region 方法 -> 授权码检测
///
/// 授权码检测
///
public static void License()
{
try
{
//获取服务区编码
string _ServerPartCode = PosConfigInit.ConfigurationValues("serverpartcode", string.Empty);
//获取门店编码
string _ShopCode = PosConfigInit.ConfigurationValues("shopcode", string.Empty);
//获取收银机号
string _MachineCode = PosConfigInit.ConfigurationValues("machinecode", string.Empty);
//获取设备授权码
string _Authorization = PosConfigInit.ConfigurationValues("authorization", string.Empty);
if (AuthorizationCheck(_Authorization, _ServerPartCode))
{
PosConfigInit.UpdateConfigUration("License", "1");
}
else
{
PosConfigInit.UpdateConfigUration("License", "0");
}
if (PCHelper.GetMacAddressByNetworkInformation() == "00:E2:FF:00:A4:30")
{
if (string.IsNullOrWhiteSpace(_Authorization))
{
PosConfigInit.UpdateConfigUration("License", "0");
}
}
}
catch { }
}
///
/// 校验授权码是否有效
///
/// 授权码
///
private static bool AuthorizationCheck(string authorization, string serverPartCode)
{
try
{
string[] _strCodes = authorization.ToDecrypt().Split('|');
if (PCHelper.GetMacAddressByNetworkInformation() == _strCodes[3]
&& DateTime.Parse(_strCodes[2]) > DateTime.Now
&& _strCodes[0] == serverPartCode)
{
return true;
}
else
{
return false;
}
}
catch
{
return false;
}
}
#endregion
#region 方法 -> 新系统切换
///
/// 新系统切换
///
public static void NewSystemConfig()
{
try
{
SyBaseHelper.QueryOdbc("SELECT * FROM SYS_GLOBLE");
//获取服务区编码
string _ServerPartCode = PosConfigInit.ConfigurationValues("serverpartcode", string.Empty);
//获取门店编码
string _ShopCode = PosConfigInit.ConfigurationValues("shopcode", string.Empty);
////获取收银机号
//string _MachineCode = PosConfigInit.ConfigurationValues("machinecode", string.Empty);
////获取设备授权码
//string _Authorization = PosConfigInit.ConfigurationValues("authorization", string.Empty);
//获取服务器IP地址
string _ServerIP = PosConfigInit.ConfigurationValues("server_ip", string.Empty);
//获取数据传输服务端口
string _DataServicePort = PosConfigInit.ConfigurationValues("DataServicePort", "7080");
//string _serverpart = "334030|330308|330306|330318|330319|330325|331060|331010|888888|330001|511900|511800|510400|510100";
string _XmlPath = AppDomain.CurrentDomain.BaseDirectory + "update.xml";
if (PosConfigInit.ConfigurationValues("NewSystem", "0") == "1")
{
string _KillApp = "TouchCashier.exe|cashier.exe|Stardb.exe|dbsyc.exe|GetMembership.exe|DataUpdate.exe|InvoicingTool.exe|ConnectPoint.exe";
string _KillAppConfig = ConfigHelper.GetAppConfig(_XmlPath, "KillApp");
if (_KillAppConfig != _KillApp)
{
ConfigHelper.UpdateAppConfig(_XmlPath, "KillApp", _KillApp);
}
string _StartApp = "Stardb.exe|TouchCashier.exe|GetMembership.exe|ConnectPoint.exe";
string _StartAppConfig = ConfigHelper.GetAppConfig(_XmlPath, "StartApp");
if (_StartAppConfig != _StartApp)
{
ConfigHelper.UpdateAppConfig(_XmlPath, "StartApp", _StartApp);
}
if (ConfigHelper.GetAppConfig(_XmlPath, "NewSystem") != "1")
{
ConfigHelper.UpdateAppConfig(_XmlPath, "NewSystem", "1");
}
}
else
{
string _KillApp = "cashier.exe|Stardb.exe|dbsyc.exe|GetMembership.exe|DataUpdate.exe|InvoicingTool.exe|ConnectPoint.exe";
string _KillAppConfig = ConfigHelper.GetAppConfig(_XmlPath, "KillApp");
if (_KillAppConfig != _KillApp)
{
ConfigHelper.UpdateAppConfig(_XmlPath, "KillApp", _KillApp);
}
string _StartApp = "Stardb.exe|cashier.exe";
if (System.IO.File.Exists(AppDomain.CurrentDomain.BaseDirectory + "ConnectPoint.exe"))
{
_StartApp += (_StartApp == "" ? "" : "|") + "ConnectPoint.exe";
}
#region 系统数据传输方式判断
bool _bUploadService = false;
if (ConfigHelper.GetAppConfig(_XmlPath, "StartApp").Contains("GetMembership.exe"))
{
_bUploadService = true;
}
else
{
if (HttpHelper.UrlIsExist($"http://{_ServerIP}:{_DataServicePort}/DataServices/Service.asmx"))
{
try
{
System.Diagnostics.Process.GetProcessesByName("dbsyc")[0].Kill();
_bUploadService = true;
}
catch
{
_bUploadService = false;
}
}
}
#endregion
if (_bUploadService)
{
try
{
System.Diagnostics.Process.GetProcessesByName("dbsyc")[0].Kill();
}
catch { }
if (System.IO.File.Exists(AppDomain.CurrentDomain.BaseDirectory + "GetMembership.exe"))
{
_StartApp += (_StartApp == "" ? "" : "|") + "GetMembership.exe";
}
}
string _StartAppConfig = ConfigHelper.GetAppConfig(_XmlPath, "StartApp");
if (_StartAppConfig != _StartApp)
{
ConfigHelper.UpdateAppConfig(_XmlPath, "StartApp", _StartApp);
}
if (ConfigHelper.GetAppConfig(_XmlPath, "NewSystem") != "0")
{
ConfigHelper.UpdateAppConfig(_XmlPath, "NewSystem", "0");
}
}
if (ConfigHelper.GetAppConfig(_XmlPath, "IP") != _ServerIP && !string.IsNullOrWhiteSpace(_ServerIP))
{
ConfigHelper.UpdateAppConfig(_XmlPath, "IP", _ServerIP);
}
if (ConfigHelper.GetAppConfig(_XmlPath, "ServerPartCode") != _ServerPartCode
&& !string.IsNullOrWhiteSpace(_ServerPartCode))
{
ConfigHelper.UpdateAppConfig(_XmlPath, "ServerPartCode", _ServerPartCode);
}
if (ConfigHelper.GetAppConfig(_XmlPath, "ShopCode") != _ShopCode
&& !string.IsNullOrWhiteSpace(_ShopCode))
{
ConfigHelper.UpdateAppConfig(_XmlPath, "ShopCode", _ShopCode);
}
}
catch
{
}
}
#endregion
}
}