/// <summary> /// 同步共享库存到平台 /// </summary> /// <returns></returns> private bool SynchronizeShareInventory(List <AutoPartsShareInventoryManagerUIModel> paramShareInventoryList) { var funcName = "SynchronizeShareInventory"; LogHelper.WriteBussLogStart(Trans.IS, LoginInfoDAX.UserName, funcName, "", "", null); if (paramShareInventoryList.Count > 0) { var jsonShareInventoryList = (JValue)JsonConvert.SerializeObject(paramShareInventoryList); string argsPostData = string.Format(ApiParameter.BF0040, ConfigurationManager.AppSettings[AppSettingKey.MCT_CODE], LoginInfoDAX.OrgCode, jsonShareInventoryList); string strApiData = APIDataHelper.GetAPIData(ApiUrl.BF0040Url, argsPostData); //本地调试: //string strApiData = APIDataHelper.GetAPIData("http://localhost:61860//API/BF0040", argsPostData); var jsonResult = (JObject)JsonConvert.DeserializeObject(strApiData); if (jsonResult == null || jsonResult[SysConst.EN_RESULTCODE].ToString() != SysConst.EN_I0001) { var strErrorMessage = jsonResult == null ? "" : jsonResult[SysConst.EN_RESULTCODE].ToString(); LogHelper.WriteBussLogEndOK(Trans.IS, LoginInfoDAX.UserName, funcName, strErrorMessage, "", null); return(false); } } return(true); }
/// <summary> /// 验证激活码 /// </summary> /// <param name="activateCode"></param> /// <returns></returns> private void ValActivateSoftCode(string activateCode) { #region 激活 string argsPostData = string.Format(ApiParameter.BF0001, HttpUtility.UrlEncode(activateCode), SysConst.ProductCode); string strApiData = APIDataHelper.GetAPIData(ApiUrl.BF0001Url, argsPostData); var jsonResult = (JObject)JsonConvert.DeserializeObject(strApiData); if (jsonResult["ResultCode"].ToString().Equals("I0001")) { #region 更新appSettings //更新appSettings ChangeAppConfiguration(jsonResult, activateCode); //刷新appSettings ConfigurationManager.RefreshSection("appSettings"); #endregion try { var boolTemp = false; DBManager.DBInit(DBCONFIG.Coeus); DBManager.BeginTransaction(DBCONFIG.Coeus); #region 步组织 var argsListOrganization = jsonResult["ListOrganization"]; if (argsListOrganization != null) { var plateformOrgList = JsonConvert.DeserializeObject <List <MDLSM_Organization> >(argsListOrganization.ToString()); var localOrgList = new List <MDLSM_Organization>(); bll.QuerryForList <MDLSM_Organization>(new MDLSM_Organization(), localOrgList); #region if (localOrgList.Count > 0) { foreach (var model in localOrgList) { model.Org_IsValid = false; model.WHERE_Org_ID = model.Org_ID; boolTemp = bll.Save <MDLSM_Organization>(model); if (!boolTemp) { MessageBoxs.Show(Trans.COM, this.ToString(), "商户激活失败!\r\n更新组织状态失败!", "消息", MessageBoxButtons.OK, MessageBoxIcon.Error); DBManager.RollBackTransaction(DBCONFIG.Coeus); return; } } } foreach (var org in plateformOrgList) { var templocalOrgList = localOrgList.Where(p => p.Org_Code == org.Org_Code).ToList(); if (templocalOrgList.Count > 0) { var argsOrganizationorg = templocalOrgList[0]; argsOrganizationorg.WHERE_Org_ID = templocalOrgList[0].Org_ID; argsOrganizationorg.Org_Code = org.Org_Code; argsOrganizationorg.Org_FullName = org.Org_FullName; argsOrganizationorg.Org_ShortName = org.Org_ShortName; argsOrganizationorg.Org_Contacter = org.Org_Contacter; argsOrganizationorg.Org_TEL = org.Org_TEL; argsOrganizationorg.Org_PhoneNo = org.Org_PhoneNo; argsOrganizationorg.Org_Prov_Code = org.Org_Prov_Code; argsOrganizationorg.Org_City_Code = org.Org_City_Code; argsOrganizationorg.Org_Dist_Code = org.Org_Dist_Code; argsOrganizationorg.Org_Addr = org.Org_Addr; argsOrganizationorg.Org_Remark = org.Org_Remark; argsOrganizationorg.Org_PlatformCode = jsonResult["MCT_Code"].ToString(); argsOrganizationorg.Org_IsValid = true; boolTemp = bll.Save <MDLSM_Organization>(argsOrganizationorg); if (!boolTemp) { MessageBoxs.Show(Trans.COM, this.ToString(), "商户激活失败!\r\n更新组织内容失败!", "消息", MessageBoxButtons.OK, MessageBoxIcon.Error); DBManager.RollBackTransaction(DBCONFIG.Coeus); return; } } else { var argsorg = new MDLSM_Organization { Org_Code = org.Org_Code, Org_FullName = org.Org_FullName, Org_ShortName = org.Org_ShortName, Org_Contacter = org.Org_Contacter, Org_TEL = org.Org_TEL, Org_PhoneNo = org.Org_PhoneNo, Org_Prov_Code = org.Org_Prov_Code, Org_City_Code = org.Org_City_Code, Org_Dist_Code = org.Org_Dist_Code, Org_Addr = org.Org_Addr, Org_Remark = org.Org_Remark, Org_PlatformCode = jsonResult["MCT_Code"].ToString(), Org_IsValid = true }; boolTemp = bll.Save <MDLSM_Organization>(argsorg); if (!boolTemp) { MessageBoxs.Show(Trans.COM, this.ToString(), "商户激活失败!\r\n新增组织失败!", "消息", MessageBoxButtons.OK, MessageBoxIcon.Error); DBManager.RollBackTransaction(DBCONFIG.Coeus); return; } } } #endregion } #endregion #region 更新参数表 var argsParameterQuery = new MDLSM_Parameter { Para_Code1 = "1001", Para_IsValid = true }; var parameterResult = new MDLSM_Parameter(); bll.QuerryForObject <MDLSM_Parameter, MDLSM_Parameter>(argsParameterQuery, parameterResult); parameterResult.Para_Code1 = "1001"; parameterResult.Para_Name1 = "商户编码"; parameterResult.Para_Value1 = jsonResult["MCT_Code"] == null ? "" : jsonResult["MCT_Code"].ToString(); ; boolTemp = bll.Save <MDLSM_Parameter>(parameterResult); if (!boolTemp) { MessageBoxs.Show(Trans.COM, this.ToString(), "商户激活失败!\r\n更新系统参数(商户编码)失败!", "消息", MessageBoxButtons.OK, MessageBoxIcon.Error); DBManager.RollBackTransaction(DBCONFIG.Coeus); return; } #endregion DBManager.CommitTransaction(DBCONFIG.Coeus); } catch (Exception ex) { MessageBoxs.Show(Trans.COM, this.ToString(), "商户激活失败!\r\n" + ex.Message, "消息", MessageBoxButtons.OK, MessageBoxIcon.Error); DBManager.RollBackTransaction(DBCONFIG.Coeus); return; } } else { var strErrorMessage = jsonResult["ResultMsg"] == null ? "" : jsonResult["ResultMsg"].ToString(); MessageBoxs.Show(Trans.COM, this.ToString(), "商户激活失败!\r\n" + strErrorMessage, "消息", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } #endregion MessageBoxs.Show(Trans.COM, this.ToString(), "恭喜!您已成功激活本系统!\r\n", "消息", MessageBoxButtons.OK, MessageBoxIcon.Information); var loginWindow = new FrmLogin(); loginWindow.Show(); this.Hide(); }
/// <summary> /// 保存 /// </summary> /// <param name="paramModel">UIModel</param> /// <returns></returns> public bool SaveDetailDS(CodeTableManagerUIModel paramModel) { //服务端检查 if (!ServerCheck(paramModel)) { return(false); } #region 保存码表 //将UIModel转为TBModel var argsCodeTable = CopyModel <MDLSM_CodeTable>(paramModel); argsCodeTable.CT_Value = argsCodeTable.CT_Name; argsCodeTable.CT_Desc = argsCodeTable.CT_Name; #region 新增 //判断主键是否被赋值 if (string.IsNullOrEmpty(argsCodeTable.CT_ID)) { #region 步配件级别 if (argsCodeTable.CT_Type == CodeTypeEnum.Code.AUTOPARTSLEVEL) { if (!string.IsNullOrEmpty(argsCodeTable.CT_Name)) { string argsPostData = string.Format(ApiParameter.BF0014, ConfigurationManager.AppSettings[AppSettingKey.MCT_CODE], argsCodeTable.CT_Name); string strApiData = APIDataHelper.GetAPIData(ApiUrl.BF0014Url, argsPostData); var jsonResult = (JObject)JsonConvert.DeserializeObject(strApiData); if (jsonResult == null || (jsonResult[SysConst.EN_RESULTCODE] != null && !jsonResult[SysConst.EN_RESULTCODE].ToString().Equals(SysConst.EN_I0001))) { ResultMsg = MsgHelp.GetMsg(MsgCode.E_0010, new object[] { SystemActionEnum.Name.SYNCHRONIZE + SystemTableColumnEnums.BS_AutoPartsArchive.Name.APA_Level }); } } } #endregion //生成新ID argsCodeTable.CT_ID = Guid.NewGuid().ToString(); argsCodeTable.CT_CreatedBy = LoginInfoDAX.UserName; argsCodeTable.CT_CreatedTime = BLLCom.GetCurStdDatetime(); argsCodeTable.CT_UpdatedBy = LoginInfoDAX.UserName; argsCodeTable.CT_UpdatedTime = BLLCom.GetCurStdDatetime(); //主键未被赋值,则执行新增 if (!_bll.Insert(argsCodeTable)) { ResultMsg = MsgHelp.GetMsg(MsgCode.E_0010, new object[] { SystemActionEnum.Name.NEW + SystemTableEnums.Name.SM_CodeTable }); return(false); } } #endregion #region 更新 else { //主键被赋值,则需要更新,更新需要设定更新条件 argsCodeTable.WHERE_CT_ID = argsCodeTable.CT_ID; argsCodeTable.WHERE_CT_VersionNo = argsCodeTable.CT_VersionNo; argsCodeTable.CT_VersionNo++; argsCodeTable.CT_UpdatedBy = LoginInfoDAX.UserName; argsCodeTable.CT_UpdatedTime = BLLCom.GetCurStdDatetime(); if (!_bll.Update(argsCodeTable)) { ResultMsg = MsgHelp.GetMsg(MsgCode.E_0010, new object[] { MsgParam.UPDATE + SystemTableEnums.Name.SM_CodeTable }); return(false); } } #endregion //将最新数据回写给DetailDS CopyModel(argsCodeTable, paramModel); #endregion 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); }
/// <summary> /// 保存数据 /// </summary> /// <param name="paramModel">待保存的车辆品牌车系</param> /// <returns></returns> public bool SaveDetailDS(VehicleBrandInspireSummaManagerUIModel paramModel) { //服务端检查 if (!ServerCheck(paramModel)) { return(false); } //将UIModel转为TBModel var argsVehicleBrandInspireSumma = CopyModel <MDLBS_VehicleBrandInspireSumma>(paramModel); try { DBManager.BeginTransaction(DBCONFIG.Coeus); //判断主键是否被赋值 if (string.IsNullOrEmpty(argsVehicleBrandInspireSumma.VBIS_ID)) { #region 新增 if (argsVehicleBrandInspireSumma.VBIS_IsValid == true) { #region 步平台数据 //获取车辆品牌车系信息 string argsPostData = string.Format(ApiParameter.BF0020, argsVehicleBrandInspireSumma.VBIS_Brand, argsVehicleBrandInspireSumma.VBIS_Inspire, ConfigurationManager.AppSettings[AppSettingKey.MCT_CODE]); string strApiData = APIDataHelper.GetAPIData(ApiUrl.BF0020Url, argsPostData); var jsonResult = (JObject)JsonConvert.DeserializeObject(strApiData); if (jsonResult != null && jsonResult[SysConst.EN_RESULTCODE] != null && jsonResult[SysConst.EN_RESULTCODE].ToString().Equals(SysConst.EN_I0001)) { paramModel.VBIS_Brand = jsonResult[SystemTableColumnEnums.BS_VehicleBrandInspireSumma.Code.VBIS_Brand] == null ? "" : jsonResult[SystemTableColumnEnums.BS_VehicleBrandInspireSumma.Code.VBIS_Brand].ToString(); paramModel.VBIS_Inspire = jsonResult[SystemTableColumnEnums.BS_VehicleBrandInspireSumma.Code.VBIS_Inspire] == null ? "" : jsonResult[SystemTableColumnEnums.BS_VehicleBrandInspireSumma.Code.VBIS_Inspire].ToString(); paramModel.VBIS_Model = jsonResult[SystemTableColumnEnums.BS_VehicleBrandInspireSumma.Code.VBIS_Model] == null ? "" : jsonResult[SystemTableColumnEnums.BS_VehicleBrandInspireSumma.Code.VBIS_Model].ToString(); paramModel.VBIS_BrandSpellCode = jsonResult[SystemTableColumnEnums.BS_VehicleBrandInspireSumma.Code.VBIS_BrandSpellCode] == null ? "" : jsonResult[SystemTableColumnEnums.BS_VehicleBrandInspireSumma.Code.VBIS_BrandSpellCode].ToString(); paramModel.VBIS_InspireSpellCode = jsonResult[SystemTableColumnEnums.BS_VehicleBrandInspireSumma.Code.VBIS_InspireSpellCode] == null ? "" : jsonResult[SystemTableColumnEnums.BS_VehicleBrandInspireSumma.Code.VBIS_InspireSpellCode].ToString(); paramModel.VBIS_IsValid = true; paramModel.VBIS_CreatedBy = LoginInfoDAX.UserName; paramModel.VBIS_UpdatedBy = LoginInfoDAX.UserName; } else { var strErrorMessage = jsonResult == null ? "" : jsonResult["ResultMsg"].ToString(); LogHelper.WriteBussLogEndNG(BussID, LoginInfoDAX.UserName, MethodBase.GetCurrentMethod().ToString(), strErrorMessage, "", null); } #endregion } //生成新ID argsVehicleBrandInspireSumma.VBIS_ID = Guid.NewGuid().ToString(); argsVehicleBrandInspireSumma.VBIS_CreatedBy = LoginInfoDAX.UserName; argsVehicleBrandInspireSumma.VBIS_CreatedTime = BLLCom.GetCurStdDatetime(); argsVehicleBrandInspireSumma.VBIS_UpdatedBy = LoginInfoDAX.UserName; argsVehicleBrandInspireSumma.VBIS_UpdatedTime = BLLCom.GetCurStdDatetime(); //主键未被赋值,则执行新增 if (!_bll.Insert(argsVehicleBrandInspireSumma)) { DBManager.RollBackTransaction(DBCONFIG.Coeus); ResultMsg = MsgHelp.GetMsg(MsgCode.E_0010, new object[] { SystemActionEnum.Name.NEW + SystemTableEnums.Name.BS_VehicleBrandInspireSumma }); return(false); } #endregion } else { #region 更新 //主键被赋值,则需要更新,更新需要设定更新条件 argsVehicleBrandInspireSumma.WHERE_VBIS_ID = argsVehicleBrandInspireSumma.VBIS_ID; argsVehicleBrandInspireSumma.WHERE_VBIS_VersionNo = argsVehicleBrandInspireSumma.VBIS_VersionNo; argsVehicleBrandInspireSumma.VBIS_VersionNo++; argsVehicleBrandInspireSumma.VBIS_UpdatedBy = LoginInfoDAX.UserName; argsVehicleBrandInspireSumma.VBIS_UpdatedTime = BLLCom.GetCurStdDatetime(); if (!_bll.Update(argsVehicleBrandInspireSumma)) { DBManager.RollBackTransaction(DBCONFIG.Coeus); ResultMsg = MsgHelp.GetMsg(MsgCode.E_0010, new object[] { MsgParam.UPDATE + SystemTableEnums.Name.BS_VehicleBrandInspireSumma }); 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.WriteErrorLog(BussID, MethodBase.GetCurrentMethod().ToString(), ex.Message + SysConst.ENTER + ex.StackTrace, null, ex); LogHelper.WriteBussLogEndNG(BussID, LoginInfoDAX.UserName, MethodBase.GetCurrentMethod().ToString(), ex.Message, "", null); return(false); } //将最新数据回写给DetailDS CopyModel(argsVehicleBrandInspireSumma, paramModel); //刷新车辆品牌缓存 var resultVehicleBrandList = CacheDAX.Get(CacheDAX.ConfigDataKey.VehicleBrand) as List <MDLBS_VehicleBrandInspireSumma>; List <MDLBS_VehicleBrandInspireSumma> newVehicleBrandList = new List <MDLBS_VehicleBrandInspireSumma>(); if (resultVehicleBrandList != null) { newVehicleBrandList = resultVehicleBrandList; if (resultVehicleBrandList.All(x => x.VBIS_Brand != argsVehicleBrandInspireSumma.VBIS_Brand)) { newVehicleBrandList.Insert(0, argsVehicleBrandInspireSumma); newVehicleBrandList = newVehicleBrandList.GroupBy(p => new { p.VBIS_Brand, p.VBIS_BrandSpellCode }) .Select(g => g.First()).OrderBy(x => x.VBIS_Brand).ToList(); CacheDAX.Add(CacheDAX.ConfigDataKey.VehicleBrand, newVehicleBrandList, true); } } else { newVehicleBrandList.Add(argsVehicleBrandInspireSumma); CacheDAX.Add(CacheDAX.ConfigDataKey.VehicleBrand, newVehicleBrandList, true); } //刷新车辆车系缓存 var resultVehicleInspireList = CacheDAX.Get(CacheDAX.ConfigDataKey.VehicleBrandInspire) as List <MDLBS_VehicleBrandInspireSumma>; List <MDLBS_VehicleBrandInspireSumma> newVehicleInspireList = new List <MDLBS_VehicleBrandInspireSumma>(); if (resultVehicleInspireList != null) { newVehicleInspireList = resultVehicleInspireList; if (resultVehicleInspireList.All(x => x.VBIS_Brand != argsVehicleBrandInspireSumma.VBIS_Brand)) { newVehicleInspireList.Insert(0, argsVehicleBrandInspireSumma); newVehicleInspireList = newVehicleInspireList.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(); CacheDAX.Add(CacheDAX.ConfigDataKey.VehicleBrandInspire, newVehicleInspireList, true); } } else { newVehicleInspireList.Add(argsVehicleBrandInspireSumma); CacheDAX.Add(CacheDAX.ConfigDataKey.VehicleBrandInspire, newVehicleInspireList, true); } return(true); }
/// <summary> /// 导入配件档案 /// </summary> /// <param name="paramImportAutoPartsArchiveList">待导入的配件档案列表</param> /// <returns></returns> public bool ImportAutoPartsArchive(List <ImportAutoPartsArchiveUIModel> paramImportAutoPartsArchiveList) { var funcName = "ImportAutoPartsArchive"; LogHelper.WriteBussLogStart(Trans.BS, LoginInfoDAX.UserName, funcName, "", "", null); if (paramImportAutoPartsArchiveList == null || paramImportAutoPartsArchiveList.Count == 0) { //待导入的数据为空 ResultMsg = MsgHelp.GetMsg(MsgCode.E_0000, new object[] { "待导入的数据为空" }); return(true); } try { #region 通过平台接口导入并返回配件档案列表 var jsonAutoPartsPriceTypeList = (JValue)JsonConvert.SerializeObject(paramImportAutoPartsArchiveList); string argsPostData = string.Format(ApiParameter.BF0046, ConfigurationManager.AppSettings[AppSettingKey.MCT_CODE], jsonAutoPartsPriceTypeList); string strApiData = APIDataHelper.GetAPIData(ApiUrl.BF0046Url, argsPostData); //本地调试: //string strApiData = APIDataHelper.GetAPIData("http://*****:*****@ImportAutoPartsArchiveList", SqlDbType.Structured); cmd.Parameters[0].Value = importAutoPartsArchiveDataTable; cmd.Parameters.Add("@ResultCode", SqlDbType.VarChar, 50); cmd.Parameters[1].Direction = ParameterDirection.Output; cmd.ExecuteNonQuery(); sqlCon.Close(); string resultCode = cmd.Parameters[1].Value?.ToString(); if (resultCode == "导入失败") { ResultMsg = MsgHelp.GetMsg(MsgCode.E_0010, new object[] { SystemActionEnum.Name.IMPORT + SystemTableEnums.Name.BS_AutoPartsArchive }); return(false); } #endregion } catch (Exception ex) { ResultMsg = MsgHelp.GetMsg(MsgCode.E_0018, new object[] { SystemActionEnum.Name.IMPORT + SystemTableEnums.Name.BS_AutoPartsArchive, ex.Message }); return(false); } return(true); }
/// <summary> /// 从平台同步授权商户信息到本地数据库 /// </summary> public static bool SynchronizeSupMerchantAuthorityInfo() { var funcName = "SynchronizeSupMerchantAuthorityInfo"; LogHelper.WriteBussLogStart(Trans.SM, LoginInfoDAX.UserName, funcName, "", "", null); var argsMerchantPostData = string.Format(ApiParameter.BF0012, ConfigurationManager.AppSettings[AppSettingKey.MCT_CODE], HttpUtility.UrlEncode(ConfigurationManager.AppSettings[AppSettingKey.ACTIVATION_CODE]), SysConst.ProductCode); var strMerchantApiData = APIDataHelper.GetAPIData(ApiUrl.BF0012Url, argsMerchantPostData); var jsonMerchantResult = (JObject)JsonConvert.DeserializeObject(strMerchantApiData); if (jsonMerchantResult != null && jsonMerchantResult[SysConst.EN_RESULTCODE].ToString().Equals(SysConst.EN_I0001)) { //获取平台[汽配汽修商户授权]列表 var platformAROrgAuthorityList = jsonMerchantResult["AROrgSupMerchantAuthorityList"]; var platformMctAuthJson = (JArray)JsonConvert.DeserializeObject(platformAROrgAuthorityList.ToString()); //转存到临时List,便于后面使用 List <MDLSM_AROrgSupMerchantAuthority> tempPlatformAROrgAuthorityList = JsonConvert.DeserializeObject <List <MDLSM_AROrgSupMerchantAuthority> >(platformMctAuthJson.ToString()); #region 入到[汽配汽修商户授权]列表中 AROrgSupMerchantAuthorityDataSet.AROrgSupMerchantAuthorityDataTable supMerchantAuthorityDataTable = new AROrgSupMerchantAuthorityDataSet.AROrgSupMerchantAuthorityDataTable(); foreach (var loopAROrgAuthority in tempPlatformAROrgAuthorityList) { if (string.IsNullOrEmpty(loopAROrgAuthority.ASAH_ARMerchant_Code)) { continue; } AROrgSupMerchantAuthorityDataSet.AROrgSupMerchantAuthorityRow newAROrgAuthorityRow = supMerchantAuthorityDataTable.NewAROrgSupMerchantAuthorityRow(); newAROrgAuthorityRow.ASAH_ID = loopAROrgAuthority.ASAH_ID; newAROrgAuthorityRow.ASAH_ARMerchant_Code = loopAROrgAuthority.ASAH_ARMerchant_Code; newAROrgAuthorityRow.ASAH_ARMerchant_Name = loopAROrgAuthority.ASAH_ARMerchant_Name; newAROrgAuthorityRow.ASAH_AROrg_Code = loopAROrgAuthority.ASAH_AROrg_Code; newAROrgAuthorityRow.ASAH_AROrg_Name = loopAROrgAuthority.ASAH_AROrg_Name; newAROrgAuthorityRow.ASAH_AROrg_Contacter = loopAROrgAuthority.ASAH_AROrg_Contacter; newAROrgAuthorityRow.ASAH_AROrg_Phone = loopAROrgAuthority.ASAH_AROrg_Phone; newAROrgAuthorityRow.ASAH_Remark = loopAROrgAuthority.ASAH_Remark; if (loopAROrgAuthority.ASAH_IsValid != null) { newAROrgAuthorityRow.ASAH_IsValid = loopAROrgAuthority.ASAH_IsValid.Value; } newAROrgAuthorityRow.ASAH_CreatedBy = string.IsNullOrEmpty(loopAROrgAuthority.ASAH_CreatedBy) ? LoginInfoDAX.UserName : loopAROrgAuthority.ASAH_CreatedBy; newAROrgAuthorityRow.ASAH_CreatedTime = loopAROrgAuthority.ASAH_CreatedTime == null ? BLLCom.GetCurStdDatetime() : loopAROrgAuthority.ASAH_CreatedTime.Value; newAROrgAuthorityRow.ASAH_UpdatedBy = LoginInfoDAX.UserName; newAROrgAuthorityRow.ASAH_UpdatedTime = BLLCom.GetCurStdDatetime(); if (loopAROrgAuthority.ASAH_VersionNo != null) { newAROrgAuthorityRow.ASAH_VersionNo = loopAROrgAuthority.ASAH_VersionNo.Value; } supMerchantAuthorityDataTable.AddAROrgSupMerchantAuthorityRow(newAROrgAuthorityRow); } #endregion try { //打开数据库连接 using (SqlConnection sqlCon = new SqlConnection { ConnectionString = DBManager.GetConnectionString(DBCONFIG.Coeus) }) { //创建并初始化SqlCommand对象 SqlCommand cmdSupMerchant = new SqlCommand(); cmdSupMerchant.Connection = sqlCon; cmdSupMerchant.CommandText = "P_SM_BatchSyncAROrgSupMerchantAuthorityInfo"; cmdSupMerchant.CommandType = CommandType.StoredProcedure; cmdSupMerchant.Parameters.Add("@AROrgSupMerchantAuthorityList", SqlDbType.Structured); cmdSupMerchant.Parameters[0].Value = supMerchantAuthorityDataTable; sqlCon.Open(); cmdSupMerchant.ExecuteNonQuery(); } } catch (Exception ex) { LogHelper.WriteBussLogEndOK(Trans.SM, LoginInfoDAX.UserName, funcName, MsgHelp.GetMsg(MsgCode.E_0010, new object[] { SystemActionEnum.Name.SYNCHRONIZE + SystemTableEnums.Name.SM_AROrgSupMerchantAuthority }), "", null); return(false); } } else { ErrMsg = jsonMerchantResult == null ? "" : jsonMerchantResult["ResultMsg"].ToString(); LogHelper.WriteBussLogEndOK(Trans.SM, LoginInfoDAX.UserName, funcName, ErrMsg, "", null); return(false); } LogHelper.WriteBussLogEndOK(Trans.SM, LoginInfoDAX.UserName, funcName, "", "", null); return(true); }
/// <summary> /// 同步配件档案 /// </summary> /// <param name="paramModel">UIModel</param> /// <param name="paramSyncWithPlatform">是否同步平台</param> /// <returns></returns> public bool?SyncAutoPartsArchive(MaintainAutoPartsDetailUIModel paramModel, bool paramSyncWithPlatform) { try { //检查配件档案是否已存在 MDLBS_AutoPartsArchive curAutoPartsArchive = new MDLBS_AutoPartsArchive(); CopyModel(paramModel, curAutoPartsArchive); MDLBS_AutoPartsArchive resultAutoPartsArchive = AutoPartsComFunction.GetAutoPartsArchive(curAutoPartsArchive); if (!string.IsNullOrEmpty(resultAutoPartsArchive.APA_ID)) { paramModel.APA_Barcode = resultAutoPartsArchive.APA_Barcode; MDLBS_AutoPartsArchive updateAutoPartsArchive = new MDLBS_AutoPartsArchive(); updateAutoPartsArchive.WHERE_APA_ID = resultAutoPartsArchive.APA_ID; updateAutoPartsArchive.WHERE_APA_VersionNo = resultAutoPartsArchive.APA_VersionNo; updateAutoPartsArchive.APA_VehicleModelCode = paramModel.APA_VehicleModelCode; updateAutoPartsArchive.APA_ExchangeCode = paramModel.APA_ExchangeCode; updateAutoPartsArchive.APA_VersionNo = resultAutoPartsArchive.APA_VersionNo + 1; var updateArchiveResult = Save <MDLBS_AutoPartsArchive>(updateAutoPartsArchive); if (!updateArchiveResult) { ResultMsg = MsgHelp.GetMsg(MsgCode.E_0010, new object[] { SystemActionEnum.Name.SAVE + SystemTableEnums.Name.BS_AutoPartsArchive }); return(false); } return(null); } paramModel.APA_Barcode = null; //不同步平台 if (!paramSyncWithPlatform) { return(null); } #region 配件档案已存在,从平台获取配件档案 string argsPostData = string.Format(ApiParameter.BF0017, ConfigurationManager.AppSettings[AppSettingKey.MCT_CODE], SysConst.Merchant, paramModel.APA_Name, paramModel.APA_Brand, paramModel.APA_Specification, paramModel.APA_UOM, paramModel.APA_Level, paramModel.APA_VehicleBrand, paramModel.APA_VehicleInspire, paramModel.APA_VehicleCapacity, paramModel.APA_VehicleYearModel, paramModel.APA_VehicleGearboxTypeName, paramModel.APA_OEMNo, paramModel.APA_ThirdNo, paramModel.APA_Barcode, true); 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()); #endregion #region 新增配件档案 //待新增的配件档案 MDLBS_AutoPartsArchive insertAutoPartsArchive = new MDLBS_AutoPartsArchive(); 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); } insertAutoPartsArchive.APA_Name = jsonResult[SystemTableColumnEnums.BS_AutoPartsArchive.Code.APA_Name] == null ? null : jsonResult[SystemTableColumnEnums.BS_AutoPartsArchive.Code.APA_Name].ToString(); insertAutoPartsArchive.APA_OEMNo = jsonResult[SystemTableColumnEnums.BS_AutoPartsArchive.Code.APA_OEMNo] == null ? null : jsonResult[SystemTableColumnEnums.BS_AutoPartsArchive.Code.APA_OEMNo].ToString(); insertAutoPartsArchive.APA_ThirdNo = jsonResult[SystemTableColumnEnums.BS_AutoPartsArchive.Code.APA_ThirdNo] == null ? null : jsonResult[SystemTableColumnEnums.BS_AutoPartsArchive.Code.APA_ThirdNo].ToString(); insertAutoPartsArchive.APA_Brand = jsonResult[SystemTableColumnEnums.BS_AutoPartsArchive.Code.APA_Brand] == null ? null : jsonResult[SystemTableColumnEnums.BS_AutoPartsArchive.Code.APA_Brand].ToString(); insertAutoPartsArchive.APA_Specification = jsonResult[SystemTableColumnEnums.BS_AutoPartsArchive.Code.APA_Specification] == null ? null : jsonResult[SystemTableColumnEnums.BS_AutoPartsArchive.Code.APA_Specification].ToString(); insertAutoPartsArchive.APA_UOM = jsonResult[SystemTableColumnEnums.BS_AutoPartsArchive.Code.APA_UOM] == null ? null : jsonResult[SystemTableColumnEnums.BS_AutoPartsArchive.Code.APA_UOM].ToString(); insertAutoPartsArchive.APA_Level = jsonResult[SystemTableColumnEnums.BS_AutoPartsArchive.Code.APA_Level] == null ? null : jsonResult[SystemTableColumnEnums.BS_AutoPartsArchive.Code.APA_Level].ToString(); insertAutoPartsArchive.APA_VehicleBrand = jsonResult[SystemTableColumnEnums.BS_AutoPartsArchive.Code.APA_VehicleBrand] == null ? null : jsonResult[SystemTableColumnEnums.BS_AutoPartsArchive.Code.APA_VehicleBrand].ToString(); insertAutoPartsArchive.APA_VehicleInspire = jsonResult[SystemTableColumnEnums.BS_AutoPartsArchive.Code.APA_VehicleInspire] == null ? null : jsonResult[SystemTableColumnEnums.BS_AutoPartsArchive.Code.APA_VehicleInspire].ToString(); insertAutoPartsArchive.APA_VehicleCapacity = jsonResult[SystemTableColumnEnums.BS_AutoPartsArchive.Code.APA_VehicleCapacity] == null ? null : jsonResult[SystemTableColumnEnums.BS_AutoPartsArchive.Code.APA_VehicleCapacity].ToString(); insertAutoPartsArchive.APA_VehicleYearModel = jsonResult[SystemTableColumnEnums.BS_AutoPartsArchive.Code.APA_VehicleYearModel] == null ? null : jsonResult[SystemTableColumnEnums.BS_AutoPartsArchive.Code.APA_VehicleYearModel].ToString(); insertAutoPartsArchive.APA_IsValid = jsonResult[SystemTableColumnEnums.BS_AutoPartsArchive.Code.APA_IsValid] == null || Convert.ToBoolean(jsonResult[SystemTableColumnEnums.BS_AutoPartsArchive.Code.APA_IsValid]); insertAutoPartsArchive.APA_ID = null; insertAutoPartsArchive.APA_Barcode = barCode; insertAutoPartsArchive.APA_SUPP_ID = paramModel.APA_SUPP_ID; insertAutoPartsArchive.APA_WH_ID = paramModel.APA_WH_ID; insertAutoPartsArchive.APA_WHB_ID = paramModel.APA_WHB_ID; insertAutoPartsArchive.APA_Org_ID = LoginInfoDAX.OrgID; insertAutoPartsArchive.APA_CreatedBy = LoginInfoDAX.UserName; insertAutoPartsArchive.APA_CreatedTime = BLLCom.GetCurStdDatetime(); insertAutoPartsArchive.APA_UpdatedBy = LoginInfoDAX.UserName; insertAutoPartsArchive.APA_UpdatedTime = BLLCom.GetCurStdDatetime(); //变速类型 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) { insertAutoPartsArchive.APA_VehicleGearboxTypeName = resultVehicleGearboxTypeName.Trim().Substring(0, resultVehicleGearboxTypeName.Trim().Length - 1); } if (resultVehicleGearboxTypeCode.Trim().Length > 0) { insertAutoPartsArchive.APA_VehicleGearboxTypeCode = resultVehicleGearboxTypeCode.Trim().Substring(0, resultVehicleGearboxTypeCode.Trim().Length - 1); } } var insertArchiveResult = Save <MDLBS_AutoPartsArchive>(insertAutoPartsArchive); if (!insertArchiveResult) { ResultMsg = MsgHelp.GetMsg(MsgCode.E_0010, new object[] { SystemActionEnum.Name.NEW + SystemTableEnums.Name.BS_AutoPartsArchive }); return(false); } paramModel.APA_Barcode = barCode; } #endregion } catch (Exception ex) { ResultMsg = MsgHelp.GetMsg(MsgCode.E_0018, new object[] { SystemActionEnum.Name.SAVE + SystemTableEnums.Name.BS_AutoPartsArchive, ex.Message }); LogHelper.WriteBussLogEndNG(BussID, LoginInfoDAX.UserName, MethodBase.GetCurrentMethod().ToString(), ex.Message, "", null); return(false); } return(true); }
/// <summary> /// 从平台同步授权商户信息到本地数据库 /// </summary> public static bool SynchronizeSupMerchantAuthorityInfo() { var funcName = "SynchronizeSupMerchantAuthorityInfo"; LogHelper.WriteBussLogStart(Trans.COM, LoginInfoDAX.UserName, funcName, "", "", null); var argsMerchantPostData = string.Format(ApiParameter.BF0012, ConfigurationManager.AppSettings[AppSettingKey.MCT_CODE], HttpUtility.UrlEncode(ConfigurationManager.AppSettings[AppSettingKey.ACTIVATION_CODE]), SysConst.ProductCode); var strMerchantApiData = APIDataHelper.GetAPIData(ApiUrl.BF0012Url, argsMerchantPostData); var jsonMerchantResult = (JObject)JsonConvert.DeserializeObject(strMerchantApiData); if (jsonMerchantResult != null && jsonMerchantResult["ResultCode"].ToString().Equals("I0001")) { var argsSettingKeyMctCode1 = jsonMerchantResult["AROrgSupMerchantAuthorityList"]; var platformMctAuthJson = (JArray)JsonConvert.DeserializeObject(argsSettingKeyMctCode1.ToString()); var localAuthorityList = new List <MDLSM_AROrgSupMerchantAuthority>(); _bllBase.QuerryForList(new MDLSM_AROrgSupMerchantAuthority(), localAuthorityList); var invalidAuthorityList = new List <MDLSM_AROrgSupMerchantAuthority>(); #region _bllBase.CopyModelList(localAuthorityList, invalidAuthorityList); //从无效列表中移除在平台上有效的授权 foreach (var json in platformMctAuthJson) { var validOrgList = invalidAuthorityList.Where( p => p.ASAH_ARMerchant_Code == json["ASAH_ARMerchant_Code"].ToString() && p.ASAH_AROrg_Code == json["ASAH_AROrg_Code"].ToString()).ToList(); if (validOrgList.Count > 0) { invalidAuthorityList.Remove(validOrgList[0]); } } try { DBManager.BeginTransaction(DBCONFIG.Coeus); if (invalidAuthorityList.Count > 0) { foreach (var model in invalidAuthorityList) { model.ASAH_IsValid = false; model.WHERE_ASAH_ID = model.ASAH_ID; bool save = _bllBase.Save <MDLSM_AROrgSupMerchantAuthority>(model); if (!save) { DBManager.RollBackTransaction(DBCONFIG.Coeus); LogHelper.WriteBussLogEndOK(Trans.SM, LoginInfoDAX.UserName, funcName, "同步汽配汽修商户授权失败!", "", null); } } } // 保存授权信息 foreach (var json in platformMctAuthJson) { var argsAuthority = new MDLSM_AROrgSupMerchantAuthority(); var sameAuthorityList = localAuthorityList.Where( p => p.ASAH_ARMerchant_Code == json["ASAH_ARMerchant_Code"].ToString() && p.ASAH_AROrg_Code == json["ASAH_AROrg_Code"].ToString()).ToList(); if (sameAuthorityList.Count > 0) { argsAuthority = sameAuthorityList[0]; } argsAuthority.WHERE_ASAH_ID = argsAuthority.ASAH_ID; argsAuthority.ASAH_ID = json["ASAH_ID"].ToString(); argsAuthority.ASAH_ARMerchant_Code = json["ASAH_ARMerchant_Code"].ToString(); argsAuthority.ASAH_ARMerchant_Name = json["ASAH_ARMerchant_Name"].ToString(); argsAuthority.ASAH_AROrg_Code = json["ASAH_AROrg_Code"].ToString(); argsAuthority.ASAH_AROrg_Name = json["ASAH_AROrg_Name"].ToString(); argsAuthority.ASAH_Remark = json["ASAH_Remark"].ToString(); argsAuthority.ASAH_IsValid = true; argsAuthority.ASAH_CreatedBy = json["ASAH_CreatedBy"].ToString(); argsAuthority.ASAH_UpdatedBy = json["ASAH_UpdatedBy"].ToString(); bool save = _bllBase.Save <MDLSM_AROrgSupMerchantAuthority>(argsAuthority); if (!save) { DBManager.RollBackTransaction(DBCONFIG.Coeus); LogHelper.WriteBussLogEndOK(Trans.SM, LoginInfoDAX.UserName, funcName, "同步汽配汽修商户授权失败!", "", null); } } DBManager.CommitTransaction(DBCONFIG.Coeus); } catch (Exception ex) { DBManager.RollBackTransaction(DBCONFIG.Coeus); LogHelper.WriteErrorLog(Trans.SM, funcName, ex.Message, null, ex); LogHelper.WriteBussLogEndNG(Trans.SM, LoginInfoDAX.UserName, funcName, ex.Message, "", null); return(false); } #endregion } else { ErrMsg = jsonMerchantResult == null ? "" : jsonMerchantResult["ResultMsg"].ToString(); LogHelper.WriteBussLogEndOK(Trans.SM, LoginInfoDAX.UserName, funcName, ErrMsg, "", null); return(false); } LogHelper.WriteBussLogEndOK(Trans.SM, LoginInfoDAX.UserName, funcName, "", "", null); return(true); }
/// <summary> /// 从平台同步组织信息到本地数据库 /// </summary> /// <returns></returns> public static bool SynchronizeOrgInfo() { var funcName = "SynchronizeOrgInfo"; LogHelper.WriteBussLogStart(Trans.COM, LoginInfoDAX.UserName, funcName, "", "", null); //根据商户编码和产品编码来查询组织信息 string argsPostData = string.Format(ApiParameter.BF0002, ConfigurationManager.AppSettings[AppSettingKey.MCT_CODE], SysConst.ProductCode); string strApiData = APIDataHelper.GetAPIData(ApiUrl.BF0002Url, argsPostData); var jsonResult = (JObject)JsonConvert.DeserializeObject(strApiData); if (jsonResult != null && jsonResult["ResultCode"].ToString().Equals("I0001")) { var argsSettingKeyMctCode1 = jsonResult["ListOrganization"]; var platformOrgJson = (JArray)JsonConvert.DeserializeObject(argsSettingKeyMctCode1.ToString()); var localOrgList = new List <MDLSM_Organization>(); _bllBase.QuerryForList(new MDLSM_Organization { WHERE_Org_IsValid = true }, localOrgList); var invalidOrgList = new List <MDLSM_Organization>(); _bllBase.CopyModelList(localOrgList, invalidOrgList); //从无效列表中移除在平台上有效的组织 foreach (var json in platformOrgJson) { var validOrgList = invalidOrgList.Where(p => p.Org_Code == json["Org_Code"].ToString()).ToList(); if (validOrgList.Count > 0) { invalidOrgList.Remove(validOrgList[0]); } } try { DBManager.BeginTransaction(DBCONFIG.Coeus); if (invalidOrgList.Count > 0) { foreach (var model in invalidOrgList) { model.WHERE_Org_ID = model.Org_ID; model.Org_IsValid = false; bool save = _bllBase.Save <MDLSM_Organization>(model); if (!save) { DBManager.RollBackTransaction(DBCONFIG.Coeus); LogHelper.WriteBussLogEndOK(Trans.COM, LoginInfoDAX.UserName, funcName, "同步组织失败!", "", null); return(false); } } } var orgList = new List <MDLSM_Organization>(); foreach (var json in platformOrgJson) { var argsorg = new MDLSM_Organization(); var sameOrgList = localOrgList.Where(p => p.Org_Code == json["Org_Code"].ToString()).ToList(); if (sameOrgList.Count > 0) { argsorg = sameOrgList[0]; } argsorg.WHERE_Org_ID = argsorg.Org_ID; argsorg.Org_Code = json["Org_Code"].ToString(); argsorg.Org_FullName = json["Org_FullName"].ToString(); argsorg.Org_ShortName = json["Org_ShortName"].ToString(); argsorg.Org_Contacter = json["Org_Contacter"].ToString(); argsorg.Org_TEL = json["Org_TEL"].ToString(); argsorg.Org_PhoneNo = json["Org_PhoneNo"].ToString(); argsorg.Org_Prov_Code = json["Org_Prov_Code"].ToString(); argsorg.Org_City_Code = json["Org_City_Code"].ToString(); argsorg.Org_Dist_Code = json["Org_Dist_Code"].ToString(); argsorg.Org_Addr = json["Org_Addr"].ToString(); argsorg.Org_Longitude = json["Org_Longitude"].ToString(); argsorg.Org_Latitude = json["Org_Latitude"].ToString(); argsorg.Org_MarkerTitle = json["Org_MarkerTitle"].ToString(); argsorg.Org_MarkerContent = json["Org_MarkerContent"].ToString(); argsorg.Org_Remark = json["Org_Remark"].ToString(); //Org_MCT_ID 作为MCT_Code来存放 argsorg.Org_MCT_ID = ConfigurationManager.AppSettings[AppSettingKey.MCT_CODE] ?? string.Empty; argsorg.Org_CreatedBy = argsorg.Org_UpdatedBy = "系统同步"; argsorg.Org_IsValid = true; bool save = _bllBase.Save <MDLSM_Organization>(argsorg); if (!save) { DBManager.RollBackTransaction(DBCONFIG.Coeus); LogHelper.WriteBussLogEndOK(Trans.COM, LoginInfoDAX.UserName, funcName, "同步组织失败!", "", null); return(false); } orgList.Add(argsorg); } DBManager.CommitTransaction(DBCONFIG.Coeus); LoginInfoDAX.OrgList = new List <MDLSM_Organization>(orgList); } catch (Exception ex) { DBManager.RollBackTransaction(DBCONFIG.Coeus); LogHelper.WriteErrorLog(Trans.COM, "ExecuteSyncCommand", ex.Message, null, ex); LogHelper.WriteBussLogEndOK(Trans.COM, LoginInfoDAX.UserName, funcName, ex.Message, "", null); return(false); } } else { var strErrorMessage = jsonResult == null ? "" : jsonResult["ResultMsg"].ToString(); LogHelper.WriteBussLogEndOK(Trans.COM, LoginInfoDAX.UserName, funcName, strErrorMessage, "", null); } LogHelper.WriteBussLogEndOK(Trans.COM, LoginInfoDAX.UserName, funcName, "", "", null); return(true); }