using System; using System.Collections.Generic; using System.Text; using Model; using Common; using System.Data; using System.Collections; namespace BLL { public class DALMove : IDALMove { public IList GetList(AjaxMoveList Json,ref PageInfo page) { try { IList list = new List(); StringBuilder strSql = new StringBuilder(); List para = new List(); strSql.Append("Select * from View_Log_MovePos "); if (!string.IsNullOrEmpty(Json.MDNo)) { if (para.Count < 1) strSql.Append("where "); else strSql.Append(" and "); strSql.Append("MDNo like '%' + @MDNo + '%' "); para.Add(new SqlParam("@MDNo", Json.MDNo)); } if (!string.IsNullOrEmpty(Json.AuditStatu)) { if (para.Count < 1) strSql.Append("where "); else strSql.Append(" and "); strSql.Append("AuditStatu like '%' + @AuditStatu + '%' "); para.Add(new SqlParam("@AuditStatu", Json.AuditStatu)); } if (!string.IsNullOrEmpty(Json.Statu)) { if (para.Count < 1) strSql.Append("where "); else strSql.Append(" and "); strSql.Append("Statu like '%' + @Statu + '%' "); para.Add(new SqlParam("@Statu", Json.Statu)); } if (Json.BeCreateTime != DateTime.MinValue && Json.BeCreateTime != null && Json.BeCreateTime != DateTime.MaxValue) { if (para.Count < 1) strSql.Append("where "); else strSql.Append(" and "); strSql.Append("CreateTime >= @CreateTime1 "); para.Add(new SqlParam("@CreateTime1", Convert.ToDateTime(Json.BeCreateTime))); } if (Json.EnCreateTime != DateTime.MinValue && Json.EnCreateTime != null && Json.EnCreateTime != DateTime.MaxValue) { if (para.Count < 1) strSql.Append("where "); else strSql.Append(" and "); strSql.Append("CreateTime <= @CreateTime2 "); para.Add(new SqlParam("@CreateTime2", Convert.ToDateTime(Json.EnCreateTime))); } SqlParam[] param = null; if (para != null) param = para.ToArray(); DataTable dt = DataFactory.SqlDataBase().GetPageList(strSql.ToString(), param, "CreateTime", "desc", ref page); list = ModelConvertHelper.DataTableToModel(dt); return list; } catch { throw new NotImplementedException(); } } public MovePos GetModel(string OrdNo) { try { MovePos us = null; StringBuilder strSql = new StringBuilder(); strSql.Append(" Select * from View_Log_MovePos where "); strSql.Append("MDNo = @MDNo "); //strSql.Append("and IsDel != 1"); SqlParam[] para = new SqlParam[] { new SqlParam("@MDNo", OrdNo), }; IDataReader dt = DataFactory.SqlDataBase().GetDataReaderBySQL(strSql, para); us = ModelConvertHelper.ReaderToModel(dt); return us; } catch { throw new NotImplementedException(); } } public MovePos GetModel(string MDNo,ref IList erpMats) { try { MovePos us = null; StringBuilder strSql = new StringBuilder(); strSql.Append(" Select * from Log_MovePos where "); strSql.Append("MDNo = @MDNo "); //strSql.Append("and IsDel != 1"); SqlParam[] para = new SqlParam[] { new SqlParam("@MDNo", MDNo), }; IDataReader dt = DataFactory.SqlDataBase().GetDataReaderBySQL(strSql, para); us = ModelConvertHelper.ReaderToModel(dt); IDALMoveDetail erpInDetail = new DALMoveDetail(); erpMats = erpInDetail.GetList(MDNo); return us; } catch { throw new NotImplementedException(); } } public bool Add(MovePos model,List Mats) { bool result = false; try { Hashtable ht1 = new Hashtable() ; Hashtable rs = new Hashtable(); ht1["sCode"] = "MDNO"; ht1["OUT_sResult"] = ""; int num = DataFactory.SqlDataBase().ExecuteByProcReturn("GetSerialNo", ht1, ref rs); if (num == 0) return result; model.MDNo = rs["OUT_sResult"].ToString(); foreach (MoveMat erp in Mats) { erp.MDNo = model.MDNo; } IDALMoveDetail dALErp = new DALMoveDetail(); bool value = dALErp.Add(Mats); Hashtable ht = new Hashtable(); ht["MDNo"] = "'" + model.MDNo + "'"; ht["AuditStatu"] = "'" + model.AuditStatu + "'"; ht["Statu"] = "'" + model.Statu + "'"; ht["CreateUser"] = "'" + model.CreateUser + "'"; //ht["Demo"] = "'" + model.Demo + "'"; int _ret = DataFactory.SqlDataBase().InsertByHashtableNullParam("Log_MovePos", ht); if (_ret == 1) result = true; return result; } catch { return result; } } public bool Update(MovePos model, List Mats) { bool result = false; try { foreach (MoveMat erp in Mats) { erp.MDNo = model.MDNo; } IDALMoveDetail dALErp = new DALMoveDetail(); if (!dALErp.Update(Mats)) return false; Hashtable ht = new Hashtable(); ht["MDNo"] = string.IsNullOrEmpty(model.MDNo) ? "''" : "'" + model.MDNo + "'"; ht["Statu"] = string.IsNullOrEmpty(model.Statu) ? "''" : "( select top 1 OrdTypeNo from OrdType where OrdTypeName = '"+ model.Statu + "')"; ht["Demo"] = string.IsNullOrEmpty(model.Demo) ? "''" : "'" + model.Demo + "'"; string MDNo = "'" + model.MDNo + "'"; int _ret = DataFactory.SqlDataBase().UpdateByHashtable("Log_MovePos", nameof(model.MDNo), MDNo, ht); if (_ret == 1) result = true; return result; } catch { return result; } } public bool UpdateAudit(MovePos movePos) { bool result = false; try { Hashtable ht = new Hashtable(); ht["AuditStatu"] = "'AD01'"; ht["Statu"] = "'ER04'"; ht["MDNo"] = "'" + movePos.MDNo + "'"; Hashtable ht1 = new Hashtable(); ht1["AuditStatu"] = "'" + movePos.AuditStatu + "'"; ht1["AuditUser"] = "'" + movePos.AuditUser + "'"; int _ret = DataFactory.SqlDataBase().UpdateByHashtable("Log_MovePos", ht1, ht); if (_ret == 1) result = true; return result; } catch { return result; } } public bool UpdateClose(string[] MDNo, string Statu) { bool result = false; try { Hashtable ht = new Hashtable(); ht["Statu"] = "ER03"; int dt = DataFactory.SqlDataBase().IsExist("Log_MovePos", "MDNo", MDNo, ht); if (dt >= MDNo.Length) { int _ret = DataFactory.SqlDataBase().BatchDeleteData("Log_MovePos", "MDNo", MDNo); if (_ret >= MDNo.Length) 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("Log_MovePos", 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[] OrdNo) { bool result = false; try { Hashtable ht = new Hashtable(); ht["Statu"] = "01"; int dt = DataFactory.SqlDataBase().IsExist("Log_MovePos", "MDNo", OrdNo, ht); if (dt >= OrdNo.Length) { int _ret = DataFactory.SqlDataBase().BatchDeleteData("Log_MovePos", "MDNo", OrdNo); if (_ret >= OrdNo.Length) { int dt1 = DataFactory.SqlDataBase().IsExist("Log_Move_Detail", "MDNo", OrdNo); if (dt1 > 0) { int _ret1 = DataFactory.SqlDataBase().BatchDeleteData("Log_Move_Detail", "MDNo", OrdNo); if (_ret1 >= dt1) result = true; } } } return result; } catch { return result; } } } }