Added method RofstInfo.GetROImageByFilename to find image files by name.

Added method RoImageInforList GetByRODbIDFilename to find image files by name.
Find ROImages if not attached to the current ROFST.  The Export/Import code was not saving ROImage usages properly
This commit is contained in:
Rich 2015-02-18 14:43:00 +00:00
parent 8d46574ec2
commit 14a0b600fd
3 changed files with 93 additions and 2 deletions

View File

@ -881,7 +881,26 @@ namespace VEPROMS.CSLA.Library
throw new DbCslaException("ROFstInfo.DataPortal_Fetch", ex); throw new DbCslaException("ROFstInfo.DataPortal_Fetch", ex);
} }
} }
public ROImageInfo GetROImageByFilename(string filename)
{
ROImageInfoList images = ROImageInfoList.GetByRODbIDFilename(RODbID, filename);
if (images == null || images.Count == 0)
{
_MyLog.WarnFormat("\r\nReferenced Object Image {0} Missing\r\nNeed to Update RO Values",filename);
return null;
}
ROImageInfo retval = null;
foreach (ROImageInfo image in images)
{
if (image.DTS > DTS && retval != null) break;
retval = image;
}
if(retval.DTS > DTS)
_MyLog.WarnFormat("\r\nReferenced Object Image {0} newer {1} than RO.FST {2}\r\nNeed to Update RO Values",filename,retval.DTS.ToShortDateString(),DTS.ToShortDateString());
else
_MyLog.WarnFormat("Referenced Object Image {0} older {1} then RO.FST {2}\r\nNeed to Update RO Values",filename,retval.DTS.ToShortDateString(),DTS.ToShortDateString());
return retval;
}
} }
public class ROFstInfoROTableUpdateEventArgs public class ROFstInfoROTableUpdateEventArgs
{ {

View File

@ -443,5 +443,70 @@ namespace VEPROMS.CSLA.Library
} }
this.RaiseListChangedEvents = true; this.RaiseListChangedEvents = true;
} }
public static ROImageInfoList GetByRODbIDFilename(int rODbID,string filename)
{
try
{
ROImageInfoList tmp = DataPortal.Fetch<ROImageInfoList>(new RODbIDFilenameCriteria(rODbID,filename));
//ROImageInfo.AddList(tmp);
tmp.AddEvents();
return tmp;
}
catch (Exception ex)
{
throw new DbCslaException("Error on ROImageInfoList.GetByRODbIDFilename", ex);
}
}
private class RODbIDFilenameCriteria
{
public RODbIDFilenameCriteria(int rODbID,string filename)
{
_RODbID = rODbID;
_Filename = filename;
}
private int _RODbID;
public int RODbID
{
get { return _RODbID; }
set { _RODbID = value; }
}
private string _Filename;
public string Filename
{
get { return _Filename; }
set { _Filename = value; }
}
}
private void DataPortal_Fetch(RODbIDFilenameCriteria criteria)
{
this.RaiseListChangedEvents = false;
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ROImageInfoList.DataPortal_FetchRODbIDFilename", GetHashCode());
try
{
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
{
using (SqlCommand cm = cn.CreateCommand())
{
cm.CommandType = CommandType.StoredProcedure;
cm.CommandText = "getROImagesByRODbID_Filename";
cm.Parameters.AddWithValue("@RODbID", criteria.RODbID);
cm.Parameters.AddWithValue("@FileName", criteria.Filename);
cm.CommandTimeout = Database.DefaultTimeout;
using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader()))
{
IsReadOnly = false;
while (dr.Read()) this.Add(new ROImageInfo(dr));
IsReadOnly = true;
}
}
}
}
catch (Exception ex)
{
if (_MyLog.IsErrorEnabled) _MyLog.Error("ROImageInfoList.DataPortal_FetchRODbIDFilename", ex);
throw new DbCslaException("ROImageInfoList.DataPortal_FetchRODbIDFilename", ex);
}
this.RaiseListChangedEvents = true;
}
} }
} }

View File

@ -971,6 +971,7 @@ namespace Volian.Print.Library
DocVersionInfo dvi = proc.ActiveParent as DocVersionInfo; DocVersionInfo dvi = proc.ActiveParent as DocVersionInfo;
ROFstInfo rofst = dvi.DocVersionAssociations[0].MyROFst; ROFstInfo rofst = dvi.DocVersionAssociations[0].MyROFst;
ROImageInfo roImage = ROImageInfo.GetByROFstID_FileName(rofst.ROFstID, vals[0]); ROImageInfo roImage = ROImageInfo.GetByROFstID_FileName(rofst.ROFstID, vals[0]);
if (roImage == null) roImage = rofst.GetROImageByFilename(vals[0]);// need code to go and get an ROImaage if it exists
if (roImage != null) if (roImage != null)
{ {
ROImageConfig rc = new ROImageConfig(roImage); ROImageConfig rc = new ROImageConfig(roImage);
@ -2792,7 +2793,13 @@ namespace Volian.Print.Library
if (roImage != null) if (roImage != null)
ImageText = val; ImageText = val;
else else
{
roImage = rofst.GetROImageByFilename(vals[0]);// need code to go and get an ROImaage if it exists
if (roImage == null)
erMsg = string.Format("Image {0} does not exist.", vals[0]); erMsg = string.Format("Image {0} does not exist.", vals[0]);
else
ImageText = val;
}
} }
catch (Exception ex) catch (Exception ex)