/// <summary> /// Lấy thông tin của cau kết nối /// </summary> /// <returns></returns> public static Conection getConection() { Conection conect = null; try { if (!File.Exists(clsGlobal.S_FILECONNECT)) { return(conect); } DataSet ds = new DataSet(); ds.ReadXml(clsGlobal.S_FILECONNECT); if (ds != null) { if (ds.Tables.Count > 0) { if (ds.Tables[0].Rows.Count > 0) { DataRow dr = ds.Tables[0].Select(DBCONNECT.COLUMN_ACTIVE + "=True")[0]; if (dr != null) { conect = new Conection { DataBase = dr[DBCONNECT.COLUMN_DATABASES].ToString(), ServerName = dr[DBCONNECT.COLUMN_SERVERS].ToString(), Uid = Cryptography.DecryptData(dr[DBCONNECT.COLUMN_UID].ToString()), Pwd = Cryptography.DecryptData(dr[DBCONNECT.COLUMN_PASSWORD].ToString()) }; } } } } } catch (Exception ex) { conect = null; Logger.TranferDataLog("Load Config Error " + ex.ToString() + "_" + DateTime.Now.ToString()); } return(conect); }
/// <summary> /// Thực hiện chạy file /// </summary> public static void RunScripFile() { if (isRunscriptFile) { return; } try { isRunscriptFile = true; DataSet ds = vnyi.Library.PUB.TranferData.GetFilePlustToDataBase(2); if (ds != null) { if (ds.Tables.Count > 0) { if (ds.Tables[0].Rows.Count > 0) { foreach (DataRow item in ds.Tables[0].Rows) { string FilePath = item["FilePath"].ToString(); if (File.Exists(FilePath)) { Int64 AutoID = clsFormat.Int64Convert(item["AUTOID"]); Logger.TranferDataLog("Excuse file " + FilePath); Conection conect = Utility.getConection(); string command = "/c sqlcmd -S " + conect.ServerName + " -U " + conect.Uid + " -P " + conect.Pwd + " -d " + conect.DataBase + " -i \"" + FilePath + "\"";// -o \"" + fileOutPut + "\""; ProcessStartInfo info = new ProcessStartInfo("cmd", command); info.UseShellExecute = false; info.CreateNoWindow = true; info.WindowStyle = ProcessWindowStyle.Hidden; info.WorkingDirectory = System.IO.Path.GetTempPath(); info.RedirectStandardOutput = true; info.RedirectStandardError = true; Process p = new Process(); p.StartInfo = info; p.Start(); string OutPut = p.StandardOutput.ReadToEnd(); if (!string.IsNullOrEmpty(OutPut)) { Logger.TranferDataLog(OutPut); } OutPut = p.StandardError.ReadToEnd(); p.WaitForExit(); bool isUpdateSucess = false; do { isUpdateSucess = vnyi.Library.PUB.TranferData.UpdateFileExcuted(AutoID); }while (!isUpdateSucess); File.Delete(FilePath); } } } } } } catch (Exception ex) { Logger.TranferDataLog("Excuce Script Error :" + ex.ToString()); } finally { isRunscriptFile = false; } }