コード例 #1
0
 public static AdminClass create_Instance()
 {
     if (instance == null) //this "if" will be true only when first time intance is created
     {
         instance = new AdminClass();
     }
     return(instance);
     //This will return the saved instance everytime whenever create_Instance() is called bcz instance is static !
 }
コード例 #2
0
        private void button1_Click(object sender, EventArgs e)
        {
            Console.Beep();

            string str      = " ";
            string username = "******";
            string password = "******";

            if (First_Page.opt1 == 0)
            {
                string doc_path = First_Page.doc_path;
                try
                {
                    StreamReader sr = new StreamReader(doc_path + txtusername.Text + ".txt");
                    for (int i = 0; i < 2; ++i)
                    {
                        str = sr.ReadLine();
                    }

                    username = sr.ReadLine();
                    password = sr.ReadLine();
                    sr.Close();
                }
                catch
                {
                    MessageBox.Show("User Not Found", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                checkCredentials(username, password);
            }

            else if (First_Page.opt1 == 1)
            {
                string patient_path = First_Page.pat_path;
                try
                {
                    StreamReader sr = new StreamReader(patient_path + txtusername.Text + ".txt");
                    for (int i = 0; i < 2; ++i)
                    {
                        str = sr.ReadLine();
                    }

                    username = sr.ReadLine();
                    password = sr.ReadLine();
                    sr.Close();
                }
                catch
                {
                    MessageBox.Show("User Not Found", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                checkCredentials(username, password);
            }

            else
            {
                AdminClass admin = AdminClass.create_Instance(); //Single instance of admin class

                if (txtusername.Text == admin._username)
                {
                    if (txtpassword.Text == admin._password)
                    {
                        this.Hide();
                        Admin ad = new Admin(true);
                        ad.ShowDialog();
                        this.Close();
                    }
                    else
                    {
                        MessageBox.Show("Password Unmatched", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
                else
                {
                    MessageBox.Show("Username Unmatched", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }