⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 wizardform.cs

📁 Souce Code and sample to transfer SQL Server database to SqlServer Compact edition database. C#, d
💻 CS
📖 第 1 页 / 共 3 页
字号:
//* Copyright (c) 2008, Scott "Johnny" Smith (www.JohnnyCantCode.com)
//* All rights reserved.
//*
//* Redistribution and use in source and binary forms, with or without
//* modification, are permitted provided that the following conditions are met:
//*     * Redistributions of source code must retain the above copyright
//*       notice, this list of conditions and the following disclaimer.
//*     * Redistributions in binary form must reproduce the above copyright
//*       notice, this list of conditions and the following disclaimer in the
//*       documentation and/or other materials provided with the distribution.
//*     * Neither the name of the <organization> nor the
//*       names of its contributors may be used to endorse or promote products
//*       derived from this software without specific prior written permission.
//*
//* THIS SOFTWARE IS PROVIDED BY Scott "Johnny" Smith ``AS IS'' AND ANY
//* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
//* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
//* DISCLAIMED. IN NO EVENT SHALL <copyright holder> BE LIABLE FOR ANY
//* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
//* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
//* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
//* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
//* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
//* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using GLT.SqlCopy.Controls;
using GLT.SqlCopy.Properties;
using System.IO;
using System.Diagnostics;
using Microsoft.SqlServer.Management.Smo;
using System.Reflection;
using System.Security.Policy;

