public bool SetValue(object value) { if (textBox is PDatePicker) { if (valueIsString && stringDateIsMiladi == false) { (textBox as PDatePicker).SelectedPersianDate = value?.ToString(); } else { (textBox as PDatePicker).SelectedDate = value?.ToString(); } } else { if (value != null && valueIsString && stringDateIsMiladi == false) { var date = AgentHelper.GetMiladiDateFromShamsi(value.ToString()); } else { (textBox as DatePicker).Text = value?.ToString(); } } return(true); }
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { if (value != null && value.ToString() != "") { return(AgentHelper.GetMiladiDateFromShamsi(value.ToString())); } else { return(null); } }
private void TxtShamsiDatePicker_SelectedDateChanged(object sender, SelectionChangedEventArgs e) { if (!shamsiIsChangingMiladi && !miladiIsChangingShamsi) { shamsiIsChangingMiladi = true; if (string.IsNullOrEmpty(txtShamsiDatePicker.SelectedPersianDate)) { txtMiladiDatePicker.SelectedDate = null; } else { txtMiladiDatePicker.SelectedDate = AgentHelper.GetMiladiDateFromShamsi(txtShamsiDatePicker.SelectedPersianDate); } shamsiIsChangingMiladi = false; } }
public static DateTime?ReadValueFromProperty(object value, DateConverterParameter param) { DateTime?dateTime = null; if (value != null && value.ToString() != "") { if (param.valueIsString) { if (!param.hasnotDatePicker) { string stringdate = null; if (param.hasnotTimePicker) { stringdate = value.ToString(); } else { stringdate = value.ToString().Split(' ')[0]; } if (param.stringDateIsMiladi == false) { dateTime = AgentHelper.GetMiladiDateFromShamsi(stringdate); } else { dateTime = Convert.ToDateTime(stringdate); } } if (!param.hasnotTimePicker) { string stringtime = null; if (param.hasnotDatePicker) { stringtime = value.ToString(); } else { stringtime = value.ToString().Split(" ".ToCharArray(), 2)[1]; } if (param.stringTimeIsMiladi == false && param.stringTimeISAMPMFormat == true) { stringtime = stringtime.Replace("ق.ظ", "AM").Replace("ب.ظ", "PM"); } DateTime time; if (DateTime.TryParse(stringtime, out time)) { if (dateTime == null) { dateTime = time; } else { dateTime = dateTime.Value.Add(time.TimeOfDay); } } } } else { //اگر نوع خصوصیت تایم باشه در دیتابیس مقدار تایم اسپن میاد if (value is TimeSpan) { dateTime = DateTime.Today.Add((TimeSpan)value); } else { dateTime = Convert.ToDateTime(value); } } } return(dateTime); }