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.
345 lines
13 KiB
345 lines
13 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Web;
|
|
using Warehouse.DAL.DelContainer;
|
|
using Warehouse.Models.mesModel;
|
|
using Warehouse.Models.whMS;
|
|
using Z.EntityFramework.Plus;
|
|
|
|
namespace Warehouse.DAL.StockIn
|
|
{
|
|
public class StockInMSDal
|
|
{
|
|
public List<tstock> QueryStock()
|
|
{
|
|
using (var context = new whMSModel())
|
|
{
|
|
return context.tstocks.Where(a => a.type == "成品仓").ToList();
|
|
}
|
|
}
|
|
|
|
public List<tstoragelocation> QueryLocationByStock(int stockid)
|
|
{
|
|
using (var context = new whMSModel())
|
|
{
|
|
return context.tstoragelocations.Where(a => a.stockid == stockid).ToList();
|
|
}
|
|
}
|
|
|
|
public tlocationcondition QueryLocationCondiction(int LocationId)
|
|
{
|
|
using (var context = new whMSModel())
|
|
{
|
|
return context.tlocationconditions.Where(a => a.status == "Y" && a.storagelocationid == LocationId).FirstOrDefault<tlocationcondition>();
|
|
}
|
|
}
|
|
|
|
//查询库位条件并且是实际值,库位条件表保存的是组件类型的id和晶体类型的id
|
|
public dynamic QueryLocationCondictionValue(int LocationId)
|
|
{
|
|
string sql = @"select [powergrade]
|
|
,[color]
|
|
,[igrade]
|
|
,[celltype]
|
|
,[finalgrade]
|
|
,[cellqty]
|
|
,[frame]
|
|
,[jbox]
|
|
,[bartype],b.source_desc as bartypevalue
|
|
,[modulespec],c.source_desc as modulespecvalue
|
|
,(select count(*) from tstockinlog where status=2 and storagelocationid =@locationid ) as locationqty
|
|
from tlocationcondition a
|
|
left join mes_main.dbo.df_source b on a.bartype = b.source_id
|
|
left join mes_main.dbo.df_source c on a.modulespec = c.source_id
|
|
where a.status = 'Y' and a.storagelocationid =@locationid ";
|
|
using (var context = new whMSModel())
|
|
{
|
|
var res = context.DynamicListFromSql(sql, new Dictionary<string, object> { { "locationid", LocationId } });
|
|
if (res.Count() != 0)
|
|
{
|
|
return res.FirstOrDefault();
|
|
}
|
|
else
|
|
{
|
|
return res.ToList();
|
|
}
|
|
}
|
|
}
|
|
|
|
//查询所有可用的库位条件
|
|
public List<dynamic> QueryAllLocationCondction()
|
|
{
|
|
using (var context = new whMSModel())
|
|
{
|
|
string sql = @"select a.*,[storagelocationid]
|
|
,[powergrade]
|
|
,[color]
|
|
,[igrade]
|
|
,[celltype]
|
|
,[finalgrade]
|
|
,[cellqty]
|
|
,[frame]
|
|
,[jbox]
|
|
,[bartype]
|
|
,[modulespec]
|
|
,[status]
|
|
,[createuser]
|
|
,[createtime] from tstoragelocation a
|
|
inner join tstock b on a.stockid = b.id and b.type = '成品仓'
|
|
left join tlocationcondition c on c.storagelocationid = a.id and c.status='Y'";
|
|
var res = context.DynamicListFromSql(sql, null);
|
|
if (res != null)
|
|
{
|
|
return res.ToList();
|
|
}
|
|
else
|
|
{
|
|
return null;
|
|
}
|
|
}
|
|
}
|
|
|
|
public pack_pallets QueryPallet(string Pallet)
|
|
{
|
|
using (var context = new mesModel())
|
|
{
|
|
return context.pack_pallets.Where(a => a.pallet_nbr == Pallet).FirstOrDefault<pack_pallets>();
|
|
|
|
}
|
|
}
|
|
|
|
//public List<dynamic> QueryPallet(string Pallet)
|
|
//{
|
|
// using (var context = new whMSModel())
|
|
// {
|
|
// string sql = @"select * from [mes_main].[dbo].[pack_pallets] where pallet_nbr = '" + Pallet + "'";
|
|
// var res = context.DynamicListFromSql(sql, null);
|
|
// return res.ToList();
|
|
// }
|
|
//}
|
|
|
|
|
|
public config_products QueryProduct(string product)
|
|
{
|
|
using (var context = new mesModel())
|
|
{
|
|
return context.config_products.Where(a => a.product_code == product).FirstOrDefault<config_products>();
|
|
}
|
|
}
|
|
|
|
public int StockIn(tstockinlog Obj)
|
|
{
|
|
using (var context = new whMSModel())
|
|
{
|
|
context.tstockinlogs.Add(Obj);
|
|
return context.SaveChanges();
|
|
}
|
|
}
|
|
|
|
public int UpdatePalletStatus(int Status, string Pallet)
|
|
{
|
|
using (var context = new mesModel())
|
|
{
|
|
return context.pack_pallets.Where(a => a.pallet_nbr == Pallet).Update(x => new pack_pallets() { pallet_status = Convert.ToByte(Status) });
|
|
}
|
|
}
|
|
|
|
public tlocationcondition AddLocationCondiction(tlocationcondition Obj)
|
|
{
|
|
using (var context = new whMSModel())
|
|
{
|
|
context.tlocationconditions.Add(Obj);
|
|
context.SaveChanges();
|
|
return Obj;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
//add by xue lei on 2018-8-25 柜号入库
|
|
public ReturnMsg ContainerStockIn(string Container, int LocationId, ref tlocationcondition CondictionPara, ref List<dynamic> ListPara)
|
|
{
|
|
using (var context = new whMSModel())
|
|
{
|
|
//0.9柜号里的托盘是否入库
|
|
var ConrainerStockInfo = new DelContainerMSDal().QueryStockInfoByContianer(Container);
|
|
|
|
if (ConrainerStockInfo != null)
|
|
{
|
|
var PalletInfo = ConrainerStockInfo.FirstOrDefault();
|
|
if (PalletInfo.stockinstatus == 2)
|
|
{
|
|
return new ReturnMsg { res = "fail", msg = "柜号里的托盘:" + PalletInfo.palletno + " 已经入库,库位:" + PalletInfo.location };
|
|
}
|
|
if (PalletInfo.stockinstatus == 4)
|
|
{
|
|
return new ReturnMsg { res = "fail", msg = "柜号里的托盘:" + PalletInfo.palletno + " 已经监装" };
|
|
}
|
|
if (PalletInfo.stockinstatus == 3)
|
|
{
|
|
return new ReturnMsg { res = "fail", msg = "柜号里的托盘:" + PalletInfo.palletno + " 已经出货" };
|
|
}
|
|
}
|
|
|
|
//1、库位为空用柜号的条件
|
|
tcontainer ContainerObj = new tcontainer();
|
|
ContainerObj = context.tcontainers.First(a => a.containerno == Container);
|
|
long CondictionId = 0;
|
|
var LocationCondiction = context.tlocationconditions.Where(a => a.status == "Y" && a.storagelocationid == LocationId).FirstOrDefault();
|
|
if (LocationCondiction == null)
|
|
{
|
|
tlocationcondition LocationCondictionObj = new tlocationcondition();
|
|
LocationCondictionObj.bartype = ContainerObj.bartype;
|
|
LocationCondictionObj.cellqty = ContainerObj.cellqty;
|
|
LocationCondictionObj.celltype = ContainerObj.celltype;
|
|
LocationCondictionObj.color = ContainerObj.color;
|
|
LocationCondictionObj.finalgrade = ContainerObj.finalgrade;
|
|
LocationCondictionObj.powergrade = ContainerObj.powergrade;
|
|
LocationCondictionObj.igrade = ContainerObj.igrade;
|
|
LocationCondictionObj.modulespec = ContainerObj.modulespec;
|
|
LocationCondictionObj.jbox = ContainerObj.jbox;
|
|
LocationCondictionObj.status = "Y";
|
|
LocationCondictionObj.frame = ContainerObj.frame;
|
|
LocationCondictionObj.createtime = System.DateTime.Now;
|
|
LocationCondictionObj.createuser = System.Web.HttpContext.Current.Request.Cookies["userid"].Value.ToString();
|
|
LocationCondictionObj.storagelocationid = LocationId;
|
|
|
|
context.tlocationconditions.Add(LocationCondictionObj);
|
|
context.SaveChanges();
|
|
CondictionId = LocationCondictionObj.id;
|
|
CondictionPara = LocationCondictionObj;
|
|
}
|
|
else
|
|
{
|
|
//2、检查库位条件和柜号条件是否匹配
|
|
var LocationCondictionMS = LocationCondiction;
|
|
CondictionPara = LocationCondiction;
|
|
CondictionId = LocationCondictionMS.id;
|
|
//电压
|
|
if ((LocationCondictionMS.powergrade ?? "") != (ContainerObj.powergrade ?? ""))
|
|
{
|
|
return new ReturnMsg { res = "fail", msg = "柜号功率和库位条件不一致" };//Json(new { result = "fail", msg = "托盘电压和库位条件不一致" });
|
|
}
|
|
//电流
|
|
if ((LocationCondictionMS.igrade ?? "") != (ContainerObj.igrade ?? ""))
|
|
{
|
|
return new ReturnMsg { res = "fail", msg = "柜号电流和库位条件不一致" };//Json(new { result = "fail", msg = "托盘电流和库位条件不一致" });
|
|
}
|
|
//等级
|
|
if ((LocationCondictionMS.finalgrade ?? "") != (ContainerObj.finalgrade ?? ""))
|
|
{
|
|
return new ReturnMsg { res = "fail", msg = "柜号最终等级和库位条件不一致" };//Json(new { result = "fail", msg = "托盘最终等级和库位条件不一致" });
|
|
}
|
|
//颜色
|
|
if ((LocationCondictionMS.color ?? "") != (ContainerObj.color ?? ""))
|
|
{
|
|
return new ReturnMsg { res = "fail", msg = "柜号颜色和库位条件不一致" };//Json(new { result = "fail", msg = "托盘颜色和库位条件不一致" });
|
|
}
|
|
//电池片数量
|
|
if ((LocationCondictionMS.cellqty ?? "") != (ContainerObj.cellqty ?? ""))
|
|
{
|
|
return new ReturnMsg { res = "fail", msg = "柜号电池片数量和库位条件不一致" };//Json(new { result = "fail", msg = "托盘电池片数量和库位条件不一致" });
|
|
}
|
|
//晶体类型
|
|
if ((LocationCondictionMS.bartype ?? "") != (ContainerObj.bartype ?? ""))
|
|
{
|
|
return new ReturnMsg { res = "fail", msg = "柜号晶体类型和库位条件不一致" };//Json(new { result = "fail", msg = "托盘晶体类型和库位条件不一致" });
|
|
}
|
|
//组件类型
|
|
if ((LocationCondictionMS.modulespec ?? "") != (ContainerObj.modulespec ?? ""))
|
|
{
|
|
return new ReturnMsg { res = "fail", msg = "柜号组件类型和库位条件不一致" };//Json(new { result = "fail", msg = "托盘组件类型和库位条件不一致" });
|
|
}
|
|
}
|
|
|
|
ListPara = ConrainerStockInfo.ToList();
|
|
|
|
//柜号入库
|
|
List<tstockinlog> AllPallets = new List<tstockinlog>();
|
|
AllPallets = GetAllPallets(Container, LocationId, CondictionId);
|
|
context.Configuration.AutoDetectChangesEnabled = false;
|
|
context.tstockinlogs.AddRange(AllPallets);
|
|
context.SaveChanges();
|
|
//context.tstockinlogs.BulkInsert(AllPallets);
|
|
return new ReturnMsg { res = "success", msg = "" };
|
|
}
|
|
|
|
}
|
|
|
|
List<tstockinlog> GetAllPallets(string Container, int LocationId, long CondictionId)
|
|
{
|
|
using (var context = new whMSModel())
|
|
{
|
|
var ContainerPallets = context.tcontainerpallets.Where(a => a.containerno == Container);
|
|
List<tstockinlog> List = new List<tstockinlog>();
|
|
foreach (var item in ContainerPallets)
|
|
{
|
|
Models.whMS.tstockinlog stockinloginfo = new Models.whMS.tstockinlog();
|
|
stockinloginfo.palletno = item.palletno;
|
|
stockinloginfo.status = 2;//2代表已经入库 1代表已经申请入库
|
|
stockinloginfo.storagelocationid = LocationId;
|
|
stockinloginfo.storagelocationconditionid = CondictionId;
|
|
stockinloginfo.createtime = System.DateTime.Now;
|
|
stockinloginfo.createuser = System.Web.HttpContext.Current.Request.Cookies["userid"].Value.ToString();
|
|
List.Add(stockinloginfo);
|
|
}
|
|
return List;
|
|
}
|
|
}
|
|
|
|
//托盘是否OQC报检审核完成
|
|
public dynamic PalletIsQC(string Pallet)
|
|
{
|
|
using (var context = new whMSModel())
|
|
{
|
|
string Sql = @"select a.pallet_nbr as pallet,a.check_nbr as checknbr,b.check_status as checkstatus from mes_main.dbo.pack_pallets a left join mes_main.dbo.pallets_check b on a.check_nbr = b.check_nbr where a.pallet_nbr=@pallet and exists(select * from wh.dbo.tqcisenable a where a.isenable='Y') ";
|
|
|
|
var res = context.DynamicListFromSql(Sql, new Dictionary<string, object> { { "pallet", Pallet } });
|
|
return res.FirstOrDefault();
|
|
|
|
}
|
|
}
|
|
|
|
//入库进行柜号状态判断
|
|
public List<dynamic> judgeContainerStatus(string Containerno)
|
|
{
|
|
using (var context = new whMSModel())
|
|
{
|
|
string sql = @"select * from [wh].[dbo].[tcontainer] where containerno = '"+ Containerno + "'";
|
|
var res = context.DynamicListFromSql(sql, null);
|
|
return res.ToList();
|
|
}
|
|
}
|
|
|
|
|
|
//托盘入库进行托盘号状态判断
|
|
public List<dynamic> judgePalletStatus(string Palletno)
|
|
{
|
|
using (var context = new whMSModel())
|
|
{
|
|
string sql = @"select pallet_nbr,isnull(oba_spot_check,'') oba_spot_check from [mes_main].[dbo].[pack_pallets] where pallet_nbr = '" + Palletno + "'";
|
|
var res = context.DynamicListFromSql(sql, null);
|
|
return res.ToList();
|
|
}
|
|
}
|
|
|
|
|
|
//查询托盘内序列号信息
|
|
public List<dynamic> serialInfo(string Palletno)
|
|
{
|
|
using (var context = new whMSModel())
|
|
{
|
|
string sql = @"select serial_nbr,final_grade from [mes_main].[dbo].[assembly_status] where pallet_nbr = '" + Palletno + "'";
|
|
var res = context.DynamicListFromSql(sql, null);
|
|
return res.ToList();
|
|
}
|
|
}
|
|
}
|
|
//public class ReturnMsg
|
|
//{
|
|
// public string res { get; set; }
|
|
// public string msg { get; set; }
|
|
|
|
//}
|
|
}
|
|
|