Beispiel #1
0
        private void btnlogin_Click(object sender, EventArgs e)
        {
            try
            {
                if (txtuser.Text == String.Empty || txtpass.Text == String.Empty)
                {
                    SpeechSynthesizer s = new SpeechSynthesizer();
                    s.Speak(label18.Text);
                    MessageBox.Show("Please Enter Data!", "Message");
                }
                else
                {
                    var loginResult = DataAccessLayer.GetRecords("SELECT * FROM UserAccount where Username = '******'and [Pass]='" + txtpass.Text + "'");

                    if (loginResult.Rows.Count == 0)
                    {
                        SpeechSynthesizer s = new SpeechSynthesizer();
                        s.Speak(label17.Text);
                        MessageBox.Show("Invalid Credentials!", "Message", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                        return;
                    }
                    else
                    {
                        SpeechSynthesizer s = new SpeechSynthesizer();


                        GlobalVariable.LoggedInUser = loginResult;


                        StringBuilder qry = new StringBuilder();
                        qry.AppendLine("INSERT INTO UserLogs ");
                        qry.AppendLine("(");
                        qry.AppendLine("UserId,");
                        qry.AppendLine("Activity,");
                        qry.AppendLine("LogDate");
                        qry.AppendLine(") VALUES (");
                        qry.AppendLine("'" + loginResult.Rows[0].Field <int>("ID").ToString() + "',");
                        qry.AppendLine("'" + Class1.Activity.LOGIN.ToString() + "',");
                        qry.AppendLine("'" + DateTime.Now.ToString("MMM-dd-yyyy hh:mm:ss tt") + "'");
                        qry.AppendLine(")");
                        DataAccessLayer.ExecuteNonQuery(qry.ToString());

                        SpeechSynthesizer sa = new SpeechSynthesizer();
                        sa.Speak(label16.Text);
                        MessageBox.Show("Log-in Successful!", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information);

                        /* this.Hide();
                         * load loading = new load();
                         * loading.Show();*/
                        p.Visible             = false;
                        label11.Visible       = false;
                        pictureBox2.Visible   = false;
                        pictureBox3.Visible   = false;
                        panel1.Visible        = false;
                        panel2.Visible        = false;
                        txtpass.Visible       = false;
                        txtuser.Visible       = false;
                        btnlogin.Visible      = false;
                        btncancel.Visible     = false;
                        panel3.Visible        = false;
                        btn_del.Visible       = true;
                        label13.Visible       = true;
                        label10.Visible       = false;
                        btn_admin.Visible     = false;
                        btn_editgrade.Visible = false;
                        label14.Visible       = false;
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed due to " + ex.Message, "Message");
            }
        }