Commit abae6d68 authored by 罗显健's avatar 罗显健

更新器优化:1.发布按钮增加控制 2.执行的脚本文件显示相对路径。

parent a5c81d7c
...@@ -79,8 +79,6 @@ namespace UpdateExecuter ...@@ -79,8 +79,6 @@ namespace UpdateExecuter
} }
/// <summary> /// <summary>
/// 分割sql脚本,返回单条可执行脚本。 /// 分割sql脚本,返回单条可执行脚本。
/// 处理 go 语句执行会报错的情况。 /// 处理 go 语句执行会报错的情况。
...@@ -130,6 +128,17 @@ namespace UpdateExecuter ...@@ -130,6 +128,17 @@ namespace UpdateExecuter
return lstSql; return lstSql;
} }
/// <summary>
/// 返回相对目录。A - B。
/// </summary>
/// <param name="pathSource">源路径 A</param>
/// <param name="pathBase">基础路径 B</param>
/// <returns></returns>
public static string GetRelativePath(string pathSource, string pathBase)
{
return pathSource.Replace(pathBase, "").TrimStart(new char[] { '\\' });
}
} }
} }
...@@ -162,49 +162,17 @@ namespace UpdateExecuter ...@@ -162,49 +162,17 @@ namespace UpdateExecuter
private async void btnExecute_Click(object sender, System.EventArgs e) private async void btnExecute_Click(object sender, System.EventArgs e)
{ {
Debug.WriteLine($"当前线程:{System.Threading.Thread.CurrentThread.ManagedThreadId }"); try
this._scriptPath = txtDBPath.Text;
this._updateFilePath = txtFilePath.Text;
if (string.IsNullOrEmpty(_scriptPath) && string.IsNullOrEmpty(_updateFilePath))
{ {
MessageBox.Show(this, "[脚本目录]和[文件目录]不能同时为空,请至少选择一个!", "提示"); btnExecute.Enabled = false;
return;
}
if (!string.IsNullOrEmpty(_scriptPath) && !Directory.Exists(_scriptPath)) Debug.WriteLine($"当前线程:{System.Threading.Thread.CurrentThread.ManagedThreadId }");
{
MessageBox.Show(this, "目录有误!", "提示");
this.txtDBPath.Focus();
return;
}
if (!string.IsNullOrEmpty(_updateFilePath) && !Directory.Exists(_updateFilePath))
{
MessageBox.Show(this, "目录有误!", "提示");
this.txtFilePath.Focus();
return;
}
var items = lstClient.CheckedItems; if (!CheckExecuter()) return;
if (items.Count == 0)
{
MessageBox.Show("请选择客户...");
return;
}
List<string> lstClientName = new List<string>(); var lstClientName = GetSelectedClient();
for (var i = 0; i < items.Count; i++)
{
ListViewItem item = items[i];
item.ForeColor = System.Drawing.Color.Black;
item.BackColor = System.Drawing.Color.White;
lstClientName.Add(item.Text);
}
listViewMsg.Items.Clear(); listViewMsg.Items.Clear(); // 清空历史消息
#region 执行数据库脚本更新 #region 执行数据库脚本更新
...@@ -225,7 +193,6 @@ namespace UpdateExecuter ...@@ -225,7 +193,6 @@ namespace UpdateExecuter
#endregion #endregion
#region 发布程序文件更新 #region 发布程序文件更新
if (!string.IsNullOrEmpty(_updateFilePath)) if (!string.IsNullOrEmpty(_updateFilePath))
...@@ -234,8 +201,15 @@ namespace UpdateExecuter ...@@ -234,8 +201,15 @@ namespace UpdateExecuter
} }
#endregion #endregion
}
catch (Exception ex)
{
MessageBox.Show($"更新发布失败:{ex.Message}");
}
finally
{
btnExecute.Enabled = true;
}
lblSpeed.Text = "更新发布完成!"; lblSpeed.Text = "更新发布完成!";
} }
...@@ -267,6 +241,61 @@ namespace UpdateExecuter ...@@ -267,6 +241,61 @@ namespace UpdateExecuter
} }
} }
/// <summary>
/// 更新之前的检查操作
/// </summary>
/// <returns></returns>
private bool CheckExecuter()
{
this._scriptPath = txtDBPath.Text;
this._updateFilePath = txtFilePath.Text;
if (string.IsNullOrEmpty(_scriptPath) && string.IsNullOrEmpty(_updateFilePath))
{
MessageBox.Show(this, "[脚本目录]和[文件目录]不能同时为空,请至少选择一个!", "提示");
return false;
}
if (!string.IsNullOrEmpty(_scriptPath) && !Directory.Exists(_scriptPath))
{
MessageBox.Show(this, "目录有误!", "提示");
this.txtDBPath.Focus();
return false;
}
if (!string.IsNullOrEmpty(_updateFilePath) && !Directory.Exists(_updateFilePath))
{
MessageBox.Show(this, "目录有误!", "提示");
this.txtFilePath.Focus();
return false;
}
var items = lstClient.CheckedItems;
if (items.Count == 0)
{
MessageBox.Show("请选择客户...");
return false;
}
return true;
}
/// <summary>
/// 获取选择的客户列表
/// </summary>
/// <returns></returns>
private List<string> GetSelectedClient()
{
List<string> lstClientName = new List<string>();
var items = lstClient.CheckedItems;
for (var i = 0; i < items.Count; i++)
{
ListViewItem item = items[i];
item.ForeColor = System.Drawing.Color.Black;
item.BackColor = System.Drawing.Color.White;
lstClientName.Add(item.Text);
}
return lstClientName;
}
#endregion #endregion
...@@ -368,7 +397,7 @@ namespace UpdateExecuter ...@@ -368,7 +397,7 @@ namespace UpdateExecuter
num++; num++;
_execSql = sql; _execSql = sql;
ShowProcessSpeed(file.FullName, $"执行进度:{num}/{lstSql.Count}", sql); ShowProcessSpeed(Utils.GetRelativePath(file.FullName, _scriptPath), $"执行进度:{num}/{lstSql.Count}", sql);
SqlHelper.ExecuteNonQuery(conn, CommandType.Text, sql); SqlHelper.ExecuteNonQuery(conn, CommandType.Text, sql);
})); }));
...@@ -383,7 +412,7 @@ namespace UpdateExecuter ...@@ -383,7 +412,7 @@ namespace UpdateExecuter
} }
catch (Exception ex) catch (Exception ex)
{ {
ShowProcessSpeed(_execFile.FullName, $"执行失败:{ex.Message}", _execSql); ShowProcessSpeed(Utils.GetRelativePath(_execFile.FullName, _scriptPath), $"执行失败:{ex.Message}", _execSql);
ShowFileInfo($"在客户[{client}]执行脚本文件失败:{_execFile.Name}.", _execFile, false); ShowFileInfo($"在客户[{client}]执行脚本文件失败:{_execFile.Name}.", _execFile, false);
MessageBox.Show($"在客户 [{client}] 执行脚本失败, Ctrl + V 查看脚本。 \r\n{ex.Message}"); MessageBox.Show($"在客户 [{client}] 执行脚本失败, Ctrl + V 查看脚本。 \r\n{ex.Message}");
return false; return false;
...@@ -391,9 +420,6 @@ namespace UpdateExecuter ...@@ -391,9 +420,6 @@ namespace UpdateExecuter
return true; return true;
} }
#endregion #endregion
#region 文件更新操作 #region 文件更新操作
...@@ -438,8 +464,6 @@ namespace UpdateExecuter ...@@ -438,8 +464,6 @@ namespace UpdateExecuter
} }
} }
/// <summary> /// <summary>
/// 上传更新文件 /// 上传更新文件
/// </summary> /// </summary>
...@@ -499,10 +523,6 @@ namespace UpdateExecuter ...@@ -499,10 +523,6 @@ namespace UpdateExecuter
} }
#endregion #endregion
#region 其他 #region 其他
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment