Exemplo n.º 1
0
        private void RenameTableCmd_Execute(object sender, ExecutedRoutedEventArgs e)
        {
            string            oldTableName = CurrentTreeArgs.TableName;
            InputValueWindows iv           = new InputValueWindows("Table Name");

            if (iv.ShowDialog() == true)
            {
                string newTableName = iv.X_GetInputedValue.ToString();
                if (newTableName == oldTableName)
                {
                    return;
                }

                string cmdStr = App.MainEngineer.CurrentCommandTextHandler.GetRenameTableCmdStr(oldTableName, newTableName);

                App.MainEngineer.DoExecuteNonQuery(cmdStr);

                //here if we load all schema info that will cost a lot of time to do
                //so here ,just find the node of this table and change the treeNode Text value
                //LoadAllSchemaInfo();
                foreach (TreeViewItem item in mainTreeView.Items)
                {
                    if (item.Header.ToString() == oldTableName)
                    {
                        item.Header = newTableName;
                        CurrentTreeArgs.TableName = newTableName;
                    }
                }
            }
        }
Exemplo n.º 2
0
        private void RenameColumnCmd_Execute(object sender, ExecutedRoutedEventArgs e)
        {
            string            newColumnName = string.Empty;
            InputValueWindows iv            = new InputValueWindows("New column name");

            if (iv.ShowDialog() == true)
            {
                string cmdStr = App.MainEngineer.CurrentCommandTextHandler.GetRenameColumnCmdStr(CurrentTreeArgs.TableName,
                                                                                                 CurrentTreeArgs.ColumnName, newColumnName);
                App.MainEngineer.DoExecuteNonQuery(cmdStr);

                RefreshColumnsInfo(CurrentTreeArgs.TableName);
            }
        }
Exemplo n.º 3
0
        private void CreateIndexCmd_Execute(object sender, ExecutedRoutedEventArgs e)
        {
            InputValueWindows iv = new InputValueWindows("New index name");

            iv.X_MaxLength = 20;
            if (iv.ShowDialog() == true)
            {
                string newIndexName = iv.X_GetInputedValue.ToString();

                if ((newIndexName.Length > 20) || (string.IsNullOrEmpty(newIndexName)))
                {
                    MessageBox.Show(String.Format("Index name length must less than {0} and large than 0 ", 20));
                    return;
                }

                string cmdStr = App.MainEngineer.CurrentCommandTextHandler.GetCreateIndexCmdStr(newIndexName, CurrentTreeArgs.TableName,
                                                                                                CurrentTreeArgs.ColumnName);
                App.MainEngineer.DoExecuteNonQuery(cmdStr);
                RefreshColumnsInfo(CurrentTreeArgs.TableName);
            }
        }
Exemplo n.º 4
0
        private void itemCreateIndex_Click()
        {
            string newIndexName = string.Empty;

ReDo:
            //using (PopupForm p = new PopupForm())
            //{
            //    p.X_NotifyStr = "Index name";
            //    if (p.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            //    {
            //        newIndexName = p.X_Result;
            //    }
            //    else
            //    {
            //        return;
            //    }
            //}

            InputValueWindows iv = new InputValueWindows("New Index name");

            if (iv.ShowDialog() == true)
            {
                newIndexName = iv.X_GetInputedValue.ToString();
            }
            else
            {
                return;
            }

            if ((newIndexName.Length > 20) || (string.IsNullOrEmpty(newIndexName)))
            {
                MessageBox.Show(String.Format("Index name length must less than {0} and large than 0 ", 20));
                goto ReDo;
            }

            string cmdStr = App.MainEngineer.CurrentCommandTextHandler.GetCreateIndexCmdStr(newIndexName, X_CurItemArgs.TableName, X_CurItemArgs.ColumnName);

            X_CallNotifyEvent(cmdStr, true);
        }
Exemplo n.º 5
0
        public virtual ContextMenu CreateMenuForTable()
        {
            ContextMenu ctMenu = new ContextMenu();

            #region select all
            MenuItem itemSelectAll = new MenuItem();
            itemSelectAll.Header = "TitleSelectAll".GetFromResourece();
            itemSelectAll.Click += (s, e) =>
            {
                string cmdStr = string.Format("Select * from {0}", App.MainEngineer.GetMaskedTableName(X_CurItemArgs.TableName));
                X_CallNotifyEvent(cmdStr, true);
            };
            ctMenu.Items.Add(itemSelectAll);
            #endregion
            ctMenu.Items.Add(new Separator());

            #region Select
            MenuItem itemSelect = new MenuItem();
            itemSelect.Header = "TitleSelect".GetFromResourece();
            itemSelect.Click += (s1, e1) =>
            {
                X_CallNotifyEvent(String.Format("SELECT * FROM {0}", App.MainEngineer.GetMaskedTableName(X_CurItemArgs.TableName)), false);
            };
            ctMenu.Items.Add(itemSelect);
            #endregion

            #region Insert
            MenuItem itemInsert = new MenuItem();
            itemInsert.Header = "TitleInsert".GetFromResourece();
            itemInsert.Click += delegate
            {
                itemInsert_Click(X_CurItemArgs.TableName);
            };
            ctMenu.Items.Add(itemInsert);
            #endregion

            #region Update
            MenuItem itemUpdate = new MenuItem();
            itemUpdate.Header = "TilteUpdate".GetFromResourece();
            itemUpdate.Click += delegate
            {
                string cmdStr = string.Empty;
                try
                {
                    List <string> columnlist = App.MainEngineer.GetColumnNameListFromTable(X_CurItemArgs.TableName);

                    string columnP = string.Empty;
                    foreach (string item in columnlist)
                    {
                        columnP += string.Format("{0}={1},", item, "COLUMN_VALUE");
                    }

                    columnP = columnP.Substring(0, columnP.Length - 1);

                    columnP += " where WHERE_CALUSE";
                    cmdStr   = String.Format("UPDATE {0} SET {1}", App.MainEngineer.GetMaskedTableName(X_CurItemArgs.TableName), columnP);
                }
                catch (Exception ee)
                {
                    ee.HandleMyException();
                    return;
                }

                X_CallNotifyEvent(cmdStr, false);
            };
            ctMenu.Items.Add(itemUpdate);
            #endregion

            #region Delete
            MenuItem itemDelete = new MenuItem();
            itemDelete.Header = "TitleDelete".GetFromResourece();
            itemDelete.Click += delegate
            {
                string cmdStr = String.Format("Delete from {0} WHERE (COLUMN_NAME) = (COLUMN_VALUE) ",
                                              App.MainEngineer.GetMaskedTableName(X_CurItemArgs.TableName));

                X_CallNotifyEvent(cmdStr, false);
            };
            ctMenu.Items.Add(itemDelete);
            #endregion

            ctMenu.Items.Add(new Separator());

            #region Insert Row
            MenuItem itemInsertDataRow = new MenuItem();
            itemInsertDataRow.Header = "TitleInsertARow".GetFromResourece();
            itemInsertDataRow.Click += delegate { itemInsertDataRow_Click(); };
            ctMenu.Items.Add(itemInsertDataRow);
            #endregion

            #region NewTable
            ctMenu.Items.Add(new Separator());

            MenuItem itemCreateTable = new MenuItem();
            itemCreateTable.Header = "CreatTableDialogTitle".GetFromResourece();
            itemCreateTable.Click += new RoutedEventHandler(itemCreateTable_Click);
            ctMenu.Items.Add(itemCreateTable);
            #endregion


            #region Rename Table
            MenuItem itemRenameTable = new MenuItem();
            itemRenameTable.Header = "TitleRenameTable".GetFromResourece();
            itemRenameTable.Click += delegate
            {
                string            newTableName = string.Empty;
                InputValueWindows iv           = new InputValueWindows("Table Name");
                if (iv.ShowDialog() == true)
                {
                    newTableName = iv.X_GetInputedValue.ToString();
                }
                else
                {
                    return;
                }
                if (string.IsNullOrEmpty(newTableName))
                {
                    "TitleCanNotEmptyNewTableName".GetFromResourece().Warning();
                    return;
                }

                string cmdStr = App.MainEngineer.CurrentCommandTextHandler.GetRenameTableCmdStr(X_CurItemArgs.TableName, newTableName);
                X_CallNotifyEvent(cmdStr, true);
            };
            ctMenu.Items.Add(itemRenameTable);

            MenuItem copyTableItem = new MenuItem();
            copyTableItem.Header = "TitleCopyTable".GetFromResourece();
            copyTableItem.Click += delegate
            {
                try
                {
                    string            newTableName = string.Empty;
                    InputValueWindows iv           = new InputValueWindows("Table Name");
                    if (iv.ShowDialog() == true)
                    {
                        newTableName = iv.X_GetInputedValue.ToString();
                    }

                    if (string.IsNullOrEmpty(newTableName))
                    {
                        ("TitleCanNotEmptyNewTableName".GetFromResourece()).Warning();
                        return;
                    }

                    List <string> allTableList = App.MainEngineer.GetTableListInDatabase();
                    if (allTableList.Contains(newTableName))
                    {
                        "InfoTableNameExisted".GetFromResourece().Show();
                        return;
                    }

                    // oldTableName = App.MainEngineer.GetMaskedTableName(oldTableName);
                    // newTableName = App.MainEngineer.GetMaskedTableName(newTableName);
                    //If copy successful
                    if (CopyTable(X_CurItemArgs.TableName, newTableName))
                    {
                        "TitleCopyDataSuccessful".GetFromResourece().Show();
                        if (RefreshAllNodeEvent != null)
                        {
                            RefreshAllNodeEvent(null, null);
                        }
                    }
                }
                catch (Exception ee)
                {
                    ee.HandleMyException();
                }
            };
            ctMenu.Items.Add(copyTableItem);

            #endregion

            #region Drop Table
            MenuItem itemDeleteTable = new MenuItem();
            itemDeleteTable.Header = "TitleDropTable".GetFromResourece();
            itemDeleteTable.Click += delegate
            {
                if ("ConfirmTextDropTable".GetFromResourece().Confirm())
                {
                    string cmdStr = string.Empty;
                    if ("ConfirmTextDropTableWithCascade".GetFromResourece().Confirm())
                    {
                        cmdStr = App.MainEngineer.CurrentCommandTextHandler.GetDropTableCmdStrWithCascade(X_CurItemArgs.TableName);
                    }
                    else
                    {
                        cmdStr = App.MainEngineer.CurrentCommandTextHandler.GetDropTableCmdStr(X_CurItemArgs.TableName);
                    }
                    X_CallNotifyEvent(cmdStr, true);
                }
            };
            ctMenu.Items.Add(itemDeleteTable);
            #endregion

            #region Modify Schema
            MenuItem itemModifySchema = new MenuItem();
            itemModifySchema.Header = "TitleModifyTableSchema".GetFromResourece();
            itemModifySchema.Click += delegate
            {
                //CreateTableDetailWindow ct = new CreateTableDetailWindow(CreateTableDetailWindow.EnteringType.ModifySchema,
                //X_CurItemArgs.TableName);
                //ct.ShowDialog();
                //X_CurItemArgs.TableName
                BaseTableSchema          schemaInfo = App.MainEngineer.GetTableSchemaInfoObject(X_CurItemArgs.TableName);
                CreateTableSchemaBaseWin win        = GetCreateTableSchemaWindow();
                win.CurSchemaInfo = schemaInfo;
                win.IsModifyMode  = true;
                //If Successful then refresh table list
                if ((bool)win.ShowDialog())
                {
                    if (RefreshAllNodeEvent != null)
                    {
                        RefreshAllNodeEvent(null, null);
                    }
                }
            };
            ctMenu.Items.Add(itemModifySchema);
            #endregion

            ctMenu.Items.Add(new Separator());

            #region GetAllColumnInfo
            MenuItem itemGetColumnsInfo = new MenuItem();
            itemGetColumnsInfo.Header = "TitleGetColumnInfo".GetFromResourece();
            itemGetColumnsInfo.Click += delegate
            {
                X_CallShowResultEvent(App.MainEngineer.GetColumnInfoFromTable(X_CurItemArgs.TableName));
            };
            ctMenu.Items.Add(itemGetColumnsInfo);
            #endregion

            #region GetAllIndexes
            MenuItem itemGetIndexesInfo = new MenuItem();
            itemGetIndexesInfo.Header = "TitleGetIndexesInfo".GetFromResourece();
            itemGetIndexesInfo.Click += delegate
            {
                X_CallShowResultEvent(App.MainEngineer.GetIndexInfoFromTable(X_CurItemArgs.TableName));
            };
            ctMenu.Items.Add(itemGetIndexesInfo);
            #endregion

            ctMenu.Items.Add(new Separator());

            #region GetSupportType
            MenuItem itemProviderInfo = new MenuItem();
            itemProviderInfo.Header = "TitleGetSupportedType".GetFromResourece();
            itemProviderInfo.Click += delegate
            {
                X_CallShowResultEvent(App.MainEngineer.GetProviderInfoFromTable(X_CurItemArgs.TableName));
            };
            ctMenu.Items.Add(itemProviderInfo);
            #endregion

            return(ctMenu);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Create Table
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void itemCreateTable_Click(object sender, RoutedEventArgs e)
        {
            SwitchToCreateTable st = new SwitchToCreateTable();

            st.ShowDialog();

            switch (st.CurCreateType)
            {
            case SwitchToCreateTable.CreateType.NotSelected:
                return;

            case SwitchToCreateTable.CreateType.Simple:
                st.Close();
                goto ReDo;

            case SwitchToCreateTable.CreateType.Normal:

                st.Close();
                CreateTableSchemaBaseWin win = GetCreateTableSchemaWindow();
                //If Successful then refresh table list
                if ((bool)win.ShowDialog())
                {
                    if (RefreshAllNodeEvent != null)
                    {
                        RefreshAllNodeEvent(null, null);
                    }
                }

                return;

            default:
                return;
            }



ReDo:
            string tableName = string.Empty;
            //using (PopupForm p = new PopupForm())
            //{
            //    p.X_NotifyStr = "Table name";
            //    if (p.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            //    {
            //        tableName = p.X_Result;
            //    }
            //    else
            //    {
            //        return;
            //    }
            //}

            InputValueWindows iv = new InputValueWindows("Table name");

            if (iv.ShowDialog() == true)
            {
                tableName = iv.X_GetInputedValue.ToString();
            }
            else
            {
                return;
            }

            if (tableName.Length > App.MainEngineer.MaxTableNameLength)
            {
                MessageBox.Show(String.Format("Table name length must large than {0} ", App.MainEngineer.MaxTableNameLength));

                goto ReDo;
            }
            if (string.IsNullOrEmpty(tableName))
            {
                "Please input the table name".Notify();
                goto ReDo;
            }

            string cmdStr = String.Format("Create table [{0}] (ID int , Comment nvarchar(255))", tableName);

            X_CallNotifyEvent(cmdStr, true);
        }
Exemplo n.º 7
0
        public virtual ContextMenu CreateMenuForColumn()
        {
            ContextMenu ctMenu = new ContextMenu();

            MenuItem itemDropColumn = new MenuItem();

            itemDropColumn.Header = "Drop Column";

            itemDropColumn.Click += delegate
            {
                if ("ConfirmTextDropColumn".GetFromResourece().Confirm())
                {
                    string cmdStr = App.MainEngineer.CurrentCommandTextHandler.GetDropColumnCmdStr(X_CurItemArgs.TableName, X_CurItemArgs.ColumnName);

                    X_CallNotifyEvent(cmdStr, true);
                }
            };

            ctMenu.Items.Add(itemDropColumn);

            MenuItem itemRenameColumn = new MenuItem();

            itemRenameColumn.Header = "Rename Column";
            itemRenameColumn.Click += delegate
            {
                string newColumnName = string.Empty;
                //using (PopupForm p = new PopupForm())
                //{
                //    p.X_NotifyStr = "New Column name";
                //    if (p.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                //    {
                //        newColumnName = p.X_Result;
                //    }
                //    else
                //    {
                //        return;
                //    }
                //}

                InputValueWindows iv = new InputValueWindows("New Column name");
                if (iv.ShowDialog() == true)
                {
                    newColumnName = iv.X_GetInputedValue.ToString();
                }
                else
                {
                    return;
                }

                string cmdStr = App.MainEngineer.CurrentCommandTextHandler.GetRenameColumnCmdStr(X_CurItemArgs.TableName, X_CurItemArgs.ColumnName, newColumnName);

                X_CallNotifyEvent(cmdStr, true);
            };

            ctMenu.Items.Add(itemRenameColumn);

            MenuItem itemModidyTypeColumn = new MenuItem();

            itemModidyTypeColumn.Header = "Modify Column";
            itemModidyTypeColumn.Click += delegate
            {
                string cmdStr = String.Format("ALTER TABLE [{0}]  ALTER COLUMN {1} [NewType] ",
                                              X_CurItemArgs.TableName, X_CurItemArgs.ColumnName);
                X_CallNotifyEvent(cmdStr, false);
            };
            ctMenu.Items.Add(itemModidyTypeColumn);

            MenuItem itemInsertColumn = new MenuItem();

            itemInsertColumn.Header = "Insert Column";
            itemInsertColumn.Click += delegate
            {
                string cmdStr = String.Format("ALTER TABLE [{0}] ADD COLUMN [ColumnName] [ColumnType]", X_CurItemArgs.TableName);

                X_CallNotifyEvent(cmdStr, false);
            };

            ctMenu.Items.Add(itemInsertColumn);

            ctMenu.Items.Add(new Separator());

            MenuItem itemCreateIndex = new MenuItem();

            itemCreateIndex.Header = "Create Index";
            itemCreateIndex.Click += delegate { itemCreateIndex_Click(); };
            ctMenu.Items.Add(itemCreateIndex);

            ctMenu.Items.Add(new Separator());
            MenuItem itemCopyColumnName = new MenuItem();

            itemCopyColumnName.Header = "Copy Column Name";
            itemCopyColumnName.Click += delegate
            {
                Clipboard.SetText(X_CurItemArgs.ColumnName);
            };
            ctMenu.Items.Add(itemCopyColumnName);


            return(ctMenu);
        }