public JsonResult MakeJsonResult(int code, string msg) { JsonResult jsonResult = new JsonResult(); JRes jRes = new JRes(); jRes.msg = msg; jRes.res = code; jsonResult.Data = jRes; return(jsonResult); }
/// <summary> /// 多条sql执行 无事务 /// </summary> /// <param name="dto"></param> /// <returns>主体部分执行成功条数</returns> public int MultipleSQLExecuteReturnRows(MultiSQLExecuteParam dto) { SqlConnection connection = new SqlConnection(this.connectString); var beforeRows = -1; var afterRows = -1; int count = 0; try { connection.Open(); if (!string.IsNullOrEmpty(dto.beforeSql)) { //执行before if (dto.beforeObj != null) { beforeRows = connection.Execute(dto.beforeSql, dto.beforeObj); } else if (dto.beforeParam.Count > 0) { beforeRows = connection.Execute(dto.beforeSql, dto.beforeParam); } else { beforeRows = connection.Execute(dto.beforeSql, null); } } //执行的是存储过程 //执行主体 if (!string.IsNullOrEmpty(dto.listSql)) { if (dto.listSql.IndexOf("EXECUTE") != -1) { foreach (object item in dto.objList) { JRes res = connection.Query <JRes>(dto.listSql, item).SingleOrDefault(); if (res.res == 1) { count++; } } } else { foreach (object item in dto.objList) { connection.Execute(dto.listSql, item); count++; } } } if (!string.IsNullOrEmpty(dto.afterSql)) { //执行after if (dto.afterObj != null) { afterRows = connection.Execute(dto.afterSql, dto.afterObj); } else if (dto.afterParam.Count > 0) { afterRows = connection.Execute(dto.afterSql, dto.afterParam); } else { afterRows = connection.Execute(dto.afterSql, null); } } connection.Close(); } catch (Exception ex) { connection.Close(); Log.WriteLog(ex.Message); return(count); } return(count); }