123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809 |
- using OTS.WinFormsUI.Docking;
- using SourceGrid;
- using System;
- using System.Collections.Generic;
- using System.Drawing;
- using System.Drawing.Imaging;
- using System.Runtime.InteropServices;
- using System.Windows.Forms;
- namespace OTSPartA_STDEditor
- {
- public partial class STDRuleslist : DockContent
- {
- public STDdata Predata = null;//之前选中的位置
- public Form_Main m_MainForm = null;
- ValueChangedEvent m_ValueChangedEvent = null;//单元格内容改变事件
- Dictionary<int,STDGroups> GroupViewDic=null;
- public STDRuleslist(Form_Main mainForm)
- {
- InitializeComponent();
- m_MainForm = mainForm;
- m_ValueChangedEvent = new ValueChangedEvent(this);
- }
- System.Collections.Hashtable table_STDRuleslist;
- private void STDRuleslist_Load(object sender, EventArgs e)
- {
- m_MainForm.lan = new Language(this);
- table_STDRuleslist = m_MainForm.lan.GetNameTable("Attributes");
- InitRuleView();
- button_UpOrder.Enabled = false;
- button_DownOrder.Enabled = false;
- }
- /// <summary>
- /// [颜色:16进制转成RGB]
- /// </summary>
- /// <param name="strColor">设置16进制颜色 [返回RGB]</param>
- /// <returns></returns>
- public static System.Drawing.Color colorHx16toRGB(string strHxColor)
- {
- try
- {
- if (strHxColor.Length == 0)
- {//如果为空
- return System.Drawing.Color.FromArgb(255, 255, 204);//设为白色
- }
- else
- {//转换颜色
- return System.Drawing.Color.FromArgb(System.Int32.Parse(strHxColor.Substring(1, 2), System.Globalization.NumberStyles.AllowHexSpecifier), System.Int32.Parse(strHxColor.Substring(3, 2), System.Globalization.NumberStyles.AllowHexSpecifier), System.Int32.Parse(strHxColor.Substring(5, 2), System.Globalization.NumberStyles.AllowHexSpecifier));
- }
- }
- catch
- {//设为白色
- return System.Drawing.Color.FromArgb(255, 255, 204);
- }
- }
- private void MineralsGrid_Click(object sender, EventArgs e)
- {
- SourceGrid.Grid ls_gd = (SourceGrid.Grid)sender;
- ls_gd.Focus();
- int i = ls_gd.Selection.ActivePosition.Row;
- int j = ls_gd.Selection.ActivePosition.Column;
- if (i >= 0 && j >= 0)
- {
- if (Predata != null)
- {
- m_MainForm.SaveDataOfSelRule(Predata.STDId);
- }
- m_MainForm.ChangeSTDEditorAndGrid_Attributes(((STDdata)Grid_Minerals[i, 0].Tag).STDId);
- m_MainForm.m_SubMidWindow.m_ComparativeLibrary.MakeCheckboxUnchecked();
- Predata = (STDdata)Grid_Minerals[i, 0].Tag;
- }
- SetOrderButtonsStatus();
- }
- private void ToolStripMenuItem_New_Click(object sender, EventArgs e)
- {
- int i = Grid_Minerals.Selection.ActivePosition.Row;
- int j = Grid_Minerals.Selection.ActivePosition.Column;
- if (i >= 0 && j >= 0)
- {
- int id = ((STDdata)Grid_Minerals[i, 0].Tag).STDId;
- m_MainForm.SaveDataOfSelRule(id);
- Predata = (STDdata)Grid_Minerals[i, 0].Tag;
- int STDId = m_MainForm._sTDEditor.AddSTDDictionaryItem();
- AddNewRow(STDId, "NewRuleName", Attributes.colorHx16toRGB(m_MainForm._sTDEditor.STDDictionary[STDId].Color));
- m_MainForm.m_SubMidWindow.m_ComparativeLibrary.MakeCheckboxUnchecked();
- }
- else
- {
- int STDId = m_MainForm._sTDEditor.AddSTDDictionaryItem();
- AddNewRow(STDId, "NewRuleName", Attributes.colorHx16toRGB(m_MainForm._sTDEditor.STDDictionary[STDId].Color));
- m_MainForm.m_SubMidWindow.m_ComparativeLibrary.MakeCheckboxUnchecked();
- }
- }
- public void AddNewRow(int STDId, string RuleName, Color color)
- {
- Grid_Minerals.Rows.Insert(Grid_Minerals.Rows.Count);
- Grid_Minerals[Grid_Minerals.Rows.Count - 1, 0] = new SourceGrid.Cells.Cell(RuleName, typeof(string));
- Grid_Minerals[Grid_Minerals.Rows.Count - 1, 0].Tag = m_MainForm._sTDEditor.STDDictionary[STDId];
- Grid_Minerals.Rows[Grid_Minerals.Rows.Count - 1].Height = 25;
- Grid_Minerals[Grid_Minerals.Rows.Count - 1, 1] = new SourceGrid.Cells.Cell();
- m_MainForm._sTDEditor.STDDictionary[STDId].StrName = RuleName;
- m_MainForm.ChangeSTDEditorAndGrid_Attributes(STDId);
- SourceGrid.Cells.Views.Cell view = new SourceGrid.Cells.Views.Cell();
- view.BackColor = color;
- Grid_Minerals[Grid_Minerals.Rows.Count - 1, 1].View = view;
- Position pos = new Position(Grid_Minerals.Rows.Count - 1, 0);
- Grid_Minerals.Selection.Focus(pos, true);
- Predata = (STDdata)Grid_Minerals[Grid_Minerals.Rows.Count - 1, 0].Tag;
- SetOrderButtonsStatus();
- }
- void Grid_MineralsDelRow()
- {
- int x = Grid_Minerals.Selection.ActivePosition.Row;
- if (x > 0)
- {
- m_MainForm.RemoveSTDDictionaryItem(((STDdata)Grid_Minerals[x, 0].Tag).STDId);
- Grid_Minerals.Rows.Remove(x);
- if (Grid_Minerals.RowsCount > 1)
- {
- if (x != Grid_Minerals.RowsCount)
- {
- Position pos = new Position(x, 0);
- Grid_Minerals.Selection.Focus(pos, true);
- Grid_Minerals[x, 0].Grid.Select();
- m_MainForm.ChangeSTDEditorAndGrid_Attributes(((STDdata)Grid_Minerals[x, 0].Tag).STDId);
- Predata = (STDdata)Grid_Minerals[x, 0].Tag;
- }
- else
- {
- Position pos = new Position(x - 1, 0);
- Grid_Minerals.Selection.Focus(pos, true);
- Grid_Minerals[x - 1, 0].Grid.Select();
- m_MainForm.ChangeSTDEditorAndGrid_Attributes(((STDdata)Grid_Minerals[x-1, 0].Tag).STDId);
- Predata = (STDdata)Grid_Minerals[x-1, 0].Tag;
- }
- }
- else
- {
- m_MainForm.SetNull();
- Predata = null;
- }
- }
- else
- {
- MessageBox.Show("There is no rule to delete!", "Tip");
- }
- }
- private void ToolStripMenuItem_Del_Click(object sender, EventArgs e)
- {
- Grid_MineralsDelRow();
- }
- public class ValueChangedEvent : SourceGrid.Cells.Controllers.ControllerBase
- {
- protected STDRuleslist m_parentWnd = null;
- public ValueChangedEvent(STDRuleslist parentWnd)
- {
- m_parentWnd = parentWnd;
- }
- public override void OnValueChanged(SourceGrid.CellContext sender, EventArgs e)
- {
- base.OnValueChanged(sender, e);
- if (sender.Value != null&& sender.Value.ToString().Replace(" ", "").Trim() != "")
- {
- m_parentWnd.ChangeStrName(sender.Position.Row, sender.Value.ToString());
- }
- else
- {
- m_parentWnd.ChangeStrName(sender.Position.Row, "NewRuleName");
- m_parentWnd.Grid_Minerals[sender.Position.Row,0].Value = "NewRuleName";
- }
- }
- }
- public void ChangeStrName(int RowNum, string NewStrName)
- {
- m_MainForm.ChangeStrName(RowNum, NewStrName);
- }
- private void Grid_Minerals_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e)
- {
- SourceGrid.Grid ls_gd = (SourceGrid.Grid)sender;
- ls_gd.Focus();
- int i = ls_gd.Selection.ActivePosition.Row;
- int j = ls_gd.Selection.ActivePosition.Column;
- if(i==-1)
- {
- return;
- }
- if (e.KeyCode == Keys.Up)
- {
- if (i >= 2 && j >= 0)
- {
- //规则名称不为空
- if (Grid_Minerals[i, 0].Value.ToString().Replace(" ", "").Trim() != "")
- {
- int id = ((STDdata)Grid_Minerals[i, 0].Tag).STDId;
- m_MainForm.SaveDataOfSelRule(id);
- m_MainForm.ChangeSTDEditorAndGrid_Attributes(((STDdata)Grid_Minerals[i - 1, 0].Tag).STDId);
- m_MainForm.m_SubMidWindow.m_ComparativeLibrary.MakeCheckboxUnchecked();
- Predata = (STDdata)Grid_Minerals[i - 1, 0].Tag;
- if (i == 2)
- {
- button_UpOrder.Enabled = false;
- }
- if (i == ls_gd.RowsCount - 1)
- {
- button_DownOrder.Enabled = true;
- }
- }
- else
- {
- Position pos = new Position(i + 1, 0);
- Grid_Minerals.Selection.Focus(pos, true);
- m_MainForm.m_SubMidWindow.m_ComparativeLibrary.MakeCheckboxUnchecked();
- }
- }
- }
- if (e.KeyCode == Keys.Down)
- {
- if (i < ls_gd.RowsCount - 1 && j >= 0)
- {
- if (Grid_Minerals[i, 0].Value.ToString().Replace(" ", "").Trim() != "")
- {
- int id = ((STDdata)Grid_Minerals[i, 0].Tag).STDId;
-
- m_MainForm.SaveDataOfSelRule(id);
- m_MainForm.ChangeSTDEditorAndGrid_Attributes(((STDdata)Grid_Minerals[i + 1, 0].Tag).STDId);
- Predata = (STDdata)Grid_Minerals[i+1, 0].Tag;
- m_MainForm.m_SubMidWindow.m_ComparativeLibrary.MakeCheckboxUnchecked();
- if (i == 1)
- {
- button_UpOrder.Enabled = true;
- }
- if (i == ls_gd.RowsCount - 2)
- {
- button_DownOrder.Enabled = false;
- }
-
- }
- else
- {
- Position pos = new Position(i - 1, 0);
- Grid_Minerals.Selection.Focus(pos, true);
- m_MainForm.m_SubMidWindow.m_ComparativeLibrary.MakeCheckboxUnchecked();
- }
- }
- }
- if (e.KeyCode == Keys.Delete)
- {
- Grid_MineralsDelRow();
- }
- }
- public int ChangeSTDRulesLISTBackColor()
- {
- if (tabControl1.SelectedIndex == 1)
- {
- if (Grid_Minerals.RowsCount > 1)
- {
- Position pos = new Position(1, 0);
- Grid_Minerals[1, 0].Grid.Select();
- Grid_Minerals[Grid_Minerals.Selection.ActivePosition.Row, 1].View.BackColor = m_MainForm.m_Attributes.Grid_Attributes[3, 1].View.BackColor;
- m_MainForm._sTDEditor.STDDictionary[((STDdata)Grid_Minerals[Grid_Minerals.Selection.ActivePosition.Row, 0].Tag).STDId].Color = Attributes.colorRGBtoHx16(m_MainForm.m_Attributes.Grid_Attributes[3, 1].View.BackColor.R, m_MainForm.m_Attributes.Grid_Attributes[3, 1].View.BackColor.G, m_MainForm.m_Attributes.Grid_Attributes[3, 1].View.BackColor.B);
- Grid_Minerals.Refresh();
- return ((STDdata)Grid_Minerals[Grid_Minerals.Selection.ActivePosition.Row, 0].Tag).STDId;
- }
- else
- {
- return -1;
- }
- }
- else
- {
- if(treeView_G.SelectedNode.Level==0)
- {
- return -1;
- }
- STDdata ddata = (STDdata)treeView_G.SelectedNode.Tag;
- int id= ddata.STDId;
- m_MainForm._sTDEditor.STDDictionary[id].Color = Attributes.colorRGBtoHx16(m_MainForm.m_Attributes.Grid_Attributes[3, 1].View.BackColor.R, m_MainForm.m_Attributes.Grid_Attributes[3, 1].View.BackColor.G, m_MainForm.m_Attributes.Grid_Attributes[3, 1].View.BackColor.B);
- InitGroupView();
- foreach(TreeNode treeNode in treeView_G.Nodes)
- {
- if(((STDGroups)treeNode.Tag).id== ddata.GroupId)
- {
- foreach (TreeNode node in treeNode.Nodes)
- {
- if (((STDdata)node.Tag).STDId == id)
- {
- treeView_G.SelectedNode = node;
- Predata = (STDdata)node.Tag;
- }
- }
- }
- }
- return id;
- }
- }
- private void button_UpOrder_Click(object sender, EventArgs e)
- {
-
- }
- private void button_DownOrder_Click(object sender, EventArgs e)
- {
-
- }
- public void InsertNewRow(int STDId, string RuleName, Color color)
- {
- Grid_Minerals.Focus(true);
- Grid_Minerals.Rows.InsertRange(Grid_Minerals.Selection.ActivePosition.Row, 1);
- int i = Grid_Minerals.Selection.ActivePosition.Row;
- Grid_Minerals[Grid_Minerals.Selection.ActivePosition.Row, 0] = new SourceGrid.Cells.Cell(RuleName, typeof(string));
- Grid_Minerals[Grid_Minerals.Selection.ActivePosition.Row, 0].Tag = m_MainForm._sTDEditor.STDDictionary[STDId];
- Grid_Minerals.Rows[Grid_Minerals.Selection.ActivePosition.Row].Height = 25;
- Grid_Minerals[Grid_Minerals.Selection.ActivePosition.Row, 1] = new SourceGrid.Cells.Cell();
- m_MainForm.ChangeSTDEditorAndGrid_Attributes(STDId);
- Grid_Minerals.Focus(true);
- SourceGrid.Cells.Views.Cell view = new SourceGrid.Cells.Views.Cell();
- view.BackColor = color;
- Grid_Minerals[Grid_Minerals.Selection.ActivePosition.Row, 1].View = view;
- Position pos = new Position(Grid_Minerals.Selection.ActivePosition.Row, 0);
- Grid_Minerals.Selection.Focus(pos, true);
- Predata = (STDdata)Grid_Minerals[Grid_Minerals.Selection.ActivePosition.Row - 1, 0].Tag ;
- SetOrderButtonsStatus();
- }
- void SetOrderButtonsStatus()
- {
- Grid_Minerals.Focus();
- int i = Grid_Minerals.Selection.ActivePosition.Row;
- int j = Grid_Minerals.Selection.ActivePosition.Column;
- if (i != -1)
- {
- if (i == 1)
- {
- button_UpOrder.Enabled = false;
- }
- else
- {
- button_UpOrder.Enabled = true;
- }
- if (i == Grid_Minerals.RowsCount - 1)
- {
- button_DownOrder.Enabled = false;
- }
- else
- {
- button_DownOrder.Enabled = true;
- }
- }
- else
- {
- button_UpOrder.Enabled = false;button_DownOrder.Enabled = false;
- }
- }
- private void tabControl1_SelectedIndexChanged(object sender, EventArgs e)
- {
- if (Predata != null)
- {
- m_MainForm.SaveDataOfSelRule(Predata.STDId);
- }
- if (tabControl1.SelectedIndex == 0)
- {
- Predata = null;
- InitGroupEditorView();
- }
- else if (tabControl1.SelectedIndex == 1)
- {
- ConvertToRuleViewDic();
- InitRuleView();
- //int i = Grid_Minerals.Selection.ActivePosition.Row;
- //int j = Grid_Minerals.Selection.ActivePosition.Column;
- //if (i >= 0 && j >= 0)
- //{
- // int id = ((STDdata)Grid_Minerals[i, 0].Tag).STDId;
- // if (m_MainForm._sTDEditor.STDDictionary.ContainsKey(id))
- // {
- // m_MainForm.ChangeSTDEditorAndGrid_Attributes(id);
- // Predata = (STDdata)Grid_Minerals[i, 0].Tag;
- // }
- if (m_MainForm._sTDEditor.STDDictionary.Count == 0)
- {
- m_MainForm.SetNull();
- Predata = null;
- }
- else
- {
- Position pos = new Position(1, 0);
- Grid_Minerals[1, 0].Grid.Select();
- Grid_Minerals.Selection.Focus(pos, true);
- Grid_Minerals.Refresh();
- m_MainForm.ChangeSTDEditorAndGrid_Attributes(((STDdata)Grid_Minerals[1, 0].Tag).STDId);
-
- Predata = (STDdata)Grid_Minerals[1, 0].Tag;
- }
- //}
- }
- }
- void InitGroupEditorView()
- {
- GroupViewDic = ConvertToGroupViewDic();
- InitGroupView();
- }
- Dictionary<int, STDGroups> ConvertToGroupViewDic()
- {
- Dictionary<int, STDGroups> keyValuePairs = new Dictionary<int, STDGroups>();
- keyValuePairs = m_MainForm._sTDEditor.GroupDictionary;
- foreach (STDGroups group in keyValuePairs.Values)
- {
- group.ContainSTD.Clear();
- }
- foreach (STDdata Ddata in m_MainForm._sTDEditor.STDDictionary.Values)
- {
- keyValuePairs[Ddata.GroupId].ContainSTD.Add(Ddata);
- }
- return keyValuePairs;
- }
- public void ConvertToRuleViewDic()
- {
- m_MainForm._sTDEditor.GroupIdDictionaryFromId.Clear();
- m_MainForm._sTDEditor.GroupIdDictionaryFromName.Clear();
- m_MainForm._sTDEditor.STDDictionary.Clear();
- foreach (STDGroups group in GroupViewDic.Values)
- {
- foreach (STDdata Ddata in group.ContainSTD)
- {
- m_MainForm._sTDEditor.STDDictionary.Add(Ddata.STDId, Ddata);
- }
- m_MainForm._sTDEditor.GroupIdDictionaryFromName.Add(group.name.ToString(), int.Parse(group.id.ToString()));
- m_MainForm._sTDEditor.GroupIdDictionaryFromId.Add(int.Parse(group.id.ToString()), group.name.ToString());
- }
- if (treeView_G.SelectedNode == null){return;}
- if (treeView_G.SelectedNode.Level == 1)
- {
- m_MainForm.SaveDataOfSelRule(((STDdata)treeView_G.SelectedNode.Tag).STDId);
- }
- }
- private void ToolStripMenuItem_NewGroup_Click(object sender, EventArgs e)
- {
- STDGroups group = new STDGroups();
- int id = 0;
- foreach(STDGroups grp in GroupViewDic.Values)
- {
- if(grp.id>id)
- {
- id= grp.id;
- }
- }
- id++;
- group.id = id;
- group.name = "Group" + id.ToString();
- group.color = Attributes.colorRGBtoHx16(Color.WhiteSmoke.R, Color.WhiteSmoke.G, Color.WhiteSmoke.B);
- GroupViewDic.Add(group.id, group);
- m_MainForm.m_Attributes.AddSTDGroupsToAttribute();
- this.Refresh();
- TreeNode treeNode = new TreeNode();
- treeNode.Tag = group;
- treeNode.Text = group.name;
- m_MainForm._sTDEditor.GroupIdDictionaryFromId.Add(id, group.name);
- m_MainForm._sTDEditor.GroupIdDictionaryFromName.Add(group.name, group.id);
- treeView_G.Nodes.Add(treeNode);
- treeView_G.SelectedNode = treeNode;
- m_MainForm.SetNull();
- Predata = null;
- }
- private void ToolStripMenuItem_DelGroup_Click(object sender, EventArgs e)
- {
- if(treeView_G.SelectedNode==null)
- {
- MessageBox.Show("Please select a group!", "Tip");
- return;
- }
- if (treeView_G.SelectedNode.Level == 0)
- {
- int id = ((STDGroups)treeView_G.SelectedNode.Tag).id;
- if(((STDGroups)treeView_G.SelectedNode.Tag).id==0)
- {
- MessageBox.Show("Can not delete the group which named default!", "Tip");
- return;
- }
- DialogResult result = MessageBox.Show("删除组会一并删除组内规则,是否继续?", "Tip", MessageBoxButtons.YesNo);
- if (result == DialogResult.Yes)
- {
- m_MainForm._sTDEditor.GroupIdDictionaryFromId.Remove(id);
- m_MainForm._sTDEditor.GroupIdDictionaryFromName.Remove(GroupViewDic[id].name);
- GroupViewDic.Remove(id);
- treeView_G.Nodes.Remove(treeView_G.SelectedNode);
- this.Refresh();
- }
- }
- else
- {
- MessageBox.Show("Please select a group!", "Tip");
- return;
- }
- }
- private void ToolStripMenuItem_EdGroupColor_Click(object sender, EventArgs e)
- {
- if(treeView_G.SelectedNode==null)
- {
- MessageBox.Show("Please select a group!", "Tip");
- return;
- }
- if (treeView_G.SelectedNode.Level == 0)
- {
- ColorDialog cd = new ColorDialog();
- cd.FullOpen = true;//自定义颜色界面打开
- DialogResult result = cd.ShowDialog();
- if (result == DialogResult.OK)
- {
- GroupViewDic[((STDGroups)treeView_G.SelectedNode.Tag).id].color = Attributes.colorRGBtoHx16(cd.Color.R, cd.Color.G, cd.Color.B);
- InitGroupView();
- }
- }
- else
- {
- MessageBox.Show("Please select a group!", "Tip");
- }
- }
- void InitGroupView()
- {
- treeView_G.ImageList=new ImageList();
- treeView_G.Nodes.Clear();
- treeView_G.ImageList.ColorDepth = ColorDepth.Depth32Bit;
- foreach (STDGroups group in GroupViewDic.Values)
- {
- TreeNode treeNode = new TreeNode();
- treeNode.Tag = group;
- treeNode.Text = group.name;
- Color color = Attributes.colorHx16toRGB(group.color);
- Bitmap bitmap = new Bitmap(100, 100, PixelFormat.Format32bppArgb);
- Graphics graphics = Graphics.FromImage(bitmap);
- SolidBrush b1 = new SolidBrush(color);
- graphics.FillEllipse(b1, new Rectangle(0, 0, 100, 100));
- treeView_G.ImageList.Images.Add(group.id.ToString(),bitmap);
- treeNode.ImageKey = group.id.ToString();
- treeNode.SelectedImageKey = group.id.ToString();
- treeView_G.Nodes.Add(treeNode);
- foreach (STDdata ddata in group.ContainSTD)
- {
- TreeNode childtreeNode = new TreeNode();
- childtreeNode.Tag = ddata;
- childtreeNode.Text = ddata.StrName;
- Color color2 = Attributes.colorHx16toRGB(ddata.Color);
- SolidBrush b2 = new SolidBrush(color2);
- graphics.FillEllipse(b2, new Rectangle(0, 0, 100, 100));
- treeView_G.ImageList.Images.Add("0x"+ ddata.STDId, bitmap);
- //bitmap.Save(@"C:\Users\yunyunyun\Desktop\9-9-1\a\"+ ddata.STDId + @".bmp");
- childtreeNode.ImageKey = "0x" + ddata.STDId;
- childtreeNode.SelectedImageKey = "0x" + ddata.STDId;
- treeNode.Nodes.Add(childtreeNode);
- }
- }
- treeView_G.Font = new Font("微软雅黑", 12);
- treeView_G.ShowLines = false;
- this.Refresh();
- }
- void InitRuleView()
- {
- Grid_Minerals.Rows.Clear();
- Grid_Minerals.Columns.Clear();
- Grid_Minerals.Redim(m_MainForm._sTDEditor.STDDictionary.Count + 1, 2);
- SourceGrid.Cells.ColumnHeader head1 = null;
- if (m_MainForm.lan.GetNameTable("Form_Main")["language"].ToString() == "EN")
- {
- head1 = new SourceGrid.Cells.ColumnHeader("Rule Name");
- }
- else
- {
- head1 = new SourceGrid.Cells.ColumnHeader("规则名称");
- }
- Grid_Minerals[0, 0] = head1;
- SourceGrid.Cells.ColumnHeader head2 = null;
- if (m_MainForm.lan.GetNameTable("Form_Main")["language"].ToString() == "EN")
- {
- head2 = new SourceGrid.Cells.ColumnHeader("Color");
- }
- else
- {
- head2 = new SourceGrid.Cells.ColumnHeader("颜色");
- }
- Grid_Minerals[0, 1] = head2;
- SourceGrid.Cells.Views.ColumnHeader boldHeader = new SourceGrid.Cells.Views.ColumnHeader();
- boldHeader.Font = new Font("Microsoft YaHei UI", 11, FontStyle.Bold);
- boldHeader.TextAlignment = DevAge.Drawing.ContentAlignment.MiddleCenter;
- Grid_Minerals[0, 0].View = boldHeader;
- Grid_Minerals[0, 1].View = boldHeader;
- Grid_Minerals.Rows.SetHeight(0, 25);
- head1.AutomaticSortEnabled = false;
- head2.AutomaticSortEnabled = false;
- Grid_Minerals.Selection.EnableMultiSelection = false;
- Grid_Minerals.AutoStretchColumnsToFitWidth = true;
- Grid_Minerals.Columns[0].Width = this.Width / 2 - 15;
- Grid_Minerals.Columns[1].Width = this.Width / 2 - 39;
- int i = 1;
- foreach (KeyValuePair<int, STDdata> kv in m_MainForm._sTDEditor.STDDictionary)
- {
- Grid_Minerals[i, 0] = new SourceGrid.Cells.Cell(kv.Value.StrName, typeof(string));
- Grid_Minerals.Rows[i].Height = 25;
- Grid_Minerals[i, 0].Tag = kv.Value;
- Grid_Minerals[i, 1] = new SourceGrid.Cells.Cell();
- SourceGrid.Cells.Views.Cell view = new SourceGrid.Cells.Views.Cell();
- view.BackColor = colorHx16toRGB(kv.Value.Color);
- Grid_Minerals[i, 1].View = view;
- i++;
- }
- Grid_Minerals.Controller.AddController(m_ValueChangedEvent);
- Grid_Minerals.FixedRows = 1;
- Grid_Minerals.Selection.FocusStyle = FocusStyle.None;
- }
- private void treeView_G_ItemDrag(object sender, ItemDragEventArgs e)
- {
- if (e.Button == MouseButtons.Left)
- {
- //只处理左键拖拽操作;
- m_targetNode = null;
- TreeNode _node = (TreeNode)e.Item;
- //只允许拖拽子级节点;
- if (_node.Level > 0)
- {
- //开始拖拽;
- DoDragDrop(e.Item, DragDropEffects.Move | DragDropEffects.Copy);
- }
- }
- }
- TreeNode m_targetNode; //用于记录当前拖拽到的目标节点;
- private void treeView_G_DragDrop(object sender, DragEventArgs e)
- {
- if (m_targetNode != null)
- {
- TreeNode _node = (TreeNode)e.Data.GetData(typeof(TreeNode));
- if (!m_targetNode.Equals(_node))
- {
- if (m_targetNode.Level == _node.Level)
- {
- //1. 不同的父节点;
- //2. 被拖拽的节点不在目标节点的上面(相邻);
- if (!_node.Parent.Equals(m_targetNode.Parent) || m_targetNode.Index - 1 != _node.Index)
- {
- _node.Remove();
- m_targetNode.Parent.Nodes.Insert(m_targetNode.Index, _node);
- m_targetNode.Parent.ExpandAll();
- }
- }
- else
- {
- GroupViewDic[((STDGroups)_node.Parent.Tag).id].ContainSTD.Remove((STDdata)_node.Tag);
- _node.Remove();
- ((STDdata)_node.Tag).GroupId = ((STDGroups)m_targetNode.Tag).id;
- m_targetNode.Nodes.Add(_node);
- GroupViewDic[((STDGroups)m_targetNode.Tag).id].ContainSTD.Add((STDdata)_node.Tag);
- treeView_G.SelectedNode = _node; // 选中节点
- m_targetNode.Expand(); // 展开父节点
- m_MainForm.ChangeSTDEditorAndGrid_Attributes(int.Parse(((STDdata)_node.Tag).STDId.ToString()));
- Predata = (STDdata)_node.Tag;
- }
- }
- m_targetNode = null;
- _node = null;
- }
- }
- [DllImport("user32.dll")]
- private static extern int SendMessage(IntPtr hWnd, int wMsg, int wParam,int lParam);
- private void treeView_G_DragOver(object sender, DragEventArgs e)
- {
- const Single scrollRegion = 20;
- Point pt = treeView_G.PointToClient(Cursor.Position);
- if ((pt.Y + scrollRegion) > treeView_G.Height)
- {
- SendMessage(treeView_G.Handle, (int)277, (int)1, 0);
- }
- else if (pt.Y < (treeView_G.Top + scrollRegion))
- {
- SendMessage(treeView_G.Handle, (int)277, (int)0, 0);
- }
- TreeNode _node2 = treeView_G.GetNodeAt(treeView_G.PointToClient(new Point(e.X, e.Y)));
- m_targetNode = null;
- if (_node2 != null)
- {
- m_targetNode = _node2;
- e.Effect = DragDropEffects.Move;
- }
- else
- {
- e.Effect = DragDropEffects.None;
- }
- }
- private void treeView_G_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
- {
- if(Predata!=null)
- {
- m_MainForm.SaveDataOfSelRule(Predata.STDId);
- }
- if(e.Node.Level==0)
- {
- m_MainForm.SetNull();
- Predata = null;
- }
- else
- {
- m_MainForm.ChangeSTDEditorAndGrid_Attributes(int.Parse(((STDdata)e.Node.Tag).STDId.ToString()));
- Predata = (STDdata)e.Node.Tag;
- }
- }
- public void AdjustTreenodeByGroup(int Groupid)
- {
- if (m_MainForm.m_STDRuleslist.tabControl1.SelectedIndex == 1)
- {
- return;
- }
- if (treeView_G.SelectedNode.Level == 0)
- {
- return;
- }
- STDdata ddata = (STDdata)treeView_G.SelectedNode.Tag;
- TreeNode nodenew = null;
- foreach (TreeNode node in treeView_G.Nodes)
- {
- if (((STDGroups)node.Tag).id == Groupid)
- {
- nodenew = node;break;
- }
- }
- foreach (TreeNode node in treeView_G.Nodes)
- {
- foreach (TreeNode node1 in node.Nodes)
- {
- if (((STDdata)node1.Tag).STDId == ddata.STDId)
- {
- GroupViewDic[((STDGroups)node.Tag).id].ContainSTD.Remove(ddata);
- node1.Remove();
- ((STDdata)node1.Tag).GroupId = ddata.GroupId;
- nodenew.Nodes.Add(node1);
- GroupViewDic[Groupid].ContainSTD.Add(ddata);
- treeView_G.SelectedNode = node1;
- nodenew.Expand();
- m_MainForm.ChangeSTDEditorAndGrid_Attributes(int.Parse(((STDdata)node1.Tag).STDId.ToString()));
- Predata = ddata;
- break;
- }
- }
- }
- }
- }
- }
|