private void btnSave_Click(object sender, EventArgs e)
        {
            Contact contact = new Contact();
            bool    ok      = false;

            if (Validation.ContactDataValidation(txtUserID.Text, txtName.Text, txtPhone.Text))
            {
                MessageBox.Show("Please enter the Contact details.");
                return;
            }
            else
            {
                contact.Id       = txtUserID.Text;
                contact.Name     = txtName.Text;
                contact.Phone    = txtPhone.Text;
                contact.Computer = txtComputer.Text;
            }

            if (txtUserID.Enabled == false)
            {
                //UPDATE
                ok = DALHelpers.UpdateContact(contact);

                if (ok == true)
                {
                    MessageBox.Show("The record was successfully saved!");
                }
                else
                {
                    MessageBox.Show("Error: An error has ocurred when trying to update the Contact!");
                }

                this.Close();
            }
            else //NEW CONTACT
            {
                List <Contact> contactList = new List <Contact>();

                contactList = DALHelpers.GetContactById(contact.Id);
                if (contactList.Count > 0)
                {
                    MessageBox.Show("Error: The ID: " + contact.Id + " ,already exists in the database!");
                }
                else
                {
                    ok = DALHelpers.AddContact(contact);

                    if (ok == true)
                    {
                        MessageBox.Show("The record was successfully saved!");
                    }
                }

                this.Close();
            }
        }
Beispiel #2
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            hasTheSaveButtonPressed = true;

            Contact contact = new Contact();
            bool    ok      = false;

            contact.Id        = txtUserID.Text;
            contact.Name      = txtName.Text;
            contact.CellPhone = txtCellPhone.Text;
            contact.Phone     = txtPhone.Text;
            contact.Computer  = txtComputer.Text;

            foreach (Team team in teamList)
            {
                if (cmbTeam.Text == team.TeamName)
                {
                    contact.TeamId   = team.TeamId;
                    contact.TeamName = team.TeamName;
                }
            }

            if (Validation.ContactDataValidation(contact))
            {
                MessageBox.Show("Please enter the Contact details.");
                return;
            }

            if (txtUserID.Enabled == false)
            {
                //UPDATE
                ok = DALHelpers.UpdateContact(contact);

                if (ok == true)
                {
                    MessageBox.Show("The record was successfully saved!");
                }
                else
                {
                    MessageBox.Show("Error: An error has ocurred when trying to update the Contact!");
                }

                ActivityLog.ContactLogger(contact, "UPDATE", "Contact", Environment.UserName);
                this.Close();
            }
            else //NEW CONTACT
            {
                List <Contact> contactList = new List <Contact>();

                contactList = DALHelpers.GetContactById(contact.Id);
                if (contactList.Count > 0)
                {
                    MessageBox.Show("Error: The ID: " + contact.Id + " already exists in the database!");
                    return;
                }
                else
                {
                    ok = DALHelpers.AddContact(contact);

                    if (ok == true)
                    {
                        ActivityLog.ContactLogger(contact, "CREATE", "Contact", Environment.UserName);
                        MessageBox.Show("The record was successfully saved!");
                    }
                }

                this.Close();
            }
        }