void RefreshItemState(ListViewItem item) { if (item == null) { return; } var query = item.Tag as QueryParam; switch (query.QueryState) { case QueryState.None: item.ImageKey = "standby"; ListViewResource.SwitchListViewItemStyle(item, RowStyleType.RoyalBlue); item.Text = "等待查票"; break; case QueryState.Query: item.ImageKey = "query"; ListViewResource.SwitchListViewItemStyle(item, RowStyleType.LightGreen); item.Text = "查票中"; break; case QueryState.Wait: item.ImageKey = "wait"; ListViewResource.SwitchListViewItemStyle(item, RowStyleType.Olive); item.Text = "休息中"; break; default: break; } }
void DoImport(Entity.Web.Passenger[] list) { //去掉重复的。 var target = list .Where(s => s.Type != 3 && !Session.UserProfile.Passengers.Any(x => x.Name == s.Name && s.IdNo == x.IdNo) && !lst.Items.Cast <ListViewItem>().Any(x => x.Tag != null && (x.Tag as Entity.Web.Passenger).Name == s.Name && (x.Tag as Entity.Web.Passenger).IdNo == s.IdNo)).ToList(); if (target.Count == 0) { this.Information("没有可以导入的乘客信息,或所有的联系人已经在当前账号中导入."); return; } //追加 lst.Items.AddRange(target.Select(s => { var item = new ListViewItem(new[] { s.Name, ParamData.PassengerType.GetValue(s.Type), ParamData.PassengerIdType.GetValue(s.IdTypeCode), s.IdNo, s.MobileNo }, 0) { Tag = s }; ListViewResource.SwitchListViewItemStyle(item, RowStyleType.Blue); return(item); }).ToArray()); }
void BeginImport() { var target = lst.Items.Cast <ListViewItem>().Where(s => s.Tag != null).Select(s => new KeyValuePair <ListViewItem, Entity.Web.Passenger>(s, s.Tag as Entity.Web.Passenger)).ToQueue(); if (!target.Any()) { this.Information("没有需要要导入的联系人 ⊙﹏⊙!"); return; } ThreadPool.QueueUserWorkItem(_ => { AppContext.HostForm.Invoke(() => { btnOk.Enabled = false; loading.Visible = true; }); try { var worker = new Otn.Workers.PassengerManager() { Session = Session }; while (!_importCanceled && target.Count > 0) { var item = target.Dequeue(); AppContext.HostForm.Invoke(() => { item.Key.ImageIndex = 1; ListViewResource.SwitchListViewItemStyle(item.Key, RowStyleType.DeepBlue); item.Key.EnsureVisible(); }); var result = worker.AddPassenger(item.Value); if (result.IsNullOrEmpty()) { AppContext.HostForm.Invoke(() => { item.Key.ImageIndex = 2; ListViewResource.SwitchListViewItemStyle(item.Key, RowStyleType.Green); item.Key.Tag = null; }); } else { AppContext.HostForm.Invoke(() => { item.Key.ImageIndex = 3; ListViewResource.SwitchListViewItemStyle(item.Key, RowStyleType.Red); item.Key.Tag = null; }); } } } catch (Exception ex) { this.Error("导入的过程中出现错误:" + ex.ToString()); Trace.TraceError(ex.ToString()); } AppContext.HostForm.Invoke(() => { btnOk.Enabled = true; loading.Visible = false; if (!_importCanceled) { this.Information("导入完成 ♪(´▽`)"); } DialogResult = DialogResult.OK; Close(); }); }); }