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.
188 lines
6.6 KiB
188 lines
6.6 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.Data;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using CK.SCP.Models;
|
|
using CK.SCP.Models.ScpEntity;
|
|
using System.Data.Entity.Migrations;
|
|
using CK.SCP.Utils;
|
|
using CK.SCP.Models.Enums;
|
|
using System.Data.Entity.Core;
|
|
|
|
namespace CK.SCP.Controller
|
|
{
|
|
public class SCP_TB_VENDER_CONTROLLER
|
|
{
|
|
public static List<TA_VENDER> GetlistByName(TA_VENDER model)
|
|
{
|
|
using (ScpEntities db = EntitiesFactory.CreateScpInstance())
|
|
{
|
|
return db.TA_VENDER.Where(p => p.VendName == model.VendName).ToList();
|
|
}
|
|
}
|
|
public static List<TA_VENDER> Getlist()
|
|
{
|
|
using (ScpEntities db = EntitiesFactory.CreateScpInstance())
|
|
{
|
|
|
|
return db.TA_VENDER.ToList();
|
|
}
|
|
}
|
|
public static TB_FACTORY GetFactory(string site)
|
|
{
|
|
using (ScpEntities db = EntitiesFactory.CreateScpInstance())
|
|
{
|
|
|
|
return db.TB_FACTORY.Where(p=>p.ErpSite== site).FirstOrDefault();
|
|
}
|
|
}
|
|
public static List<TA_VENDER> Getlist1(string site)
|
|
{
|
|
using (ScpEntities db = EntitiesFactory.CreateScpInstance())
|
|
{
|
|
|
|
return db.TA_VENDER.Where(p=>p.Site== site).ToList();
|
|
}
|
|
}
|
|
|
|
public static List<TA_VENDER> Getlist(List<string> lsVenderID )
|
|
{
|
|
using (ScpEntities db = EntitiesFactory.CreateScpInstance())
|
|
{
|
|
return db.TA_VENDER.Where(p=> lsVenderID.Contains(p.VendId)).ToList();
|
|
}
|
|
}
|
|
public static List<TA_VENDER> Getlist(string p_site)
|
|
{
|
|
using (ScpEntities db = EntitiesFactory.CreateScpInstance())
|
|
{
|
|
|
|
return db.TA_VENDER.Where(p => p.Site==p_site ).ToList();
|
|
}
|
|
}
|
|
public static TA_VENDER GetVender(string p_VenderID,string p_Site)
|
|
{
|
|
using (ScpEntities db = EntitiesFactory.CreateScpInstance())
|
|
{
|
|
return db.TA_VENDER.Where(p => p.VendId==p_VenderID && p.Site==p_Site).FirstOrDefault();
|
|
}
|
|
}
|
|
|
|
public static List<TA_VENDER> GetVendNameList(List<string> p_list, string p_site)
|
|
{
|
|
List<TA_VENDER> _ls = new List<TA_VENDER>();
|
|
using (ScpEntities db = EntitiesFactory.CreateScpInstance())
|
|
{
|
|
IQueryable<TA_VENDER> query = db.TA_VENDER;
|
|
if (p_list.Count > 0)
|
|
{
|
|
query = query.Where(p => p_list.Contains(p.VendId));
|
|
}
|
|
if (!string.IsNullOrEmpty(p_site))
|
|
{
|
|
query = query.Where(p => p.Site == p_site);
|
|
}
|
|
_ls=query.ToList();
|
|
}
|
|
return _ls;
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
public static ResultObject<bool> Save_TA_VENDER(List<TA_VENDER> p_entitys)
|
|
{
|
|
ResultObject<bool> _ret = new ResultObject<bool>();
|
|
try
|
|
{
|
|
using (ScpEntities db = EntitiesFactory.CreateScpInstance())
|
|
{
|
|
foreach (var itm in p_entitys)
|
|
{
|
|
var _entity = db.TA_VENDER.Where(p => p.UID == itm.UID).FirstOrDefault();
|
|
_entity.Quota = itm.Quota;
|
|
db.TA_VENDER.AddOrUpdate(p => p.UID, _entity);
|
|
}
|
|
if (_ret.MessageList.Count > 0)
|
|
{
|
|
_ret.State = ReturnStatus.Failed;
|
|
|
|
}
|
|
else
|
|
{
|
|
if (db.SaveChanges() != -1)
|
|
{
|
|
_ret.State = ReturnStatus.Succeed;
|
|
_ret.Result = true;
|
|
}
|
|
else
|
|
{
|
|
_ret.State = ReturnStatus.Failed;
|
|
_ret.Result = false;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
catch (System.Data.Entity.Validation.DbEntityValidationException dbEx)//捕获实体验证异常
|
|
{
|
|
var sb = new StringBuilder();
|
|
|
|
foreach (var error in dbEx.EntityValidationErrors.ToList())
|
|
{
|
|
|
|
error.ValidationErrors.ToList().ForEach(i =>
|
|
{
|
|
sb.AppendFormat("表:{0},字段:{1},信息:{2}\r\n", error.Entry.Entity.GetType().Name, i.PropertyName, i.ErrorMessage);
|
|
});
|
|
}
|
|
_ret.State = ReturnStatus.Failed;
|
|
_ret.Result = false;
|
|
_ret.ErrorList.Add(dbEx);
|
|
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_TB_VENDER_CONTROLLER), "Save_TA_VENDER", sb.ToString());
|
|
throw new ScpException(ResultCode.DbEntityValidationException, sb.ToString(), "字段验证失败" + sb.ToString());
|
|
}
|
|
catch (OptimisticConcurrencyException ex)//并发冲突异常
|
|
{
|
|
|
|
_ret.State = ReturnStatus.Failed;
|
|
_ret.Result = false;
|
|
_ret.ErrorList.Add(ex);
|
|
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_TB_VENDER_CONTROLLER), "Save_TA_VENDER", ex.ToString());
|
|
throw new ScpException(ResultCode.Exception, "9999", ex.ToString());
|
|
}
|
|
catch (ScpException ex)
|
|
{
|
|
_ret.State = ReturnStatus.Failed;
|
|
_ret.Result = false;
|
|
_ret.ErrorList.Add(ex);
|
|
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_TB_VENDER_CONTROLLER), "Save_TA_VENDER", ex.ToString());
|
|
if (ex.InnerException != null && ex.InnerException.GetType() == typeof(UpdateException))
|
|
{
|
|
var inner = (UpdateException)ex.InnerException;
|
|
|
|
|
|
throw new ScpException(ResultCode.Exception, "0000", ex.ToString());
|
|
}
|
|
else
|
|
{
|
|
if (ex.InnerException != null) throw ex.InnerException;
|
|
}
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
|
|
|
|
_ret.State = ReturnStatus.Failed;
|
|
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_TB_VENDER_CONTROLLER), "Save_TA_VENDER", e.Message);
|
|
_ret.Result = false;
|
|
_ret.ErrorList.Add(e);
|
|
throw e;
|
|
}
|
|
return _ret;
|
|
}
|
|
|
|
}
|
|
}
|
|
|