private void registrationButton_Click(object sender, EventArgs e)
        {
            int         doReg      = 0;
            Trainee     hasTrainee = new Trainee();
            DatabaseIDU database   = new DatabaseIDU();

            try
            {
                if (passwordTextBox.Text == rePasswordTextBox.Text)
                {
                    Trainee trainee = new Trainee();
                    trainee.TraineeId   = idTextBox.Text;
                    trainee.TraineeName = nameTaxtBox.Text;
                    trainee.BatchNo     = batchTaxtBox.Text;
                    trainee.UserName    = userNameTextBox.Text;
                    trainee.Password    = passwordTextBox.Text;
                    hasTrainee          = database.CheckTrainee(trainee);
                    if (hasTrainee.UserName == trainee.UserName)
                    {
                        MessageBox.Show("Username already exists.Please try another one.");
                    }
                    else if (hasTrainee.TraineeId == trainee.TraineeId)
                    {
                        MessageBox.Show("Trainee id must be unique.");
                    }
                    else
                    {
                        doReg = database.Registration(trainee);
                        if (doReg > 0)
                        {
                            MessageBox.Show("Registration successful.");
                        }
                    }
                }
                else
                {
                    MessageBox.Show("Password did not match.");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error occured.");
            }
        }
Exemple #2
0
        public int Registration(Trainee trainee)
        {
            int doneRegistration = 0;

            try
            {
                connectionObj.Open();
                string query = String.Format("INSERT INTO Trainee(TraineeId,TraineeName,TraineeBatchNo,TraineeUserName,TraineePassword) VALUES('" + trainee.TraineeId + "','" + trainee.TraineeName + "','" + trainee.BatchNo + "','" + trainee.UserName + "','" + trainee.Password + "')");
                commandObj       = new SqlCommand(query, connectionObj);
                doneRegistration = commandObj.ExecuteNonQuery();
            }
            catch (Exception e)
            {
                throw new Exception("Error in registration", e);
            }
            finally
            {
                connectionObj.Close();
            }
            return(doneRegistration);
        }
Exemple #3
0
        private void loginButton_Click(object sender, EventArgs e)
        {
            int         doLogin  = 0;
            Login       login    = new Login();
            Trainee     aTrainee = new Trainee();
            DatabaseIDU database = new DatabaseIDU();

            if (userNameTextBox.Text == "" || passwordTextBox.Text == "")
            {
                MessageBox.Show("Please Enter Username And Password");
            }
            else
            {
                try
                {
                    login.UserName = userNameTextBox.Text;
                    login.Password = passwordTextBox.Text;
                    login.Role     = roleComboBox.SelectedItem.ToString();
                    login.Now      = Convert.ToDateTime(dateTimeTextBox.Text);
                    if (login.Role == "Others")
                    {
                        aTrainee = database.Login(login);
                        if (aTrainee.TraineeId != null)
                        {
                            Login.loginOther  = 1;
                            Login.BaNo        = aTrainee.BatchNo;
                            Login.ShooterName = aTrainee.TraineeName;
                            Login.TraineeId   = aTrainee.TraineeId;
                            MessageBox.Show("You are successfully logged in.");
                            mainForm.SetMenuItem(1);
                            this.Dispose();
                        }
                        else
                        {
                            MessageBox.Show("Incorrect username or password.Please try again");
                        }
                    }
                    else if (login.Role == "Admin")
                    {
                        int doneLogin = database.AdminLogin(login);
                        if (doneLogin == 1)
                        {
                            Login.loginAdmin = 1;
                            MessageBox.Show("You are successfully logged in.");
                            //MainForm main = new MainForm();
                            //Application.Run(main);
                            mainForm.SetMenuItem(1);
                            this.Dispose();
                        }
                        else
                        {
                            MessageBox.Show("Incorrect username or password.Please try again.");
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Error Occured...");
                    //throw new Exception("Error", ex);
                }
            }
        }