Click here to Skip to main content
15,886,071 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.Text;
using System.Data.SqlClient;
using System.Data;
using System.Data.OleDb;
using System.Windows.Forms;

namespace mytray
{
    /*class DataBase
    {
        OleDbConnection sqlConnection1 = null;
        public DataBase ()
        {
            connect();
        }
        ~DataBase()
        {
            if (sqlConnection1 != null && sqlConnection1.State==ConnectionState.Open)
                sqlConnection1.Close();
        }
        void connect()
        {
            string connectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="
                +Application.StartupPath+"\\hijri.mdb";
     //       string connectionString =
         //    "Dsn=MS Access Database;dbq=C:\\BookDb.mdb;fil=MS Access;";
//connectionString="Dsn=MS Access Database;dbq=C:\BookDb.mdb;defaultdir=C:\;driverid=25;fil=MS Access;maxbuffersize=2048;pagetimeout=5;uid=admin"


           
            sqlConnection1 = new OleDbConnection(connectionString);
       //    sqlConnection1.co
          
             
        }
        public string GetShamsiDayInfo(int Day, int Month,out bool Vacation)
    {
        //connect();
            OleDbCommand cmd = new OleDbCommand();
            OleDbDataReader reader;

            cmd.CommandText = "SELECT * FROM ImpDays_Shamsi where Day=" 
                               +Day.ToString()+" AND Month="+Month.ToString();
            cmd.CommandType = CommandType.Text;
            cmd.Connection = sqlConnection1;

           sqlConnection1.Open();

            reader = cmd.ExecuteReader();
            // Data is accessible through the DataReader object here.
            string Comment="";
            Vacation = false;
            while (reader.Read())
            {
            //   string s= reader["Day"].ToString();
           //    s += reader["Month"].ToString();
            //   s += reader["Vacation"].ToString();
                Comment = reader["Comment"].ToString();
               Vacation = (bool)reader["Vacation"];
            }
            sqlConnection1.Close();
            return Comment;
        }
        public string GetGhamariDayInfo(int Day, int Month, out bool Vacation)
        {
           sqlConnection1.Open();
            //connect();
            OleDbCommand cmd = new OleDbCommand();
            OleDbDataReader reader;

            cmd.CommandText = "SELECT * FROM ImpDays_Ghamari where Day="
                               + Day.ToString() + "AND Month=" + Month.ToString();
            cmd.CommandType = CommandType.Text;
            cmd.Connection = sqlConnection1;

            //sqlConnection1.Open();

            reader = cmd.ExecuteReader();
            // Data is accessible through the DataReader object here.
            string Comment = "";
            Vacation = false;
            while (reader.Read())
            {
                //   string s= reader["Day"].ToString();
                //    s += reader["Month"].ToString();
                //   s += reader["Vacation"].ToString();
                Comment = reader["Comment"].ToString();
                Vacation = (bool)reader["Vacation"];
            }
            sqlConnection1.Close();
            return Comment;
        }
    }
     */
    class MyDataBase
    {
        
        DataSet MyDataSet = new DataSet();
        public MyDataBase()
        {
            connect();
        }
        ~MyDataBase()
        {
        }
        void connect()
        {
            OleDbConnection myAccessConn = null;
            string connectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="
                + Application.StartupPath + "\\hijri.mdb";
            string strSelect_shamsi = "SELECT * FROM ImpDays_Shamsi";
            string strSelect_Ghamari = "SELECT * FROM ImpDays_Ghamari";
            
             try
            {
                myAccessConn = new OleDbConnection(connectionString);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error: Failed to create a database connection. \n{0}", ex.Message);
                return;
            }

            ///////////////
            try
            {

                OleDbCommand myAccessCommand = new OleDbCommand(strSelect_shamsi, myAccessConn);
                OleDbDataAdapter myDataAdapter = new OleDbDataAdapter(myAccessCommand);

                myAccessConn.Open();
                myDataAdapter.Fill(MyDataSet, "ImpDays_Shamsi");

            }
            catch (Exception ex)
            {
                Console.WriteLine("Error: Failed to retrieve the required data from the DataBase.\n{0}", ex.Message);
                return;
            }

            try
            {

                OleDbCommand myAccessCommand = new OleDbCommand(strSelect_Ghamari, myAccessConn);
                OleDbDataAdapter myDataAdapter = new OleDbDataAdapter(myAccessCommand);

              //  myAccessConn.Open();
                myDataAdapter.Fill(MyDataSet, "ImpDays_Ghamari");

            }
            catch (Exception ex)
            {
                Console.WriteLine("Error: Failed to retrieve the required data from the DataBase.\n{0}", ex.Message);
                return;
            }
            finally
            {
                myAccessConn.Close();
            }

        }
       void  test()
        {
		// A dataset can contain multiple tables, so let's get them all
		// into an array:
		DataTableCollection dta = MyDataSet.Tables;
		foreach (DataTable dt in dta)
		
			Console.WriteLine("Found data table {0}", dt.TableName);
	
	    
		// The next two lines show two different ways you can get the
		// count of tables in a dataset:
		Console.WriteLine("{0} tables in data set", MyDataSet.Tables.Count);
		Console.WriteLine("{0} tables in data set", dta.Count);
		// The next several lines show how to get information on a
		// specific table by name from the dataset:
        Console.WriteLine("{0} rows in Categories table", MyDataSet.Tables["ImpDays_Shamsi"].Rows.Count);
		// The column info is automatically fetched from the database, so
		// we can read it here:
        Console.WriteLine("{0} columns in Categories table", MyDataSet.Tables["ImpDays_Shamsi"].Columns.Count);
        DataColumnCollection drc = MyDataSet.Tables["ImpDays_Shamsi"].Columns;
		int i = 0;
		foreach (DataColumn dc in drc)
		{
			// Print the column subscript, then the column's name and its
			// data type:
			Console.WriteLine("Column name[{0}] is {1}, of type {2}",i++ , dc.ColumnName, dc.DataType);
		}
        DataRowCollection dra = MyDataSet.Tables["ImpDays_Shamsi"].Rows;
		foreach (DataRow dr in dra)
		{
			// Print the CategoryID as a subscript, then the CategoryName:
			Console.WriteLine("CategoryName[{0}] is {1}", dr[0], dr[1]);
		}
      
        }

       
        public string GetShamsiDayInfo(int Day, int Month, out bool Vacation)
        {
           // DataTable DT_Shamsi=MyDataSet.Tables["ImpDays_Shamsi"];
            DataRowCollection dra = MyDataSet.Tables["ImpDays_Shamsi"].Rows;
            string Comment = "";
            Vacation = false;
 
		    foreach (DataRow dr in dra)
            {
                if((Day==(int)dr["Day"]) && (Month==(int) dr["Month"]))
                {
                    Comment = dr["Comment"].ToString();
                    Vacation = (bool)dr["Vacation"];
                }
            }
            return Comment;
        }

        public string GetGhamariDayInfo(int Day, int Month, out bool Vacation)
        {
           // DataTable DT_Shamsi=MyDataSet.Tables["ImpDays_Ghamari"];
            DataRowCollection dra = MyDataSet.Tables["ImpDays_Ghamari"].Rows;
            string Comment = "";
            Vacation = false;
 
		    foreach (DataRow dr in dra)
            {
                if((Day==(int)dr["Day"]) && (Month==(int) dr["Month"]))
                {
                    Comment = dr["Comment"].ToString();
                    Vacation = (bool)dr["Vacation"];
                }
            }
            return Comment;

        }
    }
}

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