410 lines
19 KiB
C#
410 lines
19 KiB
C#
using Newtonsoft.Json;
|
||
using Newtonsoft.Json.Linq;
|
||
using System;
|
||
using System.Collections;
|
||
using System.Collections.Generic;
|
||
using System.Data;
|
||
using System.Drawing;
|
||
using System.IO;
|
||
using System.IO.Ports;
|
||
using System.Linq;
|
||
using System.Net;
|
||
using System.Net.Sockets;
|
||
using System.Security.Cryptography;
|
||
using System.Text;
|
||
using System.Windows;
|
||
using System.Windows.Controls;
|
||
using System.Windows.Data;
|
||
using System.Windows.Documents;
|
||
using System.Windows.Input;
|
||
using System.Windows.Media;
|
||
using System.Windows.Media.Imaging;
|
||
using System.Windows.Navigation;
|
||
using System.Windows.Shapes;
|
||
using ZXing;
|
||
using ZXing.Common;
|
||
using ZXing.QrCode;
|
||
using Lib = ESSupport.Lib;
|
||
namespace PosSystemConfig
|
||
{
|
||
/// <summary>
|
||
/// MainWindow.xaml 的交互逻辑
|
||
/// </summary>
|
||
public partial class MainWindow : Window
|
||
{
|
||
EncodingOptions options = null;
|
||
BarcodeWriter writer = null;
|
||
|
||
public MainWindow()
|
||
{
|
||
InitializeComponent();
|
||
}
|
||
/// <summary>
|
||
/// 中文空白字符,用于替换空格
|
||
/// </summary>
|
||
private static string ChineseSpace = " ";
|
||
|
||
/// <summary>
|
||
/// 汉字转区位码方法
|
||
/// </summary>
|
||
/// <param name="character">汉字</param>
|
||
/// <returns>区位码</returns>
|
||
public static string ChineseToCoding(string character)
|
||
{
|
||
string coding = string.Empty;
|
||
|
||
//空格处理(如不用可以注释)
|
||
character = character.Replace(" ", ChineseSpace);
|
||
|
||
try
|
||
{
|
||
for (int i = 0; i < character.Length; i++)
|
||
{
|
||
byte[] bytes = Encoding.GetEncoding("GB2312").GetBytes(character.Substring(i, 1));
|
||
if (bytes.Length == 2)
|
||
{
|
||
string lowCode = System.Convert.ToString(bytes[0] - 160, 10);
|
||
if (lowCode.Length == 1)
|
||
lowCode = "0" + lowCode;
|
||
string hightCode = System.Convert.ToString(bytes[1] - 160, 10);
|
||
if (hightCode.Length == 1)
|
||
hightCode = "0" + hightCode;
|
||
coding += (lowCode + hightCode);
|
||
}
|
||
else
|
||
{
|
||
string lowCode = System.Convert.ToString(bytes[0], 16);
|
||
if (lowCode.Length == 1)
|
||
lowCode = "0" + lowCode;
|
||
coding += (lowCode);
|
||
}
|
||
}
|
||
return coding;
|
||
}
|
||
catch
|
||
{
|
||
return null;
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 区位码转汉字方法
|
||
/// </summary>
|
||
/// <param name="coding">区位码</param>
|
||
/// <returns>汉字</returns>
|
||
public static string CodingToChinese(string coding)
|
||
{
|
||
string characters = string.Empty;
|
||
if (coding.Length % 4 != 0)//编码为16进制,必须为4的倍数。
|
||
{
|
||
throw new System.Exception("编码格式不正确");
|
||
}
|
||
for (int i = 0; i < coding.Length / 4; i++)
|
||
{
|
||
byte[] bytes = new byte[2];
|
||
int j = i * 4;
|
||
string lowCode = coding.Substring(j, 2); //取出低字节,并以16进制进制转换
|
||
bytes[0] = System.Convert.ToByte(lowCode, 16);
|
||
string highCode = coding.Substring(j + 2, 2); //取出高字节,并以16进制进行转换
|
||
bytes[1] = System.Convert.ToByte(highCode, 16);
|
||
string character = Encoding.GetEncoding("GB2312").GetString(bytes);
|
||
characters += character;
|
||
}
|
||
|
||
//空格复原(将中文空白字符转换普通空格)
|
||
characters = characters.Replace(ChineseSpace, " ");
|
||
|
||
return characters;
|
||
}
|
||
static void sc_DataReceived(object sender, SerialDataReceivedEventArgs e, byte[] bits)
|
||
{
|
||
//Console.WriteLine(BitConverter.ToString(bits));
|
||
string[] _strScale = BitConverter.ToString(bits).Split('-');
|
||
if (_strScale.Length >= 7)
|
||
{
|
||
//Console.WriteLine(_strScale[2].Substring(1) + _strScale[3].Substring(1) + _strScale[4].Substring(1) + _strScale[5].Substring(1) + _strScale[6].Substring(1));
|
||
Console.WriteLine(decimal.Parse(_strScale[2].Substring(1) + _strScale[3].Substring(1) + _strScale[4].Substring(1) + _strScale[5].Substring(1) + _strScale[6].Substring(1)) / 1000);
|
||
}
|
||
}
|
||
static Lib.SerialClass sc;
|
||
int i = 0;
|
||
public static string ParamSign(Dictionary<string, string> signParm, string MD5code, string MD5Key)
|
||
{
|
||
var list = signParm.OrderBy(s => s.Key);
|
||
string str = "";
|
||
foreach (var ss in list)
|
||
{
|
||
if (!string.IsNullOrWhiteSpace(ss.Value))
|
||
str += (string.IsNullOrWhiteSpace(str) ? "" : "&") + ss.Key + "=" + ss.Value;
|
||
}
|
||
//str = signParm.OrderBy(p => p.Key).Select(pair => pair.Key + "=" + pair.Value.ToString()).DefaultIfEmpty("").Aggregate((a, b) => a + "&" + b);
|
||
if (!string.IsNullOrEmpty(MD5code))
|
||
{
|
||
str += "&code=" + MD5code;
|
||
}
|
||
if (!string.IsNullOrEmpty(MD5Key))
|
||
{
|
||
str += "&key=" + MD5Key;
|
||
}
|
||
|
||
str = BitConverter.ToString(MD5.Create().ComputeHash(Encoding.UTF8.GetBytes(str))).Replace("-", "").ToUpper();
|
||
return str;
|
||
}
|
||
private void Button_Click(object sender, RoutedEventArgs e)
|
||
{
|
||
//i++;
|
||
|
||
//Dictionary<string, string> parm = new Dictionary<string, string>();
|
||
////parm.Add("Membership_Type", "");
|
||
////parm.Add("Membership_Name", "测试会员");
|
||
////parm.Add("Membership_Mobilephone", "");
|
||
////parm.Add("Start_Date", "20170101000000");
|
||
////parm.Add("End_Date", DateTime.Now.ToString("yyyyMMddHHmmss"));
|
||
////parm.Add("Membership_ID", "");
|
||
//parm.Add("Membership_Card", "0000000001");
|
||
////parm.Add("ECode", "");
|
||
////parm.Add("ICCard_Code", "");
|
||
//parm.Add("MachineCode", "5422");
|
||
//parm.Add("TicketCode", "1351321651354" + i.ToString());
|
||
////parm.Add("PlatformCode", "88888801200220190513140457");
|
||
////parm.Add("TicketCode", "135132165135315");
|
||
//parm.Add("Recode_Type", "3000");
|
||
//parm.Add("Recode_Amount", "0.01");
|
||
////parm.Add("Refund_Amount", "0.01");
|
||
//parm.Add("time_stamp", Convert.ToInt32((DateTime.Now - new DateTime(1970, 1, 1, 0, 0, 0)).TotalSeconds).ToString());
|
||
//parm.Add("sign", ParamSign(parm, "888888012002", "17018EAF3EEBB72A0834F709EAA11D4B"));
|
||
|
||
//Hashtable _Hashtable = new Hashtable();
|
||
//_Hashtable.Add("code", "888888012002");
|
||
//_Hashtable.Add("jsonString", JsonConvert.SerializeObject(parm));
|
||
////JObject _JObject = JObject.Parse(JsonConvert.SerializeObject(parm));
|
||
//try
|
||
//{
|
||
// //string result = Lib.SoapWSHelper.QuerySoapWebServiceString("http://192.168.10.110:7080/DataServices/Service.asmx", "OrderQuery", _Hashtable);
|
||
// string result = Lib.SoapWSHelper.QuerySoapWebServiceString("http://60.191.61.26:7081/Service.asmx", "OrderPay", _Hashtable);
|
||
// MessageBox.Show(result, "");
|
||
//}
|
||
//catch { }
|
||
//i++;
|
||
//if (sc == null)
|
||
//{
|
||
// sc = new Lib.SerialClass("COM3");
|
||
//}
|
||
//else
|
||
//{
|
||
// sc.ClosePort();
|
||
// sc = new Lib.SerialClass("COM3");
|
||
//}
|
||
//int o = i;
|
||
//sc.DataReceived += delegate (object senders, SerialDataReceivedEventArgs es, byte[] bits)
|
||
//{
|
||
// string[] _strScale = BitConverter.ToString(bits).Split('-');
|
||
// if (_strScale.Length >= 7)
|
||
// {
|
||
// //Console.WriteLine(_strScale[2].Substring(1) + _strScale[3].Substring(1) + _strScale[4].Substring(1) + _strScale[5].Substring(1) + _strScale[6].Substring(1));
|
||
// Console.WriteLine(o + ":" + decimal.Parse(_strScale[2].Substring(1) + _strScale[3].Substring(1) + _strScale[4].Substring(1) + _strScale[5].Substring(1) + _strScale[6].Substring(1)) / 1000);
|
||
// }
|
||
//};
|
||
//sc.OpenPort();
|
||
//sc.SendData(new byte[] { 0x50 }, 0, 1);
|
||
//sc.SendData("!0R");
|
||
// sc.SendData("!0V0004A2281084002500100000000803000000000000000000000000000000000000000000000000B34734801CDE");
|
||
// Console.ReadLine();
|
||
// sc.ClosePort();
|
||
//Socket mySocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
|
||
//IPAddress ipAddress = IPAddress.Parse("192.168.11.124");
|
||
//IPEndPoint ipEndPoint = new IPEndPoint(ipAddress, 4001);
|
||
|
||
//mySocket.Connect(ipEndPoint);
|
||
////mySocket.Send(System.Text.Encoding.Default.GetBytes(ChineseToCoding("1P0005A2281080002000000000000803000000000000000100000020106100712201318301924400##测试一##测试一##测试一")));
|
||
//mySocket.Send(System.Text.Encoding.Default.GetBytes("!0V0004A2281084002500100000000803000000000000000000000000000000000000000000000000B34734801CDE"));
|
||
|
||
//mySocket.Close();
|
||
|
||
//MessageBox.Show((1 == 1 ? 1 * 2 : 2 * 6).ToString());
|
||
GetQRCode();
|
||
return;
|
||
//MessageBox.Show("1.wmv|" + Lib.FileHelper.GetMD5ByHashAlgorithm(@"F:\EShangTech\99_工作报表\试播内容\试播1227.wmv"));
|
||
//MessageBox.Show("2.mpg|" + Lib.FileHelper.GetMD5ByHashAlgorithm(@"F:\EShangTech\99_工作报表\试播内容\杭州禁毒公益广告.mp4"));
|
||
//MessageBox.Show("3.mp4|" + Lib.FileHelper.GetMD5ByHashAlgorithm(@"F:\EShangTech\99_工作报表\试播内容\十二茶涧.mp4"));
|
||
if (String.IsNullOrWhiteSpace(txtIP.Text.Trim()))
|
||
{
|
||
MessageBox.Show("服务器IP不能为空", "系统提示");
|
||
txtIP.Focus();
|
||
txtIP.SelectAll();
|
||
return;
|
||
}
|
||
if (String.IsNullOrWhiteSpace(txtPort.Text.Trim()))
|
||
{
|
||
MessageBox.Show("服务器端口不能为空", "系统提示");
|
||
txtPort.Focus();
|
||
txtPort.SelectAll();
|
||
return;
|
||
}
|
||
if (String.IsNullOrWhiteSpace(txtConName.Text.Trim()))
|
||
{
|
||
MessageBox.Show("数据库实例名不能为空", "系统提示");
|
||
txtConName.Focus();
|
||
txtConName.SelectAll();
|
||
return;
|
||
}
|
||
if (String.IsNullOrWhiteSpace(txtDbName.Text.Trim()))
|
||
{
|
||
MessageBox.Show("数据库用户名不能为空", "系统提示");
|
||
txtDbName.Focus();
|
||
txtDbName.SelectAll();
|
||
return;
|
||
}
|
||
if (String.IsNullOrWhiteSpace(txtDbUser.Text.Trim()))
|
||
{
|
||
MessageBox.Show("数据库登录名不能为空", "系统提示");
|
||
txtDbUser.Focus();
|
||
txtDbUser.SelectAll();
|
||
return;
|
||
}
|
||
if (String.IsNullOrWhiteSpace(txtDbPass.Text.Trim()))
|
||
{
|
||
MessageBox.Show("数据库密码不能为空", "系统提示");
|
||
txtDbPass.Focus();
|
||
txtDbPass.SelectAll();
|
||
return;
|
||
}
|
||
if (String.IsNullOrWhiteSpace(txtServerPart.Text.Trim()))
|
||
{
|
||
MessageBox.Show("服务区编码不能为空", "系统提示");
|
||
txtServerPart.Focus();
|
||
txtServerPart.SelectAll();
|
||
return;
|
||
}
|
||
if (String.IsNullOrWhiteSpace(txtShop.Text.Trim()))
|
||
{
|
||
MessageBox.Show("门店编码不能为空", "系统提示");
|
||
txtShop.Focus();
|
||
txtShop.SelectAll();
|
||
return;
|
||
}
|
||
if (String.IsNullOrWhiteSpace(txtMachine.Text.Trim()))
|
||
{
|
||
MessageBox.Show("收银机号不能为空", "系统提示");
|
||
txtMachine.Focus();
|
||
txtMachine.SelectAll();
|
||
return;
|
||
}
|
||
string _strConfig = String.Format("数据库IP:{0}\n数据库端口:{1}\n数据库实例:{2}\n数据库用户名:{3}" +
|
||
"\n数据库登录名:{4}\n数据库密码:{5}\n服务区编码:{6}\n门店编码:{7}\n收银机号:{8}",
|
||
txtIP.Text.Trim(), txtPort.Text.Trim(), txtConName.Text.Trim(), txtDbName.Text.Trim(), txtDbUser.Text.Trim(),
|
||
txtDbPass.Text.Trim(), txtServerPart.Text.Trim(), txtShop.Text.Trim(), txtMachine.Text.Trim());
|
||
if (MessageBox.Show(_strConfig + "\n确认配置无误并生成配置二维码?", "系统提示", MessageBoxButton.YesNo,
|
||
MessageBoxImage.Question, MessageBoxResult.Yes, MessageBoxOptions.None) == MessageBoxResult.Yes)
|
||
{
|
||
GetQRCode();
|
||
}
|
||
}
|
||
private void GetQRCode()
|
||
{
|
||
//'serverpartcode','shopcode','machinecode','server_ip','service_port'
|
||
DataTable _DataTable = new DataTable();
|
||
_DataTable.Columns.Add("k", typeof(string));
|
||
_DataTable.Columns.Add("v", typeof(string));
|
||
//_DataTable.Rows.Add("server_ip", "10.120.18.1");
|
||
//_DataTable.Rows.Add("MobilePayOperators", "1005");
|
||
//_DataTable.Rows.Add("service_port", "7081");//1521
|
||
//_DataTable.Rows.Add("service_port2", "7081");//1521
|
||
//_DataTable.Rows.Add("service_port3", "7081");//1521
|
||
//_DataTable.Rows.Add("service_port4", "7081");//1521
|
||
//_DataTable.Rows.Add("service_port5", "7081");//1521
|
||
//_DataTable.Rows.Add("DataServicePort", "7080");
|
||
_DataTable.Rows.Add("mobile_pay", "1");
|
||
//_DataTable.Rows.Add("server_ip", txtIP.Text.Trim());
|
||
//_DataTable.Rows.Add("server_dbport", txtPort.Text.Trim());//1521
|
||
//_DataTable.Rows.Add("server_conname", txtConName.Text.Trim());//orcl
|
||
//_DataTable.Rows.Add("server_dbname", txtDbName.Text.Trim());//highway_exchange
|
||
//_DataTable.Rows.Add("server_dbuser", txtDbUser.Text.Trim());//highway_exchange
|
||
//_DataTable.Rows.Add("server_dbpass", txtDbPass.Text.Trim());//qrwl
|
||
//_DataTable.Rows.Add("serverpartcode", txtServerPart.Text.Trim());
|
||
//_DataTable.Rows.Add("shopcode", txtShop.Text.Trim());
|
||
//_DataTable.Rows.Add("machinecode", txtMachine.Text.Trim());
|
||
//_DataTable.Rows.Add("member_ip", "183.129.232.100");
|
||
//_DataTable.Rows.Add("member_port", "8010");
|
||
//_DataTable.Rows.Add("quick_sale", "0");
|
||
//_DataTable.Rows.Add("expirydate", "2021-10-12");
|
||
options = new QrCodeEncodingOptions
|
||
{
|
||
DisableECI = true,
|
||
CharacterSet = "UTF-8",
|
||
Width = (int)picQRCode.Height,
|
||
Height = (int)picQRCode.Width
|
||
};
|
||
writer = new BarcodeWriter
|
||
{
|
||
Format = BarcodeFormat.QR_CODE,
|
||
Options = options
|
||
};
|
||
Bitmap bitmap = writer.Write(Lib.JsonHelper.ToJson(_DataTable, "Configuration"));
|
||
picQRCode.Source = BitmapToBitmapImage(bitmap);
|
||
}
|
||
private BitmapImage BitmapToBitmapImage(Bitmap bitmap)
|
||
{
|
||
BitmapImage bitmapImage = new BitmapImage();
|
||
using (MemoryStream ms = new MemoryStream())
|
||
{
|
||
bitmap.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp);
|
||
bitmapImage.BeginInit();
|
||
bitmapImage.StreamSource = ms;
|
||
bitmapImage.CacheOption = BitmapCacheOption.OnLoad;
|
||
bitmapImage.EndInit();
|
||
bitmapImage.Freeze();
|
||
}
|
||
return bitmapImage;
|
||
}
|
||
|
||
private void Button_Click_1(object sender, RoutedEventArgs e)
|
||
{
|
||
}
|
||
private bool CerSale(string endaccountCode, string serverPartCode, string shopCode,
|
||
string machineCode, string sellWorkerCode, DateTime startDate, DateTime endDate, int workerNumber)
|
||
{
|
||
int _Maxid = 0;
|
||
try
|
||
{
|
||
_Maxid = ((int)Lib.SyBaseHelper.QueryOdbc(
|
||
@"SELECT MAX(COMMODITYSALE_ID) FROM T_COMMODITYSALE_NEW").Tables[0].Rows[0][0]) + 1;
|
||
}
|
||
catch
|
||
{
|
||
_Maxid = 1;
|
||
}
|
||
string _SaleSql = string.Format(
|
||
@"SELECT A.COMMODITY_CODE,A.COMMODITY_BARCODE,
|
||
A.COMMODITY_TYPE,A.COMMODITY_NAME,A.COMMODITY_SYMBOL,
|
||
COUNT(A.SELLMASTER_CODE) AS TICKTE_COUNT,
|
||
ISNULL(SUM(A.SELLDETAILS_COUNT), 0) AS TOTAL_COUNT,
|
||
ISNULL(SUM(A.SELLDETAILS_AMOUNT), 0) AS TOTAL_AMOUNT,
|
||
ISNULL(SUM(A.SELLDETAILS_OFFPRICE), 0) AS TOTAL_OFFAMOUNT
|
||
FROM T_SELLDETAILS A,T_SELLMASTER B
|
||
WHERE A.SELLMASTER_CODE = B.SELLMASTER_CODE AND B.SELLWORKER_CODE='{5}' AND
|
||
B.SERVERPARTCODE = '{0}' AND B.SHOPCODE='{1}' AND B.MACHINECODE='{2}' AND
|
||
B.SELLMASTER_DATE BETWEEN DATETIME('{3}') AND DATETIME('{4}')
|
||
GROUP BY A.COMMODITY_CODE,A.COMMODITY_NAME,
|
||
A.COMMODITY_BARCODE,A.COMMODITY_TYPE,A.COMMODITY_SYMBOL",
|
||
serverPartCode, shopCode, machineCode, startDate.ToString("yyyy/MM/dd HH:mm:ss"),
|
||
endDate.ToString("yyyy/MM/dd HH:mm:ss"), sellWorkerCode);
|
||
DataTable _DataTable = Lib.SyBaseHelper.QueryOdbc(_SaleSql).Tables[0];
|
||
List<string> _InsertList = new List<string>();
|
||
for (int i = 0; i < _DataTable.Rows.Count; i++)
|
||
{
|
||
_InsertList.Add("INSERT INTO T_COMMODITYSALE_NEW (COMMODITYSALE_ID,ENDACCOUNT_CODE,COMMODITY_TYPE," +
|
||
"COMMODITY_CODE,COMMODITY_BARCODE,COMMODITY_NAME,TICKTE_COUNT,TOTAL_COUNT,TOTAL_AMOUNT," +
|
||
"TOTAL_OFFAMOUNT,WOKER_NUMBER,TRANSFER_STATE,CREATE_DATE,COMMODITY_SYMBOL) " +
|
||
"VALUES (" + (_Maxid + i) + ",'" + endaccountCode + "','" + _DataTable.Rows[i]["COMMODITY_TYPE"].ToString() +
|
||
"','" + _DataTable.Rows[i]["COMMODITY_CODE"].ToString() + "','" + _DataTable.Rows[i]["COMMODITY_BARCODE"].ToString() +
|
||
"','" + _DataTable.Rows[i]["COMMODITY_NAME"].ToString() + "'," + _DataTable.Rows[i]["TICKTE_COUNT"].ToString() +
|
||
"," + _DataTable.Rows[i]["TOTAL_COUNT"].ToString() + "," + _DataTable.Rows[i]["TOTAL_AMOUNT"].ToString() +
|
||
"," + _DataTable.Rows[i]["TOTAL_OFFAMOUNT"].ToString() + "," + workerNumber +
|
||
",0,DATETIME('" + endDate.ToString("yyyy/MM/dd HH:mm:ss") + "'),'" + _DataTable.Rows[i]["COMMODITY_SYMBOL"].ToString() + "')");
|
||
}
|
||
return true;
|
||
}
|
||
}
|
||
}
|