FirmWareInstallation.cs

МИНИСТЕРСТВО ОБРАЗОВАНИЯ И НАУКИ РОССИЙСКОЙ ФЕДЕРАЦИИ

федеральное государственное бюджетное образовательное учреждение

высшего образования

«УЛЬЯНОВСКИЙ ГОСУДАРСТВЕННЫЙ ТЕХНИЧЕСКИЙ УНИВЕРСИТЕТ»

Кафедра «Измерительно-вычислительные комплексы»

 

 

Элемент управления “Помощник в выборе прошивки”

Текст программы

Р.02069337. 16/889-03 ТЗ-01

Листов 32

 

 

Руководитель разработки:

ассистент каф. ИВК

Москвичёва Мария Геннадьевна

«   »                           2020 г.

Исполнитель:

студент гр. ИСТбд-21

Ёрочкин Денис Сергеевич

«   »                           2020 г.

 

 

2020

 

FirmWareInstallation.cs

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Drawing;

using System.Data;

using System.Linq;

using System.Text;

using System.Threading;

using System.Threading.Tasks;

using System.Windows.Forms;

 

namespace WindowsFormsControlLibrary1

{

#region Interfaces

public interface IControlSettings

{

   Font ListBoxFont { get; set; } // Шрифт элементов ListBox

   Color LabelColor { get; set; } // Задний фон элементов Label

   Color BackGround { get; set; } // Задний фон ListBox

   Cursor LabelDefaultCursor { get; set; } // Курсор в области Label

   bool ListboxScrollVisible { get; set; } // Видимость колеса прокрутки в ListBox

 

}

 

public interface IPropertiesFunc

{

   bool DataIsValid(object sender); // Проверка корректности данных

   void ResetProperties(bool ResetFirm, bool ResetPhone, bool ResetFirmWare, bool ResetVersion); // Очистка для ввода новых данных

   bool SelectionIsAvailable(int ID,Func<int> Value); // Проверка корректности выбора полей

   bool UniqueCheck(List<string> Unique, string Value);

   string RecoveryLastRemovedData(bool RecoveryState, Func<string, bool> Recycle, string Firm = "Default", string Phone = "Default", string FirmWare = "Default", string Version = "Default", bool IsAvailable = true, string ProCreator = "Default", ushort YearOfCreation = 2000); // Сохранение или восстановление последних удалённых данных в зависимости от параметра RecoveryState

 

}

#endregion

 

public partial class FirmWareInstallation: UserControl

{

   #region Events

   public delegate void AddFirmWare(object sender, EventArgs e);

   public delegate void DeleteFirmWare(object sender, EventArgs e);

   public delegate void UpdateFirmWare(object sender, FirmWareStorage e);

   public delegate void HideUnAvailableFirmWare(object sender, FirmWareStorage e);

 

   [Browsable(true)]

   [Category("AdvancedEvents")]

   public event AddFirmWare AddNewItem;

   [Browsable(true)]

   [Category("AdvancedEvents")]

   public event DeleteFirmWare DeleteItem;

   [Browsable(true)]

   [Category("AdvancedEvents")]

   public event UpdateFirmWare UpdateItem;

   [Browsable(true)]

   [Category("AdvancedEvents")]

   public event HideUnAvailableFirmWare HideItem;

 

   protected virtual void onAddFirmWare(object sender, EventArgs e)

   {

       AddNewItem?.Invoke(this, e);

   }

   protected virtual void onDeleteFirmWare(object sender, EventArgs e)

   {

       DeleteItem?.Invoke(this, e);

   }

   protected virtual void onUpdateFirmWare(object sender, FirmWareStorage e)

   {

       UpdateItem?.Invoke(this, e);

   }

   protected virtual void onHideUnAvailableFirmWare(object sender, FirmWareStorage e)

   {

       HideItem?.Invoke(this, e);

   }

   #endregion

 

   #region Properties

   // Второстепенные свойства

   private bool HideIsAvailable = true; // Можно ли спрятать элементы в ListBox

   private bool AllowUpdates = false; // Можно ли обновлять элементы в ListBox

   private bool RecoveryIsEnable = false; // Включение корзины

   FirmWareStorage str = new FirmWareStorage();

 

   // Собственные свойства

   private string Bin = ""; // Корзина

   static List<FirmWareStorage> Storage = new List<FirmWareStorage>(); // Хранилище

   static List<FirmWareStorage> HiddenStorage = new List<FirmWareStorage>(); // Хранилище спрятанных элементов

   private bool HiddenValue = false; // Спрятаны ли элементы

   private int C; // Счётчик добавленных/удалённых прошивок

   #endregion

 

   #region Constructors

   // Конструктор без параметров

   public FirmWareInstallation()

   {

       InitializeComponent();

   }

   // Конструктор позиционирования элемента управления

      public FirmWareInstallation(int x, int y)

   {

       InitializeComponent();

       this.Location = new Point(x, y);

   }

   // Конструктор размера элемента управления

   public FirmWareInstallation(double Size)

   {

       InitializeComponent();

       string temp = Size.ToString();

       string[] temp1 = temp.Split(new char[] { '.', ',' });

       int width = Convert.ToInt32(temp1[0]);

       int height = Convert.ToInt32(temp1[1]);

       this.Width = width;

       this.Height = height;

   }

   // Конструктор доступности элемента управления

   public FirmWareInstallation(bool EnableState)

   {

       InitializeComponent();

       this.Enabled = EnableState;

   }

   #endregion

 

   #region PropertiesGetAndSet

   // Собственные свойства

   [Category("MY Properties")]

   [Browsable(false)]

   [Description("Корзина")]

   public string BIN

   {

       get { return this.Bin; }

       set

       {

           if(value!= "")

           {

               this.Bin = value;

               this.RecoverLabel.ForeColor = Color.Green;

               this.RecoverLabel.BackColor = Color.Black;

           }

           else

           {

               this.Bin = value;

               this.RecoverLabel.ForeColor = SystemColors.ControlText;

               this.RecoverLabel.BackColor = SystemColors.Menu;

           }

       }

   }

 

