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

📄 formnorthwindce.cs

📁 用VS。NET基于wince
💻 CS
字号:
using System;
using System.Drawing;
using System.Collections;
using System.Windows.Forms;
using System.Data;
using System.Data.SqlServerCe;
using System.IO;
using System.Runtime.InteropServices;
using System.Reflection;
using System.ComponentModel;

namespace Microsoft.Sql.SqlCe.Samples.Cs.NorthwindCe {

    /// <summary>
    /// Summary description for FormNorthwindCe.
    /// </summary>
    public class FormNorthwindCe : System.Windows.Forms.Form {

        private System.ComponentModel.Container components = null;
        private System.Windows.Forms.MainMenu   mainMenuNorthwind;
        private System.Windows.Forms.MenuItem   menuItemFile;
        private System.Windows.Forms.MenuItem   menuItemFileExit;
        private System.Windows.Forms.MenuItem   menuItemNorthwind;
        private System.Windows.Forms.MenuItem   menuItemEmployees;
        private System.Windows.Forms.MenuItem   menuItemCustomers;
        private System.Windows.Forms.MenuItem   menuItemOrders;
        private System.Windows.Forms.MenuItem   menuItemSync;
        private System.Windows.Forms.MenuItem   menuItemSyncRepl;

        private ControlCustomers                controlCustomers = null;
        private ControlEmployees                controlEmployees = null;
        private	ControlReplication              controlReplication = null;
        private ControlOrders                   controlOrders = null;


        public FormNorthwindCe() 
        {
            InitializeComponent();
            InitializeMenu();
            // Uncomment the following lines if you want to include a copy of the sample database on your device.
            // You also need to change the build action of the NorthwindDemo.sdf file to "content".
            // This will bring down the database to the \Windows\Start Menu directory on your device.
            // The following code moves the NorthwindDemo.sdf file to your \My Documents directory on your device.
            //
			//            try {
			//                if (File.Exists(NorthwindData.GetInstance().LocalDatabaseFile)) {
			//                    File.Delete(NorthwindData.GetInstance().LocalDatabaseFile);
			//                }
			//                
			//                File.Move(@"\Windows\Start Menu\NorthwindDemo.sdf", NorthwindData.GetInstance().LocalDatabaseFile);
			//            }
			//            catch(Exception e) {
			//                // Error handling mechanism
			//                //
			//                MessageBox.Show(@"Moving NorthwindDemo.sdf file: " + e.Message, "Northwind");
			//            }
        }


        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        protected override void Dispose( bool disposing ) {
            if( disposing ) {
                if (components != null) {
                    components.Dispose();
                }
            }
            base.Dispose( disposing );
        }

		#region Windows Form Designer generated code
        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent() {
            // 
            // FormNorthwindCe
            // 
            this.ClientSize = new System.Drawing.Size(240, 298);
            this.ControlBox = false;
            this.Text = "NorthwindCe";
            this.Load += new System.EventHandler(this.FormNorthwindCe_Load);

        }

        private void InitializeMenu() {
            this.mainMenuNorthwind = new System.Windows.Forms.MainMenu();
            this.menuItemFile = new System.Windows.Forms.MenuItem();
            this.menuItemFileExit = new System.Windows.Forms.MenuItem();
            this.menuItemSync = new System.Windows.Forms.MenuItem();
            this.menuItemSyncRepl = new System.Windows.Forms.MenuItem();
            this.menuItemNorthwind = new System.Windows.Forms.MenuItem();
            this.menuItemEmployees = new System.Windows.Forms.MenuItem();
            this.menuItemCustomers = new System.Windows.Forms.MenuItem();
            this.menuItemOrders = new System.Windows.Forms.MenuItem();

            // 
            // mainMenuNorthwind
            // 
            this.mainMenuNorthwind.MenuItems.Add(this.menuItemFile);
            this.mainMenuNorthwind.MenuItems.Add(this.menuItemNorthwind);
            this.mainMenuNorthwind.MenuItems.Add(this.menuItemSync);
            // 
            // menuItemFile
            // 
            this.menuItemFile.MenuItems.Add(this.menuItemFileExit);
            this.menuItemFile.Text = "File";
            // 
            // menuItemFileExit
            // 
            this.menuItemFileExit.Text = "Exit";
            this.menuItemFileExit.Click += new System.EventHandler(this.menuItemFileExit_Click);
            // 
            // menuItemSync
            // 
            this.menuItemSync.MenuItems.Add(this.menuItemSyncRepl);
            this.menuItemSync.Text = "Sync";
            // 
            // menuItemFileExit
            // 
            this.menuItemSyncRepl.Text = "Replication";
            this.menuItemSyncRepl.Click += new System.EventHandler(this.menuItemSyncRepl_Click);
            // 
            // menuItemNorthwind
            // 
            this.menuItemNorthwind.MenuItems.Add(this.menuItemEmployees);
            this.menuItemNorthwind.MenuItems.Add(this.menuItemCustomers);
            this.menuItemNorthwind.MenuItems.Add(this.menuItemOrders);
            this.menuItemNorthwind.Text = "Northwind";
            // 
            // menuItemEmployees
            // 
            this.menuItemEmployees.Text = "Employees";
            this.menuItemEmployees.Click += new System.EventHandler(this.menuItemEmployees_Click);
            // 
            // menuItemCustomers
            // 
            this.menuItemCustomers.Text = "Customers";
            this.menuItemCustomers.Click += new System.EventHandler(this.menuItemCustomers_Click);
            // 
            // menuItemOrders
            // 
            this.menuItemOrders.Text = "Orders";
            this.menuItemOrders.Click += new System.EventHandler(this.menuItemOrders_Click);
            this.Menu = this.mainMenuNorthwind;
        }
		#endregion
	

