Exemplo n.º 1
0
        /// <summary>
        /// 自动确认收款单
        /// </summary>
        /// <param name="fileIdentity">上传文件标识符</param>
        /// <param name="soOutFromDate">订单出库起始时间</param>
        /// <param name="soOutToDate">订单出库结束时间</param>
        /// <param name="successSysNoList">成功确认的订单系统编号列表</param>
        /// <param name="failedSysNoList">确认失败的订单系统编号列表,包括匹配失败的订单编号</param>
        /// <param name="submitConfirmCount">成功提交审核的订单数(仅仅是成功提交,不保证能审核成功)</param>
        /// <param name="failedMessage">失败信息</param>
        public virtual void AutoConfirm(string fileIdentity, DateTime?soOutFromDate, DateTime?soOutToDate,
                                        out List <int> successSysNoList, out List <int> failedSysNoList, out int submitConfirmCount, out string failedMessage)
        {
            FileStream fs        = FileUploadManager.OpenFile(fileIdentity);
            DataTable  dataTable = ProcessUploadFile(fs);

            if (dataTable.Rows.Count == 0)
            {
                // throw new ECCentral.BizEntity.BizException("上传记录格式不正确,请重新上传");
                throw new ECCentral.BizEntity.BizException(ResouceManager.GetMessageString("Invoice.SOIncome", "SOIncome_FormatError"));
            }
            if (dataTable.Rows.Count > 1000)
            {
                //throw new ECCentral.BizEntity.BizException("上传记录大于1000条,会造成系统不稳定,请减少记录重试");
                throw new ECCentral.BizEntity.BizException(ResouceManager.GetMessageString("Invoice.SOIncome", "SOIncome_UploadCountLimitError"));
            }

            List <int> soSysNoList = new List <int>();

            dataTable.AsEnumerable().Where(r => r["OrderSysNo"] != null && !string.IsNullOrEmpty(r["OrderSysNo"].ToString()))
            .ForEach(row =>
            {
                int soSysNo;
                if (int.TryParse(row["OrderSysNo"].ToString(), out soSysNo))
                {
                    soSysNoList.Add(soSysNo);
                }
            });

            DateTime?fromDateTime = null;
            DateTime?toDateTime   = null;

            if (!soOutFromDate.HasValue)
            {
                fromDateTime = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1);
            }
            else
            {
                fromDateTime = soOutFromDate.Value;
            }
            if (soOutToDate.HasValue)
            {
                toDateTime = soOutToDate.Value.AddDays(1).AddSeconds(-1);
            }

            var normalSaleIncomeList = new List <SOIncomeInfo>();
            var masterSaleIncomeList = new List <SOIncomeInfo>();
            var errorMessage         = new StringBuilder();

            GetNeedConfirmSysNoList(soSysNoList, dataTable, fromDateTime, toDateTime, normalSaleIncomeList, masterSaleIncomeList, errorMessage);
            submitConfirmCount = normalSaleIncomeList.Count + masterSaleIncomeList.Count;
            ProcessAutoConfirm(normalSaleIncomeList, masterSaleIncomeList, dataTable, out successSysNoList, out failedSysNoList, errorMessage);

            failedMessage = errorMessage.ToString();
        }