BaoKai_202508-Wms-Jingwang..../WMS.FrmOut/AutoCK/FrmYckOrder.cs

480 lines
17 KiB
C#
Raw Normal View History

2025-08-24 09:35:55 +08:00
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 FrmYckOrder : FormBase
{
/// <summary>
/// 库存List
/// </summary>
List<MIStockModel> miStockList = new List<MIStockModel>();
public FrmYckOrder()
{
InitializeComponent();
}
string mesIP = string.Empty;
private void FrmSdOrders_Load(object sender, EventArgs e)
{
mesIP = "10.10.90.192:8080";
comboBox1.SelectedIndex = 0;
BindMiStockData();
}
public override void Del()
{
ctrlButtons3_Click(null, null);
}
/// <summary>
/// 绑定库存数据
/// </summary>
/// <param name="mistock"></param>
public void BindMiStockData()
{
new Thread(delegate ()
{
string errText = string.Empty;
try
{
this.Invoke(new MethodInvoker(delegate
{
miStockList = IBussFactory<BussMIStockSearch>.Instance().GetMiStockForLookUp("1");
if (miStockList != null)
{
bgsStock.DataSource = miStockList;
}
getList();
}));
}
catch (Exception)
{
SystemCommon.ShowInfoMessageBox("error");
}
}).Start();
}
public List<OrderDetailModel> or_det_List = new List<OrderDetailModel>();
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();
if ( t_sts.Text=="1" )
{
t_sts.Text = "占用";
}
else
{
t_sts.Text = "正常";
}
}
private void getList()
{
List<PickingWaveGoodsModel> taskData = IBussFactory<BussPickingWaveGoods>.Instance().GetTaskdataHand();
if (taskData != null)
{
bindingSource1.DataSource = taskData;
}
}
private void ctrlButtons2_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 (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;
}
DataTable dt = IBussFactory<BussPickingWaveGoods>.Instance().getDecid(this.comboBox1.Text.Trim());
string decidsts = dt.Rows[0]["STS"].ToString().Trim();
if (decidsts!="2")
{
SystemCommon.ShowInfoMessageBox("该库口非出库模式!");
return;
}
if (IBussFactory<BussPickingWaveGoods>.Instance().getPickData(this.txtLocation.Text))
{
SystemCommon.ShowInfoMessageBox("该托盘已生成出库单!");
return;
}
string remark = string.Empty;
DataTable dt2 = IBussFactory<BussPickingWaveGoods>.Instance().getRemark(this.txtLocation.Text.Trim());
if (dt2.Rows.Count > 0)
{
remark=dt2.Rows[0]["REMARK"].ToString().Trim();
}
DataTable dt3 = IBussFactory<BussPickingWaveGoods>.Instance().getyck(remark, this.txtLocation.Text.Trim().Substring(9,2));
try
{
if (dt3.Rows.Count > 0)
{
foreach (DataRow row in dt3.Rows)
{
string orderstr = "YKXJD" + DateTime.Now.ToString("yyyyMMddHHmmssfff");
PickingWaveGoodsModel or_Model = new PickingWaveGoodsModel();
or_Model.PUTIN_ID = orderstr;
or_Model.PICKINGID = orderstr;
or_Model.GOOD_ID = row["GOODS_ID"].ToString().Trim();
or_Model.LOC_ID = row["LOCATION_ID"].ToString().Trim();
or_Model.WARE_DATE = Convert.ToDateTime(DateTime.Now.ToString());
or_Model.PICKING_NUM = Convert.ToDecimal(row["SHELVES_NUM"].ToString().Trim());
or_Model.CTL = row["CTL"].ToString().Trim();
or_Model.status = "1";
or_Model.outStand = this.comboBox1.Text.Trim();
or_Model.typests = "3";
or_Model.PROVIDER_ID = row["PROVIDER_ID"].ToString().Trim();
or_Model.STORAGE_ID = "JXJW";
or_Model.GOODS_NUM_SJ = Convert.ToDecimal(row["SHELVES_NUM"].ToString().Trim());
string errText = "";
//try
//{
errText = IBussFactory<BussOrders>.Instance().InsSDOrder(or_Model);
// if (errText.Length == 0)
// {
// SystemCommon.ShowInfoMessageBox("手动产生出库单成功!");
// IBussFactory<BussOrders>.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); }
//}
//catch (Exception ex)
//{
// SystemCommon.ShowInfoMessageBox("网络连接错误!");
// return;
//}
}
}
}
catch
{
SystemCommon.ShowInfoMessageBox("网络连接错误!");
return;
}
SystemCommon.ShowInfoMessageBox("手动产生出库单成功!");
IBussFactory<BussOrders>.Instance().UpdateLock(txtLocation.Text.Trim());
LogWriteText.WriteLog(DateTime.Now.ToString() + " 手动产生出库单成功 ");
getList();
BindMiStockData();
}
}
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<BussPickingWaveGoods>.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<BussPickingWaveGoods>.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<BussOrders>.Instance().InsSDOrder(or_Model);
if (errText.Length == 0)
{
SystemCommon.ShowInfoMessageBox("手动产生预出库单成功!");
IBussFactory<BussOrders>.Instance().UpdateLock(txtLocation.Text.Trim());
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<BussPickingWaveGoods>.Instance().getPickData(this.txtLocation.Text))
{
SystemCommon.ShowInfoMessageBox("该托盘已生成出库单!");
return;
}
if (textBox1.Text.Trim()== "")
{
SystemCommon.ShowInfoMessageBox("移库库位不能为空");
return;
}
if (IBussFactory<BussPickingWaveGoods>.Instance().getLocS(textBox1.Text.Trim()))
{
SystemCommon.ShowInfoMessageBox("移库库位不存在或有货");
return;
}
try
{
string errText = "";
errText = IBussFactory<BussOrders>.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;
}
}
}
}
}