예제 #1
0
        /// <summary>
        /// 保存库存图片
        /// </summary>
        /// <param name="paramAutoPartsPictureList">库存图片UIModel列表</param>
        /// <returns></returns>
        public bool SaveAutoPartsPicture(List <AutoPartsPictureUIModel> paramAutoPartsPictureList)
        {
            var funcName = "SaveAutoPartsPicture";

            LogHelper.WriteBussLogStart(BussID, LoginInfoDAX.UserName, funcName, "", "", null);

            #region 准备数据

            //待保存的库存图片列表
            List <MDLPIS_InventoryPicture> savePictureList = new List <MDLPIS_InventoryPicture>();

            foreach (var loopPicture in paramAutoPartsPictureList)
            {
                if (string.IsNullOrEmpty(loopPicture.SourceFilePath))
                {
                    continue;
                }
                #region 将图片保存到本地以及上传文件服务器

                string fileNetUrl        = string.Empty;
                bool   savePictureResult = BLLCom.SaveFileByFileName(loopPicture.SourceFilePath, loopPicture.INVP_PictureName, ref fileNetUrl);
                if (!savePictureResult)
                {
                    ResultMsg = MsgHelp.GetMsg(MsgCode.E_0010, new object[] { SystemActionEnum.Name.SAVE + MsgParam.AUTOPARTS_PICTURE });
                    LogHelper.WriteBussLogEndNG(BussID, LoginInfoDAX.UserName, funcName, ResultMsg, "", null);
                    return(false);
                }
                #endregion

                #region 保存库存图片数据

                //截取上传图片返回值中的文件名称
                int fileNameStartIndex = fileNetUrl.IndexOf("FileName=", StringComparison.Ordinal) + 1;
                int fileNameEndIndex   = fileNameStartIndex + "FileName=".Length;
                int length             = fileNetUrl.Length;
                //文件名称
                string tempFileName = fileNetUrl.Substring(fileNameEndIndex - 1, length - (fileNameEndIndex - 1));

                MDLPIS_InventoryPicture newAutoPartsPicture = new MDLPIS_InventoryPicture();

                _bll.CopyModel(loopPicture, newAutoPartsPicture);
                newAutoPartsPicture.INVP_PictureName = tempFileName;
                newAutoPartsPicture.INVP_IsValid     = true;
                newAutoPartsPicture.INVP_CreatedBy   = LoginInfoDAX.UserName;
                newAutoPartsPicture.INVP_CreatedTime = BLLCom.GetCurStdDatetime();
                newAutoPartsPicture.INVP_UpdatedBy   = LoginInfoDAX.UserName;
                newAutoPartsPicture.INVP_UpdatedTime = BLLCom.GetCurStdDatetime();

                newAutoPartsPicture.WHERE_INVP_ID        = newAutoPartsPicture.INVP_ID;
                newAutoPartsPicture.WHERE_INVP_VersionNo = newAutoPartsPicture.INVP_VersionNo;

                savePictureList.Add(newAutoPartsPicture);

                #endregion
            }

            #endregion

            #region 带事务的保存

            try
            {
                DBManager.BeginTransaction(DBCONFIG.Coeus);

                #region 保存单头

                foreach (var loopPicture in savePictureList)
                {
                    //执行保存
                    bool saveInvPictureResult = _bll.Save(loopPicture);
                    if (!saveInvPictureResult)
                    {
                        DBManager.RollBackTransaction(DBCONFIG.Coeus);

                        //保存失败,删除本地以及文件服务器上的图片
                        var outMsg = string.Empty;
                        BLLCom.DeleteFileByFileName(loopPicture.INVP_PictureName, ref outMsg);

                        ResultMsg = MsgHelp.GetMsg(MsgCode.E_0010, new object[] { SystemActionEnum.Name.SAVE + MsgParam.AUTOPARTS_PICTURE });
                        LogHelper.WriteBussLogEndNG(BussID, LoginInfoDAX.UserName, funcName, ResultMsg, "", null);
                        return(false);
                    }
                }
                #endregion

                DBManager.CommitTransaction(DBCONFIG.Coeus);
            }
            catch (Exception ex)
            {
                DBManager.RollBackTransaction(DBCONFIG.Coeus);

                foreach (var loopPicture in savePictureList)
                {
                    //保存失败,删除本地以及文件服务器上的图片
                    var outMsg = string.Empty;
                    BLLCom.DeleteFileByFileName(loopPicture.INVP_PictureName, ref outMsg);
                }

                ResultMsg = MsgHelp.GetMsg(MsgCode.E_0018, new object[] { SystemActionEnum.Name.SAVE, ex.Message });
                LogHelper.WriteBussLogEndNG(BussID, LoginInfoDAX.UserName, funcName, ex.Message, "", null);
                return(false);
            }

            #endregion

            #region 更新配件图片版本号
            foreach (var loopPicture in paramAutoPartsPictureList)
            {
                //保存成功,删除临时保存的图片
                if (File.Exists(loopPicture.SourceFilePath))
                {
                    File.Delete(loopPicture.SourceFilePath);
                }
                //本次保存的图片
                var thisSavePicture = savePictureList.FirstOrDefault(x => x.INVP_PictureName == loopPicture.INVP_PictureName);
                if (thisSavePicture != null)
                {
                    _bll.CopyModel(thisSavePicture, loopPicture);
                }
                //设置版本号
                if (loopPicture.INVP_VersionNo == null)
                {
                    loopPicture.INVP_VersionNo = 1;
                }
                else
                {
                    loopPicture.INVP_VersionNo += 1;
                }
            }
            #endregion

            return(true);
        }
