コード例 #1
0
        //計算機票成本 (不管第一段是從那裡出發)
        private static TrafficSectorCostModel GetTrafficCost(string prod_no, string dept, string arrv, DateTime s_date,
                                                             long traffic_xid, long traffic_cost_xid, bool is_holiday)
        {
            TrafficSectorCostModel costModel = null;

            try
            {
                String dept_date     = s_date.ToString("yyyyMMdd");
                int    ThisDayOfWeek = Convert.ToInt32(s_date.DayOfWeek);

                // 找出該段交通成本
                DataSet dsFlyCost = TrafficDAL.QuryDailyFlyCost(prod_no, dept, arrv, dept_date, traffic_xid, traffic_cost_xid);

                // 查無任何成本, 發出異常警示
                if (dsFlyCost.Tables[0].Rows.Count < 1)
                {
                    return(costModel);
                }

                // 過濾掉有重覆及效期迄日比較遠的資料
                List <DataRow> cost_lst = dsFlyCost.Tables[0].AsEnumerable().OrderBy(f => f.Field <Decimal>("SEC")).ThenBy(f => f.Field <string>("VALID_E_DATE")).ToList <DataRow>();
                if (cost_lst != null)
                {
                    if (cost_lst.Count > 0)
                    {
                        cost_lst = ReChkSecValid(cost_lst, dept_date);                         //過濾掉有重覆及效期迄日比較遠的資料
                    }
                }

                if (cost_lst != null)
                {
                    bool  ChkFlyCost = true;
                    float AdultFlyCost = 0, ChildFlyCost = 0, SeniorFlyCost = 0;

                    // 取得交通成本
                    ReCalculateFlyCost(ref ChkFlyCost, ref AdultFlyCost, ref ChildFlyCost, ref SeniorFlyCost, cost_lst, is_holiday);

                    // 建立交通航段的成本
                    costModel = new TrafficSectorCostModel()
                    {
                        COST_XID    = traffic_cost_xid,
                        ADULT_COST  = AdultFlyCost.ToString(),
                        CHILD_COST  = ChildFlyCost.ToString(),
                        SENIOR_COST = SeniorFlyCost.ToString()
                    };
                }
            }
            catch (Exception ex)
            {
                //Website.Instance.logger.FatalFormat("{0},{1}", ex.Message, ex.StackTrace);
                throw ex;
            }

            return(costModel);
        }
