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

📄 loginform.cs

📁 通过数据库结构自动 生成三层结构代码,相当不错的一款软件
💻 CS
📖 第 1 页 / 共 2 页
字号:
namespace Codematic
{
    using Codematic.Properties;
    using LTP.CmConfig;
    using LTP.DBFactory;
    using LTP.IDBO;
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data.SqlClient;
    using System.Diagnostics;
    using System.Drawing;
    using System.Windows.Forms;
    using WiB.Pinkie.Controls;

    public class LoginForm : Form
    {
        private ButtonXP btn_Cancel;
        private ButtonXP btn_ConTest;
        private ButtonXP btn_Ok;
        public CheckBox chk_Simple;
        public ComboBox cmbDBlist;
        public ComboBox comboBox_Verified;
        public ComboBox comboBoxServer;
        public ComboBox comboBoxServerVer;
        private IContainer components;
        public string constr;
        public string dbname = "master";
        private DbSettings dbobj = new DbSettings();
        public GroupBox groupBox1;
        public Label label1;
        public Label label2;
        public Label label3;
        private Label label4;
        public Label label5;
        public Label label6;
        private PictureBox pictureBox1;
        private ToolTip toolTip1;
        public TextBox txtPass;
        public TextBox txtUser;

        public LoginForm()
        {
            this.InitializeComponent();
        }

        private void btn_Cancel_Click(object sender, EventArgs e)
        {
            base.Close();
        }

        private void btn_ConTest_Click(object sender, EventArgs e)
        {
            try
            {
                string str = this.comboBoxServer.Text.Trim();
                string str2 = this.txtUser.Text.Trim();
                string str3 = this.txtPass.Text.Trim();
                if ((str2 == "") || (str == ""))
                {
                    MessageBox.Show(this, "服务器或用户名不能为空!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                }
                else
                {
                    if (this.GetSelVerified() == "Windows")
                    {
                        this.constr = "Integrated Security=SSPI;Data Source=" + str + ";Initial Catalog=master";
                    }
                    else if (str3 == "")
                    {
                        this.constr = "user id=" + str2 + ";initial catalog=master;data source=" + str;
                    }
                    else
                    {
                        this.constr = "user id=" + str2 + ";password=" + str3 + ";initial catalog=master;data source=" + str;
                    }
                    try
                    {
                        this.Text = "正在连接服务器,请稍候...";
                        IDbObject obj2 = DBOMaker.CreateDbObj(this.GetSelVer());
                        obj2.DbConnectStr = this.constr;
                        List<string> dBList = obj2.GetDBList();
                        this.cmbDBlist.Enabled = true;
                        this.cmbDBlist.Items.Clear();
                        this.cmbDBlist.Items.Add("全部库");
                        if ((dBList != null) && (dBList.Count > 0))
                        {
                            foreach (string str5 in dBList)
                            {
                                this.cmbDBlist.Items.Add(str5);
                            }
                        }
                        this.cmbDBlist.SelectedIndex = 0;
                        this.Text = "连接服务器成功!";
                    }
                    catch (Exception exception)
                    {
                        LogInfo.WriteLog(exception);
                        this.Text = "连接服务器或获取数据信息失败!";
                        string text = "连接服务器或获取数据信息失败!\r\n";
                        text = (text + "请检查服务器地址或用户名密码是否正确!\r\n") + "如果连接失败,服务器名可以用 “(local)”或是“.” 或者“机器名” 试一下!\r\n" + "如果需要查看帮助文件以帮助您解决问题,请点“确定”,否则点“取消”";
                        if (MessageBox.Show(this, text, "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Hand) == DialogResult.OK)
                        {
                            try
                            {
                                new Process();
                                Process.Start("IExplore.exe", "http://help.maticsoft.com");
                            }
                            catch
                            {
                                MessageBox.Show("请访问:http://www.maticsoft.com", "完成", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                            }
                        }
                    }
                }
            }
            catch (Exception exception2)
            {
                LogInfo.WriteLog(exception2);
                MessageBox.Show(this, exception2.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
        }

        private void btn_Ok_Click(object sender, EventArgs e)
        {
            try
            {
                string str = this.comboBoxServer.Text.Trim();
                string str2 = this.txtUser.Text.Trim();
                string str3 = this.txtPass.Text.Trim();
                if ((str2 == "") || (str == ""))
                {
                    MessageBox.Show(this, "服务器或用户名不能为空!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                }
                else
                {
                    if (this.cmbDBlist.SelectedIndex > 0)
                    {
                        this.dbname = this.cmbDBlist.Text;
                    }
                    else
                    {
                        this.dbname = "master";
                    }
                    if (this.GetSelVerified() == "Windows")
                    {
                        this.constr = "Integrated Security=SSPI;Data Source=" + str + ";Initial Catalog=" + this.dbname;
                    }
                    else if (str3 == "")
                    {
                        this.constr = "user id=" + str2 + ";initial catalog=" + this.dbname + ";data source=" + str;
                    }
                    else
                    {
                        this.constr = "user id=" + str2 + ";password=" + str3 + ";initial catalog=" + this.dbname + ";data source=" + str;
                    }
                    SqlConnection connection = new SqlConnection(this.constr);
                    try
                    {
                        this.Text = "正在连接服务器,请稍候...";
                        connection.Open();
                    }
                    catch (Exception exception)
                    {
                        this.Text = "连接服务器失败!";
                        LogInfo.WriteLog(exception);
                        MessageBox.Show(this, "连接服务器失败!请检查服务器地址或用户名密码是否正确!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Hand);
                        return;
                    }
                    finally
                    {
                        connection.Close();
                    }
                    this.Text = "连接服务器成功!";
                    if (this.dbobj == null)
                    {
                        this.dbobj = new DbSettings();
                    }
                    string selVer = this.GetSelVer();
                    this.dbobj.DbType = selVer;
                    this.dbobj.Server = str;
                    this.dbobj.ConnectStr = this.constr;
                    this.dbobj.DbName = this.dbname;
                    this.dbobj.ConnectSimple = this.chk_Simple.Checked;
                    if (!DbConfig.AddSettings(this.dbobj))
                    {
                        MessageBox.Show(this, "该服务器已经存在!请更换服务器地址或检查输入是否正确!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Hand);
                    }
                    else
                    {
                        base.DialogResult = DialogResult.OK;
                        base.Close();
                    }
                }
            }
            catch (Exception exception2)
            {
                MessageBox.Show(this, exception2.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                LogInfo.WriteLog(exception2);
            }
        }

        private void comboBox_Verified_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (this.GetSelVerified() == "Windows")
            {
                this.label2.Enabled = false;
                this.label3.Enabled = false;
                this.txtUser.Enabled = false;
                this.txtPass.Enabled = false;
            }
            else
            {
                this.label2.Enabled = true;
                this.label3.Enabled = true;
                this.txtUser.Enabled = true;
                this.txtPass.Enabled = true;
            }
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing && (this.components != null))
            {
                this.components.Dispose();
            }
            base.Dispose(disposing);
        }

        public string GetSelVer()
        {
            switch (this.comboBoxServerVer.Text)
            {
                case "SQL Server2000":
                    return "SQL2000";

                case "SQL Server2005":
                    return "SQL2005";
            }
            return "SQL2005";
        }

        public string GetSelVerified()
        {
            if (this.comboBox_Verified.SelectedItem.ToString() == "Windows 身份认证")
            {
                return "Windows";

⌨️ 快捷键说明

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