using System;
using System.Collections.Generic;
using QMAPP.BLL;
using QMAPP.Entity;
using QMAPP.FJC.BLL.Dict;
using QMAPP.FJC.DAL.ProduceManage;
using QMAPP.FJC.Entity.ProduceManage;
using QMFrameWork.Data;
using QMFrameWork.Log;
using QMAPP.FJC.Entity;
using QMAPP.MD.Entity.TianJin;
using QMAPP.FJC.DAL.TianJin;
using System.Data;
namespace QMAPP.FJC.BLL.TianJin
{
///
/// 模块名称:天津--仓库信息
/// 作 者:张松男
/// 编写日期:2022年02月15日
///
public class StorageBLL : BaseBLL
{
#region 获取信息
///
/// 获取信息
///
/// 条件
/// 信息
public DataResult Get(Storage model)
{
DataResult result = new DataResult();
try
{
result.Result = new StorageDAL().Get(model);
result.IsSuccess = true;
}
catch (Exception ex)
{
LogManager.LogHelper.Error(new LogInfo()
{
ErrorInfo = ex,
Tag = ex.StackTrace,
Info = "获取异常!"
});
result.IsSuccess = false;
result.Ex = ex;
result.Msg = "获取异常";
}
return result;
}
#endregion
#region 获取列表
///
/// 获取列表
///
/// 条件
/// 数据页
/// 数据页
public DataResult GetList(Storage condition, DataPage page)
{
DataResult result = new DataResult();
try
{
DataPage dataPage = new StorageDAL().GetList(condition, page);
result.IsSuccess = true;
result.Result = dataPage;
}
catch (Exception ex)
{
LogManager.LogHelper.Error(new LogInfo()
{
ErrorInfo = ex,
Tag = ex.StackTrace,
Info = "获取列表异常!"
});
result.IsSuccess = false;
result.Ex = ex;
result.Msg = "获取列表异常!";
}
return result;
}
///
/// 获取列表
///
/// 条件
/// 全部集合
public List GetAllList()
{
try
{
//获取信息列表
return new StorageDAL().GetALL();
}
catch (Exception ex)
{
LogManager.LogHelper.Error(new LogInfo()
{
ErrorInfo = ex,
Tag = ex.StackTrace,
Info = "获取列表异常!"
});
throw ex;
}
}
#endregion
public DataResult SelectCount(string ProductCode)
{
DataResult result = new DataResult();
StorageDAL cmdDAL = new StorageDAL();
result.Result = cmdDAL.SelectCount(ProductCode);
return result;
}
#region 入库信息
///
/// 入库信息
///
/// 信息
/// 插入行数
public DataResult Insert(Storage info)
{
DataResult result = new DataResult();
try
{
//基本信息
info.PID = Guid.NewGuid().ToString();
info.CREATEUSER = this.LoginUser.UserName;
info.CREATEDATE = DateTime.Now.ToString();
info.UPDATEUSER = info.CREATEUSER;
info.UPDATEDATE = info.CREATEDATE;
//返迁入库,状态从前端传入 State=3
if (string.IsNullOrEmpty(info.State))
info.State = "1";
StorageDAL cmdDAL = new StorageDAL();
result.Result = cmdDAL.Insert(info);
var storageLog = new StorageLog();
storageLog.PID = Guid.NewGuid().ToString();
storageLog.CREATEUSER = this.LoginUser.UserName;
storageLog.CREATEDATE = DateTime.Now.ToString();
storageLog.UPDATEUSER = info.CREATEUSER;
storageLog.UPDATEDATE = info.CREATEDATE;
storageLog.State = "1";
storageLog.ProductCode = info.ProductCode;
storageLog.MATERIALCODE = info.MATERIALCODE;
storageLog.MATERIALNAME = info.MATERIALNAME;
storageLog.InStorageType = info.InStorageType;
//storageLog
StorageLogDAL cmdDALlog = new StorageLogDAL();
cmdDALlog.Insert(storageLog);
result.IsSuccess = true;
return result;
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 出库信息
///
/// 出库信息
///
///
/// 更新行数
public DataResult Update(Storage model)
{
DataResult result = new DataResult();
result.IsSuccess = true;
try
{
Storage info = new Storage();
if (!string.IsNullOrEmpty(model.ProductCode))
{
info = new StorageDAL().Get(model.ProductCode);
}
if (!string.IsNullOrEmpty(model.PID))
{
info = new StorageDAL().GetPID(model.PID);
}
//条码涉及到返迁入库,条码会有重复的可能
//if (info.State == "2")
//{
// result.IsSuccess = false;
// result.Msg = $"条码{model.ProductCode}在{info.UPDATEDATE}已进行过出库操作!";
// return result;
//}
int temp = 0;
//基本信息
if (!string.IsNullOrEmpty(model.State))
{
info.UPDATEDATE = DateTime.Now.ToString();
info.UPDATEUSER = this.LoginUser.UserName;
info.State = model.State;
temp = new StorageDAL().Update(info);
var storageLog2 = new StorageLog();
storageLog2.PID = Guid.NewGuid().ToString();
storageLog2.CREATEUSER = this.LoginUser.UserName;
storageLog2.CREATEDATE = DateTime.Now.ToString();
storageLog2.UPDATEUSER = info.CREATEUSER;
storageLog2.UPDATEDATE = info.CREATEDATE;
storageLog2.State = model.State;
storageLog2.ProductCode = info.ProductCode;
storageLog2.MATERIALCODE = info.MATERIALCODE;
storageLog2.MATERIALNAME = info.MATERIALNAME;
storageLog2.InStorageType = info.InStorageType;
StorageLogDAL cmdDALlog2 = new StorageLogDAL();
cmdDALlog2.Insert(storageLog2);
}
else
{
info.State = "2";
info.UPDATEDATE = DateTime.Now.ToString();
info.UPDATEUSER = this.LoginUser.UserName;
info.OutStorageType = model.OutStorageType;
temp = new StorageDAL().Update(info);
var storageLog = new StorageLog();
storageLog.PID = Guid.NewGuid().ToString();
storageLog.CREATEUSER = this.LoginUser.UserName;
storageLog.CREATEDATE = DateTime.Now.ToString();
storageLog.UPDATEUSER = info.CREATEUSER;
storageLog.UPDATEDATE = info.CREATEDATE;
storageLog.State = "2";
storageLog.ProductCode = info.ProductCode;
storageLog.MATERIALCODE = info.MATERIALCODE;
storageLog.MATERIALNAME = info.MATERIALNAME;
storageLog.InStorageType = info.InStorageType;
StorageLogDAL cmdDALlog = new StorageLogDAL();
cmdDALlog.Insert(storageLog);
}
if (temp == 0)
{
result.IsSuccess = false;
result.Msg = "更新失败!";
return result;
}
}
catch (Exception ex)
{
LogManager.LogHelper.Error(new LogInfo()
{
ErrorInfo = ex,
Tag = ex.StackTrace,
Info = "更新异常!"
});
result.IsSuccess = false;
result.Ex = ex;
result.Msg = "更新异常";
}
return result;
}
#endregion
#region 导出数据
///
/// 获取导出的数据
///
/// 查询条件
/// 数据
public DataTable GetExportData(Storage model)
{
try
{
return new StorageDAL().GetExportData(model);
}
catch (Exception ex)
{
LogManager.LogHelper.Error(new LogInfo()
{
ErrorInfo = ex,
Tag = ex.StackTrace,
Info = "导出库存信息"
});
throw ex;
}
}
#endregion
}
}