Пример #1
0
        private void buttonEdit_Click(object sender, EventArgs e)
        {
            try
            {
                if (inputtedValues())
                {
                    Trans[dataGridView1.SelectedCells[0].RowIndex].Name = textBoxName.Text;

                    Trans[dataGridView1.SelectedCells[0].RowIndex].Cost       = Convert.ToInt32(textBoxCost.Text);
                    Trans[dataGridView1.SelectedCells[0].RowIndex].Engine     = textBoxEngine.Text;
                    Trans[dataGridView1.SelectedCells[0].RowIndex].Fact.City  = textBoxCity.Text;
                    Trans[dataGridView1.SelectedCells[0].RowIndex].Fact.Name1 = textBoxFact.Text;

                    comboBoxType.SelectedIndex = 0;
                    if (Trans[dataGridView1.SelectedCells[0].RowIndex] is GroundTransport)
                    {
                        comboBoxType.SelectedIndex = 1;
                        GroundTransport curr = Trans[dataGridView1.SelectedCells[0].RowIndex] as GroundTransport;
                        curr.Transmission = Convert.ToInt32(textBox1.Text);
                        Trans[dataGridView1.SelectedCells[0].RowIndex] = curr;
                    }
                    else if (Trans[dataGridView1.SelectedCells[0].RowIndex] is WaterTransport)
                    {
                        comboBoxType.SelectedIndex = 2;
                        WaterTransport curr = Trans[dataGridView1.SelectedCells[0].RowIndex] as WaterTransport;
                        curr.CountDeck = Convert.ToInt32(textBox1.Text);
                        curr.Crew      = Convert.ToInt32(textBox2.Text);
                        Trans[dataGridView1.SelectedCells[0].RowIndex] = curr;
                    }
                    else if (Trans[dataGridView1.SelectedCells[0].RowIndex] is AirTransport)
                    {
                        comboBoxType.SelectedIndex = 3;
                        AirTransport curr = Trans[dataGridView1.SelectedCells[0].RowIndex] as AirTransport;
                        curr.Capacity = Convert.ToInt32(textBox1.Text);
                        curr.Weight   = Convert.ToInt32(textBox2.Text);
                        Trans[dataGridView1.SelectedCells[0].RowIndex] = curr;
                    }
                    else if (Trans[dataGridView1.SelectedCells[0].RowIndex] is WorkTransport)
                    {
                        comboBoxType.SelectedIndex = 4;
                        WorkTransport curr = Trans[dataGridView1.SelectedCells[0].RowIndex] as WorkTransport;
                        curr.Size = Convert.ToInt32(textBox1.Text);
                        curr.Kind = Convert.ToInt32(textBox2.Text);
                        Trans[dataGridView1.SelectedCells[0].RowIndex] = curr;
                    }
                    dataGridAndAllListsUpdate();
                    ClearTextBoxes();
                }
                else
                {
                    MessageBox.Show("Заполните все поля!");
                }
            }
            catch
            {
                MessageBox.Show("Выберите ТС!");
            }
        }
Пример #2
0
        private void dataGridView1_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e)
        {
            listBoxInfo.Items.Clear();
            FillTextBoxes();
            try
            {
                listBoxInfo.Items.Add($"Название: { Trans[dataGridView1.SelectedCells[0].RowIndex].Name}");
                listBoxInfo.Items.Add($"Стоимость: { Trans[dataGridView1.SelectedCells[0].RowIndex].Cost}");
                listBoxInfo.Items.Add($"Двигатель: { Trans[dataGridView1.SelectedCells[0].RowIndex].Engine}");
                listBoxInfo.Items.Add($"Завод Изготовитель: город{Trans[dataGridView1.SelectedCells[0].RowIndex].Fact.City}, название {Trans[dataGridView1.SelectedCells[0].RowIndex].Fact.Name1}");
                listBoxInfo.Items.Add($"Водитель: Имя {Trans[dataGridView1.SelectedCells[0].RowIndex].Driver.Name2}, Фамилия {Trans[dataGridView1.SelectedCells[0].RowIndex].Driver.Surname}, Категория {Trans[dataGridView1.SelectedCells[0].RowIndex].Driver.Category}");



                if (Trans[dataGridView1.SelectedCells[0].RowIndex] is GroundTransport)
                {
                    GroundTransport curr = Trans[dataGridView1.SelectedCells[0].RowIndex] as GroundTransport;
                    listBoxInfo.Items.Add("Тип Транспортного средства: Наземный Транспорт");
                    listBoxInfo.Items.Add($"Тип коробки: {curr.Transmission}");
                }
                else if (Trans[dataGridView1.SelectedCells[0].RowIndex] is WaterTransport)
                {
                    WaterTransport curr = Trans[dataGridView1.SelectedCells[0].RowIndex] as WaterTransport;
                    listBoxInfo.Items.Add("Тип Транспортного средства: Водный Транспорт");
                    listBoxInfo.Items.Add($"Количество Цилиндров: { curr.CountDeck}");
                    listBoxInfo.Items.Add($"Экипаж: { curr.Crew} кол-во человек");
                }
                else if (Trans[dataGridView1.SelectedCells[0].RowIndex] is AirTransport)
                {
                    AirTransport curr = Trans[dataGridView1.SelectedCells[0].RowIndex] as AirTransport;
                    listBoxInfo.Items.Add("Тип Транспортного средства: Воздушный Транспорт");
                    listBoxInfo.Items.Add($"Вместимость: { curr.Capacity}");
                    listBoxInfo.Items.Add($"Вес: { curr.Weight}");
                }

                else if (Trans[dataGridView1.SelectedCells[0].RowIndex] is WorkTransport)
                {
                    WorkTransport curr = Trans[dataGridView1.SelectedCells[0].RowIndex] as WorkTransport;
                    listBoxInfo.Items.Add("Тип Транспортного средства: Рабочий Транспорт");
                    listBoxInfo.Items.Add($"Размер: { curr.Size}");
                    listBoxInfo.Items.Add($"Тип: { curr.Kind}");
                }
                else
                {
                    listBoxInfo.Items.Add("Тип Транспортного средства: Транспорт");
                }
            }
            catch
            {
                MessageBox.Show("Выберите Транспортное Средство!");
            }
        }