예제 #2
0
        /// <summary>
        /// 保存
        /// </summary>
        /// <param name="paramHead"></param>
        /// <param name="paramDetailList"></param>
        /// <param name="paramPictureNameAndPath"></param>
        /// <returns></returns>
        public bool SaveDetailDS(ReceiptBillManagerUIModel paramHead, SkyCarBindingList <ReceiptBillManagerDetailUIModel, MDLFM_ReceiptBillDetail> paramDetailList,
                                 Dictionary <string, string> paramPictureNameAndPath)
        {
            var funcName = "SaveDetailDS";

            LogHelper.WriteBussLogStart(BussID, LoginInfoDAX.UserName, funcName, "", "", null);
            //服务端检查
            if (!ServerCheck(paramHead, paramDetailList))
            {
                return(false);
            }

            #region 准备数据

            #region 单头
            //将UIModel转为TBModel
            var argsHead = paramHead.ToTBModelForSaveAndDelete <MDLFM_ReceiptBill>();
            //判断主键是否被赋值
            if (string.IsNullOrEmpty(paramHead.RB_ID))
            {
                argsHead.RB_ID = Guid.NewGuid().ToString();
                //单号
                argsHead.RB_No          = BLLCom.GetCoeusDocumentNo(DocumentTypeEnums.Code.RB);
                argsHead.RB_CreatedBy   = LoginInfoDAX.UserName;
                argsHead.RB_CreatedTime = BLLCom.GetCurStdDatetime();
            }
            argsHead.RB_UpdatedBy   = LoginInfoDAX.UserName;
            argsHead.RB_UpdatedTime = BLLCom.GetCurStdDatetime();

            #endregion

            #region 明细

            //添加的明细
            if (paramDetailList != null && paramDetailList.InsertList != null &&
                paramDetailList.InsertList.Count > 0)
            {
                foreach (var loopDetailItem in paramDetailList)
                {
                    loopDetailItem.RBD_RB_ID       = argsHead.RB_ID ?? argsHead.WHERE_RB_ID;
                    loopDetailItem.RBD_RB_No       = argsHead.RB_No;
                    loopDetailItem.RBD_CreatedBy   = LoginInfoDAX.UserName;
                    loopDetailItem.RBD_CreatedTime = BLLCom.GetCurStdDatetime();
                    loopDetailItem.RBD_UpdatedBy   = LoginInfoDAX.UserName;
                    loopDetailItem.RBD_UpdatedTime = BLLCom.GetCurStdDatetime();
                }
            }
            #endregion

            #region   图片

            foreach (var loopPicture in paramPictureNameAndPath)
            {
                if (string.IsNullOrEmpty(loopPicture.Key) ||
                    string.IsNullOrEmpty(loopPicture.Value))
                {
                    continue;
                }

                #region 将图片保存到本地以及上传文件服务器

                string fileNetUrl        = string.Empty;
                bool   savePictureResult = BLLCom.SaveFileByFileName(loopPicture.Value, loopPicture.Key, ref fileNetUrl);
                if (!savePictureResult)
                {
                    ResultMsg = MsgHelp.GetMsg(MsgCode.E_0010, new object[] { SystemActionEnum.Name.SAVE + MsgParam.IMAGE });
                    LogHelper.WriteBussLogEndNG(BussID, LoginInfoDAX.UserName, funcName, ResultMsg, "", null);
                    return(false);
                }
                #endregion

                //截取上传图片返回值中的文件名称
                int fileNameStartIndex = fileNetUrl.IndexOf("FileName=", StringComparison.Ordinal) + 1;
                int fileNameEndIndex   = fileNameStartIndex + "FileName=".Length;
                int length             = fileNetUrl.Length;
                //文件名称
                string tempFileName = fileNetUrl.Substring(fileNameEndIndex - 1, length - (fileNameEndIndex - 1));

                //给各个图片赋值
                if (loopPicture.Key == argsHead.RB_CertificatePic)
                {
                    argsHead.RB_CertificatePic = tempFileName;
                }
            }
            #endregion

            #endregion

            #region 带事务的保存

            try
            {
                DBManager.BeginTransaction(DBCONFIG.Coeus);

                #region 保存单头

                //执行保存
                if (!_bll.Save(argsHead, argsHead.RB_ID))
                {
                    DBManager.RollBackTransaction(DBCONFIG.Coeus);

                    foreach (var loopPicture in paramPictureNameAndPath)
                    {
                        if (string.IsNullOrEmpty(loopPicture.Key) ||
                            string.IsNullOrEmpty(loopPicture.Value))
                        {
                            continue;
                        }
                        //保存失败,删除本地以及文件服务器上的图片
                        var outMsg = string.Empty;
                        BLLCom.DeleteFileByFileName(loopPicture.Key, ref outMsg);
                    }

                    ResultMsg = MsgHelp.GetMsg(MsgCode.E_0010, new object[] { SystemActionEnum.Name.SAVE + SystemTableEnums.Name.FM_ReceiptBill });
                    LogHelper.WriteBussLogEndNG(BussID, LoginInfoDAX.UserName, funcName, ResultMsg, "", null);
                    return(false);
                }

                #endregion

                #region 保存明细

                //执行保存
                if (!_bll.UnitySave(paramDetailList))
                {
                    DBManager.RollBackTransaction(DBCONFIG.Coeus);

                    foreach (var loopPicture in paramPictureNameAndPath)
                    {
                        if (string.IsNullOrEmpty(loopPicture.Key) ||
                            string.IsNullOrEmpty(loopPicture.Value))
                        {
                            continue;
                        }
                        //保存失败,删除本地以及文件服务器上的图片
                        var outMsg = string.Empty;
                        BLLCom.DeleteFileByFileName(loopPicture.Key, ref outMsg);
                    }

                    ResultMsg = MsgHelp.GetMsg(MsgCode.E_0010, new object[] { SystemActionEnum.Name.SAVE + SystemTableEnums.Name.FM_ReceiptBillDetail });
                    LogHelper.WriteBussLogEndNG(BussID, LoginInfoDAX.UserName, funcName, ResultMsg, "", null);
                    return(false);
                }

                #endregion

                DBManager.CommitTransaction(DBCONFIG.Coeus);
            }
            catch (Exception ex)
            {
                DBManager.RollBackTransaction(DBCONFIG.Coeus);

                foreach (var loopPicture in paramPictureNameAndPath)
                {
                    if (string.IsNullOrEmpty(loopPicture.Key) ||
                        string.IsNullOrEmpty(loopPicture.Value))
                    {
                        continue;
                    }
                    //保存失败,删除本地以及文件服务器上的图片
                    var outMsg = string.Empty;
                    BLLCom.DeleteFileByFileName(loopPicture.Key, ref outMsg);
                }

                ResultMsg = MsgHelp.GetMsg(MsgCode.E_0018, new object[] { SystemActionEnum.Name.SAVE, ex.Message });
                LogHelper.WriteBussLogEndNG(BussID, LoginInfoDAX.UserName, funcName, ex.Message, "", null);
                return(false);
            }

            #endregion

            //将最新数据回写给DetailDS
            CopyModel(argsHead, paramHead);

            //更新明细版本号
            if (paramDetailList != null)
            {
                if (paramDetailList.InsertList != null)
                {
                    foreach (var loopInsertDetail in paramDetailList.InsertList)
                    {
                        //新增时版本号为1
                        loopInsertDetail.RBD_VersionNo = 1;
                    }
                }

                foreach (var loopUpdateDetail in paramDetailList.UpdateList)
                {
                    //更新时版本号加1
                    loopUpdateDetail.RBD_VersionNo = loopUpdateDetail.RBD_VersionNo + 1;
                }
            }

            foreach (var loopPicture in paramPictureNameAndPath)
            {
                if (string.IsNullOrEmpty(loopPicture.Key) ||
                    string.IsNullOrEmpty(loopPicture.Value))
                {
                    continue;
                }
                //保存成功,删除临时保存的图片
                if (File.Exists(loopPicture.Value))
                {
                    File.Delete(loopPicture.Value);
                }
            }
            return(true);
        }
