天津投入产出系统后端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

247 lines
8.7 KiB

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Windows.Forms.DataVisualization.Charting;
using QMAPP.WinForm.Common.SPCMonitor;
using QMAPP.ServicesAgent;
using QMAPP.FJC.Entity.Basic;
using QMAPP.FJC.Entity;
using QMAPP.Entity;
namespace QMAPP.WinForm.Forms.Operation
{
/// <summary>
/// 描述:SPC监控
/// 作者:单雨春
/// 时间:2015年6月3日08:36:01
/// </summary>
public partial class SPCControlForm : Form
{
private ServiceAgent wcfAgent = null;
public SPCControlForm()
{
InitializeComponent();
ClientContext.MachineInfo = new MachineInfo();
ClientContext.MachineInfo.PROCESSTYPE = "11";
ClientContext.MachineInfo.PRODUCELINE = "B9";
ClientContext.MachineInfo.MACHINECODDE = "PUNCH01";
Init();
}
/// <summary>
/// 页面初始化
/// </summary>
private void Init()
{
wcfAgent = ClientContext.GetServiceAgent();
DataResult<List<ProcessParameter>> result = new DataResult<List<ProcessParameter>>();
InitSetChart();
#region 绑定监控值
result = wcfAgent.InvokeServiceFunction<DataResult<List<ProcessParameter>>>(QMAPP.ServicesAgent.B9BasicService.ProcessParameterBLL_GetAllList.ToString(),
new ProcessParameter {
PROCESSTYPE = ClientContext.MachineInfo.PROCESSTYPE,
MACHINECODDE = ClientContext.MachineInfo.MACHINECODDE,
PRODUCELINE = ClientContext.MachineInfo.PRODUCELINE
});
result.Result.Insert(0, new ProcessParameter { PARANAME = string.Empty });
cbxProcessParameter.DataSource = result.Result;
cbxProcessParameter.DisplayMember = "PARANAME";
cbxProcessParameter.ValueMember = "PARANAME";
#endregion
}
/// <summary>
/// 查询验证
/// </summary>
private bool Check()
{
string strMVStart = txtMVStart.Text;
string strMVEnd = txtMVEnd.Text;
if(string.IsNullOrEmpty(txtCount.Text.Trim()))
{
MessageBox.Show(Resource1.PleaseMotorCount);
return false;
}
if (cbxProcessParameter.SelectedIndex == 0)
{
MessageBox.Show(Resource1.PleaseSelectMotorValue);
return false;
}
if (!string.IsNullOrEmpty(strMVStart) && !string.IsNullOrEmpty(strMVEnd) && Convert.ToDouble(strMVEnd) < Convert.ToDouble(strMVStart))
{
MessageBox.Show(Resource1.MotorScope);
return false;
}
return true;
}
/// <summary>
/// 获得到图表数据
/// </summary>
/// <returns></returns>
private DataTable GetChartData()
{
string strParameterName = cbxProcessParameter.SelectedValue.ToString();
DataResult<DataTable> dataResult = wcfAgent.InvokeServiceFunction<DataResult<DataTable>>(QMAPP.ServicesAgent.B9IPCService.SPCControlBLL_GetData.ToString(),
new ProcessParameter
{
PROCESSTYPE = ClientContext.MachineInfo.PROCESSTYPE,
PRODUCELINE = ClientContext.MachineInfo.PRODUCELINE,
MACHINECODDE = ClientContext.MachineInfo.MACHINECODDE,
SelectColumn = strParameterName,
MonitorCount = Convert.ToInt32(txtCount.Text),
MVStart = string.IsNullOrEmpty(txtMVStart.Text) ? 0 : Convert.ToInt32(txtMVStart.Text),
MVEnd = string.IsNullOrEmpty(txtMVEnd.Text) ? 0 : Convert.ToInt32(txtMVEnd.Text)
});
if (!dataResult.IsSuccess)
{
MessageBox.Show(dataResult.Msg);
}
return dataResult.Result;
}
/// <summary>
/// 初始化图形
/// </summary>
private void InitSetChart()
{
#region 通用图形显示
//清除画板
this.chartData.ChartAreas.Clear();
this.chartData.ChartAreas.Add(new ChartArea("ChartA"));
//清除数据
this.chartData.Series.Clear();
//清除标题
this.chartData.Titles.Clear();
//清除图例
this.chartData.Legends.Clear();
//仅不显示x轴方向的网格线
chartData.ChartAreas["ChartA"].AxisX.MajorGrid.Enabled = false;
//仅不显示y轴方向的网格线
chartData.ChartAreas["ChartA"].AxisY.MajorGrid.Enabled = false;
//图表背景颜色是渐进
chartData.ChartAreas["ChartA"].BackColor = System.Drawing.Color.FromArgb(250, 235, 206);//图表区背景第1种颜色
chartData.ChartAreas["ChartA"].BackSecondaryColor = System.Drawing.Color.White; //图表区背景第2种颜色
chartData.ChartAreas["ChartA"].BackGradientStyle = GradientStyle.TopBottom;
#endregion
}
/// <summary>
/// 趋势图
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void tbtnTendency_Click(object sender, EventArgs e)
{
#region 准备数据
if (!Check())
{
return;
}
InitSetChart();
DataTable dt = GetChartData();
string strParameterName = cbxProcessParameter.SelectedValue.ToString();
#endregion
#region 趋势图
if (dt != null && dt.Rows.Count > 0)
{
chartData = ChartHelper.DrawTendencyChart(chartData, dt, strParameterName);
Series series = new Series();
series.ChartType = SeriesChartType.Line;
series.MarkerStyle = MarkerStyle.Circle;
for (int i = 0; i < dt.Rows.Count; i++)
{
series.Points.AddXY(i, Convert.ToDouble(dt.Rows[i][strParameterName]));
}
chartData.Series.Add(series);
}
else
{
MessageBox.Show(Resource1.NothingData);
}
#endregion
}
/// <summary>
/// 分布图
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void tbtnDistribution_Click(object sender, EventArgs e)
{
#region 准备数据
if (!Check())
{
return;
}
InitSetChart();
DataTable dt = GetChartData();
string strParameterName = cbxProcessParameter.SelectedValue.ToString();
#endregion
#region 分布图
if (dt != null && dt.Rows.Count > 0)
{
Dictionary<double, int> dict = ChartHelper.GetBarValue(dt, strParameterName);
chartData = ChartHelper.DrawDistributionChart(chartData, dt, dict, strParameterName);
//显示图形的类型
Series series = new Series();
series.ChartType = SeriesChartType.Column;//设置图表类型-分布图
series.IsValueShownAsLabel = true;
foreach (double key in dict.Keys)
{
series.Points.AddXY(key, dict[key]);
}
chartData.Series.Add(series);
}
else
{
MessageBox.Show(Resource1.NothingData);
}
#endregion
}
/// <summary>
/// 只能输入浮点型
/// 46-小数点
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void txtDouble_KeyPress(object sender, KeyPressEventArgs e)
{
//只能输入浮点型
if ((e.KeyChar < 48 || e.KeyChar > 57) && (e.KeyChar != 8) && (e.KeyChar != 46))
e.Handled = true;
}
/// <summary>
/// 只能输入数值
/// 48-0;57-9;
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void txtNumber_KeyPress(object sender, KeyPressEventArgs e)
{
//只能输入数值
if ((e.KeyChar < 48 || e.KeyChar > 57) && (e.KeyChar != 8))
e.Handled = true;
}
}
}