using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;

namespace TellerSystem.Contract.Function
{
    /// <summary>
    /// 根据打包合同号查询录入或已审核的贴现信息
    /// 根据合同号查询所有的录入或已审核的贴现信息，返回文件
    /// </summary>
    public class QueryAccordPackingNum : TFOutput
    {
        #region Output
        /// <summary>
        /// 文件
        /// 文件格式： 协议编号|转贴现率|转贴现利息|本地异地|在途天数|票据类型|票据号码|票面金额|票到期日|申请人名称| 总条数| 总票据金额| 总贴现利息|
        /// </summary>
        public string WJ { get; internal set; }

        /// <summary>
        /// 文件
        /// 文件格式： 协议编号|转贴现率|转贴现利息|本地异地|在途天数|票据类型|票据号码|票面金额|票到期日|申请人名称| 总条数| 总票据金额| 总贴现利息|
        /// </summary>
        public List<E_WJ> WJData { get; internal set; }

        /// <summary>
        /// 文件
        /// 文件格式： 协议编号|转贴现率|转贴现利息|本地异地|在途天数|票据类型|票据号码|票面金额|票到期日|申请人名称| 总条数| 总票据金额| 总贴现利息|
        /// </summary>
        public class E_WJ
        {
            /// <summary>
            /// 协议编号
            /// </summary>
            public string XYBH { get; set; }

            /// <summary>
            /// 转贴现率
            /// </summary>
            public string ZTXL { get; set; }

            /// <summary>
            /// 转贴现利息
            /// </summary>
            public string ZTXLX { get; set; }

            /// <summary>
            /// 本地异地
            /// </summary>
            public string BDYD { get; set; }

            /// <summary>
            /// 在途天数
            /// </summary>
            public string ZTTS { get; set; }

            /// <summary>
            /// 票据类型
            /// </summary>
            public string PJLX { get; set; }

            /// <summary>
            /// 票据号码
            /// </summary>
            public string PJHM { get; set; }

            /// <summary>
            /// 票面金额
            /// </summary>
            public string PMJE { get; set; }

            /// <summary>
            /// 票到期日
            /// </summary>
            public string PDQR { get; set; }

            /// <summary>
            /// 申请人名称
            /// </summary>
            public string SQRMC { get; set; }

            /// <summary>
            ///  总条数
            /// </summary>
            public string ZTS { get; set; }

            /// <summary>
            ///  总票据金额
            /// </summary>
            public string ZPJJE { get; set; }

            /// <summary>
            ///  总贴现利息
            /// </summary>
            public string ZTXLX_1 { get; set; }

        }

        #endregion

        #region Input
		/// <summary>
        /// 参数清单
        /// </summary>
        public class Input : TFInput
        {
            /// <summary>
            /// 打包合同号 0620
            /// (null) 
            /// </summary>
            public string DBHTH { get; set; }

            /// <summary>
            /// 区分标志 0670
            /// X录入 2已审核 
            /// </summary>
            public string QFBZ { get; set; }


            /// <summary>                 
            /// 定义业务逻辑              
            /// </summary>                
            /// <returns></returns>  
            public override TFOutput Raise()
            {
                //拉取数据                                  
                var output = new QueryAccordPackingNum();
                PageData.TradeAPIs.InitFd(MessageData);
                PageData.TradeAPIs.CommSend(MessageData);
				MessageData.Fd126_5 = MainCode;
                MessageData.Fd16 = "CXCL";
                MessageData.Fd62 = DBHTH;
                MessageData.Fd67 = QFBZ;
                MessageData.Fd128 = "0007";

                PageData.TradeAPIs.CallServer(MessageData);
                if (MessageData.Fd12 != "0000")
                {
                    output.IsFailed = true;
                    output.FailureCause = PageData.TradeAPIs.GetError(MessageData);
                }                
                output.WJData = AnilyzeFileData<E_WJ>(MessageData.FileData,
                                            "协议编号|转贴现率|转贴现利息|本地异地|在途天数|票据类型|票据号码|票面金额|票到期日|申请人名称| 总条数| 总票据金额| 总贴现利息|",
                                            x =>
                                            {
                                                return new E_WJ
                                                {
                                                    XYBH = x["协议编号"],
                                                    ZTXL = x["转贴现率"],
                                                    ZTXLX = x["转贴现利息"],
                                                    BDYD = x["本地异地"],
                                                    ZTTS = x["在途天数"],
                                                    PJLX = x["票据类型"],
                                                    PJHM = x["票据号码"],
                                                    PMJE = x["票面金额"],
                                                    PDQR = x["票到期日"],
                                                    SQRMC = x["申请人名称"],
                                                    ZTS = x[" 总条数"],
                                                    ZPJJE = x[" 总票据金额"],
                                                    ZTXLX_1 = x[" 总贴现利息"]
                                                };
                                            });
                output.WJ = MessageData.FileData;

                return output;
            }
        }
        #endregion
    }
}
