using DevExpress.XtraReports.Data; using Newtonsoft.Json; using Newtonsoft.Json.Linq; using System; using System.Collections; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.IO; using System.Linq; using System.Net; using System.Text; using System.Threading; using System.Threading.Tasks; using System.Windows.Forms; using WMS.Business; using WMS.Business.CK; using WMS.Business.Report; using WMS.Common; using WMS.Frm.Base; using WMS.Model.CK; using WMS.Model.Stock; namespace WMS.FrmCK { public partial class FrmSdOrders : FormBase { /// /// 库存List /// List miStockList = new List(); public FrmSdOrders() { InitializeComponent(); } string barcode = string.Empty; string storid = string.Empty; string mesIP = string.Empty; private void FrmSdOrders_Load(object sender, EventArgs e) { mesIP = "10.10.90.192:8080"; comboBox1.Items.Clear(); // 添加新的选项 comboBox1.Items.Add("J03-SCDB-IN-Schedule${04}"); comboBox1.Items.Add("J03-DTDB-IN-Schedule${04}"); BindMiStockData(); } public override void Del() { ctrlButtons3_Click(null, null); } /// /// 绑定库存数据 /// /// public void BindMiStockData() { new Thread(delegate () { string errText = string.Empty; try { this.Invoke(new MethodInvoker(delegate { //miStockList = IBussFactory.Instance().GetMiStockForLookUp(); //if (miStockList != null) //{ // bgsStock.DataSource = miStockList; //} bgsStock.DataSource = IBussFactory.Instance().GetMiStockForLookUp2(); getList(); })); } catch (Exception) { SystemCommon.ShowInfoMessageBox("error"); } }).Start(); } public List or_det_List = new List(); private void GVMiStock_RowClick(object sender, DevExpress.XtraGrid.Views.Grid.RowClickEventArgs e) { if (GVMiStock.RowCount == 0) { return; } this.txtCTL.Text = GVMiStock.GetFocusedRowCellValue("CTL").ToString(); this.txtLocation.Text = GVMiStock.GetFocusedRowCellValue("LOCATION_ID").ToString(); this.txtGoodsId.Text = GVMiStock.GetFocusedRowCellValue("GOODS_ID").ToString(); //txtGoodsName.Text = GVMiStock.GetFocusedRowCellValue("GOODS_NAME").ToString(); txtCCNum.Text = GVMiStock.GetFocusedRowCellValue("SHELVES_NUM").ToString(); txtCKnum.Text = GVMiStock.GetFocusedRowCellValue("SHELVES_NUM").ToString(); this.txtGDH.Text = GVMiStock.GetFocusedRowCellValue("PROVIDER_ID").ToString(); t_sts.Text = GVMiStock.GetFocusedRowCellValue("STS").ToString(); barcode= GVMiStock.GetFocusedRowCellValue("BARCODE").ToString(); storid = GVMiStock.GetFocusedRowCellValue("STORAGE_ID").ToString(); if ( t_sts.Text=="1" ) { t_sts.Text = "占用"; } else { t_sts.Text = "正常"; } } private void getList() { List taskData = IBussFactory.Instance().GetTaskdataHand(); if (taskData != null) { bindingSource1.DataSource = taskData; } } public void Clear() { if (SystemCommon.ShowMessageBoxResult("确定选择库位:" + this.textBox1.Text.ToString() + "手动出库吗?") == DialogResult.OK) { string tasktype = string.Empty; if (textBox1.Text == "") { SystemCommon.ShowInfoMessageBox("输入库位不能为空"); return; } if (textBox1.Text.Length!=11) { SystemCommon.ShowInfoMessageBox("输入库位格式不对"); return; } if (this.comboBox1.Text.Trim() == "A1" || this.comboBox1.Text.Trim() == "A4") { SystemCommon.ShowInfoMessageBox("不能出零拣"); return; } else { tasktype = "3"; DataTable dt = IBussFactory.Instance().getDecid(this.comboBox1.Text.Trim()); string decidsts = dt.Rows[0]["STS"].ToString().Trim(); if (decidsts != "2") { SystemCommon.ShowInfoMessageBox("该库口非出库模式!"); return; } } IBussFactory.Instance().InsTMISTOCK(textBox1.Text); string orderstr = "SJD" + DateTime.Now.ToString("yyyyMMddHHmmssfff"); PickingWaveGoodsModel or_Model = new PickingWaveGoodsModel(); or_Model.PUTIN_ID = orderstr; or_Model.PICKINGID = orderstr; or_Model.GOOD_ID ="111111"; or_Model.LOC_ID = this.textBox1.Text; or_Model.WARE_DATE = Convert.ToDateTime(DateTime.Now.ToString()); or_Model.PICKING_NUM = 1; or_Model.BARCODE = "111111"; or_Model.CTL = "111111"; or_Model.status = "1"; or_Model.outStand = this.comboBox1.Text.Trim(); or_Model.typests = tasktype; or_Model.PROVIDER_ID = "111111"; or_Model.STORAGE_ID = "JXJW"; or_Model.GOODS_NUM_SJ = 1; string errText = ""; try { errText = IBussFactory.Instance().InsSDOrder(or_Model); if (errText.Length == 0) { SystemCommon.ShowInfoMessageBox("手动产生出库单成功!"); IBussFactory.Instance().UpdateLock(txtLocation.Text.Trim()); LogWriteText.WriteLog(DateTime.Now.ToString() + " 手动产生出库单成功,库位:" + or_Model.LOC_ID + " 物料编号:" + or_Model.GOOD_ID + " 工单ID:" + or_Model.PROVIDER_ID); } else { SystemCommon.ShowInfoMessageBox("错误!" + errText); } getList(); BindMiStockData(); } catch (Exception ex) { return; } } } private void ctrlButtons2_Click(object sender, EventArgs e) { if (SystemCommon.ShowMessageBoxResult("确定选择库位:" + this.txtLocation.Text.ToString() + "手动出库吗?") == DialogResult.OK) { if(comboBox1.Text.Trim().ToString()=="") { SystemCommon.ShowInfoMessageBox("终点不能为空"); return; } string tasktype = string.Empty; if (txtLocation.Text == "") { SystemCommon.ShowInfoMessageBox("库位不能为空"); return; } //if (txtLocation.Text.Substring(0,2) != "JW") //{ // SystemCommon.ShowInfoMessageBox("非立库库位"); // return; //} if (t_sts.Text.Trim()=="占用") { SystemCommon.ShowInfoMessageBox("不能出库,库存已经被占用"); return; } if (this.txtCKnum.Text == "") { SystemCommon.ShowInfoMessageBox("请输入出库数"); return; } if (Convert.ToDecimal(this.txtCKnum.Text.Trim()) > Convert.ToDecimal(this.txtCCNum.Text.Trim())) { SystemCommon.ShowInfoMessageBox("出库数不能大于库存数"); return; } //if (this.txtGoodsId.Text.Trim()=="00000") //{ // SystemCommon.ShowInfoMessageBox("不能手动出空托盘"); // return; //} //if (this.comboBox1.Text.Trim() == "A1" || this.comboBox1.Text.Trim() == "A4") //{ // if (SystemCommon.ShowMessageBoxResult("确定选择库位:" + this.txtLocation.Text.ToString() + "零拣出库吗?") == DialogResult.OK) // { // if (storid == "JXJWTH") // { // SystemCommon.ShowInfoMessageBox("退货存储不能生成零拣任务!"); // return; // } // if (ZjcheckB.Checked == true) // { // tasktype = "8"; // } // else // { // tasktype = "7"; // } // } // else // { // comboBox1.Text = "A2"; // return; // } //} //else //{ // tasktype = "3"; // DataTable dt = IBussFactory.Instance().getDecid(this.comboBox1.Text.Trim()); // string decidsts = dt.Rows[0]["STS"].ToString().Trim(); // if (decidsts != "2") // { // SystemCommon.ShowInfoMessageBox("该库口非出库模式!"); // return; // } //} if (IBussFactory.Instance().getPickData(this.txtLocation.Text)) { SystemCommon.ShowInfoMessageBox("该托盘已生成出库单!"); return; } if (IBussFactory.Instance().getPickDataCount()) { SystemCommon.ShowInfoMessageBox("出库任务不能多余10条!"); return; } //DataTable dt2 = IBussFactory.Instance().getYK(); //string locid = string.Empty; //string lockloc = string.Empty; //if (dt2.Rows.Count > 0) //{ // for(int i=0; i < dt2.Rows.Count; i++) // { // locid = dt2.Rows[i]["OUTSTAND"].ToString().Trim(); // lockloc += GetLock(locid); // } //} //if (lockloc.Contains(txtLocation.Text)) //{ // SystemCommon.ShowInfoMessageBox("该库位附近有移库!请稍后出库"); // return; //} string orderstr= DateTime.Now.ToString("yyyyMMddHHmmssfff"); PickingWaveGoodsModel or_Model = new PickingWaveGoodsModel(); or_Model.PUTIN_ID = orderstr; or_Model.PICKINGID = orderstr; or_Model.GOOD_ID = this.txtGoodsId.Text; or_Model.LOC_ID = this.txtLocation.Text; or_Model.WARE_DATE = Convert.ToDateTime(DateTime.Now.ToString()); or_Model.PICKING_NUM = Convert.ToDecimal(this.txtCKnum.Text.Trim()); or_Model.BARCODE = barcode; or_Model.CTL = this.txtCTL.Text; or_Model.status = "0"; or_Model.outStand = this.comboBox1.Text.Trim(); or_Model.typests = tasktype; or_Model.PROVIDER_ID = this.txtGDH.Text.Trim(); or_Model.OUT_ID = orderstr; if (storid == "LDC") { or_Model.STORAGE_ID = "LDC"; } else { or_Model.STORAGE_ID = "JXJW"; } or_Model.GOODS_NUM_SJ = Convert.ToDecimal(this.txtCKnum.Text.Trim()); string errText = ""; try { errText = IBussFactory.Instance().InsSDOrder(or_Model); if (errText.Length == 0) { SystemCommon.ShowInfoMessageBox("手动产生出库单成功!"); IBussFactory.Instance().UpdateLock(txtLocation.Text.Trim()); LogWriteText.WriteLog(DateTime.Now.ToString() + " 手动产生出库单成功,库位:" + or_Model.LOC_ID + " 物料编号:" + or_Model.GOOD_ID + " 工单ID:" + or_Model.PROVIDER_ID); } else { SystemCommon.ShowInfoMessageBox("错误!"+ errText); } getList(); BindMiStockData(); } catch (Exception ex) { SystemCommon.ShowInfoMessageBox("网络连接错误!"); return; } } } private void ctrlButtons1_Click(object sender, EventArgs e) { BindMiStockData(); getList(); } private void ctrlButtons3_Click(object sender, EventArgs e) { if (SystemCommon.ShowMessageBoxResult("确定预出库该:" + this.txtLocation.Text.ToString()+"物料?") == DialogResult.OK) { if (this.txtLocation.Text == "") { SystemCommon.ShowInfoMessageBox("请选择确定预出库的货物!"); return; } string Layer = txtLocation.Text.Substring(txtLocation.Text.Length-2,2); #region 寻找预出库移库库位 string loc = IBussFactory.Instance().getYckLoc(Layer); if (loc == string.Empty) { SystemCommon.ShowInfoMessageBox("该层预出库库位已满!"); return; } else { Yckcommit(loc); } #endregion } } private string GetLock(string locid) { string lockloc = string.Empty; string Xloc = locid.Substring(3, 2).ToString(); string Yloc = locid.Substring(6, 2).ToString(); string Zloc = locid.Substring(locid.Length - 1, 1); if (int.Parse(Xloc) > 0 && int.Parse(Xloc) < 4) { for(int j = 1; j < 4; j++) { lockloc += "JW-" + j.ToString().PadLeft(2, '0') + "-" + Yloc + "-" + Zloc.PadLeft(2, '0'); } } else if(int.Parse(Xloc) > 4 && int.Parse(Xloc) <11) { for (int j = 5; j < 11; j++) { lockloc += "JW-" + j.ToString().PadLeft(2, '0') + "-" + Yloc + "-" + Zloc.PadLeft(2, '0'); } } else if (int.Parse(Xloc) >11 && int.Parse(Xloc) < 18) { for (int j = 12; j < 18; j++) { lockloc += "JW-" + j.ToString().PadLeft(2, '0') + "-" + Yloc + "-" + Zloc.PadLeft(2, '0'); } } else if (int.Parse(Xloc) > 18 && int.Parse(Xloc) < 25) { for (int j = 19; j < 25; j++) { lockloc += "JW-" + j.ToString().PadLeft(2, '0') + "-" + Yloc + "-" + Zloc.PadLeft(2, '0'); } } else if (int.Parse(Xloc) > 25 && int.Parse(Xloc) < 29) { for (int j = 26; j < 29; j++) { lockloc += "JW-" + j.ToString().PadLeft(2, '0') + "-" + Yloc + "-" + Zloc.PadLeft(2, '0'); } } return lockloc; } private string PostJSON(string url, string strPost, ref string errText) { errText = string.Empty; string result = string.Empty; //生成文件流 byte[] buffer = Encoding.UTF8.GetBytes(strPost); //向流中写字符串 StreamWriter mywriter = null; //根据url创建请求对象 HttpWebRequest objrequest = (HttpWebRequest)WebRequest.Create(url); //设置发送方式 objrequest.Method = "POST"; objrequest.Timeout = 5000; //提交长度 objrequest.ContentLength = buffer.Length; //发送内容格式 objrequest.ContentType = "application/json"; try { mywriter = new StreamWriter(objrequest.GetRequestStream()); mywriter.Write(strPost); } catch (Exception ex) { errText = ex.Message; result = "发送JSON失败!"; } finally { mywriter.Close(); } //读取服务器返回信息c HttpWebResponse objresponse = (HttpWebResponse)objrequest.GetResponse(); using (StreamReader sr = new StreamReader(objresponse.GetResponseStream())) { result = sr.ReadToEnd(); sr.Close(); } return result; } public void Yckcommit(string locid) { if (t_sts.Text.Trim() == "占用") { SystemCommon.ShowInfoMessageBox("不能出库,库存已经被占用"); return; } if (IBussFactory.Instance().getPickData(this.txtLocation.Text)) { SystemCommon.ShowInfoMessageBox("该托盘已生成出库单!"); return; } string orderstr = "XJYCKD" + DateTime.Now.ToString("yyyyMMddHHmmssfff"); PickingWaveGoodsModel or_Model = new PickingWaveGoodsModel(); or_Model.PUTIN_ID = orderstr; or_Model.PICKINGID = orderstr; or_Model.GOOD_ID = this.txtGoodsId.Text; or_Model.LOC_ID = this.txtLocation.Text; or_Model.WARE_DATE = Convert.ToDateTime(DateTime.Now.ToString()); or_Model.PICKING_NUM = Convert.ToDecimal(this.txtCKnum.Text.Trim()); or_Model.CTL = this.txtCTL.Text; or_Model.status = "1"; or_Model.outStand = locid; or_Model.typests = "3"; or_Model.PROVIDER_ID = this.txtGDH.Text.Trim(); or_Model.STORAGE_ID = "JXJW"; or_Model.GOODS_NUM_SJ = Convert.ToDecimal(this.txtCKnum.Text.Trim()); string errText = ""; try { errText = IBussFactory.Instance().InsSDOrder(or_Model); if (errText.Length == 0) { SystemCommon.ShowInfoMessageBox("手动产生预出库单成功!"); IBussFactory.Instance().UpdateLock(txtLocation.Text.Trim()); //更新移库目的位置 IBussFactory.Instance().UpdateYkLoc(locid); LogWriteText.WriteLog(DateTime.Now.ToString() + " 手动产生预出库单成功,库位:" + or_Model.LOC_ID + " 物料编号:" + or_Model.GOOD_ID ); } else { SystemCommon.ShowInfoMessageBox("错误!" + errText); } getList(); BindMiStockData(); } catch (Exception ex) { SystemCommon.ShowInfoMessageBox("网络连接错误!"); return; } } private void ctrlButtons4_Click(object sender, EventArgs e) { if (SystemCommon.ShowMessageBoxResult("确定选择库位:" + this.txtLocation.Text.ToString() + "移库吗?") == DialogResult.OK) { if (txtLocation.Text == "") { SystemCommon.ShowInfoMessageBox("库位不能为空"); return; } if (t_sts.Text.Trim() == "占用") { SystemCommon.ShowInfoMessageBox("不能移库,库存已经被占用"); return; } if (IBussFactory.Instance().getPickData(this.txtLocation.Text)) { SystemCommon.ShowInfoMessageBox("该托盘已生成出库单!"); return; } if (textBox1.Text.Trim()== "") { SystemCommon.ShowInfoMessageBox("移库库位不能为空"); return; } if (IBussFactory.Instance().getLocS(textBox1.Text.Trim())) { SystemCommon.ShowInfoMessageBox("移库库位不存在或有货"); return; } try { string errText = ""; errText = IBussFactory.Instance().InsYK(txtLocation.Text.Trim(), textBox1.Text.Trim()); if (errText.Length == 0) { SystemCommon.ShowInfoMessageBox("手动产生移库单成功!"); } else { SystemCommon.ShowInfoMessageBox("错误!" + errText); } getList(); BindMiStockData(); } catch (Exception ex) { SystemCommon.ShowInfoMessageBox("网络连接错误!"); return; } } } //private void ZjcheckB_CheckedChanged(object sender, EventArgs e) //{ // if (comboBox1.Text.Trim()=="A2"||comboBox1.Text.Trim()=="A3") // { // if (ZjcheckB.Checked == true) // { // SystemCommon.ShowInfoMessageBox("追加模式只允许A1 A4库口!请选择正确出库站台"); // } // ZjcheckB.Checked = false; // } //} private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) { //if (comboBox1.Text == "A1" || comboBox1.Text == "A4") //{ // if (SystemCommon.ShowMessageBoxResult("确定生成零拣:" + this.txtLocation.Text.ToString() + "任务吗?") == DialogResult.OK) // { // } // else // { // comboBox1.Text = "A2"; // } //} } private void ctrlButtons5_Click(object sender, EventArgs e) { if (SystemCommon.ShowMessageBoxResult("确定选择库位:" + this.txtLocation.Text.ToString() + "盘点出库吗?") == DialogResult.OK) { string tasktype = string.Empty; if (txtLocation.Text == "") { SystemCommon.ShowInfoMessageBox("库位不能为空"); return; } if (this.comboBox1.Text.Trim() == "A2" || this.comboBox1.Text.Trim() == "A3") { SystemCommon.ShowInfoMessageBox("盘点任务只能出A1,A4"); return; } if (txtLocation.Text.Substring(0, 2) != "JW") { SystemCommon.ShowInfoMessageBox("非立库库位"); return; } if (t_sts.Text.Trim() == "占用") { SystemCommon.ShowInfoMessageBox("不能出库,库存已经被占用"); return; } if (this.txtCKnum.Text == "") { SystemCommon.ShowInfoMessageBox("请输入出库数"); return; } if (Convert.ToDecimal(this.txtCKnum.Text.Trim()) > Convert.ToDecimal(this.txtCCNum.Text.Trim())) { SystemCommon.ShowInfoMessageBox("出库数不能大于库存数"); return; } if (this.txtGoodsId.Text.Trim() == "00000") { SystemCommon.ShowInfoMessageBox("不能手动出空托盘"); return; } if (storid == "JXJWTH") { SystemCommon.ShowInfoMessageBox("退货存储不能生成盘点任务!"); return; } if (IBussFactory.Instance().getPickData(this.txtLocation.Text)) { SystemCommon.ShowInfoMessageBox("该托盘已生成出库单!"); return; } if (IBussFactory.Instance().getPickDataCount()) { SystemCommon.ShowInfoMessageBox("出库任务不能多余10条!"); return; } string orderstr = "SJD" + DateTime.Now.ToString("yyyyMMddHHmmssfff"); PickingWaveGoodsModel or_Model = new PickingWaveGoodsModel(); or_Model.PUTIN_ID = orderstr; or_Model.PICKINGID = orderstr; or_Model.GOOD_ID = this.txtGoodsId.Text; or_Model.LOC_ID = this.txtLocation.Text; or_Model.WARE_DATE = Convert.ToDateTime(DateTime.Now.ToString()); or_Model.PICKING_NUM = Convert.ToDecimal(this.txtCKnum.Text.Trim()); or_Model.BARCODE = barcode; or_Model.CTL = this.txtCTL.Text; or_Model.status = "1"; or_Model.outStand = this.comboBox1.Text.Trim(); or_Model.typests = "156"; or_Model.PROVIDER_ID = this.txtGDH.Text.Trim(); if (storid == "JXJWTH") { or_Model.STORAGE_ID = "JXJWTH"; } else { or_Model.STORAGE_ID = "JXJW"; } or_Model.GOODS_NUM_SJ = Convert.ToDecimal(this.txtCKnum.Text.Trim()); string errText = ""; try { errText = IBussFactory.Instance().InsSDOrder(or_Model); if (errText.Length == 0) { SystemCommon.ShowInfoMessageBox("手动产生盘点出库单成功!"); IBussFactory.Instance().UpdateLock(txtLocation.Text.Trim()); LogWriteText.WriteLog(DateTime.Now.ToString() + " 手动产生盘点出库单成功,库位:" + or_Model.LOC_ID + " 物料编号:" + or_Model.GOOD_ID + " 工单ID:" + or_Model.PROVIDER_ID); } else { SystemCommon.ShowInfoMessageBox("错误!" + errText); } getList(); BindMiStockData(); } catch (Exception ex) { SystemCommon.ShowInfoMessageBox("网络连接错误!"); return; } } } } }