Files
friction/PanelResult.cs
2017-06-23 03:00:13 +09:00

142 lines
3.8 KiB
C#

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using WeifenLuo.WinFormsUI.Docking;
namespace friction
{
public partial class PanelResult : DockContent
{
MainForm m_Owner = null;
public PanelResult(MainForm owner)
{
InitializeComponent();
m_Owner = owner;
Theme.Apply(this);
Theme.Apply(dgvData);
Theme.Apply(lvColumn);
typeof(DataGridView).InvokeMember("DoubleBuffered",
BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.SetProperty,
null, dgvData, new object[] { true });
dgvData.CellFormatting += DgvData_CellFormatting;
}
private void DgvData_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
{
DataGridViewRow row = dgvData.Rows[e.RowIndex];
if(e.ColumnIndex == row.Cells[Config.COLUMN_NAME.RPN].ColumnIndex)
{
if ((float)e.Value <= 3)
e.CellStyle.BackColor = Theme.Green;
else if ((float)e.Value <= 5)
e.CellStyle.BackColor = Theme.Yellow;
else
e.CellStyle.BackColor = Theme.Red;
}
}
public void UpdateData(DataHandler data)
{
dgvData.DataSource = data.GetData();
dgvData.DefaultCellStyle.Format = "N2";
Dictionary<string, bool> CacheChecked = new Dictionary<string, bool>();
foreach (ListViewItem item in lvColumn.Items)
{
string key = item.SubItems[0].Text;
bool bChecked = item.Checked;
CacheChecked.Add(key, bChecked);
}
lvColumn.Items.Clear();
List<List<string>> Columns = new List<List<string>>() { data.GetActiveColumns(), data.GetNonactiveColumns() };
for(int iGroup=0; iGroup<Columns.Count; iGroup++)
{
foreach(string col in Columns[iGroup])
{
ListViewItem item = new ListViewItem(new string[] { col });
item.Text = col;
if (CacheChecked.ContainsKey(col) == true)
item.Checked = CacheChecked[col];
else if (iGroup == 0)
item.Checked = true;
else
item.Checked = false;
item.ForeColor = (iGroup == 0) ? Theme.Forecolor : Theme.Gray;
lvColumn.Items.Add(item);
}
}
}
private void lvColumn_ItemChecked(object sender, ItemCheckedEventArgs e)
{
string strColName = e.Item.SubItems[0].Text;
bool bShow = e.Item.Checked;
dgvData.Columns[strColName].Visible = bShow;
}
private void lvColumn_SizeChanged(object sender, EventArgs e)
{
Theme.ResizeFullColumn(lvColumn);
}
public void SelectRowByHumidity(string strSpring, string strTable, float fHumidity, float fRPN)
{
dgvData.ClearSelection();
DataGridViewRow row = dgvData.Rows
.Cast<DataGridViewRow>()
.Where(r =>
r.Cells[Config.COLUMN_NAME.SPRING].Value.Equals(strSpring) &&
r.Cells[Config.COLUMN_NAME.TABLE].Value.Equals(strTable) &&
r.Cells[Config.COLUMN_NAME.RPN].Value.Equals(fRPN) &&
r.Cells[Config.COLUMN_NAME.HUMIDITY].Value.Equals(fHumidity)
)
.First();
if (row != null)
{
row.Selected = true;
dgvData.FirstDisplayedScrollingRowIndex = row.Index;
}
}
public void SelectRowByTemperature(string strSpring, string strTable, float fTemperature, float fRPN)
{
dgvData.ClearSelection();
DataGridViewRow row = dgvData.Rows
.Cast<DataGridViewRow>()
.Where(r =>
r.Cells[Config.COLUMN_NAME.SPRING].Value.Equals(strSpring) &&
r.Cells[Config.COLUMN_NAME.TABLE].Value.Equals(strTable) &&
r.Cells[Config.COLUMN_NAME.RPN].Value.Equals(fRPN) &&
r.Cells[Config.COLUMN_NAME.TEMP].Value.Equals(fTemperature)
)
.First();
if (row != null)
{
row.Selected = true;
dgvData.FirstDisplayedScrollingRowIndex = row.Index;
}
}
}
}