PDA

View Full Version : مبتدی: نحوه استفاده از کلاس persian calende



nafisehk
یک شنبه 22 مرداد 1391, 19:56 عصر
سلام دوستان
من میخوام تاریخ شمسی و تو دیتابیس ذخیره کنم.. آیا روشی بهتر از تبدیل تاریخ به میلادی و ذخیره تاریخ میللادی و تبدیل تاریخ میلادی به شمسی برای بازیابی وجود نداره؟

من مبتدی هستم ممکننه راهنماییم کنید...چه جوری باید از کد زیر استفاده کنم


// Name : C# Calendar
// Author : Terrence Ma
// Email : terrence@terrence.com
// Web : http://www.terrence.com
// Date : V1.0 10/05/2002
// Copyright : © 2002 Terrence Ma
// License : Non-commercial use only
// Warranty : No Warranty
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace calendar
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.Label lblMonth01;
private System.Windows.Forms.ComboBox cbxMonth01;
private System.Windows.Forms.Label lblYear01;
private System.Windows.Forms.ComboBox cbxYear01;
private System.Windows.Forms.MonthCalendar calCal01;
private System.Windows.Forms.Button btnSelect01;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.calCal01 = new System.Windows.Forms.MonthCalendar();
this.lblMonth01 = new System.Windows.Forms.Label();
this.cbxMonth01 = new System.Windows.Forms.ComboBox();
this.lblYear01 = new System.Windows.Forms.Label();
this.cbxYear01 = new System.Windows.Forms.ComboBox();
this.btnSelect01 = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// calCal01
//
this.calCal01.Location = new System.Drawing.Point(60, 30);
this.calCal01.Name = "calCal01";
this.calCal01.TabIndex = 0;
//
// lblMonth01
//
this.lblMonth01.Location = new System.Drawing.Point(8, 256);
this.lblMonth01.Name = "lblMonth01";
this.lblMonth01.Size = new System.Drawing.Size(56, 23);
this.lblMonth01.TabIndex = 1;
this.lblMonth01.Text = "Month :";
this.lblMonth01.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// cbxMonth01
//
this.cbxMonth01.Items.AddRange(new object[] {
"01",
"02",
"03",
"04",
"05",
"06",
"07",
"08",
"09",
"10",
"11",
"12"});
this.cbxMonth01.Location = new System.Drawing.Point(72, 256);
this.cbxMonth01.Name = "cbxMonth01";
this.cbxMonth01.Size = new System.Drawing.Size(48, 24);
this.cbxMonth01.TabIndex = 2;
this.cbxMonth01.Text = "01";
//
// lblYear01
//
this.lblYear01.Location = new System.Drawing.Point(144, 256);
this.lblYear01.Name = "lblYear01";
this.lblYear01.Size = new System.Drawing.Size(40, 23);
this.lblYear01.TabIndex = 3;
this.lblYear01.Text = "Year :";
this.lblYear01.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// cbxYear01
//
this.cbxYear01.Items.AddRange(new object[] {
"1990",
"1991",
"1992",
"1993",
"1994",
"1995",
"1996",
"1997",
"1998",
"1999",
"2000",
"2001",
"2002",
"2003",
"2004",
"2005",
"2006",
"2007",
"2008",
"2009",
"2010",
"2011",
"2012",
"2013",
"2014",
"2015",
"2016",
"2017",
"2018",
"2019",
"2020",
"2021",
"2022",
"2023",
"2024",
"2025",
"2026",
"2027",
"2028",
"2029",
"2030"});
this.cbxYear01.Location = new System.Drawing.Point(192, 256);
this.cbxYear01.Name = "cbxYear01";
this.cbxYear01.Size = new System.Drawing.Size(62, 24);
this.cbxYear01.TabIndex = 4;
this.cbxYear01.Text = "1990";
//
// btnSelect01
//
this.btnSelect01.Location = new System.Drawing.Point(280, 256);
this.btnSelect01.Name = "btnSelect01";
this.btnSelect01.Size = new System.Drawing.Size(62, 23);
this.btnSelect01.TabIndex = 5;
this.btnSelect01.Text = "Select";
this.btnSelect01.Click += new System.EventHandler(this.btnSelect01_Click);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 15);
this.ClientSize = new System.Drawing.Size(352, 320);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.btnSelect01,
this.cbxYear01,
this.lblYear01,
this.cbxMonth01,
this.lblMonth01,
this.calCal01});
this.Name = "Form1";
this.Text = "C# Calendar";
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void btnSelect01_Click(object sender, System.EventArgs e)
{
string DateSelect01 = cbxMonth01.Text + "/1/" +cbxYear01.Text;
calCal01.SelectionRange = new SelectionRange(
Convert.ToDateTime(DateSelect01),
Convert.ToDateTime(DateSelect01));
}
}
}

