Ejemplo n.º 1
0
        private void buttonEdit_Click_1(object sender, EventArgs e)
        {
            try
            {
                if (inputtedValues())
                {
                    Models[dataGridView1.SelectedCells[0].RowIndex].Name = textBoxName.Text;

                    Models[dataGridView1.SelectedCells[0].RowIndex].EstimatedCost    = Convert.ToDouble(textBoxCost.Text);
                    Models[dataGridView1.SelectedCells[0].RowIndex].Number           = textBoxNumber.Text;
                    Models[dataGridView1.SelectedCells[0].RowIndex].RepairStartDate  = dateTimePicker1.Value;
                    Models[dataGridView1.SelectedCells[0].RowIndex].Address.City     = textBoxCity.Text;
                    Models[dataGridView1.SelectedCells[0].RowIndex].Address.Street   = textBoxStreet.Text;
                    Models[dataGridView1.SelectedCells[0].RowIndex].Address.Building = Convert.ToInt32(textBoxBuilding.Text);

                    comboBoxCompany.SelectedIndex = 0;
                    if (Models[dataGridView1.SelectedCells[0].RowIndex] is Samsung)
                    {
                        comboBoxCompany.SelectedIndex = 1;
                        Samsung curr = Models[dataGridView1.SelectedCells[0].RowIndex] as Samsung;
                        curr.PhoneModel = textBox1.Text;
                        curr.Restored   = checkBoxRestored.Checked;
                        Models[dataGridView1.SelectedCells[0].RowIndex] = curr;
                    }
                    else if (Models[dataGridView1.SelectedCells[0].RowIndex] is Apple)
                    {
                        comboBoxCompany.SelectedIndex = 2;
                        Apple curr = Models[dataGridView1.SelectedCells[0].RowIndex] as Apple;
                        curr.PhoneModel = textBox1.Text;
                        curr.Restored   = checkBoxRestored.Checked;
                        Models[dataGridView1.SelectedCells[0].RowIndex] = curr;
                    }
                    else if (Models[dataGridView1.SelectedCells[0].RowIndex] is Xiaomi)
                    {
                        comboBoxCompany.SelectedIndex = 3;
                        Xiaomi curr = Models[dataGridView1.SelectedCells[0].RowIndex] as Xiaomi;
                        curr.PhoneModel = textBox1.Text;
                        Models[dataGridView1.SelectedCells[0].RowIndex] = curr;
                    }
                    else if (Models[dataGridView1.SelectedCells[0].RowIndex] is Huawei)
                    {
                        comboBoxCompany.SelectedIndex = 4;
                        Huawei curr = Models[dataGridView1.SelectedCells[0].RowIndex] as Huawei;
                        curr.PhoneModel = textBox1.Text;
                        Models[dataGridView1.SelectedCells[0].RowIndex] = curr;
                    }
                    dataGridAndAllListsUpdate();
                    ClearTextBoxes();
                }
                else
                {
                    MessageBox.Show("Заполните все поля!");
                }
            }
            catch
            {
                MessageBox.Show("Выберите модель!");
            }
        }
Ejemplo n.º 2
0
        private void FillTextBoxes()
        {
            textBoxName.Text = Models[dataGridView1.SelectedCells[0].RowIndex].Name;

            textBoxCost.Text      = Models[dataGridView1.SelectedCells[0].RowIndex].EstimatedCost.ToString();
            textBoxNumber.Text    = Models[dataGridView1.SelectedCells[0].RowIndex].Number;
            dateTimePicker1.Value = Models[dataGridView1.SelectedCells[0].RowIndex].RepairStartDate;
            textBoxCity.Text      = Models[dataGridView1.SelectedCells[0].RowIndex].Address.City;
            textBoxStreet.Text    = Models[dataGridView1.SelectedCells[0].RowIndex].Address.Street;
            textBoxBuilding.Text  = Models[dataGridView1.SelectedCells[0].RowIndex].Address.Building.ToString();


            comboBoxCompany.SelectedIndex = 0;
            if (Models[dataGridView1.SelectedCells[0].RowIndex] is Samsung)
            {
                comboBoxCompany.SelectedIndex = 1;
                Samsung curr = Models[dataGridView1.SelectedCells[0].RowIndex] as Samsung;
                textBox1.Text            = curr.PhoneModel.ToString();
                checkBoxRestored.Checked = curr.Restored;
            }
            else if (Models[dataGridView1.SelectedCells[0].RowIndex] is Apple)
            {
                comboBoxCompany.SelectedIndex = 2;
                Apple curr = Models[dataGridView1.SelectedCells[0].RowIndex] as Apple;
                textBox1.Text            = curr.PhoneModel.ToString();
                checkBoxRestored.Checked = curr.Restored;
            }
            else if (Models[dataGridView1.SelectedCells[0].RowIndex] is Xiaomi)
            {
                comboBoxCompany.SelectedIndex = 3;
                Xiaomi curr = Models[dataGridView1.SelectedCells[0].RowIndex] as Xiaomi;
                textBox1.Text = curr.PhoneModel.ToString();
            }
            else if (Models[dataGridView1.SelectedCells[0].RowIndex] is Huawei)
            {
                comboBoxCompany.SelectedIndex = 4;
                Huawei curr = Models[dataGridView1.SelectedCells[0].RowIndex] as Huawei;
                textBox1.Text = curr.PhoneModel.ToString();
            }
        }
Ejemplo n.º 3
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, Models);
                    }
                    MessageBox.Show("Успешно!");
                }
                else if (s.IndexOf(".json") > 0)
                {
                    DataContractJsonSerializer jsonFormatter = new DataContractJsonSerializer(typeof(List <Phones>),
                                                                                              new Type[] { typeof(Apple), typeof(Samsung), typeof(Xiaomi), typeof(Huawei) });
                    using (FileStream fs = new FileStream(s, FileMode.OpenOrCreate))
                    {
                        jsonFormatter.WriteObject(fs, Models);
                    }
                    MessageBox.Show("Успешно!");
                }
                else if (s.IndexOf(".txt") > 0)
                {
                    string text = "";
                    for (int i = 0; i < Models.Count; i++)
                    {
                        if (Models[i] is Apple)
                        {
                            Apple curr = Models[i] as Apple;
                            text += $"'Apple'|'{curr.Name}'|'{curr.RepairStartDate}'|'{curr.Number}'|'{curr.EstimatedCost}'|'{curr.Address.City}'|'" +
                                    $"{curr.Address.Street}'|'{curr.Address.Building}'|'{curr.PhoneModel}'|'{curr.Restored}'\r\n";
                        }
                        else if (Models[i] is Samsung)
                        {
                            Samsung curr = Models[i] as Samsung;
                            text += $"'Samsung'|'{curr.Name}'|'{curr.RepairStartDate}'|'{curr.Number}'|'{curr.EstimatedCost}'|'{curr.Address.City}'|'" +
                                    $"{curr.Address.Street}'|'{curr.Address.Building}'|'{curr.PhoneModel}'|'{curr.Restored}'\r\n";
                        }
                        else if (Models[i] is Xiaomi)
                        {
                            Xiaomi curr = Models[i] as Xiaomi;
                            text += $"'Xiaomi'|'{curr.Name}'|'{curr.RepairStartDate}'|'{curr.Number}'|'{curr.EstimatedCost}'|'{curr.Address.City}'|'" +
                                    $"{curr.Address.Street}'|'{curr.Address.Building}'|'{curr.PhoneModel}'\r\n";
                        }
                        else if (Models[i] is Huawei)
                        {
                            Huawei curr = Models[i] as Huawei;
                            text += $"'Huawei'|'{curr.Name}'|'{curr.RepairStartDate}'|'{curr.Number}'|'{curr.EstimatedCost}'|'{curr.Address.City}'|'" +
                                    $"{curr.Address.Street}'|'{curr.Address.Building}'|'{curr.PhoneModel}'\r\n";
                        }
                        else
                        {
                            Phones curr = Models[i] as Phones;
                            text += $"'Не уточнено'|'{curr.Name}'|'{curr.RepairStartDate}'|'{curr.Number}'|'{curr.EstimatedCost}'|'{curr.Address.City}'|'" +
                                    $"{curr.Address.Street}'|'{curr.Address.Building}'\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))
                    {
                        Models = (List <Phones>)formatter.Deserialize(fs);
                    }
                    MessageBox.Show("Успешно!");
                }
                else if (s.IndexOf(".json") > 0)
                {
                    DataContractJsonSerializer jsonFormatter = new DataContractJsonSerializer(typeof(List <Phones>),
                                                                                              new Type[] { typeof(Apple), typeof(Samsung), typeof(Xiaomi), typeof(Huawei) });
                    using (FileStream fs = new FileStream(s, FileMode.OpenOrCreate))
                    {
                        Models = (List <Phones>)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);
                            DateTime repairStartDate = Convert.ToDateTime(line[2].Substring(1, line[2].Length - 2));
                            string   number          = line[3].Substring(1, line[3].Length - 2);
                            int      estimatedCost   = Convert.ToInt32(line[4].Substring(1, line[4].Length - 2));
                            string   city            = line[5].Substring(1, line[5].Length - 2);
                            string   street          = line[6].Substring(1, line[6].Length - 2);
                            int      building        = Convert.ToInt32(line[7].Substring(1, line[7].Length - 2));
                            string   secondparam     = "";
                            if (clName != "Не уточнено")
                            {
                                secondparam = line[8].Substring(1, line[8].Length - 2);
                            }
                            bool restored = false;
                            if (clName == "Apple")
                            {
                                restored = Convert.ToBoolean(line[9].Substring(1, line[9].Length - 2));
                            }

                            if (clName == "Samsung")
                            {
                                restored = Convert.ToBoolean(line[9].Substring(1, line[9].Length - 2));
                            }

                            Address currAddr = new Address(city, street, building);
                            Phones  phone1   = getModelsTypeByString(clName, name, repairStartDate, number, currAddr, estimatedCost, secondparam, restored);
                            Models.Add(phone1);
                        }
                    }
                    MessageBox.Show("Успешно!");
                }
                else
                {
                    MessageBox.Show("Что-то пошло не так!");
                }
            }
        }
