161 lines
6.1 KiB
C#
161 lines
6.1 KiB
C#
using FineUIPro;
|
|
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
|
|
|
|
namespace BLL
|
|
{
|
|
|
|
public static class TwMaterialstockService
|
|
{
|
|
|
|
|
|
|
|
#region 获取列表
|
|
/// <summary>
|
|
/// 记录数
|
|
/// </summary>
|
|
public static int Count
|
|
{
|
|
get;
|
|
set;
|
|
}
|
|
public static List<Model.Tw_MaterialStockOutput> GetTw_MaterialStockByModle(Model.Tw_MaterialStockOutput table)
|
|
{
|
|
using (Model.SGGLDB db = new Model.SGGLDB(Funs.ConnString))
|
|
{
|
|
var q = from x in db.Tw_MaterialStock
|
|
join mat in db.HJGL_MaterialCodeLib on x.PipeLineMatCode equals mat.MaterialCode into mm
|
|
from mat in mm.DefaultIfEmpty()
|
|
where
|
|
(string.IsNullOrEmpty(table.Id) || x.Id.Contains(table.Id)) &&
|
|
(string.IsNullOrEmpty(table.WarehouseCode) || x.WarehouseCode.Contains(table.WarehouseCode)) &&
|
|
(string.IsNullOrEmpty(table.PipeLineMatCode) || x.PipeLineMatCode.Contains(table.PipeLineMatCode)) &&
|
|
(string.IsNullOrEmpty(table.MaterialUnit) || mat.MaterialUnit.Contains(table.MaterialUnit)) &&
|
|
(string.IsNullOrEmpty(table.ProjectId) || x.ProjectId.Contains(table.ProjectId))
|
|
select new Model.Tw_MaterialStockOutput
|
|
{
|
|
Id = x.Id,
|
|
WarehouseCode = x.WarehouseCode,
|
|
PipeLineMatCode = x.PipeLineMatCode,
|
|
StockNum = x.StockNum,
|
|
ProjectId = x.ProjectId,
|
|
MaterialName = mat.MaterialName,
|
|
MaterialSpec = mat.MaterialSpec,
|
|
MaterialUnit = mat.MaterialUnit,
|
|
MaterialDef = mat.MaterialDef
|
|
}
|
|
;
|
|
|
|
return q.ToList();
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取分页列表
|
|
/// </summary>
|
|
/// <param name="table"></param>
|
|
/// <param name="grid1"></param>
|
|
/// <returns></returns>
|
|
public static IEnumerable GetListData(Model.Tw_MaterialStockOutput table, Grid grid1)
|
|
{
|
|
var q = GetTw_MaterialStockByModle(table);
|
|
Count = q.Count();
|
|
if (Count == 0)
|
|
{
|
|
return null;
|
|
}
|
|
q = q.Skip(grid1.PageSize * grid1.PageIndex).Take(grid1.PageSize).ToList();
|
|
// q = SortConditionHelper.SortingAndPaging(q, Grid1.SortField, Grid1.SortDirection, Grid1.PageIndex, Grid1.PageSize);
|
|
return from x in q
|
|
select x;
|
|
}
|
|
#endregion
|
|
|
|
public static Model.Tw_MaterialStock GetTw_MaterialStockById(string Id)
|
|
{
|
|
return Funs.DB.Tw_MaterialStock.FirstOrDefault(x => x.Id == Id);
|
|
}
|
|
|
|
public static void AddTw_MaterialStock(Model.Tw_MaterialStock newtable)
|
|
{
|
|
|
|
Model.Tw_MaterialStock table = new Model.Tw_MaterialStock
|
|
{
|
|
Id = newtable.Id,
|
|
WarehouseCode = newtable.WarehouseCode,
|
|
PipeLineMatCode = newtable.PipeLineMatCode,
|
|
StockNum = newtable.StockNum,
|
|
ProjectId = newtable.ProjectId,
|
|
};
|
|
Funs.DB.Tw_MaterialStock.InsertOnSubmit(table);
|
|
Funs.DB.SubmitChanges();
|
|
}
|
|
|
|
public static void UpdateTw_MaterialStock(Model.Tw_MaterialStock newtable)
|
|
{
|
|
|
|
Model.Tw_MaterialStock table = Funs.DB.Tw_MaterialStock.FirstOrDefault(x => x.Id == newtable.Id);
|
|
if (table != null)
|
|
{
|
|
table.Id = newtable.Id;
|
|
table.WarehouseCode = newtable.WarehouseCode;
|
|
table.PipeLineMatCode = newtable.PipeLineMatCode;
|
|
table.StockNum = newtable.StockNum;
|
|
table.ProjectId = newtable.ProjectId;
|
|
Funs.DB.SubmitChanges();
|
|
}
|
|
|
|
}
|
|
public static void DeleteTw_MaterialStockById(string Id)
|
|
{
|
|
|
|
Model.Tw_MaterialStock table = Funs.DB.Tw_MaterialStock.FirstOrDefault(x => x.Id == Id);
|
|
if (table != null)
|
|
{
|
|
Funs.DB.Tw_MaterialStock.DeleteOnSubmit(table);
|
|
Funs.DB.SubmitChanges();
|
|
}
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// 根据项目编码,材料编码,仓库编码,数量增减库存
|
|
/// </summary>
|
|
/// <param name="ProjectId"></param>
|
|
/// <param name="MaterialCode"></param>
|
|
/// <param name="WarehouseCode"></param>
|
|
/// <param name="inOutType"></param>
|
|
/// <param name="StockNum"></param>
|
|
public static void UpdateStockNum(string ProjectId, string MaterialCode, string WarehouseCode, TwConst.InOutType inOutType, decimal? StockNum)
|
|
{
|
|
Model.Tw_MaterialStock table = Funs.DB.Tw_MaterialStock.FirstOrDefault(x => x.ProjectId == ProjectId && x.PipeLineMatCode == MaterialCode && x.WarehouseCode == WarehouseCode);
|
|
//如果是入库,则库存数量加上,如果是出库,则库存数量减去
|
|
if (inOutType == TwConst.InOutType.出库)
|
|
{
|
|
StockNum = -StockNum;//出库,库存数量减去
|
|
}
|
|
if (table != null)
|
|
{
|
|
table.StockNum = table.StockNum ?? 0;
|
|
table.StockNum += StockNum;
|
|
Funs.DB.SubmitChanges();
|
|
}
|
|
else
|
|
{
|
|
Model.Tw_MaterialStock newtable = new Model.Tw_MaterialStock
|
|
{
|
|
Id = Guid.NewGuid().ToString(),
|
|
ProjectId = ProjectId,
|
|
PipeLineMatCode = MaterialCode,
|
|
WarehouseCode = WarehouseCode,
|
|
StockNum = StockNum ?? 0,
|
|
};
|
|
Funs.DB.Tw_MaterialStock.InsertOnSubmit(newtable);
|
|
Funs.DB.SubmitChanges();
|
|
}
|
|
}
|
|
}
|
|
} |