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.
933 lines
34 KiB
933 lines
34 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using QMFrameWork.Data;
|
|
using QMAPP.FJC.Entity.Stocktaking;
|
|
using QMAPP.FJC.DAL.Stocktaking;
|
|
using QMAPP.FJC.BLL.Dict;
|
|
using QMAPP.BLL;
|
|
using QMAPP.Entity;
|
|
using System.Data;
|
|
using QMAPP.FJC.Web.Models.Stocktaking;
|
|
using QMAPP.FJC.Entity;
|
|
using QMFrameWork.Log;
|
|
using QMAPP.FJC.Entity.Operation;
|
|
using QMAPP.FJC.DAL.Operation;
|
|
using QMAPP.MD.DAL;
|
|
using QMAPP.FJC.DAL.ProduceManage;
|
|
using QMAPP.FJC.BLL.Operation;
|
|
using QMAPP.FJC.Entity.ProductIn;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace QMAPP.FJC.BLL.Stocktaking
|
|
{
|
|
/// <summary>
|
|
/// 模块编号:M14-1
|
|
/// 作 用:库存盘点
|
|
/// 作 者:崔法宝
|
|
/// 编写日期:2015年06月04日
|
|
///</summary>
|
|
public class StocktakingBLL : BaseBLL
|
|
{
|
|
|
|
|
|
#region 获取列表
|
|
/// <summary>
|
|
/// 获取列表
|
|
/// </summary>
|
|
/// <param name="condition">条件</param>
|
|
/// <param name="page">数据页</param>
|
|
/// <returns>数据页</returns>
|
|
public DataResult<DataPage> GetList(Countingplaninfo condition, DataPage page)
|
|
{
|
|
DataResult<DataPage> result = new DataResult<DataPage>();
|
|
try
|
|
{
|
|
result.IsSuccess = true;
|
|
page = new StocktakingDAL().GetList(condition, page);
|
|
List<Countingplaninfo> list = page.Result as List<Countingplaninfo>;
|
|
//处理字典信息
|
|
DictManageBLL dictPLANSTATE = new DictManageBLL(DictKind.STOCK_PLAN_STATE);
|
|
DictManageBLL dictCOUNTTYPE = new DictManageBLL(DictKind.COUNTTYPE);
|
|
foreach (var info in list)
|
|
{
|
|
info.COUNTTYPE = dictCOUNTTYPE.GetDictValue(info.COUNTTYPE);
|
|
info.PLAN_STATE = dictPLANSTATE.GetDictValue(info.PLAN_STATE);
|
|
}
|
|
result.Result = page;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
return result;
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 获取列表(同时手持也用此方法)
|
|
/// </summary>
|
|
/// <param name="condition">条件</param>
|
|
/// <returns>全部集合</returns>
|
|
public List<Countingplaninfo> GetAllList(Countingplaninfo condition)
|
|
{
|
|
try
|
|
{
|
|
//获取物料信息列表
|
|
List<Countingplaninfo> list = new StocktakingDAL().GetAllList(condition);
|
|
return list;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region 获取设备信息,填充Grid
|
|
/// <summary>
|
|
/// 获取设备信息,填充Grid
|
|
/// </summary>
|
|
/// <param name="condition"></param>
|
|
/// <returns></returns>
|
|
public List<QMAPP.MD.Entity.Material> GetMachineInfo(QMAPP.MD.Entity.Material condition)
|
|
{
|
|
QMAPP.MD.Entity.Material material = new QMAPP.MD.Entity.Material();
|
|
List<QMAPP.MD.Entity.Material> materialList = new List<MD.Entity.Material>();
|
|
//根据设备iD获取本体信息
|
|
material.PID = condition.PID;
|
|
material.MaterialCodes = condition.MaterialCodes;
|
|
try
|
|
{
|
|
materialList = new MaterialDAL().GetMaterialInfoList(material);
|
|
|
|
//foreach (QMAPP.MD.Entity.Material m in materialList)
|
|
//{
|
|
// material.MATERIAL_CODE = m.MATERIAL_CODE;
|
|
// material.MATERIAL_TYPE_CODE = m.MATERIAL_TYPE_CODE;
|
|
// material.CreateDate = (DateTime.Now.ToString("yyyy-MM-dd"));
|
|
//}
|
|
for (var i = 0; i < materialList.Count(); i++)
|
|
{
|
|
materialList[i].CreateDate = (DateTime.Now.ToString("yyyy-MM-dd"));
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
LogManager.LogHelper.Error(new LogInfo()
|
|
{
|
|
ErrorInfo = ex,
|
|
Tag = ex.StackTrace,
|
|
Info = "逻辑层-获取本体信息!"
|
|
});
|
|
throw ex;
|
|
}
|
|
return materialList;
|
|
}
|
|
#endregion
|
|
|
|
#region 插入信息(T_PP_COUNTINGPLAN)
|
|
/// <summary>
|
|
/// 插入信息(T_PP_COUNTINGPLAN)
|
|
/// </summary>
|
|
/// <param name="">信息</param>
|
|
/// <returns>插入行数</returns>
|
|
public int Insert(Countingplaninfo model)
|
|
{
|
|
model.PLAN_STATE = "0";
|
|
model.REGISTNUMBER = 0;
|
|
model.ACTUALNUMBER = 0;
|
|
model.CREATEUSER = this.LoginUser.UserID;
|
|
model.CREATEDATE = DateTime.Now;
|
|
model.UPDATEUSER = model.CREATEUSER;
|
|
model.UPDATEDATE = model.CREATEDATE;
|
|
try
|
|
{
|
|
int result = new StocktakingDAL().Insert(model);
|
|
|
|
return result;
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region 插入信息 T_PP_COUNTINGDETAIL表
|
|
/// <summary>
|
|
/// 插入信息
|
|
/// </summary>
|
|
/// <param name="">信息</param>
|
|
/// <returns>插入行数</returns>
|
|
public DataResult<int> InsertStocktakingDeail(Countingplaninfo model, List<QMAPP.MD.Entity.Material> materiallist)
|
|
{
|
|
List<CountingdetailInfo> List = new List<CountingdetailInfo>();
|
|
DataResult<int> result = new DataResult<int>();
|
|
StocktakingDAL cmdDAL = new StocktakingDAL();
|
|
cmdDAL.BaseSession = AppDataFactory.CreateMainSession();
|
|
|
|
foreach (QMAPP.MD.Entity.Material ma in materiallist)
|
|
{
|
|
CountingdetailInfo detailmodel = new CountingdetailInfo();
|
|
|
|
detailmodel.PID = Guid.NewGuid().ToString();
|
|
detailmodel.PLANID = model.PID;
|
|
detailmodel.MATERIAL_CODE = ma.MATERIAL_CODE;
|
|
detailmodel.MATERIAL_TYPE_CODE = ma.MATERIAL_TYPE_CODE;
|
|
detailmodel.CREATEUSER = this.LoginUser.UserID;
|
|
detailmodel.CREATEDATE = DateTime.Now;
|
|
detailmodel.UPDATEUSER = detailmodel.CREATEUSER;
|
|
detailmodel.UPDATEDATE = detailmodel.CREATEDATE;
|
|
|
|
List.Add(detailmodel);
|
|
}
|
|
try
|
|
{
|
|
//if (ExistsMateriel(model))
|
|
//{
|
|
// result.IsSuccess = false;
|
|
// result.Msg = Resource.MaterielCodeIsHave;
|
|
// return result;
|
|
//}
|
|
if(model.EDITFLAG==null)
|
|
{
|
|
result.Result = cmdDAL.InsertStocktakingPlan(List);
|
|
}else
|
|
{
|
|
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
LogManager.LogHelper.Error(new LogInfo()
|
|
{
|
|
ErrorInfo = ex,
|
|
Tag = ex.StackTrace,
|
|
Info = "逻辑矩阵逻辑层-插入信息!"
|
|
});
|
|
result.IsSuccess = false;
|
|
result.Msg = Resource.SystemException;
|
|
throw ex;
|
|
}
|
|
result.IsSuccess = true;
|
|
return result;
|
|
}
|
|
#endregion
|
|
|
|
#region 修改更新信息(单表(T_PP_COUNTINGPLAN))
|
|
/// <summary>
|
|
/// 修改信息(单表)
|
|
/// </summary>
|
|
/// <param name="">信息</param>
|
|
/// <returns>修改行数</returns>
|
|
public DataResult<int> Update(Countingplaninfo model)
|
|
{
|
|
object count = null;
|
|
DataResult<int> result = new DataResult<int>();
|
|
try
|
|
{
|
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
|
{
|
|
count = new StocktakingDAL().Update(model);
|
|
result.Result = Convert.ToInt32(count);
|
|
result.IsSuccess = true;
|
|
return result;
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
result.IsSuccess = false;
|
|
throw ex;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region 获取信息
|
|
/// <summary>
|
|
/// 获取信息
|
|
/// </summary>
|
|
/// <param name="">条件</param>
|
|
/// <returns>信息</returns>
|
|
public DataResult<Countingplaninfo> Get(Countingplaninfo model)
|
|
{
|
|
DataResult<Countingplaninfo> result = new DataResult<Countingplaninfo>();
|
|
try
|
|
{
|
|
result.Result = new StocktakingDAL().Get(model);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
result.IsSuccess = false;
|
|
result.Msg = Resource.SystemException;
|
|
throw ex;
|
|
}
|
|
result.IsSuccess = true;
|
|
return result;
|
|
}
|
|
#endregion
|
|
|
|
#region 获取列表
|
|
/// <summary>
|
|
/// 获取列表
|
|
/// </summary>
|
|
/// <param name="condition">条件</param>
|
|
/// <param name="page">数据页</param>
|
|
/// <returns>数据页</returns>
|
|
public DataResult<DataPage> GetMaterialGridList(CountingdetailInfo condition, DataPage page)
|
|
{
|
|
|
|
DataResult<DataPage> result = new DataResult<DataPage>();
|
|
try
|
|
{
|
|
//获取信息列表
|
|
DataPage dataPage = new StocktakingDAL().GetMaterialGridList(condition, page);
|
|
|
|
result.Result = dataPage;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
LogManager.LogHelper.Error(new LogInfo()
|
|
{
|
|
ErrorInfo = ex,
|
|
Tag = ex.StackTrace,
|
|
Info = "设备信息逻辑层-获取列表!"
|
|
});
|
|
result.IsSuccess = false;
|
|
result.Msg = Resource.SystemException;
|
|
throw ex;
|
|
}
|
|
result.IsSuccess = true;
|
|
return result;
|
|
}
|
|
#endregion
|
|
|
|
#region 编辑时删除
|
|
/// <summary>
|
|
/// 编辑时删除
|
|
/// </summary>
|
|
/// <param name=""></param>
|
|
/// <returns>删除个数</returns>
|
|
public DataResult<int> EditDelete(CountingdetailInfo model)
|
|
{
|
|
DataResult<int> result = new DataResult<int>();
|
|
if (string.IsNullOrEmpty(model.EDITFLAG))
|
|
{
|
|
string[] list = model.MaterialCodes.Split(";".ToCharArray());
|
|
try
|
|
{
|
|
foreach (string str in list)
|
|
{
|
|
result.Result += this.EditDeleteUserWithMachine(new CountingdetailInfo { MATERIAL_CODE = str, PLANID = model.PLANID });
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
result.IsSuccess = false;
|
|
result.Msg = Resource.SystemException;
|
|
throw ex;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
try
|
|
{
|
|
result.Result += this.EditDeleteUserWithMachine(new CountingdetailInfo { PLANID = model.PLANID });
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
result.IsSuccess = false;
|
|
result.Msg = Resource.SystemException;
|
|
throw ex;
|
|
}
|
|
}
|
|
result.IsSuccess = true;
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 删除信息
|
|
/// </summary>
|
|
/// <param name="">信息</param>
|
|
/// <returns>删除个数</returns>
|
|
public int EditDeleteUserWithMachine(CountingdetailInfo model)
|
|
{
|
|
int count = 0;
|
|
try
|
|
{
|
|
count = new StocktakingDAL().EditDeleteUserWithMachine(model);
|
|
return count;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region 编辑时保存
|
|
/// <summary>
|
|
/// 编辑时保存
|
|
/// </summary>
|
|
/// <param name=""></param>
|
|
/// <returns></returns>
|
|
public DataResult<int> EditInsertStocktakingDeail(Countingplaninfo model, List<QMAPP.MD.Entity.Material> materiallist)
|
|
{
|
|
int count = 0;
|
|
StocktakingDAL cmdDAL = new StocktakingDAL();
|
|
cmdDAL.BaseSession = AppDataFactory.CreateMainSession();
|
|
DataResult<int> result = new DataResult<int>();
|
|
try
|
|
{
|
|
//存在的物料信息(更新)
|
|
List<CountingdetailInfo> updateCountingdetail = new List<CountingdetailInfo>();
|
|
//新加的物料信息(增加)
|
|
List<CountingdetailInfo> addCountingdetail = new List<CountingdetailInfo>();
|
|
|
|
foreach (QMAPP.MD.Entity.Material ma in materiallist)
|
|
{
|
|
count = cmdDAL.GetDetailInfo(new CountingdetailInfo() { PLANID = model.PID, MATERIAL_CODE = ma.MATERIAL_CODE });
|
|
CountingdetailInfo detailInfo = new CountingdetailInfo();
|
|
|
|
//如果T_PP_COUNTINGDETAIL表存在数据,则更新
|
|
if (count != 0)
|
|
{
|
|
detailInfo.PLANID = model.PID;
|
|
detailInfo.MATERIAL_CODE = ma.MATERIAL_CODE;
|
|
|
|
updateCountingdetail.Add(detailInfo);
|
|
}
|
|
else
|
|
{
|
|
detailInfo.PID = Guid.NewGuid().ToString();
|
|
detailInfo.PLANID = model.PID;
|
|
detailInfo.MATERIAL_CODE = ma.MATERIAL_CODE;
|
|
detailInfo.MATERIAL_TYPE_CODE = ma.MATERIAL_TYPE_CODE;
|
|
detailInfo.CREATEUSER = this.LoginUser.UserID;
|
|
detailInfo.CREATEDATE = DateTime.Now;
|
|
detailInfo.UPDATEUSER = detailInfo.CREATEUSER;
|
|
detailInfo.UPDATEDATE = detailInfo.CREATEDATE;
|
|
|
|
addCountingdetail.Add(detailInfo);
|
|
}
|
|
|
|
//插入
|
|
if (addCountingdetail.Count > 0)
|
|
{
|
|
result.Result = cmdDAL.InsertStocktakingPlan(addCountingdetail);
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
result.Result = count;
|
|
result.Msg = "成功!";
|
|
result.IsSuccess = true;
|
|
return result;
|
|
}
|
|
#endregion
|
|
|
|
#region 删除父表数据根据ID T_PP_COUNTINGPLAN
|
|
/// <summary>
|
|
/// 删除父表数据根据ID
|
|
/// </summary>
|
|
/// <param name="">信息</param>
|
|
/// <returns>插入行数</returns>
|
|
public DataResult<int> Delete(string PID)
|
|
{
|
|
object count = null;
|
|
DataResult<int> result = new DataResult<int>();
|
|
try
|
|
{
|
|
|
|
|
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
|
{
|
|
count = new StocktakingDAL().Delete(PID);
|
|
result.Result = Convert.ToInt32(count);
|
|
result.IsSuccess = true;
|
|
return result;
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
result.IsSuccess = false;
|
|
throw ex;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region 删除子表的数据根据PLANID T_PP_COUNTINGDETAIL
|
|
/// <summary>
|
|
/// 删除子表的数据根据PLANID
|
|
/// </summary>
|
|
/// <param name="">信息</param>
|
|
/// <returns>插入行数</returns>
|
|
public DataResult<int> SubDelete(string PLANID)
|
|
{
|
|
object count = null;
|
|
DataResult<int> result = new DataResult<int>();
|
|
try
|
|
{
|
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
|
{
|
|
count = new StocktakingDAL().SubDelete(PLANID);
|
|
result.Result = Convert.ToInt32(count);
|
|
result.IsSuccess = true;
|
|
return result;
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
result.IsSuccess = false;
|
|
throw ex;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region 获取每日最新的计划单号
|
|
/// <summary>
|
|
/// 获取每日最新的计划单号
|
|
/// </summary>
|
|
/// <param name="">信息</param>
|
|
/// <returns>计划单号</returns>
|
|
public object GetPlanNoByDate(string NowDate)
|
|
{
|
|
try
|
|
{
|
|
return new StocktakingDAL().GetPlanNoByDate(NowDate);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
|
|
}
|
|
#endregion
|
|
|
|
#region 获取盘点明细查询
|
|
/// <summary>
|
|
/// 获取盘点明细查询
|
|
/// </summary>
|
|
/// <param name="condition">条件</param>
|
|
/// <param name="page">数据页</param>
|
|
/// <returns>数据页</returns>
|
|
public DataResult<DataPage> GetPanDetail(string PID, DataPage page)
|
|
{
|
|
DataResult<DataPage> result = new DataResult<DataPage>();
|
|
try
|
|
{
|
|
result.IsSuccess = true;
|
|
page = new StocktakingDAL().GetPanDetail(PID, page);
|
|
List<CountSheetInfo> list = page.Result as List<CountSheetInfo>;
|
|
result.Result = page;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
return result;
|
|
}
|
|
#endregion
|
|
|
|
#region 盘点比对
|
|
/// <summary>
|
|
/// 盘点比对
|
|
/// </summary>
|
|
/// <param name="PID"></param>
|
|
/// <returns></returns>
|
|
public DataResult<int> detailCompareResult(string PID, string CREATEUSER)
|
|
{
|
|
StocktakingDAL dal = new StocktakingDAL();
|
|
DataResult<int> result = new DataResult<int>();
|
|
|
|
try
|
|
{
|
|
Countingplaninfo plan = dal.Get(new Countingplaninfo() { PID = PID });
|
|
|
|
//获取手持终端的盘点信息
|
|
List<CountResultInfo> sheetList = dal.GetCountSheetInfoList(new CountSheetInfo() { PLANID = PID });
|
|
List<string> sheetStrList = sheetList.Select(o => o.PRODUCTCODE).ToList<string>();
|
|
|
|
|
|
if (sheetList.Count == 0)
|
|
{
|
|
result.IsSuccess = false;
|
|
result.Msg = "未盘点实物,不能进行对比!";
|
|
return result;
|
|
}
|
|
|
|
List<CountResultInfo> resultList = new List<CountResultInfo>();
|
|
|
|
//按条码进行盘点
|
|
if (plan.COUNTTYPE == EnumGeter.COUNTTYPE.CHECKBYCODE.GetHashCode().ToString())
|
|
{
|
|
//获取符合条件的产品信息
|
|
List<CountResultInfo> proListIn = dal.GetListIn(new Countingplaninfo() { PID = sheetList[0].PLANID });
|
|
List<string> proStrListIn = proListIn.Select(o => o.PRODUCTCODE).ToList<string>();
|
|
|
|
plan.ACTUALNUMBER = sheetList.Count;
|
|
plan.REGISTNUMBER = proListIn.Count;
|
|
plan.PLAN_STATE = "1";
|
|
|
|
//系统有,实物没有,实物亏
|
|
|
|
List<string> strList1 = proStrListIn.Except(sheetStrList).ToList<string>();
|
|
List<CountResultInfo> list1 = proListIn.Where(o => strList1.Contains(o.PRODUCTCODE)).ToList<CountResultInfo>();
|
|
|
|
//实物有,系统没有,实物赢
|
|
|
|
List<string> strList2 = sheetStrList.Except(proStrListIn).ToList<string>();
|
|
List<CountResultInfo> list2 = sheetList.Where(o => strList2.Contains(o.PRODUCTCODE)).ToList<CountResultInfo>();
|
|
|
|
//要修改的产品信息
|
|
List<Product> proList = new List<Product>();
|
|
//入库数据
|
|
List<QMAPP.FJC.Entity.ProductIn.ProductIn> proInList = new List<QMAPP.FJC.Entity.ProductIn.ProductIn>();
|
|
//出库库数据
|
|
List<ProductOut> proOutList = new List<ProductOut>();
|
|
|
|
foreach (var cr in list1)
|
|
{
|
|
cr.PID = Guid.NewGuid().ToString();
|
|
cr.COMPARERESULT = EnumGeter.COMPARERESULT.LOSS.GetHashCode().ToString();
|
|
cr.CREATEUSER = this.LoginUser.UserID.ToString();
|
|
cr.CREATEDATE = System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
|
|
}
|
|
|
|
foreach (var cr in list2)
|
|
{
|
|
cr.PID = Guid.NewGuid().ToString();
|
|
cr.COMPARERESULT = EnumGeter.COMPARERESULT.GAIN.GetHashCode().ToString();
|
|
cr.CREATEUSER = this.LoginUser.UserID.ToString();
|
|
cr.CREATEDATE = System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
|
|
}
|
|
resultList = list1.Concat(list2).ToList<CountResultInfo>();
|
|
}
|
|
else
|
|
{
|
|
#region 数量盘点
|
|
|
|
DataTable dt = dal.GetResult(new Countingplaninfo() { PID = sheetList[0].PLANID });
|
|
|
|
int actualNumber = 0;
|
|
int registNumber = 0;
|
|
for (int i = 0; i < dt.Rows.Count; i++)
|
|
{
|
|
CountResultInfo cr = new CountResultInfo();
|
|
cr.PID = Guid.NewGuid().ToString();
|
|
cr.PLANID = plan.PID;
|
|
cr.CREATEUSER = this.LoginUser.UserID.ToString();
|
|
cr.CREATEDATE = System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
|
|
cr.MATERIAL_CODE = dt.Rows[i]["MATERIAL_CODE"].ToString();
|
|
cr.MATERIAL_TYPE_CODE = dt.Rows[i]["MATERIAL_TYPE_CODE"].ToString();
|
|
cr.QTY = (Convert.ToInt32(dt.Rows[i]["QC"]) > 0) ? Convert.ToInt32(dt.Rows[i]["QC"]).ToString() : Convert.ToInt32(dt.Rows[i]["CQ"]).ToString();
|
|
cr.COMPARERESULT = (Convert.ToInt32(dt.Rows[i]["QC"]) > 0) ?
|
|
EnumGeter.COMPARERESULT.GAIN.GetHashCode().ToString()
|
|
: EnumGeter.COMPARERESULT.LOSS.GetHashCode().ToString();
|
|
|
|
actualNumber += Convert.ToInt32(dt.Rows[i]["QTY"]);
|
|
registNumber += Convert.ToInt32(dt.Rows[i]["CAPACITY"]);
|
|
|
|
resultList.Add(cr);
|
|
}
|
|
|
|
plan.ACTUALNUMBER = actualNumber;
|
|
plan.REGISTNUMBER = registNumber;
|
|
plan.PLAN_STATE = "1";
|
|
|
|
#endregion
|
|
}
|
|
|
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
|
{
|
|
session.OpenTs();
|
|
|
|
dal.UpdatePlan(plan);
|
|
|
|
dal.BaseSession = session;
|
|
|
|
dal.DeletResultInfo(PID);
|
|
|
|
foreach (var re in resultList)
|
|
{
|
|
session.Insert<CountResultInfo>(re);
|
|
}
|
|
session.CommitTs();
|
|
|
|
result.Result = resultList.Count;
|
|
}
|
|
|
|
result.IsSuccess = true;
|
|
return result;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
result.IsSuccess = false;
|
|
throw ex;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region 获取盘点对比结果查询
|
|
/// <summary>
|
|
/// 获取盘点对比结果查询
|
|
/// </summary>
|
|
/// <param name="condition">条件</param>
|
|
/// <param name="page">数据页</param>
|
|
/// <returns>数据页</returns>
|
|
public DataResult<DataPage> GetPanResultDetail(string PID, DataPage page)
|
|
{
|
|
DataResult<DataPage> result = new DataResult<DataPage>();
|
|
try
|
|
{
|
|
result.IsSuccess = true;
|
|
page = new StocktakingDAL().GetPanResultDetail(PID, page);
|
|
List<CountResultInfo> list = page.Result as List<CountResultInfo>;
|
|
result.Result = page;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
return result;
|
|
}
|
|
#endregion
|
|
|
|
#region 手持插入表T_PP_COUNTSHEET
|
|
/// <summary>
|
|
/// 手持插入表
|
|
/// </summary>
|
|
/// <param name="model"></param>
|
|
/// <returns></returns>
|
|
public DataResult<CountSheetInfo> InsertCountSheet(CountSheetInfo model)
|
|
{
|
|
DataResult<CountSheetInfo> result = new DataResult<CountSheetInfo>();
|
|
result.Result = model;
|
|
try
|
|
{
|
|
StocktakingDAL stdal = new StocktakingDAL();
|
|
//有产品条码,查询产品条码信息
|
|
if (!string.IsNullOrEmpty(model.PRODUCTCODE))
|
|
{
|
|
if (System.Text.RegularExpressions.Regex.IsMatch(model.PRODUCTCODE, "^DP\\w+(-\\w+)?-DF[LR][FR]\\w+$"))//扫描输入为门板计划标签
|
|
{
|
|
//从计划标签中截取产品码
|
|
model.PRODUCTCODE = model.PRODUCTCODE.Substring(model.PRODUCTCODE.LastIndexOf('-') + 1);
|
|
return result;
|
|
}
|
|
//此产查验品条码是否存在于T_AW_PRODUCT表
|
|
Product product = new ProductDAL().GetProductByAssembleCode(model.PRODUCTCODE);
|
|
if (product == null)
|
|
{
|
|
result.IsSuccess = false;
|
|
result.Msg = "产品信息不存在!";
|
|
return result;
|
|
}
|
|
else
|
|
model.PRODUCTCODE = product.PRODUCTCODE;
|
|
model.MAINCODE = product.MAINCODE;
|
|
model.MATERIAL_CODE = product.MATERIAL_CODE;
|
|
//model.MATERIALNAME = product.MACHINENAME;
|
|
//model.PRODUCTCODE = product.PRODUCTCODE;
|
|
//model.QTY = product.CAPACITY - product.USINGCOUNT;
|
|
model.MATERIAL_TYPE_CODE = product.MATERIAL_TYPE;
|
|
model.QTY = 1;
|
|
|
|
//查验此产品条码是否已经盘点
|
|
CountSheetInfo information = new StocktakingDAL().GetStocktaking(new CountSheetInfo { PRODUCTCODE = model.PRODUCTCODE, PLAN_NO = model.PLAN_NO });
|
|
if (information != null)
|
|
{
|
|
result.IsSuccess = false;
|
|
result.Msg = "此产品已盘点,无需重复扫描!";
|
|
return result;
|
|
}
|
|
}
|
|
Countingplaninfo palnid = new StocktakingDAL().GetPlanId(new Countingplaninfo { PLAN_NO = model.PLAN_NO });
|
|
if (palnid == null)
|
|
{
|
|
result.IsSuccess = false;
|
|
result.Msg = "盘点计划已失效或删除!";
|
|
return result;
|
|
}
|
|
model.PLANID = palnid.PID;
|
|
//无产品条码,查验物料信息
|
|
if (model.MATERIAL_CODE == "")
|
|
{
|
|
result.IsSuccess = false;
|
|
result.Msg = "物料信息不能为空!";
|
|
return result;
|
|
}
|
|
MD.Entity.Material material = stdal.IsPlanMaterial(model.PLANID, model.MATERIAL_CODE);
|
|
if (material == null)
|
|
{
|
|
result.IsSuccess = false;
|
|
result.Msg = "此产品物料不在当前盘点计划内!";
|
|
return result;
|
|
}
|
|
model.MATERIALNAME = material.MATERIAL_NAME;
|
|
model.MATERIAL_TYPE_CODE = material.MATERIAL_TYPE_CODE;
|
|
|
|
//基本信息
|
|
model.PID = Guid.NewGuid().ToString();
|
|
//model.CREATEUSER = base.LoginUser.UserID;
|
|
model.CREATEDATE = DateTime.Now;
|
|
model.COUNT_DATE = model.CREATEDATE;
|
|
//model.UPDATEUSER = base.LoginUser.UserID;
|
|
model.UPDATEDATE = model.CREATEDATE;
|
|
StocktakingDAL cmdDAL = new StocktakingDAL();
|
|
var ret = new StocktakingDAL().InsertCountSheet(model);
|
|
result.IsSuccess = true;
|
|
result.Msg = Resource.MsgSuccess;
|
|
model.MATERIALNAME = material.MATERIAL_SHORT;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
LogManager.LogHelper.Error(new LogInfo()
|
|
{
|
|
ErrorInfo = ex,
|
|
Tag = ex.StackTrace,
|
|
Info = "盘点计划-插入信息"
|
|
});
|
|
result.IsSuccess = false;
|
|
result.Msg = Resource.SystemException;
|
|
}
|
|
return result;
|
|
}
|
|
#endregion
|
|
|
|
#region 手持获取物料信息
|
|
/// <summary>
|
|
/// 手持获取物料信息
|
|
/// </summary>
|
|
/// <param name="PLANID"></param>
|
|
/// <returns></returns>
|
|
public List<Entity.MD.Material> GetMaterialOfPlan(string PLANID)
|
|
{
|
|
return new StocktakingDAL().GetMaterialOfPlan(PLANID);
|
|
}
|
|
#endregion
|
|
|
|
#region 获取导出的数据
|
|
/// <summary>
|
|
/// 获取导出的数据
|
|
/// </summary>
|
|
/// <param name="user">查询条件</param>
|
|
/// <returns>数据</returns>
|
|
public DataTable GetExportData(string PID)
|
|
{
|
|
try
|
|
{
|
|
return new StocktakingDAL().GetExportData(PID);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region 盘点完成
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="PID"></param>
|
|
/// <returns></returns>
|
|
public DataResult<int> CompleteCompare(string PID)
|
|
{
|
|
DataResult<int> result = new DataResult<int>();
|
|
|
|
StocktakingDAL dal = new StocktakingDAL();
|
|
Countingplaninfo plan = dal.Get(new Countingplaninfo() { PID = PID });
|
|
plan.PLAN_STATE = "2";
|
|
|
|
List<CountingdetailInfo> detailList = dal.GetCountDetailList(new CountingdetailInfo() { PLANID = plan.PID});
|
|
|
|
ProductDAL productDal = new ProductDAL();
|
|
ScrapRecordDAL scarpDal = new ScrapRecordDAL();
|
|
|
|
//获取所有的比对结果
|
|
List<CountResultInfo> resultInfoList = new List<CountResultInfo>();
|
|
resultInfoList = dal.GetResultInfoList(PID);
|
|
|
|
Dictionary<string, int> dict = new Dictionary<string, int>();
|
|
|
|
//遍历盘点计划下所有的零件号信息
|
|
foreach (var d in detailList)
|
|
{
|
|
#region 统计差额数量
|
|
//如果盘点对比结果中没有差异,直接跳过
|
|
if (resultInfoList.Count(o => o.MATERIAL_CODE == d.MATERIAL_CODE) == 0)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
int gainQTY = 0;
|
|
int lossQTY = 0;
|
|
|
|
gainQTY = resultInfoList.Where(
|
|
o => o.COMPARERESULT == EnumGeter.COMPARERESULT.GAIN.GetHashCode().ToString() && o.MATERIAL_CODE == d.MATERIAL_CODE)
|
|
.Sum(o => Convert.ToInt32(o.QTY));
|
|
|
|
lossQTY = resultInfoList.Where(
|
|
o => o.COMPARERESULT == EnumGeter.COMPARERESULT.LOSS.GetHashCode().ToString() && o.MATERIAL_CODE == d.MATERIAL_CODE)
|
|
.Sum(o => Convert.ToInt32(o.QTY));
|
|
|
|
CountResultInfo info = resultInfoList.First(o => o.MATERIAL_CODE == d.MATERIAL_CODE);
|
|
|
|
dict.Add(d.MATERIAL_CODE, gainQTY - lossQTY);
|
|
|
|
#endregion
|
|
}
|
|
|
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
|
{
|
|
session.OpenTs();
|
|
|
|
#region 更新差额数量
|
|
|
|
foreach (var v in dict.Keys)
|
|
{
|
|
string upsql = string.Format("update T_PP_COUNTRESULTVALUE set CHECKRESULT={0} where MATERIAL_CODE='{1}'", dict[v], v);
|
|
int i = session.ExecuteSql(upsql, new List<DataParameter>().ToArray());
|
|
if (i == 0)
|
|
{
|
|
string insertSql = string.Format("insert into T_PP_COUNTRESULTVALUE values(NEWID(),'{0}',{1},'{2}')", v, dict[v], System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
|
|
i = session.ExecuteSql(insertSql, new List<DataParameter>().ToArray());
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
//更新计划
|
|
session.Update<Countingplaninfo>(plan);
|
|
|
|
session.CommitTs();
|
|
}
|
|
|
|
if (plan.COUNTTYPE == EnumGeter.COUNTTYPE.CHECKBYCODE.GetHashCode().ToString())
|
|
{
|
|
Task task = new Task(() =>
|
|
{
|
|
StocktakingDAL deal = new StocktakingDAL();
|
|
deal.ProductInOutDeal(plan);
|
|
});
|
|
|
|
task.Start();
|
|
}
|
|
|
|
result.IsSuccess = true;
|
|
result.Result = 1;
|
|
return result;
|
|
|
|
}
|
|
|
|
#endregion
|
|
|
|
}
|
|
}
|
|
|