   [Category("MY Properties")]

   [Browsable(false)]

   [Description("Спрятаны ли элементы")]

   public bool HideCompleted

   {

       get { return this.HiddenValue; }

       set

       {

           if (value == true && this.HiddenValue!= true)

           {

               this.HiddenValue = value;

               HideLabel.Text = "Показать все прошивки";

               MessageBox.Show(" Недоступные прошивки спрятаны!");

           }

           else if (value == false && this.HiddenValue!= false)

           {

               this.HiddenValue = value;

               HideLabel.Text = "Спрятать недоступные прошивки";

               MessageBox.Show(" Все прошивки снова видны!");

           }

       }

   }

 

   [Category("MY Properties")]

   [Browsable(false)]

   [Description("Счётчик добавленных/удалённых прошивок")]

   public int CountValue

   {

       get { return this.C; }

       set

       {

           if (this.C < value)

           {

               this.C = value;

               MessageBox.Show(" Прошивка была добавлена!");

           }

           else if(this.C > value)

           {

               this.C = value;

               MessageBox.Show(" Прошивка была удалена!");

           }

       }

   }

 

   // Второстепенные свойства

   [Category("Main Properties")]

   [Description("Можно ли спрятать элементы в ListBox")]

   public bool HideIsAvailableVal

   {

       get { return this.HideIsAvailable; }

       set { this.HideIsAvailable = value; }

   }

 

   [Category("Main Properties")]

   [Description("Можно ли обновлять элементы в ListBox")]

   public bool AllowUpdatesVal

   {

       get { return this.AllowUpdates; }

       set { this.AllowUpdates = value; }

   }

  

   [Category("Second Properties")]

   [Description("Доступно ли восстановление")]

   public bool RecoveryIsEnableVal

   {

       get { return this.RecoveryIsEnable; }

       set { this.RecoveryIsEnable = value; }

   }

 

   // Сопоставленные свойства

   [Category("Associated Properties")]

   [Description("Шрифт элементов ListBox")]

   public Font ListBoxFont

   {

       get { return this.FirmList.Font; }

       set

       {

           this.FirmList.Font = value;

           this.PhoneList.Font = value;

           this.FirmWareList.Font = value;

           this.VersionList.Font = value;

       }

   }

 

   [Category("Associated Properties")]

     [Description("Цвет фона элементов Label")]

   public Color LabelColor

   {

       get { return this.AddLabel.BackColor; }

       set

       {

           this.AddLabel.BackColor = value;

           this.DeleteLabel.BackColor = value;

           this.UpdateLabel.BackColor = value;

           this.RecoverLabel.BackColor = value;

           this.HideLabel.BackColor = value;

           this.labelInfo.BackColor = value;

       }

   }

 

   [Category("Associated Properties")]

   [Description("Задний фон ListBox")]

   public Color ListBoxBackColor

   {

       get { return this.FirmList.BackColor; }

       set

       {

           this.FirmList.BackColor = value;

           this.PhoneList.BackColor = value;

           this.FirmWareList.BackColor = value;

           this.VersionList.BackColor = value;

       }

   }

 

   [Category("Associated Properties")]

   [Description("Курсор в области Label")]

   public Cursor LabelDefaultCursor

   {

       get { return this.AddLabel.Cursor; }

       set

       {

           this.AddLabel.Cursor = value;

           this.DeleteLabel.Cursor = value;

           this.UpdateLabel.Cursor = value;

           this.RecoverLabel.Cursor = value;

           this.HideLabel.Cursor = value;

           this.labelInfo.Cursor = value;

       }

   }

 

   [Category("Associated Properties")]

   [Description("Колесо прокрутки ListBox")]

   public bool ListboxScrollVisible

   {

       get { return this.FirmList.ScrollAlwaysVisible; }

       set

       {

           this.FirmList.ScrollAlwaysVisible = value;

           this.PhoneList.ScrollAlwaysVisible = value;

           this.FirmWareList.ScrollAlwaysVisible = value;

           this.VersionList.ScrollAlwaysVisible = value;

       }

   }

    #endregion

 

   #region Methods

   public bool DataIsValid(object sender)

   {

       if ((sender as FirmWareStorage).GetFirm == String.Empty)

       {

           MessageBox.Show(" Не указана фирма телефона!");

           return false;

       }

       if((sender as FirmWareStorage).GetPhone == String.Empty)

       {

           MessageBox.Show(" Не указана модель телефона!");

           return false;

       }

       if ((sender as FirmWareStorage).GetFirmWare == String.Empty)

       {

           MessageBox.Show(" Не указана прошивка телефона!");

           return false;

       }

       if ((sender as FirmWareStorage).GetVersion == String.Empty)

       {

           MessageBox.Show(" Не указана версия прошивки!");

           return false;

       }

       if ((sender as FirmWareStorage).GetProCreator == String.Empty)

       {

           MessageBox.Show(" Не указан создатель прошивки!");

           return false;

       }

       if ((sender as FirmWareStorage).GetYearOfCreation == 0)

       {

           MessageBox.Show(" Не указан год создания прошивки!");               

           return false;

       }

       return true;

   }

 

   public void ResetProperties(bool ResetFirm, bool ResetPhone, bool ResetFirmWare, bool ResetVersion)

