PDA

View Full Version : شمسی کردن کامپوننت های date editor و scheduler در devexpress



Hossein.R1369
شنبه 31 شهریور 1397, 23:35 عصر
با سلام خدمت دوستان
من تا حدی تونستم با مِتد زیر انجام بدم، تقویم devexpress رو شمسی کنم و یه مشکلی هم دارم:
public void ToPersian(DevExpress.XtraEditors.DateEdit DateTimePicker){
System.Globalization.PersianCalendar Shamsi = new System.Globalization.PersianCalendar();
DateTime PersianToday = Shamsi.GetYear(DateTime.Now) + "/" + Shamsi.GetMonth(DateTime.Now) + "/" + Shamsi.GetDayOfMonth(DateTime.Now);
System.Threading.Thread.CurrentThread.CurrentCultu re = new System.Globalization.CultureInfo("fa-IR");
System.Threading.Thread.CurrentThread.CurrentCultu re.DateTimeFormat.MonthNames = new string[] { "فروردین", "اردیبهشت", "خرداد", "تیر", "مرداد", "شهریور", "مهر", "آبان", "آذر", "دی", "بهمن", "اسفند", "" };
System.Threading.Thread.CurrentThread.CurrentCultu re.DateTimeFormat.MonthGenitiveNames = new string[] { "فروردین", "اردیبهشت", "خرداد", "تیر", "مرداد", "شهریور", "مهر", "آبان", "آذر", "دی", "بهمن", "اسفند", "" };
System.Threading.Thread.CurrentThread.CurrentCultu re.DateTimeFormat.AbbreviatedMonthNames = new string[] { "فروردین", "اردیبهشت", "خرداد", "تیر", "مرداد", "شهریور", "مهر", "آبان", "آذر", "دی", "بهمن", "اسفند", "" };
System.Threading.Thread.CurrentThread.CurrentCultu re.DateTimeFormat.AbbreviatedMonthGenitiveNames = new string[] { "فروردین", "اردیبهشت", "خرداد", "تیر", "مرداد", "شهریور", "مهر", "آبان", "آذر", "دی", "بهمن", "اسفند", "" };
System.Threading.Thread.CurrentThread.CurrentCultu re.DateTimeFormat.AbbreviatedDayNames = new string[] { "ی", "د", "س", "چ", "پ", "ج", "ش" };
System.Threading.Thread.CurrentThread.CurrentCultu re.DateTimeFormat.ShortestDayNames = new string[] { "ی", "د", "س", "چ", "پ", "ج", "ش" };
System.Threading.Thread.CurrentThread.CurrentCultu re.DateTimeFormat.DayNames = new string[] { "یکشنبه", "دوشنبه", "ﺳﻪشنبه", "چهارشنبه", "پنجشنبه", "جمعه", "شنبه" };
System.Threading.Thread.CurrentThread.CurrentCultu re.DateTimeFormat.AMDesignator = "ق.ظ";
System.Threading.Thread.CurrentThread.CurrentCultu re.DateTimeFormat.PMDesignator = "ب.ظ";
System.Threading.Thread.CurrentThread.CurrentCultu re.DateTimeFormat.ShortTimePattern = "HH:mm";
System.Threading.Thread.CurrentThread.CurrentCultu re.DateTimeFormat.DateSeparator = "/";
System.Threading.Thread.CurrentThread.CurrentCultu re.DateTimeFormat.FullDateTimePattern = "dd/MM/yyyy HH:mm";
System.Threading.Thread.CurrentThread.CurrentCultu re.DateTimeFormat.FirstDayOfWeek = DayOfWeek.Saturday;
System.Threading.Thread.CurrentThread.CurrentCultu re.DateTimeFormat.ShortDatePattern = "dd/MM/yyyy";
System.Threading.Thread.CurrentThread.CurrentCultu re.DateTimeFormat.LongDatePattern = "dd/MM/yyyy HH:mm";
System.Threading.Thread.CurrentThread.CurrentCultu re.DateTimeFormat.SetAllDateTimePatterns(new string[] { "dd/MM/yyyy" }, 'd');
System.Threading.Thread.CurrentThread.CurrentCultu re.DateTimeFormat.SetAllDateTimePatterns(new string[] { "dddd, dd MMMM yyyy" }, 'D');
System.Threading.Thread.CurrentThread.CurrentCultu re.DateTimeFormat.SetAllDateTimePatterns(new string[] { "yyyy MMMM" }, 'y');
System.Threading.Thread.CurrentThread.CurrentCultu re.DateTimeFormat.SetAllDateTimePatterns(new string[] { "yyyy MMMM" }, 'Y');

DateTimePicker.EditValue = PersianToday;
DateTimePicker.Properties.TodayDate = PersianToday;
DateTimePicker.Properties.EditFormat.FormatType = DevExpress.Utils.FormatType.DateTime;
DateTimePicker.Properties.DisplayFormat.FormatType = DevExpress.Utils.FormatType.DateTime;
DateTimePicker.Properties.FirstDayOfWeek = DayOfWeek.Saturday;
DateTimePicker.Properties.EditMask = "yyyy/MM/dd";
DateTimePicker.Properties.Mask.UseMaskAsDisplayFor mat = true;
DateTimePicker.RightToLeft = RightToLeft.Yes;
}

نتیجه کار به شکل زیر شده:

148928


فقط اینجا یه مشکلی هست روزهای هفته درست قرار نمیگیره و شش ماه دوم 31 روز هم داره. مثلا ماه اسفند!! که اگر اساتید راهنمایی کنن این مورد هم حل میشه....