Renamed the database selector form to "Login Form" and updated its UI. Moved database initialization to the login form. Made the exit file menu option on the main form functional.
This commit is contained in:
@@ -98,12 +98,10 @@
|
||||
<HintPath>..\packages\HtmlRenderer.WinForms.1.5.0.6\lib\net45\HtmlRenderer.WinForms.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="PresentationCore" />
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.ComponentModel.DataAnnotations" />
|
||||
<Reference Include="System.Configuration" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="System.Deployment" />
|
||||
<Reference Include="System.Drawing" />
|
||||
<Reference Include="System.Runtime.Serialization" />
|
||||
@@ -112,7 +110,6 @@
|
||||
<Reference Include="System.Web" />
|
||||
<Reference Include="System.Windows.Forms" />
|
||||
<Reference Include="System.Xml" />
|
||||
<Reference Include="WindowsBase" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="ActualSale.cs" />
|
||||
@@ -128,11 +125,11 @@
|
||||
<Compile Include="DebugDatabaseConverter.Designer.cs">
|
||||
<DependentUpon>DebugDatabaseConverter.cs</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="FrmDatabaseSelector.cs">
|
||||
<Compile Include="FrmLoginForm.cs">
|
||||
<SubType>Form</SubType>
|
||||
</Compile>
|
||||
<Compile Include="FrmDatabaseSelector.Designer.cs">
|
||||
<DependentUpon>FrmDatabaseSelector.cs</DependentUpon>
|
||||
<Compile Include="FrmLoginForm.Designer.cs">
|
||||
<DependentUpon>FrmLoginForm.cs</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="FrmManageAdItems.cs">
|
||||
<SubType>Form</SubType>
|
||||
@@ -199,8 +196,8 @@
|
||||
<EmbeddedResource Include="FrmAddRecord.resx">
|
||||
<DependentUpon>FrmAddRecord.cs</DependentUpon>
|
||||
</EmbeddedResource>
|
||||
<EmbeddedResource Include="FrmDatabaseSelector.resx">
|
||||
<DependentUpon>FrmDatabaseSelector.cs</DependentUpon>
|
||||
<EmbeddedResource Include="FrmLoginForm.resx">
|
||||
<DependentUpon>FrmLoginForm.cs</DependentUpon>
|
||||
</EmbeddedResource>
|
||||
<EmbeddedResource Include="FrmMain.resx">
|
||||
<DependentUpon>FrmMain.cs</DependentUpon>
|
||||
|
||||
@@ -25,6 +25,9 @@
|
||||
<setting name="ConnectionString" serializeAs="String">
|
||||
<value />
|
||||
</setting>
|
||||
<setting name="DefaultServer" serializeAs="String">
|
||||
<value>(LocalDb)\MSSQLLocalDB</value>
|
||||
</setting>
|
||||
</AdvertsingProfitControl.Properties.Settings>
|
||||
</userSettings>
|
||||
</configuration>
|
||||
-108
@@ -1,108 +0,0 @@
|
||||
namespace AdvertsingProfitControl
|
||||
{
|
||||
partial class FrmDatabaseSelector
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (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()
|
||||
{
|
||||
this.label1 = new System.Windows.Forms.Label();
|
||||
this.label2 = new System.Windows.Forms.Label();
|
||||
this.serverNameTextBox = new System.Windows.Forms.TextBox();
|
||||
this.label3 = new System.Windows.Forms.Label();
|
||||
this.button1 = new System.Windows.Forms.Button();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// label1
|
||||
//
|
||||
this.label1.AutoSize = true;
|
||||
this.label1.Location = new System.Drawing.Point(1, 9);
|
||||
this.label1.Name = "label1";
|
||||
this.label1.Size = new System.Drawing.Size(35, 13);
|
||||
this.label1.TabIndex = 0;
|
||||
this.label1.Text = "label1";
|
||||
//
|
||||
// label2
|
||||
//
|
||||
this.label2.AutoSize = true;
|
||||
this.label2.Location = new System.Drawing.Point(13, 166);
|
||||
this.label2.Name = "label2";
|
||||
this.label2.Size = new System.Drawing.Size(69, 13);
|
||||
this.label2.TabIndex = 1;
|
||||
this.label2.Text = "Server Name";
|
||||
//
|
||||
// serverNameTextBox
|
||||
//
|
||||
this.serverNameTextBox.Location = new System.Drawing.Point(88, 163);
|
||||
this.serverNameTextBox.Name = "serverNameTextBox";
|
||||
this.serverNameTextBox.Size = new System.Drawing.Size(180, 20);
|
||||
this.serverNameTextBox.TabIndex = 2;
|
||||
this.serverNameTextBox.Text = "(LocalDb)\\MSSQLLocalDB";
|
||||
//
|
||||
// label3
|
||||
//
|
||||
this.label3.AutoSize = true;
|
||||
this.label3.Location = new System.Drawing.Point(16, 194);
|
||||
this.label3.Name = "label3";
|
||||
this.label3.Size = new System.Drawing.Size(35, 13);
|
||||
this.label3.TabIndex = 3;
|
||||
this.label3.Text = "label3";
|
||||
//
|
||||
// button1
|
||||
//
|
||||
this.button1.Location = new System.Drawing.Point(354, 270);
|
||||
this.button1.Name = "button1";
|
||||
this.button1.Size = new System.Drawing.Size(105, 23);
|
||||
this.button1.TabIndex = 4;
|
||||
this.button1.Text = "button1";
|
||||
this.button1.UseVisualStyleBackColor = true;
|
||||
this.button1.Click += new System.EventHandler(this.button1_Click);
|
||||
//
|
||||
// FrmDatabaseSelector
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(486, 319);
|
||||
this.Controls.Add(this.button1);
|
||||
this.Controls.Add(this.label3);
|
||||
this.Controls.Add(this.serverNameTextBox);
|
||||
this.Controls.Add(this.label2);
|
||||
this.Controls.Add(this.label1);
|
||||
this.Name = "FrmDatabaseSelector";
|
||||
this.Text = "FrmDatabaseSelector";
|
||||
this.ResumeLayout(false);
|
||||
this.PerformLayout();
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private System.Windows.Forms.Label label1;
|
||||
private System.Windows.Forms.Label label2;
|
||||
private System.Windows.Forms.TextBox serverNameTextBox;
|
||||
private System.Windows.Forms.Label label3;
|
||||
private System.Windows.Forms.Button button1;
|
||||
}
|
||||
}
|
||||
@@ -1,37 +0,0 @@
|
||||
using System;
|
||||
using System.Data.SqlClient;
|
||||
using System.Windows.Forms;
|
||||
using AdvertsingProfitControl.Properties;
|
||||
|
||||
namespace AdvertsingProfitControl
|
||||
{
|
||||
public partial class FrmDatabaseSelector : Form
|
||||
{
|
||||
public bool _connectionSuccessful = false;
|
||||
|
||||
public FrmDatabaseSelector()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private void button1_Click(object sender, EventArgs e)
|
||||
{
|
||||
var connectionString = "Data Source=" + serverNameTextBox.Text + ";" + "Initial Catalog=AdvertisingProfitControl;Integrated Security=True;MultipleActiveResultSets=True;App=EntityFramework";
|
||||
try
|
||||
{
|
||||
//Test the connection string with a forced timeout of 2 seconds.
|
||||
using (var conn = new SqlConnection(connectionString + "Connection Timeout=2"))
|
||||
{
|
||||
conn.Open(); // throws if invalid
|
||||
}
|
||||
Settings.Default.ConnectionString = connectionString;
|
||||
_connectionSuccessful = true;
|
||||
this.Close();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
label1.Text = ex.Message;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,120 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
</root>
|
||||
+181
@@ -0,0 +1,181 @@
|
||||
namespace AdvertsingProfitControl
|
||||
{
|
||||
partial class FrmLoginForm
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (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()
|
||||
{
|
||||
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(FrmLoginForm));
|
||||
this.serverNameLable = new System.Windows.Forms.Label();
|
||||
this.authenticationTypeLabel = new System.Windows.Forms.Label();
|
||||
this.connectButton = new System.Windows.Forms.Button();
|
||||
this.authenticationTypeComboBox = new System.Windows.Forms.ComboBox();
|
||||
this.loginLabel = new System.Windows.Forms.Label();
|
||||
this.passwordLabel = new System.Windows.Forms.Label();
|
||||
this.loginTextBox = new System.Windows.Forms.TextBox();
|
||||
this.passwordTextBox = new System.Windows.Forms.TextBox();
|
||||
this.serverNameComboBox = new System.Windows.Forms.ComboBox();
|
||||
this.informationLabel = new System.Windows.Forms.Label();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// serverNameLable
|
||||
//
|
||||
this.serverNameLable.AutoSize = true;
|
||||
this.serverNameLable.Location = new System.Drawing.Point(15, 23);
|
||||
this.serverNameLable.Margin = new System.Windows.Forms.Padding(6, 0, 6, 0);
|
||||
this.serverNameLable.Name = "serverNameLable";
|
||||
this.serverNameLable.Size = new System.Drawing.Size(133, 25);
|
||||
this.serverNameLable.TabIndex = 1;
|
||||
this.serverNameLable.Text = "Server Name:";
|
||||
//
|
||||
// authenticationTypeLabel
|
||||
//
|
||||
this.authenticationTypeLabel.AutoSize = true;
|
||||
this.authenticationTypeLabel.Location = new System.Drawing.Point(6, 89);
|
||||
this.authenticationTypeLabel.Margin = new System.Windows.Forms.Padding(6, 0, 6, 0);
|
||||
this.authenticationTypeLabel.Name = "authenticationTypeLabel";
|
||||
this.authenticationTypeLabel.Size = new System.Drawing.Size(142, 25);
|
||||
this.authenticationTypeLabel.TabIndex = 3;
|
||||
this.authenticationTypeLabel.Text = "Authentication:";
|
||||
//
|
||||
// connectButton
|
||||
//
|
||||
this.connectButton.Location = new System.Drawing.Point(476, 267);
|
||||
this.connectButton.Margin = new System.Windows.Forms.Padding(6);
|
||||
this.connectButton.Name = "connectButton";
|
||||
this.connectButton.Size = new System.Drawing.Size(157, 42);
|
||||
this.connectButton.TabIndex = 5;
|
||||
this.connectButton.Text = "Connect";
|
||||
this.connectButton.UseVisualStyleBackColor = true;
|
||||
this.connectButton.Click += new System.EventHandler(this.AttemptConnection);
|
||||
//
|
||||
// authenticationTypeComboBox
|
||||
//
|
||||
this.authenticationTypeComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
|
||||
this.authenticationTypeComboBox.Enabled = false;
|
||||
this.authenticationTypeComboBox.FormattingEnabled = true;
|
||||
this.authenticationTypeComboBox.Items.AddRange(new object[] {
|
||||
"Windows Authentication",
|
||||
"SQL Server Authentication"});
|
||||
this.authenticationTypeComboBox.Location = new System.Drawing.Point(167, 89);
|
||||
this.authenticationTypeComboBox.MaxDropDownItems = 5;
|
||||
this.authenticationTypeComboBox.Name = "authenticationTypeComboBox";
|
||||
this.authenticationTypeComboBox.Size = new System.Drawing.Size(280, 32);
|
||||
this.authenticationTypeComboBox.TabIndex = 2;
|
||||
//
|
||||
// loginLabel
|
||||
//
|
||||
this.loginLabel.AutoSize = true;
|
||||
this.loginLabel.Location = new System.Drawing.Point(82, 155);
|
||||
this.loginLabel.Name = "loginLabel";
|
||||
this.loginLabel.Size = new System.Drawing.Size(66, 25);
|
||||
this.loginLabel.TabIndex = 6;
|
||||
this.loginLabel.Text = "Login:";
|
||||
//
|
||||
// passwordLabel
|
||||
//
|
||||
this.passwordLabel.AutoSize = true;
|
||||
this.passwordLabel.Location = new System.Drawing.Point(44, 221);
|
||||
this.passwordLabel.Name = "passwordLabel";
|
||||
this.passwordLabel.Size = new System.Drawing.Size(104, 25);
|
||||
this.passwordLabel.TabIndex = 7;
|
||||
this.passwordLabel.Text = "Password:";
|
||||
//
|
||||
// loginTextBox
|
||||
//
|
||||
this.loginTextBox.Enabled = false;
|
||||
this.loginTextBox.Location = new System.Drawing.Point(167, 155);
|
||||
this.loginTextBox.Name = "loginTextBox";
|
||||
this.loginTextBox.Size = new System.Drawing.Size(280, 29);
|
||||
this.loginTextBox.TabIndex = 3;
|
||||
//
|
||||
// passwordTextBox
|
||||
//
|
||||
this.passwordTextBox.Enabled = false;
|
||||
this.passwordTextBox.Location = new System.Drawing.Point(167, 218);
|
||||
this.passwordTextBox.Name = "passwordTextBox";
|
||||
this.passwordTextBox.PasswordChar = '*';
|
||||
this.passwordTextBox.RightToLeft = System.Windows.Forms.RightToLeft.No;
|
||||
this.passwordTextBox.Size = new System.Drawing.Size(280, 29);
|
||||
this.passwordTextBox.TabIndex = 4;
|
||||
//
|
||||
// serverNameComboBox
|
||||
//
|
||||
this.serverNameComboBox.FormattingEnabled = true;
|
||||
this.serverNameComboBox.Location = new System.Drawing.Point(167, 23);
|
||||
this.serverNameComboBox.Name = "serverNameComboBox";
|
||||
this.serverNameComboBox.Size = new System.Drawing.Size(452, 32);
|
||||
this.serverNameComboBox.TabIndex = 1;
|
||||
//
|
||||
// informationLabel
|
||||
//
|
||||
this.informationLabel.AutoSize = true;
|
||||
this.informationLabel.Location = new System.Drawing.Point(11, 267);
|
||||
this.informationLabel.Name = "informationLabel";
|
||||
this.informationLabel.Size = new System.Drawing.Size(0, 25);
|
||||
this.informationLabel.TabIndex = 11;
|
||||
//
|
||||
// FrmLoginForm
|
||||
//
|
||||
this.AcceptButton = this.connectButton;
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(11F, 24F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(648, 324);
|
||||
this.Controls.Add(this.informationLabel);
|
||||
this.Controls.Add(this.serverNameComboBox);
|
||||
this.Controls.Add(this.passwordTextBox);
|
||||
this.Controls.Add(this.loginTextBox);
|
||||
this.Controls.Add(this.passwordLabel);
|
||||
this.Controls.Add(this.loginLabel);
|
||||
this.Controls.Add(this.authenticationTypeComboBox);
|
||||
this.Controls.Add(this.connectButton);
|
||||
this.Controls.Add(this.authenticationTypeLabel);
|
||||
this.Controls.Add(this.serverNameLable);
|
||||
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.Fixed3D;
|
||||
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
|
||||
this.Margin = new System.Windows.Forms.Padding(6);
|
||||
this.MaximizeBox = false;
|
||||
this.Name = "FrmLoginForm";
|
||||
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
|
||||
this.Text = "Connect to Database";
|
||||
this.ResumeLayout(false);
|
||||
this.PerformLayout();
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
private System.Windows.Forms.Label serverNameLable;
|
||||
private System.Windows.Forms.Label authenticationTypeLabel;
|
||||
private System.Windows.Forms.Button connectButton;
|
||||
private System.Windows.Forms.ComboBox authenticationTypeComboBox;
|
||||
private System.Windows.Forms.Label loginLabel;
|
||||
private System.Windows.Forms.Label passwordLabel;
|
||||
private System.Windows.Forms.TextBox loginTextBox;
|
||||
private System.Windows.Forms.TextBox passwordTextBox;
|
||||
private System.Windows.Forms.ComboBox serverNameComboBox;
|
||||
private System.Windows.Forms.Label informationLabel;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
using System;
|
||||
using System.Data.SqlClient;
|
||||
using System.Windows.Forms;
|
||||
using Microsoft.Win32;
|
||||
|
||||
namespace AdvertsingProfitControl
|
||||
{
|
||||
public partial class FrmLoginForm : Form
|
||||
{
|
||||
public bool ConnectionSuccessful;
|
||||
|
||||
public FrmLoginForm()
|
||||
{
|
||||
InitializeComponent();
|
||||
var registryView = Environment.Is64BitOperatingSystem ? RegistryView.Registry64 : RegistryView.Registry32;
|
||||
using (var hklm = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, registryView))
|
||||
{
|
||||
var instanceKey = hklm.OpenSubKey(@"SOFTWARE\Microsoft\Microsoft SQL Server\Instance Names\SQL", false);
|
||||
if (instanceKey != null)
|
||||
{
|
||||
foreach (var instanceName in instanceKey.GetValueNames())
|
||||
{
|
||||
serverNameComboBox.Items.Add(Environment.MachineName + @"\" + instanceName);
|
||||
}
|
||||
}
|
||||
}
|
||||
//Set the default server
|
||||
serverNameComboBox.Text = Properties.Settings.Default.DefaultServer;
|
||||
authenticationTypeComboBox.SelectedIndex = 0;
|
||||
serverNameComboBox.TextChanged += ServerNameTextChanged;
|
||||
}
|
||||
|
||||
private void ServerNameTextChanged(object sender, EventArgs e)
|
||||
{
|
||||
//Disable the connect button if the combo box's text is empty.
|
||||
connectButton.Enabled = serverNameComboBox.Text.Length != 0;
|
||||
}
|
||||
|
||||
private void AttemptConnection(object sender, EventArgs e)
|
||||
{
|
||||
var connectionString = "Data Source=" + serverNameComboBox.Text + ";Initial Catalog=AdvertisingProfitControl;Integrated Security=True;MultipleActiveResultSets=True;App=EntityFramework";
|
||||
try
|
||||
{
|
||||
//Test the connection string with a forced timeout of 2 seconds.
|
||||
using (var conn = new SqlConnection("Data Source=" + serverNameComboBox.Text + ";Integrated Security=True;MultipleActiveResultSets=True;App=EntityFramework;Connection Timeout=2"))
|
||||
{
|
||||
conn.Open(); // throws if invalid
|
||||
conn.Close();
|
||||
}
|
||||
Properties.Settings.Default.ConnectionString = connectionString;
|
||||
//Set the default server name.
|
||||
if (Properties.Settings.Default.DefaultServer != serverNameComboBox.Text)
|
||||
{
|
||||
Properties.Settings.Default.DefaultServer = serverNameComboBox.Text;
|
||||
Properties.Settings.Default.Save();
|
||||
}
|
||||
ConnectionSuccessful = true;
|
||||
//Try to initialize the database.
|
||||
var db = new AdvertisingProfitControlModel();
|
||||
//Force the UI thread to draw the label's text so the user can see it.
|
||||
informationLabel.Text = @"Connection successful! Preparing main form...";
|
||||
informationLabel.Invalidate();
|
||||
informationLabel.Update();
|
||||
informationLabel.Refresh();
|
||||
db.Database.Initialize(false);
|
||||
db.Database.Connection.Close();
|
||||
Close();
|
||||
}
|
||||
catch (SqlException ex)
|
||||
{
|
||||
MessageBox.Show(ex.Message, @"Connection Failed", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
informationLabel.Text = @"Failed to connect to a database.";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
+2
-1
@@ -172,8 +172,9 @@
|
||||
// exitFileMainMenu
|
||||
//
|
||||
this.exitFileMainMenu.Name = "exitFileMainMenu";
|
||||
this.exitFileMainMenu.Size = new System.Drawing.Size(138, 34);
|
||||
this.exitFileMainMenu.Size = new System.Drawing.Size(240, 34);
|
||||
this.exitFileMainMenu.Text = "E&xit";
|
||||
this.exitFileMainMenu.Click += new System.EventHandler(this.ExitProgram);
|
||||
//
|
||||
// recordsToolStripMenuItem
|
||||
//
|
||||
|
||||
@@ -276,6 +276,12 @@ namespace AdvertsingProfitControl
|
||||
MessageBox.Show(@"The current database's version is " + version.VersionNumber + @".", @"Database Version Number", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
|
||||
}
|
||||
|
||||
private void ExitProgram(object sender, EventArgs e)
|
||||
{
|
||||
Close();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Print Handler Methods
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
using System.Data.Entity.Infrastructure;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
|
||||
@@ -19,18 +19,17 @@ namespace AdvertsingProfitControl
|
||||
//var errorConsoleThread = new Thread(console.Show);
|
||||
//errorConsoleThread.IsBackground = true;
|
||||
//errorConsoleThread.Start();
|
||||
var form = new FrmDatabaseSelector();
|
||||
var form = new FrmLoginForm();
|
||||
form.ShowDialog();
|
||||
if (form._connectionSuccessful)
|
||||
//Check to see if there was a successful connection, otherwise simply quite.
|
||||
if (!form.ConnectionSuccessful) return;
|
||||
if (args.Length == 1 && args[0] == "/debug")
|
||||
{
|
||||
if (args.Length == 1 && args[0] == "/debug")
|
||||
{
|
||||
Application.Run(new FrmMain(true));
|
||||
}
|
||||
else
|
||||
{
|
||||
Application.Run(new FrmMain(false));
|
||||
}
|
||||
Application.Run(new FrmMain(true));
|
||||
}
|
||||
else
|
||||
{
|
||||
Application.Run(new FrmMain(false));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+13
-1
@@ -12,7 +12,7 @@ namespace AdvertsingProfitControl.Properties {
|
||||
|
||||
|
||||
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
|
||||
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "15.0.1.0")]
|
||||
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "15.1.0.0")]
|
||||
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
|
||||
|
||||
private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
|
||||
@@ -34,5 +34,17 @@ namespace AdvertsingProfitControl.Properties {
|
||||
this["ConnectionString"] = value;
|
||||
}
|
||||
}
|
||||
|
||||
[global::System.Configuration.UserScopedSettingAttribute()]
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
|
||||
[global::System.Configuration.DefaultSettingValueAttribute("(LocalDb)\\MSSQLLocalDB")]
|
||||
public string DefaultServer {
|
||||
get {
|
||||
return ((string)(this["DefaultServer"]));
|
||||
}
|
||||
set {
|
||||
this["DefaultServer"] = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,5 +5,8 @@
|
||||
<Setting Name="ConnectionString" Type="System.String" Scope="User">
|
||||
<Value Profile="(Default)" />
|
||||
</Setting>
|
||||
<Setting Name="DefaultServer" Type="System.String" Scope="User">
|
||||
<Value Profile="(Default)">(LocalDb)\MSSQLLocalDB</Value>
|
||||
</Setting>
|
||||
</Settings>
|
||||
</SettingsFile>
|
||||
Reference in New Issue
Block a user