예제 #3
0
        /// <summary>
        /// 审核
        /// </summary>
        /// <param name="paramHead">物流单</param>
        /// <param name="paramDetailList">物流单明细列表</param>
        /// <returns></returns>
        public bool ApproveDetailDS(LogisticsBillManagerUIModel paramHead, SkyCarBindingList <LogisticsBillDetailManagerUIModel, MDLSD_LogisticsBillDetail> paramDetailList,
                                    Dictionary <string, string> paramPictureNameAndPath)
        {
            var funcName = "ApproveDetailDS";

            LogHelper.WriteBussLogStart(BussID, LoginInfoDAX.UserName, funcName, "", "", null);

            if (paramHead == null ||
                string.IsNullOrEmpty(paramHead.LB_ID) ||
                string.IsNullOrEmpty(paramHead.LB_No))
            {
                //没有获取到物流单,审核失败
                ResultMsg = MsgHelp.GetMsg(MsgCode.W_0024, new object[] { SystemTableEnums.Name.SD_LogisticsBill, SystemActionEnum.Name.APPROVE });
                LogHelper.WriteBussLogEndNG(BussID, LoginInfoDAX.UserName, funcName, ResultMsg, "", null);
                return(false);
            }

            #region 准备数据

            #region 变量定义

            //待更新的当前[物流单]
            MDLSD_LogisticsBill updateCurLogisticsBill = new MDLSD_LogisticsBill();
            updateCurLogisticsBill = paramHead.ToTBModelForSaveAndDelete <MDLSD_LogisticsBill>();
            //待更新的当前[物流单明细]列表
            List <MDLSD_LogisticsBillDetail> updateCurLogisticsBillDetailList = new List <MDLSD_LogisticsBillDetail>();
            CopyModelList(paramDetailList, updateCurLogisticsBillDetailList);

            //待新增的当前[物流单异动日志]
            MDLSD_LogisticsBillTrans newLogisticsBillTrans = new MDLSD_LogisticsBillTrans();

            //待更新的当前物流单对应的[销售订单]
            MDLSD_SalesOrder updateCurSalesOrder = new MDLSD_SalesOrder();
            //待更新的当前物流单对应的[销售订单明细]列表
            List <MDLSD_SalesOrderDetail> updateCurSalesOrderDetailList = new List <MDLSD_SalesOrderDetail>();
            //待更新的[调拨单]
            MDLPIS_TransferBill transferBill = new MDLPIS_TransferBill();

            #endregion

            #region 更新[物流单]
            //更新[物流单].[单据状态]为{配送中},[审核状态]为{已审核}
            updateCurLogisticsBill.LB_StatusCode         = LogisticsBillStatusEnum.Code.PSZ;
            updateCurLogisticsBill.LB_StatusName         = LogisticsBillStatusEnum.Name.PSZ;
            updateCurLogisticsBill.LB_ApprovalStatusCode = ApprovalStatusEnum.Code.YSH;
            updateCurLogisticsBill.LB_ApprovalStatusName = ApprovalStatusEnum.Name.YSH;
            updateCurLogisticsBill.LB_UpdatedBy          = LoginInfoDAX.UserName;
            updateCurLogisticsBill.LB_UpdatedTime        = BLLCom.GetCurStdDatetime();
            #endregion

            #region 新增[物流单异动日志]
            //新增状态为 当前物流单状态 的[物流单异动日志]
            newLogisticsBillTrans.LBT_ID          = Guid.NewGuid().ToString();
            newLogisticsBillTrans.LBT_Org_ID      = updateCurLogisticsBill.LB_Org_ID;
            newLogisticsBillTrans.LBT_Org_Name    = updateCurLogisticsBill.LB_Org_Name;
            newLogisticsBillTrans.LBT_LB_ID       = updateCurLogisticsBill.LB_ID ?? updateCurLogisticsBill.WHERE_LB_ID;
            newLogisticsBillTrans.LBT_LB_NO       = updateCurLogisticsBill.LB_No;
            newLogisticsBillTrans.LBT_Time        = BLLCom.GetCurStdDatetime();
            newLogisticsBillTrans.LBT_Status      = updateCurLogisticsBill.LB_StatusName;
            newLogisticsBillTrans.LBT_IsValid     = true;
            newLogisticsBillTrans.LBT_CreatedBy   = LoginInfoDAX.UserName;
            newLogisticsBillTrans.LBT_CreatedTime = BLLCom.GetCurStdDatetime();
            newLogisticsBillTrans.LBT_UpdatedBy   = LoginInfoDAX.UserName;
            newLogisticsBillTrans.LBT_UpdatedTime = BLLCom.GetCurStdDatetime();
            #endregion

            if (paramHead.LB_SourceTypeName == DeliveryBillSourceTypeEnum.Name.ZZDB)
            {
                #region 更新[调拨单]

                _bll.QueryForObject <MDLPIS_TransferBill, MDLPIS_TransferBill>(new MDLPIS_TransferBill()
                {
                    WHERE_TB_No = paramHead.LB_SourceNo
                }, transferBill);
                if (!string.IsNullOrEmpty(transferBill.TB_ID))
                {
                    transferBill.TB_StatusName      = TransfeStatusEnum.Name.YWC;
                    transferBill.TB_StatusCode      = TransfeStatusEnum.Code.YWC;
                    transferBill.WHERE_TB_ID        = transferBill.TB_ID;
                    transferBill.WHERE_TB_VersionNo = transferBill.TB_VersionNo;
                    transferBill.TB_VersionNo       = +1;
                }

                #endregion
            }
            else
            {
                #region 更新[销售订单]
                //查询物流单对应的销售订单
                _bll.QueryForObject <MDLSD_SalesOrder, MDLSD_SalesOrder>(new MDLSD_SalesOrder
                {
                    WHERE_SO_No      = updateCurLogisticsBill.LB_SourceNo,
                    WHERE_SO_IsValid = true
                }, updateCurSalesOrder);
                if (!string.IsNullOrEmpty(updateCurSalesOrder.SO_ID))
                {
                    //更新[销售订单].[单据状态]为{已发货}
                    updateCurSalesOrder.SO_StatusCode      = SalesOrderStatusEnum.Code.YFH;
                    updateCurSalesOrder.SO_StatusName      = SalesOrderStatusEnum.Name.YFH;
                    updateCurSalesOrder.SO_UpdatedBy       = LoginInfoDAX.UserName;
                    updateCurSalesOrder.SO_UpdatedTime     = BLLCom.GetCurStdDatetime();
                    updateCurSalesOrder.WHERE_SO_ID        = updateCurSalesOrder.SO_ID;
                    updateCurSalesOrder.WHERE_SO_VersionNo = updateCurSalesOrder.SO_VersionNo;
                }
                #endregion

                #region 获取对应的[销售订单明细]列表

                _bll.QueryForList <MDLSD_SalesOrderDetail, MDLSD_SalesOrderDetail>(new MDLSD_SalesOrderDetail
                {
                    WHERE_SOD_SO_ID   = updateCurSalesOrder.SO_ID,
                    WHERE_SOD_IsValid = true
                }, updateCurSalesOrderDetailList);
                #endregion
            }

            #region   图片

            foreach (var loopPicture in paramPictureNameAndPath)
            {
                if (string.IsNullOrEmpty(loopPicture.Key) ||
                    string.IsNullOrEmpty(loopPicture.Value))
                {
                    continue;
                }

                #region 将图片保存到本地以及上传文件服务器

                string fileNetUrl        = string.Empty;
                bool   savePictureResult = BLLCom.SaveFileByFileName(loopPicture.Value, loopPicture.Key, ref fileNetUrl);
                if (!savePictureResult)
                {
                    ResultMsg = MsgHelp.GetMsg(MsgCode.E_0010, new object[] { SystemActionEnum.Name.SAVE + MsgParam.IMAGE });
                    LogHelper.WriteBussLogEndNG(BussID, LoginInfoDAX.UserName, funcName, ResultMsg, "", null);
                    return(false);
                }
                #endregion

                //截取上传图片返回值中的文件名称
                int fileNameStartIndex = fileNetUrl.IndexOf("FileName=", StringComparison.Ordinal) + 1;
                int fileNameEndIndex   = fileNameStartIndex + "FileName=".Length;
                int length             = fileNetUrl.Length;
                //文件名称
                string tempFileName = fileNetUrl.Substring(fileNameEndIndex - 1, length - (fileNameEndIndex - 1));

                //给各个图片赋值
                if (loopPicture.Key == updateCurLogisticsBill.LB_AcceptPicPath1)
                {
                    updateCurLogisticsBill.LB_AcceptPicPath1 = tempFileName;
                }
                else if (loopPicture.Key == updateCurLogisticsBill.LB_AcceptPicPath2)
                {
                    updateCurLogisticsBill.LB_AcceptPicPath2 = tempFileName;
                }
                else if (loopPicture.Key == updateCurLogisticsBill.LB_ReceivedPicPath1)
                {
                    updateCurLogisticsBill.LB_ReceivedPicPath1 = tempFileName;
                }
                else if (loopPicture.Key == updateCurLogisticsBill.LB_ReceivedPicPath2)
                {
                    updateCurLogisticsBill.LB_ReceivedPicPath2 = tempFileName;
                }
            }
            #endregion

            #endregion

            #region 带事务的保存

            try
            {
                DBManager.BeginTransaction(DBCONFIG.Coeus);

                #region 更新[物流单]
                bool updateLogisticsBillResult = _bll.Save(updateCurLogisticsBill);
                if (!updateLogisticsBillResult)
                {
                    DBManager.RollBackTransaction(DBCONFIG.Coeus);

                    foreach (var loopPicture in paramPictureNameAndPath)
                    {
                        if (string.IsNullOrEmpty(loopPicture.Key) ||
                            string.IsNullOrEmpty(loopPicture.Value))
                        {
                            continue;
                        }
                        //保存失败,删除本地以及文件服务器上的图片
                        var outMsg = string.Empty;
                        BLLCom.DeleteFileByFileName(loopPicture.Key, ref outMsg);
                    }

                    ResultMsg = MsgHelp.GetMsg(MsgCode.E_0010, new object[] { MsgParam.UPDATE + SystemTableEnums.Name.SD_LogisticsBill });
                    return(false);
                }

                #endregion

                #region 更新[物流单明细]

                foreach (var loopLogisticsBillDetail in updateCurLogisticsBillDetailList)
                {
                    //更新[物流单明细].[物流状态]为{配送中}
                    loopLogisticsBillDetail.LBD_StatusCode  = LogisticsBillDetailStatusEnum.Code.PSZ;
                    loopLogisticsBillDetail.LBD_StatusName  = LogisticsBillDetailStatusEnum.Name.PSZ;
                    loopLogisticsBillDetail.LBD_UpdatedBy   = LoginInfoDAX.UserName;
                    loopLogisticsBillDetail.LBD_UpdatedTime = BLLCom.GetCurStdDatetime();
                    if (paramHead.LB_SourceTypeName == DeliveryBillSourceTypeEnum.Name.ZZDB)
                    {
                        loopLogisticsBillDetail.LBD_SignQty = loopLogisticsBillDetail.LBD_DeliveryQty;
                    }
                    loopLogisticsBillDetail.WHERE_LBD_ID        = loopLogisticsBillDetail.LBD_ID;
                    loopLogisticsBillDetail.WHERE_LBD_VersionNo = loopLogisticsBillDetail.LBD_VersionNo;

                    bool updateLogisticsBillDetailResult = _bll.Save(loopLogisticsBillDetail);
                    if (!updateLogisticsBillDetailResult)
                    {
                        DBManager.RollBackTransaction(DBCONFIG.Coeus);

                        foreach (var loopPicture in paramPictureNameAndPath)
                        {
                            if (string.IsNullOrEmpty(loopPicture.Key) ||
                                string.IsNullOrEmpty(loopPicture.Value))
                            {
                                continue;
                            }
                            //保存失败,删除本地以及文件服务器上的图片
                            var outMsg = string.Empty;
                            BLLCom.DeleteFileByFileName(loopPicture.Key, ref outMsg);
                        }

                        ResultMsg = MsgHelp.GetMsg(MsgCode.E_0010, new object[] { MsgParam.UPDATE + SystemTableEnums.Name.SD_LogisticsBillDetail });
                        return(false);
                    }
                }
                #endregion

                #region 新增[物流单日志]
                bool addLogisticsBillTransResult = _bll.Insert(newLogisticsBillTrans);
                if (!addLogisticsBillTransResult)
                {
                    DBManager.RollBackTransaction(DBCONFIG.Coeus);

                    foreach (var loopPicture in paramPictureNameAndPath)
                    {
                        if (string.IsNullOrEmpty(loopPicture.Key) ||
                            string.IsNullOrEmpty(loopPicture.Value))
                        {
                            continue;
                        }
                        //保存失败,删除本地以及文件服务器上的图片
                        var outMsg = string.Empty;
                        BLLCom.DeleteFileByFileName(loopPicture.Key, ref outMsg);
                    }

                    ResultMsg = MsgHelp.GetMsg(MsgCode.E_0010, new object[] { SystemActionEnum.Name.NEW + SystemTableEnums.Name.SD_LogisticsBillTrans });
                    return(false);
                }
                #endregion

                if (paramHead.LB_SourceTypeName == DeliveryBillSourceTypeEnum.Name.ZZDB)
                {
                    #region 更新[调拨单]数据
                    if (!string.IsNullOrEmpty(transferBill.TB_ID))
                    {
                        bool updateTransferBillResult = _bll.Update(transferBill);
                        if (!updateTransferBillResult)
                        {
                            DBManager.RollBackTransaction(DBCONFIG.Coeus);

                            foreach (var loopPicture in paramPictureNameAndPath)
                            {
                                if (string.IsNullOrEmpty(loopPicture.Key) ||
                                    string.IsNullOrEmpty(loopPicture.Value))
                                {
                                    continue;
                                }
                                //保存失败,删除本地以及文件服务器上的图片
                                var outMsg = string.Empty;
                                BLLCom.DeleteFileByFileName(loopPicture.Key, ref outMsg);
                            }

                            ResultMsg = MsgHelp.GetMsg(MsgCode.E_0010, new object[] { MsgParam.UPDATE + SystemTableEnums.Name.PIS_TransferBill });
                            return(false);
                        }
                    }
                    #endregion
                }
                else
                {
                    #region 更新[销售订单]数据
                    if (!string.IsNullOrEmpty(updateCurSalesOrder.SO_ID))
                    {
                        bool updateSalesOrderResult = _bll.Update(updateCurSalesOrder);
                        if (!updateSalesOrderResult)
                        {
                            DBManager.RollBackTransaction(DBCONFIG.Coeus);

                            foreach (var loopPicture in paramPictureNameAndPath)
                            {
                                if (string.IsNullOrEmpty(loopPicture.Key) ||
                                    string.IsNullOrEmpty(loopPicture.Value))
                                {
                                    continue;
                                }
                                //保存失败,删除本地以及文件服务器上的图片
                                var outMsg = string.Empty;
                                BLLCom.DeleteFileByFileName(loopPicture.Key, ref outMsg);
                            }

                            ResultMsg = MsgHelp.GetMsg(MsgCode.E_0010, new object[] { MsgParam.UPDATE + SystemTableEnums.Name.SD_SalesOrder });
                            return(false);
                        }
                    }
                    #endregion

                    #region 更新[销售订单明细]数据

                    if (updateCurSalesOrderDetailList.Count > 0)
                    {
                        foreach (var loopSalesOrderDetail in updateCurSalesOrderDetailList)
                        {
                            //更新[销售订单明细].[单据状态]与单头一致
                            loopSalesOrderDetail.SOD_StatusName         = updateCurSalesOrder.SO_StatusName;
                            loopSalesOrderDetail.SOD_StatusCode         = updateCurSalesOrder.SO_StatusCode;
                            loopSalesOrderDetail.SOD_ApprovalStatusName = updateCurSalesOrder.SO_ApprovalStatusName;
                            loopSalesOrderDetail.SOD_ApprovalStatusCode = updateCurSalesOrder.SO_ApprovalStatusCode;
                            loopSalesOrderDetail.SOD_UpdatedBy          = LoginInfoDAX.UserName;
                            loopSalesOrderDetail.SOD_UpdatedTime        = BLLCom.GetCurStdDatetime();
                            loopSalesOrderDetail.WHERE_SOD_ID           = loopSalesOrderDetail.SOD_ID;
                            loopSalesOrderDetail.WHERE_SOD_VersionNo    = loopSalesOrderDetail.SOD_VersionNo;

                            bool updateLogisticsBillDetailResult = _bll.Update(loopSalesOrderDetail);
                            if (!updateLogisticsBillDetailResult)
                            {
                                DBManager.RollBackTransaction(DBCONFIG.Coeus);

                                foreach (var loopPicture in paramPictureNameAndPath)
                                {
                                    if (string.IsNullOrEmpty(loopPicture.Key) ||
                                        string.IsNullOrEmpty(loopPicture.Value))
                                    {
                                        continue;
                                    }
                                    //保存失败,删除本地以及文件服务器上的图片
                                    var outMsg = string.Empty;
                                    BLLCom.DeleteFileByFileName(loopPicture.Key, ref outMsg);
                                }

                                ResultMsg = MsgHelp.GetMsg(MsgCode.E_0010, new object[] { MsgParam.UPDATE + SystemTableEnums.Name.SD_SalesOrderDetail });
                                return(false);
                            }
                        }
                    }
                    #endregion
                }



                DBManager.CommitTransaction(DBCONFIG.Coeus);
            }
            catch (Exception ex)
            {
                DBManager.RollBackTransaction(DBCONFIG.Coeus);

                foreach (var loopPicture in paramPictureNameAndPath)
                {
                    if (string.IsNullOrEmpty(loopPicture.Key) ||
                        string.IsNullOrEmpty(loopPicture.Value))
                    {
                        continue;
                    }
                    //保存失败,删除本地以及文件服务器上的图片
                    var outMsg = string.Empty;
                    BLLCom.DeleteFileByFileName(loopPicture.Key, ref outMsg);
                }

                ResultMsg = MsgHelp.GetMsg(MsgCode.E_0018, new object[] { SystemActionEnum.Name.APPROVE, ex.Message });
                LogHelper.WriteBussLogEndNG(BussID, LoginInfoDAX.UserName, MethodBase.GetCurrentMethod().ToString(),
                                            ex.Message, "", null);
                return(false);
            }

            #endregion

            //将最新数据回写给DetailDS
            CopyModel(updateCurLogisticsBill, paramHead);

            //更新明细版本号
            if (paramDetailList != null)
            {
                foreach (var loopUpdateDetail in paramDetailList)
                {
                    if (loopUpdateDetail.LBD_VersionNo == null)
                    {
                        //新增时版本号为1
                        loopUpdateDetail.LBD_VersionNo = 1;
                        if (paramHead.LB_SourceTypeName == DeliveryBillSourceTypeEnum.Name.ZZDB)
                        {
                            loopUpdateDetail.LBD_SignQty = loopUpdateDetail.LBD_DeliveryQty;
                        }
                    }
                    else
                    {
                        //更新时版本号加1
                        loopUpdateDetail.LBD_VersionNo = loopUpdateDetail.LBD_VersionNo + 1;
                        if (paramHead.LB_SourceTypeName == DeliveryBillSourceTypeEnum.Name.ZZDB)
                        {
                            loopUpdateDetail.LBD_SignQty = loopUpdateDetail.LBD_DeliveryQty;
                        }
                    }
                }
            }

            foreach (var loopPicture in paramPictureNameAndPath)
            {
                if (string.IsNullOrEmpty(loopPicture.Key) ||
                    string.IsNullOrEmpty(loopPicture.Value))
                {
                    continue;
                }
                //保存成功,删除临时保存的图片
                if (File.Exists(loopPicture.Value))
                {
                    File.Delete(loopPicture.Value);
                }
            }
            return(true);
        }
