commit e5d1f72e7d7772566ce810f326d0b98940fad4b4 Author: Guitaras_Fingerchpoker Date: Thu May 15 11:20:37 2025 +0300 first commit diff --git a/.vs/AvaloniaAppApplication/DesignTimeBuild/.dtbcache.v2 b/.vs/AvaloniaAppApplication/DesignTimeBuild/.dtbcache.v2 new file mode 100644 index 0000000..82667da Binary files /dev/null and b/.vs/AvaloniaAppApplication/DesignTimeBuild/.dtbcache.v2 differ diff --git a/.vs/AvaloniaAppApplication/FileContentIndex/a5cb4664-7b72-446b-8075-3a66931ce577.vsidx b/.vs/AvaloniaAppApplication/FileContentIndex/a5cb4664-7b72-446b-8075-3a66931ce577.vsidx new file mode 100644 index 0000000..3ec56ad Binary files /dev/null and b/.vs/AvaloniaAppApplication/FileContentIndex/a5cb4664-7b72-446b-8075-3a66931ce577.vsidx differ diff --git a/.vs/AvaloniaAppApplication/v17/.futdcache.v2 b/.vs/AvaloniaAppApplication/v17/.futdcache.v2 new file mode 100644 index 0000000..38cf915 Binary files /dev/null and b/.vs/AvaloniaAppApplication/v17/.futdcache.v2 differ diff --git a/.vs/AvaloniaAppApplication/v17/.suo b/.vs/AvaloniaAppApplication/v17/.suo new file mode 100644 index 0000000..00db081 Binary files /dev/null and b/.vs/AvaloniaAppApplication/v17/.suo differ diff --git a/.vs/AvaloniaAppApplication/v17/DocumentLayout.backup.json b/.vs/AvaloniaAppApplication/v17/DocumentLayout.backup.json new file mode 100644 index 0000000..a8a91da --- /dev/null +++ b/.vs/AvaloniaAppApplication/v17/DocumentLayout.backup.json @@ -0,0 +1,97 @@ +{ + "Version": 1, + "WorkspaceRootPath": "C:\\Users\\jauli\\Desktop\\AvaloniaAppApplication\\", + "Documents": [ + { + "AbsoluteMoniker": "D:0:0:{8D422B75-EA6B-4567-A2B3-34A14929F3D1}|AvaloniaAppApplication\\AvaloniaAppApplication.csproj|c:\\users\\jauli\\desktop\\avaloniaappapplication\\avaloniaappapplication\\dto\\servicedto.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}", + "RelativeMoniker": "D:0:0:{8D422B75-EA6B-4567-A2B3-34A14929F3D1}|AvaloniaAppApplication\\AvaloniaAppApplication.csproj|solutionrelative:avaloniaappapplication\\dto\\servicedto.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}" + }, + { + "AbsoluteMoniker": "D:0:0:{8D422B75-EA6B-4567-A2B3-34A14929F3D1}|AvaloniaAppApplication\\AvaloniaAppApplication.csproj|c:\\users\\jauli\\desktop\\avaloniaappapplication\\avaloniaappapplication\\models\\service.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}", + "RelativeMoniker": "D:0:0:{8D422B75-EA6B-4567-A2B3-34A14929F3D1}|AvaloniaAppApplication\\AvaloniaAppApplication.csproj|solutionrelative:avaloniaappapplication\\models\\service.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}" + }, + { + "AbsoluteMoniker": "D:0:0:{8D422B75-EA6B-4567-A2B3-34A14929F3D1}|AvaloniaAppApplication\\AvaloniaAppApplication.csproj|c:\\users\\jauli\\desktop\\avaloniaappapplication\\avaloniaappapplication\\mainwindow.axaml.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}", + "RelativeMoniker": "D:0:0:{8D422B75-EA6B-4567-A2B3-34A14929F3D1}|AvaloniaAppApplication\\AvaloniaAppApplication.csproj|solutionrelative:avaloniaappapplication\\mainwindow.axaml.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}" + } + ], + "DocumentGroupContainers": [ + { + "Orientation": 0, + "VerticalTabListWidth": 256, + "DocumentGroups": [ + { + "DockedWidth": 200, + "SelectedChildIndex": 2, + "Children": [ + { + "$type": "Bookmark", + "Name": "ST:0:0:{aa2115a1-9712-457b-9047-dbb71ca2cdd2}" + }, + { + "$type": "Bookmark", + "Name": "ST:0:0:{1c4feeaa-4718-4aa9-859d-94ce25d182ba}" + }, + { + "$type": "Document", + "DocumentIndex": 0, + "Title": "ServiceDTO.cs", + "DocumentMoniker": "C:\\Users\\jauli\\Desktop\\AvaloniaAppApplication\\AvaloniaAppApplication\\DTO\\ServiceDTO.cs", + "RelativeDocumentMoniker": "AvaloniaAppApplication\\DTO\\ServiceDTO.cs", + "ToolTip": "C:\\Users\\jauli\\Desktop\\AvaloniaAppApplication\\AvaloniaAppApplication\\DTO\\ServiceDTO.cs", + "RelativeToolTip": "AvaloniaAppApplication\\DTO\\ServiceDTO.cs", + "ViewState": "AgIAAAwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA==", + "Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000738|", + "WhenOpened": "2025-05-15T08:08:39.169Z", + "EditorCaption": "" + }, + { + "$type": "Document", + "DocumentIndex": 1, + "Title": "Service.cs", + "DocumentMoniker": "C:\\Users\\jauli\\Desktop\\AvaloniaAppApplication\\AvaloniaAppApplication\\Models\\Service.cs", + "RelativeDocumentMoniker": "AvaloniaAppApplication\\Models\\Service.cs", + "ToolTip": "C:\\Users\\jauli\\Desktop\\AvaloniaAppApplication\\AvaloniaAppApplication\\Models\\Service.cs", + "RelativeToolTip": "AvaloniaAppApplication\\Models\\Service.cs", + "ViewState": "AgIAAAsAAAAAAAAAAAA3wAAAAAAAAAAAAAAAAA==", + "Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000738|", + "WhenOpened": "2025-05-15T08:08:05.349Z", + "EditorCaption": "" + }, + { + "$type": "Document", + "DocumentIndex": 2, + "Title": "MainWindow.axaml.cs", + "DocumentMoniker": "C:\\Users\\jauli\\Desktop\\AvaloniaAppApplication\\AvaloniaAppApplication\\MainWindow.axaml.cs", + "RelativeDocumentMoniker": "AvaloniaAppApplication\\MainWindow.axaml.cs", + "ToolTip": "C:\\Users\\jauli\\Desktop\\AvaloniaAppApplication\\AvaloniaAppApplication\\MainWindow.axaml.cs", + "RelativeToolTip": "AvaloniaAppApplication\\MainWindow.axaml.cs", + "ViewState": "AgIAADkAAAAAAAAAAAAYwAAAAAAAAAAAAAAAAA==", + "Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000738|", + "WhenOpened": "2025-05-15T08:05:40.137Z", + "EditorCaption": "" + } + ] + }, + { + "DockedWidth": 73, + "SelectedChildIndex": -1, + "Children": [ + { + "$type": "Bookmark", + "Name": "ST:1:0:{d212f56b-c48a-434c-a121-1c5d80b59b9f}" + }, + { + "$type": "Bookmark", + "Name": "ST:0:0:{d78612c7-9962-4b83-95d9-268046dad23a}" + }, + { + "$type": "Bookmark", + "Name": "ST:0:0:{34e76e81-ee4a-11d0-ae2e-00a0c90fffc3}" + } + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/.vs/AvaloniaAppApplication/v17/DocumentLayout.json b/.vs/AvaloniaAppApplication/v17/DocumentLayout.json new file mode 100644 index 0000000..728bdc9 --- /dev/null +++ b/.vs/AvaloniaAppApplication/v17/DocumentLayout.json @@ -0,0 +1,97 @@ +{ + "Version": 1, + "WorkspaceRootPath": "C:\\Users\\jauli\\Desktop\\AvaloniaAppApplication\\", + "Documents": [ + { + "AbsoluteMoniker": "D:0:0:{8D422B75-EA6B-4567-A2B3-34A14929F3D1}|AvaloniaAppApplication\\AvaloniaAppApplication.csproj|c:\\users\\jauli\\desktop\\avaloniaappapplication\\avaloniaappapplication\\dto\\servicedto.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}", + "RelativeMoniker": "D:0:0:{8D422B75-EA6B-4567-A2B3-34A14929F3D1}|AvaloniaAppApplication\\AvaloniaAppApplication.csproj|solutionrelative:avaloniaappapplication\\dto\\servicedto.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}" + }, + { + "AbsoluteMoniker": "D:0:0:{8D422B75-EA6B-4567-A2B3-34A14929F3D1}|AvaloniaAppApplication\\AvaloniaAppApplication.csproj|c:\\users\\jauli\\desktop\\avaloniaappapplication\\avaloniaappapplication\\models\\service.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}", + "RelativeMoniker": "D:0:0:{8D422B75-EA6B-4567-A2B3-34A14929F3D1}|AvaloniaAppApplication\\AvaloniaAppApplication.csproj|solutionrelative:avaloniaappapplication\\models\\service.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}" + }, + { + "AbsoluteMoniker": "D:0:0:{8D422B75-EA6B-4567-A2B3-34A14929F3D1}|AvaloniaAppApplication\\AvaloniaAppApplication.csproj|c:\\users\\jauli\\desktop\\avaloniaappapplication\\avaloniaappapplication\\mainwindow.axaml.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}", + "RelativeMoniker": "D:0:0:{8D422B75-EA6B-4567-A2B3-34A14929F3D1}|AvaloniaAppApplication\\AvaloniaAppApplication.csproj|solutionrelative:avaloniaappapplication\\mainwindow.axaml.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}" + } + ], + "DocumentGroupContainers": [ + { + "Orientation": 0, + "VerticalTabListWidth": 256, + "DocumentGroups": [ + { + "DockedWidth": 200, + "SelectedChildIndex": 2, + "Children": [ + { + "$type": "Bookmark", + "Name": "ST:0:0:{aa2115a1-9712-457b-9047-dbb71ca2cdd2}" + }, + { + "$type": "Bookmark", + "Name": "ST:0:0:{1c4feeaa-4718-4aa9-859d-94ce25d182ba}" + }, + { + "$type": "Document", + "DocumentIndex": 0, + "Title": "ServiceDTO.cs", + "DocumentMoniker": "C:\\Users\\jauli\\Desktop\\AvaloniaAppApplication\\AvaloniaAppApplication\\DTO\\ServiceDTO.cs", + "RelativeDocumentMoniker": "AvaloniaAppApplication\\DTO\\ServiceDTO.cs", + "ToolTip": "C:\\Users\\jauli\\Desktop\\AvaloniaAppApplication\\AvaloniaAppApplication\\DTO\\ServiceDTO.cs", + "RelativeToolTip": "AvaloniaAppApplication\\DTO\\ServiceDTO.cs", + "ViewState": "AgIAAAMAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA==", + "Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000738|", + "WhenOpened": "2025-05-15T08:08:39.169Z", + "EditorCaption": "" + }, + { + "$type": "Document", + "DocumentIndex": 1, + "Title": "Service.cs", + "DocumentMoniker": "C:\\Users\\jauli\\Desktop\\AvaloniaAppApplication\\AvaloniaAppApplication\\Models\\Service.cs", + "RelativeDocumentMoniker": "AvaloniaAppApplication\\Models\\Service.cs", + "ToolTip": "C:\\Users\\jauli\\Desktop\\AvaloniaAppApplication\\AvaloniaAppApplication\\Models\\Service.cs", + "RelativeToolTip": "AvaloniaAppApplication\\Models\\Service.cs", + "ViewState": "AgIAAAsAAAAAAAAAAAA3wAAAAAAAAAAAAAAAAA==", + "Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000738|", + "WhenOpened": "2025-05-15T08:08:05.349Z", + "EditorCaption": "" + }, + { + "$type": "Document", + "DocumentIndex": 2, + "Title": "MainWindow.axaml.cs", + "DocumentMoniker": "C:\\Users\\jauli\\Desktop\\AvaloniaAppApplication\\AvaloniaAppApplication\\MainWindow.axaml.cs", + "RelativeDocumentMoniker": "AvaloniaAppApplication\\MainWindow.axaml.cs", + "ToolTip": "C:\\Users\\jauli\\Desktop\\AvaloniaAppApplication\\AvaloniaAppApplication\\MainWindow.axaml.cs", + "RelativeToolTip": "AvaloniaAppApplication\\MainWindow.axaml.cs", + "ViewState": "AgIAADkAAAAAAAAAAAAYwAAAAAAAAAAAAAAAAA==", + "Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000738|", + "WhenOpened": "2025-05-15T08:05:40.137Z", + "EditorCaption": "" + } + ] + }, + { + "DockedWidth": 73, + "SelectedChildIndex": -1, + "Children": [ + { + "$type": "Bookmark", + "Name": "ST:1:0:{d212f56b-c48a-434c-a121-1c5d80b59b9f}" + }, + { + "$type": "Bookmark", + "Name": "ST:0:0:{d78612c7-9962-4b83-95d9-268046dad23a}" + }, + { + "$type": "Bookmark", + "Name": "ST:0:0:{34e76e81-ee4a-11d0-ae2e-00a0c90fffc3}" + } + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/.vs/ProjectEvaluation/avaloniaappapplication.metadata.v9.bin b/.vs/ProjectEvaluation/avaloniaappapplication.metadata.v9.bin new file mode 100644 index 0000000..cc3635e Binary files /dev/null and b/.vs/ProjectEvaluation/avaloniaappapplication.metadata.v9.bin differ diff --git a/.vs/ProjectEvaluation/avaloniaappapplication.projects.v9.bin b/.vs/ProjectEvaluation/avaloniaappapplication.projects.v9.bin new file mode 100644 index 0000000..4668652 Binary files /dev/null and b/.vs/ProjectEvaluation/avaloniaappapplication.projects.v9.bin differ diff --git a/.vs/ProjectEvaluation/avaloniaappapplication.strings.v9.bin b/.vs/ProjectEvaluation/avaloniaappapplication.strings.v9.bin new file mode 100644 index 0000000..e052c98 Binary files /dev/null and b/.vs/ProjectEvaluation/avaloniaappapplication.strings.v9.bin differ diff --git a/AvaloniaAppApplication.sln b/AvaloniaAppApplication.sln new file mode 100644 index 0000000..b9b2f97 --- /dev/null +++ b/AvaloniaAppApplication.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.8.34330.188 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AvaloniaAppApplication", "AvaloniaAppApplication\AvaloniaAppApplication.csproj", "{8D422B75-EA6B-4567-A2B3-34A14929F3D1}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {8D422B75-EA6B-4567-A2B3-34A14929F3D1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {8D422B75-EA6B-4567-A2B3-34A14929F3D1}.Debug|Any CPU.Build.0 = Debug|Any CPU + {8D422B75-EA6B-4567-A2B3-34A14929F3D1}.Release|Any CPU.ActiveCfg = Release|Any CPU + {8D422B75-EA6B-4567-A2B3-34A14929F3D1}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {7A744A1E-FE08-4044-BAFF-E8C17FD6ADBA} + EndGlobalSection +EndGlobal diff --git a/AvaloniaAppApplication/AddEditWindow.axaml b/AvaloniaAppApplication/AddEditWindow.axaml new file mode 100644 index 0000000..be32bd3 --- /dev/null +++ b/AvaloniaAppApplication/AddEditWindow.axaml @@ -0,0 +1,90 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/AvaloniaAppApplication/AddEditWindow.axaml.cs b/AvaloniaAppApplication/AddEditWindow.axaml.cs new file mode 100644 index 0000000..81cec94 --- /dev/null +++ b/AvaloniaAppApplication/AddEditWindow.axaml.cs @@ -0,0 +1,293 @@ +using Avalonia; +using Avalonia.Controls; +using Avalonia.Markup.Xaml; +using Avalonia.Media.Imaging; +using AvaloniaAppApplication.DTO; +using AvaloniaAppApplication.Models; +using Microsoft.EntityFrameworkCore; +using MsBox.Avalonia; +using System; +using System.Collections.ObjectModel; +using System.IO; +using System.Linq; +using System.Text; +using System.Xml.Linq; + +namespace AvaloniaAppApplication; + +public partial class AddEditWindow : Window +{ + ServiceDTO currentService = new ServiceDTO(); + ObservableCollection serviceImages + = new ObservableCollection(); + + + + // + public AddEditWindow() + { + InitializeComponent(); + DataContext = currentService; + } + + // + public AddEditWindow(ServiceDTO service) + { + InitializeComponent(); + currentService = service; + DataContext = currentService; + TitleTB.Text = ""; + LoadImages(); + + } + + public void LoadImages() + { + var servicePhotosList = Manager.context.Servicephotos + .Where(s => s.Id == currentService.Id) + .Select(s => new ServicePhotoDTO + { + ServiceId = s.Serviceid, + PhotoPath = s.Photopath + }) + .ToList(); + + foreach (var photo in servicePhotosList) + { + serviceImages.Add(photo); + } + + + if (serviceImages.Any()) + { + foreach (var serviceImage in serviceImages) + { + Bitmap bitmap = new Bitmap(AppDomain.CurrentDomain.BaseDirectory.ToString().Replace("\\bin\\Debug\\net7.0\\", "\\") + serviceImage.PhotoPath.Trim()); + currentService.ServiceBitmaps.Add(new ServicePhotoDTO + { + Bitmap = bitmap, + PhotoPath = currentService.MainImagePath, + ServiceId = currentService.Id + }); + } + + } + + } + + private async void SaveButton_Click(object? sender, Avalonia.Interactivity.RoutedEventArgs e) + { + try + { + StringBuilder errors = new StringBuilder(); + if (string.IsNullOrEmpty(TitleTX.Text) || string.IsNullOrWhiteSpace(TitleTX.Text) || + string.IsNullOrEmpty(CostTX.Text) || string.IsNullOrWhiteSpace(CostTX.Text) || + string.IsNullOrEmpty(DescriptionTX.Text) || string.IsNullOrWhiteSpace(DescriptionTX.Text) || + string.IsNullOrEmpty(DiscountTX.Text) || string.IsNullOrWhiteSpace(DiscountTX.Text) || + string.IsNullOrEmpty(DurationTX.Text) || string.IsNullOrWhiteSpace(DurationTX.Text)) + { + var msbox = MessageBoxManager.GetMessageBoxStandard("!", " !"); + var res = await msbox.ShowWindowDialogAsync(this); + return; + } + + if (!DurationTX.Text.All(char.IsDigit) || !CostTX.Text.All(char.IsDigit)) + { + errors.AppendLine(" !"); + } + + if (int.Parse(DurationTX.Text) > 2400) + { + errors.AppendLine(" , 4 !"); + } + + if (errors.Length > 0) + { + var msbox = MessageBoxManager.GetMessageBoxStandard("!", errors.ToString()); + var res = await msbox.ShowWindowDialogAsync(this); + return; + } + + if (currentService.Discount > 100) + { + var msbox = MessageBoxManager.GetMessageBoxStandard("!", " 100%"); + var res = await msbox.ShowWindowDialogAsync(this); + return; + } + + if (errors.Length > 0) + { + var msbox = MessageBoxManager.GetMessageBoxStandard("!", errors.ToString()); + var res = await msbox.ShowWindowDialogAsync(this); + return; + } + var service = new Service() + { + Title = currentService.Title, + Cost = (decimal)currentService.Cost, + Description = currentService.Description, + Discount = currentService.Discount, + Mainimagepath = currentService.MainImagePath, + Durationinseconds = (int)currentService.Durationinseconds + }; + // + if (currentService.Id == 0) + { + if (Manager.context.Services.Any(s => s.Title == currentService.Title)) + { + var ms = MessageBoxManager.GetMessageBoxStandard("!", " !"); + var ress = await ms.ShowWindowDialogAsync(this); + return; + } + ManageBitmaps(); + Manager.context.Add(service); + Manager.context.SaveChanges(); + var msbox = MessageBoxManager.GetMessageBoxStandard("OK!", " !"); + var res = await msbox.ShowWindowDialogAsync(this); + + } + else // + { + var serviceToEdit = Manager.context.Services.FirstOrDefault(s => s.Id == currentService.Id); + serviceToEdit.Title = currentService.Title; + serviceToEdit.Cost = (decimal)currentService.Cost; + serviceToEdit.Description = currentService.Description; + serviceToEdit.Discount = currentService.Discount; + serviceToEdit.Mainimagepath = currentService.MainImagePath; + serviceToEdit.Durationinseconds = (int)currentService.Durationinseconds; + + ManageBitmaps(); + Manager.context.Update(serviceToEdit); + Manager.context.SaveChanges(); + var msbox = MessageBoxManager.GetMessageBoxStandard("OK!", " !"); + var res = await msbox.ShowWindowDialogAsync(this); + + } + + Close(); + } + catch (Exception ex) + { + var msbox = MessageBoxManager.GetMessageBoxStandard("!", " !"); + var res = await msbox.ShowWindowDialogAsync(this); + return; + } + + } + + public void ManageBitmaps() + { + var servicePhotosInDB = Manager.context.Servicephotos.ToList(); + foreach (var servicePhoto in servicePhotosInDB) + { + if (!currentService.ServiceBitmaps.Any(b => b.ServiceId == servicePhoto.Id && b.PhotoPath == servicePhoto.Photopath)) + { + var imageToRemove = Manager.context.Servicephotos.FirstOrDefault(b => b.Serviceid == currentService.Id + && b.Photopath == servicePhoto.Photopath); + if (imageToRemove != null) + Manager.context.Servicephotos.Remove(imageToRemove); + + + } + } + + foreach (var serviceBitmap in currentService.ServiceBitmaps) + { + if (!currentService.ServiceBitmaps.Any(b => b.ServiceId == serviceBitmap.Id && b.PhotoPath == serviceBitmap.PhotoPath)) + { + var newServicePhotoToAdd = new Servicephoto + { + Serviceid = currentService.Id, + Photopath = serviceBitmap.PhotoPath + }; + Manager.context.Add(newServicePhotoToAdd); + + } + } + Manager.context.SaveChanges(); + } + + private async void AddPictureButton_Click(object? sender, Avalonia.Interactivity.RoutedEventArgs e) + { + try + { + var openFileDialog = new OpenFileDialog(); + openFileDialog.Filters.Add(new FileDialogFilter { Name = " ", Extensions = { "jpg", "jpeg", "png", "bmp" } }); + openFileDialog.AllowMultiple = false; + + var result = await openFileDialog.ShowAsync(this); + if (result != null && result.Length > 0) + { + var picToAdd = new Bitmap(result[0]); + string picName = "asset" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".jpg"; + string appDataPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory.ToString().Replace("\\bin\\Debug\\net7.0\\", "\\"), " "); + + using (var fileStream = new FileStream(Path.Combine(appDataPath, picName), FileMode.Create)) + { + picToAdd.Save(fileStream); + } + + currentService.ImageBitmap = picToAdd; + currentService.MainImagePath = Path.Combine(" ", picName); + } + } + catch (Exception ex) + { + var msbox = MessageBoxManager.GetMessageBoxStandard("!", ex.Message); + var res = await msbox.ShowWindowDialogAsync(this); + return; + } + } + + private async void AddImageButton_Click(object? sender, Avalonia.Interactivity.RoutedEventArgs e) + { + var openFileDialog = new OpenFileDialog(); + openFileDialog.Filters.Add(new FileDialogFilter { Extensions = { "png", "jpeg", "jpg", "bmp" } }); + openFileDialog.AllowMultiple = false; + + try + { + var result = await openFileDialog.ShowAsync(this); + if (result != null && result.Length > 0) + { + string imagePath = result[0].ToString(); + Bitmap bitmap = new Bitmap(imagePath); + + string assetsFolderPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory.ToString().Replace("\\bin\\Debug\\net7.0\\", "\\"), " "); + string fileName = Guid.NewGuid().ToString() + ".jpg"; + string savedImagePath = Path.Combine(assetsFolderPath, fileName); + + if (currentService.ServiceBitmaps.Any(b => b.PhotoPath == (" /" + fileName).Trim())) + { + var msbox = MessageBoxManager.GetMessageBoxStandard("", " !"); + var res = await msbox.ShowWindowDialogAsync(this); + return; + } + using (var stream = File.OpenWrite(savedImagePath)) + { + bitmap.Save(stream); + } + + var imageToAdd = new ServicePhotoDTO + { + Bitmap = bitmap, + PhotoPath = (" /" + fileName).Trim(), + ServiceId = currentService.Id + }; + currentService.ServiceBitmaps.Add(imageToAdd); + + currentService.MainImagePath = (" /" + fileName).Trim(); + } + } + catch + { + return; + } + } + + private void DeleteImageButton_Click(object? sender, Avalonia.Interactivity.RoutedEventArgs e) + { + if (currentService.ServicePhotos.Count > 0) + currentService.ServiceBitmaps.RemoveAt(PictureLB.SelectedIndex); + } +} diff --git a/AvaloniaAppApplication/App.axaml b/AvaloniaAppApplication/App.axaml new file mode 100644 index 0000000..7c8296c --- /dev/null +++ b/AvaloniaAppApplication/App.axaml @@ -0,0 +1,10 @@ + + + + + + + \ No newline at end of file diff --git a/AvaloniaAppApplication/App.axaml.cs b/AvaloniaAppApplication/App.axaml.cs new file mode 100644 index 0000000..5617d48 --- /dev/null +++ b/AvaloniaAppApplication/App.axaml.cs @@ -0,0 +1,24 @@ +using Avalonia; +using Avalonia.Controls.ApplicationLifetimes; +using Avalonia.Markup.Xaml; + +namespace AvaloniaAppApplication +{ + public partial class App : Application + { + public override void Initialize() + { + AvaloniaXamlLoader.Load(this); + } + + public override void OnFrameworkInitializationCompleted() + { + if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop) + { + desktop.MainWindow = new AuthWindow(); + } + + base.OnFrameworkInitializationCompleted(); + } + } +} \ No newline at end of file diff --git a/AvaloniaAppApplication/AuthWindow.axaml b/AvaloniaAppApplication/AuthWindow.axaml new file mode 100644 index 0000000..8670cc4 --- /dev/null +++ b/AvaloniaAppApplication/AuthWindow.axaml @@ -0,0 +1,17 @@ + + + + Авторизация + + +