   {

       if(ResetVersion)

       {

           for (int i = this.VersionList.Items.Count; i > 0; --i)

               this.VersionList.SetSelected(i - 1, false);

           this.VersionList.Items.Clear();

           this.VersionList.Visible = false;

           this.label4.Visible = false;

       }

       if (ResetFirmWare)

       {

           for (int i = this.FirmWareList.Items.Count; i > 0; --i)

               this.FirmWareList.SetSelected(i - 1, false);

           this.FirmWareList.Items.Clear();

           labelNum.Visible = false;

           this.FirmWareList.Visible = false;

           this.label3.Visible = false;

       }

       if (ResetPhone)

       {

           for (int i = this.PhoneList.Items.Count; i > 0; --i)

               this.PhoneList.SetSelected(i - 1, false);

           this.PhoneList.Items.Clear();

           this.PhoneList.Visible = false;

           this.label2.Visible = false;

       }

       if (ResetFirm)

       {

           for (int i = this.FirmList.Items.Count; i > 0; --i)

               this.FirmList.SetSelected(i - 1, false);

           this.FirmList.Items.Clear();

           List<string> UniqueChecker = new List<string>();

           for (int i = 0; (Storage.Count - 1) >= i; i++)

           {

               if (UniqueCheck(UniqueChecker, Storage.ElementAt(i).GetFirm))

               {

                   this.FirmList.Items.Add(Storage.ElementAt(i).GetFirm);

                   UniqueChecker.Add(Storage.ElementAt(i).GetFirm);

               }

           }

       }

   }

 

   public bool SelectionIsAvailable(int ID)

   {

       if(ID == 0 || ID == 1)

       {

           if (this.FirmList.SelectedItems.Count == 0)

           {

               MessageBox.Show(" Обязательное действие! Выберите фирму телефона!");

               return false;

           }

           else if (this.FirmList.SelectedItems.Count > 1)

           {

               MessageBox.Show(" Выберите только одну фирму телефона!");

               return false;

           }

       }

       if (ID == 0 || ID == 2)

       {

           if (this.PhoneList.SelectedItems.Count == 0)

           {

               MessageBox.Show(" Обязательное действие! Выберите телефон!");

               return false;

           }

           else if (this.PhoneList.SelectedItems.Count > 1)

           {

               MessageBox.Show(" Выберите только один телефон!");

               return false;

           }

       }

       if (ID == 0 || ID == 3)

       {

           if (this.FirmWareList.SelectedItems.Count == 0)

           {

               MessageBox.Show(" Обязательное действие! Выберите прошивку телефона!");

               return false;

           }

           else if (this.FirmWareList.SelectedItems.Count > 1)

           {

               MessageBox.Show(" Выберите только одну прошивку телефона!");

               return false;

           }

       }

       if(ID == 0 || ID == 4)

       {

           if (this.VersionList.SelectedItems.Count == 0)

           {

               MessageBox.Show(" Обязательное действие! Выберите версию прошивки телефона!");

               return false;

           }

           else if (this.VersionList.SelectedItems.Count > 1)

           {

               MessageBox.Show(" Выберите только одну версию прошивки телефона!");

               return false;

           }

       }

       return true;

   }

 

   static bool RecycleFunc(string Bin)

   {

       if(Bin!= "")

           return true;

       else return false;

   }

   public string RecoveryLastRemovedData(bool RecoveryState, Func<string,bool> Recycle, string Firm = "Default", string Phone = "Default", string FirmWare = "Default", string Version = "Default", bool IsAvailable = true, string ProCreator = "Default", ushort YearOfCreation = 2000)

   {

           string Tmp = null;

           if (RecoveryState == false)

           {

               Tmp = Firm + "|" + Phone + "|" + FirmWare + "|" + Version + "|" + IsAvailable.ToString() + "|" + ProCreator + "|" + YearOfCreation.ToString();

               return Tmp;

           }

           else

           {

               if (Recycle(BIN))

               {

                   return BIN;

               }

               else MessageBox.Show(" Ошибка! Корзина пуста!");

               return null;

           }

   }

 

   bool UniqueCheck(List<string> Unique, string Value)

   {

       foreach (string Current in Unique)

           if (Current == Value)

               return false;

       return true;

   }

   #endregion

 

   #region MainCode

   private void FirmWareInstallation_Load(object sender, EventArgs e)

   {

       #region StartValues

       FirmWareStorage temp1 = new FirmWareStorage();

       FirmWareStorage temp2 = new FirmWareStorage();

       FirmWareStorage temp3 = new FirmWareStorage();

       FirmWareStorage temp4 = new FirmWareStorage();

       FirmWareStorage temp5 = new FirmWareStorage();

       FirmWareStorage temp6 = new FirmWareStorage();

       FirmWareStorage temp7 = new FirmWareStorage();

       FirmWareStorage temp8 = new FirmWareStorage();

       FirmWareStorage temp9 = new FirmWareStorage();

       FirmWareStorage temp10 = new FirmWareStorage();

       temp1.SetFirm("Samsung");

       temp1.SetPhone("Galaxy S");

       temp1.SetFirmWare("I9000XWJW7");

       temp1.SetVersion("2.3.6");

       temp1.SetIsAvailable(true);

       temp1.SetProCreator("Gingerbread");

       temp1.SetYearOfCreation(2012);

       Storage.Add(temp1);

       temp2.SetFirm("Xiaomi");

       temp2.SetPhone("Mi 7");

       temp2.SetFirmWare("MIUI 11");

       temp2.SetVersion("11.0.5.0 Recovery");

       temp2.SetIsAvailable(true);

       temp2.SetProCreator("MIUI");

       temp2.SetYearOfCreation(2020);

       Storage.Add(temp2);

       temp3.SetFirm("Huawei");

       temp3.SetPhone("Honor 5X");

       temp3.SetFirmWare("KIW-L21C432B340");

       temp3.SetVersion("EMUI 4.0");

       temp3.SetIsAvailable(true);

       temp3.SetProCreator("EMUI");

       temp3.SetYearOfCreation(2016);

       Storage.Add(temp3);

       temp4.SetFirm("Lenovo");

       temp4.SetPhone("A6000");

       temp4.SetFirmWare("А6000_S054_150915_8G_ROW");

       temp4.SetVersion("5.0.2");

       temp4.SetIsAvailable(false);

       temp4.SetProCreator("R&D Lenovo");

       temp4.SetYearOfCreation(2016);

       Storage.Add(temp4);

       temp5.SetFirm("Motorola");

       temp5.SetPhone("Moto G8");

       temp5.SetFirmWare("Moto G Hybrid Kernel");

       temp5.SetVersion("ver. 014");

       temp5.SetIsAvailable(true);

       temp5.SetProCreator("faux123");

       temp5.SetYearOfCreation(2014);

       Storage.Add(temp5);

       temp6.SetFirm("Lenovo");

       temp6.SetPhone("A6000");

       temp6.SetFirmWare("A6000-S058_151030_8G_ROW");

       temp6.SetVersion("5.0.2");

       temp6.SetIsAvailable(true);

       temp6.SetProCreator("Gingerbread");

       temp6.SetYearOfCreation(2014);

       Storage.Add(temp6);

       temp7.SetFirm("Lenovo");

       temp7.SetPhone("A6000");

       temp7.SetFirmWare("A6000-S056_150924_8G_ROW");

       temp7.SetVersion("5.0.2");

       temp7.SetIsAvailable(false);

       temp7.SetProCreator("Gingerbread");

       temp7.SetYearOfCreation(2013);

       Storage.Add(temp7);

       temp8.SetFirm("Lenovo");

       temp8.SetPhone("A6000");

       temp8.SetFirmWare("A6000_S061_160727_WCB0C57CA0");

       temp8.SetVersion("5.0.2");

       temp8.SetIsAvailable(true);

       temp8.SetProCreator("Gingerbread");

       temp8.SetYearOfCreation(2017);

       Storage.Add(temp8);

       temp9.SetFirm("Lenovo");

       temp9.SetPhone("A6000");

       temp9.SetFirmWare("A6000_S061_160727_WCB0C57CA0");

       temp9.SetVersion("5.1.2");

       temp9.SetIsAvailable(true);

       temp9.SetProCreator("Gingerbread");

       temp9.SetYearOfCreation(2017);

       Storage.Add(temp9);

       temp10.SetFirm("Lenovo");

       temp10.SetPhone("A6000");

       temp10.SetFirmWare("A6000_S061_160727_WCB0C57CA0");

       temp10.SetVersion("4.6.2");

       temp10.SetIsAvailable(false);

       temp10.SetProCreator("Gingerbread");

       temp10.SetYearOfCreation(2012);

       Storage.Add(temp10);

       FirmWareStorage temp11 = new FirmWareStorage();

       temp11.SetFirm("Lenovo");

       temp11.SetPhone("A6000");

       temp11.SetFirmWare("A6000_S061_160727_WCB0C57CA0");

       temp11.SetVersion("4.4.1");

       temp11.SetIsAvailable(false);

       temp11.SetProCreator("Gingerbread");

       temp11.SetYearOfCreation(2011);

       Storage.Add(temp11);

       FirmWareStorage temp12 = new FirmWareStorage();

       temp12.SetFirm("Lenovo");

       temp12.SetPhone("A6000");

       temp12.SetFirmWare("A6000-S058_151030_8G_ROW");

       temp12.SetVersion("5.2.1");

       temp12.SetIsAvailable(true);

       temp12.SetProCreator("Gingerbread");

       temp12.SetYearOfCreation(2017);

       Storage.Add(temp12);

       FirmWareStorage temp13 = new FirmWareStorage();

       temp13.SetFirm("Lenovo");

       temp13.SetPhone("A6000");

       temp13.SetFirmWare("A6000-S058_151030_8G_ROW");

       temp13.SetVersion("4.9.1");

       temp13.SetIsAvailable(false);

       temp13.SetProCreator("Gingerbread");

       temp13.SetYearOfCreation(2014);

       Storage.Add(temp13);

       FirmWareStorage temp14 = new FirmWareStorage();

       temp14.SetFirm("Lenovo");

       temp14.SetPhone("A606");

       temp14.SetFirmWare("S040_150702_ROW");

       temp14.SetVersion("2.3.1");

       temp14.SetIsAvailable(false);

       temp14.SetProCreator("Gingerbread");

       temp14.SetYearOfCreation(2013);

         Storage.Add(temp14);

       FirmWareStorage temp15 = new FirmWareStorage();

       temp15.SetFirm("Lenovo");

       temp15.SetPhone("A606");

       temp15.SetFirmWare("S038_150422_ROW");

       temp15.SetVersion("4.6.1");

       temp15.SetIsAvailable(true);

       temp15.SetProCreator("Gingerbread");

       temp15.SetYearOfCreation(2015);

       Storage.Add(temp15);

       FirmWareStorage temp16 = new FirmWareStorage();

       temp16.SetFirm("Lenovo");

       temp16.SetPhone("A606");

       temp16.SetFirmWare("S059_141025_ROW");

       temp16.SetVersion("4.0.1");

       temp16.SetIsAvailable(true);

       temp16.SetProCreator("Gingerbread");

       temp16.SetYearOfCreation(2014);

       Storage.Add(temp16);

       FirmWareStorage temp17 = new FirmWareStorage();

       temp17.SetFirm("Lenovo");

       temp17.SetPhone("A606");

       temp17.SetFirmWare("S059_141025_ROW");

       temp17.SetVersion("4.3.1");

       temp17.SetIsAvailable(false);

       temp17.SetProCreator("Gingerbread");

       temp17.SetYearOfCreation(2014);

       Storage.Add(temp17);

       FirmWareStorage temp18 = new FirmWareStorage();

       temp18.SetFirm("Lenovo");

       temp18.SetPhone("A606");

       temp18.SetFirmWare("S059_141025_ROW");

       temp18.SetVersion("5.0.2");

       temp18.SetIsAvailable(true);

       temp18.SetProCreator("Gingerbread");

       temp18.SetYearOfCreation(2016);

       Storage.Add(temp18);

       FirmWareStorage temp19 = new FirmWareStorage();

       temp19.SetFirm("Lenovo");

       temp19.SetPhone("A606");

       temp19.SetFirmWare("S040_150702_ROW");

       temp19.SetVersion("4.0");

       temp19.SetIsAvailable(true);

       temp19.SetProCreator("Gingerbread");

       temp19.SetYearOfCreation(2015);

       Storage.Add(temp19);

       FirmWareStorage temp20 = new FirmWareStorage();

       temp20.SetFirm("Lenovo");

       temp20.SetPhone("A606");

       temp20.SetFirmWare("S038_150422_ROW");

       temp20.SetVersion("5.1");

       temp20.SetIsAvailable(true);

       temp20.SetProCreator("Gingerbread");

       temp20.SetYearOfCreation(2017);

       Storage.Add(temp20);

       FirmWareStorage temp21 = new FirmWareStorage();

       temp21.SetFirm("Lenovo");

       temp21.SetPhone("Z6 Lite");

       temp21.SetFirmWare("ZUI_11.5.117_ST_200331_qpst");

       temp21.SetVersion("5.0");

       temp21.SetIsAvailable(true);

       temp21.SetProCreator("GPST");

       temp21.SetYearOfCreation(2017);

       Storage.Add(temp21);

       FirmWareStorage temp22 = new FirmWareStorage();

       temp22.SetFirm("Lenovo");

       temp22.SetPhone("Z6 Lite");

       temp22.SetFirmWare("ZUI_11.5.117_ST_200331_qpst");

       temp22.SetVersion("6.1");

       temp22.SetIsAvailable(true);

       temp22.SetProCreator("GPST");

       temp22.SetYearOfCreation(2018);

       Storage.Add(temp22);

       FirmWareStorage temp23 = new FirmWareStorage();

       temp23.SetFirm("Lenovo");

       temp23.SetPhone("Z6 Lite");

       temp23.SetFirmWare("ZUI_11.5.117_ST_200331_qpst");

       temp23.SetVersion("7.0.1");

       temp23.SetIsAvailable(true);

       temp23.SetProCreator("GPST");

       temp23.SetYearOfCreation(2019);

       Storage.Add(temp23);

       FirmWareStorage temp24 = new FirmWareStorage();

       temp24.SetFirm("Lenovo");

       temp24.SetPhone("Z6 Lite");

       temp24.SetFirmWare("ZUI 11.5.117");

       temp24.SetVersion("5.0.1");

       temp24.SetIsAvailable(false);

       temp24.SetProCreator("denoolen");

       temp24.SetYearOfCreation(2017);

       Storage.Add(temp24);

       FirmWareStorage temp25 = new FirmWareStorage();

       temp25.SetFirm("Lenovo");

       temp25.SetPhone("Z6 Lite");

       temp25.SetFirmWare("ZUI 11.5.117");

       temp25.SetVersion("5.0.1");

       temp25.SetIsAvailable(false);

       temp25.SetProCreator("denoolen");

       temp25.SetYearOfCreation(2017);

       Storage.Add(temp25);

       #endregion

       List<string> UniqueChecker = new List<string>();

       for (int i = 0; (Storage.Count - 1) >= i; i++)

       {

           if (UniqueCheck(UniqueChecker, Storage.ElementAt(i).GetFirm))

           {

               this.FirmList.Items.Add(Storage.ElementAt(i).GetFirm);

               UniqueChecker.Add(Storage.ElementAt(i).GetFirm);

           }

       }

       if (HideIsAvailable == false)

           this.HideLabel.Enabled = false;

       if (AllowUpdates == false)

           this.UpdateLabel.Enabled = false;

       this.AddLabel.Enabled = false;

       this.DeleteLabel.Enabled = false;

       this.PhoneList.Visible = false;

       this.FirmWareList.Visible = false;

       this.VersionList.Visible = false;

       this.label3.Visible = false;

       this.label2.Visible = false;

       this.label4.Visible = false;

 

   }

 

