Photos Image Control Version 2

Thursday, 24 April 2008 16:31 by Frimbob

Earlier I created a custom User control , to fill a gab in the blog framework I am currently using. This user control read a assigned directory for subdirectories containing image files (JPG). This control would print category out onto the one screen.

While this was useful for a small number of images it obviously is not sufficient for future use. I learnt a lot about user controls then and applied this new knowledge in creating version 2

new controls ouput
Figure 1 Example of Version 2

Version 2 needed another layer,as you can see in the above image. Each folder is a category and I decided that I would not support subcategories of categories, this meant that I only required an extra menu.

Other Requirements

  • An option would be needed to set the number of Images per row.
  • CSS defaults would be Necessary as well as an option to turn them off
  • CSS Classes would need to be defined if defaults where turn off
  • Use the existing thumbnail httphandler.
  • Cross browser CSS consistency (lacking from version 1)
  • Written in C# (Version one was in VB)
  • Turn off the initial Category view off and just print every photo found.
  • Use the light box extension included with the blog framework
File Download Here

PhotoGallery.zip (6.27 kb)

Instructions

This control was developed for BlogEngine.NET  however it should work on any ASP.net 2.0 page this control also uses a httpHandler to create image thumbnails also included in the download. Currently only supports JPG file extensions.

Unzip the files to the "Your_blog_root"/User controls/..  folder.

The control can be implemented using BlogEngine user-control injection feature.

  1. Create a new page or post open end mode on a new line type [ ]
  2. type the following between the two brackets[]- usercontrol: ~/User controls/Photo2.ascx; PhotoDirectory=~/Photos/; NumberPerRow=3; NumberCatPerRow=2; ShowCategories=True;
  3. Ensure that no html is present between the [] tags.
  4. Each proeprty should end in';'.

There are 2 views both are shown below, the view on the left Will be referred to as the ' Category View'. The screen shot on the right will be referred to as the 'Item View' .

imageblog_240408 blogimage2_240408 

Supported Properties

  1. PhotoDirectory : path in string to the root folder where the images are stored default is "~/Photos/"
  2. NumberPerRow: Number of Images per row in the Item View e.g 5.
  3. NumberCatPerRow: Number of Images per row in the Category View e.g 2.
  4. ShowCategories: Bool (True/False) , Turn on or off Category View.
  5. CSSDefaults: Use the built in CSS Defaults.
  6. CatCellPadding: Category View cell padding, cant be set by css class.
  7. CatCellSpacing: Category View cell Spacing, cant be set by css class.
  8. ItemCellPadding: Item View cell padding, cant be set by css class.
  9. ItemCellSpacing: Item View cell Spacing, cant be set by css class. 

CSS Classes

CatagoryView

  • PhotosTable - Table element;
  • photoCatagoryLabel - Label Element inside the cell
  • photoCatagoryLabelImage - image element inside the cell
  • PhotosTableRow   - Row Element inside each row.

Item View

  • ItemTableLabel -Label at the top of the Item View
  • ItemTable - Table element
  • Itemhyp - hyperlink which the image is a child of
  • ItemCellImage - cell image.
  • ItemNewbtn - return to previous view button

Code Critique

This section is for other developer and potential employers 'wink wink'. Below I will present the code I created for this control and attempt to justify its existence. this will following in a class breakdown, then my method.

Why use this control? I wanted to spend a little time answering this one question, While there exist others for BlogEngine.Net , this control is less high tech than other controls that use Silver-Light or a re Java-Script heavy. This control should be considered to be the minimum that should be provided in the absence of scripting. Silver-Light, Flash and AJAX photo gallery's are simply just better looking but there always is a person who cant get the plusgins or have script access.

This control while having a script element (lightbox) if  turned off it will still achieve its aim of displaying images, and creating folders full of jpg's is quick and easy with any ftp tool.

Class Layout

This control consists of 3 Classes

  1. Class aphotoCatagory - this represent a single category and is instanced multiple times in a collection.
  2. Class PhotoData - this class is a wrapper for a collection of aphotoCatagory objects, it also handles creation of this collection through File IO interaction.
  3. Class User_controls_Photo2 -  this class contains the display methods and event handlers.

In essence we have object which represent a folder another object that represents a collection of folders and an object to represent the User Interface.  Its a rather group of objects

Can we have multiple user controls on a single page and the answer is Yes each user control is and individual namespaces that is not accessible through normal means to the container page. You can think off classing wrapped in a User Control as private unless changed. 

aphotoCatagory

   1: public class aphotoCatagory
   2: {
   3:     #region declarations
   4:     //catagory name
   5:     public String Cname;
   6:     public String Cpath;
   7:     #endregion
   8:  
   9:     #region Private
  10:     private List<string> Cpaths = new List<string>();
  11:     #endregion
  12:  
  13:     #region  Public
  14:     public bool Add(string str)
  15:     {
  16:         Cpaths.Add(str);
  17:         if (Cpaths.Contains(str))
  18:         {
  19:             return true;
  20:         }
  21:         else
  22:         {
  23:             return false;
  24:         }
  25:  
  26:     } //end of add
  27:  
  28:     public bool remove(string str)
  29:     {
  30:  
  31:         if (Cpaths.Remove(str))
  32:         {
  33:             return true;
  34:         }
  35:         else
  36:         {
  37:             return false;
  38:         }
  39:  
  40:     }//end of remove
  41:  
  42:     public int count()
  43:     {
  44:         return Cpaths.Count;
  45:  
  46:     }//end of cound
  47:  
  48:     public string getItem(int item)
  49:     {
  50:         if (item < Cpaths.Count && item >= 0)
  51:         {
  52:             return Cpaths[item];
  53:  
  54:         }
  55:         else
  56:         {
  57:             return "No item found at this index";
  58:         }
  59:  
  60:     } //end of getitem
  61:     #endregion
  62:  
  63: }//end if aphotoCatagory

The methods are very simple there is a Count() to number of files found, getItem() which return the path of a file , and add() and remove() methods to manipulate the files in the collection. This class has 2 properties a Name and a Cpath which is unused at the current time.

Class PhotoData

   1: public class PhotoData
   2: {
   3:     #region Declarations and properties
   4:  
   5:     //the directory that holds the photos
   6:     private List<aphotoCatagory> CatagoryLists = new List<aphotoCatagory>();
   7:  
   8:     private String _PhotoDirectory;
   9:     #endregion
  10:  
  11:     #region Private Class Methods
  12:     private void makeCatagoryList(string PhotoDirectory)
  13:     {
  14:         try
  15:         {
  16:             if (Directory.Exists(HttpContext.Current.Server.MapPath(PhotoDirectory)))
  17:             {
  18:                 string[] aryDirectories = 
  19:                 Directory.GetDirectories(HttpContext.Current.Server.MapPath(PhotoDirectory));
  20:  
  21:                 string[] files;
  22:                 string[] ExclusionDirectories = { "_vti_cnf", "_vti_pvt", "_vti_script" };
  23:  
  24:                 //test for front page extensions and remove them
  25:                 for (int i = 0; i < aryDirectories.Length; i++)
  26:                 {
  27:                     //test for folder with _vt_cnf , _vt_pvt _vti_script
  28:                     foreach (string j in ExclusionDirectories)
  29:                     {
  30:  
  31:                         if (aryDirectories[i].Contains(j))
  32:                         {
  33:                             aryDirectories[i] = "";
  34:                         } //end if
  35:                     } //end for each
  36:                 } //end for
  37:                 int ab = aryDirectories.Length;
  38:  
  39:                 //test for condition that no subfolders found
  40:                 if (aryDirectories.Length == 1 && aryDirectories[0] == "")
  41:                 {
  42:                     files = Directory.GetFiles(HttpContext.Current.Server.MapPath(PhotoDirectory));
  43:                     if (files.Length >= 1) //if not empty
  44:                     {
  45:                         aphotoCatagory cat = new aphotoCatagory();
  46:                         string keyname = returnCatagoryName(HttpContext.Current.Server.MapPath(PhotoDirectory));
  47:                         cat.Cname = keyname;
  48:                         cat.Cpath = HttpContext.Current.Server.MapPath(PhotoDirectory);
  49:                         PhotoItems(keyname, ref cat, false); // fill the object up
  50:                         CatagoryLists.Add(cat); //add the catagory to the list;   
  51:                     } //end if  
  52:  
  53:                 }
  54:                 else
  55:                 {
  56:                     for (int i = 0; i < aryDirectories.Length; i++)
  57:                     {
  58:                         files = Directory.GetFiles(aryDirectories[i]); //test for empty directories
  59:                         if (files.Length >= 1) //if not empty
  60:                         {
  61:                             aphotoCatagory cat = new aphotoCatagory();
  62:                             string keyname = returnCatagoryName(aryDirectories[i]);
  63:                             cat.Cname = keyname;
  64:                             cat.Cpath = aryDirectories[i];
  65:                             PhotoItems(keyname, ref cat, true); // fill the object up
  66:                             CatagoryLists.Add(cat); //add the catagory to the list;   
  67:                         } //end if
  68:                     }//end for
  69:                 }//end if
  70:  
  71:             }//end if
  72:         }
  73:         catch
  74:         {
  75:             //just produce null wont crash the Web application
  76:         }
  77:     } //end of makeCatagoryList()
  78:  
  79:     private void PhotoItems(string key, ref aphotoCatagory cat, Boolean subs)
  80:     {
  81:         string[] aryDirectories = null;
  82:         string keys;
  83:  
  84:         //combine the relative path and the key Catagory Name: 'Play'
  85:         if (subs)
  86:         {
  87:             keys = Path.Combine(_PhotoDirectory, key);
  88:  
  89:             //get the files in the directory returns c:\\Directory\\Directory\\Directory\\Directory\\FileName.jpg'
  90:             //use mappath change our relative path to application root.
  91:             aryDirectories = Directory.GetFiles(HttpContext.Current.Server.MapPath(keys), "*.jpg");
  92:  
  93:             //make the path relative not the full c:\\Directory\\Directory\\Directory\\Directory\\FileName.jpg'
  94:             for (int i = 0; i < aryDirectories.Length; i++)
  95:             {
  96:                 //return a file name from the full path e.g 'image01.jpg'
  97:                 string str = Path.GetFileName(aryDirectories[i]);
  98:                 //combine our relative path and with the catagory name.
  99:                 string temp = Path.Combine(_PhotoDirectory, this.returnCatagoryName(aryDirectories[i]));
 100:                 //combine the filename and the relative path (cant use path.combine)
 101:                 aryDirectories[i] = temp + '/' + str;
 102:                 cat.Add(aryDirectories[i]);
 103:             } //end for
 104:         }
 105:         else
 106:         {
 107:             keys = _PhotoDirectory;
 108:  
 109:             //get the files in the directory returns 
 110:             //c:\\Directory\\Directory\\Directory\\Directory\\FileName.jpg'
 111:             //use mappath change our relative path to application root.
 112:             aryDirectories = Directory.GetFiles(HttpContext.Current.Server.MapPath(keys), "*.jpg");
 113:  
 114:             //make the path relative not the full 
 115:             //c:\\Directory\\Directory\\Directory\\Directory\\FileName.jpg'
 116:             for (int i = 0; i < aryDirectories.Length; i++)
 117:             {
 118:                 string str = Path.GetFileName(aryDirectories[i]);
 119:                 aryDirectories[i] = Path.Combine( _PhotoDirectory , str); 
 120:                 cat.Add(aryDirectories[i]);
 121:             } //end fir
 122:         
 123:         }//end if
 124:         
 125:  
 126:     } //end of PhototItrms
 127:  
 128:     #endregion
 129:  
 130:     #region public Methods
 131:     public int count()
 132:     {
 133:         return CatagoryLists.Count;
 134:     }
 135:  
 136:     public string returnCatagoryName(string dpath)
 137:     {
 138:  
 139:         string[] nameary; //temp var
 140:         nameary = dpath.Split(Path.DirectorySeparatorChar);
 141:         string CatName = null;
 142:         
 143:         if (Path.HasExtension(dpath))
 144:         {
 145:             CatName = nameary[nameary.GetUpperBound(0) - 1];
 146:         }//end if
 147:         else
 148:         {
 149:             CatName = nameary[nameary.GetUpperBound(0)];
 150:         }//end else
 151:         return CatName;
 152:     } //end of returnCatagoryName
 153:  
 154:  
 155:     public aphotoCatagory getItem(int item)
 156:     {
 157:         if (item < CatagoryLists.Count && item >= 0)
 158:         {
 159:             return CatagoryLists[item];
 160:  
 161:         }
 162:         else
 163:         {
 164:             return null;
 165:         }
 166:  
 167:     } //end of getitem
 168:  
 169:     #endregion
 170:  
 171:     #region constructor
 172:     public PhotoData(string directory)
 173:     {
 174:         _PhotoDirectory = directory; //set the state variable
 175:         makeCatagoryList(_PhotoDirectory);  //fill the dictionary object
 176:  
 177:     }
 178:     #endregion
 179:  
 180: } //end of class

