From f8ca7c183379ad6f444444768e1ba3d9f1c2d435 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=D0=91=D0=9F?= <pbhhbff@list.ru>
Date: Mon, 14 Apr 2025 12:49:39 +0300
Subject: [PATCH] 2

---
 App.xaml.cs                  |   1 +
 BuyPage.xaml                 |   4 +-
 BuyPage.xaml.cs              |  27 ++++++-
 MainPage.xaml                |  14 ++--
 MainPage.xaml.cs             |   6 +-
 Models/Users.cs              |   4 +-
 MyDiplom.csproj              |   3 +
 MyDiplom.csproj.user         |   3 +
 UsersPage.xaml               | 166 +++++++++++++++++++++++++++++++++++++++++++
 UsersPage.xaml.cs            |  17 +++++
 ViewModels/UserViewModels.cs |  34 ++++++++-
 11 files changed, 265 insertions(+), 14 deletions(-)
 create mode 100644 UsersPage.xaml
 create mode 100644 UsersPage.xaml.cs

diff --git a/App.xaml.cs b/App.xaml.cs
index 6231dc8..1e70c23 100644
--- a/App.xaml.cs
+++ b/App.xaml.cs
@@ -9,6 +9,7 @@
           
 
             MainPage = new MainPage();
+            MainPage = new NavigationPage(new MainPage());
         }
 	}
 }
diff --git a/BuyPage.xaml b/BuyPage.xaml
index effdf67..7c138af 100644
--- a/BuyPage.xaml
+++ b/BuyPage.xaml
@@ -26,10 +26,10 @@
                            HeightRequest="50"
                            VerticalOptions="Center"
                            HorizontalOptions="Fill">
-            <Entry WidthRequest="300"/>
+            <Entry WidthRequest="300" Placeholder="Введите сумму" Keyboard="Numeric" x:Name="AmountEntry"/>
             <Label Text="₽"
                FontSize="18"
-               VerticalOptions="Center" />
+               VerticalOptions="Center"/>
             
 
            
diff --git a/BuyPage.xaml.cs b/BuyPage.xaml.cs
index f5543d9..c515af3 100644
--- a/BuyPage.xaml.cs
+++ b/BuyPage.xaml.cs
@@ -1,5 +1,10 @@
 using CommunityToolkit.Maui.Views;
 
+using MyDiplom.Models;
+using MyDiplom.ViewModels;
+
+using Windows.System;
+
 namespace MyDiplom;
 
 public partial class BuyPage : Popup
@@ -7,14 +12,32 @@ public partial class BuyPage : Popup
     public BuyPage()
     {
         InitializeComponent();
-    }
 
+    }
+    ApplicationUser User { get; set; } = new ApplicationUser();
     private void CloseButtonClicked(object sender, EventArgs e)
     {
         Close();
     }
     private void BuyButtonCliked(object sender, EventArgs e)
     {
+        string amountText = AmountEntry.Text;
+        if (decimal.TryParse(amountText, out decimal amount))
+        {
+            //User.Balance += amount;
+            //var userViewModel = (BindingContext as UserViewModels);
+            //if (userViewModel != null)
+            //{
+            //    userViewModel.User.Balance += amount;
 
+            //}
+            var userViewModel = (BindingContext as UserViewModels);
+            if (userViewModel != null)
+            {
+                userViewModel.UpdateBalance(amount);
+             
+            }
+        }
     }
-}
+  }
+
diff --git a/MainPage.xaml b/MainPage.xaml
index 503abd2..d4e1a51 100644
--- a/MainPage.xaml
+++ b/MainPage.xaml
@@ -15,10 +15,12 @@
             <ColumnDefinition Width="*"/>
         </Grid.ColumnDefinitions>
        
-        <StackLayout Grid.ColumnSpan="2"  Orientation="Horizontal" Padding="10"
-                     Background="black"  
+        <StackLayout Grid.ColumnSpan="2" 
+                     Orientation="Horizontal"
+                     Padding="10"
+                     Background="Black"  
                      HeightRequest="80"                           
-                     HorizontalOptions="Fill" >
+                     HorizontalOptions="Fill">
 
            
                 <Label Text="TgBots" TextColor="White" FontSize="40"  
