zoukankan      html  css  js  c++  java
  • 解析机票舱位和子舱位方法

    public static string GetSeats(string _f_az, string _s_az, string _airCom, string _trip, string _date, decimal _yPrice)
    {
    // SA--Q1SA--AAAS-SS-AS-SQ-A-
    // 1-8: number of seat; A: seat number >= 9
    GetAirSeats(_airCom, _trip, _date, _yPrice); // get seat codes & discount
    string s = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    string airSeats = "";
    try
    {
    airSeats = HTAirSeat[_airCom + "-" + _trip].ToString();
    }
    catch
    {
    airSeats = "A=0,B=0,C=0,D=0,E=0,F=0,G=0,H=0,I=0,J=0,K=0,L=0,M=0,N=0,O=0,P=0,Q=0,R=0,S=0,T=0,U=0,V=0,W=0,X=0,Y=0,Z=0";
    }
    ArrayList al = new ArrayList();
    for (int i = 0; i < _f_az.Length; i++)
    {
    string c = _f_az.Substring(i, 1);
    string _s = s.Substring(i, 1);
    if (c.MatchReg(@"^A|[1-8]{1}$"))
    {
    try
    {
    al.Add(_s + "=" + airSeats.Substring(airSeats.IndexOf(_s + "=")).Split(',')[0].Split('=')[1] + "=" + c);

    // 子舱位
    if (_s_az != "" && _s_az.IndexOf(_s) != -1)
    {
    string saz = _s_az.Substring(_s_az.IndexOf(_s), 2);
    al.Add(saz + "=" + airSeats.Substring(airSeats.IndexOf(saz + "=")).Split(',')[0].Split('=')[1] + "=" + c);
    }
    }
    catch
    {
    continue;
    }
    }
    }
    if (al.Count == 0)
    {
    return "";
    }
    al.Sort(new Common.SeatComparer());
    string[] gs = new string[al.Count];
    al.CopyTo(gs);
    al = null;
    return gs.JOIN(",");
    }

    public class SeatComparer : IComparer
    {
    // Calls CaseInsensitiveComparer.Compare with the parameters reversed.
    int IComparer.Compare(Object x, Object y)
    {
    decimal X = Convert.ToDecimal((x.ToString().Split('=')[1]));
    decimal Y = Convert.ToDecimal((y.ToString().Split('=')[1]));
    return X == Y ? 0 : (X > Y ? 1 : -1);
    }
    }

  • 相关阅读:
    Java中判断两个列表是否相等
    chrome:插件、跨域、调试....
    mac 开发环境采坑
    webpack升级踩坑
    js-使用装饰器去抖
    React setState 笔试题,下面的代码输出什么?
    react 解决:容器组件更新,导致内容组件重绘
    centos使用ngnix代理https
    javascript 理解继承
    js 数据监听--对象的变化
  • 原文地址:https://www.cnblogs.com/taomylife/p/3424664.html
Copyright © 2011-2022 走看看