// 添加一个新的册对象 public int NewEntity(string strItemBarcode, out string strError) { strError = ""; EntityEditControl control = new EntityEditControl(); control.Barcode = strItemBarcode; control.AutoScroll = false; control.DisplayMode = "simple_register"; control.Width = 120; control.AutoSize = true; control.Font = this.Font; control.Initializing = false; control.PaintContent += new PaintEventHandler(control_PaintContent); this.flowLayoutPanel_entities.Controls.Add(control); this.flowLayoutPanel_entities.ScrollControlIntoView(control); return(0); }
private void button_scan_Click(object sender, EventArgs e) { string strError = ""; int nRet = 0; this.textBox_input.SelectAll(); this.textBox_input.Focus(); if (this._step == Step.PrepareSearchBiblio) { this.BaseForm.QueryWord = this.textBox_input.Text; this._lastISBN = this.textBox_input.Text; // 显示“正在检索” this.SetStep(Step.SearchingBiblio); this.BaseForm.DoSearch(this.textBox_input.Text, "ISBN", false); this.SetStep(Step.SearchBiblioCompleted); // 如果检索命中,要选择后,切换到下一页。选择方面,可以提示输入 1 2 3 4 等用以选择 // 如果检索没有命中,提示再次扫入相同的 ISBN,可以直接进入创建新记录流程 if (this.BaseForm.SearchResultErrorCount > 0) { this.SetStep(Step.SearchBiblioError); } else if (this.BaseForm.SearchResultCount > 0) { if (this.BaseForm.SearchResultCount == 1) { // 命中唯一的一条 this.EditSelectedBrowseLine(); // 观察书目记录包含多少册记录。 this.SetStep(Step.EditEntity); return; } this.textBox_input.Text = "1"; this.SetStep(Step.SelectSearchResult); } else { Debug.Assert(this.BaseForm.SearchResultCount == 0, ""); // 没有命中。当再次输入同样的 ISBN, 表示创建新书目记录 this.SetStep(Step.SearchBiblioNotFound); } return; } if (this._step == Step.SelectSearchResult) { int index = 0; // 如果输入刚才用过的 ISBN ,表示选择第一个记录 if (this.textBox_input.Text == this._lastISBN && string.IsNullOrEmpty(this._lastISBN) == false) { index = 1; } else { // 根据输入的数字挑选命中记录 if (StringUtil.IsPureNumber(this.textBox_input.Text) == false) { strError = "请输入一个数字"; goto ERROR1; } if (int.TryParse(this.textBox_input.Text, out index) == false) { strError = "输入的应该是一个数字"; goto ERROR1; } // TODO: 可以根据检索命中列表中事项的最大个数,探测 input 中输入达到这么多个字符后不需要按回车键就可以开始后续处理 if (index - 1 >= this.BaseForm.ResultListCount) { strError = "请输入一个 1-" + (this.BaseForm.ResultListCount + 1).ToString() + " 之间的数字"; goto ERROR1; } } this.BaseForm.SelectBrowseLine(true, index - 1); this.EditSelectedBrowseLine(); // 观察书目记录包含多少册记录。 this.SetStep(Step.EditEntity); return; } if (this._step == Step.SearchBiblioNotFound) { // 如果输入刚才用过的 ISBN ,表示创建新书目记录 if (this.textBox_input.Text == this._lastISBN && string.IsNullOrEmpty(this._lastISBN) == false) { nRet = this.BaseForm.NewBiblio(false); if (nRet == -1) { this.DisplayError("操作出错"); return; } this.SetStep(Step.EditBiblio); return; } else { string strText = this.textBox_input.Text; this.SetStep(Step.PrepareSearchBiblio); this.textBox_input.Text = strText; this.BeginInvoke(new Action <object, EventArgs>(button_scan_Click), this, new EventArgs()); return; } //return; } if (this._step == Step.EditBiblio) { // 观察输入的字符串,如果和检索使用过的 ISBN 一致,则增加一个册(册条码号为空); // 如果是其他 ISBN,则回到检索画面自动启动检索书目; // 如果不是 ISBN,则当作为当前书目字段输入内容 string strText = this.textBox_input.Text; if (strText == this._lastISBN && string.IsNullOrEmpty(this._lastISBN) == false) { // 将上一个 EntityEditControl 中的蓝色行标记清除 if (this._currentEntityControl != null) { this.BaseForm.DisableWizardControl(); this._currentEntityControl.ClearActiveState(); this.BaseForm.EnableWizardControl(); } this._currentEntityControl = this.BaseForm.AddNewEntity("", false); this._currentEntityLine = null; #if NO // 越过第一个字段 this._currentEntityLine = GetNextEntityLine(this._currentEntityLine); #endif return; } if (QuickChargingForm.IsISBN(ref strText) == true) { this.SetStep(Step.PrepareSearchBiblio); this.textBox_input.Text = strText; this.BeginInvoke(new Action <object, EventArgs>(button_scan_Click), this, new EventArgs()); return; } else { // 为当前子字段添加内容,顺次进入下一子字段。等所有字段都输入完以后,自动进入 EditEntity 状态 if (this._currenBiblioLine != null) { if (string.IsNullOrEmpty(this.textBox_input.Text) == true) { List <EasyLine> selected_lines = new List <EasyLine>(); selected_lines.Add(this._currenBiblioLine); EasyMarcControl container = this._currenBiblioLine.Container; // 删除前要先找到上一个行。否则删除后查找将无法继续 this._currenBiblioLine = GetPrevBiblioLine(this._currenBiblioLine); // 删除 container.DeleteElements(selected_lines); } else { this._currenBiblioLine.Content = this.textBox_input.Text; this.textBox_input.Text = ""; } SetStep(Step.EditBiblio); } else { this.textBox_input.Text = ""; SetStep(Step.EditEntity); } return; } } if (this._step == Step.EditEntity) { // 观察输入的字符串,如果和检索使用过的 ISBN 一致,则增加一个册(册条码号为空); // 如果是其他 ISBN,则回到检索画面自动启动检索书目; // 如果不是 ISBN,则当作册条码号增加一个册 string strText = this.textBox_input.Text; if (strText == this._lastISBN && string.IsNullOrEmpty(this._lastISBN) == false) { // 将上一个 EntityEditControl 中的蓝色行标记清除 if (this._currentEntityControl != null) { this.BaseForm.DisableWizardControl(); this._currentEntityControl.ClearActiveState(); this.BaseForm.EnableWizardControl(); } this._currentEntityControl = this.BaseForm.AddNewEntity("", false); this._currentEntityLine = null; #if NO // 越过第一个字段 this._currentEntityLine = GetNextEntityLine(this._currentEntityLine); #endif this.BeginInvoke(new Func <Step, string, bool>(SetStep), Step.EditEntity, ""); return; } if (QuickChargingForm.IsISBN(ref strText) == true) { // TODO: 连带引起保存书目和册记录可能会失败哟 if (this.SetStep(Step.PrepareSearchBiblio) == false) { return; } this.textBox_input.Text = strText; this.BeginInvoke(new Action <object, EventArgs>(button_scan_Click), this, new EventArgs()); return; } else { // 首次输入册条码号。还没有关联的 EntityEditControl if (this._currentEntityControl == null) { this._currentEntityControl = this.BaseForm.AddNewEntity(strText, false); this._currentEntityLine = null; // 越过第一个字段 this._currentEntityLine = GetNextEntityLine(this._currentEntityLine); this.BeginInvoke(new Func <Step, string, bool>(SetStep), Step.EditEntity, ""); return; } // 为册编辑器当前行输入内容,顺次进入下一行。等所有字段都输入完以后,自动进入 EditEntity 等待输入册条码号的状态 if (this._currentEntityLine != null) { this._currentEntityLine.Content = this.textBox_input.Text; this.textBox_input.Text = ""; SetStep(Step.EditEntity); } else { // 进入首次等待输入册条码号的状态 this._currentEntityControl = null; this._currentEntityLine = null; this.textBox_input.Text = ""; SetStep(Step.EditEntity); } return; } } return; ERROR1: MessageBox.Show(this, strError); }
public void SetCurrentEntityLine(EntityEditControl control, EditLine line) { this._currentEntityControl = control; this._currentEntityLine = line; }