示例#1
0
 private void BindData()
 {
     try
     {
         DataTable dt = dbobj.GetTabData(dbName, tabname);
         dataGridView1.DataSource = dt;
         dataGridView1.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCellsExceptHeader);
         StatusLabel_Count.Text = dt.Rows.Count + "行 ";
     }
     catch (System.Exception er)
     {
         LogHelper.WriteException(er);
     }
 }
示例#2
0
 void ThreadWork()
 {
     try
     {
         timer1.Enabled       = true;
         StatusLabel_Tip.Text = "正在查询,请稍候...";
         BindDataList();
         timer1.Enabled       = false;
         StatusLabel_Tip.Text = "完成";
     }
     catch (System.Exception er)
     {
         LogHelper.WriteException(er);
     }
 }
示例#3
0
 /// <summary>
 /// 增加TabPage
 /// </summary>
 /// <param name="pageTitle">page页标题</param>
 /// <param name="ctrForm">窗体</param>
 /// <param name="mainfrm">主窗体</param>
 public static void AddTabPage(string pageTitle, Control ctrForm, MainForm mainfrm)
 {
     try
     {
         if (mainfrm.tabControlMain.Visible == false)
         {
             mainfrm.tabControlMain.Visible = true;
         }
         Crownwood.Magic.Controls.TabPage page = new Crownwood.Magic.Controls.TabPage();
         page.Title   = pageTitle;
         page.Control = ctrForm;
         mainfrm.tabControlMain.TabPages.Add(page);
         mainfrm.tabControlMain.SelectedTab = page;
     }
     catch (Exception ex)
     {
         LogHelper.WriteException(ex);
     }
 }
示例#4
0
        /// <summary>
        /// 判断sql的版本
        /// </summary>
        /// <param name="connectionString">数据库连接字符串</param>
        /// <returns>当前SQL数据库版本号</returns>
        private string GetSQLVer(string connectionString)
        {
            string SQLString = "SELECT SERVERPROPERTY('productversion')";

            using (SqlConnection connection = new SqlConnection(connectionString))
            {
                using (SqlCommand cmd = new SqlCommand(SQLString, connection))
                {
                    try
                    {
                        connection.Open();
                        object obj = cmd.ExecuteScalar();
                        if ((Object.Equals(obj, null)) || (Object.Equals(obj, System.DBNull.Value)))
                        {
                            return("");
                        }
                        else
                        {
                            string ver = obj.ToString().Trim();
                            if (ver.Length > 1)
                            {
                                return(ver.Substring(0, 1));
                            }
                            else
                            {
                                return("");
                            }
                        }
                    }
                    catch (System.Data.SqlClient.SqlException ex)
                    {
                        connection.Close();
                        LogHelper.WriteException(ex);
                        throw ex;
                    }
                    finally
                    {
                        cmd.Dispose();
                        connection.Close();
                    }
                }
            }
        }
