📄 loginmysql.cs
字号:
namespace Codematic
{
using Codematic.Properties;
using LTP.CmConfig;
using LTP.DBFactory;
using LTP.IDBO;
using MySql.Data.MySqlClient;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.Windows.Forms;
using WiB.Pinkie.Controls;
public class LoginMySQL : Form
{
private ButtonXP btn_Cancel;
private ButtonXP btn_ConTest;
private ButtonXP btn_Ok;
public CheckBox chk_Simple;
public ComboBox cmbDBlist;
public ComboBox comboBoxServer;
private IContainer components;
public string constr;
public string dbname = "mysql";
private DbSettings dbobj = new DbSettings();
public GroupBox groupBox1;
public Label label1;
public Label label2;
public Label label3;
private Label label4;
private Label label5;
private PictureBox pictureBox1;
private TextBox textBox1;
public TextBox txtPass;
public TextBox txtUser;
public LoginMySQL()
{
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
{
this.constr = string.Format("server={0};user id={1}; password={2}; database=mysql; pooling=false", str, str2, str3);
try
{
this.Text = "正在连接服务器,请稍候...";
IDbObject obj2 = DBOMaker.CreateDbObj("MySQL");
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 str4 in dBList)
{
this.cmbDBlist.Items.Add(str4);
}
}
this.cmbDBlist.SelectedIndex = 0;
this.Text = "连接服务器成功!";
}
catch (Exception exception)
{
LogInfo.WriteLog(exception);
this.Text = "连接服务器或获取数据信息失败!";
if (MessageBox.Show(this, "连接服务器或获取数据信息失败!\r\n请检查服务器地址或用户名密码是否正确!查看帮助文件以帮助您解决问题?", "提示", 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 = "mysql";
}
this.constr = string.Format("server={0};user id={1}; password={2}; database={3}; pooling=false", new object[] { str, str2, str3, this.dbname });
MySqlConnection connection = new MySqlConnection(this.constr);
try
{
this.Text = "正在连接服务器,请稍候...";
connection.Open();
}
catch (Exception exception)
{
LogInfo.WriteLog(exception);
this.Text = "连接服务器失败!";
MessageBox.Show(this, "连接服务器失败!请检查服务器地址或用户名密码是否正确!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Hand);
return;
}
finally
{
connection.Close();
}
this.Text = "连接服务器成功!";
if (this.dbobj == null)
{
this.dbobj = new DbSettings();
}
this.dbobj.DbType = "MySQL";
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);
}
}
protected override void Dispose(bool disposing)
{
if (disposing && (this.components != null))
{
this.components.Dispose();
}
base.Dispose(disposing);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -