From f19d11d82ac5d052e725aaeb71ab91ef99e0e854 Mon Sep 17 00:00:00 2001 From: Teslime Date: Tue, 30 Nov 2021 11:49:54 +0300 Subject: [PATCH 01/20] Bugs from the name change have been fixed. --- DataAcces.cs | 40 +++++------ DirectorySearching.Designer.cs | 22 +++--- NewNumberRegister.Designer.cs | 22 +++--- NewNumberRegister.cs | 15 ++-- NumberUpdate.Designer.cs | 126 +++++++++++---------------------- NumberUpdate.cs | 11 +-- Person.cs | 3 +- models/PersonDTO.cs | 3 +- 8 files changed, 95 insertions(+), 147 deletions(-) diff --git a/DataAcces.cs b/DataAcces.cs index e0288e7..4e2996b 100644 --- a/DataAcces.cs +++ b/DataAcces.cs @@ -8,16 +8,13 @@ using System.Data.SqlClient; using System.Threading.Tasks; using Phonebook.models; -// "Insert into Room(ID, roomNo, checkIn, IsDelete) values ( @ID, @roomNo, GETDATE(), 'False')"; -// string queryIsDelete = "select roomNo from Room where IsDelete= 'False'"; - -// string deleteQuery = "update Room set IsDelete='True', checkOut=GETDATE() where roomNo = @_roomNo"; + namespace Phonebook { public class DataAcces : IDataAcces { - private string connectionString = "Data Source=LAPTOP-VBIOM4D2;Initial Catalog = Phonebook; Integrated Security = True"; + private readonly string connectionString = "Data Source=LAPTOP-VBIOM4D2;Initial Catalog = Phonebook; Integrated Security = True"; private bool _resultSeach; @@ -27,20 +24,18 @@ public bool Search(PersonDTO directoryDTO) { connectionSearch.Open(); - string Search = "select Name, Lastname, Number from Person where Name = @name and Lastname = @lastname"; + string Search = "select NameSurname from Person where NameSurname Like '%'+ @NameSurname +'%'"; SqlCommand SearchCommand = new SqlCommand(Search,connectionSearch); - SearchCommand.Parameters.Add(new System.Data.SqlClient.SqlParameter("@name", SqlDbType.NChar, 15) { Value = directoryDTO.Name }); - SearchCommand.Parameters.Add(new System.Data.SqlClient.SqlParameter("@lastname", SqlDbType.NChar, 15) { Value = directoryDTO.Lastname }); - + + SearchCommand.Parameters.Add(new System.Data.SqlClient.SqlParameter("@NameSurname", SqlDbType.NChar, 15) { Value = directoryDTO.NameSurname }); SqlDataReader sqlDataReader = SearchCommand.ExecuteReader(); while (sqlDataReader.Read()) { - directoryDTO.Name = sqlDataReader["Name"].ToString(); - directoryDTO.Lastname = sqlDataReader["Lastname"].ToString(); - long.TryParse(sqlDataReader["Number"].ToString(), out long Number); - directoryDTO.Number = Number; + + directoryDTO.NameSurname = sqlDataReader["NameSurname"].ToString(); + directoryDTO.Number = sqlDataReader["Number"].ToString(); _resultSeach = true; } @@ -55,25 +50,25 @@ public void Delete(PersonDTO directoryDTO) using(var connectionDelete = new SqlConnection(connectionString)) { connectionDelete.Open(); - string Delete = "Delete from Person where Name = @name and Lastname = @lastname"; + string Delete = "Delete from Person where NameSurname = @NameSurname"; SqlCommand DeleteCommand = new SqlCommand(Delete, connectionDelete); - DeleteCommand.Parameters.Add(new System.Data.SqlClient.SqlParameter("@name", SqlDbType.NChar, 15) { Value = directoryDTO.Name }); - DeleteCommand.Parameters.Add(new System.Data.SqlClient.SqlParameter("@lastname", SqlDbType.NChar, 15) { Value = directoryDTO.Lastname }); + DeleteCommand.Parameters.Add(new System.Data.SqlClient.SqlParameter("@NameSurname", SqlDbType.NChar, 15) { Value = directoryDTO.NameSurname }); + DeleteCommand.ExecuteNonQuery(); connectionDelete.Close(); } - } + } public void RegisterDatabase(PersonDTO directoryDTO) { using (var connectionRegister = new SqlConnection(connectionString)) { connectionRegister.Open(); - string registerPerson = "Insert into Person(Name, Lastname, Number) values(@name, @lastname, @number)"; + string registerPerson = "Insert into Person(NameSurname, Number) values(@NameSurname, @Number)"; SqlCommand sqlCommand = new SqlCommand(registerPerson, connectionRegister); - sqlCommand.Parameters.Add(new System.Data.SqlClient.SqlParameter("@name", SqlDbType.NChar, 15) { Value = directoryDTO.Name }); - sqlCommand.Parameters.Add(new System.Data.SqlClient.SqlParameter("@lastname", SqlDbType.NChar, 15) { Value = directoryDTO.Lastname }); - sqlCommand.Parameters.Add(new System.Data.SqlClient.SqlParameter("@number", SqlDbType.VarChar, 11) { Value = directoryDTO.Number }); + + sqlCommand.Parameters.Add(new System.Data.SqlClient.SqlParameter("@NameSurname", SqlDbType.NChar, 15) { Value = directoryDTO.NameSurname }); + sqlCommand.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Number", SqlDbType.VarChar, 11) { Value = directoryDTO.Number }); sqlCommand.ExecuteNonQuery(); connectionRegister.Close(); } @@ -84,7 +79,8 @@ public void Update(PersonDTO directoryDTO) using(var ConnectionUpdate = new SqlConnection(connectionString)) { ConnectionUpdate.Open(); - string Update = "Update Person SET Name = , Lastname = where Name = @name and Lastname = @lastname "; + string Update = "Update Person SET NameSurname = @NameSurname , Number = @Number where PersonId = @PersonId "; + ConnectionUpdate.Close(); } } diff --git a/DirectorySearching.Designer.cs b/DirectorySearching.Designer.cs index f4d61dd..c2f97f1 100644 --- a/DirectorySearching.Designer.cs +++ b/DirectorySearching.Designer.cs @@ -30,7 +30,7 @@ protected override void Dispose(bool disposing) private void InitializeComponent() { this.label1 = new System.Windows.Forms.Label(); - this.txtName = new System.Windows.Forms.TextBox(); + this.txtNameSurname = new System.Windows.Forms.TextBox(); this.label2 = new System.Windows.Forms.Label(); this.btnSearch = new System.Windows.Forms.Button(); this.SuspendLayout(); @@ -45,13 +45,13 @@ private void InitializeComponent() this.label1.TabIndex = 0; this.label1.Text = "Please enter the name or surname of the person whose number\r\nyou want to delete:"; // - // txtName + // txtNameSurname // - this.txtName.Font = new System.Drawing.Font("Microsoft Sans Serif", 14.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(162))); - this.txtName.Location = new System.Drawing.Point(250, 166); - this.txtName.Name = "txtName"; - this.txtName.Size = new System.Drawing.Size(198, 29); - this.txtName.TabIndex = 6; + this.txtNameSurname.Font = new System.Drawing.Font("Microsoft Sans Serif", 14.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(162))); + this.txtNameSurname.Location = new System.Drawing.Point(250, 166); + this.txtNameSurname.Name = "txtNameSurname"; + this.txtNameSurname.Size = new System.Drawing.Size(198, 29); + this.txtNameSurname.TabIndex = 6; // // label2 // @@ -59,9 +59,9 @@ private void InitializeComponent() this.label2.Font = new System.Drawing.Font("Microsoft Sans Serif", 11.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(162))); this.label2.Location = new System.Drawing.Point(100, 166); this.label2.Name = "label2"; - this.label2.Size = new System.Drawing.Size(124, 18); + this.label2.Size = new System.Drawing.Size(116, 18); this.label2.TabIndex = 5; - this.label2.Text = "Name / Surname:"; + this.label2.Text = "Name Surname:"; // // btnSearch // @@ -79,7 +79,7 @@ private void InitializeComponent() this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(800, 450); this.Controls.Add(this.btnSearch); - this.Controls.Add(this.txtName); + this.Controls.Add(this.txtNameSurname); this.Controls.Add(this.label2); this.Controls.Add(this.label1); this.Name = "DirectorySearching"; @@ -92,7 +92,7 @@ private void InitializeComponent() #endregion private System.Windows.Forms.Label label1; - private System.Windows.Forms.TextBox txtName; + private System.Windows.Forms.TextBox txtNameSurname; private System.Windows.Forms.Label label2; private System.Windows.Forms.Button btnSearch; } diff --git a/NewNumberRegister.Designer.cs b/NewNumberRegister.Designer.cs index 82d09d9..9a186b6 100644 --- a/NewNumberRegister.Designer.cs +++ b/NewNumberRegister.Designer.cs @@ -33,7 +33,7 @@ private void InitializeComponent() this.label2 = new System.Windows.Forms.Label(); this.label3 = new System.Windows.Forms.Label(); this.btnRegister = new System.Windows.Forms.Button(); - this.txtName = new System.Windows.Forms.TextBox(); + this.txtNameSurname = new System.Windows.Forms.TextBox(); this.txtNumber = new System.Windows.Forms.TextBox(); this.label4 = new System.Windows.Forms.Label(); this.SuspendLayout(); @@ -44,9 +44,9 @@ private void InitializeComponent() this.label1.Font = new System.Drawing.Font("Microsoft Sans Serif", 11.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(162))); this.label1.Location = new System.Drawing.Point(89, 143); this.label1.Name = "label1"; - this.label1.Size = new System.Drawing.Size(124, 18); + this.label1.Size = new System.Drawing.Size(120, 18); this.label1.TabIndex = 0; - this.label1.Text = "Name / Surname:"; + this.label1.Text = "Name Surname:"; // // label2 // @@ -78,13 +78,13 @@ private void InitializeComponent() this.btnRegister.UseVisualStyleBackColor = true; this.btnRegister.Click += new System.EventHandler(this.btnRegister_Click); // - // txtName + // txtNameSurname // - this.txtName.Font = new System.Drawing.Font("Microsoft Sans Serif", 14.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(162))); - this.txtName.Location = new System.Drawing.Point(239, 143); - this.txtName.Name = "txtName"; - this.txtName.Size = new System.Drawing.Size(198, 29); - this.txtName.TabIndex = 4; + this.txtNameSurname.Font = new System.Drawing.Font("Microsoft Sans Serif", 14.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(162))); + this.txtNameSurname.Location = new System.Drawing.Point(239, 143); + this.txtNameSurname.Name = "txtNameSurname"; + this.txtNameSurname.Size = new System.Drawing.Size(198, 29); + this.txtNameSurname.TabIndex = 4; // // txtNumber // @@ -111,7 +111,7 @@ private void InitializeComponent() this.ClientSize = new System.Drawing.Size(800, 450); this.Controls.Add(this.label4); this.Controls.Add(this.txtNumber); - this.Controls.Add(this.txtName); + this.Controls.Add(this.txtNameSurname); this.Controls.Add(this.btnRegister); this.Controls.Add(this.label3); this.Controls.Add(this.label2); @@ -129,7 +129,7 @@ private void InitializeComponent() private System.Windows.Forms.Label label2; private System.Windows.Forms.Label label3; private System.Windows.Forms.Button btnRegister; - private System.Windows.Forms.TextBox txtName; + private System.Windows.Forms.TextBox txtNameSurname; private System.Windows.Forms.TextBox txtNumber; private System.Windows.Forms.Label label4; } diff --git a/NewNumberRegister.cs b/NewNumberRegister.cs index 710c874..289008a 100644 --- a/NewNumberRegister.cs +++ b/NewNumberRegister.cs @@ -21,19 +21,14 @@ public NewNumberRegister(IDataAcces dataAcces) InitializeComponent(); this.dataAcces = dataAcces; } - - - //public NewNumberRegister(IDataAcces dataAcces) - //{ - // this.dataAcces = dataAcces; - //} + + Person directory = new Person(); public void MapperDirectory() { - directory.Name = txtName.Text; - directory.Lastname = txtSurname.Text; - long.TryParse(txtNumber.Text, out long number); - directory.Number = number; + + directory.NameSurname = txtNameSurname.Text; + directory.Number = txtNumber.Text; var config = new MapperConfiguration(cfg => cfg.CreateMap()); var mapper= new Mapper(config); diff --git a/NumberUpdate.Designer.cs b/NumberUpdate.Designer.cs index c7b0248..14d985d 100644 --- a/NumberUpdate.Designer.cs +++ b/NumberUpdate.Designer.cs @@ -31,31 +31,25 @@ private void InitializeComponent() { this.pnlUpdate = new System.Windows.Forms.Panel(); this.pnlNumber = new System.Windows.Forms.TextBox(); - this.pnlLastname = new System.Windows.Forms.TextBox(); - this.pnlName = new System.Windows.Forms.TextBox(); this.label4 = new System.Windows.Forms.Label(); - this.label5 = new System.Windows.Forms.Label(); - this.label6 = new System.Windows.Forms.Label(); this.btnUpdate = new System.Windows.Forms.Button(); this.btnCancel = new System.Windows.Forms.Button(); this.lblSureQuery = new System.Windows.Forms.Label(); this.btnSearch = new System.Windows.Forms.Button(); this.label3 = new System.Windows.Forms.Label(); - this.label2 = new System.Windows.Forms.Label(); - this.txtLastname = new System.Windows.Forms.TextBox(); - this.txtName = new System.Windows.Forms.TextBox(); + this.txtNameSurname = new System.Windows.Forms.TextBox(); this.label1 = new System.Windows.Forms.Label(); + this.label2 = new System.Windows.Forms.Label(); + this.pnlNameSurname = new System.Windows.Forms.TextBox(); this.pnlUpdate.SuspendLayout(); this.SuspendLayout(); // // pnlUpdate // + this.pnlUpdate.Controls.Add(this.label2); + this.pnlUpdate.Controls.Add(this.pnlNameSurname); this.pnlUpdate.Controls.Add(this.pnlNumber); - this.pnlUpdate.Controls.Add(this.pnlLastname); - this.pnlUpdate.Controls.Add(this.pnlName); this.pnlUpdate.Controls.Add(this.label4); - this.pnlUpdate.Controls.Add(this.label5); - this.pnlUpdate.Controls.Add(this.label6); this.pnlUpdate.Controls.Add(this.btnUpdate); this.pnlUpdate.Controls.Add(this.btnCancel); this.pnlUpdate.Controls.Add(this.lblSureQuery); @@ -67,59 +61,25 @@ private void InitializeComponent() // // pnlNumber // - this.pnlNumber.Location = new System.Drawing.Point(165, 181); + this.pnlNumber.Location = new System.Drawing.Point(237, 133); this.pnlNumber.Name = "pnlNumber"; - this.pnlNumber.Size = new System.Drawing.Size(198, 20); + this.pnlNumber.Size = new System.Drawing.Size(161, 20); this.pnlNumber.TabIndex = 12; // - // pnlLastname - // - this.pnlLastname.Location = new System.Drawing.Point(165, 132); - this.pnlLastname.Name = "pnlLastname"; - this.pnlLastname.Size = new System.Drawing.Size(198, 20); - this.pnlLastname.TabIndex = 11; - // - // pnlName - // - this.pnlName.Location = new System.Drawing.Point(165, 82); - this.pnlName.Name = "pnlName"; - this.pnlName.Size = new System.Drawing.Size(198, 20); - this.pnlName.TabIndex = 10; - // // label4 // this.label4.AutoSize = true; this.label4.Font = new System.Drawing.Font("Microsoft Sans Serif", 11.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(162))); - this.label4.Location = new System.Drawing.Point(72, 180); + this.label4.Location = new System.Drawing.Point(72, 133); this.label4.Name = "label4"; this.label4.Size = new System.Drawing.Size(69, 18); this.label4.TabIndex = 9; this.label4.Text = "Number :"; // - // label5 - // - this.label5.AutoSize = true; - this.label5.Font = new System.Drawing.Font("Microsoft Sans Serif", 11.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(162))); - this.label5.Location = new System.Drawing.Point(72, 134); - this.label5.Name = "label5"; - this.label5.Size = new System.Drawing.Size(81, 18); - this.label5.TabIndex = 8; - this.label5.Text = "Lastname :"; - // - // label6 - // - this.label6.AutoSize = true; - this.label6.Font = new System.Drawing.Font("Microsoft Sans Serif", 11.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(162))); - this.label6.Location = new System.Drawing.Point(72, 81); - this.label6.Name = "label6"; - this.label6.Size = new System.Drawing.Size(56, 18); - this.label6.TabIndex = 7; - this.label6.Text = "Name :"; - // // btnUpdate // this.btnUpdate.Font = new System.Drawing.Font("Microsoft Sans Serif", 11.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(162))); - this.btnUpdate.Location = new System.Drawing.Point(75, 229); + this.btnUpdate.Location = new System.Drawing.Point(38, 194); this.btnUpdate.Name = "btnUpdate"; this.btnUpdate.Size = new System.Drawing.Size(143, 32); this.btnUpdate.TabIndex = 5; @@ -130,7 +90,7 @@ private void InitializeComponent() // btnCancel // this.btnCancel.Font = new System.Drawing.Font("Microsoft Sans Serif", 11.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(162))); - this.btnCancel.Location = new System.Drawing.Point(442, 229); + this.btnCancel.Location = new System.Drawing.Point(405, 194); this.btnCancel.Name = "btnCancel"; this.btnCancel.Size = new System.Drawing.Size(143, 32); this.btnCancel.TabIndex = 4; @@ -151,7 +111,7 @@ private void InitializeComponent() // btnSearch // this.btnSearch.Font = new System.Drawing.Font("Microsoft Sans Serif", 11.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(162))); - this.btnSearch.Location = new System.Drawing.Point(572, 99); + this.btnSearch.Location = new System.Drawing.Point(466, 92); this.btnSearch.Name = "btnSearch"; this.btnSearch.Size = new System.Drawing.Size(125, 33); this.btnSearch.TabIndex = 13; @@ -163,35 +123,18 @@ private void InitializeComponent() // this.label3.AutoSize = true; this.label3.Font = new System.Drawing.Font("Microsoft Sans Serif", 11.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(162))); - this.label3.Location = new System.Drawing.Point(339, 109); + this.label3.Location = new System.Drawing.Point(115, 99); this.label3.Name = "label3"; - this.label3.Size = new System.Drawing.Size(77, 18); + this.label3.Size = new System.Drawing.Size(120, 18); this.label3.TabIndex = 12; - this.label3.Text = "Lastname:"; - // - // label2 - // - this.label2.AutoSize = true; - this.label2.Font = new System.Drawing.Font("Microsoft Sans Serif", 11.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(162))); - this.label2.Location = new System.Drawing.Point(135, 107); - this.label2.Name = "label2"; - this.label2.Size = new System.Drawing.Size(56, 18); - this.label2.TabIndex = 11; - this.label2.Text = "Name: "; - // - // txtLastname - // - this.txtLastname.Location = new System.Drawing.Point(437, 107); - this.txtLastname.Name = "txtLastname"; - this.txtLastname.Size = new System.Drawing.Size(100, 20); - this.txtLastname.TabIndex = 10; + this.label3.Text = "Name Surname:"; // - // txtName + // txtNameSurname // - this.txtName.Location = new System.Drawing.Point(197, 107); - this.txtName.Name = "txtName"; - this.txtName.Size = new System.Drawing.Size(100, 20); - this.txtName.TabIndex = 9; + this.txtNameSurname.Location = new System.Drawing.Point(280, 102); + this.txtNameSurname.Name = "txtNameSurname"; + this.txtNameSurname.Size = new System.Drawing.Size(136, 20); + this.txtNameSurname.TabIndex = 10; // // label1 // @@ -203,6 +146,23 @@ private void InitializeComponent() this.label1.TabIndex = 8; this.label1.Text = "Please enter the name or surname of the person whose number you want to update:"; // + // label2 + // + this.label2.AutoSize = true; + this.label2.Font = new System.Drawing.Font("Microsoft Sans Serif", 11.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(162))); + this.label2.Location = new System.Drawing.Point(72, 85); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(120, 18); + this.label2.TabIndex = 14; + this.label2.Text = "Name Surname:"; + // + // pnlNameSurname + // + this.pnlNameSurname.Location = new System.Drawing.Point(237, 88); + this.pnlNameSurname.Name = "pnlNameSurname"; + this.pnlNameSurname.Size = new System.Drawing.Size(161, 20); + this.pnlNameSurname.TabIndex = 13; + // // NumberUpdate // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); @@ -211,9 +171,7 @@ private void InitializeComponent() this.Controls.Add(this.pnlUpdate); this.Controls.Add(this.btnSearch); this.Controls.Add(this.label3); - this.Controls.Add(this.label2); - this.Controls.Add(this.txtLastname); - this.Controls.Add(this.txtName); + this.Controls.Add(this.txtNameSurname); this.Controls.Add(this.label1); this.Name = "NumberUpdate"; this.Text = "NumberUpdate"; @@ -232,15 +190,11 @@ private void InitializeComponent() private System.Windows.Forms.Label lblSureQuery; private System.Windows.Forms.Button btnSearch; private System.Windows.Forms.Label label3; - private System.Windows.Forms.Label label2; - private System.Windows.Forms.TextBox txtLastname; - private System.Windows.Forms.TextBox txtName; + private System.Windows.Forms.TextBox txtNameSurname; private System.Windows.Forms.Label label1; private System.Windows.Forms.TextBox pnlNumber; - private System.Windows.Forms.TextBox pnlLastname; - private System.Windows.Forms.TextBox pnlName; private System.Windows.Forms.Label label4; - private System.Windows.Forms.Label label5; - private System.Windows.Forms.Label label6; + private System.Windows.Forms.Label label2; + private System.Windows.Forms.TextBox pnlNameSurname; } } \ No newline at end of file diff --git a/NumberUpdate.cs b/NumberUpdate.cs index 8dedd41..d762dd6 100644 --- a/NumberUpdate.cs +++ b/NumberUpdate.cs @@ -26,8 +26,8 @@ public NumberUpdate(IDataAcces dataAcces) PersonDTO directoryDTO; private void MapperDto() { - SearchDto.Name = txtName.Text; - SearchDto.Lastname = txtLastname.Text; + SearchDto.NameSurname = txtNameSurname.Text; + var config = new MapperConfiguration(cfg => cfg.CreateMap()); var mapper = new Mapper(config); directoryDTO = mapper.Map(SearchDto); @@ -39,13 +39,12 @@ private void ResultForm(bool _resultSearch) if (_resultSearch == true) { pnlUpdate.Visible = true; - pnlName.Text = directoryDTO.Name; - pnlLastname.Text = directoryDTO.Lastname; + pnlNameSurname.Text = directoryDTO.NameSurname; pnlNumber.Text = directoryDTO.Number.ToString(); } else { - MessageBox.Show("No record found named " + txtName.Text + " " + txtLastname.Text + ". Please try again"); + MessageBox.Show("No record found named " + txtNameSurname.Text + ". Please try again"); } } private void btnSearch_Click(object sender, EventArgs e) @@ -64,5 +63,7 @@ private void btnCancel_Click(object sender, EventArgs e) { MessageBox.Show("No action was taken."); } + + } } diff --git a/Person.cs b/Person.cs index c12746b..e948d68 100644 --- a/Person.cs +++ b/Person.cs @@ -8,8 +8,9 @@ namespace Phonebook { public class Person { + public int PersonId { get; set; } public string NameSurname { get; set; } - public long Number { get; set; } + public string Number { get; set; } } } diff --git a/models/PersonDTO.cs b/models/PersonDTO.cs index 144bb2e..9a42e03 100644 --- a/models/PersonDTO.cs +++ b/models/PersonDTO.cs @@ -8,7 +8,8 @@ namespace Phonebook.models { public class PersonDTO { + public int PersonId { get; set; } public string NameSurname { get; set; } - public long Number { get; set; } + public string Number { get; set; } } } From 48888c98cb33cd7345b91a0f9ce43ca47faf9fc4 Mon Sep 17 00:00:00 2001 From: Teslime Date: Wed, 8 Dec 2021 22:37:09 +0300 Subject: [PATCH 02/20] The feature of getting the PersonId of the person called has been added to the feature of SearchPerson. --- App.config | 6 ++++++ DataAcces.cs | 30 ++++++++++++++++++------------ IDataAcces.cs | 2 +- NumberDelete.Designer.cs | 4 ++-- Properties/Settings.Designer.cs | 31 +++++++++++++++++++------------ Properties/Settings.settings | 19 +++++++++++++------ 6 files changed, 59 insertions(+), 33 deletions(-) diff --git a/App.config b/App.config index 56efbc7..e61bec6 100644 --- a/App.config +++ b/App.config @@ -1,5 +1,11 @@  + + + + + diff --git a/DataAcces.cs b/DataAcces.cs index 4e2996b..af7c6a6 100644 --- a/DataAcces.cs +++ b/DataAcces.cs @@ -14,33 +14,39 @@ namespace Phonebook { public class DataAcces : IDataAcces { - private readonly string connectionString = "Data Source=LAPTOP-VBIOM4D2;Initial Catalog = Phonebook; Integrated Security = True"; + private readonly string connectionString = ConfigurationManager.ConnectionStrings["Phonebook.Properties.Settings.Setting"].ConnectionString; private bool _resultSeach; - public bool Search(PersonDTO directoryDTO) + public bool SearchPerson(PersonDTO directoryDTO) { using(var connectionSearch = new SqlConnection(connectionString)) { connectionSearch.Open(); - string Search = "select NameSurname from Person where NameSurname Like '%'+ @NameSurname +'%'"; - SqlCommand SearchCommand = new SqlCommand(Search,connectionSearch); + string Search = "select PersonId from Person where NameSurname Like '%'+ @NameSurname +'%'"; + SqlCommand SearchCommand = new SqlCommand(Search, connectionSearch); - SearchCommand.Parameters.Add(new System.Data.SqlClient.SqlParameter("@NameSurname", SqlDbType.NChar, 15) { Value = directoryDTO.NameSurname }); + SearchCommand.Parameters.Add(new System.Data.SqlClient.SqlParameter("@NameSurname", SqlDbType.NVarChar, 250) { Value = directoryDTO.NameSurname }); - SqlDataReader sqlDataReader = SearchCommand.ExecuteReader(); - while (sqlDataReader.Read()) - { - - directoryDTO.NameSurname = sqlDataReader["NameSurname"].ToString(); - directoryDTO.Number = sqlDataReader["Number"].ToString(); + var findPersonId = SearchCommand.ExecuteScalar(); + + if (findPersonId == null) + { + System.Windows.Forms.MessageBox.Show("An error occurred while retrieving the registered customer's ID."); + _resultSeach = false; + } + else + { + if (!int.TryParse(findPersonId.ToString(), out int _PersonId)) + { + System.Windows.Forms.MessageBox.Show("An error occurred while retrieving the registered customer's ID."); + } _resultSeach = true; } - sqlDataReader.Close(); connectionSearch.Close(); } return _resultSeach; diff --git a/IDataAcces.cs b/IDataAcces.cs index 08f8618..2e91132 100644 --- a/IDataAcces.cs +++ b/IDataAcces.cs @@ -10,7 +10,7 @@ namespace Phonebook public interface IDataAcces { void RegisterDatabase(PersonDTO directoryDTO); - bool Search(PersonDTO directoryDTO); + bool SearchPerson(PersonDTO directoryDTO); void Delete(PersonDTO directoryDTO); void Update(PersonDTO directoryDTO); diff --git a/NumberDelete.Designer.cs b/NumberDelete.Designer.cs index 5ccb971..f693c72 100644 --- a/NumberDelete.Designer.cs +++ b/NumberDelete.Designer.cs @@ -111,7 +111,7 @@ private void InitializeComponent() // this.lblNameSurname.AutoSize = true; this.lblNameSurname.Font = new System.Drawing.Font("Microsoft Sans Serif", 11.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(162))); - this.lblNameSurname.Location = new System.Drawing.Point(28, 15); + this.lblNameSurname.Location = new System.Drawing.Point(35, 15); this.lblNameSurname.Name = "lblNameSurname"; this.lblNameSurname.Size = new System.Drawing.Size(0, 18); this.lblNameSurname.TabIndex = 1; @@ -156,7 +156,7 @@ private void InitializeComponent() this.Controls.Add(this.btnSearch); this.Controls.Add(this.label1); this.Name = "NumberDelete"; - this.Text = "NumberDelete"; + this.Text = "Delete The Number"; this.pnlDelete.ResumeLayout(false); this.pnlDelete.PerformLayout(); this.ResumeLayout(false); diff --git a/Properties/Settings.Designer.cs b/Properties/Settings.Designer.cs index 126ae65..219e1d2 100644 --- a/Properties/Settings.Designer.cs +++ b/Properties/Settings.Designer.cs @@ -8,22 +8,29 @@ // //------------------------------------------------------------------------------ - -namespace Phonebook.Properties -{ +namespace Phonebook.Properties { + + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")] - internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase - { - + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "16.10.0.0")] + internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { + private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); - - public static Settings Default - { - get - { + + public static Settings Default { + get { return defaultInstance; } } + + [global::System.Configuration.ApplicationScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.SpecialSettingAttribute(global::System.Configuration.SpecialSetting.ConnectionString)] + [global::System.Configuration.DefaultSettingValueAttribute("Data Source=LAPTOP-VBIOM4D2;Initial Catalog=Phonebook;Integrated Security=True")] + public string Setting { + get { + return ((string)(this["Setting"])); + } + } } } diff --git a/Properties/Settings.settings b/Properties/Settings.settings index 3964565..9e22ed8 100644 --- a/Properties/Settings.settings +++ b/Properties/Settings.settings @@ -1,7 +1,14 @@  - - - - - - + + + + + <?xml version="1.0" encoding="utf-16"?> +<SerializableConnectionString xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> + <ConnectionString>Data Source=LAPTOP-VBIOM4D2;Initial Catalog=Phonebook;Integrated Security=True</ConnectionString> + <ProviderName>System.Data.SqlClient</ProviderName> +</SerializableConnectionString> + Data Source=LAPTOP-VBIOM4D2;Initial Catalog=Phonebook;Integrated Security=True + + + \ No newline at end of file From 218add73f4f90d9778d5e1f1c6ed043ef3cdb4f4 Mon Sep 17 00:00:00 2001 From: Teslime Date: Thu, 9 Dec 2021 15:22:48 +0300 Subject: [PATCH 03/20] Added the ability to delete the record if it matches the PersonId returned from SearchPerson(). --- DataAcces.cs | 14 +++++++------- IDataAcces.cs | 4 ++-- NumberDelete.cs | 17 +++++++++-------- NumberUpdate.cs | 11 +++++++---- 4 files changed, 25 insertions(+), 21 deletions(-) diff --git a/DataAcces.cs b/DataAcces.cs index af7c6a6..13fc02a 100644 --- a/DataAcces.cs +++ b/DataAcces.cs @@ -18,7 +18,7 @@ public class DataAcces : IDataAcces private bool _resultSeach; - public bool SearchPerson(PersonDTO directoryDTO) + public int SearchPerson(PersonDTO directoryDTO) { using(var connectionSearch = new SqlConnection(connectionString)) { @@ -36,7 +36,7 @@ public bool SearchPerson(PersonDTO directoryDTO) if (findPersonId == null) { System.Windows.Forms.MessageBox.Show("An error occurred while retrieving the registered customer's ID."); - _resultSeach = false; + return 0; } else { @@ -44,21 +44,21 @@ public bool SearchPerson(PersonDTO directoryDTO) { System.Windows.Forms.MessageBox.Show("An error occurred while retrieving the registered customer's ID."); } - _resultSeach = true; + return _PersonId; } connectionSearch.Close(); } - return _resultSeach; + } - public void Delete(PersonDTO directoryDTO) + public void DeletePerson(PersonDTO directoryDTO) { using(var connectionDelete = new SqlConnection(connectionString)) { connectionDelete.Open(); - string Delete = "Delete from Person where NameSurname = @NameSurname"; + string Delete = "Delete from Person where PersonId = @PersonId"; SqlCommand DeleteCommand = new SqlCommand(Delete, connectionDelete); - DeleteCommand.Parameters.Add(new System.Data.SqlClient.SqlParameter("@NameSurname", SqlDbType.NChar, 15) { Value = directoryDTO.NameSurname }); + DeleteCommand.Parameters.Add(new System.Data.SqlClient.SqlParameter("@PersonId", SqlDbType.Int) { Value = directoryDTO.PersonId}); DeleteCommand.ExecuteNonQuery(); connectionDelete.Close(); diff --git a/IDataAcces.cs b/IDataAcces.cs index 2e91132..8a1435a 100644 --- a/IDataAcces.cs +++ b/IDataAcces.cs @@ -10,8 +10,8 @@ namespace Phonebook public interface IDataAcces { void RegisterDatabase(PersonDTO directoryDTO); - bool SearchPerson(PersonDTO directoryDTO); - void Delete(PersonDTO directoryDTO); + int SearchPerson(PersonDTO directoryDTO); + void DeletePerson(PersonDTO directoryDTO); void Update(PersonDTO directoryDTO); diff --git a/NumberDelete.cs b/NumberDelete.cs index a4ce984..467a34c 100644 --- a/NumberDelete.cs +++ b/NumberDelete.cs @@ -29,20 +29,21 @@ private void MapperSearch() var config = new MapperConfiguration(cfg => cfg.CreateMap()); var mapper = new Mapper(config); directoryDTO = mapper.Map(SearchDto); - ResultForm(dataAcces.Search(directoryDTO)); + ResultForm(dataAcces.SearchPerson(directoryDTO)); } - private void ResultForm(bool _resultSearch) + private void ResultForm(int _resultSearch) { - if(_resultSearch == true) + if(_resultSearch == 0) { - pnlDelete.Visible = true; - lblNameSurname.Text = SearchDto.NameSurname; - + MessageBox.Show("The data suitable for the " + txtNameSurname.Text + ". you are looking for could not be found in the directory. Please make a selection. End the deletion or try again!"); + } else { - MessageBox.Show("The data suitable for the " + txtNameSurname.Text + ". you are looking for could not be found in the directory. Please make a selection. End the deletion or try again!"); + pnlDelete.Visible = true; + lblNameSurname.Text = SearchDto.NameSurname; + directoryDTO.PersonId = _resultSearch; } } private void btnSearch_Click(object sender, EventArgs e) @@ -53,7 +54,7 @@ private void btnSearch_Click(object sender, EventArgs e) private void btnYes_Click(object sender, EventArgs e) { - dataAcces.Delete(directoryDTO); + dataAcces.DeletePerson(directoryDTO); MessageBox.Show("Process completed."); } diff --git a/NumberUpdate.cs b/NumberUpdate.cs index d762dd6..b3b9cba 100644 --- a/NumberUpdate.cs +++ b/NumberUpdate.cs @@ -31,20 +31,23 @@ private void MapperDto() var config = new MapperConfiguration(cfg => cfg.CreateMap()); var mapper = new Mapper(config); directoryDTO = mapper.Map(SearchDto); - ResultForm(dataAcces.Search(directoryDTO)); + ResultForm(dataAcces.SearchPerson(directoryDTO)); } - private void ResultForm(bool _resultSearch) + private void ResultForm(int _resultSearch) { - if (_resultSearch == true) + if (_resultSearch == 0) { + MessageBox.Show("No record found named " + txtNameSurname.Text + ". Please try again"); pnlUpdate.Visible = true; pnlNameSurname.Text = directoryDTO.NameSurname; pnlNumber.Text = directoryDTO.Number.ToString(); } else { - MessageBox.Show("No record found named " + txtNameSurname.Text + ". Please try again"); + pnlUpdate.Visible = true; + pnlNameSurname.Text = directoryDTO.NameSurname; + pnlNumber.Text = directoryDTO.Number.ToString(); } } private void btnSearch_Click(object sender, EventArgs e) From e052dd92d6dea4fcb53ff9fde26b311c1c029d6d Mon Sep 17 00:00:00 2001 From: Teslime Date: Mon, 13 Dec 2021 14:46:04 +0300 Subject: [PATCH 04/20] Added DI --- App.config | 13 ++++++++++--- DataAcces.cs => DataAccess.cs | 2 +- IDataAcces.cs => IDataAccess.cs | 2 +- MainScreenForm.cs | 9 ++++++--- NewNumberRegister.cs | 10 +++++----- NumberDelete.cs | 10 +++++----- NumberUpdate.cs | 8 ++++---- Phonebook.csproj | 19 +++++++++++++++++-- Program.cs | 12 ++++++++++++ packages.config | 5 +++++ 10 files changed, 66 insertions(+), 24 deletions(-) rename DataAcces.cs => DataAccess.cs (98%) rename IDataAcces.cs => IDataAccess.cs (92%) diff --git a/App.config b/App.config index e61bec6..c1fd63e 100644 --- a/App.config +++ b/App.config @@ -1,12 +1,19 @@ - + - + + + + + + + + + \ No newline at end of file diff --git a/DataAcces.cs b/DataAccess.cs similarity index 98% rename from DataAcces.cs rename to DataAccess.cs index 13fc02a..1fb9c9d 100644 --- a/DataAcces.cs +++ b/DataAccess.cs @@ -12,7 +12,7 @@ namespace Phonebook { - public class DataAcces : IDataAcces + public class DataAccess : IDataAccess { private readonly string connectionString = ConfigurationManager.ConnectionStrings["Phonebook.Properties.Settings.Setting"].ConnectionString; diff --git a/IDataAcces.cs b/IDataAccess.cs similarity index 92% rename from IDataAcces.cs rename to IDataAccess.cs index 8a1435a..2a4087b 100644 --- a/IDataAcces.cs +++ b/IDataAccess.cs @@ -7,7 +7,7 @@ namespace Phonebook { - public interface IDataAcces + public interface IDataAccess { void RegisterDatabase(PersonDTO directoryDTO); int SearchPerson(PersonDTO directoryDTO); diff --git a/MainScreenForm.cs b/MainScreenForm.cs index ee7f4e1..ef4c41d 100644 --- a/MainScreenForm.cs +++ b/MainScreenForm.cs @@ -12,28 +12,31 @@ namespace Phonebook { public partial class MainScreenForm : Form { + private readonly IDataAccess _dataAccess; + public MainScreenForm() { InitializeComponent(); + _dataAccess = (IDataAccess)Program.ServiceProvider.GetService(typeof(IDataAccess)); } private void btnRegister_Click(object sender, EventArgs e) { - NewNumberRegister newNumberRegister = new NewNumberRegister(new DataAcces()); + NewNumberRegister newNumberRegister = new NewNumberRegister(_dataAccess); newNumberRegister.Show(); this.Hide(); } private void btnDelete_Click(object sender, EventArgs e) { - NumberDelete numberDelete = new NumberDelete(new DataAcces()); + NumberDelete numberDelete = new NumberDelete(_dataAccess); numberDelete.Show(); this.Hide(); } private void btnUpdate_Click(object sender, EventArgs e) { - NumberUpdate numberUpdate = new NumberUpdate(new DataAcces()); + NumberUpdate numberUpdate = new NumberUpdate(_dataAccess); numberUpdate.Show(); this.Hide(); } diff --git a/NewNumberRegister.cs b/NewNumberRegister.cs index 289008a..a4b1823 100644 --- a/NewNumberRegister.cs +++ b/NewNumberRegister.cs @@ -14,12 +14,12 @@ namespace Phonebook { public partial class NewNumberRegister : Form { - - public IDataAcces dataAcces; - public NewNumberRegister(IDataAcces dataAcces) + + private readonly IDataAccess _dataAccess; + public NewNumberRegister(IDataAccess _dataAccess) { InitializeComponent(); - this.dataAcces = dataAcces; + this._dataAccess = _dataAccess; } @@ -33,7 +33,7 @@ public void MapperDirectory() var config = new MapperConfiguration(cfg => cfg.CreateMap()); var mapper= new Mapper(config); var directoryDTO = mapper.Map(directory); - dataAcces.RegisterDatabase(directoryDTO); + _dataAccess.RegisterDatabase(directoryDTO); MessageBox.Show("işlem başarıyla tamamlandı."); diff --git a/NumberDelete.cs b/NumberDelete.cs index 467a34c..fd25949 100644 --- a/NumberDelete.cs +++ b/NumberDelete.cs @@ -14,11 +14,11 @@ namespace Phonebook { public partial class NumberDelete : Form { - IDataAcces dataAcces; - public NumberDelete(IDataAcces dataAcces) + private readonly IDataAccess _dataAccess; + public NumberDelete(IDataAccess _dataAccess) { InitializeComponent(); - this.dataAcces = dataAcces; + this._dataAccess = _dataAccess; } Person SearchDto = new Person(); PersonDTO directoryDTO; @@ -29,7 +29,7 @@ private void MapperSearch() var config = new MapperConfiguration(cfg => cfg.CreateMap()); var mapper = new Mapper(config); directoryDTO = mapper.Map(SearchDto); - ResultForm(dataAcces.SearchPerson(directoryDTO)); + ResultForm(_dataAccess.SearchPerson(directoryDTO)); } private void ResultForm(int _resultSearch) @@ -54,7 +54,7 @@ private void btnSearch_Click(object sender, EventArgs e) private void btnYes_Click(object sender, EventArgs e) { - dataAcces.DeletePerson(directoryDTO); + _dataAccess.DeletePerson(directoryDTO); MessageBox.Show("Process completed."); } diff --git a/NumberUpdate.cs b/NumberUpdate.cs index b3b9cba..68f4ba7 100644 --- a/NumberUpdate.cs +++ b/NumberUpdate.cs @@ -14,11 +14,11 @@ namespace Phonebook { public partial class NumberUpdate : Form { - IDataAcces dataAcces; - public NumberUpdate(IDataAcces dataAcces) + private readonly IDataAccess _dataAccess; + public NumberUpdate(IDataAccess _dataAccess) { InitializeComponent(); - this.dataAcces = dataAcces; + this._dataAccess = _dataAccess; } @@ -31,7 +31,7 @@ private void MapperDto() var config = new MapperConfiguration(cfg => cfg.CreateMap()); var mapper = new Mapper(config); directoryDTO = mapper.Map(SearchDto); - ResultForm(dataAcces.SearchPerson(directoryDTO)); + ResultForm(_dataAccess.SearchPerson(directoryDTO)); } private void ResultForm(int _resultSearch) diff --git a/Phonebook.csproj b/Phonebook.csproj index 2e899bc..4b1fbe9 100644 --- a/Phonebook.csproj +++ b/Phonebook.csproj @@ -36,9 +36,24 @@ packages\AutoMapper.10.1.1\lib\net461\AutoMapper.dll + + packages\Microsoft.Bcl.AsyncInterfaces.6.0.0\lib\net461\Microsoft.Bcl.AsyncInterfaces.dll + + + packages\Microsoft.Extensions.DependencyInjection.6.0.0\lib\net461\Microsoft.Extensions.DependencyInjection.dll + + + packages\Microsoft.Extensions.DependencyInjection.Abstractions.6.0.0\lib\net461\Microsoft.Extensions.DependencyInjection.Abstractions.dll + + + packages\System.Runtime.CompilerServices.Unsafe.6.0.0\lib\net461\System.Runtime.CompilerServices.Unsafe.dll + + + packages\System.Threading.Tasks.Extensions.4.5.4\lib\net461\System.Threading.Tasks.Extensions.dll + @@ -50,7 +65,7 @@ - + @@ -65,7 +80,7 @@ DirectorySearching.cs - + Form diff --git a/Program.cs b/Program.cs index 840b9a3..7953c31 100644 --- a/Program.cs +++ b/Program.cs @@ -3,17 +3,29 @@ using System.Linq; using System.Threading.Tasks; using System.Windows.Forms; +using Microsoft.Extensions.DependencyInjection; namespace Phonebook { static class Program { + public static IServiceProvider ServiceProvider { get; set; } + + static void ConfigureServices() + { + var services = new ServiceCollection(); + services.AddTransient(); + ServiceProvider = services.BuildServiceProvider(); + } + /// /// The main entry point for the application. /// [STAThread] + static void Main() { + ConfigureServices(); Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new MainScreenForm()); diff --git a/packages.config b/packages.config index 5be5bb7..973dea0 100644 --- a/packages.config +++ b/packages.config @@ -1,4 +1,9 @@  + + + + + \ No newline at end of file From 42ae35cdb1dc02ae39a21df37d70fdc675872d45 Mon Sep 17 00:00:00 2001 From: Teslime Date: Mon, 13 Dec 2021 15:12:31 +0300 Subject: [PATCH 05/20] Added edit to confirmation message. --- DataAccess.cs | 3 +-- NewNumberRegister.cs | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/DataAccess.cs b/DataAccess.cs index 1fb9c9d..402599d 100644 --- a/DataAccess.cs +++ b/DataAccess.cs @@ -15,8 +15,7 @@ namespace Phonebook public class DataAccess : IDataAccess { private readonly string connectionString = ConfigurationManager.ConnectionStrings["Phonebook.Properties.Settings.Setting"].ConnectionString; - - private bool _resultSeach; + public int SearchPerson(PersonDTO directoryDTO) { diff --git a/NewNumberRegister.cs b/NewNumberRegister.cs index a4b1823..998cd4c 100644 --- a/NewNumberRegister.cs +++ b/NewNumberRegister.cs @@ -34,7 +34,7 @@ public void MapperDirectory() var mapper= new Mapper(config); var directoryDTO = mapper.Map(directory); _dataAccess.RegisterDatabase(directoryDTO); - MessageBox.Show("işlem başarıyla tamamlandı."); + MessageBox.Show("The operation completed successfully."); } From b037749e61f31fb52fccda244f09cdf57c350368 Mon Sep 17 00:00:00 2001 From: Teslime Date: Thu, 16 Dec 2021 14:37:44 +0300 Subject: [PATCH 06/20] Added the ability to find the value to be updated and assign it to the Text boxes. --- DataAccess.cs | 57 ++++++++++++++++++++++++++++++++++++++++++++++--- IDataAccess.cs | 4 ++-- NumberUpdate.cs | 37 ++++++++++++++++---------------- 3 files changed, 74 insertions(+), 24 deletions(-) diff --git a/DataAccess.cs b/DataAccess.cs index 402599d..b9da23b 100644 --- a/DataAccess.cs +++ b/DataAccess.cs @@ -8,7 +8,8 @@ using System.Data.SqlClient; using System.Threading.Tasks; using Phonebook.models; - +using AutoMapper; + namespace Phonebook { @@ -62,7 +63,7 @@ public void DeletePerson(PersonDTO directoryDTO) DeleteCommand.ExecuteNonQuery(); connectionDelete.Close(); } - } + } public void RegisterDatabase(PersonDTO directoryDTO) { using (var connectionRegister = new SqlConnection(connectionString)) @@ -71,7 +72,7 @@ public void RegisterDatabase(PersonDTO directoryDTO) string registerPerson = "Insert into Person(NameSurname, Number) values(@NameSurname, @Number)"; SqlCommand sqlCommand = new SqlCommand(registerPerson, connectionRegister); - + sqlCommand.Parameters.Add(new System.Data.SqlClient.SqlParameter("@NameSurname", SqlDbType.NChar, 15) { Value = directoryDTO.NameSurname }); sqlCommand.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Number", SqlDbType.VarChar, 11) { Value = directoryDTO.Number }); sqlCommand.ExecuteNonQuery(); @@ -79,6 +80,56 @@ public void RegisterDatabase(PersonDTO directoryDTO) } } + public PersonDTO MapperSearchForUpdatePerson(Person person) + { + var config = new MapperConfiguration(cfg => cfg.CreateMap()); + var mapper = new Mapper(config); + var personDTO = mapper.Map(person); + return personDTO; + } + + public PersonDTO SearchForUpdatePerson(string _nameSurname) + { + using (var connectionSearch = new SqlConnection(connectionString)) + { + connectionSearch.Open(); + + Person person = new Person(); + string SearchQuery = "SELECT TOP 1 PersonId, NameSurname, Number FROM Person WHERE NameSurname LIKE '%'+ @NameSurname +'%'"; + var cmd = new SqlCommand(SearchQuery, connectionSearch); + cmd.Parameters.Add(new System.Data.SqlClient.SqlParameter("@NameSurname", SqlDbType.NVarChar, 250) { Value = _nameSurname }); + + var reader = cmd.ExecuteReader(); + + if(!reader.HasRows) + { + System.Windows.Forms.MessageBox.Show("No record found named " + _nameSurname + ". Please try again"); + } + else + { + + while(reader.Read()) + { + if (!int.TryParse(reader["PersonId"].ToString().ToString(), out int _PersonId)) + { + System.Windows.Forms.MessageBox.Show("An error occurred while retrieving the registered customer's ID."); + } + person.PersonId = _PersonId; + person.NameSurname = reader["NameSurname"].ToString(); + person.Number = reader["Number"].ToString(); + + } + + } + + + reader.Close(); + connectionSearch.Close(); + return MapperSearchForUpdatePerson(person); + } + + + } public void Update(PersonDTO directoryDTO) { using(var ConnectionUpdate = new SqlConnection(connectionString)) diff --git a/IDataAccess.cs b/IDataAccess.cs index 2a4087b..179f9c5 100644 --- a/IDataAccess.cs +++ b/IDataAccess.cs @@ -13,7 +13,7 @@ public interface IDataAccess int SearchPerson(PersonDTO directoryDTO); void DeletePerson(PersonDTO directoryDTO); void Update(PersonDTO directoryDTO); - - + PersonDTO SearchForUpdatePerson(string _nameSurname); + PersonDTO MapperSearchForUpdatePerson(Person person); } } diff --git a/NumberUpdate.cs b/NumberUpdate.cs index 68f4ba7..a78cdfe 100644 --- a/NumberUpdate.cs +++ b/NumberUpdate.cs @@ -22,37 +22,36 @@ public NumberUpdate(IDataAccess _dataAccess) } - Person SearchDto = new Person(); - PersonDTO directoryDTO; - private void MapperDto() - { - SearchDto.NameSurname = txtNameSurname.Text; + Person person = new Person(); + PersonDTO personDTO = new PersonDTO(); + //private void MapperDto() + //{ + // SearchDto.NameSurname = txtNameSurname.Text; - var config = new MapperConfiguration(cfg => cfg.CreateMap()); - var mapper = new Mapper(config); - directoryDTO = mapper.Map(SearchDto); - ResultForm(_dataAccess.SearchPerson(directoryDTO)); - } + // var config = new MapperConfiguration(cfg => cfg.CreateMap()); + // var mapper = new Mapper(config); + // directoryDTO = mapper.Map(SearchDto); + // + //} - private void ResultForm(int _resultSearch) + private void ResultForm() { - if (_resultSearch == 0) + personDTO = _dataAccess.SearchForUpdatePerson(txtNameSurname.Text); + + if (personDTO.PersonId == 0) { - MessageBox.Show("No record found named " + txtNameSurname.Text + ". Please try again"); - pnlUpdate.Visible = true; - pnlNameSurname.Text = directoryDTO.NameSurname; - pnlNumber.Text = directoryDTO.Number.ToString(); + pnlUpdate.Visible = false; } else { pnlUpdate.Visible = true; - pnlNameSurname.Text = directoryDTO.NameSurname; - pnlNumber.Text = directoryDTO.Number.ToString(); + pnlNameSurname.Text = personDTO.NameSurname; + pnlNumber.Text = personDTO.Number; } } private void btnSearch_Click(object sender, EventArgs e) { - MapperDto(); + ResultForm(); } private void btnUpdate_Click(object sender, EventArgs e) From 35d120e207135a3675931a471dfb136178136d8d Mon Sep 17 00:00:00 2001 From: Teslime Date: Thu, 16 Dec 2021 18:00:08 +0300 Subject: [PATCH 07/20] Added ability to update new values in database. --- DataAccess.cs | 13 +++++++++---- IDataAccess.cs | 2 +- NumberUpdate.cs | 24 +++++++++++++----------- 3 files changed, 23 insertions(+), 16 deletions(-) diff --git a/DataAccess.cs b/DataAccess.cs index b9da23b..192dc2e 100644 --- a/DataAccess.cs +++ b/DataAccess.cs @@ -127,15 +127,20 @@ public PersonDTO SearchForUpdatePerson(string _nameSurname) connectionSearch.Close(); return MapperSearchForUpdatePerson(person); } - - } - public void Update(PersonDTO directoryDTO) + + public void UpdatePerson(PersonDTO personDTO) { using(var ConnectionUpdate = new SqlConnection(connectionString)) { ConnectionUpdate.Open(); - string Update = "Update Person SET NameSurname = @NameSurname , Number = @Number where PersonId = @PersonId "; + + string UpdateQuery = "Update Person SET NameSurname = @NameSurname , Number = @Number where PersonId = @PersonId "; + var cmd = new SqlCommand(UpdateQuery, ConnectionUpdate); + cmd.Parameters.Add(new System.Data.SqlClient.SqlParameter("@PersonId", SqlDbType.Int) { Value = personDTO.PersonId }); + cmd.Parameters.Add(new System.Data.SqlClient.SqlParameter("@NameSurname", SqlDbType.NChar, 15) { Value = personDTO.NameSurname }); + cmd.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Number", SqlDbType.VarChar, 11) { Value = personDTO.Number }); + cmd.ExecuteNonQuery(); ConnectionUpdate.Close(); } diff --git a/IDataAccess.cs b/IDataAccess.cs index 179f9c5..ecca31a 100644 --- a/IDataAccess.cs +++ b/IDataAccess.cs @@ -12,7 +12,7 @@ public interface IDataAccess void RegisterDatabase(PersonDTO directoryDTO); int SearchPerson(PersonDTO directoryDTO); void DeletePerson(PersonDTO directoryDTO); - void Update(PersonDTO directoryDTO); + void UpdatePerson(PersonDTO personDTO); PersonDTO SearchForUpdatePerson(string _nameSurname); PersonDTO MapperSearchForUpdatePerson(Person person); } diff --git a/NumberUpdate.cs b/NumberUpdate.cs index a78cdfe..737d95a 100644 --- a/NumberUpdate.cs +++ b/NumberUpdate.cs @@ -23,16 +23,18 @@ public NumberUpdate(IDataAccess _dataAccess) Person person = new Person(); - PersonDTO personDTO = new PersonDTO(); - //private void MapperDto() - //{ - // SearchDto.NameSurname = txtNameSurname.Text; - - // var config = new MapperConfiguration(cfg => cfg.CreateMap()); - // var mapper = new Mapper(config); - // directoryDTO = mapper.Map(SearchDto); - // - //} + PersonDTO personDTO = new PersonDTO(); + private void MapperFilledField() + { + person.PersonId = personDTO.PersonId; + person.NameSurname = pnlNameSurname.Text; + person.Number = pnlNumber.Text; + + var config = new MapperConfiguration(cfg => cfg.CreateMap()); + var mapper = new Mapper(config); + personDTO = mapper.Map(person); + _dataAccess.UpdatePerson(personDTO); + } private void ResultForm() { @@ -56,7 +58,7 @@ private void btnSearch_Click(object sender, EventArgs e) private void btnUpdate_Click(object sender, EventArgs e) { - + MapperFilledField(); MessageBox.Show("Process completed."); } From 3f1654ed15b7290e91532bf60c5d36f7fd257c9a Mon Sep 17 00:00:00 2001 From: Teslime Date: Thu, 16 Dec 2021 18:09:50 +0300 Subject: [PATCH 08/20] The parameter names in the DataAccess have been edited. --- DataAccess.cs | 14 +++++++------- IDataAccess.cs | 6 +++--- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/DataAccess.cs b/DataAccess.cs index 192dc2e..616c711 100644 --- a/DataAccess.cs +++ b/DataAccess.cs @@ -18,7 +18,7 @@ public class DataAccess : IDataAccess private readonly string connectionString = ConfigurationManager.ConnectionStrings["Phonebook.Properties.Settings.Setting"].ConnectionString; - public int SearchPerson(PersonDTO directoryDTO) + public int SearchPerson(PersonDTO personDTO) { using(var connectionSearch = new SqlConnection(connectionString)) { @@ -27,7 +27,7 @@ public int SearchPerson(PersonDTO directoryDTO) string Search = "select PersonId from Person where NameSurname Like '%'+ @NameSurname +'%'"; SqlCommand SearchCommand = new SqlCommand(Search, connectionSearch); - SearchCommand.Parameters.Add(new System.Data.SqlClient.SqlParameter("@NameSurname", SqlDbType.NVarChar, 250) { Value = directoryDTO.NameSurname }); + SearchCommand.Parameters.Add(new System.Data.SqlClient.SqlParameter("@NameSurname", SqlDbType.NVarChar, 250) { Value = personDTO.NameSurname }); var findPersonId = SearchCommand.ExecuteScalar(); @@ -51,20 +51,20 @@ public int SearchPerson(PersonDTO directoryDTO) } } - public void DeletePerson(PersonDTO directoryDTO) + public void DeletePerson(PersonDTO personDTO) { using(var connectionDelete = new SqlConnection(connectionString)) { connectionDelete.Open(); string Delete = "Delete from Person where PersonId = @PersonId"; SqlCommand DeleteCommand = new SqlCommand(Delete, connectionDelete); - DeleteCommand.Parameters.Add(new System.Data.SqlClient.SqlParameter("@PersonId", SqlDbType.Int) { Value = directoryDTO.PersonId}); + DeleteCommand.Parameters.Add(new System.Data.SqlClient.SqlParameter("@PersonId", SqlDbType.Int) { Value = personDTO.PersonId}); DeleteCommand.ExecuteNonQuery(); connectionDelete.Close(); } } - public void RegisterDatabase(PersonDTO directoryDTO) + public void RegisterDatabase(PersonDTO personDTO) { using (var connectionRegister = new SqlConnection(connectionString)) { @@ -73,8 +73,8 @@ public void RegisterDatabase(PersonDTO directoryDTO) string registerPerson = "Insert into Person(NameSurname, Number) values(@NameSurname, @Number)"; SqlCommand sqlCommand = new SqlCommand(registerPerson, connectionRegister); - sqlCommand.Parameters.Add(new System.Data.SqlClient.SqlParameter("@NameSurname", SqlDbType.NChar, 15) { Value = directoryDTO.NameSurname }); - sqlCommand.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Number", SqlDbType.VarChar, 11) { Value = directoryDTO.Number }); + sqlCommand.Parameters.Add(new System.Data.SqlClient.SqlParameter("@NameSurname", SqlDbType.NChar, 15) { Value = personDTO.NameSurname }); + sqlCommand.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Number", SqlDbType.VarChar, 11) { Value = personDTO.Number }); sqlCommand.ExecuteNonQuery(); connectionRegister.Close(); } diff --git a/IDataAccess.cs b/IDataAccess.cs index ecca31a..6f75978 100644 --- a/IDataAccess.cs +++ b/IDataAccess.cs @@ -9,9 +9,9 @@ namespace Phonebook { public interface IDataAccess { - void RegisterDatabase(PersonDTO directoryDTO); - int SearchPerson(PersonDTO directoryDTO); - void DeletePerson(PersonDTO directoryDTO); + void RegisterDatabase(PersonDTO personDTO); + int SearchPerson(PersonDTO personDTO); + void DeletePerson(PersonDTO personDTO); void UpdatePerson(PersonDTO personDTO); PersonDTO SearchForUpdatePerson(string _nameSurname); PersonDTO MapperSearchForUpdatePerson(Person person); From a61300429bfa80d03f073ececadf37f70422d283 Mon Sep 17 00:00:00 2001 From: Teslime Date: Thu, 16 Dec 2021 22:13:49 +0300 Subject: [PATCH 09/20] Added the ability to switch to the MainScreenForm with the Cancel Click in NumberUpdate.cs. --- NumberUpdate.cs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/NumberUpdate.cs b/NumberUpdate.cs index 737d95a..0cd6e8f 100644 --- a/NumberUpdate.cs +++ b/NumberUpdate.cs @@ -65,6 +65,10 @@ private void btnUpdate_Click(object sender, EventArgs e) private void btnCancel_Click(object sender, EventArgs e) { + MainScreenForm mainScreenForm = new MainScreenForm(); + mainScreenForm.Show(); + this.Hide(); + MessageBox.Show("No action was taken."); } From ff634dd99d6e6e973958a18210a4a5ce427351d9 Mon Sep 17 00:00:00 2001 From: Teslime Date: Thu, 16 Dec 2021 22:24:32 +0300 Subject: [PATCH 10/20] Renamed in NumberUpdate form --- NumberUpdate.Designer.cs | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/NumberUpdate.Designer.cs b/NumberUpdate.Designer.cs index 14d985d..d1c086e 100644 --- a/NumberUpdate.Designer.cs +++ b/NumberUpdate.Designer.cs @@ -30,6 +30,8 @@ protected override void Dispose(bool disposing) private void InitializeComponent() { this.pnlUpdate = new System.Windows.Forms.Panel(); + this.label2 = new System.Windows.Forms.Label(); + this.pnlNameSurname = new System.Windows.Forms.TextBox(); this.pnlNumber = new System.Windows.Forms.TextBox(); this.label4 = new System.Windows.Forms.Label(); this.btnUpdate = new System.Windows.Forms.Button(); @@ -39,8 +41,6 @@ private void InitializeComponent() this.label3 = new System.Windows.Forms.Label(); this.txtNameSurname = new System.Windows.Forms.TextBox(); this.label1 = new System.Windows.Forms.Label(); - this.label2 = new System.Windows.Forms.Label(); - this.pnlNameSurname = new System.Windows.Forms.TextBox(); this.pnlUpdate.SuspendLayout(); this.SuspendLayout(); // @@ -59,6 +59,23 @@ private void InitializeComponent() this.pnlUpdate.TabIndex = 7; this.pnlUpdate.Visible = false; // + // label2 + // + this.label2.AutoSize = true; + this.label2.Font = new System.Drawing.Font("Microsoft Sans Serif", 11.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(162))); + this.label2.Location = new System.Drawing.Point(72, 85); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(120, 18); + this.label2.TabIndex = 14; + this.label2.Text = "Name Surname:"; + // + // pnlNameSurname + // + this.pnlNameSurname.Location = new System.Drawing.Point(237, 88); + this.pnlNameSurname.Name = "pnlNameSurname"; + this.pnlNameSurname.Size = new System.Drawing.Size(161, 20); + this.pnlNameSurname.TabIndex = 13; + // // pnlNumber // this.pnlNumber.Location = new System.Drawing.Point(237, 133); @@ -146,23 +163,6 @@ private void InitializeComponent() this.label1.TabIndex = 8; this.label1.Text = "Please enter the name or surname of the person whose number you want to update:"; // - // label2 - // - this.label2.AutoSize = true; - this.label2.Font = new System.Drawing.Font("Microsoft Sans Serif", 11.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(162))); - this.label2.Location = new System.Drawing.Point(72, 85); - this.label2.Name = "label2"; - this.label2.Size = new System.Drawing.Size(120, 18); - this.label2.TabIndex = 14; - this.label2.Text = "Name Surname:"; - // - // pnlNameSurname - // - this.pnlNameSurname.Location = new System.Drawing.Point(237, 88); - this.pnlNameSurname.Name = "pnlNameSurname"; - this.pnlNameSurname.Size = new System.Drawing.Size(161, 20); - this.pnlNameSurname.TabIndex = 13; - // // NumberUpdate // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); @@ -174,7 +174,7 @@ private void InitializeComponent() this.Controls.Add(this.txtNameSurname); this.Controls.Add(this.label1); this.Name = "NumberUpdate"; - this.Text = "NumberUpdate"; + this.Text = "Update Person "; this.pnlUpdate.ResumeLayout(false); this.pnlUpdate.PerformLayout(); this.ResumeLayout(false); From cc294be366b0de10836458232b779ca7d84223f6 Mon Sep 17 00:00:00 2001 From: Teslime Date: Thu, 16 Dec 2021 22:29:01 +0300 Subject: [PATCH 11/20] Renamed in ListingPhonebook form --- ...esigner.cs => ListingPhonebook.Designer.cs | 13 +- DirectoryListing.cs => ListingPhonebook.cs | 6 +- ListingPhonebook.resx | 120 ++++++++++++++++++ Phonebook.csproj | 9 +- 4 files changed, 140 insertions(+), 8 deletions(-) rename DirectoryListing.Designer.cs => ListingPhonebook.Designer.cs (76%) rename DirectoryListing.cs => ListingPhonebook.cs (77%) create mode 100644 ListingPhonebook.resx diff --git a/DirectoryListing.Designer.cs b/ListingPhonebook.Designer.cs similarity index 76% rename from DirectoryListing.Designer.cs rename to ListingPhonebook.Designer.cs index 84e49a6..b90c8aa 100644 --- a/DirectoryListing.Designer.cs +++ b/ListingPhonebook.Designer.cs @@ -1,7 +1,7 @@  namespace Phonebook { - partial class DirectoryListing + partial class ListingPhonebook { /// /// Required designer variable. @@ -29,10 +29,17 @@ protected override void Dispose(bool disposing) /// private void InitializeComponent() { - this.components = new System.ComponentModel.Container(); + this.SuspendLayout(); + // + // ListingPhonebook + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(800, 450); - this.Text = "DirectoryListing"; + this.Name = "ListingPhonebook"; + this.Text = "Listing Phonebook"; + this.ResumeLayout(false); + } #endregion diff --git a/DirectoryListing.cs b/ListingPhonebook.cs similarity index 77% rename from DirectoryListing.cs rename to ListingPhonebook.cs index 9e4fdf9..61abc90 100644 --- a/DirectoryListing.cs +++ b/ListingPhonebook.cs @@ -10,11 +10,13 @@ namespace Phonebook { - public partial class DirectoryListing : Form + public partial class ListingPhonebook : Form { - public DirectoryListing() + public ListingPhonebook() { InitializeComponent(); } + + } } diff --git a/ListingPhonebook.resx b/ListingPhonebook.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/ListingPhonebook.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Phonebook.csproj b/Phonebook.csproj index 4b1fbe9..09f9f48 100644 --- a/Phonebook.csproj +++ b/Phonebook.csproj @@ -68,11 +68,11 @@ - + Form - - DirectoryListing.cs + + ListingPhonebook.cs Form @@ -107,6 +107,9 @@ + + ListingPhonebook.cs + DirectorySearching.cs From c86cbdfdd38113e01886395b426c79ed61e8f598 Mon Sep 17 00:00:00 2001 From: Teslime Date: Thu, 16 Dec 2021 22:30:23 +0300 Subject: [PATCH 12/20] Renamed in SearchingPhonebook.cs form --- Phonebook.csproj | 10 +++++----- ...ching.Designer.cs => SearchingPhonebook.Designer.cs | 4 ++-- DirectorySearching.cs => SearchingPhonebook.cs | 4 ++-- DirectorySearching.resx => SearchingPhonebook.resx | 0 4 files changed, 9 insertions(+), 9 deletions(-) rename DirectorySearching.Designer.cs => SearchingPhonebook.Designer.cs (98%) rename DirectorySearching.cs => SearchingPhonebook.cs (78%) rename DirectorySearching.resx => SearchingPhonebook.resx (100%) diff --git a/Phonebook.csproj b/Phonebook.csproj index 09f9f48..338f030 100644 --- a/Phonebook.csproj +++ b/Phonebook.csproj @@ -74,11 +74,11 @@ ListingPhonebook.cs - + Form - - DirectorySearching.cs + + SearchingPhonebook.cs @@ -110,8 +110,8 @@ ListingPhonebook.cs - - DirectorySearching.cs + + SearchingPhonebook.cs MainScreenForm.cs diff --git a/DirectorySearching.Designer.cs b/SearchingPhonebook.Designer.cs similarity index 98% rename from DirectorySearching.Designer.cs rename to SearchingPhonebook.Designer.cs index c2f97f1..d2a5cb1 100644 --- a/DirectorySearching.Designer.cs +++ b/SearchingPhonebook.Designer.cs @@ -1,7 +1,7 @@  namespace Phonebook { - partial class DirectorySearching + partial class SearchingPhonebook { /// /// Required designer variable. @@ -83,7 +83,7 @@ private void InitializeComponent() this.Controls.Add(this.label2); this.Controls.Add(this.label1); this.Name = "DirectorySearching"; - this.Text = "DirectorySearching"; + this.Text = "Searching Phonebook"; this.ResumeLayout(false); this.PerformLayout(); diff --git a/DirectorySearching.cs b/SearchingPhonebook.cs similarity index 78% rename from DirectorySearching.cs rename to SearchingPhonebook.cs index 9a9488b..d60e365 100644 --- a/DirectorySearching.cs +++ b/SearchingPhonebook.cs @@ -10,9 +10,9 @@ namespace Phonebook { - public partial class DirectorySearching : Form + public partial class SearchingPhonebook : Form { - public DirectorySearching() + public SearchingPhonebook() { InitializeComponent(); } diff --git a/DirectorySearching.resx b/SearchingPhonebook.resx similarity index 100% rename from DirectorySearching.resx rename to SearchingPhonebook.resx From 154b73ba4805d5eb626e2423fc0e7d3c472c8545 Mon Sep 17 00:00:00 2001 From: Teslime Date: Fri, 17 Dec 2021 13:21:28 +0300 Subject: [PATCH 13/20] Added ListingPhonebook design. --- ListingPhonebook.Designer.cs | 57 ++++++++++++++++++++++++++++++++++++ ListingPhonebook.cs | 2 +- 2 files changed, 58 insertions(+), 1 deletion(-) diff --git a/ListingPhonebook.Designer.cs b/ListingPhonebook.Designer.cs index b90c8aa..b79a1b8 100644 --- a/ListingPhonebook.Designer.cs +++ b/ListingPhonebook.Designer.cs @@ -29,19 +29,76 @@ protected override void Dispose(bool disposing) /// private void InitializeComponent() { + System.Windows.Forms.ListViewItem listViewItem1 = new System.Windows.Forms.ListViewItem(""); + this.listView1 = new System.Windows.Forms.ListView(); + this.PersonId = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); + this.NameSurname = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); + this.Number = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); + this.label1 = new System.Windows.Forms.Label(); this.SuspendLayout(); // + // listView1 + // + this.listView1.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] { + this.PersonId, + this.NameSurname, + this.Number}); + this.listView1.Font = new System.Drawing.Font("Microsoft Sans Serif", 11.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(162))); + this.listView1.HideSelection = false; + this.listView1.Items.AddRange(new System.Windows.Forms.ListViewItem[] { + listViewItem1}); + this.listView1.Location = new System.Drawing.Point(37, 79); + this.listView1.Name = "listView1"; + this.listView1.Size = new System.Drawing.Size(441, 325); + this.listView1.TabIndex = 1; + this.listView1.UseCompatibleStateImageBehavior = false; + this.listView1.View = System.Windows.Forms.View.Details; + // + // PersonId + // + this.PersonId.Text = "Person ID"; + this.PersonId.Width = 89; + // + // NameSurname + // + this.NameSurname.Text = "Name Surname"; + this.NameSurname.Width = 164; + // + // Number + // + this.Number.Text = "Number"; + this.Number.Width = 181; + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Font = new System.Drawing.Font("Microsoft Sans Serif", 11.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(162))); + this.label1.Location = new System.Drawing.Point(34, 42); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(93, 18); + this.label1.TabIndex = 2; + this.label1.Text = "Phonebook :"; + // // ListingPhonebook // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(800, 450); + this.Controls.Add(this.label1); + this.Controls.Add(this.listView1); this.Name = "ListingPhonebook"; this.Text = "Listing Phonebook"; this.ResumeLayout(false); + this.PerformLayout(); } #endregion + + private System.Windows.Forms.ListView listView1; + private System.Windows.Forms.ColumnHeader PersonId; + private System.Windows.Forms.ColumnHeader Number; + public System.Windows.Forms.ColumnHeader NameSurname; + private System.Windows.Forms.Label label1; } } \ No newline at end of file diff --git a/ListingPhonebook.cs b/ListingPhonebook.cs index 61abc90..817a1b3 100644 --- a/ListingPhonebook.cs +++ b/ListingPhonebook.cs @@ -17,6 +17,6 @@ public ListingPhonebook() InitializeComponent(); } - + } } From 5c5d48317c45f152cff932130d950bdbddba2283 Mon Sep 17 00:00:00 2001 From: Teslime Date: Fri, 17 Dec 2021 17:40:15 +0300 Subject: [PATCH 14/20] The data in the database is listed in the ListingPhonebook form with listview. --- DataAccess.cs | 33 +++++++++++++++++++++++++++++++++ IDataAccess.cs | 2 ++ ListingPhonebook.Designer.cs | 30 ++++++++++++++---------------- ListingPhonebook.cs | 26 ++++++++++++++++++++++++-- MainScreenForm.Designer.cs | 1 + MainScreenForm.cs | 7 +++++++ 6 files changed, 81 insertions(+), 18 deletions(-) diff --git a/DataAccess.cs b/DataAccess.cs index 616c711..0fc06b3 100644 --- a/DataAccess.cs +++ b/DataAccess.cs @@ -145,5 +145,38 @@ public void UpdatePerson(PersonDTO personDTO) ConnectionUpdate.Close(); } } + public List MapperListingPhonebook(List person) + { + + var config = new MapperConfiguration(cfg => cfg.CreateMap()); + var mapper = new Mapper(config); + List personDto = mapper.Map, List>(person); + return personDto; + + } + public List ListingPhonebook() + { + using(var connectionList= new SqlConnection(connectionString)) + { + connectionList.Open(); + string ListingPhonebookQuery = "SELECT PersonId, NameSurname, Number FROM Person"; + List personList = new List(); + var cmd = new SqlCommand(ListingPhonebookQuery, connectionList); + + var reader = cmd.ExecuteReader(); + + while(reader.Read()) + { + if (!int.TryParse(reader["PersonId"].ToString().ToString(), out int _PersonId)) + { + System.Windows.Forms.MessageBox.Show("An error occurred while retrieving the registered customer's ID."); + } + personList.Add(new Person { PersonId = _PersonId, NameSurname = reader["NameSurname"].ToString(), Number = reader["Number"].ToString() }); + } + return MapperListingPhonebook(personList); + reader.Close(); + connectionList.Close(); + } + } } } diff --git a/IDataAccess.cs b/IDataAccess.cs index 6f75978..6b1d1d4 100644 --- a/IDataAccess.cs +++ b/IDataAccess.cs @@ -15,5 +15,7 @@ public interface IDataAccess void UpdatePerson(PersonDTO personDTO); PersonDTO SearchForUpdatePerson(string _nameSurname); PersonDTO MapperSearchForUpdatePerson(Person person); + List ListingPhonebook(); + List MapperListingPhonebook(List person); } } diff --git a/ListingPhonebook.Designer.cs b/ListingPhonebook.Designer.cs index b79a1b8..56125c7 100644 --- a/ListingPhonebook.Designer.cs +++ b/ListingPhonebook.Designer.cs @@ -29,30 +29,27 @@ protected override void Dispose(bool disposing) /// private void InitializeComponent() { - System.Windows.Forms.ListViewItem listViewItem1 = new System.Windows.Forms.ListViewItem(""); - this.listView1 = new System.Windows.Forms.ListView(); + this.listViewPhonebook = new System.Windows.Forms.ListView(); this.PersonId = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); this.NameSurname = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); this.Number = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); this.label1 = new System.Windows.Forms.Label(); this.SuspendLayout(); // - // listView1 + // listViewPhonebook // - this.listView1.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] { + this.listViewPhonebook.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] { this.PersonId, this.NameSurname, this.Number}); - this.listView1.Font = new System.Drawing.Font("Microsoft Sans Serif", 11.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(162))); - this.listView1.HideSelection = false; - this.listView1.Items.AddRange(new System.Windows.Forms.ListViewItem[] { - listViewItem1}); - this.listView1.Location = new System.Drawing.Point(37, 79); - this.listView1.Name = "listView1"; - this.listView1.Size = new System.Drawing.Size(441, 325); - this.listView1.TabIndex = 1; - this.listView1.UseCompatibleStateImageBehavior = false; - this.listView1.View = System.Windows.Forms.View.Details; + this.listViewPhonebook.Font = new System.Drawing.Font("Microsoft Sans Serif", 11.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(162))); + this.listViewPhonebook.HideSelection = false; + this.listViewPhonebook.Location = new System.Drawing.Point(37, 79); + this.listViewPhonebook.Name = "listViewPhonebook"; + this.listViewPhonebook.Size = new System.Drawing.Size(441, 325); + this.listViewPhonebook.TabIndex = 1; + this.listViewPhonebook.UseCompatibleStateImageBehavior = false; + this.listViewPhonebook.View = System.Windows.Forms.View.Details; // // PersonId // @@ -85,9 +82,10 @@ private void InitializeComponent() this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(800, 450); this.Controls.Add(this.label1); - this.Controls.Add(this.listView1); + this.Controls.Add(this.listViewPhonebook); this.Name = "ListingPhonebook"; this.Text = "Listing Phonebook"; + this.Load += new System.EventHandler(this.ListingPhonebook_Load); this.ResumeLayout(false); this.PerformLayout(); @@ -95,7 +93,7 @@ private void InitializeComponent() #endregion - private System.Windows.Forms.ListView listView1; + private System.Windows.Forms.ListView listViewPhonebook; private System.Windows.Forms.ColumnHeader PersonId; private System.Windows.Forms.ColumnHeader Number; public System.Windows.Forms.ColumnHeader NameSurname; diff --git a/ListingPhonebook.cs b/ListingPhonebook.cs index 817a1b3..c2459d8 100644 --- a/ListingPhonebook.cs +++ b/ListingPhonebook.cs @@ -7,16 +7,38 @@ using System.Text; using System.Threading.Tasks; using System.Windows.Forms; +using Phonebook.models; namespace Phonebook { public partial class ListingPhonebook : Form { - public ListingPhonebook() + private readonly IDataAccess _dataAccess; + public ListingPhonebook(IDataAccess _dataAccess) { InitializeComponent(); + this._dataAccess = _dataAccess; } - + private void ShowListingPhonebook() + { + List personDTO = _dataAccess.ListingPhonebook(); + + foreach(PersonDTO getPhonebook in personDTO) + { + ListViewItem personList = new ListViewItem(); + personList.Text = getPhonebook.PersonId.ToString(); + personList.SubItems.Add(getPhonebook.NameSurname); + personList.SubItems.Add(getPhonebook.Number); + + listViewPhonebook.Items.Add(personList); + } + + + } + private void ListingPhonebook_Load(object sender, EventArgs e) + { + ShowListingPhonebook(); + } } } diff --git a/MainScreenForm.Designer.cs b/MainScreenForm.Designer.cs index b398334..7eeb670 100644 --- a/MainScreenForm.Designer.cs +++ b/MainScreenForm.Designer.cs @@ -94,6 +94,7 @@ private void InitializeComponent() this.btnListing.TabIndex = 4; this.btnListing.Text = "Listing The Directory"; this.btnListing.UseVisualStyleBackColor = true; + this.btnListing.Click += new System.EventHandler(this.btnListing_Click); // // btnSearching // diff --git a/MainScreenForm.cs b/MainScreenForm.cs index ef4c41d..f6d1353 100644 --- a/MainScreenForm.cs +++ b/MainScreenForm.cs @@ -40,5 +40,12 @@ private void btnUpdate_Click(object sender, EventArgs e) numberUpdate.Show(); this.Hide(); } + + private void btnListing_Click(object sender, EventArgs e) + { + ListingPhonebook listingPhonebook = new ListingPhonebook(_dataAccess); + listingPhonebook.Show(); + this.Hide(); + } } } From c99870f750124aff2c7f511c99cc0e8e06b44bd9 Mon Sep 17 00:00:00 2001 From: Teslime Date: Fri, 17 Dec 2021 19:59:35 +0300 Subject: [PATCH 15/20] Added the design of the SearchingPhonebook form. --- SearchingPhonebook.Designer.cs | 169 +++++++++++++++++++++++++++------ 1 file changed, 140 insertions(+), 29 deletions(-) diff --git a/SearchingPhonebook.Designer.cs b/SearchingPhonebook.Designer.cs index d2a5cb1..e2576d6 100644 --- a/SearchingPhonebook.Designer.cs +++ b/SearchingPhonebook.Designer.cs @@ -29,26 +29,26 @@ protected override void Dispose(bool disposing) /// private void InitializeComponent() { - this.label1 = new System.Windows.Forms.Label(); this.txtNameSurname = new System.Windows.Forms.TextBox(); this.label2 = new System.Windows.Forms.Label(); - this.btnSearch = new System.Windows.Forms.Button(); + this.btnSearchNameSurname = new System.Windows.Forms.Button(); + this.label3 = new System.Windows.Forms.Label(); + this.label1 = new System.Windows.Forms.Label(); + this.label4 = new System.Windows.Forms.Label(); + this.txtNumber = new System.Windows.Forms.TextBox(); + this.btnSearchNumber = new System.Windows.Forms.Button(); + this.label5 = new System.Windows.Forms.Label(); + this.lblNumber = new System.Windows.Forms.Label(); + this.lblPersonId = new System.Windows.Forms.Label(); + this.lblNameSurname = new System.Windows.Forms.Label(); + this.pnlResultFound = new System.Windows.Forms.Panel(); + this.pnlResultFound.SuspendLayout(); this.SuspendLayout(); // - // label1 - // - this.label1.AutoSize = true; - this.label1.Font = new System.Drawing.Font("Microsoft Sans Serif", 14.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(162))); - this.label1.Location = new System.Drawing.Point(92, 76); - this.label1.Name = "label1"; - this.label1.Size = new System.Drawing.Size(547, 48); - this.label1.TabIndex = 0; - this.label1.Text = "Please enter the name or surname of the person whose number\r\nyou want to delete:"; - // // txtNameSurname // this.txtNameSurname.Font = new System.Drawing.Font("Microsoft Sans Serif", 14.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(162))); - this.txtNameSurname.Location = new System.Drawing.Point(250, 166); + this.txtNameSurname.Location = new System.Drawing.Point(256, 128); this.txtNameSurname.Name = "txtNameSurname"; this.txtNameSurname.Size = new System.Drawing.Size(198, 29); this.txtNameSurname.TabIndex = 6; @@ -57,43 +57,154 @@ private void InitializeComponent() // this.label2.AutoSize = true; this.label2.Font = new System.Drawing.Font("Microsoft Sans Serif", 11.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(162))); - this.label2.Location = new System.Drawing.Point(100, 166); + this.label2.Location = new System.Drawing.Point(106, 128); this.label2.Name = "label2"; this.label2.Size = new System.Drawing.Size(116, 18); this.label2.TabIndex = 5; this.label2.Text = "Name Surname:"; // - // btnSearch + // btnSearchNameSurname + // + this.btnSearchNameSurname.Font = new System.Drawing.Font("Microsoft Sans Serif", 11.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(162))); + this.btnSearchNameSurname.Location = new System.Drawing.Point(512, 119); + this.btnSearchNameSurname.Name = "btnSearchNameSurname"; + this.btnSearchNameSurname.Size = new System.Drawing.Size(133, 38); + this.btnSearchNameSurname.TabIndex = 7; + this.btnSearchNameSurname.Text = "Search"; + this.btnSearchNameSurname.UseVisualStyleBackColor = true; + // + // label3 + // + this.label3.AutoSize = true; + this.label3.Font = new System.Drawing.Font("Microsoft Sans Serif", 11.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(162))); + this.label3.Location = new System.Drawing.Point(84, 80); + this.label3.Name = "label3"; + this.label3.Size = new System.Drawing.Size(561, 18); + this.label3.TabIndex = 8; + this.label3.Text = "Please enter the name or surname of the person whose number you want to search:"; + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Font = new System.Drawing.Font("Microsoft Sans Serif", 11.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(162))); + this.label1.Location = new System.Drawing.Point(84, 209); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(467, 18); + this.label1.TabIndex = 9; + this.label1.Text = "Please enter the number of the person whose find you want to search:\r\n"; + // + // label4 + // + this.label4.AutoSize = true; + this.label4.Font = new System.Drawing.Font("Microsoft Sans Serif", 11.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(162))); + this.label4.Location = new System.Drawing.Point(106, 261); + this.label4.Name = "label4"; + this.label4.Size = new System.Drawing.Size(69, 18); + this.label4.TabIndex = 10; + this.label4.Text = "Number :"; + // + // txtNumber // - this.btnSearch.Font = new System.Drawing.Font("Microsoft Sans Serif", 11.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(162))); - this.btnSearch.Location = new System.Drawing.Point(506, 157); - this.btnSearch.Name = "btnSearch"; - this.btnSearch.Size = new System.Drawing.Size(133, 50); - this.btnSearch.TabIndex = 7; - this.btnSearch.Text = "Search"; - this.btnSearch.UseVisualStyleBackColor = true; + this.txtNumber.Font = new System.Drawing.Font("Microsoft Sans Serif", 14.25F); + this.txtNumber.Location = new System.Drawing.Point(256, 250); + this.txtNumber.Name = "txtNumber"; + this.txtNumber.Size = new System.Drawing.Size(198, 29); + this.txtNumber.TabIndex = 13; // - // DirectorySearching + // btnSearchNumber + // + this.btnSearchNumber.Font = new System.Drawing.Font("Microsoft Sans Serif", 11.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(162))); + this.btnSearchNumber.Location = new System.Drawing.Point(512, 241); + this.btnSearchNumber.Name = "btnSearchNumber"; + this.btnSearchNumber.Size = new System.Drawing.Size(133, 38); + this.btnSearchNumber.TabIndex = 14; + this.btnSearchNumber.Text = "Search"; + this.btnSearchNumber.UseVisualStyleBackColor = true; + // + // label5 + // + this.label5.AutoSize = true; + this.label5.Font = new System.Drawing.Font("Microsoft Sans Serif", 11.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(162))); + this.label5.Location = new System.Drawing.Point(19, 10); + this.label5.Name = "label5"; + this.label5.Size = new System.Drawing.Size(267, 18); + this.label5.TabIndex = 15; + this.label5.Text = "The person and number you are calling:"; + // + // lblNumber + // + this.lblNumber.AutoSize = true; + this.lblNumber.Font = new System.Drawing.Font("Microsoft Sans Serif", 11.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(162))); + this.lblNumber.Location = new System.Drawing.Point(399, 57); + this.lblNumber.Name = "lblNumber"; + this.lblNumber.Size = new System.Drawing.Size(0, 18); + this.lblNumber.TabIndex = 16; + // + // lblPersonId + // + this.lblPersonId.AutoSize = true; + this.lblPersonId.Font = new System.Drawing.Font("Microsoft Sans Serif", 11.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(162))); + this.lblPersonId.Location = new System.Drawing.Point(41, 57); + this.lblPersonId.Name = "lblPersonId"; + this.lblPersonId.Size = new System.Drawing.Size(0, 18); + this.lblPersonId.TabIndex = 17; + // + // lblNameSurname + // + this.lblNameSurname.AutoSize = true; + this.lblNameSurname.Font = new System.Drawing.Font("Microsoft Sans Serif", 11.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(162))); + this.lblNameSurname.Location = new System.Drawing.Point(208, 57); + this.lblNameSurname.Name = "lblNameSurname"; + this.lblNameSurname.Size = new System.Drawing.Size(0, 18); + this.lblNameSurname.TabIndex = 18; + // + // pnlResultFound + // + this.pnlResultFound.Controls.Add(this.label5); + this.pnlResultFound.Controls.Add(this.lblNumber); + this.pnlResultFound.Controls.Add(this.lblNameSurname); + this.pnlResultFound.Controls.Add(this.lblPersonId); + this.pnlResultFound.Location = new System.Drawing.Point(65, 336); + this.pnlResultFound.Name = "pnlResultFound"; + this.pnlResultFound.Size = new System.Drawing.Size(599, 100); + this.pnlResultFound.TabIndex = 19; + // + // SearchingPhonebook // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(800, 450); - this.Controls.Add(this.btnSearch); + this.Controls.Add(this.pnlResultFound); + this.Controls.Add(this.btnSearchNumber); + this.Controls.Add(this.txtNumber); + this.Controls.Add(this.label4); + this.Controls.Add(this.label1); + this.Controls.Add(this.label3); + this.Controls.Add(this.btnSearchNameSurname); this.Controls.Add(this.txtNameSurname); this.Controls.Add(this.label2); - this.Controls.Add(this.label1); - this.Name = "DirectorySearching"; + this.Name = "SearchingPhonebook"; this.Text = "Searching Phonebook"; + this.pnlResultFound.ResumeLayout(false); + this.pnlResultFound.PerformLayout(); this.ResumeLayout(false); this.PerformLayout(); } #endregion - - private System.Windows.Forms.Label label1; private System.Windows.Forms.TextBox txtNameSurname; private System.Windows.Forms.Label label2; - private System.Windows.Forms.Button btnSearch; + private System.Windows.Forms.Button btnSearchNameSurname; + private System.Windows.Forms.Label label3; + private System.Windows.Forms.Label label1; + private System.Windows.Forms.Label label4; + private System.Windows.Forms.TextBox txtNumber; + private System.Windows.Forms.Button btnSearchNumber; + private System.Windows.Forms.Label label5; + private System.Windows.Forms.Label lblNumber; + private System.Windows.Forms.Label lblPersonId; + private System.Windows.Forms.Label lblNameSurname; + private System.Windows.Forms.Panel pnlResultFound; } } \ No newline at end of file From 8d90618b1952e996011d9e4828f73b6160051804 Mon Sep 17 00:00:00 2001 From: Teslime Date: Fri, 17 Dec 2021 21:47:25 +0300 Subject: [PATCH 16/20] Added the ability to search by name and surname in the SearchingPhonebook form. --- DataAccess.cs | 1 - MainScreenForm.Designer.cs | 1 + MainScreenForm.cs | 7 +++++++ SearchingPhonebook.Designer.cs | 1 + SearchingPhonebook.cs | 29 ++++++++++++++++++++++++++++- 5 files changed, 37 insertions(+), 2 deletions(-) diff --git a/DataAccess.cs b/DataAccess.cs index 0fc06b3..dd60d38 100644 --- a/DataAccess.cs +++ b/DataAccess.cs @@ -121,7 +121,6 @@ public PersonDTO SearchForUpdatePerson(string _nameSurname) } } - reader.Close(); connectionSearch.Close(); diff --git a/MainScreenForm.Designer.cs b/MainScreenForm.Designer.cs index 7eeb670..cb638a1 100644 --- a/MainScreenForm.Designer.cs +++ b/MainScreenForm.Designer.cs @@ -106,6 +106,7 @@ private void InitializeComponent() this.btnSearching.TabIndex = 5; this.btnSearching.Text = "Searching The Directory"; this.btnSearching.UseVisualStyleBackColor = true; + this.btnSearching.Click += new System.EventHandler(this.btnSearching_Click); // // MainScreenForm // diff --git a/MainScreenForm.cs b/MainScreenForm.cs index f6d1353..f86cfb4 100644 --- a/MainScreenForm.cs +++ b/MainScreenForm.cs @@ -47,5 +47,12 @@ private void btnListing_Click(object sender, EventArgs e) listingPhonebook.Show(); this.Hide(); } + + private void btnSearching_Click(object sender, EventArgs e) + { + SearchingPhonebook searchingPhonebook = new SearchingPhonebook(_dataAccess); + searchingPhonebook.Show(); + this.Hide(); + } } } diff --git a/SearchingPhonebook.Designer.cs b/SearchingPhonebook.Designer.cs index e2576d6..64af766 100644 --- a/SearchingPhonebook.Designer.cs +++ b/SearchingPhonebook.Designer.cs @@ -72,6 +72,7 @@ private void InitializeComponent() this.btnSearchNameSurname.TabIndex = 7; this.btnSearchNameSurname.Text = "Search"; this.btnSearchNameSurname.UseVisualStyleBackColor = true; + this.btnSearchNameSurname.Click += new System.EventHandler(this.btnSearchNameSurname_Click); // // label3 // diff --git a/SearchingPhonebook.cs b/SearchingPhonebook.cs index d60e365..7483182 100644 --- a/SearchingPhonebook.cs +++ b/SearchingPhonebook.cs @@ -7,14 +7,41 @@ using System.Text; using System.Threading.Tasks; using System.Windows.Forms; +using Phonebook.models; namespace Phonebook { public partial class SearchingPhonebook : Form { - public SearchingPhonebook() + private readonly IDataAccess _dataAccess; + public SearchingPhonebook(IDataAccess _dataAccess) { InitializeComponent(); + this._dataAccess = _dataAccess; + } + + PersonDTO personDTO = new PersonDTO(); + + private void ResultSearchNameSurname() + { + personDTO = _dataAccess.SearchForUpdatePerson(txtNameSurname.Text); + + if(personDTO.PersonId == 0) + { + pnlResultFound.Visible = false; + + } + else + { + lblPersonId.Text = personDTO.PersonId.ToString(); + lblNameSurname.Text = personDTO.NameSurname; + lblNumber.Text = personDTO.Number; + } + } + + private void btnSearchNameSurname_Click(object sender, EventArgs e) + { + ResultSearchNameSurname(); } } } From f457186d79c635c74029f9ad4d85044797467e3c Mon Sep 17 00:00:00 2001 From: Teslime Date: Tue, 21 Dec 2021 15:11:10 +0300 Subject: [PATCH 17/20] Added SearchByNameNumber() method to search both by number and nameSurname. Applied to SearchingPhonebook. --- DataAccess.cs | 34 ++++++++++++++++++++++++++-------- IDataAccess.cs | 2 +- NumberUpdate.cs | 2 +- SearchingPhonebook.Designer.cs | 1 + SearchingPhonebook.cs | 13 +++++++++---- 5 files changed, 38 insertions(+), 14 deletions(-) diff --git a/DataAccess.cs b/DataAccess.cs index dd60d38..198721e 100644 --- a/DataAccess.cs +++ b/DataAccess.cs @@ -73,8 +73,8 @@ public void RegisterDatabase(PersonDTO personDTO) string registerPerson = "Insert into Person(NameSurname, Number) values(@NameSurname, @Number)"; SqlCommand sqlCommand = new SqlCommand(registerPerson, connectionRegister); - sqlCommand.Parameters.Add(new System.Data.SqlClient.SqlParameter("@NameSurname", SqlDbType.NChar, 15) { Value = personDTO.NameSurname }); - sqlCommand.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Number", SqlDbType.VarChar, 11) { Value = personDTO.Number }); + sqlCommand.Parameters.Add(new System.Data.SqlClient.SqlParameter("@NameSurname", SqlDbType.NChar, 250) { Value = personDTO.NameSurname }); + sqlCommand.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Number", SqlDbType.VarChar, 16) { Value = personDTO.Number }); sqlCommand.ExecuteNonQuery(); connectionRegister.Close(); } @@ -88,17 +88,35 @@ public PersonDTO MapperSearchForUpdatePerson(Person person) return personDTO; } - public PersonDTO SearchForUpdatePerson(string _nameSurname) + public PersonDTO SearchByNameNumber(string _nameSurname, string _number) { using (var connectionSearch = new SqlConnection(connectionString)) { connectionSearch.Open(); Person person = new Person(); - string SearchQuery = "SELECT TOP 1 PersonId, NameSurname, Number FROM Person WHERE NameSurname LIKE '%'+ @NameSurname +'%'"; + string SearchQuery; + + if(_number == null) + { + SearchQuery = "SELECT TOP 1 PersonId, NameSurname, Number FROM Person WHERE NameSurname LIKE '%'+ @NameSurname +'%'"; + } + else + { + SearchQuery = "SELECT TOP 1 PersonId, NameSurname, Number FROM Person WHERE Number = @Number"; + } + var cmd = new SqlCommand(SearchQuery, connectionSearch); - cmd.Parameters.Add(new System.Data.SqlClient.SqlParameter("@NameSurname", SqlDbType.NVarChar, 250) { Value = _nameSurname }); - + + if(_number == null) + { + cmd.Parameters.Add(new System.Data.SqlClient.SqlParameter("@NameSurname", SqlDbType.NVarChar, 250) { Value = _nameSurname }); + } + else + { + cmd.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Number", SqlDbType.VarChar, 16) { Value = _number }); + } + var reader = cmd.ExecuteReader(); if(!reader.HasRows) @@ -137,8 +155,8 @@ public void UpdatePerson(PersonDTO personDTO) string UpdateQuery = "Update Person SET NameSurname = @NameSurname , Number = @Number where PersonId = @PersonId "; var cmd = new SqlCommand(UpdateQuery, ConnectionUpdate); cmd.Parameters.Add(new System.Data.SqlClient.SqlParameter("@PersonId", SqlDbType.Int) { Value = personDTO.PersonId }); - cmd.Parameters.Add(new System.Data.SqlClient.SqlParameter("@NameSurname", SqlDbType.NChar, 15) { Value = personDTO.NameSurname }); - cmd.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Number", SqlDbType.VarChar, 11) { Value = personDTO.Number }); + cmd.Parameters.Add(new System.Data.SqlClient.SqlParameter("@NameSurname", SqlDbType.NChar, 250) { Value = personDTO.NameSurname }); + cmd.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Number", SqlDbType.VarChar, 16) { Value = personDTO.Number }); cmd.ExecuteNonQuery(); ConnectionUpdate.Close(); diff --git a/IDataAccess.cs b/IDataAccess.cs index 6b1d1d4..1228665 100644 --- a/IDataAccess.cs +++ b/IDataAccess.cs @@ -13,7 +13,7 @@ public interface IDataAccess int SearchPerson(PersonDTO personDTO); void DeletePerson(PersonDTO personDTO); void UpdatePerson(PersonDTO personDTO); - PersonDTO SearchForUpdatePerson(string _nameSurname); + PersonDTO SearchByNameNumber(string _nameSurname, string _number); PersonDTO MapperSearchForUpdatePerson(Person person); List ListingPhonebook(); List MapperListingPhonebook(List person); diff --git a/NumberUpdate.cs b/NumberUpdate.cs index 0cd6e8f..a865bf8 100644 --- a/NumberUpdate.cs +++ b/NumberUpdate.cs @@ -38,7 +38,7 @@ private void MapperFilledField() private void ResultForm() { - personDTO = _dataAccess.SearchForUpdatePerson(txtNameSurname.Text); + personDTO = _dataAccess.SearchByNameNumber(txtNameSurname.Text, null); if (personDTO.PersonId == 0) { diff --git a/SearchingPhonebook.Designer.cs b/SearchingPhonebook.Designer.cs index 64af766..bd5c002 100644 --- a/SearchingPhonebook.Designer.cs +++ b/SearchingPhonebook.Designer.cs @@ -121,6 +121,7 @@ private void InitializeComponent() this.btnSearchNumber.TabIndex = 14; this.btnSearchNumber.Text = "Search"; this.btnSearchNumber.UseVisualStyleBackColor = true; + this.btnSearchNumber.Click += new System.EventHandler(this.btnSearchNumber_Click); // // label5 // diff --git a/SearchingPhonebook.cs b/SearchingPhonebook.cs index 7483182..6dcd182 100644 --- a/SearchingPhonebook.cs +++ b/SearchingPhonebook.cs @@ -22,10 +22,8 @@ public SearchingPhonebook(IDataAccess _dataAccess) PersonDTO personDTO = new PersonDTO(); - private void ResultSearchNameSurname() + private void ResultSearch() { - personDTO = _dataAccess.SearchForUpdatePerson(txtNameSurname.Text); - if(personDTO.PersonId == 0) { pnlResultFound.Visible = false; @@ -40,8 +38,15 @@ private void ResultSearchNameSurname() } private void btnSearchNameSurname_Click(object sender, EventArgs e) + { + personDTO = _dataAccess.SearchByNameNumber(txtNameSurname.Text, null); + ResultSearch(); + } + + private void btnSearchNumber_Click(object sender, EventArgs e) { - ResultSearchNameSurname(); + personDTO = _dataAccess.SearchByNameNumber(null, txtNumber.Text); + ResultSearch(); } } } From da6a13c5ced164e57e6c5b5e9fb558acd45226e1 Mon Sep 17 00:00:00 2001 From: Teslime Date: Tue, 21 Dec 2021 15:16:53 +0300 Subject: [PATCH 18/20] Changed has been name. --- MainScreenForm.Designer.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/MainScreenForm.Designer.cs b/MainScreenForm.Designer.cs index cb638a1..650fd5e 100644 --- a/MainScreenForm.Designer.cs +++ b/MainScreenForm.Designer.cs @@ -92,7 +92,7 @@ private void InitializeComponent() this.btnListing.Name = "btnListing"; this.btnListing.Size = new System.Drawing.Size(196, 98); this.btnListing.TabIndex = 4; - this.btnListing.Text = "Listing The Directory"; + this.btnListing.Text = "Listing The Phonebook"; this.btnListing.UseVisualStyleBackColor = true; this.btnListing.Click += new System.EventHandler(this.btnListing_Click); // @@ -104,7 +104,7 @@ private void InitializeComponent() this.btnSearching.Name = "btnSearching"; this.btnSearching.Size = new System.Drawing.Size(196, 98); this.btnSearching.TabIndex = 5; - this.btnSearching.Text = "Searching The Directory"; + this.btnSearching.Text = "Searching The Phonebook"; this.btnSearching.UseVisualStyleBackColor = true; this.btnSearching.Click += new System.EventHandler(this.btnSearching_Click); // From a97cce31e53a76e06c24da9ea29d4a10cbcc0d63 Mon Sep 17 00:00:00 2001 From: Teslime Date: Thu, 23 Dec 2021 22:29:23 +0300 Subject: [PATCH 19/20] Added a back button to return to the main page. --- ListingPhonebook.Designer.cs | 14 ++++++++++++++ ListingPhonebook.cs | 8 ++++++++ NewNumberRegister.Designer.cs | 20 +++++++++++++++++--- NewNumberRegister.cs | 8 +++++++- NumberDelete.Designer.cs | 1 + NumberDelete.cs | 8 +++++++- NumberUpdate.Designer.cs | 16 +++++++++++++++- NumberUpdate.cs | 9 ++++++--- SearchingPhonebook.Designer.cs | 15 +++++++++++++++ SearchingPhonebook.cs | 9 +++++++++ 10 files changed, 99 insertions(+), 9 deletions(-) diff --git a/ListingPhonebook.Designer.cs b/ListingPhonebook.Designer.cs index 56125c7..5035408 100644 --- a/ListingPhonebook.Designer.cs +++ b/ListingPhonebook.Designer.cs @@ -34,6 +34,7 @@ private void InitializeComponent() this.NameSurname = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); this.Number = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); this.label1 = new System.Windows.Forms.Label(); + this.btnBack = new System.Windows.Forms.Button(); this.SuspendLayout(); // // listViewPhonebook @@ -76,11 +77,23 @@ private void InitializeComponent() this.label1.TabIndex = 2; this.label1.Text = "Phonebook :"; // + // btnBack + // + this.btnBack.Font = new System.Drawing.Font("Microsoft Sans Serif", 11.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(162))); + this.btnBack.Location = new System.Drawing.Point(638, 384); + this.btnBack.Name = "btnBack"; + this.btnBack.Size = new System.Drawing.Size(125, 33); + this.btnBack.TabIndex = 15; + this.btnBack.Text = "Back"; + this.btnBack.UseVisualStyleBackColor = true; + this.btnBack.Click += new System.EventHandler(this.btnBack_Click); + // // ListingPhonebook // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(800, 450); + this.Controls.Add(this.btnBack); this.Controls.Add(this.label1); this.Controls.Add(this.listViewPhonebook); this.Name = "ListingPhonebook"; @@ -98,5 +111,6 @@ private void InitializeComponent() private System.Windows.Forms.ColumnHeader Number; public System.Windows.Forms.ColumnHeader NameSurname; private System.Windows.Forms.Label label1; + private System.Windows.Forms.Button btnBack; } } \ No newline at end of file diff --git a/ListingPhonebook.cs b/ListingPhonebook.cs index c2459d8..fddf246 100644 --- a/ListingPhonebook.cs +++ b/ListingPhonebook.cs @@ -40,5 +40,13 @@ private void ListingPhonebook_Load(object sender, EventArgs e) { ShowListingPhonebook(); } + + private void btnBack_Click(object sender, EventArgs e) + { + MainScreenForm mainScreenForm = new MainScreenForm(); + mainScreenForm.Show(); + this.Hide(); + + } } } diff --git a/NewNumberRegister.Designer.cs b/NewNumberRegister.Designer.cs index 9a186b6..3d543cf 100644 --- a/NewNumberRegister.Designer.cs +++ b/NewNumberRegister.Designer.cs @@ -36,6 +36,7 @@ private void InitializeComponent() this.txtNameSurname = new System.Windows.Forms.TextBox(); this.txtNumber = new System.Windows.Forms.TextBox(); this.label4 = new System.Windows.Forms.Label(); + this.btnBack = new System.Windows.Forms.Button(); this.SuspendLayout(); // // label1 @@ -70,7 +71,7 @@ private void InitializeComponent() // btnRegister // this.btnRegister.Font = new System.Drawing.Font("Microsoft Sans Serif", 11.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(162))); - this.btnRegister.Location = new System.Drawing.Point(536, 325); + this.btnRegister.Location = new System.Drawing.Point(363, 291); this.btnRegister.Name = "btnRegister"; this.btnRegister.Size = new System.Drawing.Size(133, 50); this.btnRegister.TabIndex = 3; @@ -81,7 +82,7 @@ private void InitializeComponent() // txtNameSurname // this.txtNameSurname.Font = new System.Drawing.Font("Microsoft Sans Serif", 14.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(162))); - this.txtNameSurname.Location = new System.Drawing.Point(239, 143); + this.txtNameSurname.Location = new System.Drawing.Point(298, 143); this.txtNameSurname.Name = "txtNameSurname"; this.txtNameSurname.Size = new System.Drawing.Size(198, 29); this.txtNameSurname.TabIndex = 4; @@ -89,7 +90,7 @@ private void InitializeComponent() // txtNumber // this.txtNumber.Font = new System.Drawing.Font("Microsoft Sans Serif", 14.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(162))); - this.txtNumber.Location = new System.Drawing.Point(239, 206); + this.txtNumber.Location = new System.Drawing.Point(298, 206); this.txtNumber.Name = "txtNumber"; this.txtNumber.Size = new System.Drawing.Size(198, 29); this.txtNumber.TabIndex = 6; @@ -104,11 +105,23 @@ private void InitializeComponent() this.label4.TabIndex = 7; this.label4.Text = "Enter the number you want to save:"; // + // btnBack + // + this.btnBack.Font = new System.Drawing.Font("Microsoft Sans Serif", 11.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(162))); + this.btnBack.Location = new System.Drawing.Point(632, 389); + this.btnBack.Name = "btnBack"; + this.btnBack.Size = new System.Drawing.Size(125, 33); + this.btnBack.TabIndex = 15; + this.btnBack.Text = "Back"; + this.btnBack.UseVisualStyleBackColor = true; + this.btnBack.Click += new System.EventHandler(this.btnBack_Click); + // // NewNumberRegister // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(800, 450); + this.Controls.Add(this.btnBack); this.Controls.Add(this.label4); this.Controls.Add(this.txtNumber); this.Controls.Add(this.txtNameSurname); @@ -132,5 +145,6 @@ private void InitializeComponent() private System.Windows.Forms.TextBox txtNameSurname; private System.Windows.Forms.TextBox txtNumber; private System.Windows.Forms.Label label4; + private System.Windows.Forms.Button btnBack; } } \ No newline at end of file diff --git a/NewNumberRegister.cs b/NewNumberRegister.cs index 998cd4c..42b3d3a 100644 --- a/NewNumberRegister.cs +++ b/NewNumberRegister.cs @@ -45,6 +45,12 @@ private void btnRegister_Click(object sender, EventArgs e) } - + private void btnBack_Click(object sender, EventArgs e) + { + MainScreenForm mainScreenForm = new MainScreenForm(); + mainScreenForm.Show(); + this.Hide(); + + } } } diff --git a/NumberDelete.Designer.cs b/NumberDelete.Designer.cs index f693c72..8c68ab0 100644 --- a/NumberDelete.Designer.cs +++ b/NumberDelete.Designer.cs @@ -143,6 +143,7 @@ private void InitializeComponent() this.btnBack.TabIndex = 14; this.btnBack.Text = "Back"; this.btnBack.UseVisualStyleBackColor = true; + this.btnBack.Click += new System.EventHandler(this.btnBack_Click); // // NumberDelete // diff --git a/NumberDelete.cs b/NumberDelete.cs index fd25949..990be08 100644 --- a/NumberDelete.cs +++ b/NumberDelete.cs @@ -63,6 +63,12 @@ private void btnNo_Click(object sender, EventArgs e) MessageBox.Show("No action was taken."); } - + private void btnBack_Click(object sender, EventArgs e) + { + MainScreenForm mainScreenForm = new MainScreenForm(); + mainScreenForm.Show(); + this.Hide(); + + } } } diff --git a/NumberUpdate.Designer.cs b/NumberUpdate.Designer.cs index d1c086e..5219d69 100644 --- a/NumberUpdate.Designer.cs +++ b/NumberUpdate.Designer.cs @@ -41,6 +41,7 @@ private void InitializeComponent() this.label3 = new System.Windows.Forms.Label(); this.txtNameSurname = new System.Windows.Forms.TextBox(); this.label1 = new System.Windows.Forms.Label(); + this.btnBack = new System.Windows.Forms.Button(); this.pnlUpdate.SuspendLayout(); this.SuspendLayout(); // @@ -55,7 +56,7 @@ private void InitializeComponent() this.pnlUpdate.Controls.Add(this.lblSureQuery); this.pnlUpdate.Location = new System.Drawing.Point(43, 155); this.pnlUpdate.Name = "pnlUpdate"; - this.pnlUpdate.Size = new System.Drawing.Size(687, 283); + this.pnlUpdate.Size = new System.Drawing.Size(577, 283); this.pnlUpdate.TabIndex = 7; this.pnlUpdate.Visible = false; // @@ -163,11 +164,23 @@ private void InitializeComponent() this.label1.TabIndex = 8; this.label1.Text = "Please enter the name or surname of the person whose number you want to update:"; // + // btnBack + // + this.btnBack.Font = new System.Drawing.Font("Microsoft Sans Serif", 11.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(162))); + this.btnBack.Location = new System.Drawing.Point(637, 385); + this.btnBack.Name = "btnBack"; + this.btnBack.Size = new System.Drawing.Size(125, 33); + this.btnBack.TabIndex = 15; + this.btnBack.Text = "Back"; + this.btnBack.UseVisualStyleBackColor = true; + this.btnBack.Click += new System.EventHandler(this.btnBack_Click); + // // NumberUpdate // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(800, 450); + this.Controls.Add(this.btnBack); this.Controls.Add(this.pnlUpdate); this.Controls.Add(this.btnSearch); this.Controls.Add(this.label3); @@ -196,5 +209,6 @@ private void InitializeComponent() private System.Windows.Forms.Label label4; private System.Windows.Forms.Label label2; private System.Windows.Forms.TextBox pnlNameSurname; + private System.Windows.Forms.Button btnBack; } } \ No newline at end of file diff --git a/NumberUpdate.cs b/NumberUpdate.cs index a865bf8..7c75012 100644 --- a/NumberUpdate.cs +++ b/NumberUpdate.cs @@ -64,14 +64,17 @@ private void btnUpdate_Click(object sender, EventArgs e) } private void btnCancel_Click(object sender, EventArgs e) + { + + MessageBox.Show("No action was taken."); + } + + private void btnBack_Click(object sender, EventArgs e) { MainScreenForm mainScreenForm = new MainScreenForm(); mainScreenForm.Show(); this.Hide(); - MessageBox.Show("No action was taken."); } - - } } diff --git a/SearchingPhonebook.Designer.cs b/SearchingPhonebook.Designer.cs index bd5c002..6e6efe6 100644 --- a/SearchingPhonebook.Designer.cs +++ b/SearchingPhonebook.Designer.cs @@ -42,6 +42,7 @@ private void InitializeComponent() this.lblPersonId = new System.Windows.Forms.Label(); this.lblNameSurname = new System.Windows.Forms.Label(); this.pnlResultFound = new System.Windows.Forms.Panel(); + this.btnBack = new System.Windows.Forms.Button(); this.pnlResultFound.SuspendLayout(); this.SuspendLayout(); // @@ -170,12 +171,25 @@ private void InitializeComponent() this.pnlResultFound.Name = "pnlResultFound"; this.pnlResultFound.Size = new System.Drawing.Size(599, 100); this.pnlResultFound.TabIndex = 19; + this.pnlResultFound.Visible = false; + // + // btnBack + // + this.btnBack.Font = new System.Drawing.Font("Microsoft Sans Serif", 11.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(162))); + this.btnBack.Location = new System.Drawing.Point(636, 393); + this.btnBack.Name = "btnBack"; + this.btnBack.Size = new System.Drawing.Size(125, 33); + this.btnBack.TabIndex = 20; + this.btnBack.Text = "Back"; + this.btnBack.UseVisualStyleBackColor = true; + this.btnBack.Click += new System.EventHandler(this.btnBack_Click); // // SearchingPhonebook // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(800, 450); + this.Controls.Add(this.btnBack); this.Controls.Add(this.pnlResultFound); this.Controls.Add(this.btnSearchNumber); this.Controls.Add(this.txtNumber); @@ -208,5 +222,6 @@ private void InitializeComponent() private System.Windows.Forms.Label lblPersonId; private System.Windows.Forms.Label lblNameSurname; private System.Windows.Forms.Panel pnlResultFound; + private System.Windows.Forms.Button btnBack; } } \ No newline at end of file diff --git a/SearchingPhonebook.cs b/SearchingPhonebook.cs index 6dcd182..ecaf349 100644 --- a/SearchingPhonebook.cs +++ b/SearchingPhonebook.cs @@ -31,6 +31,7 @@ private void ResultSearch() } else { + pnlResultFound.Visible = true; lblPersonId.Text = personDTO.PersonId.ToString(); lblNameSurname.Text = personDTO.NameSurname; lblNumber.Text = personDTO.Number; @@ -48,5 +49,13 @@ private void btnSearchNumber_Click(object sender, EventArgs e) personDTO = _dataAccess.SearchByNameNumber(null, txtNumber.Text); ResultSearch(); } + + private void btnBack_Click(object sender, EventArgs e) + { + MainScreenForm mainScreenForm = new MainScreenForm(); + mainScreenForm.Show(); + this.Hide(); + + } } } From ba2d0fee63b2568c8d5a410aeafe55991e07695e Mon Sep 17 00:00:00 2001 From: Teslime Date: Thu, 23 Dec 2021 22:43:37 +0300 Subject: [PATCH 20/20] In the opening, the page is fixed in one point. --- ListingPhonebook.Designer.cs | 1 + MainScreenForm.Designer.cs | 1 + NewNumberRegister.Designer.cs | 1 + NumberDelete.Designer.cs | 1 + NumberUpdate.Designer.cs | 1 + SearchingPhonebook.Designer.cs | 1 + 6 files changed, 6 insertions(+) diff --git a/ListingPhonebook.Designer.cs b/ListingPhonebook.Designer.cs index 5035408..08001ea 100644 --- a/ListingPhonebook.Designer.cs +++ b/ListingPhonebook.Designer.cs @@ -97,6 +97,7 @@ private void InitializeComponent() this.Controls.Add(this.label1); this.Controls.Add(this.listViewPhonebook); this.Name = "ListingPhonebook"; + this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; this.Text = "Listing Phonebook"; this.Load += new System.EventHandler(this.ListingPhonebook_Load); this.ResumeLayout(false); diff --git a/MainScreenForm.Designer.cs b/MainScreenForm.Designer.cs index 650fd5e..9b4f104 100644 --- a/MainScreenForm.Designer.cs +++ b/MainScreenForm.Designer.cs @@ -122,6 +122,7 @@ private void InitializeComponent() this.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(162))); this.Margin = new System.Windows.Forms.Padding(4); this.Name = "MainScreenForm"; + this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; this.Text = "Main Screen"; this.ResumeLayout(false); this.PerformLayout(); diff --git a/NewNumberRegister.Designer.cs b/NewNumberRegister.Designer.cs index 3d543cf..a64dfdb 100644 --- a/NewNumberRegister.Designer.cs +++ b/NewNumberRegister.Designer.cs @@ -130,6 +130,7 @@ private void InitializeComponent() this.Controls.Add(this.label2); this.Controls.Add(this.label1); this.Name = "NewNumberRegister"; + this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; this.Text = "Add To Directory"; this.ResumeLayout(false); this.PerformLayout(); diff --git a/NumberDelete.Designer.cs b/NumberDelete.Designer.cs index 8c68ab0..b5b9720 100644 --- a/NumberDelete.Designer.cs +++ b/NumberDelete.Designer.cs @@ -157,6 +157,7 @@ private void InitializeComponent() this.Controls.Add(this.btnSearch); this.Controls.Add(this.label1); this.Name = "NumberDelete"; + this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; this.Text = "Delete The Number"; this.pnlDelete.ResumeLayout(false); this.pnlDelete.PerformLayout(); diff --git a/NumberUpdate.Designer.cs b/NumberUpdate.Designer.cs index 5219d69..0af6471 100644 --- a/NumberUpdate.Designer.cs +++ b/NumberUpdate.Designer.cs @@ -187,6 +187,7 @@ private void InitializeComponent() this.Controls.Add(this.txtNameSurname); this.Controls.Add(this.label1); this.Name = "NumberUpdate"; + this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; this.Text = "Update Person "; this.pnlUpdate.ResumeLayout(false); this.pnlUpdate.PerformLayout(); diff --git a/SearchingPhonebook.Designer.cs b/SearchingPhonebook.Designer.cs index 6e6efe6..058d817 100644 --- a/SearchingPhonebook.Designer.cs +++ b/SearchingPhonebook.Designer.cs @@ -200,6 +200,7 @@ private void InitializeComponent() this.Controls.Add(this.txtNameSurname); this.Controls.Add(this.label2); this.Name = "SearchingPhonebook"; + this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; this.Text = "Searching Phonebook"; this.pnlResultFound.ResumeLayout(false); this.pnlResultFound.PerformLayout();