using System; using System.Collections.Generic; using System.Data; using System.Linq; using System.Text; using System.Threading.Tasks; using Common; using Model; namespace BLL.DAL { public class DAL_OperationRecord { public DataTable GetUserItems() { try { StringBuilder stringBuilder = new StringBuilder(); stringBuilder.Append("select * from UserInfo where IsDel = 0 "); stringBuilder.Append("order by CreatTime ;"); DataTable dt = DataFactory.SqlDataBase().GetDataTableBySQL(stringBuilder); return dt; } catch { throw new NotImplementedException(); } } public IList GetList(AjaxLogOperationList Json, ref PageInfo pageInfo) { try { StringBuilder strSql = new StringBuilder(); strSql.Append("Select WCSLogOperation.*,UserInfo.UserName as CreateUserName ,Dictionary.TypeName as TypeName from WCSLogOperation left join UserInfo on WCSLogOperation.CreateUser = UserInfo.ID left join Dictionary on WCSLogOperation.Type = Dictionary.Code where WCSLogOperation.Id>0 and Dictionary.TopCode = 'OperationType' "); if (!string.IsNullOrWhiteSpace(Json.MenuName)) { strSql.Append(" and MenuName like '%" + Json.MenuName + "%' "); } if (!string.IsNullOrWhiteSpace(Json.UserCode)) { strSql.Append(" and CreateUser = '" + Json.UserCode + "' "); } if (Json.BeginTime != DateTime.MinValue && Json.BeginTime != null && Json.BeginTime != DateTime.MaxValue) { strSql.Append($"and CreateTime >= '{Convert.ToDateTime(Json.BeginTime).ToShortDateString()}' "); } if (Json.EndTime != DateTime.MinValue && Json.EndTime != null && Json.EndTime != DateTime.MaxValue) { strSql.Append($"and CreateTime <= '{Convert.ToDateTime(Json.EndTime).ToShortDateString() + " 23:59:59.999"}' "); } DataTable dt = DataFactory.SqlDataBase().GetPageList(strSql.ToString(), null, "CreateTime", "Desc", ref pageInfo); return ModelConvertHelper.DataTableToModel(dt); } catch { throw new NotImplementedException(); } } /// /// 添加操作日志 /// /// /// 登录人 /// public bool AddOperation(OperationModel model, string loginName) { bool result = false; try { StringBuilder sqlString = new StringBuilder(); //查询菜单信息 sqlString.Append($"select * from ResMenu where IsDel = 0 and ResName = '{model.MenuName}'; "); DataTable dt = DataFactory.SqlDataBase().GetDataTableBySQL(sqlString); if (dt.Rows.Count == 0) { throw new Exception("未查询到菜单信息"); } var parentNo = dt.Rows[0]["ParentNum"].ToString(); //模块号 var menuNo = dt.Rows[0]["ResNum"].ToString(); //菜单号 //查询操作类型 sqlString.Clear(); sqlString.Append($"select * from Dictionary where IsDel = 0 and TopCode = 'OperationType' and TypeName = '{model.Type}'; "); DataTable dt2 = DataFactory.SqlDataBase().GetDataTableBySQL(sqlString); if (dt2.Rows.Count == 0) { throw new Exception("未查询到操作类型信息"); } var operaType = dt2.Rows[0]["Code"].ToString(); //操作类型Code // 新增任务 sqlString.Clear(); sqlString.Append("insert into WCSLogOperation (ParentNo,MenuNo,MenuName,FkNo,Type,Msg,CreateTime,CreateUser) values ( "); sqlString.Append($"'{parentNo}','{menuNo}','{model.MenuName}','{model.FkNo}','{operaType}','{model.Msg}',GETDATE(),'{loginName}');"); var num = DataFactory.SqlDataBase().ExecuteBySql(sqlString); if (num == 1) { result = true; } return result; } catch (Exception e) { throw new Exception(e.Message); } } } }