c#之tcbs 列印憑證示例

wisdomone1發表於2011-09-16
 //**************************************************************************//
        //****************          資金型別處理         ***************************//
        //**************************************************************************//
        private bool ProcessFundGrid(long clearingAcctNumber, long deductSchedNbr, long? submNbrToCopy, string deductSubOrgNbr)//
        {
            if (base.ExceptionList.Count <= 0)
            {
                string rtxnTranTypeCode = string.Empty;
                decimal availaibleSubAcctBalance = decimal.MinValue;
                decimal glavailaibleSubAcctBalance = 0M;
                string rtxnTypeCode = string.Empty;
                string intlRtxnDesc = string.Empty;
                bool isCopy = this._formMode == FormMode.Copy;
                if ((((base.ActiveTask != null) && (base.ActiveTask.ActiveAccount != null)) && (base.ActiveTask.ActiveAccount.SubAccounts["NOTE", "BAL"] != null)) && (this.txtAmount.Value != null))
                {
                    decimal totCash = 0M;
                    //是否超過最大限額的判斷--start
                    if (base.ActiveTask.ActiveAccount.SubAccounts["NOTE", "BAL"].OrigBal.HasValue)
                    {
                        availaibleSubAcctBalance = base.ActiveTask.ActiveAccount.SubAccounts["NOTE", "BAL"].OrigBal.Value;
                    }
                    else
                    {
                        availaibleSubAcctBalance = 0M;
                    }
                    if ((this.txtAmount.Value + availaibleSubAcctBalance) > 999999999999999.99M)
                    {
                        CoreMessageBox.Show(MessageBoxOption.Error, 99999L, "賬戶餘額{0} 與交易金額{1} 之和已超過最大限額【999,999,999,999,999.99】", new object[] { FI.FormatCurrency(availaibleSubAcctBalance), FI.FormatCurrency((decimal)this.txtAmount.Value) });
                        return false;
                    }
                    //是否超過最大限額的判斷--end
                    //if (base.ActiveTask.ActiveAccount.CurrAcctStatCd == "APPR")
                    //{
                    //    rtxnTypeCode = "NA";
                    //}

                    //交易型別
                    rtxnTypeCode = "PAYD";//
                    Rtxn rtxn = Rtxn.NewRtxn(new long?(base.ActiveTask.ActiveAccount.AcctNbr.Value), rtxnTypeCode);
                    //現金箱
                    if (CoreUser.CashboxNbr != long.MinValue)
                    {
                        rtxn.CashboxNbr = CoreUser.CashboxNbr;
                    }
                    //生效日期
                    if (this.calDepositEffectiveDate.SelectedDate.HasValue)
                    {
                        rtxn.EffectiveDate = this.calDepositEffectiveDate.SelectedDate.Value;
                    }
                    //交易發生額
                    if (this.txtAmount.Text != null)
                    {
                        rtxn.TranAmt = decimal.Parse(this.txtAmount.Text);
                    }
                    //交易子賬號
                    rtxn.HoldSubAcctNbr = base.ActiveTask.ActiveAccount.SubAccounts["NOTE", "BAL"].SubAcctNbr;
                    //資金列表的判斷
                    for (int iCount = 0; iCount < this.grdFundGrid.Funds.Count; iCount++)
                    {
                        if (!((this.grdFundGrid.Funds[iCount].Amt != 0M) && this.grdFundGrid.Funds[iCount].Amt.HasValue))
                        {
                            CoreMessageBox.Show(MessageBoxOption.Error, 99999L, "金額無效", new object[0]);
                            return false;
                        }
                        if (this.grdFundGrid.Funds[iCount].FundTypCd == null)
                        {
                            CoreMessageBox.Show(MessageBoxOption.Error, 99999L, "資金型別不可為空", new object[0]);
                            return false;
                        }
                        if (this.grdFundGrid.Funds[iCount].FundTypCd == "CASH")
                        {
                            totCash += this.grdFundGrid.Funds[iCount].Amt.Value;
                        }
                        if (!this.grdFundGrid.Funds[iCount].ParentRtxnIsNull)
                        {
                            rtxnTranTypeCode = this.grdFundGrid.Funds[iCount].ParentRtxn.RtxnTypCd;
                        }
                        if ((!this.grdFundGrid.Funds[iCount].AcctNbr.HasValue && (rtxnTranTypeCode != string.Empty)) && (rtxnTranTypeCode != null))
                        {
                            CoreMessageBox.Show(MessageBoxOption.Error, 99999L, "賬號不可為空.", new object[0]);
                            return false;
                        }
                        string wthacctnbr = string.Empty;
                        string wthacctorgnbr = string.Empty;
                        this.approvepersnbr = long.MinValue;
                        wthacctnbr = this.grdFundGrid.WthAccount;
                        if (wthacctnbr != string.Empty)
                        {
                            if (this._contractAcctNbr.ToString() != wthacctnbr)
                            {
                                CoreMessageBox.Show(MessageBoxOption.Error, 99999L, "劃款賬戶不是簽約賬戶!");

                                return false;
                            }
                            Acct acctOrgNbr = Acct.GetAcct(long.Parse(wthacctnbr), new object[] { AcctFetch.Basic });
                            //20110417--款項有內部賬劃出時加授權頁面
                            if (acctOrgNbr.MjAcctType.ToString() == "GL")
                            {

                                ////判斷取款賬戶內是否有足夠的資金
                                //if (acctOrgNbr.SubAccounts["NOTE", "BAL"].BalanceHistoryIsNull==false)
                                //{
                                //    glavailaibleSubAcctBalance = decimal.Parse(acctOrgNbr.GetAvailableFunds(acctOrgNbr.SubAccounts["NOTE", "BAL"].SubAcctNbr.Value).ToString());
                                //}
                                //else
                                //{
                                //    glavailaibleSubAcctBalance = 0M;
                                //}
                                //判斷取款賬戶內是否有足夠的資金
                                try
                                {
                                    glavailaibleSubAcctBalance = decimal.Parse(acctOrgNbr.GetAvailableFunds(acctOrgNbr.SubAccounts["NOTE", "BAL"].SubAcctNbr.Value).ToString());
                                }
                                catch (Exception ex)
                                {
                                    glavailaibleSubAcctBalance = 0M;
                                }
                                if (glavailaibleSubAcctBalance > (decimal?)(this.txtAmount.Value * -1M))
                                {
                                    CoreMessageBox.Show(MessageBoxOption.Error, 99999L, "此內部戶內餘額不足!");

                                    return false;
                                }
                                if (!this.InvokeOverrideScreen(0x185L))
                                {
                                    return false;
                                }

                            }


                        }
                        //交易描述
                        if (CalcTypVarValue.BankVariables["BANK", "TRAN", CoreUser.PostingDate] != null)
                        {
                            CalcTypVarValue calcTypVarValue = CalcTypVarValue.BankVariables["BANK", "TRAN", CoreUser.PostingDate];
                            if ((calcTypVarValue.CalcVarValue == "Y") && (((rtxnTypeCode == "PAYD") && ((rtxnTranTypeCode == "WTH") || (rtxnTranTypeCode == "GLD"))) && (Math.Abs(this.grdFundGrid.Funds[iCount].Amt.Value) == Math.Abs(this.grdFundGrid.TotalAmount))))
                            {
                                intlRtxnDesc = "Transfer from " + this.grdFundGrid.Funds[iCount].AcctNbr.ToString();
                            }
                        }
                        //子交易的新增
                        rtxn.AddFund(this.grdFundGrid.Funds[iCount].FundTypCd, this.grdFundGrid.Funds[iCount].FundTypDtlCd, this.grdFundGrid.Funds[iCount].ClearCatCd, this.grdFundGrid.Funds[iCount].Amt, this.grdFundGrid.Funds[iCount].NbrOfItems);
                    }


                    rtxn.AddBalance(base.ActiveTask.ActiveAccount.SubAccounts["NOTE", "BAL"].SubAcctNbr, "NOTE", "BAL", (decimal?)(this.txtAmount.Value * -1M));//20110321將【RTXNBAL】表中變為負數
                    rtxn.InternalDescription = intlRtxnDesc;
                    
                    long? numberOfItems = long.MinValue;
                    RtxnCollection rtxnCollection = this.grdFundGrid.ChildTrxns;
                    //string strCheckNbr = string.Empty;
                    //string[] strArrayCheckNbr;
                    bool flag = false;
                    foreach (Rtxn rtxnChild in rtxnCollection)
                    {
                        //if (rtxnChild.CheckNbr != null)
                        //{
                        //    strCheckNbr = strCheckNbr + rtxnChild.CheckNbr.ToString() + ";";
                        //}

                        if (rtxnChild.RtxnFundTyps.Count > 0)
                        {
                            //strCheckNbr = rtxnChild.CheckNbr.ToString();
                            long? nbrOfItemsTemp = rtxnChild.RtxnFundTyps[0].NbrOfItems;
                            if (!nbrOfItemsTemp.HasValue || nbrOfItemsTemp.GetValueOrDefault() <= 0L)
                            {
                                numberOfItems = 1L;
                            }
                            else
                            {
                                numberOfItems = rtxnChild.RtxnFundTyps[0].NbrOfItems;
                            }
                            rtxn.ChildRtxns.Add(rtxnChild);
                        }

                    }
                   
                    ////重複支票號的判斷
                    //if (strCheckNbr.Length > 0)
                    //{
                    //    strArrayCheckNbr = strCheckNbr.Split(';');
                    //    if (strArrayCheckNbr.Length > 1)
                    //    {
                    //        CoreMessageBox.Show(MessageBoxOption.Error, 99999L, "轉賬失敗!批次入賬一次只能使用一張轉賬支票!");

                    //        return false;
                    //    }
                    //    for (int i = 0; i < strArrayCheckNbr.Length - 1; i++)
                    //    {
                    //        for (int j = i + 1; j < strArrayCheckNbr.Length; j++)
                    //        {
                    //            if (strArrayCheckNbr[i] == strArrayCheckNbr[j])
                    //            {
                    //                flag = true;
                    //                break;
                    //            }
                    //        }
                    //    }
                    //    if (flag)
                    //    {
                    //        CoreMessageBox.Show(MessageBoxOption.Error, 99999L, "發現重複的支票號,轉賬失敗!");

                    //        return false;
                    //    }
                    //}


                  
                    rtxn.SetupDeposit(RtxnValidator.Deposit);

                    DeductSchedSubmProcessor deductSchedSubmProcessor = new DeductSchedSubmProcessor();
                    try
                    {
                        if (rtxn != null)
                        {
                            deductSchedSubmProcessor.PostOptionalCopy(rtxn, deductSchedNbr, clearingAcctNumber, this.calSubmissionEffectiveDate.SelectedDate, isCopy, false, submNbrToCopy);
                            deductSchedSubmProcessor = deductSchedSubmProcessor.Save(base.ActvCatCd, base.ActvTypCd) as DeductSchedSubmProcessor;
                            rtxn = deductSchedSubmProcessor.RtxnObj;
                        }
                    }
                    catch (CoreTransactionException tExcp)
                    {
                        if (rtxn != null)
                        {
                            frmOverride verrideFrm = new frmOverride(tExcp.Transaction);
                            if (overrideFrm.ShowDialog(this) == DialogResult.Cancel)
                            {
                                return false;
                            }
                            rtxn.ApproverPersNbr = overrideFrm.PersNbr;
                            deductSchedSubmProcessor.PostOptionalCopy(rtxn, deductSchedNbr, clearingAcctNumber, this.calSubmissionEffectiveDate.SelectedDate, isCopy, true, submNbrToCopy);
                            deductSchedSubmProcessor = deductSchedSubmProcessor.Save(base.ActvCatCd, base.ActvTypCd) as DeductSchedSubmProcessor;
                            rtxn = deductSchedSubmProcessor.RtxnObj;
                        }
                    }
                    if (totCash > 0M)
                    {
                        TxnCashCount.ClearCashCounts();
                        TxnCashCount.IsRtxn = true;
                        TxnCashCount.TxnTypCd = rtxn.RtxnTypCd;
                        TxnCashCount.AcctNbr = rtxn.Account.AcctNbr.Value;
                        TxnCashCount.CashboxNbr = CoreUser.CashboxNbr;
                        TxnCashCount.TxnNbr = rtxn.RtxnNbr.Value;
                        TxnCashCount.RequestAmount = totCash;
                        TxnCashCount.DispenseOrCashCount();
                        TxnCashCount.CallCashCount();
                    }
                    if (deductSchedSubmProcessor.ErrorNbr <= 0)
                    {
                        this.PopulateGrid();
                        //列印憑證的方法
            PrePrint(rtxn, rtxnCollection, deductSchedNbr.ToString().PadLeft(8, '0'), deductSchedSubmProcessor.SubmdNbr.ToString(), approvepersnbr);
                    }

                    return true;
                }
            }
            return false;
        }