예제 #4
0
        /// <summary>
        /// 保存
        /// </summary>
        /// <param name="paramHead">UIModel</param>
        /// <param name="paramDetailList">明细List</param>
        /// <param name="paramPictureNameAndPath"></param>
        /// <returns></returns>
        public bool SaveDetailDS(LogisticsBillManagerUIModel paramHead, SkyCarBindingList <LogisticsBillDetailManagerUIModel, MDLSD_LogisticsBillDetail> paramDetailList,
                                 Dictionary <string, string> paramPictureNameAndPath)
        {
            var funcName = "SaveDetailDS";

            LogHelper.WriteBussLogStart(BussID, LoginInfoDAX.UserName, funcName, "", "", null);

            //服务端检查
            if (!ServerCheck(paramHead, paramDetailList))
            {
                LogHelper.WriteBussLogEndNG(BussID, LoginInfoDAX.UserName, funcName, ResultMsg, "", null);
                return(false);
            }

            #region 准备数据

            #region 单头

            var argsHead = paramHead.ToTBModelForSaveAndDelete <MDLSD_LogisticsBill>();
            //判断主键是否被赋值
            if (string.IsNullOrEmpty(paramHead.LB_ID))
            {
                argsHead.LB_ID = Guid.NewGuid().ToString();
                //物流单号
                argsHead.LB_No          = BLLCom.GetCoeusDocumentNo(DocumentTypeEnums.Code.LB);
                argsHead.LB_CreatedBy   = LoginInfoDAX.UserName;
                argsHead.LB_CreatedTime = BLLCom.GetCurStdDatetime();
            }
            argsHead.LB_UpdatedBy   = LoginInfoDAX.UserName;
            argsHead.LB_UpdatedTime = BLLCom.GetCurStdDatetime();

            #endregion

            #region 明细
            //添加的明细
            if (paramDetailList != null && paramDetailList.InsertList != null && paramDetailList.InsertList.Count > 0)
            {
                foreach (var loopLogisticsBillDetail in paramDetailList.InsertList)
                {
                    loopLogisticsBillDetail.LBD_LB_ID = argsHead.LB_ID ?? argsHead.WHERE_LB_ID;
                    loopLogisticsBillDetail.LBD_LB_No = argsHead.LB_No;
                }
            }
            #endregion

            #region   图片

            foreach (var loopPicture in paramPictureNameAndPath)
            {
                if (string.IsNullOrEmpty(loopPicture.Key) ||
                    string.IsNullOrEmpty(loopPicture.Value))
                {
                    continue;
                }

                #region 将图片保存到本地以及上传文件服务器

                string fileNetUrl        = string.Empty;
                bool   savePictureResult = BLLCom.SaveFileByFileName(loopPicture.Value, loopPicture.Key, ref fileNetUrl);
                if (!savePictureResult)
                {
                    ResultMsg = MsgHelp.GetMsg(MsgCode.E_0010, new object[] { SystemActionEnum.Name.SAVE + MsgParam.IMAGE });
                    LogHelper.WriteBussLogEndNG(BussID, LoginInfoDAX.UserName, funcName, ResultMsg, "", null);
                    return(false);
                }
                #endregion

                //截取上传图片返回值中的文件名称
                int fileNameStartIndex = fileNetUrl.IndexOf("FileName=", StringComparison.Ordinal) + 1;
                int fileNameEndIndex   = fileNameStartIndex + "FileName=".Length;
                int length             = fileNetUrl.Length;
                //文件名称
                string tempFileName = fileNetUrl.Substring(fileNameEndIndex - 1, length - (fileNameEndIndex - 1));

                //给各个图片赋值
                if (loopPicture.Key == argsHead.LB_AcceptPicPath1)
                {
                    argsHead.LB_AcceptPicPath1 = tempFileName;
                }
                else if (loopPicture.Key == argsHead.LB_AcceptPicPath2)
                {
                    argsHead.LB_AcceptPicPath2 = tempFileName;
                }
                else if (loopPicture.Key == argsHead.LB_ReceivedPicPath1)
                {
                    argsHead.LB_ReceivedPicPath1 = tempFileName;
                }
                else if (loopPicture.Key == argsHead.LB_ReceivedPicPath2)
                {
                    argsHead.LB_ReceivedPicPath2 = tempFileName;
                }
            }
            #endregion

            #region 物流订单异动日志

            //新增状态为 当前物流单状态 的[物流单异动日志]
            MDLSD_LogisticsBillTrans newLogisticsBillTrans = new MDLSD_LogisticsBillTrans
            {
                LBT_ID          = Guid.NewGuid().ToString(),
                LBT_Org_ID      = argsHead.LB_Org_ID,
                LBT_Org_Name    = argsHead.LB_Org_Name,
                LBT_LB_ID       = argsHead.LB_ID ?? argsHead.WHERE_LB_ID,
                LBT_LB_NO       = argsHead.LB_No,
                LBT_Time        = BLLCom.GetCurStdDatetime(),
                LBT_Status      = argsHead.LB_StatusName,
                LBT_IsValid     = true,
                LBT_CreatedBy   = LoginInfoDAX.UserName,
                LBT_CreatedTime = BLLCom.GetCurStdDatetime(),
                LBT_UpdatedBy   = LoginInfoDAX.UserName,
                LBT_UpdatedTime = BLLCom.GetCurStdDatetime()
            };

            #endregion

            #endregion

            #region 事务处理
            try
            {
                DBManager.BeginTransaction(DBCONFIG.Coeus);

                #region 保存[物流单]

                //执行保存
                if (!_bll.Save(argsHead, argsHead.LB_ID))
                {
                    DBManager.RollBackTransaction(DBCONFIG.Coeus);

                    foreach (var loopPicture in paramPictureNameAndPath)
                    {
                        if (string.IsNullOrEmpty(loopPicture.Key) ||
                            string.IsNullOrEmpty(loopPicture.Value))
                        {
                            continue;
                        }
                        //保存失败,删除本地以及文件服务器上的图片
                        var outMsg = string.Empty;
                        BLLCom.DeleteFileByFileName(loopPicture.Key, ref outMsg);
                    }

                    ResultMsg = MsgHelp.GetMsg(MsgCode.E_0010, new object[] { SystemActionEnum.Name.SAVE + SystemTableEnums.Name.SD_LogisticsBill });
                    LogHelper.WriteBussLogEndNG(BussID, LoginInfoDAX.UserName, funcName, ResultMsg, "", null);
                    return(false);
                }

                #endregion

                #region 保存[物流单明细]

                //执行保存
                if (!_bll.UnitySave(paramDetailList))
                {
                    DBManager.RollBackTransaction(DBCONFIG.Coeus);

                    foreach (var loopPicture in paramPictureNameAndPath)
                    {
                        if (string.IsNullOrEmpty(loopPicture.Key) ||
                            string.IsNullOrEmpty(loopPicture.Value))
                        {
                            continue;
                        }
                        //保存失败,删除本地以及文件服务器上的图片
                        var outMsg = string.Empty;
                        BLLCom.DeleteFileByFileName(loopPicture.Key, ref outMsg);
                    }

                    ResultMsg = MsgHelp.GetMsg(MsgCode.E_0010, new object[] { SystemActionEnum.Name.SAVE + SystemTableEnums.Name.SD_LogisticsBillDetail });
                    LogHelper.WriteBussLogEndNG(BussID, LoginInfoDAX.UserName, funcName, ResultMsg, "", null);
                    return(false);
                }

                #endregion

                #region 新增[物流单日志]
                bool addLogisticsBillTransResult = _bll.Insert(newLogisticsBillTrans);
                if (!addLogisticsBillTransResult)
                {
                    DBManager.RollBackTransaction(DBCONFIG.Coeus);

                    foreach (var loopPicture in paramPictureNameAndPath)
                    {
                        if (string.IsNullOrEmpty(loopPicture.Key) ||
                            string.IsNullOrEmpty(loopPicture.Value))
                        {
                            continue;
                        }
                        //保存失败,删除本地以及文件服务器上的图片
                        var outMsg = string.Empty;
                        BLLCom.DeleteFileByFileName(loopPicture.Key, ref outMsg);
                    }

                    ResultMsg = MsgHelp.GetMsg(MsgCode.E_0010, new object[] { SystemActionEnum.Name.NEW + SystemTableEnums.Name.SD_LogisticsBillTrans });
                    return(false);
                }
                #endregion

                DBManager.CommitTransaction(DBCONFIG.Coeus);
            }
            catch (Exception ex)
            {
                DBManager.RollBackTransaction(DBCONFIG.Coeus);

                foreach (var loopPicture in paramPictureNameAndPath)
                {
                    if (string.IsNullOrEmpty(loopPicture.Key) ||
                        string.IsNullOrEmpty(loopPicture.Value))
                    {
                        continue;
                    }
                    //保存失败,删除本地以及文件服务器上的图片
                    var outMsg = string.Empty;
                    BLLCom.DeleteFileByFileName(loopPicture.Key, ref outMsg);
                }

                //保存[物流单管理]信息发生异常
                ResultMsg = MsgHelp.GetMsg(MsgCode.E_0018, new object[] { SystemActionEnum.Name.SAVE, ex.Message });
                LogHelper.WriteBussLogEndNG(BussID, LoginInfoDAX.UserName, MethodBase.GetCurrentMethod().ToString(),
                                            ex.Message, "", null);
                return(false);
            }
            #endregion

            //将最新数据回写给DetailDS argsLogisticsBill
            CopyModel(argsHead, paramHead);

            //更新明细版本号
            if (paramDetailList != null)
            {
                if (paramDetailList.InsertList != null)
                {
                    foreach (var loopInsertDetail in paramDetailList.InsertList)
                    {
                        //新增时版本号为1
                        loopInsertDetail.LBD_VersionNo = 1;
                    }
                }

                foreach (var loopUpdateDetail in paramDetailList.UpdateList)
                {
                    //更新时版本号加1
                    loopUpdateDetail.LBD_VersionNo = loopUpdateDetail.LBD_VersionNo + 1;
                }
            }

            foreach (var loopPicture in paramPictureNameAndPath)
            {
                if (string.IsNullOrEmpty(loopPicture.Key) ||
                    string.IsNullOrEmpty(loopPicture.Value))
                {
                    continue;
                }
                //保存成功,删除临时保存的图片
                if (File.Exists(loopPicture.Value))
                {
                    File.Delete(loopPicture.Value);
                }
            }
            return(true);
        }