   private void FirmList_Click(object sender, EventArgs e)

   {

       if(SelectionIsAvailable(1))

       {

           ResetProperties(false,true,true,true);

           List<string> UniqueChecker = new List<string>();

           for(int i = 0; i <= (Storage.Count - 1); i++)

           {

               if ((UniqueCheck(UniqueChecker, Storage.ElementAt(i).GetPhone)) && (Storage.ElementAt(i).GetFirm == this.FirmList.SelectedItem.ToString()))

               {

                   this.PhoneList.Items.Add(Storage.ElementAt(i).GetPhone);

                   UniqueChecker.Add(Storage.ElementAt(i).GetPhone);

               }

           }

           this.PhoneList.Visible = true;

           this.label2.Visible = true;

       }

   }

 

   private void PhoneList_Click(object sender, EventArgs e)

   {

       if (SelectionIsAvailable(2))

       {

           int Number = 0;

           ResetProperties(false, false, true, true);

           List<string> UniqueChecker = new List<string>();

           for (int i = 0; i <= (Storage.Count - 1); i++)

           {

               if ((UniqueCheck(UniqueChecker, Storage.ElementAt(i).GetFirmWare)) && (Storage.ElementAt(i).GetPhone == this.PhoneList.SelectedItem.ToString()))

               {

                   if (Storage.ElementAt(i).GetIsAvailable)

                       Number += 1;

                   this.FirmWareList.Items.Add(Storage.ElementAt(i).GetFirmWare);

                   UniqueChecker.Add(Storage.ElementAt(i).GetFirmWare);

               }

           }

           this.FirmWareList.Visible = true;

           this.label3.Visible = true;

           this.labelNum.Visible = true;

           this.labelNum.Text = "Число доступных прошивок на данный телефон:" + Number.ToString();

       }

   }

 

   private void FirmWareList_Click(object sender, EventArgs e)

   {

       if (SelectionIsAvailable(3))

       {

           ResetProperties(false, false, false, true);

           List<string> UniqueChecker = new List<string>();

           for (int i = 0; i <= (Storage.Count - 1); i++)

           {

               if ((UniqueCheck(UniqueChecker, Storage.ElementAt(i).GetVersion)) && (Storage.ElementAt(i).GetFirmWare == this.FirmWareList.SelectedItem.ToString()))

               {

                   this.VersionList.Items.Add(Storage.ElementAt(i).GetVersion);

                   UniqueChecker.Add(Storage.ElementAt(i).GetVersion);

               }

           }

           this.VersionList.Visible = true;

           this.label4.Visible = true;

       }

   }

 

