Click here to Skip to main content
Click here to Skip to main content
Articles » Languages » C# » Date / Time » Downloads
 
Add your own
alternative version

Persian Calendar with Tray Icon

, 12 Mar 2012 CPOL
A Persian calendar that shows a tray icon
traycalande-binary.zip
hijri.mdb
mytray.exe
traycalande-source.zip
traycalande-source
bin
Release
ClassDiagram1.cd
ClassDiagram2.cd
CrystalReport1.rpt
CrystalReport_task.rpt
CrystalReport_taskall.rpt
hijri.mdb
In_DataSet.xsc
In_DataSet.xss
mytray.csproj.user
mytray.csproj.vspscc
mytray.suo
mytray.vssscc
mytray_TemporaryKey.pfx
Properties
Settings.settings
vssver.scc
Resources
icon1.ico
icon10.ico
icon11.ico
icon12.ico
icon13.ico
icon14.ico
icon15.ico
icon16.ico
icon17.ico
icon18.ico
icon19.ico
icon2.ico
icon20.ico
icon21.ico
icon22.ico
icon23.ico
icon24.ico
icon25.ico
icon26.ico
icon27.ico
icon28.ico
icon29.ico
icon3.ico
icon30.ico
icon31.ico
icon4.ico
icon5.ico
icon6.ico
icon7.ico
icon8.ico
icon9.ico
tumb.jpg
vssver.scc
vssver2.scc
��using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Text;

using System.Windows.Forms;

using mytray.Properties;



namespace mytray

{

    public partial class Form_Calendar : Form

    {

        Form_Task form_task = new Form_Task();

        int CurrentMonth=0;

        int CurrentYear=0;

        CPersianCalender theCalender = new CPersianCalender();

        MyDataBase db = new MyDataBase();

        public int GhamariAdjust

        {

            set

            {

                theCalender.SetGhamariAdjust(value);

                if(CurrentMonth!=0 && CurrentYear!=0)

                CreatMonthCalendar(CurrentMonth, CurrentYear);

            }

        }



        string GetDayInfo(int PersianYear, int PersianMonth,int PersianDay, out bool Vacation)

        {

            int[] d = theCalender.ConvertPersianTOGhamariDate(PersianYear,PersianMonth,PersianDay);

           

            bool Vacation_shamsi, Vacation_ghamari;

            string Comment_shamsi = db.GetShamsiDayInfo(PersianDay, PersianMonth, out Vacation_shamsi);



            string Comment_Ghamari = db.GetGhamariDayInfo(d[2], d[1], out Vacation_ghamari);

            string Comment="";

            if (Comment_shamsi != "")

                    Comment+= Comment_shamsi;

            if(Comment_shamsi != "" && Comment_Ghamari != "")

                Comment+="\n";

            if (Comment_Ghamari != "")

                    Comment +=Comment_Ghamari;



            Vacation = Vacation_shamsi || Vacation_ghamari;

            return Comment;

          }



       void CreatMonthCalendar(int Month,int Year)

