using OTS.WinFormsUI.Docking;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace OTSPartA_STDEditor
{
public partial class Attributes : DockContent
{
public Form_Main m_MainForm = null;
///
/// [颜色:16进制转成RGB]
///
/// 设置16进制颜色 [返回RGB]
///
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);
}
}
///
/// [颜色:RGB转成16进制]
///
/// 红 int
/// 绿 int
/// 蓝 int
///
public static string colorRGBtoHx16(int R, int G, int B)
{
return System.Drawing.ColorTranslator.ToHtml(System.Drawing.Color.FromArgb(R, G, B));
}
private void clickEvent_Click(object sender, EventArgs e)
{
SourceGrid.CellContext context = (SourceGrid.CellContext)sender;
int i = context.Position.Row;
int j = context.Position.Column;
/// 保证鼠标点击的GRID行和列是有效的
if (i >= 0 && j >= 0)
{
ColorDialog cd = new ColorDialog();
cd.FullOpen = true;//自定义颜色界面打开
DialogResult result = cd.ShowDialog();
if (result == DialogResult.OK)
{
SourceGrid.Cells.Views.Cell view = new SourceGrid.Cells.Views.Cell();
view.BackColor = cd.Color;
Grid_Attributes[i, j].View = view;
m_MainForm.ChangeSTDRulesLISTBackColor();
}
}
Grid_Attributes.Refresh();
}
private void EditorEvent_EditEnded(object sender, EventArgs e)
{
SourceGrid.CellContext context = (SourceGrid.CellContext)sender;
//if(Grid_Attributes[context.Position.Row, context.Position.Column].Value==null)
//{
// MessageBox.Show("The name of rule cannot be null!", "warnning");
// return;
//}
m_MainForm.ChangeSTDRuleName(Convert.ToString( Grid_Attributes[context.Position.Row, context.Position.Column].Value));
}
private class MyHeader : SourceGrid.Cells.ColumnHeader
{
public MyHeader(object value) : base(value)
{
SourceGrid.Cells.Views.ColumnHeader view = new SourceGrid.Cells.Views.ColumnHeader();
view.Font = new Font(FontFamily.GenericSansSerif, 9, FontStyle.Bold);
view.TextAlignment = DevAge.Drawing.ContentAlignment.MiddleLeft;
//view.BackColor = Color.Green;
//view.ForeColor= Color.Red;
View = view;
//自带排序true;不实现排序false
AutomaticSortEnabled = false;
}
}
public Attributes(Form_Main mainForm)
{
InitializeComponent();
m_MainForm = mainForm;
}
private void Attributes_Load(object sender, EventArgs e)
{
m_MainForm.lan = new Language(this);
Grid_Attributes.Redim(13, 2);
if (m_MainForm.lan.GetNameTable("Form_ConstantsEditor2")["language"].ToString() == "ZH")
{
//SourceGrid.Cells.ColumnHeader head1 = new SourceGrid.Cells.ColumnHeader("通用属性");
Grid_Attributes[0, 0] = new SourceGrid.Cells.Cell("通用属性 ", typeof(string));
//head1.AutomaticSortEnabled = false;
Grid_Attributes[1, 0] = new SourceGrid.Cells.Cell("STDId ", typeof(string));
Grid_Attributes[2, 0] = new SourceGrid.Cells.Cell("规则名称 ", typeof(string));
Grid_Attributes[3, 0] = new SourceGrid.Cells.Cell("颜色", typeof(string));
Grid_Attributes[4, 0] = new SourceGrid.Cells.Cell("是否元素分析 ", typeof(string));
Grid_Attributes[5, 0] = new SourceGrid.Cells.Cell("硬度", typeof(string));
Grid_Attributes[6, 0] = new SourceGrid.Cells.Cell("密度", typeof(string));
Grid_Attributes[7, 0] = new SourceGrid.Cells.Cell("导电性", typeof(string));
Grid_Attributes[8, 0] = new SourceGrid.Cells.Cell("BSE", typeof(string));
Grid_Attributes[9, 0] = new SourceGrid.Cells.Cell("化学式", typeof(string));
Grid_Attributes[10, 0] = new SourceGrid.Cells.Cell("元素", typeof(string));
Grid_Attributes[11, 0] = new SourceGrid.Cells.Cell("分组名称", typeof(string));
}
else
{
Grid_Attributes[0, 0] = new SourceGrid.Cells.Cell("General Properties", typeof(string));
Grid_Attributes[1, 0] = new SourceGrid.Cells.Cell("STDId ", typeof(string));
Grid_Attributes[2, 0] = new SourceGrid.Cells.Cell("RuleName ", typeof(string));
Grid_Attributes[3, 0] = new SourceGrid.Cells.Cell("Color", typeof(string));
Grid_Attributes[4, 0] = new SourceGrid.Cells.Cell("IfElementAnalysis", typeof(string));
Grid_Attributes[5, 0] = new SourceGrid.Cells.Cell("Hardness", typeof(string));
Grid_Attributes[6, 0] = new SourceGrid.Cells.Cell("Density", typeof(string));
Grid_Attributes[7, 0] = new SourceGrid.Cells.Cell("Conductivity", typeof(string));
Grid_Attributes[8, 0] = new SourceGrid.Cells.Cell("BSE", typeof(string));
Grid_Attributes[9, 0] = new SourceGrid.Cells.Cell("Formula", typeof(string));
Grid_Attributes[10, 0] = new SourceGrid.Cells.Cell("Element", typeof(string));
Grid_Attributes[11, 0] = new SourceGrid.Cells.Cell("GroupName", typeof(string));
}
Grid_Attributes[1, 1] = new SourceGrid.Cells.Cell(" ", typeof(int));
Grid_Attributes[2, 1] = new SourceGrid.Cells.Cell(" ", typeof(string));
Grid_Attributes[3, 1] = new SourceGrid.Cells.Cell("", typeof(string));
Grid_Attributes[4, 1] = new SourceGrid.Cells.CheckBox(null, true);
Grid_Attributes[5, 1] = new SourceGrid.Cells.Cell("", typeof(string));
Grid_Attributes[6, 1] = new SourceGrid.Cells.Cell("", typeof(string));
Grid_Attributes[7, 1] = new SourceGrid.Cells.Cell("", typeof(string));
Grid_Attributes[8, 1] = new SourceGrid.Cells.Cell("", typeof(int));
Grid_Attributes[9, 1] = new SourceGrid.Cells.Cell("", typeof(string));
Grid_Attributes[10, 1] = new SourceGrid.Cells.Cell("", typeof(string));
Grid_Attributes[11, 1] = new SourceGrid.Cells.Cell("", typeof(string));
Grid_Attributes[0, 0].ColumnSpan = 2;
Grid_Attributes.AutoStretchColumnsToFitWidth = true;
Grid_Attributes.Columns[0].Width = 195;
Grid_Attributes.Columns[1].Width = 195;
for (int i=0;i<10;i++)
{
Grid_Attributes.Rows[i].Height = 25;
}
SourceGrid.Cells.Views.Cell view = new SourceGrid.Cells.Views.Cell();
view.Font = new Font(FontFamily.GenericSansSerif, 10, FontStyle.Bold);
view.TextAlignment = DevAge.Drawing.ContentAlignment.MiddleCenter;
view.BackColor = Color.LightGray;
Grid_Attributes[0, 0].View = view;
SourceGrid.Cells.Controllers.CustomEvents EditorEvent = new SourceGrid.Cells.Controllers.CustomEvents();
EditorEvent.EditEnded += new EventHandler(EditorEvent_EditEnded);
Grid_Attributes[2, 1].AddController(EditorEvent);
SourceGrid.Cells.Controllers.CustomEvents clickEvent = new SourceGrid.Cells.Controllers.CustomEvents();
clickEvent.Click += new EventHandler(clickEvent_Click);
Grid_Attributes[3,1].AddController(clickEvent);
Grid_Attributes[0, 1].AddController(SourceGrid.Cells.Controllers.Unselectable.Default);
Grid_Attributes[1, 1].AddController(SourceGrid.Cells.Controllers.Unselectable.Default);
Grid_Attributes[3, 1].AddController(SourceGrid.Cells.Controllers.Unselectable.Default);
Grid_Attributes[0, 0].AddController(SourceGrid.Cells.Controllers.Unselectable.Default);
Grid_Attributes[1, 0].AddController(SourceGrid.Cells.Controllers.Unselectable.Default);
Grid_Attributes[2, 0].AddController(SourceGrid.Cells.Controllers.Unselectable.Default);
Grid_Attributes[3, 0].AddController(SourceGrid.Cells.Controllers.Unselectable.Default);
Grid_Attributes[4, 0].AddController(SourceGrid.Cells.Controllers.Unselectable.Default);
Grid_Attributes[5, 0].AddController(SourceGrid.Cells.Controllers.Unselectable.Default);
Grid_Attributes[6, 0].AddController(SourceGrid.Cells.Controllers.Unselectable.Default);
Grid_Attributes[7, 0].AddController(SourceGrid.Cells.Controllers.Unselectable.Default);
Grid_Attributes[8, 0].AddController(SourceGrid.Cells.Controllers.Unselectable.Default);
Grid_Attributes[9, 0].AddController(SourceGrid.Cells.Controllers.Unselectable.Default);
Grid_Attributes[10, 0].AddController(SourceGrid.Cells.Controllers.Unselectable.Default);
Grid_Attributes.Selection.FocusStyle = SourceGrid.FocusStyle.None;
//SourceGrid.Position po = new SourceGrid.Position(1, 0);
//Grid_Attributes[1, 0].Grid.Select();
//Grid_Attributes.Selection.Focus(po, true);
}
public void SetDatatoGrid_Attributes(int STDId)
{
Grid_Attributes[1, 1].Value = STDId;
Grid_Attributes[2, 1].Value = m_MainForm.STDDictionary[STDId].StrName;
SourceGrid.Cells.Views.Cell view = new SourceGrid.Cells.Views.Cell();
view.BackColor = colorHx16toRGB(m_MainForm.STDDictionary[STDId].Color);
Grid_Attributes[3, 1].View = view;
Grid_Attributes[4, 1].Value = Convert.ToBoolean(m_MainForm.STDDictionary[STDId].IfElementAnalysis);
Grid_Attributes[5, 1].Value = m_MainForm.STDDictionary[STDId].Hardness;
Grid_Attributes[6, 1].Value = m_MainForm.STDDictionary[STDId].Density;
Grid_Attributes[7, 1].Value = m_MainForm.STDDictionary[STDId].Electrical_conductivity;
Grid_Attributes[8, 1].Value = int.Parse(m_MainForm.STDDictionary[STDId].BSE);
Grid_Attributes[9, 1].Value = m_MainForm.STDDictionary[STDId].Formula;
Grid_Attributes[10, 1].Value = m_MainForm.STDDictionary[STDId].Element;
//m_MainForm.AddSTDGroupsToAttribute();
Grid_Attributes[11, 1].Value = m_MainForm.GroupIdDictionaryFromId[int.Parse(m_MainForm.STDDictionary[STDId].GroupId)];
//SourceGrid.Position po = new SourceGrid.Position(1, 0);
//Grid_Attributes[1, 0].Grid.Select();
//Grid_Attributes.Selection.Focus(po, true);
Grid_Attributes.Refresh();
}
}
}