using System; using System.Collections.Generic; using System.Text; using Model; using Common; using System.Data; using System.Collections; namespace BLL { public class DALArea : IDALArea { public IList GetList() { try { IList ls = new List(); StringBuilder strSql = new StringBuilder(); strSql.Append("Select RoleName from Roles where IsDel !=1"); IDataReader dt = DataFactory.SqlDataBase().GetDataReaderBySQL(strSql); ls = ModelConvertHelper.DataReaderToModel(dt); return ls; } catch { throw new NotImplementedException(); } } public IList GetList(AjaxAreaList Json, ref PageInfo page) { try { IList list = new List(); StringBuilder strSql = new StringBuilder(); List para = new List(); strSql.Append("Select ID, StorageNo,StorageName,pai,lie,ceng,Demo from StorageArea "); if (!string.IsNullOrEmpty(Json.StorageNo)) { if (para.Count < 1) strSql.Append("where "); else strSql.Append(" and "); strSql.Append("StorageNo like '%' + @StorageNo + '%' "); para.Add(new SqlParam("@StorageNo", Json.StorageNo)); } if (!string.IsNullOrEmpty(Json.StorageName)) { if (para.Count < 1) strSql.Append("where "); else strSql.Append(" and "); strSql.Append("StorageName like '%' + @StorageName + '%' "); para.Add(new SqlParam("@StorageName", Json.StorageName)); } SqlParam[] param = null; if (para != null) param = para.ToArray(); DataTable dt = DataFactory.SqlDataBase().GetPageList(strSql.ToString(), param, "ID", "Asc", ref page); list = ModelConvertHelper.DataTableToModel(dt); return list; } catch { throw new NotImplementedException(); } } public Area GetModel(string StorageNo) { try { Area us = null; StringBuilder strSql = new StringBuilder(); strSql.Append("Select StorageNo,StorageName,Pai,Lie,Ceng,Demo from StorageArea where "); strSql.Append("StorageNo = @StorageNo "); SqlParam[] para = new SqlParam[] { new SqlParam("@StorageNo", StorageNo), }; IDataReader dt = DataFactory.SqlDataBase().GetDataReaderBySQL(strSql, para); us = ModelConvertHelper.ReaderToModel(dt); return us; } catch { throw new NotImplementedException(); } } public bool Add(Area model) { bool result = false; try { Hashtable ht = new Hashtable(); ht["StorageNo"] = "'" + model.StorageNo + "'"; ht["StorageName"] = "'" + model.StorageName + "'"; ht["Pai"] = "'" + model.Pai + "'"; ht["Lie"] = "'" + model.Lie + "'"; ht["Ceng"] = "'" + model.Ceng + "'"; ht["Demo"] = "'" + model.Demo + "'"; int _ret = DataFactory.SqlDataBase().InsertByHashtableNullParam("StorageArea", ht); if (_ret == 1) result = true; return result; } catch { return result; } } /// /// 验证是否已生成库位 /// /// 库区编码 /// true:已创建库位 fale:未创建库位 public bool IsCreateLocation(string StorageNo) { bool bl = false; try { StringBuilder sbstr = new StringBuilder(); sbstr.Append("select status from StorageArea where StorageNo = '" + StorageNo + "';"); DataTable dt = DataFactory.SqlDataBase().GetDataTableBySQL(sbstr); if(dt != null) { if (dt.Rows[0][0].ToString() == "1") { bl = true; } } } catch (Exception) { bl = false; } return bl; } /// /// 自动生成仓位 /// /// /// public bool Createlocation(string StorageNo) { bool bl = true; try { // 获取库区信息 Area StorageInfo = this.GetModel(StorageNo); // 根据库区 排 列 层 生成库位信息。 int pai = int.Parse(StorageInfo.Pai); int lie = int.Parse(StorageInfo.Lie); int ceng = int.Parse(StorageInfo.Ceng); IDALGoodsPos provider = new DALGoodsPos(); // 循环取得每个库位号 for (int p = 1; p <= pai; p++) { for (int l = 1; l <= lie; l++) { for (int c = 1; c <= ceng; c++) { GoodsPos gdModel = new GoodsPos(); gdModel.Area = StorageNo; gdModel.pai = p.ToString().PadLeft(2, '0'); gdModel.lie = l.ToString().PadLeft(2, '0'); gdModel.ceng = c.ToString().PadLeft(2, '0'); gdModel.property = "N"; gdModel.ALock = "N"; gdModel.Demo = ""; provider.Add(gdModel, ""); } } } // 改变创建库位标记 Hashtable ht = new Hashtable(); ht["status"] = "'1'"; StorageNo = "'" + StorageNo + "'"; if (DataFactory.SqlDataBase().UpdateByHashtable("StorageArea", "StorageNo", StorageNo, ht) != 1) { bl = false; } } catch (Exception ex) { bl = false; } return bl; } public bool Update(Area model) { bool result = false; try { Hashtable ht = new Hashtable(); ht["StorageName"] = string.IsNullOrEmpty(model.StorageName) ? "''" : "'" + model.StorageName + "'"; ht["pai"] = string.IsNullOrEmpty(model.Pai) ? "''" : "'" + model.Pai + "'"; ht["lie"] = string.IsNullOrEmpty(model.Lie) ? "''" : "'" + model.Lie + "'"; ht["ceng"] = string.IsNullOrEmpty(model.Ceng) ? "''" : "'" + model.Ceng + "'"; ht["Demo"] = string.IsNullOrEmpty(model.Demo) ? "''" : "'" + model.Demo + "'"; string StorageNo = "'" + model.StorageNo + "'"; int _ret = DataFactory.SqlDataBase().UpdateByHashtable("StorageArea", nameof(model.StorageNo), StorageNo, ht); if (_ret == 1) result = true; return result; } catch { return result; } } public bool IsExist(string name, string value) { bool result = false; try { string[] para = new string[] { value }; int dt = DataFactory.SqlDataBase().IsExist("StorageArea", name, para); if (dt > 0) result = true; return result; } catch { return result; } } public DataTable GetDataTable(string[] strWhere) { DataTable dt = null; try { int index = 0; string str = "@RoleNum" + index; SqlParam[] param = new SqlParam[strWhere.Length]; StringBuilder sql = new StringBuilder(); sql.Append("Select RoleNum as 角色编号, RoleName as 角色名,CreatUser as 创建人,CreatTime as 创建时间,UpdateUser as 更新人,UpdateTime as 更新时间,Demo as 备注 FROM View_GetRoles where RoleNum in ("); for (int i = 0; i < param.Length - 1; i++) { string obj2 = strWhere[i]; str = "@RoleNum" + index; sql.Append(str).Append(","); param[index] = new SqlParam(str, obj2); index++; } str = "@RoleNum" + 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 bool BatchDelete(string[] RoleNum) { bool result = false; try { int dt = DataFactory.SqlDataBase().IsExist("StorageArea", "StorageNo", RoleNum); if (dt >= RoleNum.Length) { int _ret = DataFactory.SqlDataBase().BatchDeleteData("StorageArea", "StorageNo", RoleNum); if (_ret >= RoleNum.Length) result = true; } return result; } catch { return result; } } } }