恒石成品库WCS
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.

486 lines
20 KiB

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DBFactory;
using Microsoft.VisualBasic;
using System.ServiceModel;
namespace wcfControlMonitorClient
{
/// <summary>
/// Creator:Richard.liu
/// ģ�¹����´��Զ�����
/// </summary>
public partial class FrmAutoCommand : Form
{
DBOperator dbo = CStaticClass.dbo;
int AutoManageIdx = 0;
#region ====��������
CommonClassLib.UCellPanel cellPanel = null;
#endregion
private static FrmAutoCommand _formInstance;
public static FrmAutoCommand FormInstance
{
get
{
if (_formInstance == null)
{
_formInstance = new FrmAutoCommand();
}
return _formInstance;
}
set { _formInstance = value; }
}
public FrmAutoCommand()
{
dbo.Open();
InitializeComponent();
_formInstance = this;
////��������:�Ѷ���ȡ����001��������002�������ȶ�003�����ػش�004��
////����ľ������005(һ��������ľ�����񣬲��ֳɶ�����һ��������)
//this.cbKind.Items.Add("");
//this.cbKind.Items.Add("�����ȶ�");
//this.cbKind.Items.Add("���ػش�");
////this.cbKind.Items.Add("����������");
//this.cbKind.Text="�����ȶ�";
////cbtasktype
//DataSet ds = dbo.ExceSQL("select * from T_ITEMTASKTYPE where FCODE !='-'");
// oracle �ͻ��˸���
DataSet ds = dbo.ExceSQL("select * from T_ITEMTASKTYPE where FCODE !=0");
if (ds.Tables[0].DefaultView.Count > 0)
{
cbtasktype.ValueMember = "FCODE";
cbtasktype.DisplayMember = "FNAME";
cbtasktype.DataSource = ds.Tables[0].DefaultView;
}
}
private void button1_Click(object sender, EventArgs e)
{
if (MessageBox.Show("��ȷ��Ҫ�����Զ���������", "������ʾ��", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) !=DialogResult.OK)
{
return;
}
if (tbFPALLETBARCODE.Text.Trim().Length < 1)
{
MessageBox.Show("���������룡", "��������ʾ", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
if (panelType.Visible)
{
if (this.comboBoxType.Text.Trim() == "")
{
MessageBox.Show("��ѡ���������ͣ�", "������ʾ��", MessageBoxButtons.OK, MessageBoxIcon.Warning);
this.comboBoxType.Focus();
return;
}
}
if ((this.cbtasktype.Text.Trim().Length == 0) || (this.cbstartposition.Text.Trim().Length == 0) || (this.cbendposition.Text.Trim().Length == 0))
{
MessageBox.Show("�����������͡�����λ�á��յ�λ�ö����������ֿ�ֵ��", "��������ʾ", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
if ((tbstartsite.Enabled == true) && (tbstartsite.Text.Trim().Length == 0))
{
MessageBox.Show("����λ�������������Ա���ָ������λ�ã�", "��������ʾ", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
if ((tbendsite.Enabled == true) && (tbendsite.Text.Trim().Length == 0))
{
MessageBox.Show("�յ�λ�������������Ա���ָ������λ�ã�", "��������ʾ", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
if ((cbKind.Text.Trim().Length > 0) &&(txtparm.Text.Trim().Length==0))
{
MessageBox.Show("���������������ǿ�ֵ������ָ������������", "��������ʾ", MessageBoxButtons.OK,MessageBoxIcon.Warning );
return;
}
if ((cbInWorkBench.Text.Trim().Length > 0) && (cbInWorkBench.Text.Trim().Length == 0))
{
MessageBox.Show("�Ƿ�����λ����ѡ����", "��������ʾ", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
int tasktype= Convert.ToInt32(this.cbtasktype.SelectedValue);
int count = 0;////����this.cbInWorkBench.Text����count
int pallettype = 0;
//if (tasktype == 5 || tasktype == 6||(tasktype == 4 && cbstartposition.SelectedValue.ToString() == "12008"))
// {
// if (int.TryParse(this.textBoxCount.Text.Trim(), out count) == false)
// {
// string message = string.Format("��������ȷ��{0}��Ϣ��", labelCount.Text);
// MessageBox.Show(message, "��������ʾ", MessageBoxButtons.OK, MessageBoxIcon.Warning);
// return;
// }
// }
if (tasktype == 1)//����ʱ��ȡ�Ƿ�˫������
{
count = CheckBoxfork2.Checked ? 2 : 1;
}
if (panelType.Visible)
{
if (comboBoxType.SelectedIndex > -1)
{
pallettype = comboBoxType.SelectedIndex + 1;//�������浥���Ѷ�������������(1С���̣�2������)
}
}
//���÷���
string errtext=string.Empty;
string startcell=string.Empty,endcell=string.Empty;
//������ת�������в�
//string st = tbstartsite.SelectedValue.ToString();
//string clpy = st.Substring(0, 2).ToString();//��
//string clpx = st.Substring(3, 2).ToString();//��
//string clpz = st.Substring(6, 2).ToString();//��
//string syxz = (clpz + "-" + clpx + "-" + clpy).ToString();//������λ
//������ת�������в�
//string ed = tbstartsite.SelectedValue.ToString();
//string eclpy = ed.Substring(0, 2).ToString();//��
//string eclpx = ed.Substring(3, 2).ToString();//��
//string eclpz = ed.Substring(6, 2).ToString();//��
//string eyxz = (eclpz + "-" + eclpx + "-" + eclpy).ToString();//������λ
if (tbstartsite.SelectedValue != null)
{
//startcell = syxz; //������ת��
startcell = tbstartsite.SelectedValue.ToString();
}
else
{
startcell = tbstartsite.Text;
}
if (tbendsite.SelectedValue != null)
{
//endcell = eyxz;
endcell = tbendsite.SelectedValue.ToString();
}
else
{
endcell = tbendsite.Text;
}
Model.AutoTask at = new Model.AutoTask(Convert.ToInt32(this.cbtasktype.SelectedValue), tbFPALLETBARCODE.Text, cbstartposition.SelectedValue.ToString(), startcell, cbendposition.SelectedValue.ToString(), endcell, this.tbstartsite.Enabled, this.tbendsite.Enabled, pallettype);//����this.cbInWorkBench.Text����pallettype
CStaticClass.WcfControl.BeginBuildAutoTask(at, new AsyncCallback(BuildAutoTaskCallBack), at);
//{
// MessageBox.Show(errtext, "������ʾ", MessageBoxButtons.OK, MessageBoxIcon.Error);
// return;
//}
}
private void button2_Click(object sender, EventArgs e)
{
string Sql, _kind, _txtparm;
DataSet ds;
//dbo.TransBegin();
try
{
//����IO_CONTROLDETAIL
//��������:�Ѷ���ȡ����001��������002�������ȶ�003�����ػش�004��
switch (this.cbKind.Text.Trim())
{
case "�����ȶ�":
_kind = "003";
break;
case "���ػش�":
_kind = "004";
break;
//case "����������":
// _kind = "005";
// break;
default:
_kind = "003";
break;
}
_txtparm = this.txtparm.Text.Trim();
if (_kind == "005")
{
}
else
{
int fid=GetIOControlDetailFid(1, AutoManageIdx);
Sql = "insert into IO_CONTROLDETAIL(FID,FCONTROLID,F_ManageTaskKindIndex,FKIND,FINDEX,FVALUE) " +
"values("+fid+"," + AutoManageIdx + ",1,'" + _kind + "',0,'" + _txtparm + "')";
ds = dbo.ExceSQL(Sql);
}
//dbo.TransCommit();
}
catch (Exception ex)
{
//dbo.TransRollback();
throw ex;
}
}
private void FrmAutoCommand_Load(object sender, EventArgs e)
{
cbInWorkBench.SelectedIndex =2;
if (cellPanel == null)
{
cellPanel = new CommonClassLib.UCellPanel(this, tbstartsite, null, tbFPALLETBARCODE, string.Empty);
cellPanel.TaskType = "100";
cellPanel.GoodsName = "";
cellPanel.Dock = DockStyle.Fill;
cellPanel.AllowWareHouseChanged = false;
plCell.Controls.Add(cellPanel);
}
cellPanel.Visible = true;
}
private void cbtasktype_SelectedIndexChanged(object sender, EventArgs e)
{
this.tbFPALLETBARCODE.Enabled = true;
this.tbFPALLETBARCODE.Text = "";
string StrSql = string.Format(" and F_WorkArea like '%{0}%'", CStaticClass.UserArea);
int IOtype =Convert.ToInt32(this.cbtasktype.SelectedValue.ToString());
// add for CATL YB2 �޸�
DataView dvs = dbo.ExceSQL("SELECT DISTINCT F_StartDevice,F_DeviceName FROM T_Base_Route,T_Base_Device where F_StartDevice = F_DeviceIndex and T_Base_Route.F_RouteKind = " + IOtype + StrSql + "order by F_StartDevice").Tables[0].DefaultView;
//cbstartposition
cbstartposition.ValueMember = "F_StartDevice";
cbstartposition.DisplayMember = "F_DeviceName";
cbstartposition.DataSource = dvs;
// add for CATL YB2 �޸�
DataView dvs1 = dbo.ExceSQL("SELECT DISTINCT F_EndDevice,F_DeviceName FROM T_Base_Route,T_Base_Device where F_EndDevice = F_DeviceIndex and T_Base_Route.F_RouteKind = " + IOtype + StrSql + "order by F_EndDevice ").Tables[0].DefaultView;
//cbendposition
cbendposition.ValueMember = "F_EndDevice";
cbendposition.DisplayMember = "F_DeviceName";
cbendposition.DataSource = dvs1;
labelCount.Visible = false;
textBoxCount.Visible = false;
labelCount.Text="����";
labelBarcode.Text = "����";
int type=Convert.ToInt32(this.cbtasktype.SelectedValue);
if (type == 5||type == 6||Convert.ToInt32(this.cbstartposition.SelectedValue)==12008)//�뿪��ɫͨ��������
{
//labelCount.Visible = true;
//textBoxCount.Visible = true;//�����ƻ���������ɫͨ����������������������֪ͨ����
}
if (type == 5)//�����ƻ�
{
labelBarcode.Text="��������";
}
if (type == 6)//֪ͨ��������
{
labelCount.Text="����";
}
//CheckBoxfork2.Visible = false;
//if (Convert.ToInt32(this.cbtasktype.SelectedValue) == 1)//����˫���Զ���������
//{
// CheckBoxfork2.Visible = true;
//}
}
private void cbstartposition_SelectedIndexChanged(object sender, EventArgs e)
{
tbstartsite.DataSource = null;
tbstartsite.Text = "";
//�����������豸tbstartsite.enable=true
DataSet ds = dbo.ExceSQL("select FLaneWay from ST_CELL where FLaneWay=" + Convert.ToInt32(cbstartposition.SelectedValue) + "");
//DataSet ds = dbo.ExceSQL("select F_DeviceIndex,F_DeviceKindIndex from T_Base_Device where F_DeviceKindIndex=10 and F_DeviceIndex=" + Convert.ToInt32(cbstartposition.SelectedValue) + "");
if (ds.Tables[0].DefaultView.Count > 0)
{
tbstartsite.Enabled = true;
plCell.Enabled = true;
if (cellPanel == null)
{
cellPanel = new CommonClassLib.UCellPanel(this, tbstartsite, null,null, string.Empty);
cellPanel.TaskType = "100";
cellPanel.GoodsName = "";
cellPanel.Dock = DockStyle.Fill;
cellPanel.AllowWareHouseChanged = false ;
plCell.Controls.Add(cellPanel);
}
cellPanel.ControlCellCode = tbstartsite;
cellPanel.Laneway = this.cbstartposition.SelectedValue.ToString();
cellPanel.WareHouse = GetWarehouse(Convert.ToInt32(this.cbstartposition.SelectedValue));
cellPanel.Visible = plCell.Visible;
}
else
{
tbstartsite.Enabled = true;
DataView dv1 = dbo.ExceSQL("SELECT T_Base_Device.F_DeviceName, T_Base_Device.F_DeviceIndex FROM T_Base_Lane_Gate,T_Base_Device WHERE T_Base_Lane_Gate.F_LaneGateDeviceIndex = T_Base_Device.F_DeviceIndex and F_DeviceKindIndex=9 and F_LaneIndex=" + cbstartposition.SelectedValue + "").Tables[0].DefaultView;
if(dv1.Count>0)
{
tbstartsite.DisplayMember = "F_DeviceName";
tbstartsite.ValueMember = "F_DeviceIndex";
tbstartsite.DataSource = dv1;
}
else
{
plCell.Enabled = false;
tbstartsite.Enabled = false;
}
}
DataView dv = dbo.ExceSQL("select F_DeviceIndex,F_DeviceKindIndex from T_Base_Device where F_DeviceKindIndex=11 and F_DeviceIndex=" + Convert.ToInt32(cbstartposition.SelectedValue) + "").Tables[0].DefaultView;
if (dv.Count > 0)
{
tbstartsite.Enabled = true;
dv = dbo.ExceSQL("SELECT T_Base_Device.F_DeviceName, T_Base_Device.F_DeviceIndex FROM T_Base_AGV_Gate,T_Base_Device WHERE T_Base_AGV_Gate.F_AGVGateDeviceIndex = T_Base_Device.F_DeviceIndex and F_ChannelsIndex=" + cbstartposition.SelectedValue + "").Tables[0].DefaultView;
tbstartsite.DisplayMember = "F_DeviceName";
tbstartsite.ValueMember = "F_DeviceIndex";
tbstartsite.DataSource = dv;
}
labelCount.Visible = false;
textBoxCount.Visible = false;
//int type = Convert.ToInt32(this.cbtasktype.SelectedValue);
int startdevice = Convert.ToInt32(this.cbstartposition.SelectedValue);
int enddevice = Convert.ToInt32(this.cbendposition.SelectedValue);
//if ((startdevice >= 18001 && startdevice <= 18004) || (enddevice >= 18001 && enddevice <= 18004))
//{
// panelType.Visible = true;
//}
//else
//{
// panelType.Visible = false;
//}
comboBoxType.SelectedIndex = -1;
comboBoxType.Text = "";
}
private void cbendposition_SelectedIndexChanged(object sender, EventArgs e)
{
tbendsite.DataSource = null;
tbendsite.Text = "";
//�����������豸tbstartsite.enable=true
DataSet ds = dbo.ExceSQL("select FLaneWay from ST_CELL where FLaneWay=" + Convert.ToInt32(cbendposition.SelectedValue) + "");
//DataSet ds = dbo.ExceSQL("select F_DeviceIndex,F_DeviceKindIndex from T_Base_Device where F_DeviceKindIndex=10 and F_DeviceIndex= " +Convert.ToInt32( cbendposition.SelectedValue) + "");
if (ds.Tables[0].DefaultView.Count > 0)
{
tbendsite.Enabled = true;
//�������
plCell.Enabled = true;
if (cellPanel == null)
{
cellPanel = new CommonClassLib.UCellPanel(this, tbendsite, null, null,string.Empty);
cellPanel.TaskType = "100";
cellPanel.GoodsName = "";
cellPanel.Dock = DockStyle.Fill;
cellPanel.AllowWareHouseChanged = false;
plCell.Controls.Add(cellPanel);
}
cellPanel.ControlCellCode = tbendsite;
cellPanel.Laneway = this.cbendposition.SelectedValue.ToString();
cellPanel.WareHouse = GetWarehouse(Convert.ToInt32(this.cbendposition.SelectedValue));
cellPanel.Visible = plCell.Visible;
}
else
{
tbendsite.Enabled = true;
DataView dv1 = dbo.ExceSQL("SELECT T_Base_Device.F_DeviceName, T_Base_Device.F_DeviceIndex FROM T_Base_Lane_Gate,T_Base_Device WHERE T_Base_Lane_Gate.F_LaneGateDeviceIndex = T_Base_Device.F_DeviceIndex and F_DeviceKindIndex=9 and F_LaneIndex=" + cbendposition.SelectedValue + "").Tables[0].DefaultView;
if (dv1.Count > 0)
{
tbendsite.DisplayMember = "F_DeviceName";
tbendsite.ValueMember = "F_DeviceIndex";
tbendsite.DataSource = dv1;
}
else
{
plCell.Enabled = false;
tbendsite.Enabled = false;
}
}
DataView dv = dbo.ExceSQL("select F_DeviceIndex,F_DeviceKindIndex from T_Base_Device where F_DeviceKindIndex=11 and F_DeviceIndex=" + Convert.ToInt32(cbendposition.SelectedValue) + "").Tables[0].DefaultView;
if (dv.Count > 0)
{
tbendsite.Enabled = true;
dv = dbo.ExceSQL("SELECT T_Base_Device.F_DeviceName, T_Base_Device.F_DeviceIndex FROM T_Base_AGV_Gate,T_Base_Device WHERE T_Base_AGV_Gate.F_AGVGateDeviceIndex = T_Base_Device.F_DeviceIndex and F_ChannelsIndex=" + cbendposition.SelectedValue + "").Tables[0].DefaultView;
tbendsite.DisplayMember = "F_DeviceName";
tbendsite.ValueMember = "F_DeviceIndex";
tbendsite.DataSource = dv;
}
int startdevice = Convert.ToInt32(this.cbstartposition.SelectedValue);
int enddevice = Convert.ToInt32(this.cbendposition.SelectedValue);
//if ((startdevice >= 18001 && startdevice <= 18004) || (enddevice >= 18001 && enddevice <= 18004))
//{
// panelType.Visible = true;
//}
//else
//{
// panelType.Visible = false;
//}
}
int GetIOControlDetailFid(int ManageTaskKindIndex,int FCONTROLID)
{
DataSet ds = dbo.ExceSQL("SELECT MAX(FID) AS MaxFID FROM IO_CONTROLDETAIL GROUP BY F_ManageTaskKindIndex, FCONTROLID HAVING (F_ManageTaskKindIndex = " + ManageTaskKindIndex + ") AND (FCONTROLID = " + FCONTROLID + ")");
if (ds.Tables[0].DefaultView.Count > 0)
{
return (Convert.ToInt32(ds.Tables[0].DefaultView[0]["MaxFID"]) + 1);
}
else
{
return 1;
}
}
void BuildAutoTaskCallBack(IAsyncResult ar)
{
string errtext=string.Empty;
if (CStaticClass.WcfControl.EndBuildAutoTask(out errtext, ar) == false)
{
MessageBox.Show(errtext, "������ʾ", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void FrmAutoCommand_FormClosing(object sender, FormClosingEventArgs e)
{
_formInstance = null;
}
string GetWarehouse(int laneway)
{
DataView dv = dbo.ExceSQL(string.Format("SELECT DISTINCT FWAREHOUSE FROM ST_CELL WHERE (FLaneWay = {0})",laneway)).Tables[0].DefaultView;
if (dv.Count > 0)
{
return dv[0][0].ToString();
}
else
{
// add for CATL YB2
return "1";
}
}
}
}