Beispiel #1
0
        public void InitData()
        {
            JToken json = NewtonjsonHelper.ReadFile(Global.USER_SETTING_PATH);
            //读取链接名称并赋值给下拉框
            List <string> serverNames1 = json["DbServer"].Children().Select(m => m.Value <string>("ServerName")).ToList();
            List <string> serverNames2 = json["DbServer"].Children().Select(m => m.Value <string>("ServerName")).ToList();

            cb_db1.DataSource = serverNames1;
            cb_db2.DataSource = serverNames2;
        }
Beispiel #2
0
        private void Cb_ServerName_SelectedIndexChanged(object sender, EventArgs e)
        {
            string selectedText = cb_ServerName.SelectedValue.ToString();
            JToken json         = NewtonjsonHelper.ReadFile(Global.USER_SETTING_JSON_PATH);
            //加载配置项
            JToken selectedItem = json["DbServer"].Children().FirstOrDefault(m => m.Value <string>("ServerName") == selectedText);

            tb_ServerType.Text       = selectedItem.Value <string>("ServerType");
            tb_ConnectionString.Text = selectedItem.Value <string>("ConnectionString");
        }
Beispiel #3
0
        private void f_dbConnection_Load(object sender, EventArgs e)
        {
            JToken json = NewtonjsonHelper.ReadFile(Global.USER_SETTING_JSON_PATH);

            string selected = BindServerName(json);

            //加载配置项
            JToken selectedItem = json["DbServer"].Children().FirstOrDefault(m => m.Value <bool>("IsUse") == true);

            tb_ServerType.Text       = selectedItem.Value <string>("ServerType");
            tb_ConnectionString.Text = selectedItem.Value <string>("ConnectionString");
        }
Beispiel #4
0
        /// <summary>
        /// 保存修改
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected override void btn_Save_Click(object sender, EventArgs e)
        {
            string serverName       = cb_ServerName.Text;
            string serverType       = tb_ServerType.Text;
            string connectionString = tb_ConnectionString.Text;
            JToken json             = NewtonjsonHelper.ReadFile(Global.USER_SETTING_JSON_PATH);
            bool   isEdit           = json["DbServer"].Children().Any(m => m.Value <string>("ServerName") == serverName);

            #region 设置所有链接选中状态为false
            var servers = json["DbServer"];
            for (int i = 0; i < servers.Count(); i++)
            {
                servers[i]["IsUse"] = false;
            }
            #endregion

            if (isEdit)
            {
                JToken edit = json["DbServer"].FirstOrDefault(m => m.Value <string>("ServerName") == serverName);
                edit["ServerName"]       = serverName;
                edit["ServerType"]       = serverType;
                edit["ConnectionString"] = connectionString;
                edit["IsUse"]            = true;
            }
            else
            {
                JObject newServer = new JObject();
                newServer.Add(new JProperty("ServerName", serverName));
                newServer.Add(new JProperty("ServerType", serverType));
                newServer.Add(new JProperty("ConnectionString", connectionString));
                newServer.Add(new JProperty("IsUse", true));
                json["DbServer"].Last.AddAfterSelf(newServer);
            }
            NewtonjsonHelper.WriteFile(Global.USER_SETTING_JSON_PATH, json as JObject);
            MessageBox.Show("保存成功");
            BindServerName(json);
            //base.btn_Save_Click(sender,e);
        }
Beispiel #5
0
 public BaseForm()
 {
     appSetting  = NewtonjsonHelper.ReadFile(@"D:\CodeSpace\Git\CodeSpace.CSharp\FBCodeProdece2\FBCodeProdece\AppSetting.json");
     userSetting = NewtonjsonHelper.ReadFile(@"D:\CodeSpace\Git\CodeSpace.CSharp\FBCodeProdece2\FBCodeProdece\UserSetting.json");
 }