School Commit Init

This commit is contained in:
2024-08-31 12:07:21 +03:00
commit 0b130ee18c
2801 changed files with 4720552 additions and 0 deletions
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8" ?>
<contacts>
<contact>
<Id>fc0e19f2-114f-47f1-a25a-1245035bc7b3</Id>
<username>@patri.stoica</username>
<email>email1@example.com</email>
<phoneNumber>0752111222</phoneNumber>
<birthday>2000-01-01T00:00:00</birthday>
</contact>
<contact>
<Id>68ce0f1a-b031-4c62-b2d2-f297e2f68768</Id>
<username>@delia.gherasim</username>
<phoneNumber>0743111222</phoneNumber>
<birthday>1995-05-05T00:00:00</birthday>
</contact>
</contacts>
@@ -0,0 +1,50 @@
<UserControl x:Class="District_3_App.FriendsSettings.Friends"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:District_3_App.FriendsSettings"
mc:Ignorable="d"
Height="450" Width="800" Background="White">
<UserControl.Resources>
<!-- Define the loading button template -->
<ControlTemplate x:Key="LoadingButtonTemplate" TargetType="Button">
<Grid>
<!-- Use an Image as the button content -->
<Image Source="\images\button.png" Stretch="Uniform"/>
</Grid>
</ControlTemplate>
<ControlTemplate x:Key="LoadingButtonEyeTemplate" TargetType="Button">
<Grid>
<!-- Use an Image as the button content -->
<Image Source="\images\buttonEye.png" Stretch="Uniform"/>
</Grid>
</ControlTemplate>
<!-- Define ComboBox item template with a button -->
<DataTemplate x:Key="ComboBoxItemTemplate">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<TextBlock Grid.Column="0" Text="{Binding}" Margin="0,0,5,0" />
<Button Grid.Column="1" Content="follow" Click="ItemButton_Click" Background="White" Foreground="Black" BorderBrush="White" FontSize="10" FontWeight="Bold" />
</Grid>
</DataTemplate>
</UserControl.Resources>
<Grid Background="White">
<Label Content="Friends Settings" HorizontalAlignment="Left" Margin="68,51,0,0" VerticalAlignment="Top" FontSize="18" FontWeight="Bold"/>
<Label Content="Sync Contacts" HorizontalAlignment="Left" Margin="68,107,0,0" VerticalAlignment="Top" FontSize="16"/>
<Label Content="See who viewed your profile" HorizontalAlignment="Left" Margin="68,294,0,0" VerticalAlignment="Top" RenderTransformOrigin="-0.175,0.579" FontSize="16"/>
<!-- Use the custom loading button template -->
<Button Click="LoadUsernamesContacts_Click" HorizontalAlignment="Left" Margin="181,110,0,0" VerticalAlignment="Top" Width="19" Height="25" RenderTransformOrigin="0.09,0.483" ClickMode="Press"/>
<Button HorizontalAlignment="Left" Margin="282,296,0,0" VerticalAlignment="Top" RenderTransformOrigin="0.092,-0.076" Height="29" Width="18"/>
<ComboBox x:Name="usernamesContactsComboBox" ItemTemplate="{StaticResource ComboBoxItemTemplate}" HorizontalContentAlignment="Stretch" HorizontalAlignment="Left" Margin="70,143,0,0" VerticalAlignment="Top" Width="221" />
<TextBlock HorizontalAlignment="Left" Margin="81,146,0,0" TextWrapping="Wrap" Text="See contacts" VerticalAlignment="Top" RenderTransformOrigin="-0.074,-3.498"/>
<ComboBox x:Name="usernamesViewersComboBox" HorizontalAlignment="Left" Margin="70,330,0,0" VerticalAlignment="Top" Width="221" RenderTransformOrigin="0.981,0.598"/>
<TextBlock HorizontalAlignment="Left" Margin="81,333,0,0" TextWrapping="Wrap" Text="See everyone" VerticalAlignment="Top" RenderTransformOrigin="0.456,0.425"/>
<Image Source="/FriendsSettings/buttonEye.png" Margin="305,306,481,132" />
<Image Source="/FriendsSettings/button.png" Margin="204,114,581,321" />
</Grid>
</UserControl>
@@ -0,0 +1,303 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Xml;
using System.Xml.Linq;
using District_3_App.Enitities;
using District_3_App.ProfileSocialNetworkInfoStuff.Entities;
using District_3_App.Repository;
namespace District_3_App.FriendsSettings
{
/// <summary>
/// Interaction logic for Friends.xaml
/// </summary>
public partial class Friends : UserControl
{
// Getting lists
private static Dictionary<string, UserInfo> GetContacts()
{
var contacts = new Dictionary<string, UserInfo>();
string filePath;
// Create User objects with usernames and add them to the dictionary
/*contacts["0752111222"] = new User("@patri.stoica", "0752111222");
contacts["0743111222"] = new User("@delia.gherasim", "0743111222");*/
// Load the XML document
string baseDirectory = AppDomain.CurrentDomain.BaseDirectory;
string relativePath = baseDirectory.Substring(0, baseDirectory.IndexOf("bin\\Debug"));
string currfilePath = System.IO.Path.Combine(relativePath, "FriendsSettings");
filePath = System.IO.Path.Combine(currfilePath, "Contacts.xml");
Console.WriteLine(filePath);
/*if (!File.Exists(filePath))
{
XDocument xDocument1 = new XDocument(new XElement("FancierProfiles"));
xDocument1.Save(filePath);
}*/
// MessageBox.Show("Reading profile info from file: " + filePath);
XDocument xDocument = XDocument.Load(filePath);
XElement root = xDocument.Element("contacts");
if (root != null && root.HasElements)
{
foreach (var userElem in root.Elements("contact"))
{
Guid userId;
if (!Guid.TryParse((string)userElem.Element("Id"), out userId))
{
userId = Guid.NewGuid();
}
UserInfo user = new UserInfo();
try
{
user.Id = userId;
user.Username = (string)userElem.Element("username");
user.Email = (string)userElem.Element("email");
user.PhoneNumber = (string)userElem.Element("phoneNumber");
user.Birthday = (DateTime)userElem.Element("birthday");
contacts[user.PhoneNumber] = user;
}
catch (Exception ex)
{
Console.WriteLine($"Error parsing profile: {ex.Message}");
}
}
}
return contacts;
}
private static Dictionary<string, UserInfo> GetViewers()
{
var contacts = new Dictionary<string, UserInfo>();
string filePath;
// Create User objects with usernames and add them to the dictionary
/*contacts["0752111222"] = new User("@patri.stoica", "0752111222");
contacts["0743111222"] = new User("@delia.gherasim", "0743111222");
contacts["0755111222"] = new User("@anita.gorog", "0755111222");*/
// Load the XML document
string baseDirectory = AppDomain.CurrentDomain.BaseDirectory;
string relativePath = baseDirectory.Substring(0, baseDirectory.IndexOf("bin\\Debug"));
string currfilePath = System.IO.Path.Combine(relativePath, "FriendsSettings");
filePath = System.IO.Path.Combine(currfilePath, "Viewers.xml");
Console.WriteLine(filePath);
/*if (!File.Exists(filePath))
{
XDocument xDocument1 = new XDocument(new XElement("FancierProfiles"));
xDocument1.Save(filePath);
}*/
// MessageBox.Show("Reading profile info from file: " + filePath);
XDocument xDocument = XDocument.Load(filePath);
XElement root = xDocument.Element("viewers");
if (root != null && root.HasElements)
{
foreach (var userElem in root.Elements("viewer"))
{
Guid userId;
if (!Guid.TryParse((string)userElem.Element("Id"), out userId))
{
userId = Guid.NewGuid();
}
UserInfo user = new UserInfo();
try
{
user.Id = userId;
user.Username = (string)userElem.Element("username");
user.Email = (string)userElem.Element("email");
user.PhoneNumber = (string)userElem.Element("phoneNumber");
user.Birthday = (DateTime)userElem.Element("birthday");
contacts[user.PhoneNumber] = user;
}
catch (Exception ex)
{
Console.WriteLine($"Error parsing profile: {ex.Message}");
}
}
}
return contacts;
}
private static Dictionary<string, UserInfo> GetFriends()
{
var friends = new Dictionary<string, UserInfo>();
string filePath;
// Load the XML document
string baseDirectory = AppDomain.CurrentDomain.BaseDirectory;
string relativePath = baseDirectory.Substring(0, baseDirectory.IndexOf("bin\\Debug"));
string currfilePath = System.IO.Path.Combine(relativePath, "FriendsSettings");
filePath = System.IO.Path.Combine(currfilePath, "Friends.xml");
Console.WriteLine(filePath);
/*if (!File.Exists(filePath))
{
XDocument xDocument1 = new XDocument(new XElement("FancierProfiles"));
xDocument1.Save(filePath);
}*/
// MessageBox.Show("Reading profile info from file: " + filePath);
XDocument xDocument = XDocument.Load(filePath);
XElement root = xDocument.Element("friends");
if (root != null && root.HasElements)
{
foreach (var userElem in root.Elements("friend"))
{
Guid userId;
if (!Guid.TryParse((string)userElem.Element("Id"), out userId))
{
userId = Guid.NewGuid();
}
UserInfo user = new UserInfo();
try
{
user.Id = userId;
user.Username = (string)userElem.Element("username");
user.Email = (string)userElem.Element("email");
user.PhoneNumber = (string)userElem.Element("phoneNumber");
user.Birthday = (DateTime)userElem.Element("birthday");
friends[user.PhoneNumber] = user;
}
catch (Exception ex)
{
Console.WriteLine($"Error parsing profile: {ex.Message}");
}
}
}
return friends;
}
public void SaveFriendsToXml()
{
string filePath;
// Load the XML document
string baseDirectory = AppDomain.CurrentDomain.BaseDirectory;
string relativePath = baseDirectory.Substring(0, baseDirectory.IndexOf("bin\\Debug"));
string currentFilePath = System.IO.Path.Combine(relativePath, "FriendsSettings");
filePath = System.IO.Path.Combine(currentFilePath, "Friends.xml");
try
{
XDocument xDocument = new XDocument(new XElement("friends"));
foreach (var friend in friends.Values)
{
XElement friendElement = new XElement("friend",
new XElement("Id", friend.Id),
new XElement("username", friend.Username),
new XElement("email", friend.Email),
new XElement("phoneNumber", friend.PhoneNumber),
new XElement("birthday", friend.Birthday));
xDocument.Root?.Add(friendElement);
}
xDocument.Save(filePath);
}
catch (Exception ex)
{
Console.WriteLine("Error saving friends to XML: " + ex.Message);
}
}
private Dictionary<string, UserInfo> syncContacts = GetContacts();
private Dictionary<string, UserInfo> usernames_viewers = GetViewers();
private Dictionary<string, UserInfo> friends = GetFriends();
public Friends()
{
InitializeComponent();
}
private void LoadUsernamesContacts_Click(object sender, RoutedEventArgs e)
{
usernamesContactsComboBox.Items.Clear();
foreach (UserInfo user in syncContacts.Values)
{
usernamesContactsComboBox.Items.Add(user.Username);
}
}
private bool AddSyncContact(UserInfo contactToAdd, string key)
{
if (friends.ContainsKey(key))
{
Console.WriteLine("User already added.");
return false;
}
else
{
friends[key] = contactToAdd;
Console.WriteLine($"User added: {contactToAdd.Username}");
}
return true;
}
private bool RemoveSyncContact(string key)
{
friends.Remove(key);
return true;
}
private void ItemButton_Click(object sender, RoutedEventArgs e)
{
Button clickedButton = (Button)sender;
Grid grid = (Grid)VisualTreeHelper.GetParent(clickedButton);
TextBlock textBlock = (TextBlock)grid.Children[0];
string username = textBlock.Text;
bool added = false;
foreach (UserInfo user in syncContacts.Values)
{
if (user.Username == username)
{
string phoneNumber = user.PhoneNumber;
added = AddSyncContact(user, phoneNumber);
if (added)
{
MessageBox.Show($"Username added to friends: {username}");
}
else
{
RemoveSyncContact(user.PhoneNumber);
MessageBox.Show($"Username removed from friends: {username}");
}
SaveFriendsToXml();
}
}
StringBuilder stringBuilder = new StringBuilder();
foreach (UserInfo friend in friends.Values)
{
stringBuilder.AppendLine(friend.Username + ',' + friend.PhoneNumber);
}
string friendsList = stringBuilder.ToString();
MessageBox.Show("Friends List:\n\n" + friendsList);
}
}
}
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<friends>
<friend>
<Id>68ce0f1a-b031-4c62-b2d2-f297e2f68768</Id>
<username>@delia.gherasim</username>
<email></email>
<phoneNumber>0743111222</phoneNumber>
<birthday>1995-05-05T00:00:00</birthday>
</friend>
</friends>
@@ -0,0 +1,27 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace District_3_App.FriendsSettings
{
public class User
{
public Guid Id { get; set; }
public string Username { get; set; }
public string? Email { get; set; }
public string PhoneNumber { get; set; }
public DateTime? Birthday { get; set; }
public User(string newUsername, string newPhoneNumber)
{
Username = newUsername;
PhoneNumber = newPhoneNumber;
}
public User()
{
}
}
}
@@ -0,0 +1,27 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace District_3_App.FriendsSettings
{
public class UserInfo
{
public Guid Id { get; set; }
public string Username { get; set; }
public string? Email { get; set; }
public string PhoneNumber { get; set; }
public DateTime? Birthday { get; set; }
public UserInfo(string newUsername, string newPhoneNumber)
{
Username = newUsername;
PhoneNumber = newPhoneNumber;
}
public UserInfo()
{
}
}
}
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="utf-8" ?>
<viewers>
<viewer>
<Id>fc0e19f2-114f-47f1-a25a-1245035bc7b3</Id>
<username>@patri.stoica</username>
<email>email1@example.com</email>
<phoneNumber>0752111222</phoneNumber>
<birthday>2000-01-01T00:00:00</birthday>
</viewer>
<viewer>
<Id>68ce0f1a-b031-4c62-b2d2-f297e2f68768</Id>
<username>@delia.gherasim</username>
<phoneNumber>0743111222</phoneNumber>
<birthday>1995-05-05T00:00:00</birthday>
</viewer>
<viewer>
<Id>xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxz</Id>
<username>@anita.gorog</username>
<phoneNumber>0755111222</phoneNumber>
<birthday>1995-08-05T00:00:00</birthday>
</viewer>
</viewers>
Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB