Exemplo n.º 1
0
        /// <summary>
        /// 得到用户的销售单列表
        /// </summary>
        /// <param name="UserId">用户编号</param>
        /// <returns></returns>
        public DataTable GetOrders(string UserId)
        {
            var area = _assSalesOrderRepository.GetAll();

            if (!string.IsNullOrEmpty(UserId))
            {
                area = area.Where(a => a.SALESPERSON == UserId);
            }
            var list = from assSalesOrder in area
                       join user in SMOWMSDbContext.coreUsers on assSalesOrder.SALESPERSON equals user.USER_ID
                       orderby assSalesOrder.CREATEDATE descending
                       select new AssSOListOutputDto()
            {
                SOID            = assSalesOrder.SOID,
                NAME            = assSalesOrder.NAME,
                SALESPERSON     = assSalesOrder.SALESPERSON,
                SALESPERSONNAME = user.USER_NAME,
                STATUS          = assSalesOrder.STATUS,
                STATUSNAME      = "",
                Time            = "",
                REALID          = assSalesOrder.REALID,
                CREATEDATE      = assSalesOrder.CREATEDATE
            };
            var temTable = LINQToDataTable.ToDataTable(list);

            foreach (DataRow row in temTable.Rows)
            {
                AssSalesOrderRow assSalesOrderRow = _assSoRowRepository.GetBySOID(row["SOID"].ToString()).FirstOrDefault();
                AssTemplate      assTemplate      = _assTemplateRepository.GetById(assSalesOrderRow.TEMPLATEID).FirstOrDefault();
                row["Image"] = assTemplate.IMAGE;

                int status = int.Parse(row["STATUS"].ToString());
                row["STATUSNAME"] = Enum.GetName(typeof(SalesOrderStatus), status);
                row["Time"]       = DateTime.Parse(row["CREATEDATE"].ToString()).ToShortDateString();
            }
            return(temTable);
        }
Exemplo n.º 2
0
        /// <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);
            }
        }
Exemplo n.º 3
0
        /// <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);
            }
        }