/// <summary> /// 添加线程到队列 /// </summary> /// <param name="paythread"></param> private static void AddPayThread(PAY_THREAD paythread) { if (m_PayThreads == null) { m_PayThreads = new List <PAY_THREAD>(); } Monitor.Enter(m_PayThreads); try { //根据支付ID找到原来的线程 foreach (PAY_THREAD thread in m_PayThreads) { if (thread.PayMethodID == paythread.PayMethodID) { if (thread.PayThread != null && thread.PayThread.IsAlive) { thread.PayThread.Abort(); } m_PayThreads.Remove(thread); break; } } m_PayThreads.Add(paythread); } finally { Monitor.Exit(m_PayThreads); } }
static void ucPayButton_threadPayFinshed(PayMethod_Config config, object sender) { PayMethod_Config m_PayConfig = config; UCPayMode2 uPayMode = (UCPayMode2)sender; //接收支付线程消息 PAY_THREAD paythread = GetPayThreadInfo(m_PayConfig.PayMethodID); if (paythread != null && paythread.PayMethodID != -1) { //支付完成 if (paythread.Succeed) { //m_PayConfig.ProcStep = paythread.ProcStep; uPayMode.PayValue = decimal.Round(paythread.PayFee, 2);//显示在控件上 uPayMode.TicketNo = paythread.TicketNo; CostFee.SetPayModeFee(m_PayConfig.PayMethodID, paythread.TicketNo, decimal.Round(paythread.PayFee, 2)); //CostFee.ChangeValue(m_UCPayModes);//测试 SetCashValue(CostFee.ChangeFee); switch (m_PayConfig.InputFrom) { case PAY_FEE_FROM.pffManualInput: //手工输入 break; case PAY_FEE_FROM.pffAutoCalculate: //自动计算支付金额 switch (paythread.ProcStep) { case PAY_PROCSTEP.ppsHandFinsed: uPayMode.btnPay.Text = "获取"; uPayMode.btnPay.Visible = true; uPayMode.btnPay.Enabled = true; break; case PAY_PROCSTEP.ppsAutoFinshed: uPayMode.btnPay.Visible = false; break; } break; default: break; } } else { MessageBox.Show("计算错误:" + paythread.LastErrorMessage); } } }
static void ucPayButton_btnPayClick(PayMethod_Config config, object sender, EventArgs e) { PayMethod_Config m_PayConfig = config; UCPayMode2 uPayMode = (UCPayMode2)sender; //接收支付线程消息 PAY_THREAD paythread = (PAY_THREAD)GetPayThreadInfo(m_PayConfig.PayMethodID).Clone(); if (paythread != null) { StartPay(ref paythread, m_PayConfig); } uPayMode.btnPay.Enabled = false; CashFocus(); }
/// <summary> /// 开始执行后台支付 /// </summary> /// <param name="paythread">支付方式线程</param> /// <returns>开始支付是否成功</returns> private static bool StartPay(ref PAY_THREAD paythread, PayMethod_Config config) { //启动后台线程开始支付 bool bSucceed = false; switch (paythread.InputFrom) { case PAY_FEE_FROM.pffManualInput: //手工输入 bSucceed = true; paythread.Succeed = true; break; case PAY_FEE_FROM.pffAutoCalculate: //自动计算支付金额 paythread.PayThread = new Thread(paythread.ExecAutoDataItfPay); bSucceed = true; break; default: //手工输入,支付按钮不可用 paythread.LastErrorMessage = "支付完成"; paythread.Succeed = true; break; } //启动线程 if (bSucceed) { //保存支付ID为名称,在线程内部根据此值可获得相应的支付配置信息 if (paythread.PayThread != null) { paythread.PayThread.Name = paythread.PayMethodID.ToString(); paythread.PayThread.Priority = ThreadPriority.Normal; AddPayThread(paythread); paythread.PayThread.Start(); } else { AddPayThread(paythread); } } //if (paythread.InputFrom == PAY_FEE_FROM.pffAutoCalculate) //{ // WindowsAPI.SendMessage(paythread.Handle, UCPayMode2.WM_PAY_STATUS, 1, 0); //} return(bSucceed); }
/// <summary> /// 第二步:创建控件后开始计算支付金额 /// </summary> /// <param name="totalFee">总金额</param> /// <param name="zyDepositFee">预交金总额</param> /// <param name="_paymentCalculate">支付方式计算</param> /// <param name="_setFeeValue">显示支付金额</param> /// <param name="_defaultCash">现金项默认</param> public static void StartExecPay(decimal totalFee, decimal zyDepositFee, AsynPaymentCalculate _paymentCalculate, SetFeeValueDelegate _setFeeValue, bool _defaultCash) { CostFee.InitFee(totalFee, zyDepositFee, m_UCPayModes); UCPayMode2 change_uPayMode = m_UCPayModes.Find(x => x._config.PayMethodID == -1); change_uPayMode.PayValue = CostFee.ChangeFee;//显示找零金额 paymentCalculate = _paymentCalculate; setFeeValue = _setFeeValue; if (setFeeValue != null) { //给界面显示金额 setFeeValue(CostFee); } defaultCash = _defaultCash; if (m_PayConfigs != null) { m_PayThreads = null;//清空线程 //SetCashValue(CostFee.ChangeFee); for (int i = 0; i < m_PayConfigs.Count; i++) { PayMethod_Config m_PayConfig = m_PayConfigs[i]; //m_PayConfig.ProcStep = PAY_PROCSTEP.ppsHandFinsed;//开始 PAY_THREAD paythread = new PAY_THREAD(); //paythread.iPatType = m_PayConfig.PatientType; //paythread.iPatLstID = patListID; //paythread.FeeIDs = feeIDs; //paythread.PayType = iPatType; //paythread.SoCityNum = ""; paythread.PayMethodID = m_PayConfig.PayMethodID; paythread.InputFrom = m_PayConfig.InputFrom; //paythread.ProcStep = m_PayConfig.ProcStep; paythread.Handle = m_PayConfig.Handle; paythread.paymentCalculate = paymentCalculate; //启动后台线程开始支付 bool bSucceed = false; bSucceed = StartPay(ref paythread, m_PayConfig); if (bSucceed == false) { //执行支付失败 //m_PayConfig.ProcStep = PAY_PROCSTEP.ppsHandFinsed; } } } }