public FrmDbToScript(string longServerName, string dbName)
        {
            InitializeComponent();
            DbName = dbName;
            dsb    = ObjHelper.CreatDsb(longServerName);
            dbobj  = ObjHelper.CreatDbObj(longServerName);
            this.lblServer.Text = longServerName;

            List <string> dblist = dbobj.GetDBList();

            if (dblist != null)
            {
                if (dblist.Count > 0)
                {
                    foreach (string name in dblist)
                    {
                        this.cmbDB.Items.Add(name);
                    }
                }
            }
            //DataTable dt = dbobj.GetDBList();
            //if (dt != null)
            //{
            //    foreach (DataRow row in dt.Rows)
            //    {
            //        this.cmbDB.Items.Add(row["name"].ToString());
            //    }
            //}
            this.btn_Creat.Enabled = false;
            this.cmbDB.Text        = DbName;
        }
Beispiel #2
0
        private bool test()
        {
            this.labMessage.Text = string.Empty;
            string str1 = this.txbServer.Text.Trim();
            string str2 = this.txbName.Text.Trim();
            string str3 = this.txbSecrity.Text.Trim();

            if (string.IsNullOrWhiteSpace(str2) || string.IsNullOrWhiteSpace(str1))
            {
                return(false);
            }
            if (this.GetSelVerified() == "Windows")
            {
                this.constr = "initial catalog=master;Data Source=" + str1 + ";Integrated Security=SSPI;";
            }
            else if (str3 == "")
            {
                this.constr = "initial catalog=master;Data Source=" + str1 + ";user id=" + str2 + ";";
            }
            else
            {
                this.constr = "initial catalog=master;Data Source=" + str1 + ";user id=" + str2 + ";password="******";";
            }
            IDbObject dbObject = (IDbObject) new DataAccess();

            dbObject.DbConnectStr = this.constr;
            if (!string.IsNullOrWhiteSpace(this.GetSQLVer(this.constr)))
            {
                List <string> dbList = dbObject.GetDBList();
                if (dbList != null && dbList.Count > 0)
                {
                    this.btnSQLServer.Enabled     = true;
                    this.comboBoxDatabase.Enabled = true;
                    this.comboBoxDatabase.Items.Clear();
                    foreach (object obj in dbList)
                    {
                        this.comboBoxDatabase.Items.Add(obj);
                    }
                    this.comboBoxDatabase.SelectedIndex = 0;
                    return(true);
                }
            }
            this.btnSQLServer.Enabled     = false;
            this.comboBoxDatabase.Enabled = false;
            return(false);
        }
Beispiel #3
0
 private void btn_ConTest_Click(object sender, EventArgs e)
 {
     try
     {
         string text  = this.comboBoxServer.Text.Trim();
         string text2 = this.txtUser.Text.Trim();
         string text3 = this.txtPass.Text.Trim();
         if (text2 == "" || text == "")
         {
             MessageBox.Show(this, "服务器或用户名不能为空!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
         }
         else
         {
             if (this.GetSelVerified() == "Windows")
             {
                 this.constr = "Integrated Security=SSPI;Data Source=" + text + ";Initial Catalog=master";
             }
             else
             {
                 if (text3 == "")
                 {
                     this.constr = "User Id=" + text2 + ";Database=master; Server=" + text;
                 }
                 else
                 {
                     this.constr = string.Concat(new string[]
                     {
                         "User Id=",
                         text2,
                         ";Password="******";Database=master; Server=",
                         text
                     });
                 }
             }
             string selVer = this.GetSelVer();
             try
             {
                 string sQLVer = this.GetSQLVer(this.constr);
                 if (sQLVer != "11" && selVer == "SQL2012")
                 {
                     DialogResult dialogResult = MessageBox.Show(this, "该数据库服务器版本并非SQLServer 2012,是否进行重新选择?点“否”可继续。", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Asterisk);
                     if (dialogResult == DialogResult.OK)
                     {
                         return;
                     }
                 }
                 if (sQLVer != "10" && selVer == "SQL2008")
                 {
                     DialogResult dialogResult2 = MessageBox.Show(this, "该数据库服务器版本并非SQLServer 2008,是否进行重新选择?点“否”可继续。", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Asterisk);
                     if (dialogResult2 == DialogResult.OK)
                     {
                         return;
                     }
                 }
                 if (sQLVer != "9" && selVer == "SQL2005")
                 {
                     DialogResult dialogResult3 = MessageBox.Show(this, "该数据库服务器版本并非SQLServer 2005,是否进行重新选择?点“否”可继续。", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Asterisk);
                     if (dialogResult3 == DialogResult.OK)
                     {
                         return;
                     }
                 }
                 if (sQLVer != "8" && selVer == "SQL2000")
                 {
                     DialogResult dialogResult4 = MessageBox.Show(this, "该数据库服务器版本并非SQLServer 2000,是否进行重新选择?点“否”可继续。", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Asterisk);
                     if (dialogResult4 == DialogResult.OK)
                     {
                         return;
                     }
                 }
             }
             catch
             {
             }
             try
             {
                 this.Text = "正在连接服务器,请稍候...";
                 IDbObject dbObject = DBOMaker.CreateDbObj(selVer);
                 if (dbObject == null)
                 {
                     LogInfo.WriteLog("创建数据库对象失败:" + selVer);
                     MessageBox.Show(this, "创建数据库对象失败:" + selVer, "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Hand);
                 }
                 else
                 {
                     dbObject.DbConnectStr = this.constr;
                     List <string> dBList = dbObject.GetDBList();
                     dBList.Sort();
                     this.cmbDBlist.Enabled = true;
                     this.cmbDBlist.Items.Clear();
                     this.cmbDBlist.Items.Add("全部库");
                     if (dBList != null && dBList.Count > 0)
                     {
                         foreach (string current in dBList)
                         {
                             this.cmbDBlist.Items.Add(current);
                         }
                     }
                     this.cmbDBlist.SelectedIndex = 0;
                     this.Text = "连接服务器成功!";
                 }
             }
             catch (Exception ex)
             {
                 LogInfo.WriteLog(ex);
                 this.Text = "连接服务器或获取数据信息失败!";
                 string text4 = "连接服务器或获取数据信息失败!\r\n";
                 text4 += "1.请检查服务器地址或用户名密码是否正确!\r\n";
                 text4 += "2.请确保是SQLServer正式版,而非SQLEXPRESS版!\r\n";
                 text4 += "3.如果连接失败,服务器名可以尝试用“机器名”代替IP,或者 “(local)”或是“.”试一下!\r\n";
                 text4 += "4.如果需要查看帮助文件以帮助您解决问题,请点“确定”,否则点“取消”";
                 DialogResult dialogResult5 = MessageBox.Show(this, text4, "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Hand);
                 if (dialogResult5 == 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 ex2)
     {
         LogInfo.WriteLog(ex2);
         MessageBox.Show(this, ex2.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
     }
 }
Beispiel #4
0
        private void FrmBatchCodeMaker_Shown(object sender, EventArgs e)
        {
            string mastedb = "master";

            switch (dbobj.DbType)
            {
            case "SQL2000":
            case "SQL2005":
            case "SQL2008":
                mastedb = "master";
                break;

            case "Oracle":
            case "OleDb":
                mastedb = dbset.DbName;
                break;

            case "MySQL":
                mastedb = "mysql";
                break;
            }
            if ((dbset.DbName == "") || (dbset.DbName == mastedb))
            {
                List <string> dblist = dbobj.GetDBList();
                if (dblist != null)
                {
                    if (dblist.Count > 0)
                    {
                        foreach (string dbname in dblist)
                        {
                            this.cboDBList.Items.Add(dbname);
                        }
                    }
                }
            }
            else
            {
                this.cboDBList.Items.Add(dbset.DbName);
            }

            if (this.cboDBList.Items.Count > 0)
            {
                this.cboDBList.SelectedIndex = 0;
            }
            else
            {
                List <string> tabNames = dbobj.GetTables("");
                this.listTable1.Items.Clear();
                this.listTable2.Items.Clear();
                if (tabNames.Count > 0)
                {
                    foreach (string tabname in tabNames)
                    {
                        listTable1.Items.Add(tabname);
                    }
                }
            }
            this.btnExport.Enabled = false;
            SettingHelper setting = new SettingHelper();

            setting.GetSetting();
            txtTargetFolder.Text = setting.Output;
            txtNamespace.Text    = setting.Project;
            txtCompanyName.Text  = setting.Company;
            txtDeveloper.Text    = setting.Author;
            txtCreateYear.Text   = DateTime.Now.Year.ToString();
            txtCreateDate.Text   = DateTime.Now.ToString("yyyy-MM-dd");
        }