   private void AddLabel_Click(object sender, EventArgs e)

   {

       Form1 Form1 = new Form1();

       Form1.label8.Text = "Добавить прошивку";

       Form1.labelConfirm.Text = "Подтвердить";

       string tmp1;

       string tmp2;

       string tmp3;

       string tmp4;

       bool tmp5;

       string tmp6;

       ushort tmp7;

       do

       {

           Form1.ShowDialog();

           tmp1 = Form1.textBoxFirm.Text;

           tmp2 = Form1.textBoxPhone.Text;

           tmp3 = Form1.textBoxFirmWare.Text;

           tmp4 = Form1.textBoxVersion.Text;

           tmp5 = Form1.checkBoxEnable.Checked;

           tmp6 = Form1.textBoxProCreator.Text;

           tmp7 = Convert.ToUInt16(Form1.numericUpDownYearOfCreation.Value);

           if (tmp1!= String.Empty)

               Form1.textBoxFirm.Text = tmp1;

           if (tmp2!= String.Empty)

               Form1.textBoxPhone.Text = tmp2;

           if (tmp3!= String.Empty)

               Form1.textBoxFirmWare.Text = tmp3;

           if (tmp4!= String.Empty)

               Form1.textBoxVersion.Text = tmp4;

           Form1.checkBoxEnable.Checked = tmp5;

           if (tmp6!= String.Empty)

               Form1.textBoxProCreator.Text = tmp6;

           Form1.numericUpDownYearOfCreation.Value = Convert.ToDecimal(tmp7);

           str.SetFirm(tmp1);

           str.SetPhone(tmp2);

           str.SetFirmWare(tmp3);

           str.SetVersion(tmp4);

           str.SetIsAvailable(tmp5);

           str.SetProCreator(tmp6);

           str.SetYearOfCreation(tmp7);

       } while (!DataIsValid(str));

       bool checker = true;

       foreach(FirmWareStorage Addition in Storage)

       {

           if ((Addition.GetFirm == str.GetFirm) && (Addition.GetPhone == str.GetPhone) && (Addition.GetFirmWare == str.GetFirmWare) && (Addition.GetVersion == str.GetVersion))

           {

               checker = false;

           }

       }

       if (checker == true)

       {

           this.str.AddNewItem(str);

           ResetProperties(true, true, true, true);

           CountValue += 1;

           return;

       }

       if (checker == false)

       {

           if (AllowUpdatesVal == true)

               MessageBox.Show(" Такая прошивка уже существует! Невозможно добавить! Если вы хотите заменить текущую прошивку на новую, нажмите на обновление и повторите запрос!");

           else MessageBox.Show(" Такая прошивка уже существует! Невозможно добавить!");

       }

   }

 

   private void DeleteLabel_Click(object sender, EventArgs e)

   {

       if(SelectionIsAvailable(0))

       {

           foreach(FirmWareStorage check in Storage)

           {

               if((this.FirmList.SelectedItem.ToString() == check.GetFirm) && (this.PhoneList.SelectedItem.ToString() == check.GetPhone) && (this.FirmWareList.SelectedItem.ToString() == check.GetFirmWare) && (this.VersionList.SelectedItem.ToString() == check.GetVersion))

               {

                   str = check;

                   break;

               }

           }

           if(RecoveryIsEnable == true)

           {

               Func<string, bool> Rec = RecycleFunc;

               BIN = RecoveryLastRemovedData(false, Rec, str.GetFirm, str.GetPhone, str.GetFirmWare, str.GetVersion, str.GetIsAvailable, str.GetProCreator, str.GetYearOfCreation);

           }

           this.str.DeleteItem(str);

           ResetProperties(true, true, true, true);

           CountValue -= 1;

       }

   }

 

   private void HideLabel_Click(object sender, EventArgs e)

   {

       if(HiddenStorage.Count == 0)

       {

           if (Storage.Count > 0)

           {

               int Count = 0;

               int CheckOne = 0;

               int CheckTwo = 1;

               while(CheckOne < CheckTwo)

               {

                   foreach (FirmWareStorage Current in Storage)

                   {

                       if (Current.GetIsAvailable == false)

                       {

                           str = Current;

                           this.str.HideItem(str, false);

                           Count += 1;

                           CheckTwo += 1;

                           break;

                       }

                   }

                   CheckOne += 1;

               }

               if (Count > 0)

               {

                   HideCompleted = true;

                   ResetProperties(true, true, true, true);

               }

           }

           else MessageBox.Show(" Невозможно выполнить действие, так как нет ни одной прошивки!");

       }

       else

       {

           int CheckOne = 0;

           int CheckTwo = 1;

           while (CheckOne < CheckTwo)

           {

               foreach (FirmWareStorage Value in HiddenStorage)

               {

                   str = Value;

                   this.str.HideItem(str, true);

                   CheckTwo += 1;

                   break;

                }

               CheckOne += 1;

           }

           HideCompleted = false;

           ResetProperties(true, true, true, true);

       }

   }

 

   private void UpdateLabel_Click(object sender, EventArgs e)

