SourceCode/PROMS/VEPROMS User Interface/frmRODbProperties.cs
2012-10-19 16:10:46 +00:00

171 lines
5.5 KiB
C#

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using VEPROMS.CSLA.Library;
namespace VEPROMS
{
public partial class frmRODbProperties : Form
{
private Point _ParentLocation;
public Point ParentLocation
{
get { return _ParentLocation; }
set { _ParentLocation = value; }
}
private RODbInfo _roDbInfo;
private string _origROName;
private string _origFolderPath;
private DocVersion _docVersion;
public frmRODbProperties(DocVersion docVersion, RODbInfo roDbInfo)
{
_roDbInfo = roDbInfo;
_docVersion = docVersion;
InitializeComponent();
_origROName = (_roDbInfo == null) ? null : _roDbInfo.ROName;
_origFolderPath = (_roDbInfo == null) ? null : _roDbInfo.FolderPath;
}
private void ppBtnFldrDlg_Click(object sender, EventArgs e)
{
FolderBrowserDialog dlgROFolder = new FolderBrowserDialog();
if (dlgROFolder.ShowDialog() == DialogResult.OK)
{
ppTxtPath.Text = dlgROFolder.SelectedPath;
}
}
private void ppBtnOk_Click(object sender, EventArgs e)
{
// 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 (!Directory.Exists(ppTxtPath.Text))
{
MessageBox.Show(ppTxtPath.Text, "Invalid Directory for RO Database");
return;
}
if (!File.Exists(ppTxtPath.Text + @"\ro.fst"))
{
MessageBox.Show(ppTxtPath.Text, "Ro.Fst Doesn't Exist");
return;
}
RODb roDb = RODb.Get(_roDbInfo.RODbID);
if (_origROName != ppRTxtName.Text) roDb.ROName = ppRTxtName.Text;
if (_origFolderPath != ppTxtPath.Text)
{
// see if an rodb already exists with this pathname.
RODbInfoList roDbList = RODbInfoList.Get();
foreach (RODbInfo rdi in roDbList)
{
if (ppTxtPath.Text.ToUpper() == rdi.FolderPath.ToUpper())
{
// get the most recent rofst data for this rodb:
ROFstInfoList roFstList = ROFstInfoList.GetByRODbID(rdi.RODbID);
DateTime dts = new DateTime(1900, 1, 1);
int rofstinfoid = -1;
foreach (ROFstInfo rfi in roFstList)
{
if (rfi.DTS > dts)
{
dts = rfi.DTS;
rofstinfoid = rfi.ROFstID;
}
}
_docVersion.DocVersionAssociations[0].MyROFst = ROFst.Get(rofstinfoid);
_docVersion.Save().Dispose();
DialogResult = DialogResult.OK;
Close();
return;
}
}
roDb.FolderPath = ppTxtPath.Text;
}
try
{
roDb.Save().Dispose();
DialogResult = DialogResult.OK;
Close();
return;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
return;
}
}
// this is creating a new rodb. A new rofst record will be created as well & the association set
// check for unique name/path first
RODbInfoList allrodbinfo = RODbInfoList.Get();
foreach (RODbInfo rdi in allrodbinfo)
{
if (ppRTxtName.Text == rdi.ROName)
{
MessageBox.Show("Create unique Description.", "Description is not unique");
return;
}
if (ppTxtPath.Text.ToUpper() == rdi.FolderPath.ToUpper())
{
MessageBox.Show("Specify unique Folder Path or cancel and select an existing RO Database from drop-down.", "Folder Path is not unique" );
return;
}
}
if (ppRTxtName.Text == null || ppRTxtName.Text == "")
{
MessageBox.Show("You must enter a Description.");
return;
}
if (ppTxtPath.Text == null || ppTxtPath.Text == "")
{
MessageBox.Show("You must enter a Path.");
return;
}
// check for an ro.fst existing in the selected path. If it is valid, create an rodb, rofst
// and an association to its docversion.
string rofstPath = ppTxtPath.Text + @"\ro.fst";
if (!File.Exists(rofstPath))
{
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);
RODbInfo newrdi = RODbInfo.Get(newroDb.RODbID);
newroDb.Save().Dispose();
ROFst rofst = ROFstInfo.AddRoFst(newrdi, _docVersion);
DialogResult = DialogResult.OK;
Close();
}
private void frmRODbProperties_Load(object sender, EventArgs e)
{
Location = ParentLocation;
ppRTxtName.Text = (_roDbInfo == null) ? null : _roDbInfo.ROName;
ppTxtPath.Text = (_roDbInfo == null) ? null : _roDbInfo.FolderPath;
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
// the file system. Otherwise it is derived from the top node - and changed from folder
// properties on the top node. And lastly, it is the code default.
ppTxtExt.Text = cfg.GetDefaultGraphicExtension();
ppLblGraphicFileExtLoc.Text = (cfg == null) ? null : cfg.GetDefaultGraphicExtensionLocation();
if (_roDbInfo == null)
{
string newFolderPath = null;
FolderBrowserDialog dlgROFolder = new FolderBrowserDialog();
if (dlgROFolder.ShowDialog() == DialogResult.OK)
{
newFolderPath = dlgROFolder.SelectedPath;
}
ppTxtPath.Text = newFolderPath;
}
}
}
}