Ejemplo n.º 4
0
        private void dataGridView1_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e)
        {
            listBoxInfo.Items.Clear();
            FillTextBoxes();
            try
            {
                listBoxInfo.Items.Add($"Номер: { Models[dataGridView1.SelectedCells[0].RowIndex].Number}");
                listBoxInfo.Items.Add($"Ориентировочная стоимость: { Models[dataGridView1.SelectedCells[0].RowIndex].EstimatedCost}");


                if (Models[dataGridView1.SelectedCells[0].RowIndex] is Samsung)
                {
                    Samsung curr = Models[dataGridView1.SelectedCells[0].RowIndex] as Samsung;
                    listBoxInfo.Items.Add("Фирма: Samsung");
                    listBoxInfo.Items.Add($"Модель: { curr.PhoneModel}");

                    if (curr.Restored)
                    {
                        listBoxInfo.Items.Add("Восстановлен");
                    }
                    else
                    {
                        listBoxInfo.Items.Add("Оригинальный");
                    }
                }
                else if (Models[dataGridView1.SelectedCells[0].RowIndex] is Apple)
                {
                    Apple curr = Models[dataGridView1.SelectedCells[0].RowIndex] as Apple;
                    listBoxInfo.Items.Add("Фирма: Apple");
                    listBoxInfo.Items.Add($"Модель: { curr.PhoneModel}");

                    if (curr.Restored)
                    {
                        listBoxInfo.Items.Add("Восстановлен");
                    }
                    else
                    {
                        listBoxInfo.Items.Add("Оригинальный");
                    }
                }
                else if (Models[dataGridView1.SelectedCells[0].RowIndex] is Xiaomi)
                {
                    Xiaomi curr = Models[dataGridView1.SelectedCells[0].RowIndex] as Xiaomi;
                    listBoxInfo.Items.Add("Фирма: Xiaomi");
                    listBoxInfo.Items.Add($"Модель: { curr.PhoneModel}");
                }

                else if (Models[dataGridView1.SelectedCells[0].RowIndex] is Huawei)
                {
                    Huawei curr = Models[dataGridView1.SelectedCells[0].RowIndex] as Huawei;
                    listBoxInfo.Items.Add("Фирма: Huawei");
                    listBoxInfo.Items.Add($"Модель: { curr.PhoneModel}");
                }
                else
                {
                    listBoxInfo.Items.Add("Фирма: не определена");
                    listBoxInfo.Items.Add("Модель: не определена");
                }
            }
            catch
            {
                MessageBox.Show("Выберите устройство!");
            }
        }