using System;
|
using System.Collections.Generic;
|
using System.ComponentModel;
|
using System.ComponentModel.Design;
|
using System.Data;
|
using System.Linq;
|
using System.Text;
|
using WMS.Entity.BllAsnEntity;
|
using WMS.Entity.BllCheckEntity;
|
using WMS.Entity.BllSoEntity;
|
using WMS.Entity.Context;
|
using WMS.Entity.LogEntity;
|
using WMS.Entity.SysEntity;
|
|
namespace WMS.DAL
|
{
|
public class Common
|
{
|
//public static readonly DataContext Db = new DataContext();
|
|
|
/// <summary>
|
/// 获取深度为1的储位号(根据深度为2的储位号)
|
/// </summary>
|
/// <param name="houseNo">仓库号</param>
|
/// <param name="locateNo">储位号</param>
|
/// <returns></returns>
|
public SysStorageLocat GetLocateNoDepth1(string houseNo, string locateNo)
|
{
|
try
|
{
|
var Db = DataContext.Db;
|
var ceshi = Db.Queryable<SysStorageLocat>()
|
.Where(m => m.IsDel == "0" && m.WareHouseNo == houseNo && m.LocatNo == locateNo).ToList();
|
|
//获取储位信息
|
var sql = $@"select * from SysStorageLocat where WareHouseNo = '{houseNo}' and LocatNo = '{locateNo}'; ";
|
var locate = Db.Ado.SqlQuery<SysStorageLocat>(sql).First();
|
if (locate == null)
|
{
|
throw new Exception($"未查询到仓库号为{houseNo}、储位号为{locateNo}的信息");
|
}
|
//获取深度为2的储位信息
|
var sql2 = $@"select * from SysStorageLocat where WareHouseNo = '{houseNo}' and row = {locate.Row} and [Column] = {locate.Column} and Layer = {locate.Layer} and Depth = '01'; ";
|
var data = Db.Ado.SqlQuery<SysStorageLocat>(sql2).First();
|
if (data == null)
|
{
|
throw new Exception($"未查询到仓库号为{houseNo}、储位号为{locateNo}的里面储位信息");
|
}
|
|
return data;
|
}
|
catch (Exception e)
|
{
|
throw new Exception(e.Message);
|
}
|
}
|
/// <summary>
|
/// 获取深度为2的储位号(根据深度为1的储位号)
|
/// </summary>
|
/// <param name="houseNo">仓库号</param>
|
/// <param name="locateNo">储位号</param>
|
/// <returns></returns>
|
public SysStorageLocat GetLocateNoDepth2(string houseNo, string locateNo)
|
{
|
try
|
{
|
var Db = DataContext.Db;
|
//获取储位信息
|
var sql = $@"select * from SysStorageLocat where WareHouseNo = '{houseNo}' and LocatNo = '{locateNo}'; ";
|
var locate = Db.Ado.SqlQuery<SysStorageLocat>(sql).First();
|
if (locate == null)
|
{
|
throw new Exception($"未查询到仓库号为{houseNo}、储位号为{locateNo}的信息");
|
}
|
//获取深度为2的储位信息
|
var sql2 = $@"select * from SysStorageLocat where WareHouseNo = '{houseNo}' and row = {locate.Row} and [Column] = {locate.Column} and Layer = {locate.Layer} and Depth = '02'; ";
|
var data = Db.Ado.SqlQuery<SysStorageLocat>(sql2).First();
|
if (data == null)
|
{
|
throw new Exception($"未查询到仓库号为{houseNo}、储位号为{locateNo}的里面储位信息");
|
}
|
return data;
|
}
|
catch (Exception e)
|
{
|
throw new Exception(e.Message);
|
}
|
}
|
|
/// <summary>
|
/// 根据前缀获取最大单据号
|
/// </summary>
|
/// <param name="codeFlag">单据前缀</param>
|
/// <returns></returns>
|
public string GetMaxNo(string codeFlag)
|
{
|
try
|
{
|
var maxNo = "";
|
//获取异常号
|
maxNo = SelectMaxNo(codeFlag);
|
if (!string.IsNullOrEmpty(maxNo))
|
{
|
maxNo = maxNo.Substring(codeFlag.Length);
|
}
|
//获取数据库时间八位
|
string date = DateTime.Now.ToString("yyyyMMdd").Trim();
|
string no = "";
|
if (string.IsNullOrEmpty(maxNo))
|
{
|
no = codeFlag + date + "00001";
|
}
|
else
|
{
|
if (maxNo.Substring(0, 8) == date)
|
{
|
int lastNo = Convert.ToInt32(maxNo.Substring(8, 5)) + 1;
|
no = codeFlag + date + (lastNo.ToString().PadLeft(5, '0'));
|
}
|
else
|
{
|
no = codeFlag + date + "00001";
|
}
|
}
|
return no;
|
}
|
catch (Exception e)
|
{
|
Console.WriteLine(e);
|
throw;
|
}
|
}
|
/// <summary>
|
/// 根据前缀判断出当前最大单据号
|
/// </summary>
|
/// <param name="codeFlag">单据前缀</param>
|
/// <returns></returns>
|
public string SelectMaxNo(string codeFlag)
|
{
|
try
|
{
|
string orderNo = "";
|
if (codeFlag == InOutFlag.SO.ToString())//出库
|
{
|
var list = DataContext.Db.Queryable<BllExportNotice>().Where(m => m.SONo.StartsWith("SO")).ToList();
|
orderNo = list.Max(a => a.SONo);
|
}
|
if (codeFlag == InOutFlag.WSO.ToString())//波次出库
|
{
|
}
|
else if (codeFlag == InOutFlag.ASN.ToString())//入库
|
{
|
var list = DataContext.Db.Queryable<BllArrivalNotice>().Where(m => m.ASNNo.StartsWith("ASN")).ToList();
|
orderNo = list.Select(a => a.ASNNo).Max();
|
}
|
else if (codeFlag == InOutFlag.PM.ToString())//移库
|
{
|
}
|
else if (codeFlag == InOutFlag.CR.ToString())//盘点
|
{
|
var list = DataContext.Db.Queryable<BllStockCheck>().Where(m => m.CRNo.StartsWith("CR")).ToList();
|
orderNo = list.Select(a => a.CRNo).Max();
|
}
|
else if (codeFlag == InOutFlag.TK.ToString())//任务
|
{
|
var list = DataContext.Db.Queryable<LogTask>().Where(m => m.TaskNo.StartsWith("TK")).ToList();
|
orderNo = list.Max(m=>m.TaskNo);
|
}
|
else if (codeFlag == InOutFlag.EX.ToString())//异常
|
{
|
var list = DataContext.Db.Queryable<SysException>().Where(m => m.ExceptionNo.StartsWith("EX")).ToList();
|
orderNo = list.Max(a => a.ExceptionNo);
|
}
|
|
return orderNo;
|
}
|
catch (Exception e)
|
{
|
throw new Exception(e.Message);
|
}
|
}
|
|
/// <summary>
|
/// 执行sql语句获取行数
|
/// </summary>
|
/// <param name="sqlString">查询语句</param>
|
/// <returns>行数</returns>
|
public int GetRowCount(string sqlString)
|
{
|
try
|
{
|
var db = DataContext.Db;
|
var rowCount = db.Ado.GetInt(sqlString);
|
|
return rowCount;
|
}
|
catch (Exception ex)
|
{
|
throw new Exception(ex.Message);
|
}
|
}
|
|
/// <summary>
|
/// 判断托盘是否在入库中
|
/// </summary>
|
/// <param name="palletNo">托盘号</param>
|
/// <returns></returns>
|
public LogTask GetImTask(string palletNo)
|
{
|
try
|
{
|
var db = DataContext.Db;
|
//查询托盘是否有正在入库的任务
|
var imTask = db.Queryable<LogTask>().First(m => m.PalletNo == palletNo && m.IsDel == "0" && m.Status == "1");
|
|
return imTask;
|
}
|
catch (Exception ex)
|
{
|
throw new Exception(ex.Message);
|
}
|
}
|
|
}
|
public enum InOutFlag
|
{
|
/// <summary>
|
/// 入库单
|
/// </summary>
|
[Description("入库单")]
|
ASN,
|
/// <summary>
|
/// 出库单
|
/// </summary>
|
[Description("出库单")]
|
SO,
|
/// <summary>
|
/// 波次出库单
|
/// </summary>
|
[Description("波次出库单")]
|
WSO,
|
/// <summary>
|
/// 出库单
|
/// </summary>
|
[Description("盘点单")]
|
CR,
|
/// <summary>
|
/// 移库单
|
/// </summary>
|
[Description("移库单")]
|
PM,
|
|
/// <summary>
|
/// 任务
|
/// </summary>
|
[Description("任务")]
|
TK,
|
/// <summary>
|
/// 异常号
|
/// </summary>
|
[Description("异常")]
|
EX
|
}
|
}
|