using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Text;
using Common;
using Model;
namespace BLL
{
public class DALGoodsPos : IDALGoodsPos
{
public bool Add(GoodsPos model, string loginUser)
{
bool result = false;
try
{
Hashtable ht = new Hashtable();
ht["Addre"] = "'" + model.Area + model.pai.PadLeft(2,'0') + model.lie.PadLeft(2, '0') + model.ceng.PadLeft(2, '0') + "'";
ht["pai"] = "'" + model.pai.PadLeft(2, '0') + "'";
ht["lie"] = "'" + model.lie.PadLeft(2, '0') + "'";
ht["ceng"] = "'" + model.ceng.PadLeft(2, '0') + "'";
ht["Property"] = "'" + model.property + "'";
ht["ALock"] = "'" + model.ALock + "'";
ht["StorageAraeNo"] = "'" + model.Area + "'";
ht["Demo"] = "'" + model.Demo + "'";
ht["guid"] = "NEWID()";
int _ret = DataFactory.SqlDataBase().InsertByHashtableNullParam("GoodsPos", ht);
if (_ret == 1) result = true;
return result;
}
catch
{
return result;
}
}
public bool UpdateLock(string[] Addre, string ALock)
{
bool result = false;
try
{
int dt = DataFactory.SqlDataBase().IsExist("GoodsPos", "Addre", Addre);
if (dt >= Addre.Length)
{
Hashtable ht = new Hashtable();
string str = "";
if (ALock == "Lock") str = "NL";
if (ALock == "UnLock") str = "N";
ht["ALock"] = string.IsNullOrEmpty(ALock) ? "'N'" : "'" + str + "'";
int _ret = DataFactory.SqlDataBase().UpdateByHashtable("GoodsPos", "Addre", Addre ,ht);
if (_ret >= Addre.Length) result = true;
}
return result;
}
catch
{
return result;
}
}
public bool UpdateProperty(string[] Addre, string Property)
{
bool result = false;
try
{
int dt = DataFactory.SqlDataBase().IsExist("GoodsPos", "Addre", Addre);
if (dt >= Addre.Length)
{
Hashtable ht = new Hashtable();
string str = "";
//if (ALock == "Lock") str = "NL";
//if (ALock == "UnLock") str = "N";
ht["Property"] = string.IsNullOrEmpty(Property) ? "'N'" : "'" + Property + "'";
int _ret = DataFactory.SqlDataBase().UpdateByHashtable("GoodsPos", "Addre", Addre, ht);
if (_ret >= Addre.Length) result = true;
}
return result;
}
catch
{
return result;
}
}
public bool BatchDelete(string[] MatNo)
{
bool result = false;
try
{
int dt = DataFactory.SqlDataBase().IsExist("Material", "MatNo", MatNo);
if (dt >= MatNo.Length)
{
int _ret = DataFactory.SqlDataBase().BatchDeleteData("Material", "MatNo", MatNo);
if (_ret > MatNo.Length) result = true;
}
return result;
}
catch
{
return result;
}
}
public bool Delete(string MatNo)
{
throw new NotImplementedException();
}
public DataTable GetDataTable(string[] strWhere)
{
DataTable dt = null;
try
{
int index = 0;
string str = "@MatNo" + index;
SqlParam[] param = new SqlParam[strWhere.Length];
StringBuilder sql = new StringBuilder();
sql.Append("Select MatNo as 物料编码,MatName as 物料名称,packFormat as 包装规格,PackQuant as 包装量,UnitFrist as 计量单位(主),UnitSec as 计量单位(辅),Matweighttype as 物料轻重,storecondition as 储存环境,usefreq as 频率,sizeNum as 包装尺寸 FROM MatNo where MatNo in (");
for (int i = 0; i < param.Length - 1; i++)
{
string obj2 = strWhere[i];
str = "@MatNo" + index;
sql.Append(str).Append(",");
param[index] = new SqlParam(str, obj2);
index++;
}
str = "@MatNo" + index;
sql.Append(str);
param[index] = new SqlParam(str, strWhere[index]);
sql.Append(")");
dt = DataFactory.SqlDataBase().GetDataTableBySQL(sql, param, "");
return dt;
}
catch
{
throw new NotImplementedException();
}
}
public DataTable GetDataTable(int PageSize, int PageIndex, string strWhere)
{
throw new NotImplementedException();
}
//GetNullList
///
/// 查询库位
///
///
///
/// 库位集合
public IList GetList(AjaxGoodsPosList Json, ref PageInfo pageInfo)
{
try
{
IList list = new List();
StringBuilder strSql = new StringBuilder();
List para = new List();
strSql.Append("Select * from view_GoodsPos ");
if (Json.Addre != null && Json.Addre != "")
{
if (para.Count < 1) strSql.Append("where "); else strSql.Append(" and ");
strSql.Append("addre like '%"+Json.Addre+"%' ");
para.Add(new SqlParam("@addre", Json.Addre));
}
if (Json.pai != null && Json.pai != "")
{
if (para.Count < 1) strSql.Append("where "); else strSql.Append(" and ");
strSql.Append("pai = @pai ");
para.Add(new SqlParam("@pai", Json.pai.PadLeft(2,'0')));
}
if (Json.lie != null && Json.lie != "")
{
if (para.Count < 1) strSql.Append("where "); else strSql.Append(" and ");
strSql.Append("lie = @lie ");
para.Add(new SqlParam("@lie", Json.lie.PadLeft(2, '0')));
}
if (Json.ceng != null && Json.ceng != "")
{
if (para.Count < 1) strSql.Append("where "); else strSql.Append(" and ");
strSql.Append("ceng = @ceng ");
para.Add(new SqlParam("@ceng", Json.ceng.PadLeft(2, '0')));
}
if (Json.Area != null && Json.Area != "")
{
if (para.Count < 1) strSql.Append("where "); else strSql.Append(" and ");
strSql.Append("StorageAraeNo = '" + Json.Area + "' ");
para.Add(new SqlParam("@Area", Json.Area));
}
if (Json.statu != null && Json.statu != "")
{
if (para.Count < 1) strSql.Append("where "); else strSql.Append(" and ");
strSql.Append("statuNo = '"+ Json.statu + "' ");
para.Add(new SqlParam("@statu", Json.statu));
}
if (Json.property != null && Json.property != "")
{
if (para.Count < 1) strSql.Append("where "); else strSql.Append(" and ");
strSql.Append("propertyNo = '"+ Json.property + "' ");
para.Add(new SqlParam("@property", Json.property));
}
if (Json.ALock != null && Json.ALock != "")
{
if (para.Count < 1) strSql.Append("where "); else strSql.Append(" and ");
strSql.Append("ALockNo = '"+ Json.ALock + "' ");
para.Add(new SqlParam("@ALock", Json.ALock));
}
SqlParam[] param = null;
if (para != null)
param = para.ToArray();
DataTable dt = DataFactory.SqlDataBase().GetPageList(strSql.ToString(), param, "Id", "ASC", ref pageInfo);
list = ModelConvertHelper.DataTableToModel(dt);
return list;
}
catch
{
throw new NotImplementedException();
}
}
///
/// 获取库位信息
///
///
///
public GoodsPos GetModel(string addre)
{
try
{
GoodsPos us = null;
StringBuilder strSql = new StringBuilder();
strSql.Append("select * from GoodsPos where ");
strSql.Append("addre = '"+ addre + "'");
SqlParam[] para = new SqlParam[]
{
new SqlParam("@addre", "'" + addre + "'"),
};
IDataReader dt = DataFactory.SqlDataBase().GetDataReaderBySQL(strSql, para);
us = ModelConvertHelper.ReaderToModel(dt);
return us;
}
catch
{
throw new NotImplementedException();
}
}
public bool IsExist(string name, string value)
{
bool result = false;
try
{
string[] para = new string[] { value };
int dt = DataFactory.SqlDataBase().IsExist("Material", name, para);
if (dt > 0) result = true;
return result;
}
catch
{
throw new NotImplementedException();
}
}
public bool IsExist(Hashtable ht)
{
bool result = false;
try
{
int dt = DataFactory.SqlDataBase().IsExist("Material", ht);
if (dt > 0) result = true;
return result;
}
catch
{
throw new NotImplementedException();
}
}
///
/// 更新库位状态
///
///
///
public bool Update(GoodsPos model)
{
bool result = false;
try
{
StringBuilder sbstr = new StringBuilder();
sbstr.Append("update GoodsPos set statu= '"+ model.statu+ "',");
sbstr.Append("Property= '" + model.property+ "',ALock='"+ model.ALock+ "',");
sbstr.Append( "Demo='" + model.Demo+ "' ");
sbstr.Append("where Addre = '" + model.Area + "';");
// 数据库交互
int _ret = DataFactory.SqlDataBase().ExecuteBySql(sbstr);
if (_ret == 1)
{
result = true;
}
return result;
}
catch
{
return result;
}
}
public bool AnditMat(string[] MatNo, string AuditModel)
{
bool result = false;
try
{
int dt = DataFactory.SqlDataBase().IsExist("Material", "MatNo", MatNo);
if (dt >= MatNo.Length)
{
Hashtable ht = new Hashtable();
ht["AuditFlag"] = string.IsNullOrEmpty(AuditModel) ? "'N'" :"'" + AuditModel + "'";
int _ret = DataFactory.SqlDataBase().UpdateByHashtable("Material", "MatNo", MatNo, ht);
if (_ret >= MatNo.Length) result = true;
}
return result;
}
catch
{
return result;
}
}
public IList GetPaiList(string StorageNO)
{
try
{
IList ls = new List();
StringBuilder strSql = new StringBuilder();
strSql.Append("Select distinct pai,cast( pai as decimal) as ord from goodsPos");
if (StorageNO != string.Empty)
{
strSql.Append(" where StorageAraeNo = '" + StorageNO + "'");
}
strSql.Append(" order by cast( pai as decimal);");
IDataReader dt = DataFactory.SqlDataBase().GetDataReaderBySQL(strSql);
ls = ModelConvertHelper.DataReaderToModel(dt);
return ls;
}
catch
{
throw new NotImplementedException();
}
}
public IList GetLieList(string StorageNO)
{
try
{
IList ls = new List();
StringBuilder strSql = new StringBuilder();
strSql.Append("Select distinct lie,cast( lie as decimal) as ord from goodsPos");
if (StorageNO != string.Empty)
{
strSql.Append(" where StorageAraeNo = '" + StorageNO + "'");
}
strSql.Append(" order by cast( lie as decimal);");
IDataReader dt = DataFactory.SqlDataBase().GetDataReaderBySQL(strSql);
ls = ModelConvertHelper.DataReaderToModel(dt);
return ls;
}
catch
{
throw new NotImplementedException();
}
}
public IList GetCengList(string StorageNO)
{
try
{
IList ls = new List();
StringBuilder strSql = new StringBuilder();
strSql.Append("Select distinct ceng,cast( ceng as decimal) as ord from goodsPos");
if (StorageNO != string.Empty)
{
strSql.Append(" where StorageAraeNo = '" + StorageNO + "'");
}
strSql.Append(" order by cast( ceng as decimal);");
IDataReader dt = DataFactory.SqlDataBase().GetDataReaderBySQL(strSql);
ls = ModelConvertHelper.DataReaderToModel(dt);
return ls;
}
catch
{
throw new NotImplementedException();
}
}
public IList GetPropertyList()
{
try
{
IList ls = new List();
StringBuilder strSql = new StringBuilder();
strSql.Append("Select PropertyNo,PropertyName from log_Property ");
IDataReader dt = DataFactory.SqlDataBase().GetDataReaderBySQL(strSql);
ls = ModelConvertHelper.DataReaderToModel(dt);
return ls;
}
catch
{
throw new NotImplementedException();
}
}
public IList GetStatuList()
{
try
{
IList ls = new List();
StringBuilder strSql = new StringBuilder();
strSql.Append("Select StatuNo,StatuName from log_Statu ");
IDataReader dt = DataFactory.SqlDataBase().GetDataReaderBySQL(strSql);
ls = ModelConvertHelper.DataReaderToModel(dt);
return ls;
}
catch
{
throw new NotImplementedException();
}
}
public IList GetALockList()
{
try
{
IList ls = new List();
StringBuilder strSql = new StringBuilder();
strSql.Append("Select AlockNo,AlockName from log_ALock ");
IDataReader dt = DataFactory.SqlDataBase().GetDataReaderBySQL(strSql);
ls = ModelConvertHelper.DataReaderToModel(dt);
return ls;
}
catch
{
throw new NotImplementedException();
}
}
public IList GetAreaList()
{
try
{
IList ls = new List();
StringBuilder strSql = new StringBuilder();
strSql.Append("Select StorageNo as AreaNo,StorageName as AreaName from StorageArea ");
IDataReader dt = DataFactory.SqlDataBase().GetDataReaderBySQL(strSql);
ls = ModelConvertHelper.DataReaderToModel(dt);
return ls;
}
catch
{
throw new NotImplementedException();
}
}
public IList GetAddreList(string AreaNo)
{
try
{
IList ls = new List();
StringBuilder strSql = new StringBuilder();
strSql.Append("Select distinct Addre from goodsPos");
if (AreaNo != string.Empty)
{
strSql.Append(" where StorageAraeNo = '" + AreaNo + "'");
}
else
{
strSql.Append(" where 1=0");
}
strSql.Append(" order by addre;");
IDataReader dt = DataFactory.SqlDataBase().GetDataReaderBySQL(strSql);
ls = ModelConvertHelper.DataReaderToModel(dt);
return ls;
}
catch
{
throw new NotImplementedException();
}
}
}
}