Example #1
0
        private void editUserB_Click(object sender, EventArgs e)
        {
            if (usersList.SelectedIndex != -1)
            {
                int          ind = usersList.SelectedIndex;
                AddUser      adu = new AddUser(group[ind].name, group[ind].surname, group[ind].patron, group[ind].birthday);
                DialogResult dr  = adu.ShowDialog();
                if (dr == DialogResult.OK)
                {
                    XmlDocument xDoc = new XmlDocument();
                    xDoc.Load("data.xml");
                    XmlElement xRoot = xDoc.DocumentElement;
                    foreach (XmlNode xnodeGroups in xRoot)
                    {
                        XmlNode attr = xnodeGroups.Attributes.GetNamedItem("id");
                        if (attr.Value == groups[groupsList.SelectedIndex].id.ToString())
                        {
                            foreach (XmlNode xnode in xnodeGroups)
                            {
                                XmlNode attr2 = xnode.Attributes.GetNamedItem("id");
                                if (attr2.Value == group[ind].id.ToString())
                                {
                                    attr2       = xnode.Attributes.GetNamedItem("surname");
                                    attr2.Value = adu.surnameBox.Text;
                                    attr2       = xnode.Attributes.GetNamedItem("name");
                                    attr2.Value = adu.nameBox.Text;
                                    attr2       = xnode.Attributes.GetNamedItem("patron");
                                    attr2.Value = adu.patronBox.Text;
                                    attr2       = xnode.Attributes.GetNamedItem("birthday");
                                    attr2.Value = adu.dateTimePicker1.Value.ToShortDateString();

                                    xDoc.Save("data.xml");
                                    UpdateUsersList();
                                    break;
                                }
                            }
                        }
                    }
                }
            }
        }