private void listBox1_Click(object sender, EventArgs e)
        {
            try
            {
                CONTACT    contact = new CONTACT();
                int        groupid = (Int32)listBox1.SelectedValue;
                SqlCommand command = new SqlCommand("SELECT fname as FirstName, lname as LastName, [mygroups].name as Group, phone, email, address, pic FROM [mycontact] INNER JOIN [mygroups] on [mycontact].group_id = mygroups.id WHERE [mycontact].userid = @userid AND [mycontact].group_id = @groupid");
                command.Parameters.AddWithValue("@groupid", groupid);
                command.Parameters.AddWithValue("@userid", Globals.GlobalUserId);
                dataGridView1.DataSource = contact.SelectContactList(command);

                for (int i = 0; i < dataGridView1.Rows.Count; i++)
                {
                    if (IsOdd(i))
                    {
                        dataGridView1.Rows[i].DefaultCellStyle.BackColor = Color.WhiteSmoke;
                    }
                }
            }
            catch (Exception)
            {
            }

            dataGridView1.ClearSelection();
        }
Exemplo n.º 2
0
        private void button_Add_Contact_Click(object sender, EventArgs e)
        {
            string fname   = textBoxFName.Text;
            string lname   = textBoxLName.Text;
            string phone   = textBoxPhone.Text;
            string address = textBoxAddress.Text;
            string email   = textBoxEmail.Text;
            int    userid  = Globals.GlobalUserId;

            try
            {
                // get the group id
                int groupid = (int)comboBoxGroup.SelectedValue;

                // get the image
                MemoryStream pic = new MemoryStream();
                pictureBoxContactImage.Image.Save(pic, pictureBoxContactImage.Image.RawFormat);

                CONTACT contact = new CONTACT();

                if (contact.insertContact(fname, lname, phone, address, email, userid, groupid, pic))
                {
                    MessageBox.Show("New Contact Added", "Add Contact", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else
                {
                    MessageBox.Show("Error", "Add Contact", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            catch (Exception)
            {
                MessageBox.Show("One Or More Fields Are Empty", "Add Contact", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        // button edit contact
        private void button_Edit_Contact_Click(object sender, EventArgs e)
        {
            CONTACT contact = new CONTACT();

            string fname   = textBoxFName.Text;
            string lname   = textBoxLName.Text;
            string phone   = textBoxPhone.Text;
            string address = textBoxAddress.Text;
            string email   = textBoxEmail.Text;

            try
            {
                Int32 id = Convert.ToInt32(textBoxContactId.Text);

                int groupid = (int)comboBoxGroup.SelectedValue;

                MemoryStream pic = new MemoryStream();
                pictureBoxContactImage.Image.Save(pic, pictureBoxContactImage.Image.RawFormat);

                if (contact.updateContact(id, fname, lname, phone, address, email, groupid, pic))
                {
                    MessageBox.Show("Contact Inormation UpDated", "Edit Contact", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else
                {
                    MessageBox.Show("Error", "Add Contact", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Add Contact", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        // button select the contact you want to edit from the list
        private void buttonSelectContact_Click(object sender, EventArgs e)
        {
            // open the form to select a contact from it
            Select_Contact_Form SelectContactF = new Select_Contact_Form();

            SelectContactF.ShowDialog();

            try
            {
                // get the contact id
                int contactId = Convert.ToInt32(SelectContactF.dataGridView1.CurrentRow.Cells[0].Value.ToString());

                CONTACT   contact = new CONTACT();
                DataTable table   = contact.GetContactById(contactId);

                textBoxContactId.Text       = table.Rows[0]["id"].ToString();
                textBoxFName.Text           = table.Rows[0]["fname"].ToString();
                textBoxLName.Text           = table.Rows[0]["lname"].ToString();
                comboBoxGroup.SelectedValue = table.Rows[0]["group_id"];
                textBoxPhone.Text           = table.Rows[0]["phone"].ToString();
                textBoxEmail.Text           = table.Rows[0]["email"].ToString();
                textBoxAddress.Text         = table.Rows[0]["address"].ToString();

                byte[]       pic     = (byte[])table.Rows[0]["pic"];
                MemoryStream picture = new MemoryStream(pic);
                pictureBoxContactImage.Image = Image.FromStream(picture);
            }
            catch (Exception)
            {
                // if no contact is selected
            }
        }
        private void Select_Contact_Form_Load(object sender, EventArgs e)
        {
            // display image on the panel ( close and minimize )
            panel4.BackgroundImage = Image.FromFile("../../images/img4.png");

            CONTACT    contact = new CONTACT();
            SqlCommand command = new SqlCommand("SELECT id, fname as firstname, lname as lastname, group_id as group id FROM [mycontact] WHERE userid = @uid");

            command.Parameters.AddWithValue("@uid", Globals.GlobalUserId);
            dataGridView1.DataSource = contact.SelectContactList(command);
        }
Exemplo n.º 6
0
        // button remove selected contact by id
        private void buttonRemoveContact_Click(object sender, EventArgs e)
        {
            CONTACT contact = new CONTACT();

            if (!TextBoxContactId.Text.Equals("")) // check if TextBoxContactId is empty
            {
                int contactid = Convert.ToInt32(TextBoxContactId.Text);

                if (contact.deleteContact(contactid))
                {
                    MessageBox.Show("Contact Deleted", "Remove Contact", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else
                {
                    MessageBox.Show("Remove Contact", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            else
            {
                MessageBox.Show("No Contact Selected", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        private void Contacts_Full_List_Form_Load(object sender, EventArgs e)
        {
            // display image on the panel ( close and minimize )
            panel4.BackgroundImage = Image.FromFile("../../images/img4.png");

            DataGridViewImageColumn picCol = new DataGridViewImageColumn();

            dataGridView1.RowTemplate.Height = 80;

            CONTACT contact = new CONTACT();
            //SqlCommand command = new SqlCommand("SELECT [mycontact].fname as FirstName, [mycontact].lname as LastName, [mygroups].name as Group, phone, email, address, pic FROM [mycontact] INNER JOIN [mygroups] on [mycontact].group_id = [mygroups].id WHERE [mycontact].userid = @userid");
            SqlCommand command = new SqlCommand("SELECT [mygroups].name as GroupName,fname as FirstName, lname as LastName,  phone, email, address, pic FROM [mycontact] INNER JOIN [mygroups] on [mycontact].group_id = [mygroups].id WHERE [mycontact].userid = @userid");

            command.Parameters.AddWithValue("@userid", Globals.GlobalUserId);
            dataGridView1.DataSource = contact.SelectContactList(command);

            picCol = (DataGridViewImageColumn)dataGridView1.Columns[6];

            picCol.ImageLayout = DataGridViewImageCellLayout.Stretch;

            for (int i = 0; i < dataGridView1.Rows.Count; i++)
            {
                if (IsOdd(i))
                {
                    dataGridView1.Rows[i].DefaultCellStyle.BackColor = Color.WhiteSmoke;
                }
            }

            GROUP group = new GROUP();

            listBox1.DataSource    = group.getGroups(Globals.GlobalUserId);
            listBox1.DisplayMember = "name";
            listBox1.ValueMember   = "id";

            listBox1.SelectedItem = null;
            dataGridView1.ClearSelection();
        }