veniz2008
یک شنبه 22 مرداد 1391, 20:23 عصر
سلام. به نظر من بهتره از nvarchar(10) برای ذخیره کردن تاریخ استفاده کنی. البته میتونی از datetime هم استفاده کنی ولی موقع خوندن از دیتابیس باید یک تبدیل انجام بدی و تاریخ رو به شمسی تبدیل کنی. راه اول ساده تر هست.
موفق باشید.

nafisehk
یک شنبه 22 مرداد 1391, 21:55 عصر
من قبلا از 1 masked textbox با مسک 00/00/0000 استاده کردم و محتویات اون رو تو فیلد char(10) ریختم ... اما اگه کاربر تاریخ رو وارد نکنه داخل db // ذخیره میشه و برای مقایسه با مشکل مواجه میشم... از طرفی باید رشته ها مقایسه شن

nafisehk
یک شنبه 22 مرداد 1391, 21:58 عصر
من چطور میتونم از کلاس بالا استفاده کنم...لطفا راهنماییم کنید چن روز بیشتر تا تحویل پروژم نمونده

tooraj_azizi_1035
یک شنبه 22 مرداد 1391, 22:12 عصر
تاریخ رو با char(10) تو دیتابیس ذخیره کن. تو مقایسه تاریخ هم رشته ای با هم مقایسه می شن که نتیجه همونیه کا ما میخواییم. چیز دیگه ای هست؟ در رابطه با اون مشکل هم
HidePromptOnLeaveرو true کن ببین تاثیر داره.

nafisehk
یک شنبه 22 مرداد 1391, 22:18 عصر
چطور می تونم از کلاس بالا استفاده کنم؟ ؟

tooraj_azizi_1035
یک شنبه 22 مرداد 1391, 22:27 عصر
using System;
using System.Globalization;

