using Model;
using System;
using System.Collections.Generic;
using System.Data;
using System.Text;
using Common;
using System.Collections;
using System.Net;
namespace BLL
{
public class DALTray
{
///
/// 查询托盘信息
///
/// 托盘实体类
/// 分页信息
/// 托盘信息,实体
public IList GetList(TrayList trayModel, ref PageInfo pageInfo)
{
try
{
IList list = new List();
StringBuilder strSql = new StringBuilder();
strSql.Append("Select * from View_Log_Store_Palno where 1 = 1 ");
if (trayModel.Addre != null && trayModel.Addre != "")
{
strSql.Append(" and Addre like '%" + trayModel.Addre + "%'");
}
if (trayModel.Palno != null && trayModel.Palno != "")
{
strSql.Append(" and Palno like '%" + trayModel.Palno + "%'");
}
if (trayModel.ALock != null && trayModel.ALock != "")
{
strSql.Append(" and ALockNo = '" + trayModel.ALock + "'");
}
if (trayModel.BeCreateTime != null && trayModel.BeCreateTime != DateTime.MinValue)
{
strSql.Append(" and CreateTime >= '"+trayModel.BeCreateTime+"'");
}
if (trayModel.EnCreateTime != null && trayModel.EnCreateTime != DateTime.MinValue)
{
strSql.Append(" and CreateTime <= '" + trayModel.EnCreateTime + "'");
}
DataTable dt = DataFactory.SqlDataBase().GetPageList(strSql.ToString(), null, "CreateTime", "DESC", ref pageInfo);
return ModelConvertHelper.DataTableToModel(dt);
}
catch
{
throw new NotImplementedException();
}
}
///
/// 获取单行托盘信息
///
/// 托盘码
/// dataRow
public Tray GetTrayModel(string Palno)
{
try
{
StringBuilder strSql = new StringBuilder();
strSql.Append("Select * from View_Log_Store_Palno where palno = '" + Palno + "';");
IDataReader dr = DataFactory.SqlDataBase().GetDataReaderBySQL(strSql);
return ModelConvertHelper.ReaderToModel(dr);
}
catch (Exception)
{
return null;
}
}
///
/// 新增编辑托盘
///
/// 托盘信息集合
/// true:保存成功 false:保存失败
public bool AddEdit(Tray trayModel)
{
bool bl = false;
try
{
int rowCount = 0;
if (trayModel.Palno == "")
{
// add托盘
string palnoNext = this.GetPalnoCode();
Hashtable ht = new Hashtable();
ht["Addre"] = "'" + trayModel.Addre + "'";
ht["Palno"] = "'" + palnoNext + "'";
ht["ALock"] = "'" + trayModel.ALock + "'";
ht["CreateTime"] = "convert(varchar(20),getdate(),120)";
ht["Demo"] = "'" + trayModel.Demo + "'";
ht["guid"] = "NEWID()";
rowCount = DataFactory.SqlDataBase().InsertByHashtableNullParam("log_Store_Palno", ht);
}
else
{
// Edit托盘
Hashtable ht = new Hashtable();
ht["Addre"] = "'" + trayModel.Addre + "'";
ht["CreateTime"] = "'" + trayModel.CreateTime + "'";
ht["Demo"] = "'" + trayModel.Demo + "'";
rowCount = DataFactory.SqlDataBase().UpdateByHashtable("log_Store_Palno", "Palno", trayModel.Palno, ht);
}
if (rowCount == 1)
{
bl = true;
}
}
catch (Exception)
{
bl = false;
}
return bl;
}
///
/// 删除托盘
///
/// 须删除项主键集合
/// true:删除成功 false:删除失败
public bool Delete(string[] Palno)
{
bool bl = false;
try
{
// 后期可根据库存明细,来限制托盘的删除。
int rowCount = DataFactory.SqlDataBase().BatchDeleteData("log_Store_Palno", "Palno", Palno);
if (rowCount >= Palno.Length)
{
bl = true;
}
return bl;
}
catch (Exception)
{
return bl;
}
}
///
/// 获取货位信息
///
///
public DataTable GetGoodsPosPrint(string StorageNo)
{
try
{
StringBuilder strSql = new StringBuilder();
if (StorageNo != "")
{
strSql.Append("select Addre from GoodsPos where StorageAraeNo = '" + StorageNo + "'; ");
}
DataTable dt = DataFactory.SqlDataBase().GetDataTableBySQL(strSql);
return dt;
}
catch (Exception)
{
throw new NotImplementedException();
}
}
///
/// 获取单个货位信息
///
///
///
public DataTable GetGoodsPos(string Addre)
{
try
{
StringBuilder strSql = new StringBuilder();
if (Addre != "")
{
strSql.Append("select tb1.Addre,tb2.StorageName from GoodsPos as tb1 ");
strSql.Append("left join StorageArea as tb2 on tb1.StorageAraeNo = tb2.StorageNo ");
strSql.Append("where tb1.Addre = '"+ Addre + "';");
}
DataTable dt = DataFactory.SqlDataBase().GetDataTableBySQL(strSql);
return dt;
}
catch (Exception)
{
throw new NotImplementedException();
}
}
///
/// 打印托盘信息
///
///
///
///
public DataTable GetTrayPrint(string Addre,string TrayNo)
{
try
{
StringBuilder strSql = new StringBuilder();
strSql.Append("select tb1.Addre,tb2.StorageName,tb3.Palno from GoodsPos as tb1 ");
strSql.Append("left join StorageArea as tb2 on tb1.StorageAraeNo = tb2.StorageNo ");
strSql.Append("left join log_Store_Palno as tb3 on tb1.Addre = tb3.Addre ");
if (Addre != "")
{
strSql.Append("where tb1.Addre = '" + Addre + "';");
}
else if (TrayNo != "")
{
strSql.Append("where tb3.Palno = '" + TrayNo + "';");
}
DataTable dt = DataFactory.SqlDataBase().GetDataTableBySQL(strSql);
return dt;
}
catch (Exception)
{
throw new NotImplementedException();
}
}
///
/// 获取最大托盘码
///
///
private string GetPalnoCode()
{
StringBuilder sbstr = new StringBuilder();
try
{
string palno = "00000001";
sbstr.Append("select isnull(max(palno)+1,'0') as palno from log_Store_Palno;");
DataTable dt = DataFactory.SqlDataBase().GetDataTableBySQL(sbstr);
if (dt.Rows[0][0].ToString() != "0")
{
palno = dt.Rows[0][0].ToString().PadLeft(8,'0');
}
return palno;
}
catch (Exception)
{
return null;
}
}
}
}