//创建数据库信息类接口 public static LTP.IDBO.IDbObject CreatDbObj(string longservername) { LTP.CmConfig.DbSettings dbset = LTP.CmConfig.DbConfig.GetSetting(longservername); LTP.IDBO.IDbObject dbobj = LTP.DBFactory.DBOMaker.CreateDbObj(dbset.DbType); dbobj.DbConnectStr = dbset.ConnectStr; return(dbobj); }
//创建脚本接口 public static LTP.IDBO.IDbScriptBuilder CreatDsb(string longservername) { LTP.CmConfig.DbSettings dbset = LTP.CmConfig.DbConfig.GetSetting(longservername); LTP.IDBO.IDbScriptBuilder dsb = LTP.DBFactory.DBOMaker.CreateScript(dbset.DbType); dsb.DbConnectStr = dbset.ConnectStr; return(dsb); }
public DataExport(string longservername, string dbname) { InitializeComponent(); DbName = dbname; dbset = LTP.CmConfig.DbConfig.GetSetting(longservername); dbobj = LTP.DBFactory.DBOMaker.CreateDbObj(dbset.DbType); dbobj.DbConnectStr = dbset.ConnectStr; cb = new LTP.CodeBuild.CodeBuilders(dbobj); dsb = LTP.DBFactory.DBOMaker.CreateScript(dbset.DbType);// ObjHelper.CreatDsb(longservername); this.lblServer.Text = dbset.Server; }
private void btn_Ok_Click(object sender, EventArgs e) { try { string server = this.comboBoxServer.Text.Trim(); string user = this.txtUser.Text.Trim(); string pass = this.txtPass.Text.Trim(); string port = this.textBox1.Text.Trim(); if ((user == "") || (server == "")) { MessageBox.Show(this, "服务器或用户名不能为空!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } if (this.cmbDBlist.SelectedIndex > 0) { dbname = cmbDBlist.Text; } else { dbname = "mysql"; } constr = String.Format("server={0};user id={1}; Port={2};password={3}; database={4}; pooling=false", server, user, port, pass, dbname); //测试连接 MySqlConnection myCn = new MySqlConnection(constr); try { this.Text = "正在连接服务器,请稍候..."; myCn.Open(); } catch (System.Exception ex) { LogInfo.WriteLog(ex); this.Text = "连接服务器失败!"; MessageBox.Show(this, "连接服务器失败!请检查服务器地址或用户名密码是否正确!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } finally { myCn.Close(); } this.Text = "连接服务器成功!"; if (dbobj == null) { dbobj = new LTP.CmConfig.DbSettings(); } string strtype = "MySQL"; //将当前配置写入配置文件 dbobj.DbType = strtype; dbobj.Server = server; dbobj.ConnectStr = constr; dbobj.DbName = dbname; dbobj.ConnectSimple = chk_Simple.Checked; bool succ = LTP.CmConfig.DbConfig.AddSettings(dbobj); if (!succ) { MessageBox.Show(this, "该服务器已经存在!请更换服务器地址或检查输入是否正确!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } this.DialogResult = DialogResult.OK; this.Close(); } catch (System.Exception ex) { MessageBox.Show(this, ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Warning); LogInfo.WriteLog(ex); } }
private void btn_ConTest_Click(object sender, EventArgs e) { try { string server = this.comboBoxServer.Text.Trim(); string user = this.txtUser.Text.Trim(); string pass = this.txtPass.Text.Trim(); string port = this.textBox1.Text.Trim(); if ((user == "") || (server == "")) { MessageBox.Show(this, "服务器或用户名不能为空!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } constr = String.Format("server={0};uid={1}; Port={2};pwd={3}; database=mysql; pooling=false", server, user, port, pass); try { this.Text = "正在连接服务器,请稍候..."; LTP.IDBO.IDbObject dbobj; dbobj = LTP.DBFactory.DBOMaker.CreateDbObj("MySQL"); dbobj.DbConnectStr = constr; List <string> dblist = dbobj.GetDBList(); this.cmbDBlist.Enabled = true; this.cmbDBlist.Items.Clear(); this.cmbDBlist.Items.Add("全部库");//5_1_a_s_p_x if (dblist != null) { if (dblist.Count > 0) { foreach (string dbname in dblist) { this.cmbDBlist.Items.Add(dbname); } } } this.cmbDBlist.SelectedIndex = 0; this.Text = "连接服务器成功!"; } catch (System.Exception ex) { LogInfo.WriteLog(ex); this.Text = "连接服务器或获取数据信息失败!"; DialogResult drs = MessageBox.Show(this, "连接服务器或获取数据信息失败!\r\n请检查服务器地址或用户名密码是否正确!查看帮助文件以帮助您解决问题?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Error); if (drs == DialogResult.OK) { try { Process proc = new Process(); Process.Start("IExplore.exe", "http://help.maticsoft.com"); } catch { MessageBox.Show("请访问:http://www.maticsoft.com", "完成", MessageBoxButtons.OK, MessageBoxIcon.Information); } } return; } } catch (System.Exception ex) { LogInfo.WriteLog(ex); MessageBox.Show(this, ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Warning); } }
private void BtnOk_Click(object sender, System.EventArgs e) { try { string user = this.txtUser.Text.Trim(); string pass = this.txtPass.Text.Trim(); string server = this.txtServer.Text.Trim(); if ((user.Trim() == "") || (server.Trim() == "")) { MessageBox.Show(this, "用户名或密码不能为空!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } constr = "Data Source=" + server + "; user id=" + user + ";password="******"正在连接服务器,请稍候..."; myCn.Open(); } catch { this.Text = "连接服务器失败!"; myCn.Close(); MessageBox.Show(this, "连接服务器失败!请检查服务器地址或用户名密码是否正确!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } myCn.Close(); this.Text = "连接服务器成功!"; if (dbobj == null) { dbobj = new LTP.CmConfig.DbSettings(); } //将当前配置写入配置文件 dbobj.DbType = "Oracle"; dbobj.Server = server; dbobj.ConnectStr = constr; dbobj.DbName = ""; dbobj.ConnectSimple = chk_Simple.Checked; bool succ = LTP.CmConfig.DbConfig.AddSettings(dbobj); if (!succ) { MessageBox.Show(this, "该服务器已经存在!请更换服务器地址或检查输入是否正确!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } //将当前数据库系统类型写入配置 //MainForm.setting.DbType="Oracle"; //LTP.CmConfig.ModuleConfig.SaveSettings(MainForm.setting); this.DialogResult = DialogResult.OK; this.Close(); } catch (System.Exception ex) { MessageBox.Show(this, ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Warning); LogInfo.WriteLog(ex); } }
private void btn_Ok_Click(object sender, EventArgs e) { try { string server = this.txtServer.Text.Trim(); string pass = this.txtPass.Text.Trim(); if (this.radBtn_DB.Checked) { GetConstr(); if (server == "") { MessageBox.Show(this, "数据库不能为空!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } } if (this.radBtn_Constr.Checked) { if (txtConstr.Text == "") { MessageBox.Show(this, "数据库不能为空!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } } string constr = this.txtConstr.Text; //测试连接 SQLiteConnection myCn = new SQLiteConnection(constr); try { this.Text = "正在连接数据库,请稍候..."; myCn.Open(); } catch { this.Text = "连接数据库失败!"; MessageBox.Show(this, "连接数据库失败!请检查数据库地址或密码是否正确!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } myCn.Close(); this.Text = "连接数据库成功!"; if (dbobj == null) { dbobj = new LTP.CmConfig.DbSettings(); } //将当前配置写入配置文件 dbobj.DbType = "SQLite"; dbobj.Server = server; dbobj.ConnectStr = constr; dbobj.DbName = ""; LTP.CmConfig.DbConfig.AddSettings(dbobj); this.DialogResult = DialogResult.OK; this.Close(); } catch (System.Exception ex) { MessageBox.Show(this, ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Warning); LogInfo.WriteLog(ex); } }
private void btn_ConTest_Click(object sender, System.EventArgs e) { try { string server = this.comboBoxServer.Text.Trim(); string user = this.txtUser.Text.Trim(); string pass = this.txtPass.Text.Trim(); if ((user == "") || (server == "")) { MessageBox.Show(this, "服务器或用户名不能为空!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } if (GetSelVerified() == "Windows") { constr = "Integrated Security=SSPI;Data Source=" + server + ";Initial Catalog=master"; } else { if (pass == "") { constr = "user id=" + user + ";initial catalog=master;data source=" + server; } else { constr = "user id=" + user + ";password="******";initial catalog=master;data source=" + server; } } string strtype = GetSelVer(); #region 判断版本 GetSelVer() try { string ver = GetSQLVer(constr); if ((ver == "8") && (strtype == "SQL2005")) { DialogResult dr = MessageBox.Show(this, "该数据库服务器版本并非SQLServer 2005,是否进行重新选择?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information); if (dr == DialogResult.OK) { //comboBoxServerVer.SelectedIndex = 1; return; } } if ((ver == "9") && (strtype == "SQL2000")) { DialogResult dr = MessageBox.Show(this, "该数据库服务器版本并非SQLServer 2000,是否进行重新选择?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information); if (dr == DialogResult.OK) { //comboBoxServerVer.SelectedIndex = 0; return; } } } catch { } #endregion try { this.Text = "正在连接服务器,请稍候..."; LTP.IDBO.IDbObject dbobj; dbobj = LTP.DBFactory.DBOMaker.CreateDbObj(strtype); dbobj.DbConnectStr = constr; List <string> dblist = dbobj.GetDBList(); this.cmbDBlist.Enabled = true; this.cmbDBlist.Items.Clear(); this.cmbDBlist.Items.Add("全部库"); if (dblist != null) { if (dblist.Count > 0) { foreach (string dbname in dblist) { this.cmbDBlist.Items.Add(dbname); } } } this.cmbDBlist.SelectedIndex = 0; this.Text = "连接服务器成功!"; } catch (System.Exception ex) { LogInfo.WriteLog(ex); this.Text = "连接服务器或获取数据信息失败!"; string strinfo = "连接服务器或获取数据信息失败!\r\n"; strinfo += "请检查服务器地址或用户名密码是否正确!\r\n"; strinfo += "如果连接失败,服务器名可以用 “(local)”或是“.” 或者“机器名” 试一下!\r\n"; strinfo += "如果需要查看帮助文件以帮助您解决问题,请点“确定”,否则点“取消”"; DialogResult drs = MessageBox.Show(this, strinfo, "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Error); if (drs == DialogResult.OK) { try { Process proc = new Process(); Process.Start("IExplore.exe", "http://help.maticsoft.com"); } catch { MessageBox.Show("请访问:http://www.maticsoft.com", "完成", MessageBoxButtons.OK, MessageBoxIcon.Information); } } return; } } catch (System.Exception ex) { //LogInfo.WriteLog(System.Reflection.MethodBase.GetCurrentMethod(), ex); LogInfo.WriteLog(ex); MessageBox.Show(this, ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Warning); } }
private void btn_Ok_Click(object sender, System.EventArgs e) { try { string server = this.comboBoxServer.Text.Trim(); string user = this.txtUser.Text.Trim(); string pass = this.txtPass.Text.Trim(); if ((user == "") || (server == "")) { MessageBox.Show(this, "服务器或用户名不能为空!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } if (this.cmbDBlist.SelectedIndex > 0) { dbname = cmbDBlist.Text; } else { dbname = "master"; } if (GetSelVerified() == "Windows") { constr = "Integrated Security=SSPI;Data Source=" + server + ";Initial Catalog=" + dbname; } else { if (pass == "") { constr = "user id=" + user + ";initial catalog=" + dbname + ";data source=" + server; } else { constr = "user id=" + user + ";password="******";initial catalog=" + dbname + ";data source=" + server; } } string strtype = GetSelVer(); #region 判断版本 GetSelVer() try { string ver = GetSQLVer(constr); if ((ver == "8") && (strtype == "SQL2005")) { DialogResult dr = MessageBox.Show(this, "该服务器并非SQLServer 2005,是否进行更改选择?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information); if (dr == DialogResult.OK) { comboBoxServerVer.SelectedIndex = 1; } } if ((ver == "9") && (strtype == "SQL2000")) { DialogResult dr = MessageBox.Show(this, "该服务器并非SQLServer 2000,是否进行更改选择?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information); if (dr == DialogResult.OK) { comboBoxServerVer.SelectedIndex = 0; } } } catch { } #endregion //测试连接 SqlConnection myCn = new SqlConnection(constr); try { this.Text = "正在连接服务器,请稍候..."; myCn.Open(); } catch (System.Exception ex) { this.Text = "连接服务器失败!"; LogInfo.WriteLog(ex); MessageBox.Show(this, "连接服务器失败!请检查服务器地址或用户名密码是否正确!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } finally { myCn.Close(); } this.Text = "连接服务器成功!"; if (dbobj == null) { dbobj = new LTP.CmConfig.DbSettings(); } //string strtype="SQL2000"; //if (this.comboBoxServerVer.Text == "SQL Server2005") //{ // strtype="SQL2005"; //} //将当前配置写入配置文件 dbobj.DbType = strtype; dbobj.Server = server; dbobj.ConnectStr = constr; dbobj.DbName = dbname; dbobj.ConnectSimple = chk_Simple.Checked; bool succ = LTP.CmConfig.DbConfig.AddSettings(dbobj); if (!succ) { MessageBox.Show(this, "该服务器已经存在!请更换服务器地址或检查输入是否正确!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } this.DialogResult = DialogResult.OK; this.Close(); } catch (System.Exception ex) { MessageBox.Show(this, ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Warning); LogInfo.WriteLog(ex); } }
private void CreatDbObj(string servername) { LTP.CmConfig.DbSettings dbset = LTP.CmConfig.DbConfig.GetSetting(servername); dbobj = LTP.DBFactory.DBOMaker.CreateDbObj(dbset.DbType); dbobj.DbConnectStr = dbset.ConnectStr; }