// 自动为每条书目记录创建一条订购记录 // 修改历史: // 2013/10/12 创建 // 2013/10/27 entity_form.OrderControl.ReplaceMacroValues() using System; using System.Collections; using System.Collections.Generic; using System.Windows.Forms; using System.IO; using System.Text; using System.Xml; using dp2Circulation; using DigitalPlatform.Marc; using DigitalPlatform.Xml; using DigitalPlatform.Script; public class MyMarcQueryHost : MarcQueryHost { OrderItem _item = null; EntityForm entity_form = null; public override void OnBegin(object sender, StatisEventArgs e) { // 打开一个种册窗 // entity_form = this.MainForm.EnsureChildForm(); entity_form = new EntityForm(); entity_form.MainForm = this.MainForm; entity_form.MdiParent = this.MainForm; entity_form.Show(); } public override void OnRecord(object sender, StatisEventArgs e) { string strError = ""; int nRet = 0; // 第一次需要出现对话框询问要新增的记录内容 if (_item == null) { _item = new OrderItem(); // 设置缺省值 nRet = entity_form.OrderControl.SetItemDefaultValues( "order_normalRegister_default", false, _item, out strError); if (nRet == -1) { strError = "设置缺省值的时候发生错误: " + strError; goto ERROR1; } _item.Parent = "?"; // 名义 ID,避免报警 OrderEditForm edit = new OrderEditForm(); edit.EnableButtonOK = true; edit.BiblioDbName = Global.GetDbName(this.RecordPath); edit.Text = "新增订购事项"; edit.MainForm = this.MainForm; edit.Item = _item; REDO: edit.ShowDialog(this.MainForm); if (edit.DialogResult != DialogResult.OK) { e.Continue = ContinueType.SkipAll; return; } if (string.IsNullOrEmpty(_item.BatchNo) == true) { strError = "尚未设置批次号,请到一般订购缺省值面板中设置"; MessageBox.Show(this.MainForm, strError); goto REDO; } if (string.IsNullOrEmpty(_item.Price) == true) { strError = "尚未设置订购价格,请到一般订购缺省值面板中设置"; MessageBox.Show(this.MainForm, strError); goto REDO; } if (string.IsNullOrEmpty(_item.Seller) == true) { strError = "尚未设置订购渠道,请到一般订购缺省值面板中设置"; MessageBox.Show(this.MainForm, strError); goto REDO; } if (string.IsNullOrEmpty(_item.Distribute) == true) { strError = "尚未设置订购去向,请到一般订购缺省值面板中设置"; MessageBox.Show(this.MainForm, strError); goto REDO; } if (string.IsNullOrEmpty(_item.Copy) == true) { strError = "尚未设置订购复本,请到一般订购缺省值面板中设置"; MessageBox.Show(this.MainForm, strError); goto REDO; } } // return: // -1 出错 // 0 没有装载(例如发现窗口内的记录没有保存,出现警告对话框后,操作者选择了Cancel;或者“到头”“到尾”) // 1 成功装载 // 2 通道被占用 nRet = entity_form.LoadRecord(this.RecordPath, "", true, false, out strError); if (nRet != 1) goto ERROR1; { // 把模板对象复制给实际对象 OrderItem item = new OrderItem(); _item.CopyTo(item); // 替换字段中的宏 nRet = entity_form.OrderControl.ReplaceMacroValues( item, out strError); if (nRet == -1) goto ERROR1; _item.RefID = ""; // 迫使重新生成 参考 ID nRet = entity_form.OrderControl.AppendItem(item, out strError); if (nRet == -1) goto ERROR1; } nRet = entity_form.DoSaveAll(""); if (nRet == -1) goto ERROR1; return; ERROR1: e.Continue = ContinueType.Error; e.ParamString = strError; } public override void OnEnd(object sender, StatisEventArgs e) { if (entity_form != null) entity_form.Close(); } }