//**************************************************************************//
        //****************      轉賬支票取款時列印憑條   ***************************//
        //**************************************************************************//
        private void PrePrint(Rtxn rtxn, RtxnCollection childRtxn, string deductSchedNbr, string submdNbr, long approvepersnbr)
        {
            string rgAcctnbr = null;//付款人賬號
            string rgName = null;//付款人名稱
            string rgChecknbr = null;//轉賬支票號
            Acct rgAcct = null;
            string resultString = string.Empty;
            if ((childRtxn != null) && (childRtxn[0].CheckNbr.ToString() != null) && (childRtxn[0].CheckNbr.ToString() != ""))
            {
                resultString = CoreMessageBox.Show(new string[] { "確定" }, 0L, "請插入支票背面,按確定按鈕開始列印", new object[0]);
            }
            else
            {
                resultString = CoreMessageBox.Show(new string[] { "確定" }, 0L, "請插入通用業務憑證,按確定按鈕開始列印", new object[0]);
            }
            if (resultString == "確定")
            {
                try
                {
                    //子交易(透過轉賬支票從單位賬戶取款)
                    if (childRtxn != null)
                    {
                        Rtxn rtxnChild = childRtxn[0];

                        rgAcct = Acct.GetAcct(rtxnChild.AcctNbr, new object[] { 0L });
                        if ((orgAcct != null) && (orgAcct.MjAcctTypCd.ToString() == "GL"))
                        {
                            rgAcctnbr = rtxnChild.AcctNbr.ToString();
                            //orgName = orgAcct.BranchOrg.OrgName;//透過內部戶轉到清算賬戶
                            rgName = GlAcctTitle.GetDecodeGLAccttitl(rtxnChild.AcctNbr, new object[] { }).GlAcctTitleName.ToString();//
                        }
                        else
                        {
                            rgAcctnbr = rtxnChild.MediumId;  //單位帳號
                            if (orgAcct != null && orgAcct.TaxRptForOrgNbr.HasValue && (orgAcct.TaxRptForOrgNbr.Value > 0L))
                            {
                                rgName = orgAcct.TaxRptForOrganization.OrgName;  //單位名稱                    
                            }
                            else
                            {
                                rgName = "";  //單位名稱                
                            }
                        }

                        rgChecknbr = rtxnChild.CheckNbr.ToString();  //轉賬支票號
                    }
                    else
                    {
                        CoreMessageBox.Show("沒有需要列印的交易!");
                        return;
                    }

                    System.Collections.Hashtable ht = new System.Collections.Hashtable();
                    ht.Add("serialNumber", string.Concat(rtxn.AcctNbr, rtxn.RtxnNbr)); //交易流水號
                    ht.Add("tranType", "(代發工資)批次入賬");  //交易型別
                    RtxnStatHist _rtxnStatHist = RtxnStatHist.GetRtxnStatHist(rtxn.AcctNbr, rtxn.RtxnNbr, new object[] { RtxnStatHistFetch.TransDetail });
                    if (_rtxnStatHist != null)
                    {
                        ht.Add("tranDate", _rtxnStatHist.PostDate.Value.ToString("yyyy-MM-dd"));  //交易記賬日期
                        ht.Add("tranTime", ((DateTime)_rtxnStatHist.ActDateTime).ToString("HH:mm:ss"));  //交易時間
                    }
                    else
                    {
                        ht.Add("tranDate", CoreUser.PostingDate.ToString("yyyy-MM-dd"));  //交易記賬日期
                        ht.Add("tranTime", base.CurrTime.ToString("HH:mm:ss"));  //交易時間
                    }

                    ht.Add("checkno", orgChecknbr);  //支票號
                    ht.Add("deductschednbr", deductSchedNbr);  //協議號
                    ht.Add("submdnbr", submdNbr);  //批次號
                    ht.Add("payeeName", orgName);  //付款人名稱(單位賬戶)
                    ht.Add("payeeAcctnbr", orgAcctnbr);  //付款人賬號
                    if (rtxn.Account != null && rtxn.Account.BranchOrgNbr.HasValue && (rtxn.Account.BranchOrgNbr.Value > 0L))
                    {
                        ht.Add("receiverName", rtxn.Account.BranchOrg.OrgName);  //收款人名稱(銀行內部戶)   
                        ht.Add("receiverBankName", rtxn.Account.BranchOrg.OrgName);  //收款人開戶行(銀行內部戶)
                    }
                    else
                    {
                        ht.Add("receiverName", "");  //收款人名稱(銀行內部戶)
                        ht.Add("receiverBankName", "");  //收款人開戶行(銀行內部戶)
                    }
                    ht.Add("receiverAcctnbr", rtxn.AcctNbr);  //收款人賬號(銀行內部戶)
                    ht.Add("Currency", Acct.GetAcct(rtxn.AcctNbr).AccountCurrency.CurrencyDesc); //幣種
                    ht.Add("traamtxiaoxie", Math.Abs(rtxn.TranAmt.Value).ToString("C"));//金額 (小寫)
                    ht.Add("traamtdaxie", Math.Abs(rtxn.TranAmt.Value).ToString());//金額 (大寫)
                    //ht.Add("des", "代發單位透過轉賬支票進行代發工資批次入賬");//備       注
                    if ((orgAcct != null) && (orgAcct.MjAcctTypCd.ToString() == "GL"))
                    {
                        ht.Add("des", "代發單位透過【內部賬戶】進行代發工資批次入賬");//備      注
                    }
                    else
                    {
                        if (orgChecknbr != null && orgChecknbr != "")
                        {
                            ht.Add("des", "代發單位透過【轉賬支票】進行代發工資批次入賬");//備      注
                        }
                        else
                        {
                            ht.Add("des", "代發單位透過【提款】進行代發工資批次入賬");//備      注
                        }
                    }

                    ht.Add("transactor", CoreUser.SAFUserName);//經       辦
                    Pers pers;
                    string approverPersName = "";
                    if (approvepersnbr != long.MinValue)
                    {
                        pers = Pers.GetPers(approvepersnbr, new object[] { });
                        if (pers != null)
                        {
                            approverPersName = pers.LastName;
                        }
                    }

                    if (rtxn != null && rtxn.ApproverPersNbr != long.MinValue)
                    {
                        pers = Pers.GetPers(rtxn.ApproverPersNbr, new object[] { });
                        if (pers != null)
                        {
                            approverPersName = pers.LastName;
                        }
                    }

                    ht.Add("authorization", approverPersName);//授       權

                    //資料準備完成開始列印
                    #region 轉賬支票取款憑證
                    //OSI.Core.Windows.Printing.PrintManager pm = new OSI.Core.Windows.Printing.PrintManager();
                    //OSI.Core.Windows.Query.DynamicQueryManager dqm = new OSI.Core.Windows.Query.DynamicQueryManager();
                    //CoreMessageBox.Show("請插入支票背面,開始列印");
                    //20110916 zxy 修改 {16} 自2623換行到2628   新加 {18},用於在通用憑證右上角列印  年   月    日 
                    string str = string.Format(
                    @"
                                                                  {18}
      {0}{1}
      {2}{3}
      {4}{5}
      {6}
      {7}
      {8}
      {9}
      {10}
      {11}
      {12}
      {13}{14}
      {15}
     




      {16}{17}
     
",
                              OSI.Core.Windows.Printing.PrintUtil.PadLeft(string.Concat("流 水 號:", ht["serialNumber"]), 39),
                                                                          string.Concat("交易型別:", ht["tranType"]),
                              OSI.Core.Windows.Printing.PrintUtil.PadLeft(string.Concat("交易日期:", ht["tranDate"]), 39),
                                                                          string.Concat("交易時間:", ht["tranTime"]),
                              OSI.Core.Windows.Printing.PrintUtil.PadLeft(string.Concat("協 議 號:", ht["deductschednbr"]), 39),
                                                                          string.Concat("批 次 號:", ht["submdnbr"]),
                                                                          string.Concat("支 票 號:", ht["checkno"]),
                                                                          string.Concat("付 款 人:", ht["payeeName"]),
                                                                          string.Concat("付款賬號:", ht["payeeAcctnbr"]),
                                                                          string.Concat("收 款 人:", ht["receiverName"]),
                                                                          string.Concat("收款賬號:", ht["receiverAcctnbr"]),
                                                                          string.Concat("收款人開戶行:", ht["receiverBankName"]),
                                                                          string.Concat("幣    種:", ht["Currency"]),

                              OSI.Core.Windows.Printing.PrintUtil.PadLeft(string.Concat("金    額(小寫):", ht["traamtxiaoxie"]), 39),
                              string.Concat("金    額(大寫):", OSI.Core.Windows.Printing.PrintUtil.MoneyToChinese(ht["traamtdaxie"].ToString())),
                                                                          string.Concat("備    注:", ht["des"]),
                              OSI.Core.Windows.Printing.PrintUtil.PadLeft(string.Concat("經    辦:", ht["transactor"].ToString().Trim()), 39),//20110916 zxy 新增OSI.Core.Windows.Printing.PrintUtil.PadLeft(
                                                                          string.Concat("授    權:", ht["authorization"]),//20110916 zxy 新加右括號及逗號
                              OSI.Core.Windows.Printing.PrintUtil.PadLeft("年" + OSI.Core.Security.CoreUser.PostingDate.Year.ToString() + "月" + OSI.Core.Security.CoreUser.PostingDate.Month.ToString() + "日" + OSI.Core.Security.CoreUser.PostingDate.Day.ToString(), 100));//20110916 zxy 新添

                     

                    OSI.Framework.Trace.TraceWriter.WriteFile(str);

                    //dqm.ClearPrtVarArray();
                    //dqm.SetPrtVarArrayText(0, str);
                    //pm.Print(6000020, dqm);
                   
                    RtxnStatHistPrt rxhp = RtxnStatHistPrt.NewRtxnStatHistPrt();
                    rxhp.AcctNbr = Convert.ToInt64(rtxn.AcctNbr);
                    rxhp.RtxnNbr = Convert.ToInt32(rtxn.RtxnNbr);
                    rxhp.ActDateTime = _rtxnStatHist.ActDateTime.GetValueOrDefault();
                    rxhp.TimeUniquExtn = _rtxnStatHist.TimeUniqueExtn.GetValueOrDefault();
                    rxhp.PrtItemTypCd = "PAYD";
                    rxhp.PrtItemStr = str;
                    rxhp.Save();
                    OSI.Core.Windows.Printing.PrintManager pm = new OSI.Core.Windows.Printing.PrintManager();
                    pm.Print(6000223, str, "代發工資批次入賬憑條列印");


                    #endregion
                }
                catch (Exception ex)
                {
                    CoreMessageBox.Show("列印失敗");
                }

            }

        }









//列印憑證的結果

                                                              年2012月5日15                                                                                      
      流 水 號:183903053010ss290            交易型別:(xss)abc
      交易日期:2023-05-15                   交易時間:19:40:23
      協 議 號:00000192                     批 次 號:6
      支 票 號:
      付 款 人:ab
      付款賬號:2334
      收 款 人:sx銀行結算管理部(清算中心)
      收款賬號:22333
      收款人開戶行:sx銀行結算管理部(清算中心)
      幣    種:人民幣
      金    額(小寫):¥20.00              金    額(大寫):貳拾元整
      備    注:代發單位透過【提款】進行代發工資批次入賬
     




      經    辦:axs                          授    權:
      

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/9240380/viewspace-707749/,如需轉載,請註明出處,否則將追究法律責任。

相關文章