using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Data.Odbc; using System.Drawing; using System.Linq; using System.Runtime.InteropServices; using System.Text; using System.Web; using System.Windows.Forms; using ZXing; using ZXing.Common; using ZXing.QrCode; namespace DataUpdate { public partial class ScanAudit : Form { //调用API [DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true)] public static extern IntPtr GetForegroundWindow(); //获得本窗体的句柄 [DllImport("user32.dll", EntryPoint = "SetForegroundWindow")] public static extern bool SetForegroundWindow(IntPtr hWnd);//设置此窗体为活动窗体 //AppID(应用ID) public string AppID = "wxcf4dbe1815d5d872"; EncodingOptions options = null; BarcodeWriter writer = null; string _type; public string serverpartcode { get { return ConfigUrationValues("serverpartcode", "").Trim(); } } public string shopcode { get { return ConfigUrationValues("shopcode", "").Trim(); } } public string machinecode { get { return ConfigUrationValues("machinecode", "").Trim(); } } public string ScanAuditURL { get { return ConfigUrationValues("ScanAuditURL", "http://syyw.eshangtech.com:8060/ScanUpdate/ScanAudit.html").Trim(); } } public ScanAudit(string[] type) { InitializeComponent(); _type = type[0]; QRCodeAudit(); } private void MainTop_Tick(object sender, EventArgs e) { if (Handle != GetForegroundWindow()) //持续使该窗体置为最前,屏蔽该行则单次置顶 { SetForegroundWindow(Handle); } } private void QRCodeAudit() { switch (ConfigUrationValues("ScanAuditURL", "http://syyw.eshangtech.com:8060/ScanUpdate/ScanAudit.html")) { case "http://syyw.eshangtech.com:8060/ScanUpdate/ScanAudit.html": AppID = "wx858626d07d286094"; lblProvince.Text = "当前上传省份:四川"; break; case "http://cloud.eshangtech.com:8000/ScanUpdate/ScanAudit.html": AppID = "wx85e69a5fb601be16"; lblProvince.Text = "当前上传省份:浙江"; break; case "http://cloud.eshangtech.com:8000/ScanUpdate_GZ/ScanAudit.html": AppID = "wxeba135b691515795"; lblProvince.Text = "当前上传省份:贵州"; break; case "http://cloud.eshangtech.com:8000/ScanUpdate_Test/ScanAudit.html": AppID = "wxcf4dbe1815d5d872"; lblProvince.Text = "当前上传省份:驿商测试"; break; case "http://113.16.255.162:6060/ScanUpdate/ScanAudit.html": AppID = "wx84783c575daaea05"; lblProvince.Text = "当前上传省份:广西恒信"; break; case "http://60.191.61.27:8080/ScanUpdate/ScanAudit.html": AppID = "wxcafd073c85194384"; lblProvince.Text = "当前上传省份:广西交投"; break; case "http://47.92.38.105:6060/ScanUpdate/ScanAudit.html": AppID = "wx201f8336954afc75"; lblProvince.Text = "当前上传省份:甘肃"; break; case "http://220.177.42.231:6060/ScanUpdate/ScanAudit.html": AppID = "wxc95cc47b53ccf30b"; lblProvince.Text = "当前上传省份:江西"; break; default: lblProvince.Text = "当前上传省份:"; break; } string _cashpay = "0"; PaymentMain paymentMain = new PaymentMain(); paymentMain.ShowDialog(); if (paymentMain.DialogResult == DialogResult.OK) { _cashpay = paymentMain.strpay; string _selectsql = "select max(endaccount_startdate) from t_endaccount " + "where serverpartcode ='" + serverpartcode + "' and shopcode ='" + shopcode + "' and machinecode ='" + machinecode + "' and endaccount_date is null and endaccount_startdate < now()"; DataTable _EndAccountTable = DBHelper.ExecuteDataSet(_selectsql).Tables[0]; if (_EndAccountTable.Rows.Count > 0) { if (_EndAccountTable.Rows[0][0].ToString() == "") { MessageBox.Show("请先登陆收银系统!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information); Environment.Exit(0); } _selectsql = "select count(distinct selldata_date) as ticketcount,isnull(sum(sellcount), 0) as totalcount," + "isnull(sum(factamount), 0) as totalsellamount,isnull(sum(offprice), 0) as totaloffamount,isnull(sum(cash), 0) as cash," + "isnull(sum(creditcard), 0) as creditcard,isnull(sum(ticketbill), 0) as ticketbill,isnull(sum(vipperson), 0) as vipperson ," + "isnull(sum(costbill), 0) as costbill,isnull(sum(otherpay), 0) as otherpay from t_selldata where serverpartcode ='" + serverpartcode + "' and shopcode ='" + shopcode + "' and machinecode ='" + machinecode + "' and selldata_date between ( select max(endaccount_startdate) from t_endaccount where serverpartcode ='" + serverpartcode + "' and shopcode ='" + shopcode + "' and machinecode ='" + machinecode + "' and endaccount_date is null and endaccount_startdate < now() ) and now()"; DataTable _CashierAuditTable = DBHelper.ExecuteDataSet(_selectsql).Tables[0]; if (_CashierAuditTable.Rows.Count > 0) { string _startdate = _EndAccountTable.Rows[0][0].ToString(); string _enddate = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"); decimal _MaxID = 0; decimal _ticketcount = decimal.Parse(_CashierAuditTable.Rows[0]["ticketcount"].ToString()); decimal _totalcount = decimal.Parse(_CashierAuditTable.Rows[0]["totalcount"].ToString()); decimal _totalsellamount = decimal.Parse(_CashierAuditTable.Rows[0]["totalsellamount"].ToString()); decimal _totaloffamount = decimal.Parse(_CashierAuditTable.Rows[0]["totaloffamount"].ToString()); decimal _cash = decimal.Parse(_CashierAuditTable.Rows[0]["cash"].ToString()); decimal _creditcard = decimal.Parse(_CashierAuditTable.Rows[0]["creditcard"].ToString()); decimal _ticketbill = decimal.Parse(_CashierAuditTable.Rows[0]["ticketbill"].ToString()); decimal _vipperson = decimal.Parse(_CashierAuditTable.Rows[0]["vipperson"].ToString()); decimal _costbill = decimal.Parse(_CashierAuditTable.Rows[0]["costbill"].ToString()); decimal _otherpay = decimal.Parse(_CashierAuditTable.Rows[0]["otherpay"].ToString()); try { _MaxID = decimal.Parse(DBHelper.ExecuteDataSet("select max(endaccount_id) from t_endaccount").Tables[0].Rows[0][0].ToString()); } catch { _MaxID = 0; } string _insertsql = "insert into t_endaccount (endaccount_id, endaccount_startdate, endaccount_date, " + "serverpartcode, shopcode, machinecode, endpersoncode, ticketcount, totalcount, totalsellamount, " + "totaloffamount, cash, creditcard, ticketbill, vipperson, costbill, otherpay, cashpay, flag) values (" + (_MaxID + 1) + ",datetime('" + _startdate + "'),datetime('" + _enddate + "'),'" + serverpartcode + "','" + shopcode + "','" + machinecode + "','S9999'," + _ticketcount + "," + _totalcount + "," + _totalsellamount + "," + _totaloffamount + "," + _cash + "," + _creditcard + "," + _ticketbill + "," + _vipperson + "," + _costbill + "," + _otherpay + "," + (_cashpay == "" ? "0" : _cashpay) + ",5)"; try { DBHelper.ExcuteSql(_insertsql); } catch (Exception ex) { MessageBox.Show("稽核信息生成失败,请重试!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information); Environment.Exit(0); } _startdate = DateTime.Parse(_startdate).ToString("yyyyMMddHHmmss"); _enddate = DateTime.Parse(_enddate).ToString("yyyyMMddHHmmss"); string strScanAudit = (_MaxID + 1).ToString() + "|" + _startdate + "|" + _enddate + "|" + serverpartcode + "|" + shopcode + "|" + machinecode + "|S9999|" + _ticketcount.ToString("F2") + "|" + _totalcount.ToString("F2") + "|" + _totalsellamount.ToString("F2") + "|" + _totaloffamount.ToString("F2") + "|" + _cash.ToString("F2") + "|" + _creditcard.ToString("F2") + "|" + _ticketbill.ToString("F2") + "|" + _vipperson.ToString("F2") + "|" + _costbill.ToString("F2") + "|" + _otherpay.ToString("F2") + "|" + (_cashpay == "" ? "0" : _cashpay) + "|5"; strScanAudit = strScanAudit.Replace(".00", ""); //string text = "ScanAudit=" + HttpUtility.UrlEncode(strScanAudit) + "&Length=" + strScanAudit.Length + // "&RowCount=1&RecordCount=1&CheckCode=" + CreateMD5(strScanAudit) + "&ScanIndex=1&ScanCount=1"; string strurl = "http://mall.eshangtech.com/getcode.html?appid=" + AppID + "&scope=snsapi_base&state=" + HttpUtility.UrlEncode("ScanAudit=" + HttpUtility.UrlEncode(strScanAudit) + "&Length=" + strScanAudit.Length + "&RowCount=1&RecordCount=1&CheckCode=" + CreateMD5(strScanAudit) + "&ScanIndex=1&ScanCount=1") + "&redirect_uri=" + HttpUtility.UrlEncode(ScanAuditURL); options = new QrCodeEncodingOptions { DisableECI = true, CharacterSet = "UTF-8", Width = picQRCode.Height, Height = picQRCode.Width }; writer = new BarcodeWriter(); writer.Format = BarcodeFormat.QR_CODE; writer.Options = options; Bitmap bitmap = writer.Write(strurl); picQRCode.Image = bitmap; } } } } #region 方法 --> 获取配置信息 /// /// 获取配置信息 /// /// 配置名称 /// 无配置信息时默认值 /// public static string ConfigUrationValues(string ConfigUrationName, string defaultValue) { string strSQL = "select configuration_name,configuration_values from dba.t_configuration where lower(configuration_name) = lcase('" + ConfigUrationName + "')"; string strValues = ""; try { using (DataTable _DataTable = ExecuteDataSet(strSQL).Tables[0]) { if (_DataTable.Rows.Count > 0) { foreach (DataRow row in _DataTable.Rows) { if (row["configuration_name"].ToString().ToLower() == ConfigUrationName.ToLower()) { strValues = row["configuration_values"].ToString(); } } } else { strValues = ConfigHelper.Win32API.INIGetStringValue(Environment.CurrentDirectory + "\\setup.ini", "DBCONECT", ConfigUrationName, defaultValue); if (strValues == "") strValues = ConfigHelper.Win32API.INIGetStringValue(Environment.CurrentDirectory + "\\set.ini", "DBCONECT", ConfigUrationName, defaultValue); } } } catch { strValues = ConfigHelper.Win32API.INIGetStringValue(Environment.CurrentDirectory + "\\setup.ini", "DBCONECT", ConfigUrationName, defaultValue); if (strValues == "") strValues = ConfigHelper.Win32API.INIGetStringValue(Environment.CurrentDirectory + "\\set.ini", "DBCONECT", ConfigUrationName, defaultValue); } return strValues; } #endregion /// /// 本地数据库连接 /// /// public static OdbcConnection AnyWhereConn() { string strConn = "DSN=anysql1;UID=dba;PWD=sql;"; OdbcConnection Conany = new OdbcConnection(strConn); return Conany; } /// /// 本地执行SQL语句并返回DataSet /// /// SQL语句 /// public static DataSet ExecuteDataSet(string SelectSql) { using (OdbcConnection conany = AnyWhereConn()) { DataSet _DataSet = new DataSet(); try { OdbcDataAdapter _OdbcDataAdapter = new OdbcDataAdapter(SelectSql, conany); _OdbcDataAdapter.Fill(_DataSet); return _DataSet; } catch (Exception ex) { throw new Exception(ex.Message); } } } #region 创建md5 16位大写加密 public static string CreateMD5(string text) { var md5 = new System.Security.Cryptography.MD5CryptoServiceProvider(); //换成utf8后对于中文加密也适用 byte[] output = md5.ComputeHash(System.Text.Encoding.UTF8.GetBytes(text)); string pass2md5 = BitConverter.ToString(output, 4, 8).Replace("-", ""); //pass2md5 = pass2md5.ToUpper(); return pass2md5; } #endregion private void btnClose_Click(object sender, EventArgs e) { Close(); } private void ScanAudit_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Escape) { Close(); } else if (e.KeyCode == Keys.F12) { ProvinceMain _MessageBox = new ProvinceMain(_type); _MessageBox.ShowDialog(); if (_MessageBox.DialogResult == DialogResult.OK) { QRCodeAudit(); } } } } }