@@ -26,7 +28,7 @@
         HorizontalOptions="StartAndExpand"/>
 
             <StackLayout HorizontalOptions="End" Orientation="Horizontal" Padding="0,0,10,0" Spacing="20">
-                <Label Text="{Binding User.Balance, StringFormat='Ваш Баланс {0} Р'}"  TextColor="White"  VerticalOptions="Center" />
+                <Label x:Name="BalanceLabel" Text="{Binding User.Balance, StringFormat='Ваш Баланс {0} Р'}"  TextColor="White"  VerticalOptions="Center" />
 
 
                 <Button Text="Пополнить"
@@ -37,7 +39,7 @@
          HeightRequest="20"
           Clicked="OnButtonClicked"              />
 
-                <Label Text="{Binding User.DisplayName}" TextColor="White" />
+                <Label Text="{Binding User.DisplayName}" TextColor="White" Padding="0,20,0,0" />
 
                 <Button Text="Профиль" 
          TextColor="White"
@@ -59,7 +61,7 @@
             <Button Text="Главная" TextColor="Black"
                                     BackgroundColor="Transparent"/>
             <Button Text="Личный кабинет" TextColor="Black"
-                                    BackgroundColor="Transparent" />
+                                    BackgroundColor="Transparent" Clicked="UsersButtonClicked" />
             <Button Text="О нас" TextColor="Black"
                                     BackgroundColor="Transparent"/>
             <Button Text="Новости" TextColor="Black"
diff --git a/MainPage.xaml.cs b/MainPage.xaml.cs
index 7595a6c..8eaf275 100644
--- a/MainPage.xaml.cs
+++ b/MainPage.xaml.cs
@@ -22,6 +22,10 @@ namespace MyDiplom
 		{
             var buyPopup = new BuyPage();
 			this.ShowPopup(buyPopup);
-        }		
+        }
+        private async void UsersButtonClicked(object sender, EventArgs e) 
+		{
+			await Navigation.PushAsync(new UsersPage());
+        }
 	}
 }
diff --git a/Models/Users.cs b/Models/Users.cs
index a90408e..8f5c2fc 100644
--- a/Models/Users.cs
+++ b/Models/Users.cs
@@ -4,12 +4,14 @@ using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
 
+using Windows.System;
+
 namespace MyDiplom.Models
 {
     public class ApplicationUser
     {
         public string? DisplayName { get; set; }
-        public decimal Balance { get; set; } = 0;
+        public decimal Balance { get; set; } = 0.0m;
         public string? InvitedUserId { get; set; }
     }
 }
diff --git a/MyDiplom.csproj b/MyDiplom.csproj
index f481f5e..00472ce 100644
--- a/MyDiplom.csproj
+++ b/MyDiplom.csproj
@@ -68,6 +68,9 @@
 	  <MauiXaml Update="BuyPage.xaml">
 	    <Generator>MSBuild:Compile</Generator>
 	  </MauiXaml>
+	  <MauiXaml Update="UsersPage.xaml">
+	    <Generator>MSBuild:Compile</Generator>
+	  </MauiXaml>
 	</ItemGroup>
 
 </Project>
diff --git a/MyDiplom.csproj.user b/MyDiplom.csproj.user
index 01c533b..9b9421d 100644
--- a/MyDiplom.csproj.user
+++ b/MyDiplom.csproj.user
@@ -9,6 +9,9 @@
     <MauiXaml Update="BuyPage.xaml">
       <SubType>Designer</SubType>
     </MauiXaml>
+    <MauiXaml Update="UsersPage.xaml">
+      <SubType>Designer</SubType>
+    </MauiXaml>
   </ItemGroup>
   <ItemGroup>
     <None Update="App.xaml">
