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.
172 lines
6.1 KiB
172 lines
6.1 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using ICSSoft.Frame.Data.Entity;
|
|
using ICSSoft.Base.Config.AppConfig;
|
|
using System.Data;
|
|
using System.Data.Sql;
|
|
using System.Data.Linq;
|
|
using ICSSoft.Base.Config.DBHelper;
|
|
using System.Data.SqlClient;
|
|
|
|
namespace ICSSoft.Frame.Data.DAL
|
|
{
|
|
public class ICSStockBarCodeDAL
|
|
{
|
|
/// <summary>
|
|
/// 生成箱号条形码
|
|
/// </summary>
|
|
/// <param name="Listguid"></param>
|
|
/// <param name="Appconstr"></param>
|
|
public static void CreatebarCode(List<ICSITEMLot> Listguid, string Appconstr)
|
|
{
|
|
FramDataContext db = new FramDataContext(Appconstr);
|
|
db.Connection.Open();
|
|
db.Transaction = db.Connection.BeginTransaction();
|
|
try
|
|
{
|
|
decimal sumQty = 0;
|
|
foreach (ICSITEMLot TBLIcsCartonNo in Listguid)
|
|
{
|
|
bool isNew = false;
|
|
var lines = db.ICSITEMLot.Where(a => a.LotNO == TBLIcsCartonNo.LotNO && a.WorkPoint == AppConfig.WorkPointCode).ToList();
|
|
if (lines.Count() > 0)
|
|
{
|
|
throw new Exception("条码出现重复");
|
|
}
|
|
isNew = true;
|
|
sumQty += TBLIcsCartonNo.LOTQTY;
|
|
var line = new ICSITEMLot();
|
|
line.ID = TBLIcsCartonNo.ID;
|
|
line.ItemCode = TBLIcsCartonNo.ItemCode;
|
|
line.ACTIVE = "Y";
|
|
line.LotNO = TBLIcsCartonNo.LotNO;
|
|
line.TransNO = TBLIcsCartonNo.TransNO;
|
|
line.TransLine = TBLIcsCartonNo.TransLine;
|
|
line.PRODUCTDATE = TBLIcsCartonNo.PRODUCTDATE;
|
|
line.Exdate = TBLIcsCartonNo.Exdate;
|
|
line.LOTQTY = TBLIcsCartonNo.LOTQTY;
|
|
line.EATTRIBUTE3 = TBLIcsCartonNo.LOTQTY;
|
|
line.EATTRIBUTE4 = 0;
|
|
line.MUSER = AppConfig.UserId;
|
|
line.MUSERName = AppConfig.UserName;
|
|
line.TYPE = TBLIcsCartonNo.TYPE;
|
|
line.MTIME = TBLIcsCartonNo.MTIME;
|
|
line.WorkPoint = AppConfig.WorkPointCode;
|
|
if (isNew) db.ICSITEMLot.InsertOnSubmit(line);
|
|
|
|
}
|
|
var purch = db.ICSPOArrive.SingleOrDefault(a => a.Free2 == Listguid[0].TransNO && a.Free3 == Listguid[0].TransLine.ToString());
|
|
if (purch != null)
|
|
{
|
|
purch.PackQty = purch.PackQty + sumQty;
|
|
}
|
|
|
|
db.SubmitChanges();
|
|
db.Transaction.Commit();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
db.Transaction.Rollback();
|
|
throw new Exception(ex.Message);
|
|
}
|
|
|
|
|
|
}
|
|
|
|
#region select
|
|
public static ICSEC select(String guid, String Appconstr)
|
|
{
|
|
FramDataContext db = new FramDataContext(Appconstr);
|
|
db.Connection.Open();
|
|
db.Transaction = db.Connection.BeginTransaction();
|
|
ICSEC entity = new ICSEC();
|
|
try
|
|
{
|
|
var line = db.ICSEC.SingleOrDefault(a => a.ID == guid);
|
|
return (ICSEC)line;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw new Exception(ex.Message);
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region delete
|
|
public static void delete(string lotStr, string connStr)
|
|
{
|
|
SqlConnection conn = new SqlConnection(connStr);
|
|
SqlCommand com = conn.CreateCommand();
|
|
SqlTransaction tran;
|
|
conn.Open();
|
|
tran = conn.BeginTransaction();
|
|
com.Transaction = tran;
|
|
try
|
|
{
|
|
string sql = @"IF EXISTS(SELECT * FROM dbo.ICSWareHouseLotInfo
|
|
WHERE LotNO IN (" + lotStr + @"))
|
|
BEGIN
|
|
RAISERROR('物料条码已经入库',16,0)
|
|
END";
|
|
|
|
com.CommandText = sql;
|
|
com.ExecuteNonQuery();
|
|
|
|
sql = @"UPDATE b SET b.PackQty = b.PackQty-a.qty
|
|
FROM (SELECT TransNO,TransLine,SUM(LOTQTY) AS qty FROM [dbo].[ICSITEMLot]
|
|
WHERE LotNO IN (" + lotStr + @") GROUP BY TransNO,TransLine) a
|
|
INNER JOIN [dbo].[ICSPOArrive] b ON a.TransNO = b.Free2 and a.TransLine = b.Free3
|
|
where 0 <= PackQty-a.qty";
|
|
com.CommandText = sql;
|
|
com.ExecuteNonQuery();
|
|
|
|
sql = @"DELETE [dbo].[ICSITEMLot] WHERE LotNO IN (" + lotStr + ")";
|
|
com.CommandText = sql;
|
|
com.ExecuteNonQuery();
|
|
|
|
com.Transaction.Commit();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
com.Transaction.Rollback();
|
|
throw ex;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region delete
|
|
public static DataTable FindDataByID(string ID,string Code, string connStr)
|
|
{
|
|
try
|
|
{
|
|
string sql = @" SELECT iQuantity-PackQty AS sumQty,PackQty,
|
|
(SELECT COUNT(a.LotNO) FROM dbo.ICSITEMLot a
|
|
INNER JOIN dbo.ICSPOArrive b ON a.TransNO = b.Free2 AND a.TransLine = b.Free3
|
|
WHERE b.ERPAutoid = '{0}' GROUP BY a.TransNO,a.TransLine) AS cont,
|
|
( SELECT CONVERT(INT,MAX(RIGHT(LotNO,5))) AS maxLot FROM dbo.ICSITEMLot
|
|
WHERE LotNO LIKE ('{1}'+'%') AND TYPE = '原材料') AS maxLot,
|
|
isnull(b.INVCARTONQTY,0) as INVCARTONQTY,a.Free2,a.Free3,a.cInvCode,a.cCode,a.Free1 FROM dbo.ICSPOArrive a
|
|
INNER JOIN dbo.ICSINVENTORY b ON a.cInvCode = b.INVCODE WHERE ERPAutoid = '{0}'";
|
|
sql = string.Format(sql, ID,Code);
|
|
return DBHelper.ExecuteDataset(connStr,CommandType.Text,sql).Tables[0];
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
private static DataTable SQlReturnData(SqlCommand cmd)
|
|
{
|
|
DataTable dt = new DataTable();
|
|
SqlDataAdapter dr = new System.Data.SqlClient.SqlDataAdapter();
|
|
dr.SelectCommand = cmd;
|
|
dr.Fill(dt);
|
|
return dt;
|
|
}
|
|
|
|
}
|
|
}
|