        {

          ///////////////////////

            dataGridView1.Rows.Clear();

            Form_Task ftask = new Form_Task();

           ///find the first day of month weekday

           ///

            int FistdayDayofWeek = theCalender.GetDayOfWeek(1/*fist day of month*/, Month, Year);

            int DaysOfPersianMonth = theCalender.GetDaysOfPersianMonth(Month, Year);



            int[] ff = theCalender.GetPersianDate();

            int NowYear = ff[0];

            int NowMonth = ff[1];

            int NowDay = ff[2];



            

            int k = -1;

            int j = 0;

            for (int i = 1; i < DaysOfPersianMonth + FistdayDayofWeek; i++)

            {

                if (i % 7 == 1) 

                {

                    dataGridView1.Rows.Add();

                    k++; j = 6;

                }

                 DataGridViewRow drow = dataGridView1.Rows[k];

                 if (i >= FistdayDayofWeek)

                 {

                     //drow.Cells[j].Style.SelectionBackColor = System.Drawing.Color.White;

                     int DayNumber = i - FistdayDayofWeek + 1;

                     drow.Cells[j].Value = DayNumber.ToString();

                     drow.Cells[j].ToolTipText = theCalender.GetDayFullTooltip(DayNumber, Month, Year);

                     // drow.Cells[j].di





                     if (i - FistdayDayofWeek + 1 == NowDay && NowMonth == CurrentMonth && NowYear == CurrentYear)

                     {

                         drow.Cells[j].Style.BackColor = System.Drawing.SystemColors.HotTrack;

                         drow.Cells[j].Style.ForeColor = System.Drawing.Color.White;

                         drow.Cells[j].Style.SelectionBackColor = System.Drawing.SystemColors.HotTrack;

                         drow.Cells[j].Style.SelectionForeColor = System.Drawing.Color.White;





                     }

                     bool Vacation;

                     string Comment = GetDayInfo(Year, Month,DayNumber,out Vacation);

                     if (Comment != "")

                         drow.Cells[j].ToolTipText +="\n"+Comment;

                     if (i % 7 == 0 || Vacation == true)

                     {

                         drow.Cells[j].Style.ForeColor = System.Drawing.Color.Red;

                         drow.Cells[j].Style.SelectionForeColor = System.Drawing.Color.Red;

                     }

                    drow.Cells[j].Tag = Year.ToString() + "/" + Month.ToString() + "/" + DayNumber.ToString();

                    ftask.Date = (string)drow.Cells[j].Tag;

                    if (ftask.TaskCount > 0 && Settings.Default.ShowTask==true)

                    {

                        drow.Cells[j].Style.ForeColor = Color.White;

                        drow.Cells[j].Style.SelectionForeColor = Color.White;

                        drow.Cells[j].Style.BackColor = Color.Black;

                        drow.Cells[j].Style.SelectionBackColor = Color.Black;



                    }

                    

                 }

                j--;



            }

            label_mon_day.Text = theCalender.GetMonthName(CurrentMonth) + " " + Convert.ToString(CurrentYear);

     

        }

        public void GoToCurrentDate()

        {

            int[] ff = theCalender.GetPersianDate();

            int yy = ff[0];

            int mm = ff[1];

            int dd = ff[2];

            CurrentMonth = mm;

            CurrentYear = yy;

            int dayOfWeek = theCalender.GetDayOfWeek(dd, mm, yy);

            CreatMonthCalendar(CurrentMonth, CurrentYear);

            label_Today.Text = "'E1H2 :  " + theCalender.GetDayOfWeekName(dayOfWeek)

                + " " + Convert.ToString(dd) + " " + theCalender.GetMonthName(mm) 

                + " " + Convert.ToString(yy);

  

        }



        private void GoToNextYear()

        {

           

            CurrentYear++;

            CreatMonthCalendar(CurrentMonth, CurrentYear);

        }



        private void GoToPervYear()

        {

            CurrentYear--;

            CreatMonthCalendar(CurrentMonth, CurrentYear);

        }



        public Form_Calendar()

        {

            InitializeComponent();

            Screen Srn = Screen.PrimaryScreen;



            if (Srn.WorkingArea.X == 0 && Srn.WorkingArea.Y == 0)

            {

                this.Left = Srn.WorkingArea.Width - this.Width;

                this.Top = Srn.WorkingArea.Height - this.Height;

            }



            if (Srn.WorkingArea.Y > 0)//start menu is on top of screen

            {

                this.Left = Srn.WorkingArea.Width - this.Width;

                this.Top = Srn.WorkingArea.Y;



            }



            if (Srn.WorkingArea.X > 0)//start menu is on left of screen

            {

                this.Left = Srn.WorkingArea.X;

                this.Top = Srn.WorkingArea.Height - this.Height;



            }

        }



