Exemplo n.º 1
0
        private void LoadButton_Click(object sender, EventArgs e)
        {
            if (OpenFileDialog.ShowDialog() == DialogResult.Cancel)
            {
                return;
            }

            MainTextBox.ResetText();

            string filename = OpenFileDialog.FileName;

            using (StreamReader inputfile = new StreamReader(filename, Encoding.GetEncoding(1251)))
            {
                while (!inputfile.EndOfStream)
                {
                    inputfile.ReadLine();
                    string temp1  = inputfile.ReadLine();
                    string temp2  = inputfile.ReadLine();
                    string temp3  = inputfile.ReadLine();
                    uint   temp3u = 0;

                    if (uint.TryParse(temp3, out temp3u))
                    {
                        temp = new Facility(temp1, temp2, temp3u);
                    }
                    else
                    {
                        temp = new WorkPlace(temp1, temp2, temp3);
                    }

                    if (temp.name != "")
                    {
                        Corporation.AddDepartment(temp);
                        inputfile.ReadLine();

                        while ((inputfile.Peek() != '[') && (!inputfile.EndOfStream))
                        {
                            Corporation.AddEmployee(new Employee(inputfile.ReadLine(), inputfile.ReadLine(),
                                                                 temp, inputfile.ReadLine(), inputfile.ReadLine()));
                            if (!inputfile.EndOfStream)
                            {
                                inputfile.ReadLine();
                            }
                        }
                    }
                    else
                    {
                        break;
                    }
                }

                CounterLabel.Text = "Число отделов: " + Corporation.GetDepartmentCount()
                                    + ". Число сотрудников: " + Corporation.GetEmployeeCount() + ".";

                inputfile.Close();
            }
        }
Exemplo n.º 2
0
        private void SwitchSearchAction()
        {
            if (OKButton.Visible == false)
            {
                MainTextBox.ReadOnly = false;
                MainTextBox.ResetText();

                ShowAll.Enabled       = false;
                NameSearch.Enabled    = false;
                PosSearch.Enabled     = false;
                NameDepSearch.Enabled = false;
                PosDepSearch.Enabled  = false;

                OKButton.Visible = true;
            }
        }
Exemplo n.º 3
0
        private void SwitchMode()
        {
            if ((OKButton.Visible == false) && (ShowAll.Enabled == true))
            {
                MainTextBox.ReadOnly = false;
                MainTextBox.ResetText();

                AddDep.Enabled      = false;
                RemoveDep.Enabled   = false;
                EditDep.Enabled     = false;
                AddEmp.Enabled      = false;
                RemoveEmp.Enabled   = false;
                TransferEmp.Enabled = false;
                MainSearch.Enabled  = false;
                LoadButton.Enabled  = false;
                SaveButton.Enabled  = false;

                OKButton.Visible     = true;
                CancelButton.Visible = true;
            }
            else if (ShowAll.Enabled == false)
            {
                MainTextBox.ReadOnly = true;

                ShowAll.Enabled       = true;
                NameSearch.Enabled    = true;
                PosSearch.Enabled     = true;
                NameDepSearch.Enabled = true;
                PosDepSearch.Enabled  = true;

                ShowAll.Visible       = false;
                NameSearch.Visible    = false;
                PosSearch.Visible     = false;
                NameDepSearch.Visible = false;
                PosDepSearch.Visible  = false;
                OKButton.Visible      = false;
                CancelButton.Visible  = false;

                AddDep.Visible      = true;
                RemoveDep.Visible   = true;
                EditDep.Visible     = true;
                AddEmp.Visible      = true;
                RemoveEmp.Visible   = true;
                TransferEmp.Visible = true;
                MainSearch.Visible  = true;
                LoadButton.Visible  = true;
                SaveButton.Visible  = true;
            }
            else
            {
                CounterLabel.Text = "Число отделов: " + Corporation.GetDepartmentCount()
                                    + ". Число сотрудников: " + Corporation.GetEmployeeCount() + ".";

                MainTextBox.ReadOnly = true;
                MainTextBox.ResetText();

                AddDep.Enabled      = true;
                RemoveDep.Enabled   = true;
                EditDep.Enabled     = true;
                AddEmp.Enabled      = true;
                RemoveEmp.Enabled   = true;
                TransferEmp.Enabled = true;
                MainSearch.Enabled  = true;
                LoadButton.Enabled  = true;
                SaveButton.Enabled  = true;

                OKButton.Visible     = false;
                CancelButton.Visible = false;
            }
        }
