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.
232 lines
8.9 KiB
232 lines
8.9 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;
|
|
using CK.SCP.Models.ScpEntity.ExcelExportEnttity;
|
|
using CK.SCP.Models.AppBoxEntity;
|
|
using System.Collections;
|
|
|
|
namespace CK.SCP.Controller
|
|
{
|
|
/// <summary>
|
|
/// 采购对应收货管理地址
|
|
/// </summary>
|
|
public class SCP_TB_ADDRESS_BUYER_CONTROLLER
|
|
{
|
|
/// <summary>
|
|
/// 获取采购收货地址对应关系
|
|
/// </summary>
|
|
/// <param name="Buyer">采购</param>
|
|
/// <param name="p_action"></param>
|
|
public static void GetTbAddressBuyerList(string Buyer,string SubSite, Action<ResultObject<IQueryable<TB_ADDRESS_BUYER>>> p_action)
|
|
{
|
|
ResultObject<IQueryable<TB_ADDRESS_BUYER>> _ret = new ResultObject<IQueryable<TB_ADDRESS_BUYER>>();
|
|
try
|
|
{
|
|
using (ScpEntities db = EntitiesFactory.CreateScpInstance())
|
|
{
|
|
IQueryable<TB_ADDRESS_BUYER> q = db.TB_ADDRESS_BUYER;
|
|
if (!string.IsNullOrEmpty(Buyer))
|
|
{
|
|
q = q.Where(p => p.Buyer.Contains(Buyer));
|
|
}
|
|
if (!string.IsNullOrEmpty(SubSite))
|
|
{
|
|
q = q.Where(p => p.SubSite == SubSite);
|
|
}
|
|
_ret.State = ReturnStatus.Succeed;
|
|
_ret.Result = q;
|
|
p_action(_ret);
|
|
}
|
|
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
_ret.State = ReturnStatus.Failed;
|
|
_ret.ErrorList.Add(e);
|
|
if (e.InnerException != null)
|
|
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_TB_ADDRESS_BUYER_CONTROLLER), "GetTbAddressBuyerList(Exception)", LogHelper.GetExceptionMessage(e).Message);
|
|
|
|
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_TB_ADDRESS_BUYER_CONTROLLER), "GetTbAddressBuyerList", e.Message);
|
|
throw e;
|
|
}
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 导入
|
|
/// </summary>
|
|
/// <param name="p_order_list"></param>
|
|
/// <param name="p_creator"></param>
|
|
/// <returns></returns>
|
|
public static ResultObject<bool> EXCEL_ADRESS_BUYER_LIST(List<SCP_ADDRESS_BUYER_EXPORT> p_order_list,string SubSite, string p_creator)
|
|
{
|
|
ResultObject<bool> _ret = new ResultObject<bool>();
|
|
try
|
|
{
|
|
using (ScpEntities db = EntitiesFactory.CreateScpInstance())
|
|
{
|
|
List<string> lineError = new List<string>();
|
|
List<string> ErrorList = new List<string>();
|
|
var _lst = p_order_list;
|
|
List<long> uidList = db.TB_ADDRESS.Select(q => q.UID).ToList();
|
|
/// 校验
|
|
lineError = Checked(p_order_list, uidList);
|
|
|
|
if (lineError.Count > 0)
|
|
{
|
|
_ret.State = ReturnStatus.Failed;
|
|
_ret.MessageList.AddRange(lineError);
|
|
_ret.Result = false;
|
|
}
|
|
else
|
|
{
|
|
DateTime time = DateTime.Now;
|
|
_lst.ForEach(p =>
|
|
{
|
|
var _Sitelist = db.TB_ADDRESS_BUYER.Count(t => t.Buyer == p.采购人 && t.SubSite == SubSite);
|
|
if (_Sitelist == 0)
|
|
{
|
|
TB_ADDRESS_BUYER buyer = new TB_ADDRESS_BUYER();
|
|
buyer.AddressUID = long.Parse(p.收货地址ID);
|
|
buyer.Buyer = p.采购人;
|
|
buyer.Creator = p_creator;
|
|
buyer.CreateTime = time;
|
|
buyer.SubSite = SubSite;
|
|
db.TB_ADDRESS_BUYER.Add(buyer);
|
|
}
|
|
else if (_Sitelist == 1)
|
|
{
|
|
var buyer = db.TB_ADDRESS_BUYER.SingleOrDefault(t => t.Buyer == p.采购人 && t.SubSite == SubSite);
|
|
buyer.AddressUID = long.Parse(p.收货地址ID);
|
|
buyer.UpdateTime = time;
|
|
buyer.UpdateUser = p_creator;
|
|
db.TB_ADDRESS_BUYER.AddOrUpdate(a => a.UID, buyer);
|
|
}
|
|
|
|
});
|
|
if (_ret.MessageList.Count == 0)
|
|
{
|
|
int state = db.SaveChanges();
|
|
if (state != -1)
|
|
{
|
|
_ret.State = ReturnStatus.Succeed;
|
|
_ret.Result = true;
|
|
}
|
|
else
|
|
{
|
|
_ret.State = ReturnStatus.Failed;
|
|
_ret.Result = false;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
_ret.State = ReturnStatus.Failed;
|
|
_ret.Result = false;
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
_ret.State = ReturnStatus.Failed;
|
|
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_TB_ADDRESS_BUYER_CONTROLLER), "EXCEL_ADRESS_BUYER_LIST", e.Message);
|
|
_ret.Result = false;
|
|
_ret.ErrorList.Add(e);
|
|
throw e;
|
|
}
|
|
return _ret;
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// 校验 查看是否有错误
|
|
/// </summary>
|
|
/// <param name="p_order_list">导入文件</param>
|
|
/// <param name="ulist">地址uidlist</param>
|
|
/// <returns></returns>
|
|
public static List<string> Checked(List<SCP_ADDRESS_BUYER_EXPORT> p_order_list, List<long> ulist)
|
|
{
|
|
List<string> errorlist = new List<string>();
|
|
List<string> userName = new List<string>();
|
|
using (AppBoxContext db = EntitiesFactory.CreateAppBoxInstance())
|
|
{
|
|
List<User> users = db.Users.ToList();
|
|
userName = users.Select(q => q.Name).ToList();
|
|
}
|
|
long ID;
|
|
foreach (var item in p_order_list)
|
|
{
|
|
var count = p_order_list.Where(q => q.采购人 == item.采购人).Count();
|
|
if (count > 1)
|
|
{
|
|
errorlist.Add(String.Format("{0}重复", item.采购人));
|
|
break;
|
|
}
|
|
if (!userName.Contains(item.采购人))
|
|
{
|
|
errorlist.Add(string.Format("{0}不是当前系统人员", item.采购人));
|
|
break;
|
|
}
|
|
if (!long.TryParse(item.收货地址ID, out ID))
|
|
{
|
|
errorlist.Add(string.Format("{0}不能转化为数字", item.收货地址ID));
|
|
break;
|
|
}
|
|
else if (!ulist.Contains(ID))
|
|
{
|
|
errorlist.Add(string.Format("{0}不在收货信息管理(重庆专用)的UID里", item.收货地址ID));
|
|
break;
|
|
}
|
|
|
|
}
|
|
return errorlist;
|
|
}
|
|
/// <summary>
|
|
/// 删除
|
|
/// </summary>
|
|
/// <param name="uidlist">uid列表</param>
|
|
/// <returns></returns>
|
|
public static ResultObject<bool> DeleteByUid(List<long> uidlist)
|
|
{
|
|
ResultObject<bool> _ret = new ResultObject<bool>();
|
|
try
|
|
{
|
|
using (ScpEntities db = EntitiesFactory.CreateScpInstance())
|
|
{
|
|
var list = db.TB_ADDRESS_BUYER.Where(itm => uidlist.Contains(itm.UID));
|
|
|
|
db.TB_ADDRESS_BUYER.RemoveRange(list);
|
|
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(SCP_TB_ADDRESS_BUYER_CONTROLLER), "DeleteByUid", e.Message); throw e;
|
|
}
|
|
return _ret;
|
|
}
|
|
}
|
|
}
|
|
|