/// <summary>
        /// 修改销售单
        /// </summary>
        /// <param name="inputDto">销售单信息</param>
        /// <returns></returns>
        public ReturnInfo UpdateSalesOrderOnly(AssSalesOrderInputDto inputDto)
        {
            ReturnInfo    RInfo        = new ReturnInfo();
            StringBuilder sb           = new StringBuilder();
            string        ValidateInfo = Helper.BasicValidate(inputDto).ToString();

            sb.Append(ValidateInfo);
            if (sb.Length == 0)
            {
                try
                {
                    AssSalesOrder salesOrder = _assSalesOrderRepository.GetById(inputDto.SOID).FirstOrDefault();
                    if (salesOrder != null)
                    {
                        salesOrder.CUSID       = inputDto.CUSID;
                        salesOrder.SALESPERSON = inputDto.SALESPERSON;
                        salesOrder.REALID      = inputDto.REALID;
                        salesOrder.MODIFYUSER  = inputDto.MODIFYUSER;
                        salesOrder.NAME        = inputDto.NAME;
                        salesOrder.MODIFYDATE  = DateTime.Now;
                        salesOrder.CREATEDATE  = salesOrder.CREATEDATE;
                        _unitOfWork.RegisterDirty(salesOrder);
                    }

                    //得到原有行项的所有TemplateId
                    List <string> TempIds = _assSoRowRepository.GetAll().Where(a => a.SOID == inputDto.SOID)
                                            .Select(a => a.TEMPLATEID).ToList();
                    //得到现在行项的所有TemplateId
                    List <string> NowTempIds = inputDto.RowInputDtos.Select(a => a.TEMPLATEID).ToList();
                    //得到更新的
                    List <string> Update = TempIds.Intersect(NowTempIds).ToList();
                    //得到新增的
                    List <string> Add = NowTempIds.Except(TempIds).ToList();
                    //得到删除的
                    List <string> Delete = TempIds.Except(NowTempIds).ToList();

                    foreach (var templateId in Add)
                    {
                        var info             = inputDto.RowInputDtos.Find(a => a.TEMPLATEID == templateId);
                        AssSalesOrderRow row = new AssSalesOrderRow()
                        {
                            SOID           = inputDto.SOID,
                            CREATEDATE     = DateTime.Now,
                            CREATEUSER     = inputDto.CREATEUSER,
                            MODIFYDATE     = DateTime.Now,
                            MODIFYUSER     = inputDto.CREATEUSER,
                            QUANTOUT       = 0,
                            QUANTRETREATED = info.QUANT,
                            REALPRICE      = info.PRICE,
//                            Time = DateTime.Now,
                            QUANTSALED = 0,
                            STATUS     = (int)SalesOrderStatus.销售中,
                            TEMPLATEID = templateId
                        };
                        _unitOfWork.RegisterNew(row);
                    }

                    foreach (var templateId in Delete)
                    {
                        AssSalesOrderRow row = _assSoRowRepository
                                               .GetBySOIDandTemplateID(inputDto.SOID, templateId).FirstOrDefault();
                        if (row != null)
                        {
                            _unitOfWork.RegisterDeleted(row);
                        }
                    }

                    foreach (var templateId in Update)
                    {
                        var info             = inputDto.RowInputDtos.Find(a => a.TEMPLATEID == templateId);
                        AssSalesOrderRow row = _assSoRowRepository
                                               .GetBySOIDandTemplateID(inputDto.SOID, templateId).FirstOrDefault();
                        if (row != null)
                        {
                            row.MODIFYDATE = DateTime.Now;
                            row.MODIFYUSER = inputDto.CREATEUSER;
//                            row.Time = DateTime.Now;
                            row.QUANTOUT       = 0;
                            row.QUANTRETREATED = 0;
                            row.QUANTSALED     = 0;
                            row.STATUS         = (int)SalesOrderStatus.销售中;
                            row.TEMPLATEID     = templateId;
                            row.REALPRICE      = info.PRICE;
                            row.QUANTSALED     = info.QUANT;
                            _unitOfWork.RegisterDirty(row);
                        }
                    }
                    bool result = _unitOfWork.Commit();
                    RInfo.IsSuccess = result;
                    RInfo.ErrorInfo = inputDto.SOID;
                    return(RInfo);
                }
                catch (Exception ex)
                {
                    _unitOfWork.Rollback();
                    sb.Append(ex.Message);
                    RInfo.IsSuccess = false;
                    RInfo.ErrorInfo = sb.ToString();
                    return(RInfo);
                }
            }
            else
            {
                RInfo.IsSuccess = false;
                RInfo.ErrorInfo = sb.ToString();
                return(RInfo);
            }
        }
        /// <summary>
        /// 添加销售单
        /// </summary>
        /// <param name="inputDto">销售单信息</param>
        /// <returns></returns>
        public ReturnInfo AddSalesOrder(AssSalesOrderInputDto inputDto)
        {
            ReturnInfo    RInfo = new ReturnInfo();
            StringBuilder sb    = new StringBuilder();

            if (string.IsNullOrEmpty(inputDto.SOID))
            {
                string MaxId = _assSalesOrderRepository.GetMaxId();
                string SoId  = Helper.GenerateIDEx2("S", MaxId);
                //产生资产编号
                inputDto.SOID = SoId;
            }
            string ValidateInfo = Helper.BasicValidate(inputDto).ToString();

            sb.Append(ValidateInfo);
            if (sb.Length == 0)
            {
                try
                {
                    AssSalesOrder salesOrder = Mapper.Map <AssSalesOrderInputDto, AssSalesOrder>(inputDto);
                    salesOrder.STATUS     = (int)SalesOrderStatus.销售中;
                    salesOrder.CREATEDATE = DateTime.Now;
                    salesOrder.MODIFYDATE = DateTime.Now;
                    _unitOfWork.RegisterNew(salesOrder);

                    foreach (var inputDtoRow in inputDto.RowInputDtos)
                    {
                        AssSalesOrderRow row = new AssSalesOrderRow
                        {
                            STATUS     = (int)SalesOrderStatus.销售中,
                            QUANTSALED = inputDtoRow.QUANT,
                            REALPRICE  = inputDtoRow.PRICE,
                            CREATEUSER = inputDtoRow.CREATEUSER,
                            MODIFYUSER = inputDtoRow.MODIFYUSER,
                            TEMPLATEID = inputDtoRow.TEMPLATEID,
                            CREATEDATE = DateTime.Now,
                            MODIFYDATE = DateTime.Now,
//                            Time = DateTime.Now,
                            SOID = inputDto.SOID
                        };
                        _unitOfWork.RegisterNew(row);
                    }
                    bool result = _unitOfWork.Commit();
                    RInfo.IsSuccess = result;
                    RInfo.ErrorInfo = inputDto.SOID;
                    return(RInfo);
                }
                catch (Exception ex)
                {
                    _unitOfWork.Rollback();
                    sb.Append(ex.Message);
                    RInfo.IsSuccess = false;
                    RInfo.ErrorInfo = sb.ToString();
                    return(RInfo);
                }
            }
            else
            {
                RInfo.IsSuccess = false;
                RInfo.ErrorInfo = sb.ToString();
                return(RInfo);
            }
        }