/// <summary>
 /// Processes login request.
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void loginButton_Click(object sender, EventArgs e)
 {
     try
     {
         String username = usernameTextBox.Text;
         String password = passwordTextBox.Text;
         if (String.IsNullOrEmpty(username) || String.IsNullOrEmpty(password))
         {
             MessageBox.Show("Must show password and username");
         }
         else
         {
             bool loggedIn = AgentDB.loginRequest(username, password);
             if (loggedIn)
             {
                 DialogResult = DialogResult.OK;
             }
             else
             {
                 MessageBox.Show("Your username or password are incorrect");
             }
         }
     }
     catch (SqlException ex)
     {
         MessageBox.Show("Database error # " + ex.Number +
                         ": " + ex.Message, ex.GetType().ToString());
     }
 }
        //adds an agent
        private void AddButton_Click(object sender, EventArgs e)
        {
            //REBUILD VALIDATION -- No agent ID assigned, automatically done
            if (Validator.IsPresent(agtFirstNameTextBox) && Validator.IsPresent(agtLastNameTextBox) &&
                Validator.IsPresent(agtBusPhoneTextBox) && Validator.IsPresent(agtEmailTextBox))
            {
                agt = new Agent();
                //cant use build agent here since an Id wont be input, it will be auto assign
                agt.AgtFirstName     = agtFirstNameTextBox.Text;
                agt.AgtLastName      = agtLastNameTextBox.Text;
                agt.AgtMiddleInitial = agtMiddleInitialTextBox.Text;
                agt.AgtBusPhone      = agtBusPhoneTextBox.Text;
                agt.AgtEmail         = agtEmailTextBox.Text;
                agt.AgtPosition      = agtPositionComboBox.Text;
                agt.AgencyID         = Convert.ToInt32(agencyIDComboBox.SelectedValue);

                try
                {
                    AgentDB.AddAgent(agt);
                    MessageBox.Show("Agent added successfully.", "Success");
                    ClearContent();
                }
                catch (Exception ex) { MessageBox.Show(ex.Message, ex.GetType().ToString()); ClearContent(); }
            }
        }
 //deletes an agent
 private void DeleteButton_Click(object sender, EventArgs e)
 {
     if (isValid())//checks there is a value selected
     {
         agt = new Agent();
         BuildAgent(agt);
         //confirmation window
         DialogResult result = MessageBox.Show("Delete " + agt.AgtLastName + ", " + agt.AgtFirstName + "?",
                                               "Confirm Delete", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
         if (result == DialogResult.Yes)
         {
             try
             {
                 if (!AgentDB.DeleteAgent(agt))//failed
                 {
                     MessageBox.Show("Another user has updated or deleted that supplier.", "Database Error");
                     ClearContent();
                 }
                 else//success
                 {
                     MessageBox.Show("Delete Successful.");
                     ClearContent();
                 }
             }
             catch (Exception ex) { MessageBox.Show(ex.Message, ex.GetType().ToString()); }
         }
     }
     else
     {
         MessageBox.Show("Data fields are empty.", "Input Error");
     }
 }
Пример #4
0
        // Method to verify agent login
        private void btnOK_Click(object sender, EventArgs e)
        {
            // Validate fields are not blank
            if ((validaterClass.isProvided(emailLogin, "The field \"Email\" must be provided")) &&
                (validaterClass.isProvided(passwordLogin, "The field \"Password\" must be provided")))
            {
                bool    result  = false;
                AgentDB agentDB = new AgentDB();
                //example too
                //usernmae = [email protected]
                string passsword = "abcd1234";
                //HashSalt hashy = new HashSalt();
                AgentDB.GenerateSaltedHash(passsword);

                result = agentDB.AgentLogin(new Agent(emailLogin.Text, passwordLogin.Text));
                if (result)
                {
                    //Open dashboard and close this form
                    this.DialogResult = DialogResult.OK;
                }
                else
                {
                    MessageBox.Show("Your email or Password is wrong");
                }
            }
        }
Пример #5
0
        private void btnSignIn_Click(object sender, EventArgs e)
        {
            string firstName = txtFirstName.Text;
            string lastName  = txtLastName.Text;

            List <Agent> agents = AgentDB.GetAllAgents();

            // Find if user first name and last name is in database
            var agent = agents.SingleOrDefault(a => a.AgtFirstName.ToLower() == firstName.ToLower() &&
                                               a.AgtLastName.ToLower() == lastName.ToLower());

            if (agent != null)   // if found a match
            {
                loggedInAgt                  = new Agent();
                loggedInAgt.AgentId          = agent.AgentId;
                loggedInAgt.AgtFirstName     = agent.AgtFirstName;
                loggedInAgt.AgtMiddleInitial = agent.AgtMiddleInitial;
                loggedInAgt.AgtLastName      = agent.AgtLastName;
                loggedInAgt.AgtEmail         = agent.AgtEmail;
                loggedInAgt.AgtBusPhone      = agent.AgtBusPhone;
                loggedInAgt.AgtPosition      = agent.AgtPosition;
                loggedInAgt.AgencyId         = agent.AgencyId;
                DialogResult                 = DialogResult.OK;
            }
            else
            {
                MessageBox.Show("Incorrect First Name or Last Name");
                DialogResult = DialogResult.None;
            }
        }
        //clears the content (useful for updating datagrid after add/delete)
        private void ClearContent()
        {
            agentIDTextBox.Clear();
            agtFirstNameTextBox.Clear();
            agtLastNameTextBox.Clear();
            agtMiddleInitialTextBox.Clear();
            agtBusPhoneTextBox.Clear();
            agtEmailTextBox.Clear();
            agtPositionComboBox.SelectedIndex = 2; //hovers over the junior agent option

            //resets the datagrid
            agents = AgentDB.GetAgents();
            agentDataGridView.DataSource = agents;
        }
        //updates information for agents
        private void UpdateButton_Click(object sender, EventArgs e)
        {
            if (isValid())//checks there is an object first
            {
                agt = new Agent();
                BuildAgent(agt);//builds the new agent,now we use TempAgent to check the changes

                if (AgentDB.UpdateAgent(tempAgent, agt))
                {
                    MessageBox.Show("Agent successfully updated.", "Success");
                    ClearContent();
                }
                else
                {
                    MessageBox.Show("There was an error updating, please try again."); ClearContent();
                }
            }
        }
        //builds the datagrid on load
        private void frmAgents_Load(object sender, EventArgs e)
        {
            this.WindowState             = FormWindowState.Maximized;
            agents                       = AgentDB.GetAgents();
            agentDataGridView.DataSource = agents;

            //clears out the duplicate types before they are added to the combo box
            List <string> agtPositions = new List <string>();

            foreach (Agent agentPos in agents)
            {
                if (!agtPositions.Contains(agentPos.AgtPosition))
                {
                    agtPositions.Add(agentPos.AgtPosition);
                }
            }

            agtPositionComboBox.DataSource    = agtPositions;
            agtPositionComboBox.SelectedIndex = 2; //hovers over the junior agent option

            agencies = AgencyDB.GetAgencies();
            agencyIDComboBox.DataSource = agencies;
        }
Пример #9
0
 public agentMgr(AgentDB db)
 {
     this.DB = db;
 }