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 Lskj.Control;
using Lskj.Core;
using Lskj.Util;
using Lskj.Data;
using Lskj.Business.Impl;
using System.Data.SqlClient;
namespace WindowsFormsApplication2
{
public partial class FrmMain : BaseForm
{
public DynamicDemoModel Model;
public TextBox t1 { get { return textBox1; } }
public TextBox t2 { get { return textBox2; } }
public FrmMain()
{
InitializeComponent();
}
private System.Data.DataTable ClsjTable = new System.Data.DataTable();
private System.Data.DataTable YlsjTable = new System.Data.DataTable();
private System.Data.DataTable BcpsjTable = new System.Data.DataTable();
private System.Data.DataTable CpsjTable = new System.Data.DataTable();
private System.Data.DataTable JTlSjTable = new System.Data.DataTable();
private System.Data.DataTable YSjTable = new System.Data.DataTable();
private System.Data.DataTable YXjTable = new System.Data.DataTable();
private System.Data.DataTable tmpTable = new System.Data.DataTable();
public void adddata()
{
//材料上机
string sql = @"select coalias,isnull(YsTig,0) as YsTig,mxId,primaryKey,Billid_stepover,a.id,uniqueCode,ABS(Amount) AS Amount,jtBillNo,p.model as model,p.spec as spec
from wms_productBarCode a WITH(NOLOCK)
join mps_PlanBomBaseTab aa WITH(NOLOCK) on a.objectId = aa.productid
join Wms_BillOutMainTab a1 WITH(NOLOCK) on primaryKey = wms_mout_billdocument_id
left
join p_ProductTab p on p.ProductId=a.objectId
left
join Mps_MachineSetTab b on a.Jtid = b.id
left
join P_ProviderTab c on a.poid = c.id
where modid in (1100201, 11002)
and wms_mout_workshop = '" + DllBaseClass.workshop + "'and aa.planlistid = '" + DllBaseClass.planlistid + "' " +
" and uniqueCode like '%" + textBox7.Text + "%' and amount<0 ";
ClsjTable = BaseImpl.GetDataTableResult(sql);
gridControlCLSJ.DataSource = ClsjTable;
//余料上机
string jttj = "";
if (checkBox1.Checked == false)
{ jttj = " and jtid='" + DllBaseClass.Gjtid + "' "; }
sql = "select coalias,Jtid,a.id,jtbillno,ClTm,barcode,amount,OutBarID from wms_BillOutExpendTab a WITH (NOLOCK) join Mps_MachineSetTab b on a.Jtid=b.id left join P_ProviderTab c on a.pid=c.id " +
"where workshopid='" + DllBaseClass.workshop + "' and Tmqz='CLXJ' " + jttj + " and RedTig=0 and ISNULL(SjTig,0)=0 and productid='" + textBox3.Text + "' and barcode like '%" + textBox8.Text + "%' ";
YlsjTable = BaseImpl.GetDataTableResult(sql);
gridControlYLSJ.DataSource = YlsjTable;
//半成品上机
sql = "select A.ID,PrCoName,jtBillNo,barcode,joinamount from Mrp_WorkOrderTab A JOIN Mps_MachineSetTab B ON A.Jtid=B.id where a.workshopid='" + DllBaseClass.workshop + "' and productid='" + textBox3.Text + "' and barcode='" + textBox10.Text + "' and isnull(BcpSjtig,0)=0 and isnull(rktig,0)=0 ";
BcpsjTable = BaseImpl.GetDataTableResult(sql);
gridControlBcpSj.DataSource = BcpsjTable;
//成品上机
sql = "select coalias, mxId,primaryKey,Billid_stepover,a.id,uniqueCode,ABS(Amount) AS Amount,jtBillNo from wms_productBarCode a WITH (NOLOCK) join Wms_BilljoinsMainTab a1 WITH (NOLOCK) on primaryKey=wms_mjoins_billdocument_id join Wms_BilljoinslistTab a2 on wms_mjoins_billdocument_id=wms_ljoins_billdocument_id and a.mxId=a2.wms_ljoins_id " +
" left join Mps_MachineSetTab b on a.Jtid=b.id left join P_CustomerTab c on a.coid=c.id " +
" where modid in (1100301,11003) and wms_ljoins_jtid='" + DllBaseClass.Gjtid + "' and (objectId='" + textBox3.Text + "' or '" + textBox6.Text + "'='替代纸') and ISNULL(SjTig,0)=0 " +
" and uniqueCode like '%" + textBox11.Text + "%' and amount<0 ";
CpsjTable = BaseImpl.GetDataTableResult(sql);
gridControlCpSj.DataSource = CpsjTable;
//机台料上机
sql = "select top 20 id,ClTm,operatordate,amount,OutBarID from WMS_BillOutUsedByPlanTab where jtid='" + DllBaseClass.Gjtid + "' and Productid='" + textBox3.Text + "' and planlistid<>'" + DllBaseClass.planlistid + "' and cltm not in (select cltm from WMS_BillOutUsedByPlanTab where planlistid='" + DllBaseClass.planlistid + "' and issn=1 ) and issn=1 and Sjtype<>5 order by operatordate desc ";
JTlSjTable = BaseImpl.GetDataTableResult(sql);
gridControlJTLSJ.DataSource = JTlSjTable;
//已上机材料
sql = "select c.coalias,d.coalias as khcoalias,a.*,spec,model from WMS_BillOutUsedByPlanTab a join p_ProductTab b on a.Productid=b.ProductId left join P_ProviderTab c on a.pid=c.id left join P_CustomerTab d on a.cid=d.id where planlistid='" + DllBaseClass.planlistid + "' and issn=1 ";
YSjTable = BaseImpl.GetDataTableResult(sql);
gridControlYSJ.DataSource = YSjTable;
//已经下机器材料
sql = "select coalias,a.*,spec,model from WMS_BillOutUsedByPlanTab a join p_ProductTab b on a.Productid=b.ProductId left join P_ProviderTab c on a.pid=c.id where planlistid='" + DllBaseClass.planlistid + "' and issn=0 ";
YXjTable = BaseImpl.GetDataTableResult(sql);
gridControlYXJ.DataSource = YXjTable;
}
/**
* 说明如下:ss
* 开发环境:采用Vs2010开发环境
* 调用.net程序支持2种模式:1、调用exe 2、调用dll类库
*
* 1、调用exe方式:无需建立DllBaseClass.cs参数类,直接建立exe程序即可。参数通过入口参数提取。
* 2、调用dll方式: 需要建立DllBaseClass.cs参数类,需要注意类名称必须为DllBaseClass,具体参考DllBaseClass.cs方法,基本上通用。
*
* 通用设置:
* 建立窗口需要继承BaseForm窗口,同时引入6个公共dll程序(Lskj.Business.dll、Lskj.Control.dll、Lskj.Core.dll、Lskj.Data.dll、Lskj.Model.dll、Lskj.Util.dll)
* 此窗口在Lskj.Control.dll中,前提需要安装DevExpress15.2版本。
* Lskj.Business.dll 所有业务处理类库,以及访问数据库操作类
* Lskj.Core.dll 数据库连接创建类库
* Lskj.Data.dll 存放资源文件以及所有提示信息
* Lskj.Model.dll 存放公用的业务对象Model
* Lskj.Util.dll 存放所有常用操作类
*
* 下面展示一下怎么创建连接获取数据等
**/
///
/// 说明:窗口加载时调用
/// 创建人:龚宇超
/// 创建日期:
/// 修改人:
/// 修改日期:
/// 修改备注:
/// 版本:1.0
///
/// The source of the event.
/// The instance containing the event data.
private void FrmMain_Load(object sender, EventArgs e)
{
//隐藏选项卡
tabControl1.TabPages[3].Parent = null;
tabControl1.TabPages[3].Parent = null;
// 检查数据库连接
if (!DBConfig.Instance.CreateConnection())
{
MessageUtil.Show(ResourceKeys.UnConnectServer);
return;
}
// 检查delphi连接
//if (DelphiHelper.Delphi_Init(new StringBuilder(DBConfig.Instance.GetDelphiConnection())) == 0)
//{
// MessageUtil.Show(ResourceKeys.UnConnectServer + "[By Delphi]");
// return;
//}
// 访问数据库开始操作,所有公共操作在BaseImpl类里面,下面还有很多继承类
string sqlValue = "select * from p_systemtab";
DataTable tmpTable = BaseImpl.GetDataTableResult(sqlValue);
// MessageUtil.Show(table.Rows.Count + "");
this.Text = tmpTable.Rows[0]["ClientName"].ToString();
string sql = "select productid,appellation,spec,model from p_producttab where productid='" + DllBaseClass.YzProductid + "' ";
tmpTable = BaseImpl.GetDataTableResult(sql);
textBox3.Text = tmpTable.Rows[0]["productid"].ToString();
textBox4.Text = tmpTable.Rows[0]["appellation"].ToString();
textBox5.Text = tmpTable.Rows[0]["spec"].ToString();
textBox6.Text = tmpTable.Rows[0]["model"].ToString();
sql = "select a.workshopid,YsHour,jtbillno,jtlsj from Mps_MachineSetTab a join Mrp_WpSetTab b on a.wpid=b.id where a.id='" + DllBaseClass.Gjtid + "' ";
tmpTable = BaseImpl.GetDataTableResult(sql);
DllBaseClass.YsHour = Convert.ToInt32(tmpTable.Rows[0]["YsHour"].ToString());
DllBaseClass.jtlsj = Convert.ToInt32(tmpTable.Rows[0]["jtlsj"].ToString());
DllBaseClass.workshop = tmpTable.Rows[0]["workshopid"].ToString();
DllBaseClass.GjtName = tmpTable.Rows[0]["jtbillno"].ToString();
adddata();
textBox1.Text = "操作员:" + DllBaseClass.Goperatorname + "计划ID" + DllBaseClass.planlistid + "机台ID" + DllBaseClass.Gjtid + "原纸编码" + DllBaseClass.YzProductid + "验收小时" + DllBaseClass.YsHour.ToString() + "车间" + DllBaseClass.workshop + "机台编码" + DllBaseClass.GjtName;
}
private void button6_Click(object sender, EventArgs e)
{
Close();
}
private void button1_Click(object sender, EventArgs e)
{
DialogResult str1 = MessageBox.Show("确定将此卷号上机吗", "提示!", MessageBoxButtons.YesNo);
if (str1 == DialogResult.Yes)
{
if (YSjTable.Rows.Count != 0 && checkBox2.Checked == false)
{
MessageBox.Show("已经有材料上机,如果想多卷上机,请勾选多卷上机", "提示");
return;
}
try
{
string sql = "insert WMS_BillOutUsedByPlanTab( pid,Sjtype,issn,OutDate,OutListID,OutBarID,ParentClTm,ClTm,Storehouseid,Productid,Jtid,planlistid,amount,Famount,operatorname,operatordate) " +
"select poid,1,1,Billdt ,mxid,id,uniqueCode,uniqueCode,storehouseid,objectId,'" + DllBaseClass.Gjtid + "','" + DllBaseClass.planlistid + "',-Amount,-long,'" + DllBaseClass.Goperatorname + "',getdate() " +
"from wms_productBarCode WITH (NOLOCK) where id='" + ClsjTable.Rows[gridViewClSj.FocusedRowHandle]["id"].ToString() + "' ";
BaseImpl.ExecSqlValue(sql);
sql = "update wms_productBarCode set sjtig=1 where id='" + ClsjTable.Rows[gridViewClSj.FocusedRowHandle]["id"].ToString() + "' ";
BaseImpl.ExecSqlValue(sql);
}
catch (Exception ex)
{
MessageBox.Show("保存失败" + ex.Message);
return;
}
MessageBox.Show("上机成功", "提示");
adddata();
}
}
private void button2_Click(object sender, EventArgs e)
{
DialogResult str1 = MessageBox.Show("确定将此卷号上机吗", "提示!", MessageBoxButtons.YesNo);
if (str1 == DialogResult.Yes)
{
string sql = "select 1 from wms_productBarCode WITH (NOLOCK) where id='" + YlsjTable.Rows[gridViewYLSJ.FocusedRowHandle]["OutBarID"].ToString() + "' and DATEDIFF(month,Billdt,getdate())>0 ";
tmpTable = BaseImpl.GetDataTableResult(sql);
if (tmpTable.Rows.Count != 0)
{
MessageBox.Show("此记录不是当前月领料出库,不能上机", "提示");
return;
}
if (YSjTable.Rows.Count != 0 && checkBox2.Checked == false)
{
MessageBox.Show("已经有材料上机,如果想多卷上机,请勾选多卷上机", "提示");
return;
}
try
{
sql = "insert WMS_BillOutUsedByPlanTab( pid,Sjtype,issn,OutDate,OutListID,OutBarID,expid,ParentClTm,ClTm,Storehouseid,Productid,Jtid,planlistid,amount,operatorname,operatordate) " +
"select pid,2,1,OutDate ,OutListID,OutBarID,id,ClTm,Barcode,Storehouseid,Productid,'" + DllBaseClass.Gjtid + "','" + DllBaseClass.planlistid + "',Amount,'" + DllBaseClass.Goperatorname + "',getdate() " +
"from wms_BillOutExpendTab WITH (NOLOCK) where id='" + YlsjTable.Rows[gridViewYLSJ.FocusedRowHandle]["id"].ToString() + "' ";
BaseImpl.ExecSqlValue(sql);
sql = "update wms_BillOutExpendTab set sjtig=1 where id='" + YlsjTable.Rows[gridViewYLSJ.FocusedRowHandle]["id"].ToString() + "' ";
BaseImpl.ExecSqlValue(sql);
}
catch (Exception ex)
{
MessageBox.Show("上机失败" + ex.Message);
return;
}
MessageBox.Show("上机成功", "提示");
adddata();
}
}
private void textBox7_KeyDown(object sender, KeyEventArgs e)
{
}
private void button5_Click_1(object sender, EventArgs e)
{
DialogResult str1 = MessageBox.Show("确定要删除此卷号上机吗", "提示!", MessageBoxButtons.YesNo);
if (str1 == DialogResult.Yes)
{
string sql = "select 1 from wms_BillOutExpendTab where OutBarID='" + YSjTable.Rows[gridViewYSJ.FocusedRowHandle]["OutBarID"].ToString() + "' and " +
" ParentClTm='" + YSjTable.Rows[gridViewYSJ.FocusedRowHandle]["ClTm"].ToString() + "' ";
tmpTable = BaseImpl.GetDataTableResult(sql);
if (tmpTable.Rows.Count != 0)
{
MessageBox.Show("此条码已经被后续使用,不能删除上机", "提示");
return;
}
sql = "select 1 from wms_BillOutExpendTab where SjWorkId='" + YSjTable.Rows[gridViewYSJ.FocusedRowHandle]["SjWorkId"].ToString() + "' and " +
" ParentClTm='" + YSjTable.Rows[gridViewYSJ.FocusedRowHandle]["ClTm"].ToString() + "' ";
tmpTable = BaseImpl.GetDataTableResult(sql);
if (tmpTable.Rows.Count != 0)
{
MessageBox.Show("此条码已经被后续使用,不能删除上机", "提示");
return;
}
sql = " delete WMS_BillOutUsedByPlanTab where id='" + YSjTable.Rows[gridViewYSJ.FocusedRowHandle]["id"].ToString() + "' ";
BaseImpl.ExecSqlValue(sql);
//材料上机
if (Convert.ToInt32(YSjTable.Rows[gridViewYSJ.FocusedRowHandle]["sjtype"].ToString()) == 1)
{
sql = " update wms_productBarCode set sjtig=0 where id='" + YSjTable.Rows[gridViewYSJ.FocusedRowHandle]["OutBarID"].ToString() + "' ";
BaseImpl.ExecSqlValue(sql);
}
//余料上机
if (Convert.ToInt32(YSjTable.Rows[gridViewYSJ.FocusedRowHandle]["sjtype"].ToString()) == 2)
{
sql = " update wms_BillOutExpendTab set sjtig=0 where barcode='" + YSjTable.Rows[gridViewYSJ.FocusedRowHandle]["ClTm"].ToString() + "' ";
BaseImpl.ExecSqlValue(sql);
}
//半成品上机
if (Convert.ToInt32(YSjTable.Rows[gridViewYSJ.FocusedRowHandle]["sjtype"].ToString()) == 3)
{
sql = " update Mrp_WorkOrderTab set BcpSjtig=0 where id='" + YSjTable.Rows[gridViewYSJ.FocusedRowHandle]["SjWorkId"].ToString() + "' ";
BaseImpl.ExecSqlValue(sql);
}
//成品上机
if (Convert.ToInt32(YSjTable.Rows[gridViewYSJ.FocusedRowHandle]["sjtype"].ToString()) == 4)
{
sql = " update wms_productBarCode set sjtig=0 where id='" + YSjTable.Rows[gridViewYSJ.FocusedRowHandle]["OutBarID"].ToString() + "' ";
BaseImpl.ExecSqlValue(sql);
}
}
adddata();
}
private void button4_Click(object sender, EventArgs e)
{
if (DllBaseClass.jtlsj != 1)
{
MessageBox.Show("此工序不允许机台料上机", "提示");
return;
}
DialogResult str1 = MessageBox.Show("确定将此卷号上机吗", "提示!", MessageBoxButtons.YesNo);
if (str1 == DialogResult.Yes)
{
string sql = "select 1 from wms_productBarCode WITH (NOLOCK) where id='" + JTlSjTable.Rows[gridViewJTLSJ.FocusedRowHandle]["OutBarID"].ToString() + "' and DATEDIFF(month,Billdt,getdate())>0 ";
tmpTable = BaseImpl.GetDataTableResult(sql);
if (tmpTable.Rows.Count != 0)
{
MessageBox.Show("此记录不是当前月领料出库,不能上机", "提示");
return;
}
if (YSjTable.Rows.Count != 0 && checkBox2.Checked == false)
{
MessageBox.Show("已经有材料上机,如果想多卷上机,请勾选多卷上机", "提示");
return;
}
sql = "select 1 from WMS_BillOutUsedByPlanTab where planlistid='+planlistid+' and ClTm='" + JTlSjTable.Rows[gridViewJTLSJ.FocusedRowHandle]["ClTm"].ToString() + "' ";
tmpTable = BaseImpl.GetDataTableResult(sql);
if (tmpTable.Rows.Count != 0)
{
MessageBox.Show("此条码在此订单已经上机,不能继续上机", "提示");
return;
}
sql = "insert WMS_BillOutUsedByPlanTab( pid,Sjtype,issn,OutDate,OutListID,OutBarID,expid,ParentClTm,ClTm,Storehouseid,Productid,Jtid,planlistid,amount,operatorname,operatordate) " +
"select pid,5,1,OutDate, OutListID,OutBarID,expid,ParentClTm,ClTm,Storehouseid,Productid,Jtid,'" + DllBaseClass.planlistid + "',amount,'" + DllBaseClass.Goperatorname + "',getdate() from WMS_BillOutUsedByPlanTab where id= '" + JTlSjTable.Rows[gridViewJTLSJ.FocusedRowHandle]["ID"].ToString() + "' ";
BaseImpl.ExecSqlValue(sql);
}
}
private void button6_Click_1(object sender, EventArgs e)
{
Close();
}
private void textBox7_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == 13)
{
string str1 = textBox7.Text;
string str2 = textBox7.Text + "&";
int F = 0;
F = str2.IndexOf("&");
if (F == 0)
{
str1 = textBox1.Text;
}
else
{
str1 = str2.Substring(0, F);
}
textBox7.Text = str1;
adddata();
}
}
private void gridControlCLSJ_Click(object sender, EventArgs e)
{
}
private void gridControlJTLSJ_Click(object sender, EventArgs e)
{
}
private void checkBox1_Click(object sender, EventArgs e)
{
adddata();
}
private void button3_Click(object sender, EventArgs e)
{
DialogResult str1 = MessageBox.Show("确定将此卷号上机吗", "提示!", MessageBoxButtons.YesNo);
if (str1 == DialogResult.Yes)
{
if (YSjTable.Rows.Count != 0 && checkBox2.Checked == false)
{
MessageBox.Show("已经有材料上机,如果想多卷上机,请勾选多卷上机", "提示");
return;
}
try
{
string sql = "insert WMS_BillOutUsedByPlanTab( cid,Sjtype,issn,SjWorkId,ParentClTm,ClTm,Productid,Jtid,planlistid,amount,operatorname,operatordate) " +
"select PrCoid,3,1,id,barcode,barcode,productid,'" + DllBaseClass.Gjtid + "','" + DllBaseClass.planlistid + "',joinamount,'" + DllBaseClass.Goperatorname + "',getdate() " +
"from Mrp_WorkOrderTab WITH (NOLOCK) where id='" + BcpsjTable.Rows[gridViewBcpSj.FocusedRowHandle]["id"].ToString() + "' ";
BaseImpl.ExecSqlValue(sql);
sql = "update Mrp_WorkOrderTab set BcpSjtig=1 where id='" + BcpsjTable.Rows[gridViewBcpSj.FocusedRowHandle]["id"].ToString() + "' ";
BaseImpl.ExecSqlValue(sql);
}
catch (Exception ex)
{
MessageBox.Show("保存失败" + ex.Message);
return;
}
MessageBox.Show("上机成功", "提示");
adddata();
}
}
private void textBox10_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == 13)
{
adddata();
}
}
private void textBox11_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == 13)
{
adddata();
}
}
private void button7_Click(object sender, EventArgs e)
{
DialogResult str1 = MessageBox.Show("确定将此卷号上机吗", "提示!", MessageBoxButtons.YesNo);
if (str1 == DialogResult.Yes)
{
if (YSjTable.Rows.Count != 0 && checkBox2.Checked == false)
{
MessageBox.Show("已经有材料上机,如果想多卷上机,请勾选多卷上机", "提示");
return;
}
try
{
string sql = "insert WMS_BillOutUsedByPlanTab( cid,Sjtype,issn,OutDate,OutListID,OutBarID,ParentClTm,ClTm,Storehouseid,Productid,Jtid,planlistid,amount,operatorname,operatordate) " +
"select coid,4,1,Billdt ,mxid,id,uniqueCode,uniqueCode,storehouseid,objectId,'" + DllBaseClass.Gjtid + "','" + DllBaseClass.planlistid + "',-Amount,'" + DllBaseClass.Goperatorname + "',getdate() " +
"from wms_productBarCode WITH (NOLOCK) where id='" + CpsjTable.Rows[gridViewCpSj.FocusedRowHandle]["id"].ToString() + "' ";
BaseImpl.ExecSqlValue(sql);
sql = "update wms_productBarCode set sjtig=1 where id='" + CpsjTable.Rows[gridViewCpSj.FocusedRowHandle]["id"].ToString() + "' ";
BaseImpl.ExecSqlValue(sql);
}
catch (Exception ex)
{
MessageBox.Show("保存失败" + ex.Message);
return;
}
MessageBox.Show("上机成功", "提示");
adddata();
}
}
}
}