예제 #1
0
        /// <summary>
        /// (RunStart事件)開始產生新的專案.
        /// </summary>
        /// <param name="automationObject">目前執行的 Visual Studio 的執行個體.</param>
        /// <param name="replacementsDictionary">專案的所有文字檔案內容</param>
        /// <param name="runKind">指定會定義範本精靈可建立之不同範本的常數</param>
        /// <param name="customParams"></param>
        public void RunStarted(object automationObject,
                               Dictionary <string, string> replacementsDictionary,
                               WizardRunKind runKind, object[] customParams)
        {
            try
            {
                inputORMForm = new frmORMappingWindow();
                DialogResult result = inputORMForm.ShowDialog();

                if (result == DialogResult.OK)
                {
                    settingForm = new frmSettings();
                    settingForm.ShowDialog();

                    defaultTable = frmSettings.SelectedTableName;

                    //Add table name from Screen.
                    replacementsDictionary.Add("$custommessage$", defaultTable);
                    //加入主要鍵值條件
                    replacementsDictionary.Add("$Key$", frmSettings.SelectedKey);
                    //取出剛才設為 Key 條件的 DataColumn 的 DataType.
                    DataColumn col     = frmSettings.SelectedTableColumns.Where(c => c.ColumnName == frmSettings.SelectedKey).FirstOrDefault();
                    string     keyType = GetGeneralDataType(col.DataType);
                    replacementsDictionary.Add("$KeyType$", keyType);
                    //寫入連線字串
                    replacementsDictionary.Add("$DataSource$", frmORMappingWindow.ConnectionInfo.DataSourceName);
                    replacementsDictionary.Add("$InitialCatalog$", frmORMappingWindow.ConnectionInfo.Initial_Catalog);
                    replacementsDictionary.Add("$UserID$", frmORMappingWindow.ConnectionInfo.UserId);
                    if (MessageBox.Show("是否要將資料庫連線密碼寫入在 web.config 中?", "Gelis 簡單 ORM 產生器. v0.7", MessageBoxButtons.OKCancel, MessageBoxIcon.Information) == DialogResult.OK)
                    {
                        replacementsDictionary.Add("$Password$", frmORMappingWindow.ConnectionInfo.Password);
                    }
                    else
                    {
                        replacementsDictionary.Add("$Password$", "");
                    }
                }
                else
                {
                    throw new WizardCancelledException("Is Cancel!!!.");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
            finally
            {
                frmORMappingWindow.ConnectionInfo.IsConnect = false;
                settingForm.Dispose();
                settingForm = null;
            }
        }
        /// <summary>
        /// (RunStart事件)開始產生新的專案.
        /// </summary>
        /// <param name="automationObject">目前執行的 Visual Studio 的執行個體.</param>
        /// <param name="replacementsDictionary">專案的所有文字檔案內容</param>
        /// <param name="runKind">指定會定義範本精靈可建立之不同範本的常數</param>
        /// <param name="customParams"></param>
        public void RunStarted(object automationObject,
            Dictionary<string, string> replacementsDictionary,
            WizardRunKind runKind, object[] customParams)
        {
            try
            {
                inputORMForm = new frmORMappingWindow();
                DialogResult result = inputORMForm.ShowDialog();

                if (result == DialogResult.OK)
                {
                    settingForm = new frmSettings();
                    settingForm.ShowDialog();

                    defaultTable = frmSettings.SelectedTableName;

                    //Add table name from Screen.
                    replacementsDictionary.Add("$custommessage$", defaultTable);
                    //加入主要鍵值條件
                    replacementsDictionary.Add("$Key$", frmSettings.SelectedKey);
                    //取出剛才設為 Key 條件的 DataColumn 的 DataType.
                    DataColumn col = frmSettings.SelectedTableColumns.Where(c => c.ColumnName == frmSettings.SelectedKey).FirstOrDefault();
                    string keyType = GetGeneralDataType(col.DataType);
                    replacementsDictionary.Add("$KeyType$", keyType);
                    //寫入連線字串
                    replacementsDictionary.Add("$DataSource$", frmORMappingWindow.ConnectionInfo.DataSourceName);
                    replacementsDictionary.Add("$InitialCatalog$", frmORMappingWindow.ConnectionInfo.Initial_Catalog);
                    replacementsDictionary.Add("$UserID$", frmORMappingWindow.ConnectionInfo.UserId);
                    if (MessageBox.Show("是否要將資料庫連線密碼寫入在 web.config 中?", "Gelis 簡單 ORM 產生器. v0.7", MessageBoxButtons.OKCancel, MessageBoxIcon.Information) == DialogResult.OK)
                    {
                        replacementsDictionary.Add("$Password$", frmORMappingWindow.ConnectionInfo.Password);
                    }
                    else
                    {
                        replacementsDictionary.Add("$Password$", "");
                    }
                }
                else
                    throw new WizardCancelledException("Is Cancel!!!.");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
            finally
            {
                frmORMappingWindow.ConnectionInfo.IsConnect = false;
                settingForm.Dispose();
                settingForm = null;
            }
        }