示例#1
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);
        }
示例#2
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);
        }