private new void Update() { string msg; ShowWaitMsg("正在检查系统更新"); #region 系统更新 OnlineDataSync(); #endregion ShowWaitMsg("正在更新系统参数"); #region 读取远程参数 if (!TransModule.GetConfig(out msg)) { MessageBox.Show("下载系统参数出错:" + msg + "\r\n请联系管理员", "错误", MessageBoxButtons.OK, MessageBoxIcon.Hand, MessageBoxDefaultButton.Button1); } #endregion ShowWaitMsg("正在更新菜品信息"); #region 读取菜品 if (!TransModule.GetGoods(out msg)) { MessageBox.Show("下载菜品信息错误!"); } else { frmSale.RefreshGoodsMenu(); } #endregion HideWaitMsg(); }
//登录 private void button1_Click(object sender, EventArgs e) { if (tbUserCode.Text == "999999999" && tbPassword.Text == "12345678") { if (MessageBox.Show("退出系统?", "", MessageBoxButtons.OKCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == DialogResult.OK) { this.DialogResult = DialogResult.Cancel; } return; } if (string.IsNullOrEmpty(tbUserCode.Text)) { MessageBox.Show("请输入用户名称"); tbUserCode.Focus(); return; } string msg; ShowWaitMsg("正在登陆"); //初始化webservice TransModule.Init(PubGlobal.SysConfig.WebServiceUrl, tbUserCode.Text, tbPassword.Text, PubGlobal.SysConfig.DeptCode); if (!TransModule.Logon(out msg)) { //登陆失败 MessageBox.Show(msg); tbUserCode.Focus(); } else { //登陆成功 this.DialogResult = DialogResult.OK; } HideWaitMsg(); }
/// <summary> /// 刷新 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void button1_Click(object sender, EventArgs e) { decimal total; string msg; if (!TransModule.QueryTrade(out total, out msg)) { MessageBox.Show(msg); } else { lblTotal.Text = total.ToString("F2"); mSaleFlowBindingSource.ResetBindings(false); } }
//private void TestTrade() //{ // string inCardNo = "000001",msg; // this.Invoke(dlgShowWaitMsg, "正在读取金额"); // this.Invoke(dlgHideWaitMsg); // #region 读金额 // if (!TransModule.GetCzCard(inCardNo, out msg)) // { // //读取金额失败 // this.Invoke(dlgShowErrorMsgBox, "读取金额失败\r\n错误原因:" + msg); // this.Invoke(dlgHideWaitMsg); // readSuccess = false; // readCardStatus.ReleaseMutex(); // } // #endregion // Thread.Sleep(100); // this.Invoke(dlgShowWaitMsg, "正在交易"); // #region 交易 // //PubGlobal.BussinessVar.card.Total = CardStrFormater.GetMoney(icCard.ReadIC("1", "0", PubGlobal.SysConfig.CzkPassword)); // //WintecIDT700.Beep(100); // if (Trade(out msg)) // { // this.Invoke(dlgShowInfoMsgBox, "交易成功\r\n卡余额:" + PubGlobal.BussinessVar.card.Total); // this.Invoke(dlgCloseForm);//关闭窗口 // } // else // { // this.Invoke(dlgShowErrorMsgBox, "交易失败\r\n失败原因:" + msg); // //交易失败 // PubGlobal.BussinessVar.card = null; // readSuccess = false; // } // #endregion // this.Invoke(dlgHideWaitMsg); //} /// <summary> /// 交易 /// </summary> /// <returns></returns> private bool Trade(out string msg) { if (PubGlobal.BussinessVar.card.Total - PubGlobal.BussinessVar.card.CzkType.KbMoney < PubGlobal.BussinessVar.Total) { msg = "余额不足。\r\n当前卡余额为" + PubGlobal.BussinessVar.card.Total + "元"; return(false); } MPayFlow payFlow = new MPayFlow(); payFlow.Operater = PubGlobal.SysConfig.User.UserCode; payFlow.Paypmt = "12"; payFlow.PosNO = PubGlobal.SysConfig.PosNO; payFlow.Ref_no = PubGlobal.BussinessVar.card.InCardno; payFlow.RowNO = 1; payFlow.Sa_date = DateTime.Today; payFlow.Sa_time = DateTime.Now.ToString("HH:mm:ss"); COMM.SerialNoBuilder.GetSerialNo();//获取流水号 payFlow.SerialNo = PubGlobal.SysConfig.PosNO + payFlow.Sa_date.ToString("yyMMdd") + PubGlobal.BussinessVar.SerialNo; payFlow.Squadno = "1"; payFlow.Total = PubGlobal.BussinessVar.Total; foreach (MSaleFlow saleFlow in PubGlobal.BussinessVar.saleFlowList) { saleFlow.SerialNo = payFlow.SerialNo; saleFlow.Sa_date = payFlow.Sa_date; saleFlow.Sa_time = payFlow.Sa_time; } PubGlobal.BussinessVar.payFlowList.Add(payFlow); this.Invoke(dlgShowWaitMsg, "正在交易"); if (!TransModule.SaveTrade(out msg)) { PubGlobal.BussinessVar.card = null; readSuccess = false; return(false); } else { COMM.SerialNoBuilder.CommitSerialNo(); //提交流水号 PrintBill(); //交易成功,打印小票 return(true); } }
private void button1_Click(object sender, EventArgs e) { string msg; if (string.IsNullOrEmpty(tbPosNO.Text)) { MessageBox.Show("请输入收款机号"); tbPosNO.Focus(); return; } if (TransModule.HelloWorld(tbServer.Text, tbPort.Text, out msg)) { //测试通过 if (MessageBox.Show("测试成功,是否保存参数?", string.Empty, MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == DialogResult.Yes) { //保存参数 if (SaveConfig(tbAPPVersion.Text, tbPosNO.Text, tbServer.Text, tbPort.Text, tbDeptCode.Text, tbStype.Text, rbDept.Checked?"1":"0", tbPrintCount.Text, out msg)) { MessageBox.Show("保存成功!请重新启动设备"); return; } else { if (MessageBox.Show("保存失败,是否重试?", "错误", MessageBoxButtons.RetryCancel, MessageBoxIcon.Hand, MessageBoxDefaultButton.Button1) == DialogResult.Retry) { button1_Click(null, null); } } } } else { //测试失败 if (MessageBox.Show("连接失败,是否重试?", "错误", MessageBoxButtons.RetryCancel, MessageBoxIcon.Hand, MessageBoxDefaultButton.Button1) == DialogResult.Retry) { button1_Click(null, null); } } }
/// <summary> /// 系统更新 /// </summary> public void OnlineDataSync() { int isUpdate = 0; string msg; try { isUpdate = TransModule.CheckUpdate(out msg); if (isUpdate == 1) { //更新引导程序 string path = PubGlobal.Envionment.UpdateFolderPath + PubGlobal.Envionment.UPDATE_EXE_FILE_NAME; if (File.Exists(path)) { File.Delete(PubGlobal.Envionment.UpdateAppPath); File.Move(path, PubGlobal.Envionment.UpdateAppPath); File.Delete(path); } //关闭本程序,启动更新程序 //更新完成后,关闭更新程序,启动主程序 System.Diagnostics.Process p = new System.Diagnostics.Process(); p.StartInfo.FileName = PubGlobal.Envionment.UpdateAppPath; p.Start(); //关闭该程序 HideWaitMsg(); this.Close(); } } catch (Exception ex) { MessageBox.Show(ex.Message); } HideWaitMsg(); }
static Mutex readCardStatus = new Mutex(true);//读卡状态标志 /// <summary> /// 读卡 /// </summary> private void ReadCard() { icCard = new ICCard("com2");//初始化 string inCardNo, msg; while (true) // { readCardStatus.WaitOne(); //等待窗口开启 #region 寻卡 if (!readSuccess && icCard.SearchIC()) { Thread.Sleep(100); #region 读卡号 try { inCardNo = CardStrFormater.GetCardNo(icCard.ReadIC("0", "1", PubGlobal.SysConfig.CzkPassword), PubGlobal.SysConfig.CzkLen); if (!string.IsNullOrEmpty(inCardNo)) { readSuccess = true; WintecIDT700.Beep(100); } } catch { //读卡失败,释放资源,重新读卡 //this.Invoke(dlgShowErrorMsgBox, "读卡错误"); readCardStatus.ReleaseMutex(); readSuccess = false; continue; } #endregion Thread.Sleep(100); this.Invoke(dlgShowWaitMsg, "正在读取金额"); #region 读金额 if (!TransModule.GetCzCard(inCardNo, out msg)) { //读取金额失败 this.Invoke(dlgShowErrorMsgBox, "读取金额失败\r\n错误原因:" + msg); this.Invoke(dlgHideWaitMsg); readSuccess = false; readCardStatus.ReleaseMutex(); continue; } #endregion if (!WriteCard(PubGlobal.BussinessVar.card.Total - PubGlobal.BussinessVar.Total, 1, out msg)) { MessageBox.Show("写金额失败"); } Thread.Sleep(100); this.Invoke(dlgShowWaitMsg, "正在交易"); #region 交易 //PubGlobal.BussinessVar.card.Total = CardStrFormater.GetMoney(icCard.ReadIC("1", "0", PubGlobal.SysConfig.CzkPassword)); //WintecIDT700.Beep(100); if (Trade(out msg)) { this.Invoke(dlgShowInfoMsgBox, "交易成功\r\n卡余额:" + PubGlobal.BussinessVar.card.Total); tradeSuccess = true; } else { this.Invoke(dlgShowErrorMsgBox, "交易失败\r\n失败原因:" + msg); //交易失败 if (!WriteCard(PubGlobal.BussinessVar.card.Total, 1, out msg)) { MessageBox.Show("写卡失败"); } PubGlobal.BussinessVar.card = null; } #endregion this.Invoke(dlgHideWaitMsg); } #endregion readCardStatus.ReleaseMutex(); //释放阻塞 this.Invoke(dlgCloseForm); //关闭窗口 Thread.Sleep(500); //线程休眠500毫秒 } }