⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 serverchoiceforms.cs

📁 用vc#编写的小游戏
💻 CS
字号:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Xml;
using System.IO;
using System.Windows.Forms;

namespace Mine.UIL
{
    public partial class ServerChoiceForms : Form
    {
        public ServerChoiceForms()
        {
            InitializeComponent();
        }

        private void butOK_Click(object sender, EventArgs e)
        {
            XmlDocument xmlDoc = new XmlDocument();
            xmlDoc.LoadXml("<user></user>");
            XmlNode root = xmlDoc.SelectSingleNode("user");
            XmlElement serverName = xmlDoc.CreateElement("servername");
            XmlElement databasename = xmlDoc.CreateElement("databasename");
            XmlElement username = xmlDoc.CreateElement("username");
            XmlElement userpassword = xmlDoc.CreateElement("userpassword");
            XmlElement connecttype = xmlDoc.CreateElement("connecttype");
            root.AppendChild(serverName);
            root.AppendChild(databasename);
            root.AppendChild(username);
            root.AppendChild(userpassword);
            root.AppendChild(connecttype);

            serverName.InnerText = textBox1.Text;
            databasename.InnerText = textBox2.Text;
            if (radioButton1.Checked == true)
            {
                username.InnerText = "0";
                userpassword.InnerText = "0";
                connecttype.InnerText = "windows";
            }
            if (radioButton2.Checked == true)
            {
                username.InnerText = this.textBox3.Text ;
                userpassword.InnerText = this.textBox4.Text ;
                connecttype.InnerText = "usernameandpassword";
            }

            xmlDoc.Save("Config.xml");
            MessageBox.Show("服务器信息保存成功!","提示信息",MessageBoxButtons.OK,MessageBoxIcon.Information);
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (radioButton2.Checked == true)
            { 
                //用户名,密码验证
                bool bo = false;

                StringBuilder strBuider = new StringBuilder();
                strBuider.Append("Data Source=");
                strBuider.Append(textBox1.Text + @";" + @"Initial Catalog=" + textBox2.Text);
                strBuider.Append(@";User ID="+textBox3.Text+@";Password="+textBox4.Text);

                Mine.ADL.Users user = new Mine.ADL.Users(strBuider.ToString());
                bo = user.Exists("0", "0", "0", "0", 0);

                if (bo)
                {
                    MessageBox.Show("连接成功!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }

            }
            else if (radioButton1.Checked == true)
            {
                bool bo = false;

                //Windows系统验证
                StringBuilder strBuider=new StringBuilder();
                strBuider.Append("Data Source=");
                strBuider.Append(textBox1.Text + @";"+@"Initial Catalog="+textBox2.Text);
                strBuider.Append(@";Integrated Security=True");

                Mine.ADL.Users user = new Mine.ADL.Users(strBuider.ToString());
                bo=user.Exists("0", "0", "0", "0", 0);

                if (bo)
                {
                    MessageBox.Show("连接成功!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }

            }
        }

        private void radioButton1_CheckedChanged(object sender, EventArgs e)
        {
            if (radioButton1.Checked == true)
            {
                textBox3.ReadOnly = true;
                textBox4.ReadOnly = true;
            }
            if (radioButton2.Checked == true)
            {
                textBox3.ReadOnly = false;
                textBox4.ReadOnly = false;
            }
        }


    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -