نمایش تاریخ فارسی در همه دات نت ها

rezazd

عضو جدید
همتنطور که میدانید دات نت 2 از تاریخ شمسی پشتیبانی میکند به مثال زبر توجه کنید
کد:
[SIZE=2][COLOR=#0000ff]protected[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]void[/COLOR][/SIZE][SIZE=2] Repeater1_ItemDataBound([/SIZE][SIZE=2][COLOR=#0000ff]object[/COLOR][/SIZE][SIZE=2] sender, [/SIZE][SIZE=2][COLOR=#2b91af]RepeaterItemEventArgs[/COLOR][/SIZE][SIZE=2] e)[/SIZE]
[SIZE=2]{[/SIZE]
[SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][SIZE=2] (e.Item.ItemType == [/SIZE][SIZE=2][COLOR=#2b91af]ListItemType[/COLOR][/SIZE][SIZE=2].Item || e.Item.ItemType == [/SIZE][SIZE=2][COLOR=#2b91af]ListItemType[/COLOR][/SIZE][SIZE=2].AlternatingItem)[/SIZE]
[SIZE=2]{[/SIZE]
[SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][SIZE=2] ( e.Item.FindControl([/SIZE][SIZE=2][COLOR=#a31515]"RPLabel1"[/COLOR][/SIZE][SIZE=2]) != [/SIZE][SIZE=2][COLOR=#0000ff]null[/COLOR][/SIZE][SIZE=2])[/SIZE]
[SIZE=2]{[/SIZE]
[SIZE=2]TMPDT = [/SIZE][SIZE=2][COLOR=#2b91af]Convert[/COLOR][/SIZE][SIZE=2].ToDateTime((([/SIZE][SIZE=2][COLOR=#2b91af]Label[/COLOR][/SIZE][SIZE=2])e.Item.FindControl([/SIZE][SIZE=2][COLOR=#a31515]"RPLabel1"[/COLOR][/SIZE][SIZE=2])).Text);[/SIZE]
 
[SIZE=2](([/SIZE][SIZE=2][COLOR=#2b91af]Label[/COLOR][/SIZE][SIZE=2])e.Item.FindControl([/SIZE][SIZE=2][COLOR=#a31515]"RPLabel1"[/COLOR][/SIZE][SIZE=2])).Text = mpd.ShowPerianDate(TMPDT ,[/SIZE][SIZE=2][COLOR=#0000ff]true[/COLOR][/SIZE][SIZE=2],[/SIZE][SIZE=2][COLOR=#0000ff]true[/COLOR][/SIZE][SIZE=2],[/SIZE][SIZE=2][COLOR=#a31515]"/"[/COLOR][/SIZE][SIZE=2] ) ;[/SIZE]
[SIZE=2]}[/SIZE]
[SIZE=2]}[/SIZE]
[SIZE=2]}[/SIZE]
.
.
.
[SIZE=2][COLOR=#0000ff]<[/COLOR][/SIZE][SIZE=2][COLOR=#a31515]td[/COLOR][/SIZE][SIZE=2][COLOR=#ff0000]dir[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]="rtl"[/COLOR][/SIZE][SIZE=2][COLOR=#ff0000]width[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]="120"[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]>[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]<[/COLOR][/SIZE][SIZE=2][COLOR=#a31515]asp[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]:[/COLOR][/SIZE][SIZE=2][COLOR=#a31515]Label[/COLOR][/SIZE][SIZE=2][COLOR=#ff0000]id[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]="RPLabel1"[/COLOR][/SIZE][SIZE=2][COLOR=#ff0000]Text[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]='[/COLOR][/SIZE][SIZE=2]<%#DataBinder.Eval(Container.DataItem, "News_DateTime")%>[/SIZE][SIZE=2][COLOR=#0000ff]'[/COLOR][/SIZE][SIZE=2][COLOR=#ff0000]Runat[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]="server"[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]/>[/COLOR][/SIZE]
</td>

در کد سی شارپ بالا من یک لیبیل را که داخل ریپیتور تعریف کرده بودم هنگام نمایش روی صفحه وب فارسی میکنم در اخر هم یک تکه کد در فایل جداگانه نوشتم که برای من عمل فارسی سازی را انجام میدهد یک تکنیک جالب مهم پیدا کردن و تغییر دادن یک کنترا داخل صفحه در حال رندر شدن است
این یک مثال تکنیکی است فقط برای ایده دادن حتما عزیزان کد های قشنگ تر و بهینه تر می نویسند

کد:
[SIZE=2][COLOR=#0000ff]public[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]class[/COLOR][/SIZE][SIZE=2][COLOR=#2b91af]MyPerDate[/COLOR][/SIZE]
[SIZE=2]{[/SIZE]
[SIZE=2][COLOR=#0000ff]string[/COLOR][/SIZE][SIZE=2][] montname = [/SIZE][SIZE=2][COLOR=#0000ff]new[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]string[/COLOR][/SIZE][SIZE=2][12] { [/SIZE][SIZE=2][COLOR=#a31515]"ه©ي©§یë"[/COLOR][/SIZE][SIZE=2], [/SIZE][SIZE=2][COLOR=#a31515]"ں©§ی ى¬¢"[/COLOR][/SIZE][SIZE=2], [/SIZE][SIZE=2][COLOR=#a31515]"¦©§ں§"[/COLOR][/SIZE][SIZE=2], [/SIZE][SIZE=2][COLOR=#a31515]"¢ï©"[/COLOR][/SIZE][SIZE=2], [/SIZE][SIZE=2][COLOR=#a31515]"ê©§ں§"[/COLOR][/SIZE][SIZE=2], [/SIZE][SIZE=2][COLOR=#a31515]"¬ى©ïي©"[/COLOR][/SIZE][SIZE=2], [/SIZE][SIZE=2][COLOR=#a31515]"êى©"[/COLOR][/SIZE][SIZE=2], [/SIZE][SIZE=2][COLOR=#a31515]"™ ںë"[/COLOR][/SIZE][SIZE=2], [/SIZE][SIZE=2][COLOR=#a31515]"™¨©"[/COLOR][/SIZE][SIZE=2], [/SIZE][SIZE=2][COLOR=#a31515]"§ی"[/COLOR][/SIZE][SIZE=2], [/SIZE][SIZE=2][COLOR=#a31515]" ىêë"[/COLOR][/SIZE][SIZE=2], [/SIZE][SIZE=2][COLOR=#a31515]"ں«هë§"[/COLOR][/SIZE][SIZE=2] };[/SIZE]
[SIZE=2][COLOR=#0000ff]string[/COLOR][/SIZE][SIZE=2][] weekname = [/SIZE][SIZE=2][COLOR=#0000ff]new[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]string[/COLOR][/SIZE][SIZE=2][7] { [/SIZE][SIZE=2][COLOR=#a31515]"ïک¬ë ى"[/COLOR][/SIZE][SIZE=2], [/SIZE][SIZE=2][COLOR=#a31515]"§ي¬ë ى"[/COLOR][/SIZE][SIZE=2], [/SIZE][SIZE=2][COLOR=#a31515]"«ى ¬ë ى"[/COLOR][/SIZE][SIZE=2], [/SIZE][SIZE=2][COLOR=#a31515]"چىں©¬ë ى"[/COLOR][/SIZE][SIZE=2], [/SIZE][SIZE=2][COLOR=#a31515]"پë¤ ¬ë ى"[/COLOR][/SIZE][SIZE=2], [/SIZE][SIZE=2][COLOR=#a31515]"¤êمى"[/COLOR][/SIZE][SIZE=2], [/SIZE][SIZE=2][COLOR=#a31515]"¬ë ى"[/COLOR][/SIZE][SIZE=2] };[/SIZE]
[SIZE=2][COLOR=#0000ff]public[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]string[/COLOR][/SIZE][SIZE=2] ShowPerianDate([/SIZE][SIZE=2][COLOR=#2b91af]DateTime[/COLOR][/SIZE][SIZE=2] Dt, [/SIZE][SIZE=2][COLOR=#0000ff]bool[/COLOR][/SIZE][SIZE=2] mstr, [/SIZE][SIZE=2][COLOR=#0000ff]bool[/COLOR][/SIZE][SIZE=2] westr, [/SIZE][SIZE=2][COLOR=#0000ff]string[/COLOR][/SIZE][SIZE=2] sprator)[/SIZE]
[SIZE=2]{[/SIZE]
[SIZE=2][COLOR=#0000ff]string[/COLOR][/SIZE][SIZE=2] s=[/SIZE][SIZE=2][COLOR=#a31515]""[/COLOR][/SIZE][SIZE=2];[/SIZE]
[SIZE=2][COLOR=#2b91af]PersianCalendar[/COLOR][/SIZE][SIZE=2] jc = [/SIZE][SIZE=2][COLOR=#0000ff]new[/COLOR][/SIZE][SIZE=2][COLOR=#2b91af]PersianCalendar[/COLOR][/SIZE][SIZE=2]();[/SIZE]
 
[SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][SIZE=2] (westr)[/SIZE]
[SIZE=2]s = weekname[[/SIZE][SIZE=2][COLOR=#2b91af]Convert[/COLOR][/SIZE][SIZE=2].ToInt16([/SIZE][SIZE=2][COLOR=#2b91af]Enum[/COLOR][/SIZE][SIZE=2].Parse([/SIZE][SIZE=2][COLOR=#0000ff]typeof[/COLOR][/SIZE][SIZE=2]([/SIZE][SIZE=2][COLOR=#2b91af]DayOfWeek[/COLOR][/SIZE][SIZE=2]), Dt.DayOfWeek.ToString()))]+[/SIZE][SIZE=2][COLOR=#a31515]" "[/COLOR][/SIZE][SIZE=2] ;[/SIZE]
 
[SIZE=2]s += jc.GetDayOfMonth(Dt).ToString() +sprator;[/SIZE]
[SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][SIZE=2] (mstr)[/SIZE]
[SIZE=2]s += montname[jc.GetMonth(Dt)-1] + sprator ;[/SIZE]
[SIZE=2][COLOR=#0000ff]else[/COLOR][/SIZE]
[SIZE=2]s += jc.GetMonth(Dt).ToString() + sprator;[/SIZE]
[SIZE=2]s += jc.GetYear(Dt).ToString();[/SIZE]
[SIZE=2][COLOR=#0000ff]return[/COLOR][/SIZE][SIZE=2] s;[/SIZE]
 
 
 
[SIZE=2]}[/SIZE]
[SIZE=2]}[/SIZE]

نمی دونم چرا بهم ربخته نشان داده شده ! بهر جهت نام فارسی ماهها و روز های هفته را اول کار تعریف کردم
 
آخرین ویرایش توسط مدیر:

yasin_d

عضو جدید
کاربر ممتاز
با اجازه شما ویرایش شد....تگ کد در اینجا به این صورت [] است نه <>.
این پست بنا به درخواست شما حذف خواهد شد
با تشکر
 
بالا