解析机票舱位和子舱位方法

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);
}
}

原文地址:https://www.cnblogs.com/taomylife/p/3424664.html