Skip to content

Commit

Permalink
v1.3 更新 bugfix
Browse files Browse the repository at this point in the history
修复数据库事务的一些bug
  • Loading branch information
GMYXDS committed Nov 3, 2022
1 parent 5b4ca23 commit 2b7c696
Show file tree
Hide file tree
Showing 7 changed files with 103 additions and 54 deletions.
4 changes: 2 additions & 2 deletions MstscManager/Controls/Set_exe_directory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ private void set_or_update_path(string key,UITextBox button) {
path = path.Replace(System.Environment.CurrentDirectory+"\\", "");
//Console.WriteLine(path);
if (button.Text != "") {//update
DbSqlHelper.ExecuteNonQuery("update Commom_setting set val = ? where key = ?", path, key);
DbSqlHelper.ExecuteNonQuery2("update Commom_setting set val = ? where key = ?", path, key);
} else {//insert
DbSqlHelper.ExecuteNonQuery("INSERT INTO Commom_setting (key,val) VALUES (?,?);", key, path);
DbSqlHelper.ExecuteNonQuery2("INSERT INTO Commom_setting (key,val) VALUES (?,?);", key, path);
}
button.Text = path;
}
Expand Down
111 changes: 68 additions & 43 deletions MstscManager/FMain.cs

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions MstscManager/Forms/Add_server.cs
Original file line number Diff line number Diff line change
Expand Up @@ -352,13 +352,13 @@ private void uiButton1_Click(object sender, EventArgs e) {
string notice_msg = "数据添加成功!";
if (!is_update) {
//保存数据库
DbSqlHelper.ExecuteNonQuery("INSERT INTO Server_setting(server_name,group_id,connect_type,ip,port,user_name,user_pass,end_date,mark_text,user_id,connect_setting,connect_string) VALUES (?,?,?,?,?,?,?,?,?,?,?,?);",
DbSqlHelper.ExecuteNonQuery2("INSERT INTO Server_setting(server_name,group_id,connect_type,ip,port,user_name,user_pass,end_date,mark_text,user_id,connect_setting,connect_string) VALUES (?,?,?,?,?,?,?,?,?,?,?,?);",
config["server_name"], config["group_id"], config["connect_type"], config["ip"], config["port"], config["user_name"], config["user_pass"], config["end_date"], config["mark_text"], config["user_id"], config["connect_setting"], config["connect_string"]);
//ShowInfoNotifier("数据添加成功!");
} else {
//更新
//保存数据库
DbSqlHelper.ExecuteNonQuery("update Server_setting set server_name = ?,group_id = ?,connect_type = ?,ip = ?,port = ?,user_name = ?,user_pass = ?,end_date = ?,mark_text = ?,user_id = ?,connect_setting = ?,connect_string = ? where id = ?",
DbSqlHelper.ExecuteNonQuery2("update Server_setting set server_name = ?,group_id = ?,connect_type = ?,ip = ?,port = ?,user_name = ?,user_pass = ?,end_date = ?,mark_text = ?,user_id = ?,connect_setting = ?,connect_string = ? where id = ?",
config["server_name"], config["group_id"], config["connect_type"], config["ip"], config["port"], config["user_name"], config["user_pass"], config["end_date"], config["mark_text"], config["user_id"], config["connect_setting"], config["connect_string"],target_id);
notice_msg = "数据更新成功!";
}
Expand Down
8 changes: 4 additions & 4 deletions MstscManager/Forms/user.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ private void uiButton1_Click(object sender, EventArgs e) {
string mark_text = uiTextBox3.Text;
if (user_name == "") { ShowWarningTip("<用户名>是必须的!"); return; }
if (user_pass == "") { ShowWarningTip("<密码>是必须的!"); return; }
DbSqlHelper.ExecuteNonQuery("insert into User_setting (user_name,user_pass,mark_text) values (?,?,?)", user_name, user_pass, mark_text);
DbSqlHelper.ExecuteNonQuery2("insert into User_setting (user_name,user_pass,mark_text) values (?,?,?)", user_name, user_pass, mark_text);
//ShowInfoNotifier("数据添加成功!");
ShowSuccessTip("数据添加成功");
//刷新界面?
Expand All @@ -28,7 +28,7 @@ private void uiButton2_Click(object sender, EventArgs e) {
if (ShowAskDialog("确定要删除当前选中的账号吗?删除之后,如果有关联的服务器将失效!", false)) {
string id = uiDataGridView1.SelectedRows[0].Cells[3].Value.ToString();
//Console.WriteLine(id);
DbSqlHelper.ExecuteNonQuery("delete from User_setting where id = ?", id);
DbSqlHelper.ExecuteNonQuery2("delete from User_setting where id = ?", id);
uiDataGridView1.Rows.Remove(uiDataGridView1.SelectedRows[0]);
ShowSuccessTip("数据删除成功");
}
Expand Down Expand Up @@ -70,7 +70,7 @@ private void real_init() {
private void update_table() {
UIDataGridView view = uiDataGridView1;
view.Rows.Clear();
SqliteDataReader reader = DbSqlHelper.ExecuteReader("select * from User_setting");
SqliteDataReader reader = DbSqlHelper.ExecuteReader2("select * from User_setting");
while (reader.Read()) {
view.Rows.Add(reader["user_name"], reader["user_pass"], reader["mark_text"], reader["id"]);
}
Expand All @@ -85,7 +85,7 @@ private void uiButton3_Click(object sender, EventArgs e) {
string mark_text = uiTextBox3.Text;
if (user_name == "") { ShowWarningTip("<用户名>是必须的!"); return; }
if (user_pass == "") { ShowWarningTip("<密码>是必须的!"); return; }
DbSqlHelper.ExecuteNonQuery("update User_setting set user_name = ?,user_pass = ?,mark_text = ? where id = ? ", user_name, user_pass, mark_text,id);
DbSqlHelper.ExecuteNonQuery2("update User_setting set user_name = ?,user_pass = ?,mark_text = ? where id = ? ", user_name, user_pass, mark_text,id);
ShowSuccessTip("数据更新成功");
update_table();
}
Expand Down
25 changes: 23 additions & 2 deletions MstscManager/Utils/DbSqlHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,27 @@ private static void PrepareCommand(SqliteCommand cmd, SqliteConnection conn, str
}
cmd.Prepare();
}
private static void PrepareCommand2(SqliteCommand cmd, SqliteConnection conn, string cmdText, params object[] p) {
if (conn.State != ConnectionState.Open) conn.Open();
cmd.Parameters.Clear();
cmd.Connection = conn;
cmd.CommandText = cmdText;
cmd.CommandType = CommandType.Text;
cmd.CommandTimeout = 30;
if (p != null) {
int index = 0;
while (index < p.Length) {
cmd.CommandText = cmd.CommandText.ReplaceOne("?", "$t" + index.ToString());
index++;
}
index = 0;
foreach (object parm in p) {
cmd.Parameters.AddWithValue("$t" + index.ToString(), parm);
index++;
}
}
cmd.Prepare();
}
public static int ExecuteNonQuery(string cmdText, params object[] p) {
if (common_conn == null) common_conn = new SqliteConnection(ConnectionString);
//using (SqliteConnection conn = new SqliteConnection(ConnectionString)) {
Expand All @@ -45,7 +66,7 @@ public static int ExecuteNonQuery2(string cmdText, params object[] p) {
//if (common_conn == null) common_conn = new SqliteConnection(ConnectionString);
using (SqliteConnection conn = new SqliteConnection(ConnectionString)) {
using (SqliteCommand command = new SqliteCommand()) {
PrepareCommand(command, conn, cmdText, p);
PrepareCommand2(command, conn, cmdText, p);
return command.ExecuteNonQuery();
}
}
Expand All @@ -61,7 +82,7 @@ public static SqliteDataReader ExecuteReader2(string cmdText, params object[] p)
//if (common_conn == null) common_conn = new SqliteConnection(ConnectionString);
SqliteConnection conn = new SqliteConnection(ConnectionString);
SqliteCommand command = new SqliteCommand();
PrepareCommand(command, conn, cmdText, p);
PrepareCommand2(command, conn, cmdText, p);
return command.ExecuteReader(CommandBehavior.CloseConnection);

}
Expand Down
2 changes: 1 addition & 1 deletion MstscManager/Utils/Share.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ public static class Share {
public static string iniconfig_path = @"data\MstscManager.ini";
public static string iniconfig_action = "Settings";
public static string now_group_name = "全部分类";
public static string now_version = "1.2";
public static string now_version = "1.3";
}
}
3 changes: 3 additions & 0 deletions Updates.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,6 @@
- [x] 优化导入导出txt卡顿问题,将txt导入导出改成了csv导入导出
- [x] 优化整体软件交互速度

## v1.3

- 修复加速sql的一些bug

0 comments on commit 2b7c696

Please sign in to comment.