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 const string AppID = "wx85e69a5fb601be16"; //AppSecret(应用密钥) public const string AppSecret = "dfcf7748e6c7027695cbec8ffedc04dc"; 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, string cash) { InitializeComponent(); _type = type[0]; QRCodeAudit(cash); } private void MainTop_Tick(object sender, EventArgs e) { if (Handle != GetForegroundWindow()) //持续使该窗体置为最前,屏蔽该行则单次置顶 { SetForegroundWindow(Handle); } } private void QRCodeAudit(string cash) { switch (ConfigUrationValues("ScanAuditURL", "http://syyw.eshangtech.com:8060/ScanUpdate/ScanAudit.html")) { case "http://syyw.eshangtech.com:8060/ScanUpdate/ScanAudit.html": lblProvince.Text = "当前上传省份:四川"; break; case "http://cloud.eshangtech.com:8000/ScanUpdate/ScanAudit.html": lblProvince.Text = "当前上传省份:浙江"; break; case "http://cloud.eshangtech.com:8000/ScanUpdate_GZ/ScanAudit.html": lblProvince.Text = "当前上传省份:贵州"; break; case "http://cloud.eshangtech.com:8000/ScanUpdate_Test/ScanAudit.html": lblProvince.Text = "当前上传省份:驿商测试"; break; case "http://113.16.255.162:6060/ScanUpdate/ScanAudit.html": lblProvince.Text = "当前上传省份:广西"; break; default: lblProvince.Text = "当前上传省份:"; break; } string _cashpay = "0"; //PaymentMain paymentMain = new PaymentMain(); //paymentMain.ShowDialog(); //if (paymentMain.DialogResult == DialogResult.OK) //{ //_cashpay = paymentMain.strpay; _cashpay = cash; string _selectsql = "select max(startdate) from t_endaccount_new " + "where serverpartcode ='" + serverpartcode + "' and shopcode ='" + shopcode + "' and machinecode ='" + machinecode + "' and enddate is null and 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(*) as ticketcount,isnull(sum(sellmaster_count), 0) as totalcount," + "isnull(sum(sellmaster_amount), 0) as totalsellamount,isnull(sum(sellmaster_offprice), 0) as totaloffamount,isnull(sum(cashpay), 0) as cashpay," + "isnull(sum(bankpay), 0) as bankpay,isnull(sum(memberpay), 0) as memberpay,isnull(sum(couponpay), 0) as couponpay ," + "isnull(sum(mobilepay), 0) as mobilepay,isnull(sum(otherpay), 0) as otherpay from t_sellmaster where serverpartcode ='" + serverpartcode + "' and shopcode ='" + shopcode + "' and machinecode ='" + machinecode + "' and sellmaster_date between ( select max(startdate) from t_endaccount_new where serverpartcode ='" + serverpartcode + "' and shopcode ='" + shopcode + "' and machinecode ='" + machinecode + "' and enddate is null and 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 cashpay = decimal.Parse(_CashierAuditTable.Rows[0]["cashpay"].ToString()); decimal bankpay = decimal.Parse(_CashierAuditTable.Rows[0]["bankpay"].ToString()); decimal memberpay = decimal.Parse(_CashierAuditTable.Rows[0]["memberpay"].ToString()); decimal couponpay = decimal.Parse(_CashierAuditTable.Rows[0]["couponpay"].ToString()); decimal mobilepay = decimal.Parse(_CashierAuditTable.Rows[0]["mobilepay"].ToString()); decimal otherpay = decimal.Parse(_CashierAuditTable.Rows[0]["otherpay"].ToString()); try { _MaxID = decimal.Parse(DBHelper.ExecuteDataSet("select max(endaccount_id) from t_endaccount_new").Tables[0].Rows[0][0].ToString()); } catch { _MaxID = 0; } string _insertsql = "insert into t_endaccount_new (endaccount_id, startdate, enddate, " + "serverpartcode, shopcode, machinecode, endperson_code, ticket_count, total_count, total_amount, " + "total_offamount, cashpay, bankpay, memberpay, couponpay, mobilepay, internalpay, contribution_amount) values (" + (_MaxID + 1) + ",datetime('" + _startdate + "'),datetime('" + _enddate + "'),'" + serverpartcode + "','" + shopcode + "','" + machinecode + "','S9999'," + _ticketcount + "," + _totalcount + "," + _totalsellamount + "," + _totaloffamount + "," + cashpay + "," + bankpay + "," + memberpay + "," + couponpay + "," + mobilepay + "," + 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 + "|" + _totalcount + "|" + _totalsellamount + "|" + _totaloffamount + "|" + cashpay + "|" + bankpay + "|" + memberpay + "|" + couponpay + "|" + mobilepay + "|" + otherpay + "|" + (_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(""); } } } } }