| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420 |
- 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;
- }
- }
- }
- }
|