static TrainWnd[] DeserializeFromClSet(byte[] b, out byte color) { color = 0; ClSet cs = new ClSet(b, 2); ClTable ct1 = cs.Tables["Infomations"], ct2 = cs.Tables["CarStream"]; if (ct1 == null || ct2 == null) { return(new TrainWnd[0]); } TrainWnd[] wnds = new TrainWnd[ct1.Rows.Count]; ClRow[] crs; int col_carcnt = ct1.GetColumnIndex("I_CAR_CNT"); int col_flag = ct1.GetColumnIndex("B_FLAG"); int col_len = ct1.GetColumnIndex("F_LEN"); int col_wegh = ct1.GetColumnIndex("F_WEGH"); int col_tranum = ct1.GetColumnIndex("C_TRA_NUM"); int col_line = ct1.GetColumnIndex("I_LINE_ID"); int col_note = ct1.GetColumnIndex("C_NOTE"); int col_locomtype = ct1.GetColumnIndex("B_LOCOM_TYPE"); int col_grocnt = ct2.GetColumnIndex("I_CAR_CNT"); int col_groid = ct2.GetColumnIndex("I_GRO_ID"); for (int i = 0; i < wnds.Length; i++) { wnds[i] = new TrainWnd(); wnds[i].cnt = Convert.ToInt16(ct1.Rows[i][col_carcnt]); wnds[i].flag = Convert.ToByte(ct1.Rows[i][col_flag]); wnds[i].length = Convert.ToInt16(ct1.Rows[i][col_len]) / 10f; wnds[i].lineID = Convert.ToInt16(ct1.Rows[i][col_line]); wnds[i].weight = Convert.ToSingle(ct1.Rows[i][col_wegh]); wnds[i].trainnum = Convert.ToString(ct1.Rows[i][col_tranum]); wnds[i].infomation = ct1.Rows[i][col_note].ToString(); if (col_locomtype >= 0) { wnds[i].LocomType = Convert.ToByte(ct1.Rows[i][col_locomtype]); } crs = ct2["I_LINE_ID", "=", wnds[i].lineID]; foreach (ClRow cr in crs) { CarInfomation inf = new CarInfomation(); inf.cnt = Convert.ToInt16(cr[col_grocnt]); inf.dir = Convert.ToInt16(cr[col_groid]); wnds[i].infomations.Add(inf); } } try { ct1 = cs.Tables["SYSCOLOR"]; if (ct1 != null && ct1.Rows.Count > 0) { color = Convert.ToByte(ct1.Rows[0][0]); } } catch { } return(wnds); }
static TrainWnd[] DeserializeFromStruct(byte[] b) { int n = BitConverter.ToInt16(b, 2); TrainWnd[] wnds = new TrainWnd[n]; int i; n = 4; for (i = 0; i < wnds.Length; i++) { wnds[i] = new TrainWnd(); wnds[i].lineID = BitConverter.ToInt16(b, n); n += 2; wnds[i].flag = b[n]; n++; wnds[i].cnt = b[n]; n++; wnds[i].weight = BitConverter.ToInt16(b, n); n += 2; wnds[i].length = BitConverter.ToInt16(b, n) / 10f; n += 2; wnds[i].trainnum = Tools.Byte2String(b, ref n); int m = b[n]; n++; for (int j = 0; j < m; j++) { CarInfomation ci = new CarInfomation(); ci.dir = BitConverter.ToInt16(b, n); n += 2; ci.cnt = b[n]; n++; wnds[i].infomations.Add(ci); } } return(wnds); }