Exemplo n.º 4
0
        private void OKButton_Click(object sender, EventArgs e)
        {
            StringReader text      = new StringReader(MainTextBox.Text);
            string       TextToAdd = "";

            try
            {
                switch (OKButtonAction)
                {
                case "AddDep":
                    string temp1  = text.ReadLine();
                    string temp2  = text.ReadLine();
                    string temp3  = text.ReadLine();
                    uint   temp3u = 0;

                    if (uint.TryParse(temp3, out temp3u))
                    {
                        Corporation.AddDepartment(new Facility(temp1, temp2, temp3u));
                    }
                    else
                    {
                        Corporation.AddDepartment(new WorkPlace(temp1, temp2, temp3));
                    }
                    break;

                case "RemoveDep":
                    Corporation.RemoveDepartment(text.ReadLine());
                    break;

                case "EditDep":
                    Corporation.EditDepartmentDescription(text.ReadLine(), text.ReadLine());
                    break;

                case "AddEmp":
                    Corporation.AddEmployee(text.ReadLine(), text.ReadLine(), text.ReadLine(), text.ReadLine(), text.ReadLine());
                    break;

                case "RemoveEmp":
                    Corporation.RemoveEmployee(text.ReadLine(), text.ReadLine(), text.ReadLine());
                    break;

                case "TransferEmp":
                    Corporation.MoveEmployeeToDepartment(text.ReadLine(), text.ReadLine(), text.ReadLine());
                    break;

                case "NameSearch":
                    TextToAdd   = "";
                    ListToPrint = new List <Employee>(Corporation.FindBySecondName(text.ReadLine()));

                    if (ListToPrint.Count == 0)
                    {
                        MainTextBox.ResetText();
                        MessageBox.Show("Сотрудники не найдены.");
                    }

                    foreach (Employee item2 in ListToPrint)
                    {
                        TextToAdd += "\n" + item2.firstName + "\n";
                        TextToAdd += item2.secondName + "\n";
                        TextToAdd += item2.position + " (" + item2.department.name + ")\n";
                        TextToAdd += item2.bio + "\n";
                    }
                    MainTextBox.Text = TextToAdd;
                    break;

                case "PosSearch":
                    TextToAdd   = "";
                    ListToPrint = new List <Employee>(Corporation.FindByPosition(text.ReadLine()));

                    if (ListToPrint.Count == 0)
                    {
                        MainTextBox.ResetText();
                        MessageBox.Show("Сотрудники не найдены.");
                    }

                    foreach (Employee item2 in ListToPrint)
                    {
                        TextToAdd += "\n" + item2.firstName + "\n";
                        TextToAdd += item2.secondName + "\n";
                        TextToAdd += item2.position + " (" + item2.department.name + ")\n";
                        TextToAdd += item2.bio + "\n";
                    }
                    MainTextBox.Text = TextToAdd;
                    break;

                case "NameDepSearch":
                    TextToAdd   = "";
                    ListToPrint = new List <Employee>(Corporation.FindBySecondNameAndDepartment(text.ReadLine(), text.ReadLine()));

                    if (ListToPrint.Count == 0)
                    {
                        MainTextBox.ResetText();
                        MessageBox.Show("Сотрудники не найдены.");
                    }

                    foreach (Employee item2 in ListToPrint)
                    {
                        TextToAdd += "\n" + item2.firstName + "\n";
                        TextToAdd += item2.secondName + "\n";
                        TextToAdd += item2.position + " (" + item2.department.name + ")\n";
                        TextToAdd += item2.bio + "\n";
                    }
                    MainTextBox.Text = TextToAdd;
                    break;

                case "PosDepSearch":
                    TextToAdd   = "";
                    ListToPrint = new List <Employee>(Corporation.FindByPositionAndDepartment(text.ReadLine(), text.ReadLine()));

                    if (ListToPrint.Count == 0)
                    {
                        MainTextBox.ResetText();
                        MessageBox.Show("Сотрудники не найдены.");
                    }

                    foreach (Employee item2 in ListToPrint)
                    {
                        TextToAdd += "\n" + item2.firstName + "\n";
                        TextToAdd += item2.secondName + "\n";
                        TextToAdd += item2.position + " (" + item2.department.name + ")\n";
                        TextToAdd += item2.bio + "\n";
                    }
                    MainTextBox.Text = TextToAdd;
                    break;
                }

                SwitchMode();
            }
            catch (NullReferenceException)
            {
                SwitchMode();
                MessageBox.Show("Неверный формат данных.");
                return;
            }
            catch (OverflowException)
            {
                SwitchMode();
                MessageBox.Show("Неверный формат данных.");
                return;
            }
            catch (FormatException)
            {
                SwitchMode();
                MessageBox.Show("Неверный формат данных.");
                return;
            }
        }