📄 controlreplication.cs
字号:
using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Windows.Forms;
using System.Data.SqlServerCe;
using System.IO;
namespace Microsoft.Sql.SqlCe.Samples.Cs.NorthwindCe {
/// <summary>
/// Summary description for ControlReplication.
/// </summary>
public class ControlReplication : System.Windows.Forms.Control {
private System.Windows.Forms.Label labelAuth;
private System.Windows.Forms.Label labelSqlServer;
private System.Windows.Forms.Label labelUserID;
private System.Windows.Forms.Label labelPassword;
private System.Windows.Forms.Label labelInternetUrl;
private System.Windows.Forms.Label labelInternetLogin;
private System.Windows.Forms.Label labelInternetPwd;
private System.Windows.Forms.Label labelSubscriber;
private System.Windows.Forms.TextBox textBoxPublisher;
private System.Windows.Forms.TextBox textBoxUserID;
private System.Windows.Forms.TextBox textBoxPassword;
private System.Windows.Forms.TextBox textBoxInternetUrl;
private System.Windows.Forms.TextBox textBoxInternetLogin;
private System.Windows.Forms.TextBox textBoxInternetPwd;
private System.Windows.Forms.TextBox textBoxSubscriber;
private System.Windows.Forms.RadioButton radioButtonSQLAuth;
private System.Windows.Forms.RadioButton radioButtonWinAuth;
private System.Windows.Forms.Button buttonSync;
private System.Windows.Forms.Panel panelProps;
private System.Windows.Forms.Button buttonReset;
private NorthwindData dataNorthwind = null;
private readonly string publisherDatabase;
private readonly string publication;
private bool init = true;
private FormNorthwindCe formNorthwind = null;
public ControlReplication() {
// Initialize database info
//
publisherDatabase = @"NWind_SqlCe";
publication = "SqlCeReplDemoNet";
// Get northwind data object
//
dataNorthwind = NorthwindData.GetInstance();
if (null == dataNorthwind) {
MessageBox.Show("Unable to get northwind data object", "Northwind");
return;
}
// Starts the cursor icon since this function may take some time.
//
System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.WaitCursor;
//
// Required for Windows Form Designer support
//
InitializeComponent();
InitReplSync();
System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.Default;
}
public bool Initialize {
get {
return init;
}
}
public FormNorthwindCe FormNorthwind {
set {
formNorthwind = value;
}
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
base.Dispose( disposing );
}
#region Component 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() {
this.Size = new System.Drawing.Size(246, 302);
this.labelAuth = new System.Windows.Forms.Label();
this.labelSqlServer = new System.Windows.Forms.Label();
this.labelUserID = new System.Windows.Forms.Label();
this.labelPassword = new System.Windows.Forms.Label();
this.labelInternetUrl = new System.Windows.Forms.Label();
this.labelInternetLogin = new System.Windows.Forms.Label();
this.labelInternetPwd = new System.Windows.Forms.Label();
this.labelSubscriber = new System.Windows.Forms.Label();
this.textBoxPublisher = new System.Windows.Forms.TextBox();
this.textBoxUserID = new System.Windows.Forms.TextBox();
this.textBoxPassword = new System.Windows.Forms.TextBox();
this.textBoxInternetUrl = new System.Windows.Forms.TextBox();
this.textBoxInternetLogin = new System.Windows.Forms.TextBox();
this.textBoxInternetPwd = new System.Windows.Forms.TextBox();
this.textBoxSubscriber = new System.Windows.Forms.TextBox();
this.radioButtonSQLAuth = new System.Windows.Forms.RadioButton();
this.radioButtonWinAuth = new System.Windows.Forms.RadioButton();
this.buttonSync = new System.Windows.Forms.Button();
this.panelProps = new System.Windows.Forms.Panel();
this.buttonReset = new System.Windows.Forms.Button();
//
// labelAuth
//
this.labelAuth.Font = new System.Drawing.Font("Microsoft Sans Serif", 7.8F, System.Drawing.FontStyle.Bold);
this.labelAuth.Location = new System.Drawing.Point(-8, 8);
this.labelAuth.Size = new System.Drawing.Size(96, 16);
this.labelAuth.Text = "Authentication:";
this.labelAuth.TextAlign = System.Drawing.ContentAlignment.TopRight;
//
// labelSqlServer
//
this.labelSqlServer.Font = new System.Drawing.Font("Microsoft Sans Serif", 7.8F, System.Drawing.FontStyle.Bold);
this.labelSqlServer.Location = new System.Drawing.Point(8, 29);
this.labelSqlServer.Size = new System.Drawing.Size(80, 16);
this.labelSqlServer.Text = "Publisher:";
this.labelSqlServer.TextAlign = System.Drawing.ContentAlignment.TopRight;
//
// labelUserID
//
this.labelUserID.Font = new System.Drawing.Font("Microsoft Sans Serif", 7.8F, System.Drawing.FontStyle.Bold);
this.labelUserID.Location = new System.Drawing.Point(8, 53);
this.labelUserID.Size = new System.Drawing.Size(80, 16);
this.labelUserID.Text = "User ID:";
this.labelUserID.TextAlign = System.Drawing.ContentAlignment.TopRight;
//
// labelPassword
//
this.labelPassword.Font = new System.Drawing.Font("Microsoft Sans Serif", 7.8F, System.Drawing.FontStyle.Bold);
this.labelPassword.Location = new System.Drawing.Point(16, 77);
this.labelPassword.Size = new System.Drawing.Size(72, 16);
this.labelPassword.Text = "Password:";
this.labelPassword.TextAlign = System.Drawing.ContentAlignment.TopRight;
//
// labelInternetUrl
//
this.labelInternetUrl.Font = new System.Drawing.Font("Microsoft Sans Serif", 7.8F, System.Drawing.FontStyle.Bold);
this.labelInternetUrl.Location = new System.Drawing.Point(8, 101);
this.labelInternetUrl.Size = new System.Drawing.Size(80, 16);
this.labelInternetUrl.Text = "Internet URL:";
this.labelInternetUrl.TextAlign = System.Drawing.ContentAlignment.TopRight;
//
// labelInternetLogin
//
this.labelInternetLogin.Font = new System.Drawing.Font("Microsoft Sans Serif", 7.8F, System.Drawing.FontStyle.Bold);
this.labelInternetLogin.Location = new System.Drawing.Point(8, 125);
this.labelInternetLogin.Size = new System.Drawing.Size(80, 16);
this.labelInternetLogin.Text = "Internet Login:";
this.labelInternetLogin.TextAlign = System.Drawing.ContentAlignment.TopRight;
//
// labelInternetPwd
//
this.labelInternetPwd.Font = new System.Drawing.Font("Microsoft Sans Serif", 7.8F, System.Drawing.FontStyle.Bold);
this.labelInternetPwd.Location = new System.Drawing.Point(8, 149);
this.labelInternetPwd.Size = new System.Drawing.Size(80, 16);
this.labelInternetPwd.Text = "Internet Pwd:";
this.labelInternetPwd.TextAlign = System.Drawing.ContentAlignment.TopRight;
//
// labelSubscriber
//
this.labelSubscriber.Font = new System.Drawing.Font("Microsoft Sans Serif", 7.8F, System.Drawing.FontStyle.Bold);
this.labelSubscriber.Location = new System.Drawing.Point(8, 173);
this.labelSubscriber.Size = new System.Drawing.Size(80, 16);
this.labelSubscriber.Text = "Subscriber:";
this.labelSubscriber.TextAlign = System.Drawing.ContentAlignment.TopRight;
//
// textBoxPublisher
//
this.textBoxPublisher.Location = new System.Drawing.Point(8, 26);
this.textBoxPublisher.Size = new System.Drawing.Size(136, 20);
this.textBoxPublisher.Text = "";
//
// textBoxUserID
//
this.textBoxUserID.Location = new System.Drawing.Point(8, 51);
this.textBoxUserID.Size = new System.Drawing.Size(136, 20);
this.textBoxUserID.Text = "sa";
//
// textBoxPassword
//
this.textBoxPassword.PasswordChar = '*';
this.textBoxPassword.Location = new System.Drawing.Point(8, 75);
this.textBoxPassword.Size = new System.Drawing.Size(136, 20);
this.textBoxPassword.Text = "";
//
// textBoxInternetUrl
//
this.textBoxInternetUrl.Location = new System.Drawing.Point(8, 99);
this.textBoxInternetUrl.Size = new System.Drawing.Size(136, 20);
this.textBoxInternetUrl.Text = "";
//
// textBoxInternetLogin
//
this.textBoxInternetLogin.Location = new System.Drawing.Point(8, 123);
this.textBoxInternetLogin.Size = new System.Drawing.Size(136, 20);
this.textBoxInternetLogin.Text = "";
//
// textBoxInternetPwd
//
this.textBoxInternetPwd.PasswordChar = '*';
this.textBoxInternetPwd.Location = new System.Drawing.Point(8, 147);
this.textBoxInternetPwd.Size = new System.Drawing.Size(136, 20);
this.textBoxInternetPwd.Text = "";
//
// textBoxSubscriber
//
this.textBoxSubscriber.Location = new System.Drawing.Point(8, 171);
this.textBoxSubscriber.Size = new System.Drawing.Size(136, 20);
this.textBoxSubscriber.Text = "SQLCESub#1";
//
// radioButtonSQLAuth
//
this.radioButtonSQLAuth.Checked = true;
this.radioButtonSQLAuth.Location = new System.Drawing.Point(8, 8);
this.radioButtonSQLAuth.Size = new System.Drawing.Size(56, 16);
this.radioButtonSQLAuth.Text = "SQL";
this.radioButtonSQLAuth.CheckedChanged += new System.EventHandler(this.radioButtonSQLAuth_CheckedChanged);
//
// radioButtonWinAuth
//
this.radioButtonWinAuth.Location = new System.Drawing.Point(64, 8);
this.radioButtonWinAuth.Size = new System.Drawing.Size(80, 16);
this.radioButtonWinAuth.Text = "Windows";
//
// buttonSync
//
this.buttonSync.Location = new System.Drawing.Point(120, 200);
this.buttonSync.Size = new System.Drawing.Size(112, 24);
this.buttonSync.Text = "Synchronize";
this.buttonSync.Click += new System.EventHandler(this.buttonSync_Click);
//
// panelProps
//
this.panelProps.Controls.Add(this.radioButtonWinAuth);
this.panelProps.Controls.Add(this.radioButtonSQLAuth);
this.panelProps.Controls.Add(this.textBoxSubscriber);
this.panelProps.Controls.Add(this.textBoxInternetPwd);
this.panelProps.Controls.Add(this.textBoxInternetLogin);
this.panelProps.Controls.Add(this.textBoxInternetUrl);
this.panelProps.Controls.Add(this.textBoxPassword);
this.panelProps.Controls.Add(this.textBoxUserID);
this.panelProps.Controls.Add(this.textBoxPublisher);
this.panelProps.Location = new System.Drawing.Point(88, 0);
this.panelProps.Size = new System.Drawing.Size(152, 200);
//
// buttonReset
//
this.buttonReset.Location = new System.Drawing.Point(8, 200);
this.buttonReset.Size = new System.Drawing.Size(104, 24);
this.buttonReset.Text = "Reset";
this.buttonReset.Click += new System.EventHandler(this.buttonReset_Click);
//
// FormRepl
//
this.ClientSize = new System.Drawing.Size(242, 264);
this.Controls.Add(this.buttonReset);
this.Controls.Add(this.buttonSync);
this.Controls.Add(this.labelSubscriber);
this.Controls.Add(this.labelInternetPwd);
this.Controls.Add(this.labelInternetLogin);
this.Controls.Add(this.labelInternetUrl);
this.Controls.Add(this.labelPassword);
this.Controls.Add(this.labelUserID);
this.Controls.Add(this.labelSqlServer);
this.Controls.Add(this.labelAuth);
this.Controls.Add(this.panelProps);
this.Text = "Replication";
}
#endregion
// This function initializes the Replication settings.
//
internal void InitReplSync() {
init = true;
try {
// This will execute only if the database exists.
//
if (File.Exists(dataNorthwind.LocalDatabaseFile)) {
// Open connection to the Northwind database.
//
if (ConnectionState.Closed == dataNorthwind.NorthwindConnection.State) {
dataNorthwind.NorthwindConnection.Open();
}
// Load the connection information.
//
LoadAppProps();
init = false;
}
}
catch(SqlCeException e) {
// Error handling mechanism
//
NorthwindData.ShowErrors(e);
}
catch {
}
// If we're unable to load the connection information from "ApplicationProperties" table,
// then use the following default setting, enable the controls, and set the sync button text to "Initialize".
// Otherwise, disable the connection info controls and set the sync button text to "Synchronize".
//
if (init) {
this.textBoxInternetUrl.Text = @"http://<IIS Server>/<virtual directory>/sscesa20.dll";
this.textBoxInternetLogin.Text = String.Empty;
this.textBoxInternetPwd.Text = String.Empty;
this.textBoxPublisher.Text = @"<Database Server>";
this.textBoxUserID.Text = @"sa";
this.textBoxPassword.Text = @"";
this.radioButtonSQLAuth.Checked = true;
this.textBoxSubscriber.Text = @"SQLCESub#1";
this.panelProps.Enabled = true;
buttonSync.Text = "Initialize";
}
else {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -