Click here to Skip to main content
15,886,032 members
Articles / Web Development / ASP.NET

Persian Calendar with Tray Icon

Rate me:
Please Sign up or sign in to vote.
3.71/5 (16 votes)
12 Mar 2012CPOL2 min read 70K   2.4K   27  
A Persian calendar that shows a tray icon
��using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Text;

using System.Windows.Forms;

using System.Resources;

using System.Reflection;

using System.IO;

using System.Globalization;

using System.Threading;

using mytray.Properties;

namespace mytray

{

    public partial class Form_Main : Form

    {

        bool bullonclosed = false;

        Form_tip f_tip = new Form_tip();

        Form_Calendar From_cal = null;

        Form_Settings Form_set = null;

        MyDataBase db = new MyDataBase();

        int NowYear=0,NowMonth=0,NowDay=0;

        int GhamariAdj = 0;

        Icon[] Icon_ar = new Icon[32];

       CPersianCalender theCalender = new CPersianCalender();

        public int GhamariAdjust 

        {

            set

        {

            if (value <= 2 && value >= -2)

                GhamariAdj = value;

            else

                GhamariAdj = 0;

            theCalender.SetGhamariAdjust(GhamariAdj);

            ShowDate();

            if (From_cal != null && From_cal.IsDisposed != true)

                From_cal.GhamariAdjust = GhamariAdj;

        }

            get

            {

                return GhamariAdj;

            }

        }



        public void ShowDate()

        {

            notifyIcon1.Icon = Icon_ar[NowDay];

            String StrComment = theCalender.GetDayFullTooltip(NowDay,NowMonth,NowYear);

            

            int[] d=theCalender.GetGhamariDate();

           

            bool Vacation_shamsi,Vacation_ghamari;

            string Comment_shamsi = db.GetShamsiDayInfo(NowDay, NowMonth, out Vacation_shamsi);

            

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

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

            {

                StrComment += "\n";

                if (Comment_shamsi != "")

                    StrComment += Comment_shamsi;

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

                    StrComment+="\n";

 

                if (Comment_Ghamari != "")

                    StrComment += Comment_Ghamari;

                if (Vacation_shamsi == true || Vacation_ghamari == true)

                {

                    if (StrComment.Length > 57)

                        StrComment = StrComment.Remove(57);



                    StrComment += "-*97JD";

                }



            }

            if (StrComment.Length > 63)

               StrComment= StrComment.Remove(63);

            notifyIcon1.Text = StrComment;







        }



        public Form_Main()

        {

            InitializeComponent();

            Icon_ar[1] = global::mytray.Properties.Resources.icon1;

            Icon_ar[2] = global::mytray.Properties.Resources.icon2;

            Icon_ar[3] = global::mytray.Properties.Resources.icon3;

            Icon_ar[4] = global::mytray.Properties.Resources.icon4;

            Icon_ar[5] = global::mytray.Properties.Resources.icon5;

            Icon_ar[6] = global::mytray.Properties.Resources.icon6;

            Icon_ar[7] = global::mytray.Properties.Resources.icon7;

            Icon_ar[8] = global::mytray.Properties.Resources.icon8;

            Icon_ar[9] = global::mytray.Properties.Resources.icon9;

            Icon_ar[10] = global::mytray.Properties.Resources.icon10;

            Icon_ar[11] = global::mytray.Properties.Resources.icon11;

            Icon_ar[12] = global::mytray.Properties.Resources.icon12;

            Icon_ar[13] = global::mytray.Properties.Resources.icon13;

            Icon_ar[14] = global::mytray.Properties.Resources.icon14;

            Icon_ar[15] = global::mytray.Properties.Resources.icon15;

            Icon_ar[16] = global::mytray.Properties.Resources.icon16;

            Icon_ar[17] = global::mytray.Properties.Resources.icon17;

            Icon_ar[18] = global::mytray.Properties.Resources.icon18;

            Icon_ar[19] = global::mytray.Properties.Resources.icon19;

            Icon_ar[20] = global::mytray.Properties.Resources.icon20;

            Icon_ar[21] = global::mytray.Properties.Resources.icon21;

            Icon_ar[22] = global::mytray.Properties.Resources.icon22;

            Icon_ar[23] = global::mytray.Properties.Resources.icon23;

            Icon_ar[24] = global::mytray.Properties.Resources.icon24;

            Icon_ar[25] = global::mytray.Properties.Resources.icon25;

            Icon_ar[26] = global::mytray.Properties.Resources.icon26;

            Icon_ar[27] = global::mytray.Properties.Resources.icon27;

            Icon_ar[28] = global::mytray.Properties.Resources.icon28;

            Icon_ar[29] = global::mytray.Properties.Resources.icon29;

            Icon_ar[30] = global::mytray.Properties.Resources.icon30;

            Icon_ar[31] = global::mytray.Properties.Resources.icon31;

            



            int[] ff = theCalender.GetPersianDate();

            int yy = ff[0];

            int mm = ff[1];

            int dd = ff[2];

            NowDay = dd;

            NowMonth = mm;

            NowYear = yy;

           // ShowDate();

            //read GhamariAdjust and show date

            GhamariAdjust=Settings.Default.GhamariAdjust;

            notifyIcon1.ContextMenuStrip = contextMenuStrip1;

            notifyIcon1.Visible = true;

            timer_Refrash.Start();

           // MyDataBase m = new MyDataBase();

            f_tip.Show();

   

        }



