using Model; using System; using System.Collections.Generic; using System.Data; using System.Text; using Common; using System.Collections; namespace BLL { public class DALTask : IDALTask { public bool IsExist(string name, string value) { bool result = false; try { string[] para = new string[] { value }; int dt = DataFactory.SqlDataBase().IsExist("PaTask", 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("PaTask",ht); if (dt > 0) result = true; return result; } catch { throw new NotImplementedException(); } } public bool Add(PaTask model) { bool result = false; try { Hashtable ht = new Hashtable(); //ht["UserCode"] = "'" + model.UserCode + "'"; //ht["Username"] = "'" + model.Username + "'"; //ht["Pwd"] = "'" + Md5Helper.Md5(model.Pwd, 32) + "'"; //ht["RealName"] = "'" + model.RealName + "'"; //ht["RoleNum"] = "(select RoleNum from Roles where RoleName ='" + model.RoleName + "')"; //ht["DepartNum"] = "(select DepartNum from DepartMent where DepartName ='" + model.DepartName + "')"; //ht["Mobile"] = "'"+model.Mobile + "'"; //ht["Phone"] = "'" + model.Phone + "'"; //ht["Email"] = "'" + model.email + "'"; //ht["Ord"] = "(select Max(Ord) from PaTask) + 1"; //ht["IsDel"] = 0; //ht["CreatUser"] = "'"+ model.CreatUser + "'"; //ht["UpdateTime"] = "GetDate()"; //ht["CreatTime"] = "GetDate()"; //ht["Demo"] = "'" + model.Demo + "'"; //ht["UpdateUser"] = "'" + model.CreatUser + "'"; ht["guid"] = "NEWID()"; int _ret = DataFactory.SqlDataBase().InsertByHashtableNullParam("PaTask", ht); if (_ret == 1) result = true; return result; } catch { return result; } } //public bool Add(CheckData model) //{ // bool result = false; // try // { // Hashtable ht1 = new Hashtable(); // Hashtable rs = new Hashtable(); // ht1["sCode"] = "CTNO"; // ht1["OUT_sResult"] = ""; // int num = DataFactory.SqlDataBase().ExecuteByProcReturn("GetSerialNo", ht1, ref rs); // if (num == 0) return result; // model.TaskId = rs["OUT_sResult"].ToString(); // Hashtable ht = new Hashtable(); // ht["TaskId"] = "'" + model.TaskId + "'"; // ht["MatNo"] = "'" + model.MatNo + "'"; // ht["Batch"] = "'" + model.Batch + "'"; // ht["Palno"] = "'" + model.Palno + "'"; // ht["Quant"] = "'" + model.Quant + "'"; // ht["CreateUser"] = "'" + model.CreateUser + "'"; // ht["Statu"] = "'ER01'"; // ht["Type"] = "'OD004'"; // int _ret = DataFactory.SqlDataBase().InsertByHashtableNullParam("CheckData", ht); // if (_ret == 1) result = true; // return result; // } // catch // { // return result; // } //} public bool Update(PaTask model) { bool result = false; try { Hashtable ht = new Hashtable(); //ht["RealName"] = string.IsNullOrEmpty(model.RealName) ? "''" : "'" + model.RealName+"'" ; //ht["RoleNum"] = "(select RoleNum from Roles where RoleName ='" + model.RoleName + "')"; //ht["DepartNum"] = "(select DepartNum from DepartMent where DepartName ='" + model.DepartName + "')"; //ht["Mobile"] = string.IsNullOrEmpty(model.Mobile) ? "''" : "'" + model.Mobile + "'"; //ht["Phone"] = string.IsNullOrEmpty(model.Phone) ? "''" : "'" + model.Phone + "'"; //ht["Email"] = string.IsNullOrEmpty(model.email) ? "''" : "'" + model.email + "'"; //ht["UpdateTime"] = "GetDate()"; //ht["UpdateUser"] = string.IsNullOrEmpty(model.UpdateUser) ? "''" : "'" + model.UpdateUser + "'"; //ht["Demo"] = string.IsNullOrEmpty(model.Demo) ? "''" : "'" + model.Demo + "'"; //string UserCode = "'" + model.UserCode + "'"; //int _ret = DataFactory.SqlDataBase().UpdateByHashtable("PaTask", "UserCode", UserCode, ht); //if (_ret == 1) result = true; return result; } catch { return result; } } public bool Update(string UserCode,string Pwd,string UpdateUser) { bool result = false; try { Hashtable ht = new Hashtable(); ht["Pwd"] = string.IsNullOrEmpty(Pwd) ? "''" : "'" + Md5Helper.Md5(Pwd, 32) + "'"; if (UpdateUser != null) { ht["UpdateUser"] = "'" + UpdateUser + "'"; ht["UpdateTime"] = "getdate()"; UserCode = "'" + UserCode + "'"; } int _ret = DataFactory.SqlDataBase().UpdateByHashtable("PaTask", "UserCode", UserCode, ht); if (_ret == 1) result = true; return result; } catch { return result; } } public PaTask DataRowToModel(DataRow row) { throw new NotImplementedException(); } public bool Delete(string UserCode) { bool result = false; try { Hashtable ht = new Hashtable(); int _ret = DataFactory.SqlDataBase().DeleteData("PaTask", "UserCode", UserCode); if (_ret == 1) result = true; return result; } catch { return result; } } public bool BatchDelete(string[] TaskId) { bool result = false; try { int dt = DataFactory.SqlDataBase().IsExist("Task", "TaskId", TaskId); if (dt >= TaskId.Length) { int _ret = DataFactory.SqlDataBase().BatchDeleteData("Task", "TaskId", TaskId); if (_ret >= TaskId.Length) result = true; } return result; } catch { return result; } } public IList GetList() { throw new NotImplementedException(); } public IList GetList(AjaxTaskList Json,ref PageInfo pageInfo) { try { IList list = new List(); StringBuilder strSql = new StringBuilder(); List para = new List(); strSql.Append("Select TaskId,OrdNo,OrdType,MatNo,MatName,Batch,PackFormat,UnitFrist,Palno,Quant,Quant_Qy,Statu,StartAddr,StopAddr,CreateTime,COMDAT ,[Priority],Demo, Demo1,Demo2,Demo3,Demo4 from Task "); if (Json.TaskId != null && Json.TaskId != "") { if (para.Count <1 ) strSql.Append("where "); else strSql.Append(" and "); strSql.Append("TaskId like '%' + @TaskId + '%' "); para.Add(new SqlParam("@TaskId", Json.TaskId)); } if (Json.OrdNo != null && Json.OrdNo != "") { if (para.Count < 1) strSql.Append("where "); else strSql.Append(" and "); strSql.Append("OrdNo like '%' + @OrdNo + '%' "); para.Add(new SqlParam("@OrdNo", Json.OrdNo)); } if (Json.OrdType != null && Json.OrdType != "") { if (para.Count < 1) strSql.Append("where "); else strSql.Append(" and "); strSql.Append("OrdType = @OrdType "); para.Add(new SqlParam("@OrdType", Json.OrdType)); } if (Json.MatNo != null && Json.MatNo != "") { if (para.Count <1) strSql.Append("where "); else strSql.Append(" and "); strSql.Append("MatNo like '%' + @MatNo + '%' "); para.Add(new SqlParam("@MatNo", Json.MatNo)); } if (Json.Batch != null && Json.Batch != "") { if (para.Count <1) strSql.Append("where ");else strSql.Append(" and "); strSql.Append("Batch like '%' + @Batch + '%' "); para.Add(new SqlParam("@Batch", Json.Batch)); } if (Json.Statu != null && Json.Statu != "") { if (para.Count < 1) strSql.Append("where "); else strSql.Append(" and "); strSql.Append("Statu = @Statu "); para.Add(new SqlParam("@Statu", Json.Statu)); } if (Json.BeCreateTime != null && Json.BeCreateTime != DateTime.MinValue && Json.BeCreateTime != DateTime.MaxValue) { if (para.Count < 1) strSql.Append("where "); else strSql.Append(" and "); strSql.Append("CreateTime >= @CreateTime1"); para.Add(new SqlParam("@CreateTime1", Json.BeCreateTime)); } if (Json.EnCreateTime != null && Json.EnCreateTime != DateTime.MinValue && Json.EnCreateTime != DateTime.MaxValue) { if (para.Count < 1) strSql.Append("where "); else strSql.Append(" and "); strSql.Append("CreateTime <= @CreateTime2"); para.Add(new SqlParam("@CreateTime2", Json.EnCreateTime)); } if (Json.BeCOMDAT != null && Json.BeCOMDAT != DateTime.MinValue && Json.BeCOMDAT != DateTime.MaxValue) { if (para.Count < 1) strSql.Append("where "); else strSql.Append(" and "); strSql.Append("COMDAT >= @COMDAT1"); para.Add(new SqlParam("@COMDAT1", Json.BeCOMDAT)); } if (Json.EnCOMDAT != null && Json.EnCOMDAT != DateTime.MinValue && Json.EnCOMDAT != DateTime.MaxValue) { if (para.Count < 1) strSql.Append("where "); else strSql.Append(" and "); strSql.Append("COMDAT <= @COMDAT2"); para.Add(new SqlParam("@COMDAT2", Json.EnCOMDAT)); } SqlParam[] param = null; if (para != null) param = para.ToArray(); DataTable dt = DataFactory.SqlDataBase().GetPageList(strSql.ToString(), param, "CreateTime", "DESC", ref pageInfo); list = ModelConvertHelper.DataTableToModel(dt); return list; } catch { throw new NotImplementedException(); } } public PaTask GetModel(string username, string pwd) { try { PaTask us = null; StringBuilder strSql = new StringBuilder(); strSql.Append("Select * from PaTask where "); strSql.Append("Username = @Username "); strSql.Append("and Pwd = @Pwd "); strSql.Append("and IsDel != 1"); SqlParam[] para = new SqlParam[] { new SqlParam("@Username", username), new SqlParam("@Pwd", Md5Helper.Md5(pwd, 32)) }; IDataReader dt = DataFactory.SqlDataBase().GetDataReaderBySQL(strSql, para); //IList Lu = ModelConvertHelper.DataReaderToModel(dt); us = ModelConvertHelper.ReaderToModel(dt); return us; } catch { throw new NotImplementedException(); } } public PaTask GetModel(string usercode) { try { PaTask us = null; StringBuilder strSql = new StringBuilder(); strSql.Append("Select UserCode,UserName,RealName,Phone,Mobile,Email,RoleName,DepartName,CreatUser,CreatTime,UpdateUser,UpdateTime,Demo,Ord,IsDel from View_UserInfo where "); strSql.Append("UserCode = @UserCode "); strSql.Append("and IsDel != 1"); SqlParam[] para = new SqlParam[] { new SqlParam("@UserCode", usercode), }; IDataReader dt = DataFactory.SqlDataBase().GetDataReaderBySQL(strSql, para); us = ModelConvertHelper.ReaderToModel(dt); return us; } catch { throw new NotImplementedException(); } } public DataTable GetDataTable(string[] strWhere) { DataTable dt = null; try { int index = 0; string str = "@UserCode" + index; SqlParam[] param = new SqlParam[strWhere.Length]; StringBuilder sql = new StringBuilder(); sql.Append("Select Username as 用户名,UserCode as 员工编号,RealName as 真名,Email as 邮箱,Mobile as 手机,Phone as 固话,CreatTime as 创建时间,DepartName as 部门,RoleName as 角色,Demo as 备注 FROM View_UserInfo where UserCode in ("); for (int i = 0; i < param.Length - 1; i++) { string obj2 = strWhere[i]; str = "@UserCode" + index; sql.Append(str).Append(","); param[index] = new SqlParam(str, obj2); index++; } str = "@UserCode" + 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(); } } }