private void AddTabPage(string name, string text, ConfigList config = null, Control frame = null) { var tp = new TabPage() { Name = name, Margin = new Padding(0), Text = text, Padding = new Padding(0) }; var tsmi = new ToolStripMenuItem("关闭 " + tp.Text); var tsi = (ToolStripItem)tsmi; tp.TextChanged += (a, b) => { tsi.Text = "关闭 " + tp.Text; }; tsi.Click += (s, a) => { this.tabSelectPages.TabPages.Remove(tp); contextMenuStrip.Items.Remove(tsi); }; var pas = new List <Nomal_Passengers>(); //CloneJsonTrainList(_passengersData, pas); var cfg = config.CloneConfigList(); cfg.Init = false; tp.Controls.Add(new TicketMain(_cookieContainer, null, cfg, frame) { Dock = DockStyle.Fill, UserName = _userName }); this.tabSelectPages.TabPages.Add(tp); this.tabSelectPages.SelectedTab = tp; contextMenuStrip.Items.Add(tsi); }
public static void WriteConfigToDisk(string file, List <ConfigList> cookieJar) { DesCryption dc = new DesCryption(); List <ConfigList> tmpList = new List <ConfigList>(); foreach (ConfigList v in cookieJar) { ConfigList cl = v; System.Collections.Hashtable ht = new System.Collections.Hashtable(); foreach (var x in v.Passengers.Keys) { string tmp = x.ToString(); tmp = dc.EncryptString(x.ToString(), "A1B3C5D7"); aNyoNe.GetInfoFrom12306.Nomal_Passengers pd = new aNyoNe.GetInfoFrom12306.Nomal_Passengers(); pd = (aNyoNe.GetInfoFrom12306.Nomal_Passengers)(v.Passengers[x]); pd.Passenger_id_no = dc.EncryptString(pd.Passenger_id_no, "A1B3C5D7"); pd.Passenger_name = dc.EncryptString(pd.Passenger_name, "A1B3C5D7"); ht.Add(tmp, pd); } cl.Passengers = ht; tmpList.Add(cl); } using (Stream stream = File.Create(file)) { try { BinaryFormatter formatter = new BinaryFormatter(); formatter.Serialize(stream, tmpList); } catch { } } }
public static void WriteConfigToDisk(string file, ConfigList cookieJar) { using (Stream stream = File.Create(file)) { try { BinaryFormatter formatter = new BinaryFormatter(); formatter.Serialize(stream, cookieJar); } catch { } } }
public static void WriteConfigToDisk(string file, ConfigList cookieJar) { using (Stream stream = File.Create(file)) { try { BinaryFormatter formatter = new BinaryFormatter(); formatter.Serialize(stream, cookieJar); } catch (Exception e) { } } }
public static ConfigList CloneConfigList(this ConfigList list) { var cfg = new ConfigList(); cfg.Init = list.Init; cfg.User = list.User; cfg.From = list.From; cfg.To = list.To; cfg.Date = list.Date; cfg.Time = list.Time; cfg.Turn = list.Turn; cfg.TurnDates = list.TurnDates; cfg.Passengers = list.Passengers; cfg.SeatTypes = list.SeatTypes; cfg.TrainNos = list.TrainNos; cfg.CustomColumn = list.CustomColumn; return(cfg); }
public static List <ConfigList> ReadConfigFromDisk_ConfigList(string file) { try { using (Stream stream = File.Open(file, FileMode.Open)) { BinaryFormatter formatter = new BinaryFormatter(); List <ConfigList> lst = formatter.Deserialize(stream) as List <ConfigList>; DesCryption dc = new DesCryption(); List <ConfigList> tmpList = new List <ConfigList>(); foreach (ConfigList v in lst) { ConfigList cl = v; System.Collections.Hashtable ht = new System.Collections.Hashtable(); foreach (var x in v.Passengers.Keys) { string tmp = x.ToString(); tmp = dc.DecryptString(x.ToString(), "A1B3C5D7"); aNyoNe.GetInfoFrom12306.Nomal_Passengers pd = new aNyoNe.GetInfoFrom12306.Nomal_Passengers(); pd = (aNyoNe.GetInfoFrom12306.Nomal_Passengers)(v.Passengers[x]); pd.Passenger_id_no = dc.DecryptString(pd.Passenger_id_no, "A1B3C5D7"); pd.Passenger_name = dc.DecryptString(pd.Passenger_name, "A1B3C5D7"); ht.Add(tmp, pd); } cl.Passengers = ht; tmpList.Add(cl); } return(tmpList); } } catch { return(new List <ConfigList>()); } }
public static ConfigList CloneConfigList(this ConfigList list) { var cfg = new ConfigList(); cfg.Init = list.Init; cfg.User = list.User; cfg.From = list.From; cfg.To= list.To; cfg.Date= list.Date; cfg.Time= list.Time; cfg.Turn = list.Turn; cfg.TurnDates = list.TurnDates; cfg.Passengers = list.Passengers; cfg.SeatTypes = list.SeatTypes; cfg.TrainNos = list.TrainNos; cfg.CustomColumn = list.CustomColumn; return cfg; }
/// <summary> /// 设置当前查询页的初始配置 /// </summary> /// <param name="cfg"></param> public void SetConfigToControl(ConfigList cfg) { cboFrom.Text = cfg.From.IndexOf("|") > -1 ? cfg.From.Split('|')[0] : cfg.From; cboTo.Text = cfg.To.IndexOf("|") > -1 ? cfg.To.Split('|')[0] : cfg.To; dtpRiqi.Value = cfg.Date >= DateTime.Now ? cfg.Date : DateTime.Now; cboShijian.Text = cfg.Time; customColumn = cfg.CustomColumn; if (customColumn == null) InitColumns(); string flag = ""; foreach (var v in customColumn.Keys) { dgvTrainView.Columns[v.ToString()].Visible = (bool)customColumn[v]; flag = v.ToString().Substring(1, 1); ((CheckBox)plCostomColumn.Controls["seat" + flag]).Checked = (bool)customColumn[v]; } if (cfg.Turn) { TurnDatesInit(); chkSelectTurn.Checked = true; fplTurnDates.Visible = true; foreach (var v in cfg.TurnDates.Keys) { for (int i = 0; i < flpTurnCheckBox.Controls.Count; i++) { if (flpTurnCheckBox.Controls[i].Text == v.ToString()) { ((CheckBox)flpTurnCheckBox.Controls[i]).Checked = true; turnDateTable.Add(v, cfg.TurnDates[v]); } } } } foreach (var v in cfg.Passengers.Keys) { for (int i = 1; i < flplPassengers.Controls.Count; i++) { if (v.ToString().Contains(flplPassengers.Controls[i].Text) && v.ToString().Split('|')[1] == ((Nomal_Passengers)(flplPassengers.Controls[i].Tag)).Passenger_id_no) { ((CheckBox)flplPassengers.Controls[i]).Tag = cfg.Passengers[v]; ((CheckBox)flplPassengers.Controls[i]).Checked = true; } } } UpdateAutoPassengersList(); for (int i = 0; i < cfg.SeatTypes.Count; i++) { QuickAddSeatType(cfg.SeatTypes[i]); } for (int i = 0; i < cfg.TrainNos.Count; i++) { QuikAddTrainInfo(cfg.TrainNos[i]); } InitAutoSubmitPassengersSeat(); }
//初始化用户配置文件 private void InitConfig() { if (isInitConfig) { DeterMineCall(() => { selectPassengerCount = 0; foreach (var v in config.Passengers.Keys) { for (int i = 1; i < flplPassengers.Controls.Count; i++) { if (v.ToString().Contains(flplPassengers.Controls[i].Text) && v.ToString().Split('|')[1] == ((Nomal_Passengers)(flplPassengers.Controls[i].Tag)).Passenger_id_no) { ((CheckBox)flplPassengers.Controls[i]).Checked = true; } } } }); } else { isInitConfig = true; DeterMineCall(() => { if (_config != null&&_config.Init==true) { config = _config; } else { var cfgList = new List<ConfigList>(); var path = System.IO.Directory.GetCurrentDirectory() + "\\data\\" + _userName; if (System.IO.Directory.Exists(path)) cfgList = LocalCookie.ReadConfigFromDisk_ConfigList(path + "\\config.cfg"); foreach (var c in cfgList.Where(x=>x.ParentName=="defaultPage")) { _config=config = (ConfigList) c; } } SetConfigToControl(config); }); } }
public TicketMain(CookieContainer cookie,List<Nomal_Passengers> passenger, ConfigList cfg = null,Control frame=null) { InitializeComponent(); this._frame = frame; var buttonColumn = new DataGridViewDisableButtonColumn(); buttonColumn.Name = "BookTicket"; buttonColumn.DataPropertyName = "buttonTextInfo"; buttonColumn.HeaderText = "预 订"; buttonColumn.Width = 110; buttonColumn.DefaultCellStyle = new DataGridViewCellStyle() { Alignment = DataGridViewContentAlignment.MiddleCenter }; dgvTrainView.Columns.Add(buttonColumn); var trainno = new DataGridViewTextBoxColumn(); if (passenger != null) _passengersData.AddRange(passenger);// = passenger; else if (this._frame != null && ((TicketFrame)frame).Passengers.Count != 0) { _passengersData.AddRange(((TicketFrame)frame).Passengers); } trainno.Name = "train_no"; trainno.DataPropertyName = "train_no"; trainno.Visible = false; dgvTrainView.Columns.Add(trainno); //加载配置 if (cfg != null && !cfg.Init) { _config = cfg; _config.Init = true; DeterMineCall(() => { _userName = _config.User; cboFrom.Text = _config.From; cboTo.Text = _config.To; dtpRiqi.Value = _config.Date; cboShijian.Text = _config.Time; if (_config.Watched) { AutoPicker.Value = DateTime.Now; AutoPicker.Checked = true; } if (_config.Turn == true) { chkSelectTurn.Checked = true; turnDateTable = _config.TurnDates; } else { chkSelectTurn.Checked = false; } _QuickPassengers = _config.Passengers; //_QuickAddSeatType = _config.SeatTypes; //_QuickAddTrainData = _config.TrainNos; }); } ttt = new ToolTip() { IsBalloon = true }; InitCityCode(); cookieContainer = cookie; InitColumns(); InitSortInfo(); configList = new List<ConfigList>(); //dgvQuickTrainInfo.AutoGenerateColumns = false; FormThis = this; _trainData = new List<JsonTrainData>(); _BindingData = new BindingList<JsonTrainData>(_trainData); SafeTime = ((TicketFrame)(_frame)).SafeTime;//默认的订单提交安全期 //_passengersData = new List<Nomal_Passengers>(); //cboFrom.GotFocus += cboFrom_GotFocus; //cboTo.GotFocus += cboTo_GotFocus; cboFrom.TextUpdate += new EventHandler(cboFrom_TextUpdate); cboTo.TextUpdate += new EventHandler(cboTo_TextUpdate); _autoBooker = new AutoBooker(this); }
//初始化用户配置文件 private void InitConfig() { DeterMineCall(() => { lblVersion.Text = "Version " + Assembly.GetExecutingAssembly().GetName().Version.ToString(); config = LocalCookie.ReadConfigFromDisk_ConfigList(System.IO.Directory.GetCurrentDirectory() + "\\config.cfg"); if (config.User == user) { cboFrom.Text = config.From; cboTo.Text = config.To; dtpRiqi.Value = config.Date>=DateTime.Now?config.Date:DateTime.Now; cboShijian.Text = config.Time; if (config.Turn) { TurnDatesInit(); chkSelectTurn.Checked = true; fplTurnDates.Visible = true; foreach (var v in config.TurnDates.Keys) { for (int i = 0; i < flpTurnCheckBox.Controls.Count; i++) { if (flpTurnCheckBox.Controls[i].Text == v.ToString()) { ((CheckBox)flpTurnCheckBox.Controls[i]).Checked = true; turnDateTable.Add(v, config.TurnDates[v]); } } } } foreach (var v in config.Passengers.Keys) { for (int i = 1; i < flplPassengers.Controls.Count; i++) { if (v.ToString().Contains(flplPassengers.Controls[i].Text)) { ((CheckBox)flplPassengers.Controls[i]).Checked = true; } } } for (int i = 0; i < config.SeatTypes.Count; i++) { QuickAddSeatType(config.SeatTypes[i]); } for (int i = 0; i < config.TrainNos.Count; i++) { QuikAddTrainInfo(config.TrainNos[i]); } } }); }