//自动计算支付金额 public decimal AutoCalculateFee(PayMethod_Config m_PayConfig, List <UCPayMode2> m_UCPayModes) { decimal retValue = 0; if (m_PayConfig.InputFrom == PAY_FEE_FROM.pffAutoCalculate) { for (int i = 0; i < m_UCPayModes.Count; i++) { if (m_UCPayModes[i]._config.PayMethodID == m_PayConfig.PayMethodID) { //先清0 m_UCPayModes[i].PayValue = 0; break; } } decimal _ChangeFee = 0;//加上凑整费 for (int i = 0; i < m_UCPayModes.Count; i++) { if (m_UCPayModes[i]._config.InputFrom != PAY_FEE_FROM.pffManualInput && m_UCPayModes[i]._config.PayMethodID != -1) { _ChangeFee += m_UCPayModes[i].PayValue; } } _ChangeFee = -PayTotalFee + _ChangeFee; } return(retValue); }
public UCPayMode2(PayMethod_Config config) { InitializeComponent(); _config = config; //手工输入 if (config.InputFrom == PAY_FEE_FROM.pffManualInput) { diPayMoney.Enabled = true; } else { SetControlEnabled(false); this.diPayMoney.ForeColor = Color.Black; this.TabStop = false; diPayMoney.TabStop = false; } if (config.PayMethodID == -1) { SetControlEnabled(false); this.diPayMoney.ForeColor = Color.Black; this.TabStop = false; diPayMoney.TabStop = false; } btnPay.Visible = false; //显示颜色 lbTitle.ForeColor = config.FontColor; lbTitle.Text = config.PayMethodName; diPayMoney.ForeColor = config.FontColor; diPayMoney.Value = 0; }
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; } } } }
/// <summary> /// 第一步:创建支付方式对象 /// </summary> /// <param name="WorkID">医疗机构ID</param> /// <param name="flpPayCtrl">支付对象容器</param> /// <param name="iPatType">病人类型</param> /// <param name="iUseType">病人来源: 0-门诊 1-住院</param> /// <param name="totalFee">处方金额</param> /// <param name="zyDepositFee">住院预交金</param> /// <param name="_setFeeValue">回调返回金额</param> /// <returns>支付方式个数</returns> public static int InitUCPayModeControl(int WorkID, FlowLayoutPanel flpPayCtrl, int iPatType, int iUseType) { workID = WorkID; CostFee = new CostFeeStyle(); m_PayConfigs = new List <PayMethod_Config>(); m_UCPayModes = new List <UCPayMode2>(); //根据支付方式动态创建支付控件到 flpPayCtrl List <PayMethod_Config> rows = GetPatientPayMethodConfig(iPatType, (PAY_USERTYPE)iUseType); if (rows == null) { return(0); } flpPayCtrl.Controls.Clear(); flpPayCtrl.SuspendLayout(); int iTabStopIndex = 0; foreach (PayMethod_Config row in rows) { UCPayMode2 ucPayButton = new UCPayMode2(row); ucPayButton.TabIndex = iTabStopIndex++; ucPayButton.Margin = new Padding(0, 0, 0, 0); //ucPayButton.Dock = DockStyle.Top; ucPayButton.Width = flpPayCtrl.Width - 20; ucPayButton.btnPayClick += new btnPayClickEventHandler(ucPayButton_btnPayClick); ucPayButton.diPayMoneyTextChanged += new diPayMoneyTextChangedEventHandler(ucPayButton_diPayMoneyTextChanged); ucPayButton.threadPayFinshed += new threadPayFinshedEventHandler(ucPayButton_threadPayFinshed); flpPayCtrl.Controls.Add(ucPayButton); if (row.PayMethodID == -1) { ucPayButton.diPayMoney.MinValue = -1000000000; //找零可以为负数 } m_UCPayModes.Add(ucPayButton); //控件集合 PayMethod_Config config = row; config.Handle = ucPayButton.Handle; m_PayConfigs.Add(config); } flpPayCtrl.ResumeLayout(false); return(rows.Count); }
static void ucPayButton_diPayMoneyTextChanged(PayMethod_Config config, object sender, EventArgs e) { UCPayMode2 uPayMode = (UCPayMode2)sender; //找零的值不执行下面代码 if (config.PayMethodID == -1) { return; } CostFee.ChangeValue(m_UCPayModes); //其他支付方式值改变会自动触发 自动计算支付金额 与 总金额优惠自动计算 //if (config.InputFrom != PAY_FEE_FROM.pffAutoCalculate) //{ // for (int i = m_UCPayModes.Count - 1; i >= 0; i--) // { // if (m_UCPayModes[i]._config.InputFrom == PAY_FEE_FROM.pffAutoCalculate) // { // if (m_UCPayModes[i].btnPay.Visible && m_UCPayModes[i].btnPay.Enabled) // m_UCPayModes[i].btnPay.PerformClick(); // } // } //} //显示找零 UCPayMode2 change_uPayMode = m_UCPayModes.Find(x => x._config.PayMethodID == -1); change_uPayMode.PayValue = CostFee.ChangeFee;//显示找零金额 if (config.PayMethodID != 1002) { //补充支付方式数据 CostFee.SetPayModeFee(config.PayMethodID, uPayMode.TicketNo, uPayMode.PayValue); } else//更新现金支付方式1002 { CostFee.SetPayModeFee(config.PayMethodID, uPayMode.TicketNo, CostFee.CashFee); } //结算面板显示对应金额 setFeeValue(CostFee); }
/// <summary> /// 根据病人身份信息,取得结算方式 /// </summary> /// <param name="iPatType">病人身份</param> /// <param name="iUseType">病人来源: 0-门诊 1-住院</param> /// <returns>符合条件的记录</returns> private static List <PayMethod_Config> GetPatientPayMethodConfig(int iPatType, PAY_USERTYPE iUseType) { List <PayMethod_Config> Configs = new List <PayMethod_Config>(); PayMethod_Config config = new PayMethod_Config(); #region 根据病人类型获取支付方式 Action <ClientRequestData> requestAction = ((ClientRequestData request) => { request.AddData(iPatType); request.AddData((int)iUseType); request.AddData(workID); }); ServiceResponseData retdata = InvokeWcfService("MainFrame.Service", "CashPaymentController", "GetPaymentData", requestAction); m_dtPayMethodConfig = retdata.GetData <DataTable>(0); //bool bHavePaySurplus = false; //是否存在结余支付 foreach (DataRow row in m_dtPayMethodConfig.Rows) { config = new PayMethod_Config(); config.PayMethodID = Convert.ToInt32(row["PaymentID"]); config.PatientType = iUseType; config.OrderNum = Convert.ToInt32(row["PayOrder"]); config.PayMethodName = row["PayName"].ToString(); config.InputFrom = (PAY_FEE_FROM)Convert.ToInt32(row["InputFrom"]); config.RuleExplain = row["PayRule"].ToString(); config.FontColor = Color.FromArgb(Convert.ToInt32(row["FontColor"])); config.IsAccountFee = Convert.ToInt32(row["IsAccountFee"]); if (config.FontColor == Color.Transparent || config.FontColor.ToArgb() == 0) { config.FontColor = SystemColors.ControlText; } //config.ProcStep = PAY_PROCSTEP.ppsAutoFinshed; Configs.Add(config); } #endregion #region 默认添加现金支付方式,支付方式固定PayMethodID=1002 //config = new PayMethod_Config(); //config.PayMethodID = 1002; //config.PayMethodName = "现金支付"; //config.PatientType = iUseType; //config.OrderNum = 999999; //config.InputFrom = PAY_FEE_FROM.pffManualInput; //config.RuleExplain = ""; //config.FontColor = Color.Red; //config.ProcStep = PAY_PROCSTEP.ppsNotStart; ////config.PayStID = 0; ////config.ProcStatus = true; ////config.TicketNo = ""; ////config.NeedPayFee = 0; ////config.PayFee = 0; ////config.NeedRound = !bHavePaySurplus; //存在结余支付,不需要凑整和显示补零; ////config.NeedPayFee = 0; //Configs.Add(config); #endregion #region 找零,支付方式固定PayMethodID=-1 config = new PayMethod_Config(); config.PayMethodID = -1; config.PayMethodName = "找零"; config.PatientType = iUseType; config.OrderNum = 999999; config.InputFrom = PAY_FEE_FROM.pffManualInput; config.RuleExplain = ""; config.FontColor = Color.Red; //config.ProcStep = PAY_PROCSTEP.ppsAutoFinshed; //config.PayStID = -1; Configs.Add(config); #endregion return(Configs); }