C2017-003: Support SQL Server for storing of Referenced Object data
This commit is contained in:
@@ -2,6 +2,7 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
using System.Data.SqlClient;
|
||||
using System.Drawing;
|
||||
using System.Text;
|
||||
using System.Windows.Forms;
|
||||
@@ -58,6 +59,7 @@ namespace VEPROMS
|
||||
private RODbInfo _roDbInfo;
|
||||
private string _origROName;
|
||||
private string _origFolderPath;
|
||||
private string _origSQLConnect = null;
|
||||
private DocVersion _docVersion;
|
||||
public frmRODbProperties(DocVersion docVersion, RODbInfo roDbInfo)
|
||||
{
|
||||
@@ -66,6 +68,7 @@ namespace VEPROMS
|
||||
InitializeComponent();
|
||||
_origROName = (_roDbInfo == null) ? null : _roDbInfo.ROName;
|
||||
_origFolderPath = (_roDbInfo == null) ? null : _roDbInfo.FolderPath;
|
||||
_origSQLConnect = (_roDbInfo == null) ? null : (_roDbInfo.DBConnectionString == null || _roDbInfo.DBConnectionString == "" || _roDbInfo.DBConnectionString == "cstring") ? null : _roDbInfo.DBConnectionString;
|
||||
// Disable the OK button when initialized. Enable it if the user makes changes
|
||||
ppBtnOk.Enabled = false;
|
||||
}
|
||||
@@ -86,7 +89,8 @@ namespace VEPROMS
|
||||
// check for modify. If the path to this rodb already exists, we've got to use that
|
||||
// as the assocation. if it's a new path, i.e. a modify of the rodb record, just save current data.
|
||||
// Then close & return.
|
||||
if (_origROName !=null && _origFolderPath !=null && (_origROName != ppRTxtName.Text || _origFolderPath != ppTxtPath.Text))
|
||||
if ((_origROName !=null && _origFolderPath !=null && (_origROName != ppRTxtName.Text || _origFolderPath != ppTxtPath.Text)) ||
|
||||
(_origSQLConnect != ppTxtSQL.Text || _origSQLConnect != ppTxtSQL.Text))
|
||||
{
|
||||
if (!Directory.Exists(ppTxtPath.Text))
|
||||
{
|
||||
@@ -100,6 +104,12 @@ namespace VEPROMS
|
||||
}
|
||||
RODb roDb = RODb.GetJustRoDb(_roDbInfo.RODbID);
|
||||
if (_origROName != ppRTxtName.Text) roDb.ROName = ppRTxtName.Text;
|
||||
if (!(_origSQLConnect == "cstring" && (ppTxtSQL.Text == null || ppTxtSQL.Text == "")) && _origSQLConnect != ppTxtSQL.Text)
|
||||
{
|
||||
// C2017-003: ro in sql. 'cstring' in connection string represents using MS Access database
|
||||
// if connect string is null, set connect string to "cstring" otherwise, use what user typed in:
|
||||
roDb.DBConnectionString = (ppTxtSQL.Text == null || ppTxtSQL.Text == "") ? "cstring" : ppTxtSQL.Text;
|
||||
}
|
||||
if (_origFolderPath != ppTxtPath.Text)
|
||||
{
|
||||
// see if an rodb already exists with this pathname.
|
||||
@@ -184,7 +194,8 @@ namespace VEPROMS
|
||||
MessageBox.Show("No existing ro.fst in path " + ppTxtPath.Text + ". Check for invalid path");
|
||||
return;
|
||||
}
|
||||
RODb newroDb = RODb.MakeRODb(ppRTxtName.Text, ppTxtPath.Text, "cstring", null);
|
||||
string connectstr = ppTxtSQL.Text != null && ppTxtSQL.Text != "" ? ppTxtExt.Text : "cstring";
|
||||
RODb newroDb = RODb.MakeRODb(ppRTxtName.Text, ppTxtPath.Text, connectstr, null);
|
||||
RODbInfo newrdi = RODbInfo.Get(newroDb.RODbID);
|
||||
newroDb.Save().Dispose();
|
||||
ROFst rofst = ROFstInfo.AddRoFst(newrdi, _docVersion, DoProgressBarRefresh);
|
||||
@@ -196,6 +207,7 @@ namespace VEPROMS
|
||||
Location = ParentLocation;
|
||||
ppRTxtName.Text = (_roDbInfo == null) ? null : _roDbInfo.ROName;
|
||||
ppTxtPath.Text = (_roDbInfo == null) ? null : _roDbInfo.FolderPath;
|
||||
ppTxtSQL.Text = (_roDbInfo == null) ? null : (_roDbInfo.DBConnectionString == "cstring") ? null : _roDbInfo.DBConnectionString;
|
||||
RODbConfig cfg = (_roDbInfo == null) ? new RODbConfig() : new RODbConfig(_roDbInfo);
|
||||
// Note that the Graphic Extension data is shown in a non-editable text box here because
|
||||
// the data is either retrieved from the roapp.ini - and if there can only be editted from
|
||||
@@ -235,5 +247,38 @@ namespace VEPROMS
|
||||
//The OK button should only be enabled if the path has changed
|
||||
ppBtnOk.Enabled = _origFolderPath != ppTxtPath.Text;
|
||||
}
|
||||
private void ppTxtSQL_TextChanged(object sender, EventArgs e)
|
||||
{
|
||||
//The OK button should only be enabled if the path has changed
|
||||
ppBtnOk.Enabled = _origSQLConnect != ppTxtSQL.Text;
|
||||
}
|
||||
// C2017-003: test that the sql string entered can connect to the database:
|
||||
private void ppBtnTestSQL_Click(object sender, EventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
using (SqlConnection connection = new SqlConnection(ppTxtSQL.Text))
|
||||
{
|
||||
try
|
||||
{
|
||||
connection.Open();
|
||||
if (connection.State == ConnectionState.Open)
|
||||
{
|
||||
MessageBox.Show("You have been successfully connected to the database!");
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Connection failed.");
|
||||
}
|
||||
}
|
||||
catch (SqlException) { }
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show("Connection failed: " + ex);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user