示例#5
0
        public DataList(IDbObject idbobj, string dbname, string tabName)
        {
            InitializeComponent();
            try
            {
                dbobj   = idbobj;
                dbName  = dbname;
                tabname = tabName;
                StatusLabel_dbName.Text = "库:" + dbname + ",表:" + tabname + "  ";

                mythread = new Thread(new ThreadStart(ThreadWork));
                mythread.Start();
                //ThreadWork();
            }
            catch (System.Exception er)
            {
                LogHelper.WriteException(er);
            }
        }
 private void btn_Creat_Click(object sender, System.EventArgs e)
 {
     try
     {
         if (this.txtTargetFolder.Text == "")
         {
             MessageBox.Show("请选择保存文件路径!", "完成", MessageBoxButtons.OK, MessageBoxIcon.Information);
             return;
         }
         DbName = this.cmbDB.Text;
         pictureBox1.Visible = true;
         mythread            = new Thread(new ThreadStart(ThreadWork));
         mythread.Start();
         //ThreadWork();
     }
     catch (System.Exception ex)
     {
         LogHelper.WriteException(ex);
         MessageBox.Show(ex.Message, "完成", MessageBoxButtons.OK, MessageBoxIcon.Stop);
     }
 }
        void ThreadWork()
        {
            try
            {
                //this.Cursor=System.Windows.Forms.Cursors.WaitCursor;
                SetBtnDisable();
                int    tblCount = this.listTable2.Items.Count;
                string filename = this.txtTargetFolder.Text;

                SetprogressBar1Max(tblCount);
                SetprogressBar1Val(1);
                SetlblStatuText("0");

                #region 循环每个表

                for (int i = 0; i < tblCount; i++)
                {
                    //this.listTable2.SelectedIndex=i;
                    string tableName = this.listTable2.Items[i].ToString();
                    dsb.Fieldlist = new List <ColumnInfo>();
                    dsb.CreateTabScript(DbName, tableName, filename, progressBar2);

                    SetprogressBar1Val(i + 1);
                    SetlblStatuText((i + 1).ToString());
                }
                #endregion

                SetBtnEnable();
                //this.Cursor=System.Windows.Forms.Cursors.Default;
                MessageBox.Show("脚本全部生成成功!", "完成", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            catch (System.Exception ex)
            {
                LogHelper.WriteException(ex);
                SetBtnEnable();
                //this.Cursor=System.Windows.Forms.Cursors.Default;
                MessageBox.Show("脚本生成失败!请检查表名是否规范或其他问题导致。(" + ex.Message + ")", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
示例#8
0
        void SaveAs()
        {
            TextEditorControl editor = textEditorContent;

            if (editor != null)
            {
                SaveFileDialog dialog = null;
                try
                {
                    dialog             = new SaveFileDialog();
                    dialog.Filter      = SharpPadFileFilter;
                    dialog.FilterIndex = 0;
                    dialog.FileName    = this.SaveFileName;
                    DialogResult result = dialog.ShowDialog();
                    if (DialogResult.OK == result)
                    {
                        string kk = editor.Text;
                        FileHelper.WriteFile(dialog.FileName, editor.Text);
                    }
                }
                catch (System.AccessViolationException accEx)
                {
                    LogHelper.WriteException(accEx);
                }
                catch (System.StackOverflowException flowEx)
                {
                    LogHelper.WriteException(flowEx);
                }
                catch (Exception ex)
                {
                    LogHelper.WriteException(ex);
                }
                finally
                {
                    dialog.Dispose();
                }
            }
        }
 private void mnuOpen_Click(object sender, EventArgs e)
 {
     try
     {
         using (OpenFileDialog dialog = new OpenFileDialog())
         {
             dialog.Filter      = SharpPadFileFilter;
             dialog.FilterIndex = 0;
             dialog.ShowDialog();
             if (!string.IsNullOrEmpty(dialog.FileName))
             {
                 using (StreamReader reader = new StreamReader(dialog.FileName, Encoding.Default))
                 {
                     this.textEditorContent.Text = reader.ReadToEnd();
                 }
             }
             //if (DialogResult.OK == dialog.ShowDialog())
             //{
             //    StreamReader reader = new StreamReader(dialog.FileName, Encoding.Default);
             //    this.textEditorContent.Text= reader.ReadToEnd();
             //}
         }
     }
     catch (System.AccessViolationException accEx)
     {
         LogHelper.WriteException(accEx);
     }
     catch (System.StackOverflowException flowEx)
     {
         LogHelper.WriteException(flowEx);
     }
     catch (Exception ex)
     {
         LogHelper.WriteException(ex);
     }
 }
        private void mnuSave_Click(object sender, EventArgs e)
        {
            try
            {
                using (SaveFileDialog dialog = new SaveFileDialog())
                {
                    dialog.Title = "保存当前代码";
                    string text = "";
                    if (this.Type == "CS")
                    {
                        dialog.Filter = "C# files (*.cs)|*.cs|All files (*.*)|*.*";
                        text          = this.textEditorContent.Text;
                    }
                    if (this.Type == "SQL")
                    {
                        dialog.Filter = "SQL files (*.sql)|*.sql|All files (*.*)|*.*";
                        text          = this.textEditorContent.Text;
                    }
                    if (this.Type == "Aspx")
                    {
                        dialog.Filter = "Aspx files (*.aspx)|*.aspx|All files (*.*)|*.*";
                        text          = this.textEditorContent.Text;
                    }
                    if (this.Type == "XML")
                    {
                        dialog.Filter = "Aspx files (*.xml)|*.xml|All files (*.*)|*.*";
                        text          = this.textEditorContent.Text;
                    }
                    if (this.Type == "HTML")
                    {
                        dialog.Filter = "HTML files (*.html)|*.html|All files (*.*)|*.*";
                        text          = this.textEditorContent.Text;
                    }

                    if (this.Type == "JavaScript")
                    {
                        dialog.Filter = "JavaScritp files (*.js)|*.js|All files (*.*)|*.*";
                        text          = this.textEditorContent.Text;
                    }

                    if (!string.IsNullOrEmpty(this.SaveFileName))
                    {
                        dialog.FileName = this.SaveFileName;
                    }

                    dialog.ShowDialog();
                    if (!string.IsNullOrEmpty(dialog.FileName))
                    {
                        using (StreamWriter writer = new StreamWriter(dialog.FileName, false, Encoding.Default))
                        {
                            writer.Write(text);
                            writer.Flush();
                            writer.Close();
                        }
                    }
                }
            }
            catch (System.AccessViolationException accEx)
            {
                LogHelper.WriteException(accEx);
            }
            catch (System.StackOverflowException flowEx)
            {
                LogHelper.WriteException(flowEx);
            }
            catch (Exception ex)
            {
                LogHelper.WriteException(ex);
            }
        }
示例#11
0
        //批量代码生成
        private void cmnuItemBatchGenerateAll_Click(object sender, EventArgs e)
        {
            if (tvPDObjectView.SelectedNode == null || tvPDObjectView.SelectedNode.Tag == null || string.IsNullOrEmpty(tvPDObjectView.SelectedNode.Tag.ToString()) || tvPDObjectView.SelectedNode.Tag.ToString() != this.TAGTABLES)
            {
                MessageBox.Show("请选择“数据表”节点进行代码的批量生成!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            var setHelper = new SettingHelper();

            setHelper.GetSetting();
            if (string.IsNullOrEmpty(setHelper.Output))
            {
                MessageBox.Show("请先设置代码的输出路径!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                var projProperty = new ProjectProperty();
                projProperty.ShowDialog();
                return;
            }
            var overwrite      = true;
            var codeOutPutPath = setHelper.Output;
            // 设置鼠标繁忙状态,并保留原先的状态
            var holdCursor = this.Cursor;

            this.Cursor = Cursors.WaitCursor;
            mainfrm.InvokeSendStatusMessage("准备批量生成代码...");
            try
            {
                foreach (TreeNode node in this.tvPDObjectView.SelectedNode.Nodes)
                {
                    tvPDObjectView.SelectedNode = node;
                    var className   = node.Text.Split(',')[0].Replace("_", string.Empty);
                    var tableName   = node.Text.Split(',')[0];
                    var description = node.Text.Split(',')[1];
                    mainfrm.InvokeSendStatusMessage("当前处理对象:" + tableName);
                    if ((!string.IsNullOrEmpty(className)) && (!string.IsNullOrEmpty(this.ProductName)))
                    {
                        className = className.Replace(this.ProductName, string.Empty);
                    }

                    var codeMaker = new PDMCodeMaker(this.xmlDocument, this.CompanyName, this.Project, this.Author, DateTime.Now.Year.ToString(), DateTime.Now.ToString("yyyy-MM-dd"), className, "Manager", tableName, description);
                    overwrite = codeMaker.BuilderTable(codeOutPutPath, overwrite);
                    overwrite = codeMaker.BuilderEntity(codeOutPutPath, overwrite);
                    overwrite = codeMaker.BuilderManager(codeOutPutPath, overwrite);

                    var fileName = codeOutPutPath + "\\" + this.Project + ".BizLogic\\IService\\" + "I" + className + "Service.cs";
                    this.GengerateIService(fileName);
                    fileName = codeOutPutPath + "\\" + this.Project + ".BizLogic\\Service\\" + className + "Service.cs";
                    this.GenerateService(fileName);
                }
            }
            catch (Exception ex)
            {
                LogHelper.WriteException(ex);
            }
            finally
            {
                // 设置鼠标默认状态,原来的光标状态
                this.Cursor = holdCursor;
                mainfrm.InvokeSendStatusMessage("就绪。");
                // 打开文件夹
                Process.Start(codeOutPutPath);
            }
        }
示例#12
0
        private void miFile_DropDownItemClicked(object sender, ToolStripItemClickedEventArgs e)
        {
            #region 快捷菜单-文件
            try
            {
                switch (e.ClickedItem.Name)
                {
                case "miOpenFile":     //打开
                {
                    TextEditorControl editor = textEditorContent;
                    if (editor != null)
                    {
                        using (OpenFileDialog dialog = new OpenFileDialog())
                        {
                            dialog.Filter      = SharpPadFileFilter;
                            dialog.FilterIndex = 0;
                            if (DialogResult.OK == dialog.ShowDialog())
                            {
                                editor.LoadFile(dialog.FileName);
                                CheckCurrentViewMode(editor.Document.HighlightingStrategy.Name);
                                if (System.IO.Path.GetExtension(dialog.FileName).ToLower() == ".xml")
                                {
                                    if (!(textEditorContent.Document.FoldingManager.FoldingStrategy is XmlFoldingStrategy))
                                    {
                                        textEditorContent.Document.FoldingManager.FoldingStrategy = new XmlFoldingStrategy();
                                    }
                                    UpdateFolding();
                                }
                            }
                        }
                    }
                }
                break;

                case "miSave":     //保存
                {
                    TextEditorControl editor = textEditorContent;
                    if (editor != null)
                    {
                        SaveAs();
                    }
                }
                break;

                case "miSaveAs":     //另存为
                    SaveAs();
                    break;
                }
            }
            catch (System.AccessViolationException accEx)
            {
                LogHelper.WriteException(accEx);
            }
            catch (System.StackOverflowException flowEx)
            {
                LogHelper.WriteException(flowEx);
            }
            catch (Exception ex)
            {
                LogHelper.WriteException(ex);
            }
            #endregion
        }
示例#13
0
        private void btnConnTest_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;
                }
                constr = GetSelVerified() == "Windows"
                                ? "Integrated Security=SSPI;Data Source=" + server + ";Initial Catalog=master"
                                : (pass == ""
                                    ? "user id=" + user + ";initial catalog=master;data source=" + server
                                    : "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 = "正在连接服务器,请稍候...";

                    IDbObject dbobj;
                    dbobj = DBOMaker.CreateDbObj(strtype);

                    dbobj.DbConnectStr = constr;
                    var 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)
                {
                    LogHelper.WriteException(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://www.cnblogs.com/huyong/");
                        }
                        catch
                        {
                            MessageBox.Show("请访问:http://www.cnblogs.com/huyong/", "完成", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }
                    }
                    return;
                }
            }
            catch (System.Exception ex)
            {
                //LogInfo.WriteLog(System.Reflection.MethodBase.GetCurrentMethod(), ex);
                LogHelper.WriteException(ex);
                MessageBox.Show(this, ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
示例#14
0
        private void btnOk_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;
                }

                dbName = this.cmbDBlist.SelectedIndex > 0 ? cmbDBlist.Text : "master";

                constr = GetSelVerified() == "Windows"
                                ? "Integrated Security=SSPI;Data Source=" + server + ";Initial Catalog=" + dbName
                                : (pass == ""
                                    ? "user id=" + user + ";initial catalog=" + dbName + ";data source=" + server
                                    : "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 = 2;
                        }
                    }

                    if ((ver == "9") && (strtype == "SQL2000"))
                    {
                        DialogResult dr = MessageBox.Show(this, "该服务器并非SQLServer 2000,是否进行更改选择?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
                        if (dr == DialogResult.OK)
                        {
                            comboBoxServerVer.SelectedIndex = 1;
                        }
                    }

                    if ((ver == "10") && (strtype != "SQL2008"))
                    {
                        DialogResult dr = MessageBox.Show(this, "该服务器并非SQLServer 2008,是否进行更改选择?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
                        if (dr == DialogResult.OK)
                        {
                            comboBoxServerVer.SelectedIndex = 0;
                        }
                    }
                }
                catch
                {
                }

                #endregion

                //测试连接
                var myCn = new SqlConnection(constr);
                try
                {
                    this.Text = "正在连接服务器,请稍候...";
                    myCn.Open();
                }
                catch (System.Exception ex)
                {
                    this.Text = "连接服务器失败!";
                    LogHelper.WriteException(ex);
                    MessageBox.Show(this, "连接服务器失败!请检查服务器地址或用户名密码是否正确!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                finally
                {
                    myCn.Close();
                }

                this.Text = "连接服务器成功!";

                if (dbobj == null)
                {
                    dbobj = new 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 = 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);
                LogHelper.WriteException(ex);
            }
        }
示例#15
0
        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 DbSettings();
                }

                //将当前配置写入配置文件
                dbobj.DbType        = "Oracle";
                dbobj.Server        = server;
                dbobj.ConnectStr    = constr;
                dbobj.DbName        = "";
                dbobj.ConnectSimple = chk_Simple.Checked;
                bool succ = DbConfig.AddSettings(dbobj);
                if (!succ)
                {
                    MessageBox.Show(this, "该服务器已经存在!请更换服务器地址或检查输入是否正确!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                //将当前数据库系统类型写入配置
                //MainForm.setting.DbType="Oracle";
                //ModuleConfig.SaveSettings(MainForm.setting);
                this.DialogResult = DialogResult.OK;
                this.Close();
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(this, ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                LogHelper.WriteException(ex);
            }
        }
示例#16
0
        /// <summary>
        /// 生成数据库类型为SqlServer指定表的DDL
        /// </summary>
        private void GenerateSqlServerDDL()
        {
            //对于已经生成过的就不用再次生成了,节约资源。
            if (!string.IsNullOrEmpty(textEditorDDL.Text) && textEditorDDL.Text.Trim().Length > 10)
            {
                return;
            }

            ScriptOption();
            ServerConnection sqlConnection = null;

            try
            {
                var sbOutPut = new StringBuilder();

                if (dbSet.ConnectStr.ToLower().Contains("integrated security")) //Windows身份验证
                {
                    sqlConnection = new ServerConnection(dbSet.Server);
                }
                else        //SqlServer身份验证
                {
                    var linkDataArray = dbSet.ConnectStr.Split(';');
                    var userName      = string.Empty;
                    var pwd           = string.Empty;
                    foreach (var str in linkDataArray)
                    {
                        if (str.ToLower().Replace(" ", "").Contains("userid="))
                        {
                            userName = str.Split('=')[1];
                        }

                        if (str.ToLower().Replace(" ", "").Contains("password"))
                        {
                            pwd = str.Split('=')[1];
                        }
                    }

                    sqlConnection = new ServerConnection(dbSet.Server, userName, pwd);
                }

                var    sqlServer = new Server(sqlConnection);
                var    table     = sqlServer.Databases[dbSet.DbName].Tables[txtName.Text];
                string ids;
                //编写表的脚本
                sbOutPut = new StringBuilder();
                sbOutPut.AppendLine();
                sCollection = table.Script(scriptOption);

                foreach (var str in sCollection)
                {
                    //此处修正smo的bug
                    if (str.Contains("ADD  DEFAULT") && str.Contains("') AND type = 'D'"))
                    {
                        ids = str.Substring(str.IndexOf("OBJECT_ID(N'") + "OBJECT_ID(N'".Length, str.IndexOf("') AND type = 'D'") - str.IndexOf("OBJECT_ID(N'") - "OBJECT_ID(N'".Length);
                        sbOutPut.AppendLine(str.Insert(str.IndexOf("ADD  DEFAULT") + 4, "CONSTRAINT " + ids));
                    }
                    else
                    {
                        sbOutPut.AppendLine(str);
                    }

                    sbOutPut.AppendLine("GO");
                }

                //生成存储过程
                this.textEditorDDL.SetCodeEditorContent("SQL", sbOutPut.ToString());
                this.textEditorDDL.SaveFileName = this.TableName + ".sql";
                sbOutPut = new StringBuilder();
            }
            catch (Exception ex)
            {
                LogHelper.WriteException(ex);
            }
            finally
            {
                sqlConnection.Disconnect();
            }
        }