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