// 通用版本 List<ItemInfo> GetItemInfos(string strDbType, string strHowToGetItemRecord, ref List<ItemInfo> item_infos) { // 优化速度 if (item_infos != null) return item_infos; // 如果当前书目库下没有包含实体库,调用会抛出异常。特殊处理 // TODO: 是否需要用hashtable优化速度? string strBiblioDBName = Global.GetDbName(this.CurrentRecPath); string strItemDbName = ""; if (strDbType == "item") strItemDbName = this.BiblioStatisForm.MainForm.GetItemDbName(strBiblioDBName); else if (strDbType == "order") strItemDbName = this.BiblioStatisForm.MainForm.GetOrderDbName(strBiblioDBName); else if (strDbType == "issue") strItemDbName = this.BiblioStatisForm.MainForm.GetIssueDbName(strBiblioDBName); else if (strDbType == "comment") strItemDbName = this.BiblioStatisForm.MainForm.GetCommentDbName(strBiblioDBName); else { throw new Exception("未知的 strDbType '"+strDbType+"'"); } if (String.IsNullOrEmpty(strItemDbName) == true) return new List<ItemInfo>(); // 返回一个空的数组 item_infos = new List<ItemInfo>(); long lPerCount = 100; // 每批获得多少个 long lStart = 0; long lResultCount = 0; long lCount = -1; for (; ; ) { string strStyle = ""; if (strHowToGetItemRecord == "delay") strStyle = "onlygetpath"; else if (strHowToGetItemRecord == "first") strStyle = "onlygetpath,getfirstxml"; EntityInfo[] infos = null; string strError = ""; long lRet = 0; if (strDbType == "item") lRet = this.BiblioStatisForm.Channel.GetEntities( null, this.CurrentRecPath, lStart, lCount, strStyle, "zh", out infos, out strError); else if (strDbType == "order") lRet = this.BiblioStatisForm.Channel.GetOrders( null, this.CurrentRecPath, lStart, lCount, strStyle, "zh", out infos, out strError); else if (strDbType == "issue") lRet = this.BiblioStatisForm.Channel.GetIssues( null, this.CurrentRecPath, lStart, lCount, strStyle, "zh", out infos, out strError); else if (strDbType == "comment") lRet = this.BiblioStatisForm.Channel.GetComments( null, this.CurrentRecPath, lStart, lCount, strStyle, "zh", out infos, out strError); if (lRet == -1) throw new Exception(strError); lResultCount = lRet; // 2009/11/23 if (infos == null) return item_infos; for (int i = 0; i < infos.Length; i++) { EntityInfo info = infos[i]; string strXml = info.OldRecord; /* if (String.IsNullOrEmpty(strXml) == true) continue; * */ ItemInfo item_info = new ItemInfo(strDbType); item_info.Container = this; item_info.RecPath = info.OldRecPath; item_info.Timestamp = info.OldTimestamp; item_info.OldRecord = strXml; item_infos.Add(item_info); } lStart += infos.Length; if (lStart >= lResultCount) break; if (lCount == -1) lCount = lPerCount; if (lStart + lCount > lResultCount) lCount = lResultCount - lStart; } // end of for return item_infos; }
// 为一行装载数据 int LoadItemData(ListViewItem item, out string strError) { Debug.Assert(item.Tag == null, ""); strError = ""; string strRecPath = item.Text; string strItemXml = ""; string strBiblioHtml = ""; stop.OnStop += new StopEventHandler(this.DoStop); stop.Initial("正在获取路径为 '" + strRecPath + "' 的册信息和书目信息 ..."); stop.BeginLoop(); Cursor oldCursor = this.Cursor; this.Cursor = Cursors.WaitCursor; try { long lRet = Channel.GetItemInfo( stop, "@path:" + strRecPath, "xml", out strItemXml, "html", out strBiblioHtml, out strError); if (lRet == -1) goto ERROR1; // error if (lRet == 0) { strError = "路径为 '" + strRecPath + "' 的册记录没有找到"; goto ERROR1; // not found } } finally { stop.EndLoop(); stop.OnStop -= new StopEventHandler(this.DoStop); stop.Initial(""); this.Cursor = oldCursor; } ItemInfo info = new ItemInfo(); info.BiblioHtml = strBiblioHtml; info.ItemXml = strItemXml; info.RecPath = strRecPath; item.Tag = info; // 储存起来 return 0; ERROR1: return -1; }
// 为一行装载数据 int LoadItemData(ListViewItem item, out string strError) { Debug.Assert(item.Tag == null, ""); strError = ""; // TODO: 要能获取暗黑风格的 HTML string strFormatList = "xml,html"; if (this.NoBorrowHistory == true) strFormatList += ":noborrowhistory"; string strRecPath = ListViewUtil.GetItemText(item, COLUMN_RECPATH); string strPatronXml = ""; string strPatronHtml = ""; LibraryChannel channel = this.GetChannel(); stop.OnStop += new StopEventHandler(this.DoStop); stop.Initial("正在获取路径为 '" + strRecPath + "' 的读者记录 ..."); stop.BeginLoop(); Cursor oldCursor = this.Cursor; this.Cursor = Cursors.WaitCursor; try { string[] results = null; long lRet = channel.GetReaderInfo( stop, "@path:" + strRecPath, strFormatList, // "xml,html", out results, out strError); if (lRet == -1) goto ERROR1; // error if (lRet == 0) { strError = "路径为 '" + strRecPath + "' 的读者记录没有找到"; goto ERROR1; // not found } if (results == null || results.Length < 2) { strError = "results error"; goto ERROR1; } strPatronXml = results[0]; strPatronHtml = results[1]; } finally { this.Cursor = oldCursor; stop.EndLoop(); stop.OnStop -= new StopEventHandler(this.DoStop); stop.Initial(""); this.ReturnChannel(channel); } ItemInfo info = new ItemInfo(); info.PatronHtml = strPatronHtml; info.PatronXml = strPatronXml; info.RecPath = strRecPath; item.Tag = info; // 储存起来 return 0; ERROR1: return -1; }
// 为一行装载数据 int LoadItemData(ListViewItem item, out string strError) { Debug.Assert(item.Tag == null, ""); strError = ""; // TODO: 要能获取暗黑风格的 HTML string strFormatList = "xml,html"; if (this.NoBorrowHistory == true) { strFormatList += ":noborrowhistory"; } string strRecPath = ListViewUtil.GetItemText(item, COLUMN_RECPATH); string strPatronXml = ""; string strPatronHtml = ""; LibraryChannel channel = this.GetChannel(); stop.OnStop += new StopEventHandler(this.DoStop); stop.Initial("正在获取路径为 '" + strRecPath + "' 的读者记录 ..."); stop.BeginLoop(); Cursor oldCursor = this.Cursor; this.Cursor = Cursors.WaitCursor; try { string[] results = null; long lRet = channel.GetReaderInfo( stop, "@path:" + strRecPath, strFormatList, // "xml,html", out results, out strError); if (lRet == -1) { goto ERROR1; // error } if (lRet == 0) { strError = "路径为 '" + strRecPath + "' 的读者记录没有找到"; goto ERROR1; // not found } if (results == null || results.Length < 2) { strError = "results error"; goto ERROR1; } strPatronXml = results[0]; strPatronHtml = results[1]; } finally { this.Cursor = oldCursor; stop.EndLoop(); stop.OnStop -= new StopEventHandler(this.DoStop); stop.Initial(""); this.ReturnChannel(channel); } ItemInfo info = new ItemInfo(); info.PatronHtml = strPatronHtml; info.PatronXml = strPatronXml; info.RecPath = strRecPath; item.Tag = info; // 储存起来 return(0); ERROR1: return(-1); }
// 创建新用户 private void button_create_Click(object sender, EventArgs e) { string strError = ""; int nRet = 0; // 刷新模板,准备输入信息 if (Control.ModifierKeys == Keys.Control) { for (int i = 0; i < this.listView_users.Items.Count; i++) { this.listView_users.Items[i].Selected = false; } return; } if (this.textBox_userName.Text == "") { strError = "用户名不能为空"; goto ERROR1; } UserInfo info = new UserInfo(); info.UserName = this.textBox_userName.Text; info.Type = this.textBox_userType.Text; info.Rights = this.textBox_userRights.Text; info.LibraryCode = this.checkedComboBox_libraryCode.Text; // this.textBox_libraryCode.Text; info.Access = this.textBox_access.Text; info.Comment = this.textBox_comment.Text; if (this.checkBox_changePassword.Checked == true) { if (this.textBox_confirmPassword.Text != this.textBox_password.Text) { strError = "密码 和 再次输入密码 不一致。"; goto ERROR1; } info.SetPassword = true; info.Password = this.textBox_password.Text; } else info.SetPassword = false; // 保存用户信息 nRet = CreateUserInfo( info, out strError); if (nRet == -1) goto ERROR1; this.EditChanged = false; // 加入listview ListViewItem item = new ListViewItem(); ItemInfo item_info = new ItemInfo(); info.SetPassword = false; item_info.UserInfo = info; item.Tag = item_info; SetListViewItemValue(item_info, item); this.listView_users.Items.Add(item); MessageBox.Show(this, "用户 '" + info.UserName + "' 创建成功"); return; ERROR1: MessageBox.Show(this, strError); }
static void SetListViewItemValue(ItemInfo item_info, ListViewItem item) { ListViewUtil.ChangeItemText(item, COLUMN_LIBRARYCODE, item_info.UserInfo.LibraryCode); ListViewUtil.ChangeItemText(item, COLUMN_USERNAME, item_info.UserInfo.UserName); ListViewUtil.ChangeItemText(item, COLUMN_TYPE, item_info.UserInfo.Type); ListViewUtil.ChangeItemText(item, COLUMN_RIGHTS, item_info.UserInfo.Rights); ListViewUtil.ChangeItemText(item, COLUMN_CHANGED, item_info.Changed == true ? "*" : ""); if (item_info.Changed == true) item.BackColor = Color.Yellow; else item.BackColor = SystemColors.Window; ListViewUtil.ChangeItemText(item, COLUMN_ACCESSCODE, item_info.UserInfo.Access); ListViewUtil.ChangeItemText(item, COLUMN_COMMENT, item_info.UserInfo.Comment); #if NO while (item.SubItems.Count < 6) { item.SubItems.Add(""); } item.SubItems[0].Text = item_info.UserInfo.LibraryCode; item.SubItems[1].Text = item_info.UserInfo.UserName; item.SubItems[2].Text = item_info.UserInfo.Type; item.SubItems[3].Text = item_info.UserInfo.Rights; item.SubItems[4].Text = item_info.Changed == true ? "*" : ""; if (item_info.Changed == true) item.BackColor = Color.Yellow; else item.BackColor = SystemColors.Window; item.SubItems[5].Text = item_info.UserInfo.Access; #endif }
// 列出所有用户 // return: // -1 出错 // 0 没有找到 // 1 找到 int ListAllUsers(out string strError) { strError = ""; this.listView_users.Items.Clear(); this.m_nCurrentItemIndex = -1; this.ClearEdit(); EnableControls(false); stop.OnStop += new StopEventHandler(this.DoStop); stop.Initial("正在获得全部用户信息 ..."); stop.BeginLoop(); this.Update(); this.MainForm.Update(); try { int nStart = 0; for (; ; ) { UserInfo[] users = null; long lRet = Channel.GetUser( stop, "list", "", nStart, -1, out users, out strError); if (lRet == -1) goto ERROR1; if (lRet == 0) { strError = "不存在用户信息。"; return 0; // not found } Debug.Assert(users != null, ""); for (int i = 0; i < users.Length; i++) { UserInfo info = users[i]; ListViewItem item = new ListViewItem(); /* item.Text = info.UserName; item.SubItems.Add(info.Type); item.SubItems.Add(info.Rights); item.SubItems.Add(""); * */ ItemInfo item_info = new ItemInfo(); item_info.UserInfo = info; item.Tag = item_info; SetListViewItemValue(item_info, item); this.listView_users.Items.Add(item); } nStart += users.Length; if (nStart >= lRet) break; } } finally { stop.EndLoop(); stop.OnStop -= new StopEventHandler(this.DoStop); stop.Initial(""); EnableControls(true); } return 1; ERROR1: return -1; }