Пример #3
0
        private void FillTextBoxes()
        {
            textBoxName.Text = Trans[dataGridView1.SelectedCells[0].RowIndex].Name;

            textBoxEngine.Text    = Trans[dataGridView1.SelectedCells[0].RowIndex].Cost.ToString();
            textBoxCity.Text      = Trans[dataGridView1.SelectedCells[0].RowIndex].Fact.City;
            textBoxFact.Text      = Trans[dataGridView1.SelectedCells[0].RowIndex].Fact.Name1;
            textBoxDriveName.Text = Trans[dataGridView1.SelectedCells[0].RowIndex].Driver.Name2;
            textBoxSurname.Text   = Trans[dataGridView1.SelectedCells[0].RowIndex].Driver.Surname;
            textBoxCategory.Text  = Trans[dataGridView1.SelectedCells[0].RowIndex].Driver.Category;
            textBoxCost.Text      = Trans[dataGridView1.SelectedCells[0].RowIndex].Engine;

            comboBoxType.SelectedIndex = 0;
            if (Trans[dataGridView1.SelectedCells[0].RowIndex] is GroundTransport)
            {
                comboBoxType.SelectedIndex = 1;
                GroundTransport curr = Trans[dataGridView1.SelectedCells[0].RowIndex] as GroundTransport;
                textBox1.Text = curr.Transmission.ToString();
            }
            else if (Trans[dataGridView1.SelectedCells[0].RowIndex] is WaterTransport)
            {
                comboBoxType.SelectedIndex = 2;
                WaterTransport curr = Trans[dataGridView1.SelectedCells[0].RowIndex] as WaterTransport;
                textBox1.Text = curr.CountDeck.ToString();
                textBox2.Text = curr.Crew.ToString();
            }
            else if (Trans[dataGridView1.SelectedCells[0].RowIndex] is AirTransport)
            {
                comboBoxType.SelectedIndex = 3;
                AirTransport curr = Trans[dataGridView1.SelectedCells[0].RowIndex] as AirTransport;
                textBox1.Text = curr.Capacity.ToString();
                textBox2.Text = curr.Weight.ToString();
            }
            else if (Trans[dataGridView1.SelectedCells[0].RowIndex] is WorkTransport)
            {
                comboBoxType.SelectedIndex = 4;
                WorkTransport curr = Trans[dataGridView1.SelectedCells[0].RowIndex] as WorkTransport;
                textBox1.Text = curr.Size.ToString();
                textBox2.Text = curr.Kind.ToString();
            }
        }
