/// <summary> /// 更新运价处理 /// </summary> /// <param name="tmpfromcity">出发城市</param> /// <param name="tmptocity">到达城市</param> public static void UpdatePrice(string tmpfromcity, string tmptocity) { //调用黑屏获取运价 //发送指令并获取返回内容 string ResultContent = WebManage.SendCommand("FD:" + tmpfromcity + tmptocity, m_UpdatePriceWorkInfo.officenum, true, true, m_UpdatePriceWorkInfo.serverip, m_UpdatePriceWorkInfo.serverport); //解析FD的结果 FDInfo tmpFD = new FDInfo(); tmpFD.FromCity = tmpfromcity; tmpFD.ToCity = tmptocity; GetFDInfo(ref tmpFD, ResultContent); //如果解析出了运价信息则更新 if ((tmpFD.ClassPriceList.Count > 0) && (tmpFD.FullPriceList.Count > 0)) { //更新数据库数据 UpdateDataBasePriceInfo(tmpFD); Log.Record("UpdateClassPrice.log", "城市对:" + tmpfromcity + tmptocity + ",更新完毕..."); } else { Log.Record("UpdateClassPrice.log", "城市对:" + tmpfromcity + tmptocity + ",缺少全价或舱位价格信息,略过更新..."); } }
/// <summary> /// 更新数据库的舱位运价 /// </summary> /// <param name="FD">运价结果信息</param> public static void UpdateDataBasePriceInfo(FDInfo FD) { BaseDataManage Manage = new BaseDataManage(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + "\\Dal.dll"); #region 航线舱位价格数据处理 //删除航线舱位价格数据 string tmpSQL = " FromCityCode='" + FD.FromCity + "' and ToCityCode='" + FD.ToCity + "' "; bool DelFlag = (bool)(Manage.CallMethod("Bd_Air_CabinDiscount", "DeleteBySQL", null, new object[] { tmpSQL })); if (!DelFlag) { Log.Record("UpdateClassPrice.log", "UpdateDataBasePriceInfo:处理出现错误!删除Bd_Air_CabinDiscount数据:" + FD.FromCity + "|" + FD.ToCity); return; } //循环插入数据 for (int i = 0; i < FD.ClassPriceList.Count; i++) { try { Bd_Air_CabinDiscount tmpCabinDiscount = new Bd_Air_CabinDiscount(); tmpCabinDiscount.AirCode = FD.ClassPriceList[i].CarrierCode; tmpCabinDiscount.Cabin = FD.ClassPriceList[i].ClassCode; tmpCabinDiscount.CabinName = FD.ClassPriceList[i].ClassLevel; tmpCabinDiscount.CabinPrice = decimal.Parse(FD.ClassPriceList[i].ClassPrice); tmpCabinDiscount.FromCityCode = FD.FromCity; tmpCabinDiscount.ToCityCode = FD.ToCity; tmpCabinDiscount.IsGN = 0; //添加数据 bool AddFlag = (bool)Manage.CallMethod("Bd_Air_CabinDiscount", "Insert", null, new object[] { tmpCabinDiscount }); if (!AddFlag) { Log.Record("UpdateClassPrice.log", "UpdateDataBasePriceInfo:处理出现错误!添加Bd_Air_CabinDiscount数据:" + FD.ClassPriceList[i].CarrierCode + "|" + FD.ClassPriceList[i].ClassCode + "|" + FD.FromCity + "|" + FD.ToCity + "|" + FD.ClassPriceList[i].ClassPrice); } } catch (Exception ex) { Log.Record("UpdateClassPrice.log", ex, "UpdateDataBasePriceInfo:处理出现错误!添加Bd_Air_CabinDiscount数据"); } } #endregion 航线舱位价格数据处理 #region 航线价格数据处理 //删除航线舱位价格数据 tmpSQL = " FromCityCode='" + FD.FromCity + "' and ToCityCode='" + FD.ToCity + "' "; DelFlag = (bool)(Manage.CallMethod("Bd_Air_Fares", "DeleteBySQL", null, new object[] { tmpSQL })); if (!DelFlag) { Log.Record("UpdateClassPrice.log", "UpdateDataBasePriceInfo:处理出现错误!删除Bd_Air_Fares航线价格数据:" + FD.FromCity + "|" + FD.ToCity); return; } //循环插入数据 for (int i = 0; i < FD.FullPriceList.Count; i++) { try { Bd_Air_Fares tmpAirFares = new Bd_Air_Fares(); tmpAirFares.CarryCode = FD.FullPriceList[i].carrier; tmpAirFares.FromCityCode = FD.FromCity; tmpAirFares.ToCityCode = FD.ToCity; tmpAirFares.FareFee = decimal.Parse(FD.FullPriceList[i].fullPrice); tmpAirFares.IsDomestic = 0; tmpAirFares.Mileage = int.Parse(FD.Mileage); //添加数据 bool AddFlag = (bool)Manage.CallMethod("Bd_Air_Fares", "Insert", null, new object[] { tmpAirFares }); if (!AddFlag) { Log.Record("UpdateClassPrice.log", "UpdateDataBasePriceInfo:处理出现错误!添加Bd_Air_Fares数据:" + FD.FullPriceList[i].carrier + "|" + FD.FullPriceList[i].fullPrice + "|" + FD.FromCity + "|" + FD.ToCity); } } catch (Exception ex) { Log.Record("UpdateClassPrice.log", ex, "UpdateDataBasePriceInfo:处理出现错误!添加Bd_Air_Fares数据"); } } #endregion 航线价格数据处理 }
/// <summary> /// 解析FD结果,填入FD结果类 /// </summary> /// <param name="fdResultContent">FD结果字符串</param> public static void GetFDInfo(ref FDInfo FD, string fdResultContent) { //>PFDXUZXIY ^FD:XUZXIY/15JAN13/ /CNY /TPM 860 / //^01 GS/F / 1430.00= 2860.00/F/F/ / . /25MAR12 /GS01 //^02 GS/C / 1240.00= 2480.00/C/C/ / . /25MAR12 /GS01 //^03 GS/Y / 950.00= 1900.00/Y/Y/ / . /25MAR12 /GS01 //^04 GS/B / 860.00= 1720.00/B/Y/ / . /25MAR12 /GS02 //^05 GS/H / 810.00= 1620.00/H/Y/ / . /25MAR12 /GS02 //^06 GS/K / 760.00= 1520.00/K/Y/ / . /25MAR12 /GS02 //^07 GS/L / 710.00= 1420.00/L/Y/ / . /25MAR12 /GS02 //^08 GS/M / 670.00= 1340.00/M/Y/ / . /25MAR12 /GS02 //^09 GS/Q / 570.00= 1140.00/Q/Y/ / . /25MAR12 /GS02 //^10 GS/X / 480.00= 960.00/X/Y/ / . /25MAR12 /GS02 ^11 GS/U / 430.00= 860.00/U/Y/ / . /25MAR12 /GS02 ^12 GS/E / 380.00= 760.00/E/Y/ / . /25MAR12 /GS02 ^13 HU/R / 2380.00= 4760.00/R/F/ / . /25MAR12 /HU07 ^14 HU/C / 1430.00= 2860.00/C/C/ / . /25SEP12 /HU08 ^15 HU/F / 1430.00= 2860.00/F/F/ / . /25MAR12 /HU07 ^16 HU/C1 / 1140.00= 2280.00/C/C/ / . /25SEP12 /HU08 ^17 HU/Y / 950.00= 1900.00/Y/Y/ / . /25MAR12 /HU08 ^18 HU/B / 860.00= 1720.00/B/Y/ / . /25MAR12 /HU09 ^ ^PAGE 1/3^>PFDXUZXIY ^FD:XUZXIY/15JAN13/ /CNY /TPM 860 / ^19 HU/H / 810.00= 1620.00/H/Y/ / . /25MAR12 /HU09 ^20 HU/K / 760.00= 1520.00/K/Y/ / . /25MAR12 /HU09 ^21 HU/L / 710.00= 1420.00/L/Y/ / . /25MAR12 /HU09 ^22 HU/M / 670.00= 1340.00/M/Y/ / . /25MAR12 /HU09 ^23 HU/M1 / 620.00= 1240.00/M/Y/ / . /25MAR12 /HU09 ^24 HU/Q / 570.00= 1140.00/Q/Y/ / . /25MAR12 /HU09 ^25 HU/Q1 / 520.00= 1040.00/Q/Y/ / . /25MAR12 /HU09 ^26 HU/X / 480.00= 960.00/X/Y/ / . /25MAR12 /HU09 ^27 HU/U / 430.00= 860.00/U/Y/ / . /25MAR12 /HU09 ^28 HU/E / 380.00= 760.00/E/Y/ / . /25MAR12 /HU09 ^29 MU/F / 1710.00 /F/F/ / . /01JAN13 30JUN13/MU04 ^30 MU/C / 1430.00 /C/C/ / . /01JAN13 30JUN13/MU04 ^31 MU/F / 2860.00/F/F/ / . /01JAN13 30JUN13/MU04 ^32 MU/C / 2480.00/C/C/ / . /01JAN13 30JUN13/MU04 ^33 MU/Y / 950.00= 1900.00/Y/Y/ / . /01JAN13 30JUN13/MU05 ^34 MU/B / 860.00= 1720.00/B/Y/ / . /01JAN13 30JUN13/MU06 ^35 MU/E / 810.00= 1620.00/E/Y/ / . /01JAN13 30JUN13/MU06 ^36 MU/H / 760.00= 1520.00/H/Y/ / . /01JAN13 30JUN13/MU06 ^ ^PAGE 2/3^>PFDXUZXIY ^FD:XUZXIY/15JAN13/ /CNY /TPM 860 / ^37 MU/L / 710.00= 1420.00/L/Y/ / . /01JAN13 30JUN13/MU06 ^38 MU/M / 670.00= 1340.00/M/Y/ / . /01JAN13 30JUN13/MU06 ^39 MU/N / 620.00= 1240.00/N/Y/ / . /01JAN13 30JUN13/MU06 ^40 MU/R / 570.00= 1140.00/R/Y/ / . /01JAN13 30JUN13/MU06 ^41 MU/S / 520.00= 1040.00/S/Y/ / . /01JAN13 30JUN13/MU06 ^42 MU/V / 480.00= 960.00/V/Y/ / . /01JAN13 30JUN13/MU06 ^43 MU/T / 430.00= 860.00/T/Y/ / . /01JAN13 30JUN13/MU06 ^ ^PAGE 3/3^^ //以^分割 string[] sl = fdResultContent.Split('^'); //是否已经获得里程标志 bool MilFlag = false; //避免添加重复舱位 string airclass = "|"; string tmpstr = ""; for (int i = 0; i < sl.Length; i++) { try { if (sl[i].Trim() == "") { continue; } tmpstr = sl[i]; #region 获取里程信息 if (!MilFlag) { if (sl[i].IndexOf("/TPM") != -1) { tmpstr = sl[i].Substring(sl[i].IndexOf("/TPM") + 4).Trim(); FD.Mileage = tmpstr.Substring(0, tmpstr.IndexOf("/")).Trim(); MilFlag = true; } continue; } #endregion 获取里程信息 #region 前三位不是数字则继续循环 tmpstr = sl[i].Substring(0, 3).Trim(); try { int.Parse(tmpstr); } catch { continue; } #endregion 前三位不是数字则继续循环 ClassPriceInfo tmpClassPriceInfo = new ClassPriceInfo(); //以空格和/进行分割 string[] sl2 = sl[i].Split(new Char[] { ' ', '/' }); int index = 0; for (int j = 0; j < sl2.Length; j++) { if (sl2[j] == "") { continue; } switch (index) { case 0: if (sl2[j].Trim().Length > 2) { tmpClassPriceInfo.CarrierCode = sl2[j].Substring(3); index++; } index++; break; case 1: tmpClassPriceInfo.CarrierCode = sl2[j]; index++; break; case 2: if (sl2[j].Trim().Length == 3) { tmpClassPriceInfo.ClassCode = sl2[j].Trim().Substring(0, 1); } else { tmpClassPriceInfo.ClassCode = sl2[j]; } index++; break; case 3: if (sl2[j].IndexOf("=") == -1) { tmpClassPriceInfo.ClassPrice = sl2[j].Trim(); index++; break; } tmpClassPriceInfo.ClassPrice = sl2[j].Substring(0, sl2[j].IndexOf("=")); index++; break; case 4: case 5: index++; break; case 6: tmpClassPriceInfo.ClassLevel = sl2[j]; break; } if (index >= 6) { break; } } //跳过重复舱位 if (airclass.Contains("|" + tmpClassPriceInfo.CarrierCode + tmpClassPriceInfo.ClassCode + "|")) { continue; } airclass += tmpClassPriceInfo.CarrierCode + tmpClassPriceInfo.ClassCode + "|"; FD.ClassPriceList.Add(tmpClassPriceInfo); if (tmpClassPriceInfo.ClassCode.ToLower() == "y") { FullPriceInfo tmpFullPriceInfo = new FullPriceInfo(); tmpFullPriceInfo.carrier = tmpClassPriceInfo.CarrierCode; tmpFullPriceInfo.fullPrice = tmpClassPriceInfo.ClassPrice; FD.FullPriceList.Add(tmpFullPriceInfo); } } catch (Exception ex) { Log.Record("UpdateClassPrice.log", ex, "GetFDInfo:处理出现错误!" + sl[i]); } } }