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.
 
 
 
 
 

1198 lines
53 KiB

using CK.SCP.Models;
using CK.SCP.Models.Enums;
using CK.SCP.Models.ScpEntity;
using CK.SCP.Models.WmsEntity;
using CK.SCP.Utils;
using System;
using System.Collections.Generic;
using System.Data.Entity.Migrations;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
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 static ResultObject<bool> Save_TB_QUALITY(List<long> p_list, QUAL_STATE p_state )
{
ResultObject<bool> _ret = new ResultObject<bool>();
try
{
using (ScpEntities db = EntitiesFactory.CreateScpInstance())
{
var _entityList=db.TB_QUALITY.Where(p=>p_list.Contains(p.UID)).ToList();
foreach (var itm in _entityList)
{
itm.state = ((int)p_state).ToString();
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;
}
public static void Get_TM_HYANTOLIN_REVIEW_List(V_TM_HYANTOLIN_REVIEW p_entity, Action<ResultObject<IQueryable<V_TM_HYANTOLIN_REVIEW>>> p_action)
{
ResultObject<IQueryable<V_TM_HYANTOLIN_REVIEW>> _ret = new ResultObject<IQueryable<V_TM_HYANTOLIN_REVIEW>>();
try
{
using (var db = EntitiesFactory.CreateScpInstance())
{
IQueryable<V_TM_HYANTOLIN_REVIEW> q = db.V_TM_HYANTOLIN_REVIEW;
if (p_entity.UID != 0)
{
q = q.Where(p => p.UID == p_entity.UID);
}
if (!string.IsNullOrEmpty(p_entity.ReviewBillNum))
{
q = q.Where(p => p.ReviewBillNum == p_entity.ReviewBillNum);
}
if (!string.IsNullOrEmpty(p_entity.RelationReviewNo))
{
q = q.Where(p => p.RelationReviewNo == p_entity.RelationReviewNo);
}
if (!string.IsNullOrEmpty(p_entity.BarCode))
{
q = q.Where(p => p.BarCode.Contains(p_entity.BarCode));
}
if (!string.IsNullOrEmpty(p_entity.PartCode))
{
q = q.Where(p => p.PartCode.Contains(p_entity.PartCode));
}
if (!string.IsNullOrEmpty(p_entity.Batch))
{
q = q.Where(p => p.Batch.Contains(p_entity.Batch));
}
if (!string.IsNullOrEmpty(p_entity.ProjectId))
{
q = q.Where(p => p.ProjectId.Contains(p_entity.ProjectId));
}
if (!string.IsNullOrEmpty(p_entity.BadCouse))
{
q = q.Where(p => p.BadCouse.Contains(p_entity.BadCouse));
}
if (!string.IsNullOrEmpty(p_entity.ReviewResult))
{
q = q.Where(p => p.ReviewResult.Contains(p_entity.ReviewResult));
}
if (!string.IsNullOrEmpty(p_entity.UltimateDepart))
{
q = q.Where(p => p.UltimateDepart.Contains(p_entity.UltimateDepart));
}
if (!string.IsNullOrEmpty(p_entity.UltimateName))
{
q = q.Where(p => p.UltimateName.Contains(p_entity.UltimateName));
}
if (!string.IsNullOrEmpty(p_entity.OperName))
{
q = q.Where(p => p.OperName.Contains(p_entity.OperName));
}
if (p_entity.BeginTime != null)
{
q = q.Where(p => p_entity.BeginTime.Value <= p.ReviewTime);
}
if (p_entity.EndTime != null)
{
q = q.Where(p => p_entity.EndTime.Value >= p.ReviewTime);
}
//if (p_entity.State != 3)
//{
// q = q.Where(p => p.State == p_entity.State);
//}
if (p_entity.UserInVendIds != null && p_entity.UserInVendIds.Count > 0)
{
q = q.Where(p => p_entity.UserInVendIds.Contains(p.VendId));
}
if (p_entity.UserInAddress != null && p_entity.UserInAddress.Count > 0)
{
q = q.Where(p => p_entity.UserInAddress.Contains(p.Domain));
}
if (p_entity.BillStateList != null && p_entity.BillStateList.Count > 0)
{
q = q.Where(p => p_entity.BillStateList.Contains(p.State.Value));
}
_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(TM_HYANTOLIN_REVIEW), "Get_TM_HYANTOLIN_REVIEW_List", e.Message);
throw e;
}
}
public static void Get_TM_HYANTOLIN_REVIEW_List(TM_HYANTOLIN_REVIEW p_entity, Action<ResultObject<IQueryable<TM_HYANTOLIN_REVIEW>>> p_action)
{
ResultObject<IQueryable<TM_HYANTOLIN_REVIEW>> _ret = new ResultObject<IQueryable<TM_HYANTOLIN_REVIEW>>();
try
{
using (var db = EntitiesFactory.CreateScpInstance())
{
IQueryable<TM_HYANTOLIN_REVIEW> q = db.TM_HYANTOLIN_REVIEW;
if (p_entity.UID != 0)
{
q = q.Where(p => p.UID == p_entity.UID);
}
if (!string.IsNullOrEmpty(p_entity.ReviewBillNum))
{
q = q.Where(p => p.ReviewBillNum==p_entity.ReviewBillNum);
}
if (!string.IsNullOrEmpty(p_entity.RelationReviewNo))
{
q = q.Where(p => p.RelationReviewNo==p_entity.RelationReviewNo);
}
if (!string.IsNullOrEmpty(p_entity.BarCode))
{
q = q.Where(p => p.BarCode.Contains(p_entity.BarCode));
}
if (!string.IsNullOrEmpty(p_entity.PartCode))
{
q = q.Where(p => p.PartCode.Contains(p_entity.PartCode));
}
if (!string.IsNullOrEmpty(p_entity.Batch))
{
q = q.Where(p => p.Batch.Contains(p_entity.Batch));
}
if (!string.IsNullOrEmpty(p_entity.ProjectId))
{
q = q.Where(p => p.ProjectId.Contains(p_entity.ProjectId));
}
if (p_entity.Qty != 0)
{
q = q.Where(p => p.Qty == p_entity.Qty);
}
if (!string.IsNullOrEmpty(p_entity.BadCouse))
{
q = q.Where(p => p.BadCouse.Contains(p_entity.BadCouse));
}
if (!string.IsNullOrEmpty(p_entity.ReviewResult))
{
q = q.Where(p => p.ReviewResult.Contains(p_entity.ReviewResult));
}
if (!string.IsNullOrEmpty(p_entity.UltimateDepart))
{
q = q.Where(p => p.UltimateDepart.Contains(p_entity.UltimateDepart));
}
if (!string.IsNullOrEmpty(p_entity.UltimateName))
{
q = q.Where(p => p.UltimateName.Contains(p_entity.UltimateName));
}
if (p_entity.ClaimAmount != 0)
{
q = q.Where(p => p.ClaimAmount == p_entity.ClaimAmount);
}
if (!string.IsNullOrEmpty(p_entity.OperName))
{
q = q.Where(p => p.OperName.Contains(p_entity.OperName));
}
if (p_entity.BeginTime!=null)
{
q = q.Where(p => p_entity.BeginTime.Value<=p.ReviewTime);
}
if (p_entity.EndTime != null)
{
q = q.Where(p => p_entity.EndTime.Value >= p.ReviewTime);
}
q = q.Where(p => p.State == 0);
_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(TM_HYANTOLIN_REVIEW), "Get_TM_HYANTOLIN_REVIEW_List", e.Message);
throw e;
}
}
public static ResultObject<bool> Save_TM_HYANTOLIN_REVIEW(List<int> p_list, REVIEW_STATE p_state)
{
ResultObject<bool> _ret = new ResultObject<bool>();
try
{
using (var db = EntitiesFactory.CreateScpInstance())
{
var _list = db.V_TM_HYANTOLIN_REVIEW.Where(p => p_list.Contains(p.UID)).ToList();
if (REVIEW_STATE.CLOSE == p_state)
{
var _entityList = db.TM_HYANTOLIN_REVIEW.Where(p => p_list.Contains(p.UID)).ToList();
foreach (var itm in _entityList)
{
itm.State = ((int)p_state);
//if (!string.IsNullOrEmpty(itm.UltimateName) && Regex.IsMatch(itm.UltimateName,@"\S+"))
//{
//}
}
db.TM_HYANTOLIN_REVIEW.AddOrUpdate(_entityList.ToArray());
foreach (var itm in _list)
{
TB_RECEIVE_DETAIL _entity = db.TB_RECEIVE_DETAIL.Where(p => p.RecvBillNum == itm.ReviewBillNum && p.PartCode==itm.PartCode ).FirstOrDefault();
if (_entity == null)
{
_entity = new TB_RECEIVE_DETAIL();
}
_entity.RecvBillNum = itm.ReviewBillNum;
_entity.PoBillNum = itm.ReviewBillNum;
_entity.PoLine = 999;
_entity.PartCode = itm.PartCode;
_entity.Batch = itm.Batch;
_entity.Qty = -1;
_entity.DockCode = itm.UltimateDepart;
_entity.State = 1;
_entity.CreateTime = itm.CreateTime.Value;
_entity.CreateUser = itm.OperName;
_entity.IsDeleted = false;
_entity.BillType = 2;
_entity.VendBatch = itm.Batch;
_entity.Remark = itm.Domain;
_entity.PoUnit = itm.Unit;
_entity.LocUnit = itm.Unit;
_entity.GUID = Guid.NewGuid();
db.TB_RECEIVE_DETAIL.AddOrUpdate(_entity);
}
foreach (var itm in _list)
{
TB_RECEIVE_DETAIL_QAD _entity = db.TB_RECEIVE_DETAIL_QAD.Where(p => p.RecvBillNum == itm.ReviewBillNum && p.PartCode == itm.PartCode).FirstOrDefault();
if (_entity == null)
{
_entity = new TB_RECEIVE_DETAIL_QAD();
}
_entity.RecvBillNum = itm.ReviewBillNum;
_entity.ErpRecvBillNum = itm.ReviewBillNum;
_entity.PoBillNum = itm.ReviewBillNum;
_entity.PoLine = 999;
_entity.PartCode = itm.PartCode;
_entity.Batch = itm.Batch;
_entity.Qty = -1;
_entity.DockCode = itm.UltimateDepart;
_entity.State = 1;
_entity.PoUnit = itm.Unit;
_entity.LocUnit = itm.Unit;
_entity.Remark = itm.BadCouse;
_entity.CreateTime = itm.ReviewTime.Value;
_entity.CreateUser = itm.OperName;
_entity.IsDeleted = false;
_entity.BillType = 2;
_entity.VendBatch = itm.Batch;
_entity.CurAmt = itm.ClaimAmount;
_entity.StdCost = itm.ClaimAmount;
_entity.PurCost = itm.ClaimAmount;
_entity.Tax = "13";
_entity.Site = itm.Domain;
_entity.GUID = Guid.NewGuid();
db.TB_RECEIVE_DETAIL_QAD.AddOrUpdate(_entity);
}
foreach (var itm in _list)
{
TB_RECEIVE _entity= db.TB_RECEIVE.Where(p => p.RecvBillNum == itm.ReviewBillNum).FirstOrDefault();
if (_entity == null)
{
_entity = new TB_RECEIVE();
}
_entity.RecvBillNum = itm.ReviewBillNum;
_entity.PoBillNum = itm.ReviewBillNum;
_entity.AsnBillNum = itm.RelationReviewNo;
_entity.Site = itm.Domain;
_entity.VendId = itm.UltimateName;
_entity.ShipTime = itm.ReviewTime.Value;
_entity.State = 1;
_entity.Remark = itm.BadCouse;
_entity.CreateTime = itm.CreateTime.Value;
_entity.CreateUser = itm.OperName;
_entity.IsDeleted = false;
_entity.OperName = itm.OperName;
_entity.BillType = 2;
_entity.GUID = Guid.NewGuid();
db.TB_RECEIVE.AddOrUpdate(_entity);
}
foreach (var itm in _list)
{
TB_RECEIVE_QAD _entity = db.TB_RECEIVE_QAD.Where(p => p.RecvBillNum == itm.ReviewBillNum).FirstOrDefault();
if (_entity == null)
{
_entity = new TB_RECEIVE_QAD();
}
_entity.RecvBillNum = itm.ReviewBillNum;
_entity.PoBillNum = itm.ReviewBillNum;
_entity.AsnBillNum = itm.RelationReviewNo;
_entity.Site = itm.Domain;
_entity.ErpRecvBillNum = itm.ReviewBillNum;
_entity.Site = itm.Domain;
_entity.VendId = itm.UltimateName;
_entity.ShipTime = itm.ReviewTime.Value;
_entity.State = 1;
_entity.Remark = itm.BadCouse;
_entity.CreateTime = itm.CreateTime.Value;
_entity.CreateUser = itm.OperName;
_entity.IsDeleted = false;
_entity.OperName = itm.OperName;
_entity.BillType = 2;
_entity.Tax = "13";
_entity.GUID = Guid.NewGuid();
db.TB_RECEIVE_QAD.AddOrUpdate(_entity);
}
foreach (var itm in _list)
{
TB_PO_DETAIL _entity = db.TB_PO_DETAIL.Where(p => p.PoBillNum == itm.ReviewBillNum && p.PartCode==itm.PartCode).FirstOrDefault();
if (_entity == null)
{
_entity = new TB_PO_DETAIL();
}
_entity.PoBillNum = itm.ReviewBillNum;
_entity.PoLine = 999;
_entity.BeginTime = itm.ReviewTime;
_entity.EndTime = itm.ReviewTime;
_entity.PartCode = itm.PartCode;
_entity.ShippedQty = -1;
_entity.ReceivedQty =-1;
_entity.RejectQty = "-1";
_entity.Price = itm.ClaimAmount.Value;
_entity.Currency = itm.Currency;
_entity.PlanQty = itm.Qty.Value;
_entity.PackQty = 1;
_entity.TempQty = itm.Qty.Value;
_entity.PoUnit = itm.Unit;
_entity.LocUnit = itm.Unit;
_entity.State = 0;
_entity.Remark = itm.Domain;
_entity.UnConv = 1;
_entity.DockCode = itm.UltimateDepart;
_entity.CreateTime = itm.CreateTime.Value;
_entity.CreateUser = itm.OperName;
_entity.IsDeleted = false;
db.TB_PO_DETAIL.AddOrUpdate(_entity);
}
foreach (var itm in _list)
{
TB_PO _entity = db.TB_PO.Where(p => p.PoBillNum == itm.ReviewBillNum ).FirstOrDefault();
if (_entity == null)
{
_entity = new TB_PO();
}
_entity.PoBillNum = itm.ReviewBillNum;
_entity.ErpBillNum = itm.ReviewBillNum;
_entity.VendId = itm.VendId;
_entity.ModType = 3;
_entity.Contacter = itm.OperName;
_entity.Site = itm.Domain;
_entity.Buyer = itm.OperName;
_entity.BuyerPhone = itm.OperName;
_entity.State = 1;
_entity.Remark = "索赔单据不能操作";
_entity.BeginTime = itm.ReviewTime.Value;
_entity.EndTime = itm.ReviewTime.Value;
_entity.ReceivedPort = itm.UltimateDepart;
_entity.CreateTime = itm.ReviewTime.Value;
_entity.CreateUser = itm.OperName;
_entity.UpdateTime = itm.ReviewTime.Value;
_entity.UpdateUser = itm.OperName;
_entity.UpdateInfo = itm.OperName;
_entity.IsDeleted = false;
db.TB_PO.AddOrUpdate(_entity);
}
}
else
{
if (REVIEW_STATE.OPEN == p_state)
{
var _ls=_list.Select(p => p.ReviewBillNum).ToList();
if (_ls.Count > 0)
{
var _count = db.TB_INVOICE_DETAIL.Count(p => _ls.Contains(p.RecvBillNum) && p.IsDeleted==false);
if (_count > 0)
{
_ret.MessageList.Add("索赔单信息,在发票里已经存在,不能取消索赔!");
}
else
{
var _entityList = db.TM_HYANTOLIN_REVIEW.Where(p => p_list.Contains(p.UID)).ToList();
foreach (var itm in _entityList)
{
itm.State = ((int)p_state);
}
db.TM_HYANTOLIN_REVIEW.AddOrUpdate(_entityList.ToArray());
foreach (var itm in _list)
{
var rev = db.TB_RECEIVE.Where(p => p.RecvBillNum == itm.ReviewBillNum && p.Site==itm.Domain).FirstOrDefault();
var rev_detail = db.TB_RECEIVE_DETAIL.Where(p => p.RecvBillNum == itm.ReviewBillNum && p.Remark==itm.Domain).FirstOrDefault();
var qad = db.TB_RECEIVE_QAD.Where(p => p.RecvBillNum == itm.ReviewBillNum && p.Site == itm.Domain).FirstOrDefault();
var qad_detail = db.TB_RECEIVE_DETAIL_QAD.Where(p => p.RecvBillNum == itm.ReviewBillNum && p.Site == itm.Domain).FirstOrDefault();
var po = db.TB_PO.Where(p => p.PoBillNum== itm.ReviewBillNum && p.Site == itm.Domain).FirstOrDefault(); ;
var po_detail = db.TB_PO_DETAIL.Where(p => p.PoBillNum == itm.ReviewBillNum && p.Remark == itm.Domain).FirstOrDefault();
if (rev != null)
{
db.TB_RECEIVE.Remove(rev);
}
if (rev_detail != null)
{
db.TB_RECEIVE_DETAIL.Remove(rev_detail);
}
if (qad != null)
{
db.TB_RECEIVE_QAD.Remove(qad);
}
if (qad_detail != null)
{
db.TB_RECEIVE_DETAIL_QAD.Remove(qad_detail);
}
if (po != null)
{
db.TB_PO.Remove(po);
}
if (po_detail != null)
{
db.TB_PO_DETAIL.Remove(po_detail);
}
}
}
}
}
}
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(TM_HYANTOLIN_REVIEW), "Save_TM_HYANTOLIN_REVIEW", e.Message);
_ret.Result = false;
_ret.ErrorList.Add(e);
throw e;
}
return _ret;
}
public ResultObject<bool> Del_TM_HYANTOLIN_REVIEW(List<TM_HYANTOLIN_REVIEW> p_entitys)
{
ResultObject<bool> _ret = new ResultObject<bool>();
try
{
using (var db = EntitiesFactory.CreateScpInstance())
{
foreach (var itm in p_entitys)
{
db.TM_HYANTOLIN_REVIEW.Remove(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;
_ret.Result = false;
_ret.ErrorList.Add(e);
LogHelper.Writlog(LogHelper.LogType.Error, typeof(TM_HYANTOLIN_REVIEW), "Del_TM_HYANTOLIN_REVIEW", e.Message); throw e;
}
return _ret;
}
public static ResultObject<List<TB_CLAIM_APPEND>> Get_TB_CLAIM_APPEND_List(TB_CLAIM_APPEND p_entity)
{
ResultObject<List<TB_CLAIM_APPEND>> _ret = new ResultObject<List<TB_CLAIM_APPEND>>();
try
{
using (ScpEntities db = EntitiesFactory.CreateScpInstance())
{
IQueryable<TB_CLAIM_APPEND> q = db.TB_CLAIM_APPEND;
if (p_entity.CaimGUID!=Guid.Empty)
{
q = q.Where(p => p.CaimGUID==p_entity.CaimGUID);
}
if (!string.IsNullOrEmpty(p_entity.FileName))
{
q = q.Where(p => p.FileName.Contains(p_entity.FileName));
}
if (!string.IsNullOrEmpty(p_entity.Extend))
{
q = q.Where(p => p.Extend.Contains(p_entity.Extend));
}
if (!string.IsNullOrEmpty(p_entity.FileNameMD5))
{
q = q.Where(p => p.FileNameMD5.Contains(p_entity.FileNameMD5));
}
_ret.State = ReturnStatus.Succeed;
_ret.Result = q.ToList();
}
}
catch (Exception e)
{
_ret.State = ReturnStatus.Failed;
_ret.ErrorList.Add(e);
LogHelper.Writlog(LogHelper.LogType.Error, typeof(TB_CLAIM_APPEND), "Get_TB_CLAIM_APPEND_List", e.Message);
throw e;
}
return _ret;
}
public static ResultObject<bool> Save_TB_CLAIM_APPEND(List<TB_CLAIM_APPEND> p_entitys)
{
ResultObject<bool> _ret = new ResultObject<bool>();
try
{
using (ScpEntities db = EntitiesFactory.CreateScpInstance())
{
db.TB_CLAIM_APPEND.AddOrUpdate(p_entitys.ToArray());
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_CLAIM_APPEND), "Save_TB_CLAIM_APPEND", e.Message);
_ret.Result = false;
_ret.ErrorList.Add(e);
throw e;
}
return _ret;
}
public static ResultObject<bool> Del_TB_CLAIM_APPEND(List<TB_CLAIM_APPEND> p_entitys)
{
ResultObject<bool> _ret = new ResultObject<bool>();
try
{
using (ScpEntities db = EntitiesFactory.CreateScpInstance())
{
var _ls = p_entitys.Select(p=>p.UID).ToList();
if (_ls.Count > 0)
{
var _entitys=db.TB_CLAIM_APPEND.Where(p => _ls.Contains(p.UID)).ToList();
foreach (var itm in _entitys)
{
db.TB_CLAIM_APPEND.Remove(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;
_ret.Result = false;
_ret.ErrorList.Add(e);
LogHelper.Writlog(LogHelper.LogType.Error, typeof(TB_CLAIM_APPEND), "Del_TB_CLAIM_APPEND", e.Message); throw e;
}
return _ret;
}
}
}