コード例 #1
0
        private void backButton_Click(object sender, EventArgs e)
        {
            SelectAdminOperation form = new SelectAdminOperation();

            form.Show();
            this.Hide();
        }
コード例 #2
0
        private void BackBtn_Click(object sender, EventArgs e)
        {
            SelectAdminOperation op = new SelectAdminOperation();

            op.Show();
            this.Hide();
        }
コード例 #3
0
        private void authenticate()
        {
            try
            {
                string        LoadConnString     = ConfigurationManager.ConnectionStrings["DigiDoorConnString"].ConnectionString;
                SqlConnection LoadConn           = new SqlConnection(LoadConnString);
                SqlCommand    checkCurrentStatus = new SqlCommand("SELECT TOP 1 * FROM system_status_table ORDER BY Serial_Number DESC", LoadConn);
                LoadConn.Open();                                                //open connection to database
                SqlDataReader Checkreader = checkCurrentStatus.ExecuteReader(); //used with read
                Checkreader.Read();
                currentState = Checkreader[1].ToString();
                if (currentState == "Inactive")
                {
                    disableControls();
                    MessageBox.Show("System has been disabled and cannot be used! Please contact administrator!", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                LoadConn.Close();


                TimeSpan ActivityTime;
                TimeSpan timeNow;
                string   currentDate = DateTime.Now.ToString("MM-dd-yy");
                Regex    rx          = new Regex("^[*][0-9]{4}[#]$"); //*1234#
                //if (enteredPINTextBox.Text == string.Empty)
                //{
                //    MessageBox.Show("Enter a valid PIN to open door!");
                //}

                if (!rx.IsMatch(ScreenLabel.Text))
                {
                    MessageBox.Show("Enter PIN in the format : *wxyz#\n Where wxyz are numeric digits!", "Incorrect Pattern", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                    return;
                }

                if (cam.IsRunning)
                {
                    cam.Stop();
                    captureImagePB.Image.Save(saveFileDialog1.FileName);
                    imgloc = saveFileDialog1.FileName.ToString();
                    captureImagePB.ImageLocation = imgloc;
                }

                else
                {
                    cam.Start();
                }
                enteredPIN = ScreenLabel.Text;


                string        ConnString = ConfigurationManager.ConnectionStrings["DigiDoorConnString"].ConnectionString;
                SqlConnection conn       = new SqlConnection(ConnString);

                SqlDataReader reader;
                string        allowedBegTime, allowedEndTime, NameOfUser, username;
                TimeSpan      begTimeVal, EndTimeVal;


                conn.Open();

                SqlDataAdapter sda = new SqlDataAdapter("SELECT Count(*) FROM [dbo].[user_table] where passcode='" + enteredPIN + "'", conn);
                DataTable      dt  = new DataTable();
                sda.Fill(dt);
                if (dt.Rows[0][0].ToString() == "1")
                {
                    // MessageBox.Show("Authentication Successful!");
                    myPort.WriteLine("A");

                    SqlCommand retrieveAllowedTime = new SqlCommand("select * from [dbo].[user_table] where passcode='" + enteredPIN + "'", conn);
                    // conn.Open();    //open connection to database
                    reader = retrieveAllowedTime.ExecuteReader();  //used with read
                    reader.Read();

                    NameOfUser     = reader[1].ToString();
                    username       = reader[2].ToString();
                    allowedBegTime = reader[5].ToString();
                    allowedEndTime = reader[6].ToString();

                    begTimeVal = TimeSpan.Parse(allowedBegTime);
                    EndTimeVal = TimeSpan.Parse(allowedEndTime);

                    conn.Close();


                    timeNow      = DateTime.Now.TimeOfDay;
                    ActivityTime = new TimeSpan(timeNow.Hours, timeNow.Minutes, timeNow.Seconds);


                    if (captureImagePB.Image != null)
                    {
                        FileStream   fs = new FileStream(imgloc, FileMode.Open, FileAccess.Read);
                        BinaryReader br = new BinaryReader(fs);
                        img = br.ReadBytes((int)fs.Length);
                    }
                    if (activeStatus)
                    {
                        SelectAdminOperation adminop = new SelectAdminOperation();
                        adminop.setActiveStatus = activeStatus.ToString();
                        adminop.setSystemStatus = "Active";


                        if (ActivityTime >= begTimeVal && ActivityTime <= EndTimeVal)
                        {
                            conn.Open();
                            MessageBox.Show("Door Open! You can now enter!", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            speech(NameOfUser);

                            SqlCommand cmd = new SqlCommand("log_tableAddEntry", conn);
                            cmd.CommandType = CommandType.StoredProcedure;

                            cmd.Parameters.Add(new SqlParameter("user_name", username));
                            cmd.Parameters.Add(new SqlParameter("check_In_Time", ActivityTime));
                            cmd.Parameters.Add(new SqlParameter("captured_Image", img));
                            cmd.Parameters.Add(new SqlParameter("currentDate", currentDate));

                            cmd.ExecuteNonQuery();
                            conn.Close();

                            //MessageBox.Show("Welcome " + username, "success", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            captureImagePB.Image = null;
                        }

                        else
                        {
                            MessageBox.Show("Sorry! You can only Log in between " + allowedBegTime + "-" + allowedEndTime, "Alert", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                        }
                    }
                    else
                    {
                        MessageBox.Show("System Halted! Please contact administrator!", "Halted", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                        starButton.Enabled = false;
                        hashButton.Enabled = false;
                        // sendMail();
                        //SelectAdminOperation adminop = new SelectAdminOperation();
                        //adminop.setActiveStatus = activeStatus.ToString();
                        //adminop.setSystemStatus = "Inactive";
                    }
                }
                else
                {
                    timeNow = DateTime.Now.TimeOfDay;
                    TimeSpan activityTime = new TimeSpan(timeNow.Hours, timeNow.Minutes, timeNow.Seconds);
                    invalidAttempts++;
                    if (invalidAttempts < 3)
                    {
                        MessageBox.Show("No match found\n Invalid attempts = " + invalidAttempts, "Alert!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        Console.Beep();
                    }

                    if (invalidAttempts >= 3)
                    {
                        activeStatus    = false;
                        systemStatus    = "Inactive";
                        threeTimesfalse = true;
                        Console.Beep(2000, 1500);
                        SqlCommand cmd = new SqlCommand("UpdateSystemStatus", conn);
                        cmd.CommandType = CommandType.StoredProcedure;
                        cmd.Parameters.Add(new SqlParameter("system_status", systemStatus));
                        cmd.Parameters.Add(new SqlParameter("act_time", activityTime));
                        cmd.Parameters.Add(new SqlParameter("act_date", currentDate));
                        cmd.ExecuteNonQuery();
                        conn.Close();
                        MessageBox.Show(invalidAttempts + " Invalid attempts" + "\n\nSystem Halted! Please contact administrator!", "Halted", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                        CheckOutButton.Enabled = false;
                        SelectAdminOperation adminop = new SelectAdminOperation();
                        adminop.setActiveStatus = activeStatus.ToString();
                        adminop.setSystemStatus = "Inactive";
                    }
                }

                ScreenLabel.Text = "";
            }
            catch (Exception ex)
            {
                string lineNumber = ex.StackTrace.Substring(ex.StackTrace.Length - 7, 7);
                MessageBox.Show(ex.Message + "\n" + lineNumber);
            }
        }
コード例 #4
0
        private void LoginBtn_Click(object sender, EventArgs e)
        {
            try
            {
                string enteredUName, enteredPIN;

                enteredUName = EnteredUnameTextBox.Text;
                enteredPIN   = EnteredPINTextBox.Text;

                if (EnteredUnameTextBox.Text == string.Empty)
                {
                    errorProvider1.SetError(EnteredUnameTextBox, "Enter username!");
                }
                if (EnteredPINTextBox.Text == string.Empty)
                {
                    errorProvider1.SetError(EnteredPINTextBox, "Enter a valid PIN");
                }

                string        ConnString = ConfigurationManager.ConnectionStrings["DigiDoorConnString"].ConnectionString;
                SqlConnection conn       = new SqlConnection(ConnString);

                SqlDataAdapter sda = new SqlDataAdapter("SELECT Count(*) FROM [dbo].[user_table] where user_name ='" + enteredUName + "' AND passcode='" + enteredPIN + "' AND category ='" + "Admin" + "' ", conn);
                DataTable      dt  = new DataTable();
                sda.Fill(dt);
                if (dt.Rows[0][0].ToString() == "1")
                {
                    TimeSpan timeNow     = DateTime.Now.TimeOfDay;
                    TimeSpan LoginTime   = new TimeSpan(timeNow.Hours, timeNow.Minutes, timeNow.Seconds);
                    string   currentDate = DateTime.Now.ToString("MM-dd-yy");

                    if (conn.State != ConnectionState.Open)
                    {
                        conn.Open();
                    }


                    SqlCommand cmd = new SqlCommand("AdminLoginTable_AddEntry", conn);
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.Add(new SqlParameter("user_name", enteredUName));
                    cmd.Parameters.Add(new SqlParameter("login_time", LoginTime));
                    cmd.Parameters.Add(new SqlParameter("@login_date", currentDate));


                    cmd.ExecuteNonQuery();
                    conn.Close();

                    //MessageBox.Show("Login successful!");
                    SelectAdminOperation from = new SelectAdminOperation();
                    from.ShowEnableButton = InvalidAttempt;
                    from.Show();
                    this.Hide();
                }
                else
                {
                    MessageBox.Show("Login Failed.Please try again", "Alert!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }

                autoComplete.Add(EnteredUnameTextBox.Text);
            }
            catch (Exception ex)
            {
                string lineNumber = ex.StackTrace.Substring(ex.StackTrace.Length - 7, 7);
                MessageBox.Show(ex.Message + "\n" + lineNumber, "Exception!", MessageBoxButtons.OK, MessageBoxIcon.Stop);
            }
        }