/// <summary> /// 确定索引 {1、按第一列索引;2、如果没有则按照第二列索引;} /// </summary> private void Index(string strInput) { if (txbDisplay.Text.Trim() == "") { return; } lsvContext.SelectedItems.Clear(); string strTem = ""; int i; for (int i1 = 0; i1 < lsvContext.Columns.Count; i1++) { if (IsIndex(i1)) //判断本字段是否要索引 { foreach (ListViewItem lsvItem in lsvContext.Items) { strTem = lsvItem.SubItems[i1].Text.ToLower(); i = strTem.IndexOf(strInput.ToLower()); if (i == 0) { lsvItem.Selected = true; lsvContext.EnsureVisible(lsvItem.Index); break; } } if (lsvContext.SelectedItems.Count > 0) { break; } } } }
NewEvent(object sender, System.EventArgs e) { KeyEventItem kei = textspy.kei; string strEvent = ""; string strChar = ""; string strCode = ""; string strValue = ""; string strMod = ""; // Fetch event name. switch (kei.etype) { case EventType.Event_KeyDown: strEvent = "KeyDown"; break; case EventType.Event_KeyPress: strEvent = "KeyPress"; break; case EventType.Event_KeyUp: strEvent = "KeyUp"; break; case EventType.Event_GotFocus: strEvent = "GotFocus"; break; case EventType.Event_LostFocus: strEvent = "LostFocus"; break; } // Fill in event details. if (kei.etype == EventType.Event_KeyUp || kei.etype == EventType.Event_KeyDown) { strCode = kei.eUpDown.KeyCode.ToString(); strValue = kei.eUpDown.KeyValue.ToString(); strMod = ((kei.eUpDown.Control) ? "C" : " ") + ((kei.eUpDown.Alt) ? "A" : " ") + ((kei.eUpDown.Shift) ? "S" : " "); } if (kei.etype == EventType.Event_KeyPress) { strChar = kei.ePress.KeyChar.ToString(); } ListViewItem lvi = new ListViewItem(strEvent); lvi.SubItems.Add(strChar); lvi.SubItems.Add(strCode); lvi.SubItems.Add(strValue); lvi.SubItems.Add(strMod); lviewOutput.Items.Add(lvi); int iItem = lviewOutput.Items.Count - 1; lviewOutput.EnsureVisible(iItem); }
//添加单行数据 public void AddListViewData(ListView list, Dictionary<string, string> data) { if (list.InvokeRequired)//不能访问就创建委托 { ListViewDelegate d = new ListViewDelegate(AddListViewData); list.Invoke(d, new object[] { list, data }); } else { list.BeginUpdate(); ListViewItem list_item = new ListViewItem(); bool need_init = true; foreach (KeyValuePair<string, string> cell in data) { ListViewItem.ListViewSubItem list_sub_item = new ListViewItem.ListViewSubItem(); if (need_init) { list_item.Text = cell.Value; need_init = false; } else { list_sub_item.Text = cell.Value; list_item.SubItems.Add(list_sub_item); } } list.Items.Add(list_item); list.EnsureVisible(list.Items.Count - 1); list.EndUpdate(); } }
void doSort(ListView lv) { lv.Sort(); if (lv.Items.Count > 0) lv.AutoResizeColumns(ColumnHeaderAutoResizeStyle.ColumnContent); if (lv.SelectedItems.Count > 0) lv.EnsureVisible(lv.SelectedIndices[0]); }
private void listView_VisibleChanged(object sender, EventArgs e) { ListView.SelectedListViewItemCollection selection = listView.SelectedItems; if (listView.SelectedItems.Count > 0 && listView.Visible) { listView.EnsureVisible(listView.SelectedItems[0].Index); } }
public void ListViewBuilder(ListView listView, Color? color = null, int columnFullWidth = 99, params string[] value) { listView.Items.Add(new ListViewItem(value)); if (color != null) { listView.Items[listView.Items.Count - 1].ForeColor = (Color)color; } listView.EnsureVisible(listView.Items.Count - 1); ListViewResizeColumn(listView, columnFullWidth); }
private void AddPacket(TimePacket packet) { PacketListViewItem item = new PacketListViewItem(packet, m_BaseTime, m_LastTime); lvPackets.Items.Add(item); if (m_AutoScrolling) { lvPackets.EnsureVisible(lvPackets.Items.Count - 1); } m_LastTime = packet.Time; }
private void MoveSelectedItem(System.Windows.Forms.ListView lv, int idx, bool moveUp) { // Gotta have >1 item in order to move if (lv.Items.Count < 1) { return; } int offset = 0; if (idx >= 0) { if (moveUp) { offset = -1; } else { // ignore movedown of last item if (idx < (lv.Items.Count - 1)) { offset = 1; } } } if (offset == 0) { return; } mbIgnoreChange = true; lv.BeginUpdate(); int selitem = idx + offset; for (int i = 0; i < lv.Items[idx].SubItems.Count; i++) { string cache = lv.Items[selitem].SubItems[i].Text; lv.Items[selitem].SubItems[i].Text = lv.Items[idx].SubItems[i].Text; lv.Items[idx].SubItems[i].Text = cache; } lv.Focus(); lv.Items[idx].Selected = false; lv.Items[selitem].Selected = true; lv.EnsureVisible(selitem); mbIgnoreChange = false; lv.EndUpdate(); SyncData(); }
// Based upon http://www.knowdotnet.com/articles/listviewmoveitem.html public static void MoveSelectedItem(System.Windows.Forms.ListView lv, int idx, bool moveUp) { // Gotta have >1 item in order to move if (lv.Items.Count > 1) { int offset = 0; if (idx >= 0) { if (moveUp) { // ignore moveup of row(0) offset = -1; } else { // ignore movedown of last item if (idx < (lv.Items.Count - 1)) { offset = 1; } } } if (offset != 0) { lv.BeginUpdate(); int selitem = idx + offset; if (selitem >= 0) { for (int i = 0; i < lv.Items[idx].SubItems.Count; i++) { string cache = lv.Items[selitem].SubItems[i].Text; lv.Items[selitem].SubItems[i].Text = lv.Items[idx].SubItems[i].Text; lv.Items[idx].SubItems[i].Text = cache; } var tagIdx = lv.Items[selitem].Tag; var tagSel = lv.Items[idx].Tag; lv.Items[selitem].Tag = tagSel; lv.Items[idx].Tag = tagIdx; lv.Focus(); lv.Items[selitem].Selected = true; lv.EnsureVisible(selitem); } lv.EndUpdate(); } } }
public void AsyncUpdateLog(PacketLogEntry logEntry) { if (menuItemPause.Checked) { return; } AddListItem(logEntry); if (!ListViewPackets.Focused && ListViewPackets.Items.Count > 0) { ListViewPackets.EnsureVisible(ListViewPackets.Items.Count - 1); } }
public void EnsureListViewItemVisible( System.Windows.Forms.ListView p_oListView, int p_intItem) { if (p_oListView.InvokeRequired) { EnsureListViewItemVisibleCallback d = new EnsureListViewItemVisibleCallback(EnsureListViewItemVisible); p_oListView.Invoke( d, new object[] { p_oListView, p_intItem }); } else { p_oListView.EnsureVisible(p_intItem); } }
public static void SelectListItem(ListView lst, int index) { if (lst.Items.Count > 0) { foreach (ListViewItem v in lst.Items) { if (v.Index == index) { v.Focused = true; v.Selected = true; lst.EnsureVisible(index); break; } } } }
private void loadGroups() { // carregar informação da base de dados IDbConnection conn = GisaDataSetHelper.GetConnection(); try { conn.Open(); TrusteeRule.Current.LoadGroupsData(GisaDataSetHelper.GetInstance(), conn); } finally { conn.Close(); } lstVwTrustees.Items.Clear(); ListViewItem item = null; foreach (GISADataset.TrusteeRow t in GisaDataSetHelper.GetInstance().Trustee) { #if TESTING if (t.CatCode == "GRP") { item = lstVwTrustees.Items.Add(""); updateListViewItem(item, t); if (t.BuiltInTrustee) { item.ForeColor = System.Drawing.Color.Gray; } } #else if (t.CatCode == "GRP" && ! t.BuiltInTrustee) { item = lstVwTrustees.Items.Add(""); updateListViewItem(item, t); } #endif } lstVwTrustees.Sort(); if (lstVwTrustees.Items.Count > 0) { lstVwTrustees.EnsureVisible(0); lstVwTrustees.Items[0].Selected = true; } }
private static void SynchronizeCursor(ListView first, ListView second) { if (first.SelectedIndices.Count > 0) { int index = first.SelectedIndices[0]; if (index < second.Items.Count) { second.SelectedIndices.Add(index); second.EnsureVisible(index); } } }
// 根据册条码号或者记录路径,装入册记录 // parameters: // strBarcodeOrRecPath 册条码号或者记录路径。如果内容前缀为"@path:"则表示为路径 // strMatchLocation 附加的馆藏地点匹配条件。如果==null,表示没有这个附加条件(注意,""和null含义不同,""表示确实要匹配这个值) // return: // -2 册条码号或者记录路径已经在list中存在了(行没有加入listview中) // -1 出错(注意表示出错的行已经加入listview中了) // 0 因为馆藏地点不匹配,没有加入list中 // 1 成功 int LoadOneItem( string strPubType, string strBarcodeOrRecPath, RecordInfo info, ListView list, string strMatchLocation, out string strOutputItemRecPath, ref ListViewItem item, out string strError) { strError = ""; strOutputItemRecPath = ""; long lRet = 0; // 判断是否有 @path: 前缀,便于后面分支处理 bool bIsRecPath = StringUtil.HasHead(strBarcodeOrRecPath, "@path:"); string strItemText = ""; string strBiblioText = ""; // string strItemRecPath = ""; string strBiblioRecPath = ""; XmlDocument item_dom = null; string strBiblioSummary = ""; string strISBnISSN = ""; if (info == null) { byte[] item_timestamp = null; REDO_GETITEMINFO: lRet = Channel.GetItemInfo( stop, strBarcodeOrRecPath, "xml", out strItemText, out strOutputItemRecPath, out item_timestamp, "recpath", out strBiblioText, out strBiblioRecPath, out strError); if (lRet == -1) { DialogResult temp_result = MessageBox.Show(this, strError + "\r\n\r\n是否重试?", "AccountBookForm", MessageBoxButtons.RetryCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1); if (temp_result == DialogResult.Retry) goto REDO_GETITEMINFO; } if (lRet == -1 || lRet == 0) { #if NO if (item == null) { item = new ListViewItem(strBarcodeOrRecPath, 0); list.Items.Add(item); } else { Debug.Assert(item.ListView == list, ""); } // item.SubItems.Add(strError); ListViewUtil.ChangeItemText(item, COLUMN_ERRORINFO, strError); SetItemColor(item, TYPE_ERROR); // 将新加入的事项滚入视野 list.EnsureVisible(list.Items.IndexOf(item)); #endif SetError(list, ref item, strBarcodeOrRecPath, strError); goto ERROR1; } SummaryInfo summary = (SummaryInfo)this.m_summaryTable[strBiblioRecPath]; if (summary != null) { strBiblioSummary = summary.Summary; strISBnISSN = summary.ISBnISSn; } if (strBiblioSummary == "" && this.checkBox_load_fillBiblioSummary.Checked == true) { string[] formats = new string[2]; formats[0] = "summary"; formats[1] = "@isbnissn"; string[] results = null; byte[] timestamp = null; stop.SetMessage("正在装入书目记录 '" + strBiblioRecPath + "' 的摘要 ..."); Debug.Assert(String.IsNullOrEmpty(strBiblioRecPath) == false, "strBiblioRecPath值不能为空"); REDO_GETBIBLIOINFO: lRet = Channel.GetBiblioInfos( stop, strBiblioRecPath, "", formats, out results, out timestamp, out strError); if (lRet == -1) { DialogResult temp_result = MessageBox.Show(this, strError + "\r\n\r\n是否重试?", "AccountBookForm", MessageBoxButtons.RetryCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1); if (temp_result == DialogResult.Retry) goto REDO_GETBIBLIOINFO; } if (lRet == -1 || lRet == 0) { if (lRet == 0 && String.IsNullOrEmpty(strError) == true) strError = "书目记录 '" + strBiblioRecPath + "' 不存在"; strBiblioSummary = "获得书目摘要时发生错误: " + strError; } else { Debug.Assert(results != null && results.Length == 2, "results必须包含2个元素"); strBiblioSummary = results[0]; strISBnISSN = results[1]; // 避免cache占据的内存太多 if (this.m_summaryTable.Count > 1000) this.m_summaryTable.Clear(); if (summary == null) { summary = new SummaryInfo(); summary.Summary = strBiblioSummary; summary.ISBnISSn = strISBnISSN; this.m_summaryTable[strBiblioRecPath] = summary; } } } // 剖析一个册的xml记录,取出有关信息放入listview中 if (item_dom == null) { item_dom = new XmlDocument(); try { item_dom.LoadXml(strItemText); } catch (Exception ex) { strError = "册记录的XML装入DOM时出错: " + ex.Message; goto ERROR1; } } } else { // record 不为空调用时,对调用时参数strBarcodeOrRecPath不作要求 strBarcodeOrRecPath = "@path:" + info.Record.Path; bIsRecPath = true; if (info.Record.RecordBody.Result.ErrorCode != ErrorCodeValue.NoError) { #if NO if (item == null) item = new ListViewItem(strBarcodeOrRecPath, 0); item.SubItems.Add(info.Record.RecordBody.Result.ErrorString); SetItemColor(item, TYPE_ERROR); list.Items.Add(item); // 将新加入的事项滚入视野 list.EnsureVisible(list.Items.Count - 1); #endif SetError(list, ref item, strBarcodeOrRecPath, info.Record.RecordBody.Result.ErrorString); goto ERROR1; } strItemText = info.Record.RecordBody.Xml; strOutputItemRecPath = info.Record.Path; // item_dom = info.Dom; strBiblioRecPath = info.BiblioRecPath; if (info.SummaryInfo != null) { strBiblioSummary = info.SummaryInfo.Summary; strISBnISSN = info.SummaryInfo.ISBnISSn; } } // 附加的馆藏地点匹配 if (strMatchLocation != null) { // TODO: #reservation, 情况如何处理? string strLocation = DomUtil.GetElementText(item_dom.DocumentElement, "location"); // 2013/3/26 if (strLocation == null) strLocation = ""; if (strMatchLocation != strLocation) return 0; } if (item == null) { item = AddToListView(list, item_dom, strOutputItemRecPath, strBiblioSummary, strISBnISSN, strBiblioRecPath); // 图标 // item.ImageIndex = TYPE_NORMAL; SetItemColor(item, TYPE_NORMAL); // 将新加入的事项滚入视野 list.EnsureVisible(list.Items.Count - 1); #if NO // 填充需要从订购库获得的栏目信息 if (this.checkBox_load_fillOrderInfo.Checked == true) FillOrderColumns(item, strPubType); #endif } else { SetListViewItemText(item_dom, true, strOutputItemRecPath, strBiblioSummary, strISBnISSN, strBiblioRecPath, item); SetItemColor(item, TYPE_NORMAL); } return 1; ERROR1: return -1; }
internal override void SetError(ListView list, ref ListViewItem item, string strBarcodeOrRecPath, string strError) { // 确保线程安全 2014/9/3 if (list != null && list.InvokeRequired) { Delegate_SetError d = new Delegate_SetError(SetError); object[] args = new object[4]; args[0] = list; args[1] = item; args[2] = strBarcodeOrRecPath; args[3] = strError; this.Invoke(d, args); // 取出 ref 参数值 item = (ListViewItem)args[1]; return; } if (item == null) { item = new ListViewItem(strBarcodeOrRecPath, 0); list.Items.Add(item); } else { Debug.Assert(item.ListView == list, ""); } // item.SubItems.Add(strError); ListViewUtil.ChangeItemText(item, COLUMN_ERRORINFO, strError); SetItemColor(item, TYPE_ERROR); // 将新加入的事项滚入视野 list.EnsureVisible(list.Items.IndexOf(item)); }
private static void UpdateFileListFiltered(ListView listView, IEnumerable<ListViewItem> items, string filter) { var selection = new Pair<ListViewItem, int>(); foreach (var item in items) { item.Selected = false; var filterPos = item.Text.IndexOf( filter, StringComparison.CurrentCultureIgnoreCase); if (filterPos < 0) continue; if (selection.First == null) selection = new Pair<ListViewItem, int>(item, filterPos); else if ((filterPos == 0) && (selection.Second != 0)) selection = new Pair<ListViewItem, int>(item, filterPos); listView.Items.Add(item); } if (selection.First == null) return; selection.First.Selected = true; listView.EnsureVisible(selection.First.Index); }
// Hey //[Test] public void EnsureVisibleTest () { Form myform = new Form (); myform.ShowInTaskbar = false; myform.Visible = true; ListView mylistview = new ListView (); mylistview.Items.Add ("A"); myform.Controls.Add (mylistview); mylistview.BeginUpdate (); for(int x = 1 ; x < 5000 ; x++) { mylistview.Items.Add ("Item " + x.ToString()); } mylistview.EndUpdate (); mylistview.EnsureVisible (4999); myform.Dispose (); }
private void doEnsureVisible(ListView listView, ListViewItem item) { int index = listView.Items.IndexOf(item); if (index < 0) return; if (listView.Items.Count > index + 2) listView.EnsureVisible(index + 2); else if (listView.Items.Count > index + 1) listView.EnsureVisible(index + 1); else listView.EnsureVisible(index); }
public override void ModelToView() { IsPopulated = false; ControloRevisoes1.ControloAutores1.LoadAndPopulateAuthors(); if (SessionHelper.GetGisaPrincipal().TrusteeUserAuthor != null) { ControloRevisoes1.ControloAutores1.SelectedAutor = SessionHelper.GetGisaPrincipal().TrusteeUserAuthor.TrusteeRow; } txtIdentificadorRegisto.Text = CurrentControloAut.ID.ToString(); if (!(CurrentControloAut.IsRegrasConvencoesNull())) { txtRegrasConvencoes.Text = CurrentControloAut.RegrasConvencoes; } else { txtRegrasConvencoes.Text = ""; } if (!(CurrentControloAut.IsObservacoesNull())) { txtObservacoes.Text = CurrentControloAut.Observacoes; } else { txtObservacoes.Text = ""; } lstVwIdentidadeInstituicoes.Items.Clear(); foreach (GISADataset.ControloAutRelRow carRow in GisaDataSetHelper.GetInstance().ControloAutRel.Select(QueryFilter)) { AddIdentidadeInstituicao(carRow); } UpdateLstVwIdentidadeInstituicoesButtonsState(); // populate datas criacao history lstVwDataCriacaoRevisao.Items.Clear(); ListViewItem item = null; foreach (GISADataset.ControloAutDataDeDescricaoRow cadddRow in GisaDataSetHelper.GetInstance().ControloAutDataDeDescricao.Select(QueryFilter, "DataEdicao DESC")) { item = lstVwDataCriacaoRevisao.Items.Add(""); item.SubItems.AddRange(new string[] { "", "", "" }); item.SubItems[colDataRegisto.Index].Text = cadddRow.DataEdicao.ToString(); item.SubItems[colDataDescricao.Index].Text = string.Format("{0:yyyy}-{0:MM}-{0:dd}", cadddRow.DataAutoria); if (SessionHelper.AppConfiguration.GetCurrentAppconfiguration().TipoServer.ID == Convert.ToInt64(TipoServer.ClienteServidor)) { item.SubItems[colOperator.Index].Text = cadddRow.TrusteeUserRowByTrusteeUserControloAutDataDeDescricao.TrusteeRow.Name; } if (!cadddRow.IsIDTrusteeAuthorityNull()) { item.SubItems[colAuthority.Index].Text = cadddRow.TrusteeUserRowByTrusteeUserControloAutDataDeDescricaoAuthority.TrusteeRow.Name; } item.Tag = cadddRow; } lstVwDataCriacaoRevisao.SelectedItems.Clear(); // the following should ensure the list was scrolled all the // way to the bottom. it doesn't always not working though. if (lstVwDataCriacaoRevisao.Items.Count > 0) { lstVwDataCriacaoRevisao.EnsureVisible(0); } // populate linguas ArrayList Iso639Data = new ArrayList(); GISADataset.Iso639Row i639Row = (GISADataset.Iso639Row)(GisaDataSetHelper.GetInstance().Iso639.NewRow()); i639Row.ID = -1; i639Row.LanguageNameEnglish = ""; Iso639Data.Add(i639Row); Iso639Data.AddRange(GisaDataSetHelper.GetInstance().Iso639.Select()); cbLingua.DataSource = Iso639Data; cbLingua.DisplayMember = "LanguageNameEnglish"; cbLingua.ValueMember = "ID"; try { cbLingua.SelectedValue = CurrentControloAut.IDIso639p2; } catch (StrongTypingException) { cbLingua.SelectedValue = -1; } // populate alfabetos ArrayList Iso15924Data = new ArrayList(); GISADataset.Iso15924Row i15924Row = (GISADataset.Iso15924Row)(GisaDataSetHelper.GetInstance().Iso15924.NewRow()); i15924Row.ID = -1; i15924Row.ScriptNameEnglish = ""; Iso15924Data.Add(i15924Row); Iso15924Data.AddRange(GisaDataSetHelper.GetInstance().Iso15924.Select()); cbAlfabeto.DataSource = Iso15924Data; cbAlfabeto.DisplayMember = "ScriptNameEnglish"; cbAlfabeto.ValueMember = "ID"; try { cbAlfabeto.SelectedValue = CurrentControloAut.IDIso15924; } catch (StrongTypingException) { cbAlfabeto.SelectedValue = -1; } // populate checkboxes chkDefinitivo.Checked = CurrentControloAut.Autorizado; chkCompleta.Checked = CurrentControloAut.Completo; IsPopulated = true; }
/// <summary> /// Flushes the output. /// </summary> /// <param name="lv"> /// The lv. /// </param> private void FlushOutput(ListView lv) { if (this.InvokeRequired) { this.BeginInvoke(new FlushOutputDelegate(this.FlushOutput), new object[] { lv }); return; } if (this.lvitems.Count > 0) { if (lv.Items.Count >= Convert.ToInt32(ScreenLines)) { lv.Items.Clear(); } lv.BeginUpdate(); lv.Items.AddRange(this.lvitems.ToArray()); lv.EnsureVisible(lv.Items.Count - 1); lv.EndUpdate(); this.lvitems.Clear(); } }
public void DownloadSpoiler(XmlDocument xSet, XmlDocument xSetLang, ListView list, ProgressBar progressBar) { mList = list; ListViewItem item; if(Directory.Exists("cards")) Directory.Delete("cards", true); Directory.CreateDirectory("cards"); foreach(XmlNode nodeSet in xSet.DocumentElement.SelectNodes("card_sets/item")) { string setCode = nodeSet.Attributes["code"].Value; string setName = xSetLang.DocumentElement.SelectSingleNode("card_sets_lang/item[@code='" + setCode + "' and @language='ENG']/@name").InnerText; if(setCode != "M12") continue; string cardsPath = "cards\\" + setCode + ".xml"; string cardsLangPath = "cards\\" + setCode + ".eng.xml"; if(File.Exists(cardsPath)) File.Delete(cardsPath); if(File.Exists(cardsLangPath)) File.Delete(cardsLangPath); XmlDocument xCards = new XmlDocument(); xCards.LoadXml("<cards />"); XmlDocument xCardsLang = new XmlDocument(); xCardsLang.LoadXml("<cards />"); DateTime setDate = XmlConvert.ToDateTime(nodeSet.Attributes["releaseDate"].Value, "yyyy-MM-ddTHH:mm:ss"); xCards.DocumentElement.Attributes.Append(xCards.CreateAttribute("releaseDate")).Value = setDate.ToString("yyyy-MM-ddTHH:mm:ss"); xCards.DocumentElement.Attributes.Append(xCards.CreateAttribute("code")).Value = setCode; xCardsLang.DocumentElement.Attributes.Append(xCardsLang.CreateAttribute("name")).Value = setName; string contentTextPath = Path.Combine(Path.Combine(CARDS_DIRPATH, setCode), "CONTENT.txt"); string contentXmlPath = Path.Combine(Path.Combine(CARDS_DIRPATH, setCode), "CONTENT.xml"); string listPath = Path.Combine(Path.Combine(CARDS_DIRPATH, setCode), "list.xml"); item = new ListViewItem(setCode); ListViewItem.ListViewSubItem subItem = item.SubItems.Add("Working..."); mList.Items.Add(item); mList.EnsureVisible(mList.Items.Count - 1); Application.DoEvents(); progressBar.Minimum = 0; progressBar.Step = 1; progressBar.Value = 0; XmlDocument xCardList = new XmlDocument(); xCardList.Load(listPath); XmlDocument xContent = new XmlDocument(); string allContent; if(!File.Exists(contentTextPath)) { // download page content subItem.Text = "Downloading..."; mList.FindForm().Refresh(); Application.DoEvents(); allContent = string.Empty; xContent.LoadXml("<content />"); progressBar.Maximum = xCardList.SelectNodes("//card").Count; foreach(XmlNode cardNode in xCardList.SelectNodes("//card")) { string id = cardNode.SelectSingleNode("@id").InnerText; string content = Download(URL_SPOILER + id); allContent += content; XmlNode nodeContent = xContent.ImportNode(GetDocument(content).DocumentElement, true); xContent.DocumentElement.AppendChild(nodeContent); progressBar.PerformStep(); mList.FindForm().Refresh(); Application.DoEvents(); } File.WriteAllText(contentTextPath, allContent); xContent.Save(contentXmlPath); subItem.Text = "OK!"; mList.FindForm().Refresh(); Application.DoEvents(); } subItem.Text = "Creating..."; mList.FindForm().Refresh(); Application.DoEvents(); xContent.Load(contentXmlPath); progressBar.Value = 0; progressBar.Maximum = xContent.DocumentElement.SelectNodes("td").Count; XmlNodeList cardListNodes = xCardList.DocumentElement.SelectNodes("card"); XmlNodeList contentNodes = xContent.DocumentElement.SelectNodes("td"); for(int i = 0; i < cardListNodes.Count; i++) { SpoilerReader spoilerReader = new SpoilerReader(cardListNodes[i].SelectSingleNode("@name").InnerText, cardListNodes[i].SelectSingleNode("@color").InnerText); spoilerReader.CreateCardNode(contentNodes[i], xCards, xCardsLang, setCode, setDate, i + 1); progressBar.PerformStep(); mList.FindForm().Refresh(); Application.DoEvents(); } subItem.Text = "OK!"; mList.FindForm().Refresh(); Application.DoEvents(); xCards.Save(cardsPath); xCardsLang.Save(cardsLangPath); } }
/// <summary> /// Thread for actual moving /// </summary> public void Movement() { MovementDirection bForward = MovementDirection.Forward; if (_bKeepRunning) { //dont let the user change where we are going while we run cbxDestinations.Enabled = false; cbxPatrolAreas.Enabled = false; PatrolArea patrolarea; try { patrolarea = _patrolareas.GetPatrolArea(cbxPatrolAreas.SelectedItem.ToString()); } catch (Exception E) { MessageBox.Show(E.Message, "Load Area Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } //clear display of last time we ran lvwDisplay.Items.Clear(); //determine direction bForward = FindDirection(); //set patrolareas direction patrolarea.Direction = bForward; //find closest and set waypoint internal iterator to next waypoint in the correct direction //this also sets the waypoint internal direction setting Waypoint wpt = patrolarea.FindClosest(bForward); //get the next waypoint in the correct direction wpt = patrolarea.GetNextWaypoint(); //run through all the waypoints while (wpt != null && _bKeepRunning && _ak.GameProcess != 0) { //update the display ListViewItem lvi = new ListViewItem(wpt.Name, 0); lvi.SubItems.Add(wpt.X.ToString() + ", " + wpt.Y.ToString()); lvi.SubItems.Add(_ak.ZDistance(_ak.gPlayerXCoord, _ak.gPlayerYCoord, _ak.gPlayerZCoord, wpt.X, wpt.Y, wpt.Z).ToString("N")); lvwDisplay.Items.Add(lvi); lvwDisplay.EnsureVisible(lvwDisplay.Items.Count - 1); wpt.MoveTo(250, false, cbxStopOnDamage.Checked); //have we gotten to the selected destination? if (cbxDestinations.SelectedIndex != -1 && wpt.Name == cbxDestinations.SelectedItem.ToString()) { break; } //get the next waypoint in the correct direction wpt = patrolarea.GetNextWaypoint(); } _ak.StopRunning(); string status = "Reached Destination"; if (!_bKeepRunning) { status = "Stopped"; } ListViewItem doneLVI = new ListViewItem(status, 0); lvwDisplay.Items.Add(doneLVI); lvwDisplay.EnsureVisible(lvwDisplay.Items.Count - 1); _bKeepRunning = false; //done running, let them change destinations again cbxDestinations.Enabled = true; cbxPatrolAreas.Enabled = true; } }
private static bool FindFirstInProductList(ListView list, ProductSearchSettings settings) { foreach (ListViewItem lvi in list.Items) lvi.Selected = false; if (settings.SearchStartingRow >= list.Items.Count) return false; for (int i = settings.SearchStartingRow; i < list.Items.Count; i++) { ListViewItem lvi = list.Items[i]; if (FindInItem(lvi, settings)) { lvi.Selected = true; settings.SearchStartingRow = i + 1; list.EnsureVisible(i); return true; } } return false; }
private void AddKeyToScript(ListView listview) { if (m_selectedKey == null) return; listview.Items.Add((ListViewItem)m_selectedKey.Clone()); listview.EnsureVisible(listview.Items.Count - 1); AutoCheckValidity(); }
internal override void SetError(ListView list, ref ListViewItem item, string strBarcodeOrRecPath, string strError) { if (item == null) { item = new ListViewItem(strBarcodeOrRecPath, 0); list.Items.Add(item); } else { Debug.Assert(item.ListView == list, ""); } // item.SubItems.Add(strError); ListViewUtil.ChangeItemText(item, COLUMN_ERRORINFO, strError); SetItemColor(item, TYPE_ERROR); // 将新加入的事项滚入视野 list.EnsureVisible(list.Items.IndexOf(item)); }
/// <summary> /// Runs all test cases and displays the results. /// </summary> private void Run() { TsCHdaItem[] items = null; try { // clear existing results. resultsLv_.Items.Clear(); // free the existing dataset. if (mDataset_ != null) { mDataset_.Dispose(); mDataset_ = null; } // load the dataset. TestData[] tests = LoadDataSet(); if (tests == null) { return; } // create the item. OpcItemResult[] results = mServer_.CreateItems(new OpcItem[] { new OpcItem(mItemId_) }); if (results == null || results.Length != 1) { //throw new InvalidResponseException(); } // return items. items = new TsCHdaItem[] { new TsCHdaItem(results[0]) }; // execute test cases. foreach (TestData test in tests) { ExecuteTest(test, items); } // adjust columns. AdjustColumns(); // scroll to the first failed result. for (int ii = 0; ii < resultsLv_.Items.Count; ii++) { if (resultsLv_.Items[ii].ForeColor == Color.Red) { resultsLv_.EnsureVisible(ii); break; } } } finally { if (items != null) { try { mServer_.ReleaseItems(items); } catch {} } } }
// 根据册条码号或者记录路径,装入册记录 // parameters: // strBarcodeOrRecPath 册条码号或者记录路径。如果内容前缀为"@path:"则表示为路径 // strMatchLocation 附加的馆藏地点匹配条件。如果==null,表示没有这个附加条件(注意,""和null含义不同,""表示确实要匹配这个值) // return: // -2 册条码号或者记录路径已经在list中存在了(行没有加入listview中) // -1 出错(注意表示出错的行已经加入listview中了) // 0 因为馆藏地点不匹配,没有加入list中 // 1 成功 internal virtual int LoadOneItem( string strPubType, bool bFillSummaryColumn, string[] summary_col_names, string strBarcodeOrRecPath, RecordInfo info, ListView list, string strMatchLocation, out string strOutputItemRecPath, ref ListViewItem item, out string strError) { strError = ""; strOutputItemRecPath = ""; long lRet = 0; // 判断是否有 @path: 前缀,便于后面分支处理 bool bIsRecPath = StringUtil.HasHead(strBarcodeOrRecPath, "@path:"); string strItemText = ""; string strBiblioText = ""; // string strItemRecPath = ""; string strBiblioRecPath = ""; XmlDocument item_dom = null; #if NO string strBiblioSummary = ""; string strISBnISSN = ""; #endif SummaryInfo summary = null; byte[] item_timestamp = null; if (info == null) { REDO_GETITEMINFO: lRet = Channel.GetItemInfo( stop, strBarcodeOrRecPath, "xml", out strItemText, out strOutputItemRecPath, out item_timestamp, "recpath", out strBiblioText, out strBiblioRecPath, out strError); if (lRet == -1) { DialogResult temp_result = MessageBox.Show(this, strError + "\r\n\r\n是否重试?", this.FormCaption, MessageBoxButtons.RetryCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1); if (temp_result == DialogResult.Retry) goto REDO_GETITEMINFO; } if (lRet == -1 || lRet == 0) { SetError(list, ref item, strBarcodeOrRecPath, strError); goto ERROR1; } summary = (SummaryInfo)this.m_summaryTable[strBiblioRecPath]; if (summary != null) { #if NO strBiblioSummary = summary.Summary; strISBnISSN = summary.ISBnISSn; #endif } if (summary == null && bFillSummaryColumn == true) { string[] results = null; byte[] timestamp = null; stop.SetMessage("正在装入书目记录 '" + strBiblioRecPath + "' 的摘要 ..."); Debug.Assert(String.IsNullOrEmpty(strBiblioRecPath) == false, "strBiblioRecPath值不能为空"); REDO_GETBIBLIOINFO: lRet = Channel.GetBiblioInfos( stop, strBiblioRecPath, "", summary_col_names, out results, out timestamp, out strError); if (lRet == -1) { DialogResult temp_result = MessageBox.Show(this, strError + "\r\n\r\n是否重试?", this.FormCaption, MessageBoxButtons.RetryCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1); if (temp_result == DialogResult.Retry) goto REDO_GETBIBLIOINFO; } if (lRet == -1 || lRet == 0) { if (lRet == 0 && String.IsNullOrEmpty(strError) == true) strError = "书目记录 '" + strBiblioRecPath + "' 不存在"; // strBiblioSummary = "获得书目摘要时发生错误: " + strError; summary = new SummaryInfo(); summary.Values = new string[1]; summary.Values[0] = "获得书目摘要时发生错误: " + strError; } else { Debug.Assert(results != null && results.Length == summary_col_names.Length, "results必须包含 " + summary_col_names.Length + " 个元素"); #if NO strBiblioSummary = results[0]; strISBnISSN = results[1]; #endif // 避免cache占据的内存太多 if (this.m_summaryTable.Count > 1000) this.m_summaryTable.Clear(); if (summary == null) { summary = new SummaryInfo(); summary.Values = new string[summary_col_names.Length]; for (int j = 0; j < summary_col_names.Length; j++) { summary.Values[j] = results[j]; } this.m_summaryTable[strBiblioRecPath] = summary; } } } // 剖析一个册的xml记录,取出有关信息放入listview中 if (item_dom == null) { item_dom = new XmlDocument(); try { item_dom.LoadXml(strItemText); } catch (Exception ex) { strError = "册记录的XML装入DOM时出错: " + ex.Message; goto ERROR1; } } } else { // record 不为空调用时,对调用时参数strBarcodeOrRecPath不作要求 strBarcodeOrRecPath = "@path:" + info.Record.Path; bIsRecPath = true; if (info.Record.RecordBody.Result.ErrorCode != ErrorCodeValue.NoError) { SetError(list, ref item, strBarcodeOrRecPath, info.Record.RecordBody.Result.ErrorString); goto ERROR1; } strItemText = info.Record.RecordBody.Xml; strOutputItemRecPath = info.Record.Path; // 2013/4/3 if (info.Record.RecordBody != null) item_timestamp = info.Record.RecordBody.Timestamp; // item_dom = info.Dom; strBiblioRecPath = info.BiblioRecPath; if (info.SummaryInfo != null) { #if NO strBiblioSummary = info.SummaryInfo.Summary; strISBnISSN = info.SummaryInfo.ISBnISSn; #endif summary = info.SummaryInfo; } } // 附加的馆藏地点匹配 if (strMatchLocation != null) { // TODO: #reservation, 情况如何处理? string strLocation = DomUtil.GetElementText(item_dom.DocumentElement, "location"); // 2013/3/26 if (strLocation == null) strLocation = ""; if (strMatchLocation != strLocation) return 0; } if (item == null) { item = AddToListView(list, item_dom, item_timestamp, strOutputItemRecPath, strBiblioRecPath, #if NO strBiblioSummary, strISBnISSN, #endif summary_col_names, summary); // 将新加入的事项滚入视野 list.EnsureVisible(list.Items.Count - 1); #if NO // 填充需要从订购库获得的栏目信息 if (this.checkBox_load_fillOrderInfo.Checked == true) FillOrderColumns(item, strPubType); #endif } else { SetListViewItemText(item_dom, item_timestamp, true, strOutputItemRecPath, strBiblioRecPath, #if NO strBiblioSummary, strISBnISSN, #endif summary_col_names, summary, item); } int nRet = VerifyItem( strPubType, strBarcodeOrRecPath, item, item_dom, out strError); if (nRet == -1) goto ERROR1; return 1; ERROR1: return -1; }
// 根据册条码号或者记录路径,装入册记录 // parameters: // strBarcodeOrRecPath 册条码号或者记录路径。如果内容前缀为"@path:"则表示为路径 // strMatchLocation 附加的馆藏地点匹配条件。如果==null,表示没有这个附加条件(注意,""和null含义不同,""表示确实要匹配这个值) // return: // -2 册条码号已经在list中存在了(行没有加入listview中) // -1 出错(注意表示出错的行已经加入listview中了) // 0 因为馆藏地点不匹配,没有加入list中 // 1 成功 public int LoadOneItem( string strBarcodeOrRecPath, ListView list, string strMatchLocation, out string strError) { strError = ""; // 判断是否有 @path: 前缀,便于后面分支处理 bool bIsRecPath = StringUtil.HasHead(strBarcodeOrRecPath, "@path:"); ; string strItemXml = ""; string strBiblioText = ""; string strItemRecPath = ""; string strBiblioRecPath = ""; byte[] item_timestamp = null; long lRet = Channel.GetItemInfo( stop, strBarcodeOrRecPath, "xml", out strItemXml, out strItemRecPath, out item_timestamp, "recpath", out strBiblioText, out strBiblioRecPath, out strError); if (lRet == -1 || lRet == 0) { ListViewItem item = null; if (bIsRecPath == false) item = new ListViewItem(strBarcodeOrRecPath, 0); else item = new ListViewItem("", 0); // 暂时还没有办法知道条码 // 2009/10/29 OriginItemData data = new OriginItemData(); item.Tag = data; data.Timestamp = item_timestamp; data.Xml = strItemXml; ListViewUtil.ChangeItemText(item, COLUMN_ERRORINFO, strError); // item.SubItems.Add(strError); SetItemColor(item, TYPE_ERROR); list.Items.Add(item); // 将新加入的事项滚入视野 list.EnsureVisible(list.Items.Count - 1); goto ERROR1; } string strBiblioSummary = ""; string strISBnISSN = ""; string strTargetRecPath = ""; // 看看册条码号是否有重复? // 顺便获得同种的事项 for (int i = 0; i < list.Items.Count; i++) { ListViewItem curitem = list.Items[i]; if (bIsRecPath == false) { if (strBarcodeOrRecPath == curitem.Text) { strError = "册条码号 " + strBarcodeOrRecPath + " 发生重复"; return -2; } } else { if (strBarcodeOrRecPath == ListViewUtil.GetItemText(curitem, COLUMN_RECPATH)) { strError = "记录路径 " + strBarcodeOrRecPath + " 发生重复"; return -2; } } if (strBiblioSummary == "" && curitem.ImageIndex != TYPE_ERROR) { if (curitem.SubItems[COLUMN_BIBLIORECPATH].Text == strBiblioRecPath) { strBiblioSummary = ListViewUtil.GetItemText(curitem, COLUMN_SUMMARY); strISBnISSN = ListViewUtil.GetItemText(curitem, COLUMN_ISBNISSN); strTargetRecPath = ListViewUtil.GetItemText(curitem, COLUMN_TARGETRECPATH); } } } if (strBiblioSummary == "") { string[] formats = new string[3]; formats[0] = "summary"; formats[1] = "@isbnissn"; formats[2] = "targetrecpath"; string[] results = null; byte[] timestamp = null; Debug.Assert(String.IsNullOrEmpty(strBiblioRecPath) == false, "strBiblioRecPath值不能为空"); lRet = Channel.GetBiblioInfos( stop, strBiblioRecPath, "", formats, out results, out timestamp, out strError); if (lRet == -1 || lRet == 0) { if (lRet == 0 && String.IsNullOrEmpty(strError) == true) strError = "书目记录 '" + strBiblioRecPath + "' 不存在"; strBiblioSummary = "获得书目摘要时发生错误: " + strError; } else { Debug.Assert(results != null && results.Length == 3, "results必须包含3个元素"); strBiblioSummary = results[0]; strISBnISSN = results[1]; strTargetRecPath = results[2]; } } // 剖析一个册的xml记录,取出有关信息放入listview中 XmlDocument dom = new XmlDocument(); try { dom.LoadXml(strItemXml); } catch (Exception ex) { strError = ex.Message; goto ERROR1; } // 附加的馆藏地点匹配 if (strMatchLocation != null) { string strLocation = DomUtil.GetElementText(dom.DocumentElement, "location"); // 2013/3/26 if (strLocation == null) strLocation = ""; if (strMatchLocation != strLocation) return 0; } { ListViewItem item = AddToListView(list, dom, strItemRecPath, strBiblioSummary, strISBnISSN, strBiblioRecPath, strTargetRecPath); // 设置timestamp/xml OriginItemData data = (OriginItemData)item.Tag; Debug.Assert(data != null, ""); data.Timestamp = item_timestamp; data.Xml = strItemXml; if (this.comboBox_load_type.Text == "连续出版物") { // 检查是否为合订册记录或者单册记录。不能为合订成员 // return: // 0 不是。图标已经设置为TYPE_ERROR // 1 是。图标尚未设置 int nRet = CheckBindingItem(item); if (nRet == 1) { // 图标 SetItemColor(item, TYPE_NORMAL); } } else { Debug.Assert(this.comboBox_load_type.Text == "图书", ""); // 图标 SetItemColor(item, TYPE_NORMAL); } // 将新加入的事项滚入视野 list.EnsureVisible(list.Items.Count - 1); // 检查条码号 if (bIsRecPath == false) { string strBarcode = DomUtil.GetElementText(dom.DocumentElement, "barcode"); if (strBarcode != strBarcodeOrRecPath) { if (strBarcode.ToUpper() == strBarcodeOrRecPath.ToUpper()) strError = "用于检索的条码号 '" + strBarcodeOrRecPath + "' 和册记录中的条码号 '" + strBarcode + "' 大小写不一致"; else strError = "用于检索的条码号 '" + strBarcodeOrRecPath + "' 和册记录中的条码号 '" + strBarcode + "' 不一致"; ListViewUtil.ChangeItemText(item, COLUMN_ERRORINFO, strError); SetItemColor(item, TYPE_ERROR); goto ERROR1; } } } return 1; ERROR1: return -1; }