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

📄 ibuyspydata.cs

📁 采用vc#.net和sqlce实现智能手机端和服务器数据交换
💻 CS
📖 第 1 页 / 共 4 页
字号:
using System;
using System.Data;
using System.Data.SqlServerCe;
using System.Windows.Forms;
using System.IO;
using System.Runtime.InteropServices;
using System.Text;


namespace Microsoft.Sql.SqlCe.Samples.Cs.IBuySpyDelivery.IBuySpyDevice
{
    internal enum SyncType {Replication, Rda};

    internal enum SyncStatus {InitSync, ReinitSync, RegularSync};

    internal enum OrderStatus {Failed = 0, Delivered = 1, Pending = 2};

    /// <summary>
	/// Summary description for the IBuySpyData class. This class controls all data access for 
	/// the application.
    /// </summary>
    internal class IBuySpyData
    {
        /// Static memeber to hold the Singleton object.
        ///
        static IBuySpyData dataIBuySpy          = null;

        /// Connection to local database.
        ///
        private SqlCeConnection  cnIBuySpy      = null;

        /// SqlCeDataAdpaters to load Customers, Orders, OrderDetails, Categories and Inventory data.
        ///
        private SqlCeDataAdapter daCustomers    = null;
        private SqlCeDataAdapter daOrders       = null;
        private SqlCeDataAdapter daOrderDetails = null;
        private SqlCeDataAdapter daCategories   = null;
        private SqlCeDataAdapter daInventory    = null;

        /// DataSet to hold Customers, Orders and OrderDetails data.
        ///
        private DataSet dsCustomerOrders        = null;

        /// DataSet to hold Categories and Inventory data.
        ///
        private DataSet dsInventory             = null;

        /// Configuration properties.
        ///
        private string   serverName;
        private int      driverID;
        private SyncType syncMethod;

        private readonly string dbDriverIDs;

        /// Database and local connection strings.
        ///
        private readonly string programPath;
        private readonly string localDatabaseFile;
        private readonly string localConnString;

        /// Remote connection string.
        ///
        private string remoteConnString;

        /// Internet properties.
        ///
        private string internetUrl;
        private readonly string internetLogin;
        private readonly string internetPassword;

        /// Publisher properties.
        ///
        private readonly string publisherDatabase;
        private readonly string publication;
        private readonly SecurityType publisherSecurityMode;
        private readonly string publisherLogin;
        private readonly string publisherPassword;
			
        /// Subscriber properties.
        ///
        private string subscriber;

        /// Flag to indicate whether the inventory has beed changed.
        ///
        private bool inventoryChanged = false;

        private IBuySpyData()
        {
            /// Sets the directory in which all the application files (database, images, and executable)
            /// are located.
            ///
            this.programPath             = @"\Program Files\IBuySpyDeviceC#";

            /// Sets local database file name.
            ///
            this.localDatabaseFile       = programPath + @"\IBuySpyStore.sdf";

            /// Construct the local connecting strings.
            ///
            this.localConnString         = @"Data Source=" + localDatabaseFile;

            /// Local driver id database.
            ///
            this.dbDriverIDs             = "DriverIDs.sdf";

            /// The URL to the Sql Server CE Server Agent running on the server.
            ///
            this.internetUrl             = @"http://<IIS Server>/ssce/sqlcesa30.dll";

            /// The IIS username is blank.
            ///
            this.internetLogin           = String.Empty;

            /// The IIS password is blank.
            ///
            this.internetPassword        = String.Empty;

            /// The Publisher database name.
            ///
            this.publisherDatabase       = "Store";

            /// The publication name.
            ///
            this.publication             = "StoreSample";

            /// NT Authentication is used.
            ///
            this.publisherSecurityMode   = SecurityType.NTAuthentication;

            /// The Publisher username is blank.
            ///
            this.publisherLogin          = String.Empty;

            /// The Publisher password is blank.
            ///
            this.publisherPassword       = String.Empty;

            /// The Subscriber name. Each driver device has its own Subscriber name using the format Driver#<DriverID>.
            ///
            this.subscriber              = @"Driver#1";

            /// The name of the server running both IIS and SQL Server.
            ///
            this.serverName              = @"<Your Server>";

            /// The default DriverID value is set to -1 to indicate that no DriverID has been specified.
            ///
            this.driverID                = -1;

            /// The default synchronization method is replication.
            ///
            this.syncMethod              = SyncType.Replication;

            /// Create SQL Server CE connection object.
            ///
            this.cnIBuySpy = new SqlCeConnection(this.localConnString);
            if (null == this.cnIBuySpy)
            {
                throw(new Exception("Unable to create SqlCeConnection object."));
            }
        }

