422 lines
12 KiB
C#

/*********************************************************************************************
* Copyright 2004 - Volian Enterprises, Inc. All rights reserved.
* Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE
* ------------------------------------------------------------------------------
* $Workfile: DataPath.cs $ $Revision: 5 $
* $Author: Jsj $ $Date: 3/06/07 1:26p $
*
* $History: DataPath.cs $
*
* ***************** Version 5 *****************
* User: Jsj Date: 3/06/07 Time: 1:26p
* Updated in $/LibSource/VEObject
* check for a null Location.
*
* ***************** Version 4 *****************
* User: Kathy Date: 1/24/05 Time: 2:45p
* Updated in $/LibSource/VEObject
* B2005-004 fixes
*
* ***************** Version 3 *****************
* User: Kathy Date: 1/19/05 Time: 11:59a
* Updated in $/LibSource/VEObject
* Fix B2005-003 - missing plant security setting
*
* ***************** Version 2 *****************
* User: Kathy Date: 1/14/05 Time: 10:38a
* Updated in $/LibSource/VEObject
* B2004-061: fix security options
*
* ***************** Version 1 *****************
* User: Kathy Date: 7/27/04 Time: 8:53a
* Created in $/LibSource/VEObject
*********************************************************************************************/
using System;
using System.Windows.Forms;
using System.Collections;
using System.Xml;
using System.IO;
using System.ComponentModel;
using Utils;
namespace VEObject
{
/// <summary>
/// This defines the DataPath class, which handles the datapath information
/// which tells the program where to search for veproms data. A datapath is of
/// the form "[path],[title];" for example G:\,GDRIVE;
/// Its children are vedata directories as found in the menuwin.xml file.
/// These vedata directories represent plant data.
/// </summary>
public class VEO_DataPath : VEO_Base
{
protected string tmpTitle;
protected string tmpLocation;
protected bool changeLocation;
protected bool changeTitle;
private string PrevDirectory;
public VEO_DataPath(UserRunTime iusrRunTime, string ititle, string iloc)
{
iconStates = new int[5] {6,21,8,22,7};
_Title = ititle;
_Location = iloc;
usrRunTime = iusrRunTime;
changeTitle=false;
changeLocation=false;
isNew=false;
LoadLockInfo();
icon = iconStates[(int)Lock.LockStatus];
}
// the following properties are used in the properties dialog for modification
// of 'property' data.
[Description("Location"),Category("Data Path"),ReadOnly(true)]public string Location
{
get{return _Location;}
set
{
ShortName sname = new ShortName(value);
_Location=sname.ShortFileName;
sname = null;
}
}
[Description("Title"),Category("Data Path")]public string Title
{
get
{
if (!changeTitle)
return _Title;
else
return tmpTitle;
}
set
{
changeTitle=true;
tmpTitle=value;
}
}
public override void Restore()
{
changeTitle = false;
}
// Make a new child, which is a plant node.
public override Object MakeNewChild()
{
VEO_Plant pl = new VEO_PlantN(usrRunTime,null,null);
return (Object) pl;
}
// 'Open' positions in the datapath directory (for creation of plant
// directories (store the previous directory, to position out of this
// directory on end).
public override bool Open()
{
if (Directory.Exists(_Location) == false) return false;
isOpen = true;
PrevDirectory = Directory.GetCurrentDirectory();
if(_Location!=null)Directory.SetCurrentDirectory(_Location);
return true;
}
// Close clears any multi-user settings for the system level
public override bool Close()
{
if (!isOpen)return false;
isOpen = false;
Directory.SetCurrentDirectory(PrevDirectory);
return true;
}
// Save the new plant & add to children if it succeeds.
public override bool SaveChild(Object obj)
{
VEO_Plant plnt = (VEO_Plant)obj;
bool succeed = plnt.SaveNew(this._Location);
if (succeed == true)
{
plnt._Location = this._Location + plnt._Location;
plnt.parentObj = this;
}
return succeed;
}
public override bool Delete()
{
// concatenate title/loc so that it can be removed from the datapath string
string delpth = _Location + "," + _Title + ";";
bool success = usrRunTime.DeletePathFromCfg(delpth);
return success;
}
// for this data path, read in which plants are available, and add to
// the list.
public override bool Read(bool dummy)
{
ArrayList tmpChildren = new ArrayList();
// using the . do exist tests to see if they exist on this datapath.
XmlDocument xmldoc = usrRunTime.menuwinXML.GetXmlDoc();
XmlElement top = (XmlElement) xmldoc.FirstChild;
XmlElement sys = (XmlElement) top.SelectSingleNode("SystemAttach");
XmlElement ele = (XmlElement) sys.SelectSingleNode("Plant");
while (ele != null)
{
// get plants and test for existence with the location for
// this datapath. If exists, add it to the PlantList.
//get the TemplateName & if there is a {t} replace the {t}
// with this datapath's path.
XmlElement tn = (XmlElement) ele.SelectSingleNode("TemplateName");
if (tn != null)
{
string templatename = tn.InnerText;
if (templatename.IndexOf("{t}",0) != -1)
{
string tpath = templatename.Replace("{t}",this.Location);
string path = tpath.Substring(0,tpath.IndexOf(" menu"));
DirectoryInfo source = new DirectoryInfo(path.Replace("/","//"));
if (source.Exists)
{
XmlElement etitle = (XmlElement) ele.SelectSingleNode("MenuName");
VEO_Plant plnt = new VEO_Plant(usrRunTime, etitle.InnerText,path);
plnt.parentObj = this;
tmpChildren.Add(plnt);
}
}
}
ele = (XmlElement) ele.NextSibling;
}
Security lsec = usrRunTime.sec;
if (lsec.OpenFile()==true)
{
for(int i=0;i<tmpChildren.Count;i++)
{
VEO_Plant plnt = (VEO_Plant) tmpChildren[i];
lsec.AddPlant(i,plnt._Location);
// Check if the plant is included in the vesam file. If not,
// it may have been added since vesam was run. In this case,
// the BlockAccess flag is used to determine whether the user
// should have access to the plant.
bool hasSec = lsec.PlantHasSecurity(i);
// see if the plant has any plant options, if so, include
// it in the list. If not, check to see if any of its procedures
// have options set & if so, the plant should be included.
//
bool procopts=false;
if (hasSec)
{
plnt.accessFlags = lsec.GetPlantSecurity(i);
if (plnt.accessFlags==0L)
{
procopts = lsec.AnyOptionsSet(i);
}
}
// if security is okay, i.e. either the plant has options or at least
// one of the sets within it has some options, include the plant in the
// list. Also, if there is not security, but access is not blocked
// (!BlockAccess) add it.
if ((hasSec && (plnt.accessFlags!=0L||procopts)) || (!hasSec&&!lsec.BlockAccess()))
Children.Add(plnt);
}
lsec.CloseFile();
}
return true;
}
// write out to the user's cfg file.
public override bool Write()
{
string newtitle=null;
string oldmodstr=_Location + "," + _Title + ";";
if (changeTitle)
newtitle = tmpTitle;
else
newtitle = _Title;
string newmodstr = _Location + "," + newtitle + ";";
usrRunTime.ModTitleToCfg(oldmodstr,newmodstr);
if (changeTitle) _Title=newtitle;
changeTitle=false;
return true;
}
public override void DoListView(ListView veoListView)
{
ListViewItem item=null;
veoListView.Columns.Add("Location", 120, HorizontalAlignment.Left);
veoListView.Columns.Add("Title", 300, HorizontalAlignment.Left);
for (int i=0; i<Children.Count; i++)
{
VEO_Plant plnt = (VEO_Plant) Children[i];
item = new ListViewItem(plnt._Location,plnt.icon);
item.Tag = plnt;
item.SubItems.Add(plnt._Title);
veoListView.Items.Add(item);
}
}
public override bool mnuAllowNew()
{
if (amILockedByMe()==false) return false; // new (plant) requires sys lock
if(usrRunTime.sec.SystemAdminFlag) return true;
return false;
}
public override bool CollapseSibling()
{
if (!usrRunTime.InMultiUserMode) return false;
return true;
}
}
// the following class inherits from the VEO_DataPath and is used to handle
// a New data path (it has the Location property as editable).
class VEO_DataPathN : VEO_DataPath
{
public VEO_DataPathN(UserRunTime iusrRunTime, string ititle, string iloc)
: base(iusrRunTime, ititle, iloc)
{
isNew=true;
}
// this method is used so that if a new datapath is created, it is associated
// with editable properties (such as path). When the object exists this is
// not editable. So when a new object is created, if it's successful, it's
// copied to an object which is not editable for the treeview & any further
// operations.
public override Object Copy()
{
VEO_DataPath dp = new VEO_DataPath(usrRunTime,this._Title,this._Location);
dp.parentObj=this.parentObj;
return (Object) dp;
}
public void SaveFields()
{
// B2007-005
// Check to see if tmpLocation is null before checking for a substring.
if (tmpLocation != null && tmpLocation.Substring(tmpLocation.Length-1,1) != "\\")
_Location = tmpLocation+"\\";
else
_Location=tmpLocation;
_Title=tmpTitle;
changeLocation=false;
changeTitle=false;
}
[Description("Location"),Category("Data Path"),ReadOnly(false),EditorAttribute(typeof(VEFolderBrowserDlg), typeof(System.Drawing.Design.UITypeEditor))]public new string Location
{
get
{
if (!changeLocation)
return _Location;
else
return tmpLocation;
}
set
{
ShortName sname = new ShortName(value);
tmpLocation=sname.ShortFileName;
sname = null;
changeLocation=true;
}
}
}
public class VEFolderBrowserDlg : System.Drawing.Design.UITypeEditor
{
public override System.Drawing.Design.UITypeEditorEditStyle GetEditStyle(System.ComponentModel.ITypeDescriptorContext context)
{
return System.Drawing.Design.UITypeEditorEditStyle.Modal;
}
public override object EditValue(
System.ComponentModel.ITypeDescriptorContext context,
System.IServiceProvider provider, object value)
{
FolderBrowserDialog FldrDlg = new FolderBrowserDialog();
FldrDlg.ShowNewFolderButton = true;
FldrDlg.SelectedPath = Directory.GetCurrentDirectory();
if(FldrDlg.ShowDialog() == DialogResult.OK)
return FldrDlg.SelectedPath;
else
return null;
}
public override bool GetPaintValueSupported(
System.ComponentModel.ITypeDescriptorContext context)
{
return false;
}
}
public class VESymbDlg : System.Drawing.Design.UITypeEditor
{
public override System.Drawing.Design.UITypeEditorEditStyle GetEditStyle(System.ComponentModel.ITypeDescriptorContext context)
{
return System.Drawing.Design.UITypeEditorEditStyle.Modal;
}
public override object EditValue(
System.ComponentModel.ITypeDescriptorContext context,
System.IServiceProvider provider, object value)
{
System.Windows.Forms.GridItem grdentr = (GridItem) provider;
SymbolListSteps symblst = new SymbolListSteps();
SymbDlg symdlg = new SymbDlg(symblst,grdentr);
if(symdlg.ShowDialog() == DialogResult.OK)
{
return symdlg.ReturnText;
}
else
return value;
}
public override bool GetPaintValueSupported(
System.ComponentModel.ITypeDescriptorContext context)
{
return false;
}
}
public class VECreateFolderBrowserDlg : System.Drawing.Design.UITypeEditor
{
public override System.Drawing.Design.UITypeEditorEditStyle GetEditStyle(System.ComponentModel.ITypeDescriptorContext context)
{
return System.Drawing.Design.UITypeEditorEditStyle.Modal;
}
public override object EditValue(
System.ComponentModel.ITypeDescriptorContext context,
System.IServiceProvider provider, object value)
{
FolderBrowserDialog FldrDlg = new FolderBrowserDialog();
FldrDlg.SelectedPath = Directory.GetCurrentDirectory();
FldrDlg.ShowNewFolderButton = true;
if(FldrDlg.ShowDialog() == DialogResult.OK)
return FldrDlg.SelectedPath;
else
return null;
}
public override bool GetPaintValueSupported(
System.ComponentModel.ITypeDescriptorContext context)
{
return false;
}
}
}