        private void Form_Calendar_Load(object sender, EventArgs e)

        {

            double w = Properties.Settings.Default.Transparency;

            this.Opacity = w/10;

            GoToCurrentDate();

        }



        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)

        {

        }



        private void button_Perv_Click(object sender, EventArgs e)

        {

            CurrentMonth--;

            if (CurrentMonth <= 0)

            {

                CurrentMonth = 12;

                CurrentYear--;

            }

            CreatMonthCalendar(CurrentMonth, CurrentYear);

            label_mon_day.Text= theCalender.GetMonthName(CurrentMonth) + " " + Convert.ToString(CurrentYear);

        }



        private void button_next_Click(object sender, EventArgs e)

        {

            CurrentMonth++;

            if (CurrentMonth >12)

            {

                CurrentMonth = 1;

                CurrentYear++;

            }

            CreatMonthCalendar(CurrentMonth, CurrentYear);

            label_mon_day.Text = theCalender.GetMonthName(CurrentMonth) + " " + Convert.ToString(CurrentYear);

        }



        private void ToolStripMenuItemToday_Click(object sender, EventArgs e)

        {

            GoToCurrentDate();



        }



        private void ToolStripMenuItem_nextYear_Click(object sender, EventArgs e)

        {

            GoToNextYear(); 

        }



        private void ToolStripMenuItem_PervYear_Click(object sender, EventArgs e)

        {

            GoToPervYear();

        }



        private void Form_Calendar_MouseLeave(object sender, EventArgs e)

        {

            //timer1.Start();

        }



        private void Form_Calendar_MouseEnter(object sender, EventArgs e)

        {

            //timer1.Stop();

        }



        private void timer1_Tick(object sender, EventArgs e)

        {

          //  timer1.Stop();

          //  Close();

        }



        private void button_close_Click(object sender, EventArgs e)

        {

            Close();

        }



        private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)

        {

            Close();

        }



        private void linkLabel_nextYear_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)

        {

            GoToNextYear(); 

        }



        private void linkLabel_PervYear_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)

        {

            GoToPervYear(); 

        }



        private void linkLabel_today_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)

        {

            GoToCurrentDate();



        }



        private void Form_Calendar_StyleChanged(object sender, EventArgs e)

        {

           

        }



        private void dataGridView1_SelectionChanged(object sender, EventArgs e)

        {



        }



        private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)

        {



        }



        private void dataGridView1_CellContentDoubleClick(object sender, DataGridViewCellEventArgs e)

        {

            DataGridView dataGrid = (DataGridView)sender;

            string date = (string)dataGrid.Rows[e.RowIndex].Cells[e.ColumnIndex].Tag;

            if (form_task.IsDisposed)

                form_task = new Form_Task();

            form_task.Date = date;

            form_task.Show();

           // form_task.Activate();

            //MessageBox.Show("test");



        }



        private void ToolStripMenuItem_Goto_Click(object sender, EventArgs e)

        {

           string [] ar= txtDate.Text.Split('/');

           try

           {

               CurrentMonth = int.Parse(ar[1]);

               CurrentYear = int.Parse(ar[0]);





               CreatMonthCalendar(CurrentMonth, CurrentYear);

               label_mon_day.Text = theCalender.GetMonthName(CurrentMonth) + " " + Convert.ToString(CurrentYear);

           }

           catch

           {



           }

        }

    }

}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

mohammad hajibegloo
Engineer neyshabur azad univeristy
Iran (Islamic Republic Of) Iran (Islamic Republic Of)
I had worked as programmer,project manager,web developer for more than 3 years, and have worked on programming personaly for more than 10 years.
I have worked in university as a teacher for 8 years.
my favorite langueges are : VC++,C#,ASP.NET,PHP

| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.150327.1 | Last Updated 12 Mar 2012
Article Copyright 2008 by mohammad hajibegloo
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid