Skip to content

Commit

Permalink
Todays updates and pics
Browse files Browse the repository at this point in the history
  • Loading branch information
mmeents committed Dec 10, 2022
1 parent bc55f84 commit ee8b4d5
Show file tree
Hide file tree
Showing 9 changed files with 307 additions and 107 deletions.
48 changes: 43 additions & 5 deletions AppStatic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public static Int32 GetImageIndexFromCode(string ObjectType) {
}

public static class CodeStatic {
public static string nl { get { return Environment.NewLine; } }
public static string SQLDefNullValue(string sqlType) {
string w = sqlType.ToLower().ParseString(" ()", 0);
string result = "";
Expand Down Expand Up @@ -62,11 +63,14 @@ public static string GetSQLParamList(this TreeNode tnTable) {
}
return sRes;
}
public static string GetSQLInsertListAsSQLParam(this TreeNode tnTable) {
public static string GetSQLInsertListAsSQLParam(this TreeNode tnTable, bool IncludeFirstCol = false) {
string sRes = ""; string sFTT = "true";
foreach (TreeNode tn in tnTable.Nodes) {
if (sFTT == "true") {
sFTT = "false";
if (IncludeFirstCol) {
sRes = "@" + tn.Text.ParseString(" ()", 0);
}
} else {
if (sRes == "") {
sRes = "@" + tn.Text.ParseString(" ()", 0);
Expand Down Expand Up @@ -219,7 +223,8 @@ public static string GenerateCSharpRepoLikeClassFromTable(this TreeNode tnTable)
$" IEnumerable<{className}> result;" + nl +
" string connectionString = Settings.GetConnectionString(\"PD\");" + nl +
" using (SqlConnection connection = new SqlConnection(connectionString)) {" + nl +
$" result = await connection.QueryAsync<{className}>(\"select {sColListb} from {tblName} \");" + nl +
$" result = await connection.QueryAsync<{className}>("+nl+
$" \"select {sColListb} from {tblName} \");" + nl +
" }" + nl +
" return Ok(result);" + nl +
" }" + nl + nl +
Expand All @@ -229,7 +234,8 @@ public static string GenerateCSharpRepoLikeClassFromTable(this TreeNode tnTable)
$" {className} result;" + nl +
" using (SqlConnection connection = new SqlConnection(connectionString)) {" + nl +
" var param = new {" + sKey + "};" + nl +
$" result = await connection.QueryFirstOrDefaultAsync<{className}>(\"select {sColListb} from {tblName} where {sKey} = @{sKey} \", param);" + nl +
$" result = await connection.QueryFirstOrDefaultAsync<{className}>("+nl+
$" \"select {sColListb} from {tblName} where {sKey} = @{sKey} \", param);" + nl +
" }" + nl +
" return Ok($\"{result.AsJson()}\");" + nl +
" }" + nl + nl +
Expand All @@ -238,7 +244,8 @@ public static string GenerateCSharpRepoLikeClassFromTable(this TreeNode tnTable)
" string connectionString = Settings.GetConnectionString(\"PD\");" + nl +
$" {className} result;" + nl +
" using (SqlConnection connection = new SqlConnection(connectionString)) {" + nl +
$" result = await connection.QueryFirstOrDefaultAsync<{className}>(\"dbo.sp_AddUpdate{className}\", {classVarName}, commandType: CommandType.StoredProcedure);" + nl +
$" result = await connection.QueryFirstOrDefaultAsync<{className}>("+nl+
$" \"dbo.sp_AddUpdate{className}\", {classVarName}, commandType: CommandType.StoredProcedure);" + nl +
" }" + nl +
" return Ok(result.AsJson());" + nl +
" }" + nl + nl +
Expand All @@ -248,7 +255,8 @@ public static string GenerateCSharpRepoLikeClassFromTable(this TreeNode tnTable)
" string connectionString = Settings.GetConnectionString(\"PD\");" + nl +
" var param = new {" + $"{sKey}" + "};" + nl +
" using (SqlConnection connection = new SqlConnection(connectionString)) {" + nl +
" result = await connection.ExecuteAsync(\"delete from " + $"[{className}] where [{sKey}] = @{sKey} " + "\", param);" + nl +
" result = await connection.ExecuteAsync("+nl+
" \"delete from " + $"[{className}] where [{sKey}] = @{sKey} " + "\", param);" + nl +
" }" + nl +
" return Ok(result == 1);" + nl +
" }" + nl +
Expand All @@ -258,6 +266,36 @@ public static string GenerateCSharpRepoLikeClassFromTable(this TreeNode tnTable)

}

public static string GenerateCSharpExecStoredProc(this TreeNode tnStProc) {
string sDBName = tnStProc.Parent.Parent.Parent.Text.ParseFirst(":");
string a = "";
string c = "";
for (Int32 i = 0; i < tnStProc.Nodes.Count; i++) {
if (a == "") {
a = tnStProc.Nodes[i].Text.ParseString(" @", 0).AsLowerCaseFirstLetter();
} else {
a = a + ", " + tnStProc.Nodes[i].Text.ParseString(" @", 0).AsLowerCaseFirstLetter();
}
c = c + nl + $" {GetCTypeFromSQLType(tnStProc.Nodes[i].Text.ParseLast(" "))} {tnStProc.Nodes[i].Text.ParseFirst(" @").AsLowerCaseFirstLetter()} = {SQLDefNullValue(tnStProc.Nodes[i].Text.ParseLast(" "))};";
}
string className = tnStProc.Text.ParseLast(".").AsUpperCaseFirstLetter();
var s = " // C Dapper Edit via Add Update stored procdure" + nl +
$" public async Task<ActionResult> Exec{className}Async() " + "{" + nl +
$" string connectionString = Settings.GetConnectionString(\"{sDBName}\");" + nl +
$" {className}Result result;" +
c + nl +
" var params = new {" + $"{a}" + "};" + nl +
" using (SqlConnection connection = new SqlConnection(connectionString)) {" + nl +
$" result = await connection.QueryAsync<{className}Result>(\"{tnStProc.Text.ParseFirst(" ")}\", params, commandType: CommandType.StoredProcedure);" + nl +
" }" + nl +
" return Ok(result.ToJson());" + nl +
" }" + nl + nl;
return s;
}
public static string GetExecSQLStoredProcedure(this TreeNode tnStProc) {
return "-- the call to execute " + nl
+$"Exec {tnStProc.Text} {tnStProc.GetSQLInsertListAsSQLParam(true)}";
}

}
}
Binary file added Images/GenerateFromTable.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Images/SetConnectionStrings.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit ee8b4d5

Please sign in to comment.