protected void gv_refdata_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { if ((e.Row.RowState & DataControlRowState.Edit) > 0) { DropDownList ddList = (DropDownList)e.Row.FindControl("lbleditwilayah"); //return DataTable havinf department data DateTimeFormatInfo info = DateTimeFormatInfo.GetInstance(null); int year = DateTime.Now.Year; int year1 = DateTime.Now.Year + 1; for (int Y = year; Y <= year1; Y++) { ddList.Items.Add(new ListItem(Y.ToString(), Y.ToString())); } DataRowView dr = e.Row.DataItem as DataRowView; ddList.SelectedValue = dr["hk_year"].ToString().Trim(); DropDownList ddList1 = (DropDownList)e.Row.FindControl("txtEditcode"); DataSet Ds = new DataSet(); try { string com = "select hr_month_Code,hr_month_desc from Ref_hr_month ORDER BY hr_month_Code"; SqlDataAdapter adpt = new SqlDataAdapter(com, conn); DataTable dt = new DataTable(); adpt.Fill(dt); ddList1.DataSource = dt; ddList1.DataBind(); ddList1.DataTextField = "hr_month_desc"; ddList1.DataValueField = "hr_month_Code"; ddList1.DataBind(); ddList1.Items.Insert(0, new ListItem("--- PILIH ---", "")); } catch (Exception ex) { throw ex; } ddList1.SelectedValue = dr["hk_month"].ToString().Trim(); } } if (e.Row.RowType == DataControlRowType.Footer) { DropDownList lbladdwilayah = (DropDownList)e.Row.FindControl("lbladdwilayah"); DateTimeFormatInfo info = DateTimeFormatInfo.GetInstance(null); int year = DateTime.Now.Year; int year1 = DateTime.Now.Year + 1; for (int Y = year; Y <= year1; Y++) { lbladdwilayah.Items.Add(new ListItem(Y.ToString(), Y.ToString())); } lbladdwilayah.SelectedValue = DateTime.Now.Year.ToString(); DropDownList txtAddcode = (DropDownList)e.Row.FindControl("txtAddcode"); DataSet Ds = new DataSet(); try { string com = "select hr_month_Code,hr_month_desc from Ref_hr_month ORDER BY hr_month_Code"; SqlDataAdapter adpt = new SqlDataAdapter(com, conn); DataTable dt = new DataTable(); adpt.Fill(dt); txtAddcode.DataSource = dt; txtAddcode.DataBind(); txtAddcode.DataTextField = "hr_month_desc"; txtAddcode.DataValueField = "hr_month_Code"; txtAddcode.DataBind(); txtAddcode.Items.Insert(0, new ListItem("--- PILIH ---", "")); } catch (Exception ex) { throw ex; } } }
public String ToString(String format, IFormatProvider formatProvider) { return(DateTimeFormat.Format(ClockDateTime, format, DateTimeFormatInfo.GetInstance(formatProvider), Offset)); }
public TimePicker() { DateTimeFormatInfo = DateTimeFormatInfo.GetInstance(CultureInfo.CurrentCulture); Keyboard.AddKeyDownHandler(this, OnKeyDown); Mouse.AddPreviewMouseDownOutsideCapturedElementHandler(this, OnMouseDownOutsideCapturedElement); }
public bool runTest() { Console.WriteLine(s_strTFPath + " " + s_strTFName + " , for " + s_strClassMethod + " , Source ver " + s_strDtTmVer); int iCountErrors = 0; int iCountTestcases = 0; String strLoc = "Loc_000oo"; String strValue = String.Empty; try { DateTime dt1, dt2; String str1 = String.Empty; CultureInfo ci = CultureInfo.InvariantCulture; strLoc = "Loc_498hx"; iCountTestcases++; try { dt1 = DateTime.ParseExact(null, "", null); iCountErrors++; printerr("Error_98hvc! Expected exception not thrown, dt1==" + dt1.ToString()); } catch (ArgumentNullException aexc) { printinfo("Info_98hcy! Caught expected ArgumentNullException, aexc==" + aexc.Message); } catch (Exception exc) { iCountErrors++; printerr("Error_29h8x! Unexpected Exception: " + exc.ToString()); } strLoc = "Loc_49hvh"; iCountTestcases++; try { dt1 = DateTime.ParseExact("", null, null); dt2 = new DateTime(2000, 2, 29, 17, 59, 01); iCountErrors++; printerr("Error_458vh! Expected exception not thrown, dt1==" + dt1.ToString()); } catch (ArgumentNullException aexc) { printinfo("Info_29hce! Caught expected ArgumentNullException, aexc==" + aexc.Message); } catch (Exception exc) { iCountErrors++; printerr("Error_198zz! Unexpected exception: " + exc.ToString()); } strLoc = "Loc_20jx9"; iCountTestcases++; try { dt1 = DateTime.ParseExact("", "G", null); iCountErrors++; printerr("Error_298hc! Expected exception not thrown, dt1==" + dt1.ToString()); } catch (FormatException fExc) { printinfo("Info_98v89! Caught expected exception, fexc==" + fExc.Message); } catch (Exception exc) { iCountErrors++; printerr("Error_209xq! Unexpected exception: " + exc.ToString()); } strLoc = "Loc_298yg"; iCountTestcases++; try { dt1 = DateTime.ParseExact(DateTime.Now.ToString(), "", null); iCountErrors++; printerr("Error_2h8x9! Expected exception not thrown, dt1==" + dt1.ToString()); } catch (FormatException) { } catch (Exception exc) { iCountErrors++; printerr("Error_209v9! unexpected exception: " + exc.ToString()); } CultureInfo[] cultinfos = CultureInfo.GetCultures(CultureTypes.AllCultures); IEnumerator cultenum = new ArrayList(cultinfos).GetEnumerator(); strLoc = "Loc_248ch"; str1 = "-1/10/2000 17:44:22"; iCountTestcases++; try { dt1 = DateTime.ParseExact(str1, "G", DateTimeFormatInfo.GetInstance(CultureInfo.InvariantCulture)); iCountErrors++; printerr("Error_2d333! Expected exception not thrown, dt1==" + dt1.ToString()); } catch (FormatException fexc) { printinfo("Info_98hcx! Caught expected FormatException, fexc==" + fexc.Message); } catch (Exception exc) { iCountErrors++; printerr("Error_89hf8! Unexpected exception: " + exc.ToString()); } str1 = "11/31/2000 14:38:22"; iCountTestcases++; try { dt1 = DateTime.ParseExact(str1, "G", DateTimeFormatInfo.GetInstance(CultureInfo.InvariantCulture)); iCountErrors++; printerr("Error_1908x! Expected exception not thrown, dt1==" + dt1.ToString()); } catch (FormatException fexc) { printinfo("Info_1979s! Caught expected Exception, fexc==" + fexc.Message); } catch (Exception exc) { iCountErrors++; printerr("Error_287vh! Unexpected exception: " + exc.ToString()); } str1 = "31/11/2000 14:44:22"; iCountTestcases++; try { dt1 = DateTime.ParseExact(str1, "G", DateTimeFormatInfo.GetInstance(CultureInfo.InvariantCulture)); iCountErrors++; printerr("Error_29299! Expected Exception not thrown, dt1==" + dt1.ToString()); } catch (FormatException fexc) { printinfo("Info_39duh! Caught expected Exception, fexc==" + fexc.Message); } catch (Exception exc) { iCountErrors++; printerr("Error_4h7vc! Unexpected exception: " + exc.ToString()); } while (cultenum.MoveNext()) { ci = (CultureInfo)cultenum.Current; if (ci.IsNeutralCulture) { continue; } if (ci.Name.Equals("div-MV")) { continue; } strLoc = "Loc_98vhg"; try { dt2 = new DateTime(2000, 5, 10, 17, 44, 22); str1 = dt2.ToString("G", DateTimeFormatInfo.GetInstance(ci)); dt1 = DateTime.ParseExact(str1, "G", DateTimeFormatInfo.GetInstance(ci)); iCountTestcases++; if (!dt1.Equals(dt2)) { iCountErrors++; printerr("Error_98hx1! Expected==" + dt2.ToString() + " , got==" + dt1.ToString()); } } catch (Exception) { iCountErrors++; printerr("Error_298dx! Failed RoundTrip:" + ci.DisplayName + " : " + ci); } strLoc = "Loc_298hx"; try { dt2 = new DateTime(2000, 5, 10, 17, 44, 0); str1 = dt2.ToString("g", DateTimeFormatInfo.GetInstance(ci)); dt1 = DateTime.ParseExact(dt2.ToString("g", DateTimeFormatInfo.GetInstance(ci)), "g", DateTimeFormatInfo.GetInstance(ci)); iCountTestcases++; if (!dt1.Equals(dt2)) { iCountErrors++; printerr("Error_g98h4! Expected==" + dt2.ToString() + " , got==" + dt1.ToString()); } } catch (Exception) { iCountErrors++; printerr("Error_298vn! Failed RoundTrip: " + ci.DisplayName + " : " + ci); } strLoc = "Loc_t598h"; try { dt2 = new DateTime(2000, 2, 29, 17, 59, 22); dt1 = DateTime.ParseExact(dt2.ToString("d", DateTimeFormatInfo.GetInstance(ci)), "d", DateTimeFormatInfo.GetInstance(ci)); iCountTestcases++; if (!dt1.Equals(new DateTime(2000, 2, 29))) { iCountErrors++; printerr("Error_399s8! Expected==" + new DateTime(2000, 2, 29).ToString() + " , got==" + dt1.ToString()); } } catch (Exception) { iCountErrors++; printerr("Error_48hfd! Failed RoundTrip: " + ci.DisplayName + " : " + ci); } strLoc = "Loc_98hgy"; str1 = "2/28/1999 13:00:01"; try { dt2 = new DateTime(1999, 2, 28, 17, 00, 01); dt1 = DateTime.ParseExact(dt2.ToString("D", DateTimeFormatInfo.GetInstance(ci)), "D", DateTimeFormatInfo.GetInstance(ci)); iCountTestcases++; if (!dt1.Equals(new DateTime(1999, 2, 28))) { iCountErrors++; printerr("Error_29hcy! Expected==" + new DateTime(1999, 2, 28).ToString() + " , got==" + dt1.ToString()); } } catch (Exception) { iCountErrors++; printerr("Error_28y84! Failed RoundTrip: " + ci.DisplayName + " : " + ci); } strLoc = "Loc_4987v"; try { dt2 = new DateTime(2000, 2, 29, 17, 59, 00); str1 = dt2.ToString("f", DateTimeFormatInfo.GetInstance(ci)); dt1 = DateTime.ParseExact(str1, "f", DateTimeFormatInfo.GetInstance(ci)); iCountTestcases++; if (!dt1.ToString("f", DateTimeFormatInfo.GetInstance(ci)).Equals(str1)) { iCountErrors++; printerr("Error_4998x! Expected==" + dt2.Ticks + " , got==" + dt1.Ticks); } } catch (Exception) { iCountErrors++; printerr("Error_298x7! Failed Roundtrip: " + ci.DisplayName + " : " + ci); } strLoc = "Loc_47hcq"; try { dt2 = new DateTime(2000, 2, 29, 17, 59, 01); str1 = dt2.ToString("F", DateTimeFormatInfo.GetInstance(ci)); dt1 = DateTime.ParseExact(str1, "F", DateTimeFormatInfo.GetInstance(ci)); iCountTestcases++; if (!dt1.Equals(dt2)) { iCountErrors++; printerr("Error_3190s! Expected==" + dt2.ToString() + " , got==" + dt1.ToString()); } } catch (Exception) { iCountErrors++; printerr("Error_209us! Failed Roundtrip: " + ci.DisplayName + " : " + ci); } strLoc = "Loc_2388c"; try { dt2 = new DateTime(1999, 12, 31, 23, 23, 23); str1 = dt2.ToString("m", DateTimeFormatInfo.GetInstance(ci)); dt1 = DateTime.ParseExact(str1, "m", DateTimeFormatInfo.GetInstance(ci)); iCountTestcases++; if ( !ci.Equals(new CultureInfo("ar")) && !ci.Equals(new CultureInfo("ar-SA")) ) { if (dt1.Day != dt2.Day) { iCountErrors++; printerr("Error_4985f! Expected==" + dt2.Day + " , got==" + dt1.Day + ", ci==" + ci); } iCountTestcases++; if (dt1.Month != dt2.Month) { iCountErrors++; printerr("Error_28x8y! Expected==" + dt2.Month + ", got==" + dt1.Month + ", ci==" + ci); } } } catch (Exception) { iCountErrors++; printerr("Error_857yv! Failed Roundtrip: " + ci.DisplayName + " : " + ci); } strLoc = "Loc_4f87x"; try { dt2 = new DateTime(1999, 12, 31, 23, 23, 23); str1 = dt2.ToString("M", DateTimeFormatInfo.GetInstance(ci)); dt1 = DateTime.ParseExact(str1, "M", DateTimeFormatInfo.GetInstance(ci)); iCountTestcases++; if ( !ci.Equals(new CultureInfo("ar")) && !ci.Equals(new CultureInfo("ar-SA")) ) { if (dt1.Day != dt2.Day) { iCountErrors++; printerr("Error_988s3! Expected==" + dt2.Day + " , got==" + dt1.Day + ", ci==" + ci); } if (dt1.Month != dt2.Month) { iCountErrors++; printerr("Error_1998s! Expected==" + dt2.Month + ", got==" + dt1.Month + ", ci==" + ci); } } } catch (Exception) { iCountErrors++; printerr("Error_298xh! Failed Roundtrip: " + ci.DisplayName + " : " + ci); } strLoc = "Loc_87g87"; try { dt2 = new DateTime(1883, 1, 1, 1, 1, 1); str1 = dt2.ToString("s", DateTimeFormatInfo.GetInstance(ci)); dt1 = DateTime.ParseExact(str1, "s", DateTimeFormatInfo.GetInstance(ci)); iCountTestcases++; if (!dt1.Equals(dt2)) { iCountErrors++; printerr("Error_928hd! Culture==" + ci + " , Expected==" + str1 + " , got==" + dt1.ToString("s", DateTimeFormatInfo.GetInstance(ci)) + " , Culture==" + ci.DisplayName); } } catch (Exception) { iCountErrors++; printerr("Error_1298s! Failed Roundtrip: " + ci.DisplayName + " : " + ci); } strLoc = "Loc_98409"; try { dt2 = new DateTime(938, 12, 12, 12, 19, 32); str1 = dt2.ToString("t", DateTimeFormatInfo.GetInstance(ci)); dt1 = DateTime.ParseExact(str1, "t", DateTimeFormatInfo.GetInstance(ci)); iCountTestcases++; if (dt1.Hour != dt2.Hour) { iCountErrors++; printerr("Error_298hv! Expected==" + dt2.Hour + ", got==" + dt1.Hour + ", ci==" + ci.DisplayName); } iCountTestcases++; if (dt1.Minute != dt2.Minute) { iCountErrors++; printerr("Error_298cy! Expected==" + dt2.Minute + ", got==" + dt1.Minute + ", ci==" + ci.DisplayName); } } catch (Exception) { iCountErrors++; printerr("Error_9029x! Failed RoundTrip: " + ci.DisplayName + " : " + ci); } strLoc = "Loc_298s7"; try { dt2 = new DateTime(8389, 12, 12, 12, 47, 21); str1 = dt2.ToString("T", DateTimeFormatInfo.GetInstance(ci)); dt1 = DateTime.ParseExact(str1, "T", DateTimeFormatInfo.GetInstance(ci)); iCountTestcases++; if (dt1.Hour != dt2.Hour) { iCountErrors++; printerr("Error_98xhy! Expected==" + dt2.Hour + ", got==" + dt1.Hour + ", ci==" + ci.DisplayName); } iCountTestcases++; if (dt1.Minute != dt2.Minute) { iCountErrors++; printerr("Error_199ay! Expected==" + dt2.Minute + ", got==" + dt1.Minute + ", ci==" + ci.DisplayName); } iCountTestcases++; if (dt1.Second != dt2.Second) { iCountErrors++; printerr("Error_20x98! Expected==" + dt2.Second + ", got==" + dt2.Second + ", ci==" + ci.DisplayName); } } catch (Exception) { iCountErrors++; printerr("Error_2019s! Failed Roundtrip: " + ci.DisplayName + " : " + ci + ", ci==" + ci.DisplayName); } strLoc = "Loc_1s98j"; try { dt2 = new DateTime(2000, 2, 29, 16, 59, 01); str1 = dt2.ToString("u", DateTimeFormatInfo.GetInstance(ci)); dt1 = DateTime.ParseExact(str1, "u", DateTimeFormatInfo.GetInstance(ci)); iCountTestcases++; if (!dt1.Equals(dt2)) { iCountErrors++; printerr("Error_209zj! Expected==" + dt2.ToString() + " , got==" + dt1.ToString()); } } catch (Exception) { iCountErrors++; printerr("Error_209sj! Failed Roundtrip: " + ci.DisplayName + " : " + ci); } strLoc = "Loc_fh888"; try { dt2 = new DateTime(2000, 2, 29, 16, 34, 23); str1 = dt2.ToString("U", DateTimeFormatInfo.GetInstance(ci)); dt1 = DateTime.ParseExact(str1, "U", DateTimeFormatInfo.GetInstance(ci)); iCountTestcases++; if (!dt1.Equals(dt2)) { iCountErrors++; printerr("Error_209su! Expected==" + dt2.ToString() + " , got==" + dt1.ToString()); } } catch (Exception) { iCountErrors++; printerr("Error_109us! Failed Roundtrip: " + ci.DisplayName + " : " + ci); } strLoc = "Loc_2898b"; try { dt2 = new DateTime(3233, 2, 21, 21, 32, 22); str1 = dt2.ToString("y", DateTimeFormatInfo.GetInstance(ci)); dt1 = DateTime.ParseExact(str1, "y", DateTimeFormatInfo.GetInstance(ci)); iCountTestcases++; if (dt1.Year != dt2.Year) { iCountErrors++; printerr("Error_28hcx! Expected==" + dt2.Year + ", got==" + dt1.Year + ", ci==" + ci.DisplayName); } if (dt1.Month != dt2.Month) { iCountErrors++; printerr("Error_87v8x! Expected==" + dt2.Month + ", got==" + dt1.Month); } } catch (Exception) { iCountErrors++; printerr("Error_019de! Failed Roundtrip: " + ci.DisplayName + " : " + ci); } strLoc = "Loc_9898v"; try { dt2 = new DateTime(3233, 3, 21, 21, 32, 22); str1 = dt2.ToString("Y", DateTimeFormatInfo.GetInstance(ci)); dt1 = DateTime.ParseExact(str1, "Y", DateTimeFormatInfo.GetInstance(ci)); iCountTestcases++; if (dt1.Year != dt2.Year) { iCountErrors++; printerr("Error_208x9! Expected==" + dt2.Year + ", got==" + dt1.Year + ", ci==" + ci.DisplayName); } if (dt1.Month != dt2.Month) { iCountErrors++; printerr("Error_8459b! Expected==" + dt2.Month + " ,got==" + dt1.Month + ", ci==" + ci.DisplayName); } } catch (Exception) { iCountErrors++; printerr("Error_099su! Failed Roundtrip: " + ci.DisplayName + " : " + ci); } } ci = CultureInfo.InvariantCulture; strLoc = "Loc_0g9u7"; strLoc = "Loc_398hc"; dt1 = new DateTime(2000, 2, 29, 23, 0, 0); str1 = dt1.ToString("h tt", DateTimeFormatInfo.GetInstance(ci)); try { dt1 = DateTime.ParseExact(str1, "h tt", DateTimeFormatInfo.GetInstance(ci)); iCountTestcases++; if (dt1.Hour != 23) { iCountErrors++; printerr("Error_298hd! Expected==11, got==" + dt1.Hour); } } catch (Exception) { iCountErrors++; printerr("Error_28hc8! Failed RoundTrip: " + ci.DisplayName + " : " + ci); } strLoc = "Loc_98hvy"; dt1 = new DateTime(2000, 2, 29, 23, 0, 0); str1 = dt1.ToString("hh tt", DateTimeFormatInfo.GetInstance(ci)); try { dt1 = DateTime.ParseExact(str1, "hh tt", DateTimeFormatInfo.GetInstance(ci)); iCountTestcases++; if (dt1.Hour != 23) { iCountErrors++; printerr("Error_1989s! Expected==11, got==" + dt1.Hour); } } catch (Exception) { iCountErrors++; printerr("Error_198au! Failed RoundTrip: " + ci.DisplayName + " : " + ci); } strLoc = "Loc_2987x"; dt1 = new DateTime(2000, 2, 29, 23, 0, 0); str1 = dt1.ToString("hh tt", DateTimeFormatInfo.GetInstance(ci)); try { dt1 = DateTime.ParseExact(str1, "hhhhhhhhhhhhhhhhhhhhhhhh tttttttttttttttttttttttttt", DateTimeFormatInfo.GetInstance(ci)); iCountTestcases++; if (dt1.Hour != 23) { iCountErrors++; printerr("Error_298xy! Expected==11, got==" + dt1.Hour); } } catch (Exception) { iCountErrors++; printerr("Error_29885! Failed RoundTrip: " + ci.DisplayName + " : " + ci); } strLoc = "Loc_120su"; try { str1 = "0"; dt1 = DateTime.ParseExact(str1, "H", DateTimeFormatInfo.GetInstance(ci)); iCountTestcases++; if (dt1.Hour != 0) { iCountErrors++; printerr("Error_2c7hc! Exected==0, got==" + dt1.Hour); } } catch (FormatException) { } catch (Exception exc) { iCountErrors++; printerr("Error_209ve! Unexpected exception, , exc==" + exc.ToString()); } strLoc = "Loc_298vy"; str1 = "14"; try { dt1 = DateTime.ParseExact(str1, "HH", DateTimeFormatInfo.GetInstance(ci)); iCountTestcases++; if (dt1.Hour != 14) { iCountErrors++; printerr("Error_98cz5! Expected==14, got value==" + dt1.Hour); } } catch (Exception) { iCountErrors++; printerr("Error_0190a! Failed RoundTrip: " + ci.DisplayName + " : " + ci); } strLoc = "Loc_27yvw"; str1 = "00"; try { dt1 = DateTime.ParseExact(str1, "HH", DateTimeFormatInfo.GetInstance(ci)); iCountTestcases++; if (dt1.Hour != 0) { iCountErrors++; printerr("Error_78yg7! Expected==0, got value==" + dt1.Hour); } } catch (Exception) { iCountErrors++; printerr("Error_2109s! Failed RoundTrip: " + ci.DisplayName + " : " + ci); } strLoc = "Loc_t87cy"; str1 = "1 "; try { dt1 = DateTime.ParseExact(str1, "m ", DateTimeFormatInfo.GetInstance(ci)); iCountTestcases++; if (dt1.Minute != 1) { iCountErrors++; printerr("Error_29cc7! Expected==1, got value==" + dt1.Minute); } } catch (Exception) { iCountErrors++; printerr("Error_298hd! Failed RoundTrip: " + ci.DisplayName + " : " + ci); } strLoc = "Loc_87ygy"; str1 = "59"; try { dt1 = DateTime.ParseExact(str1, "mm", DateTimeFormatInfo.GetInstance(ci)); iCountTestcases++; if (dt1.Minute != 59) { iCountErrors++; printerr("Error_38d87! Expected==59, got value==" + dt1.Minute); } } catch (Exception) { iCountErrors++; printerr("Error_010su! Failed RoundTrip: " + ci.DisplayName + " : " + ci); } strLoc = "Loc_98yv"; str1 = "13 "; try { dt1 = DateTime.ParseExact(str1, "s ", DateTimeFormatInfo.GetInstance(ci)); iCountTestcases++; if (dt1.Second != 13) { iCountErrors++; printerr("Error_29x87! Expected==13, got value==" + dt1.Second); } } catch (Exception) { iCountErrors++; printerr("Error_29yd8! Failed RoundTrip: " + ci.DisplayName + " : " + ci); } strLoc = "Loc_287yc"; str1 = "45"; try { dt1 = DateTime.ParseExact(str1, "ss", DateTimeFormatInfo.GetInstance(ci)); iCountTestcases++; if (dt1.Second != 45) { iCountErrors++; printerr("Error_2x993! Expected==45, got value==" + dt1.Second); } } catch (Exception) { iCountErrors++; printerr("Error_1980x! Failed RoundTrip: " + ci.DisplayName + " : " + ci); } strLoc = "Loc_928hx"; strLoc = "Loc_209xj"; Boolean invarfound = false; cultinfos = CultureInfo.GetCultures(CultureTypes.AllCultures); cultenum = new ArrayList(cultinfos).GetEnumerator(); while (cultenum.MoveNext()) { if (((CultureInfo)cultenum.Current).Equals(CultureInfo.InvariantCulture)) { invarfound = true; } } iCountTestcases++; if (!invarfound) { iCountErrors++; printerr("Error_20a9e! Invariant Culture not in supported cultures, "); } } catch (Exception exc_general) { ++iCountErrors; Console.WriteLine(s_strTFAbbrev + " : Error Err_8888yyy! strLoc==" + strLoc + ", exc_general==" + exc_general.ToString()); } if (iCountErrors == 0) { Console.WriteLine("paSs. " + s_strTFName + " ,iCountTestcases==" + iCountTestcases.ToString()); return(true); } else { Console.WriteLine("FAiL! " + s_strTFName + " ,iCountErrors==" + iCountErrors.ToString() + " , BugNums?: " + s_strActiveBugNums); return(false); } }
public bool runTest() { Console.WriteLine(s_strTFPath + "\\" + s_strTFName + " , for " + s_strClassMethod + " , Source ver " + s_strDtTmVer); String strLoc = "Loc_000oo"; String strValue = String.Empty; int iCountErrors = 0; int iCountTestcases = 0; DateTime date; DateTime dateReturned; DateTime dateExpected; DateTime dateExpectedFromPattern; CultureInfo[] cultures; DateTimeStyles style; String s; Random random; Hashtable table; Char[] splittableChars = { ' ', '/', ':' }; Char ch1; String[] formats = { "d", "D", "f", "F", "g", "G", "m", "M", "r", "R", "s", "t", "T", "u", "U", "y", "Y" }; Boolean fDoneAtLeastOnce; String[] dateInfoCustomFormats; String parseToBeString; TimeZone zone; TimeSpan span; int year, month, day, hour, minute, second, millisecond; DateTime tempDate; Int32 iNumOfDates; Calendar calendar = new GregorianCalendar(); GregorianCalendar greg; Calendar[] calendars = { new GregorianCalendar(GregorianCalendarTypes.Arabic), new GregorianCalendar(GregorianCalendarTypes.Localized), new GregorianCalendar(GregorianCalendarTypes.MiddleEastFrench), new GregorianCalendar(GregorianCalendarTypes.TransliteratedEnglish), new GregorianCalendar(GregorianCalendarTypes.TransliteratedFrench), new GregorianCalendar(GregorianCalendarTypes.USEnglish), new HijriCalendar(), new TaiwanCalendar(), new JapaneseCalendar(), new KoreanCalendar(), new ThaiBuddhistCalendar(), }; try { random = new Random(); for (int iCalendarCount = 0; iCalendarCount < calendars.Length; iCalendarCount++) { calendar = calendars[iCalendarCount]; strLoc = "Loc_384sdg"; date = DateTime.MinValue; if (runAllDates) { iNumOfDates = 80 * 365 + 90; date = GetStartDate(calendar); } else { iNumOfDates = 100; } for (int noDates = 0; noDates < iNumOfDates; noDates++) { strLoc = "Loc_451dsg"; if (runAllDates) { date = calendar.AddDays(date, 1); } else { year = GetRandomYear(calendar, random); month = random.Next(1, 12); day = random.Next(1, 28); hour = random.Next(0, 23); minute = random.Next(0, 59); second = random.Next(0, 59); millisecond = random.Next(0, 999); date = calendar.ToDateTime(year, month, day, hour, minute, second, millisecond); } strLoc = "Loc_347tsg"; zone = TimeZone.CurrentTimeZone; span = zone.GetUtcOffset(date); table = new Hashtable(); table.Add("d", new DateTime(date.Year, date.Month, date.Day)); table.Add("D", new DateTime(date.Year, date.Month, date.Day)); table.Add("f", new DateTime(date.Year, date.Month, date.Day, date.Hour, date.Minute, 0)); table.Add("F", new DateTime(date.Year, date.Month, date.Day, date.Hour, date.Minute, date.Second)); table.Add("g", new DateTime(date.Year, date.Month, date.Day, date.Hour, date.Minute, 0)); table.Add("G", new DateTime(date.Year, date.Month, date.Day, date.Hour, date.Minute, date.Second)); table.Add("m", new DateTime(date.Year, date.Month, date.Day)); table.Add("M", new DateTime(date.Year, date.Month, date.Day)); tempDate = date.ToLocalTime(); table.Add("r", new DateTime(tempDate.Year, tempDate.Month, tempDate.Day, tempDate.Hour, tempDate.Minute, tempDate.Second)); table.Add("R", new DateTime(tempDate.Year, tempDate.Month, tempDate.Day, tempDate.Hour, tempDate.Minute, tempDate.Second)); table.Add("s", new DateTime(date.Year, date.Month, date.Day, date.Hour, date.Minute, date.Second)); table.Add("t", new DateTime(date.Year, date.Month, date.Day, date.Hour, date.Minute, 0)); table.Add("T", new DateTime(date.Year, date.Month, date.Day, date.Hour, date.Minute, date.Second)); table.Add("u", new DateTime(tempDate.Year, tempDate.Month, tempDate.Day, tempDate.Hour, tempDate.Minute, tempDate.Second)); tempDate = date.ToUniversalTime(); table.Add("U", new DateTime(tempDate.Year, tempDate.Month, tempDate.Day, tempDate.Hour, tempDate.Minute, tempDate.Second)); table.Add("y", new DateTime(date.Year, date.Month, date.Day)); table.Add("Y", new DateTime(date.Year, date.Month, date.Day)); strLoc = "Loc_3497sdg"; cultures = CultureInfo.GetCultures(CultureTypes.AllCultures); foreach (CultureInfo culture in cultures) { strLoc = "Loc_37tsdg"; if (culture.IsNeutralCulture) { continue; } try{ culture.DateTimeFormat.Calendar = calendar; }catch { continue; } if ((calendar is GregorianCalendar)) { greg = (GregorianCalendar)calendar; if (greg.CalendarType == GregorianCalendarTypes.TransliteratedFrench) { if (calendar.GetDayOfWeek(date) == DayOfWeek.Thursday) { continue; } } } if (culture.Name.Equals("div-MV")) { continue; } iCountTestcases++; foreach (String format in formats) { if ((calendar is GregorianCalendar)) { greg = (GregorianCalendar)calendar; if (greg.CalendarType == GregorianCalendarTypes.TransliteratedFrench) { if (calendar.GetDayOfWeek(date.ToUniversalTime()) == DayOfWeek.Thursday) { continue; } } } if (!(calendar is GregorianCalendar) && (format.ToUpper().Equals("U") || format.ToUpper().Equals("R"))) { continue; } if (format.ToUpper().Equals("M")) { if (calendar.GetDayOfMonth(date) > calendar.GetDaysInMonth(calendar.GetYear(DateTime.Now), calendar.GetMonth(date))) { continue; } } if ((culture.Name.Equals("ka-GE") || culture.Name.Equals("af-ZA")) && format.Equals("u") ) { continue; } if (culture.Name.Equals("fa-IR") && format.ToUpper().Equals("Y") ) { continue; } if ((culture.Name.Equals("af-ZA") || culture.Name.Equals("th-TH")) && format.ToUpper().Equals("R") ) { continue; } if ((culture.Name.Equals("sq-AL") || culture.Name.Equals("mn-MN") ) && format.ToUpper().Equals("Y") ) { continue; } strLoc = "Loc_386tsg"; s = date.ToString(format, culture); strLoc = "Loc_3947tsg"; dateExpected = (DateTime)table[format]; dateInfoCustomFormats = null; try { dateInfoCustomFormats = DateTimeFormatInfo.GetInstance(culture).GetAllDateTimePatterns(format[0]); } catch (Exception) { Console.WriteLine("Err_3498wsg"); } try { strLoc = "Loc_9374tsdg!"; style = DateTimeStyles.None; dateReturned = DateTime.Parse(s, culture, style); if (!ResultCorrect(dateReturned, dateExpected, format, culture, calendar)) { iCountErrors++; Console.WriteLine("Err_93745sdg! Culture: <{4}>, Format: {2}, String: <{3}>, Expected: {0}, Returned: {1}", dateExpected, dateReturned, format, s, culture); } strLoc = "Loc_93456tfg!"; if (!format.Equals("U") && (culture.Name.Equals("en-US") || culture.Name.Equals("ja-JP") || culture.Name.Equals("de-DE")) ) { if (culture.Name.Equals("ja-JP") && (format.Equals("r") || format.Equals("R"))) { continue; } if (culture.Name.Equals("de-DE") && (format.Equals("f") || format.Equals("F") || format.Equals("G") || format.Equals("g") || format.Equals("t") || format.Equals("T"))) { continue; } foreach (String patternFormat in dateInfoCustomFormats) { if (GetPatternedDate(table, patternFormat, format, out dateExpectedFromPattern)) { parseToBeString = date.ToString(patternFormat, culture); dateReturned = DateTime.Parse(parseToBeString, culture, style); if (!ResultCorrect(dateReturned, dateExpectedFromPattern, format, culture, calendar)) { iCountErrors++; Console.WriteLine("Err_347tsdg! Culture: <{4}>, Format: {2}, BaseFormat: {5}, String: <{3}>, Expected: {0}, Returned: {1}", dateExpectedFromPattern, dateReturned, patternFormat, parseToBeString, culture, format); } } } } strLoc = "Loc_2837sdg!"; style = DateTimeStyles.NoCurrentDateDefault; dateReturned = DateTime.Parse(s, culture, style); if (!ResultCorrect(dateReturned, dateExpected, format, culture, calendar)) { iCountErrors++; Console.WriteLine("Err_3745dsgdg! Culture: <{4}>, Format: {2}, String: <{3}>, Expected: {0}, Returned: {1}", dateExpected, dateReturned, format, s, culture); } strLoc = "Loc_486tsg"; s = s.PadLeft(random.Next(50)); style = DateTimeStyles.AllowLeadingWhite; dateReturned = DateTime.Parse(s, culture, style); if (!ResultCorrect(dateReturned, dateExpected, format, culture, calendar)) { iCountErrors++; Console.WriteLine("Err_74985wgdsg! Culture: <{4}>, Format: {2}, String: <{3}>, Expected: {0}, Returned: {1}", dateExpected, dateReturned, format, s, culture); } strLoc = "Loc_23947tsdg!"; s = s.TrimStart(); s = s.PadRight(random.Next(50)); style = DateTimeStyles.AllowTrailingWhite; dateReturned = DateTime.Parse(s, culture, style); if (!ResultCorrect(dateReturned, dateExpected, format, culture, calendar)) { iCountErrors++; Console.WriteLine("Err_9374sdg! Culture: <{4}>, Format: {2}, String: <{3}>, Expected: {0}, Returned: {1}", dateExpected, dateReturned, format, GetUnicodeString(s), culture); } strLoc = "Loc_234967sgd!"; s = s.TrimEnd(); fDoneAtLeastOnce = false; for (int i = 0; i < 10; i++) { ch1 = splittableChars[random.Next(splittableChars.Length)]; if (s.IndexOf(ch1) > 0) { s = s.Insert(s.IndexOf(ch1), new String(' ', random.Next(2, 20))); if (!fDoneAtLeastOnce) { fDoneAtLeastOnce = true; } } } style = DateTimeStyles.AllowInnerWhite; dateReturned = DateTime.Parse(s, culture, style); if (!ResultCorrect(dateReturned, dateExpected, format, culture, calendar)) { iCountErrors++; Console.WriteLine("Err_43275sdg! Culture: <{4}>, Format: {2}, String: <{3}>, Expected: {0}, Returned: {1}", dateExpected, dateReturned, format, s, culture); } strLoc = "Loc_4329076tsfg!"; s = s.PadLeft(random.Next(50)); s = s.PadRight(random.Next(50)); style = DateTimeStyles.AllowWhiteSpaces; dateReturned = DateTime.Parse(s, culture, style); if (!ResultCorrect(dateReturned, dateExpected, format, culture, calendar)) { iCountErrors++; Console.WriteLine("Err_3497gsg! Culture: <{4}>, Format: {2}, String: <{3}>, Expected: {0}, Returned: {1}", dateExpected, dateReturned, format, s, culture); } } catch (Exception ex) { if (culture.Name.Equals("vi-VN") && Char.ToUpper(format[0]).Equals('Y')) { ex = null; } else { iCountErrors++; Console.WriteLine("Err_75639rge! Unexpected exception thrown {0}, Loc: {3}, format: {4}, Culture: {1}, s:<{2}>, Date: {5}", ex.GetType().Name, culture, s, strLoc, format, date); } } } } } } } catch (Exception exc_general) { ++iCountErrors; Console.WriteLine(s_strTFAbbrev + " : Error Err_8888yyy! strLoc==" + strLoc + ", exc_general==" + exc_general.ToString()); } if (iCountErrors == 0) { Console.WriteLine("paSs. " + s_strTFName + " ,iCountTestcases==" + iCountTestcases.ToString()); return(true); } else { Console.WriteLine("FAiL! " + s_strTFName + " ,inCountErrors==" + iCountErrors.ToString() + " , BugNums?: " + s_strActiveBugNums); return(false); } }
public static DateTimeOffset ParseExact(string input, string[] formats, IFormatProvider formatProvider, DateTimeStyles styles) { TimeSpan span; styles = ValidateStyles(styles, "styles"); return(new DateTimeOffset(DateTimeParse.ParseExactMultiple(input, formats, DateTimeFormatInfo.GetInstance(formatProvider), styles, out span).Ticks, span)); }
public static void DetermineFileFormat(Stream stream, out NumberFormatInfo numberFormat, out DateTimeFormatInfo dateTimeFormatInfo, out char separator) { using (StreamReader reader = new StreamReader(stream)) { // skip first line reader.ReadLine(); // read a block char[] buffer = new char[BUFFER_SIZE]; int charsRead = reader.ReadBlock(buffer, 0, BUFFER_SIZE); // count frequency of special characters Dictionary <char, int> charCounts = buffer.Take(charsRead) .GroupBy(c => c) .ToDictionary(g => g.Key, g => g.Count()); // depending on the characters occuring in the block // we distinghish a number of different cases based on the the following rules: // many points => it must be English number format, the other frequently occuring char is the separator // no points but many commas => this is the problematic case. Either German format (real numbers) or English format (only integer numbers) with ',' as separator // => check the line in more detail: // English: 0, 0, 0, 0 // German: 0,0 0,0 0,0 ... // => if commas are followed by space => English format // no points no commas => English format (only integer numbers) use the other frequently occuring char as separator // in all cases only treat ' ' as separator if no other separator is possible (spaces can also occur additionally to separators) if (OccurrencesOf(charCounts, '.') > 10) { numberFormat = NumberFormatInfo.InvariantInfo; dateTimeFormatInfo = DateTimeFormatInfo.InvariantInfo; separator = POSSIBLE_SEPARATORS .Where(c => OccurrencesOf(charCounts, c) > 10) .OrderBy(c => - OccurrencesOf(charCounts, c)) .DefaultIfEmpty(' ') .First(); } else if (OccurrencesOf(charCounts, ',') > 10) { // no points and many commas // count the number of tokens (chains of only digits and commas) that contain multiple comma characters int tokensWithMultipleCommas = 0; for (int i = 0; i < charsRead; i++) { int nCommas = 0; while (i < charsRead && (buffer[i] == ',' || Char.IsDigit(buffer[i]))) { if (buffer[i] == ',') { nCommas++; } i++; } if (nCommas > 2) { tokensWithMultipleCommas++; } } if (tokensWithMultipleCommas > 1) { // English format (only integer values) with ',' as separator numberFormat = NumberFormatInfo.InvariantInfo; dateTimeFormatInfo = DateTimeFormatInfo.InvariantInfo; separator = ','; } else { char[] disallowedSeparators = new char[] { ',' }; // n. def. contains a space so ' ' should be disallowed to, however existing unit tests would fail // German format (real values) numberFormat = NumberFormatInfo.GetInstance(new CultureInfo("de-DE")); dateTimeFormatInfo = DateTimeFormatInfo.GetInstance(new CultureInfo("de-DE")); separator = POSSIBLE_SEPARATORS .Except(disallowedSeparators) .Where(c => OccurrencesOf(charCounts, c) > 10) .OrderBy(c => - OccurrencesOf(charCounts, c)) .DefaultIfEmpty(' ') .First(); } } else { // no points and no commas => English format numberFormat = NumberFormatInfo.InvariantInfo; dateTimeFormatInfo = DateTimeFormatInfo.InvariantInfo; separator = POSSIBLE_SEPARATORS .Where(c => OccurrencesOf(charCounts, c) > 10) .OrderBy(c => - OccurrencesOf(charCounts, c)) .DefaultIfEmpty(' ') .First(); } } }
public void PosTest4() { DateTimeFormatInfo info = DateTimeFormatInfo.GetInstance(new TestIFormatProviderClass2()); Assert.NotNull(info); }
public void PosTest5() { DateTimeFormatInfo info = DateTimeFormatInfo.GetInstance(new TestIFormatProviderClass()); Assert.Equal(DateTimeFormatInfo.CurrentInfo, info); }
public void PosTest2() { DateTimeFormatInfo info = DateTimeFormatInfo.GetInstance(null); Assert.Equal(DateTimeFormatInfo.CurrentInfo, info); }
public void PosTest3() { DateTimeFormatInfo info = DateTimeFormatInfo.GetInstance(new DateTimeFormatInfo()); Assert.NotNull(info); }
public void PosTest1() { DateTimeFormatInfo info = DateTimeFormatInfo.GetInstance(new CultureInfo("en-us")); Assert.NotNull(info); }
protected void BindDDL() { try { List <MasValueList> lst = new List <MasValueList>(); DataTable dt = new DataTable(); dt.Columns.Add("Text"); dt.Columns.Add("Val"); DataRow dr; #region Month DateTimeFormatInfo monthsInfo = DateTimeFormatInfo.GetInstance(null); for (int i = 1; i < 13; i++) { dr = dt.NewRow(); dr["Text"] = monthsInfo.GetMonthName(i); dr["Val"] = i.ToString(); dt.Rows.Add(dr); } if (dt != null && dt.Rows.Count > 0) { ddlMonth.DataSource = dt; ddlMonth.DataTextField = "Text"; ddlMonth.DataValueField = "Val"; } else { ddlMonth.DataSource = null; } ddlMonth.DataBind(); ddlMonth.SelectedIndex = ddlMonth.Items.IndexOf(ddlMonth.Items.FindByValue(DateTime.Now.Month.ToString())); //ToInt32(obj.PayType); #endregion #region Year List <Int32> lstYear = new List <Int32>(); using (BillingEntities cre = new BillingEntities()) { lstYear = cre.TransSaleHeaders.Select(s => s.ReceivedDate.HasValue ? s.ReceivedDate.Value.Year : 0).Distinct().OrderByDescending(od => od).ToList(); } if (lstYear != null) { ddlYear.DataSource = lstYear; ddlYear.SelectedIndex = ddlYear.Items.IndexOf(ddlYear.Items.FindByValue(DateTime.Now.Year.ToString())); //ToInt32(obj.PayType); } else { ddlYear.DataSource = null; } ddlYear.DataBind(); #endregion #region Sale using (BillingEntities cre = new BillingEntities()) { lst = cre.MasValueLists.Where(w => w.FUNC.Equals("SALENAME") && w.ISACTIVE.Equals("Y")).OrderBy(od => od.CODE).ToList(); } if (lst != null && lst.Count > 0) { ddlSaleName.DataSource = lst; ddlSaleName.DataTextField = "Description"; ddlSaleName.DataValueField = "Code"; } else { ddlSaleName.DataSource = null; } ddlSaleName.Items.Insert(0, new System.Web.UI.WebControls.ListItem("", "0")); ddlSaleName.DataBind(); #endregion #region Pay Type using (BillingEntities cre = new BillingEntities()) { lst = cre.MasValueLists.Where(w => w.FUNC.Equals("PAYMENT") && w.ISACTIVE.Equals("Y")).OrderBy(od => od.TYPES).ToList(); } if (lst != null && lst.Count > 0) { lst = lst.OrderBy(od => ToInt32(od.CODE)).ToList(); ddlPay.DataSource = lst; ddlPay.DataTextField = "Description"; ddlPay.DataValueField = "Code"; } else { ddlPay.DataSource = null; } ddlPay.Items.Insert(0, new System.Web.UI.WebControls.ListItem("", "0")); ddlPay.DataBind(); #endregion } catch (Exception ex) { SendMailError(ex.Message, System.Reflection.MethodBase.GetCurrentMethod()); } }
private DateTime CreateDate(string dateString) { DateTime date = DateTime.ParseExact(dateString, "yyyy/MM/dd HH:mm:ss z", DateTimeFormatInfo.GetInstance(CultureInfo.InvariantCulture)); return(date); }
public string ToString(string format, IFormatProvider provider) { var dtfi = DateTimeFormatInfo.GetInstance(provider); return(DateTimeExFormat.FormatCustomized(this, format, dtfi)); }
// Format a date value as a string. public static String Format(DateTime date, String format, IFormatProvider provider) { DateTimeFormatInfo info; // Get the date/time formatting information to use. info = DateTimeFormatInfo.GetInstance(provider); // Validate the format string. if (format == null || format == String.Empty) { format = "G"; } if (format.Length == 1) { // Resolve the format code to a custom format string. switch (format) { case "d": format = info.ShortDatePattern; break; case "D": format = info.LongDatePattern; break; case "f": format = info.LongDatePattern + " " + info.ShortTimePattern; break; case "F": format = info.FullDateTimePattern; break; case "g": format = info.ShortDatePattern + " " + info.ShortTimePattern; break; case "G": format = info.ShortDatePattern + " " + info.LongTimePattern; break; case "m": case "M": format = info.MonthDayPattern; break; #if !ECMA_COMPAT case "r": case "R": format = info.RFC1123Pattern; break; case "s": format = info.SortableDateTimePattern; break; case "u": format = info.UniversalSortableDateTimePattern; break; #else case "r": case "R": format = "ddd, dd MMM yyyy HH':'mm':'ss 'GMT'"; break; case "s": format = "yyyy'-'MM'-'dd'T'HH':'mm':'ss"; break; case "u": format = "yyyy'-'MM'-'dd HH':'mm':'ss'Z'"; break; #endif case "t": format = info.ShortTimePattern; break; case "T": format = info.LongTimePattern; break; case "U": date = date.ToUniversalTime(); format = info.FullDateTimePattern; break; case "y": case "Y": format = info.YearMonthPattern; break; default: { throw new FormatException (_("Format_FormatString")); } // Not reached. } } return(Format(format, date, info)); }
public static DateTimeEx Parse(string value, string format, IFormatProvider provider) { return(DateTimeExParse.ParseCustomized(value, format, DateTimeFormatInfo.GetInstance(provider))); }
public static DateTimeOffset ParseExact(string input, string[] formats, IFormatProvider formatProvider, DateTimeStyles styles) { styles = ValidateStyles(styles, "styles"); return(new DateTimeOffset(DateTime.ParseExact(input, formats, DateTimeFormatInfo.GetInstance(formatProvider), styles))); }
public string ToString(string format, IFormatProvider formatProvider) { return(DateTimeFormat.Format(this.ClockDateTime, format, DateTimeFormatInfo.GetInstance(formatProvider), this.Offset)); }
public String ToString(String format, IFormatProvider formatProvider) { Contract.Ensures(Contract.Result <String>() != null); return(DateTimeFormat.Format(ClockDateTime, format, DateTimeFormatInfo.GetInstance(formatProvider), Offset)); }
private DataTable ConvertToDatatable() { CostLedgerDAL objAccBookDAL = new CostLedgerDAL(); DataTable dTN = new DataTable(); hidstr.Value = ""; Int64 TruckIdno = 0; Int32 YearIdno = 0; string PrtyName = ""; Int64 PrtyIdno = 0; PrtyName = Convert.ToString(Session["PrtyName"]); lblLedgerName.Text = "[" + Convert.ToString(Session["PrtyName"]) + "]"; PrtyIdno = Convert.ToInt64(Session["PrtyIdno"]); TruckIdno = Convert.ToInt64(Session["TruckIdno"]); TruckIdno = Convert.ToInt64(Session["TruckIdno"]); TruckIdno = Convert.ToInt64(Session["TruckIdno"]); YearIdno = Convert.ToInt32(Request.QueryString["YearIdno"]); lblTruckNo.Text = "[" + Convert.ToString(Session["TruckNo"]) + "]"; //Int64 intCompIdno = ddlcompany.SelectedItem.Text == "All" ? 0 : Convert.ToInt64(ddlcompany.SelectedValue); #region Ledger Report dTN.Columns.Add("PERTI"); dTN.Columns.Add("DEBIT"); dTN.Columns.Add("CREDIT"); dTN.Columns.Add("Balance"); dTN.Columns.Add("Mon"); dTN.Columns.Add("Truck_Idno"); string strAction = "SelectDetailReport"; DataSet dsTable = objAccBookDAL.FillCostgrid(ApplicationFunction.ConnectionString(), strAction, PrtyIdno, TruckIdno, YearIdno); #region if (dsTable != null && dsTable.Tables.Count > 0 && dsTable.Tables[0].Rows.Count > 0) { int i, j, m, mon; i = j = m = mon = 0; mon = 4; j = 0; for (i = 0; i < 12; i++) { DateTimeFormatInfo info = DateTimeFormatInfo.GetInstance(null); if (mon > 12) { mon = 1; } dTN.Rows.Add(); dTN.Rows[i][0] = (new ListItem(info.GetMonthName(mon).ToString(), mon.ToString())); dTN.Rows[i][1] = dTN.Rows[i][2] = dTN.Rows[i][3] = "00.00"; dTN.Rows[i][4] = mon; mon += 1; } for (i = 0; i < 12; i++) { if (j < dsTable.Tables[0].Rows.Count) { if (Convert.ToString(dsTable.Tables[0].Rows[j][4]) != "") { if (Convert.ToDouble(dTN.Rows[i][4]) == Convert.ToDouble(Convert.ToString(dsTable.Tables[0].Rows[j][4]).Substring(4, 2))) { dTN.Rows[i][0] = Convert.ToString(dsTable.Tables[0].Rows[j][0]); dTN.Rows[i][1] = string.Format("{0:0,0.00}", Convert.ToString(dsTable.Tables[0].Rows[j][1])); dTN.Rows[i][2] = string.Format("{0:0,0.00}", Convert.ToString(dsTable.Tables[0].Rows[j][2])); dTN.Rows[i][3] = string.Format("{0:0,0.00}", Convert.ToString(dsTable.Tables[0].Rows[j][3])); j += 1; } } } else { break; } } } #endregion #endregion objAccountBookDAL = null; return(dTN); }
public string GetCurrentMenu() { string xhtmlData; try { var webClient = new WebClient(); xhtmlData = webClient.DownloadString("http://pest.vakvarju.com/hu/napimenu"); StatisticsCollector.GetInstance().IncrementOutgoingWebRequestCount(); } catch (Exception e) { _log.Error("Failed to download the web page. Error: " + e); return("Hiba: nem lehet letölteni a VakVarjú honlapját."); } // We must strip down the html code to avoid read errors int pos = xhtmlData.IndexOf("<div id=\"etlapfelsorol\">", StringComparison.InvariantCultureIgnoreCase); if (pos > -1) { xhtmlData = xhtmlData.Remove(0, pos); } pos = xhtmlData.IndexOf("<div class=\"footerbox\">", StringComparison.CurrentCultureIgnoreCase); if (pos > -1) { xhtmlData = xhtmlData.Remove(pos); } // Poor man's sanitizer... xhtmlData = ToUtf8(xhtmlData); xhtmlData = ReplaceCaseInsensitive(xhtmlData, "í", "í"); xhtmlData = ReplaceCaseInsensitive(xhtmlData, "á", "á"); xhtmlData = ReplaceCaseInsensitive(xhtmlData, "é", "é"); xhtmlData = ReplaceCaseInsensitive(xhtmlData, "ú", "ú"); xhtmlData = ReplaceCaseInsensitive(xhtmlData, "ó", "ó"); xhtmlData = ReplaceCaseInsensitive(xhtmlData, "ö", "ö"); xhtmlData = ReplaceCaseInsensitive(xhtmlData, "ü", "ü"); xhtmlData = ReplaceCaseInsensitive(xhtmlData, "„", "\""); xhtmlData = ReplaceCaseInsensitive(xhtmlData, "”", "\""); xhtmlData = ReplaceCaseInsensitive(xhtmlData, " ", " "); xhtmlData = ReplaceCaseInsensitive(xhtmlData, "–", "-"); xhtmlData = ReplaceCaseInsensitive(xhtmlData, "<br />", "\n"); xhtmlData = ReplaceCaseInsensitive(xhtmlData, "<br/>", "\n"); xhtmlData = ReplaceCaseInsensitive(xhtmlData, "<h2>", ""); xhtmlData = ReplaceCaseInsensitive(xhtmlData, "</h2>", ""); xhtmlData = ReplaceCaseInsensitive(xhtmlData, "<p>", ""); xhtmlData = ReplaceCaseInsensitive(xhtmlData, "</p>", ""); xhtmlData = ReplaceCaseInsensitive(xhtmlData, "\t", ""); var reader = new StringReader(xhtmlData); var settings = new XmlReaderSettings { DtdProcessing = DtdProcessing.Ignore }; XmlReader xml = XmlReader.Create(reader, settings); string menuText = null; var dayOfWeek = (int)DateTime.Today.DayOfWeek; string[] dayNames = DateTimeFormatInfo.GetInstance(new CultureInfo("hu-HU")).DayNames; try { while (xml.Read()) { if (xml.NodeType != XmlNodeType.Element) { continue; } if (xml.Name != "div" || !xml.HasAttributes || xml.GetAttribute("class") != "nev") { continue; } string headerContent = xml.ReadElementContentAsString(); // Read the menu contents if we have found one for today if (!headerContent.ToLower().Contains(dayNames[dayOfWeek].ToLower())) { continue; } while (xml.Read()) { if (xml.NodeType != XmlNodeType.Element) { continue; } if (xml.Name != "div" || !xml.HasAttributes || xml.GetAttribute("class") != "text") { continue; } string content = xml.ReadElementContentAsString(); var sb = new StringBuilder(); sb.AppendLine("A mai menü a Varjúban:"); sb.AppendLine(headerContent); sb.AppendLine(); sb.AppendLine(content); menuText = sb.ToString(); break; } } } catch (XmlException e) { if (!e.Message.ToLower().Contains("unexpected end tag")) { _log.Error("Failed to parse XHTML. Error: " + e); menuText = "Hiba a feldolgozás során. Ellenőrizd a naplót."; } } if (menuText == null) { return("A mai napra nem található menü a Varjúban."); } return(menuText); }
// Constructs a DateTime from a string. The string must specify a // date and optionally a time in a culture-specific or universal format. // Leading and trailing whitespace characters are allowed. // public static DateTime Parse(String s, IFormatProvider provider) { return(DateTimeParse.Parse(s, DateTimeFormatInfo.GetInstance(provider), DateTimeStyles.None)); }
public bool TryFormat(Span <char> destination, out int charsWritten, string format = null, IFormatProvider formatProvider = null) => DateTimeFormat.TryFormat(ClockDateTime, destination, out charsWritten, format, DateTimeFormatInfo.GetInstance(formatProvider), Offset);