/**************************** ******** УДАЛЕНИЕ ********* ****************************/ private void deleteMarketBT_Click(object sender, EventArgs e) { DialogResult dr = new DialogResult(); dr = MessageBox.Show( "Сохранить супермаркет \"" + mainMarket.Name + "\" перед удалением?", "Удаление", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Exclamation); if (dr == DialogResult.Cancel) { return; } else if (dr == DialogResult.Yes) { saveMarketBT.PerformClick(); } //Удаление mainMarket.Clear(); mainMarket = null; marketNameLabel.Text = "Название супермаркета"; marketNameLabel.ForeColor = Color.Silver; sectionsAmountLabel.Text = "Количество секций"; sectionsAmountLabel.ForeColor = Color.Silver; //Деактивация кнопок addSectionBT.Enabled = false; deleteMarketBT.Enabled = false; editMarketBT.Enabled = false; saveMarketBT.Enabled = false; FillSectionsTable(); FillGoodsTable(); }
private void openBT_Click(object sender, EventArgs e) { DialogResult dr = new DialogResult(); if (!Directory.Exists(Form1.supermarketXmlPath)) { //если папка XML не сущестует, то создать ее Directory.CreateDirectory(Form1.supermarketXmlPath); } openFileDialog.InitialDirectory = Form1.supermarketXmlPath; openFileDialog.Filter = "Файлы XML (*.xml)|*.xml"; dr = openFileDialog.ShowDialog(); if (dr == DialogResult.OK) { openTextBox.Text = openFileDialog.FileName; market = new Supermarket(); if (market.Deserialize(openFileDialog.FileName)) { openResultLabel.ForeColor = Color.Green; openResultLabel.Text = "Выгрузка супермаркета \"" + market.Name + "\" прошла успешно"; addBT.Enabled = true; } else { openResultLabel.ForeColor = Color.Red; openResultLabel.Text = "Выгрузка прошла неуспешно"; } } }
private void addBT_Click(object sender, EventArgs e) { if (market == null) { market = new Supermarket(); market.Name = nameTextBox.Text; if (amountTextBox.Text != string.Empty) { market.QueueSize = Convert.ToInt32(amountTextBox.Text); } else { market.QueueSize = 0; } } }
public bool Deserialize(string path) { /*if (path == "") * path = defaultPath + "supermarket.xml";*/ //XmlSerializer ser = new XmlSerializer(typeof(Supermarket)); var dcss = new DataContractSerializerSettings { PreserveObjectReferences = true }; var dcs = new DataContractSerializer(typeof(Supermarket), dcss); try { if (File.Exists(path)) { using (FileStream st = new FileStream(path, FileMode.OpenOrCreate)) { //Supermarket sp = (Supermarket)ser.Deserialize(st); Supermarket sp = new Supermarket(); sp = (Supermarket)dcs.ReadObject(st); this.Clear(); this.Name = sp.Name; this.QueueSize = sp.QueueSize; this.AllExistSections = sp.AllExistSections; } return(true); } else { return(false); } } catch (Exception ex) { Console.WriteLine(ex.ToString()); return(false); } }
/**************************** ******** СОЗДАНИЕ ********* ****************************/ private void createMarketBT_Click(object sender, EventArgs e) { DialogResult dr = new DialogResult(); if (mainMarket == null) { //Если супермаркет еще не создан Form4 form4 = new Form4(this); dr = form4.ShowDialog(); if (dr == DialogResult.OK) { mainMarket = new Supermarket(); mainMarket = form4.Market; marketNameLabel.Text = mainMarket.Name; sectionsAmountLabel.Text = mainMarket.QueueSize.ToString(); marketNameLabel.ForeColor = Color.White; sectionsAmountLabel.ForeColor = Color.White; //Активация кнопок addSectionBT.Enabled = true; deleteMarketBT.Enabled = true; editMarketBT.Enabled = true; saveMarketBT.Enabled = true; //Заполнение таблиц FillSectionsTable(); FillGoodsTable(); } } else //Если создан { //предложить сохранить текущий супермаркет dr = MessageBox.Show( "Сохранить текущие данные о супермаркете \"" + mainMarket.Name + "\"?\nПри создании нового все данные будут потеряны.", "Создать новый файл?", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question); if (dr == DialogResult.Yes) { saveMarketBT.PerformClick(); } else if (dr == DialogResult.No) { //Удаление mainMarket.Clear(); mainMarket = null; marketNameLabel.Text = "Название супермаркета"; marketNameLabel.ForeColor = Color.Silver; sectionsAmountLabel.Text = "Количество секций"; sectionsAmountLabel.ForeColor = Color.Silver; //Деактивация кнопок addSectionBT.Enabled = false; deleteMarketBT.Enabled = false; editMarketBT.Enabled = false; saveMarketBT.Enabled = false; FillSectionsTable(); FillGoodsTable(); createMarketBT.PerformClick(); } } }