/// <summary> /// 对账 /// </summary> /// <param name="paramHead">UIModel</param> /// <returns></returns> public bool ReconciliationDetailDS(List <AccountPayableBillManagerUIModel> paramHead) { var funcName = "ReconciliationDetailDS"; LogHelper.WriteBussLogStart(BussID, LoginInfoDAX.UserName, funcName, "", "", null); #region 保存应付单 try { DBManager.BeginTransaction(DBCONFIG.Coeus); foreach (var loopAccountPayableBill in paramHead) { //将UIModel转为TBModel var updateAccountPayableBill = loopAccountPayableBill.ToTBModelForSaveAndDelete <MDLFM_AccountPayableBill>(); //更新应付单[业务状态]为[已对账] updateAccountPayableBill.APB_BusinessStatusName = AccountPayableBillStatusEnum.Name.YDZ; updateAccountPayableBill.APB_BusinessStatusCode = AccountPayableBillStatusEnum.Code.YDZ; updateAccountPayableBill.APB_UpdatedBy = LoginInfoDAX.UserName; updateAccountPayableBill.APB_UpdatedTime = BLLCom.GetCurStdDatetime(); bool updateAccountPayableBillResult = _bll.Save(updateAccountPayableBill); if (!updateAccountPayableBillResult) { DBManager.RollBackTransaction(DBCONFIG.Coeus); ResultMsg = MsgHelp.GetMsg(MsgCode.E_0010, new object[] { MsgParam.UPDATE + SystemTableEnums.Name.FM_AccountPayableBill }); LogHelper.WriteBussLogEndNG(BussID, LoginInfoDAX.UserName, funcName, ResultMsg, "", null); return(false); } _bll.CopyModel(updateAccountPayableBill, loopAccountPayableBill); //loopAccountPayableBill.APB_ID = updateAccountPayableBill.WHERE_APB_ID; } DBManager.CommitTransaction(DBCONFIG.Coeus); } catch (Exception ex) { DBManager.RollBackTransaction(DBCONFIG.Coeus); ResultMsg = MsgHelp.GetMsg(MsgCode.E_0018, new object[] { SystemActionEnum.Name.RECONCILIATION, ex.Message }); LogHelper.WriteBussLogEndNG(BussID, LoginInfoDAX.UserName, funcName, ResultMsg, "", null); return(false); } #endregion return(true); }
/// <summary> /// 保存 /// </summary> /// <param name="paramModelList">UIModel</param> /// <returns></returns> public bool SaveDetailDS(SkyCarBindingList <AutoPartsShareInventoryManagerUIModel, MDLPIS_ShareInventory> paramModelList) { //服务端检查 if (!ServerCheck(paramModelList)) { return(false); } var funcName = "SaveShareInventory"; LogHelper.WriteBussLogStart(Trans.IS, LoginInfoDAX.UserName, funcName, "", "", null); #region 准备数据 //同步到平台的数据 List <AutoPartsShareInventoryManagerUIModel> syncShareInventoryList = new List <AutoPartsShareInventoryManagerUIModel>(); #region 新增的数据 ShareInventoryDataSet.InventoryDataTable insertShareInventoryDataTable = new ShareInventoryDataSet.InventoryDataTable(); foreach (var loopInsert in paramModelList.InsertList) { loopInsert.OperateType = "Save"; ShareInventoryDataSet.InventoryRow newInventoryRow = insertShareInventoryDataTable.NewInventoryRow(); newInventoryRow.SI_Org_ID = loopInsert.SI_Org_ID; newInventoryRow.SI_WH_ID = loopInsert.SI_WH_ID; newInventoryRow.SI_WHB_ID = loopInsert.SI_WHB_ID; newInventoryRow.SI_ThirdNo = loopInsert.SI_ThirdNo; newInventoryRow.SI_OEMNo = loopInsert.SI_OEMNo; newInventoryRow.SI_Barcode = loopInsert.SI_Barcode; newInventoryRow.SI_BatchNo = loopInsert.SI_BatchNo; newInventoryRow.SI_Name = loopInsert.SI_Name; newInventoryRow.SI_Specification = loopInsert.SI_Specification; newInventoryRow.SI_SUPP_ID = loopInsert.SI_SUPP_ID; if (loopInsert.SI_Qty != null) { newInventoryRow.SI_Qty = (decimal)loopInsert.SI_Qty; } newInventoryRow.SI_PurchasePriceIsVisible = loopInsert.SI_PurchasePriceIsVisible == null ? false : loopInsert.SI_PurchasePriceIsVisible.Value; if (loopInsert.SI_PurchaseUnitPrice != null) { newInventoryRow.SI_PurchaseUnitPrice = (decimal)loopInsert.SI_PurchaseUnitPrice; } if (loopInsert.SI_PriceOfGeneralCustomer != null) { newInventoryRow.SI_PriceOfGeneralCustomer = (decimal)loopInsert.SI_PriceOfGeneralCustomer; } if (loopInsert.SI_PriceOfCommonAutoFactory != null) { newInventoryRow.SI_PriceOfCommonAutoFactory = (decimal)loopInsert.SI_PriceOfCommonAutoFactory; } if (loopInsert.SI_PriceOfPlatformAutoFactory != null) { newInventoryRow.SI_PriceOfPlatformAutoFactory = (decimal)loopInsert.SI_PriceOfPlatformAutoFactory; } newInventoryRow.SI_IsValid = loopInsert.SI_IsValid == null ? false : loopInsert.SI_IsValid.Value; newInventoryRow.SI_CreatedBy = loopInsert.SI_CreatedBy; newInventoryRow.SI_CreatedTime = BLLCom.GetCurStdDatetime(); newInventoryRow.SI_UpdatedBy = loopInsert.SI_UpdatedBy; newInventoryRow.SI_UpdatedTime = BLLCom.GetCurStdDatetime(); newInventoryRow.SI_VersionNo = "1"; insertShareInventoryDataTable.AddInventoryRow(newInventoryRow); } syncShareInventoryList.AddRange(paramModelList.InsertList); #endregion #region 修改的数据 ShareInventoryDataSet.InventoryDataTable updateShareInventoryDataTable = new ShareInventoryDataSet.InventoryDataTable(); //待更新的共享库存的ID组合字符串(用于本地保存失败时,还原平台上的数据) string updateIdStr = string.Empty; foreach (var loopUpdate in paramModelList.UpdateList) { loopUpdate.OperateType = "Save"; updateIdStr += loopUpdate.SI_ID + SysConst.Semicolon_DBC; ShareInventoryDataSet.InventoryRow newInventoryRow = updateShareInventoryDataTable.NewInventoryRow(); newInventoryRow.SI_ID = loopUpdate.SI_ID; newInventoryRow.SI_Org_ID = loopUpdate.SI_Org_ID; newInventoryRow.SI_WH_ID = loopUpdate.SI_WH_ID; newInventoryRow.SI_WHB_ID = loopUpdate.SI_WHB_ID; newInventoryRow.SI_ThirdNo = loopUpdate.SI_ThirdNo; newInventoryRow.SI_OEMNo = loopUpdate.SI_OEMNo; newInventoryRow.SI_Barcode = loopUpdate.SI_Barcode; newInventoryRow.SI_BatchNo = loopUpdate.SI_BatchNo; newInventoryRow.SI_Name = loopUpdate.SI_Name; newInventoryRow.SI_Specification = loopUpdate.SI_Specification; newInventoryRow.SI_SUPP_ID = loopUpdate.SI_SUPP_ID; if (loopUpdate.SI_Qty != null) { newInventoryRow.SI_Qty = (decimal)loopUpdate.SI_Qty; } newInventoryRow.SI_PurchasePriceIsVisible = loopUpdate.SI_PurchasePriceIsVisible == null ? false : loopUpdate.SI_PurchasePriceIsVisible.Value; if (loopUpdate.SI_PurchaseUnitPrice != null) { newInventoryRow.SI_PurchaseUnitPrice = (decimal)loopUpdate.SI_PurchaseUnitPrice; } if (loopUpdate.SI_PriceOfGeneralCustomer != null) { newInventoryRow.SI_PriceOfGeneralCustomer = (decimal)loopUpdate.SI_PriceOfGeneralCustomer; } if (loopUpdate.SI_PriceOfCommonAutoFactory != null) { newInventoryRow.SI_PriceOfCommonAutoFactory = (decimal)loopUpdate.SI_PriceOfCommonAutoFactory; } if (loopUpdate.SI_PriceOfPlatformAutoFactory != null) { newInventoryRow.SI_PriceOfPlatformAutoFactory = (decimal)loopUpdate.SI_PriceOfPlatformAutoFactory; } newInventoryRow.SI_IsValid = loopUpdate.SI_IsValid == null ? false : loopUpdate.SI_IsValid.Value; newInventoryRow.SI_CreatedBy = loopUpdate.SI_CreatedBy; newInventoryRow.SI_CreatedTime = loopUpdate.SI_CreatedTime == null ? BLLCom.GetCurStdDatetime() : loopUpdate.SI_CreatedTime.Value; newInventoryRow.SI_UpdatedBy = loopUpdate.SI_UpdatedBy; newInventoryRow.SI_UpdatedTime = BLLCom.GetCurStdDatetime(); newInventoryRow.SI_VersionNo = Convert.ToString(loopUpdate.SI_VersionNo + 1); updateShareInventoryDataTable.AddInventoryRow(newInventoryRow); } syncShareInventoryList.AddRange(paramModelList.UpdateList); #endregion #region 除的数据 ShareInventoryDataSet.InventoryDataTable deleteShareInventoryDataTable = new ShareInventoryDataSet.InventoryDataTable(); foreach (var loopDelete in paramModelList.DeleteList) { loopDelete.OperateType = "Delete"; ShareInventoryDataSet.InventoryRow newInventoryRow = deleteShareInventoryDataTable.NewInventoryRow(); newInventoryRow.SI_ID = loopDelete.SI_ID; newInventoryRow.SI_Org_ID = loopDelete.SI_Org_ID; newInventoryRow.SI_WH_ID = loopDelete.SI_WH_ID; newInventoryRow.SI_WHB_ID = loopDelete.SI_WHB_ID; newInventoryRow.SI_ThirdNo = loopDelete.SI_ThirdNo; newInventoryRow.SI_OEMNo = loopDelete.SI_OEMNo; newInventoryRow.SI_Barcode = loopDelete.SI_Barcode; newInventoryRow.SI_BatchNo = loopDelete.SI_BatchNo; newInventoryRow.SI_Name = loopDelete.SI_Name; newInventoryRow.SI_Specification = loopDelete.SI_Specification; newInventoryRow.SI_SUPP_ID = loopDelete.SI_SUPP_ID; if (loopDelete.SI_Qty != null) { newInventoryRow.SI_Qty = (decimal)loopDelete.SI_Qty; } newInventoryRow.SI_PurchasePriceIsVisible = loopDelete.SI_PurchasePriceIsVisible == null ? false : loopDelete.SI_PurchasePriceIsVisible.Value; if (loopDelete.SI_PurchaseUnitPrice != null) { newInventoryRow.SI_PurchaseUnitPrice = (decimal)loopDelete.SI_PurchaseUnitPrice; } if (loopDelete.SI_PriceOfGeneralCustomer != null) { newInventoryRow.SI_PriceOfGeneralCustomer = (decimal)loopDelete.SI_PriceOfGeneralCustomer; } if (loopDelete.SI_PriceOfCommonAutoFactory != null) { newInventoryRow.SI_PriceOfCommonAutoFactory = (decimal)loopDelete.SI_PriceOfCommonAutoFactory; } if (loopDelete.SI_PriceOfPlatformAutoFactory != null) { newInventoryRow.SI_PriceOfPlatformAutoFactory = (decimal)loopDelete.SI_PriceOfPlatformAutoFactory; } newInventoryRow.SI_IsValid = loopDelete.SI_IsValid == null ? false : loopDelete.SI_IsValid.Value; newInventoryRow.SI_CreatedBy = loopDelete.SI_CreatedBy; newInventoryRow.SI_CreatedTime = loopDelete.SI_CreatedTime == null ? BLLCom.GetCurStdDatetime() : loopDelete.SI_CreatedTime.Value; newInventoryRow.SI_UpdatedBy = loopDelete.SI_UpdatedBy; newInventoryRow.SI_UpdatedTime = BLLCom.GetCurStdDatetime(); newInventoryRow.SI_VersionNo = Convert.ToString(loopDelete.SI_VersionNo); deleteShareInventoryDataTable.AddInventoryRow(newInventoryRow); } syncShareInventoryList.AddRange(paramModelList.DeleteList); #endregion #endregion #region 保存数据 #region 步到平台 if (!SynchronizeShareInventory(syncShareInventoryList)) { //同步到平台失败 ResultMsg = MsgHelp.GetMsg(MsgCode.E_0018, new object[] { SystemActionEnum.Name.SAVE + SystemTableEnums.Name.PIS_ShareInventory, "同步平台失败" }); return(false); } #endregion try { //打开数据库并连接 using (SqlConnection mySqlConnection = new SqlConnection { ConnectionString = DBManager.GetConnectionString(DBCONFIG.Coeus) }) { SqlCommand mySqlCommand = new SqlCommand(); mySqlCommand.Connection = mySqlConnection; mySqlCommand.CommandText = "P_PIS_ShareInventory"; mySqlCommand.CommandType = CommandType.StoredProcedure; mySqlCommand.Parameters.Add("@UpdateShareInventory", SqlDbType.Structured); mySqlCommand.Parameters[0].Value = updateShareInventoryDataTable; mySqlCommand.Parameters.Add("@InsertShareInventory", SqlDbType.Structured); mySqlCommand.Parameters[1].Value = insertShareInventoryDataTable; mySqlCommand.Parameters.Add("@DeleteShareInventory", SqlDbType.Structured); mySqlCommand.Parameters[2].Value = deleteShareInventoryDataTable; mySqlConnection.Open(); mySqlCommand.ExecuteNonQuery(); } } catch (Exception ex) { #region 保存本地失败,还原同步到平台上已新增、已更新、已删除的共享库存 List <AutoPartsShareInventoryManagerUIModel> restoreSyncShareInventoryList = new List <AutoPartsShareInventoryManagerUIModel>(); foreach (var loopInsert in paramModelList.InsertList) { loopInsert.OperateType = "Delete"; } restoreSyncShareInventoryList.AddRange(paramModelList.InsertList); foreach (var loopDelete in paramModelList.DeleteList) { loopDelete.OperateType = "Save"; } restoreSyncShareInventoryList.AddRange(paramModelList.DeleteList); //查询待更新数据原保存数据内容 List <MDLPIS_ShareInventory> updateShareInventoryList = new List <MDLPIS_ShareInventory>(); _bll.QueryForList(SQLID.IS_AutoPartsShareInventoryManager_SQL02, new MDLPIS_ShareInventory { WHERE_SI_ID = updateIdStr, }, updateShareInventoryList); foreach (var loopUpdate in paramModelList.UpdateList) { var curUpdateShareInventory = updateShareInventoryList.FirstOrDefault(x => x.SI_ID == loopUpdate.SI_ID); if (curUpdateShareInventory != null && !string.IsNullOrEmpty(curUpdateShareInventory.SI_ID)) { _bll.CopyModel(curUpdateShareInventory, loopUpdate); } loopUpdate.OperateType = "Save"; } restoreSyncShareInventoryList.AddRange(paramModelList.UpdateList); SynchronizeShareInventory(restoreSyncShareInventoryList); #endregion ResultMsg = MsgHelp.GetMsg(MsgCode.E_0018, new object[] { SystemActionEnum.Name.SAVE, ex.Message }); LogHelper.WriteBussLogEndOK(Trans.IS, LoginInfoDAX.UserName, funcName, MsgHelp.GetMsg(MsgCode.E_0018, new object[] { SystemActionEnum.Name.SAVE, ex.Message }), "", null); return(false); } #endregion return(true); }
/// <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); }
/// <summary> /// 保存 /// </summary> /// <param name="paramUser"></param> /// <param name="paramUserOrgList"></param> /// <returns></returns> public bool SaveDetailDS(UserManagerUIModel paramUser, SkyCarBindingList <UserOrgUIModel, MDLSM_UserOrg> paramUserOrgList) { #region 带事务的保存 //将UIModel转为TBModel var argsUser = paramUser.ToTBModelForSaveAndDelete <MDLSM_User>(); try { DBManager.BeginTransaction(DBCONFIG.Coeus); #region 保存用户信息 if (string.IsNullOrEmpty(paramUser.User_ID)) { argsUser.User_ID = Guid.NewGuid().ToString(); argsUser.User_CreatedBy = LoginInfoDAX.UserName; argsUser.User_CreatedTime = BLLCom.GetCurStdDatetime(); } argsUser.User_IsValid = true; argsUser.User_UpdatedBy = LoginInfoDAX.UserName; argsUser.User_UpdatedTime = BLLCom.GetCurStdDatetime(); bool saveUserResult = _bll.Save(argsUser); if (!saveUserResult) { DBManager.RollBackTransaction(DBCONFIG.Coeus); ResultMsg = MsgHelp.GetMsg(MsgCode.E_0010, new object[] { SystemActionEnum.Name.SAVE + SystemTableEnums.Name.SM_User }); return(false); } #endregion //保存用户组织信息 if (paramUserOrgList != null && paramUserOrgList.InsertList != null && paramUserOrgList.InsertList.Count > 0) { foreach (var loopUserOrg in paramUserOrgList.InsertList) { loopUserOrg.UO_User_ID = argsUser.User_ID ?? argsUser.WHERE_User_ID; loopUserOrg.UO_CreatedBy = LoginInfoDAX.UserName; loopUserOrg.UO_CreatedTime = BLLCom.GetCurStdDatetime(); loopUserOrg.UO_UpdatedBy = LoginInfoDAX.UserName; loopUserOrg.UO_UpdatedTime = BLLCom.GetCurStdDatetime(); } bool saveUserOrgResult = _bll.InsertByList <UserOrgUIModel, MDLSM_UserOrg>(paramUserOrgList.InsertList); if (!saveUserOrgResult) { DBManager.RollBackTransaction(DBCONFIG.Coeus); ResultMsg = MsgHelp.GetMsg(MsgCode.E_0010, new object[] { SystemActionEnum.Name.SAVE + SystemTableEnums.Name.SM_UserOrg }); return(false); } } if (paramUserOrgList != null && paramUserOrgList.DeleteList != null && paramUserOrgList.DeleteList.Count > 0) { foreach (var loopUserOrg in paramUserOrgList.DeleteList) { loopUserOrg.WHERE_UO_ID = loopUserOrg.UO_ID; } bool deleteUserOrgResult = _bll.DeleteByList <UserOrgUIModel, MDLSM_UserOrg>(paramUserOrgList.DeleteList); if (!deleteUserOrgResult) { DBManager.RollBackTransaction(DBCONFIG.Coeus); ResultMsg = MsgHelp.GetMsg(MsgCode.E_0010, new object[] { SystemActionEnum.Name.SAVE + SystemTableEnums.Name.SM_UserOrg }); return(false); } } DBManager.CommitTransaction(DBCONFIG.Coeus); } catch (Exception ex) { DBManager.RollBackTransaction(DBCONFIG.Coeus); 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); } //将最新数据回写给DetailDS _bll.CopyModel(argsUser, paramUser); //刷新用户缓存 var resultUserList = CacheDAX.Get(CacheDAX.ConfigDataKey.SystemUser) as List <MDLSM_User>; List <MDLSM_User> newUserList = new List <MDLSM_User>(); if (resultUserList != null) { newUserList = resultUserList; if (resultUserList.All(x => x.User_ID != argsUser.User_ID && x.User_Name != argsUser.User_Name)) { newUserList.Insert(0, argsUser); CacheDAX.Add(CacheDAX.ConfigDataKey.SystemUser, newUserList, true); } } else { newUserList.Add(argsUser); CacheDAX.Add(CacheDAX.ConfigDataKey.SystemUser, newUserList, true); } return(true); #endregion }
/// <summary> /// 保存数据 /// </summary> /// <param name="paramHead">待保存的车辆信息</param> /// <param name="paramVehicleOemPartsList">待保存的原厂件信息列表</param> /// <param name="paramVehicleBrandPartsList">待保存的品牌件信息列表</param> /// <param name="paramIsJoinVinInfo">是否合并当前车架号的信息</param> /// <returns></returns> public bool SaveDetailDS(VehicleModelMatchAutoPartsManagerUIModel paramHead, SkyCarBindingList <VehicleOemPartsInfoUIModel, MDLBS_VehicleOemPartsInfo> paramVehicleOemPartsList, SkyCarBindingList <VehicleThirdPartsInfoUIModel, MDLBS_VehicleThirdPartsInfo> paramVehicleBrandPartsList, bool paramIsJoinVinInfo) { var funcName = "SaveDetailDS"; LogHelper.WriteBussLogStart(BussID, LoginInfoDAX.UserName, funcName, "", "", null); #region 准备数据 //待同步的[车辆信息列表] List <VehicleModelMatchAutoPartsManagerUIModel> syncVehicleInfoList = new List <VehicleModelMatchAutoPartsManagerUIModel>(); //待同步的[车辆原厂件信息列表] List <VehicleOemPartsInfoUIModel> syncVehicleOemPartsInfoList = new List <VehicleOemPartsInfoUIModel>(); //待同步的[车辆品牌件信息列表] List <VehicleThirdPartsInfoUIModel> syncVehicleBrandPartsInfoList = new List <VehicleThirdPartsInfoUIModel>(); #region 车辆信息 //待保存的[车辆信息] MDLBS_VehicleInfo saveVehicleInfo = new MDLBS_VehicleInfo(); if (paramIsJoinVinInfo) { #region 合并当前车架号对应信息的场合 //查询当前车架号对应的车辆信息 _bll.QueryForObject <MDLBS_VehicleInfo, MDLBS_VehicleInfo>(new MDLBS_VehicleInfo { WHERE_VC_VIN = paramHead.VC_VIN, WHERE_VC_IsValid = true, }, saveVehicleInfo); saveVehicleInfo.VC_UpdatedBy = LoginInfoDAX.UserName; saveVehicleInfo.VC_UpdatedTime = BLLCom.GetCurStdDatetime(); saveVehicleInfo.WHERE_VC_ID = saveVehicleInfo.VC_ID; saveVehicleInfo.WHERE_VC_VersionNo = saveVehicleInfo.VC_VersionNo; //查询当前车架号对应的所有[原厂件信息] List <MDLBS_VehicleOemPartsInfo> resultVehicleOemPartsInfoList = new List <MDLBS_VehicleOemPartsInfo>(); _bll.QueryForList <MDLBS_VehicleOemPartsInfo, MDLBS_VehicleOemPartsInfo>(new MDLBS_VehicleOemPartsInfo { WHERE_VOPI_VC_VIN = saveVehicleInfo.VC_VIN, WHERE_VOPI_IsValid = true, }, resultVehicleOemPartsInfoList); //查询当前车架号对应的所有[品牌件信息] List <MDLBS_VehicleThirdPartsInfo> resultVehicleBrandPartsInfoList = new List <MDLBS_VehicleThirdPartsInfo>(); _bll.QueryForList <MDLBS_VehicleThirdPartsInfo, MDLBS_VehicleThirdPartsInfo>(new MDLBS_VehicleThirdPartsInfo { WHERE_VTPI_VC_VIN = saveVehicleInfo.VC_VIN, WHERE_VTPI_IsValid = true, }, resultVehicleBrandPartsInfoList); //移除重复的[原厂件信息] foreach (var loopOemParts in resultVehicleOemPartsInfoList) { var curOemParts = paramVehicleOemPartsList.FirstOrDefault( x => x.VOPI_VC_VIN == loopOemParts.VOPI_VC_VIN && x.VOPI_OEMNo == loopOemParts.VOPI_OEMNo); if (curOemParts != null) { paramVehicleOemPartsList.Remove(curOemParts); } } //移除重复的[品牌件信息] foreach (var loopBrandParts in resultVehicleBrandPartsInfoList) { var curBrandParts = paramVehicleBrandPartsList.FirstOrDefault(x => x.VTPI_VC_VIN == loopBrandParts.VTPI_VC_VIN && x.VTPI_ThirdNo == loopBrandParts.VTPI_ThirdNo); if (curBrandParts != null) { paramVehicleBrandPartsList.Remove(curBrandParts); } } #endregion } else { #region 合并当前车架号对应信息的场合 //将UIModel转为TBModel saveVehicleInfo = paramHead.ToTBModelForSaveAndDelete <MDLBS_VehicleInfo>(); //判断主键是否被赋值 if (string.IsNullOrEmpty(paramHead.VC_ID)) { saveVehicleInfo.VC_ID = Guid.NewGuid().ToString(); saveVehicleInfo.VC_CreatedBy = LoginInfoDAX.UserName; saveVehicleInfo.VC_CreatedTime = BLLCom.GetCurStdDatetime(); } saveVehicleInfo.VC_UpdatedBy = LoginInfoDAX.UserName; saveVehicleInfo.VC_UpdatedTime = BLLCom.GetCurStdDatetime(); #endregion } VehicleModelMatchAutoPartsManagerUIModel syncehicleInfo = new VehicleModelMatchAutoPartsManagerUIModel(); _bll.CopyModel(saveVehicleInfo, syncehicleInfo); syncehicleInfo.VC_OperateType = "Save"; syncVehicleInfoList.Add(syncehicleInfo); #endregion #region 原厂件信息 //添加的明细 foreach (var loopDetailItem in paramVehicleOemPartsList.InsertList) { loopDetailItem.VOPI_VC_VIN = saveVehicleInfo.VC_VIN; loopDetailItem.VOPI_CreatedBy = LoginInfoDAX.UserName; loopDetailItem.VOPI_CreatedTime = BLLCom.GetCurStdDatetime(); loopDetailItem.VOPI_UpdatedBy = LoginInfoDAX.UserName; loopDetailItem.VOPI_UpdatedTime = BLLCom.GetCurStdDatetime(); loopDetailItem.VOPI_OperateType = "Save"; } //更新的明细 foreach (var loopDetailItem in paramVehicleOemPartsList.UpdateList) { loopDetailItem.VOPI_VC_VIN = saveVehicleInfo.VC_VIN; loopDetailItem.VOPI_UpdatedBy = LoginInfoDAX.UserName; loopDetailItem.VOPI_UpdatedTime = BLLCom.GetCurStdDatetime(); loopDetailItem.VOPI_OperateType = "Save"; } //删除的明细 foreach (var loopDetailItem in paramVehicleOemPartsList.DeleteList) { loopDetailItem.VOPI_OperateType = "Delete"; } syncVehicleOemPartsInfoList.AddRange(paramVehicleOemPartsList.InsertList); syncVehicleOemPartsInfoList.AddRange(paramVehicleOemPartsList.UpdateList); syncVehicleOemPartsInfoList.AddRange(paramVehicleOemPartsList.DeleteList); #endregion #region 品牌件信息 //添加的明细 foreach (var loopDetailItem in paramVehicleBrandPartsList.InsertList) { loopDetailItem.VTPI_VC_VIN = saveVehicleInfo.VC_VIN; loopDetailItem.VTPI_CreatedBy = LoginInfoDAX.UserName; loopDetailItem.VTPI_CreatedTime = BLLCom.GetCurStdDatetime(); loopDetailItem.VTPI_UpdatedBy = LoginInfoDAX.UserName; loopDetailItem.VTPI_UpdatedTime = BLLCom.GetCurStdDatetime(); loopDetailItem.VTPI_OperateType = "Save"; } //更新的明细 foreach (var loopDetailItem in paramVehicleBrandPartsList.UpdateList) { loopDetailItem.VTPI_VC_VIN = saveVehicleInfo.VC_VIN; loopDetailItem.VTPI_UpdatedBy = LoginInfoDAX.UserName; loopDetailItem.VTPI_UpdatedTime = BLLCom.GetCurStdDatetime(); loopDetailItem.VTPI_OperateType = "Save"; } //删除的明细 foreach (var loopDetailItem in paramVehicleBrandPartsList.DeleteList) { loopDetailItem.VTPI_OperateType = "Delete"; } syncVehicleBrandPartsInfoList.AddRange(paramVehicleBrandPartsList.InsertList); syncVehicleBrandPartsInfoList.AddRange(paramVehicleBrandPartsList.UpdateList); syncVehicleBrandPartsInfoList.AddRange(paramVehicleBrandPartsList.DeleteList); #endregion #endregion #region 步到平台 if (!SynchronizeVehicleRelateInfo(syncVehicleInfoList, syncVehicleOemPartsInfoList, syncVehicleBrandPartsInfoList)) { //同步到平台失败 ResultMsg = MsgHelp.GetMsg(MsgCode.E_0018, new object[] { SystemActionEnum.Name.SAVE, "同步平台失败" }); return(false); } #endregion #region 带事务的保存 try { DBManager.BeginTransaction(DBCONFIG.Coeus); #region 保存[车辆信息] var saveVehicleInfoResult = _bll.Save(saveVehicleInfo, saveVehicleInfo.VC_ID); if (!saveVehicleInfoResult) { DBManager.RollBackTransaction(DBCONFIG.Coeus); //保存本地失败的场合,还原平台上保存的信息 RestoreSavePlatformInfo(saveVehicleInfo, paramVehicleOemPartsList, paramVehicleBrandPartsList); ResultMsg = MsgHelp.GetMsg(MsgCode.E_0010, new object[] { SystemActionEnum.Name.SAVE + SystemTableEnums.Name.BS_VehicleInfo }); LogHelper.WriteBussLogEndNG(BussID, LoginInfoDAX.UserName, funcName, ResultMsg, "", null); return(false); } #endregion #region 保存[车辆原厂件信息] var saveOemPartsResult = _bll.UnitySave(paramVehicleOemPartsList); if (!saveOemPartsResult) { DBManager.RollBackTransaction(DBCONFIG.Coeus); //保存本地失败的场合,还原平台上保存的信息 RestoreSavePlatformInfo(saveVehicleInfo, paramVehicleOemPartsList, paramVehicleBrandPartsList); ResultMsg = MsgHelp.GetMsg(MsgCode.E_0010, new object[] { SystemActionEnum.Name.SAVE + SystemTableEnums.Name.BS_VehicleOemPartsInfo }); LogHelper.WriteBussLogEndNG(BussID, LoginInfoDAX.UserName, funcName, ResultMsg, "", null); return(false); } #endregion #region 保存[车辆品牌件信息] var saveBrandPartsResult = _bll.UnitySave(paramVehicleBrandPartsList); if (!saveBrandPartsResult) { DBManager.RollBackTransaction(DBCONFIG.Coeus); //保存本地失败的场合,还原平台上保存的信息 RestoreSavePlatformInfo(saveVehicleInfo, paramVehicleOemPartsList, paramVehicleBrandPartsList); ResultMsg = MsgHelp.GetMsg(MsgCode.E_0010, new object[] { SystemActionEnum.Name.SAVE + SystemTableEnums.Name.BS_VehicleBrandPartsInfo }); LogHelper.WriteBussLogEndNG(BussID, LoginInfoDAX.UserName, funcName, ResultMsg, "", null); return(false); } #endregion DBManager.CommitTransaction(DBCONFIG.Coeus); } catch (Exception ex) { DBManager.RollBackTransaction(DBCONFIG.Coeus); //保存本地失败的场合,还原平台上保存的信息 RestoreSavePlatformInfo(saveVehicleInfo, paramVehicleOemPartsList, paramVehicleBrandPartsList); 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(saveVehicleInfo, paramHead); #region 更新[车辆原厂件信息]版本号 foreach (var loopInsertDetail in paramVehicleOemPartsList.InsertList) { //新增时版本号为1 loopInsertDetail.VOPI_VersionNo = 1; } foreach (var loopUpdateDetail in paramVehicleOemPartsList.UpdateList) { //更新时版本号加1 loopUpdateDetail.VOPI_VersionNo = loopUpdateDetail.VOPI_VersionNo + 1; } #endregion #region 更新[车辆品牌件信息]版本号 foreach (var loopInsertDetail in paramVehicleBrandPartsList.InsertList) { //新增时版本号为1 loopInsertDetail.VTPI_VersionNo = 1; } foreach (var loopUpdateDetail in paramVehicleBrandPartsList.UpdateList) { //更新时版本号加1 loopUpdateDetail.VTPI_VersionNo = loopUpdateDetail.VTPI_VersionNo + 1; } #endregion return(true); }
/// <summary> /// 保存 /// </summary> /// <param name="paramHead">单头</param> /// <param name="paramDetailList">明细列表</param> /// <param name="paramDistributePathList">下发路径</param> /// <returns></returns> public bool SaveDetailDs(SalesTemplateManagerUIModel paramHead, SkyCarBindingList <SalesTemplateDetailUIModel, MDLSD_SalesTemplateDetail> paramDetailList, SkyCarBindingList <DistributePathUIModel, MDLSD_DistributePath> paramDistributePathList) { var funcName = "SaveDetailDS"; LogHelper.WriteBussLogStart(BussID, LoginInfoDAX.UserName, funcName, "", "", null); //服务端检查 if (!ServerCheck(paramHead)) { LogHelper.WriteBussLogEndNG(BussID, LoginInfoDAX.UserName, funcName, ResultMsg, "", null); return(false); } #region 准备数据 #region 定义变量 //待新增的目的组织的[销售模板]列表 List <MDLSD_SalesTemplate> insertSalesTmpListOfDistributeOrg = new List <MDLSD_SalesTemplate>(); //待新增的目的组织的[销售模板明细]列表 List <MDLSD_SalesTemplateDetail> insertSalesTmpDetailListOfDistributeOrg = new List <MDLSD_SalesTemplateDetail>(); //待删除的目的组织的[销售模板]列表 List <MDLSD_SalesTemplate> deleteSalesTmpListOfDistributeOrg = new List <MDLSD_SalesTemplate>(); //待删除的目的组织的[销售模板明细]列表 List <MDLSD_SalesTemplateDetail> deleteSalesTmpDetailListOfDistributeOrg = new List <MDLSD_SalesTemplateDetail>(); #endregion #region 保存[销售模板] //将UIModel转为TBModel var argsHead = paramHead.ToTBModelForSaveAndDelete <MDLSD_SalesTemplate>(); //判断主键是否被赋值 if (string.IsNullOrEmpty(paramHead.SasT_ID)) { argsHead.SasT_ID = Guid.NewGuid().ToString(); argsHead.SasT_CreatedBy = LoginInfoDAX.UserName; argsHead.SasT_CreatedTime = BLLCom.GetCurStdDatetime(); } argsHead.SasT_UpdatedBy = LoginInfoDAX.UserName; argsHead.SasT_UpdatedTime = BLLCom.GetCurStdDatetime(); #endregion #region 保存[销售模板明细] //添加的明细 if (paramDetailList != null && paramDetailList.InsertList != null && paramDetailList.InsertList.Count > 0) { foreach (var loopSalesOrderDetail in paramDetailList.InsertList) { //赋值销售模板ID loopSalesOrderDetail.SasTD_SasT_ID = argsHead.SasT_ID ?? argsHead.WHERE_SasT_ID; loopSalesOrderDetail.SasTD_CreatedBy = LoginInfoDAX.UserName; loopSalesOrderDetail.SasTD_CreatedTime = BLLCom.GetCurStdDatetime(); loopSalesOrderDetail.SasTD_UpdatedBy = LoginInfoDAX.UserName; loopSalesOrderDetail.SasTD_UpdatedTime = BLLCom.GetCurStdDatetime(); } } #endregion #region 发或取消下发销售模板 if (paramDistributePathList != null) { //下发销售模板:新增目的组织下的[销售模板]和[销售模板明细]列表 if (paramDistributePathList.InsertList != null && paramDistributePathList.InsertList.Count > 0) { foreach (var loopDistributePath in paramDistributePathList.InsertList) { #region 发路径 //赋值销售模板ID loopDistributePath.DP_SendDataID = !string.IsNullOrEmpty(argsHead.SasT_ID) ? argsHead.SasT_ID : argsHead.WHERE_SasT_ID; loopDistributePath.DP_CreatedBy = LoginInfoDAX.UserName; loopDistributePath.DP_CreatedTime = BLLCom.GetCurStdDatetime(); loopDistributePath.DP_UpdatedBy = LoginInfoDAX.UserName; loopDistributePath.DP_UpdatedTime = BLLCom.GetCurStdDatetime(); #endregion #region 目的组织下的[销售模板]列表 MDLSD_SalesTemplate insertSalesTemplate = new MDLSD_SalesTemplate(); _bll.CopyModel(argsHead, insertSalesTemplate); insertSalesTemplate.SasT_ID = Guid.NewGuid().ToString(); insertSalesTemplate.SasT_Org_ID = loopDistributePath.DP_Org_ID_To; insertSalesTemplate.SasT_CreatedBy = LoginInfoDAX.UserName; insertSalesTemplate.SasT_CreatedTime = BLLCom.GetCurStdDatetime(); insertSalesTemplate.SasT_UpdatedBy = LoginInfoDAX.UserName; insertSalesTemplate.SasT_UpdatedTime = BLLCom.GetCurStdDatetime(); insertSalesTmpListOfDistributeOrg.Add(insertSalesTemplate); #endregion #region 目的组织下的[销售模板明细]列表 if (paramDetailList != null) { foreach (var loopSalesTemplateDetail in paramDetailList) { MDLSD_SalesTemplateDetail inserSalesTemplateDetail = new MDLSD_SalesTemplateDetail(); _bll.CopyModel(loopSalesTemplateDetail, inserSalesTemplateDetail); inserSalesTemplateDetail.SasTD_ID = Guid.NewGuid().ToString(); inserSalesTemplateDetail.SasTD_SasT_ID = insertSalesTemplate.SasT_ID; inserSalesTemplateDetail.SasTD_CreatedBy = LoginInfoDAX.UserName; inserSalesTemplateDetail.SasTD_CreatedTime = BLLCom.GetCurStdDatetime(); inserSalesTemplateDetail.SasTD_UpdatedBy = LoginInfoDAX.UserName; inserSalesTemplateDetail.SasTD_UpdatedTime = BLLCom.GetCurStdDatetime(); insertSalesTmpDetailListOfDistributeOrg.Add(inserSalesTemplateDetail); } } #endregion } } //取消下发销售模板:删除目的组织下的[销售模板]和[销售模板明细]列表 if (paramDistributePathList.DeleteList != null && paramDistributePathList.DeleteList.Count > 0) { foreach (var loopDistributePath in paramDistributePathList.DeleteList) { if (string.IsNullOrEmpty(loopDistributePath.DP_ID) || string.IsNullOrEmpty(loopDistributePath.DP_Org_ID_To)) { continue; } #region 目的组织下的[销售模板] //查询目的组织下的[销售模板] var deleteSalesTemplate = _bll.QueryForObject <MDLSD_SalesTemplate>(SQLID.SD_SalesTemplate_SQL03, new SalesTemplateManagerQCModel { WHERE_SasT_Name = argsHead.SasT_Name, WHERE_DP_SendDataID = !string.IsNullOrEmpty(argsHead.SasT_ID) ? argsHead.SasT_ID : argsHead.WHERE_SasT_ID, WHERE_DP_Org_ID_From = argsHead.SasT_Org_ID, WHERE_DP_Org_ID_To = loopDistributePath.DP_Org_ID_To }); if (deleteSalesTemplate == null || string.IsNullOrEmpty(deleteSalesTemplate.SasT_ID)) { continue; } deleteSalesTemplate.WHERE_SasT_ID = deleteSalesTemplate.SasT_ID; deleteSalesTmpListOfDistributeOrg.Add(deleteSalesTemplate); #endregion #region 目的组织下的[销售模板明细]列表 List <MDLSD_SalesTemplateDetail> tempSalesTemplateDetailList = new List <MDLSD_SalesTemplateDetail>(); _bll.QueryForList <MDLSD_SalesTemplateDetail, MDLSD_SalesTemplateDetail>(new MDLSD_SalesTemplateDetail { WHERE_SasTD_SasT_ID = deleteSalesTemplate.SasT_ID, WHERE_SasTD_IsValid = true }, tempSalesTemplateDetailList); tempSalesTemplateDetailList.ForEach(x => x.WHERE_SasTD_ID = x.SasTD_ID); deleteSalesTmpDetailListOfDistributeOrg.AddRange(tempSalesTemplateDetailList); #endregion } } } #endregion #endregion #region 带事务的保存 try { DBManager.BeginTransaction(DBCONFIG.Coeus); #region 保存[销售模板] //执行保存 if (!_bll.Save(argsHead, argsHead.SasT_ID)) { DBManager.RollBackTransaction(DBCONFIG.Coeus); ResultMsg = MsgHelp.GetMsg(MsgCode.E_0010, new object[] { SystemActionEnum.Name.SAVE + SystemTableEnums.Name.SD_SalesTemplate }); LogHelper.WriteBussLogEndNG(BussID, LoginInfoDAX.UserName, funcName, ResultMsg, "", null); return(false); } #endregion #region 保存[销售模板明细] if (paramDetailList != null) { //执行保存 if (!_bll.UnitySave(paramDetailList)) { DBManager.RollBackTransaction(DBCONFIG.Coeus); ResultMsg = MsgHelp.GetMsg(MsgCode.E_0010, new object[] { SystemActionEnum.Name.SAVE + SystemTableEnums.Name.SD_SalesTemplateDetail }); LogHelper.WriteBussLogEndNG(BussID, LoginInfoDAX.UserName, funcName, ResultMsg, "", null); return(false); } } #endregion #region 保存[下发路径] if (paramDistributePathList != null) { //执行保存 if (!_bll.UnitySave(paramDistributePathList)) { DBManager.RollBackTransaction(DBCONFIG.Coeus); ResultMsg = MsgHelp.GetMsg(MsgCode.E_0010, new object[] { SystemActionEnum.Name.SAVE + SystemTableEnums.Name.SD_DistributePath }); LogHelper.WriteBussLogEndNG(BussID, LoginInfoDAX.UserName, funcName, ResultMsg, "", null); return(false); } } #endregion #region 新增目的组织下的[销售模板] if (insertSalesTmpListOfDistributeOrg.Count > 0) { var insertSalesTmpListOfDistributeOrgResult = _bll.InsertByList <MDLSD_SalesTemplate, MDLSD_SalesTemplate>(insertSalesTmpListOfDistributeOrg); if (!insertSalesTmpListOfDistributeOrgResult) { DBManager.RollBackTransaction(DBCONFIG.Coeus); ResultMsg = MsgHelp.GetMsg(MsgCode.E_0010, new object[] { SystemActionEnum.Name.DELIVER + SystemTableEnums.Name.SD_SalesTemplate }); LogHelper.WriteBussLogEndNG(BussID, LoginInfoDAX.UserName, funcName, ResultMsg, "", null); return(false); } } #endregion #region 新增目的组织下的[销售模板明细] if (insertSalesTmpDetailListOfDistributeOrg.Count > 0) { var insertSalesTmpListOfDistributeOrgResult = _bll.InsertByList <MDLSD_SalesTemplateDetail, MDLSD_SalesTemplateDetail>(insertSalesTmpDetailListOfDistributeOrg); if (!insertSalesTmpListOfDistributeOrgResult) { DBManager.RollBackTransaction(DBCONFIG.Coeus); ResultMsg = MsgHelp.GetMsg(MsgCode.E_0010, new object[] { SystemActionEnum.Name.DELIVER + SystemTableEnums.Name.SD_SalesTemplate }); LogHelper.WriteBussLogEndNG(BussID, LoginInfoDAX.UserName, funcName, ResultMsg, "", null); return(false); } } #endregion #region 除目的组织下的[销售模板] if (deleteSalesTmpListOfDistributeOrg.Count > 0) { var deleteSalesTmpListOfDistributeOrgResult = _bll.DeleteByList <MDLSD_SalesTemplate, MDLSD_SalesTemplate>(deleteSalesTmpListOfDistributeOrg); if (!deleteSalesTmpListOfDistributeOrgResult) { DBManager.RollBackTransaction(DBCONFIG.Coeus); ResultMsg = MsgHelp.GetMsg(MsgCode.E_0010, new object[] { SystemActionEnum.Name.CANCELDELIVER + SystemTableEnums.Name.SD_SalesTemplate }); LogHelper.WriteBussLogEndNG(BussID, LoginInfoDAX.UserName, funcName, ResultMsg, "", null); return(false); } } #endregion #region 除目的组织下的[销售模板明细] if (deleteSalesTmpDetailListOfDistributeOrg.Count > 0) { var deleteSalesTmpDetailListOfDistributeOrgResult = _bll.DeleteByList <MDLSD_SalesTemplateDetail, MDLSD_SalesTemplateDetail>(deleteSalesTmpDetailListOfDistributeOrg); if (!deleteSalesTmpDetailListOfDistributeOrgResult) { DBManager.RollBackTransaction(DBCONFIG.Coeus); ResultMsg = MsgHelp.GetMsg(MsgCode.E_0010, new object[] { SystemActionEnum.Name.CANCELDELIVER + SystemTableEnums.Name.SD_SalesTemplate }); LogHelper.WriteBussLogEndNG(BussID, LoginInfoDAX.UserName, funcName, ResultMsg, "", null); return(false); } } #endregion DBManager.CommitTransaction(DBCONFIG.Coeus); } catch (Exception ex) { DBManager.RollBackTransaction(DBCONFIG.Coeus); 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.SasTD_VersionNo = 1; } } foreach (var loopUpdateDetail in paramDetailList.UpdateList) { //更新时版本号加1 loopUpdateDetail.SasTD_VersionNo = loopUpdateDetail.SasTD_VersionNo + 1; } } //更新下发路径版本号 if (paramDistributePathList != null) { if (paramDistributePathList.InsertList != null) { foreach (var loopInsertDetail in paramDistributePathList.InsertList) { //新增时版本号为1 loopInsertDetail.DP_VersionNo = 1; } } foreach (var loopUpdateDetail in paramDistributePathList.UpdateList) { //更新时版本号加1 loopUpdateDetail.DP_VersionNo = loopUpdateDetail.DP_VersionNo + 1; } } return(true); }
/// <summary> /// 保存 /// </summary> /// <param name="paramHead">UIModel</param> /// <returns></returns> public bool SaveDetailDS(WarehouseManagerUIModel paramHead, SkyCarBindingList <WarehouseBinManagerUIModel, MDLPIS_WarehouseBin> paramWarehouseBinList) { //服务端检查 if (!ServerCheck(paramHead)) { return(false); } #region 准备数据 #region 仓库 //将UIModel转为TBModel var argsWarehouse = paramHead.ToTBModelForSaveAndDelete <MDLPIS_Warehouse>(); //判断主键是否被赋值 if (string.IsNullOrEmpty(paramHead.WH_ID)) { argsWarehouse.WH_ID = Guid.NewGuid().ToString(); argsWarehouse.WH_CreatedBy = LoginInfoDAX.UserName; argsWarehouse.WH_CreatedTime = BLLCom.GetCurStdDatetime(); } argsWarehouse.WH_UpdatedBy = LoginInfoDAX.UserName; argsWarehouse.WH_UpdatedTime = BLLCom.GetCurStdDatetime(); #endregion #region 仓位 //添加的仓位 if (paramWarehouseBinList != null && paramWarehouseBinList.InsertList != null && paramWarehouseBinList.InsertList.Count > 0) { foreach (var loopDetailItem in paramWarehouseBinList.InsertList) { loopDetailItem.WHB_WH_ID = argsWarehouse.WH_ID ?? argsWarehouse.WHERE_WH_ID; loopDetailItem.WHB_CreatedBy = LoginInfoDAX.UserName; loopDetailItem.WHB_CreatedTime = BLLCom.GetCurStdDatetime(); loopDetailItem.WHB_UpdatedBy = LoginInfoDAX.UserName; loopDetailItem.WHB_UpdatedTime = BLLCom.GetCurStdDatetime(); } } #endregion #endregion #region 带事务的保存 try { DBManager.BeginTransaction(DBCONFIG.Coeus); #region 保存仓库 var saveWarehouseResult = _bll.Save(argsWarehouse, argsWarehouse.WH_ID); if (!saveWarehouseResult) { DBManager.RollBackTransaction(DBCONFIG.Coeus); ResultMsg = MsgHelp.GetMsg(MsgCode.E_0010, new object[] { SystemActionEnum.Name.SAVE + SystemTableEnums.Name.PIS_Warehouse }); return(false); } #endregion #region 保存仓位 var saveWarehouseBinResult = _bll.UnitySave(paramWarehouseBinList); if (!saveWarehouseBinResult) { DBManager.RollBackTransaction(DBCONFIG.Coeus); ResultMsg = MsgHelp.GetMsg(MsgCode.E_0010, new object[] { SystemActionEnum.Name.SAVE + SystemTableEnums.Name.PIS_WarehouseBin }); return(false); } #endregion DBManager.CommitTransaction(DBCONFIG.Coeus); } catch (Exception ex) { DBManager.RollBackTransaction(DBCONFIG.Coeus); //保存[仓库]信息发生异常 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); } //将最新数据回写给DetailDS CopyModel(argsWarehouse, paramHead); #endregion #region 刷新缓存 //刷新仓库缓存 var resultWarehouseList = CacheDAX.Get(CacheDAX.ConfigDataKey.Warehouse) as List <MDLPIS_Warehouse>; List <MDLPIS_Warehouse> newWarehouseList = new List <MDLPIS_Warehouse>(); if (resultWarehouseList != null) { newWarehouseList = resultWarehouseList; if (resultWarehouseList.All(x => x.WH_ID != argsWarehouse.WH_ID && x.WH_Name != argsWarehouse.WH_Name)) { newWarehouseList.Add(argsWarehouse); CacheDAX.Add(CacheDAX.ConfigDataKey.Warehouse, newWarehouseList, true); } } else { newWarehouseList.Add(argsWarehouse); CacheDAX.Add(CacheDAX.ConfigDataKey.Warehouse, newWarehouseList, true); } //刷新仓位缓存 if (paramWarehouseBinList == null) { return(true); } var resultWarehouseBinList = CacheDAX.Get(CacheDAX.ConfigDataKey.WarehouseBin) as List <MDLPIS_WarehouseBin>; List <MDLPIS_WarehouseBin> newWarehouseBinList = new List <MDLPIS_WarehouseBin>(); if (resultWarehouseBinList != null) { newWarehouseBinList = resultWarehouseBinList; if (paramWarehouseBinList.InsertList != null && paramWarehouseBinList.InsertList.Count > 0) { foreach (var loopInsertBin in paramWarehouseBinList.InsertList) { if (resultWarehouseBinList.All(x => x.WHB_ID != loopInsertBin.WHB_ID && x.WHB_Name != loopInsertBin.WHB_Name)) { var tempWarehouseBin = new MDLPIS_WarehouseBin(); _bll.CopyModel(loopInsertBin, tempWarehouseBin); newWarehouseBinList.Add(tempWarehouseBin); CacheDAX.Add(CacheDAX.ConfigDataKey.WarehouseBin, newWarehouseBinList, true); } } } if (paramWarehouseBinList.DeleteList != null && paramWarehouseBinList.DeleteList.Count > 0) { //待移除的仓位 List <MDLPIS_WarehouseBin> removeWarehouseBinList = new List <MDLPIS_WarehouseBin>(); foreach (var loopWarehouseBin in newWarehouseBinList) { var deleteWarehouseBin = paramWarehouseBinList.DeleteList.FirstOrDefault(x => x.WHB_ID == loopWarehouseBin.WHB_ID); if (deleteWarehouseBin != null) { removeWarehouseBinList.Add(loopWarehouseBin); } } foreach (var loopWarehouseBin in removeWarehouseBinList) { newWarehouseBinList.Remove(loopWarehouseBin); } } } else { var tempWarehouseBinList = new List <MDLPIS_WarehouseBin>(); _bll.CopyModelList(paramWarehouseBinList.InsertList, tempWarehouseBinList); newWarehouseBinList.AddRange(tempWarehouseBinList); CacheDAX.Add(CacheDAX.ConfigDataKey.WarehouseBin, newWarehouseBinList, true); } #endregion return(true); }
///// <summary> ///// 初始化用户操作习惯 ///// </summary> //public static void InitUserPractice(string paramUserID) //{ // //记录日志 // LogHelper.WriteBussLog(BussID, LoginInfoDAX.UserName, "CacheDAX.InitializeUserPractice", "【Start】", string.Empty, null); // string tableName = LocalConfigFileConst.TableName.SM_ListStyle; // string localXmlFilePath = LocalConfigFileConst.ConfigFilePath.SM_ListStyle.Replace(SysConst.PH_USERID, paramUserID); // var serverTableTimeStamp = SystemConfigInfo.DBTimeStampList.Find(table => table.TableName.Equals(tableName)); // var localTableTimeStamp = LocalConfigInfo.DBTimeStampList.Find(table => table.TableName.Equals(tableName)); // var resultList = new ObservableCollection<MDLSM_ListStyle>(); // if (!File.Exists(localXmlFilePath) // || localTableTimeStamp == null // || serverTableTimeStamp == null // || localTableTimeStamp.LastUpdatedTime < serverTableTimeStamp.LastUpdatedTime // ) // { // //创建数据CRUD对象 // CRUD crud = new CRUD(DBCONFIG.Coeus); // MDLSM_ListStyle argsCondition = new MDLSM_ListStyle // { // LS_UserID = LoginInfoDAX.UserID, // LS_IsValid = true // }; // //查询系统所有枚举数据 // crud.QueryForList(argsCondition, resultList); // XmlFileUtility.SerializeToXmlFile(localXmlFilePath, typeof(ObservableCollection<MDLSM_ListStyle>), resultList); // if (localTableTimeStamp == null) // { // if (serverTableTimeStamp != null) // { // localTableTimeStamp = new DBTableTimeStampUIModel { TableName = tableName, LastUpdatedTime = serverTableTimeStamp.LastUpdatedTime }; // LocalConfigInfo.DBTimeStampList.Add(localTableTimeStamp); // } // } // else // { // if (serverTableTimeStamp != null) // { // localTableTimeStamp.LastUpdatedTime = serverTableTimeStamp.LastUpdatedTime; // } // } // } // else if (File.Exists(localXmlFilePath)) // { // resultList = XmlFileUtility.DeserializeXmlFileToObj(localXmlFilePath, typeof(ObservableCollection<MDLSM_ListStyle>)) as ObservableCollection<MDLSM_ListStyle>; // } // //将查询结果数据保存到缓存中 // if (resultList != null) // { // foreach (MDLSM_ListStyle listStyle in resultList) // { // StringBuilder strKey = new StringBuilder(); // if (!string.IsNullOrEmpty(listStyle.LS_ClassFullName)) // { // strKey.Append(CacheType.ET1001 + SysConst.ULINE + listStyle.LS_ClassFullName); // } // if (!string.IsNullOrEmpty(listStyle.LS_ListControlName)) // { // strKey.Append(SysConst.ULINE + listStyle.LS_ListControlName); // } // Add(strKey.ToString(), listStyle.LS_State, true); // } // } // //记录日志 // LogHelper.WriteBussLog(BussID, LoginInfoDAX.UserName, "CacheDAX.InitializeUserPractice", "【End】", string.Empty, null); //} /// <summary> /// 初始化汽车品牌车系信息 /// </summary> public static void InitVehicleBrandInspireList() { //记录日志 LogHelper.WriteBussLog(BussID, LoginInfoDAX.UserName, "CacheDAX.InitializeCarBrandInfo", "【Start】", string.Empty, null); string tableName = LocalConfigFileConst.TableName.SCON_VehicleBrandInspireSumma; string localXmlFilePath = LocalConfigFileConst.ConfigFilePath.OtherTablePath.Replace(SysConst.PH_TABLENAME, tableName); var serverTableTimeStamp = SystemConfigInfo.DBTimeStampList.Find(table => table.TableName.Equals(tableName)); var localTableTimeStamp = LocalConfigInfo.DBTimeStampList.Find(table => table.TableName.Equals(tableName)); var resultList = new ObservableCollection <MDLBS_VehicleBrandInspireSumma>(); if (!File.Exists(localXmlFilePath) || localTableTimeStamp == null || serverTableTimeStamp == null || localTableTimeStamp.LastUpdatedTime < serverTableTimeStamp.LastUpdatedTime ) { //创建数据CRUD对象 CRUD crud = new CRUD(DBCONFIG.Coeus); var tempResultList = new List <MDLBS_VehicleBrandInspireSumma>(); var argsCondition = new MDLBS_VehicleBrandInspireSumma { VBIS_IsValid = true }; crud.QueryForList(argsCondition, tempResultList); foreach (var sortedItem in tempResultList.OrderBy(x => x.VBIS_Brand).ThenBy(x => x.VBIS_Inspire).ToList()) { var newItem = new MDLBS_VehicleBrandInspireSumma(); _baseDax.CopyModel(sortedItem, newItem); resultList.Add(newItem); } XmlFileUtility.SerializeToXmlFile(localXmlFilePath, typeof(ObservableCollection <MDLBS_VehicleBrandInspireSumma>), resultList); if (localTableTimeStamp == null) { if (serverTableTimeStamp != null) { localTableTimeStamp = new DBTableTimeStampUIModel { TableName = tableName, LastUpdatedTime = serverTableTimeStamp.LastUpdatedTime }; LocalConfigInfo.DBTimeStampList.Add(localTableTimeStamp); } } else { if (serverTableTimeStamp != null) { localTableTimeStamp.LastUpdatedTime = serverTableTimeStamp.LastUpdatedTime; } } } else if (File.Exists(localXmlFilePath)) { resultList = XmlFileUtility.DeserializeXmlFileToObj(localXmlFilePath, typeof(ObservableCollection <MDLBS_VehicleBrandInspireSumma>)) as ObservableCollection <MDLBS_VehicleBrandInspireSumma>; } if (resultList != null) { var brandList = resultList.GroupBy(p => new { p.VBIS_Brand, p.VBIS_BrandSpellCode }) .Select(g => g.First()).OrderBy(x => x.VBIS_Brand).ToList(); var brandObsCol = new ObservableCollection <MDLBS_VehicleBrandInspireSumma>(); foreach (MDLBS_VehicleBrandInspireSumma brandInspire in brandList) { MDLBS_VehicleBrandInspireSumma newBrand = new MDLBS_VehicleBrandInspireSumma { VBIS_Brand = brandInspire.VBIS_Brand, VBIS_BrandSpellCode = brandInspire.VBIS_BrandSpellCode }; brandObsCol.Add(newBrand); } HttpRuntime.Cache.Insert(ConfigDataKey.VehicleBrand, brandObsCol); var inspireList = resultList.GroupBy(p => new { p.VBIS_Brand, p.VBIS_Inspire, p.VBIS_InspireSpellCode }) .Select(g => g.First()).OrderBy(x => x.VBIS_Brand).ThenBy(x => x.VBIS_Inspire).ToList(); var inspireObsCol = new ObservableCollection <MDLBS_VehicleBrandInspireSumma>(); foreach (MDLBS_VehicleBrandInspireSumma brandInspire in inspireList) { MDLBS_VehicleBrandInspireSumma newInspire = new MDLBS_VehicleBrandInspireSumma { VBIS_ID = brandInspire.VBIS_ID, VBIS_Brand = brandInspire.VBIS_Brand, VBIS_Inspire = brandInspire.VBIS_Inspire, VBIS_InspireSpellCode = brandInspire.VBIS_InspireSpellCode, VBIS_Model = brandInspire.VBIS_Model }; inspireObsCol.Add(newInspire); } HttpRuntime.Cache.Insert(ConfigDataKey.VehicleBrandInspire, inspireObsCol); } //记录日志 LogHelper.WriteBussLog(BussID, LoginInfoDAX.UserName, "CacheDAX.InitializeCarBrandInfo", "【End】", string.Empty, null); }
/// <summary> /// 保存 /// </summary> /// <param name="paramHead">UIModel</param> /// <param name="paramDetailList">销售订单明细列表</param> /// <returns></returns> public bool SaveDetailDs(SalesReturnOrderManagerUIModel paramHead, SkyCarBindingList <SalesOrderDetailUIModel, MDLSD_SalesOrderDetail> paramDetailList) { var funcName = "SaveDetailDS"; LogHelper.WriteBussLogStart(BussID, LoginInfoDAX.UserName, funcName, "", "", null); //服务端检查 if (!ServerCheck(paramHead)) { LogHelper.WriteBussLogEndNG(BussID, LoginInfoDAX.UserName, funcName, ResultMsg, "", null); return(false); } #region 准备数据 //待更新的[配件档案]列表 List <MDLBS_AutoPartsArchive> updateAutoPartsArchiveList = new List <MDLBS_AutoPartsArchive>(); #region 单头 //将UIModel转为TBModel var argsHead = paramHead.ToTBModelForSaveAndDelete <MDLSD_SalesOrder>(); //判断主键是否被赋值 if (string.IsNullOrEmpty(paramHead.SO_ID)) { argsHead.SO_ID = Guid.NewGuid().ToString(); //单号 argsHead.SO_No = BLLCom.GetCoeusDocumentNo(DocumentTypeEnums.Code.SO); argsHead.SO_CreatedBy = LoginInfoDAX.UserName; argsHead.SO_CreatedTime = BLLCom.GetCurStdDatetime(); } argsHead.SO_UpdatedBy = LoginInfoDAX.UserName; argsHead.SO_UpdatedTime = BLLCom.GetCurStdDatetime(); #endregion #region 明细 //添加的明细 if (paramDetailList != null && paramDetailList.InsertList != null && paramDetailList.InsertList.Count > 0) { foreach (var loopSalesOrderDetail in paramDetailList.InsertList) { //赋值销售订单ID loopSalesOrderDetail.SOD_SO_ID = argsHead.SO_ID ?? argsHead.WHERE_SO_ID; //如果[计价基准可改]为true if (loopSalesOrderDetail.SOD_SalePriceRateIsChangeable ?? false) { //回写配件档案[条码和名称唯一] //待更新的配件档案 MDLBS_AutoPartsArchive updateAutoPartsArchive = new MDLBS_AutoPartsArchive(); _bll.QueryForObject <MDLBS_AutoPartsArchive, MDLBS_AutoPartsArchive>(new MDLBS_AutoPartsArchive { WHERE_APA_IsValid = true, WHERE_APA_Barcode = loopSalesOrderDetail.SOD_Barcode, WHERE_APA_Name = loopSalesOrderDetail.SOD_Name }, updateAutoPartsArchive); if (!string.IsNullOrEmpty(updateAutoPartsArchive.APA_ID)) { updateAutoPartsArchive.WHERE_APA_ID = updateAutoPartsArchive.APA_ID; updateAutoPartsArchive.WHERE_APA_VersionNo = updateAutoPartsArchive.APA_VersionNo; updateAutoPartsArchive.APA_VersionNo++; updateAutoPartsArchive.APA_SalePriceRate = loopSalesOrderDetail.SOD_SalePriceRate; updateAutoPartsArchive.APA_UpdatedBy = LoginInfoDAX.UserName; updateAutoPartsArchive.APA_UpdatedTime = BLLCom.GetCurStdDatetime(); updateAutoPartsArchiveList.Add(updateAutoPartsArchive); } } } } #endregion #endregion #region 带事务的保存 try { DBManager.BeginTransaction(DBCONFIG.Coeus); #region 保存单头 //执行保存 if (!_bll.Save(argsHead, argsHead.SO_ID)) { DBManager.RollBackTransaction(DBCONFIG.Coeus); ResultMsg = MsgHelp.GetMsg(MsgCode.E_0010, new object[] { SystemActionEnum.Name.SAVE + SystemTableEnums.Name.SD_SalesOrder }); LogHelper.WriteBussLogEndNG(BussID, LoginInfoDAX.UserName, funcName, ResultMsg, "", null); return(false); } #endregion #region 保存明细 if (paramDetailList != null) { //执行保存 bool saveDetailResult = _bll.UnitySave(paramDetailList); if (!saveDetailResult) { DBManager.RollBackTransaction(DBCONFIG.Coeus); ResultMsg = MsgHelp.GetMsg(MsgCode.E_0010, new object[] { SystemActionEnum.Name.SAVE + SystemTableEnums.Name.SD_SalesOrderDetail }); LogHelper.WriteBussLogEndNG(BussID, LoginInfoDAX.UserName, funcName, ResultMsg, "", null); return(false); } } #endregion #region 更新[配件档案]列表 foreach (var loopAutoPartsArchive in updateAutoPartsArchiveList) { bool updateAutoPartsArchiveResult = _bll.Update(loopAutoPartsArchive); if (!updateAutoPartsArchiveResult) { 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 DBManager.CommitTransaction(DBCONFIG.Coeus); } catch (Exception ex) { DBManager.RollBackTransaction(DBCONFIG.Coeus); 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 _bll.CopyModel(argsHead, paramHead); //更新明细版本号 if (paramDetailList != null) { if (paramDetailList.InsertList != null) { foreach (var loopInsertDetail in paramDetailList.InsertList) { //新增时版本号为1 loopInsertDetail.SOD_VersionNo = 1; } } foreach (var loopUpdateDetail in paramDetailList.UpdateList) { //更新时版本号加1 loopUpdateDetail.SOD_VersionNo = loopUpdateDetail.SOD_VersionNo + 1; } } return(true); }
/// <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); }