示例#1
0
        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, "操作");
            }
        }
示例#2
0
        /// <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));
        }