Пример #4
0
        private void ChooseYourFighter(string s, bool saving)
        {
            if (saving)
            {
                if (s.IndexOf(".dat") > 0)
                {
                    BinaryFormatter formatter = new BinaryFormatter();
                    using (FileStream fs = new FileStream(s, FileMode.OpenOrCreate))
                    {
                        formatter.Serialize(fs, Trans);
                    }
                    MessageBox.Show("Успешно!");
                }
                else if (s.IndexOf(".json") > 0)
                {
                    DataContractJsonSerializer jsonFormatter = new DataContractJsonSerializer(typeof(List <Transport>),
                                                                                              new Type[] { typeof(WorkTransport), typeof(WaterTransport), typeof(GroundTransport), typeof(AirTransport) });
                    using (FileStream fs = new FileStream(s, FileMode.OpenOrCreate))
                    {
                        jsonFormatter.WriteObject(fs, Trans);
                    }
                    MessageBox.Show("Успешно!");
                }
                else if (s.IndexOf(".txt") > 0)
                {
                    string text = "";
                    for (int i = 0; i < Trans.Count; i++)
                    {
                        if (Trans[i] is WorkTransport)
                        {
                            WorkTransport curr = Trans[i] as WorkTransport;
                            text += $"''|Рабочий Транспорт'{curr.Name}'|'{curr.Cost}'|'{curr.Fact.City}'|'{curr.Fact.Name1}'|'{curr.Driver.Name2}'|'" +
                                    $"{curr.Driver.Surname}'|'{curr.Driver.Category}'|'{curr.Engine}'|'{curr.Size}'|'{curr.Kind}'\r\n";
                        }
                        else if (Trans[i] is WaterTransport)
                        {
                            WaterTransport curr = Trans[i] as WaterTransport;
                            text += $"'Водный Транспорт'|'{curr.Name}'|'{curr.Cost}'|'{curr.Fact.City}'|'{curr.Fact.Name1}'|'{curr.Driver.Name2}'|'" +
                                    $"{curr.Driver.Surname}'|'{curr.Driver.Category}'|'{curr.Engine}'|'{curr.CountDeck}'|'{curr.Crew}'\r\n";
                        }
                        else if (Trans[i] is GroundTransport)
                        {
                            GroundTransport curr = Trans[i] as GroundTransport;
                            text += $"'Наземный Транспорт'|'{curr.Name}'|'{curr.Cost}'|'{curr.Fact.City}'|'{curr.Fact.Name1}'|'{curr.Driver.Name2}'|'" +
                                    $"{curr.Driver.Surname}'|'{curr.Driver.Category}'|'{curr.Engine}'|'{curr.Transmission}'\r\n";
                        }
                        else if (Trans[i] is AirTransport)
                        {
                            AirTransport curr = Trans[i] as AirTransport;
                            text += $"'Воздушный Транспорт'|'{curr.Name}'|'{curr.Cost}'|'{curr.Fact.City}'|'{curr.Fact.Name1}'|'{curr.Driver.Name2}'|'" +
                                    $"{curr.Driver.Surname}'|'{curr.Driver.Category}'|'{curr.Engine}'|'{curr.Capacity}'|'{curr.Weight}'\r\n";
                        }
                        else
                        {
                            Transport curr = Trans[i] as Transport;
                            text += $"'Не уточнено'|'{curr.Name}'|'{curr.Cost}'|'{curr.Fact.City}'|'{curr.Fact.Name1}'|'{curr.Driver.Name2}'|'" +
                                    $"{curr.Driver.Surname}'|'{curr.Driver.Category}'|'{curr.Engine}'\r\n";
                        }
                    }
                    using (FileStream fs = new FileStream(s, FileMode.OpenOrCreate))
                    {
                        byte[] array = Encoding.Default.GetBytes(text);
                        fs.Write(array, 0, array.Length);
                    }
                    MessageBox.Show("Успешно!");
                }
                else
                {
                    MessageBox.Show("Что-то пошло не так!");
                }
            }
            else
            {
                if (s.IndexOf(".dat") > 0)
                {
                    BinaryFormatter formatter = new BinaryFormatter();
                    using (FileStream fs = new FileStream(s, FileMode.OpenOrCreate))
                    {
                        Trans = (List <Transport>)formatter.Deserialize(fs);
                    }
                    MessageBox.Show("Успешно!");
                }
                else if (s.IndexOf(".json") > 0)
                {
                    DataContractJsonSerializer jsonFormatter = new DataContractJsonSerializer(typeof(List <Transport>),
                                                                                              new Type[] { typeof(WorkTransport), typeof(WaterTransport), typeof(GroundTransport), typeof(AirTransport) });
                    using (FileStream fs = new FileStream(s, FileMode.OpenOrCreate))
                    {
                        Trans = (List <Transport>)jsonFormatter.ReadObject(fs);
                    }
                    MessageBox.Show("Успешно!");
                }
                else if (s.IndexOf(".txt") > 0)
                {
                    using (StreamReader sr = new StreamReader(s, System.Text.Encoding.Default))
                    {
                        while (!sr.EndOfStream)
                        {
                            string[] line        = sr.ReadLine().Split('|');
                            string   clName      = line[0].Substring(1, line[0].Length - 2);
                            string   name        = line[1].Substring(1, line[1].Length - 2);
                            int      cost        = Convert.ToInt32(line[2].Substring(1, line[2].Length - 2));
                            string   engine      = line[3].Substring(1, line[3].Length - 2);
                            string   city        = line[4].Substring(1, line[4].Length - 2);
                            string   name1       = line[5].Substring(1, line[5].Length - 2);
                            string   name2       = line[6].Substring(1, line[6].Length - 2);
                            string   surname     = line[7].Substring(1, line[7].Length - 2);
                            string   category    = line[8].Substring(1, line[8].Length - 2);
                            int      firstParam  = Convert.ToInt32(line[9].Substring(1, line[9].Length - 2));
                            int      secondparam = Convert.ToInt32(line[10].Substring(1, line[10].Length - 2));


                            Driver    currDrive = new Driver(name2, surname, category);
                            Factory   currFact  = new Factory(city, name1);
                            Transport trans1    = getWorkerTypeByString(clName, name, cost, currFact, currDrive, engine, firstParam, secondparam);
                            Trans.Add(trans1);
                        }
                    }
                    MessageBox.Show("Успешно!");
                }
                else
                {
                    MessageBox.Show("Что-то пошло не так!");
                }
            }
        }