/* // 根据出版日期查找第一个匹配的TreeNode节点 TreeNode FindTreeNode(string strPublishTime) { for (int i = 0; i < this.TreeView.Nodes.Count; i++) { TreeNode tree_node = this.TreeView.Nodes[i]; IssueManageItem item = (IssueManageItem)tree_node.Tag; Debug.Assert(item != null, ""); if (item.PublishTime == strPublishTime) return tree_node; } return null; } */ // 增全各期(后插)。从当前最末尾的一个期开始,增补各个期直到超过订购时间范围 void button_newAllIssue_Click(object sender, EventArgs e) { string strError = ""; int nRet = 0; int nCreateCount = 0; // 找到最后一期。如果找不到,则先出现对话框询问第一期 if (this.TreeView.Nodes.Count == 0) { string strStartDate = ""; string strEndDate = ""; // 获得可用的最大订购时间范围 // return: // -1 error // 0 not found // 1 found nRet = GetMaxOrderRange(out strStartDate, out strEndDate, out strError); if (nRet == -1) goto ERROR1; if (nRet == 0) { strError = "当前没有订购信息,无法进行增全操作"; goto ERROR1; } // 出现对话框,让输入第一期的参数。出版时间由软件自动探测和推荐 // 这里要求日常管理订购信息把已经到全的订购记录“封闭”。否则会出现把原来早就验收过的第一期出版时间推荐出来的情况 // 所谓封闭(订购信息的)操作,可以由过刊装订操作来负责 IssueDialog dlg = new IssueDialog(); MainForm.SetControlFont(dlg, this.Font, false); dlg.Text = "请指定首期的特征"; dlg.PublishTime = strStartDate + "?"; // 获得订购范围的起点日期 dlg.EditComment = "当前订购时间范围为 " + strStartDate + "-" + strEndDate; // 显示可用的订购时间范围 dlg.StartPosition = FormStartPosition.CenterScreen; REDO_INPUT: dlg.ShowDialog(this); if (dlg.DialogResult != DialogResult.OK) return; // 放弃整个功能 // 检查一下这个出版时间是否超过订购时间范围? if (InOrderRange(dlg.PublishTime) == false) { MessageBox.Show(this, "您指定的首期出版时间 '" + dlg.PublishTime + "' 不在当前订购时间范围内,请重新输入。"); goto REDO_INPUT; } IssueManageItem new_item = new IssueManageItem(); nRet = new_item.Initial("<root />", out strError); if (nRet == -1) goto ERROR1; new_item.PublishTime = dlg.PublishTime; new_item.Issue = dlg.Issue; new_item.Zong = dlg.Zong; new_item.Volume = dlg.Volume; new_item.Comment = dlg.Comment; TreeNode tree_node = new TreeNode(); tree_node.ImageIndex = TYPE_RECIEVE_ZERO; tree_node.Tag = new_item; // 显示出定位信息、卷期册号 new_item.SetNodeCaption(tree_node); int index = 0; if (this.TreeView.SelectedNode != null) index = this.TreeView.Nodes.IndexOf(this.TreeView.SelectedNode) + 1; this.TreeView.Nodes.Insert(index, tree_node); nCreateCount++; new_item.Changed = true; this.Changed = true; // 选上新插入的节点 this.TreeView.SelectedNode = tree_node; } else { // 选定最后一个TreeNode Debug.Assert(this.TreeView.Nodes.Count != 0, ""); TreeNode last_tree_node = this.TreeView.Nodes[this.TreeView.Nodes.Count - 1]; if (this.TreeView.SelectedNode != last_tree_node) this.TreeView.SelectedNode = last_tree_node; } Debug.Assert(this.TreeView.SelectedNode != null, ""); TreeNode tail_node = this.TreeView.SelectedNode; // int nWarningCount = 0; // 进行循环,增补全部节点 for (int i=0; ;i++ ) { Debug.Assert(this.TreeView.SelectedNode != null, ""); IssueManageItem ref_item = (IssueManageItem)tail_node.Tag; string strNextPublishTime = ""; string strNextIssue = ""; string strNextZong = ""; string strNextVolume = ""; { int nIssueCount = 0; // 获得一年内的期总数 // return: // -1 出错 // 0 无法获得 // 1 获得 nRet = GetOneYearIssueCount(ref_item.PublishTime, out nIssueCount, out strError); int nRefIssue = 0; try { nRefIssue = Convert.ToInt32(ref_item.Issue); } catch { nRefIssue = 0; } try { // 预测下一期的出版时间 // parameters: // strPublishTime 当前这一期出版时间 // nIssueCount 一年内出多少期 strNextPublishTime = NextPublishTime(ref_item.PublishTime, nIssueCount); } catch (Exception ex) { // 2009/2/8 strError = "在获得日期 '" + ref_item.PublishTime + "' 的后一期出版日期时发生错误: " + ex.Message; goto ERROR1; } if (strNextPublishTime == "????????") break; // 检查一下这个出版时间是否超过订购时间范围? if (InOrderRange(strNextPublishTime) == false) break; // 避免最后多插入一个 // 号码自动增量需要知道一个期是否跨年,可以通过查询采购信息得到一年所订阅的期数 if (nRefIssue >= nIssueCount && nIssueCount > 0) // 2010/3/3 { // 跨年了 strNextIssue = "1"; } else { strNextIssue = (nRefIssue + 1).ToString(); } strNextZong = IncreaseNumber(ref_item.Zong); if (nRefIssue >= nIssueCount && nIssueCount > 0) strNextVolume = IncreaseNumber(ref_item.Volume); else strNextVolume = ref_item.Volume; } // 对publishTime要查重,对号码体系要进行检查和提出警告 TreeNode dup_tree_node = null; // 对出版时间进行查重 // parameters: // exclude 检查中要排除的TreeNode对象 // return: // -1 error // 0 没有重 // 1 重 nRet = CheckPublishTimeDup(strNextPublishTime, null, out dup_tree_node, out strError); if (nRet == -1) goto ERROR1; if (nRet == 1) { //this.TreeView.SelectedNode = dup_tree_node; tail_node = dup_tree_node; MessageBox.Show(this, "出版时间为 '" + strNextPublishTime + "' 的期节点已经存在了。其位置将被调整到末尾"); // 将重复节点移动到最后位置 this.TreeView.Nodes.Remove(dup_tree_node); this.TreeView.Nodes.Add(dup_tree_node); // this.TreeView.SelectedNode = dup_tree_node; // 若没有这一句会引起死循环 tail_node = dup_tree_node; continue; } IssueManageItem new_item = new IssueManageItem(); nRet = new_item.Initial("<root />", out strError); if (nRet == -1) goto ERROR1; new_item.PublishTime = strNextPublishTime; new_item.Issue = strNextIssue; new_item.Zong = strNextZong; new_item.Volume = strNextVolume; TreeNode tree_node = new TreeNode(); tree_node.ImageIndex = TYPE_RECIEVE_ZERO; tree_node.Tag = new_item; // 显示出定位信息、卷期册号 new_item.SetNodeCaption(tree_node); int index = 0; /* if (this.TreeView.SelectedNode != null) index = this.TreeView.Nodes.IndexOf(this.TreeView.SelectedNode) + 1; * */ if (tail_node != null) index = this.TreeView.Nodes.IndexOf(tail_node) + 1; this.TreeView.Nodes.Insert(index, tree_node); nCreateCount++; new_item.Changed = true; this.Changed = true; /* // 选上新插入的节点 this.TreeView.SelectedNode = tree_node; * */ tail_node = tree_node; } if (tail_node != null) { // 选上新插入的节点 this.TreeView.SelectedNode = tail_node; } string strMessage = ""; if (nCreateCount == 0) strMessage = "没有增加新的期节点"; else strMessage = "共新增了 " + nCreateCount.ToString() + " 个期节点"; MessageBox.Show(this, strMessage); return; ERROR1: MessageBox.Show(this, strError); }
// 新增期(后插) void button_newIssue_Click(object sender, EventArgs e) { string strError = ""; int nRet = 0; IssueManageItem ref_item = null; if (this.TreeView.SelectedNode != null) ref_item = (IssueManageItem)this.TreeView.SelectedNode.Tag; IssueDialog dlg = new IssueDialog(); MainForm.SetControlFont(dlg, this.Font, false); if (ref_item != null) { // TODO: 最好能自动增量 int nIssueCount = 0; // 获得一年内的期总数 // return: // -1 出错 // 0 无法获得 // 1 获得 nRet = GetOneYearIssueCount(ref_item.PublishTime, out nIssueCount, out strError); int nRefIssue = 0; try { nRefIssue = Convert.ToInt32(ref_item.Issue); } catch { nRefIssue = 0; } string strNextPublishTime = ""; try { // 预测下一期的出版时间 // parameters: // strPublishTime 当前这一期出版时间 // nIssueCount 一年内出多少期 strNextPublishTime = NextPublishTime(ref_item.PublishTime, nIssueCount); } catch (Exception ex) { // 2009/2/8 strError = "在获得日期 '" + ref_item.PublishTime + "' 的后一期出版日期时发生错误: " + ex.Message; goto ERROR1; } dlg.PublishTime = strNextPublishTime; // 号码自动增量需要知道一个期是否跨年,可以通过查询采购信息得到一年所订阅的期数 if (nRefIssue >= nIssueCount && nIssueCount > 0) // 2010/3/3 { // 跨年了 dlg.Issue = "1"; } else { dlg.Issue = (nRefIssue+1).ToString(); } dlg.Zong = IncreaseNumber(ref_item.Zong); if (nRefIssue >= nIssueCount && nIssueCount > 0) dlg.Volume = IncreaseNumber(ref_item.Volume); else dlg.Volume = ref_item.Volume; if (nIssueCount > 0) dlg.EditComment = "一年出版 " + nIssueCount.ToString() + " 期"; } dlg.StartPosition = FormStartPosition.CenterScreen; REDO_INPUT: dlg.ShowDialog(this); if (dlg.DialogResult != DialogResult.OK) return; // 对publishTime要查重,对号码体系要进行检查和提出警告 TreeNode dup_tree_node = null; // 对出版时间进行查重 // parameters: // exclude 检查中要排除的TreeNode对象 // return: // -1 error // 0 没有重 // 1 重 nRet = CheckPublishTimeDup(dlg.PublishTime, null, out dup_tree_node, out strError); if (nRet == -1) goto ERROR1; if (nRet == 1) { // 选中所重复的TreeNode节点,便于操作者观察重复的情况 Debug.Assert(dup_tree_node != null, ""); if (dup_tree_node != null) this.TreeView.SelectedNode = dup_tree_node; MessageBox.Show(this, "拟新增的期节点 " + strError + "\r\n请修改。"); goto REDO_INPUT; } IssueManageItem new_item = new IssueManageItem(); nRet = new_item.Initial("<root />", out strError); if (nRet == -1) goto ERROR1; new_item.PublishTime = dlg.PublishTime; new_item.Issue = dlg.Issue; new_item.Zong = dlg.Zong; new_item.Volume = dlg.Volume; new_item.Comment = dlg.Comment; TreeNode tree_node = new TreeNode(); tree_node.ImageIndex = TYPE_RECIEVE_ZERO; tree_node.Tag = new_item; // 显示出定位信息、卷期册号 new_item.SetNodeCaption(tree_node); int index = 0; if (this.TreeView.SelectedNode != null) index = this.TreeView.Nodes.IndexOf(this.TreeView.SelectedNode) + 1; this.TreeView.Nodes.Insert(index, tree_node); new_item.Changed = true; this.Changed = true; // 选上新插入的节点 this.TreeView.SelectedNode = tree_node; return; ERROR1: MessageBox.Show(this, strError); }
// 修改期信息 void button_modify_Click(object sender, EventArgs e) { string strError = ""; if (this.TreeView.SelectedNode == null) { strError = "尚未选定要修改的期节点"; goto ERROR1; } IssueManageItem item = (IssueManageItem)this.TreeView.SelectedNode.Tag; IssueDialog dlg = new IssueDialog(); MainForm.SetControlFont(dlg, this.Font, false); dlg.PublishTime = item.PublishTime; dlg.Issue = item.Issue; dlg.Zong = item.Zong; dlg.Volume = item.Volume; dlg.Comment = item.Comment; dlg.StartPosition = FormStartPosition.CenterScreen; REDO_INPUT: dlg.ShowDialog(this); if (dlg.DialogResult != DialogResult.OK) return; TreeNode dup_tree_node = null; // 对出版时间进行查重 // parameters: // exclude 检查中要排除的TreeNode对象 // return: // -1 error // 0 没有重 // 1 重 int nRet = CheckPublishTimeDup(dlg.PublishTime, this.TreeView.SelectedNode, out dup_tree_node, out strError); if (nRet == -1) goto ERROR1; if (nRet == 1) { // 选中所重复的TreeNode节点,便于操作者观察重复的情况 Debug.Assert(dup_tree_node != null, ""); if (dup_tree_node != null) this.TreeView.SelectedNode = dup_tree_node; MessageBox.Show(this, "修改后的期节点 " + strError + "\r\n请修改。"); goto REDO_INPUT; } item.PublishTime = dlg.PublishTime; item.Issue = dlg.Issue; item.Zong = dlg.Zong; item.Volume = dlg.Volume; item.Comment = dlg.Comment; item.SetNodeCaption(this.TreeView.SelectedNode); item.Changed = true; this.Changed = true; // TODO: 修改出版时间后,要注意修改属于本期的所有册的出版时间字段内容 // 为了避免和标记删除的册事项发生冲突,真正修改前可要求所有未提交的册修改先保存提交? return; ERROR1: MessageBox.Show(this, strError); }