|
|
@@ -43,6 +43,14 @@ namespace MySystem.Areas.Admin.Controllers
|
|
|
ViewBag.Id = Id.ToString();
|
|
|
Dictionary<string, string> query = new Dictionary<string, string>();
|
|
|
CustomQuery item = db.CustomQuery.FirstOrDefault(m => m.Id == Id) ?? new CustomQuery();
|
|
|
+ if(SysUserName != "admin")
|
|
|
+ {
|
|
|
+ string checkString = "," + item.AdminNames + ",";
|
|
|
+ if(!checkString.Contains("," + SysUserName + ","))
|
|
|
+ {
|
|
|
+ return Content("无权限");
|
|
|
+ }
|
|
|
+ }
|
|
|
string sql = item.SqlContent;
|
|
|
MatchCollection mc = Regex.Matches(sql, @"\$\{.*?\}\$");
|
|
|
foreach(Match m in mc)
|
|
|
@@ -95,9 +103,19 @@ namespace MySystem.Areas.Admin.Controllers
|
|
|
public JsonResult IndexData(int Id, int page = 1, int limit = 30)
|
|
|
{
|
|
|
Dictionary<string, string> dicVals = new Dictionary<string, string>();
|
|
|
+ string ConnectStr = "";
|
|
|
List<CustomQuerySub> subItems = db.CustomQuerySub.Where(m => m.ParentId == Id).ToList();
|
|
|
foreach(CustomQuerySub sub in subItems)
|
|
|
{
|
|
|
+ ConnectStr = sub.DatabaseConnect;
|
|
|
+ if(!string.IsNullOrEmpty(ConnectStr))
|
|
|
+ {
|
|
|
+ ConnectStr = GetConnectStr(sub.DatabaseConnect);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ ConnectStr = MysqlConn.ReadSqlConnStr;
|
|
|
+ }
|
|
|
string sqlstr = sub.SqlContent;
|
|
|
MatchCollection mcsub = Regex.Matches(sqlstr, @"\$\{.*?\}\$");
|
|
|
foreach(Match m in mcsub)
|
|
|
@@ -121,7 +139,7 @@ namespace MySystem.Areas.Admin.Controllers
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- DataTable dtsub = CustomerSqlConn.dtable(sqlstr, MysqlConn.ReadSqlConnStr);
|
|
|
+ DataTable dtsub = CustomerSqlConn.dtable(sqlstr, ConnectStr);
|
|
|
if(dtsub.Rows.Count > 0)
|
|
|
{
|
|
|
if(dtsub.Rows.Count > 1)
|
|
|
@@ -145,6 +163,15 @@ namespace MySystem.Areas.Admin.Controllers
|
|
|
}
|
|
|
}
|
|
|
CustomQuery item = db.CustomQuery.FirstOrDefault(m => m.Id == Id) ?? new CustomQuery();
|
|
|
+ ConnectStr = item.DatabaseConnect;
|
|
|
+ if(!string.IsNullOrEmpty(ConnectStr))
|
|
|
+ {
|
|
|
+ ConnectStr = GetConnectStr(item.DatabaseConnect);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ ConnectStr = MysqlConn.ReadSqlConnStr;
|
|
|
+ }
|
|
|
string sql = item.SqlContent;
|
|
|
MatchCollection mc = Regex.Matches(sql, @"\$\{.*?\}\$");
|
|
|
foreach(Match m in mc)
|
|
|
@@ -185,7 +212,7 @@ namespace MySystem.Areas.Admin.Controllers
|
|
|
{
|
|
|
sql += " limit " + limit;
|
|
|
}
|
|
|
- DataTable dt = CustomerSqlConn.dtable(sql, MysqlConn.ReadSqlConnStr);
|
|
|
+ DataTable dt = CustomerSqlConn.dtable(sql, ConnectStr);
|
|
|
List<Dictionary<string, string>> diclist = new List<Dictionary<string, string>>();
|
|
|
foreach(DataRow dr in dt.Rows)
|
|
|
{
|
|
|
@@ -227,6 +254,16 @@ namespace MySystem.Areas.Admin.Controllers
|
|
|
List<CustomQuerySub> subItems = db.CustomQuerySub.Where(m => m.ParentId == Id).ToList();
|
|
|
foreach(CustomQuerySub sub in subItems)
|
|
|
{
|
|
|
+ string ConnectStr = sub.DatabaseConnect;
|
|
|
+ if(!string.IsNullOrEmpty(ConnectStr))
|
|
|
+ {
|
|
|
+ ConnectStr = GetConnectStr(sub.DatabaseConnect);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ ConnectStr = MysqlConn.ReadSqlConnStr;
|
|
|
+ }
|
|
|
+
|
|
|
string sqlstr = sub.SqlContent;
|
|
|
MatchCollection mcsub = Regex.Matches(sqlstr, @"\$\{.*?\}\$");
|
|
|
foreach(Match m in mcsub)
|
|
|
@@ -305,11 +342,21 @@ namespace MySystem.Areas.Admin.Controllers
|
|
|
public string Excute(int Id)
|
|
|
{
|
|
|
var sysAdmin = bsdb.SysAdmin.FirstOrDefault(m => m.AdminName == SysUserName && m.Status > -1);
|
|
|
-
|
|
|
+ string ConnectStr = "";
|
|
|
Dictionary<string, string> dicVals = new Dictionary<string, string>();
|
|
|
List<CustomQuerySub> subItems = db.CustomQuerySub.Where(m => m.ParentId == Id).ToList();
|
|
|
foreach(CustomQuerySub sub in subItems)
|
|
|
{
|
|
|
+ ConnectStr = sub.DatabaseConnect;
|
|
|
+ if(!string.IsNullOrEmpty(ConnectStr))
|
|
|
+ {
|
|
|
+ ConnectStr = GetConnectStr(sub.DatabaseConnect);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ ConnectStr = MysqlConn.ReadSqlConnStr;
|
|
|
+ }
|
|
|
+
|
|
|
string sqlstr = sub.SqlContent;
|
|
|
MatchCollection mcsub = Regex.Matches(sqlstr, @"\$\{.*?\}\$");
|
|
|
foreach(Match m in mcsub)
|
|
|
@@ -329,7 +376,7 @@ namespace MySystem.Areas.Admin.Controllers
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- DataTable dtsub = CustomerSqlConn.dtable(sqlstr, MysqlConn.ReadSqlConnStr);
|
|
|
+ DataTable dtsub = CustomerSqlConn.dtable(sqlstr, ConnectStr);
|
|
|
if(dtsub.Rows.Count > 0)
|
|
|
{
|
|
|
if(dtsub.Rows.Count > 1)
|
|
|
@@ -353,6 +400,15 @@ namespace MySystem.Areas.Admin.Controllers
|
|
|
}
|
|
|
}
|
|
|
CustomQuery item = db.CustomQuery.FirstOrDefault(m => m.Id == Id) ?? new CustomQuery();
|
|
|
+ ConnectStr = item.DatabaseConnect;
|
|
|
+ if(!string.IsNullOrEmpty(ConnectStr))
|
|
|
+ {
|
|
|
+ ConnectStr = GetConnectStr(item.DatabaseConnect);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ ConnectStr = MysqlConn.ReadSqlConnStr;
|
|
|
+ }
|
|
|
string sql = item.SqlContent;
|
|
|
MatchCollection mc = Regex.Matches(sql, @"\$\{.*?\}\$");
|
|
|
foreach(Match m in mc)
|
|
|
@@ -372,12 +428,21 @@ namespace MySystem.Areas.Admin.Controllers
|
|
|
sql = sql.Replace(m.Value, str);
|
|
|
}
|
|
|
var FileName = item.Title + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
|
|
|
- string SendData = "{\"Operater\":\"" + sysAdmin.Id + "\",\"SqlString\":\"" + sql + "\",\"FileName\":\"执行\",\"MaxCount\":\"" + item.ExcuteFlag + "\"}";
|
|
|
+ string SendData = "{\"Operater\":\"" + sysAdmin.Id + "\",\"SqlString\":\"" + sql + "\",\"FileName\":\"执行\",\"MaxCount\":\"" + item.ExcuteFlag + "\",\"ConnectStr\":\"" + ConnectStr + "\"}";
|
|
|
RedisDbconn.Instance.AddList("ExportQueue", SendData);
|
|
|
return "success";
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
+ #region 获取链接数据库字符串
|
|
|
+
|
|
|
+ public string GetConnectStr(string key)
|
|
|
+ {
|
|
|
+ return Library.ConfigurationManager.AppSettings[key].ToString();
|
|
|
+ }
|
|
|
+
|
|
|
+ #endregion
|
|
|
+
|
|
|
}
|
|
|
}
|