راجع به این سوال یه خورده بگردی تو تاپیک ها کامل توضیح دادند اما من اومدم این کارو کردم.
private void Shoro()
{
string Temp;
string keyValue;
RegistryKey key = Registry.CurrentUser.CreateSubKey("SOFTWARE");
keyValue = key.GetValue("RoozeShoro", "").ToString();
if (keyValue == "")
{
Temp = Miladi2Shamsi(DateTime.Now);
RegistryKey key2 = Registry.CurrentUser.CreateSubKey("SOFTWARE");
key2.SetValue("RoozeShoro", Temp, RegistryValueKind.String);
key2.SetValue("TarikheRooz", Temp, RegistryValueKind.String);
key2.SetValue("Tedad", "1", RegistryValueKind.String);
return;
}
else
{
if (Etebar() == false)
{
c1 = 1;
Form3 FRegister = new Form3();
FRegister.Show();
MessageBox.Show(" - لطفا با برنامه نویس تماس بگیرید", "اطلاعات", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
}
private bool Etebar()
{
bool returnValue;
string keyValue0;
string keyValue;
string keyValue1;
string TarikheRooz;
string Temp;
RegistryKey key = Registry.CurrentUser.CreateSubKey("SOFTWARE");
keyValue = key.GetValue("TarikheRooz", "").ToString();
RegistryKey key1 = Registry.CurrentUser.CreateSubKey("SOFTWARE");
keyValue0 = key1.GetValue("RoozeShoro", "").ToString();
TarikheRooz = Miladi2Shamsi(DateTime.Now);
long adad = DiffOfShamsiDate(keyValue0, TarikheRooz);
RegistryKey key2 = Registry.CurrentUser.CreateSubKey("SOFTWARE");
keyValue1 = key2.GetValue("Tedad", "").ToString();
if ((adad < 0 ) & (keyValue1 !="ok" ))
{
MessageBox.Show("به دلیل تغییر تاریخ برنامه از کار معلق شده است لطفا تاریخ سیستم را بروز کنید", "اطلاعات", MessageBoxButtons.OK, MessageBoxIcon.Information);
return false;
}
returnValue = true;
if (keyValue1 != "ok")
{
if ((keyValue != TarikheRooz) || (Convert.ToInt16(keyValue1) <= 60))
{
Temp = Miladi2Shamsi(DateTime.Now);
keyValue1 = Convert.ToString(Convert.ToInt16(keyValue1) + Convert.ToInt16(DiffOfShamsiDate(keyValue, Temp).ToString()));
key2.SetValue("Tedad", keyValue1, RegistryValueKind.String);
key2.SetValue("TarikheRooz", Temp, RegistryValueKind.String);
}
if (Convert.ToInt16(keyValue1) >= 60)
returnValue = false;
else
returnValue = true;
return returnValue;
}
else
{
returnValue = true;
return returnValue;
}
}
اینم برای پیدا کردن اختلاف روز
public long DiffOfShamsiDate(string shmasidatestart, string shmasidateend)
{
long Diffdate = 0;
System.Globalization.PersianCalendar dc = new System.Globalization.PersianCalendar();
int yy, mm, dd;
yy = Int32.Parse(shmasidatestart.Substring(0, 4));
mm = Int32.Parse(shmasidatestart.Substring(5, 2));
dd = Int32.Parse(shmasidatestart.Substring(8, 2));
DateTime tstart = dc.ToDateTime(yy, mm, dd, 0, 0, 0, 0);
yy = Int32.Parse(shmasidateend.Substring(0, 4));
mm = Int32.Parse(shmasidateend.Substring(5, 2));
dd = Int32.Parse(shmasidateend.Substring(8, 2));
DateTime tend = dc.ToDateTime(yy, mm, dd, 0, 0, 0, 0);
string diff = Convert.ToString((tend - tstart));
int temp = diff.LastIndexOf('.');
if (temp > 0)
Diffdate = Convert.ToInt64(diff.Substring(0, temp));
return Diffdate;
}
using Microsoft.Win32
اگه به کارت اومد تشکر فراموش نشه. سوالی بود در خدمتم