You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1297 lines
40 KiB
C#

using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using Mesnac.Controls.Base;
using System;
using Mesnac.Controls.Default;
using System.Drawing.Design;
using System.Collections;
using System.Windows.Forms;
using System.ComponentModel.Design;
using System.Globalization;
using Mesnac.Basic;
using Mesnac.Codd.Session;
using System.Data;
using System.Text;
using Mesnac.Compressor.Entity;
using System.Threading;
using System.Reflection;
using Mesnac.Compressor.Station;
using PLCManager;
using System.IO;
using Mesnac.Controls.Feeding;
using System.Windows.Forms.Design;
using Mesnac.Gui.Edit.Dialog;
using System.Runtime.Serialization.Formatters.Binary;
namespace Mesnac.Controls.Compressor
{
[ToolboxBitmap(typeof(Mixer2), "ICONS.mixer.bmp")]//新添加的代码
public partial class StationButton : FeedingControl
{
private List<DesignAction> _clickActionList = new List<DesignAction>();
private List<DesignAction> _keyDownActionList = new List<DesignAction>();
private List<DesignAction> _keyUpActionList = new List<DesignAction>();
private bool _mcVisible = true; //保存可见性
private bool _mcEnabled = true; //保存可用性
private bool _isValid = true; //保存有效性
private object _mcvalue;
DbHelper dbHelper = DataSourceFactory.Instance.GetDbHelper("DataSource1");
private const int dataStateIndex = 1;
private const int MaxData = 6000;
private const int dataLength = 90;//读取数据长度,字
public event EventHandler ReshreshStationData;
private int dataIndex = -1;
private bool FirstRead = true;
public StationButton()
{
InitializeComponent();
this.textBox1.ReadOnly = true;
this.textBox1.Multiline = true;
//this.textBox1.Size = new Size(150,150);
this.textBox1.BackColor = Color.LightCyan;
this.textBox2.BackColor = Color.LightCyan;
this.textBox3.BackColor = Color.LightCyan;
this.pressureSwitch1.Status = Mesnac.Controls.Feeding.PressureSwitch.Statuses.ylNormal;
panel5.Parent = this.pictureBox1;
this.panel5.BackColor = Color.Transparent;
SetDefautText();
}
public StationButton(IContainer container)
{
//container.Add(this);
InitializeComponent();
}
public List<DesignAction> ClickActionList
{
get
{
return this._clickActionList;
}
set
{
this._clickActionList = value;
}
}
public List<DesignAction> KeyDownActionList
{
get { return _keyDownActionList; }
set { _keyDownActionList = value; }
}
public List<DesignAction> KeyUpActionList
{
get { return _keyUpActionList; }
set { _keyUpActionList = value; }
}
[Description("工位"), Category("工位信息")]
public Image picture
{
get
{
return this.pictureBox1.Image;
}
set
{
this.pictureBox1.Image = value;
}
}
private Station _station
{
get
{
Station st = new Station();
if (!string.IsNullOrEmpty(MCStationName))
{
string name = MCStationName;
string[] arry = name.Split(':');
if (arry.Length > 1)
{
st.StationID = arry[0];
st.StationName = arry[1];
}
}
else
{
st.StationID = "";
st.StationName = "";
}
return st;
}
}
[Editor(typeof(PropertyGridFileItem), typeof(System.Drawing.Design.UITypeEditor))]
[Description("工位"), Category("工位信息")]
/// <summary>
/// 工位名称
/// </summary>
public string MCStationName
{
get;
set;
}
private StationInfo _stationInfo;
public StationInfo StationInfo
{
get
{
if (_stationInfo == null)
{
InitStationInfo();
}
return _stationInfo;
}
}
private void InitStationInfo()
{
if (string.IsNullOrEmpty(_station.StationID))
{
return;
}
try
{
if (dbHelper == null)
{
return ;
}
dbHelper.ClearParameter();
dbHelper.CommandType = CommandType.Text;
dbHelper.CommandText = "";
string sql = "Exec SP_Pro_getStationInfo @StationID";
dbHelper.AddParameter("@StationID", _station.StationID);
dbHelper.CommandText = sql;
DataTable ds = (DataTable)dbHelper.ToDataTable();
GetInfoName(ds);
}
catch (Exception e)
{
ICSharpCode.Core.LoggingService.Error("网络服务器请求失败"+e.ToString());
return ;
}
}
private void GetInfoName(DataTable dt)
{
//工位表
DataTable dt2 = dt;
try
{
_stationInfo = new StationInfo();
if (dt2 != null && dt2.Rows.Count > 0)
{
///工位一参数
_stationInfo.stationID = dt2.Rows[0]["StationID"].ToString();
_stationInfo.StationCode = dt2.Rows[0]["StationCode"].ToString();
_stationInfo.StationName = dt2.Rows[0]["StationName"].ToString();
_stationInfo.TableName = dt2.Rows[0]["TableName"].ToString();
_stationInfo.PreTableName = dt2.Rows[0]["PreTableName"].ToString();
_stationInfo.ParaCount = Convert.ToInt32(dt2.Rows[0]["paraCount"]);
_stationInfo.StationType = dt2.Rows[0]["Type_Class"].ToString();
_stationInfo.lineID= dt2.Rows[0]["LineID"].ToString();
_stationInfo.barcodeHead = dt2.Rows[0]["barcodeHead"].ToString();
_stationInfo.IfMainline = Convert.ToInt32(dt2.Rows[0]["LineTypeFlag"]) == 1;
_stationInfo.PLCName = dt2.Rows[0]["PLCName"].ToString().Trim();
if (dt2.Rows[0]["PLCBlock"].ToString() != "")
{
_stationInfo.PLCBlock = Convert.ToInt32(dt2.Rows[0]["PLCBlock"]);
}
_stationInfo.NGTakeStation = Convert.ToInt32(dt2.Rows[0]["IsNGStation"]) > 0;
ICSharpCode.Core.LoggingService.Debug("---------------------加载工位信息--------------------" + "\r\n");
ICSharpCode.Core.LoggingService.Debug("|工位序号:" + _stationInfo.stationID + ",工位编号:"+ _stationInfo.StationCode +",工位名称:"+ _stationInfo.StationName+",产线编号"+ _stationInfo.lineID + "|\r\n");
ICSharpCode.Core.LoggingService.Debug("---------------------工位信息完成--------------------" + "\r\n");
}
}
catch(Exception e)
{
ICSharpCode.Core.LoggingService.Error("参数获取错误:"+ e.ToString());
}
}
public object read = new object();
public void OnRerefreshData()
{
lock (read)
{
//if ()
//{
StationInfo.Data.NewFlag = false;
//plc复位
//ResetPLCState(TextName);
ThreadPool.QueueUserWorkItem(new WaitCallback(SaveStationdata), StationInfo);
}
}
public void PreWorkThread()
{
lock (read)
{
ThreadPool.QueueUserWorkItem(new WaitCallback(PreStationWork), StationInfo);
}
//ICSharpCode.Core.LoggingService.Debug("》》》》》》动态生成程序集!");
}
private void ResetPLCState(string EquipKey)
{
object[] data=new object[1];
data[0] = 0;
PlcData.Instance.PlcWriteByEquipKey(EquipKey, dataStateIndex, data);
}
public void PreStationWork(object o)
{
//ICSharpCode.Core.LoggingService.Debug("》》》》》》动态生成程序集!");
var station = o as StationInfo;
if (station == null)
{
return;
}
#region 生成动态处理类
string stationType = station.StationType;
//根据类型,动态生成业务类
Assembly assembly = Assembly.GetExecutingAssembly(); // 获取当前程序集
string AssemName = "Mesnac.Compressor.Station." + stationType;
var obj = assembly.CreateInstance(AssemName, true);
var stationManager = obj as IStation;
#endregion
stationManager = ReflectClass(stationType);
if (stationManager == null)
{
ICSharpCode.Core.LoggingService.Debug("工位类型不存在" + stationType + " 工位:" + station.StationCode);
return;
}
//ICSharpCode.Core.LoggingService.Debug("工位:" + station.StationCode + " 开始上传数据。托盘号:" + station.Data.RFIDNo);
//ICSharpCode.Core.LoggingService.Debug("》》》》》》动态生成程序集完成!");
stationManager.PrepareWork(station);
}
public void SaveStationdata(object o)
{
var station = o as StationInfo;
if (station == null)
{
return;
}
#region 生成动态处理类
string stationType = station.StationType;
//根据类型,动态生成业务类
Assembly assembly = Assembly.GetExecutingAssembly(); // 获取当前程序集
string AssemName = "Mesnac.Compressor.Station." + stationType;
var obj = assembly.CreateInstance(AssemName, true);
var stationManager = obj as IStation;
#endregion
stationManager = ReflectClass(stationType);
if (stationManager == null)
{
ICSharpCode.Core.LoggingService.Debug("工位类型不存在" + stationType + " 工位:" + station.StationCode);
return;
}
//ICSharpCode.Core.LoggingService.Debug("工位:" + station.StationCode + " 开始上传数据。托盘号:" + station.Data.RFIDNo);
stationManager.HandleData(station);
}
private object _stationone;
private int time = 0;
public static byte[] Serialize(object obj)
{
BinaryFormatter bf = new BinaryFormatter();
MemoryStream stream = new MemoryStream();
bf.Serialize(stream, obj);
byte[] datas = stream.ToArray();
stream.Dispose();
return datas;
}
public void ReceiveData(object bytes,string stationcode)
{
try
{
byte[] buff = Serialize(bytes);
if (buff != null)
{
Console.WriteLine(DateTime.Now +"》》》工位:" + stationcode + ",循环扫描数据:" + bytesToHexStr(buff, buff.Length));
}
return;
}
catch (Exception ex)
{
return;
}
}
public static string bytesToHexStr(byte[] bytes, int iLen)
{
StringBuilder sb = new StringBuilder();
if (bytes != null)
{
for (int i = 0; i < iLen; i++)
{
sb.Append(bytes[i].ToString("X2"));
}
}
return sb.ToString();
}
private object _mcValue;
public object MCValue
{
get
{
return _mcValue;
}
set
{
try
{
//Console.WriteLine(DateTime.Now + "》》》工位:" + StationInfo.StationCode + ",循环扫描数据");
if (value == null)
{
ClearText();
return;
}
//ReceiveData(value, StationInfo.StationCode);
//数据没有变化,直接返回
object[] objectarray1;
if (!TryObject(value, out objectarray1))
{
return;
}
//if (StationInfo.StationCode == "140")
//{
// int test1 = SingleConvertToInt(objectarray1, 1);
// int test2 = SingleConvertToInt(objectarray1, 2);
// if (test1 == 1 || test2 == 1)
// {
// ICSharpCode.Core.LoggingService.Error("》》》工位:" + StationInfo.StationCode + ",检测点位D12501,值:" + test1 + ",D12502值:" + test2);
// }
// ICSharpCode.Core.LoggingService.Debug("》》》工位:" + StationInfo.StationCode + ",检测点位D12501,值:" + test1 + ",D12502值:" + test2);
//}
//if (StationInfo.StationCode == "150")
//{
// int test1 = SingleConvertToInt(objectarray1, 1);
// int test2 = SingleConvertToInt(objectarray1, 2);
// if (test1 == 1 || test2 == 1)
// {
// ICSharpCode.Core.LoggingService.Error("》》》工位:" + StationInfo.StationCode + ",检测点位D12801,值:" + test1 + ",D12802值:" + test2);
// }
// ICSharpCode.Core.LoggingService.Debug("》》》工位:" + StationInfo.StationCode + ",检测点位D12801,值:" + test1 + ",D12802值:" + test2);
//}
if (value==_mcValue)
{
return;
}
time++;
object[] objectarray;
if (!TryObject(value, out objectarray))
{
return;
}
_mcValue = value;
StationInfo.Data = ParaFormart(objectarray, StationInfo.ParaCount);
SetText();
if (StationInfo.Data.AskWork)
{
//这里需要判断上工位结果是否OK
ICSharpCode.Core.LoggingService.Debug("工位:" + StationInfo.StationCode + " 收到作业请求信号");
PreWorkThread();
}
////有新数据
if (isConnect && StationInfo.Data.NewFlag)
{
ICSharpCode.Core.LoggingService.Debug("工位:" + StationInfo.StationCode + " 收到作业完成信号,开始上传数据。托盘号:" + StationInfo.Data.RFIDNo);
OnRerefreshData();
}
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
}
}
}
private string _textName = null;
public string TextName
{
get
{
return _textName;
}
set
{
_textName = value;
}
}
public bool isConnect { get; set; }
private string _state = "";
public string State
{
get
{
return _state;
}
set
{
_state = value;
}
}
public string NewMachineID = "";
public string OldMachineID
{
get;
set;
}
public string MachineName = "";
private string _productCount = "";
public string productCount
{
get
{
return _productCount;
}
set
{
_productCount = value;
}
}
#region 数据解析
/// <summary>
/// 单工位数据解析
/// </summary>
/// <param name="obj"></param>
/// <returns></returns>
public stationPara ParaFormart(object [] obj,int paraCount)
{
stationPara sinfo = new stationPara();
int index = 0;
ArrayList array = ConvertToBit(obj, index);
Array(array);
sinfo.Restart = Convert.ToInt32(array[2]) == 1;
sinfo.ReWork = Convert.ToInt32(array[6]) == 1;
sinfo.DP_OpenFlag = Convert.ToInt32(array[7]) == 1;
//是否重投
if (sinfo.Restart)
{
ICSharpCode.Core.LoggingService.Info(StationInfo.StationCode + ",开始重投");
}
//是否有主线二维码
sinfo.BarcodeUpdate = Convert.ToInt32(array[3]) == 1;
//是否有支线二维码
sinfo.MaterialBarcodeUpdate = Convert.ToInt32(array[4]) == 1;
index++;
//自动模式
if ((int)obj[1] == 1)
{
}
//重构,收到作业或放行请求才进行解析
//PLC工作请求信号
sinfo.AskWork = SingleConvertToInt(obj, index)>0;//
index++;
//放行请求
sinfo.MaskID = SingleConvertToInt(obj, index);
sinfo.NewFlag = newData(sinfo.MaskID);
index += 3;
//当前机种号
sinfo.machineID = SingleConvertToInt(obj, index);
NewMachineID = sinfo.machineID.ToString();
index++;
//托盘号
int intNum = SingleConvertToInt(obj, index);
//支线条码状态
index++;
ArrayList array2 = ConvertToBit(obj, index);
//数据保存区
index++;
sinfo.ProductOkNg = SingleConvertToInt(obj, index);
index++;
//线体代号ABC
int gongxu = SingleConvertToInt(obj, index);
sinfo.RFIDNo = string.Format("{0:X}", gongxu) + intNum.ToString().PadLeft(2, '0');
index += 1;
//sinfo.productDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");//这里不用日期了
if (sinfo.BarcodeUpdate || sinfo.MaterialBarcodeUpdate)
{
GetBarcodeList(obj, array2, index, ref sinfo);
}
index += 90;
for (int i = 0; i < paraCount; i++)
{
dataUnite du = new dataUnite();
du.actValue = ConvertToString(obj, index);
du.MaxValue = ConvertToString(obj, index + 2);
du.MinValue = ConvertToString(obj, index + 4);
du.result = ConvertToInt(obj, index + 6);
du.Remark = ConvertToString(obj, index + 8);
index += 10;
sinfo.SavedataList.Add(du);
}
return sinfo;
}
/// <summary>
/// 卓樱方法 yinzf,如果要换其他产线,这个地方肯定要重新
/// </summary>
/// <param name="buffer"></param>
/// <param name="index"></param>
/// <param name="sinfo"></param>
private void GetBarcodeList(object[] buffer, ArrayList list, int index, ref stationPara sinfo)
{
try
{
//目前只有4个支线
for (int i = 0; i <= 5; i++)
{
subLine sl = new subLine();
sl.lineID = i.ToString();
sl.barcode = "";
sinfo.subLineList.Add(sl);
}
int barcodeLegth = 10;//设置单个条码长度
if (sinfo.BarcodeUpdate)
{
sinfo.ProductBarcode = Getbarcode(buffer, index, barcodeLegth);
}
index = index + 10;
if (sinfo.MaterialBarcodeUpdate)
{
for (int i = 0; i <= 5; i++)
{
bool HaveBarcord = Convert.ToInt32(list[i]) == 1;//判断第1位是否为1,此为支线1条码
if (HaveBarcord)
{
if (i == 0)//控制器
{
sinfo.subLineList[i].barcode = Getbarcode(buffer, index, barcodeLegth);
sinfo.MaterialBarcode = sinfo.subLineList[i].barcode;
}
if (i == 1)//壳体
{
sinfo.subLineList[i].barcode = Getbarcode(buffer, 30, barcodeLegth);
sinfo.MaterialBarcode = sinfo.subLineList[i].barcode;
}
if (i == 2)//前盖
{
sinfo.subLineList[i].barcode = Getbarcode(buffer, 40, barcodeLegth);
sinfo.MaterialBarcode = sinfo.subLineList[i].barcode;
}
if (i == 3)//动盘
{
sinfo.subLineList[i].barcode = Getbarcode(buffer, 50, barcodeLegth);
sinfo.MaterialBarcode = sinfo.subLineList[i].barcode;
}
if (i == 4)//静盘
{
sinfo.subLineList[i].barcode = Getbarcode(buffer, 60, barcodeLegth);
sinfo.MaterialBarcode = sinfo.subLineList[i].barcode;
}
if (i == 5)//后盖
{
sinfo.subLineList[i].barcode = Getbarcode(buffer, 70, barcodeLegth);
sinfo.MaterialBarcode = sinfo.subLineList[i].barcode;
}
}
}
}
}
catch (Exception ex)
{
}
}
private void GetBarcodeList(object[] buffer, int index, ref stationPara sinfo)
{
try
{
//条码个数
int count = Convert.ToInt32(buffer[index]);
if (count <= 0)
{
return;
}
//支线条码个数
int subcount = count - 1;
//获取条码支线信息
for (int i = 1; i <= subcount; i++)
{
subLine sl = new subLine();
sl.lineID = buffer[index + i].ToString();
sl.barcode = "";
sinfo.subLineList.Add(sl);
}
int barcodeLegth = 10;//设置单个条码长度
//获取主条码
sinfo.ProductBarcode = Getbarcode(buffer, index + 4, barcodeLegth);
for (int i = 1; i <= subcount; i++)
{
sinfo.subLineList[i - 1].barcode = Getbarcode(buffer, index + 4 + i * barcodeLegth, barcodeLegth);
}
}
catch (Exception ex)
{
ICSharpCode.Core.LoggingService.Debug("条码信息获取失败:" + ex.ToString());
}
}
/// <summary>
/// 判断是否是新数据
/// </summary>
/// <param name="num"></param>
/// <returns></returns>
private bool newData2(int num)
{
if (num > dataIndex)
{
//if (dataIndex == -1 && num == MaxData)//第一次也上传
if (dataIndex == -1 && num!=1)//开机第一次不上传
{
return false;
}
dataIndex = num;
if (dataIndex == MaxData)
{
dataIndex = 0;
}
return true;
}
else
{
return false;
}
}
private bool newData(int num)
{
if (num>0)
{
return true;
}
return false;
}
/// <summary>
/// 获取条码号
/// </summary>
/// <param name="obj">数组</param>
/// <param name="index">起始</param>
/// <param name="length">长度</param>
/// <returns></returns>
//private string Getbarcode(object[] obj, int index, int length)
//{
// StringBuilder sb=new StringBuilder();
// for (int i = 0; i < length; i++)
// {
// string code = SingleConvertToInt(obj , index+i).ToString();
// code = "0000"+code;
// code = code.Substring(code.Length-4, 4);
// sb.Append(code);
// }
// return sb.ToString();
//}
//南京方法
private string Getbarcode(object[] buffer, int index, int len)
{
string messge = "";
try
{
//int len = Convert.ToInt32(buffer[index]) / 2 - 1;
int[] orgdata = new int[len];
for (int i = 0; i < len; i++)
{
orgdata[i] = Convert.ToInt32(buffer[index + i]);
}
byte[] newdata = new byte[len * 2];
for (int i = 0; i < len; i++)
{
newdata[i * 2] = (byte)(orgdata[i] % 256);
newdata[i * 2 + 1] = (byte)(orgdata[i] / 256);
}
messge = ASCIIEncoding.ASCII.GetString(newdata).Replace("\0", "").Replace("\n", "").Replace("\r", "").Replace("\t", "");
}
catch (Exception ex)
{
ICSharpCode.Core.LoggingService.Debug("条码信息获取失败:" + ex.ToString());
}
return messge;
}
/// <summary>
/// 杭州方法
/// </summary>
/// <param name="obj"></param>
/// <param name="index"></param>
/// <param name="length"></param>
/// <returns></returns>
//private string Getbarcode(object[] obj, int index, int length)
//{
// StringBuilder builder = new StringBuilder();
// for (int i = 0; i < length; i++)
// {
// string str = this.SingleConvertToInt(obj, index + i).ToString();
// str = "0000" + str;
// str = str.Substring(str.Length - 4, 4);
// builder.Append(str);
// }
// return builder.ToString();
//}
/// <summary>
/// 将数据里的数据解析出来
/// </summary>
/// <param name="array"></param>
private void Array(ArrayList array)
{
try
{
isConnect = Convert.ToInt32(array[0]) == 1;
State = stateString(Convert.ToInt32(array[1]));
}
catch
{
}
}
private string ConvertToString(object[] obj, int index)
{
float data = convertTofloat(obj, index);
return data.ToString("F4");
}
private int ConvertToInt(object[] obj, int index)
{
float fstate = convertTofloat(obj, index);
return Convert.ToInt32(fstate);
}
/// <summary>
/// 单字转Int
/// </summary>
/// <param name="obj"></param>
/// <returns></returns>
private int SingleConvertToInt(object[] obj, int index)
{
try
{
return Convert.ToInt16(obj[index]);
}
catch
{
return 0;
}
}
public ArrayList ConvertToBit(object[] obj, int index)
{
ArrayList al = new ArrayList();
int IntValue = SingleConvertToInt(obj,index);
for (int i = 0; i < 16; i++)
{
int value = IntValue & 1;
al.Add(value);
IntValue=IntValue >> 1;
}
return al;
}
private string stateString(int state)
{
switch (state)
{
case 0:
return "非自动";
case 1:
return "自动";
case 2:
return "未知";
default:
return "未知";
}
}
/// <summary>
/// 如果是数组获取第一个字的值如果是object获取Int值
/// </summary>
/// <param name="ob"></param>
/// <returns></returns>
private int GetValue(object ob)
{
//bool isArry = false;
int IntValue = 0;
try
{
var value = ob as object[];
object convertValue;
if (value == null)
{
convertValue = ob;
}
else
{
convertValue = value[0];
}
IntValue = Convert.ToInt32(convertValue);
}
catch
{
IntValue = Convert.ToInt32(ob);
}
return IntValue;
}
private float convertTofloat(object[] buff, int startIndex)
{
try
{
int b = Convert.ToInt32(buff[startIndex]);
int a = Convert.ToInt32(buff[startIndex + 1]);
byte[] low = System.BitConverter.GetBytes(b);
byte[] high = System.BitConverter.GetBytes(a);
byte[] abc = new byte[4];
for (int i = 0; i < 2; i++)
{
abc[i] = low[i];
}
for (int i = 0; i < 2; i++)
{
abc[i + 2] = high[i];
}
return BitConverter.ToSingle(abc, 0);
}
catch
{
return -1;
}
}
public Object[] floatToObject(float ff)
{
//正负符号默认为0
byte flag = 0;
if (ff < 0)
{
flag = 128;
ff = ff * -1;
}
byte[] floatByte = BitConverter.GetBytes(ff);
byte[] lowhByte = new byte[4];
lowhByte[0] = floatByte[0];
lowhByte[1] = floatByte[1];
lowhByte[2] = 0;
lowhByte[3] = 0;
byte[] highByte = new byte[4];
highByte[0] = floatByte[2];
highByte[1] = floatByte[3];
highByte[2] = 0;
highByte[3] = 0;
highByte[1] = (byte)(highByte[1] + flag);
UInt32 low = BitConverter.ToUInt32(lowhByte, 0);
int high = BitConverter.ToInt16(highByte, 0);
object[] buff = new object[2];
buff[0] = low;
buff[1] = high;
return buff;
}
private bool TryObject(object value, out object[] arry)
{
arry = null;
try
{
arry = (object[])value;
return true;
}
catch
{
return false;
}
}
#endregion
public void SetText()
{
try
{
if (isConnect)
{
this.pressureSwitch1.Status = Mesnac.Controls.Feeding.PressureSwitch.Statuses.ylMove;
}
else
{
this.pressureSwitch1.Status = Mesnac.Controls.Feeding.PressureSwitch.Statuses.ylNormal;
}
this.textBox1.Text = "名称:" + StationInfo.StationCode+StationInfo.StationName;
this.textBox2.Text = "机种:"+ getMachineName();
this.textBox3.Text = "状态:" + State;
}
catch(Exception ex)
{
ICSharpCode.Core.LoggingService.Debug("信息设置失败" + ex.ToString());
}
}
public void ClearText()
{
try
{
this.pressureSwitch1.Status = Mesnac.Controls.Feeding.PressureSwitch.Statuses.ylNormal;
this.textBox1.Text = "名称:" + StationInfo.StationCode + StationInfo.StationName;
this.textBox2.Text = "机种:";
this.textBox3.Text = "状态:";
}
catch (Exception ex)
{
ICSharpCode.Core.LoggingService.Debug("信息清空失败" + ex.ToString());
}
}
private string getMachineName()
{
if (!string.IsNullOrEmpty(OldMachineID) || OldMachineID != NewMachineID)
{
try
{
if (dbHelper == null)
{
return MachineName;
}
dbHelper.ClearParameter();
dbHelper.CommandType = CommandType.Text;
dbHelper.CommandText = "";
string sql = " SELECT TOP 1 T2.dict_label FROM T_BD_ProductInfo T1 LEFT JOIN dbo.sys_dict_data T2 ON T1.ProductType = T2.dict_value WHERE T2.dict_type = 'productType' AND T1.ProductType = '" + NewMachineID + "'";
dbHelper.CommandText = sql;
object ob = dbHelper.ToScalar();
if (ob != null)
{
MachineName=ob.ToString();
}
}
catch (Exception e)
{
ICSharpCode.Core.LoggingService.Error("机种获取失败"+e.ToString());
return MachineName;
}
OldMachineID = NewMachineID;
}
return MachineName;
}
private void SetDefautText()
{
this.pressureSwitch1.Status = Mesnac.Controls.Feeding.PressureSwitch.Statuses.ylNormal;
this.textBox1.Text = "名称:\r\n";
this.textBox2.Text = "机种:";
this.textBox3.Text = "状态:";
}
#region 属性
public IBaseControl MCRoot
{
get
{
return null;
}
set
{
;
}
}
#region 数据库的屏蔽,现在用不着
[TypeConverter(typeof(DataSourceConverter))]
[Description("数据连接"), Category("Data")]
public string MCDataSourceID
{
get;
set;
}
public MCDataSource MCDataSource
{
get;
set;
}
[Description("是否为数据库控件"), Category("Data")]
public bool IsDbControl
{
get;
set;
}
[Description("初始化SQL"), Category("Data")]
public string InitDataSource
{
get;
set;
}
[Description("执行SQL"), Category("Data")]
public string ActionDataSource
{
get;
set;
}
[Description("绑定数据源"), Category("Data")]
public object BindDataSource
{
get;
set;
}
[Description("操作类型"), Category("Data")]
public DbOptionTypes DbOptionType
{
get;
set;
}
#endregion
[Description("是否可见"), Category("Behavior")]
public bool MCVisible
{
get
{
return this._mcVisible;
}
set
{
this._mcVisible = value == null ? true : value;
//if (this.Site.DesignMode)
//{
// this.Visible = true;
//}
//else
//{
// this.Visible = this._mcVisible;
//}
}
}
[Description("是否可用"), Category("Behavior")]
public bool MCEnabled
{
get
{
return this._mcEnabled;
}
set
{
this._mcEnabled = value == null ? true : value;
//if (this.Site.DesignMode)
//{
// this.Enabled = true;
//}
//else
//{
// this.Enabled = this._mcEnabled;
//}
}
}
[Description("是否控制权限"), Category("Behavior")]
public bool MCPurview
{
get;
set;
}
public bool IsValid
{
get { return _isValid; }
set { _isValid = value; }
}
#endregion
private IStation ReflectClass(string Name)
{
string thisPath = this.GetType().Assembly.Location;
string assPath = (new FileInfo(thisPath)).Directory + "\\Mesnac.Compressor.Station";
//string dllName = "Mesnac.Compressor.Station";
string path = assPath + ".dll";
string className = "Mesnac.Compressor.Station."+Name;
if (!File.Exists(path))
{
return null;
}
Assembly ass = Assembly.LoadFile(path);
if (ass == null)
{
return null;
}
var classname=ass.CreateInstance(className,true);
Type type = ass.GetType(className);
if (type == null)
{
return null;
}
IStation to = (IStation)Activator.CreateInstance(type);
return to;
}
private void StationButton_Click(object sender, EventArgs e)
{
FrmStationData frm = new FrmStationData(_station.StationID, _station.StationName);
frm.ShowDialog();
}
}
public class PropertyGridFileItem : UITypeEditor
{
public override UITypeEditorEditStyle GetEditStyle(System.ComponentModel.ITypeDescriptorContext context)
{
return UITypeEditorEditStyle.Modal;
}
public override object EditValue(System.ComponentModel.ITypeDescriptorContext context, System.IServiceProvider provider, object value)
{
IWindowsFormsEditorService edSvc = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));
if (edSvc != null)
{
// 可以打开任何特定的对话框
FrmStation dialog = new FrmStation();
if (dialog.ShowDialog().Equals(DialogResult.OK))
{
Station st = new Station();
st.StationID = dialog.StationID;
st.StationName = dialog.StationName;
string result = dialog.StationID + ":" + dialog.StationName;
return result;
}
}
return value;
}
}
//[TypeConverterAttribute(typeof(StringToHumanTypeConverter))]
public class Station
{
/// <summary>
/// 工位ID
/// </summary>
public string StationID { get; set; }
/// <summary>
/// 工位名称
/// </summary>
public string StationName { get; set; }
public override string ToString()
{
if (this.StationName != null)
{
return this.StationName;
}
else
{
return base.ToString();
}
}
}
}