using System; using System.Collections; using System.Windows.Forms; using Core.StlMes.Client.LgCommon; using CoreFS.CA06; namespace Core.StlMes.Client.LgIntegrationQuery { public enum Direction { Up, Down, Left, Right } public partial class frmSetEleCols : Core.StlMes.Client.LgCommon.frmStyleBase { //密钥 string encryptKey = "HNSTXGLG"; //默认密钥向量 byte[] Keys = { 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF }; public Hashtable htbl; public ArrayList alist; public frmSetEleCols() { InitializeComponent(); } private void frmSetEleCols_Load(object sender, EventArgs e) { initCols(); } private void initCols() { try { listBoxAll.Items.Clear(); listBoxUse.Items.Clear(); string strElementsRow = ElementsConfig.GetElementsRow(); //调用函数获取要显示的列名 string[] strERow = strElementsRow.Split(new string[] { "*" }, StringSplitOptions.RemoveEmptyEntries); if (htbl == null) { htbl = new Hashtable(); } if (alist == null) { alist = new ArrayList(); } for (int i = 0; i < strERow.Length; i++) { try { listBoxUse.Items.Add(strERow[i].Trim()); } catch { } try { if (!htbl.Contains(strERow[i].Trim())) { alist.Add(strERow[i].Trim()); htbl.Add(strERow[i].Trim(), "1"); } else { htbl[strERow[i].Trim()] = "1"; } } catch { } } for (int i = 0; i < alist.Count; i++) { try { if (Convert.ToString(htbl[alist[i].ToString()]).Equals("0")) { listBoxAll.Items.Add(alist[i].ToString()); } } catch { } } try { listBoxAll.SelectedIndex = (listBoxAll.Items.Count > 0 ? 0 : -1); listBoxUse.SelectedIndex = (listBoxUse.Items.Count > 0 ? 0 : -1); } catch { } proc_SetButtonEnabled(); } catch { } } private bool SaveSettings(out string strMsg) { strMsg = ""; string strElements = ""; try { for (int i = 0; i < listBoxUse.Items.Count; i++) { try { strElements += (strElements.Length > 0 ? "*" : "") + listBoxUse.Items[i].ToString(); } catch { } } ElementsConfig.SetElementsRow(strElements); } catch (Exception ex) { Console.WriteLine(ex.Message); strMsg = ex.Message; return false; } return true; } private void frmSetEleCols_KeyPress(object sender, KeyPressEventArgs e) { if (e.KeyChar == (char)System.Windows.Forms.Keys.Escape) { this.Close(); e.Handled = true; } } private void proc_SetButtonEnabled() { try { //btnL2RSingle.Enabled = (listBoxAll.Items.Count > 0 && listBoxAll.SelectedIndex >= 0); //btnL2RAll.Enabled = listBoxAll.Items.Count > 0; //btnR2LSingle.Enabled = (listBoxUse.Items.Count > 0 && listBoxUse.SelectedIndex >= 0); //btnR2LAll.Enabled = listBoxUse.Items.Count > 0; //btnUp.Enabled = (listBoxUse.Items.Count > 0 && listBoxUse.SelectedIndex > 0); //btnDown.Enabled = (listBoxUse.Items.Count > 0 && listBoxUse.SelectedIndex < listBoxUse.Items.Count - 1); ulblChoice.Enabled = (listBoxAll.Items.Count > 0 && listBoxAll.SelectedIndex >= 0); ulblAllChoice.Enabled = listBoxAll.Items.Count > 0; ulblCancel.Enabled = (listBoxUse.Items.Count > 0 && listBoxUse.SelectedIndex >= 0); ulblAllCancel.Enabled = listBoxUse.Items.Count > 0; ulblUp.Enabled = (listBoxUse.Items.Count > 0 && listBoxUse.SelectedIndex > 0); ulblDown.Enabled = (listBoxUse.Items.Count > 0 && listBoxUse.SelectedIndex < listBoxUse.Items.Count - 1); } catch { } } private void MoveListBoxItem(ListBox lstBx, int index, Direction direct) { try { object obj; if (index > 0 && index <= lstBx.Items.Count - 1 && direct == Direction.Up) { obj = lstBx.Items[index]; lstBx.Items[index] = lstBx.Items[index - 1]; lstBx.Items[index - 1] = obj; lstBx.SelectedIndex = index - 1; } else if (index >= 0 && index < lstBx.Items.Count - 1 && direct == Direction.Down) { obj = lstBx.Items[index]; lstBx.Items[index] = lstBx.Items[index + 1]; lstBx.Items[index + 1] = obj; lstBx.SelectedIndex = index + 1; } } catch { } } private void ultraLabel_Click(object sender, EventArgs e) { try { Infragistics.Win.Misc.UltraLabel ulabel = (Infragistics.Win.Misc.UltraLabel)sender; if (ulabel == null) { return; } if (ulabel.Name == ulblChoice.Name) { if (listBoxAll.Items.Count > 0 && listBoxAll.SelectedIndex >= 0) { int index = listBoxAll.SelectedIndex; object obj = listBoxAll.Items[index]; listBoxUse.Items.Add(obj); listBoxAll.Items.RemoveAt(index); listBoxUse.SelectedIndex = listBoxUse.Items.Count - 1; listBoxAll.SelectedIndex = ((index >= 0 && index < listBoxAll.Items.Count) ? index : (listBoxAll.Items.Count > 0 ? 0 : -1)); } } else if (ulabel.Name == ulblAllChoice.Name) { if (listBoxAll.Items.Count > 0) { for (int i = 0; i < listBoxAll.Items.Count; i++) { object obj = listBoxAll.Items[i]; listBoxUse.Items.Add(obj); } listBoxAll.Items.Clear(); listBoxUse.SelectedIndex = listBoxUse.Items.Count - 1; listBoxAll.SelectedIndex = -1; } } else if (ulabel.Name == ulblCancel.Name) { if (listBoxUse.Items.Count > 0 && listBoxUse.SelectedIndex >= 0) { int index = listBoxUse.SelectedIndex; object obj = listBoxUse.Items[index]; listBoxAll.Items.Add(obj); listBoxUse.Items.RemoveAt(index); listBoxAll.SelectedIndex = listBoxAll.Items.Count - 1; listBoxUse.SelectedIndex = ((index >= 0 && index < listBoxUse.Items.Count) ? index : (listBoxUse.Items.Count > 0 ? 0 : -1)); } } else if (ulabel.Name == ulblAllCancel.Name) { if (listBoxUse.Items.Count > 0) { for (int i = 0; i < listBoxUse.Items.Count; i++) { object obj = listBoxUse.Items[i]; listBoxAll.Items.Add(obj); } listBoxUse.Items.Clear(); listBoxAll.SelectedIndex = listBoxAll.Items.Count - 1; listBoxUse.SelectedIndex = -1; } } else if (ulabel.Name == ulblUp.Name) { MoveListBoxItem(listBoxUse, listBoxUse.SelectedIndex, Direction.Up); } else if (ulabel.Name == ulblDown.Name) { MoveListBoxItem(listBoxUse, listBoxUse.SelectedIndex, Direction.Down); } } catch { } } private void ucButton_Click(object sender, EventArgs e) { ucButton ucBtn = (ucButton)sender; if (ucBtn == null) { return; } try { if (ucBtn.Name == btnL2RSingle.Name) { if (listBoxAll.Items.Count > 0 && listBoxAll.SelectedIndex >= 0) { int index = listBoxAll.SelectedIndex; object obj = listBoxAll.Items[index]; listBoxUse.Items.Add(obj); listBoxAll.Items.RemoveAt(index); listBoxUse.SelectedIndex = listBoxUse.Items.Count - 1; listBoxAll.SelectedIndex = ((index >= 0 && index < listBoxAll.Items.Count) ? index : (listBoxAll.Items.Count > 0 ? 0 : -1)); } } else if (ucBtn.Name == btnL2RAll.Name) { if (listBoxAll.Items.Count > 0) { for (int i = 0; i < listBoxAll.Items.Count; i++) { object obj = listBoxAll.Items[i]; listBoxUse.Items.Add(obj); } listBoxAll.Items.Clear(); listBoxUse.SelectedIndex = listBoxUse.Items.Count - 1; listBoxAll.SelectedIndex = -1; } } else if (ucBtn.Name == btnR2LSingle.Name) { if (listBoxUse.Items.Count > 0 && listBoxUse.SelectedIndex >= 0) { int index = listBoxUse.SelectedIndex; object obj = listBoxUse.Items[index]; listBoxAll.Items.Add(obj); listBoxUse.Items.RemoveAt(index); listBoxAll.SelectedIndex = listBoxAll.Items.Count - 1; listBoxUse.SelectedIndex = ((index >= 0 && index < listBoxUse.Items.Count) ? index : (listBoxUse.Items.Count > 0 ? 0 : -1)); } } else if (ucBtn.Name == btnR2LAll.Name) { if (listBoxUse.Items.Count > 0) { for (int i = 0; i < listBoxUse.Items.Count; i++) { object obj = listBoxUse.Items[i]; listBoxAll.Items.Add(obj); } listBoxUse.Items.Clear(); listBoxAll.SelectedIndex = listBoxAll.Items.Count - 1; listBoxUse.SelectedIndex = -1; } } else if (ucBtn.Name == btnUp.Name) { MoveListBoxItem(listBoxUse, listBoxUse.SelectedIndex, Direction.Up); } else if (ucBtn.Name == btnDown.Name) { MoveListBoxItem(listBoxUse, listBoxUse.SelectedIndex, Direction.Down); } else if (ucBtn.Name == btnRestore.Name) { initCols(); } else if (ucBtn.Name == btnSave.Name) { string strMsg = ""; if (!SaveSettings(out strMsg)) { MessageBox.Show("设置保存失败!\r\n" + strMsg, "提示"); return; } else { this.DialogResult = DialogResult.OK; this.Close(); } } else if (ucBtn.Name == btnCancel.Name) { } proc_SetButtonEnabled(); } catch { } } private void listBox_SelectedIndexChanged(object sender, EventArgs e) { proc_SetButtonEnabled(); } private void ultraToolbarsManager1_ToolClick(object sender, Infragistics.Win.UltraWinToolbars.ToolClickEventArgs e) { switch (e.Tool.Key) { case "Restore": { initCols(); break; } case "Save": { string strMsg = ""; if (!SaveSettings(out strMsg)) { MessageBox.Show("设置保存失败!\r\n" + strMsg, "提示"); return; } else { this.DialogResult = DialogResult.OK; this.Close(); } break; } case "Close": { this.DialogResult = DialogResult.Cancel; this.Close(); break; } default: break; } } } }