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.PalletBoxGet
{
public class PallectGet
{
///
/// 获取物料条码信息生成条码
///
public FormICSCreatedArrivalNoticeModel CustGetMaterialOutBox(PalletMox m)
{
FormICSCreatedArrivalNoticeModel result = new FormICSCreatedArrivalNoticeModel();
using (SqlConnection conn = new SqlConnection(Appconfig.GetMESStr()))
{
conn.Open();
using (SqlTransaction trans = conn.BeginTransaction())
{
try
{
StringBuilder strHead = new StringBuilder();
strHead.AppendLine("***************接口传入参数记录****************:");
strHead.AppendLine("外箱条码:" + m.CartonNO);
strHead.AppendLine("栈板条码:" + m.PalletCode);
strHead.AppendLine("传入站点:" + m.WorkPoint);
strHead.AppendLine("***************接口传入参数记录****************:");
Appconfig.WriteLogFile(strHead.ToString(), "物料栈板信息接口日志");
StringBuilder resultlog = new StringBuilder();
string SqlCartonNO = @"select * from ICSPallet where PalletCode = '" + m.PalletCode + "' ";
DataTable flag1 = DBhlper.Query(SqlCartonNO, Appconfig.GetMESStr());
if (flag1.Rows.Count <= 0)
{
string SqlLotNO = @"select * from ICSITEMLot2Carton where CartonNO = '" + m.CartonNO + "' ";
DataTable flag2 = DBhlper.Query(SqlLotNO, Appconfig.GetMESStr());
if (flag2.Rows.Count > 0)
{
string sql = string.Format(@"update ICSITEMLot2Carton set PalletNO='{0}'
where WorkPoint = '{2}'and CartonNO='{1}'",
m.PalletCode, m.CartonNO, m.WorkPoint);
int dt = DBhlper.EXecute(sql, Appconfig.GetMESStr());
if (dt == 0)
{
throw new Exception("栈板条码信息添加失败,请查看日志");
}
}
else
{
throw new Exception("箱号不存在,信息添加失败");
}
string sql2 = string.Format(@"insert into ICSPallet (Serial,PalletCode,BatchCode,palletStatus,MUSER,MUSERName,MTIME,WorkPoint)
Values
(NEWID(),'{0}','批量','成品','{1}','{2}',GETDATE(),'{3}')"
, m.PalletCode, m.MUSER, m.MUSERName, m.WorkPoint);
int dt2 = DBhlper.EXecute(sql2, Appconfig.GetMESStr());
if (dt2 > 0)
{
result.Code = 0;
result.ResMsg = "物料栈板条码创建成功";
result.ResData = "{}";
result.IsCompress = false;
result.IsSuccess = true;
}
}
else
{
throw new Exception("栈板已经存在,信息添加失败");
}
}
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("外箱条码:" + m.CartonNO);
str.AppendLine("栈板条码:" + m.PalletCode);
str.AppendLine("传入站点:" + m.WorkPoint);
str.AppendLine("失败原因:" + ex.Message);
Appconfig.WriteLogFile(str.ToString(), "物料栈板信息接口日志");
}
}
conn.Close();
}
return result;
}
///
/// 返回值
///
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; }
}
}
}