示例#1
0
 public void Init()
 {
     try
     {
         string file = Application.ExecutablePath;
         file = Path.GetDirectoryName(file) + "/config.txt";
         if (File.Exists(file))
         {
             GlobalConfig.Item = ConfigFileUtil <ConfigItem> .GetFromFile(file);
         }
         this.txtServer.Text  = GlobalConfig.Item.Server;
         this.txtUid.Text     = GlobalConfig.Item.UID;
         this.txtPwd.Text     = GlobalConfig.Item.PWD;
         this.cbDataBase.Text = GlobalConfig.Item.DataBase;
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
示例#2
0
        private void btnSaveConfig_Click(object sender, EventArgs e)
        {
            try
            {
                this.RefreshConfig();

                #region 保存配置到config.txt文件中

                string file = Application.ExecutablePath;
                file = Path.GetDirectoryName(file) + "/config.txt";
                if (File.Exists(file))
                {
                    File.Delete(file);
                }
                ConfigFileUtil <ConfigItem> .SaveToFile(GlobalConfig.Item, file);

                #endregion
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
示例#3
0
        /// <summary>
        /// 测试连接的方法
        /// </summary>
        private void Connect()
        {
            try
            {
                string constr = "Server={0};Database={1};uid={2};pwd={3}";
                constr = String.Format(constr, GlobalConfig.Item.Server, GlobalConfig.Item.DataBase, GlobalConfig.Item.UID, GlobalConfig.Item.PWD);
                SqlConnection con = new SqlConnection(constr);
                con.Open();
                bool flag = false;
                if (con.State == ConnectionState.Open)
                {
                    flag = true;
                }
                con.Close();
                if (flag)
                {
                    MessageBox.Show("测试连接成功!");
                    string file = Application.ExecutablePath;
                    file = Path.GetDirectoryName(file) + "/config.txt";
                    if (File.Exists(file))
                    {
                        File.Delete(file);
                    }
                    ConfigFileUtil <ConfigItem> .SaveToFile(GlobalConfig.Item, file);

                    this.btnNext.Enabled = true;
                }
                else
                {
                    MessageBox.Show("测试连接失败!");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }