Introduction
The requirement of programming projects is to display date in standard format. This paper has tried to use Visual Studio features for time display.
Figure 1 - This picture shows an example of how classes are used.
Requirements
You will need the following tools before using the class. These tools are needed for development:
- Visual Studio .NET
- .NET Framework 2.0 or higher
Using the Code
public class ClassGetShamsiDay
{
private String DayName;
private String MonthName;
private String CompleteShamsiDate;
public ClassGetShamsiDay()
{
DateTime dt = DateTime.Now;
if (dt.DayOfWeek == DayOfWeek.Friday)
DayName = "جمعه";
if (dt.DayOfWeek == DayOfWeek.Saturday)
DayName = "شنبه";
if (dt.DayOfWeek == DayOfWeek.Sunday)
DayName = "یکشنبه";
if (dt.DayOfWeek == DayOfWeek.Monday)
DayName = "دوشنبه";
if (dt.DayOfWeek == DayOfWeek.Tuesday)
DayName = "سه شنبه";
if (dt.DayOfWeek == DayOfWeek.Wednesday)
DayName = "چهار شنبه";
if (dt.DayOfWeek == DayOfWeek.Thursday)
DayName = "پنج شنبه";
PersianCalendar pt = new PersianCalendar();
int MoName = pt.GetMonth(dt);
switch (MoName)
{
case 1:
MonthName = "فروردین";
break;
case 2:
MonthName = "اردیبهشت";
break;
case 3:
MonthName = "خرداد";
break;
case 4:
MonthName = "تیر";
break;
case 5:
MonthName = "مرداد";
break;
case 6:
MonthName = "شهریور";
break;
case 7:
MonthName = "مهر";
break;
case 8:
MonthName = "آبان";
break;
case 9:
MonthName = "آذر";
break;
case 10:
MonthName = "دی";
break;
case 11:
MonthName = "بهمن";
break;
case 12:
MonthName = "اسفند";
break;
}
CompleteShamsiDate = "امروز " + DayName + " " + pt.GetDayOfMonth(dt) +
" " + MonthName + " " + pt.GetYear(dt) + " می باشد. ";
}
public String CRDaysName
{
set
{
DayName = value;
}
get
{
return DayName;
}
}
public String CRMotheName
{
set
{
MonthName = value;
}
get
{
return MonthName;
}
}
public String CRCompleteShamsiDate
{
set
{
CompleteShamsiDate = value;
}
get
{
return CompleteShamsiDate;
}
}
}
Figure 2
Using the DLL File
To use, the class should be added to the project. For this purpose, from the solution explorer, click on References. Then, click on the Add References... (as shown in Figure 2 above)
Figure 3
Then a window opens. DLL File Choose and then click on OK (see Figure 3).
Figure 4
After this step, the file has been added to the project (Figure 4).
How to Use
For using class, you need a form and button. On the Click Event, we program:
private void button1_Click(object sender, EventArgs e)
{
ShamsiDayLists.ClassGetShamsiDay shamsiDay = new ShamsiDayLists.ClassGetShamsiDay();
label1.Text = shamsiDay.CRCompleteShamsiDate;
label2.Text = shamsiDay.CRDaysName;
label3.Text = shamsiDay.CRMotheName;
}
Figure 5
Conclusion
Now you can create as many forms and reports as you want and use the custom control to view complete Shamsi date in complete string mode. If you need help, do not hesitate to contact me.