예제 #1
0
파일: ContentForm.cs 프로젝트: yswenli/WEF
        /// <summary>
        /// 加载
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ContentForm_Load(object sender, EventArgs e)
        {
            LoadForm.ShowLoading(this);

            if (ConnectionModel != null)
            {
                this.DatabaseName = ConnectionModel.Database;
                this.TableName    = ConnectionModel.TableName;
                this.IsView       = ConnectionModel.IsView;
            }



            Task.Factory.StartNew(() =>
            {
                var dbObject = DBObjectHelper.GetDBObject(ConnectionModel);

                DataTable primarykeydt = dbObject.GetKeyName(DatabaseName, TableName);

                if (primarykeydt.Rows.Count == 0)
                {
                    MessageBox.Show("当前表找不到任何主键,请选择上面的列表行来添加主键");
                }

                this.Invoke(new Action(() =>
                {
                    cnnTxt.Text = DBObjectHelper.GetCnnString(ConnectionModel, DatabaseName);

                    #region structure

                    columnsdt = dbObject.GetColumnInfoList(DatabaseName, TableName);

                    gridColumns.DataSource = columnsdt;

                    #endregion

                    cbPrimarykey.Items.Clear();

                    if (null != primarykeydt && primarykeydt.Rows.Count > 0)
                    {
                        foreach (DataRow dr in primarykeydt.Rows)
                        {
                            cbPrimarykey.Items.Add(dr["ColumnName"].ToString());
                        }

                        cbPrimarykey.SelectedIndex = 0;
                    }



                    txtClassName.Text = TableName.Trim().Replace(' ', '_');
                    txtnamespace.Text = UtilsHelper.ReadNamespace();
                }));
                LoadForm.HideLoading(this);
            });
        }
예제 #2
0
파일: BatchForm.cs 프로젝트: yswenli/WEF
        /// <summary>
        /// 初始化
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void BatchForm_Load(object sender, EventArgs e)
        {
            try
            {
                sysconfigModel = UtilsHelper.GetSysconfigModel();

                txtNamaspace.Text = sysconfigModel.Namespace;

                var index = connectionModel.Name.IndexOf("[");

                if (index < 0)
                {
                    index = connectionModel.Name.IndexOf("(");
                }

                llServer.Text       = connectionModel.Name.Substring(0, index);
                llDatabaseName.Text = DatabaseName;
                txtPath.Text        = sysconfigModel.BatchDirectoryPath;


                DataTable tablesDT = null;

                dbObject = DBObjectHelper.GetDBObject(ConnectionModel);

                tablesDT = dbObject.GetTables(DatabaseName);

                DataRow[] drs = tablesDT.Select("", "name asc");

                if (null != drs && drs.Length > 0)
                {
                    foreach (DataRow dr in drs)
                    {
                        lbleft.Items.Add(dr[0]);
                        tableview.Add(dr[0].ToString(), false);
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show($"");
                this.Close();
            }
        }
예제 #3
0
        /// <summary>
        /// 删除表/视图
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void deleteTableToolStripMenuItem_Click(object sender, EventArgs e)
        {
            try
            {
                TreeNode node = Treeview.SelectedNode;

                if (node != null && node.Level == 4)
                {
                    if (MessageBox.Show(this, "确定要删除表/视图", "WEF数据库工具", MessageBoxButtons.YesNo) == DialogResult.No)
                    {
                        return;
                    }

                    var tableName = node.Text;
                    var conModel      = _ConnectList.Find(delegate(ConnectionModel con) { return(con.ID.ToString().Equals(node.Parent.Parent.Parent.Tag.ToString())); });
                    conModel.Database = node.Parent.Parent.Text;
                    WEF.DbDAL.IDbObject dbObject = DBObjectHelper.GetDBObject(conModel);

                    var result = false;

                    if (node.Parent.Text == "数据表")
                    {
                        result = dbObject.DeleteTable(conModel.Database, tableName);
                    }
                    else if (node.Parent.Text == "视图")
                    {
                        result = dbObject.DeleteView(conModel.Database, tableName);
                    }

                    if (result)
                    {
                        MessageBox.Show(this, "删除表/视图操作成功", "WEF数据库工具");
                        Treeview.Nodes.Remove(node);
                        return;
                    }
                    MessageBox.Show(this, "删除表/视图操作失败", "WEF数据库工具");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(this, "删除表操作失败,Error:" + ex.Message, "WEF数据库工具");
            }
        }
예제 #4
0
파일: SQLForm.cs 프로젝트: yswenli/WEF
        public void RunSql()
        {
            var sql = AutoTextBox.TextBox.Text;

            stopwatch.Restart();

            LoadForm.ShowLoading(this);

            Task.Factory.StartNew(() =>
            {
                try
                {
                    WEF.DbDAL.IDbObject dbObject = DBObjectHelper.GetDBObject(ConnectionModel);

                    if (string.IsNullOrEmpty(sql))
                    {
                        LoadForm.HideLoading(this);;

                        this.Invoke(new Action(() =>
                        {
                            MessageBox.Show(this, "sql内容不能为空!");
                        }));

                        return;
                    }

                    this.Invoke(new Action(() =>
                    {
                        if (!string.IsNullOrWhiteSpace(AutoTextBox.TextBox.SelectedText))
                        {
                            sql = AutoTextBox.TextBox.SelectedText.Trim();

                            if (string.IsNullOrEmpty(sql))
                            {
                                LoadForm.HideLoading(this);;
                                MessageBox.Show(this, "sql内容不能为空!");
                                return;
                            }
                        }

                        dataGridView1.DataSource = null;
                    }));

                    if (sql.IndexOf("select", StringComparison.InvariantCultureIgnoreCase) >= 0)
                    {
                        try
                        {
                            int max = 50;

                            var ds = dbObject.Query(ConnectionModel.Database, sql);

                            if (ds != null && ds.Tables != null)
                            {
                                var dt = ds.Tables[0];

                                if (dt != null)
                                {
                                    var count = dt.Rows.Count;

                                    if (count > max)
                                    {
                                        for (int i = max; i < count; i++)
                                        {
                                            dt.Rows.RemoveAt(max);
                                        }
                                    }


                                    var dList = new List <int>();

                                    for (int i = 0; i < dt.Columns.Count; i++)
                                    {
                                        if (dt.Columns[i].DataType == typeof(DateTime))
                                        {
                                            dList.Add(i);
                                        }
                                    }


                                    dataGridView1.Invoke(new Action(() =>
                                    {
                                        dataGridView1.DataSource = dt;

                                        if (dList.Any())
                                        {
                                            foreach (var item in dList)
                                            {
                                                dataGridView1.Columns[item].DefaultCellStyle.Format = "yyyy-MM-dd HH:mm:ss.fff";
                                            }
                                        }

                                        lbl_execute.Text = $"当前显示{(max > count ? count : max)}行,影响数据行数:{count} 耗时:{stopwatch.Elapsed.TotalSeconds} 秒";
                                    }));
                                }
                            }
                            LoadForm.HideLoading(this);;
                        }
                        catch (Exception ex)
                        {
                            LoadForm.HideLoading(this);;
                            this.Invoke(new Action(() =>
                            {
                                MessageBox.Show(this, $"查询发生异常,ex:" + ex.Message);
                            }));
                        }
                    }
                    else
                    {
                        try
                        {
                            var count = dbObject.ExecuteSql(ConnectionModel.Database, sql);

                            lbl_execute.Invoke(new Action(() =>
                            {
                                lbl_execute.Text = $"影响数据行数:{count} 耗时:{stopwatch.Elapsed.TotalMilliseconds} 毫秒";
                            }));

                            LoadForm.HideLoading(this);;
                        }
                        catch (Exception ex)
                        {
                            LoadForm.HideLoading(this);;
                            this.Invoke(new Action(() =>
                            {
                                MessageBox.Show(this, $"操作发生异常,ex:" + ex.Message);
                            }));
                        }
                    }
                }
                catch (Exception ex)
                {
                    this.Invoke(new Action(() =>
                    {
                        MessageBox.Show(this, $"操作发生异常,ex:" + ex.Message);
                    }));
                }
            });
        }