You will notice that each category is stored into a List<aphotoCatagory> objected call CatagoryLists. The other methods in the class are concerned with scanning directories for images an building the datastructure.

You may notice the following code:-

   1: private void makeCatagoryList(string PhotoDirectory)
   2:     {
   3:         //code remove for bevity
   4:         
   5:     string[] ExclusionDirectories = { "_vti_cnf", "_vti_pvt", "_vti_script" };
   6:  
   7:                 //test for front page extensions and remove them
   8:                 for (int i = 0; i < aryDirectories.Length; i++)
   9:                 {
  10:                     //test for folder with _vt_cnf , _vt_pvt _vti_script
  11:                     foreach (string j in ExclusionDirectories)
  12:                     {
  13:  
  14:                         if (aryDirectories[i].Contains(j))
  15:                         {
  16:                             aryDirectories[i] = "";
  17:                         } //end if
  18:                     } //end for each
  19:                 } //end for
  20:            //code removed for bevity
  21:      }
  22:     //end class

When I was developing this extension, I wanted to be able to specify a sing directory e.g instead of the root folder ' ~/photos '  I wanted to specify '~/photos/play' an have my code produce just that directory. What I found was that when Front-Page extensions are installed runtime directories are created on the web-server called _vti_cnf , amongst others. this meant that my function would return this directory instead of a value of  0. The above code removes these directories by setting their value as an empty string.  Which can be later test for in the below.

   1: if (aryDirectories.Length == 1 && aryDirectories[0] == "")
   2: {
   3:  //deep folder with Frontpage extensions installed   
   4: }    
   5: else if(aryDirectories.Length ==0)
   6: {
   7: //deep folder with no Frontpage extensions installed                 
   8: }
   9: else
  10: {
  11:  //normal root folder                    
  12: }//end if