   {

       if (SelectionIsAvailable(0))

       {

           int ID;

           FirmWareStorage UpDate = new FirmWareStorage();

           foreach (FirmWareStorage check in Storage)

           {

               if ((this.FirmList.SelectedItem.ToString() == check.GetFirm) && (this.PhoneList.SelectedItem.ToString() == check.GetPhone) && (this.FirmWareList.SelectedItem.ToString() == check.GetFirmWare) && (this.VersionList.SelectedItem.ToString() == check.GetVersion))

               {

                   UpDate = check;

                   break;

               }

           }

           for(int i = 0; i < Storage.Count; i++)

           {

               if (Storage.ElementAt(i) == UpDate)

               {

                   ID = i;

                   break;

               }

           }

           Form1 Form1 = new Form1();

           Form1.label8.Text = "Обновить прошивку";

           Form1.textBoxFirm.Text = UpDate.GetFirm;

           Form1.textBoxFirm.ReadOnly = true;

           Form1.textBoxPhone.Text = UpDate.GetPhone;

           Form1.textBoxPhone.ReadOnly = true;

           Form1.textBoxFirmWare.Text = UpDate.GetFirmWare;

           Form1.textBoxVersion.Text = UpDate.GetVersion;

           Form1.checkBoxEnable.Checked = UpDate.GetIsAvailable;

           Form1.textBoxProCreator.Text = UpDate.GetProCreator;

           Form1.numericUpDownYearOfCreation.Value = Convert.ToInt32(UpDate.GetYearOfCreation);

           Storage.Remove(UpDate);

           string tmp3;

           string tmp4;

           bool tmp5;

           string tmp6;

           ushort tmp7;

           FirmWareStorage Clone = new FirmWareStorage();

           Clone.SetFirm(Form1.textBoxFirm.Text);

           Clone.SetPhone(Form1.textBoxPhone.Text);

           do

           {

               Form1.ShowDialog();

               tmp3 = Form1.textBoxFirmWare.Text;

               tmp4 = Form1.textBoxVersion.Text;

               tmp5 = Form1.checkBoxEnable.Checked;

               tmp6 = Form1.textBoxProCreator.Text;

               tmp7 = Convert.ToUInt16(Form1.numericUpDownYearOfCreation.Value);

               if (tmp3!= String.Empty)

                   Form1.textBoxFirmWare.Text = tmp3;

               if (tmp4!= String.Empty)

                   Form1.textBoxVersion.Text = tmp4;

               Form1.checkBoxEnable.Checked = tmp5;

               if (tmp6!= String.Empty)

                   Form1.textBoxProCreator.Text = tmp6;

               Form1.numericUpDownYearOfCreation.Value = Convert.ToDecimal(tmp7);

               Clone.SetFirmWare(tmp3);

               Clone.SetVersion(tmp4);

               Clone.SetIsAvailable(tmp5);

               Clone.SetProCreator(tmp6);

               Clone.SetYearOfCreation(tmp7);

           } while (!DataIsValid(Clone));

           this.str.UpdateItem(Clone);

           ResetProperties(true, true, true, true);

       }

   }

 

   private void RecoverLabel_Click(object sender, EventArgs e)

   {

       if (RecoveryIsEnableVal == true)

       {

           string Recycle = "";

           if (BIN!= "")

           {

               Func<string, bool> RecycleF = RecycleFunc;

               Recycle = RecoveryLastRemovedData(true, RecycleF);

               BIN = "";

               FirmWareStorage Rec = new FirmWareStorage();

               string[] Recovery = Recycle.Split('|');

               Rec.SetFirm(Recovery[0]);

               Rec.SetPhone(Recovery[1]);

               Rec.SetFirmWare(Recovery[2]);

               Rec.SetVersion(Recovery[3]);

               Rec.SetIsAvailable(Convert.ToBoolean(Recovery[4]));

               Rec.SetProCreator(Recovery[5]);

               Rec.SetYearOfCreation(Convert.ToUInt16(Recovery[6]));

               Storage.Add(Rec);

               ResetProperties(true, true, true, true);

           }

           else MessageBox.Show(" Корзина пуста!");

       }

       else

       {

           MessageBox.Show(" Ошибка! Корзина недоступна! Разрешите использование корзины перед запуском!");

       }

   }

 

   private void labelInfo_Click(object sender, EventArgs e)

   {

      if (SelectionIsAvailable(0))

       {

           Form1 Form = new Form1();

           foreach (FirmWareStorage check in Storage)

           {

               if ((this.FirmList.SelectedItem.ToString() == check.GetFirm) && (this.PhoneList.SelectedItem.ToString() == check.GetPhone) && (this.FirmWareList.SelectedItem.ToString() == check.GetFirmWare) && (this.VersionList.SelectedItem.ToString() == check.GetVersion))

               {

                   Form.textBoxFirm.Text = check.GetFirm;

                   Form.textBoxPhone.Text = check.GetPhone;

                   Form.textBoxFirmWare.Text = check.GetFirmWare;

                   Form.textBoxVersion.Text = check.GetVersion;

                   Form.checkBoxEnable.Checked = check.GetIsAvailable;

                   Form.textBoxProCreator.Text = check.GetProCreator;

                   Form.numericUpDownYearOfCreation.Value = check.GetYearOfCreation;

                   Form.label8.Text = "Информация о прошивке";

                   Form.labelConfirm.Text = "Закрыть";

                   Form.textBoxFirm.ReadOnly = true;

                   Form.textBoxPhone.ReadOnly = true;

                   Form.textBoxFirmWare.ReadOnly = true;

                   Form.textBoxVersion.ReadOnly = true;

                   Form.checkBoxEnable.Enabled = false;

                   Form.textBoxProCreator.ReadOnly = true;

                   Form.numericUpDownYearOfCreation.ReadOnly = true;

                   Form.ShowDialog();

                   break;

               }

           }

       }

   }

 

   private void labelConfirm_Click(object sender, EventArgs e)

   {

       if(maskedTextBox1.Text!= "")

           if (Convert.ToInt32(maskedTextBox1.Text) == 11111111)

           {

               this.AddLabel.Enabled = true;

               this.DeleteLabel.Enabled = true;

               if (AllowUpdates == true)

                    this.UpdateLabel.Enabled = true;

               if (HideIsAvailable == true)

                   this.HideLabel.Enabled = true;

               this.maskedTextBox1.Visible = false;

               this.labelConfirm.Visible = false;

               this.label5.Visible = false;

               this.panel2.Visible = false;

               MessageBox.Show(" Были предоставлены расширенные возможности!");

           }

           else

           {

               maskedTextBox1.Text = "";

               MessageBox.Show(" Неверный пароль!");

           }

   }

   #endregion

 

   #region Storage

   public class FirmWareStorage: EventArgs

   {

          private string Firm; // Название фирмы телефона

