ÌÈÍÈÑÒÅÐÑÒÂÎ ÍÀÓÊÈ È ÂÛÑØÅÃÎ ÎÁÐÀÇÎÂÀÍÈß ÐÎÑÑÈÉÑÊÎÉ ÔÅÄÅÐÀÖÈÈ
ôåäåðàëüíîå ãîñóäàðñòâåííîå áþäæåòíîå îáðàçîâàòåëüíîå ó÷ðåæäåíèå
âûñøåãî îáðàçîâàíèÿ
«ÓËÜßÍÎÂÑÊÈÉ ÃÎÑÓÄÀÐÑÒÂÅÍÍÛÉ ÒÅÕÍÈ×ÅÑÊÈÉ ÓÍÈÂÅÐÑÈÒÅÒ»
Êàôåäðà «Èçìåðèòåëüíî-âû÷èñëèòåëüíûå êîìïëåêñû»
Ýëåìåíò óïðàâëåíèÿ «Ïîìîùíèê â âûáîðå ïðîøèâêè äëÿ òåëåôîíà»
Îò÷åò ïî êóðñîâîé ðàáîòå
2020
Ââåäåíèå
Íàçâàíèå ýëåìåíòà óïðàâëåíèÿ: «FirmWareInstallation», óñëîâíîå îáîçíà÷åíèå: «Ïîìîùíèê â âûáîðå ïðîøèâêè». «FirmWareInstallation» ñîñòîèò èç ñëåäóþùèõ ñòàíäàðòíûõ ýëåìåíòîâ:
Label, ListBox, Textbox, MaskedTextBox, Panel, numericUpDown, CheckBox.
Ñîçäàííûé ýëåìåíò óïðàâëåíèÿ ñîäåðæèò ñëåäóþùèé íàáîð áàçîâûé ôóíêöèé:
· Äîáàâëåíèå íîâîé ïðîøèâêè â ñïèñîê òåêóùèõ ïðîøèâîê (ïðè íàëè÷èè äîñòóïà).
· Óäàëåíèå ïðîøèâêè èç ñïèñêà òåêóùèõ ïðîøèâîê (ïðè íàëè÷èè äîñòóïà).
· Îáíîâëåíèå ïðîøèâêè (ïðè íàëè÷èè äîñòóïà).
· Ïðîñìîòð ïðîøèâîê.
· Âîññòàíîâëåíèå ïîñëåäíåé óäàë¸ííîé ïðîøèâêè.
· Âîçìîæíîñòü ñïðÿòàòü íåäîñòóïíûå ïðîøèâêè.
· Ïðè âûáîðå òåëåôîíà îòîáðàæàåòñÿ êîëè÷åñòâî äîñòóïíûõ íà íåãî ïðîøèâîê.
Ðåàëèçàöèÿ
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
bool UniqueCheck(List
string
RecoveryLastRemovedData(bool RecoveryState, Func
}
#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
static
List
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
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 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
{
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
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
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
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
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
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
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(" Ñèìâîë < | > çàïðåù¸í!");
}
}
}
}
Ðåçóëüòàò
Ïðèìåð ðàáîòû ýëåìåíòà óïðàâëåíèÿ:
Ïðè íàæàòèè íà Label “Ïîäðîáíî î âûáðàííîé ïðîøèâêå”:
Ïðè íàæàòèè íà Label “Äîáàâèòü ïðîøèâêó”:
Ïðè íàæàòèè íà Label “Óäàëèòü ïðîøèâêó”:
Ïðè íàæàòèè íà Label “Îáíîâèòü ïðîøèâêó”: