Exemple #1
0
        private void bNewTbl_Click(object sender, EventArgs e) // 新建表
        {
            string newTblName = "";
            NameInput frm = new NameInput();
            DialogResult result = frm.ShowDialog();
            if (result == DialogResult.OK)
            {
                newTblName = frm.StringInput;
            }
            if (newTblName == "")
            {
                return;
            }

            bool bSucCreate = false;
            Conn.Open();
            try
            {
                string strcmd = string.Format("CREATE TABLE {0} ({1} varchar(3000))", newTblName, TRASH_FIELD);
                /* remoting
                SqlCommand cmd = Conn.CreateCommand();
               
                cmd.CommandText = strcmd;
                cmd.ExecuteNonQuery();
                 */

                Helper.ExecuteCommand(newTblName, strcmd, Conn);
                bSucCreate = true;
            }
            catch (Exception ex)
            {
                string str = string.Format("在添加表 {0} 时发生错误。\r\n\r\n错误信息:{1}", newTblName, ex.Message);
                MessageBox.Show(str);
            }
            Conn.Close();

            if (bSucCreate)
            {
                //DataTable new_tbl = Helper.GetDataTable("SELECT * FROM " + newTblName, Conn);
                DataTable new_tbl = Helper.GetDataTableProxy(newTblName, Conn);

                AllTables[newTblName] = new_tbl;

                TreeNode new_node = this.tree.Nodes.Add(newTblName);
                new_node.ImageIndex = 3;
                new_node.SelectedImageIndex = 3;

                this.tree.SelectedNode = new_node;
                ShowTableInfo(new_node);
                newNodes.Add(new_node);
            }

            // 显示新建表的结点
            tree.TopNode.ExpandAll();
            tree.TopNode.Collapse();
        }
Exemple #2
0
        private void bNewField_Click(object sender, EventArgs e) // 新建字段
        {
            string newFieldName = "";
            NameInput frm = new NameInput();
            DialogResult result = frm.ShowDialog();
            if (result == DialogResult.OK)
            {
                newFieldName = frm.StringInput.Trim();
            }
            if (newFieldName == "")
            {
                return;
            }

            string tblName = this.tree.SelectedNode.Text.Trim();
            bool bSucNewField = false;
            Conn.Open();
            try
            {
                /* remoting
                SqlCommand cmd = Conn.CreateCommand();
                cmd.CommandText = string.Format("ALTER TABLE {0} ADD {1} varchar (3000) NULL", tblName, newFieldName);
                cmd.ExecuteNonQuery();
                */

                string sql = string.Format("ALTER TABLE {0} ADD [{1}] varchar (3000) NULL", tblName, newFieldName);
                Helper.ExecuteCommand(tblName, sql, Conn);
                 
                bSucNewField = true;
            }
            catch (Exception ex)
            {
                string str = string.Format("在添加字段时发生错误。\r\n\r\n错误信息:{0}", ex.Message);
                MessageBox.Show(str);
            }
            Conn.Close();

            if (bSucNewField)
            {
                //DataTable tbl = Helper.GetDataTable("SELECT * FROM " + tblName, Conn);
                DataTable tbl = Helper.GetDataTableProxy(tblName, Conn);

                AllTables[tblName] = tbl;

                TreeNode new_node = this.tree.SelectedNode.Nodes.Add(newFieldName);
                new_node.Tag = newFieldName;
                new_node.ImageIndex = 4;
                new_node.SelectedImageIndex = 4;
                new_node.StateImageIndex = 7;

                this.tree.SelectedNode = new_node;
                ShowFieldInfo(new_node);
                DeleteTrashField(tblName); // 安静地删除___delete_me字段
            }
        }