using System;
using System.Collections;
using System.Linq;
using System.Text;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
using System.Runtime.Serialization;


namespace golestan
{
    [Serializable]
    class Program
    {
        
        static void Main(string[] args)
        {
            const int darse1 = 16 + 2 * 40;
            const int term1 = 4 + (2 * 20);
            const int ostad1 = 4 + 4 + (4 * 40);
            const int danesh = 4 + 4 + (40 * 5)+8;
            ArrayList t = new ArrayList();
            Console.WriteLine("1:if you are a student");
            Console.WriteLine("2:if you are a manager");
            Console.WriteLine("3:if you are a karshenas");
            int n=int.Parse(Console.ReadLine());
            if (n == 1)
            {
                FileStream fs = new FileStream("f:\\golestan\\daneshjo.bin", FileMode.OpenOrCreate, FileAccess.Read);
                BinaryReader bw = new BinaryReader(fs);
                int f = 0;
                string q = "y";
                while (f == 0 && q == "y")
                {
                    Console.Write("please enter username:");
                    int x = int.Parse(Console.ReadLine());
                    Console.Write("please enter pasword:");
                    int x1 = int.Parse(Console.ReadLine());
                    int i = 0;
                    while (bw.PeekChar() != -1 && f == 0)
                    {
                        fs.Position = danesh * i;
                        t[0] = bw.ReadInt32();
                        t[1] = bw.ReadString();
                        t[2] = bw.ReadString();
                        t[3] = bw.ReadString();
                        t[4] = bw.ReadString();
                        t[5] = bw.ReadString();
                        t[6] = bw.ReadInt32();
                        t[7] = bw.ReadInt32();
                        t[8] = bw.ReadInt32();
                        if ((int)t[7] == x && (int)t[8] == x1)
                        {
                            f = 1;
                        }
                    }
                    if (f == 0)
                    {
                        Console.WriteLine("pasword or username is mistake.do you want continu?");
                        q = Console.ReadLine();

                    }
                }
                if (q != "y")
                    return;
                if (t[5].ToString().Substring(0, 10) == "karshenasi")
                {
                    karshenasi r = new karshenasi((int)t[0], t[1].ToString(), t[2].ToString(), t[3].ToString(), t[4].ToString(), t[5].ToString(), (int)t[6], (int)t[7], (int)t[8]);
                    Console.WriteLine("1:didane karnametermi\n2:didane karnamekoli\n3:didane dorose araye shode\n4:didane dorose oftade\n5:didane teadad mashroti\n6:antekhab vahed");
                    int p = int.Parse(Console.ReadLine());
                    switch (p)
                    {
                        case 1:
                            {
                                Console.Write("please enter number term:");
                                int x = int.Parse(Console.ReadLine());
                                r.karnametermi(x);
                                break;
                            }
                        case 2:
                            {
                                r.karnamekoli();
                                break;
                            }
                        case 3:
                            {
                                Console.Write("please enter number term:");
                                int x = int.Parse(Console.ReadLine());
                                r.printlist(x);
                                break;
                            }
                        case 4:
                            {
                                r.doroseoftade();
                                break;
                            }
                        case 5:
                            {
                                r.tmashrot();
                                break;
                            }
                        case 6:
                            {
                                Console.Write("please enter number term:");
                                int x = int.Parse(Console.ReadLine());
                                r.avahed(x);
                                break;
                            }
                        default:
                            {
                                Console.WriteLine("error");
                                break;
                            }

                    }

                }
                else
                {
                    karshenasiarshad r = new karshenasiarshad((int)t[0], t[1].ToString(), t[2].ToString(), t[3].ToString(), t[4].ToString(), t[5].ToString(), (int)t[6], (int)t[7], (int)t[8]);
                    Console.WriteLine("1:didane karnametermi\n2:didane karnamekoli\n3:didane dorose araye shode\n4:didane dorose oftade\n5:didane teadad mashroti\n6:antekhab vahed");
                    int p = int.Parse(Console.ReadLine());
                    switch (p)
                    {
                        case 1:
                            {
                                Console.Write("please enter number term:");
                                int x = int.Parse(Console.ReadLine());
                                r.karnametermi(x);
                                break;
                            }
                        case 2:
                            {
                                r.karnamekoli();
                                break;
                            }
                        case 3:
                            {
                                Console.Write("please enter number term:");
                                int x = int.Parse(Console.ReadLine());
                                r.printlist(x);
                                break;
                            }
                        case 4:
                            {
                                r.doroseoftade();
                                break;
                            }
                        case 5:
                            {
                                r.tmashrot();
                                break;
                            }
                        case 6:
                            {
                                Console.Write("please enter number term:");
                                int x = int.Parse(Console.ReadLine());
                                r.avahed(x);
                                break;
                            }
                        default:
                            {
                                Console.WriteLine("error");
                                break;
                            }

                    }
                }
            }
            else if (n == 3)
            {
                FileStream fs = new FileStream("f:\\golestan\\karshenas.bin", FileMode.OpenOrCreate, FileAccess.Read);
                BinaryFormatter bw = new BinaryFormatter();
                karshenas r;
                int f = 0, x = 0, x1 = 0;
                string q = "y";
                while (f == 0 && q == "y")
                {
                    Console.Write("please enter username:");
                    x = int.Parse(Console.ReadLine());
                    Console.Write("please enter pasword:");
                    x1 = int.Parse(Console.ReadLine());
                    while (fs.Position < fs.Length)
                    {
                        r = (karshenas)bw.Deserialize(fs);
                        if (r.USER == x && r.PAS == x1)
                            f = 1;
                    }
                    if (f == 0)
                    {
                        Console.WriteLine("pasword or username is mistake.do you want continu?");
                        q = Console.ReadLine();

                    }
                }
                if (q != "y")
                    return;
                fs.Close();
                r = new karshenas(x, x1);
                string g="y";
                while(g=="y")
                {
                Console.WriteLine("1:tarif dars\n2:araye doros\n3:vorod nomarat\n4:moshahedeye dorose araye shode dar term\n5:taghir zarfiyat doros\n6:moshahede karnane daneshjoyan\n7:daneshjoyani ba mashroti bala\n8:daneshjoyani ke 2 bar darse ra oftade");
                int z = int.Parse(Console.ReadLine());
                switch (z)
                {
                    case 1:
                        {
                            Console.WriteLine("do you first going:");
                            string l=Console.ReadLine();
                            if(l=="y")
                            {
                            Console.Write("please enter number all course:");
                            int z1 = int.Parse(Console.ReadLine());
                            r.khalidars(z1);
                            }
                            Console.Write("please enter number of course going:");
                            int z2 = int.Parse(Console.ReadLine());
                            r.tdars(z2);
                            break;
                        }
                    case 2:
                        {
                            Console.Write("please enter number of course going:");
                            int z2 = int.Parse(Console.ReadLine());
                            r.arayeadoros(z2);
                            break;
                        }
                    case 3:
                        {
                            r.vnomre();
                            break;
                        }
                    case 4:
                        {
                            Console.Write("please enter number of term:");
                            int z3 = int.Parse(Console.ReadLine());
                            r.printlist(z3);
                            break;
                        }
                    case 5:
                        {
                            Console.Write("please enter number of course going:");
                            int z4 = int.Parse(Console.ReadLine());
                            r.taghirzafiat(z4);
                            break;
                        }
                    case 6:
                        {
                            Console.Write("please enter number of student:");
                            int z5 = int.Parse(Console.ReadLine());
                            r.moshahedekarname(z5);
                            break;
                        }
                    case 7:
                        {
                            r.mashrotbala();
                            break;
                        }
                    case 8:
                        {
                            break;
                        }
                }
                    Console.Write("do you want continue:");
                    g = Console.ReadLine();
                }
            }

            else
            {
                modir r = new modir();
                int f = 0, x = 0, x1 = 0;
                string q = "y";
                while (f == 0 && q == "y")
                {
                    Console.Write("please enter username:");
                    x = int.Parse(Console.ReadLine());
                    Console.Write("please enter pasword:");
                    x1 = int.Parse(Console.ReadLine());
                    if (x == r.USER && x1 == r.PAS)
                    {
                        f = 1;
                    }
                    else
                    {
                        Console.WriteLine("pasword or username is mistake.do you want continu?");
                        q = Console.ReadLine();
                    }

                }

                if (q != "y")
                    return;
                string g="y";
                while (g == "y")
                {
                    Console.WriteLine("1:tarif daneshjo\n2:tarif ostad\n3:tarif term\n4:moshahedeye dorose araye shode va daneshjoyane sabt shode\n5:moshahedeye sabegeye daneshjoyan\n6:moshahedeye sabegheye ostad\n7:list daneshjoyan har dars\n8:list daneshjoyan yek dars sort nomre\n9:list danesh joyan be tartib moadel term khas\n10:list daneshjoyan be tartib moadel kol\n11:list dorose ostad\n12:tarif karsenas\n13:daneshjo ba bish az k bar oftadgi");
                    int y = int.Parse(Console.ReadLine());
                    switch (y)
                    {
                        case 1:
                            {
                                Console.WriteLine("do you first going:");
                                string l = Console.ReadLine();
                                if (l == "y")
                                {
                                    Console.WriteLine("please enter number all of student");
                                    int y1 = int.Parse(Console.ReadLine());
                                    r.khalidanesh(y1);
                                }
                                Console.WriteLine("please enter number of student going");
                                int y2 = int.Parse(Console.ReadLine());
                                r.tdanesh(y2);
                                break;
                            }
                        case 2:
                            {
                                Console.WriteLine("do you first going:");
                                string l = Console.ReadLine();
                                if (l == "y")
                                {
                                    Console.WriteLine("please enter number all of ostad");
                                    int y1 = int.Parse(Console.ReadLine());
                                    r.khaliostad(y1);
                                }
                                Console.WriteLine("please enter number of student going");
                                int y2 = int.Parse(Console.ReadLine());
                                r.tostad(y2);
                                break;
                            }
                        case 3:
                            {
                                Console.WriteLine("do you first going:");
                                string l = Console.ReadLine();
                                if (l == "y")
                                {
                                    Console.WriteLine("please enter number all of term");
                                    int y1 = int.Parse(Console.ReadLine());
                                    r.khaliterm(y1);
                                }
                                Console.WriteLine("please enter number of term going");
                                int y2 = int.Parse(Console.ReadLine());
                                r.tterm(y2);
                                break;
                            }
                        case 4:
                            {
                                Console.WriteLine("please enter number term ");
                                int y2 = int.Parse(Console.ReadLine());
                                r.printlist(y2);
                                break;
                            }
                        case 5:
                            {
                                Console.WriteLine("please enter number of student ");
                                int y2 = int.Parse(Console.ReadLine());
                                r.moshahedekarname(y2);
                                break;
                            }
                        case 6:
                            {
                                Console.WriteLine("please enter number of ostad ");
                                int y2 = int.Parse(Console.ReadLine());
                                r.sabegheyeostad(y2);
                                break;
                            }
                        case 7:
                            {
                                Console.WriteLine("please enter number of darse ");
                                int y2 = int.Parse(Console.ReadLine());
                                r.list(y2);
                                break;
                            }
                        case 8:
                            {
                                Console.WriteLine("please enter number of darse ");
                                int y2 = int.Parse(Console.ReadLine());
                                r.listsortnomre(y2);
                                break;
                            }
                        case 9:
                            {
                                Console.WriteLine("please enter number of term ");
                                int y2 = int.Parse(Console.ReadLine());
                                r.sortmoadelterm(y2);
                                break;
                            }
                        case 10:
                            {
                                r.studentsortmoadelkol();
                                break;
                            }
                        case 11:
                            {
                                Console.WriteLine("please enter number of ostad ");
                                int y2 = int.Parse(Console.ReadLine());
                                r.listdoroseostad(y2);
                                break;
                            }
                        case 12:
                            {
                                Console.WriteLine("please enter number of karshenas going");
                                int y2 = int.Parse(Console.ReadLine());
                                r.tkarshenas(y2);
                                break;
                            }
                        case 13:
                            {
                                Console.WriteLine("please enter number of dars");
                                int y2 = int.Parse(Console.ReadLine());
                                Console.WriteLine("please enter number of oftadgi");
                                int y3 = int.Parse(Console.ReadLine());
                                r.idkoftaade(y2, y3);
                                break;
                            }



                    }
                    Console.WriteLine("do you continue:");
                    g = Console.ReadLine();

                }

            }
     
        }
    }
}
