public static void AddBunk(BunkView bunkView, string account) { var bunk = Bunk.CreateBunk(bunkView); BunkCollection.Instance.Add(bunk.Id, bunk); saveAddLog("舱位", bunk.ToString(), bunk.Id.ToString(), account); }
internal static Bunk CreateBunk(Guid id, BunkView bunkView) { var bunk = CreateBunk(bunkView); bunk.Id = id; return(bunk); }
public static void UpdateBunk(Guid id, BunkView bunkView, string account) { var originalBunk = QueryBunkNew(id); if (null == originalBunk) { throw new ChinaPay.Core.CustomException("原舱位不存在"); } var originalContent = originalBunk.ToString(); var bunk = Bunk.CreateBunk(id, bunkView); BunkCollection.Instance.Update(bunk.Id, bunk); saveUpdateLog("舱位", originalContent, bunk.ToString(), bunk.Id.ToString(), account); }
protected void btnSave_Click(object sender, EventArgs e) { //舱位类型 var bunkType = (BunkType)int.Parse(this.radiolist.SelectedValue); string AirlineCode = this.ddlAirline.SelectedValue; //航空公司代码 DateTime FlightBeginDate = Convert.ToDateTime(this.txtHBStartDate.Text); //航班开始日期 string FlightEndDate = string.Empty; if (!string.IsNullOrEmpty(this.txtHBStopDate.Text)) { FlightEndDate = this.txtHBStopDate.Text; //航班截止时间 } DateTime ETDZDate = Convert.ToDateTime(this.txtCpStartDate.Text); //出票时间 string Code = this.txtCwCode.Text.Trim(); //代码 bool Valid = this.radseatlist.SelectedValue == "T" ? true : false; //状态 //折扣 decimal Discount = 0; if (bunkType == BunkType.Economic || bunkType == BunkType.FirstOrBusiness) { Discount = Convert.ToDecimal(this.txtDiscount.Text.Trim()) / 100; } //描述 string Description = string.Empty; if (bunkType == BunkType.FirstOrBusiness) { Description = this.ddltdType.SelectedItem.Text; } if (bunkType == BunkType.Promotion) { Description = this.ddlTJType.SelectedItem.Text; } if (bunkType == BunkType.Free) { Description = dropMpType.SelectedItem.Text; } //子舱位 string strSeatName = seatName.Value; //创建舱位 BunkView bunkView = null; try { //验证 ExistsValidate(); switch (bunkType) { case BunkType.Economic: //经济舱位 var econmicBunkVie = new EconomicBunkView() { Discount = Discount }; if (this.ddlDepartCity.SelectedValue != "0") { econmicBunkVie.Departure = this.ddlDepartCity.SelectedValue; } if (this.ddlArriveCity.SelectedValue != "0") { econmicBunkVie.Arrival = this.ddlArriveCity.SelectedValue; } if (!string.IsNullOrEmpty(strSeatName)) { string[] strseatlist = strSeatName.Split('|'); for (int i = 0; i < strseatlist.Length; i++) { ExtendedWithDiscountBunkView ewbv = new ExtendedWithDiscountBunkView(); ewbv.Code = strseatlist[i].Split(',')[0]; ewbv.Discount = decimal.Parse(strseatlist[i].Split(',')[1]) / 100; econmicBunkVie.AddExtended(ewbv); } } bunkView = econmicBunkVie; break; case BunkType.FirstOrBusiness: //头等公务舱 var firstBusinessBunkView = new FirstBusinessBunkView() { Description = Description, Discount = Discount }; if (this.ddlDepartCity.SelectedValue != "0") { firstBusinessBunkView.Departure = this.ddlDepartCity.SelectedValue; } if (this.ddlArriveCity.SelectedValue != "0") { firstBusinessBunkView.Arrival = this.ddlArriveCity.SelectedValue; } if (!string.IsNullOrEmpty(strSeatName)) { string[] strseatlist = strSeatName.Split('|'); for (int i = 0; i < strseatlist.Length; i++) { ExtendedWithDiscountBunkView ewbv = new ExtendedWithDiscountBunkView(); ewbv.Code = strseatlist[i].Split(',')[0]; ewbv.Discount = decimal.Parse(strseatlist[i].Split(',')[1]) / 100; firstBusinessBunkView.AddExtended(ewbv); } } bunkView = firstBusinessBunkView; break; case BunkType.Promotion: //特价舱位 var promotionBunkView = new PromotionBunkView() { Description = Description }; string strSeatTJ = this.seatTJ.Value; if (!string.IsNullOrEmpty(strSeatTJ)) { string[] strseatlist = strSeatName.Split('|'); for (int i = 0; i < strseatlist.Length; i++) { promotionBunkView.AddExtended(strseatlist[i].Split(',')[0]); } } bunkView = promotionBunkView; break; case BunkType.Production: //往返产品舱 bunkView = new ProductionBunkView(); break; case BunkType.Transfer: //中转联程舱 bunkView = new TransferBunkView(); break; case BunkType.Free: //免票 bunkView = new FreeBunkView() { Description = Description }; break; case BunkType.Team: //团队 bunkView = new TeamBunkView(); break; } bunkView.Airline = AirlineCode; bunkView.Code = Code; bunkView.RefundRegulation = txtRefundRegulation.Text.Trim(); bunkView.ChangeRegulation = txtChangeRegulation.Text.Trim(); bunkView.EndorseRegulation = txtEndorseRegulation.Text.Trim(); bunkView.Remarks = txtRemarks.Text.Trim(); bunkView.ETDZDate = ETDZDate; bunkView.Valid = Valid; if (!string.IsNullOrEmpty(FlightEndDate)) { bunkView.FlightEndDate = Convert.ToDateTime(FlightEndDate); } bunkView.FlightBeginDate = FlightBeginDate; for (int i = 0; i < chklVoyageType.Items.Count; i++) { if (chklVoyageType.Items[i].Selected) { bunkView.VoyageType |= (VoyageTypeValue)(int.Parse(chklVoyageType.Items[i].Value)); } } for (int i = 0; i < chklTravelType.Items.Count; i++) { if (chklTravelType.Items[i].Selected) { bunkView.TravelType |= (TravelTypeValue)(int.Parse(chklTravelType.Items[i].Value)); } } for (int i = 0; i < chklPassengerType.Items.Count; i++) { if (chklPassengerType.Items[i].Selected) { bunkView.PassengerType |= (PassengerTypeValue)(int.Parse(chklPassengerType.Items[i].Value)); } } //添加 if (Request.QueryString["action"] != null && Request.QueryString["action"].ToString() == "add") { try { FoundationService.AddBunk(bunkView, CurrentUser.UserName); RegisterScript("alert('添加成功!'); window.location.href='Bunk.aspx';"); } catch (Exception ex) { ShowExceptionMessage(ex, "添加"); } } else//修改 { try { FoundationService.UpdateBunk(new Guid(Request.QueryString["Id"].ToString()), bunkView, CurrentUser.UserName); RegisterScript("alert('修改成功!'); window.location.href='Bunk.aspx?Search=Back';"); } catch (Exception ex) { ShowExceptionMessage(ex, "修改"); } } } catch (Exception exw) { ShowExceptionMessage(exw, "操作"); } }
protected void gvDiscount_RowCommand(object sender, GridViewCommandEventArgs e) { if (e.CommandName == "opdate") { string code = e.CommandArgument.ToString(); ChinaPay.B3B.Service.Foundation.Domain.Bunk bunk = FoundationService.QueryBunkNew(new Guid(code)); if (bunk == null) { return; } BunkView bunkView = null; switch (bunk.Type) { case BunkType.Economic: EconomicBunk economicBunk = bunk as EconomicBunk; var economicBunkView = new EconomicBunkView() { Arrival = economicBunk.ArrivalCode.Value, Departure = economicBunk.DepartureCode.Value, Discount = economicBunk.Discount }; foreach (var item in economicBunk.Extended) { economicBunkView.AddExtended(new ExtendedWithDiscountBunkView { Code = item.Code.Value, Discount = item.Discount }); } bunkView = economicBunkView; break; case BunkType.FirstOrBusiness: FirstBusinessBunk firstBusinessBunk = bunk as FirstBusinessBunk; var firstBusinessBunkView = new FirstBusinessBunkView() { Arrival = firstBusinessBunk.ArrivalCode.Value, Departure = firstBusinessBunk.DepartureCode.Value, Description = firstBusinessBunk.Description, Discount = firstBusinessBunk.Discount }; foreach (var item in firstBusinessBunk.Extended) { firstBusinessBunkView.AddExtended(new ExtendedWithDiscountBunkView { Code = item.Code.Value, Discount = item.Discount }); } bunkView = firstBusinessBunkView; break; case BunkType.Promotion: PromotionBunk promotionBunk = bunk as PromotionBunk; var promotionBunkView = new PromotionBunkView() { Description = promotionBunk.Description }; foreach (var item in promotionBunk.Extended) { promotionBunkView.AddExtended(item); } bunkView = promotionBunkView; break; case BunkType.Production: bunkView = new ProductionBunkView(); break; case BunkType.Transfer: bunkView = new TransferBunkView(); break; case BunkType.Free: FreeBunk freeBunk = bunk as FreeBunk; bunkView = new FreeBunkView() { Description = freeBunk.Description }; break; case BunkType.Team: bunkView = new TeamBunkView(); break; default: throw new Exception("舱位不存在"); } bunkView.Code = bunk.Code.Value; bunkView.RefundRegulation = bunk.RefundRegulation; bunkView.ChangeRegulation = bunk.ChangeRegulation; bunkView.EndorseRegulation = bunk.EndorseRegulation; bunkView.VoyageType = bunk.VoyageType; bunkView.PassengerType = bunk.PassengerType; bunkView.TravelType = bunk.TravelType; bunkView.Remarks = bunk.Remarks; bunkView.FlightBeginDate = bunk.FlightBeginDate; bunkView.FlightEndDate = bunk.FlightEndDate; bunkView.ETDZDate = bunk.ETDZDate; bunkView.Airline = bunk.AirlineCode.Value; bunkView.Valid = !bunk.Valid; try { FoundationService.UpdateBunk(new Guid(code), bunkView, CurrentUser.UserName); if (bunk.Valid) { RegisterScript("alert('禁用成功!'); window.location.href='Bunk.aspx?Search=Back';"); } else { RegisterScript("alert('启用成功!'); window.location.href='Bunk.aspx?Search=Back';"); } } catch (Exception ex) { ShowExceptionMessage(ex, bunk.Valid ? "禁用" : "启用"); return; } refresh(); } }
internal static Bunk CreateBunk(BunkView bunkView) { if (null == bunkView) { throw new ArgumentNullException("bunkView"); } bunkView.Validate(); Bunk bunk = null; if (bunkView is GeneralBunkView) { if (bunkView is FirstBusinessBunkView) { bunk = new FirstBusinessBunk { Description = StringUtility.Trim(((FirstBusinessBunkView)bunkView).Description) }; } else { bunk = new EconomicBunk(); } var generalBunkView = bunkView as GeneralBunkView; var generalBunk = bunk as GeneralBunk; generalBunk.DepartureCode = StringUtility.Trim(generalBunkView.Departure) ?? string.Empty; generalBunk.ArrivalCode = StringUtility.Trim(generalBunkView.Arrival) ?? string.Empty; generalBunk.Discount = generalBunkView.Discount; foreach (var item in generalBunkView.Extended) { generalBunk.AddExtended(new ExtendedWithDiscountBunk(StringUtility.Trim(item.Code), item.Discount)); } } else if (bunkView is PromotionBunkView) { var promotionBunkView = bunkView as PromotionBunkView; bunk = new PromotionBunk { Description = StringUtility.Trim(promotionBunkView.Description) }; var promotionBunk = bunk as PromotionBunk; foreach (var item in promotionBunkView.Extended) { promotionBunk.AddExtended(StringUtility.Trim(item)); } } else if (bunkView is ProductionBunkView) { bunk = new ProductionBunk(); } else if (bunkView is TransferBunkView) { bunk = new TransferBunk(); } else if (bunkView is FreeBunkView) { bunk = new FreeBunk { Description = StringUtility.Trim((bunkView as FreeBunkView).Description) }; } else if (bunkView is TeamBunkView) { bunk = new TeamBunk(); } else { throw new NotSupportedException("未知舱位类型"); } bunk.AirlineCode = StringUtility.Trim(bunkView.Airline); bunk.Code = StringUtility.Trim(bunkView.Code); bunk.ETDZDate = bunkView.ETDZDate; bunk.FlightBeginDate = bunkView.FlightBeginDate; bunk.FlightEndDate = bunkView.FlightEndDate; //bunk.EI = StringUtility.Trim(bunkView.EI); bunk.RefundRegulation = StringUtility.Trim(bunkView.RefundRegulation); bunk.ChangeRegulation = StringUtility.Trim(bunkView.ChangeRegulation); bunk.EndorseRegulation = StringUtility.Trim(bunkView.EndorseRegulation); bunk.Remarks = StringUtility.Trim(bunkView.Remarks); bunk.Valid = bunkView.Valid; bunk.ModifyTime = DateTime.Now; bunk.VoyageType = bunkView.VoyageType; bunk.TravelType = bunkView.TravelType; bunk.PassengerType = bunkView.PassengerType; return(bunk); }
/// <summary> /// 根据FD数据更新舱位运价 /// </summary> /// <param name="carrier">承运人</param> /// <param name="departure">出发地</param> /// <param name="arrival">到达地</param> /// <param name="flightDate">航班日期</param> /// <param name="fareData"></param> /// <param name="mileage"> </param> public static void FixBunkPrice(string carrier, string departure, string arrival, DateTime flightDate, List <GraduatedFare> fareData, decimal mileage) { var basePrice = fareData.FirstOrDefault(f => f.ClassOfService == "Y"); if (basePrice == null) { return; } var b3bBasePrice = FoundationService.QueryBasicPrice(carrier, departure, arrival, flightDate); if (b3bBasePrice.Price != basePrice.OneWayFare) { var basicPriceView = new BasicPriceView() { Airline = b3bBasePrice.Airline != null? b3bBasePrice.Airline.Code.Value:null, Departure = b3bBasePrice.Departure != null?b3bBasePrice.Departure.Code.Value:null, Arrival = b3bBasePrice.Arrival != null?b3bBasePrice.Arrival.Code.Value:null, FlightDate = b3bBasePrice.FlightDate, ETDZDate = b3bBasePrice.ETDZDate, Price = basePrice.OneWayFare, Mileage = b3bBasePrice.Mileage, //TODO 没有更新到最新里程数 ModifyTime = DateTime.Now }; if (b3bBasePrice.Airline == null || b3bBasePrice.FlightDate != basePrice.EffectiveDate) { basicPriceView.Airline = carrier; basicPriceView.Departure = departure; basicPriceView.Arrival = arrival; basicPriceView.FlightDate = basePrice.EffectiveDate; basicPriceView.ETDZDate = DateTime.Today < basePrice.EffectiveDate ? DateTime.Today : basePrice.EffectiveDate; basicPriceView.Mileage = mileage; FoundationService.AddBasicPrice(basicPriceView, _systemauto); } else { FoundationService.UpdateBasicPrice(b3bBasePrice.Id, basicPriceView, _systemauto); } } var bunks = FoundationService.QueryBunk(carrier, departure, arrival, flightDate).OfType <GeneralBunk>(); var diffPriceBunks = new Dictionary <Guid, BunkView>(); List <string> FixedBunk = new List <string>(); var newBunks = new List <BunkView>(); //var subBunkReg = new Regex("\\w\\d"); foreach (GraduatedFare fare in fareData) { if (fare.ApplyType == ApplyType.Roundtrip) { continue; } var isSubBunk = !string.IsNullOrEmpty(fare.SubClass);//subBunkReg.IsMatch(fare.ClassOfService); var bunk = bunks.FirstOrDefault(b => b.Code.Value == fare.ClassOfService); if (!isSubBunk) { if (FixedBunk.Contains(fare.ClassOfService)) { continue; } if (bunk == null || bunk.Airline == null || bunk.Departure == null || bunk.Arrival == null) { newBunks.Add(CreatBunkFromFDData(fare, carrier, departure, arrival, basePrice.OneWayFare)); } else if (FoundationService.CalculateFare(basePrice.OneWayFare, bunk.Discount) != fare.OneWayFare) { //var bunkView = GeneralBunkView(bunk,fare, basePrice); //diffPriceBunks.Add(bunk.Id,bunkView); var bunkView = CreatBunkFromFDData(fare, carrier, departure, arrival, basePrice.OneWayFare); newBunks.Add(bunkView); } FixedBunk.Add(fare.ClassOfService); } else { var extendedBunkView = new ExtendedWithDiscountBunkView() { Code = fare.ClassOfService + fare.SubClass, Discount = FoundationService.CalculateDiscount(basePrice.OneWayFare, fare.OneWayFare) }; if (bunk == null || bunk.Airline == null || bunk.Departure == null || bunk.Arrival == null) {//在舱位信息不够具体的时候添加子舱位 var tobeaddedbunkView = newBunks.FirstOrDefault(b => b.Code == fare.ClassOfService); if (tobeaddedbunkView != null) {//子舱位所在的舱位代码是新添加的 if (tobeaddedbunkView is FirstBusinessBunkView) { var fbBunkView = tobeaddedbunkView as FirstBusinessBunkView; fbBunkView.AddExtended(extendedBunkView); } else { var eBunkView = tobeaddedbunkView as EconomicBunkView; eBunkView.AddExtended(extendedBunkView); } } } else { BunkView bunkview = newBunks.FirstOrDefault(b => b.Code == fare.ClassOfService) ?? diffPriceBunks.FirstOrDefault(b => b.Value.Code == fare.ClassOfService).Value; bunkview = bunkview ?? GeneralBunkView(bunk, fare, basePrice, false); if (bunkview is FirstBusinessBunkView) { var fbBunkView = bunkview as FirstBusinessBunkView; var existsExtBunk = fbBunkView.Extended.FirstOrDefault(b => b.Code == extendedBunkView.Code); if (existsExtBunk != null) { existsExtBunk.Discount = extendedBunkView.Discount; if (!diffPriceBunks.ContainsKey(bunk.Id)) { diffPriceBunks.Add(bunk.Id, fbBunkView); } } else { fbBunkView.AddExtended(extendedBunkView); } } else { var fbBunkView = bunkview as EconomicBunkView; var existsExtBunk = fbBunkView.Extended.FirstOrDefault(b => b.Code == extendedBunkView.Code); if (existsExtBunk != null) { existsExtBunk.Discount = extendedBunkView.Discount; if (!diffPriceBunks.ContainsKey(bunk.Id)) { diffPriceBunks.Add(bunk.Id, fbBunkView); } } else { fbBunkView.AddExtended(extendedBunkView); } } } } } foreach (KeyValuePair <Guid, BunkView> bunk in diffPriceBunks) { FoundationService.UpdateBunk(bunk.Key, bunk.Value, _systemauto); } newBunks.ForEach(b => FoundationService.AddBunk(b, _systemauto)); }