纽威
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.
 
 
 
 
 

175 lines
7.7 KiB

using ICSSoft.Common;
using ICSSoft.Entity;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ICSSoft.DataProject
{
public class ICSLibrary
{
private static log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
private static string connString = System.Configuration.ConfigurationManager.AppSettings["ConnStr"];
private static string ERPDB = System.Configuration.ConfigurationManager.AppSettings["ERPDB"];
DataTable table = null;
SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString);
string sql = string.Empty;
VerificationMethod verification = new VerificationMethod();//验证公共方法
public object LibraryGet(ICSLibraryModel JsonData)
{
conn.Open();
SqlTransaction sqlTran = conn.BeginTransaction();
SqlCommand cmd = new SqlCommand();
cmd.Transaction = sqlTran;
cmd.Connection = conn;
string jsonInfo;
#region sql
try
{
bool isBool= verification.isStockZero(JsonData.LotNo, JsonData.WorkPoint);
if (isBool==true)
{
sql = @"select
f.ContainerCODE,
f.ContainerName,
d.InvCode,
d.InvName,
d.InvStd,
a.Quantity,
d.InvUnit,
d.AmountUnit,
i.WarehouseCode,
i.WarehouseName,
q.LocationCode,
q.LocationName,
c.ProjectCode,
c.BatchCode,
c.Version,
c.Brand,
y.TransCode,--来源单据
y.TransSequence,--来源行号
a.LotNo,
c.cFree1,
c.cFree2,
c.cFree3,
c.cFree4,
c.cFree5,
c.cFree6,
c.cFree7,
c.cFree8,
c.cFree9,
c.cFree10
from ICSWareHouseLotInfo a
left join ICSInventoryLot b on a.LotNo=b.LotNo
left join ICSExtension c on b.ExtensionID=c.id
left join ICSInventory d on b.InvCode=d.InvCode
left join ICSContainerLot e on e.LotNo=a.LotNo
left join ICSContainer f on f.ContainerID= e.ID
left join ICSLocation q on q.LocationCode=a.LocationCode
left join ICSWarehouse i on i.ID=q.WHID
left join ICSInventoryLotDetail y on y.LotNo=a.LotNo
where a.LotNo='{0}' and a.WorkPoint='{1}'";
sql = string.Format(sql, JsonData.LotNo, JsonData.WorkPoint);
table = DBHelper.SQlReturnData(sql, cmd);
if (table.Rows.Count > 0)
{
jsonInfo = JsonConvert.SerializeObject(table);
var Library = JsonConvert.DeserializeObject(jsonInfo);
return Library;
}
else
{
throw new Exception("暂无数据!");
}
}
return null;
}
catch (Exception ex)
{
cmd.Transaction.Rollback();
log.Error(ex.Message);
throw new Exception(ex.Message);
}
finally
{
if (conn.State == ConnectionState.Open)
{
conn.Close();
}
conn.Dispose();
}
#endregion
}
public object LibraryUpdate(ICSLibraryModel JsonData)
{
conn.Open();
SqlTransaction sqlTran = conn.BeginTransaction();
SqlCommand cmd = new SqlCommand();
cmd.Transaction = sqlTran;
cmd.Connection = conn;
//string jsonInfo;
string sqlLog = string.Empty;
///修改库存表的库位
sql = @"update ICSWareHouseLotInfo set WarehouseCode='{0}' ,LocationCode ='{1}' where LotNo='{2}' and WorkPoint='{3}'";
sql = string.Format(sql,JsonData.WarehouseCode,JsonData.LocationCode,JsonData.LotNo,JsonData.WorkPoint);
cmd.CommandText = sql;
int PurchaseList= cmd.ExecuteNonQuery();//返回数量
///添加日志
if (PurchaseList > 0)
{
sqlLog = @" INSERT INTO [dbo].[ICSWareHouseLotInfoLog]
([ID]
,[TransCode]
,[TransSequence]
,[LotNo]
,[InvCode]
,[FromWarehouseCode]
,[FromLocationCode]
,[ToWarehouseCode]
,[ToLocationCode]
,[Quantity]
,[Memo]
,[Lock]
,[TransType]
,[BusinessCode]
,[ERPID]
,[ERPDetailID]
,[ERPCode]
,[ERPSequence]
,[MUSER]
,[MUSERName]
,[MTIME]
,[WorkPoint]
,[EATTRIBUTE1])
(select newid(),'{0}','{1}','{2}',a.InvCode ,' ', ' ','{3}','{4}',a.Quantity,' ','0','7','14',' ',' ',' ',' ','{5}',e.F_RealName,'{6}','{7}',' '
from ICSWareHouseLotInfo a--主表
left join Sys_SRM_User e on e.F_Account='{5}' and e.F_Location='{7}'
where a.LotNo='{2}' and a. WorkPoint='{7}' )";
sqlLog = string.Format(sqlLog, JsonData.TransCode, JsonData.TransSequence, JsonData.LotNo, JsonData.WarehouseCode,JsonData.LocationCode, JsonData.User, DateTime.Now, JsonData.WorkPoint);
cmd.CommandText = sqlLog;
int Purchase = cmd.ExecuteNonQuery();//返回数量
if (Purchase>0)
{
cmd.Transaction.Commit();
}
else
{
cmd.Transaction.Rollback();
}
}
return null;
}
}
}