class Sample
{
public static void Main()
{
//--------------------------------------------------------------------------------
// Get today's date.
//--------------------------------------------------------------------------------
Console.WriteLine("\n................. Today ...........................\n");
PersianCalendar jc = new PersianCalendar();
DateTime thisDate = DateTime.Now;

// Display the current date using the Gregorian and Persian calendars.
Console.WriteLine("Today is:");
Console.WriteLine(" {0:dddd}, {0} in the Gregorian calendar.", thisDate);
Console.WriteLine(" {0}, {1}/{2}/{3} {4}:{5}:{6} in the Persian calendar.",
jc.GetDayOfWeek(thisDate),
jc.GetMonth(thisDate),
jc.GetDayOfMonth(thisDate),
jc.GetYear(thisDate),
jc.GetHour(thisDate),
jc.GetMinute(thisDate),
jc.GetSecond(thisDate));
//--------------------------------------------------------------------------------
// Fields
//--------------------------------------------------------------------------------
Console.WriteLine("\n............... Fields .............................\n");
Console.WriteLine("PersianEra = {0}", PersianCalendar.PersianEra);
//--------------------------------------------------------------------------------
// Properties
//--------------------------------------------------------------------------------
Console.WriteLine("\n............... Properties .........................\n");
Console.Write("Eras:");
foreach (int era in jc.Eras)
{
Console.WriteLine(" era = {0}", era);
}
//--------------------------------------------------------------------------------
Console.WriteLine("\nGregorian Date Range Supported by the Persian Calendar:");
Console.WriteLine(" From {0:G}", jc.MinSupportedDateTime);
Console.WriteLine(" To {0:G}", jc.MaxSupportedDateTime);
//--------------------------------------------------------------------------------
Console.WriteLine("\nTwoDigitYearMax = {0}", jc.TwoDigitYearMax);
//--------------------------------------------------------------------------------
// Methods
//--------------------------------------------------------------------------------
Console.WriteLine("\n............ Selected Methods .......................\n");

//--------------------------------------------------------------------------------
Console.WriteLine("GetDayOfYear: day = {0}", jc.GetDayOfYear(thisDate));
//--------------------------------------------------------------------------------
Console.WriteLine("GetDaysInMonth: days = {0}",
jc.GetDaysInMonth( thisDate.Year, thisDate.Month,
PersianCalendar.PersianEra));
//--------------------------------------------------------------------------------
Console.WriteLine("GetDaysInYear: days = {0}",
jc.GetDaysInYear(thisDate.Year, PersianCalendar.PersianEra));
//--------------------------------------------------------------------------------
Console.WriteLine("GetLeapMonth: leap month (if any) = {0}",
jc.GetLeapMonth(thisDate.Year, PersianCalendar.PersianEra));
//-------------------------------------------------------------
Console.WriteLine("GetMonthsInYear: months in a year = {0}",
jc.GetMonthsInYear(thisDate.Year, PersianCalendar.PersianEra));
//--------------------------------------------------------------------------------
Console.WriteLine("IsLeapDay: This is a leap day = {0}",
jc.IsLeapDay(thisDate.Year, thisDate.Month, thisDate.Day,
PersianCalendar.PersianEra));
//--------------------------------------------------------------------------------
Console.WriteLine("IsLeapMonth: This is a leap month = {0}",
jc.IsLeapMonth(thisDate.Year, thisDate.Month,
PersianCalendar.PersianEra));
//--------------------------------------------------------------------------------
Console.WriteLine("IsLeapYear: 1370 is a leap year = {0}",
jc.IsLeapYear(1370, PersianCalendar.PersianEra));
//--------------------------------------------------------------------------------

// Get the 4-digit year for a year whose last two digits are 99. The 4-digit year
// depends on the current value of the TwoDigitYearMax property.

Console.WriteLine("ToFourDigitYear:");
Console.WriteLine(" If TwoDigitYearMax = {0}, ToFourDigitYear(99) = {1}",
jc.TwoDigitYearMax, jc.ToFourDigitYear(99));
jc.TwoDigitYearMax = thisDate.Year;
Console.WriteLine(" If TwoDigitYearMax = {0}, ToFourDigitYear(99) = {1}",
jc.TwoDigitYearMax, jc.ToFourDigitYear(99));
}
}
// The example displays the following output:
// ................. Today ...........................
//
// Today is:
// Tuesday, 3/20/2012 7:54:00 AM in the Gregorian calendar.
// Tuesday, 1/1/1391 7:54:0 in the Persian calendar.
//
// ............... Fields .............................
//
// PersianEra = 1
//
// ............... Properties .........................
//
// Eras: era = 1
//
// Gregorian Date Range Supported by the Persian Calendar:
// From 3/21/0622 12:00:00 AM
// To 12/31/9999 11:59:59 PM
//
// TwoDigitYearMax = 99
//
// ............ Selected Methods .......................
//
// GetDayOfYear: day = 1
// GetDaysInMonth: days = 31
// GetDaysInYear: days = 365
// GetLeapMonth: leap month (if any) = 0
// GetMonthsInYear: months in a year = 12
// IsLeapDay: This is a leap day = False
// IsLeapMonth: This is a leap month = False
// IsLeapYear: 1370 is a leap year = True
// ToFourDigitYear:
// If TwoDigitYearMax = 99, ToFourDigitYear(99) = 99
// If TwoDigitYearMax = 2012, ToFourDigitYear(99) = 1999

nafisehk
یک شنبه 22 مرداد 1391, 22:41 عصر
ببخشید اقای تورج من مبتدی ام میسه بگید چه جوری باید از این کد استفاده کنم و این کد چکاری انجام میده؟

veniz2008
یک شنبه 22 مرداد 1391, 23:25 عصر
ببینید دوست من شما باید علم دیگران رو یاد بگیری و بعدش به سبک خودت کدنویسی کنی. شما دقیقا بگو چی میخوای تا دوستان راهنماییتون کنن. من پست اول شما رو خوندم درباره نحوه ذخیره سازی تاریخ گفته بودید. دقیقا چکاری رو میخواید انجام بدید؟