INT51DB/INT51DB/Controls/MainDisplay/ControlMainDisplayBarGraph.cs

491 lines
22 KiB
C#

using System;
using System.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using SmartX;
using INT51DB.DialogForms;
using INT51DB.Forms;
using INT51DB_ImageDll;
namespace INT51DB.Controls
{
public partial class ControlMainDisplayBarGraph : UserControl
{
#region Field
private FormMainDisplay m_ParentForm;
#endregion
#region Constructor
public ControlMainDisplayBarGraph(FormMainDisplay parent)
{
InitializeComponent();
this.ParentForm = parent;
this.InitializeDesign();
this.DefaultSetting();
}
#endregion
#region Property
public FormMainDisplay ParentForm
{
get { return this.m_ParentForm; }
private set { this.m_ParentForm = value; }
}
#endregion
#region Method
public void InitializeDesign()
{
Class1 images = new Class1();
if (this.ParentForm.ParentForm.SystemConfig.Language == DataStore.LanguageID.English)
{
}
else if (this.ParentForm.ParentForm.SystemConfig.Language == DataStore.LanguageID.Chinese)
{
}
else if (this.ParentForm.ParentForm.SystemConfig.Language == DataStore.LanguageID.Czech)
{
}
else
{
}
}
private void DefaultSetting()
{
}
public void RescaleProgressBar(ProductItem item)
{
int value = 0;
value = item.ProgressBarMaximum;
if (this.progressBar.Maximum != value)
this.progressBar.Maximum = value;
value = item.ProgressBarMinimum;
if (this.progressBar.Minimum != value)
this.progressBar.Minimum = value;
this.progressBar.Value = this.progressBar.Minimum;
}
private void SetProduct(ProductItem item)
{
string underValue = "", passValue = "", overValue = "", tareValue = "";
switch (this.ParentForm.ParentForm.CurrentSystemStatus.CurrentWeightInputMode)
{
case DataStore.WeightInputMode.Weight:
underValue = Helper.StringToDecimalPlaces(item.UnderRange, this.ParentForm.ParentForm.SystemConfig.DecimalPlaces);
passValue = Helper.StringToDecimalPlaces(item.PassRange, this.ParentForm.ParentForm.SystemConfig.DecimalPlaces);
overValue = Helper.StringToDecimalPlaces(item.OverRange, this.ParentForm.ParentForm.SystemConfig.DecimalPlaces);
tareValue = Helper.StringToDecimalPlaces(item.TareRange, this.ParentForm.ParentForm.SystemConfig.DecimalPlaces);
break;
case DataStore.WeightInputMode.Deviation:
if (item.UnderRangeDeviation == 0)
underValue = string.Format("-{0}", Helper.DoubleToString(0, this.ParentForm.ParentForm.SystemConfig.DecimalPlaces));
else
underValue = Helper.StringToDecimalPlaces(item.UnderRangeDeviation.ToString(), this.ParentForm.ParentForm.SystemConfig.DecimalPlaces);
passValue = Helper.StringToDecimalPlaces(item.PassRange, this.ParentForm.ParentForm.SystemConfig.DecimalPlaces);
overValue = Helper.StringToDecimalPlaces(item.OverRangeDeviation.ToString(), this.ParentForm.ParentForm.SystemConfig.DecimalPlaces);
overValue = string.Format("+{0}", overValue);
tareValue = Helper.StringToDecimalPlaces(item.TareRange, this.ParentForm.ParentForm.SystemConfig.DecimalPlaces);
break;
default:
break;
}
if (this.buttonUnderRange.Text != underValue)
this.buttonUnderRange.Text = underValue;
if (this.buttonPassRange.Text != passValue)
this.buttonPassRange.Text = passValue;
if (this.buttonOverRange.Text != overValue)
this.buttonOverRange.Text = overValue;
if (this.buttonTareRange.Text != tareValue)
this.buttonTareRange.Text = tareValue;
}
private void SetCount(WeightData data)
{
string value = "";
value = data.UnderCount.ToString();
if (this.labelUnderCount.Text != value)
this.labelUnderCount.Text = value;
value = data.PassCount.ToString();
if (this.labelPassCount.Text != value)
this.labelPassCount.Text = value;
value = data.OverCount.ToString();
if (this.labelOverCount.Text != value)
this.labelOverCount.Text = value;
value = data.ExNGCount.ToString();
if (this.labelExNGCount.Text != value)
this.labelExNGCount.Text = value;
value = data.TotalCount.ToString();
if (this.labelTotalCount.Text != value)
this.labelTotalCount.Text = value;
}
private void SetProgressBarValue(SmartProgressBar progressBar, double weight, DataStore.JudgmentStatus judStatus, int decimalPlaces)
{
int value = 0;
if (decimalPlaces == 0)
value = int.Parse(string.Format("{0}", weight));
else if (decimalPlaces == 1)
value = int.Parse(string.Format("{0}", weight * 10));
else if (decimalPlaces == 2)
value = int.Parse(string.Format("{0}", weight * 100));
else if (decimalPlaces == 3)
value = int.Parse(string.Format("{0}", weight * 1000));
if (progressBar.Value != value)
progressBar.Value = value;
if (judStatus == DataStore.JudgmentStatus.Over)
{
if (progressBar.BarColor1 != Color.Yellow)
progressBar.BarColor1 = Color.Yellow;
}
else if (judStatus == DataStore.JudgmentStatus.Under || judStatus == DataStore.JudgmentStatus.Double)
{
if (progressBar.BarColor1 != Color.Red)
progressBar.BarColor1 = Color.Red;
}
else
{
if (progressBar.BarColor1 != Color.Lime)
progressBar.BarColor1 = Color.Lime;
}
}
private void UpdateDisplayUser(SystemStatus status)
{
switch (status.CurrentUser.Group)
{
case DataStore.UserGroup.LogOff:
this.buttonUnderRange.Enabled = false;
this.buttonPassRange.Enabled = false;
this.buttonOverRange.Enabled = false;
this.buttonTareRange.Enabled = false;
break;
case DataStore.UserGroup.Level1Operator:
this.buttonUnderRange.Enabled = true;
this.buttonPassRange.Enabled = true;
this.buttonOverRange.Enabled = true;
this.buttonTareRange.Enabled = true;
break;
case DataStore.UserGroup.Level2Engineer:
this.buttonUnderRange.Enabled = true;
this.buttonPassRange.Enabled = true;
this.buttonOverRange.Enabled = true;
this.buttonTareRange.Enabled = true;
break;
case DataStore.UserGroup.Level3Manager:
this.buttonUnderRange.Enabled = true;
this.buttonPassRange.Enabled = true;
this.buttonOverRange.Enabled = true;
this.buttonTareRange.Enabled = true;
break;
case DataStore.UserGroup.Level4Developer:
break;
default:
break;
}
}
public void UpdateEquipmentStatusDisplay(DataStore.EquipmentStatus status)
{
this.labelSpeed.Text = "0";
this.progressBar.Value = this.progressBar.Minimum;
}
public void UpdateCurrentProductDisplay(DataStore.EquipmentStatus status, ProductItem pItem, WeightData wData)
{
this.SetProduct(pItem);
this.SetCount(wData);
this.RescaleProgressBar(pItem);
}
public void UpdateUpdateStartWeightDisplay(DataStore.EquipmentStatus status, WeightData data)
{
string value = "";
value = data.ProductionSpeed.ToString();
if (this.labelSpeed.Text != value)
this.labelSpeed.Text = value;
this.SetProgressBarValue(this.progressBar, data.Weight, data.JudgmentStatus, this.ParentForm.ParentForm.SystemConfig.DecimalPlaces);
this.SetCount(data);
}
public void Clear()
{
this.SetCount(this.ParentForm.ParentForm.CurrentWeightData);
this.progressBar.Value = this.progressBar.Minimum;
this.labelSpeed.Text = "0";
}
public void DisplayRefresh(SystemStatus status)
{
//this.UpdateDisplayUser(status);
this.SetProduct(this.ParentForm.ParentForm.CurrentProductItem);
this.SetCount(this.ParentForm.ParentForm.CurrentWeightData);
}
#endregion
#region Event Handler
private void buttonUnderRange_Click(object sender, EventArgs e)
{
string value = "", sValue = "";
double dValue = 0.0;
DialogFormNumKeyPad myKeyPad = new DialogFormNumKeyPad(this.buttonUnderRange.Text, 5, this.ParentForm.ParentForm.SystemConfig.DecimalPlaces,
false, this.ParentForm.ParentForm.SystemConfig.Language);
if (myKeyPad.ShowDialog() != DialogResult.OK)
return;
switch (this.ParentForm.ParentForm.CurrentSystemStatus.CurrentWeightInputMode)
{
case DataStore.WeightInputMode.Weight:
dValue = myKeyPad.doubleValue;
sValue = myKeyPad.StringValue;
break;
case DataStore.WeightInputMode.Deviation:
dValue = Helper.StringToWeight(this.ParentForm.ParentForm.CurrentProductItem.PassRange, this.ParentForm.ParentForm.SystemConfig.DecimalPlaces)
- Math.Abs(myKeyPad.doubleValue);
sValue = Helper.DoubleToString(dValue, this.ParentForm.ParentForm.SystemConfig.DecimalPlaces);
break;
default:
dValue = myKeyPad.doubleValue;
sValue = myKeyPad.StringValue;
break;
}
if (dValue > Helper.StringToWeight(this.ParentForm.ParentForm.CurrentProductItem.PassRange, this.ParentForm.ParentForm.SystemConfig.DecimalPlaces) || dValue < 0)
{
// 입력범위를 확인하세요
DialogFormMessage myMsg = new DialogFormMessage(1, this.ParentForm.ParentForm.SystemConfig.Language);
myMsg.ShowDialog();
}
else
{
this.ParentForm.ParentForm.CurrentProductItem.UnderRange = sValue.Replace(".", "");
switch (this.ParentForm.ParentForm.CurrentSystemStatus.CurrentWeightInputMode)
{
case DataStore.WeightInputMode.Weight:
value = myKeyPad.StringValue;
break;
case DataStore.WeightInputMode.Deviation:
if (myKeyPad.doubleValue == 0)
value = string.Format("-{0}", Helper.DoubleToString(0, this.ParentForm.ParentForm.SystemConfig.DecimalPlaces));
else
value = myKeyPad.StringValue;
break;
default:
value = myKeyPad.StringValue;
break;
}
this.buttonUnderRange.Text = value;
this.ParentForm.RescaleControl(this.ParentForm.ParentForm.CurrentProductItem);
this.ParentForm.ParentForm.SaveProductFile(this.ParentForm.ParentForm.CurrentProductItem, this.ParentForm.ParentForm.SystemConfig.ProductNumber - 1);
value = Helper.StringZeroFillDigits7(this.ParentForm.ParentForm.CurrentProductItem.UnderRange);
this.ParentForm.ParentForm.TransferDataStream(CommunicationCommand.Write, CommunicationID.MainBoard, CommunicationAddress.UnderRange, value);
}
}
private void buttonPassRange_Click(object sender, EventArgs e)
{
string value = "", underRange = "", overRange = "", viewValue = "";
int digit = 0, temp = 0;
StringBuilder sb = new StringBuilder();
int oldUnderRangeDeviation = this.ParentForm.ParentForm.CurrentProductItem.UnderRangeDeviation;
int oldOverRangeDeviation = this.ParentForm.ParentForm.CurrentProductItem.OverRangeDeviation;
if (this.ParentForm.ParentForm.CurrentWeightData.Weight < 1)
viewValue = this.buttonPassRange.Text;
else
viewValue = Helper.DoubleToString(this.ParentForm.ParentForm.CurrentWeightData.Weight, this.ParentForm.ParentForm.SystemConfig.DecimalPlaces);
DialogFormNumKeyPad myKeyPad = new DialogFormNumKeyPad(viewValue, 5, this.ParentForm.ParentForm.SystemConfig.DecimalPlaces,
false, this.ParentForm.ParentForm.SystemConfig.Language);
if (myKeyPad.ShowDialog() != DialogResult.OK)
return;
this.ParentForm.ParentForm.CurrentProductItem.PassRange = myKeyPad.StringValue.Replace(".", "");
#region UnderRange
temp = this.ParentForm.ParentForm.CurrentProductItem.PassRangeInt + oldUnderRangeDeviation;
if (temp < 0)
value = "0";
else
value = temp.ToString();
this.ParentForm.ParentForm.CurrentProductItem.UnderRange = value;
#endregion
#region OverRange
temp = this.ParentForm.ParentForm.CurrentProductItem.PassRangeInt + oldOverRangeDeviation;
if (temp > 99999)
value = "99999";
else
value = temp.ToString();
this.ParentForm.ParentForm.CurrentProductItem.OverRange = value;
#endregion
this.ParentForm.RescaleControl(this.ParentForm.ParentForm.CurrentProductItem);
this.ParentForm.ParentForm.SaveProductFile(this.ParentForm.ParentForm.CurrentProductItem, this.ParentForm.ParentForm.SystemConfig.ProductNumber - 1);
value = Helper.StringZeroFillDigits7(this.ParentForm.ParentForm.CurrentProductItem.UnderRange);
this.ParentForm.ParentForm.TransferDataStream(CommunicationCommand.Write, CommunicationID.MainBoard, CommunicationAddress.UnderRange, value);
value = Helper.StringZeroFillDigits7(this.ParentForm.ParentForm.CurrentProductItem.PassRange);
this.ParentForm.ParentForm.TransferDataStream(CommunicationCommand.Write, CommunicationID.MainBoard, CommunicationAddress.PassRange, value);
value = Helper.StringZeroFillDigits7(this.ParentForm.ParentForm.CurrentProductItem.OverRange);
this.ParentForm.ParentForm.TransferDataStream(CommunicationCommand.Write, CommunicationID.MainBoard, CommunicationAddress.OverRange, value);
switch (this.ParentForm.ParentForm.CurrentSystemStatus.CurrentWeightInputMode)
{
case DataStore.WeightInputMode.Weight:
#region WeightMode
underRange = Helper.StringToDecimalPlaces(this.ParentForm.ParentForm.CurrentProductItem.UnderRange.ToString(), this.ParentForm.ParentForm.SystemConfig.DecimalPlaces);
overRange = Helper.StringToDecimalPlaces(this.ParentForm.ParentForm.CurrentProductItem.OverRange.ToString(), this.ParentForm.ParentForm.SystemConfig.DecimalPlaces);
#endregion
break;
case DataStore.WeightInputMode.Deviation:
#region DeviationMode
if (this.ParentForm.ParentForm.CurrentProductItem.UnderRangeDeviation == 0)
underRange = string.Format("-{0}", Helper.DoubleToString(0, this.ParentForm.ParentForm.SystemConfig.DecimalPlaces));
else
underRange = Helper.StringToDecimalPlaces(this.ParentForm.ParentForm.CurrentProductItem.UnderRangeDeviation.ToString(), this.ParentForm.ParentForm.SystemConfig.DecimalPlaces);
overRange = Helper.StringToDecimalPlaces(this.ParentForm.ParentForm.CurrentProductItem.OverRangeDeviation.ToString(), this.ParentForm.ParentForm.SystemConfig.DecimalPlaces);
overRange = string.Format("+{0}", overRange);
#endregion
break;
default:
break;
}
this.buttonPassRange.Text = myKeyPad.StringValue;
this.buttonUnderRange.Text = underRange;
this.buttonOverRange.Text = overRange;
}
private void buttonOverRange_Click(object sender, EventArgs e)
{
string value = "", sValue = "";
double dValue = 0.0;
DialogFormNumKeyPad myKeyPad = new DialogFormNumKeyPad(this.buttonOverRange.Text, 5, this.ParentForm.ParentForm.SystemConfig.DecimalPlaces,
false, this.ParentForm.ParentForm.SystemConfig.Language);
if (myKeyPad.ShowDialog() != DialogResult.OK)
return;
switch (this.ParentForm.ParentForm.CurrentSystemStatus.CurrentWeightInputMode)
{
case DataStore.WeightInputMode.Weight:
dValue = myKeyPad.doubleValue;
sValue = myKeyPad.StringValue;
break;
case DataStore.WeightInputMode.Deviation:
dValue = Helper.StringToWeight(this.ParentForm.ParentForm.CurrentProductItem.PassRange, this.ParentForm.ParentForm.SystemConfig.DecimalPlaces)
+ myKeyPad.doubleValue;
sValue = Helper.DoubleToString(dValue, this.ParentForm.ParentForm.SystemConfig.DecimalPlaces);
break;
default:
dValue = myKeyPad.doubleValue;
sValue = myKeyPad.StringValue;
break;
}
if (dValue < Helper.StringToWeight(this.ParentForm.ParentForm.CurrentProductItem.PassRange, this.ParentForm.ParentForm.SystemConfig.DecimalPlaces))
{
// 입력범위를 확인하세요
DialogFormMessage myMsg = new DialogFormMessage(1, this.ParentForm.ParentForm.SystemConfig.Language);
myMsg.ShowDialog();
}
else
{
string temp = "";
this.ParentForm.ParentForm.CurrentProductItem.OverRange = sValue.Replace(".", "");
switch (this.ParentForm.ParentForm.CurrentSystemStatus.CurrentWeightInputMode)
{
case DataStore.WeightInputMode.Weight:
value = myKeyPad.StringValue;
break;
case DataStore.WeightInputMode.Deviation:
if (myKeyPad.StringValue.Contains('+') == true)
temp = myKeyPad.StringValue.Replace("+", "");
else
temp = myKeyPad.StringValue;
value = string.Format("+{0}", temp);
break;
default:
value = myKeyPad.StringValue;
break;
}
this.buttonOverRange.Text = value;
this.ParentForm.RescaleControl(this.ParentForm.ParentForm.CurrentProductItem);
this.ParentForm.ParentForm.SaveProductFile(this.ParentForm.ParentForm.CurrentProductItem, this.ParentForm.ParentForm.SystemConfig.ProductNumber - 1);
value = Helper.StringZeroFillDigits7(this.ParentForm.ParentForm.CurrentProductItem.OverRange);
this.ParentForm.ParentForm.TransferDataStream(CommunicationCommand.Write, CommunicationID.MainBoard, CommunicationAddress.OverRange, value);
}
}
private void buttonTareRange_Click(object sender, EventArgs e)
{
string value = "";
DialogFormNumKeyPad myKeyPad = new DialogFormNumKeyPad(this.buttonTareRange.Text, 5, this.ParentForm.ParentForm.SystemConfig.DecimalPlaces,
false, this.ParentForm.ParentForm.SystemConfig.Language);
if (myKeyPad.ShowDialog() == DialogResult.OK)
{
if (myKeyPad.IntValue < 0 || myKeyPad.IntValue > 99999)
{
// 입력범위를 확인하세요
DialogFormMessage myMsg = new DialogFormMessage(1, this.ParentForm.ParentForm.SystemConfig.Language);
myMsg.ShowDialog();
}
else
{
this.ParentForm.ParentForm.CurrentProductItem.TareRange = myKeyPad.StringValue.Replace(".", "");
this.buttonTareRange.Text = myKeyPad.StringValue;
this.ParentForm.ParentForm.SaveProductFile(this.ParentForm.ParentForm.CurrentProductItem, this.ParentForm.ParentForm.SystemConfig.ProductNumber - 1);
// NET Icon 표시
this.ParentForm.SetIconNET(this.ParentForm.ParentForm.CurrentProductItem);
value = Helper.StringZeroFillDigits7(this.ParentForm.ParentForm.CurrentProductItem.TareRange);
this.ParentForm.ParentForm.TransferDataStream(CommunicationCommand.Write, CommunicationID.MainBoard, CommunicationAddress.TareRange, value);
}
}
}
#endregion
}
}