        protected void Exit_Click(Object sender, System.EventArgs e)

        {

            timer_Refrash.Stop();

            Close();

        }





        private void Form1_VisibleChanged(object sender, EventArgs e)

        {

            this.Visible = false;

        }



        private void toolStripMenuItem2_Click(object sender, EventArgs e)

        {



        }



        private void toolStripMenuItem3_Click(object sender, EventArgs e)

        {



        }



        private void settingsToolStripMenuItem_Click(object sender, EventArgs e)

        {

            if (Form_set == null || Form_set.IsDisposed == true)

            {

                Form_set = new Form_Settings();

                Form_set.FMain = this;

                Form_set.Show();

            }



        }



        private void exitToolStripMenuItem1_Click(object sender, EventArgs e)

        {

            ///

            Form_About about = new Form_About();

            about.ShowDialog();

        }



        private void calendarToolStripMenuItem_Click(object sender, EventArgs e)

        {

            if (From_cal==null || From_cal.IsDisposed == true)

            {

                From_cal = new Form_Calendar();

                From_cal.GhamariAdjust = GhamariAdjust;

                From_cal.Show();

            }

            

        }



        private void notifyIcon1_MouseDoubleClick(object sender, MouseEventArgs e)

        {

            if (From_cal == null || From_cal.IsDisposed == true)

            {

                From_cal = new Form_Calendar();

                From_cal.GhamariAdjust = GhamariAdjust;

                From_cal.Show();

            }

            else

            {

                From_cal.Close();

                From_cal = null;

            }

  

        }

        private string GetTime()

        {

            string strh, strm;

            DateTime d = DateTime.Now;

            if (d.Hour < 10)

                strh = "0" + d.Hour.ToString();

            else

                strh = d.Hour.ToString();

            if (d.Minute < 10)

                strm = "0" + d.Minute.ToString();

            else

                strm = d.Minute.ToString();



            return strh + ":" + strm;



        }



        private void timer1_Tick(object sender, EventArgs e)

        {

            int[] ff = theCalender.GetPersianDate();

            int yy = ff[0];

            int mm = ff[1];

            int dd = ff[2];

            if (dd != NowDay || mm != NowMonth || yy != NowYear)

            {

                NowDay = dd;

                NowMonth = mm;

                NowYear = yy;

                ShowDate();

                if (From_cal != null && From_cal.IsDisposed != true)

                    From_cal.GoToCurrentDate();

            }



            ////////new ///////////////

            f_tip.tasksTableAdapter.Fill(f_tip.tasks_DataSet.Tasks);

            string strdate = NowYear + "/" + NowMonth + "/" + NowDay;

              f_tip.tasksBindingSource.Filter = "Date='" + strdate + "'";

              f_tip.tasksBindingSource.Filter += " AND Time='" + GetTime() + "'";

              f_tip.tasksBindingSource.Filter += " AND Done='False'";







             if (f_tip.tasksBindingSource.Count > 0 )

              {



                notifyIcon1.BalloonTipTitle = "�'1 ('B� E'F/G";

                if (notifyIcon1.BalloonTipText != f_tip.subjectTextBox.Text)

                {

                    notifyIcon1.BalloonTipText = f_tip.subjectTextBox.Text;

                    bullonclosed = false;



                    notifyIcon1.ShowBalloonTip(100000);

                }

              }



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



        }



        private void toolStripMenuItem1_Click(object sender, EventArgs e)

        {

            notifyIcon1.Visible = false;

            Close();

        }



        private void notifyIcon1_BalloonTipClosed(object sender, EventArgs e)

        {

            bullonclosed = true;

        }



        private void toolStripMenuItem2_Click_1(object sender, EventArgs e)

        {

           // f_tip.tasksTableAdapter.FillByDate(f_tip.tasks_DataSet.Tasks);



            Form_TaskPrint fp = new Form_TaskPrint();

            fp.ShowDialog();

           // string str = GetDayOfWeekName() + " " + date;

        //    fp.Init_Report(f_tip.tasks_DataSet,false);

        //    fp.ShowDialog();





        }



        private void toolStripMenuItem3_Click_1(object sender, EventArgs e)

        {

            f_tip.tasksTableAdapter.FillByDate(f_tip.tasks_DataSet.Tasks);



            Form_print fp = new Form_print();

            // string str = GetDayOfWeekName() + " " + date;

        //    fp.Init_Report(f_tip.tasks_DataSet, true);

          //  fp.ShowDialog();



        }



        private void Form_Main_Load(object sender, EventArgs e)

        {



        }

    }

}

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)


Written By
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

Comments and Discussions