Exemple #1
0
        private void btnNextForm_Click(object sender, EventArgs e)
        {
            //this will run the step by step insertion of the listbox's selected items into their appropriate database tables

            if (SetupFirstStep())
            {
                AddingConsultantOffice child = new AddingConsultantOffice(); //we are creating an object to invoke the AddingConsultantOffice form
                child.ConsultantAffliationsInfo(ConsultantIDGlobal);         //this method will send the ConsultantID to the next form(so that it can use it for database insertion)
                child.StartPosition = FormStartPosition.Manual;              //this sets the opening form dialog's start position as the location specified below
                child.Location      = new Point(320, 0);                     //this will set the location of the object's dialog form
                HomeScreen obj = new HomeScreen();                           //this will open the home screen form
                child.ShowDialog();                                          //this will open the AddingConsultantOffice as a dialog(on top of the current form)
                obj.StartTimer();
                obj.ConsultantInfo(ConsultantIDGlobal);                      //this method will send the ConsultantID to the next form(so that it can use it for database retrieval)
                obj.ConsultantOfficeInfo(ConsultantIDGlobal);                //this method will send the ConsultantID to the next form(so that it can use it for database retrieval)
                obj.Show();
                this.Hide();
                obj.Closed += (s, args) => Close(); //this closes only the current form while retaining the other opened forms
            }
        }
        private void btnLogin_Click(object sender, EventArgs e)
        {
            lblLoginInfo.Text = null;       //this will clear the Login ID notification text
            lblKeyInfo.Text   = null;       //this will clear the Security Key notification
            string Login = txtLoginID.Text; //getting the characters entered in the LoginID textbox
            string Key   = txtKeyCode.Text; //getting the characters entered in the PassKey textbox

            if (String.IsNullOrEmpty(Key))
            {
                //setting the error notification tex for empty field
                lblKeyInfo.ForeColor = Color.FloralWhite;
                lblKeyInfo.Text      = "The Key Code field is empty. Please provide a valid Key Code to proceed.";
            }
            if (String.IsNullOrEmpty(Login))
            {
                //setting the error notification tex for empty field
                lblLoginInfo.ForeColor = Color.FloralWhite;
                lblLoginInfo.Text      = "The Login ID field is empty. Please provide a valid Login ID to proceed.";
            }
            else
            {
                try
                {
                    if (con.State == ConnectionState.Closed) //this selection will open the database connecion if it is not already opened
                    {
                        con.Open();
                    }

                    //checking the login details, if LoginID is found in the database, it checks if the PinCode matches then sends the ConsultantID of the logged in consultant to the next form
                    using (SqlCommand cmd = new SqlCommand("SELECT PinCode, ConsultantID FROM ConsultantLoginTable WHERE LoginID = @userid", con))
                    {
                        cmd.Parameters.AddWithValue("@userid", Login);
                        SqlDataReader reader     = cmd.ExecuteReader();
                        bool          loginfound = reader.HasRows; //checks whether the loginID is correct by comparing it to the already present list of login ID in the database
                        if (loginfound)                            //if the loginID is found, it compares the PinCode (password) in the database query against the entered Pincode, and continues if they match
                        {
                            while (reader.Read())
                            {
                                string PinCode = reader[0].ToString().Trim();
                                if (Key.Equals(PinCode))
                                {
                                    string     ConsultantID = reader[1].ToString().Trim();
                                    HomeScreen home         = new HomeScreen();
                                    home.StartTimer(); //this is used to set the login time
                                    ConsultantMainScreen main = new ConsultantMainScreen();

                                    if (FirstTimeLogin(ConsultantID))
                                    {
                                        home.ConsultantInfo(ConsultantID);       //this is to send the next form the ConsultantID, so that it can use it to search the database for consultant's information
                                        home.ConsultantOfficeInfo(ConsultantID); //this is to send the next form the ConsultantID, so that it can use it to search the database for consultant's hospital affliation's information
                                        home.Show();
                                        this.Hide();
                                        home.Closed += (s, args) => Close();//this event will close only the current form
                                    }
                                    else
                                    {
                                        main.ConsultantInfo(ConsultantID);
                                        main.Show();
                                        this.Hide();
                                        main.Closed += (s, args) => Close();//this event will close only the current form
                                    }
                                }
                                else //if the passcodes do not match, an error notifcation will be displayed
                                {
                                    lblKeyInfo.ForeColor = Color.Tomato;
                                    lblKeyInfo.Text      = "The Key Code you entered is incorrect. Please Try Again!";
                                }
                            }
                        }
                        else //if the loginID is not found in the database an error notification is displayed
                        {
                            lblLoginInfo.ForeColor = Color.Tomato;
                            lblLoginInfo.Text      = "The Login ID '" + Login + "' is incorrect. Please Try Again!";
                        }
                        con.Close();
                    }
                }
                catch (SqlException ex)
                {
                    MessageBox.Show(null, "An error occured when logging into the Consultant System\nError: " + ex, "Connection Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }