using System;
|
using System.Collections.Generic;
|
using System.Linq;
|
using System.Text;
|
using System.Data.SqlClient;
|
using CY.IDAL;
|
using CY.Model;
|
using CY.Infrastructure.Configuration;
|
using CY.Infrastructure.Common;
|
using CY.BLL;
|
using System.Transactions;
|
using CY.Infrastructure.Query;
|
namespace CY.BLL.OA
|
{
|
public class OA_OutOfStorageBLL
|
{
|
OA_InventoryBLL _OA_InventoryBLL = null;
|
IOA_OutOfStorageDAL outOfStorageDAL = null;
|
OA_ProcurementBLL bll_OA_ProcurementBLL = null;
|
OA_ProcurementBLL _OA_ProcurementBLL = null;
|
|
public OA_OutOfStorageBLL()
|
{
|
_OA_ProcurementBLL = new OA_ProcurementBLL();
|
_OA_InventoryBLL = new OA_InventoryBLL();
|
outOfStorageDAL = AbstractFactory.Factory.GetDALByInterfaceName(AbstractFactory.DALInterface.IOA_OutOfStorageDAL) as IOA_OutOfStorageDAL;
|
bll_OA_ProcurementBLL = new OA_ProcurementBLL();
|
|
}
|
|
public bool InertModel(OA_OutOfStorage outOfStorage)
|
{
|
return outOfStorageDAL.InserModel(outOfStorage);
|
|
}
|
|
public bool UpdateModel(OA_OutOfStorage model)
|
{
|
return outOfStorageDAL.UpdateModel(model);
|
}
|
|
/// <summary>
|
/// 增加一条入库信息
|
/// </summary>
|
/// <param name="model"></param>
|
/// <returns></returns>
|
public bool InsertModel(OA_Inventory inventory, OA_OutOfStorage outOfStorage)
|
{
|
bool isSuccess = true;
|
OA_Inventory m_OA_Inventory = _OA_InventoryBLL.IfHasModel(inventory);
|
if (m_OA_Inventory != null)//如果所选货位存在此产品
|
{
|
using (TransactionScope scope = new TransactionScope())
|
{
|
isSuccess = outOfStorageDAL.InserModel(outOfStorage);
|
if (isSuccess)
|
{
|
if (outOfStorage.InfoType == "出库")
|
{
|
m_OA_Inventory.InventoryCount -= outOfStorage.Quantity;//出库数据量减
|
}
|
else
|
{
|
m_OA_Inventory.InventoryCount += outOfStorage.Quantity;//出库数据量减
|
}
|
m_OA_Inventory.TotalPrice = (m_OA_Inventory.UnitPrice ?? 0) * (m_OA_Inventory.InventoryCount ?? 0);
|
isSuccess = _OA_InventoryBLL.UpdateModel(m_OA_Inventory);
|
}
|
if (isSuccess)
|
scope.Complete();
|
}
|
return isSuccess;
|
}
|
else//如果所选货位不存在此产品
|
{
|
using (TransactionScope scope = new TransactionScope())
|
{
|
isSuccess = outOfStorageDAL.InserModel(outOfStorage);
|
if (isSuccess)
|
{
|
inventory.TotalPrice = (inventory.UnitPrice ?? 0) * (inventory.InventoryCount ?? 0);
|
isSuccess = _OA_InventoryBLL.InsertModel(inventory);
|
}
|
if (isSuccess)
|
scope.Complete();
|
}
|
return isSuccess;
|
}
|
}
|
|
public IEnumerable<Model.OA_OutOfStorage> getModelList(Pagination pa, Guid FirmId, string Operator, string InfoType, string SuppliersId, string GoodsNameId, string WarehouseId, DateTime? beginTime, DateTime? endTime, string BrandName, string SpeceicationName, string PaperWeightName, string GoodsTypeId)
|
{
|
return outOfStorageDAL.getModelList(pa, FirmId, Operator, InfoType, SuppliersId, GoodsNameId, WarehouseId, beginTime, endTime, BrandName, SpeceicationName, PaperWeightName, GoodsTypeId);
|
}
|
|
public bool InsertModelList(string[] Keys, int? WarehouseId, string WarehouseName )
|
{
|
try
|
{
|
bool isSuccess = true;
|
using (TransactionScope scope = new TransactionScope())
|
{
|
foreach (var Keyid in Keys)
|
{
|
|
OA_Procurement m_OA_Procurement = new OA_Procurement();
|
OA_Inventory m_OA_Inventory = new OA_Inventory();
|
OA_OutOfStorage m_OA_OutOfStorage = new OA_OutOfStorage();
|
OA_WarehouseInfo m_OA_WarehouseInfo = new OA_WarehouseInfo();
|
OA_WarehouseInfoBLL bll_OA_WarehouseInfoBLL = new OA_WarehouseInfoBLL();
|
|
m_OA_WarehouseInfo = bll_OA_WarehouseInfoBLL.getSingleModel(WarehouseId.ToString());
|
|
m_OA_Procurement = _OA_ProcurementBLL.SelectSingleModel(Keyid);
|
m_OA_Procurement.PurchaseStatusId = 201;
|
m_OA_Procurement.WarehouseName = m_OA_WarehouseInfo.WarehouseName;
|
if (!WarehouseName.Equals("上机使用"))
|
{
|
//库存表对象
|
m_OA_Inventory.CargoSpaceId = 0;
|
m_OA_Inventory.FirmId = m_OA_Procurement.FirmId;
|
m_OA_Inventory.GoodsId = m_OA_Procurement.GoodsId;
|
m_OA_Inventory.InventoryCount = m_OA_Procurement.Quantity;
|
m_OA_Inventory.LastUpdateTime = DateTime.Now;
|
m_OA_Inventory.Operator = m_OA_Procurement.Operator;
|
m_OA_Inventory.Remark = "";
|
m_OA_Inventory.WarehouseId = WarehouseId;
|
m_OA_Inventory.BrandId = m_OA_Procurement.BrandId;
|
m_OA_Inventory.SpecificationId = m_OA_Procurement.SpecificationId;
|
m_OA_Inventory.PaperWeightId = m_OA_Procurement.PaperWeightId;
|
m_OA_Inventory.UnitPrice = m_OA_Procurement.Price ?? 0;
|
m_OA_Inventory.TotalPrice = m_OA_Procurement.AllMoney ?? 0;
|
|
//出入库信息表对象
|
m_OA_OutOfStorage.FirmId = m_OA_Procurement.FirmId;
|
m_OA_OutOfStorage.GoodsId = m_OA_Procurement.GoodsId;
|
m_OA_OutOfStorage.CargoSpaceId = 0;
|
m_OA_OutOfStorage.LastUpdateTime = DateTime.Now;
|
m_OA_OutOfStorage.Operator = m_OA_Procurement.Operator;
|
m_OA_OutOfStorage.Remark = "";
|
m_OA_OutOfStorage.WarehouseId = WarehouseId;
|
m_OA_OutOfStorage.SuppliersId = m_OA_Procurement.SuppliersId;
|
m_OA_OutOfStorage.AllMoney = m_OA_Procurement.AllMoney;
|
m_OA_OutOfStorage.InfoType = "入库";
|
m_OA_OutOfStorage.Price = m_OA_Procurement.Price;
|
m_OA_OutOfStorage.Quantity = m_OA_Procurement.Quantity;
|
m_OA_OutOfStorage.BrandId = m_OA_Procurement.BrandId;
|
m_OA_OutOfStorage.SpecificationId = m_OA_Procurement.SpecificationId;
|
m_OA_OutOfStorage.PaperWeightId = m_OA_Procurement.PaperWeightId;
|
m_OA_OutOfStorage.TanPrice = m_OA_Procurement.TanPrice ?? 0;
|
isSuccess = InsertModel(m_OA_Inventory, m_OA_OutOfStorage);
|
}
|
|
|
if (isSuccess)
|
{
|
isSuccess = bll_OA_ProcurementBLL.UpdateModel(m_OA_Procurement);
|
|
}
|
}
|
if (isSuccess)
|
scope.Complete();
|
}
|
|
return isSuccess;
|
}
|
catch (Exception ex)
|
{
|
throw ex;
|
}
|
}
|
|
/// <summary>
|
/// 获取单个信息
|
/// </summary>
|
/// <param name="Keyid"></param>
|
/// <returns></returns>
|
public OA_OutOfStorage GetModelByKeyid(int? Keyid)
|
{
|
return outOfStorageDAL.GetModelByKeyid(Keyid);
|
}
|
|
public OA_OutOfStorage GetModelInfo(int? keyid)
|
{
|
return outOfStorageDAL.GetModelInfo(keyid);
|
}
|
|
public bool GoodsOutofStorage(Model.OA_Inventory model, Model.OA_OutOfStorage OutOfStorage)
|
{
|
OA_Inventory m_OA_Inventory = _OA_InventoryBLL.IfHasModel(model);
|
if (m_OA_Inventory != null)//如果所选货位存在此产品
|
{
|
if (m_OA_Inventory.InventoryCount < OutOfStorage.Quantity)
|
{
|
return false;
|
}
|
else
|
{
|
m_OA_Inventory.InventoryCount = m_OA_Inventory.InventoryCount - OutOfStorage.Quantity;
|
bool isSuccess = _OA_InventoryBLL.UpdateModel(m_OA_Inventory);
|
if (isSuccess)
|
{
|
OutOfStorage.InfoType = "出库";
|
isSuccess = UpdateModel(OutOfStorage);
|
}
|
return isSuccess;
|
}
|
}
|
else
|
{
|
return false;
|
}
|
|
|
|
}
|
|
public IEnumerable<Model.OA_OutOfStorage> getModelList(Pagination pa, Guid FirmId, string Keyids)
|
{
|
return outOfStorageDAL.getModelList(pa, FirmId, Keyids);
|
}
|
}
|
}
|