Exemplo n.º 1
0
        public static confJson GetConf(string strConfPath)
        {
            confJson cj = new confJson();

            if (File.Exists(strConfPath))
            {
                try
                {
                    using (StreamReader sw = new StreamReader(strConfPath))
                    {
                        string str = sw.ReadLine();
                        if (!string.IsNullOrEmpty(str))
                        {
                            cj = (confJson)JsonConvert.DeserializeObject(str, typeof(confJson));
                        }
                    }
                }
                catch (Exception ex) { }
            }
            return(cj);
        }
Exemplo n.º 2
0
        public static void SaveConf(string strDbServer, string strDbName, string strDbUid, string strDbPwd, string strTextUrl)
        {
            confJson cj          = new confJson();
            string   strConfPath = System.Windows.Forms.Application.StartupPath + @"\config.json";

            cj = GetConf(strConfPath);
            cj.RequestXls.DbServer = strDbServer;
            cj.RequestXls.DbName   = strDbName;
            cj.RequestXls.DbUid    = strDbUid;
            cj.RequestXls.DbPwd    = strDbPwd;
            cj.RequestXls.TextUrl  = strTextUrl;

            try
            {
                using (StreamWriter sw = new StreamWriter(strConfPath, false))
                {
                    string str = JsonConvert.SerializeObject(cj);
                    sw.WriteLine(str);
                }
            }
            catch (Exception ex) { }
        }