using iWareCommon.Common.Service;
|
using iWareCommon.Utils;
|
using iWareDataCore.BASE.Dao;
|
using iWareDataCore.BASE.Entity;
|
using iWareDataCore.ORM;
|
using iWareDataCore.Properties;
|
using System;
|
using System.Collections.Generic;
|
using System.Linq;
|
using System.Text;
|
using System.Threading.Tasks;
|
|
namespace iWareDataCore.BASE.Service
|
{
|
public class InOutListService : CommonService<InOutListEntity, BASEInOutList, DbModelCore>
|
{
|
private static object Lock = new object();
|
|
private InOutListService() : base(InOutListDao.GetInstance()) { }
|
|
private static InOutListService Instance = null;
|
|
/// <summary>
|
/// 获取单例的方法
|
/// </summary>
|
/// <returns>用户服务的单例实体</returns>
|
public static InOutListService GetInstance()
|
{
|
|
if (Instance == null)
|
{
|
lock (Lock)
|
{
|
if (Instance == null)
|
{
|
Instance = new InOutListService();
|
}
|
}
|
}
|
return Instance;
|
}
|
|
/// <summary>
|
/// 转换子表ORM
|
/// </summary>
|
/// <param name="iol"></param>
|
/// <param name="msg"></param>
|
/// <returns></returns>
|
public int CreateListAndDetial(InOutListEntity iol, out string msg)
|
{
|
try
|
{
|
using (var DbModel = new DbModelCore())
|
{
|
List<BASEInOutListDetail> inldlst = new List<BASEInOutListDetail>();
|
msg = "";
|
iol.InOutListDetail.ForEach(x => { inldlst.Add(x.ToOrm()); });
|
BASEInOutList biol = new BASEInOutList();
|
biol = iol.ToOrm();
|
biol.BASEInOutListDetails = inldlst;
|
DbModel.BASEInOutLists.Add(biol);
|
return DbModel.SaveChanges();
|
}
|
}
|
catch (Exception ex)
|
{
|
msg = ex.Message;
|
|
return -1;
|
|
}
|
}
|
public bool AddOutInDetail(string inoutNo, string maritalNo, out string msg)
|
{
|
try
|
{
|
msg = "";
|
using (var dbModel = new DbModelCore())
|
{
|
var cutInOut = dbModel.BASEInOutLists.FirstOrDefault(x=>x.listno== inoutNo);
|
if (cutInOut == null)
|
{
|
msg = "出入库单号不存在";
|
return false;
|
}
|
var cutMarital = dbModel.BASEMaterials.FirstOrDefault(x => x.code == maritalNo);
|
if (cutMarital == null)
|
{
|
msg = "物料不存在";
|
return false;
|
}
|
var findInOutDetail = dbModel.BASEInOutListDetails.FirstOrDefault(x => x.inoutlistid == cutInOut.id && x.materialid== cutMarital.id);
|
if (findInOutDetail != null)
|
{
|
msg = "此单号和物料已存在";
|
return false;
|
}
|
BASEInOutListDetail newDetail = new BASEInOutListDetail();
|
newDetail.inoutlistid = cutInOut.id;
|
newDetail.placeid = 0;
|
newDetail.materialid = cutMarital.id;
|
newDetail.isfinish = 0;
|
dbModel.BASEInOutListDetails.Add(newDetail);
|
dbModel.SaveChanges();
|
msg = "新增成功";
|
return true;
|
}
|
}
|
catch (Exception ex)
|
{
|
msg = ex.Message;
|
return false;
|
}
|
}
|
|
public override int Delete(int id, out string msg)
|
{
|
msg = "";
|
using (var dbModel = new DbModelCore())
|
{
|
try
|
{
|
var inoutlist = dbModel.BASEInOutLists.Where(x => id == x.id).ToList();
|
|
var inoutdetail = dbModel.BASEInOutListDetails.Where(x => id == x.inoutlistid).ToList();
|
inoutdetail.ForEach(x => dbModel.BASEInOutListDetails.Remove(x));
|
inoutlist.ForEach(x => dbModel.BASEInOutLists.Remove(x));
|
|
dbModel.SaveChanges();
|
return inoutdetail.Count;
|
}
|
catch (Exception ex)
|
{
|
msg = ex.Message;
|
LogTextHelper.WriteLog(Resources.LogDir, this.ToString(), "Delete", ex.Message);
|
return 0;
|
}
|
}
|
}
|
|
public int DeleteInOut(int id, out string msg)
|
{
|
msg = "";
|
using (var dbModel = new DbModelCore())
|
{
|
try
|
{
|
var inoutlist = dbModel.BASEInOutLists.Where(x => id == x.id).ToList();
|
|
var inoutdetail = dbModel.BASEInOutListDetails.Where(x => x.inoutlistid == id).ToList();
|
inoutdetail.ForEach(x => dbModel.BASEInOutListDetails.Remove(x));
|
dbModel.BASEInOutLists.RemoveRange(inoutlist);
|
|
dbModel.SaveChanges();
|
return inoutlist.Count;
|
}
|
catch (Exception ex)
|
{
|
msg = ex.Message;
|
LogTextHelper.WriteLog(Resources.LogDir, this.ToString(), "DeleteInOut", ex.Message);
|
return 0;
|
}
|
}
|
}
|
|
//public override int Delete(List<int> id, out string msg)
|
//{
|
// msg = "";
|
// using (var dbModel = new DbModelCore())
|
// {
|
// try
|
// {
|
// var inoutlist = dbModel.BASEInOutLists.Where(x => id == x.id).ToList();
|
|
// var inoutdetail = dbModel.BASEInOutListDetails.Where(x => id == x.inoutlistid).ToList();
|
// inoutdetail.ForEach(x => dbModel.BASEInOutListDetails.Remove(x));
|
// inoutlist.ForEach(x => dbModel.BASEInOutLists.Remove(x));
|
|
// dbModel.SaveChanges();
|
// return inoutdetail.Count;
|
// }
|
// catch (Exception ex)
|
// {
|
// msg = ex.Message;
|
// LogTextHelper.WriteLog(Resources.LogDir, this.ToString(), "Delete", ex.Message);
|
// return 0;
|
// }
|
// }
|
//}
|
|
}
|
}
|