diff --git a/Assets/logo-image.png b/Assets/logo-image.png new file mode 100644 index 0000000..094431c Binary files /dev/null and b/Assets/logo-image.png differ diff --git a/Release/Win64-installer.rar b/Release/Win64-installer.rar new file mode 100644 index 0000000..8650d07 Binary files /dev/null and b/Release/Win64-installer.rar differ diff --git a/WindowsApp/Data/DbContext.cs b/WindowsApp/Data/DbContext.cs index 21d72b0..21470eb 100644 --- a/WindowsApp/Data/DbContext.cs +++ b/WindowsApp/Data/DbContext.cs @@ -5,12 +5,21 @@ namespace PartsHunter.Data { public class PartsHunterContext : DbContext { public DbSet Components { get; set; } public DbSet HardwareDevice { get; set; } + private string dbPath = "Data\\Tables\\PartsHunter.db"; + protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { - optionsBuilder.UseSqlite("Data Source=PartsHunter.db"); + // Create directories if they do not exist + var directory = Path.GetDirectoryName(dbPath); + if (!Directory.Exists(directory)) { + Directory.CreateDirectory(directory); + } + + optionsBuilder.UseSqlite($"Data Source={dbPath}"); } + protected override void OnModelCreating(ModelBuilder modelBuilder) { base.OnModelCreating(modelBuilder); modelBuilder.Entity().ToTable("HardwareDevice"); } } -} \ No newline at end of file +} diff --git a/WindowsApp/PartsHunter.db b/WindowsApp/Data/Tables/PartsHunter.db similarity index 98% rename from WindowsApp/PartsHunter.db rename to WindowsApp/Data/Tables/PartsHunter.db index b96c19a..04fafc0 100644 Binary files a/WindowsApp/PartsHunter.db and b/WindowsApp/Data/Tables/PartsHunter.db differ diff --git a/WindowsApp/How to Regenerate the Database in EF Core.txt b/WindowsApp/How to Regenerate the Database in EF Core.txt index 58a70ba..70f5272 100644 --- a/WindowsApp/How to Regenerate the Database in EF Core.txt +++ b/WindowsApp/How to Regenerate the Database in EF Core.txt @@ -9,7 +9,7 @@ Remove the following directories and files from your project: Any existing *.db files (your database file). Clean the Solution: -In your IDE (e.g., Visual Studio), navigate to Build → Clean Solution to remove temporary files and ensure a clean build. +In Visual Studio, navigate to Build → Clean Solution to remove temporary files and ensure a clean build. Open the Package Manager Console: Go to Tools → NuGet Package Manager → Package Manager Console. @@ -26,4 +26,4 @@ Confirm that the new database and schema are created as expected. Notes: Make sure your DbContext and entity classes are correctly set up before regenerating the database. Use meaningful migration names instead of InitialCreate when adding migrations for clarity in version control. -If using a source control system, commit your changes to the migration folder after verifying the database generation. \ No newline at end of file +If using a source control system, commit your changes to the migration folder after verifying the database generation. diff --git a/WindowsApp/Migrations/20241123113103_MyStock.Designer.cs b/WindowsApp/Migrations/20241124123129_MyComponents.Designer.cs similarity index 96% rename from WindowsApp/Migrations/20241123113103_MyStock.Designer.cs rename to WindowsApp/Migrations/20241124123129_MyComponents.Designer.cs index c586702..98c6537 100644 --- a/WindowsApp/Migrations/20241123113103_MyStock.Designer.cs +++ b/WindowsApp/Migrations/20241124123129_MyComponents.Designer.cs @@ -10,8 +10,8 @@ namespace PartsHunter.Migrations { [DbContext(typeof(PartsHunterContext))] - [Migration("20241123113103_MyStock")] - partial class MyStock + [Migration("20241124123129_MyComponents")] + partial class MyComponents { /// protected override void BuildTargetModel(ModelBuilder modelBuilder) diff --git a/WindowsApp/Migrations/20241123113103_MyStock.cs b/WindowsApp/Migrations/20241124123129_MyComponents.cs similarity index 97% rename from WindowsApp/Migrations/20241123113103_MyStock.cs rename to WindowsApp/Migrations/20241124123129_MyComponents.cs index 1892cf8..b2b3f2c 100644 --- a/WindowsApp/Migrations/20241123113103_MyStock.cs +++ b/WindowsApp/Migrations/20241124123129_MyComponents.cs @@ -5,7 +5,7 @@ namespace PartsHunter.Migrations { /// - public partial class MyStock : Migration + public partial class MyComponents : Migration { /// protected override void Up(MigrationBuilder migrationBuilder) diff --git a/WindowsApp/PartsHunter.csproj b/WindowsApp/PartsHunter.csproj index 7a93931..62a4052 100644 --- a/WindowsApp/PartsHunter.csproj +++ b/WindowsApp/PartsHunter.csproj @@ -6,6 +6,18 @@ enable true enable + PartsHunter.Program + PartsHunter + Tiago Silva + Controlando Elétrons + PartsHunter is an electronic component organization system designed for efficiency and precision. It consists of three core modules: + +Windows Application: A user-friendly interface for searching and managing components by description. +Hardware Device: A communication module that interacts with the Windows application to activate LEDs, pinpointing the location of each component. +Mechanical Assembly: A storage system that organizes components across dedicated slots. + https://github.com/import-tiago/PartsHunter + logo-image.png + https://github.com/import-tiago/PartsHunter logo_icon.ico @@ -28,6 +40,11 @@ True Resources.resx + + True + True + Settings.settings + @@ -37,4 +54,22 @@ + + + + + + + True + \ + + + + + + SettingsSingleFileGenerator + Settings.Designer.cs + + + \ No newline at end of file diff --git a/WindowsApp/Properties/Settings.Designer.cs b/WindowsApp/Properties/Settings.Designer.cs new file mode 100644 index 0000000..33d5abd --- /dev/null +++ b/WindowsApp/Properties/Settings.Designer.cs @@ -0,0 +1,26 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace PartsHunter.Properties { + + + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "17.11.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 { + return defaultInstance; + } + } + } +} diff --git a/WindowsApp/Properties/Settings.settings b/WindowsApp/Properties/Settings.settings new file mode 100644 index 0000000..049245f --- /dev/null +++ b/WindowsApp/Properties/Settings.settings @@ -0,0 +1,6 @@ + + + + + + diff --git a/WindowsApp/Services/HardwareDeviceService.cs b/WindowsApp/Services/HardwareDeviceService.cs index 2ffcd13..d6b3bde 100644 --- a/WindowsApp/Services/HardwareDeviceService.cs +++ b/WindowsApp/Services/HardwareDeviceService.cs @@ -93,20 +93,27 @@ public async void turn_on_pixels(List pixels) { } } - public async Task clear_pixels() { - try { - var endpoint = $"http://{ip_addr}/clear"; - var response = await httpClient.PostAsync(endpoint, null); - if (response.IsSuccessStatusCode) { - Debug.WriteLine("Pixels cleared successfully!"); + public async Task clear_pixels(int retries = 3, int delay = 2000) { + + for (int attempt = 0; attempt < retries; attempt++) { + try { + var endpoint = $"http://{ip_addr}/clear"; + var response = await httpClient.PostAsync(endpoint, null); + + if (response.IsSuccessStatusCode) { + return true; + } + else { + Debug.WriteLine($"Attempt {attempt + 1} failed: Status code {response.StatusCode}"); + } } - else { - Debug.WriteLine($"Failed to clear pixels. Status code: {response.StatusCode}"); + catch (Exception ex) { + Debug.WriteLine($"Attempt {attempt + 1} exception: {ex.Message}"); } + + await Task.Delay(delay); } - catch (Exception ex) { - Debug.WriteLine($"Exception occurred: {ex.Message}"); - } + return false; } } } \ No newline at end of file diff --git a/WindowsApp/Views/Form1.Designer.cs b/WindowsApp/Views/Form1.Designer.cs index 65db9a5..f76742a 100644 --- a/WindowsApp/Views/Form1.Designer.cs +++ b/WindowsApp/Views/Form1.Designer.cs @@ -166,6 +166,7 @@ private void InitializeComponent() { // // dgvBoM // + dgvBoM.AllowUserToAddRows = false; dgvBoM.AllowUserToResizeRows = false; dgvBoM.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; dgvBoM.BackgroundColor = SystemColors.ControlLightLight; diff --git a/WindowsApp/Views/Form1.cs b/WindowsApp/Views/Form1.cs index 10217d4..d1382e5 100644 --- a/WindowsApp/Views/Form1.cs +++ b/WindowsApp/Views/Form1.cs @@ -211,7 +211,6 @@ private void trackBarBright_ValueChanged(object sender, EventArgs e) { private void buttonClear_Click(object sender, EventArgs e) { hardware_device.clear_pixels(); } - int selected_database_id; private void dgvStock_SelectionChanged(object sender, EventArgs e) { @@ -307,8 +306,8 @@ private async void btnShowAll_Click(object sender, EventArgs e) { foreach (DataGridViewRow row in dgvBoM.Rows) { if (row.Cells["SlotID"].Value != null) { - int slotId = Convert.ToInt32(row.Cells["SlotID"].Value); - pixels.Add(slotId); + int pixel = Convert.ToInt32(row.Cells["SlotID"].Value) - 1; + pixels.Add(pixel); } } hardware_device.turn_on_pixels(pixels); @@ -395,7 +394,6 @@ private void buttonSaveFromFile_Click(object sender, EventArgs e) { MessageBox.Show("Please specify a valid .txt file."); } } - public bool is_ip_valid(string ip_addr) { string pattern = @"^((25[0-5]|2[0-4][0-9]|[0-1]?[0-9][0-9]?)\.){3}(25[0-5]|2[0-4][0-9]|[0-1]?[0-9][0-9]?)$"; return Regex.IsMatch(ip_addr, pattern); @@ -423,10 +421,12 @@ private void pictureBoxEditIP_Click(object sender, EventArgs e) { edit_ip = !edit_ip; tbIP.Enabled = edit_ip; } - private async void Form1_FormClosing(object sender, FormClosingEventArgs e) { - await hardware_device.clear_pixels(); - Task.Delay(5000).Wait(); // Wait synchronously for demonstration + bool pixelsCleared = await hardware_device.clear_pixels(); + if (!pixelsCleared) { + Debug.WriteLine("Failed to clear pixels after multiple attempts."); + } + await Task.Delay(5000); } } } \ No newline at end of file