private void buttonEdit_Click(object sender, EventArgs e) { try { if (inputtedValues()) { Workers[dataGridView1.SelectedCells[0].RowIndex].Name = textBoxName.Text; Workers[dataGridView1.SelectedCells[0].RowIndex].Surname = textBoxSurname.Text; Workers[dataGridView1.SelectedCells[0].RowIndex].Salary = Convert.ToDouble(textBoxSalary.Text); Workers[dataGridView1.SelectedCells[0].RowIndex].Phone = textBoxPhone.Text; Workers[dataGridView1.SelectedCells[0].RowIndex].DateOfBirth = dateTimePicker1.Value; Workers[dataGridView1.SelectedCells[0].RowIndex].Address.City = textBoxCity.Text; Workers[dataGridView1.SelectedCells[0].RowIndex].Address.Street = textBoxStreet.Text; Workers[dataGridView1.SelectedCells[0].RowIndex].Address.Building = Convert.ToInt32(textBoxBuilding.Text); Workers[dataGridView1.SelectedCells[0].RowIndex].Address.Flat = Convert.ToInt32(textBoxFlat.Text); comboBoxProfession.SelectedIndex = 0; if (Workers[dataGridView1.SelectedCells[0].RowIndex] is Waiter) { comboBoxProfession.SelectedIndex = 1; Waiter curr = Workers[dataGridView1.SelectedCells[0].RowIndex] as Waiter; curr.Tips = Convert.ToInt32(textBox1.Text); Workers[dataGridView1.SelectedCells[0].RowIndex] = curr; } else if (Workers[dataGridView1.SelectedCells[0].RowIndex] is Manager) { comboBoxProfession.SelectedIndex = 2; Manager curr = Workers[dataGridView1.SelectedCells[0].RowIndex] as Manager; curr.Suborditates = Convert.ToInt32(textBox1.Text); Workers[dataGridView1.SelectedCells[0].RowIndex] = curr; } else if (Workers[dataGridView1.SelectedCells[0].RowIndex] is Chief) { comboBoxProfession.SelectedIndex = 4; Chief currChief = Workers[dataGridView1.SelectedCells[0].RowIndex] as Chief; currChief.Category = Convert.ToInt32(textBox1.Text); currChief.SignatureDish = textBoxSecond.Text; currChief.SwearLikeGordon = checkBoxSwear.Checked; Workers[dataGridView1.SelectedCells[0].RowIndex] = currChief; } else if (Workers[dataGridView1.SelectedCells[0].RowIndex] is Cook) { comboBoxProfession.SelectedIndex = 3; Cook curr = Workers[dataGridView1.SelectedCells[0].RowIndex] as Cook; curr.Category = Convert.ToInt32(textBox1.Text); Workers[dataGridView1.SelectedCells[0].RowIndex] = curr; } dataGridAndAllListsUpdate(); ClearTextBoxes(); } else { MessageBox.Show("Заполните все поля!"); } } catch { MessageBox.Show("Выберите работника!"); } }
private void buttonSerialize_Click(object sender, EventArgs e) { if (radioButtonBinary.Checked) { BinaryFormatter formatter = new BinaryFormatter(); using (FileStream fs = new FileStream("workers.dat", FileMode.OpenOrCreate)) { formatter.Serialize(fs, Workers); } } else if (radioButtonXml.Checked) { XmlSerializer formatter = new XmlSerializer(typeof(List <RestaurantWorker>), new Type[] { typeof(Waiter), typeof(Manager), typeof(Chief), typeof(Cook) }); using (FileStream fs = new FileStream("workers.xml", FileMode.OpenOrCreate)) { formatter.Serialize(fs, Workers); } } if (radioButtonFree.Checked) { string text = ""; for (int i = 0; i < Workers.Count; i++) { if (Workers[i] is Waiter) { Waiter curr = Workers[i] as Waiter; text += $"'Официант'|'{curr.Surname}'|'{curr.Name}'|'{curr.Phone}'|'{curr.DateOfBirth}'|'{curr.Salary}'|'{curr.Address.City}'|'{curr.Address.Street}'|'{curr.Address.Building}'|'{curr.Address.Flat}'|'{curr.Tips}'\r\n"; } else if (Workers[i] is Manager) { Manager curr = Workers[i] as Manager; text += $"'Менеджер'|'{curr.Surname}'|'{curr.Name}'|'{curr.Phone}'|'{curr.DateOfBirth}'|'{curr.Salary}'|'{curr.Address.City}'|'{curr.Address.Street}'|'{curr.Address.Building}'|'{curr.Address.Flat}'|'{curr.Suborditates}'\r\n"; } else if (Workers[i] is Chief) { Chief curr = Workers[i] as Chief; text += $"'Шеф-повар'|'{curr.Surname}'|'{curr.Name}'|'{curr.Phone}'|'{curr.DateOfBirth}'|'{curr.Salary}'|'{curr.Address.City}'|'{curr.Address.Street}'|'{curr.Address.Building}'|'{curr.Address.Flat}'|'{curr.Category}'|'{curr.SignatureDish}'|'{curr.SwearLikeGordon}'\r\n"; } else if (Workers[i] is Cook) { Cook curr = Workers[i] as Cook; text += $"'Менеджер'|'{curr.Surname}'|'{curr.Name}'|'{curr.Phone}'|'{curr.DateOfBirth}'|'{curr.Salary}'|'{curr.Address.City}'|'{curr.Address.Street}'|'{curr.Address.Building}'|'{curr.Address.Flat}'|'{curr.Category}'\r\n"; } else { RestaurantWorker curr = Workers[i] as RestaurantWorker; text += $"'Не уточнено'|'{curr.Surname}'|'{curr.Name}'|'{curr.Phone}'|'{curr.DateOfBirth}'|'{curr.Salary}'|'{curr.Address.City}'|'{curr.Address.Street}'|'{curr.Address.Building}'|'{curr.Address.Flat}'\r\n"; } } using (FileStream fs = new FileStream("workers.txt", FileMode.OpenOrCreate)) { byte[] array = Encoding.Default.GetBytes(text); fs.Write(array, 0, array.Length); } } }
private void dataGridView1_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e) { listBoxInfo.Items.Clear(); FillTextBoxes(); try { listBoxInfo.Items.Add($"{ Workers[dataGridView1.SelectedCells[0].RowIndex].Name} { Workers[dataGridView1.SelectedCells[0].RowIndex].Surname}"); listBoxInfo.Items.Add($"Телефон: { Workers[dataGridView1.SelectedCells[0].RowIndex].Phone}"); listBoxInfo.Items.Add($"Зарплатка: { Workers[dataGridView1.SelectedCells[0].RowIndex].Salary}"); if (Workers[dataGridView1.SelectedCells[0].RowIndex] is Waiter) { Waiter curr = Workers[dataGridView1.SelectedCells[0].RowIndex] as Waiter; listBoxInfo.Items.Add("Должность: официант"); listBoxInfo.Items.Add($"Чаевые: { curr.Tips}"); } else if (Workers[dataGridView1.SelectedCells[0].RowIndex] is Manager) { Manager curr = Workers[dataGridView1.SelectedCells[0].RowIndex] as Manager; listBoxInfo.Items.Add("Должность: менеджер"); listBoxInfo.Items.Add($"Подчиненные: { curr.Suborditates}"); } else if (Workers[dataGridView1.SelectedCells[0].RowIndex] is Chief) { Chief currChief = Workers[dataGridView1.SelectedCells[0].RowIndex] as Chief; listBoxInfo.Items.Add("Должность: шеф-повар"); listBoxInfo.Items.Add($"Разряд: { currChief.Category}"); listBoxInfo.Items.Add($"Коронное блюдо: { currChief.SignatureDish}"); if (currChief.SwearLikeGordon) { listBoxInfo.Items.Add("Матюкается как сапожник"); } else { listBoxInfo.Items.Add("Девочка/мальчик-пай"); } } else if (Workers[dataGridView1.SelectedCells[0].RowIndex] is Cook) { Cook curr = Workers[dataGridView1.SelectedCells[0].RowIndex] as Cook; listBoxInfo.Items.Add("Должность: повар"); listBoxInfo.Items.Add($"Разряд: { curr.Category}"); } else { listBoxInfo.Items.Add("Должность: работник ресторана"); } } catch { MessageBox.Show("Выберите работника!"); } }
private void FillTextBoxes() { textBoxName.Text = Workers[dataGridView1.SelectedCells[0].RowIndex].Name; textBoxSurname.Text = Workers[dataGridView1.SelectedCells[0].RowIndex].Surname; textBoxSalary.Text = Workers[dataGridView1.SelectedCells[0].RowIndex].Salary.ToString(); textBoxPhone.Text = Workers[dataGridView1.SelectedCells[0].RowIndex].Phone; dateTimePicker1.Value = Workers[dataGridView1.SelectedCells[0].RowIndex].DateOfBirth; textBoxCity.Text = Workers[dataGridView1.SelectedCells[0].RowIndex].Address.City; textBoxStreet.Text = Workers[dataGridView1.SelectedCells[0].RowIndex].Address.Street; textBoxBuilding.Text = Workers[dataGridView1.SelectedCells[0].RowIndex].Address.Building.ToString(); textBoxFlat.Text = Workers[dataGridView1.SelectedCells[0].RowIndex].Address.Flat.ToString(); comboBoxProfession.SelectedIndex = 0; if (Workers[dataGridView1.SelectedCells[0].RowIndex] is Waiter) { comboBoxProfession.SelectedIndex = 1; Waiter curr = Workers[dataGridView1.SelectedCells[0].RowIndex] as Waiter; textBox1.Text = curr.Tips.ToString(); } else if (Workers[dataGridView1.SelectedCells[0].RowIndex] is Manager) { comboBoxProfession.SelectedIndex = 2; Manager curr = Workers[dataGridView1.SelectedCells[0].RowIndex] as Manager; textBox1.Text = curr.Suborditates.ToString(); } else if (Workers[dataGridView1.SelectedCells[0].RowIndex] is Chief) { comboBoxProfession.SelectedIndex = 4; Chief currChief = Workers[dataGridView1.SelectedCells[0].RowIndex] as Chief; textBox1.Text = currChief.Category.ToString(); textBoxSecond.Text = currChief.SignatureDish; checkBoxSwear.Checked = currChief.SwearLikeGordon; } else if (Workers[dataGridView1.SelectedCells[0].RowIndex] is Cook) { comboBoxProfession.SelectedIndex = 3; Cook curr = Workers[dataGridView1.SelectedCells[0].RowIndex] as Cook; textBox1.Text = curr.Category.ToString(); } }