public static void EditContact(Contact contact, Contact newContact, User user)
        {
            if (user.contacts.Contains(contact))
            {
                user.contacts.Remove(contact);
                user.contacts.Add(contact);
            }

            user.contacts.Sort();
        }
Esempio n. 2
0
        public static void SelectFromPhoneNumbers(SqlConnection connection, User user, Contact contact)
        {
            string sql1 = "SELECT * FROM PHONENUMBER WHERE Id_contact =" + contact.id;
            SqlCommand command2 = new SqlCommand(sql1, connection);
            SqlDataReader dr = command2.ExecuteReader();

            while (dr.Read())
            {
                List<PhoneNumber> pn = new List<PhoneNumber>();
                pn.Add(new PhoneNumber(dr["Number"].ToString(), dr["Label"].ToString()));
                user.contacts[Int32.Parse(contact.id) - 1].numbers = pn;
            }

            dr.Close();
        }
Esempio n. 3
0
        public static void InsertIntoContacts(SqlConnection connection, Contact contact, User user, int index)
        {
            string saveContact = "INSERT into CONTACTS (Name,Surname,Patronymic,Id_user) " +
                   " VALUES ('" + contact.name + "', '" + contact.surname + "', '" + contact.patronymic + "', '" + index + "');";

            SqlCommand querySaveStaff = new SqlCommand(saveContact, connection);
            querySaveStaff.ExecuteNonQuery();

            foreach (PhoneNumber p in contact.numbers)
            {
                string saveNumber = "INSERT into PHONENUMBER (Number,Label,Id_contact) " +
               " VALUES ('" + p.number + "', '" + p.label + "', '" + (contact.id + user.contacts.Count) + "');";

                SqlCommand querySaveNumber = new SqlCommand(saveNumber, connection);
                querySaveNumber.ExecuteNonQuery();
            }
        }
Esempio n. 4
0
        private void btOK_Click(object sender, EventArgs e)
        {
            if (tbName.Text == "" || tbPatronymic.Text == "" || tbSurname.Text == "" || tbPhoneNumber.Text == "")
            {
                return;
            }
            else
            {
                numbers.Add(new PhoneNumber(tbPhoneNumber.Text, lbLabels.SelectedItem.ToString()));
                Contact contact = new Contact(tbName.Text, tbSurname.Text, tbPatronymic.Text, numbers);
                UserContactsProcessing.AddContact(contact, list);
                connection1.Open();

                BaseDataAccess.InsertIntoContacts(connection1, contact, list, index);

                this.DialogResult = DialogResult.OK;
                connection1.Close();

                this.Close();
            }
        }
Esempio n. 5
0
        public static List<Contact> SelectFromContacts(SqlConnection connection, int index)
        {
            List<Contact> contacts = new List<Contact>();

            string sql = "SELECT * FROM CONTACTS WHERE Id_user ="******"Id"].ToString(), dataReader1["Name"].ToString(), dataReader1["Surname"].ToString(),
                    dataReader1["Patronymic"].ToString());

                contacts.Add(contact);

            }
            dataReader1.Close();

            return contacts;
        }
Esempio n. 6
0
        public FormForEdit(User list, Contact contact)
        {
            list = new User();
            this.contact = new Contact();

            foreach (Contact us in list.contacts)
            {
                UserContactsProcessing.AddContact(us, this.list);
            }

            this.contact = contact;
            this.index = Int32.Parse(contact.id);

            InitializeComponent();

            tbName.Text = contact.name;
            tbSurname.Text = contact.surname;
            tbPatronymic.Text = contact.patronymic;

            foreach (PhoneNumber number in contact.numbers)
            {
                lbNumbers.Items.Add(number.ToString());
            }
        }
Esempio n. 7
0
 public static void UpdateContacts(SqlConnection connection, Contact contact, int index)
 {
     string sql = string.Format("Update CONTACTS Set Name = '{0}', Surname = '{1}', Patronymic = '{2}'  Where Id = '{3}'",
             contact.name, contact.surname, contact.patronymic, index);
     using (SqlCommand cmd = new SqlCommand(sql, connection))
     {
         cmd.ExecuteNonQuery();
     }
 }
 public static void AddContact(Contact contact, User user)
 {
     user.contacts.Add(contact);
 }
Esempio n. 9
0
        private void btEdit_Click(object sender, EventArgs e)
        {
            if (dgUsers.SelectedRows.Count == 0)
            {
                return;
            }

            StringBuilder sb = new StringBuilder();
            sb.Append(dgUsers[0, dgUsers.CurrentRow.Index].Value.ToString() + ' ');
            sb.Append(dgUsers[1, dgUsers.CurrentRow.Index].Value.ToString());
            string[] result = sb.ToString().Split(' ');

            List<PhoneNumber> pn = new List<PhoneNumber>();
            for (int i = 3; i < result.Length-1; i+=2)
            {
                 pn.Add(new PhoneNumber(result[i], result[i+1]));
            }

            Contact contact = new Contact(result[0], result[1], result[2], pn);
            contact.id = (dgUsers.CurrentRow.Index + 1).ToString();
            FormForEdit form = new FormForEdit(user, contact);

            form.ShowDialog();

            if (form.DialogResult == DialogResult.OK)
            {
                 user = form.list;
            }

            for (int i = 0; i < form.list.contacts.Count; i++)
            {
                dgUsers.Rows.Add();
                dgUsers.Rows[i].Cells[0].Value = form.list.contacts[i].surname + " " + form.list.contacts[i].name + " " + form.list.contacts[i].patronymic;
                StringBuilder s = new StringBuilder();
                foreach (PhoneNumber number in users[index].contacts[i].numbers)
                {
                    s.Append(number.ToString() + " ");
                }
                dgUsers.Rows[i].Cells[1].Value = s;
            }
        }
Esempio n. 10
0
        private void btOK_Click(object sender, EventArgs e)
        {
            if (tbName.Text == "" || tbPatronymic.Text == "" || tbSurname.Text == "")
            {
                return;
            }
            else
            {
                connection1.Open();

                List<PhoneNumber> numbers = new List<PhoneNumber>();
                StringBuilder sbr = new StringBuilder();
                foreach (String str in lbNumbers.Items)
                {
                    String[] result = str.Split(' ');
                    numbers.Add(new PhoneNumber(result[0], result[1]));
                }

                list.contacts.RemoveAt(Int32.Parse(contact.id) - 1);

                Contact ct = new Contact(tbName.Text, tbSurname.Text, tbPatronymic.Text, numbers);
                ct.id = index.ToString();
                UserContactsProcessing.AddContact(ct, list);

                BaseDataAccess.UpdateContacts(connection1, ct, index);

                this.DialogResult = DialogResult.OK;
                this.Close();
            }
        }