@@ -161,7 +161,7 @@ private void OutputScripts_Click(object sender, EventArgs e)
161161 string FileName = saveFileDialog . FileName ;
162162 if ( ! File . Exists ( FileName ) )
163163 {
164- using ( StreamWriter writetext = new StreamWriter ( FileName ) )
164+ using ( StreamWriter writetext = new StreamWriter ( FileName , true , Encoding . Default ) )
165165 {
166166 writetext . WriteLine ( "" ) ;
167167 }
@@ -254,6 +254,7 @@ private void RunScript_Click(object sender, EventArgs e)
254254 {
255255 string sqlText = "" ;
256256 string readtext = "" ;
257+ string FilePath = $@ "{ Directory . GetCurrentDirectory ( ) } { "\\ " } ";
257258 DialogResult result = new DialogResult ( ) ;
258259
259260 //判斷資料夾路徑是否存在
@@ -264,31 +265,30 @@ private void RunScript_Click(object sender, EventArgs e)
264265 sqlText += $@ ":r { FolderPath . Text } { "\\ " } { str } { "\n " } ";
265266 }
266267 //儲存清單.sql
267- using ( StreamWriter writetext = new StreamWriter ( $@ "{ Directory . GetCurrentDirectory ( ) } { "\\ " } { " list.sql"} ") )
268+ using ( StreamWriter writetext = new StreamWriter ( $@ "{ FilePath } { "list.sql" } ", true , Encoding . Default ) )
268269 {
269270 writetext . WriteLine ( sqlText ) ;
270271 sqlText = "" ;
271272 }
272273 //讀取 一次執行資料夾內所有的Script 文字
273- using ( StreamReader reader = new StreamReader ( $@ "{ Directory . GetCurrentDirectory ( ) } { " \\ " } { "sample.bat" } ", Encoding . Default ) )
274+ using ( StreamReader reader = new StreamReader ( $@ "{ FilePath } { "sample.bat" } ", Encoding . Default ) )
274275 {
275276 readtext = reader . ReadToEnd ( ) ;
276277 }
277278
278279 //設定bat檔內的資練庫連線資訊
279- string FilePath = $@ "{ FolderPath . Text } { "\\ ..\\ " } ";
280280 readtext = readtext . Replace ( "dbIp=*" , $@ "dbIp={ DBLocation . Text } ") ;
281281 readtext = readtext . Replace ( "dbName=*" , $@ "dbName={ DBName . Text } ") ;
282282 readtext = readtext . Replace ( "dbUsrAcc=*" , $@ "dbUsrAcc={ UserName . Text } ") ;
283283 readtext = readtext . Replace ( "dbUsrPwd=*" , $@ "dbUsrPwd={ password . Text } ") ;
284- readtext = readtext . Replace ( "batchFilePath=\" \" " , $@ "batchFilePath=""{ Path . GetFullPath ( FilePath ) } """);
285- readtext = readtext.Replace(" dbSqlFilePath= \" \" ", $@ "dbSqlFilePath=""{ Directory . GetCurrentDirectory ( ) } { " \\ " } { "list.sql" } """);
284+ readtext = readtext . Replace ( "batchFilePath=\" \" " , $@ "batchFilePath=""{ FilePath } """);
285+ readtext = readtext.Replace(" dbSqlFilePath= \" \" ", $@ "dbSqlFilePath=""{ FilePath } { "list.sql" } """);
286286
287287 // 判斷檔案是否存在
288288 string FileName = $@" { FilePath} { "RunScripts.bat" } ";
289289 if ( ! File . Exists ( FileName ) )
290290 {
291- using ( StreamWriter writetext = new StreamWriter ( FileName ) )
291+ using ( StreamWriter writetext = new StreamWriter ( FileName , true , Encoding . Default ) )
292292 {
293293 writetext . WriteLine ( "" ) ;
294294 }
@@ -305,12 +305,17 @@ private void RunScript_Click(object sender, EventArgs e)
305305 result = MessageBox . Show ( "是否執行勾選的script?" , "提示" , MessageBoxButtons . YesNo ) ;
306306 if ( result == DialogResult . Yes )
307307 {
308+ //如果log資料夾不存在就自動生成
309+ if ( ! Directory . Exists ( ( $@ "{ FilePath } { "\\ " } { "log" } ") ) )
310+ {
311+ Directory . CreateDirectory ( "log" ) ;
312+ }
308313 //開始執行批次檔
309314 ProcessStartInfo process = new ProcessStartInfo ( ) ;
310315 process . FileName = "RunScripts.bat" ;
311316 process . WorkingDirectory = FilePath ;
312317 Process . Start ( process ) ;
313- MessageBox . Show ( "已放置執行紀錄於./view. log" ) ;
318+ MessageBox . Show ( $@ "已放置執行紀錄於.\ log") ;
314319 }
315320 }
316321 else
0 commit comments