namespace GLT.SqlCopy
{
    public partial class WizardForm : Form
    {
        public WizardForm()
        {
            InitializeComponent();
            _currentStep = overviewCtrl1;

            CheckSQLMobileAssemblyPaths();
            if (!SqlMobileVer31Good && !SqlMobileVer35Good)
            {
                //in this case we do not have a good path to the Compact Edition drivers
                Dialogs.SelectMobileAssembliesDialog dialog = new GLT.SqlCopy.Dialogs.SelectMobileAssembliesDialog();
                if (dialog.ShowDialog(this) == DialogResult.OK)
                {
                    if (dialog.Ver31Valid)
                        GLT.SqlCopy.Properties.Settings.Default.SQLMobile30 = dialog.Ver31Path;

                    if (dialog.Ver35Valid)
                        GLT.SqlCopy.Properties.Settings.Default.SQLMobile35 = dialog.Ver35Path;

                    GLT.SqlCopy.Properties.Settings.Default.Save();
                }
            }

            //Verify that we have at least one good Compact Edition Driver
            bool validDriver = false;
            CheckSQLMobileAssemblyPaths();
            if (SqlMobileVer31Good)
            {
                outputCtrl1.EnableVer31 = true;
                validDriver = true;
            }
            else
                outputCtrl1.EnableVer31 = false;

            if (SqlMobileVer35Good)
            {
                outputCtrl1.EnableVer35 = true;
                validDriver = true;
            }
            else
                outputCtrl1.EnableVer35 = false;

            if (!validDriver)
            {
                MessageBox.Show(this, "Unable to locate valid SQL Server Compact Edition assemblies.", "Assemblies not found!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                Environment.Exit(0);
                return;
            }

            UpdateWizard();
        }

        private void CheckSQLMobileAssemblyPaths()
        {
            string path30 = GLT.SqlCopy.Properties.Settings.Default.SQLMobile30;
            string path35 = GLT.SqlCopy.Properties.Settings.Default.SQLMobile35;

            if (File.Exists(path30))
            {
                FileVersionInfo ver = FileVersionInfo.GetVersionInfo(path30);
                if (ver.FileVersion.Substring(0,3) == "3.0")
                    SqlMobileVer31Good = true;
                else
                    SqlMobileVer31Good = false;
            }
            else
                SqlMobileVer31Good = false;

            if (File.Exists(path35))
            {
                FileVersionInfo ver = FileVersionInfo.GetVersionInfo(path35);
                if (ver.FileVersion.Substring(0,3) == "3.5")
                    SqlMobileVer35Good = true;
                else
                    SqlMobileVer35Good = false;
            }
            else
                SqlMobileVer35Good = false;

        }

        private bool SqlMobileVer31Good = false;
        private bool SqlMobileVer35Good = false;


        private Font _SelectStepFont = new System.Drawing.Font("Arial", 9.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
        private Font _NotSelectedStepFont = new System.Drawing.Font("Arial", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
        private UserControl _currentStep = null;

        private void UpdateWizard()
        {
            pnlContent.SuspendLayout();

            if (_currentStep.GetType() == typeof(OverviewCtrl))
            {
                btnBack.Enabled = false;
                btnNext.Enabled = true;
                btnNext.Text = "Next >";
                btnCancel.Enabled = true;
                SetStepLabel(lblOverview);
            }

            if (_currentStep.GetType() == typeof(SourceCtrl))
            {
                btnBack.Enabled = true;
                btnNext.Enabled = true;
                btnNext.Text = "Next >";
                btnCancel.Enabled = true;
                SetStepLabel(lblSource);
            }

            if (_currentStep.GetType() == typeof(TableCtrl))
            {
                btnBack.Enabled = true;
                btnNext.Enabled = true;
                btnNext.Text = "Next >";
                btnCancel.Enabled = true;
                SetStepLabel(lblTables);
            }

            if (_currentStep.GetType() == typeof(OutputCtrl))
            {
                btnBack.Enabled = true;
                btnNext.Enabled = true;
                btnNext.Text = "Next >";
                btnCancel.Enabled = true;
                SetStepLabel(lblOutput);
            }

            if (_currentStep.GetType() == typeof(OptionsCtrl))
            {
                btnBack.Enabled = true;
                btnNext.Enabled = true;
                btnNext.Text = "Next >";
                btnCancel.Enabled = true;
                SetStepLabel(lblOptions);
            }

            if (_currentStep.GetType() == typeof(SummaryCtrl))
            {
                btnBack.Enabled = true;
                btnNext.Enabled = true;
                btnNext.Text = "Finish";
                btnCancel.Enabled = true;
                SetStepLabel(lblSummary);
            }

            if (_currentStep.GetType() == typeof(FinishCtrl))
            {
                btnBack.Enabled = false;
                btnNext.Enabled = false;
                btnNext.Text = "Close";
                btnCancel.Enabled = false;
                btnHelp.Enabled = false;
                SetStepLabel(lblFinish);
            }

            _currentStep.BringToFront();

            _currentStep.Dock = DockStyle.Fill;
            pnlContent.ResumeLayout();

            if (_currentStep.GetType() == typeof(FinishCtrl))
            {
                DoCopy();
            }
        }

        private void SetStepLabel(Label lbl)
        {
            pnlLabels.SuspendLayout();
            foreach (Control ctrl in pnlLabels.Controls)
            {
                if (ctrl is Label)
                {
                    ctrl.BackColor = Color.Transparent;
                    ctrl.Font = _NotSelectedStepFont;
                    ctrl.ForeColor = Color.White;
                }
            }
            lbl.BackColor = this.BackColor;
            lbl.Font = _SelectStepFont;
            lbl.ForeColor = Color.Black;
            pnlLabels.ResumeLayout();
        }

        private void btnBack_Click(object sender, EventArgs e)
        {
            if (_currentStep.GetType() == typeof(SummaryCtrl))
            {
                _currentStep = optionsCtrl1;
            }
            else if (_currentStep.GetType() == typeof(OptionsCtrl))
            {
                _currentStep = outputCtrl1;
            }
            else if (_currentStep.GetType() == typeof(OutputCtrl))
            {
                _currentStep = tableCtrl1;
            }
            else if (_currentStep.GetType() == typeof(TableCtrl))
            {
                _currentStep = sourceCtrl1;
            }
            else if (_currentStep.GetType() == typeof(SourceCtrl))
            {
                _currentStep = overviewCtrl1;
            }

            UpdateWizard();
        }

        private void btnNext_Click(object sender, EventArgs e)
        {
            if (_currentStep.GetType() == typeof(OverviewCtrl))
            {
                _currentStep = sourceCtrl1;
            }
            else if (_currentStep.GetType() == typeof(SourceCtrl))
            {
                if (String.IsNullOrEmpty(sourceCtrl1.DatabaseName))
                {
                    MessageBox.Show(this, "Please select a database before you continue.", "Select database.", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                    return;
                }
                _currentStep = tableCtrl1;
                this.Cursor = Cursors.WaitCursor;
                tableCtrl1.ListTables(sourceCtrl1.SourceServer.Databases[sourceCtrl1.DatabaseName]);
                this.Cursor = Cursors.Default;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -