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.Runtime.InteropServices; 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 { /// /// MainWindow.xaml 的交互逻辑 /// public partial class MainWindow : Window { EncodingOptions options = null; BarcodeWriter writer = null; public MainWindow() { InitializeComponent(); } /// /// 中文空白字符,用于替换空格 /// private static string ChineseSpace = " "; /// /// 汉字转区位码方法 /// /// 汉字 /// 区位码 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; } } /// /// 区位码转汉字方法 /// /// 区位码 /// 汉字 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 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) { string text = com.ccb.wlpt.RequestProcess.initFileCert("", "", "", "", ""); //Dictionary parm = new Dictionary(); //parm.Add("TicketCode", "33000502201020190904174800");//商户订单号 //parm.Add("time_stamp", Convert.ToInt32((DateTime.Now - // new DateTime(1970, 1, 1, 0, 0, 0)).TotalSeconds).ToString()); //时间戳 // //parm.Add("PlatformCode", "");//平台订单号 // //添加签名信息 //parm.Add("sign", ParamSign(parm, "330005022010", "4E65EFCB223C7089F32C0D5E18442995")); //string _strServiceURL = $"http://192.168.11.190:7082/service.asmx"; //Hashtable hashtable = new Hashtable //{ // { "url", $"http://183.129.232.104:7000/Service.asmx" }, // { "methodName", "OrderQuery"}, // { // "parameter", // JsonConvert.SerializeObject(new Hashtable // { // { "code", "330005022010" }, // { "jsonString", JsonConvert.SerializeObject(parm) } // }) // } //}; ////调用代理接口转发支付请求并接收结果 //string retString = ESSupport.Lib.SoapWSHelper.QuerySoapWebServiceString(_strServiceURL, "ProxyInterface", hashtable); //// Common.PosControl.MemberPayResult memberPayResult = JsonConvert.DeserializeObject(retString); //return; //System.Net.NetworkInformation.Ping _Ping = new System.Net.NetworkInformation.Ping(); //while (true) //{ // try // { // System.Net.NetworkInformation.PingReply reply = _Ping.Send("192.168.11.255", 120); // Console.WriteLine(reply.Status + "(" + reply.RoundtripTime + ")"); // } // catch (Exception ex) { } //} GetQRCode(); return; //string c = ""; //using (RFSupport.RFCard _RFCard = new RFSupport.RFCard()) //{ // c = _RFCard.ReadCardCode(); //} //MessageBox.Show(c); //return; //StringBuilder stringBuilder = new StringBuilder(512); byte[] stringBuilder = new byte[512]; //IntPtr stringBuilder = new IntPtr(512); string _configPath = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "config.ini"); string req = ""; req += "com.pax.pay.xwappt".PadRight(30, ' '); //不足 30 位,右补空格 req += "02"; req += "0"; req += "2".PadLeft(12, '0'); //金额分单位,不足 12 位,左补 0 req += "".PadLeft(6, '0'); //无,不足 6 位,左补 0 req += "".PadLeft(12, ' '); //无,不足 12 位,右补空格 req += "".PadRight(4, ' '); //无,不足 4 位,右补空格 req += "".PadRight(6, ' '); //无,不足 6 位,右补空格 req += (DateTime.Now.ToString("yyyyMMddHHmmss") + "0001").PadRight(20, ' '); //不足 20 位,右补空格 req += "".PadRight(40, ' '); //不足 40 位,右补空格 req += "".PadLeft(2, '0'); //无,不足 2 位,左补 0 int re = BankPay.PAXPAY_Trans(_configPath, req, stringBuilder); //string _Result = Marshal.PtrToStringAnsi(stringBuilder); string _Result = Encoding.Default.GetString(stringBuilder); byte[] _b = new byte[40]; Array.Copy(stringBuilder, 128, _b, 0, 40); string _r = Encoding.Default.GetString(_b); MessageBox.Show(re + "\n" + _configPath + "\n" + req + "\n" + _Result); int s = stringBuilder.Length; 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' DataSet _DataSet = new DataSet(); DataTable _DataTable = new DataTable(); _DataTable.TableName = "Configuration"; _DataTable.Columns.Add("k", typeof(string)); _DataTable.Columns.Add("v", typeof(string)); //_DataTable.Rows.Add("server_ip", "171.221.201.162"); //_DataTable.Rows.Add("MobilePayOperators", "1005"); //_DataTable.Rows.Add("service_port", "7081");//1521 //_DataTable.Rows.Add("service_port2", "7080"); //_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("CommoditySaleURL", "http://cloud.eshangtech.com/ScanUpdate/CommoditySale.html"); _DataTable.Rows.Add("EndAccountURL", "http://cloud.eshangtech.com/ScanUpdate/EndAccount.html"); _DataTable.Rows.Add("ScanAuditURL", "http://cloud.eshangtech.com/ScanUpdate/ScanAudit.html"); //_DataTable.Rows.Add("USING_TYPE", "1000"); //_DataTable.Rows.Add("expirydate", softerdate.SelectedDate.Value.ToString("yyyy/MM/dd HH:mm:ss")); //_DataTable.Rows.Add("syncdtime", "2019/09/12 14:28:53"); //List _Config = new List(); //_Config.Add(new { k = "CommoditySaleURL", v = "http://60.12.57.14:6060/ScanUpdate/CommoditySale.html" }); //_Config.Add(new { k = "EndAccountURL", v = "http://60.12.57.14:6060/ScanUpdate/EndAccount.html" }); //_Config.Add(new { k = "ScanAuditURL", v = "http://60.12.57.14:6060/ScanUpdate/ScanAudit.html" }); _DataSet.Tables.Add(_DataTable); 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")); //Bitmap bitmap = writer.Write(Newtonsoft.Json.JsonConvert.SerializeObject(_DataSet)); 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 _InsertList = new List(); 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; } } }