Class User_controls_Photo2

   1: public partial class User_controls_Photo2 : System.Web.UI.UserControl
   2: {
   3:  
   4:     #region Delecrations
   5:     private PhotoData Photo;
   6:     #endregion
   7:  
   8:     #region Properties
   9:     private string PD = "~/Photos/play";
  10:     public string PhotoDirectory
  11:     {
  12:         get
  13:         { return PD; }
  14:         set
  15:         { PD = value; }
  16:  
  17:     }
  18:  
  19:     //Number of items per row
  20:     private int numberperrow = 3;
  21:     public int NumberPerRow
  22:     {
  23:         get
  24:         { return numberperrow; }
  25:         set
  26:         { numberperrow = value; }
  27:  
  28:     }
  29:  
  30:     //Number of Cat items per row
  31:     private int numbercatperrow = 3;
  32:     public int NumberCatPerRow
  33:     {
  34:         get
  35:         { return numbercatperrow; }
  36:         set
  37:         { numbercatperrow = value; }
  38:  
  39:     }
  40:  
  41:     //show catagoires?
  42:     private bool SC = true;
  43:     public bool ShowCategories
  44:     {
  45:         get
  46:         { return SC; }
  47:         set
  48:         { SC = value; }
  49:  
  50:     }
  51:  
  52:     //CSSstyledefaults
  53:     private bool CSSDef = true;
  54:     public bool CSSDefaults
  55:     {
  56:         get
  57:         { return CSSDef; }
  58:         set
  59:         { CSSDef = value; }
  60:  
  61:     }
  62:  
  63:  
  64:     //Cell padding Cat
  65:     private int CatCP = 0;
  66:     public int CatCellPadding
  67:     {
  68:         get
  69:         { return CatCP; }
  70:         set
  71:         { CatCP = value; }
  72:  
  73:     }
  74:  
  75:  
  76:     //Cell Spacing Cat
  77:     private int CatCS = 20;
  78:     public int CatCellSpacing
  79:     {
  80:         get
  81:         { return CatCS; }
  82:         set
  83:         { CatCS = value; }
  84:  
  85:     }
  86:  
  87:     //Cell padding Item
  88:     private int ItemCP = 0;
  89:     public int ItemCellPadding
  90:     {
  91:         get
  92:         { return ItemCP; }
  93:         set
  94:         { ItemCP = value; }
  95:  
  96:  
  97:     }
  98:  
  99:     //Cell Spacing Item
 100:     private int ItemCS = 10;
 101:     public int ItemCellSpacing
 102:     {
 103:         get
 104:         { return ItemCS; }
 105:         set
 106:         { ItemCS = value; }
 107:     }
 108:  
 109:     #endregion
 110:  
 111:     #region Controls
 112:  
 113:     //Creates the CatagoryControls
 114:     public void CatagoryControl(PlaceHolder holdme)
 115:     {
 116:         int intItemsPerRow = numbercatperrow;
 117:         int intNumbOfRows = 0;
 118:         int numcatagories = Photo.count();
 119:         //List<string> Catagorys = Photo.returnCatagoryImagesList();  
 120:  
 121:         //determine the dimensions
 122:         if ((Photo.count() % intItemsPerRow) > 0)  // if there is a remainder do an integer division and add one to round up 
 123:         {      //the rounding will round down so add extra row to compensate
 124:             intNumbOfRows = (Photo.count() / intItemsPerRow) + 1; //rounds up
 125:         }//end if  
 126:         else
 127:         {
 128:             intNumbOfRows = (Photo.count() / intItemsPerRow); //no round as there is no remainder
 129:         } //end else
 130:  
 131:         //create the table
 132:         Table CatagoryTable = new Table();
 133:         //table Properties Here
 134:         if (CSSDef)
 135:         {
 136:  
 137:  
 138:         }
 139:         else
 140:         {
 141:             CatagoryTable.CssClass = "PhotosTable";
 142:         }//end if
 143:  
 144:         CatagoryTable.BorderWidth = 0;
 145:         CatagoryTable.CellSpacing = CatCS;
 146:         CatagoryTable.CellPadding = CatCP;
 147:         CatagoryTable.HorizontalAlign = HorizontalAlign.Center;
 148:         
 149:  
 150:         //create the rows and cells (column items)
 151:  
 152:         while (intNumbOfRows > 0)
 153:         {
 154:             //create the row
 155:             TableRow RowTable = new TableRow();
 156:  
 157:             //css styles
 158:             if (CSSDef)
 159:             {
 160:                 //RowTable.Attributes.CssStyle.Add("border", "1px solid #563434");
 161:                 RowTable.Attributes.CssStyle.Add("text-align", "center");
 162:             }
 163:             else
 164:             {
 165:                 RowTable.CssClass = "PhotosTableRow";
 166:             }
 167:  
 168:             //create the Image and Lable objects
 169:             //check for number of catagories
 170:             int i = 1;
 171:             while (numcatagories > 0 && i <= intItemsPerRow)
 172:             {
 173:                 aphotoCatagory cat = Photo.getItem(numcatagories - 1);
 174:  
 175:                 //create the cells
 176:                 TableCell CellTable = new TableCell();
 177:  
 178:                 ImageButton CellImage = new ImageButton();
 179:                 Label CellLabel = new Label();
 180:  
 181:                 CellImage.ImageUrl = @"~/User controls/CreateThumb.aspx?img=" + cat.getItem(0); //Catagorys[numcatagories - 1];
 182:                 CellImage.ID = "imgbutton" + numcatagories;
 183:                 //CellImage.Width = 200;
 184:                 CellImage.CommandName = (numcatagories - 1).ToString(); //Photo.ReturnKey(numcatagories - 1);
 185:                 CellImage.Command += new CommandEventHandler(CellImage_Command);
 186:                 CellImage.EnableViewState = false;
 187:  
 188:                 CellLabel.Text = cat.Cname;  //Photo.returnCatagoryName(Photo.ReturnItem(numcatagories - 1));
 189:                 CellLabel.AssociatedControlID = "imgbutton" + numcatagories;
 190:                 CellLabel.EnableViewState = false;
 191:  
 192:                 //css styles
 193:                 if (CSSDef)
 194:                 {
 195:                     CellLabel.Attributes.CssStyle.Add("background-color", "#563434");
 196:                     CellLabel.Attributes.CssStyle.Add("color", "white");
 197:                     CellLabel.Attributes.CssStyle.Add("font-size", "3em");
 198:                     CellLabel.Attributes.CssStyle.Add("display", "block");
 199:                     CellLabel.Attributes.CssStyle.Add("font-family", "Verdana");
 200:                     CellLabel.Attributes.CssStyle.Add("text-align", "center");
 201:                     CellLabel.Attributes.CssStyle.Add("margin", "0px 0px 5px 0px");
 202:                     CellLabel.Attributes.CssStyle.Add("padding", "5px 5px 5px 5px");
 203:                     CellTable.Attributes.CssStyle.Add("padding", "5px 5px 5px 5px");
 204:                     //CellTable.Attributes.CssStyle.Add("border", "1px solid #563434;");
 205:                     
 206:                 }
 207:                 else
 208:                 {
 209:                     CellLabel.CssClass = "photoCatagoryLabel";
 210:                     CellImage.CssClass = "photoCatagoryLabel"; 
 211:                 }
 212:  
 213:                 //add them to the current Cell
 214:                 CellTable.Controls.Add(CellLabel);
 215:                 CellTable.Controls.Add(CellImage);
 216:  
 217:                 //add cells to current row
 218:                 RowTable.Controls.Add(CellTable);
 219:  
 220:                 ++i; // increment i
 221:                 --numcatagories; //de-increment the table
 222:  
 223:             } //end while
 224:  
 225:             //add the row to the table 
 226:             CatagoryTable.Controls.Add(RowTable);
 227:  
 228:             --intNumbOfRows;  //de-increment the rows
 229:         } //end while
 230:  
 231:         //add the tabe to the placeholder
 232:         holdme.Controls.Add(CatagoryTable);
 233:  
 234:     }
 235:  
 236:     // Event Handler for Imagebutton Controls
 237:     void CellImage_Command(object sender, CommandEventArgs e)
 238:     {
 239:         //clear the current controls
 240:         PlaceHolder1a.Controls.Clear();
 241:  
 242:         int key = int.Parse(e.CommandName); //get the dictionary key (folder name)
 243:  
 244:         //get the select catagory
 245:         aphotoCatagory cat = Photo.getItem(key);
 246:  
 247:         //create a placeholder 
 248:         PlaceHolder ab = new PlaceHolder();
 249:  
 250:         //create the control
 251:         InnerCatagoryControl(ref cat, ab); //call the print method
 252:         ab.ID = "onecatagoryview";
 253:  
 254:         //add control to the current view
 255:         PlaceHolder1a.Controls.Add(ab);
 256:  
 257:     }
 258:  
 259:     //Prints the Items table
 260:     public void InnerCatagoryControl(ref aphotoCatagory cat, PlaceHolder holdme)
 261:     {
 262:  
 263:         int intItemsPerRow = numberperrow;
 264:         int intNumbOfRows = 0;
 265:         int numcatagories = cat.count();
 266:  
 267:         //Catagory Label
 268:         System.Web.UI.WebControls.Label h1 = new Label();
 269:         h1.Text = cat.Cname;
 270:  
 271:         //css styles
 272:         if (CSSDef)
 273:         {
 274:  
 275:             h1.Attributes.CssStyle.Add("font-Size", "3em");
 276:             h1.Attributes.CssStyle.Add("display", "block");
 277:             h1.Attributes.CssStyle.Add("color", "#5A5A43");
 278:             h1.Attributes.CssStyle.Add("border-bottom", "1px solid black");
 279:         }
 280:         else
 281:         {
 282:             h1.CssClass = "ItemTableLabel";
 283:  
 284:         };
 285:  
 286:         //add the control to the collection
 287:         holdme.Controls.Add(h1);
 288:  
 289:         //determine the dimensions
 290:         if ((numcatagories % intItemsPerRow) > 0)  // if there is a remainder do an integer division and add one to round up 
 291:         {      //the rounding will round down so add extra row to compensate
 292:             intNumbOfRows = (numcatagories / intItemsPerRow) + 1; //rounds up
 293:         }//end if  
 294:         else
 295:         {
 296:             intNumbOfRows = (numcatagories / intItemsPerRow); //no round as there is no remainder
 297:         } //end else
 298:  
 299:         //create the table
 300:         Table CatagoryTable = new Table();
 301:         //table Properties Here
 302:         //CatagoryTable.CssClass = "aPhotosTable";
 303:         CatagoryTable.BorderWidth = 0;
 304:         CatagoryTable.CellSpacing = ItemCS;
 305:         CatagoryTable.CellPadding = CatCP;
 306:         CatagoryTable.HorizontalAlign = HorizontalAlign.Center;
 307:  
 308:         if (CSSDef)
 309:         {
 310:             CatagoryTable.Attributes.CssStyle.Add("margin-bottom", "20px");
 311:              
 312:         }
 313:         else
 314:         {
 315:             CatagoryTable.CssClass = "ItemTable";
 316:         }
 317:  
 318:         CatagoryTable.BorderColor = System.Drawing.Color.White;
 319:  
 320:         //create the rows and cells (column items)
 321:  
 322:         while (intNumbOfRows > 0)
 323:         {
 324:             //create the row
 325:             TableRow RowTable = new TableRow();
 326:  
 327:             //create the Image and Lable objects
 328:             //check for number of catagories
 329:             int i = 0;
 330:             while (numcatagories > 0 && i < intItemsPerRow)
 331:             {
 332:                 //create the cells
 333:                 TableCell CellTable = new TableCell();
 334:  
 335:                 Image CellImage = new Image();
 336:                 HyperLink hyp = new HyperLink();
 337:  
 338:                 //link tag
 339:                 hyp.Attributes.Add("Rel", "lightbox");
 340:                 hyp.NavigateUrl = cat.getItem(numcatagories - 1);
 341:  
 342:                 //cssstyles
 343:                 if (CSSDef)
 344:                 {
 345:                     hyp.Attributes.CssStyle.Add("border", "1px solid #dcd7c8");
 346:                     hyp.Attributes.CssStyle.Add("background-color", "#b4afa3");
 347:                     hyp.Attributes.CssStyle.Add("padding", "0 2px");
 348:                     hyp.Attributes.CssStyle.Add("display", "block");
 349:                 }
 350:                 else
 351:                 {
 352:                     hyp.CssClass = "Itemhyp";
 353:                 }//end if
 354:  
 355:  
 356:                 //add <a> tage to table
 357:                 CellTable.Controls.Add(hyp);
 358:  
 359:                 CellImage.ImageUrl = @"~/User controls/CreateThumb.aspx?img=" + cat.getItem(numcatagories - 1);
 360:                 CellImage.ID = "imgNext" + numcatagories;
 361:                 //CellImage.Width = 200;
 362:                 CellImage.EnableViewState = false;
 363:  
 364:                 if (CSSDef)
 365:                 {
 366:                     CellImage.Attributes.CssStyle.Add("padding", "5px");
 367:                     CellImage.Attributes.CssStyle.Add("background-color", "white");
 368:                 }
 369:                 else
 370:                 {
 371:                     CellImage.CssClass = "ItemCellImage";
 372:                 } //end if
 373:  
 374:  
 375:                 //add image to the hyperlink
 376:                 hyp.Controls.Add(CellImage);
 377:  
 378:                 //add cells to current row
 379:                 RowTable.Controls.Add(CellTable);
 380:  
 381:                 ++i; // increment i
 382:                 --numcatagories; //de-increment the table
 383:  
 384:             } //end while
 385:  
 386:             //add the row to the table 
 387:             CatagoryTable.Controls.Add(RowTable);
 388:  
 389:             --intNumbOfRows;  //de-increment the rows
 390:         } //end while
 391:  
 392:         //add the tabe to the placeholder
 393:         holdme.Controls.Add(CatagoryTable);
 394:  
 395:  
 396:         if (SC) //if showcatagoires is false dont print the return button
 397:         {
 398:             //generate return button
 399:             Button newbtn = new Button();
 400:             newbtn.ID = "btnreturn";
 401:             newbtn.Text = "Return to Previous View";
 402:             newbtn.Click += new EventHandler(newbtn_Click); //add event handler
 403:             holdme.Controls.Add(newbtn);   //add control the bottom of heirarchy
 404:  
 405:             if (CSSDef)
 406:             {
 407:                 newbtn.Attributes.CssStyle.Add("width", "100%");
 408:                 newbtn.Attributes.CssStyle.Add("display", "block");
 409:             }
 410:             else
 411:             {
 412:                 newbtn.CssClass = "ItemNewbtn";
 413:             }
 414:         }//end if 
 415:  
 416:     }
 417:  
 418:     //return button Event Handler
 419:     void newbtn_Click(object sender, EventArgs e)
 420:     {
 421:  
 422:         //remove the image control and button control
 423:         PlaceHolder1a.Controls.Clear();
 424:  
 425:         PlaceHolder placehold = new PlaceHolder();
 426:         placehold.ID = "contentbox";
 427:         PlaceHolder1a.Controls.Add(placehold);
 428:         CatagoryControl(placehold);
 429:  
 430:     }//end of InnerCatagoryControl
 431:  
 432:     #endregion
 433:  
 434:     #region PageLoad(constructor)
 435:     protected void Page_Load(object sender, EventArgs e)
 436:     {
 437:         Photo = new PhotoData(PhotoDirectory);
 438:  
 439:         PlaceHolder placehold = new PlaceHolder();
 440:         placehold.ID = "contentbox";
 441:         PlaceHolder1a.Controls.Add(placehold);
 442:  
 443:         if (SC == true) //if showcatagories is true
 444:         {
 445:  
 446:             CatagoryControl(placehold);
 447:         }
 448:         else //print all the catagories
 449:         {
 450:             aphotoCatagory acat;
 451:  
 452:             for (int i = 0; i < Photo.count(); i++)
 453:             {
 454:                 acat = Photo.getItem(i);
 455:  
 456:                 InnerCatagoryControl(ref acat, placehold);
 457:  
 458:             }
 459:         }
 460:  
 461:  
 462:     }
 463:     #endregion
 464:  
 465:  
 466: }//end if userscontrol

These methods Create the tables that will host the images.  So why not use a data-list or a Repeater control? Well the quick answer is I hate both controls.  That and I Honestly did not think to use it till now. But hey that's what self examination is for, A data-List control would have reduced a lot of the complexity in this class. If I update the user control in the future I will make sure to use it, but I must say it is much easier to control the number of images per row using this procedural code.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Tags:   , ,
Categories:   ASP.NET | Projects
Actions:   E-mail | Permalink | Comments (457) | Comment RSSRSS comment feed

HTPC JavaScript Project

Sunday, 20 April 2008 01:58 by Frimbob

Before I start let me say this was the best of failures, I learn a-lot about  OOP Java-Script and Dom Scripting and using 3rd party library's , after working on the project I know 3 things, Java-Script is an extremely expressive language is a pain to debug but Is my firm favourite dynamic language. The second is don't use a 3rd party library that doesn't have excellent documentation its just not worth the pain.  Thirdly Active X objects are terrible way to integrate desktop applications into the web.

The Aim

  • To develop a web based HTPC application that would list TV recordings and using MPClassic allow these files to opened and played.
  • Display files based on there date in a number of lists and also a Calendar.
  • Use Java-Script and Active X objects
  • Use Internet Explorer as browser, and Active Desktop to host the web-page on a desktop. 
  • Only be available on a local level. 

The Results

 blog_260408_02 blog_260408_03

Blog_260408_04 blog_260408_05

blog_260408_06

I was able to create a beta build using Active X file objects with the EXT Java-Script library to create  menus, based around weeks. This seemed appropriate as television shows tend to be grouped into weeks, I also build a Java-Script calendar that would show the shows recorded on that date. Using query String an another Active X object I was able to get MPClassic to load a particular file.

The bugs which were the killer, The calendar never quite worked correctly and the File list where to easily corrupted, I don't think any of these bugs where unfixable but I did not wish to invest the time , when I decided the Active X approach was not worth the effort. Since Fire-Fox does not support JScript Emulators the project was IE only.
  

File download of current Work: HTPCSite.zip (1.13 mb)

I plan to revisit the project in the future, and replace the Acitve-X objects with a .Net Web-Service and a JSON objects to pass the file information to the browser code, I will also like to change the Java-Script library to the YUI, as I found the Documentation to be easier on the brain :-).

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

VB-Script Text Processor

Wednesday, 16 April 2008 03:11 by Frimbob

Project Reasons

As part of my current work at Australasian Investment Review, I need to post articles sent to me by the editor onto their web-site. Their CMS is not what I would qualify as words best. Like many web-posters we are forced to use inline styles. Simply Setting a few global style parameters in an opening div tag can waste, many minutes per article. Their CMS does allow images to be pasted directly in the story however the graphs are sent separately to the story. there need to be a way to group images per story and the ability to transform text into basic html with some opening style parameters. This script processor is the result and it my favourite program and a raising success.

Project Aim

  • Remove all formatting characters that MS-word products that confuse the CMS Java Applet, Notepad us perfect program for the job
  • Ensure consistent results in text, (remove MS_word formatting characters)
  • Global Style Parameters
  • Use Active-X objects to manipulate files
  • Using HTA with scripting language (VB-Script)
  • Display List of Images based on their Date-Created
  • Using this master list group images to a particular article
  • Image Preview that can by right Clicked > copy to clipboard.
  • Process Text (Insert extra line break)
  • Convert some pre-defined text-sequences into html e.g '......'  into <hr>. 

