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.

566 lines
24 KiB

1 year ago
using CK.SCP.Models;
using CK.SCP.Models.ScpEntity;
using CK.SCP.Utils;
using System;
using System.Collections.Generic;
using System.Data.Entity.Migrations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CK.SCP.Controller
{
public class SCP_QUALITY_CONTROLLER
{
public static void Get_TB_QUALITY_List(V_TB_QUALITY p_entity, Action<ResultObject<IQueryable<V_TB_QUALITY>>> p_action)
{
ResultObject<IQueryable<V_TB_QUALITY>> _ret = new ResultObject<IQueryable<V_TB_QUALITY>>();
try
{
using (ScpEntities db = EntitiesFactory.CreateScpInstance())
{
IQueryable<V_TB_QUALITY> q = db.V_TB_QUALITY;
if (p_entity.UID != 0)
{
q = q.Where(p => p.UID == p_entity.UID);
}
if (!string.IsNullOrEmpty(p_entity.Type))
{
q = q.Where(p => p.Type.Contains(p_entity.Type));
}
if (!string.IsNullOrEmpty(p_entity.Barcode))
{
q = q.Where(p => p.Barcode == p_entity.Barcode);
}
if (!string.IsNullOrEmpty(p_entity.Loccode))
{
q = q.Where(p => p.Loccode.Contains(p_entity.Loccode));
}
if (!string.IsNullOrEmpty(p_entity.Pobillnum))
{
q = q.Where(p => p.Pobillnum == p_entity.Pobillnum);
}
if (p_entity.Poline != 0)
{
q = q.Where(p => p.Poline == p_entity.Poline);
}
if (!string.IsNullOrEmpty(p_entity.Inspecttype))
{
q = q.Where(p => p.Inspecttype.Contains(p_entity.Inspecttype));
}
if (!string.IsNullOrEmpty(p_entity.Partcode))
{
q = q.Where(p => p.Partcode == p_entity.Partcode);
}
if (!string.IsNullOrEmpty(p_entity.Batch))
{
q = q.Where(p => p.Batch.Contains(p_entity.Batch));
}
if (p_entity.Inspqty != null)
{
q = q.Where(p => p.Inspqty == p_entity.Inspqty);
}
if (p_entity.Passqty != null)
{
q = q.Where(p => p.Passqty == p_entity.Passqty);
}
if (p_entity.Failqty != null)
{
q = q.Where(p => p.Failqty == p_entity.Failqty);
}
if (p_entity.EndTime != null)
{
q = q.Where(p => p_entity.EndTime >= p.Billtime);
}
if (p_entity.BeginTime != null)
{
q = q.Where(p => p_entity.BeginTime <= p.Billtime);
}
if (!string.IsNullOrEmpty(p_entity.Vendid))
{
q = q.Where(p => p.Vendid.Contains(p_entity.Vendid));
}
if (!string.IsNullOrEmpty(p_entity.Vendbatch))
{
q = q.Where(p => p.Vendbatch.Contains(p_entity.Vendbatch));
}
if (!string.IsNullOrEmpty(p_entity.Domain))
{
q = q.Where(p => p.Domain.Contains(p_entity.Domain));
}
if (!string.IsNullOrEmpty(p_entity.By1))
{
q = q.Where(p => p.By1.Contains(p_entity.By1));
}
if (!string.IsNullOrEmpty(p_entity.By2))
{
q = q.Where(p => p.By2.Contains(p_entity.By2));
}
if (!string.IsNullOrEmpty(p_entity.QualityNo))
{
q = q.Where(p => p.QualityNo.Contains(p_entity.QualityNo));
}
if (!string.IsNullOrEmpty(p_entity.ProjectId))
{
q = q.Where(p => p.ProjectId.Contains(p_entity.ProjectId));
}
if (p_entity.UserInAddress != null && p_entity.UserInAddress.Count > 0)
{
q = q.Where(p => p_entity.UserInAddress.Contains(p.Site));
}
if (p_entity.UserInVendIds != null && p_entity.UserInVendIds.Count > 0)
{
q = q.Where(p => p_entity.UserInVendIds.Contains(p.Vendid));
}
_ret.State = ReturnStatus.Succeed;
_ret.Result = q;
p_action(_ret);
}
}
catch (Exception e)
{
_ret.State = ReturnStatus.Failed;
_ret.ErrorList.Add(e);
LogHelper.Writlog(LogHelper.LogType.Error, typeof(TB_QUALITY), "Get_TB_QUALITY_List", e.Message);
throw e;
}
}
public static void Get_TB_RETURN_List(V_TB_RETURN p_entity, Action<ResultObject<IQueryable<V_TB_RETURN>>> p_action)
{
ResultObject<IQueryable<V_TB_RETURN>> _ret = new ResultObject<IQueryable<V_TB_RETURN>>();
try
{
using (ScpEntities db = EntitiesFactory.CreateScpInstance())
{
IQueryable<V_TB_RETURN> q = db.V_TB_RETURN;
if (p_entity.UID != 0)
{
q = q.Where(p => p.UID == p_entity.UID);
}
if (!string.IsNullOrEmpty(p_entity.Type))
{
q = q.Where(p => p.Type.Contains(p_entity.Type));
}
if (!string.IsNullOrEmpty(p_entity.Barcode))
{
q = q.Where(p => p.Barcode == p_entity.Barcode);
}
if (!string.IsNullOrEmpty(p_entity.Loccode))
{
q = q.Where(p => p.Loccode.Contains(p_entity.Loccode));
}
if (!string.IsNullOrEmpty(p_entity.Pobillnum))
{
q = q.Where(p => p.Pobillnum == p_entity.Pobillnum);
}
if (p_entity.Poline != 0)
{
q = q.Where(p => p.Poline == p_entity.Poline);
}
if (!string.IsNullOrEmpty(p_entity.Inspecttype))
{
q = q.Where(p => p.Inspecttype.Contains(p_entity.Inspecttype));
}
if (!string.IsNullOrEmpty(p_entity.Partcode))
{
q = q.Where(p => p.Partcode == p_entity.Partcode);
}
if (!string.IsNullOrEmpty(p_entity.Batch))
{
q = q.Where(p => p.Batch.Contains(p_entity.Batch));
}
if (p_entity.Inspqty != null)
{
q = q.Where(p => p.Inspqty == p_entity.Inspqty);
}
if (p_entity.Passqty != null)
{
q = q.Where(p => p.Passqty == p_entity.Passqty);
}
if (p_entity.Failqty != null)
{
q = q.Where(p => p.Failqty == p_entity.Failqty);
}
if (p_entity.EndTime != null)
{
q = q.Where(p => p.EndTime > p.Billtime);
}
if (p_entity.BeginTime != null)
{
q = q.Where(p => p.BeginTime < p.Billtime);
}
if (!string.IsNullOrEmpty(p_entity.Vendid))
{
q = q.Where(p => p.Vendid.Contains(p_entity.Vendid));
}
if (!string.IsNullOrEmpty(p_entity.Vendbatch))
{
q = q.Where(p => p.Vendbatch.Contains(p_entity.Vendbatch));
}
if (!string.IsNullOrEmpty(p_entity.Domain))
{
q = q.Where(p => p.Domain.Contains(p_entity.Domain));
}
if (!string.IsNullOrEmpty(p_entity.By1))
{
q = q.Where(p => p.By1.Contains(p_entity.By1));
}
if (!string.IsNullOrEmpty(p_entity.By2))
{
q = q.Where(p => p.By2.Contains(p_entity.By2));
}
if (!string.IsNullOrEmpty(p_entity.QualityNo))
{
q = q.Where(p => p.QualityNo.Contains(p_entity.QualityNo));
}
if (p_entity.UserInAddress != null && p_entity.UserInAddress.Count > 0)
{
q = q.Where(p => p_entity.UserInAddress.Contains(p.Site));
}
if (p_entity.UserInVendIds != null && p_entity.UserInVendIds.Count > 0)
{
q = q.Where(p => p_entity.UserInVendIds.Contains(p.Vendid));
}
_ret.State = ReturnStatus.Succeed;
_ret.Result = q;
p_action(_ret);
}
}
catch (Exception e)
{
_ret.State = ReturnStatus.Failed;
_ret.ErrorList.Add(e);
LogHelper.Writlog(LogHelper.LogType.Error, typeof(TB_QUALITY), "Get_TB_RETURN_List", e.Message);
throw e;
}
}
public static void Get_TB_ASN_QUALITY_List(V_TB_ASN p_entity, Action<ResultObject<IQueryable<V_TB_ASN>>> p_action)
{
ResultObject<IQueryable<V_TB_ASN>> _ret = new ResultObject<IQueryable<V_TB_ASN>>();
try
{
using (ScpEntities db = EntitiesFactory.CreateScpInstance())
{
StringBuilder _buffer = new StringBuilder();
_buffer.Append("select * from V_TB_ASN WHERE AsnBillNum in (");
_buffer.Append("SELECT DISTINCT b.BillNum FROM dbo.TB_QUALITY AS a INNER JOIN");
_buffer.Append(" dbo.TS_BARCODE AS b ON a.Barcode = ISNULL(b.PartCode, N'') + '.' + ISNULL(b.Batch, N'') AND a.Vendid = b.VendId)");
string _sql = _buffer.ToString();
var q=db.Database.SqlQuery<V_TB_ASN>(_sql).AsQueryable();
if (!string.IsNullOrEmpty(p_entity.AsnBillNum))
{
q = q.Where(p => p.AsnBillNum.Contains(p_entity.AsnBillNum));
}
if (!string.IsNullOrEmpty(p_entity.AskBillNum))
{
q = q.Where(p => p.AskBillNum.Contains(p_entity.AskBillNum));
}
if (!string.IsNullOrEmpty(p_entity.PoBillNum))
{
q = q.Where(p => p.PoBillNum.Contains(p_entity.PoBillNum));
}
if (!string.IsNullOrEmpty(p_entity.VendId))
{
q = q.Where(p => p.VendId.Contains(p_entity.VendId));
}
if (p_entity.State != null)
{
q = q.Where(p => p.State == p_entity.State);
}
if (!string.IsNullOrEmpty(p_entity.ShipUser))
{
q = q.Where(p => p.ShipUser.Contains(p_entity.ShipUser));
}
if (!string.IsNullOrEmpty(p_entity.ReceiveUser))
{
q = q.Where(p => p.ReceiveUser.Contains(p_entity.ReceiveUser));
}
if (!string.IsNullOrEmpty(p_entity.ErpBillNum))
{
q = q.Where(p => p.ErpBillNum.Contains(p_entity.ErpBillNum));
}
if (p_entity.ModType != null)
{
q = q.Where(p => p.ModType == p_entity.ModType);
}
//if (!string.IsNullOrEmpty(p_entity.Contacter))
//{
// q = q.Where(p => p.Contacter.Contains(p_entity.Contacter));
//}
if (!string.IsNullOrEmpty(p_entity.Buyer))
{
q = q.Where(p => p.Buyer.Contains(p_entity.Buyer));
}
if (!string.IsNullOrEmpty(p_entity.VendName))
{
q = q.Where(p => p.VendName.Contains(p_entity.VendName));
}
if (!string.IsNullOrEmpty(p_entity.State_DESC))
{
q = q.Where(p => p.State_DESC.Contains(p_entity.State_DESC));
}
if (!string.IsNullOrEmpty(p_entity.ModType_DESC))
{
q = q.Where(p => p.ModType_DESC.Contains(p_entity.ModType_DESC));
}
if (!string.IsNullOrEmpty(p_entity.CreateUser))
{
q = q.Where(p => p.CreateUser.Contains(p_entity.CreateUser));
}
if (!string.IsNullOrEmpty(p_entity.UpdateUser))
{
q = q.Where(p => p.UpdateUser.Contains(p_entity.UpdateUser));
}
if (!string.IsNullOrEmpty(p_entity.UpdateInfo))
{
q = q.Where(p => p.UpdateInfo.Contains(p_entity.UpdateInfo));
}
q = q.Where(p => p.IsDeleted == p_entity.IsDeleted);
if (p_entity.UserInAddress != null && p_entity.UserInAddress.Count > 0)
{
q = q.Where(p => p_entity.UserInAddress.Contains(p.Site));
}
if (p_entity.UserInVendIds != null && p_entity.UserInVendIds.Count > 0)
{
q = q.Where(p => p_entity.UserInVendIds.Contains(p.VendId));
}
_ret.State = ReturnStatus.Succeed;
_ret.Result = q;
p_action(_ret);
}
}
catch (Exception e)
{
_ret.State = ReturnStatus.Failed;
_ret.ErrorList.Add(e);
LogHelper.Writlog(LogHelper.LogType.Error, typeof(TB_QUALITY), "Get_TB_QUALITY_List", e.Message);
throw e;
}
}
public static ResultObject<bool> Save_ASN_TO_QUALITY(List<V_TB_ASN_DETAIL> p_asnList,string p_user)
{
ResultObject<bool> _ret = new ResultObject<bool>();
try
{
using (ScpEntities db = EntitiesFactory.CreateScpInstance())
{
foreach (var itm in p_asnList)
{
var _entity = db.V_TB_ASN_DETAIL.Where(p => p.UID == itm.UID).FirstOrDefault();
var _asn=db.V_TB_ASN.Where(p => p.AsnBillNum == _entity.AsnBillNum).FirstOrDefault();
if (_entity != null)
{
TB_QUALITY _quality = new TB_QUALITY();
_quality.QualityNo = SCP_BILLCODE_CONTROLLER.MakeQualityCode();
_quality.Failqty = itm.FailQty;
_quality.Pobillnum = itm.PoBillNum;
_quality.Billtime = DateTime.Parse(DateTime.Now.ToShortDateString());
_quality.Poline = itm.PoLine;
_quality.By1 = itm.AsnBillNum;
_quality.CreateTime = DateTime.Parse(DateTime.Now.ToShortDateString());
_quality.CreateUser = p_user;
_quality.Domain = _entity.Site;
_quality.Vendid = _entity.VendId;
_quality.Partcode = _entity.PartCode;
_quality.Batch = _entity.Batch;
_quality.Barcode = _entity.PartCode + "." + _entity.Batch;
_quality.Failreason = itm.FailReason;
_quality.Site = _asn.Site;
db.TB_QUALITY.AddOrUpdate(_quality);
}
}
if (db.SaveChanges() != -1)
{
_ret.State = ReturnStatus.Succeed;
_ret.Result = true;
}
else
{
_ret.State = ReturnStatus.Failed;
_ret.Result = false;
}
}
}
catch (Exception e)
{
_ret.State = ReturnStatus.Failed;
LogHelper.Writlog(LogHelper.LogType.Error, typeof(TB_QUALITY), "Save_ASN_TO_QUALITY", e.Message);
_ret.Result = false;
_ret.ErrorList.Add(e);
throw e;
}
return _ret;
}
public static ResultObject<bool> Save_ASN_TO_RETURN(List<V_TB_ASN_DETAIL> p_asnList, string p_user)
{
ResultObject<bool> _ret = new ResultObject<bool>();
try
{
using (ScpEntities db = EntitiesFactory.CreateScpInstance())
{
foreach (var itm in p_asnList)
{
var _entity = db.V_TB_ASN_DETAIL.Where(p => p.UID == itm.UID).FirstOrDefault();
var _asn = db.V_TB_ASN.Where(p => p.AsnBillNum == _entity.AsnBillNum).FirstOrDefault();
if (_entity != null)
{
TB_RETURN _quality = new TB_RETURN();
_quality.QualityNo = SCP_BILLCODE_CONTROLLER.MakeQualityCode();
_quality.Failqty = itm.FailQty;
_quality.Pobillnum = itm.PoBillNum;
_quality.Billtime = DateTime.Parse(DateTime.Now.ToShortDateString());
_quality.Poline = itm.PoLine;
_quality.AsnBillNum = itm.AsnBillNum;
_quality.RejectBillNum = itm.RejectBillNum;
_quality.CreateTime = itm.CreateTime;
_quality.CreateUser = p_user;
_quality.Domain = _entity.Site;
_quality.Vendid = _entity.VendId;
_quality.Partcode = _entity.PartCode;
_quality.Batch = _entity.Batch;
_quality.Barcode = _entity.PartCode + "." + _entity.Batch;
_quality.Failreason = itm.FailReason;
_quality.Site = _asn.Site;
db.TB_RETURN.AddOrUpdate(_quality);
}
}
if (db.SaveChanges() != -1)
{
_ret.State = ReturnStatus.Succeed;
_ret.Result = true;
}
else
{
_ret.State = ReturnStatus.Failed;
_ret.Result = false;
}
}
}
catch (Exception e)
{
_ret.State = ReturnStatus.Failed;
LogHelper.Writlog(LogHelper.LogType.Error, typeof(TB_RETURN), "Save_ASN_TO_QUALITY", e.Message);
_ret.Result = false;
_ret.ErrorList.Add(e);
throw e;
}
return _ret;
}
public ResultObject<bool> Save_TB_QUALITY(List<TB_QUALITY> p_entitys)
{
ResultObject<bool> _ret = new ResultObject<bool>();
try
{
using (ScpEntities db = EntitiesFactory.CreateScpInstance())
{
foreach (var itm in p_entitys)
{
db.TB_QUALITY.AddOrUpdate(itm);
}
if (db.SaveChanges() != -1)
{
_ret.State = ReturnStatus.Succeed;
_ret.Result = true;
}
else
{
_ret.State = ReturnStatus.Failed;
_ret.Result = false;
}
}
}
catch (Exception e)
{
_ret.State = ReturnStatus.Failed;
LogHelper.Writlog(LogHelper.LogType.Error, typeof(TB_QUALITY), "Save_TB_QUALITY", e.Message);
_ret.Result = false;
_ret.ErrorList.Add(e);
throw e;
}
return _ret;
}
public static ResultObject<bool> Del_TB_QUALITY(List<TB_QUALITY> p_entitys)
{
ResultObject<bool> _ret = new ResultObject<bool>();
try
{
using (ScpEntities db = EntitiesFactory.CreateScpInstance())
{
var _ids= p_entitys.Select(q => q.UID).ToList();
var query=db.TB_QUALITY.Where(p => _ids.Contains(p.UID));
var _ls=query.ToList();
db.TB_QUALITY.RemoveRange(_ls);
if (db.SaveChanges() != -1)
{
_ret.State = ReturnStatus.Succeed;
_ret.Result = true;
}
else
{
_ret.State = ReturnStatus.Failed;
_ret.Result = false;
}
}
}
catch (Exception e)
{
_ret.State = ReturnStatus.Failed;
_ret.Result = false;
_ret.ErrorList.Add(e);
LogHelper.Writlog(LogHelper.LogType.Error, typeof(TB_QUALITY), "Del_TB_QUALITY", e.Message); throw e;
}
return _ret;
}
public static ResultObject<bool> Del_TB_RETURN(List<TB_RETURN> p_entitys)
{
ResultObject<bool> _ret = new ResultObject<bool>();
try
{
using (ScpEntities db = EntitiesFactory.CreateScpInstance())
{
var _ids = p_entitys.Select(q => q.UID).ToList();
var query = db.TB_RETURN.Where(p => _ids.Contains(p.UID));
var _ls = query.ToList();
db.TB_RETURN.RemoveRange(_ls);
if (db.SaveChanges() != -1)
{
_ret.State = ReturnStatus.Succeed;
_ret.Result = true;
}
else
{
_ret.State = ReturnStatus.Failed;
_ret.Result = false;
}
}
}
catch (Exception e)
{
_ret.State = ReturnStatus.Failed;
_ret.Result = false;
_ret.ErrorList.Add(e);
LogHelper.Writlog(LogHelper.LogType.Error, typeof(TB_QUALITY), "Del_TB_QUALITY", e.Message); throw e;
}
return _ret;
}
}
}