コード例 #2
0
        // 取得交通航段
        public static List <TrafficModel> GetTrafficSectors(ProdDetailRQModel req)
        {
            List <TrafficModel> sectors = new List <TrafficModel>();

            try
            {
                // 區段 SECTOR
                DataSet sec_ds        = TrafficDAL.GetTrafficSectors(req.PRODNO, req.SDATE, req.EDATE);
                var     fw_flag       = "";
                var     accum_add_day = 0;
                var     total_psg     = req.ADULT + req.CHILD + req.CHILDNB + req.SENIOR;

                foreach (DataRow dr in sec_ds.Tables[0].Rows)
                {
                    // 檢查去/回程國定假日

                    var AddPriceWeeks = string.IsNullOrEmpty(dr.ToStringEx("ADD_PRICE_WEEKS")) ? "0000000" : dr.ToStringEx("ADD_PRICE_WEEKS");
                    var s_is_holiday  = AddPriceWeeks.Substring(Convert.ToInt32(Convert.ToDateTime(req.SDATE).DayOfWeek), 1);                    // 出發日是否為假日
                    var e_is_holiday  = AddPriceWeeks.Substring(Convert.ToInt32(Convert.ToDateTime(req.EDATE).DayOfWeek), 1);                    // 回程日是否為假日

                    s_is_holiday = (s_is_holiday.Equals("1") || NationalHolidayDAL.ChkNationalHoliday(req.SDATE)) ? "1" : "0";
                    e_is_holiday = (e_is_holiday.Equals("1") || NationalHolidayDAL.ChkNationalHoliday(req.EDATE)) ? "1" : "0";

                    var IsTripInHoliday = (dr.ToStringEx("FORWARD_FLAG").Equals("1") ? s_is_holiday : e_is_holiday).Equals("1") ? true : false;
                    var dept_date       = dr.ToStringEx("FORWARD_FLAG").Equals("1") ? req.SDATE : req.EDATE;

                    // 各段交通累積日數, 當去回程切換數值應該歸零重計
                    if (fw_flag != dr.ToStringEx("FORWARD_FLAG"))
                    {
                        accum_add_day = 0;
                        fw_flag       = dr.ToStringEx("FORWARD_FLAG");
                    }
                    accum_add_day += dr.ToInt32("ADD_DAY");

                    try
                    {
                        // 航段使用交通成本
                        TrafficSectorCostModel SectorCost = GetTrafficCost(req.PRODNO, dr.ToStringEx("DEP_FROM"), dr.ToStringEx("ARR_TO"),
                                                                           Convert.ToDateTime(dept_date), dr.ToInt64("TRAFFIC_XID"), dr.ToInt64("TRAFFIC_COST_XID"), IsTripInHoliday);
                        // 跳過無成本的交通段
                        if (SectorCost == null)
                        {
                            throw new Exception(string.Format("PROD_NO={0}, FORWARD_FLAG={1}, DATE={2}, TRAFFIC_XID={3}, TRAFFIC_COST_XID={4} 交通成本為 NULL",
                                                              req.PRODNO, dr.ToStringEx("FORWARD_FLAG"), dept_date, dr.ToInt64("TRAFFIC_XID"), dr.ToInt64("TRAFFIC_COST_XID")));
                        }

                        // 若承運商為B7, 帶入預設成本與行程代碼
                        if (dr.ToStringEx("CARRIER_CODE").Equals("B7"))
                        {
                            SectorCost.ADULT_TOURCODE  = IsTripInHoliday ? dr.ToStringEx("ADT_TOURCODE_H") : dr.ToStringEx("ADT_TOURCODE");
                            SectorCost.CHILD_TOURCODE  = IsTripInHoliday ? dr.ToStringEx("CHD_TOURCODE_H") : dr.ToStringEx("CHD_TOURCODE");
                            SectorCost.SENIOR_TOURCODE = IsTripInHoliday ? dr.ToStringEx("SEN_TOURCODE_H") : dr.ToStringEx("SEN_TOURCODE");

                            SectorCost.ADULT_FAREBASIS  = IsTripInHoliday ? dr.ToStringEx("ADT_FAREBASIS_H") : dr.ToStringEx("ADT_FAREBASIS");
                            SectorCost.CHILD_FAREBASIS  = IsTripInHoliday ? dr.ToStringEx("CHD_FAREBASIS_H") : dr.ToStringEx("CHD_FAREBASIS");
                            SectorCost.SENIOR_FAREBASIS = IsTripInHoliday ? dr.ToStringEx("SEN_FAREBASIS_H") : dr.ToStringEx("SEN_FAREBASIS");
                        }

                        #region 建構交通航段Model

                        var sec_item = new TrafficSectorModel()
                        {
                            PROD_NO                = dr.ToStringEx("PROD_NO"),
                            TRAFFIC_XID            = dr.ToStringEx("TRAFFIC_XID"),
                            TRAFFIC_COST_XID       = dr.ToStringEx("TRAFFIC_COST_XID"),
                            TRAFFIC_COST_PRICE_XID = dr.ToStringEx("TRAFFIC_COST_PRICE_XID"),

                            TRIP_WAY     = dr.ToStringEx("TRIP_WAY"),
                            FORWARD_FLAG = dr.ToStringEx("FORWARD_FLAG"),
                            SECTOR       = dr.ToInt32("SEC"),
                            TRAFFIC_TYPE = dr.ToStringEx("TRAFFIC_TYPE"),
                            CARRIER_CODE = dr.ToStringEx("CARRIER_CODE"),
                            DEP_FROM     = dr.ToStringEx("DEP_FROM"),
                            ARR_TO       = dr.ToStringEx("ARR_TO"),
                            FLY_HL_FLAG  = dr.ToStringEx("FLY_HL_FLAG"),
                            SUP_NO       = dr.ToStringEx("SUP_NO"),
                            FARE_BASIS   = dr.ToStringEx("FARE_BASIS"),
                            ARNK_FLAG    = dr.ToStringEx("ARNK_FLAG"),

                            // 票規
                            RULE_TYPE = dr.ToStringEx("RULE_TYPE"),

                            // 交通成本
                            TRAFFIC_COST = SectorCost,
                        };

                        var timetable = QueryCrsTimeTable(dr.ToDateTime("S_DATE"), dr.ToDateTime("E_DATE"), sec_item, total_psg);

                        #endregion 建構交通航段Model

                        var sector = new TrafficModel()
                        {
                            PROD_NO     = dr.ToStringEx("PROD_NO"),
                            TRAFFIC_XID = dr.ToStringEx("TRAFFIC_XID"),

                            TRIP_WAY           = dr.ToStringEx("TRIP_WAY"),
                            SECTOR             = dr.ToStringEx("SEC"),
                            TRAFFIC_TYPE       = dr.ToStringEx("TRAFFIC_TYPE"),
                            TRAFFIC_NAME       = dr.ToStringEx("CARRIER_CODE_NAME"),
                            SUP_NO             = dr.ToStringEx("SUP_NO"),
                            RETURN_FEE         = dr.ToStringEx("RETURN_FEE"),
                            RETURN_FEE_PERCENT = Convert.ToDouble(string.IsNullOrEmpty(dr.ToStringEx("RETURN_FEE_PERCENT")) ? "0" : dr.ToStringEx("RETURN_FEE_PERCENT")),
                            // 票規
                            RULE_TYPE = dr.ToStringEx("RULE_TYPE"),

                            // 交通位控
                            //TRAFFIC_QTYS = Qty,
                            // 交通時刻表
                            //TRAFFIC_TIMETBS = timetable
                        };

                        sectors.Add(sector);
                    }
                    catch (Exception ex2)
                    {
                        Website.Instance.logger.FatalFormat("{0},{1}", ex2.Message, ex2.StackTrace);
                    }
                }
            }
            catch (Exception ex)
            {
                //Website.Instance.logger.FatalFormat("{0},{1}", ex.Message, ex.StackTrace);
                throw ex;
            }

            return(sectors);
        }