Results

What is a HTA:  HTAs pack all the power of Internet Explorer—its object model, performance, rendering power and protocol support—without enforcing the strict security model and user interface of the browser. They are basically a sandbox version of Internet Explorer they make very useful script font-ends with the ability to use HTML to render the controls.

I was able to meet all my requirements, this project took me around a month to write  in November-December 2007. I will cover a class over-view in this review at 1327 lines of code not including the HTML it just shorter this way.

Classes 

Class Name Description
Class TextFile Represents a single TextFile
Class FileList Wrapps Dictionary object to store Text-File object
Class CreateOpenTextFile Contains the code that Uses WSH active X object to open and create text files
Class RegexFilters Contains a number of Test methods used in the HTML conversion process.

Class ProcessTextFiles

Contains all the logic to transform a text file into html.
Class ImageFiles Represents a single image File
Class ImageOutput Wrapper for a dictionary object of Image Files
Global Declarations No constructor is supported must use global variables instead to initialise the above classes
Event Handlers UI Code for the font end

 

WSH objects used 

 

Namespace Use

Scripting.FileSystemObject

return File System Information
Wscript.Shell Open Notepad
Scripting.Dictionary Dictionary Collection

 

Language Tricks

While VB-Script does support basic class encapsulation with properties and methods, it does not support any class inheritance.  Another major shortcoming is functions are not allowed to return an object only a value type. However there is a lonely document but usable way to force object returns from functions.

VB-script is a garbage-collection language so orphaned objects will be re-claimed after the garbage collection cycle and since we can pass object references as function parameters we are able to use scope to our advantage. In our calling function we can create a new instance of the class , empty of data, this empty object can be then passed to a function, the function is able then to set the object's reference to that of another object of same type. As this object is in scope and NOT disposed by either function will have an object with a reference to and existing object returned. Effectively we have returned an object from a function not using the (return) statement but scope. 