예제 #5
0
        /// <summary>
        /// 保存
        /// </summary>
        /// <param name="paramModel">UIModel</param>
        /// <param name="paramAutoPartsPriceDetailList">配件价格明细列表</param>
        /// <param name="paramAutoPartsPictureList">配件图片列表</param>
        /// <returns></returns>
        public bool SaveDetailDS(AutoPartsArchiveManagerUIModel paramModel, SkyCarBindingList <AutoPartsPriceTypeUIModel, MDLBS_AutoPartsPriceType> paramAutoPartsPriceDetailList, List <AutoPartsPictureUIModel> paramAutoPartsPictureList)
        {
            var funcName = "SaveDetailDS";

            LogHelper.WriteBussLogStart(BussID, LoginInfoDAX.UserName, funcName, "", "", null);
            //服务端检查
            if (!ServerCheck(paramModel))
            {
                LogHelper.WriteBussLogEndNG(BussID, LoginInfoDAX.UserName, funcName, ResultMsg, "", null);
                return(false);
            }

            #region 准备数据

            #region 配件档案

            //将UIModel转为TBModel
            var argsAutoPartsArchive = CopyModel <MDLBS_AutoPartsArchive>(paramModel);

            if (string.IsNullOrEmpty(argsAutoPartsArchive.APA_ID) && string.IsNullOrEmpty(argsAutoPartsArchive.APA_Barcode))
            {
                #region 新增
                string argsPostData = string.Format(ApiParameter.BF0017,
                                                    ConfigurationManager.AppSettings[AppSettingKey.MCT_CODE],
                                                    SysConst.Merchant,
                                                    argsAutoPartsArchive.APA_Name,
                                                    argsAutoPartsArchive.APA_Brand,
                                                    argsAutoPartsArchive.APA_Specification,
                                                    argsAutoPartsArchive.APA_UOM,
                                                    argsAutoPartsArchive.APA_Level,
                                                    argsAutoPartsArchive.APA_VehicleBrand,
                                                    argsAutoPartsArchive.APA_VehicleInspire,
                                                    argsAutoPartsArchive.APA_VehicleCapacity,
                                                    argsAutoPartsArchive.APA_VehicleYearModel,
                                                    argsAutoPartsArchive.APA_VehicleGearboxTypeName,
                                                    argsAutoPartsArchive.APA_OEMNo,
                                                    argsAutoPartsArchive.APA_ThirdNo,
                                                    argsAutoPartsArchive.APA_Barcode,
                                                    argsAutoPartsArchive.APA_IsValid);
                string strApiData = APIDataHelper.GetAPIData(ApiUrl.BF0017Url, argsPostData);
                var    apiResult  = (JObject)JsonConvert.DeserializeObject(strApiData);
                if (apiResult == null)
                {
                    ResultMsg = MsgHelp.GetMsg(MsgCode.E_0019, SystemActionEnum.Name.SAVE);
                    return(false);
                }
                if (apiResult["autoPartsArchive"] == null)
                {
                    ResultMsg = MsgHelp.GetMsg(MsgCode.E_0020, new object[] { SystemTableEnums.Name.BS_AutoPartsArchive, SystemActionEnum.Name.SAVE });
                    return(false);
                }
                var jsonResult = (JObject)JsonConvert.DeserializeObject(apiResult["autoPartsArchive"].ToString());

                if (apiResult[SysConst.EN_RESULTCODE] != null && apiResult[SysConst.EN_RESULTCODE].ToString().Equals(SysConst.EN_I0001))
                {
                    var barCode = jsonResult[SystemTableColumnEnums.BS_AutoPartsArchive.Code.APA_Barcode] == null ? null : jsonResult[SystemTableColumnEnums.BS_AutoPartsArchive.Code.APA_Barcode].ToString();
                    if (string.IsNullOrEmpty(barCode))
                    {
                        ResultMsg = MsgHelp.GetMsg(MsgCode.E_0020, new object[] { MsgParam.BARCODE, SystemActionEnum.Name.SAVE });
                        return(false);
                    }
                    argsAutoPartsArchive.APA_Name = jsonResult[SystemTableColumnEnums.BS_AutoPartsArchive.Code.APA_Name] == null
                        ? null
                        : jsonResult[SystemTableColumnEnums.BS_AutoPartsArchive.Code.APA_Name].ToString();
                    argsAutoPartsArchive.APA_OEMNo = jsonResult[SystemTableColumnEnums.BS_AutoPartsArchive.Code.APA_OEMNo] == null
                        ? null
                        : jsonResult[SystemTableColumnEnums.BS_AutoPartsArchive.Code.APA_OEMNo].ToString();
                    argsAutoPartsArchive.APA_ThirdNo = jsonResult[SystemTableColumnEnums.BS_AutoPartsArchive.Code.APA_ThirdNo] == null
                        ? null
                        : jsonResult[SystemTableColumnEnums.BS_AutoPartsArchive.Code.APA_ThirdNo].ToString();
                    argsAutoPartsArchive.APA_Brand = jsonResult[SystemTableColumnEnums.BS_AutoPartsArchive.Code.APA_Brand] == null
                        ? null
                        : jsonResult[SystemTableColumnEnums.BS_AutoPartsArchive.Code.APA_Brand].ToString();
                    argsAutoPartsArchive.APA_Specification = jsonResult[SystemTableColumnEnums.BS_AutoPartsArchive.Code.APA_Specification] == null
                        ? null
                        : jsonResult[SystemTableColumnEnums.BS_AutoPartsArchive.Code.APA_Specification].ToString();
                    argsAutoPartsArchive.APA_UOM = jsonResult[SystemTableColumnEnums.BS_AutoPartsArchive.Code.APA_UOM] == null
                        ? null
                        : jsonResult[SystemTableColumnEnums.BS_AutoPartsArchive.Code.APA_UOM].ToString();
                    argsAutoPartsArchive.APA_Level = jsonResult[SystemTableColumnEnums.BS_AutoPartsArchive.Code.APA_Level] == null
                        ? null
                        : jsonResult[SystemTableColumnEnums.BS_AutoPartsArchive.Code.APA_Level].ToString();
                    argsAutoPartsArchive.APA_VehicleBrand = jsonResult[SystemTableColumnEnums.BS_AutoPartsArchive.Code.APA_VehicleBrand] == null
                        ? null
                        : jsonResult[SystemTableColumnEnums.BS_AutoPartsArchive.Code.APA_VehicleBrand].ToString();
                    argsAutoPartsArchive.APA_VehicleInspire = jsonResult[SystemTableColumnEnums.BS_AutoPartsArchive.Code.APA_VehicleInspire] == null
                        ? null
                        : jsonResult[SystemTableColumnEnums.BS_AutoPartsArchive.Code.APA_VehicleInspire].ToString();
                    argsAutoPartsArchive.APA_VehicleCapacity = jsonResult[SystemTableColumnEnums.BS_AutoPartsArchive.Code.APA_VehicleCapacity] == null
                        ? null
                        : jsonResult[SystemTableColumnEnums.BS_AutoPartsArchive.Code.APA_VehicleCapacity].ToString();
                    argsAutoPartsArchive.APA_VehicleYearModel = jsonResult[SystemTableColumnEnums.BS_AutoPartsArchive.Code.APA_VehicleYearModel] == null
                        ? null
                        : jsonResult[SystemTableColumnEnums.BS_AutoPartsArchive.Code.APA_VehicleYearModel].ToString();
                    argsAutoPartsArchive.APA_IsValid   = jsonResult[SystemTableColumnEnums.BS_AutoPartsArchive.Code.APA_IsValid] == null || Convert.ToBoolean(jsonResult[SystemTableColumnEnums.BS_AutoPartsArchive.Code.APA_IsValid]);
                    argsAutoPartsArchive.APA_ID        = null;
                    argsAutoPartsArchive.APA_Barcode   = barCode;
                    argsAutoPartsArchive.APA_CreatedBy = LoginInfoDAX.UserName;

                    //变速类型
                    if (jsonResult["APA_VehicleGearboxType"] != null)
                    {
                        //转化变速类型
                        string vehicleGearboxTypeName = jsonResult["APA_VehicleGearboxType"].ToString();

                        string[] vehicleGearboxTypeNameList = vehicleGearboxTypeName.Split(';');

                        string resultVehicleGearboxTypeCode = string.Empty;
                        string resultVehicleGearboxTypeName = string.Empty;
                        foreach (var loopVehicleGearboxTypeName in vehicleGearboxTypeNameList)
                        {
                            switch (loopVehicleGearboxTypeName.Trim())
                            {
                            case GearboxTypeEnum.Name.AT:
                                resultVehicleGearboxTypeCode += GearboxTypeEnum.Code.AT + SysConst.Semicolon_DBC;
                                resultVehicleGearboxTypeName += GearboxTypeEnum.Name.AT + SysConst.Semicolon_DBC;
                                break;

                            case GearboxTypeEnum.Name.CVT:
                                resultVehicleGearboxTypeCode += GearboxTypeEnum.Code.CVT + SysConst.Semicolon_DBC;
                                resultVehicleGearboxTypeName += GearboxTypeEnum.Name.CVT + SysConst.Semicolon_DBC;
                                break;

                            case GearboxTypeEnum.Name.MT:
                                resultVehicleGearboxTypeCode += GearboxTypeEnum.Code.MT + SysConst.Semicolon_DBC;
                                resultVehicleGearboxTypeName += GearboxTypeEnum.Name.MT + SysConst.Semicolon_DBC;
                                break;

                            case GearboxTypeEnum.Name.MTAT:
                                resultVehicleGearboxTypeCode += GearboxTypeEnum.Code.MTAT + SysConst.Semicolon_DBC;
                                resultVehicleGearboxTypeName += GearboxTypeEnum.Name.MTAT + SysConst.Semicolon_DBC;
                                break;

                            case GearboxTypeEnum.Name.AMT:
                                resultVehicleGearboxTypeCode += GearboxTypeEnum.Code.AMT + SysConst.Semicolon_DBC;
                                resultVehicleGearboxTypeName += GearboxTypeEnum.Name.AMT + SysConst.Semicolon_DBC;
                                break;

                            case GearboxTypeEnum.Name.DSGDCT:
                                resultVehicleGearboxTypeCode += GearboxTypeEnum.Code.DSGDCT + SysConst.Semicolon_DBC;
                                resultVehicleGearboxTypeName += GearboxTypeEnum.Name.DSGDCT + SysConst.Semicolon_DBC;
                                break;

                            case GearboxTypeEnum.Name.EVAT:
                                resultVehicleGearboxTypeCode += GearboxTypeEnum.Code.EVAT + SysConst.Semicolon_DBC;
                                resultVehicleGearboxTypeName += GearboxTypeEnum.Name.EVAT + SysConst.Semicolon_DBC;
                                break;
                            }
                        }
                        //去掉最后一个半角分号
                        if (resultVehicleGearboxTypeName.Trim().Length > 0)
                        {
                            argsAutoPartsArchive.APA_VehicleGearboxTypeName = resultVehicleGearboxTypeName.Trim().Substring(0, resultVehicleGearboxTypeName.Trim().Length - 1);
                        }
                        if (resultVehicleGearboxTypeCode.Trim().Length > 0)
                        {
                            argsAutoPartsArchive.APA_VehicleGearboxTypeCode = resultVehicleGearboxTypeCode.Trim().Substring(0, resultVehicleGearboxTypeCode.Trim().Length - 1);
                        }
                    }
                }
                else
                {
                    ResultMsg = MsgHelp.GetMsg(MsgCode.E_0020, new object[] { SystemTableEnums.Name.BS_AutoPartsArchive, SystemActionEnum.Name.SAVE });
                    LogHelper.WriteBussLogEndNG(BussID, LoginInfoDAX.UserName, funcName, ResultMsg, "", null);
                    return(false);
                }

                //生成新ID
                argsAutoPartsArchive.APA_ID          = Guid.NewGuid().ToString();
                argsAutoPartsArchive.APA_UpdatedBy   = LoginInfoDAX.UserName;
                argsAutoPartsArchive.APA_CreatedBy   = LoginInfoDAX.UserName;
                argsAutoPartsArchive.APA_CreatedTime = BLLCom.GetCurStdDatetime();
                argsAutoPartsArchive.APA_UpdatedBy   = LoginInfoDAX.UserName;
                argsAutoPartsArchive.APA_UpdatedTime = BLLCom.GetCurStdDatetime();
                argsAutoPartsArchive.APA_Org_ID      = paramModel.APA_Org_ID;
                #endregion
            }
            else
            {
                #region 更新
                //主键被赋值,则需要更新,更新需要设定更新条件
                argsAutoPartsArchive.WHERE_APA_ID        = argsAutoPartsArchive.APA_ID;
                argsAutoPartsArchive.WHERE_APA_VersionNo = argsAutoPartsArchive.APA_VersionNo;
                argsAutoPartsArchive.APA_VersionNo++;
                argsAutoPartsArchive.APA_UpdatedBy   = LoginInfoDAX.UserName;
                argsAutoPartsArchive.APA_UpdatedTime = BLLCom.GetCurStdDatetime();
                #endregion
            }
            #endregion

            #region 配件价格类别

            //同步到平台的数据
            List <AutoPartsPriceTypeUIModel> syncAutoPartsPriceTypeList = new List <AutoPartsPriceTypeUIModel>();

            foreach (var loopNewAutoPartsPrice in paramAutoPartsPriceDetailList.InsertList)
            {
                loopNewAutoPartsPrice.APPT_Barcode     = argsAutoPartsArchive.APA_Barcode;
                loopNewAutoPartsPrice.APPT_OperateType = "Save";

                syncAutoPartsPriceTypeList.Add(loopNewAutoPartsPrice);
            }

            //待更新的配件价格类别的ID组合字符串(用于本地保存失败时,还原平台上的数据)
            string updateIdStr = string.Empty;
            foreach (var loopUpdateAutoPartsPrice in paramAutoPartsPriceDetailList.UpdateList)
            {
                updateIdStr += loopUpdateAutoPartsPrice.APPT_ID + SysConst.Semicolon_DBC;
                loopUpdateAutoPartsPrice.APPT_OperateType = "Save";

                syncAutoPartsPriceTypeList.Add(loopUpdateAutoPartsPrice);
            }
            foreach (var loopDeleteAutoPartsPrice in paramAutoPartsPriceDetailList.DeleteList)
            {
                loopDeleteAutoPartsPrice.APPT_OperateType = "Delete";

                syncAutoPartsPriceTypeList.Add(loopDeleteAutoPartsPrice);
            }
            #endregion

            #region 配件图片

            //待保存的配件图片列表
            List <MDLPIS_InventoryPicture> savePictureList = new List <MDLPIS_InventoryPicture>();

            foreach (var loopPicture in paramAutoPartsPictureList)
            {
                if (string.IsNullOrEmpty(loopPicture.INVP_PictureName) ||
                    string.IsNullOrEmpty(loopPicture.SourceFilePath))
                {
                    continue;
                }
                #region 将图片保存到本地以及上传文件服务器

                string fileNetUrl        = string.Empty;
                bool   savePictureResult = BLLCom.SaveFileByFileName(loopPicture.SourceFilePath, loopPicture.INVP_PictureName, ref fileNetUrl);
                if (!savePictureResult)
                {
                    ResultMsg = MsgHelp.GetMsg(MsgCode.E_0010, new object[] { SystemActionEnum.Name.SAVE + MsgParam.AUTOPARTS_PICTURE });
                    LogHelper.WriteBussLogEndNG(BussID, LoginInfoDAX.UserName, funcName, ResultMsg, "", null);
                    return(false);
                }
                #endregion

                #region 保存配件图片数据

                //截取上传图片返回值中的文件名称
                int fileNameStartIndex = fileNetUrl.IndexOf("FileName=", StringComparison.Ordinal) + 1;
                int fileNameEndIndex   = fileNameStartIndex + "FileName=".Length;
                int length             = fileNetUrl.Length;
                //文件名称
                string tempFileName = fileNetUrl.Substring(fileNameEndIndex - 1, length - (fileNameEndIndex - 1));

                MDLPIS_InventoryPicture newAutoPartsPicture = new MDLPIS_InventoryPicture();

                _bll.CopyModel(loopPicture, newAutoPartsPicture);
                newAutoPartsPicture.INVP_Barcode     = argsAutoPartsArchive.APA_Barcode;
                newAutoPartsPicture.INVP_PictureName = tempFileName;
                newAutoPartsPicture.INVP_IsValid     = true;
                newAutoPartsPicture.INVP_CreatedBy   = LoginInfoDAX.UserName;
                newAutoPartsPicture.INVP_CreatedTime = BLLCom.GetCurStdDatetime();
                newAutoPartsPicture.INVP_UpdatedBy   = LoginInfoDAX.UserName;
                newAutoPartsPicture.INVP_UpdatedTime = BLLCom.GetCurStdDatetime();

                newAutoPartsPicture.WHERE_INVP_ID        = newAutoPartsPicture.INVP_ID;
                newAutoPartsPicture.WHERE_INVP_VersionNo = newAutoPartsPicture.INVP_VersionNo;

                savePictureList.Add(newAutoPartsPicture);

                #endregion
            }

            #endregion

            #endregion

            #region  步[配件价格类别明细]到平台

            if (!SynchronizeAutoPartsPriceType(syncAutoPartsPriceTypeList))
            {
                //同步到平台失败
                ResultMsg = MsgHelp.GetMsg(MsgCode.E_0018, new object[] { SystemActionEnum.Name.SAVE + SystemTableEnums.Name.BS_AutoPartsArchive, "同步平台失败" });
                return(false);
            }
            #endregion

            #region 带事务的保存

            try
            {
                DBManager.BeginTransaction(DBCONFIG.Coeus);

                #region 保存[配件档案]

                //判断主键是否被赋值
                if (string.IsNullOrEmpty(argsAutoPartsArchive.APA_ID) && string.IsNullOrEmpty(argsAutoPartsArchive.APA_Barcode))
                {
                    #region 新增
                    //主键未被赋值,则执行新增
                    bool insertAutoPartsArchiveResult = _bll.Insert(argsAutoPartsArchive);
                    if (!insertAutoPartsArchiveResult)
                    {
                        DBManager.RollBackTransaction(DBCONFIG.Coeus);
                        ResultMsg = MsgHelp.GetMsg(MsgCode.E_0010, new object[] { SystemActionEnum.Name.NEW + SystemTableEnums.Name.BS_AutoPartsArchive });
                        LogHelper.WriteBussLogEndNG(BussID, LoginInfoDAX.UserName, funcName, ResultMsg, "", null);
                        return(false);
                    }
                    #endregion
                }
                else
                {
                    #region 更新

                    bool updateAutoPartsArchiveResult = _bll.Save(argsAutoPartsArchive);
                    if (!updateAutoPartsArchiveResult)
                    {
                        DBManager.RollBackTransaction(DBCONFIG.Coeus);
                        ResultMsg = MsgHelp.GetMsg(MsgCode.E_0010, new object[] { MsgParam.UPDATE + SystemTableEnums.Name.BS_AutoPartsArchive });
                        return(false);
                    }
                    #endregion
                }
                #endregion

                #region 保存[配件价格类别]

                bool saveAutoPartsPriceResult = _bll.UnitySave(paramAutoPartsPriceDetailList);
                if (!saveAutoPartsPriceResult)
                {
                    DBManager.RollBackTransaction(DBCONFIG.Coeus);
                    ResultMsg = MsgHelp.GetMsg(MsgCode.E_0010, new object[] { MsgParam.UPDATE + SystemTableEnums.Name.BS_AutoPartsArchive });
                    LogHelper.WriteBussLogEndNG(BussID, LoginInfoDAX.UserName, funcName, ResultMsg, "", null);
                    return(false);
                }
                #endregion

                #region 保存配件图片

                foreach (var loopPicture in savePictureList)
                {
                    //执行保存
                    bool saveInvPictureResult = _bll.Save(loopPicture);
                    if (!saveInvPictureResult)
                    {
                        DBManager.RollBackTransaction(DBCONFIG.Coeus);

                        //保存失败,删除本地以及文件服务器上的图片
                        var outMsg = string.Empty;
                        BLLCom.DeleteFileByFileName(loopPicture.INVP_PictureName, ref outMsg);

                        ResultMsg = MsgHelp.GetMsg(MsgCode.E_0010, new object[] { SystemActionEnum.Name.SAVE + MsgParam.AUTOPARTS_PICTURE });
                        LogHelper.WriteBussLogEndNG(BussID, LoginInfoDAX.UserName, funcName, ResultMsg, "", null);
                        return(false);
                    }
                }
                #endregion

                DBManager.CommitTransaction(DBCONFIG.Coeus);
            }
            catch (Exception ex)
            {
                DBManager.RollBackTransaction(DBCONFIG.Coeus);

                foreach (var loopPicture in savePictureList)
                {
                    //保存失败,删除本地以及文件服务器上的图片
                    var outMsg = string.Empty;
                    BLLCom.DeleteFileByFileName(loopPicture.INVP_PictureName, ref outMsg);
                }

                #region 保存本地失败,还原同步到平台上已新增、已更新、已删除的配件价格类别信息

                List <AutoPartsPriceTypeUIModel> restoreSyncAutoPartsPriceTypeList = new List <AutoPartsPriceTypeUIModel>();
                foreach (var loopInsert in paramAutoPartsPriceDetailList.InsertList)
                {
                    loopInsert.APPT_OperateType = "Delete";
                }
                restoreSyncAutoPartsPriceTypeList.AddRange(paramAutoPartsPriceDetailList.InsertList);
                foreach (var loopDelete in paramAutoPartsPriceDetailList.DeleteList)
                {
                    loopDelete.APPT_OperateType = "Save";
                }
                restoreSyncAutoPartsPriceTypeList.AddRange(paramAutoPartsPriceDetailList.DeleteList);
                //查询待更新数据原保存数据内容
                List <MDLBS_AutoPartsPriceType> updateAutoPartsPriceTypeList = new List <MDLBS_AutoPartsPriceType>();
                _bll.QueryForList(SQLID.BS_AutoPartsArchiveManager_SQL05, new MDLBS_AutoPartsPriceType
                {
                    WHERE_APPT_ID = updateIdStr,
                }, updateAutoPartsPriceTypeList);
                foreach (var loopUpdate in paramAutoPartsPriceDetailList.UpdateList)
                {
                    var curUpdateAutoPartsPriceType =
                        updateAutoPartsPriceTypeList.FirstOrDefault(x => x.APPT_ID == loopUpdate.APPT_ID);
                    if (curUpdateAutoPartsPriceType != null && !string.IsNullOrEmpty(curUpdateAutoPartsPriceType.APPT_ID))
                    {
                        _bll.CopyModel(curUpdateAutoPartsPriceType, loopUpdate);
                    }
                    loopUpdate.APPT_OperateType = "Save";
                }
                restoreSyncAutoPartsPriceTypeList.AddRange(paramAutoPartsPriceDetailList.UpdateList);
                SynchronizeAutoPartsPriceType(restoreSyncAutoPartsPriceTypeList);

                #endregion

                ResultMsg = MsgHelp.GetMsg(MsgCode.E_0018, new object[] { SystemActionEnum.Name.SAVE, ex.Message });
                LogHelper.WriteBussLogEndNG(BussID, LoginInfoDAX.UserName, funcName, ex.Message, "", null);
                return(false);
            }

            #endregion

            //将最新数据回写给DetailDS
            CopyModel(argsAutoPartsArchive, paramModel);

            //更新明细版本号
            if (paramAutoPartsPriceDetailList != null)
            {
                if (paramAutoPartsPriceDetailList.InsertList != null)
                {
                    foreach (var loopInsertDetail in paramAutoPartsPriceDetailList.InsertList)
                    {
                        //新增时版本号为1
                        loopInsertDetail.APPT_VersionNo = 1;
                    }
                }

                foreach (var loopUpdateDetail in paramAutoPartsPriceDetailList.UpdateList)
                {
                    //更新时版本号加1
                    loopUpdateDetail.APPT_VersionNo = loopUpdateDetail.APPT_VersionNo + 1;
                }
            }

            #region 更新配件图片版本号

            foreach (var loopPicture in paramAutoPartsPictureList)
            {
                if (string.IsNullOrEmpty(loopPicture.SourceFilePath))
                {
                    continue;
                }
                //保存成功,删除临时保存的图片
                if (File.Exists(loopPicture.SourceFilePath))
                {
                    File.Delete(loopPicture.SourceFilePath);
                }
                //本次保存的图片
                var thisSavePicture = savePictureList.FirstOrDefault(x => x.INVP_PictureName == loopPicture.INVP_PictureName);
                if (thisSavePicture != null)
                {
                    _bll.CopyModel(thisSavePicture, loopPicture);
                }
                //设置版本号
                if (loopPicture.INVP_VersionNo == null)
                {
                    loopPicture.INVP_VersionNo = 1;
                }
                else
                {
                    loopPicture.INVP_VersionNo += 1;
                }
            }
            #endregion

            return(true);
        }