using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using System.IO;

namespace Post
{
    public class SqlFileCreater
    {
        public string PATH { get; set; }
        public string FILENAME { get; set; }
        public SqlFileCreater(string filePath, string alias)
        {
            this.PATH = filePath;
            this.FILENAME = alias;
        }
        public bool WriteFile(string ddlQuery)
        {
            bool isWrite = true;
            Console.WriteLine("WriteFile : " + ddlQuery);
            string path = String.Format(@"{0}\\sql\\{1}_{2}.sql", PATH, FILENAME, @DateTime.Now.ToString("yyyyMMddHHmm"));
            Console.WriteLine("path : " + path);

            try
            {
                using(File.Create(path))
                {
                    Console.WriteLine("파일 생성 성공");
                }

                StreamWriter writer = File.AppendText(path);
                writer.WriteLine(ddlQuery);
                writer.Close();
                Console.WriteLine("파일 작성 성공");
            } catch(Exception e)
            {
                Console.WriteLine("write file : " + e.ToString());
                return false;
            }
            return isWrite;
        }
    }
}
