public FormReports(Enterprise enterprise) { InitializeComponent(); _enterprise = enterprise; foreach (Filiation elemF in _enterprise.Filiations) { comboBoxF.Items.Add(elemF.Name); } if (_enterprise.Filiations.Count != 0) { comboBoxF.SelectedIndex = 0; } }
/// <summary> /// Список филиалов в алфавитном порядке /// </summary> private void printReport1(Enterprise enterprise) { try { using (StreamWriter sw = new StreamWriter(string.Format(Application.StartupPath.ToString() + "\\Отчеты\\{0}.txt", 1), false, System.Text.Encoding.Default)) { foreach (Filiation elemF in enterprise.Filiations.OrderBy(x => x.Name)) { sw.WriteLine(elemF.Name); } } } catch (Exception e1) { Console.WriteLine(e1.Message); } }
/// <summary> /// Список филиалов в алфавитном порядке с указанием кол-ва работающих сотрудников в филиале /// </summary> private void printReport3(Enterprise enterprise) { try { using (StreamWriter sw = new StreamWriter(string.Format(Application.StartupPath.ToString() + "\\Отчеты\\{0}.txt", 3), false, System.Text.Encoding.Default)) { int countEmployee = 0; foreach (Filiation elemF in enterprise.Filiations.OrderBy(x => x.Name)) { foreach (Unit elemU in elemF.Units) { countEmployee += elemU.Employees.Count; } sw.WriteLine(elemF.Name + ":" + countEmployee.ToString()); countEmployee = 0; } } } catch (Exception e1) { Console.WriteLine(e1.Message); } }
private void openToolStripMenuItem_Click(object sender, EventArgs e) { try { OpenFileDialog openFile = new OpenFileDialog(); openFile.Filter = "xml files (*.xml)|*.xml|All files (*.*)|*.*"; if (openFile.ShowDialog() == DialogResult.OK) { XDocument doc = XDocument.Load(openFile.FileName); if (doc.Declaration.Encoding.Equals("utf-8") || doc.Declaration.Encoding.Equals("UTF-8")) { saveToolStripMenuItem.Enabled = true; XElement enterprise = doc.Root; enterpriseBase = new Enterprise(); this.Text = enterprise.Attribute("Наименование").Value; if (enterprise.HasElements) { foreach (XElement xEnterprise in enterprise.Elements()) { Filiation filiation = new Filiation(); filiation.Name = xEnterprise.Attribute("Наименование").Value; filiation.Address = xEnterprise.Attribute("Адрес").Value; foreach (XElement xUnit in xEnterprise.Elements()) { Unit unit = new Unit(); unit.Name = xUnit.Attribute("Наименование").Value; unit.Filiation = filiation; foreach (XElement xEmployee in xUnit.Elements()) { Employee employee = new Employee(); employee.EmployeeFIO.Name = xEmployee.Attribute("Имя").Value; employee.EmployeeFIO.Surname = xEmployee.Attribute("Фамилия").Value; employee.EmployeeFIO.Pathronymic = xEmployee.Attribute("Отчество").Value; employee.TypeSalary = xEmployee.Attribute("ТипЗП").Value;; employee.Salary = decimal.Parse(xEmployee.Attribute("ЗП").Value, new NumberFormatInfo { NumberDecimalSeparator = "." }); employee.Time = decimal.Parse(xEmployee.Attribute("Часы").Value, new NumberFormatInfo { NumberDecimalSeparator = "." }); employee.Unit = unit; unit.Employees.Add(employee); } filiation.Units.Add(unit); } enterpriseBase.Filiations.Add(filiation); } ShowFiliations(); } } else { MessageBox.Show("Загружаемая база повреждена"); } } } catch { MessageBox.Show("Загружаемая база повреждена"); } }