コード例 #1
0
ファイル: MainForm.cs プロジェクト: lixiaohuang/WEF
        void lp_newsqlForm(WEF.ModelGenerator.Model.Connection conModel)
        {
            SQLForm s = new SQLForm();

            s.Text            = "(" + conModel.Database + ")SQL查询窗口";
            s.ConnectionModel = conModel;
            s.Show(dpleft);
        }
コード例 #2
0
ファイル: MainForm.cs プロジェクト: lixiaohuang/WEF
        /// <summary>
        /// 创建生成
        /// </summary>
        /// <param name="conModel"></param>
        /// <param name="tableName"></param>
        void lp_newcontentForm(WEF.ModelGenerator.Model.Connection conModel)
        {
            ContentForm s = new ContentForm();

            s.Text            = "(" + conModel.Database + ")" + conModel.TableName;
            s.TableName       = conModel.TableName;
            s.DatabaseName    = conModel.Database;
            s.IsView          = conModel.IsView;
            s.ConnectionModel = conModel;
            s.Show(dpleft);
        }
コード例 #3
0
ファイル: MainForm.cs プロジェクト: liyang-love/WEF
        /// <summary>
        /// 创建生成
        /// </summary>
        /// <param name="conModel"></param>
        /// <param name="tableName"></param>
        void lp_newcontentForm(WEF.ModelGenerator.Model.Connection conModel, string tableName, string databaseName, bool isView)
        {
            ContentForm s = new ContentForm();

            s.Text            = "(" + databaseName + ")" + tableName;
            s.TableName       = tableName;
            s.DatabaseName    = databaseName;
            s.IsView          = isView;
            s.ConnectionModel = conModel;
            s.Show(dpleft);
        }
コード例 #4
0
ファイル: DBMsAccess.cs プロジェクト: lixiaohuang/WEF
        /// <summary>
        /// 确定
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button2_Click(object sender, EventArgs e)
        {
            if (rbconnstring.Checked)
            {
                if (string.IsNullOrEmpty(txtConnectionString.Text))
                {
                    MessageBox.Show("请填写连接字符串!");
                    return;
                }
            }
            else
            {
                if (string.IsNullOrEmpty(txtfilepath.Text))
                {
                    MessageBox.Show("请选择Access文件!");
                    return;
                }
            }

            Model.Connection connModel = new WEF.ModelGenerator.Model.Connection();

            if (rbdatabaseselect.Checked)
            {
                StringBuilder cstring = new StringBuilder();

                string exstension = txtfilepath.Text.Substring(txtfilepath.Text.LastIndexOf('.') + 1);
                if (exstension.ToLower().Equals("mdb"))
                {
                    cstring.Append("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=");
                }
                else if (exstension.ToLower().Equals("accdb"))
                {
                    cstring.Append("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=");
                }

                cstring.Append(txtfilepath.Text);
                cstring.Append(";");
                if (!string.IsNullOrEmpty(txtPassword.Text))
                {
                    cstring.Append("User Id=");
                    cstring.Append(txtUserName.Text);
                    cstring.Append(";Password="******";");
                }

                connModel.ConnectionString = cstring.ToString();
                connModel.Name             = txtfilepath.Text;
                connModel.Database         = connModel.Name.Substring(connModel.Name.LastIndexOf('\\') + 1);
            }
            else
            {
                connModel.ConnectionString = txtConnectionString.Text;


                string constring       = txtConnectionString.Text;
                string templeftstring  = string.Empty;
                string temprightstring = string.Empty;
                if (constring.IndexOf('/') > 0)
                {
                    templeftstring  = constring.Substring(0, constring.LastIndexOf('/'));
                    temprightstring = constring.Substring(constring.LastIndexOf('/') + 1);
                }
                else if (constring.IndexOf('\\') > 0)
                {
                    templeftstring  = constring.Substring(0, constring.LastIndexOf('\\'));
                    temprightstring = constring.Substring(constring.LastIndexOf('\\') + 1);
                }
                else
                {
                    MessageBox.Show("连接字符串格式不正确!");
                    return;
                }

                if (temprightstring.IndexOf(';') > 0)
                {
                    temprightstring = temprightstring.Substring(0, temprightstring.IndexOf(';'));
                }

                templeftstring = templeftstring.Substring(templeftstring.IndexOf('=') + 1);


                connModel.Name     = templeftstring + temprightstring;
                connModel.Database = temprightstring;
            }

            try
            {
                using (OleDbConnection oledbConn = new OleDbConnection(connModel.ConnectionString))
                {
                    oledbConn.Open();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("连接失败!\n\r" + ex.Message);
                return;
            }

            connModel.DbType = DatabaseType.MsAccess.ToString();
            connModel.ID     = Guid.NewGuid();

            UtilsHelper.AddConnection(connModel);

            this.DialogResult = DialogResult.OK;

            this.Close();
        }
コード例 #5
0
        /// <summary>
        /// 确定
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button2_Click(object sender, EventArgs e)
        {
            if (rbconnstring.Checked)
            {
                if (string.IsNullOrEmpty(txtConnectionString.Text))
                {
                    MessageBox.Show("请填写连接字符串!");
                    return;
                }
            }
            else
            {
                if (string.IsNullOrEmpty(txtfilepath.Text))
                {
                    MessageBox.Show("请选择Sqlite数据库文件!");
                    return;
                }
            }

            Model.Connection connModel = new WEF.ModelGenerator.Model.Connection();

            if (rbdatabaseselect.Checked)
            {
                StringBuilder cstring = new StringBuilder("Data Source=");
                cstring.Append(txtfilepath.Text);
                cstring.Append(";");
                if (!string.IsNullOrEmpty(txtPassword.Text))
                {
                    cstring.Append("Password="******";");
                }

                connModel.ConnectionString = cstring.ToString();
                connModel.Name             = txtfilepath.Text;
                connModel.Database         = connModel.Name.Substring(connModel.Name.LastIndexOf('\\') + 1);
            }
            else
            {
                connModel.ConnectionString = txtConnectionString.Text;


                string constring       = txtConnectionString.Text;
                string templeftstring  = string.Empty;
                string temprightstring = string.Empty;
                if (constring.IndexOf('/') > 0)
                {
                    templeftstring  = constring.Substring(0, constring.LastIndexOf('/'));
                    temprightstring = constring.Substring(constring.LastIndexOf('/') + 1);
                }
                else if (constring.IndexOf('\\') > 0)
                {
                    templeftstring  = constring.Substring(0, constring.LastIndexOf('\\'));
                    temprightstring = constring.Substring(constring.LastIndexOf('\\') + 1);
                }
                else
                {
                    MessageBox.Show("连接字符串格式不正确!");
                    return;
                }

                if (temprightstring.IndexOf(';') > 0)
                {
                    temprightstring = temprightstring.Substring(0, temprightstring.IndexOf(';'));
                }

                templeftstring = templeftstring.Substring(templeftstring.IndexOf('=') + 1);


                connModel.Name     = templeftstring + temprightstring;
                connModel.Database = temprightstring;
            }

            try
            {
                using (SQLiteConnection oledbConn = new SQLiteConnection(connModel.ConnectionString))
                {
                    oledbConn.Open();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("连接失败!\n\r" + ex.Message);
                return;
            }

            connModel.DbType = DatabaseType.Sqlite3.ToString();
            connModel.ID     = Guid.NewGuid();

            UtilsHelper.AddConnection(connModel);

            this.DialogResult = DialogResult.OK;

            this.Close();
        }