Advertisement
| 08.09.2008 at 08:47PM PDT, ID: 23635711 |
|
[x]
Attachment Details
|
||
|
[x]
The Solution Rating System
|
||
With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.
Your Input Matters If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support. Thank you! |
||
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: 167: 168: 169: 170: 171: 172: 173: 174: 175: 176: 177: 178: 179: 180: 181: 182: 183: 184: 185: 186: 187: 188: 189: 190: 191: 192: 193: 194: 195: 196: 197: 198: 199: 200: 201: 202: 203: 204: 205: 206: 207: 208: 209: 210: 211: 212: 213: 214: 215: 216: 217: 218: 219: 220: 221: 222: 223: 224: 225: 226: 227: 228: 229: 230: 231: 232: 233: 234: 235: 236: 237: 238: 239: 240: 241: 242: 243: 244: 245: 246: 247: 248: 249: 250: 251: 252: 253: 254: 255: 256: 257: 258: 259: 260: 261: 262: 263: 264: 265: 266: 267: 268: 269: 270: 271: 272: 273: 274: 275: 276: 277: 278: 279: 280: 281: 282: 283: 284: 285: 286: 287: 288: 289: 290: 291: 292: 293: 294: 295: 296: 297: 298: 299: 300: 301: 302: 303: 304: 305: 306: 307: 308: 309: 310: 311: 312: 313: 314: 315: 316: 317: 318: 319: 320: 321: 322: 323: 324: 325: 326: 327: 328: 329: 330: 331: 332: 333: 334: 335: 336: 337: 338: 339: 340: 341: 342: 343: 344: 345: 346: 347: 348: 349: 350: 351: 352: 353: 354: 355: 356: 357: 358: 359: 360: 361: 362: 363: 364: 365: 366: 367: 368: 369: 370: 371: 372: 373: 374: 375: 376: 377: 378: 379: 380: 381: 382: 383: 384: 385: 386: 387: 388: 389: 390: 391: 392: 393: 394: 395: 396: 397: 398: 399: 400: 401: 402: 403: 404: 405: 406: 407: 408: 409: 410: 411: 412: 413: 414: 415: 416: 417: 418: 419: 420: 421: 422: 423: 424: 425: 426: 427: 428: 429: 430: 431: 432: 433: 434: 435: 436: 437: 438: 439: 440: 441: 442: 443: 444: 445: 446: 447: 448: 449: 450: 451: 452: 453: 454: 455: 456: 457: 458: 459: 460: 461: 462: 463: 464: 465: 466: 467: 468: 469: 470: 471: 472: 473: 474: 475: 476: 477: 478: 479: 480: 481: 482: 483: 484: 485: 486: 487: 488: 489: 490: 491: 492: 493: 494: 495: 496: 497: 498: 499: 500: 501: 502: 503: 504: 505: 506: 507: 508: 509: 510: 511: 512: 513: 514: 515: 516: 517: 518: 519: 520: 521: 522: 523: 524: 525: 526: 527: 528: 529: 530: 531: 532: 533: 534: 535: 536: 537: 538: 539: 540: 541: 542: 543: 544: 545: 546: 547: 548: 549: 550: 551: |
using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.ComponentModel;
using System.Collections;
using System.Collections.Specialized;
using System.Text;
namespace mm_date
{
/// <summary>
/// DatePicker - Generates drop down select objects for date selection
/// Client side javascript ensures only valid date returned.
/// </summary>
[DefaultProperty("Text"),
ToolboxData("<{0}:datepicker runat=server></{0}:datepicker>")]
public class datepicker : System.Web.UI.WebControls.WebControl, System.Web.UI.IPostBackDataHandler
{
//Declarations
private int begyear = 1980;
private int endyear = System.DateTime.Today.Year;
private int date_mode = 1;
private int form_level = 0;
private DateTime initial_date = System.DateTime.Today;
private int sel_month = System.DateTime.Today.Month;
private int sel_day = System.DateTime.Today.Day;
private int sel_year = System.DateTime.Today.Year;
private int picked_month = 0;
private int picked_day = 0;
private int picked_year = 0;
private string selected_date;
private string sel_date_convert;
private DateTime date_picked;
private string control = "Datepicker";
//Define Properties
//Control Release & About
[Bindable(false),
Category("About"),
DefaultValue(""),
Description("Control: Datepicker\n" +
"Version: Ver 1.01 - 12/01/2003\n" +
"Author: Michael McLain\n" +
"Desc: Date dropdown selection control\n")]
public string Control
{
get
{
return control;
}
set
{
control = value;
}
}
//Posted Date Returned
[Bindable(true),
Category("Returned Values"),
DefaultValue(""),
Description("Returned date selected (string)")]
public string Selected_Date
{
get
{
return selected_date;
}
set
{
selected_date = value;
}
}
public bool LoadPostData(String postDataKey, NameValueCollection values)
{
selected_date = values[this.UniqueID.ToString()];
sel_date_convert = values[this.UniqueID.ToString() + "_conv"];
date_picked = System.DateTime.Parse(sel_date_convert).Date;
Month = date_picked.Month;
Day = date_picked.Day;
Year = date_picked.Year;
if (this.EnableViewState)
{
this.initial_date = date_picked;
}
return false;
}
public void RaisePostDataChangedEvent()
{
}
//Returned date in datetime format
[Bindable(true),
Category("Returned Values"),
DefaultValue(""),
Description("Returned date selected (datetime)")]
public DateTime Date_Picked
{
get
{
return date_picked;
}
set
{
date_picked = value;
}
}
//Returned Month
[Bindable(false),
Category("Returned Values"),
DefaultValue(""),
Description("Returned month selected (int)")]
public int Month
{
get
{
return picked_month;
}
set
{
picked_month = value;
}
}
//Returned Day
[Bindable(false),
Category("Returned Values"),
DefaultValue(""),
Description("Returned day selected (int)")]
public int Day
{
get
{
return picked_day;
}
set
{
picked_day = value;
}
}
//Returned year
[Bindable(false),
Category("Returned Values"),
DefaultValue(""),
Description("Returned year selected (int)")]
public int Year
{
get
{
return picked_year;
}
set
{
picked_year = value;
}
}
//Begin Year
[Bindable(true),
Category("Setup Values"),
DefaultValue(""),
Description("Beginning Year Select Range")]
public int YearRange_Start
{
get
{
return begyear;
}
set
{
begyear = value;
}
}
//End Year
[Bindable(true),
Category("Setup Values"),
DefaultValue(""),
Description("Ending Year Select Range")]
public int YearRange_End
{
get
{
return endyear;
}
set
{
endyear = value;
}
}
//Initial date selected
[Bindable(true),
Category("Setup Values"),
DefaultValue(""),
Description("Initial selected date")]
public DateTime Initial_Date
{
get
{
return initial_date;
}
set
{
initial_date = value;
}
}
//Date format returned (in string format)
//Included for backward compatibility to Classic ASP version
[Bindable(true),
Category("Setup Values"),
DefaultValue(""),
Description("Date format returned in (Selected_Date).\n1 - MM/DD/YYYY\n2 - DD/MM/YYYY\n3 - YYYYMMDD\n4 - universal format")]
public int Date_Mode
{
get
{
return date_mode;
}
set
{
date_mode = value;
}
}
//Form level index to allow handling multiple forms per page.
[Bindable(false),
Category("Setup Values"),
DefaultValue(""),
Description("Document form index level")]
public int Form_Level
{
get
{
return form_level;
}
set
{
form_level = value;
}
}
/// <summary>
/// Render this control to the output parameter specified.
/// </summary>
/// <param name="output"> The HTML writer to write out to </param>
protected override void Render(HtmlTextWriter output)
{
string cid = this.UniqueID.ToString();
string isSelected = "";
string docref = "document.forms[" + this.form_level.ToString() + "]." + cid;
string onchg = " onChange=\"tg_mm_setdays('" + docref + "'," + date_mode.ToString() + ")\"";
string objinit = "<script language=javascript>tg_mm_setdays('" + docref + "'," + date_mode.ToString() + ")</script>";
//Build control style
string ostyle = "";
string c_ostyle = "";
string ostylevalue = "";
int stylecount = this.Style.Count;
foreach (string stmp in this.Style.Keys)
{
ostylevalue = this.Style[stmp].ToString();
c_ostyle = c_ostyle + stmp + ": " + ostylevalue + "; ";
}
StringBuilder s = new StringBuilder();
//Set component container if applied style
//Container used to handle grid layout mode
if (c_ostyle != "")
{
s.Append("<div style=\"" + c_ostyle + "\">");
}
//Build select drop down styles
string color = "";
if (!this.ForeColor.IsEmpty)
{
color = this.ForeColor.Name;
if (color != "")
{
if (!this.ForeColor.IsNamedColor && !this.ForeColor.IsSystemColor)
{
color = "#" + color.Substring(2, 6);
}
}
}
string backcolor = "";
if (!this.BackColor.IsEmpty)
{
backcolor = this.BackColor.Name;
if (backcolor != "")
{
if (!this.BackColor.IsNamedColor && !this.BackColor.IsSystemColor)
{
backcolor = "#" + backcolor.Substring(2, 6);
}
}
}
string fontname = this.Font.Name;
string fontsize = this.Font.Size.ToString();
string cssclass = this.CssClass;
bool fontstyle = this.Font.Italic;
bool fontbold = this.Font.Bold;
bool underline = this.Font.Underline;
bool overline = this.Font.Overline;
bool strikeout = this.Font.Strikeout;
string textdecoration = "";
//TEXT-DECORATION: underline overline line-through
if (underline || overline || strikeout)
{
textdecoration = "TEXT-DECORATION: ";
if (underline)
{
textdecoration = textdecoration + "underline ";
}
if (overline)
{
textdecoration = textdecoration + "overline ";
}
if (strikeout)
{
textdecoration = textdecoration + "strikeout ";
}
textdecoration = textdecoration + ";";
}
if (cssclass != "")
{
cssclass = " class=\"" + cssclass + "\"";
}
ostyle = " style=\"";
if (fontname != "")
{
ostyle = ostyle + "FONT-FAMILY: " + fontname + ";";
}
if (fontsize != "")
{
ostyle = ostyle + "FONT-SIZE: " + fontsize + ";";
}
if (fontstyle)
{
ostyle = ostyle + "FONT-STYLE: italic;";
}
if (fontbold)
{
ostyle = ostyle + "FONT-WEIGHT: bold;";
}
if (color != "")
{
ostyle = ostyle + "COLOR: " + color + ";";
}
if (backcolor != "")
{
ostyle = ostyle + "BACKGROUND-COLOR: " + backcolor + ";";
}
if (textdecoration != "")
{
ostyle = ostyle + textdecoration;
}
ostyle = ostyle + "\"" + cssclass;
//Build Month Dropdown
sel_month = initial_date.Month;
sel_day = initial_date.Day;
sel_year = initial_date.Year;
//Determine days in Month
DateTime wrkdate = initial_date.Date;
int daysinmonth = 0;
while (sel_month == wrkdate.Month)
{
daysinmonth = wrkdate.Day;
wrkdate = wrkdate.AddDays(1);
}
s.Append("\n<select name=\"" + cid + "_month\"" + onchg + ostyle + ">\n");
isSelected = checkselected(1, sel_month);
s.Append("<option value=1" + isSelected + ">Jan</option>\n");
isSelected = checkselected(2, sel_month);
s.Append("<option value=2" + isSelected + ">Feb</option>\n");
isSelected = checkselected(3, sel_month);
s.Append("<option value=3" + isSelected + ">Mar</option>\n");
isSelected = checkselected(4, sel_month);
s.Append("<option value=4" + isSelected + ">Apr</option>\n");
isSelected = checkselected(5, sel_month);
s.Append("<option value=5" + isSelected + ">May</option>\n");
isSelected = checkselected(6, sel_month);
s.Append("<option value=6" + isSelected + ">Jun</option>\n");
isSelected = checkselected(7, sel_month);
s.Append("<option value=7" + isSelected + ">Jul</option>\n");
isSelected = checkselected(8, sel_month);
s.Append("<option value=8" + isSelected + ">Aug</option>\n");
isSelected = checkselected(9, sel_month);
s.Append("<option value=9" + isSelected + ">Sep</option>\n");
isSelected = checkselected(10, sel_month);
s.Append("<option value=10" + isSelected + ">Oct</option>\n");
isSelected = checkselected(11, sel_month);
s.Append("<option value=11" + isSelected + ">Nov</option>\n");
isSelected = checkselected(12, sel_month);
s.Append("<option value=12" + isSelected + ">Dec</option>\n");
s.Append("</select>\n");
//Build Day Dropdown
s.Append("\n<select name=\"" + cid + "_day\"" + onchg + ostyle + ">\n");
int i;
string lc_i;
for (i = 1; i < daysinmonth + 1; i++)
{
lc_i = i.ToString();
if (lc_i.Length == 1)
{
lc_i = "0" + lc_i;
}
isSelected = checkselected(i, sel_day);
s.Append("<option value=" + i.ToString() + isSelected + ">" + lc_i + "</option>\n");
}
s.Append("</select>\n");
//Build Year Dropdown
s.Append("\n<select name=\"" + cid + "_year\"" + onchg + ostyle + ">\n");
for (i = begyear; i <= endyear; i++)
{
lc_i = i.ToString();
isSelected = checkselected(i, sel_year);
s.Append("<option value=" + i.ToString() + isSelected + ">" + i.ToString() + "</option>\n");
}
s.Append("</select>\n");
//Build hidden input type to hold current date
s.Append("\n<input type=hidden name=\"" + cid + "\">\n");
s.Append("\n<input type=hidden name=\"" + cid + "_conv\">\n");
//Close container for applied styles
if (c_ostyle != "")
{
s.Append("</div>");
}
//Add in object initialization for Netscape inline script bug
s.Append(objinit);
//Render control
output.Write(s.ToString());
}
protected string checkselected(int current_selection, int compair_selection)
{
if (current_selection == compair_selection)
{
return " SELECTED";
}
return "";
}
// protected void Write_Client_Scripts()
/// <summary>
/// Add date validation JavaScript to the Page
/// </summary>
/// <param name="e"></param>
override protected void OnPreRender(EventArgs e)
{
StringBuilder s = new StringBuilder();
s.Append("\n<SCRIPT LANGUAGE=javascript>\n");
s.Append("function tg_mm_daysinmonth(lnMonth,lnYear) {\n");
s.Append("var dt1, cmn1, cmn2, dtt, lflag, dycnt, lmn\n");
s.Append("lmn = lnMonth-1\n");
s.Append("dt1 = new Date(lnYear,lmn,1)\n");
s.Append("cmn1 = dt1.getMonth()\n");
s.Append("dtt=dt1.getTime()+2332800000\n");
s.Append("lflag = true\n");
s.Append("dycnt=28\n");
s.Append("while (lflag) {\n");
s.Append(" dtt = dtt + 86400000\n");
s.Append(" dt1.setTime(dtt)\n");
s.Append(" cmn2 = dt1.getMonth()\n");
s.Append(" if (cmn1!=cmn2) {\n");
s.Append(" lflag = false }\n");
s.Append(" else {dycnt = dycnt + 1}}\n");
s.Append("if (dycnt > 31) {dycnt = 31}\n");
s.Append("return dycnt\n");
s.Append("}\n");
s.Append("\n");
s.Append("function tg_mm_setdays(sobjname, datemode){\n");
s.Append("var dobj = eval(sobjname + \"_day\")\n");
s.Append("var mobj = eval(sobjname + \"_month\")\n");
s.Append("var yobj = eval(sobjname + \"_year\")\n");
s.Append("var hobj = eval(sobjname)\n");
s.Append("var hobjconv = eval(sobjname + \"_conv\")\n");
s.Append("var monthdays = tg_mm_daysinmonth(mobj.options[mobj.selectedIndex].value,yobj.options[yobj.selectedIndex].value)\n");
s.Append("var selectdays = dobj.length\n");
s.Append("var curdy = dobj.options[dobj.selectedIndex].value\n");
s.Append("if (curdy.length==1) {curdy = \"0\"+curdy}\n");
s.Append("var curmn = mobj.options[mobj.selectedIndex].value\n");
s.Append("if (curmn.length==1) {curmn = \"0\"+curmn}\n");
s.Append("var curyr = yobj.options[yobj.selectedIndex].value\n");
s.Append("if (selectdays > monthdays) {\n");
s.Append(" for (var dlp=selectdays; dlp > monthdays; dlp--) {\n");
s.Append(" dobj.options[dlp-1] = null }}\n");
s.Append("else if (monthdays > selectdays) {\n");
s.Append(" for (var dlp=selectdays; dlp < monthdays; dlp++) {\n");
s.Append(" dobj.options[dlp] = new Option(dlp+1,dlp+1) }}\n");
s.Append("if (curdy > monthdays) {\n");
s.Append(" dobj.options[monthdays-1].selected = true\n");
s.Append(" curdy = monthdays }\n");
s.Append("var curdateconv = curmn+\"/\"+curdy+\"/\"+curyr\n");
s.Append("if (datemode==1) {\n");
s.Append(" var curdate = curmn+\"/\"+curdy+\"/\"+curyr }\n");
s.Append("else if (datemode==2) {\n");
s.Append(" var curdate = curdy+\"/\"+curmn+\"/\"+curyr }\n");
s.Append("else if (datemode==3) {\n");
s.Append(" var curdate = curyr+curmn+curdy }\n");
s.Append("else if (datemode==4) {\n");
s.Append(" var cdate = new Date(curyr,curmn-1,curdy)\n");
s.Append(" var curdate = cdate.toGMTString() }\n");
s.Append("hobj.value = curdate\n");
s.Append("hobjconv.value = curdateconv\n");
s.Append("}\n");
s.Append("</SCRIPT>\n");
s.Append("\n");
string CloseWindow;
CloseWindow = "alert('Hello World')";
ScriptManager.RegisterStartupScript(this,this.GetType(), "CloseWindow", CloseWindow, true);
// Add the Script to the Page
// this.Page.ClientScript.RegisterClientScriptBlock("mm_datepicker", s.ToString());
}
}
}
|
Advertisement