private void DeleteTable() { if (this.listViewLUTList.SelectedItems.Count < 1) { return; } LUTItemMgt lut = this.listViewLUTList.SelectedItems[0].Tag as LUTItemMgt; if (lut == null) { return; } if (lut.Drop()) { RefreshItemList(null); RefreshTableList(); RefreshTableButton(); } else { MessageBox.Show(this, "Delete table \"" + lut.TableName + "\" failed.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void ModifyItem() { string strSource = this.textBoxSourceValue.Text; string strTarget = this.textBoxTargetValue.Text; if (strSource.Length < 1 && strTarget.Length < 1) { return; } if (this.listViewLUTList.SelectedItems.Count < 1) { return; } LUTItemMgt lut = this.listViewLUTList.SelectedItems[0].Tag as LUTItemMgt; if (lut == null) { return; } if (this.listViewLUTItem.SelectedItems.Count < 1) { return; } LUTItem item = this.listViewLUTItem.SelectedItems[0].Tag as LUTItem; if (item == null) { return; } LUTItem newItem = new LUTItem(); newItem.SourceValue = strSource; newItem.TargetValue = strTarget; if (!CheckRepeat(newItem)) { return; } item.SourceValue = strSource; item.TargetValue = strTarget; if (lut.Update(item)) { lut.ReloadLUT(); RefreshItemList(lut); ListViewSelectItem(item); } else { MessageBox.Show(this, "Modify look up table item failed.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void ListViewAddTable(LUTItemMgt lut) { if (lut == null) { return; } int index = this.listViewLUTList.Items.Count + 1; ListViewItem i = this.listViewLUTList.Items.Add(index.ToString()); i.SubItems.Add(lut.TableName); i.Tag = lut; }
private void AddTable() { string str = this.textBoxTableName.Text.Trim(); if (str.Length < 1) { return; } if (str.Length <= LutMgt.Prefix.Length || str.ToLower().Substring(0, LutMgt.Prefix.Length) != LutMgt.Prefix) { str = LutMgt.Prefix + str; this.textBoxTableName.Text = str; } bool hasName = false; foreach (ListViewItem item in this.listViewLUTItem.Items) { LUTItemMgt table = item.Tag as LUTItemMgt; if (table != null && table.TableName == str) { hasName = true; break; } } if (hasName) { MessageBox.Show(this, "Look up table named \"" + str + "\" has already existed in the database, please input another name.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } LUTItemMgt lut = new LUTItemMgt(mgt.DataBase, str); if (lut.Create()) { this.textBoxTableName.Text = ""; ListViewAddTable(lut); ListViewSelectTable(lut); //RefreshTableButton(); } else { MessageBox.Show(this, "Create table \"" + str + "\" failed.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void ListViewSelectTable(LUTItemMgt lut) { if (lut == null) { return; } foreach (ListViewItem i in this.listViewLUTList.Items) { LUTItemMgt table = i.Tag as LUTItemMgt; if (table.TableName == lut.TableName) { i.Selected = true; i.EnsureVisible(); break; } } }
private void RefreshTableList() { this.listViewLUTList.Items.Clear(); string[] tableList = mgt.GetLutNames(); if (tableList == null) { return; } foreach (string tname in tableList) { LUTItemMgt lut = new LUTItemMgt(mgt.DataBase, tname); ListViewAddTable(lut); } if (this.listViewLUTList.Items.Count > 0) { this.listViewLUTList.Items[0].Selected = true; } }
private void DeleteItem() { if (this.listViewLUTList.SelectedItems.Count < 1) { return; } LUTItemMgt lut = this.listViewLUTList.SelectedItems[0].Tag as LUTItemMgt; if (lut == null) { return; } if (this.listViewLUTItem.SelectedItems.Count < 1) { return; } LUTItem item = this.listViewLUTItem.SelectedItems[0].Tag as LUTItem; if (item == null) { return; } if (lut.Delete(item)) { lut.ReloadLUT(); RefreshItemList(lut); RefreshItemButton(); } else { MessageBox.Show(this, "Delete look up table item failed.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void RefreshItemList(LUTItemMgt lut) { this.listViewLUTItem.Items.Clear(); if (lut == null) { return; } LUTItem[] itemList = lut.LUT; if (itemList == null) { return; } int index = 1; foreach (LUTItem item in itemList) { ListViewItem i = this.listViewLUTItem.Items.Add((index++).ToString()); i.SubItems.Add(item.SourceValue); i.SubItems.Add(item.TargetValue); i.Tag = item; } }