General Code 

   1: Option Explicit
   2: '------------------------------------------------------------------------------'
   3: 'Indiviudal File object'
   4: Class TextFile
   5:   
   6:   'declare Constances'
   7:   Private strExtension
   8:   Private strBaseName
   9:   
  10:   'Class Initilize'
  11:   Private Sub Class_Initialize
  12:     strExtension = ".txt"  
  13:     strBaseName = "Article"
  14:   End Sub
  15:  
  16:   'Class Terminate'
  17:   'Private Sub Class_Terminate
  18:     
  19:   'End Sub
  20:   'Declare the Instance Varibales'
  21:   Private strFileName
  22:   Private intNumber
  23:   Private strRead
  24:   Private strFinal
  25:   
  26:    
  27:   'Public Property Let (Write- Statements)'
  28:   Public Property Let FileName(strName)
  29:     If IsNumeric(strName) = false Then
  30:       Err.Raise 91, "TextFile", "The FileName is invalid"
  31:     End if
  32:     'set the values'
  33:     strFileName = CStr(strBaseName & strName & strExtension)   
  34:   End Property 
  35:   
  36:   Public Property Let  FileNumber(intNum) 
  37:     If IsNumeric(intNum) = False Then
  38:       Err.Raise 91, "TextFile", "The FileNumber is invalid"
  39:     End if 
  40:     'set the property Value'
  41:     intNumber = intNum
  42:   End Property
  43:   
  44:   Public Property Let Read(str)
  45:     strRead = str
  46:   End Property
  47:   
  48:   Public Property Let Final(str)
  49:     strFinal = str
  50:   End Property
  51:     
  52:   'public Property Get (Read-Statements)'
  53:   Public Property Get FileName 
  54:     FileName = strFileName 
  55:   End Property
  56:   Public Property Get FileNumber
  57:     FileNumber = intNumber 
  58:   End Property
  59:   
  60:   Public Property Get Extension 
  61:     Extension = strExtension
  62:   End Property
  63:   
  64:   Public Property Get BaseName 
  65:     BaseName = strBaseName
  66:   End Property
  67:   
  68:   Public Property Get Read
  69:     Read = strRead 
  70:   End Property
  71:   
  72:   Public Property Get Final
  73:     Final = strFinal 
  74:   End Property
  75:   
  76:   'methods'
  77:   Public Sub DisplayEntry
  78:   MsgBox " File List Entry:" & vbNewLine &_
  79:          "Extension:" & strExtension & _
  80:          "BaseName:" & strBaseName & _
  81:          "FileName:" & strFileName & _
  82:          "Number:" & intNumber 
  83:   End Sub
  84: End Class
  85: '------------------------------------------------------------------------------'
  86: '------------------------------------------------------------------------------'
  87: 'storage object for TextFile objects'
  88: Class FileList
  89:     
  90:     'Inistance Varaibles'
  91:     Private objDict
  92:     
  93:     'class Initilize'
  94:     Private Sub Class_Initialize
  95:        Set objDict = CreateObject("Scripting.Dictionary")
  96:     End Sub
  97:     
  98:     'class Terminate'
  99:     Private Sub Class_Terminate
 100:         Set objDict = Nothing
 101:     End Sub
 102:   
 103:     'wrapper for dictionary count'
 104:     Public Property Get ListCount
 105:         ListCount = objDict.Count
 106:     End Property
 107:     
 108:     'Wrapper for dictionary exists'
 109:     Public Function EntryExists(strFileName)
 110:       EntryExists = objDict.Exists(strFileName)
 111:     End Function 
 112:   
 113:     'Methods'
 114:     'Wrapper for the dictionary add method'
 115:     Public Sub AddEntry(objTextfile)
 116:       If TypeName(objTextfile) = "TextFile" Or TypeName(objTextfile) = "ImageFiles"  Then 'test if the object is the one expected'
 117:           objDict.Add objTextfile.FileName , objTextfile 'adds the file name as key and the object as the array value So have an array of objects' 
 118:       Else
 119:           Err.Raise 3200, "FileList", "Only TextFile objects can be stored"
 120:       End if
 121:      'use the file name as the key'
 122:      
 123:     End Sub
 124:     
 125:     'Wrapper for RemoveAll entry'
 126:     Public Sub ClearAll
 127:       objDict.RemoveAll 'clears the dictionary' 
 128:     End Sub 
 129:     
 130:     Public Function DisplayEntry(thefile,strFileName)
 131:       If  objDict.Exists(strFileName) Then
 132:           Set thefile = objDict.Item(strFileName)
 133:           'DisplayEntry=Cstr(objTFile.FileName) ' returns the file name as a string'
 134:       Else
 135:          Err.Raise 32002, "FileList" , "The filename " & strFileName &"not in the list"
 136:       End if
 137:     End Function
 138:     
 139:     'Matches index number to a key pair and returns the object'
 140:     Public Function MatchIndex(thefile,keynumber)
 141:       Dim arykey 
 142:       Dim i
 143:       arykey = objDict.Keys 'array with the keys'
 144:      'return the key at particular value'
 145:        For i = 0 to objDict.count -1 
 146:          If i = keynumber Then
 147:            'return the key which is the file name
 148:           Set theFile =  objDict.Item(arykey(i))
 149:           'Set MatchIndex =  theFile 
 150:          'Else ' not in index' 
 151:            'MatchIndex = null 'return a null object'
 152:          End if
 153:        Next
 154:     End Function
 155: End Class
 156: '------------------------------------------------------------------------------'
 157: '------------------------------------------------------------------------------'
 158: ' Methods to Open,Create,Delete,and Iterate through Physical Files'
 159: Class CreateOpenTextFile
 160:    'Class Initilize'
 161:    Private Sub Class_Initialize
 162:      Set objFSO       = CreateObject("Scripting.FileSystemObject")
 163:      Set wshSHELL     = CreateObject("Wscript.Shell")
 164:    End Sub
 165:  
 166:    'Class Terminate'
 167:    Private Sub Class_Terminate
 168:      Set objFSO = Nothing
 169:      Set wshSHELL = Nothing
 170:      Set objFileList = Nothing
 171:    End Sub
 172:  
 173:    'Class Varaibles'
 174:    'Private FileSystemObject'
 175:    Private objFSO
 176:    Private wshSHELL
 177:    Private objFileList
 178:    Private strActiveFile
 179:    Private strCurrentFileIndex
 180:    
 181:    
 182:    'Write statements   
 183:    Public Property Set FileLists(obj) 
 184:       Set objFileList  = obj 
 185:    End Property
 186:    
 187:    'read statement'     
 188: '    Public Property Get FileList  
 189: '       FileList = objFileList
 190: '    End Property
 191:    
 192:    Public Property Get CurrentFileIndex 
 193:       CurrentFileIndex = strCurrentFileIndex
 194:    End Property
 195:    
 196:    Public Property Get ActiveFileName
 197:       ActiveFileName = strActiveFile 
 198:    End Property
 199:    
 200:    'returns an object from the file list' 
 201:   Public Property Get ReturnObject(ByVal number) 
 202:    Dim thefile 
 203:    Set thefile = New TextFile 
 204:    Call objFileList.MatchIndex(thefile,number)
 205:    ReturnObject = Cstr(thefile.FileName) 
 206:   End Property
 207:   
 208:   'read statement'
 209:   Public Property Get ReturnTheObject(thefile,number) 
 210:     Call objFileList.MatchIndex(thefile,number)
 211:   End Property
 212:    
 213:    
 214:    'Define Public Methods'
 215:    Function CreateFiles(number) 
 216:      'data Type Test'
 217:      If Not IsNumeric(number) Then
 218:        Msgbox("Invalid Number of Files")
 219:      Else
 220:         'constants'
 221:         Const ForReading = 1
 222:            Const ForWriting = 2
 223:          
 224:         'varaibles'
 225:         Dim Filepointer  'file Pointer'  
 226:         Dim intNumFiles  'Loop Counter'
 227:         Dim intCounter   'loop counter'
 228:         Dim blnSucessful 'return value'
 229:         Dim objTextFile
 230:         
 231:         'set varaible Values'
 232:         intNumFiles = number
 233:         blnSucessful = False
 234:        
 235:          'create the Files'
 236:          For intCounter = 1 to intNumFiles
 237:                 'Create the file object'
 238:            Set objTextFile = New TextFile 'declared the class'
 239:            objTextFile.FileName = intCounter ' only part needed'
 240:            objTextFile.FileNumber = intCounter ' index in the For loop'
 241:            
 242:            'create the file' 
 243:            Set Filepointer = objFSO.OpenTextFile(objTextFile.FileName, ForWriting, True)
 244:                 Filepointer.Close()
 245:               Set Filepointer = Nothing
 246:             'Check if operation completed successfully
 247:                 
 248:             If objFSO.FileExists (objTextFile.FileName) Then 
 249:                      blnSucessful = True
 250:                     'store the file info into objFileList'
 251:               objFileList.AddEntry(objTextFile) 
 252:               
 253:             Else
 254:               blnSucessful = False
 255:               Set objTextFile = Nothing 'remove till next instance'
 256:               Exit for ' stop if a file not sucessfuly created'
 257:             End If  
 258:             
 259:             strCurrentFileIndex = intCounter
 260:             strActiveFile  =Cstr(objTextFile.BaseName &  strCurrentFileIndex & objTextFile.Extension)
 261:             Set objTextFile = Nothing 'remove till next instance'
 262:           Next
 263:       End if
 264:    CreateFiles = blnSucessful
 265:    End Function
 266:    'Open a Text File'
 267:    Public Sub Open
 268:       'test is file exists
 269:           If objFSO.FileExists(strActiveFile) Then
 270:               'open file in text editor
 271:               wshSHELL.Run strActiveFile
 272:           Else
 273:               'report error
 274:               MsgBox ("Error File NOT found Please start Process again")
 275:           End If
 276:    End Sub
 277:  
 278:   'next file'
 279:   Public Function NextFile 
 280:     'create new TextFile object to reternve the 2 class values of BaseName and Extension'
 281:     Dim objTextFile
 282:     Set objTextFile = New TextFile 'declared the class'
 283:     
 284:     If objFSO.FileExists(objTextFile.BaseName &  (strCurrentFileIndex+1) & objTextFile.Extension) Then
 285:        strActiveFile =Cstr(objTextFile.BaseName &  (strCurrentFileIndex+1) & objTextFile.Extension)
 286:        'add one increment the counter'
 287:        strCurrentFileIndex =(strCurrentFileIndex +1) 'increment the value'
 288:       NextFile = True
 289:     Else
 290:       NextFile = False
 291:       
 292:     End if
 293:     'delete the object for next occurance' 
 294:     Set objTextFile = Nothing
 295:   End Function
 296:   
 297:   
 298:   Public Function PrevFile
 299:   'create new TextFile object to reternve the 2 class values of BaseName and Extension'
 300:     Dim objTextFile
 301:     Set objTextFile = New TextFile 'declared the class'
 302:     
 303:     If objFSO.FileExists(objTextFile.BaseName &  (strCurrentFileIndex-1) & objTextFile.Extension) Then
 304:        strActiveFile =Cstr(objTextFile.BaseName &  (strCurrentFileIndex-1) & objTextFile.Extension)
 305:        'add one increment the counter'
 306:        strCurrentFileIndex =(strCurrentFileIndex -1) 'increment the value'
 307:       PrevFile = True
 308:     Else
 309:       PrevFile = False
 310:       
 311:     End if
 312:     'delete the object for next occurance' 
 313:     Set objTextFile = Nothing
 314:     
 315:   End Function
 316:   
 317:   'Function to clear the disctionary and delete the files'
 318:   Public Function DeleteTheFiles 
 319:    Dim intCount
 320:    Dim intCounter
 321:    'test the index number'
 322:      If (objFileList.ListCount > 0)  Then
 323:         intCounter =  (objFileList.ListCount-1) 
 324:            For intCount = 0 to intCounter 
 325:               Dim thefile 
 326:               Set thefile = New TextFile 
 327:             Call objFileList.MatchIndex(thefile,intCount) 'get the physical object'
 328:               objFSO.DeleteFile(thefile.FileName)            'Delete the physical Files'
 329:               Set thefile = Nothing                          'Reset for next instance'
 330:           Next 
 331:         DeleteTheFiles = True   
 332:      Else
 333:         DeleteTheFiles = False
 334:      End if
 335:    
 336:    'clear the dict'
 337:     objFileList.ClearAll
 338:   
 339:   End Function
 340:      
 341:  End Class
 342: '------------------------------------------------------------------------------'
 343: '------------------------------------------------------------------------------'
 344: 'Object to contain Regex Patterns used in the program'
 345: Class RegexFilters
 346:     
 347:     'Class Global Variables'
 348:     Private objRegExp  
 349:     Private Pattern1
 350:     Private Pattern2
 351:     Private Pattern3
 352:     Private Pattern4
 353:      
 354:     'Class Initilize'
 355:     Private Sub Class_Initialize
 356:         Set objRegExp         = New RegExp      
 357:         objRegExp.IgnoreCase  = True 
 358:         objRegExp.Global      = True 
 359:         Pattern1              = "[…|*|.|a-z|0-9]"
 360:         Pattern2              = "\b(\w+?)\b" 
 361:         Pattern3              = "^(\.+|\*+)$"
 362:         Pattern4              ="^.+\.((gif)|(GIF)|(jpg)|(JPG)|(jpeg)|(JPEG)|(png)|(PNG))$"
 363:     End Sub
 364:   
 365:     'Class Terminate'
 366:     Private Sub Class_Terminate
 367:         Set objRegExp         = Nothing
 368:     End Sub
 369:     'Read Statements'
 370:     Public Property Get PatternOne 
 371:       PatternOne    = Pattern1
 372:     End Property
 373:     
 374:     Public Property Get PatternTwo
 375:       PatternTwo    = Pattern2
 376:     End Property
 377:     
 378:     Public Property Get PatternThree
 379:       PatternThree  = Pattern3
 380:     End Property
 381:     
 382:     Public Property Get PatternFour
 383:       PatternThree  = Pattern4
 384:     End Property
 385:     
 386:     'Public Methods'
 387:     Public Function TestEmptyLine(strLine) 
 388:       objRegExp.Pattern = Pattern1
 389:       If (objRegExp.Test(strLine)) Then
 390:          TestEmptyLine    = True
 391:       Else
 392:         TestEmptyLine     = False  
 393:       End if
 394:      End Function 
 395:     
 396:     Public Function TestLineBreak(strLine)
 397:       objRegExp.Pattern = Pattern3
 398:       If ((objRegExp.Test(strLine))) Then
 399:           TestLineBreak    = True
 400:       Else
 401:           TestLineBreak    = False
 402:       End if
 403:     End Function
 404:    
 405:     Public Function TestFileType(strFileName)
 406:       objRegExp.Pattern = Pattern4
 407:       If ((objRegExp.Test(strFileName))) Then
 408:           TestFileType    = True
 409:       Else
 410:           TestFileType    = False
 411:       End if
 412:     End Function
 413:     
 414:     Public Function AddressOK(strFilePath)
 415:     Dim StrReplace
 416:         
 417:     'replace blackslashes with foward slashes'
 418:     StrReplace = Replace(strFilePath,"\","/")
 419:     
 420:     'replace spaces with a % sign'
 421:     StrReplace = Replace(StrReplace," ","%")
 422:     
 423:     AddressOK = strReplace
 424:     
 425:     End Function
 426:    
 427: End Class
 428: '------------------------------------------------------------------------------'
 429:   
 430: '------------------------------------------------------------------------------'
 431:  'Object that will contain processing logic and the Text-Stream controls
 432:  
 433:  Class ProcessTextFiles
 434:     
 435:     'Global Variables
 436:     Private objRegexFilters 
 437:     'Declare the Instance Varibales'
 438:     Private Paragraph
 439:     Private Paragraph_Close
 440:     Private Div
 441:     Private Div_Close
 442:     Private Img
 443:     Private Img_Path 
 444:     Private Img_Open
 445:     Private Img_Close
 446:     Private LineBreak
 447:     Private HRule
 448:     Private objFSO 
 449:     Private ForReading
 450:       Private ForWriting
 451:       Private objRegex
 452:       Private objTextFileInterface
 453:       Private objImageFileInterface
 454:       Private objImageOutputClass
 455:       Private blnModeSelect
 456:           
 457:     'Class Initilize'
 458:     Private Sub Class_Initialize
 459:       Set objFSO           = CreateObject("Scripting.FileSystemObject")
 460:        HRule               = "<hr style="" height: 1px; width: 80%; border: none; background-color: #527393; color: #527393;"" /><br />"
 461:        Paragraph           ="<p>"
 462:        Paragraph_Close     ="</p>"
 463:        Div                 ="<div style=""font-size:14px"">"
 464:        Div_Close           ="</div>"
 465:        Img_Open            ="<img alt=""Image"" src=""file:///"
 466:        Img_Close           = """/>"
 467:        LineBreak           ="<hr style="" height: 1px; width: 80%; border: none; background-color: #527393; color: #527393;"" /><br />"
 468:        ForReading          = 1
 469:        ForWriting          = 2
 470:        blnModeSelect          = False
 471:       End Sub
 472:  
 473:     'Class Terminate'
 474:     Private Sub Class_Terminate
 475:        Set objRegexFilters = Nothing
 476:        Set TextFileInterface = Nothing
 477:        Set objImageOutputClass = Nothing
 478:        Set objImageFileInterface = Nothing
 479:     End Sub
 480:  
 481:  'Write Statements'
 482:    Public Property Set TextFileInterface(obj) 
 483:       Set objTextFileInterface  = obj 
 484:    End Property
 485:   
 486:    'Write Statements'
 487:    Public Property Set RegexFilters(obj) 
 488:       Set objRegexFilters  = obj 
 489:    End Property
 490:    
 491:    Public Property Let ModeSelect(ByVal bln)
 492:       blnModeSelect =bln
 493:    End Property
 494:    
 495:    'Write Statements'
 496:    Public Property Set ImageFileInterface(obj) 
 497:       Set objImageFileInterface  = obj 
 498:    End Property
 499:    
 500:    Public Property Set ImageOutputClass(obj)
 501:       Set objImageOutputClass = obj
 502:    End Property
 503:  
 504:  'Processing function will be the control loop and call other private individual functions
 505:  Public Function ProcessFiles(ByVal intNumb)
 506:   Dim intCount 
 507:   'loop through each file'
 508:   For intCount = 0 to (intNumb-1) 'ListCount value gives e.g 5 files, but index starts at 0 so only need length value of 0-4 = 5 files'
 509:     Call ReadFile(intCount) 'filenumber starts at 0'
 510:       If (blnModeSelect = True) Then
 511:         Call ProcessFile(intCount)
 512:       Else 
 513:         Call ProcessFileNormal(intCount)
 514:       End if
 515:     Call WriteFile(intCount)
 516:   Next
 517:  End Function
 518:  
 519:  Public Function ProcessFileNormal(intFileIndex)
 520:    Dim objTextFile, aryNewString(), retString
 521:    
 522:    'get the current object'
 523:     Set objTextFile = New  TextFile 
 524:     Call objTextFileInterface.ReturnTheObject(objTextFile,intFileIndex)
 525:    
 526:     'process code here'
 527:    If (Ubound(objTextFile.Read) > 0) Then
 528:       'get the current value'
 529:       retString = objTextFile.Read 'get the values'
 530:       'past into final'
 531:       objTextFile.Final = retString 
 532:       ProcessFileNormal = True
 533:    Else 
 534:     ProcessFileNormal = False
 535:    End if
 536:    
 537:    'close the objects'
 538:     Set objTextFile = Nothing
 539:  End Function
 540:   
 541:  Public Function ProcessFile(intFileIndex)
 542:   Dim theFile,intI,retstring, objTextFile, i, aryNewString() ,intMax
 543:   Dim intImageFileCount, intLoop, aryImagefilePath(),strCurrentTextFileName, strElement  
 544:   
 545:   'get the current object'
 546:   Set objTextFile = New  TextFile 
 547:   Call objTextFileInterface.ReturnTheObject(objTextFile,intFileIndex)
 548:   
 549:   'file:///C:/Users/Lewis/Documents/Air/071030_BLD%20301007.gif
 550:   'get the listcount from the image object'
 551:   '' intImageFileCount = objImageFileInterface.ListCount
 552:    'set the aryImagefilePath() file Size'
 553:    'ReDim aryImagefilePath(intImageFileCount-1) '0...count
 554:   
 555:   'get current file name of the current textfile
 556:    'strCurrentTextFileName =objTextFile.filename
 557:   
 558:   'loop through each image'
 559: '   For intLoop = 0 to intImageFileCount-1
 560: '       Dim strImageFilePath
 561: '       'call method that will return the file path of each image'
 562: '       strImageFilePath =objImageOutputClass.ReturnPathIfRelationExists(strCurrentTextFileName,intLoop)
 563: '       If (strImageFilePath <> empty) Then
 564: '         'filter the path'
 565: '         strImageFilePath = objRegexFilters.AddressOK(strImageFilePath)
 566: '         'set the path into the array'
 567: '         aryImagefilePath(intLoop) = strImageFilePath
 568: '       'msgbox(aryImagefilePath(intLoop))
 569: '       End if 
 570: '   Next
 571:   
 572:   If (Ubound(objTextFile.Read) > 0) Then
 573:       'process the file'
 574:       intI=0 'set the innerloop counter'
 575:       retstring = objTextFile.Read 'get the values'
 576:       ReDim aryNewString(0) 
 577:       intMax = False 
 578:             
 579:       While intMax = False
 580:      
 581:         If (i = 0) Then 'first line'
 582:           ReDim Preserve aryNewString(i) 
 583:           aryNewString(i) = Div
 584:             'insert images here'
 585:             i=(i+1) 'increment for the images'
 586:             
 587:             'loop to print images'
 588: '             For Each strElement in aryImagefilePath 
 589: '               If (strElement <> Empty) Then
 590: '                 ReDim Preserve aryNewString(i)
 591: '                 aryNewString(i) = Paragraph & Img_Open & strElement & Img_Close & Paragraph_Close
 592: '                 i=(i+1)
 593: '               End if
 594: '             Next
 595:             
 596:         Elseif (intI = (Ubound(retstring))) Then 'last line'
 597:           ReDim Preserve aryNewString(i)
 598:           aryNewString(i) = Div_Close
 599:           intMax= True 'last operation finish the loop'
 600:         Else 'normal line'
 601:           
 602:           If  (objRegexFilters.TestLineBreak(retstring(intI))) Then   'line break' 
 603:             ReDim Preserve aryNewString(i)
 604:             aryNewString(i) =  HRule
 605:             intI =intI +1
 606:           Else
 607:             ReDim Preserve aryNewString(i)
 608:             aryNewString(i) = Paragraph & retstring(intI) & Paragraph_Close 
 609:             intI =intI +1
 610:           End if
 611:           
 612:         End if
 613:         
 614:         i= i +1 'increment the count'
 615:      
 616:       WEnd 
 617:      
 618:      'return sucess'
 619:       ProcessFile =true 
 620:      'write result to the object'
 621:       objTextFile.Final = aryNewString  
 622:   Else
 623:       'file is empty'
 624:       ProcessFile =False
 625:   End if
 626:   'close the objects'
 627:   Set objTextFile = Nothing
 628:   End Function
 629:  
 630:   Private Function WriteFile(intFileNumber)
 631:     Dim objTextFile, retstring,intCount,thefile
 632:     
 633:     'get the current object'
 634:     Set objTextFile = New Textfile
 635:     Call objTextFileInterface.ReturnTheObject(objTextFile,intFileNumber)
 636:     
 637:     If (Ubound(objTextFile.Read) > 0) Then 'test if file is Not Empty'
 638:     
 639:       'Set the Fso object to open the file'
 640:       Set theFile = objFso.OpenTextFile(objTextFile.FileName, ForWriting, False)
 641:       'get the object to write'
 642:       retstring = objTextFile.Final
 643:       intCount = 0
 644:       For intCount =0 To Ubound(retstring)
 645:         theFile.WriteLine(retstring(intCount))
 646:         theFile.WriteBlankLines(1)
 647:       Next
 648:       'Reset the objects
 649:       'objTextFile = Nothing
 650:   
 651:     End if
 652:   
 653:   End Function
 654:  
 655:  'this function will read the textfile internal Method
 656:   Private Function ReadFile(intFileNumber) 
 657:     Dim theFile,intI,retstring(), objTextFile
 658:     
 659:     'get the current object'
 660:     Set objTextFile = New  TextFile 
 661:     Call objTextFileInterface.ReturnTheObject(objTextFile,intFileNumber)
 662:     'set the fso object to the textfile'
 663:     Set theFile = objFso.OpenTextFile(objTextFile.FileName, ForReading, False)
 664:     'read the file' 
 665:     intI=0 'set the innerloop counter'
 666:     ReDim retstring(0) 
 667:     Do While thefile.AtEndOfStream = False  'only execute if file not empty'
 668:      'read the file into an array
 669:      retstring(intI) = theFile.ReadLine() 'line stored in current intI value, if previous not incremented will replace empty line.
 670:                     If objRegexFilters.TestEmptyLine(retstring(intI)) Then 'regular expression applied
 671:                      intI=intI+1 ' incremented to move next line
 672:                            ReDim Preserve retstring(intI) 
 673:                     Else 'empty line value will not increment
 674:                   End IF 
 675:     Loop
 676:          
 677:      theFile.close()'close the file'
 678:      objTextFile.Read  = retstring 'set retstring to the object'
 679:      'Reset the Variables'
 680:      Set theFile = Nothing
 681:      Set objTextFile = Nothing
 682:    End Function
 683:     
 684:  
 685:  End Class
 686: '------------------------------------------------------------------------------'
 687:  'Defines the Image Files
 688: Class ImageFiles
 689:   
 690:   'Class Global Variables
 691:    Private strAssocTextFile
 692:   
 693:    'Class Initilize'
 694:    Private Sub Class_Initialize
 695:       strAssocTextFile = empty
 696:    End Sub
 697:  
 698: '    'Class Terminate'
 699: '    Private Sub Class_Terminate
 700: '        
 701: '    End Sub
 702:   'Declare the Instance Varibales'
 703:    Private strFileName
 704:    Private strFilePath  
 705:       
 706:   'Read Statements'
 707:   Public Property Get FileName
 708:     FileName = strFileName  
 709:   End Property
 710:   
 711:   Public Property Get FilePath
 712:     FilePath = strFilePath
 713:   End Property
 714:   
 715:   Public Property Get AssocTextFile
 716:     AssocTextFile = strAssocTextFile
 717:   End Property
 718:   
 719:   'Write Statements'
 720:    Public Property Let FileName(strFile) 
 721:      strFileName = strFile  
 722:    End Property
 723:   
 724:    Public Property Let FilePath(str)
 725:      strFilePath = str  
 726:    End Property   
 727:      
 728: '   Public Property Set RelatedTextFiles(obj)
 729: '     If TypeName(obj) <> "TextFile" Then
 730: '        Msgbox ("invalid Object Type")
 731: '     Else ' is correct object'
 732: '       Set objTextFiles = obj
 733: '     End if
 734: '   End Property
 735:  
 736:   Property Let AssocTextFile(str)
 737:     strAssocTextFile = str
 738:   End Property
 739:  
 740: End Class
 741: '------------------------------------------------------------------------------'
 742: 'build add data and control output to event handlers '
 743: Class ImageOutput
 744:   'Class Instance Constants'
 745:   Private objFSO
 746:   Private intDays 
 747:   Private strDirectory 
 748:   'Varaibles'
 749:   Private objImageFileList 
 750:     
 751:   'class Initiate'
 752:   Private Sub Class_Initialize
 753:       Set objFSO       = CreateObject("Scripting.FileSystemObject")
 754:       intDays          = -1
 755:       strDirectory     = "C:\Users\Lewis\Documents\Air\"
 756:   End Sub
 757:   'class Terminate'
 758:   Private Sub Class_Terminate
 759:       Set objFSO    = Nothing
 760:   End Sub 
 761:   
 762:     'Read Statements'
 763:   Public Property Get PrintDays
 764:    Days = intDays 
 765:   End Property
 766:     
 767:      
 768:   'returns an object from the file list' 
 769:   Public Property Get ReturnPath(ByVal strFname) 
 770:    Dim objImage 
 771:    Set objImage = New ImageFiles 
 772:    Call objImageFileList.DisplayEntry(objImage,strFname)
 773:    ReturnPath = Cstr(objImage.FilePath) 
 774:   End Property
 775:   
 776:   'Write Statements'
 777:    Public Property Set ImageLists(obj) 
 778:       Set objImageFileList  = obj 
 779:    End Property
 780:   
 781:   Public Function Days(number)
 782:     intDays = -number
 783:   End Function
 784:            
 785:   'Methods'
 786:   'used to intilize the datastructure'
 787:   Public Function PopulateDictionary()
 788:     Dim objFolder
 789:     Dim objFilesCollection,intFiles
 790:     Dim objImageFiles
 791:     Dim dteToday
 792:     Dim RegexTest
 793:     Dim temp
 794:         
 795:     'regex test'
 796:     Set RegexTest = New RegexFilters
 797:     
 798:     temp = intDays
 799:     'Set the date properties'
 800:     dteToday = DateAdd("d",temp,Date)
 801:      
 802:      'clear the list if any items in there'
 803:      If (objImageFileList.ListCount >= 0) Then
 804:       Call objImageFileList.ClearAll()
 805:      End if
 806:         
 807:     'populate the objects'
 808:     If (objFSO.FolderExists(strDirectory)) Then
 809:       Set objFolder= objFSO.GetFolder(strDirectory)
 810:       Set objFilesCollection = objFolder.Files
 811:       For Each intFiles in objFilesCollection 
 812:            If (intFiles.DateCreated >= dteToday)  Then
 813:               If (RegexTest.TestFileType(intFiles.Name)) Then
 814:                 'created the file object'
 815:                 Set objImageFiles = New ImageFiles
 816:                 
 817:                 'add properties to objImageFiles'
 818:                 objImageFiles.FileName = intFiles.Name
 819:                 objImageFiles.FilePath = strDirectory & intFiles.Name           
 820:                 'add the entry to data-structure'
 821:                 objImageFileList.AddEntry(objImageFiles)
 822:                 Set objImageFiles = Nothing 'reset for next instance'
 823:               End if
 824:          End if
 825:       Next
 826:       PopulateDictionary = True
 827:     Else
 828:       PopulateDictionary = False
 829:     End if
 830:   End Function
 831:   
 832:   'return an array of all image objects'
 833:   Public Function ReturnArray()
 834:     'varaibles'
 835:     Dim aryImageFiles(), intCount, i
 836:      i=0 'set the inner loop counter default'
 837:        
 838:     'populate the array'
 839:     For intCount =0 to objImageFileList.ListCount 
 840:       'Create and ImageFiles object'
 841:       Dim objImage
 842:       Set objImage = New ImageFiles
 843:       'call the function to Set it'     
 844:       Call objImageFileList.MatchIndex(objImage,intCount) 'reterive the object'
 845:       
 846:       'Test if assocatiions are not null'
 847:       If (IsEmpty(objImage.AssocTextFile))  Then 
 848:         'resize the array'
 849:         ReDim Preserve aryImageFiles(i) 're-size the array' 
 850:         aryImageFiles(i) = objImage.FileName 'set the array vale as the image file name'
 851:         i=  (i+1)
 852:       End if 
 853:       
 854:       'reset the object'
 855:       Set objImage = Nothing
 856:     Next
 857:   
 858:     'return statement'
 859:     ReturnArray = aryImageFiles  
 860:   End Function
 861:  
 862:   'return an array of all image objects'
 863:   Public Function ReturnShortArray(strConditon)
 864:     'varaibles'
 865:     Dim aryImageFiles(), intCount ,i  
 866:      'msgbox(objImageFileList.ListCount)
 867:       i = 0
 868:            
 869:     'populate the array'
 870:     For intCount =0 to (objImageFileList.ListCount -1) 
 871:       'Create and ImageFiles object'
 872:       Dim objImage
 873:       Set objImage = New ImageFiles
 874:       'call the function to Set it'     
 875:       Call objImageFileList.MatchIndex(objImage,intCount) 'reterive the object'
 876:       
 877:       'Test if assocatiions are not null'
 878:       'Set the Inner Counter'
 879:       
 880:       
 881:       If (objImage.AssocTextFile = strConditon)  Then 
 882:         'resize the array'
 883:         ReDim Preserve aryImageFiles(i) 're-size the array' 
 884:         aryImageFiles(i) = objImage.FileName 'set the array vale as the image file name'
 885:         i = (i + 1) 'increment the counter'
 886:       End if 
 887:       
 888:       'reset the object'
 889:       Set objImage = Nothing
 890:      Next
 891:     
 892:     If (i > 0) Then  
 893:       'return statement'
 894:       ReturnShortArray = aryImageFiles
 895:     Else
 896:       ReturnShortArray = empty
 897:     End if   
 898:   End Function
 899:  
 900:    'set a varaible or remove it'
 901:   Public Function BindTextFileObject(strImgFileName,strText)
 902:     'access the dict reterive the object'
 903:     Dim objImage
 904:     Set objImage = New ImageFiles
 905:     Call objImageFileList.DisplayEntry(objImage,strImgFileName)
 906:     'msgbox("dddddd")
 907:     'change the object'
 908:     If typeName(objImage) = "ImageFiles" Then 
 909:       objImage.AssocTextFile = strText
 910:       BindTextFileObject = true
 911:        
 912:     Else 
 913:       BindTextFileObject = False
 914:     End if
 915:     
 916:     'Set objImage = Nothing 'reset the object'
 917:   End Function
 918:   
 919:     
 920:   Public Function UNBindTextFileObject(strImageFileName)
 921:     'access the dict reterive the object'
 922:     Dim objImage
 923:     Set objImage = New ImageFiles
 924:     Call objImageFileList.DisplayEntry(objImage,strImageFileName)
 925:     
 926:     'change the object'
 927:     objImage.AssocTextFile = empty
 928:     
 929:     'Set objImage = Nothing 'reset the object'
 930:   End Function
 931:   
 932:   Public Function ReturnPathIfRelationExists(strTextFileName,intIndex)
 933:     Dim objImage, index
 934:     Set objImage = New ImageFiles
 935:     'set the current object reference'
 936:     Call objImageFileList.MatchIndex(objImage,intIndex)
 937:     If (objImage.AssocTextFile = strTextFileName) Then
 938:       'return value relationExists'  
 939:       ReturnPathIfRelationExists = Cstr(objImage.FilePath)  
 940:     Else
 941:       ReturnPathIfRelationExists = Empty
 942:     End if
 943:     'remove the objects'
 944:     'objImage = Nothing
 945:   End Function
 946: End Class
 947: '------------------------------------------------------------------------------'
 948: </script>
 949: <script type="text/vbscript">
 950: '**********************Global objects******************************************'
 951: Dim objCreate 'CreateOpenTextFile object '
 952: Dim objFLists 
 953: Dim ImageOutputArray, ImageFilesDataStructure
 954: Dim objProcessTextFiles
 955: Dim WeeklyImageOutputArray,WeeklyImageFilesDataStructure
 956:  
 957: 'Create the Files'
 958: Set objCreate = New CreateOpenTextFile
 959: Set objFLists = New FileList 'created a new file-dictionary'
 960: Set objCreate.FileLists = objFLists  
 961: Set ImageOutputArray = New ImageOutput
 962: 'send the datastructures to the ImageOutputArray class'
 963: Set ImageFilesDataStructure = New FileList 'same structure used previously new instance'
 964: Set ImageOutputArray.ImageLists   = ImageFilesDataStructure 
 965: 'Process class'
 966: Set objProcessTextFiles = New ProcessTextFiles
 967: Set objProcessTextFiles.TextFileInterface = objCreate
 968: Set objProcessTextFiles.RegexFilters = New RegexFilters
 969: Set objProcessTextFiles.ImageFileInterface = ImageFilesDataStructure
 970: Set objProcessTextFiles.ImageOutputClass = ImageOutputArray 
 971:  
 972: 'weekly Images'
 973: Set WeeklyImageOutputArray = New ImageOutput
 974: 'send the datastructures to the ImageOutputArray class'
 975: Set WeeklyImageFilesDataStructure = New FileList 'same structure used previously new instance'
 976: Set WeeklyImageOutputArray.ImageLists   = WeeklyImageFilesDataStructure
 977:  
 978: 'refresh the child box'
 979: Public Sub RefreshChild ()
 980:    Dim intCurrentFileIndex
 981:    'get the current File Index'
 982:    intCurrentFileIndex = objCreate.CurrentFileIndex
 983:    strTextFileName =  objCreate.ActiveFileName
 984:       
 985:       'Reset the child master'
 986:     If (lstChild.length > 0) Then
 987:       dim ii
 988:       ii = lstChild.length -1  
 989:       For j = 0 to ii
 990:         Call lstChild.remove(lstChild.length-1)
 991:       Next
 992:     End if
 993:     
 994:     'get the filename from the slected image '
 995:     Dim aryImageArray,i
 996:     aryImageArray = ImageOutputArray.ReturnShortArray(strTextFileName) 
 997:       If (typename(aryImageArray) <> "Empty") Then
 998:           For i = 0 to (Ubound(aryImageArray)) 'length ie next free element -1 to get actual' 
 999:             Dim y 
1000:             Set y = document.createElement("option")
1001:             y.text = aryImageArray(i)
1002:             Call lstChild.add(y)
1003:             Set y = Nothing
1004:          Next
1005:      End if
1006: End Sub
1007:  
1008: Sub MasterFill ()
1009:   'get an array'
1010:     Dim aryImageArray,i,j,aryOptions
1011:     aryImageArray = ImageOutputArray.ReturnArray() 
1012:     
1013:     'Reset the First master'
1014:     If (lstMaster.length > 0) Then
1015:       dim ii
1016:       ii = lstMaster.length -1  
1017:       For j = 0 to ii
1018:         Call lstMaster.remove(lstMaster.length-1)
1019:       Next
1020:     End if
1021:     
1022:     're-fill the List'    
1023:     for i =0 to (Ubound(aryImageArray)-1) 'length ie next free element -1 to get actual' 
1024:     Dim y 
1025:      Set y = document.createElement("option")
1026:      y.text = aryImageArray(i)
1027:      Call lstMaster.add(y)
1028:      Set y = nothing
1029:     Next
1030: End Sub
1031: '*********************Event Handlers*******************************************'
1032: 'the onload event handler in the body'
1033: Public Sub NewHTA()
1034:   'hide the frame onload'
1035:   WeeklyFrame.style.display = "none"
1036:   Call WeeklyImages(1) 'default is One'
1037: End Sub
1038:  
1039: Sub Create()
1040:   'created varables
1041:   Dim intNumber 'number of files' 
1042:   
1043:   'get the number of files from the input filed'
1044:   intNumber = NumInputDataFiles.value 
1045:   If (objCreate.CreateFiles(intNumber)) Then
1046:     diditwork_step1.InnerHTML = "Successful" 
1047:   Else
1048:     diditwork_step1.InnerHTML = "Failed To Create File"
1049:   End if 
1050:   
1051:   'disbale/enable buttons'
1052:   btnPreviousFilebutton.disabled = "false" 'started at last number need to move to previous first
1053:   btnOpenFile.Disabled = "False"
1054:   btnNextFile.Disabled = "False"
1055:   btnProcessCollection.disabled="False"
1056:   filepath.InnerHtml = "Article" & intNumber &".txt"
1057:   btnRemoveImage.Disabled = "False"
1058:   btnAddImage.Disabled = "False"
1059:   btnIncreaseTime.disabled = "False"
1060:   
1061:   'set the state Filds'
1062:   'numfiles.value = intNumber 'max number of Files'
1063:   'numFilesTwo.value = intNumber 'first article to max_Number'
1064:   
1065:   'bind the image selection boxes'
1066:      If (ImageOutputArray.PopulateDictionary()) Then
1067:        Call MasterFill ()
1068:      Else 
1069:     Msgbox("Image-Binding Failed")
1070:     End if
1071: End Sub
1072:  
1073: 'event handler to open the file'
1074: Sub OpenFile()
1075:    objCreate.Open()
1076: End sub
1077:  
1078: 'event handerls for btnNext'
1079: Sub Nextbutton() 
1080:  'only change the file path if true
1081:   If  (objCreate.NextFile()) Then
1082:     filepath.innerHTML = "Article"& objCreate.CurrentFileIndex &".txt"
1083:     If (btnPreviousFilebutton.disabled = "True")  then
1084:         btnPreviousFilebutton.disabled = "False"
1085:     End if 
1086:   Else
1087:     btnNextFile.Disabled = "True" 'so cant click again
1088:     msgbox("no Files")
1089:   End if
1090:   
1091:   'reset the master and child Ray'
1092:   Call MasterFill ()
1093:   'reset the Child'
1094:   Call RefreshChild ()
1095:  
1096: End Sub 
1097:  
1098: 'eventHandler for the btnPrevious'
1099: Sub PrevButton() 
1100:  'only change the file path if true
1101:   If  (objCreate.PrevFile()) Then
1102:     filepath.innerHTML = "Article"& objCreate.CurrentFileIndex &".txt"
1103:     If (btnNextFile.Disabled = "True") Then
1104:         btnNextFile.Disabled = "False"
1105:     End if 
1106:   Else
1107:     msgbox("no Files") 
1108:     btnPreviousFilebutton.disabled = "True"
1109:   End if
1110:  
1111:   'reset the master and child Ray'
1112:   Call MasterFill ()
1113:   'reset the Child'
1114:   Call RefreshChild ()
1115:   
1116: End Sub
1117:  
1118: 'Event Handler for the btnCleanupFilesButton'
1119: Sub ProcessCollection()
1120: Call objProcessTextFiles.ProcessFiles(objFLists.ListCount)
1121:  
1122: btnCleanupFilesButton.disabled ="False" 
1123: btnProcessCollection.disabled = "true"
1124: End Sub
1125:  
1126:  
1127: Sub CleanFiles()
1128:    If (objCreate.DeleteTheFiles())Then
1129:       btnCleanupFilesButton.disabled ="True"
1130:    Else
1131:       MsgBox ("Failed to Delete Files")
1132:   End If
1133:   'refresh the page'
1134:   Call window.location.reload()
1135: End Sub
1136:  
1137: 'event hander for the btnBindImage'
1138: Sub BindImage()
1139:   'get the current Textfile'
1140:   Dim intCurrentImgIndex,strFileName,strFName,intSelectedIndex
1141:   intCurrentImgIndex =CInt(objCreate.CurrentFileIndex)
1142:   
1143:   'Set objTextFile = New TextFile
1144:   strTextFileName = objCreate.ReturnObject(intCurrentImgIndex-1)
1145:   
1146:   'get slected image file'
1147:    intSelectedIndex = lstMaster.selectedIndex
1148:    
1149:   If (intSelectedIndex >=0) Then
1150:      strImageFName= lstMaster.options(intSelectedIndex).text 
1151:     'msgbox(strImageFName & strTextFileName)
1152:     'set the object properties'
1153:     If (ImageOutputArray.BindTextFileObject(strImageFName,strTextFileName)) Then
1154:      'refresh the dam thing'
1155:      'Reset the First master'
1156:       If (lstChild.length > 0) Then
1157:         dim ii
1158:         ii = lstChild.length -1  
1159:         For j = 0 to ii
1160:           Call lstChild.remove(lstChild.length-1)
1161:         Next
1162:       End if
1163:      'get the filename from the slected image '
1164:       Dim aryImageArray,i
1165:       aryImageArray = ImageOutputArray.ReturnShortArray(strTextFileName) 
1166:       For i = 0 to (Ubound(aryImageArray)) 'length ie next free element -1 to get actual' 
1167:          Dim y 
1168:          Set y = document.createElement("option")
1169:          y.text = aryImageArray(i)
1170:          Call lstChild.add(y)
1171:          Set y = Nothing
1172:       Next
1173:       'refersh the master array'
1174:         Call MasterFill()
1175:     Else
1176:     msgbox ("binding failed")
1177:     End If
1178:   End if
1179: End Sub 
1180:  
1181: 'Bind the currently selected image to the preview'
1182: Sub ImagePreview(text)
1183:     Dim strFName,intSelectedIndex,strFilePath
1184:     'check for the right list'
1185:     If (text = "Master") Then
1186:         'get the selected item'
1187:         intSelectedIndex = lstMaster.selectedIndex
1188:         If (intSelectedIndex >= 0 ) Then
1189:             strFName = lstMaster.options(intSelectedIndex).text
1190:         End if
1191:     Else
1192:         'get the selected item'
1193:         intSelectedIndex = lstChild.selectedIndex
1194:         If (intSelectedIndex >= 0 ) Then
1195:            strFName = lstChild.options(intSelectedIndex).text
1196:         End if
1197:     End if
1198:     If (strFName <> empty) Then 
1199:         'get the full path' 
1200:         strFPath = ImageOutputArray.ReturnPath(strFName)
1201:         'set the preview frame properties'
1202:         imgPreview.src =strFPath
1203:     End if
1204: End Sub
1205:  
1206: 'event handler for the btnUnbind 
1207: Public Sub UnBindImage()
1208:   Dim intSelectedIndex,strImageFName
1209:   'get slected image file'
1210:    intSelectedIndex = lstChild.selectedIndex
1211:    If (intSelectedIndex >= 0 ) Then 'if not valid dont call it'
1212:       strImageFName= lstChild.options(intSelectedIndex).text 
1213:       Call ImageOutputArray.UNBindTextFileObject(strImageFName)  
1214:       'refersh the master array'
1215:       Call MasterFill()
1216:       'refresh the child'
1217:       Call RefreshChild()
1218:   End if
1219: End Sub
1220:  
1221:  
1222: Public Sub ChangeTimeWeekly()
1223: Dim intNumDays
1224:    'get the value from the inputbox'
1225:    intNumDays = txtnumdaysWeekly.value
1226:    intNumDays = Cint(intNumDays)
1227:    intNumDays = abs(intNumDays)
1228:   'refresh the screen'   
1229:   Call WeeklyImages(intNumDays)    
1230: End sub
1231:  
1232: 'event handler for the btnChangeTime'
1233: Public Sub ChangeTime()
1234:    Dim intNumDays
1235:    
1236:    'get the value from the inputbox'
1237:    intNumDays = txtnumdays.value
1238:    intNumDays = Cint(intNumDays)
1239:    intNumDays = abs(intNumDays)
1240:    'msgbox(typename(intNumDays))
1241:    
1242:    
1243:    'validate the value  ie not negative and is a number <365
1244:   If (IsNumeric(intNumDays)) Then
1245:       
1246:       'call the method to empty the imagefile directory'
1247:       Call ImageFilesDataStructure.ClearAll()
1248:       
1249:       'set the days variable'
1250:       Call ImageOutputArray.Days(intNumDays)
1251:                        
1252:       'populate the dictionary'
1253:       Call ImageOutputArray.PopulateDictionary()
1254:       
1255:       'refersh the master array'
1256:       Call MasterFill()
1257:       'refresh the child'
1258:       Call RefreshChild()
1259:   Else
1260:     Msgbox ("Invalid Number")  
1261:   End if
1262: End Sub
1263:  
1264: 'event handers for the tabs '
1265: Public Sub SwitchWeekly ()
1266:   NormalFrame.style.display ="none"
1267:   WeeklyFrame.style.display = "block"
1268: End Sub
1269:  
1270: Public Sub SwitchNormal ()
1271:   WeeklyFrame.style.display ="none"
1272:   NormalFrame.style.display ="block"
1273: End Sub
1274:  
1275: 'event handler for the chkMode checkbox'
1276: Public Sub ModeSwitch()
1277:  If (chkMode.checked = True) Then  'non-markp mode
1278:   objProcessTextFiles.ModeSelect = False
1279:  Else     ' Markup Mode'
1280:   objProcessTextFiles.ModeSelect = True
1281:  End if
1282: End Sub
1283:  
1284: '>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>..Event Handlers for second Frame..>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>'
1285:  
1286: Public Sub WeeklyImages(days)
1287:   'declare the varaibles'
1288:   Dim strFPath,intCount,i,thefilepath,FName
1289:   Dim objImageFile, temptext, testobject,NameNode,ButtonNode,temp
1290:    
1291:   'set the number of days'
1292:   Call WeeklyImageOutputArray.Days(days) 
1293:   
1294:   'populate the dictionary'
1295:   Call WeeklyImageOutputArray.PopulateDictionary()
1296:               
1297:   'Bind the currently selected image to the preview'
1298:   intCount = WeeklyImageFilesDataStructure.ListCount 'get count from the file list'
1299:   'use the match index method to return the image'
1300:    For i = 0 to intCount-1   
1301:        Set objImageFile = New ImageFiles
1302:        Call WeeklyImageFilesDataStructure.MatchIndex(objImageFile,i)
1303:        thefilepath= objImageFile.FilePath
1304:        FName= objImageFile.FileName
1305:        
1306:        'define button node'
1307: '        Set ImageNode  = document.createElement("img")
1308: '        Set NameNode   = document.createElement("div")
1309: '        Set ButtonNode = document.createElement("button")
1310: '                    
1311: '        With WeeklyFrame.appendChild(NameNode)
1312: '                  .innerHTML      =FName   
1313: '        End With
1314: '           
1315: '        With WeeklyFrame.appendChild(ImageNode)
1316: '        Call    .setAttribute("src", thefilepath&FileName)
1317: '                
1318: '        End With
1319:        
1320:        'With WeeklyFrame.appendChild(ImageNode)
1321:        
1322:        'End With
1323:        
1324:        temptext = temptext & "<img style=""margin:10px 20px 10px 20px"" src="""&thefilepath&FileName&""" />"
1325:        WeeklyFrame.innerHTML = tempText
1326:    Next
1327:       temptext = empty 'reset just incase'
1328: End Sub

 

Screen-Shots

 

blog_230408_01 blog_230408_02

Blog_230408_03 blog_230408_04

blog_230408_05

 

 

Download: LineRemoverClass.hta (48.81 kb)

 

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Some Screen Mockups

Thursday, 21 February 2008 14:50 by Frimbob

I have been doing some designing for the office add-in project, I have done a couple of mock-up interfaces with Viso 2007, This add-in will in a nutshell convert a articles in a document to html for easy transmission into the web-site.

Once the user clicks the button to call up a wizard which is a number of steps.


Introduction


gif_1

A simple introduction screen with some instructions


Step 1


gif_2

The code will compile a list of found articles on the current page and will allow the user to select which article to process.


Step 2


gif_3

The interface servers 2 purposes, the first to set the image folder if its not already correct and the second is to select which articles have need of image.


Step 3


gif_5

This interface is only shown for each article that was selected in Step 2, there is a lit of images which can be selected with a preview pane.


Final


gif_6

Click finish to process :-)

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Tags:   , ,
Categories:   Projects
Actions:   E-mail | Permalink | Comments (519) | Comment RSSRSS comment feed

Research Results : Number 1

Thursday, 14 February 2008 11:21 by Frimbob

The Good News:

Well I think I have solved the problem of weather I can read  a web page into a word document directly, I found that the .Net Frame work has a WebRequest Class.

Quickly using the code found in the MSDN article and adding word-specific print code, I can now import a web-page directly.

Code:

 [code]

         ' Create a request for the URL.
        Dim request As WebRequest = WebRequest.Create("
http://www.aireview.com.au/index.php?act=view&catid=8&id=7944")
        ' If required by the server, set the credentials.
        'request.Credentials = CredentialCache.DefaultCredentials
        ' Get the response.
        Dim response As WebResponse = request.GetResponse()
        ' Display the status.
        'Console.WriteLine(CType(response, HttpWebResponse).StatusDescription)
        ' Get the stream containing content returned by the server.
        Dim dataStream As Stream = response.GetResponseStream()
        ' Open the stream using a StreamReader for easy access.
        Dim reader As New StreamReader(dataStream)
        ' Read the content.
        Dim responseFromServer As String = reader.ReadToEnd()
        ' Display the content.
        Dim r As Word.Range = Me.Application.ActiveDocument.Range
        r.Text = responseFromServer.Length
        'Console.WriteLine(responseFromServer)
        ' Clean up the streams and the response.
        reader.Close()
        response.Close()

 [/code]

The Problem:

Well to sum it up It doesn't work with the www.aireview.com.au web-site.

It appears that the stream that arrives only contains 69 characters, I am guessing that the stream is taken before the PHP script has finished queuing the database.

One problem fixed on Big Problem Found.

More Research is Needed.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Tags:   ,
Categories:   Projects
Actions:   E-mail | Permalink | Comments (236) | Comment RSSRSS comment feed

Project: Office Add-In

Thursday, 14 February 2008 09:37 by Frimbob

Aim:

To build and office Add-In using VSTO 2005SE to build a weekly magazine from   HTML articles  and to transform daily articles from word into html for posting on the web-site.

Time Frame:

6 Months, with university emending I would expect at least to the mid-year before any significant gain are produced.

Project Description:

The project is broken into two main groups, the collection of classes that will transform HTML into the template for the Weekly Magazine. The second group of classes that will turn the daily articles in word into html for posting.

Aims for the First Group

  • Read the Html from a supplied URI and copy on the reverent html for the story.
  • Interfaces to gather the URI and any images for the Article.
  • Apply select styles from the template to the transformed text.
  • Either retrieve the html pages or dynamically accept a URI list and dynamically construct a script to retrieve them.
  • Allow Folder to be browsed for images.
  • Include bold HTML as bold Text as well as other generic formatting tags.
  • Split the Articles into two or more groups.

Aims for the Second Group

  • Create and XML Schema for a template
  • Design output the will allow easy access to the headline,images and the article
  • Wont automate the upload process, no database access and the text-pad used with the CMS is a java-applet.

Research:

  • VB.net and office HTML processing methods and external libraries.
  • Can VB accept a web-pages source into the text reader without first saving the page. If not can a scripting language be used to download the html pages from a dynamically constructed list of URI's.
  • Are there Similar Products available and are there any bits of information that could be useful for this project.
  • Word Markup and Object model.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Tags:   , ,
Categories:   Projects
Actions:   E-mail | Permalink | Comments (593) | Comment RSSRSS comment feed