       private string Phone; // Модель телефона

       private string FirmWare; // Название прошивки

       private string Version; // Версия прошивки

       private bool IsAvailable; // Доступна ли прошивка на данный момент

       private string ProCreator; // Создатель прошивки

       private ushort YearOfCreation = 0; // Год выпуска прошивки

           

 

       #region SetAndGetMethods

       public void SetFirm(string f)

       {

           this.Firm = f;

       }

       public string GetFirm

       {

           get

           {

               return this.Firm;

           }

       }

       public void SetPhone(string p)

       {

           this.Phone = p;

       }

       public string GetPhone

       {

           get

           {

               return this.Phone;

           }

       }

       public void SetFirmWare(string fw)

       {

           this.FirmWare = fw;

       }

       public string GetFirmWare

       {

           get

           {

               return this.FirmWare;

           }

       }

       public void SetVersion(string v)

       {

           this.Version = v;

       }

       public string GetVersion

       {

           get

           {

               return this.Version;

           }

       }

       public void SetIsAvailable(bool ia)

       {

           this.IsAvailable = ia;

       }

       public bool GetIsAvailable

       {

           get

           {

               return this.IsAvailable;

           }

       }

       public void SetProCreator(string pc)

       {

           this.ProCreator = pc;

       }

       public string GetProCreator

       {

           get

           {

               return this.ProCreator;

           }

       }

       public void SetYearOfCreation(ushort yc)

       {

           if (yc <= (ushort)DateTime.Now.Year || yc >= 1950)

               this.YearOfCreation = yc;

           else this.YearOfCreation = (ushort)DateTime.Now.Year;

       }

       public ushort GetYearOfCreation

       {

           get

           {

               return this.YearOfCreation;

              }

       }

       #endregion

 

       #region EventsCode

       public void AddNewItem(FirmWareStorage str)

       {

           Storage.Add(str);

       }

 

       public void DeleteItem(FirmWareStorage str)

       {

           Storage.Remove(str);

       }

 

       public void UpdateItem(FirmWareStorage update)

       {

           Storage.Add(update);

       }

       public void HideItem(FirmWareStorage hide, bool hidden)

       {

           if (hidden == false)

           {

               HiddenStorage.Add(hide);

               Storage.Remove(hide);

           }

           else

           {

               Storage.Add(hide);

               HiddenStorage.Remove(hide);

           }

       }

       #endregion

   }

   #endregion

}// UserControl

}

 

Добавить прошивку.cs

 

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

using System.Windows.Forms;

 

namespace WindowsFormsControlLibrary1

{

public partial class Form1: Form

{

   public bool State = false;

   public Form1()

   {

       InitializeComponent();

       textBoxFirm.Text = String.Empty;

       textBoxPhone.Text = "";

       textBoxFirmWare.Text = "";

       textBoxVersion.Text = "";

      checkBoxEnable.Checked = false;

       textBoxProCreator.Text = "";

       numericUpDownYearOfCreation.Value = 0;

   }

 

   private void Form1_Load(object sender, EventArgs e)

   {

       this.Height = 400;

       this.Width = 320;

       this.panel1.Location = new Point(0, 0);

   }

 

   public void labelConfirm_Click(object sender, EventArgs e)

   {

       Close();

   }

 

   private void panel1_Paint(object sender, PaintEventArgs e)

   {

 

   }

 

   private void textBoxFirm_TextChanged(object sender, EventArgs e)

   {

       string s = textBoxFirm.Text;

       int n = s.Length;

       string s1 = "";

       if (n > 1)

           s1 = s.Substring(n - 1, 1);

       else if (n == 1)

           s1 = s.Substring(0, 1);

       else return;

       if (s1 == "|")

       {

           textBoxFirm.Text = s.Substring(0, s.IndexOf('|'));

           MessageBox.Show(" Символ < | > запрещён!");

       }

   }

 

   private void textBoxPhone_TextChanged(object sender, EventArgs e)

   {

       string s = textBoxPhone.Text;

       int n = s.Length;

       string s1 = "";

       if (n > 1)

           s1 = s.Substring(n - 1, 1);

       else if (n == 1)

           s1 = s.Substring(0, 1);

       else return;

       if (s1 == "|")

       {

           textBoxPhone.Text = s.Substring(0, s.IndexOf('|'));

           MessageBox.Show(" Символ < | > запрещён!");

       }

   }

 

   private void textBoxFirmWare_TextChanged(object sender, EventArgs e)

   {

       string s = textBoxFirmWare.Text;

       int n = s.Length;

       string s1 = "";

       if (n > 1)

           s1 = s.Substring(n - 1, 1);

       else if (n == 1)

           s1 = s.Substring(0, 1);

       else return;

       if (s1 == "|")

       {

           textBoxFirmWare.Text = s.Substring(0, s.IndexOf('|'));

           MessageBox.Show(" Символ < | > запрещён!");

       }

   }

 

   private void textBoxVersion_TextChanged(object sender, EventArgs e)

   {

       string s = textBoxVersion.Text;

       int n = s.Length;

       string s1 = "";

       if (n > 1)

           s1 = s.Substring(n - 1, 1);

       else if (n == 1)

           s1 = s.Substring(0, 1);

       else return;

       if (s1 == "|")

       {

           textBoxVersion.Text = s.Substring(0, s.IndexOf('|'));

           MessageBox.Show(" Символ < | > запрещён!");

       }

   }

 

   private void textBoxProCreator_TextChanged(object sender, EventArgs e)

   {

       string s = textBoxProCreator.Text;

       int n = s.Length;

       string s1 = "";

       if (n > 1)

           s1 = s.Substring(n - 1, 1);

       else if (n == 1)

           s1 = s.Substring(0, 1);

       else return;

       if (s1 == "|")

       {

           textBoxProCreator.Text = s.Substring(0, s.IndexOf('|'));

           MessageBox.Show(" Символ < | > запрещён!");

       }

   }

}

}

 




double arrow
Сейчас читают про: