//点击保存按钮
        private void Seting_Win_Save_Letf_Down(object sender, RoutedEventArgs e)
        {
            T_LoginSet setmodel = new T_LoginSet();

            setmodel = ReWinDation();
            D_LoginSet Dset             = new D_LoginSet();
            string     getReturn_Result = Dset.LoginSetCheck_Query(setmodel.DataBaseIP, setmodel.DataBaseName);

            if (getReturn_Result == "Null")
            {
                bool getReturn_AddResult = Dset.LoginSetCheck_Add(setmodel);
                if (getReturn_AddResult)
                {
                    MessageBox.Show("设置成功");
                    Close();
                }
                else
                {
                    MessageBox.Show("设置失败");
                    Close();
                }
            }
            else
            {
                MessageBox.Show("设置成功");
                Close();
            }
        }
        public SetingSystem()
        {
            InitializeComponent();

            T_LoginSet setmodeltwo = new T_LoginSet();

            setmodeltwo = ReWinDation();
            if (setmodeltwo.DataBaseIP == "" && setmodeltwo.DataBaseName == "")
            {
                //数据库IP
                Win_DataBaseIP.Text = "127.0.0.1";
                //数据库实例
                Win_DataBaseInstance.Text = "";
                //数据库名称
                Win_DataBaseName.Text = "SocialSecurityManage";
                //数据库用户
                Win_DataBaseUser.Text = "sa";
                //数据库密码
                Win_DataBasePassword.Password = "******";
            }
            else
            {
                //数据库IP
                Win_DataBaseIP.Text = setmodeltwo.DataBaseIP;
                //数据库实例
                Win_DataBaseInstance.Text = setmodeltwo.DataBaseInstance;
                //数据库名称
                Win_DataBaseName.Text = setmodeltwo.DataBaseName;
                //数据库用户
                Win_DataBaseUser.Text = setmodeltwo.DataBaseUser;
                //数据库密码
                Win_DataBasePassword.Password = setmodeltwo.DataBasePassword;
            }
        }
        /// <summary>
        /// 添加操作
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public bool LoginSetCheck_Add(T_LoginSet model)
        {
            bool result = false;

            using (SqlConnection conn = new SqlConnection(constr))
            {
                try
                {
                    conn.Open();
                }
                catch (Exception ex)
                {
                }
                string sqlstr_loginsetadd = @"
                                INSERT INTO dbo.T_LoginSet
                                        ( DataBaseIP ,
                                          DataBaseInstance ,
                                          DataBaseName ,
                                          DataBaseUser ,
                                          DataBasePassword
                                        )
                                VALUES  ( @DataBaseIP,
                                          @DataBaseInstance,
                                          @DataBaseName,
                                          @DataBaseUser,
                                          @DataBasePassword
                                        )
                            ";
                using (SqlCommand com = new SqlCommand())
                {
                    com.Connection  = conn;
                    com.CommandText = sqlstr_loginsetadd;
                    com.Parameters.Add(new SqlParameter("@DataBaseIP", model.DataBaseIP));
                    com.Parameters.Add(new SqlParameter("@DataBaseInstance", model.DataBaseInstance));
                    com.Parameters.Add(new SqlParameter("@DataBaseName", model.DataBaseName));
                    com.Parameters.Add(new SqlParameter("@DataBaseUser", model.DataBaseUser));
                    com.Parameters.Add(new SqlParameter("@DataBasePassword", model.DataBasePassword));
                    try
                    {
                        result = com.ExecuteNonQuery() > 0;
                        return(result);
                    }
                    catch (Exception ex)
                    {
                        return(result);
                    }
                    finally
                    {
                        conn.Close();
                    }
                }
            }
        }
        public T_LoginSet ReWinDation()
        {
            T_LoginSet setmode = new T_LoginSet();

            #region -- 数据从页面中提取并绑定到Mode
            //数据库IP
            setmode.DataBaseIP = Win_DataBaseIP.Text;
            //数据库实例
            setmode.DataBaseInstance = Win_DataBaseInstance.Text;
            //数据库名称
            setmode.DataBaseName = Win_DataBaseName.Text;
            //数据库用户
            setmode.DataBaseUser = Win_DataBaseUser.Text;
            //数据库密码
            setmode.DataBasePassword = Win_DataBasePassword.Password;
            #endregion

            return(setmode);
        }
        /// <summary>
        /// 添加之前的验证是否存在
        /// </summary>
        /// <param name="DBIP"></param>
        /// <param name="DBName"></param>
        /// <returns></returns>
        public string LoginSetCheck_Query(string DBIP, string DBName)
        {
            string result = "NULL";

            using (SqlConnection con = new SqlConnection(constr))
            {
                #region --数据库打开异常处理
                try
                {
                    con.Open();
                }
                catch (Exception ex)
                {
                    result = "数据库打开失败!";
                    return(result);
                }
                #endregion
                string sqlstr_loginsetcheckquery = @" SELECT *
                                                      FROM  T_LoginSet
                                                      WHERE DataBaseIP=@DataBaseIP 
                                                        AND DataBaseName =@DataBaseName
                                      ";
                using (SqlCommand com = new SqlCommand())
                {
                    com.Connection  = con;                       //对应连接数据库连接
                    com.CommandText = sqlstr_loginsetcheckquery; //对应数据库SQL操作语句
                    com.Parameters.Add(new SqlParameter("@DataBaseIP", DBIP));
                    com.Parameters.Add(new SqlParameter("@DataBaseName", DBName));
                    try
                    {
                        SqlDataReader     dr    = com.ExecuteReader();     //执行SQL语句
                        List <T_LoginSet> Dmode = new List <T_LoginSet>(); //定义一个集合
                        while (dr.Read())
                        {
                            T_LoginSet modell = new T_LoginSet();
                            modell.ID               = Convert.ToInt32(dr["ID"].ToString());
                            modell.DataBaseIP       = dr["DataBaseIP"].ToString();
                            modell.DataBaseInstance = dr["DataBaseInstance"].ToString();
                            modell.DataBaseName     = dr["DataBaseName"].ToString();
                            modell.DataBaseUser     = dr["DataBaseUser"].ToString();
                            modell.DataBasePassword = dr["DataBasePassword"].ToString();
                            Dmode.Add(modell);
                        }
                        if (Dmode.Count < 1)
                        {
                            result = "Null";
                        }
                        else
                        {
                            result = "exist";
                        }
                        dr.Close();//关闭执行
                        return(result);
                    }
                    catch (Exception ex)
                    {
                        result = "数据库操作失败!";
                        return(result);
                    }
                    finally
                    {
                        con.Close();//关闭数据库
                    }
                }
            }
        }