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

📄 loginoledb.cs

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

    public class LoginOledb : Form
    {
        private ButtonXP btn_Cancel;
        private ButtonXP btn_Ok;
        private ButtonXP btn_SelDb;
        private CheckBox checkBox1;
        private IContainer components;
        private DbSettings dbobj = new DbSettings();
        public GroupBox groupBox1;
        private GroupBox groupBox2;
        private GroupBox groupBox3;
        public Label label2;
        public Label label3;
        private PictureBox pictureBox1;
        private RadioButton radBtn_Constr;
        private RadioButton radBtn_DB;
        private ToolTip toolTip1;
        public TextBox txtConstr;
        public TextBox txtPass;
        public TextBox txtServer;
        public TextBox txtUser;

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

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

        private void btn_Ok_Click(object sender, EventArgs e)
        {
            try
            {
                string str = this.txtServer.Text.Trim();
                this.txtUser.Text.Trim();
                this.txtPass.Text.Trim();
                if (this.radBtn_DB.Checked)
                {
                    this.GetConstr();
                    if (str == "")
                    {
                        MessageBox.Show(this, "数据库不能为空!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                        return;
                    }
                }
                if (this.radBtn_Constr.Checked && (this.txtConstr.Text == ""))
                {
                    MessageBox.Show(this, "数据库不能为空!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                }
                else
                {
                    string text = this.txtConstr.Text;
                    OleDbConnection connection = new OleDbConnection(text);
                    try
                    {
                        this.Text = "正在连接服务器,请稍候...";
                        connection.Open();
                    }
                    catch
                    {
                        this.Text = "连接服务器失败!";
                        MessageBox.Show(this, "连接服务器失败!请检查服务器地址或用户名密码是否正确!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Hand);
                        return;
                    }
                    connection.Close();
                    this.Text = "连接服务器成功!";
                    if (this.dbobj == null)
                    {
                        this.dbobj = new DbSettings();
                    }
                    this.dbobj.DbType = "OleDb";
                    this.dbobj.Server = str;
                    this.dbobj.ConnectStr = text;
                    this.dbobj.DbName = "";
                    DbConfig.AddSettings(this.dbobj);
                    base.DialogResult = DialogResult.OK;
                    base.Close();
                }
            }
            catch (Exception exception)
            {
                MessageBox.Show(this, exception.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                LogInfo.WriteLog(exception);
            }
        }

        private void btn_SelDb_Click(object sender, EventArgs e)
        {
            OpenFileDialog dialog = new OpenFileDialog();
            dialog.Title = "选择数据库文件";
            dialog.Filter = "Access files (*.mdb)|*.mdb|All files (*.*)|*.*";
            if (dialog.ShowDialog(this) == DialogResult.OK)
            {
                this.txtServer.Text = dialog.FileName;
                this.txtConstr.Text = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + this.txtServer.Text + ";Persist Security Info=False";
            }
        }

        private void checkBox1_CheckedChanged(object sender, EventArgs e)
        {
            if (this.checkBox1.Checked)
            {
                this.txtPass.Text = "";
                this.txtPass.Enabled = false;
            }
            else
            {
                this.txtPass.Enabled = true;
            }
        }

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

        private void GetConstr()
        {
            this.txtConstr.Text = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + this.txtServer.Text + ";Persist Security Info=False";
        }

        public void InitializeComponent()
        {
            this.components = new Container();
            ResourceManager manager = new ResourceManager(typeof(LoginOledb));
            this.txtServer = new TextBox();
            this.groupBox1 = new GroupBox();
            this.checkBox1 = new CheckBox();
            this.txtUser = new TextBox();
            this.label2 = new Label();
            this.txtPass = new TextBox();
            this.label3 = new Label();
            this.pictureBox1 = new PictureBox();
            this.toolTip1 = new ToolTip(this.components);
            this.btn_Ok = new ButtonXP();
            this.btn_Cancel = new ButtonXP();
            this.groupBox2 = new GroupBox();
            this.radBtn_DB = new RadioButton();
            this.btn_SelDb = new ButtonXP();
            this.groupBox3 = new GroupBox();
            this.txtConstr = new TextBox();
            this.radBtn_Constr = new RadioButton();
            this.groupBox1.SuspendLayout();
            this.groupBox2.SuspendLayout();
            this.groupBox3.SuspendLayout();
            base.SuspendLayout();
            this.txtServer.Location = new Point(0x68, 0x18);
            this.txtServer.Name = "txtServer";
            this.txtServer.Size = new Size(0xd8, 0x15);
            this.txtServer.TabIndex = 1;
            this.txtServer.Text = "";
            this.txtServer.TextChanged += new EventHandler(this.txtServer_TextChanged);
            this.groupBox1.Controls.Add(this.checkBox1);
            this.groupBox1.Controls.Add(this.txtUser);
            this.groupBox1.Controls.Add(this.label2);
            this.groupBox1.Controls.Add(this.txtPass);
            this.groupBox1.Controls.Add(this.label3);
            this.groupBox1.Controls.Add(this.pictureBox1);
            this.groupBox1.Location = new Point(0x18, 80);
            this.groupBox1.Name = "groupBox1";
            this.groupBox1.Size = new Size(0x170, 0x6a);

⌨️ 快捷键说明

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