Exemplo n.º 1
0
        private void SignInbtn_Click(object sender, EventArgs e)
        {
            FileStream   stream = new FileStream("admin.txt", FileMode.OpenOrCreate);
            StreamReader SR     = new StreamReader(stream);
            bool         flag   = true;

            while (SR.Peek() != -1)
            {
                String   x  = SR.ReadLine();
                String[] x1 = x.Split('*');
                if (s.transform(x1[0]) == UserNametb.Text && s.transform(x1[1]) == Passwordtb.Text)
                {
                    tabControl.Visible = true;
                    UserNametb.Clear();
                    UserNametb.Visible = false;
                    label7.Visible     = false;
                    label6.Visible     = false;
                    SignInbtn.Visible  = false;
                    Passwordtb.Clear();
                    Passwordtb.Visible = false;
                    flag = false;
                    break;
                }
            }
            SR.Close();
            stream.Close();
            if (flag)
            {
                MessageBox.Show("you enter a wrong admin name or admin password");
                Passwordtb.Clear();
                UserNametb.Clear();
            }
        }
Exemplo n.º 2
0
        private void EnterBtn_Click(object sender, EventArgs e)
        {
            if (EnterBtn.Text == "Вход")
            {
                string login = "";
                sql.Open();
                SQLiteCommand check_if_registered = new SQLiteCommand("SELECT Login FROM Registration WHERE Password = '******' AND Login = '******'", sql);
                check_if_registered.ExecuteNonQuery();
                SQLiteDataReader reader = check_if_registered.ExecuteReader();
                while (reader.Read())
                {
                    login = reader[0] + "";
                }
                string role = "";
                check_if_registered = new SQLiteCommand("SELECT role FROM Registration WHERE Password = '******' AND Login = '******'", sql);
                check_if_registered.ExecuteNonQuery();
                reader = check_if_registered.ExecuteReader();
                while (reader.Read())
                {
                    role = reader[0] + "";
                }
                if (login == "")
                {
                    MessageBox.Show("Логин или пароль указан не верно");
                }
                else
                {
                    if (MessageBox.Show("Здравствуйте " + login + " ") == DialogResult.OK)
                    {
                        UserRigts.Get_Rights(role, login);
                        Logintb.Clear();
                        Passwordtb.Clear();
                    }
                }
                currnet_role = role;
                sql.Close();
                Form1 f1 = this.Owner as Form1;
                if (role == "superuser")
                {
                    f1.roomsWorkToolStripMenuItem.Enabled        = true;
                    f1.adminToolStripMenuItem.Enabled            = true;
                    f1.clientsWorkToolStripMenuItem.Enabled      = true;
                    f1.clientsToolStripMenuItem.Enabled          = true;
                    f1.populatesClientsToolStripMenuItem.Enabled = true;
                    f1.roomsToolStripMenuItem.Enabled            = true;
                    f1.documentationToolStripMenuItem.Enabled    = true;
                    f1.ChangePassToolStripMenuItem.Enabled       = true;
                }
                else
                {
                    if (role == "manager")
                    {
                        f1.clientsWorkToolStripMenuItem.Enabled = true;
                        f1.roomsWorkToolStripMenuItem.Enabled   = true;
                        f1.ChangePassToolStripMenuItem.Enabled  = true;
                    }
                    else
                    {
                        if (role == "Bookkeeper")
                        {
                            f1.documentationToolStripMenuItem.Enabled = true;
                            f1.ChangePassToolStripMenuItem.Enabled    = true;
                        }
                    }
                }
                this.Close();
            }
            else
            {
                if (EnterBtn.Text == "Выход")
                {
                    UserRigts._role  = "";
                    UserRigts._login = "";
                    EnterBtn.Text    = "Вход";
                    Form1 f1 = this.Owner as Form1;
                    f1.roomsWorkToolStripMenuItem.Enabled        = false;
                    f1.adminToolStripMenuItem.Enabled            = false;
                    f1.clientsWorkToolStripMenuItem.Enabled      = false;
                    f1.clientsToolStripMenuItem.Enabled          = false;
                    f1.populatesClientsToolStripMenuItem.Enabled = false;
                    f1.roomsToolStripMenuItem.Enabled            = false;
                    f1.documentationToolStripMenuItem.Enabled    = false;
                    f1.ChangePassToolStripMenuItem.Enabled       = false;
                    Logintb.Clear();
                    Passwordtb.Clear();
                    Close();

                    List <Form> forms = f1.MdiChildren.ToList();
                    foreach (Form f in forms)
                    {
                        f.Close();
                    }
                }
            }
        }