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 mes_BzUsedby { 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(); //成品上机 // 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; public void adddata() { //材料上机 ,a.id as id string sql = string.Format(@"select ss.uniqueCode as 材料条码,ss.amount as 重量,ss.model 型号,ss.spec as 规格,ss.p_stock_name as 仓库,ss.storehouseareaname as 库位 from mrp_mpsPlanListTab a left join mps_PlanBomBaseTab aa on a.orderid=aa.sellorid and a.Productid=aa.CpProductid left join Wms_ProductBatchBarCode ss on ss.objectId=aa.productid where isnull(ss.amount,0)>0 and a.id = '{1}' and uniqueCode like '%{2}%'", DllBaseClass.workshop, DllBaseClass.planlistid, textBox9.Text); ClsjTable = BaseImpl.GetDataTableResult(sql); gridControlCLSJ.DataSource = ClsjTable; //成品上机 // 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) { // 检查数据库连接 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"] + ""); //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; this.textBox9.Focus(); this.gridViewClSj.BestFitColumns();//设置根据内容填充列宽 } private void button6_Click(object sender, EventArgs e) { Close(); } private void button1_Click(object sender, EventArgs e) { if (gridViewClSj.FocusedRowHandle < 0) { MessageBox.Show("请选择卷号进行上机", "提示"); return; } DialogResult str1 = MessageBox.Show("确定将此卷号上机吗", "提示!", MessageBoxButtons.YesNo); if (str1 == DialogResult.Yes) { if (YSjTable.Rows.Count != 0 && checkBox2.Checked == false) { MessageBox.Show("已经有材料上机,如果想多卷上机,请勾选多卷上机", "提示"); return; } try { //string sql2 = "insert WMS_BillOutUsedByPlanTab( pid,Sjtype,issn,OutDate,OutListID,OutBarID,ParentClTm,ClTm,Storehouseid,Productid,Jtid,planlistid,amount,operatorname,operatordate) " + //"select poid,1,1,Billdt ,mxid,id,uniqueCode,uniqueCode,storehouseid,objectId,'" + DllBaseClass.Gjtid + "','" + DllBaseClass.planlistid + "',-Amount,'" + DllBaseClass.Goperatorname + "',getdate() " + //"from wms_productBarCode WITH (NOLOCK) where id='" + ClsjTable.Rows[gridViewClSj.FocusedRowHandle]["材料条码"].ToString() + "' "; string sql = string.Format(@"insert WMS_BillOutUsedByPlanTab(pid, Sjtype, issn, OutDate, OutListID, OutBarID, ParentClTm, ClTm, Storehouseid, Productid, Jtid, planlistid, amount, operatorname, operatordate) select 0,1,1,getdate() ,0,0,uniqueCode,uniqueCode,storehouseid,objectId,'{0}','{1}',amount,'{2}',getdate() from Wms_ProductBatchBarCode a where uniqueCode = '{3}'", DllBaseClass.Gjtid, DllBaseClass.planlistid, DllBaseClass.Goperatorname, ClsjTable.Rows[gridViewClSj.FocusedRowHandle]["材料条码"].ToString()); //insert WMS_BillOutUsedByPlanTab(pid, Sjtype, issn, OutDate, OutListID, OutBarID, ParentClTm, ClTm, Storehouseid, Productid, Jtid, planlistid, amount, operatorname, operatordate) // select // 0,1,1,getdate() ,0,0,uniqueCode,uniqueCode,storehouseid,objectId,'参数2','参数1',amount,'{loginname}',getdate() // from Wms_ProductBatchBarCode a //where uniqueCode = '{uniqueCode}'--列表选中行的uniqueCode 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) { if (YSjTable.Rows.Count != 0 && checkBox2.Checked == false) { MessageBox.Show("已经有材料上机,如果想多卷上机,请勾选多卷上机", "提示"); return; } MessageBox.Show("上机成功", "提示"); adddata(); } } private void textBox7_KeyDown(object sender, KeyEventArgs e) { } private void button5_Click_1(object sender, EventArgs e) { if (gridViewYSJ.FocusedRowHandle < 0) { MessageBox.Show("请选择卷号进行上机", "提示"); return; } DialogResult str1 = MessageBox.Show("确定要删除此卷号上机吗", "提示!", MessageBoxButtons.YesNo); if (str1 == DialogResult.Yes) { string sql =string.Format(@"select 1 from WMS_BillOutUsedByPlanTab a join wms_BillOutExpendTab aa on a.planlistid = aa.planlistid and isnull(a.ClTm,'')= isnull(aa.ClTm, '') where a.id = '{0}' and a.planlistid='{1}' ", YSjTable.Rows[gridViewYSJ.FocusedRowHandle]["id"].ToString(), t2.Text.Split(new string[] { "->" }, StringSplitOptions.None)[0]); tmpTable = BaseImpl.GetDataTableResult(sql); if (tmpTable.Rows.Count != 0) { MessageBox.Show("此条码已经被后续使用,不能删除上机", "提示"); return; } sql = string.Format(@"select 1 from WMS_BillOutUsedByPlanTab a join Mrp_WorkOrderTab aa on a.planlistid=aa.planlistid and isnull(a.ClTm,'')=isnull(aa.YzBarcode,'') where a.id='{0}' and a.planlistid='{1}' ", YSjTable.Rows[gridViewYSJ.FocusedRowHandle]["id"].ToString(), t2.Text.Split(new string[] { "->" }, StringSplitOptions.None)[0]); tmpTable = BaseImpl.GetDataTableResult(sql); if (tmpTable.Rows.Count != 0) { MessageBox.Show("此条码已经被后续使用,不能删除上机", "提示"); return; } //sql = " delete WMS_BillOutUsedByPlanTab where id='" + YSjTable.Rows[gridViewYSJ.FocusedRowHandle]["id"].ToString() + "' "; sql = string.Format(" delete WMS_BillOutUsedByPlanTab where id='{0}' and a.planlistid='{1}' ", YSjTable.Rows[gridViewYSJ.FocusedRowHandle]["id"].ToString(), t2.Text.Split(new string[] { "->" }, StringSplitOptions.None)[0]); BaseImpl.ExecSqlValue(sql); } adddata(); } //private void button4_Click(object sender, EventArgs e) //{ // //if (gridViewJTLSJ.FocusedRowHandle < 0) // //{ // // MessageBox.Show("请选择卷号进行上机", "提示"); // // return; // //} // 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 = textBox9.Text; string str2 = textBox9.Text + "&"; int F = 0; F = str2.IndexOf("&"); if (F == 0) { str1 = textBox1.Text; } else { str1 = str2.Substring(0, F); } textBox9.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; } 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 button4_Click(object sender, EventArgs e) { } //private void button7_Click(object sender, EventArgs e) //{ // if (gridViewCpSj.FocusedRowHandle < 0) // { // MessageBox.Show("请选择卷号进行上机", "提示"); // return; // } // 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(); // } //} } }