public static SqlDBSetting SqlDBLoad()
        {
            SqlDBSetting setting = null;

            if (!Directory.Exists($"{MyWorkPath}\\stf"))
            {
                Directory.CreateDirectory($"{MyWorkPath}\\stf");
            }
            string SettingPath = $"{MyWorkPath}\\stf\\SqlDB.json";

            try
            {
                if (File.Exists(SettingPath))
                {
                    string json = File.ReadAllText(SettingPath, Encoding.UTF8);
                    setting = JsonConvert.DeserializeObject <SqlDBSetting>(json);
                }
                else
                {
                    SqlDBSetting Setting = new SqlDBSetting()
                    {
                        SQLEnumsType   = 1,
                        DataSource     = "127.0.0.1",
                        InitialCatalog = "chargingpiles",
                        UserID         = "root",
                        Password       = "******"
                    };
                    setting = Setting;
                    string output = JsonConvert.SerializeObject(setting, Formatting.Indented, new JsonSerializerSettings());
                    File.WriteAllText(SettingPath, output);
                }
            }
            catch (Exception ex)
            {
                Log.Error(ex, " SQLDB資訊設定載入錯誤");
            }
            return(setting);
        }
Esempio n. 2
0
        /// <summary>
        /// 資料庫JSON建置與讀取
        /// </summary>
        /// <returns></returns>
        public static SqlDBSetting SqlDB()
        {
            SqlDBSetting setting = new SqlDBSetting();

            if (!Directory.Exists($"{MyWorkPath}\\stf"))
            {
                Directory.CreateDirectory($"{MyWorkPath}\\stf");
            }
            string SettingPath = $"{MyWorkPath}\\stf\\SqlDB.json";

            try
            {
                if (File.Exists(SettingPath))
                {
                    string json = File.ReadAllText(SettingPath, Encoding.UTF8);
                    setting = JsonConvert.DeserializeObject <SqlDBSetting>(json);
                }
                else
                {
                    SqlDBSetting Setting = new SqlDBSetting()
                    {
                        DataSource     = "127.0.0.1",
                        InitialCatalog = "Turnkeydb",
                        UserID         = "sa",
                        Password       = "******"
                    };
                    setting = Setting;
                    string output = JsonConvert.SerializeObject(setting, Formatting.Indented, new JsonSerializerSettings());
                    File.WriteAllText(SettingPath, output);
                }
            }
            catch (Exception ex)
            {
                Log.Error(ex, "System setting initial 資料庫JSON failed.");
            }
            return(setting);
        }
Esempio n. 3
0
        public Form1()
        {
            InitializeComponent();

            Log.Logger = new LoggerConfiguration()
                         .WriteTo.Console()
                         .WriteTo.File($"{AppDomain.CurrentDomain.BaseDirectory}\\log\\log-.txt",
                                       rollingInterval: RollingInterval.Day,
                                       outputTemplate: "{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} [{Level:u3}] {Message:lj}{NewLine}{Exception}")
                         .CreateLogger();       //宣告Serilog初始化

            RemoveReportPathSetting = InitialMethod.RemoveReportPath();
            SqlDBSetting            = InitialMethod.SqlDB();

            SQLMethod = new SQLMethod()
            {
                Form1 = this, setting = SqlDBSetting
            };
            SQLMethod.SQLConnect();

            XMLMethod = new XMLMethod()
            {
                Form1 = this, RemoveReportPathSetting = RemoveReportPathSetting
            };

            A0101Protocol a0101Protocol = new A0101Protocol()
            {
                SQLMethod = SQLMethod, Form1 = this, XMLMethod = XMLMethod
            };

            absProtocols.Add(a0101Protocol);
            A0102Protocol a0102Protocol = new A0102Protocol()
            {
                SQLMethod = SQLMethod, Form1 = this, XMLMethod = XMLMethod
            };

            absProtocols.Add(a0102Protocol);
            A0201Protocol a0201Protocol = new A0201Protocol()
            {
                SQLMethod = SQLMethod, Form1 = this, XMLMethod = XMLMethod
            };

            absProtocols.Add(a0201Protocol);
            A0202Protocol a0202Protocol = new A0202Protocol()
            {
                SQLMethod = SQLMethod, Form1 = this, XMLMethod = XMLMethod
            };

            absProtocols.Add(a0202Protocol);
            A0301Protocol a0301Protocol = new A0301Protocol()
            {
                SQLMethod = SQLMethod, Form1 = this, XMLMethod = XMLMethod
            };

            absProtocols.Add(a0301Protocol);
            A0302Protocol a0302Protocol = new A0302Protocol()
            {
                SQLMethod = SQLMethod, Form1 = this, XMLMethod = XMLMethod
            };

            absProtocols.Add(a0302Protocol);
            A0401Protocol a0401Protocol = new A0401Protocol()
            {
                SQLMethod = SQLMethod, Form1 = this, XMLMethod = XMLMethod
            };

            absProtocols.Add(a0401Protocol);
            A0501Protocol a0501Protocol = new A0501Protocol()
            {
                SQLMethod = SQLMethod, Form1 = this, XMLMethod = XMLMethod
            };

            absProtocols.Add(a0501Protocol);
            B0101Protocol b0101Protocol = new B0101Protocol()
            {
                SQLMethod = SQLMethod, Form1 = this, XMLMethod = XMLMethod
            };

            absProtocols.Add(b0101Protocol);
            B0102Protocol b0102Protocol = new B0102Protocol()
            {
                SQLMethod = SQLMethod, Form1 = this, XMLMethod = XMLMethod
            };

            absProtocols.Add(b0102Protocol);
            B0201Protocol b0201Protocol = new B0201Protocol()
            {
                SQLMethod = SQLMethod, Form1 = this, XMLMethod = XMLMethod
            };

            absProtocols.Add(b0201Protocol);
            B0202Protocol b0202Protocol = new B0202Protocol()
            {
                SQLMethod = SQLMethod, Form1 = this, XMLMethod = XMLMethod
            };

            absProtocols.Add(b0202Protocol);
            B0401Protocol b0401Protocol = new B0401Protocol()
            {
                SQLMethod = SQLMethod, Form1 = this, XMLMethod = XMLMethod
            };

            absProtocols.Add(b0401Protocol);
            B0501Protocol b0501Protocol = new B0501Protocol()
            {
                SQLMethod = SQLMethod, Form1 = this, XMLMethod = XMLMethod
            };

            absProtocols.Add(b0501Protocol);
            E0402Protocol e0402Protocol = new E0402Protocol()
            {
                SQLMethod = SQLMethod, Form1 = this, XMLMethod = XMLMethod
            };

            absProtocols.Add(e0402Protocol);
        }