Esempio n. 1
0
        public static string Query(string sql, string dataSource)
        {
            IOWxg.Log(string.Format("sql:{0}", sql));
            IOWxg.Log(string.Format("dataSource:{0}", dataSource));

            DataSet ds = new DataSet();

            try
            {
                using (var adapter = new SqlDataAdapter(sql, dataSource))
                {
                    adapter.Fill(ds);
                }
            }
            catch (Exception ex)
            {
                IOWxg.Log(ex.StackTrace);
                return("error:" + ex.Message);
            }
            if (ds.Tables.Count == 0)
            {
                return(string.Empty);
            }

            return(UtilWxg.DataTabletoString(ds.Tables[0]));
        }
Esempio n. 2
0
        private static string ToSQLConnectString(string dataSource)
        {
            SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder();

            builder.DataSource     = UtilWxg.GetMatchGroup(dataSource, @"host=(\w)+", 1);          // 接続先の SQL Server インスタンス
            builder.UserID         = UtilWxg.GetMatchGroup(dataSource, @"User ID=(\w)+", 1);       // 接続ユーザー名
            builder.Password       = UtilWxg.GetMatchGroup(dataSource, @"Password=(\w)+", 1);      // 接続パスワード
            builder.InitialCatalog = UtilWxg.GetMatchGroup(dataSource, @"SERVICE_NAME=(\w)+", 1);; // 接続するデータベース(ここは変えないでください)
            // builder.ConnectTimeout = 60000;  // 接続タイムアウトの秒数(ms) デフォルトは 15 秒
            return(builder.ConnectionString);
        }
Esempio n. 3
0
        public static string ReplaceFiles(string diretoryName, string searchPattern, string pattern, int groupIndex, string replacement)
        {
            StringBuilder sb = new StringBuilder();

            sb.Append("method=").AppendLine("ReplaceFiles");
            sb.Append("diretoryName=").AppendLine(diretoryName);
            sb.Append("searchPattern=").AppendLine(searchPattern);
            sb.Append("pattern=").AppendLine(pattern);
            sb.Append("groupIndex=").AppendLine(groupIndex.ToString());
            sb.Append("replacement=").AppendLine(replacement);
            Log(sb.ToString());

            List <string> lstFile = new List <string>();
            DirectoryInfo di      = new DirectoryInfo(diretoryName);

            if (di.Exists)
            {
                foreach (FileInfo fi in di.GetFiles(searchPattern))
                {
                    //ファイル名変更
                    string fileName = UtilWxg.ReplaceMatchGroup(fi.Name, pattern, groupIndex, replacement);
                    if (!fileName.Equals(fi.Name))
                    {
                        string newFileName = fi.FullName.Replace(fi.Name, fileName);
                        fi.MoveTo(newFileName);
                    }
                    //ファイル内容変更
                    if (ReplaceFile(fi.FullName, searchPattern, pattern, groupIndex, replacement))
                    {
                        lstFile.Add(fi.FullName);
                    }
                }
                //フォルダ名変更
                string folderName = UtilWxg.ReplaceMatchGroup(di.Name, pattern, groupIndex, replacement);
                if (!folderName.Equals(di.Name))
                {
                    string newFolderName = di.FullName.Replace(di.Name, folderName);
                    di.MoveTo(newFolderName);
                }
                //サブフォルダ内ファイルの変更
                foreach (DirectoryInfo fi in di.GetDirectories())
                {
                    lstFile.Add(ReplaceFiles(fi.FullName, searchPattern, pattern, groupIndex, replacement) + Environment.NewLine);
                }
            }
            return(string.Join(Environment.NewLine, lstFile));
        }
Esempio n. 4
0
        public static string Batch(string sql, string dataSource)
        {
            IOWxg.Log(string.Format("sql:{0}", sql));
            IOWxg.Log(string.Format("dataSource:{0}", dataSource));

            List <string> lstValue = new List <string>();

            try
            {
                using (var con = new SqlConnection(dataSource))
                {
                    con.Open();
                    DbTransaction transaction = con.BeginTransaction();

                    string[] sqls = sql.Split(";".ToCharArray());
                    foreach (var sql1 in sqls)
                    {
                        if (sql.StartsWith("SELECT", StringComparison.OrdinalIgnoreCase))
                        {
                            DataTable dt = new DataTable();
                            using (var adapter = new SqlDataAdapter(sql1, con))
                            {
                                adapter.Fill(dt);
                            }
                            lstValue.Add(UtilWxg.DataTabletoString(dt));
                        }
                        else
                        {
                            using (var cmd = new SqlCommand(sql1, con))
                            {
                                int count = cmd.ExecuteNonQuery();
                                lstValue.Add(count.ToString());
                            }
                        }
                    }
                    transaction.Commit();
                }
            }
            catch (Exception ex)
            {
                IOWxg.Log(ex.Message);
                return("error:" + ex.Message);
            }
            return(string.Join(";", lstValue));
        }
Esempio n. 5
0
        private static bool ReplaceFile(FileInfo fi, string searchPattern, string pattern, int groupIndex, string replacement)
        {
            bool isChanged = false;

            if (fi.Exists)
            {
                string oldFileName = fi.FullName;
                string input       = File.ReadAllText(fi.FullName);
                string replaced    = UtilWxg.ReplaceMatchGroup(input, pattern, groupIndex, replacement);
                if (!input.Equals(replaced))
                {
                    isChanged = true;
                    fi.MoveTo(fi.FullName + DateTime.Now.ToString("_yyyyMMddhhmmss.bak"));
                    File.WriteAllText(oldFileName, replaced);
                }
            }
            return(isChanged);
        }