📄 splash.cs
字号:
using System;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
using System.Data.SqlServerCe;
namespace HardwareDistributor.UI
{
/// <summary>
/// UI form that loads config data, syncs database, and performs
/// other work before launching the Logon screen
/// </summary>
public partial class Splash : Form
{
private bool appLoaded;
public Splash()
{
InitializeComponent();
}
/// <summary>
/// Load Splash Screen
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Splash_Load(object sender, EventArgs e)
{
//Set this variable to false so that the Activated event
//will perform its work since this is the first time
//this screen has been activated
appLoaded = false;
}
/// <summary>
/// The Activated Event is used to kick off the execution of
/// Splash Screen code since it doesn't fire until after the
/// screen is drawn and visible.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Splash_Activated(object sender, EventArgs e)
{
//If this is the first time this form has been
//Activated, then execute the following code
if (appLoaded == false)
{
try
{
//Load Wait Cursor
Application.DoEvents();
Cursor.Current = Cursors.WaitCursor;
Application.DoEvents();
//Load device and application data
Business.Services.LoadDeviceData();
//Load configuration information from config file
Application.DoEvents();
statusBar1.Text = "Loading configuration data...";
Application.DoEvents();
Business.Services.LoadAppSettings();
//Check to see if Local Database Exists
Application.DoEvents();
statusBar1.Text = "Searching for local database...";
Application.DoEvents();
System.Threading.Thread.Sleep(500);
//If database doesn't exist
if (!Business.Services.DatabaseExists())
{
//Test to see if Network is available
Application.DoEvents();
statusBar1.Text = "Checking network connectivity...";
Application.DoEvents();
if (Business.Services.GetConnectionStatus())
{
//Test to see if Replication URL is reachable
Application.DoEvents();
statusBar1.Text = "Testing IIS server...";
Application.DoEvents();
if (Business.Services.CheckReplicationUrl())
{
//Synchronize and pull down new database
Application.DoEvents();
statusBar1.Text = "Synchronizing database...";
Application.DoEvents();
Business.Services.SyncWithDataSource();
}
else
{
//Replication URL isn't reachable
Application.DoEvents();
statusBar1.Text = "Replication server isn't available...";
Application.DoEvents();
System.Threading.Thread.Sleep(1000);
Application.DoEvents();
statusBar1.Text = "Shutting down...";
Application.DoEvents();
System.Threading.Thread.Sleep(1000);
Application.DoEvents();
this.Close();
return;
}
}
else
{
//Network isn't available
Application.DoEvents();
statusBar1.Text = "Network isn't available...";
Application.DoEvents();
System.Threading.Thread.Sleep(1000);
Application.DoEvents();
statusBar1.Text = "Shutting down...";
Application.DoEvents();
System.Threading.Thread.Sleep(1000);
Application.DoEvents();
this.Close();
return;
}
}
//Database exists so create connection and add to GlobalCache
Application.DoEvents();
statusBar1.Text = "Creating database connection...";
Application.DoEvents();
Business.Services.CacheDataSourceConnection();
//Load and cache Customers Collection
Business.GlobalCache.Instance.Customers = Business.Services.GetCustomers();
//Load Default Cursor
Application.DoEvents();
Cursor.Current = Cursors.Default;
Application.DoEvents();
//Set to true to prevent the Activate
//Event from executing code in the future
appLoaded = true;
//Database has been created so load the Logon Screen
Logon logon = new Logon();
logon.ShowDialog();
//When the user selects exit from the logon screen
//this splash screen and the rest of the app will close
this.Close();
}
catch (SqlCeException sqlEx)
{
Business.Services.LogErrors(sqlEx);
//This error means SQL Server can't be found
if (sqlEx.NativeError == 29061)
{
Application.DoEvents();
statusBar1.Text = "SQL Server unavailable...";
Application.DoEvents();
//Delete corrupt local database
if (Business.Services.DatabaseExists())
{
Business.Services.DeleteDatabase();
}
}
else
{
Application.DoEvents();
statusBar1.Text = "Database initialization error...";
Application.DoEvents();
}
System.Threading.Thread.Sleep(2000);
Application.DoEvents();
statusBar1.Text = "Shutting down...";
Application.DoEvents();
System.Threading.Thread.Sleep(2000);
Application.DoEvents();
this.Close();
}
catch (Exception ex)
{
Business.Services.LogErrors(ex);
Application.DoEvents();
statusBar1.Text = "Error initializing system";
Application.DoEvents();
System.Threading.Thread.Sleep(2000);
Application.DoEvents();
statusBar1.Text = "Shutting down...";
Application.DoEvents();
System.Threading.Thread.Sleep(2000);
Application.DoEvents();
this.Close();
}
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -