241 lines
7.1 KiB
C#
241 lines
7.1 KiB
C#
// ========================================================================
|
|
// Copyright 2006 - Volian Enterprises, Inc. All rights reserved.
|
|
// Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE
|
|
// ------------------------------------------------------------------------
|
|
// $Workfile: $ $Revision: $
|
|
// $Author: $ $Date: $
|
|
//
|
|
// $History: $
|
|
// ========================================================================
|
|
|
|
using System;
|
|
using System.Data;
|
|
using System.Data.SqlClient;
|
|
using Csla;
|
|
using Csla.Data;
|
|
using System.Configuration;
|
|
using System.IO;
|
|
using System.Xml;
|
|
using System.Drawing;
|
|
using System.ComponentModel;
|
|
|
|
namespace VEPROMS.CSLA.Library
|
|
{
|
|
public partial interface IFormatOrFormatInfo
|
|
{
|
|
PlantFormat PlantFormat { get;}
|
|
IFormatOrFormatInfo MyIParent { get;}
|
|
string Data { get; }
|
|
string ToString();
|
|
string FullName { get; }
|
|
}
|
|
public partial class Format:IFormatOrFormatInfo
|
|
{
|
|
#region PlantFormat
|
|
[NonSerialized]
|
|
private PlantFormat _PlantFormat;
|
|
public PlantFormat PlantFormat
|
|
{ get { return (_PlantFormat != null ? _PlantFormat : _PlantFormat = new PlantFormat(this)); } }
|
|
#endregion
|
|
public IFormatOrFormatInfo MyIParent { get { return MyParent; } }
|
|
public override string ToString()
|
|
{
|
|
//return Name;
|
|
//return PlantFormat.FormatData.Name;
|
|
return FullName;
|
|
}
|
|
public string FullName
|
|
{
|
|
get
|
|
{
|
|
if (ParentID == 1) return Description + " (" + Name + ")";
|
|
return MyParent.Description + " - " + Description + " (" + Name + ")";
|
|
}
|
|
}
|
|
}
|
|
public partial class FormatInfo : IFormatOrFormatInfo
|
|
{
|
|
public static bool HasLatestChanges()
|
|
{
|
|
if (!HasTopMargin()) return false;
|
|
if (!HasWCN2_MacroB9()) return false;
|
|
if (!HasSeqTabFmtTabToken()) return false;
|
|
return true;
|
|
}
|
|
private static bool HasSeqTabFmtTabToken()
|
|
{
|
|
using (FormatInfo fi = FormatInfo.Get("WCN2"))
|
|
{
|
|
XmlDocument xd = new XmlDocument();
|
|
xd.LoadXml(fi.Data);
|
|
XmlNodeList xl = xd.SelectNodes("//FormatData/SectData/StepSectionData/SequentialTabFormat/SeqTabFmt/@TabToken");//"//DocStyle/Layout/@TopMargin");
|
|
if (xl.Count == 0)
|
|
{
|
|
System.Windows.Forms.MessageBox.Show("FormatData SeqTab/TabToken is missing", "Inconsistent Format Files", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
}
|
|
private static bool HasTopMargin()
|
|
{
|
|
using (FormatInfo fi = FormatInfo.Get("WCN2"))
|
|
{
|
|
XmlDocument xd = new XmlDocument();
|
|
xd.LoadXml(fi.Data);
|
|
XmlNodeList xl = xd.SelectNodes("//DocStyle/Layout/@TopMargin");
|
|
if (xl.Count == 0)
|
|
{
|
|
System.Windows.Forms.MessageBox.Show("DocStyle TopMargin is missing", "Inconsistent Format Files", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
}
|
|
private static bool HasWCN2_MacroB9()
|
|
{
|
|
using (FormatInfo fi = FormatInfo.Get("WCN2"))
|
|
{
|
|
XmlDocument xd = new XmlDocument();
|
|
xd.LoadXml(fi.GenMac);
|
|
XmlNodeList xl = xd.SelectNodes("//*[@id='B9']");
|
|
if (xl.Count == 0)
|
|
{
|
|
System.Windows.Forms.MessageBox.Show("B9 macro is missing in WCN2 GenMac","Inconsistent Format Files", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error );
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
}
|
|
public static FormatInfo Get(string name)
|
|
{
|
|
try
|
|
{
|
|
FormatInfo tmp = DataPortal.Fetch<FormatInfo>(new NameCriteria(name));
|
|
//AddToCache(tmp);
|
|
if (tmp.ErrorMessage == "No Record Found")
|
|
{
|
|
tmp.Dispose(); // Clean-up FormatInfo
|
|
tmp = null;
|
|
}
|
|
return tmp;
|
|
}
|
|
catch (Exception ex1)
|
|
{
|
|
Exception ex = ex1;
|
|
while (ex.InnerException != null)
|
|
ex = ex.InnerException;
|
|
if (ex.Message.StartsWith("Could not find stored procedure"))
|
|
{
|
|
int formatID = 0;
|
|
using (FormatInfoList fil = FormatInfoList.Get())
|
|
{
|
|
foreach (FormatInfo fi in fil)
|
|
{
|
|
if (fi.Name == name)
|
|
{
|
|
formatID = fi.FormatID;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
if (formatID != 0) return FormatInfo.Get(formatID);
|
|
throw new DbCslaException("Format not found " + name, ex);
|
|
}
|
|
else
|
|
throw new DbCslaException("Error on FormatInfo.Get By Name", ex);
|
|
}
|
|
}
|
|
protected class NameCriteria
|
|
{
|
|
private string _Name;
|
|
public string Name
|
|
{ get { return _Name; } }
|
|
public NameCriteria(string name)
|
|
{
|
|
_Name = name;
|
|
}
|
|
}
|
|
private void DataPortal_Fetch(NameCriteria criteria)
|
|
{
|
|
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] FormatInfo.DataPortal_Fetch", GetHashCode());
|
|
try
|
|
{
|
|
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
|
|
{
|
|
ApplicationContext.LocalContext["cn"] = cn;
|
|
using (SqlCommand cm = cn.CreateCommand())
|
|
{
|
|
cm.CommandType = CommandType.StoredProcedure;
|
|
cm.CommandText = "getFormatByName";
|
|
cm.Parameters.AddWithValue("@Name", criteria.Name);
|
|
using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader()))
|
|
{
|
|
if (!dr.Read())
|
|
{
|
|
_ErrorMessage = "No Record Found";
|
|
return;
|
|
}
|
|
ReadData(dr);
|
|
}
|
|
}
|
|
// removing of item only needed for local data portal
|
|
if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client)
|
|
ApplicationContext.LocalContext.Remove("cn");
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
if (_MyLog.IsErrorEnabled) _MyLog.Error("FormatInfo.DataPortal_Fetch", ex);
|
|
_ErrorMessage = ex.Message;
|
|
throw new DbCslaException("FormatInfo.DataPortal_Fetch", ex);
|
|
}
|
|
}
|
|
#region PlantFormat
|
|
[NonSerialized]
|
|
private PlantFormat _PlantFormat;
|
|
public PlantFormat PlantFormat
|
|
{ get { return (_PlantFormat != null ? _PlantFormat : _PlantFormat = new PlantFormat(this)); } }
|
|
#endregion
|
|
public IFormatOrFormatInfo MyIParent { get { return MyParent; } }
|
|
public override string ToString()
|
|
{
|
|
//return Name;
|
|
//return PlantFormat.FormatData.Name;
|
|
return FullName;
|
|
}
|
|
public string FullName
|
|
{
|
|
get
|
|
{
|
|
if (ParentID == 1) return Description + " (" + Name + ")";
|
|
return MyParent.Description + " - " + Description + " (" + Name + ")";
|
|
}
|
|
}
|
|
public StepSectionLayoutData MyStepSectionLayoutData
|
|
{
|
|
get { return PlantFormat.FormatData.SectData.StepSectionData.StepSectionLayoutData; }
|
|
}
|
|
public StepSectionPrintData MyStepSectionPrintData
|
|
{
|
|
get { return PlantFormat.FormatData.SectData.StepSectionData.StepSectionPrintData; }
|
|
}
|
|
}
|
|
public partial class FormatInfoList
|
|
{
|
|
private static Csla.SortedBindingList<FormatInfo> _SortedFormatInfoList;
|
|
public static Csla.SortedBindingList<FormatInfo> SortedFormatInfoList
|
|
{
|
|
get
|
|
{
|
|
if (_SortedFormatInfoList == null)
|
|
{
|
|
_SortedFormatInfoList = new SortedBindingList<FormatInfo>(FormatInfoList.Get());
|
|
_SortedFormatInfoList.ApplySort("FullName", ListSortDirection.Ascending);
|
|
}
|
|
return _SortedFormatInfoList;
|
|
}
|
|
}
|
|
}
|
|
}
|