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

namespace TellerSystem.Contract.Function
{
    /// <summary>
    /// 抵质押物库存查询(文件)
    /// 根据相关要素，返回符合条件的库存抵质押品列表
    /// </summary>
    public class QueryCollateralStock : TFOutput
    {
        #region Output
        /// <summary>
        /// 库存列表
        /// 担保合同号|抵质押品编号|抵质押品认定价值|抵质押品评估价值|贷款账号|贷款户名|抵质押类型|抵质押品名称|质押存单账号|抵质押品所有人户名|当前状态|入库日期|出库日期|借据号|抵质押品与担保合同关联关系|
        /// </summary>
        public string KCLB { get; internal set; }

        /// <summary>
        /// 库存列表
        /// 担保合同号|抵质押品编号|抵质押品认定价值|抵质押品评估价值|贷款账号|贷款户名|抵质押类型|抵质押品名称|质押存单账号|抵质押品所有人户名|当前状态|入库日期|出库日期|借据号|抵质押品与担保合同关联关系|
        /// </summary>
        public List<E_KCLB> KCLBData { get; internal set; }

        /// <summary>
        /// 库存列表
        /// 担保合同号|抵质押品编号|抵质押品认定价值|抵质押品评估价值|贷款账号|贷款户名|抵质押类型|抵质押品名称|质押存单账号|抵质押品所有人户名|当前状态|入库日期|出库日期|借据号|抵质押品与担保合同关联关系|
        /// </summary>
        public class E_KCLB
        {
            /// <summary>
            /// 担保合同号
            /// </summary>
            public string DBHTH { get; set; }

            /// <summary>
            /// 抵质押品编号
            /// </summary>
            public string DZYPBH { get; set; }

            /// <summary>
            /// 抵质押品认定价值
            /// </summary>
            public string DZYPRDJZ { get; set; }

            /// <summary>
            /// 抵质押品评估价值
            /// </summary>
            public string DZYPPGJZ { get; set; }

            /// <summary>
            /// 贷款账号
            /// </summary>
            public string DKZH { get; set; }

            /// <summary>
            /// 贷款户名
            /// </summary>
            public string DKHM { get; set; }

            /// <summary>
            /// 抵质押类型
            /// </summary>
            public string DZYLX { get; set; }

            /// <summary>
            /// 抵质押品名称
            /// </summary>
            public string DZYPMC { get; set; }

            /// <summary>
            /// 质押存单账号
            /// </summary>
            public string ZYCDZH { get; set; }

            /// <summary>
            /// 抵质押品所有人户名
            /// </summary>
            public string DZYPSYRHM { get; set; }

            /// <summary>
            /// 当前状态
            /// </summary>
            public string DQZT { get; set; }

            /// <summary>
            /// 入库日期
            /// </summary>
            public string RKRQ { get; set; }

            /// <summary>
            /// 出库日期
            /// </summary>
            public string CKRQ { get; set; }

            /// <summary>
            /// 借据号
            /// </summary>
            public string JJH { get; set; }

            /// <summary>
            /// 抵质押品与担保合同关联关系
            /// </summary>
            public string DZYPYDBHTGLGX { get; set; }

        }

        #endregion

        #region Input
		/// <summary>
        /// 参数清单
        /// </summary>
        public class Input : TFInput
        {
            /// <summary>
            /// 户名 0250
            ///  
            /// </summary>
            public string HM { get; set; }

            /// <summary>
            /// 担保合同号 0380
            ///  
            /// </summary>
            public string DBHTH { get; set; }

            /// <summary>
            /// 入库起始时间 0460
            ///  
            /// </summary>
            public string QSSJ { get; set; }

            /// <summary>
            /// 入库终止时间 0470
            ///  
            /// </summary>
            public string ZZSJ { get; set; }

            /// <summary>
            /// 状态 0700
            /// *-全部 0-入库 1-出库 Y-待出库 
            /// </summary>
            public string ZT { get; set; }

            /// <summary>
            /// 抵质押类型 0710
            /// 0-全部 1-抵押 2-质押 
            /// </summary>
            public string DZYLX { get; set; }


            /// <summary>                 
            /// 定义业务逻辑              
            /// </summary>                
            /// <returns></returns>  
            public override TFOutput Raise()
            {
                //拉取数据                                  
                var output = new QueryCollateralStock();
                PageData.TradeAPIs.InitFd(MessageData);
                PageData.TradeAPIs.CommSend(MessageData);
				MessageData.Fd126_5 = MainCode;
                MessageData.Fd16 = "CXCL";
                MessageData.Fd25 = HM;
                MessageData.Fd38 = DBHTH;
                MessageData.Fd46 = QSSJ;
                MessageData.Fd47 = ZZSJ;
                MessageData.Fd70 = ZT;
                MessageData.Fd71 = DZYLX;
                MessageData.Fd128 = "0050";

                PageData.TradeAPIs.CallServer(MessageData);
                if (MessageData.Fd12 != "0000")
                {
                    output.IsFailed = true;
                    output.FailureCause = PageData.TradeAPIs.GetError(MessageData);
                }                
                output.KCLBData = AnilyzeFileData<E_KCLB>(MessageData.FileData,
                                            "担保合同号|抵质押品编号|抵质押品认定价值|抵质押品评估价值|贷款账号|贷款户名|抵质押类型|抵质押品名称|质押存单账号|抵质押品所有人户名|当前状态|入库日期|出库日期|借据号|抵质押品与担保合同关联关系|",
                                            x =>
                                            {
                                                return new E_KCLB
                                                {
                                                    DBHTH = x["担保合同号"],
                                                    DZYPBH = x["抵质押品编号"],
                                                    DZYPRDJZ = x["抵质押品认定价值"],
                                                    DZYPPGJZ = x["抵质押品评估价值"],
                                                    DKZH = x["贷款账号"],
                                                    DKHM = x["贷款户名"],
                                                    DZYLX = x["抵质押类型"],
                                                    DZYPMC = x["抵质押品名称"],
                                                    ZYCDZH = x["质押存单账号"],
                                                    DZYPSYRHM = x["抵质押品所有人户名"],
                                                    DQZT = x["当前状态"],
                                                    RKRQ = x["入库日期"],
                                                    CKRQ = x["出库日期"],
                                                    JJH = x["借据号"],
                                                    DZYPYDBHTGLGX = x["抵质押品与担保合同关联关系"]
                                                };
                                            });
                output.KCLB = MessageData.FileData;

                return output;
            }
        }
        #endregion
    }
}