        ~IBuySpyData()
        {
        }

        /// Class properties.
        ///
        internal SqlCeConnection IBuySpyConnection
        {
            get
            {
                return cnIBuySpy;
            }
        }

        internal DataSet CustomerOrderDataSet
        {
            get
            {
                return dsCustomerOrders;
            }
        }

        internal DataSet InventoryDataSet
        {
            get
            {
                return dsInventory;
            }
        }

        internal string ServerName
        {
            get
            {
                return serverName;
            }
            set
            {
                serverName = value;
            }
        }

        internal int DriverID
        {
            get
            {
                return driverID;
            }
            set
            {
                driverID = value;
            }
        }

        internal SyncType SyncMethod
        {
            get
            {
                return syncMethod;
            }
            set
            {
                syncMethod = value;
            }
        }

        internal string ProgramPath
        {
            get
            {
                return programPath;
            }
        }

        internal string LocalDatabaseFile
        {
            get
            {
                return localDatabaseFile;
            }
        }

        internal string LocalConnectionString
        {
            get
            {
                return localConnString;
            }
        }

        internal string RemoteConnectionString
        {
            get
            {
                return remoteConnString;
            }
        }

        internal string InternetUrl
        {
            get
            {
                return internetUrl;
            }
        }

        internal string InternetLogin
        {
            get
            {
                return internetLogin;
            }
        }

        internal string InternetPassword
        {
            get
            {
                return internetPassword;
            }
        }

        internal string Publisher
        {
            get
            {
                return serverName;
            }
        }

        internal string PublisherDatabase
        {
            get
            {
                return publisherDatabase;
            }
        }

        internal string Publication
        {
            get
            {
                return publication;
            }
        }

        internal SecurityType PublisherSecurityMode
        {
            get
            {
                return publisherSecurityMode;
            }
        }

        internal string PublisherLogin
        {
            get
            {
                return publisherLogin;
            }
        }

        internal string PublisherPassword
        {
            get
            {
                return publisherPassword;
            }
        }

        internal string Subscriber
        {
            get
            {
                return subscriber;
            }
        }

        internal bool InventoryChanged
        {
            get
            {
                return inventoryChanged;
            }
            set
            {
                inventoryChanged = value;
            }
        }

        /// The method returns the singleton object.
        ///
        internal static IBuySpyData GetInstance()
        {
            if (null == dataIBuySpy)
            {
                dataIBuySpy = new IBuySpyData();
            }

            return dataIBuySpy;
        }

        /// This method accesses the server database through RDA to retreive the DriverID values.
        ///
        internal DataTable LoadDriverIDs()
        {
            SqlCeConnection   cnDriverIDs = null;
            SqlCeDataAdapter  daDriverIDs = null;
            DataTable         dtDriverIDs = null;

            string            connStringDirverIDs;

            connStringDirverIDs = this.programPath + @"\" + this.dbDriverIDs;

            /// Sets the internet URL based on the server name.
            ///
            this.internetUrl = String.Format(@"http://{0}/StoreCSVS/ssce/sqlcesa30.dll", this.serverName);

            /// Construct the remote connecting strings from the application properties (ServerName and publisher database).
            ///
            this.remoteConnString = String.Format(@"Provider=sqloledb; Data Source={0}; Initial Catalog={1}; Integrated Security=SSPI",
                this.serverName,
                this.publisherDatabase);

            /// Create the Local SQL Server CE Database.
            ///
            if (File.Exists(connStringDirverIDs))
            {
                File.Delete(connStringDirverIDs);
            }

            SqlCeEngine en = new SqlCeEngine(@"Data Source=" + connStringDirverIDs);
            en.CreateDatabase();

⌨️ 快捷键说明

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