السلام عليكم ورحمة الله
لدي مشكلة مع هذا الكود وهو كود لعمل تذكير reminder
وهو في الأساس كود يتم من قبل المستخدم تحديد عنوان ووصف للمهمة التي يرغب أن يقوم المنبه بتذكيره بها ويحدد وقت وتاريخ بداية ونهاية
الكود يعمل هكذا
أريد أن أجعل البرنامج يقوم بإضافة شهرين على تاريخ المهمة ويعمل تذكير أخر لنفس المهمة بعد شهرين وعملت ذلك
إلا أن هناك مشكلة مع التاريخ الجديد الذي عملته
وهو V2Time عبارة عن التاريخ المدخل مضاف إليه شهرين والوقت والمشكلة تكمن تحديدا في date2 المضاف إليه شهرين
DateTime time = (DateTime)beginTimePicker.Value;
DateTime date = (DateTime)beginDatePicker.Value;//birthdate
DateTime date2 = date.AddMonths(2);
DateTime beginTime = date + time.TimeOfDay;
DateTime V2Time = date2 + time.TimeOfDay;
وقد جربت أن أجعل date وهو التاريخ fبدلا من date2 ونفع فدلني إلى أن الخطأ في date2 الذيتغير صيغته بعد إضافة الشهرين فلم يعد يقبله كلاس الريميندر
وهنا الكود كامل وحددت مكان المشكلة
أرجو منكم مساعدتي في حل المشكلة ولكم جزيل الشكر والعرفان
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Scheduler;
using System.IO.IsolatedStorage;
using System.IO;
namespace ReminderSample
{
public partial class AddReminder : PhoneApplicationPage
{
public AddReminder()
{
InitializeComponent();
}
/// <summary>
/// for isolated file
/// </summary>
// IsolatedStorageFile myIsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication();
private IsolatedStorageSettings appSettingsA = IsolatedStorageSettings.ApplicationSettings;
private void ApplicationBarSaveButton_Click(object sender, EventArgs e)
{
// Generate a unique name for the new reminder. You can choose a
// name that is meaningful for your app, or just use a GUID.
String name = System.Guid.NewGuid().ToString();
String name2 = System.Guid.NewGuid().ToString();
// Get the begin time for the reminder by combining the DatePicker
// value and the TimePicker value.
DateTime time = (DateTime)beginTimePicker.Value;
DateTime date = (DateTime)beginDatePicker.Value;//birthdate
DateTime date2 = date.AddMonths(2);
DateTime beginTime = date + time.TimeOfDay;
DateTime V2Time = date2 + time.TimeOfDay;//المشكلة من date2
/////date2 convert to string thane add to isolated file////
string vChvDate2 = date2.ToString("dd/MM/yyyy");
string BirthDate = date.ToString("dd/MM/yyyy");
try
{
appSettingsA.Add("birth", BirthDate);
appSettingsA.Add("V2", vChvDate2);
}
catch
//catch(ArgumentException ex)
{
//string c = "error";
//MessageBox.Show(c);
}
// Make sure that the begin time has not already passed.
if (beginTime < DateTime.Now)
{
MessageBox.Show("the begin date must be in the future.");
return;
}
// Get the expiration time for the reminder
DateTime dateX = (DateTime)expirationDatePicker.Value;
DateTime timeX = (DateTime)expirationTimePicker.Value;
DateTime expirationTime = dateX + timeX.TimeOfDay;
// Make sure that the expiration time is after the begin time.
if (expirationTime < beginTime)
{
MessageBox.Show("expiration time must be after the begin time.");
return;
}
// Determine which recurrence radio button is checked.
RecurrenceInterval recurrence = RecurrenceInterval.None;
if (dailyRadioButton.IsChecked == true)
{
recurrence = RecurrenceInterval.Daily;
}
else if (weeklyRadioButton.IsChecked == true)
{
recurrence = RecurrenceInterval.Weekly;
}
else if (monthlyRadioButton.IsChecked == true)
{
recurrence = RecurrenceInterval.Monthly;
}
else if (endOfMonthRadioButton.IsChecked == true)
{
recurrence = RecurrenceInterval.EndOfMonth;
}
else if (yearlyRadioButton.IsChecked == true)
{
recurrence = RecurrenceInterval.Yearly;
}
// Create a Uri for the page that will be launched if the user
// taps on the reminder. Use query string parameters to pass
// content to the page that is launched.
//string param1Value = param1TextBox.Text;
//string param2Value = param2TextBox.Text;
//string queryString = "";
//if (param1Value != "" && param2Value != "")
//{
// queryString = "?param1=" + param1Value + "¶m2=" + param2Value;
//}
//else if(param1Value != "" || param2Value != "")
//{
// queryString = (param1Value!=null) ? "?param1="+param1Value : "?param2="+param2Value;
//}
//Uri navigationUri = new Uri("/ShowParams.xaml" + queryString, UriKind.Relative);
Reminder reminder = new Reminder(name);
reminder.Title = titleTextBox.Text;
reminder.Content = contentTextBox.Text;
reminder.BeginTime = beginTime;
reminder.ExpirationTime = expirationTime;
reminder.RecurrenceType = recurrence;
// reminder.NavigationUri = navigationUri;
// date2 V2Time
Reminder reminder2 = new Reminder(name2);
reminder2.Title = titleTextBox.Text;
reminder2.Content = contentTextBox.Text;
reminder2.BeginTime = V2Time;//هنا المشكلة
reminder2.ExpirationTime = expirationTime;
reminder2.RecurrenceType = recurrence;
// reminder2.NavigationUri = navigationUri;
// Register the reminder with the system.
ScheduledActionService.Add(reminder);
ScheduledActionService.Add(reminder2);
// Navigate back to the main reminder list page.
NavigationService.GoBack();
}
}
}
]