        static void Main() {
            Application.Run(new FormNorthwindCe());
        }


        public void ActiveNorthwindEmployees() {
            if (null == controlEmployees) 
            {
                controlEmployees = new ControlEmployees();
                this.Controls.Add(this.controlEmployees);
                controlEmployees.Visible = false;
                controlEmployees.InitEmployees();
            }

            // Make the ControlEmployees control visible.
            //
            controlEmployees.BringToFront();
            controlEmployees.Visible = true;
        }


        public void ActiveNorthwindCustomers() {
            if (null == controlCustomers) {
                controlCustomers = new ControlCustomers();
                this.Controls.Add(this.controlCustomers);
                controlCustomers.Visible = false;
                controlCustomers.InitCustomers();
            }

            // Make the ControlCustomers control visible.
            //
            controlCustomers.BringToFront();
            controlCustomers.Visible = true;
			
        }


        public void ActiveNorthwindOrders() {
            if (null == controlOrders) {
                controlOrders = new ControlOrders();
                this.Controls.Add(this.controlOrders);
                controlOrders.Visible = false;
                controlOrders.InitOrders();
            }

            // Make the ControlOrders control visible.
            //
            controlOrders.BringToFront();
            controlOrders.Visible = true;
        }
	

        public void ActiveSyncReplication() {
            if (null == controlReplication) {
                controlReplication = new ControlReplication();
                controlReplication.FormNorthwind = this;
                this.Controls.Add(this.controlReplication);
                controlReplication.Visible = false;
                UpdateMenu();
            }
            // Make the ControlReplication control visible.
            //
            controlReplication.BringToFront();
            controlReplication.Visible = true;
        }


        // This function refreshes the various DataSets.
        //
        public override void Refresh() {
            if (null != controlOrders)
                controlOrders.InitOrders();
            if (null != controlCustomers)
                controlCustomers.InitCustomers();
            if (null != controlEmployees)
                controlEmployees.InitEmployees();
        }


        public void UpdateMenu() {
            if (null == controlReplication || controlReplication.Initialize) {
                this.menuItemNorthwind.Enabled = false;
                this.menuItemEmployees.Enabled = false;
                this.menuItemCustomers.Enabled = false;
                this.menuItemOrders.Enabled = false;
            }
            else {
                this.menuItemNorthwind.Enabled = true;
                this.menuItemEmployees.Enabled = true;
                this.menuItemCustomers.Enabled = true;
                this.menuItemOrders.Enabled = true;
            }
        }


        private void FormNorthwindCe_Load(object sender, System.EventArgs e) {
            ActiveSyncReplication();
        }


        private void menuItemSyncRepl_Click(object sender, System.EventArgs e) {
            ActiveSyncReplication();
        }


        private void menuItemEmployees_Click(object sender, System.EventArgs e) {
            ActiveNorthwindEmployees();
        }

        
        private void menuItemCustomers_Click(object sender, System.EventArgs e) {
            ActiveNorthwindCustomers();
        }


        private void menuItemOrders_Click(object sender, System.EventArgs e) {
            ActiveNorthwindOrders();
        }


        private void menuItemFileExit_Click(object sender, System.EventArgs e) {
            NorthwindData.GetInstance().Close();

            this.Close();
            Application.Exit();
        }
    }
}

⌨️ 快捷键说明

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