/// <summary>
        /// 解析任务文件内容,获取任务具体内容
        /// </summary>
        /// <param name="filename"></param>
        /// <param name="tasktype">任务类型</param>
        /// <param name="refundtaskinfo">退购的任务信息</param>
        /// <param name="fileinfo">换表、销户的任务信息</param>
        /// <returns></returns>
        public static Boolean ParseTaskFile(String filename, ref eTaskType tasktype,
                                            ref RefundTaskInfo refundtaskinfo, ref MeterDisassemblyTaskInfo disassemblytaskinfo)
        {
            //首先,初始化解密任务文件的密钥
            InitKey(EncryptKey_TaskFile);

            //取出全部的文件内容
            String  encryptstr = String.Empty;
            Boolean bl         = FileProcessor.ReadFileString(filename, out encryptstr, false);

            if (!bl || String.IsNullOrEmpty(encryptstr))
            {
                return(false);
            }

            //解析

            String filestr = DencryptTaskFileInfo(encryptstr);

            if (String.IsNullOrEmpty(filestr))
            {
                return(false);
            }
            filestr = filestr.Trim();
            //获取任务类型
            bl = GetTaskType(filestr, ref tasktype);
            if (!bl)
            {
                return(false);
            }

            //根据不同的任务类型获取任务信息类数据
            bl = GetTaskInfo(tasktype, ref refundtaskinfo, ref disassemblytaskinfo);
            return(bl);
        }
        /// <summary>
        /// 创建任务文件
        /// </summary>
        /// <param name="tasktype"></param>
        /// <param name="refundtaskinfo"></param>
        /// <param name="disassemblytaskinfo"></param>
        /// <returnes></returns>
        public static Boolean BuildTaskFile(eTaskType tasktype,
                                            RefundTaskInfo refundtaskinfo, MeterDisassemblyTaskInfo resultinfo, ref String filenamestr)
        {
            //首先,初始化解密任务文件的密钥
            InitKey(EncryptKey_TaskFile);

            //根据任务类型,获取任务文件名,带全路径
            String filename = GetFileName(tasktype, refundtaskinfo, resultinfo, false);

            if (String.IsNullOrEmpty(filename))
            {
                return(false);
            }
            filename    = TaskFileFolderPath + filename;
            filenamestr = filename;

            //构建文件具体的内容
            String filecontentstr = GetTaskFileContent(tasktype, refundtaskinfo, resultinfo);

            if (String.IsNullOrEmpty(filecontentstr))
            {
                return(false);
            }

            //加密文件内容
            String encryptresfilestr = EncryptInfo(filecontentstr);

            //创建文件
            Boolean bl = FileProcessor.WriteFileString(filename, encryptresfilestr, false);

            return(true);
        }
        /// <summary>
        /// 根据RefundTaskInfo组合成任务文件内容
        /// 仅退购的任务
        /// </summary>
        /// <param name="refundtaskinfo"></param>
        /// <returns></returns>
        private static String GetTaskFileContent_Refund(RefundTaskInfo refundtaskinfo)
        {
            if (refundtaskinfo == null)
            {
                return(null);
            }
            List <String> contentlist = new List <string> {
            };

            /*TaskID=XX(当前的任务ID)
             * TaskType=0:退购,1:换表,2:销户
             * TechnicianID =XX(上门工程师的ID)
             * MeterAddress=012017062001(表通信地址)
             * TIDTestingToken=XXXX XXXX XXXX XXXX XXXX(测试TID的TOKEN,值为0)
             * RefundToken=XXXX XXXX XXXX XXXX XXXX(撤销金额的TOKEN)
             * RefundValue=0.00(根据用户走量还是走金额,从交易记录中获取对应的值)
             * MeterProtocolType=XX (表通信协议类型,eMeterProtocolType)
             * DecimalParameter=脉冲当量小数位数;计量模式;价格精度小数位数;结算精度小数位数;是否显示K
             * SetMeterKeyParam=XXXXXXXXXXXXX (STS卡表在开启或关闭红外的时候需要这个设置密钥来制卡)
             */

            String filestr = Const_TaskID + "=" + refundtaskinfo.TaskID.ToString();

            contentlist.Add(filestr);
            filestr = Const_TaskType + "=0";
            contentlist.Add(filestr);

            filestr = Const_RefundTradeID + "=" + refundtaskinfo.RefundTradeID.ToString();
            contentlist.Add(filestr);

            filestr = Const_TechnicianID + "=" + refundtaskinfo.TechnicianID.ToString();
            contentlist.Add(filestr);

            filestr = Const_MeterAddress + "=" + refundtaskinfo.MeterAddress;
            contentlist.Add(filestr);

            filestr = Const_TIDTestingToken + "=" + refundtaskinfo.TIDTestingToken;
            contentlist.Add(filestr);
            filestr = Const_RefundValue + "=" + refundtaskinfo.RefundValue.ToString("F2");
            contentlist.Add(filestr);

            filestr = Const_MeterProtocolType + "=" + ((Int32)refundtaskinfo.ProtocolType).ToString();
            contentlist.Add(filestr);

            filestr = Const_DecimalParameter + "=" + refundtaskinfo.DecimalParameter;
            contentlist.Add(filestr);

            filestr = Const_SetMeterKeyParam + "=" + refundtaskinfo.SetMeterKeyParam;
            contentlist.Add(filestr);

            String reslutfile = DataFormatProcessor.ListToString(contentlist, Environment.NewLine);

            return(reslutfile);
        }
        /// <summary>
        /// 获取任务文件内容
        /// </summary>
        /// <param name="type"></param>
        /// <param name="refundtaskinfo"></param>
        /// <param name="resultinfo"></param>
        /// <returns></returns>
        private static String GetTaskFileContent(eTaskType type, RefundTaskInfo refundtaskinfo, MeterDisassemblyTaskInfo resultinfo)
        {
            //根据任务类型
            switch (type)
            {
            case eTaskType.CloseCustomer:
            case eTaskType.ReplaceMeter:
                return(GetTaskFileContent_Replase(resultinfo));

            case eTaskType.Refund:
                return(GetTaskFileContent_Refund(refundtaskinfo));

            default:
                return(null);
            }
        }
        /// <summary>
        /// 根据任务类型,获取任务信息
        /// </summary>
        /// <param name="type"></param>
        /// <param name="refundtaskinfo"></param>
        /// <param name="disassemblytaskinfo"></param>
        /// <returns></returns>
        private static Boolean GetTaskInfo(eTaskType type, ref RefundTaskInfo refundtaskinfo, ref MeterDisassemblyTaskInfo disassemblytaskinfo)
        {
            refundtaskinfo      = null;
            disassemblytaskinfo = null;
            switch (type)
            {
            case eTaskType.Refund:
                return(GetTaskInfo_Refund(type, ref refundtaskinfo));

            case eTaskType.CloseCustomer:
            case eTaskType.ReplaceMeter:
                return(GetTaskInfo_Replace(type, ref disassemblytaskinfo));

            default:
                return(false);
            }
        }
Beispiel #6
0
        public void CopyFrom(RefundTaskInfo src)
        {
            base.CopyFrom((RefundTask)src);
            MeterAddress = src.MeterAddress;

            RefundValue      = src.RefundValue;
            PaymentAmount    = src.PaymentAmount;
            PurchaseAmount   = src.PurchaseAmount;
            PurchaseQuantity = src.PurchaseQuantity;

            CustomerNumber    = src.CustomerNumber;
            CustomerName      = src.CustomerName;
            CustomerTelephone = src.CustomerTelephone;
            CustomerAddress   = src.CustomerAddress;
            ServicemenName    = src.ServicemenName;

            IsCard           = src.IsCard;
            ProtocolType     = src.ProtocolType;
            DecimalParameter = src.DecimalParameter;
        }
        /// <summary>
        /// 获取退购的任务信息
        /// </summary>
        /// <param name="type"></param>
        /// <param name="refundtaskinfo"></param>
        /// <returns></returns>
        private static Boolean GetTaskInfo_Refund(eTaskType type, ref RefundTaskInfo refundtaskinfo)
        {
            if (m_dicFileCon == null)
            {
                return(false);
            }
            //判断任务类型,获取弹出的处理界面
            refundtaskinfo = new RefundTaskInfo {
            };
            //TaskID
            if (!m_dicFileCon.Keys.Contains(Const_TaskID))
            {
                return(false);
            }
            refundtaskinfo.TaskID = Convert.ToInt32(m_dicFileCon[Const_TaskID]);

            //RefundTradeID
            if (!m_dicFileCon.Keys.Contains(Const_RefundTradeID))
            {
                return(false);
            }
            refundtaskinfo.RefundTradeID = Convert.ToInt32(m_dicFileCon[Const_RefundTradeID]);

            //TechnicianID
            if (!m_dicFileCon.Keys.Contains(Const_TechnicianID))
            {
                return(false);
            }
            refundtaskinfo.TechnicianID = Convert.ToInt32(m_dicFileCon[Const_TechnicianID]);

            //MeterAddress
            if (!m_dicFileCon.Keys.Contains(Const_MeterAddress))
            {
                return(false);
            }
            refundtaskinfo.MeterAddress = m_dicFileCon[Const_MeterAddress];

            //TIDTestingToken
            if (!m_dicFileCon.Keys.Contains(Const_TIDTestingToken))
            {
                return(false);
            }
            refundtaskinfo.TIDTestingToken = m_dicFileCon[Const_TIDTestingToken];

            //RefundValue
            if (!m_dicFileCon.Keys.Contains(Const_RefundValue))
            {
                return(false);
            }
            refundtaskinfo.RefundValue = Convert.ToDouble(m_dicFileCon[Const_RefundValue]);

            //MeterProtocolType
            if (!m_dicFileCon.Keys.Contains(Const_MeterProtocolType))
            {
                return(false);
            }
            Int32 MeterProtocolType = Convert.ToInt32(m_dicFileCon[Const_MeterProtocolType]);

            refundtaskinfo.ProtocolType = MeterProtocolType;
            if (refundtaskinfo.ProtocolType == (Int32)eMeterProtocolType.STS_Card ||
                refundtaskinfo.ProtocolType == (Int32)eMeterProtocolType.STS_Card_LoRa ||
                refundtaskinfo.ProtocolType == (Int32)eMeterProtocolType.SoftwareSTS_Card ||
                refundtaskinfo.ProtocolType == (Int32)eMeterProtocolType.SoftwareSTS_Card_LoRa)
            {
                refundtaskinfo.IsCard = true;
            }

            //DecimalParameter
            if (!m_dicFileCon.Keys.Contains(Const_DecimalParameter))
            {
                return(false);
            }
            refundtaskinfo.DecimalParameter = m_dicFileCon[Const_DecimalParameter];

            //SetMeterKeyParam
            if (!m_dicFileCon.Keys.Contains(Const_SetMeterKeyParam))
            {
                return(false);
            }
            refundtaskinfo.SetMeterKeyParam = m_dicFileCon[Const_SetMeterKeyParam].Trim();

            return(true);
        }