diff --git a/UsersPage.xaml b/UsersPage.xaml
new file mode 100644
index 0000000..f61b42f
--- /dev/null
+++ b/UsersPage.xaml
@@ -0,0 +1,166 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
+             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
+             x:Class="MyDiplom.UsersPage">
+
+    <Grid>
+        <Grid.RowDefinitions>
+            <RowDefinition Height="90"/>
+            <RowDefinition Height="550"/>
+            <RowDefinition  Height="*"/>
+            <RowDefinition Height="100"/>
+        </Grid.RowDefinitions>
+        <Grid.ColumnDefinitions>
+            <ColumnDefinition Width="260"/>
+            <ColumnDefinition Width="*"/>
+        </Grid.ColumnDefinitions>
+
+        <StackLayout Grid.ColumnSpan="2" 
+                     Orientation="Horizontal"
+                     Padding="10"
+                     Background="Black"  
+                     HeightRequest="80"                           
+                     HorizontalOptions="Fill">
+
+
+            <Label Text="TgBots" TextColor="White" FontSize="40"  
+        VerticalOptions="Center" 
+        HorizontalOptions="StartAndExpand"/>
+
+            <StackLayout HorizontalOptions="End" Orientation="Horizontal" Padding="0,0,10,0" Spacing="20">
+                <Label  Text="{Binding User.Balance, StringFormat='Ваш Баланс {0} Р'}"  TextColor="White"  VerticalOptions="Center" />
+
+
+                <Button Text="Пополнить"
+         Background="White"
+         TextColor="Black"
+          HorizontalOptions="EndAndExpand"
+         WidthRequest="110"
+         HeightRequest="20"
+          Clicked="OnButtonClicked"              />
+
+                <Label Text="{Binding User.DisplayName}" TextColor="White" />
+
+                <Button Text="Профиль" 
+         TextColor="White"
+         BackgroundColor="Transparent" 
+         HorizontalOptions="EndAndExpand"/>
+
+            </StackLayout>
+
+        </StackLayout>
+
+        <StackLayout  Grid.Row="1" Grid.RowSpan="4"   WidthRequest="250" Spacing="5" Padding="0,5,0,0">
+
+            <Border Stroke="Gray">
+                <Border.StrokeShape>
+                    <RoundRectangle CornerRadius="25"/>
+                </Border.StrokeShape>
+                <StackLayout Background="#F3F3F3" Spacing="2">
+
+                    <Button Text="Главная" TextColor="Black"
+                                    BackgroundColor="Transparent"/>
+                    <Button Text="Личный кабинет" TextColor="Black"
+                                    BackgroundColor="Transparent"/>
+                    <Button Text="О нас" TextColor="Black"
+                                    BackgroundColor="Transparent"/>
+                    <Button Text="Новости" TextColor="Black"
+                                    BackgroundColor="Transparent"/>
+                    <Button Text="FAQ" TextColor="Black"
+                                    BackgroundColor="Transparent"/>
+                    <Button Text="Контакты" TextColor="Black"
+                                    BackgroundColor="Transparent"/>
+                    <Button Text="О ботах" TextColor="Black"
+                                    BackgroundColor="Transparent"/>
+                </StackLayout>
+            </Border>
+            <StackLayout Spacing="5" WidthRequest="250">
+
+                <Border Stroke="Gray">
+                    <Border.StrokeShape>
+                        <RoundRectangle CornerRadius="25"/>
+                    </Border.StrokeShape>
+
+                    <StackLayout Background="#6D87D3" 
+         Spacing="2" Padding="0,10,0,0">
+                        <Label Text="Боты" HorizontalOptions="Center" Scale="2"/>
+                        <Button Text="TG FREELANCE ПОМОЩНИК"  TextColor="Black" Background="Transparent"/>
+                        <Button Text="Раскрутка TG Группы"  TextColor="Black" Background="Transparent"/>
+                        <Button Text="Интернет Магазин"  TextColor="Black" Background="Transparent"/>
+                    </StackLayout>
+
+                </Border>
+
+
+            </StackLayout>
+            <Border>
+                <Border.StrokeShape>
+                    <RoundRectangle CornerRadius="25"/>
+                </Border.StrokeShape>
+                <StackLayout Background="Black" Grid.Row="1"   WidthRequest="250"  >
+                    <Button Text="Помощь" Background="Transparent"/>
+
+                </StackLayout>
+            </Border>
+
+
+        </StackLayout>
+
+        <StackLayout Grid.Row="1"  Grid.Column="1">
+           
+            <Grid>
+
+                <Border>
+                    <Border.StrokeShape>
+                        <RoundRectangle CornerRadius="25"/>
+                    </Border.StrokeShape>
+
+                    <VerticalStackLayout Background="#F3F3F3"  HeightRequest="285"  >
+
+                        <VerticalStackLayout Padding="20" Spacing="10">
+                            <Label Text="ЛИЧНЫЙ НАБИНЕТ"  FontSize="20"  FontAttributes="Bold"  HorizontalOptions="Start"/>
+
+                           
+                            <Grid ColumnDefinitions="Auto,*,Auto" ColumnSpacing="10">
+                                <Label Text="Имя пользователя" VerticalOptions="Center"/>
+                                <Entry Text="" Grid.Column="1"/>
+                                <Button Text="Изменить" 
+                Grid.Column="2"
+                WidthRequest="100"/>
+                            </Grid>
+
+                            
+                            <Grid ColumnDefinitions="Auto,*,Auto" ColumnSpacing="10">
+                                <Label Text="Электронная почта" VerticalOptions="Center"/>
+                                <Entry Text="" Grid.Column="1"/>
+                                <Button Text="Изменить" 
+                Grid.Column="2"
+                WidthRequest="100"/>
+                            </Grid>
+
+                           
+                            <Grid ColumnDefinitions="Auto,*,Auto" ColumnSpacing="10">
+                                <Label Text="Мобильный телефон" VerticalOptions="Center"/>
+                                <Entry Text="" Grid.Column="1" Keyboard="Telephone"/>
+                                <Button Text="Изменить" 
+                                  Grid.Column="2"
+                                  WidthRequest="100"/>
+                            </Grid>
+
+                           
+                            <Grid ColumnDefinitions="Auto,*,Auto" ColumnSpacing="10">
+                                <Label Text="Телеграмм" VerticalOptions="Center"/>
+                                <Entry Text="" Grid.Column="1"/>
+                                <Button Text="Изменить" 
+                                 Grid.Column="2"
+                                  WidthRequest="100"/>
+                            </Grid>
+                        </VerticalStackLayout>
+
+
+                    </VerticalStackLayout>
+                </Border>
+            </Grid>
+        </StackLayout>
+    </Grid>
+</ContentPage>
diff --git a/UsersPage.xaml.cs b/UsersPage.xaml.cs
new file mode 100644
index 0000000..ccb1032
--- /dev/null
+++ b/UsersPage.xaml.cs
@@ -0,0 +1,17 @@
+using CommunityToolkit.Maui.Views;
+
+namespace MyDiplom;
+
+public partial class UsersPage : ContentPage
+{
+	public UsersPage()
+	{
+		InitializeComponent();
+	}
+    private void OnButtonClicked(object sender, EventArgs e)
+    {
+        var buyPopup = new BuyPage();
+        this.ShowPopup(buyPopup);
+    }
+    
+}
\ No newline at end of file
diff --git a/ViewModels/UserViewModels.cs b/ViewModels/UserViewModels.cs
index 911ad51..ddd3edf 100644
--- a/ViewModels/UserViewModels.cs
+++ b/ViewModels/UserViewModels.cs
@@ -2,18 +2,48 @@
 
 using System;
 using System.Collections.Generic;
+using System.ComponentModel;
 using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
 
+using Windows.System;
+
 namespace MyDiplom.ViewModels
 {
-    public class UserViewModels:BaseViewModel
+    public class UserViewModels : BaseViewModel
     {
         public ApplicationUser User { get; set; } = new ApplicationUser();
         public UserViewModels()
         {
-            User = new ApplicationUser { DisplayName = "Вася", Balance = 10.0m };
+            User = new ApplicationUser { DisplayName = "Вася" };
+            LoadUserData();
         }
+
+        public void UpdateBalance(decimal amount)
+        {
+            if (amount != 0)
+            {
+                User.Balance += amount;
+                OnPropertyChanged(nameof(User));
+                SaveUserData();
+
+            }
+        }
+        private void SaveUserData()
+        {
+            Preferences.Set("UserBalance", User.Balance.ToString());
+            Preferences.Set("UserDisplayName", User.DisplayName);
+        }
+
+        private void LoadUserData()
+        {
+            
+            string balanceString = Preferences.Get("UserBalance", "0");
+            User.Balance = decimal.TryParse(balanceString, out var balance) ? balance : 0;
+
+            User.DisplayName = Preferences.Get("UserDisplayName", "Вася"); 
+        }
+
     }
 }