S
si_owen
Hi folks,
I am looking to convert some C# code for a calendar control into VB. I
am unfamiliar with C# and have seen several free concersion addin tools
to transform the code, how ever I can not get these applications
(addins) to run successfully. And I was hoping that someone in this
forum may be able to help me translate the code from C# to VB.
The code can be found here:
http://www.codeproject.com/useritems/DateRangePicker.asp
CLASS 1
using System;
namespace CustomWebControls
{
[Serializable]
public struct DateRange
{
public static readonly DateRange EMPTY = new DateRange();
readonly DateTime from;
readonly DateTime to;
public DateRange(DateTime from, DateTime to)
{
this.from = from;
this.to = to;
}
public DateTime From
{
get { return from; }
}
public DateTime To
{
get { return to; }
}
public TimeSpan TimeSpan
{
get
{
return to - from;
}
}
public bool Contains(DateTime time)
{
return from <= time && time < to;
}
public DateRange Include(DateRange otherRange)
{
return Include(otherRange.From).Include(otherRange.To);
}
public DateRange Include(DateTime date)
{
if (date < from)
return new DateRange(date, to);
else if (date > to)
return new DateRange(from, date);
else
return this;
}
/// <summary>
/// Creates a one day (24 hr) long DateRange starting at
DateTime
/// </summary>
public static DateRange CreateDay(DateTime dateTime){
return new DateRange(dateTime, dateTime.AddDays(1));
}
#region operators and overrides
public override int GetHashCode()
{
return from.GetHashCode() + 29*to.GetHashCode();
}
public override bool Equals(object obj)
{
if (ReferenceEquals(this, obj)) return true;
if (!(obj is DateRange)) return false;
DateRange dateRange = (DateRange) obj;
if (!Equals(from, dateRange.from)) return false;
if (!Equals(to, dateRange.to)) return false;
return true;
}
public static bool operator == (DateRange d1, DateRange d2)
{
return d1.Equals(d2);
}
public static bool operator !=(DateRange d1, DateRange d2)
{
return !d1.Equals(d2);
}
#endregion
}
}
CLASS 2
using System.ComponentModel;
using System.Drawing;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace CustomWebControls
{
/// <summary>
/// An extended Calendar that can select DateRanges as well as
Dates
/// </summary>
[DefaultProperty("Text")]
[ToolboxData("<{0}ateRangePicker
runat=server></{0}ateRangePicker>")]
public class DateRangePicker : Calendar
{
static readonly TableItemStyle defaultSelectedDateRangeStyle =
new TableItemStyle();
static DateRangePicker()
{
//initialise a default colour for
defaultSelectedDateRangeStyle
defaultSelectedDateRangeStyle.BackColor =
Color.LightSteelBlue;
}
TableItemStyle selectedDateRangeStyle =
defaultSelectedDateRangeStyle;
protected override void OnDayRender(TableCell cell, CalendarDay
day)
{
if (SelectedDateRange.Contains(day.Date))
{
cell.ApplyStyle(selectedDateRangeStyle);
}
}
protected override void OnSelectionChanged()
{
base.OnSelectionChanged();
bool emptyDateRange = SelectedDateRange == DateRange.EMPTY;
bool dateRangeAlreadyPicked =
SelectedDateRange.TimeSpan.TotalDays > 1;
if (emptyDateRange || dateRangeAlreadyPicked)
{
SelectedDateRange = DateRange.CreateDay(SelectedDate);
//save this date as the first date in our date range
}
else
{
SelectedDateRange =
SelectedDateRange.Include(DateRange.CreateDay(SelectedDate));
//set the end date in our date range
}
}
//DateRange gets stored in the viewstate since it's a property
that needs to persist across page requests.
[Browsable(false)]
public DateRange SelectedDateRange
{
get { return (DateRange)
(ViewState["SelectedDateRange"]??DateRange.EMPTY); }
set { ViewState["SelectedDateRange"] = value; }
}
//SelectedDateRangeStyle goes into a private variable since
this property is designed.
[Category("Styles")]
[Description("The Style that is aplied to cells within the
selected Date Range")]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
[NotifyParentProperty(true)]
[PersistenceMode(PersistenceMode.InnerProperty)]
public TableItemStyle SelectedDateRangeStyle
{
get { return selectedDateRangeStyle; }
set { selectedDateRangeStyle = value; }
}
}
}
any help would be much appreceiated...
Simon
I am looking to convert some C# code for a calendar control into VB. I
am unfamiliar with C# and have seen several free concersion addin tools
to transform the code, how ever I can not get these applications
(addins) to run successfully. And I was hoping that someone in this
forum may be able to help me translate the code from C# to VB.
The code can be found here:
http://www.codeproject.com/useritems/DateRangePicker.asp
CLASS 1
using System;
namespace CustomWebControls
{
[Serializable]
public struct DateRange
{
public static readonly DateRange EMPTY = new DateRange();
readonly DateTime from;
readonly DateTime to;
public DateRange(DateTime from, DateTime to)
{
this.from = from;
this.to = to;
}
public DateTime From
{
get { return from; }
}
public DateTime To
{
get { return to; }
}
public TimeSpan TimeSpan
{
get
{
return to - from;
}
}
public bool Contains(DateTime time)
{
return from <= time && time < to;
}
public DateRange Include(DateRange otherRange)
{
return Include(otherRange.From).Include(otherRange.To);
}
public DateRange Include(DateTime date)
{
if (date < from)
return new DateRange(date, to);
else if (date > to)
return new DateRange(from, date);
else
return this;
}
/// <summary>
/// Creates a one day (24 hr) long DateRange starting at
DateTime
/// </summary>
public static DateRange CreateDay(DateTime dateTime){
return new DateRange(dateTime, dateTime.AddDays(1));
}
#region operators and overrides
public override int GetHashCode()
{
return from.GetHashCode() + 29*to.GetHashCode();
}
public override bool Equals(object obj)
{
if (ReferenceEquals(this, obj)) return true;
if (!(obj is DateRange)) return false;
DateRange dateRange = (DateRange) obj;
if (!Equals(from, dateRange.from)) return false;
if (!Equals(to, dateRange.to)) return false;
return true;
}
public static bool operator == (DateRange d1, DateRange d2)
{
return d1.Equals(d2);
}
public static bool operator !=(DateRange d1, DateRange d2)
{
return !d1.Equals(d2);
}
#endregion
}
}
CLASS 2
using System.ComponentModel;
using System.Drawing;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace CustomWebControls
{
/// <summary>
/// An extended Calendar that can select DateRanges as well as
Dates
/// </summary>
[DefaultProperty("Text")]
[ToolboxData("<{0}ateRangePicker
runat=server></{0}ateRangePicker>")]
public class DateRangePicker : Calendar
{
static readonly TableItemStyle defaultSelectedDateRangeStyle =
new TableItemStyle();
static DateRangePicker()
{
//initialise a default colour for
defaultSelectedDateRangeStyle
defaultSelectedDateRangeStyle.BackColor =
Color.LightSteelBlue;
}
TableItemStyle selectedDateRangeStyle =
defaultSelectedDateRangeStyle;
protected override void OnDayRender(TableCell cell, CalendarDay
day)
{
if (SelectedDateRange.Contains(day.Date))
{
cell.ApplyStyle(selectedDateRangeStyle);
}
}
protected override void OnSelectionChanged()
{
base.OnSelectionChanged();
bool emptyDateRange = SelectedDateRange == DateRange.EMPTY;
bool dateRangeAlreadyPicked =
SelectedDateRange.TimeSpan.TotalDays > 1;
if (emptyDateRange || dateRangeAlreadyPicked)
{
SelectedDateRange = DateRange.CreateDay(SelectedDate);
//save this date as the first date in our date range
}
else
{
SelectedDateRange =
SelectedDateRange.Include(DateRange.CreateDay(SelectedDate));
//set the end date in our date range
}
}
//DateRange gets stored in the viewstate since it's a property
that needs to persist across page requests.
[Browsable(false)]
public DateRange SelectedDateRange
{
get { return (DateRange)
(ViewState["SelectedDateRange"]??DateRange.EMPTY); }
set { ViewState["SelectedDateRange"] = value; }
}
//SelectedDateRangeStyle goes into a private variable since
this property is designed.
[Category("Styles")]
[Description("The Style that is aplied to cells within the
selected Date Range")]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
[NotifyParentProperty(true)]
[PersistenceMode(PersistenceMode.InnerProperty)]
public TableItemStyle SelectedDateRangeStyle
{
get { return selectedDateRangeStyle; }
set { selectedDateRangeStyle = value; }
}
}
}
any help would be much appreceiated...
Simon