圣珀
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.
 
 
 

174 lines
8.9 KiB

using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ICS.WCF.Base;
using ICSSoft.Entity;
namespace ICS.MoLotGetOne
{
public class MoLotGet
{
/// <summary>
/// 获取物料条码信息生成条码
/// </summary>
public FormICSCreatedArrivalNoticeModel CustGetLotNoInfo(MoLot l)
{
FormICSCreatedArrivalNoticeModel result = new FormICSCreatedArrivalNoticeModel();
using (SqlConnection conn = new SqlConnection(Appconfig.GetMESStr()))
{
conn.Open();
using (SqlTransaction trans = conn.BeginTransaction())
{
try
{
string sql = "";
int flag = 0;
SqlCommand cmd = new SqlCommand();
cmd.Connection = conn;
cmd.Transaction = trans;
StringBuilder strHead = new StringBuilder();
strHead.AppendLine("***************接口传入参数记录****************:");
strHead.AppendLine("传入条码:" + l.LotNO);
strHead.AppendLine("传入物料:" + l.ItemCODE);
strHead.AppendLine("传入数量:" + l.LotQTY);
strHead.AppendLine("传入批号:" + l.VenderLotNO);
strHead.AppendLine("传入生产日期:" + l.PRODUCTDATE);
strHead.AppendLine("传入站点:" + l.WorkPoint);
strHead.AppendLine("传入项目号:" + l.ORDERNO);
foreach (LotDoc poinfo in l.LotNOList)
{
strHead.AppendLine("传入订单号:" + poinfo.TransNO);
strHead.AppendLine("传入订单行:" + poinfo.TransLine);
strHead.AppendLine("关联条码数量:" + poinfo.LinkQTY);
}
strHead.AppendLine("***************接口传入参数记录****************:");
Appconfig.WriteLogFile(strHead.ToString(), "获取生成条码接口日志");
string SqlLotNO = @"select * from ICSItemLot where LotNO = '" + l.LotNO + "' ";
DataTable flag2 = DBhlper.Query(SqlLotNO, Appconfig.GetMESStr());
if (flag2.Rows.Count <= 0)
{
string SqlCartonNO = @"select INVCODE from ICSINVENTORY where INVCODE = '" + l.ItemCODE + "' ";
DataTable flag1 = DBhlper.Query(SqlCartonNO, Appconfig.GetMESStr());
if (flag1.Rows.Count > 0)
{
sql = @"
INSERT INTO ICSITEMLot
( ID ,LotNO ,ItemCODE ,VENDORITEMCODE ,VENDORCODE ,
VenderLotNO ,PRODUCTDATE ,LOTQTY ,ACTIVE ,Exdate ,WorkPoint ,
MUSER ,MUSERName ,MTIME ,TYPE,ORDERNO)
SELECT NEWID(),'" + l.LotNO + "','" + l.ItemCODE + "','','','" + l.VenderLotNO + "','" + l.PRODUCTDATE + "','" +
l.LotQTY + "','Y','2999-12-31 00:00:00.000','" + l.WorkPoint + "','" +
l.MUSER + "','" + l.MUSERNAME + "',GETDATE(),'成品','"+l.ORDERNO+"' ";
cmd.CommandText = sql;
flag = cmd.ExecuteNonQuery();
StringBuilder resultlog = new StringBuilder();
if (flag <= 0)
{
result.Code = -1;
result.ResMsg = "生成条码失败,信息添加失败";
result.ResData = "{}";
result.IsCompress = false;
result.IsSuccess = false;
resultlog.AppendLine("生成物料条码失败");
resultlog.AppendLine("查询sql:" + sql);
Appconfig.WriteLogFile(resultlog.ToString(), "获取生成条码接口日志");
return result;
}
string sql1 = string.Empty;
foreach (LotDoc p in l.LotNOList)
{
sql1 += @"INSERT INTO ICSLot2Doc (ID,LotNO,DocType,TransNO,TransLine,LinkQty,MTIME,MUSER,MUSERNAME,WorkPoint)
select NEWID(),LotNO,'生产订单','" + p.TransNO + "','" + p.TransLine + "'," + p.LinkQTY + @"
,MTIME,MUSER,MUSERName,WorkPoint from ICSITEMLot where LotNO='" + l.LotNO + "'";
}
cmd.CommandText = sql1;
flag = cmd.ExecuteNonQuery();
if (flag <= 0)
{
result.Code = -1;
result.ResMsg = "生成条码失败,信息添加失败";
result.ResData = "{}";
result.IsCompress = false;
result.IsSuccess = false;
}
trans.Commit();
result.Code = 0;
result.ResMsg = "物料条码生成成功";
result.ResData = "{}";
result.IsCompress = false;
result.IsSuccess = true;
}
else
{
result.Code = -1;
result.ResMsg = "物料不存在";
result.ResData = "{}";
result.IsCompress = false;
result.IsSuccess = false;
return result;
}
}
else
{
result.Code = -1;
result.ResMsg = "条码已存在";
result.ResData = "{}";
result.IsCompress = false;
result.IsSuccess = false;
return result;
}
}
catch (Exception ex)
{
trans.Rollback();
result.Code = -1;
result.ResMsg = "生成条码失败,请查看日志";
result.ResData = "{}";
result.IsCompress = false;
result.IsSuccess = false;
StringBuilder str = new StringBuilder();
str.AppendLine("***************接口传入参数记录****************:");
str.AppendLine("传入条码:" + l.LotNO);
str.AppendLine("传入物料:" + l.ItemCODE);
str.AppendLine("传入数量:" + l.LotQTY);
str.AppendLine("传入批号:" + l.VenderLotNO);
str.AppendLine("传入生产日期:" + l.PRODUCTDATE);
str.AppendLine("传入站点:" + l.WorkPoint);
str.AppendLine("传入项目号:" + l.ORDERNO);
foreach (LotDoc poinfo in l.LotNOList)
{
str.AppendLine("传入订单号:" + poinfo.TransNO);
str.AppendLine("传入订单行:" + poinfo.TransLine);
str.AppendLine("关联条码数量:" + poinfo.LinkQTY);
}
str.AppendLine("失败原因:" + ex.Message);
Appconfig.WriteLogFile(str.ToString(), "获取生成条码接口日志");
}
}
conn.Close();
}
return result;
}
/// <summary>
/// 返回值
/// </summary>
public class FormICSCreatedArrivalNoticeModel
{
//0 :正常数据,-1:失败。
public int Code { get; set; }
public string ResMsg { get; set; }
public Object ResData { get; set; }
public bool IsCompress { get; set; }
public bool IsSuccess { get; set; }
}
}
}