private void Delete_toolStripButton3_Click(object sender, EventArgs e) { //удалить строку if (this.phoneBookGridListDataGridView.SelectedRows.Count > 0) { PhoneBookList.RemoveAt(phoneBookGridListDataGridView.SelectedRows[0].Index); CopyListToGrid(); } else { MessageBox.Show("Выберите строку для удаления"); } }
public PhoneBookForm() { InitializeComponent(); phoneBookListBindingSource.DataSource = PhoneBookList; phoneBookGridListBindingSource.DataSource = PhoneBookGridList; phoneBookGridListDataGridView.ColumnHeadersDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter; phoneBookGridListDataGridView.ColumnHeadersBorderStyle = DataGridViewHeaderBorderStyle.Sunken; phoneBookGridListDataGridView.ColumnHeadersDefaultCellStyle.Font = new Font("Calibri", 14F, FontStyle.Bold, GraphicsUnit.Pixel); foreach (DataGridViewHeaderCell header in phoneBookGridListDataGridView.Rows) { header.Style.Alignment = DataGridViewContentAlignment.MiddleCenter; header.Style.Font = new Font("Arial", 12F, FontStyle.Bold, GraphicsUnit.Pixel); } // передаем в конструктор тип класса XmlSerializer formatter = new XmlSerializer(typeof(BindingList <PhoneBook>)); config = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + "\\phonebook.cfg"; datafile = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + "\\base.xml"; if (File.Exists(config)) { XmlDocument doc = new XmlDocument(); doc.Load(config); XmlNode node = doc.DocumentElement.SelectSingleNode("/config/basefile"); if (node != null) { datafile = node.InnerText; } node = doc.DocumentElement.SelectSingleNode("/config/local"); if (node != null && node.InnerText.ToLower() == "true") { //local_version = true; MessageBox.Show("!"); } } if (!(File.Exists(datafile))) { PhoneBookList.Add(new PhoneBook("*****@*****.**", new Credentials("Филип", "Дачев", "Бедросович", "Мужск.", new DateTime(1967, 12, 12)), new Address("Ленина", "10", "5"), new PhoneInfo("3242342", "Мобил."))); SaveToXmlFile(); //PhoneBookList.Clear(); MessageBox.Show("Файл base.xml не найден, создан новый."); } // десериализация PhoneBookList try { using (FileStream fs = new FileStream("base.xml", FileMode.Open)) { PhoneBookList = (BindingList <PhoneBook>)formatter.Deserialize(fs); //fs.Close(); } } catch (InvalidOperationException ex) { MessageBox.Show("Ошибка чтения" + ex); //throw; } //Console.WriteLine("Объект PhoneBookList десериализован"); //foreach (PhoneBook p in PhoneBookList) //{ // int now = int.Parse(DateTime.Now.ToString("yyyyMMdd")); // int dob = int.Parse(p.Credentials.YearOfBirth.ToString("yyyyMMdd")); // int age = (now - dob) / 10000; // Console.WriteLine($"Имя: {p.Credentials.FirstName} --- Возраст: {age}"); //} CopyListToGrid(); }
public void TestMethod1() { service = new PhoneBookList(); }
public void Setup() { service = new PhoneBookList(); }