Refactor code structure for improved readability and maintainability

This commit is contained in:
2025-08-06 21:21:34 +02:00
commit f539289f45
96 changed files with 45934 additions and 0 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,394 @@
using Avalonia;
using Avalonia.Controls;
using Avalonia.Controls.ApplicationLifetimes;
using Avalonia.Input;
using Avalonia.Interactivity;
using Avalonia.Markup.Xaml;
using Avalonia.Media;
using AvaloniaApplication1.DataBase;
using DaireApplication.DataBase;
using DaireApplication.Views;
using System;
using System.Threading;
using System.Threading.Tasks;
namespace DaireApplication;
public partial class Admin : UserControl
{
private MainWindow? _mainWindow;
private UserTable? _currentUser;
private MachineTable _machine;
private ConfigrationTable _configration;
private CancellationTokenSource _cancellationTokenSource;
private bool _isLongPress = false;
public Admin()
{
InitializeComponent();
_machine = new MachineTable();
_machine = _machine.ReadMachine();
}
public Admin(MainWindow mainWindow, UserTable currentUser)
{
_currentUser = currentUser;
_mainWindow = mainWindow;
_machine = new MachineTable();
_machine = _machine.ReadMachine();
_configration = new();
InitializeComponent();
setDefaultSettings();
setDafaultValues();
AttachHandlers(_mainWindow.logoBtn, AdvanceSettingsView);
AttachHandlers(_mainWindow.UserName, CloseApplication);
_mainWindow.minimizeBtn.Click += MinimizeButton_Click;
}
public void AttachHandlers(Button button,System.EventHandler<Avalonia.Input.HoldingRoutedEventArgs> func)
{
if (button != null)
{
button.Holding += func;
button.PointerPressed += (sender, e) =>
{
// Simulate a long press on any pointer (mouse or touch)
var point = e.GetPosition(button);
func(sender, new HoldingRoutedEventArgs(HoldingState.Started, point, e.Pointer.Type));
};
button.PointerReleased += (sender, e) =>
{
// End simulated long press
var point = e.GetPosition(button);
func(sender, new HoldingRoutedEventArgs(HoldingState.Completed, point, e.Pointer.Type));
};
}
}
private void MinimizeButton_Click(object? sender, RoutedEventArgs e)
{
_mainWindow.WindowState = Avalonia.Controls.WindowState.Minimized;
}
public static void CloseApplication(object? sender, RoutedEventArgs e)
{
var lifetime = Application.Current?.ApplicationLifetime as IClassicDesktopStyleApplicationLifetime;
lifetime?.Shutdown(); // This should correctly shut down the application
}
public void AdvanceSettingsView(object? sender, RoutedEventArgs e)
{
if (_mainWindow.ContentArea.Content== this )
{
_mainWindow.ContentArea.Content = new AdvanceSettings(_mainWindow);
}
}
private async void changeValue(object? sender, RoutedEventArgs e)
{
if (sender is Button button)
{
var gridParent = button.Parent as Grid;
var stack = gridParent.Children[1] as StackPanel;
var targetText = stack.Children[0] as TextBlock;
// Handle single click behavior (just increase or decrease by 1)
int currentValue = int.TryParse(targetText.Text, out var value) ? value : 0;
if (gridParent.Tag.ToString() != "pMint" && gridParent.Tag.ToString() != "aMint")
{
if (button.Content.ToString() == "+")
{
targetText.Text = (currentValue + 1).ToString();
}
else
{
if (currentValue>0)
{
targetText.Text = (currentValue - 1).ToString();
}
}
}
else
{
if (button.Content.ToString() == "+")
{
if (currentValue<0)
{
targetText.Text = (currentValue + 1).ToString();
}
}
else
{
targetText.Text = (currentValue - 1).ToString();
}
}
// Perform machine updates based on the tag
MachineTable data = _machine.ReadMachine();
data.Id = _machine.Id;
if (gridParent.Tag.ToString() == "pMaxt")
data.PumbMaxHeat = int.Parse(targetText.Text);
else if (gridParent.Tag.ToString() == "pMint")
data.PumbMinHeat = int.Parse(targetText.Text);
else if (gridParent.Tag.ToString() == "tmt")
data.TankMaxHeat = int.Parse(targetText.Text);
else if (gridParent.Tag.ToString() == "pd")
data.PumbDelay = int.Parse(targetText.Text);
else if (gridParent.Tag.ToString() == "pht")
data.PreHeatingTemp = int.Parse(targetText.Text);
else if (gridParent.Tag.ToString() == "md")
data.MixerDelay = int.Parse(targetText.Text);
else if (gridParent.Tag.ToString() == "pouring")
data.PouringDelay = int.Parse(targetText.Text);
else if (gridParent.Tag.ToString() == "cooling")
data.CoolingDelay = int.Parse(targetText.Text);
else if (gridParent.Tag.ToString() == "heating")
data.HeatingDelay = int.Parse(targetText.Text);
else if (gridParent.Tag.ToString() == "aMaxt")
{
data.AbsMaxHeat = int.Parse(targetText.Text);
var allConfigrations = _configration.ReadConfigrations();
foreach (var item in allConfigrations)
{
item.Max = (int)data.AbsMaxHeat;
_configration.UpdateConfigration(item);
}
_mainWindow.sendConfig = true;
}
else if (gridParent.Tag.ToString() == "aMint")
{
data.AbsMinHeat = int.Parse(targetText.Text);
var coolingConfig = _configration.ReadConfigrationById("3");
//var pumbConfig = _configration.ReadConfigrationById("4");
coolingConfig.Min = (int)data.AbsMinHeat;
_configration.UpdateConfigration(coolingConfig);
//pumbConfig.Min = 0;
//_configration.UpdateConfigration(pumbConfig);
_mainWindow.sendConfig = true;
}
_machine.UpdateMachine(data);
_mainWindow._machine = _machine.ReadMachine();
}
else if (sender is Border border)
{
Button button1 = this.FindControl<Button>(border.Tag.ToString());
var gridParent = button1.Parent as Grid;
var stack = gridParent.Children[1] as StackPanel;
var targetText = stack.Children[0] as TextBlock;
// Handle single click behavior (just increase or decrease by 1)
int currentValue = int.TryParse(targetText.Text, out var value) ? value : 0;
if (gridParent.Tag.ToString() != "pMint" && gridParent.Tag.ToString() != "aMint")
{
if (button1.Content.ToString() == "+")
{
targetText.Text = (currentValue + 1).ToString();
}
else
{
if (currentValue > 0)
{
targetText.Text = (currentValue - 1).ToString();
}
}
}
else
{
if (button1.Content.ToString() == "+")
{
if (currentValue < 0)
{
targetText.Text = (currentValue + 1).ToString();
}
}
else
{
targetText.Text = (currentValue - 1).ToString();
}
}
// Perform machine updates based on the tag
MachineTable data = _machine.ReadMachine();
data.Id = _machine.Id;
if (gridParent.Tag.ToString() == "pMaxt")
data.PumbMaxHeat = int.Parse(targetText.Text);
else if (gridParent.Tag.ToString() == "pMint")
data.PumbMinHeat = int.Parse(targetText.Text);
else if (gridParent.Tag.ToString() == "tmt")
data.TankMaxHeat = int.Parse(targetText.Text);
else if (gridParent.Tag.ToString() == "pd")
data.PumbDelay = int.Parse(targetText.Text);
else if (gridParent.Tag.ToString() == "pht")
data.PreHeatingTemp = int.Parse(targetText.Text);
else if (gridParent.Tag.ToString() == "md")
data.MixerDelay = int.Parse(targetText.Text);
else if (gridParent.Tag.ToString() == "pouring")
data.PouringDelay = int.Parse(targetText.Text);
else if (gridParent.Tag.ToString() == "cooling")
data.CoolingDelay = int.Parse(targetText.Text);
else if (gridParent.Tag.ToString() == "heating")
data.HeatingDelay = int.Parse(targetText.Text);
else if (gridParent.Tag.ToString() == "aMaxt")
{
data.AbsMaxHeat = int.Parse(targetText.Text);
var allConfigrations = _configration.ReadConfigrations();
foreach (var item in allConfigrations)
{
item.Max = (int)data.AbsMaxHeat;
_configration.UpdateConfigration(item);
}
_mainWindow.sendConfig = true;
}
else if (gridParent.Tag.ToString() == "aMint")
{
data.AbsMinHeat = int.Parse(targetText.Text);
var coolingConfig = _configration.ReadConfigrationById("3");
//var pumbConfig = _configration.ReadConfigrationById("4");
coolingConfig.Min = (int)data.AbsMinHeat;
_configration.UpdateConfigration(coolingConfig);
//pumbConfig.Min = 0;
//_configration.UpdateConfigration(pumbConfig);
_mainWindow.sendConfig = true;
}
_machine.UpdateMachine(data);
_mainWindow._machine = _machine.ReadMachine();
}
}
// Handle holding event
private async void OnLongRecipeClick(object? sender, RoutedEventArgs e)
{
if (e is HoldingRoutedEventArgs args)
{
if (args.HoldingState == HoldingState.Started)
{
_isLongPress = true;
if (sender is Button button)
{
var gridParent = button.Parent as Grid;
var stack = gridParent.Children[1] as StackPanel;
var targetText = stack.Children[0] as TextBlock;
await ChangeValueRapidly(button.Content.ToString()=="+", targetText); // Start rapid increase
args.Handled = true;
}
else if(sender is Border border)
{
Button button1 = this.FindControl<Button>(border.Tag.ToString());
var gridParent = button1.Parent as Grid;
var stack = gridParent.Children[1] as StackPanel;
var targetText = stack.Children[0] as TextBlock;
await ChangeValueRapidly(button1.Content.ToString() == "+", targetText); // Start rapid increase
args.Handled = true;
}
}
else if (args.HoldingState == HoldingState.Completed || args.HoldingState == HoldingState.Cancelled)
{
_isLongPress = false;
// Stop the rapid value change when the holding is completed
_cancellationTokenSource?.Cancel();
}
}
}
private async Task ChangeValueRapidly(bool isIncrease, TextBlock targetText)
{
// Start rapid value change when the button is held
_cancellationTokenSource?.Cancel(); // Cancel any previous task
_cancellationTokenSource = new CancellationTokenSource();
var token = _cancellationTokenSource.Token;
int currentValue = 0;
while (!token.IsCancellationRequested)
{
currentValue = int.TryParse(targetText.Text, out var value) ? value : 0;
if (targetText.Name!= "fountainMinTemp" && targetText.Name != "absMinTemp")
{
if (isIncrease)
{
targetText.Text = (currentValue + 1).ToString();
}
else
{
if (currentValue>0)
{
targetText.Text = (currentValue -1).ToString();
}
}
}
else
{
if (isIncrease)
{
if (currentValue < 0)
{
targetText.Text = (currentValue + 1).ToString();
}
}
else
{
targetText.Text = (currentValue - 1).ToString();
}
}
await Task.Delay(150); // Change speed here
}
}
private void setDafaultValues()
{
fountainMaxTemp.Text = _machine.PumbMaxHeat.ToString();
tankMaxTemp.Text = _machine.TankMaxHeat.ToString();
pumbDelay.Text = _machine.PumbDelay.ToString();
mixerDelay.Text = _machine.MixerDelay.ToString();
heatingPause.Text = _machine.HeatingDelay.ToString();
coolingPause.Text = _machine.CoolingDelay.ToString();
pouringPause.Text = _machine.PouringDelay.ToString();
fountainMinTemp.Text=_machine.PumbMinHeat.ToString();
absMaxTemp.Text= _machine.AbsMaxHeat.ToString();
absMinTemp.Text= _machine.AbsMinHeat.ToString();
preHeatingTemp.Text= _machine.PreHeatingTemp.ToString();
}
private void setDefaultSettings()
{
_mainWindow.minimizeBtn.IsVisible = true;
//Set Track Up
_mainWindow.HomeTrack.IsVisible = true;
//_mainWindow.HomePolygon.Stroke = Avalonia.Media.Brushes.Black;
_mainWindow.RecipeSelTrack.IsVisible = false;
_mainWindow.RunInterfaceTrack.IsVisible = false;
_mainWindow.RecipePanelTrack.IsVisible = false;
_mainWindow.RecipeEditTrack.IsVisible = false;
_mainWindow.DiagnosticsTrack.IsVisible = false;
_mainWindow.AdvanceSettingsTrack.IsVisible = false;
_mainWindow.SoftwareTrack.IsVisible = false;
_mainWindow.SettingTrack.IsVisible = true;
_mainWindow.SettingPolygon.Stroke = Brush.Parse("#A4275D"); ;
_mainWindow.TitleBtn.IsVisible = false;
//_mainWindow.Title.Text = _recipeTable.Name;
//Set Footer
_mainWindow.footerMsg.IsVisible = false;
_mainWindow.footer.Background = Avalonia.Media.Brushes.WhiteSmoke;
_mainWindow.footerDate.Text = DateTime.Now.ToString("dd/MM/yyyy");
_mainWindow.footerTime.Text = DateTime.Now.ToString("hh:mm tt");
_mainWindow.footerDateContainer.IsVisible = true;
_mainWindow.footerStartBtn.IsVisible = false;
_mainWindow.adminBtns.IsVisible = true;
_mainWindow.version.IsVisible = true;
}
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,140 @@
<UserControl xmlns="https://github.com/avaloniaui"
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"
x:Class="DaireApplication.Home"
Width="1280" Height="620" >
<Grid RowDefinitions="*">
<!--Main Body-->
<Grid Grid.Row="0" ColumnDefinitions="Auto,*" >
<Grid Grid.Column="1" HorizontalAlignment="Center"
VerticalAlignment="Center" Height="698" Width="465" >
<Grid x:Name="machinePic" IsVisible="True">
<Grid.Background >
<ImageBrush Source="/Assets/Machine.png"/>
</Grid.Background>
</Grid>
<Grid x:Name="CalcGrid" MaxWidth="350" MaxHeight="500" IsVisible="False">
<Grid.Styles>
<Style Selector="Button">
<Setter Property="Background" Value="White"></Setter>
<Setter Property="CornerRadius" Value="20"></Setter>
<Setter Property="Width" Value="100"></Setter>
<Setter Property="Height" Value="100"></Setter>
<Setter Property="FontSize" Value="50"></Setter>
<Setter Property="Foreground" Value="Black"></Setter>
<Setter Property="VerticalContentAlignment" Value="Center"></Setter>
<Setter Property="HorizontalContentAlignment" Value="Center"></Setter>
</Style>
<Style Selector="Button:pointerover /template/ContentPresenter">
<Setter Property="Foreground" Value="Black"></Setter>
<Setter Property="Background" Value="White"></Setter>
<Setter Property="CornerRadius" Value="20"></Setter>
<Setter Property="RenderTransform" Value="scale(1.11)"></Setter>
</Style>
</Grid.Styles>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<!-- TextBox for Input -->
<TextBox x:Name="InputTextBox" Grid.Row="0" Width="300" Height="50" FontSize="20" HorizontalAlignment="Center" Margin="10" IsReadOnly="True" PasswordChar="*"/>
<!-- Keypad Grid -->
<Grid Grid.Row="1" Margin="10">
<Grid.RowDefinitions>
<RowDefinition Height="1*" />
<RowDefinition Height="1*" />
<RowDefinition Height="1*" />
<RowDefinition Height="1*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="1*" />
<ColumnDefinition Width="1*" />
<ColumnDefinition Width="1*" />
</Grid.ColumnDefinitions>
<!-- Number Buttons -->
<Button Content="1" Grid.Row="0" Grid.Column="0" FontSize="24" Background="White" Margin="5" Click="OnKeyClick" />
<Button Content="2" Grid.Row="0" Grid.Column="1" FontSize="24" Background="White" Margin="5" Click="OnKeyClick" />
<Button Content="3" Grid.Row="0" Grid.Column="2" FontSize="24" Background="White" Margin="5" Click="OnKeyClick" />
<Button Content="4" Grid.Row="1" Grid.Column="0" FontSize="24" Background="White" Margin="5" Click="OnKeyClick" />
<Button Content="5" Grid.Row="1" Grid.Column="1" FontSize="24" Background="White" Margin="5" Click="OnKeyClick" />
<Button Content="6" Grid.Row="1" Grid.Column="2" FontSize="24" Background="White" Margin="5" Click="OnKeyClick" />
<Button Content="7" Grid.Row="2" Grid.Column="0" FontSize="24" Background="White" Margin="5" Click="OnKeyClick" />
<Button Content="8" Grid.Row="2" Grid.Column="1" FontSize="24" Background="White" Margin="5" Click="OnKeyClick" />
<Button Content="9" Grid.Row="2" Grid.Column="2" FontSize="24" Background="White" Margin="5" Click="OnKeyClick" />
<!-- Control Buttons -->
<Button Content="BACK" Grid.Row="3" Grid.Column="0" FontSize="20" Background="#D3D3D3" Margin="5" Click="OnBackClick" />
<Button Content="0" Grid.Row="3" Grid.Column="1" FontSize="24" Background="White" Margin="5" Click="OnKeyClick" />
<Button x:Name="loginBtn" Content="ENTER" Grid.Row="3" Grid.Column="2" FontSize="20" Background="#A4275D" Foreground="White" Margin="5" Click="LogIn" />
</Grid>
</Grid>
</Grid>
<Grid Grid.Column="0" RowDefinitions="Auto,1.5*">
<StackPanel Margin="10,50,0,10" Grid.Row="0" HorizontalAlignment="Center" >
<Label Foreground="Black" FontSize="30" FontWeight="Normal" >USER SELECTION</Label>
</StackPanel>
<ScrollViewer Grid.Row="1" HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto" Margin="0,0">
<Grid x:Name="DynamicGrid">
<!-- Define three columns -->
<Grid.ColumnDefinitions>
<ColumnDefinition Width="1*"/>
<ColumnDefinition Width="1*"/>
<ColumnDefinition Width="1*"/>
<ColumnDefinition Width="1*"/>
</Grid.ColumnDefinitions>
<Grid.Styles>
<Style Selector="Button">
<Setter Property="Background" Value="White"></Setter>
</Style>
<Style Selector="Button:pointerover /template/ContentPresenter">
<Setter Property="RenderTransform" Value="scale(1.11)"></Setter>
<Setter Property="Background" Value="White"></Setter>
</Style>
</Grid.Styles>
<!-- Dynamic rows will be generated programmatically in code-behind -->
</Grid>
</ScrollViewer>
</Grid>
</Grid>
</Grid>
</UserControl>

View File

@@ -0,0 +1,755 @@
using Avalonia;
using Avalonia.Controls;
using Avalonia.Controls.Shapes;
using Avalonia.Interactivity;
using Avalonia.Layout;
using Avalonia.Media;
using AvaloniaApplication1.DataBase;
using DaireApplication.DataBase;
using DaireApplication.Views;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
namespace DaireApplication;
public partial class Home : UserControl
{
private Button? _previousButton;
private Button? currentButton;
private UserTable _userRepo = new UserTable();
private MainWindow? _mainWindow;
public Home()
{
}
public Home(MainWindow mainWindow)
{
_mainWindow = mainWindow;
InitializeComponent();
// Migrate legacy data to AppData directory
DataPathManager.MigrateLegacyData();
setDefaultSettings();
setDefaultUsers();
setDefaultRecipe();
setDefaultMachine();
SetDefaultMapping();
SetDefaultConfigration();
SetDefaultScreen();
SetDefaultErrorSettings();
addDynamicButtons();
_mainWindow.UserName.Holding -= Admin.CloseApplication;
}
private async void OnUserButtonClick(object? sender, RoutedEventArgs e)
{
if (sender is Button button) // Ensure the sender is the button that triggered the event
{
currentButton = button;
if (_previousButton != null)
{
if (_previousButton == button)
{
if (button.Tag == "1")
{
CalcGrid.IsVisible = !CalcGrid.IsVisible;
machinePic.IsVisible = !machinePic.IsVisible;
return;
}
else
{
loginBtn.RaiseEvent(new RoutedEventArgs(Button.ClickEvent));
}
}
ResetButtonColor(_previousButton);
}
var textBlock = button.Content as TextBlock;
if (textBlock != null)
{
textBlock.Foreground = Avalonia.Media.Brushes.DeepPink;
}
button.BorderBrush = Avalonia.Media.Brushes.DeepPink;
button.BorderThickness = new Thickness(3);
_previousButton = button;
if (button.Tag == "1")
{
CalcGrid.IsVisible = !CalcGrid.IsVisible;
machinePic.IsVisible = !machinePic.IsVisible;
}
else
{
loginBtn.RaiseEvent(new RoutedEventArgs(Button.ClickEvent));
}
//CalcGrid.IsVisible = !CalcGrid.IsVisible;
//machinePic.IsVisible = !machinePic.IsVisible;
}
//End UI...
}
private void LogIn(object? sender, RoutedEventArgs e)
{
if (sender is Button button)
{
var users = _userRepo.ReadUsers();
string inputText = InputTextBox.Text;
foreach (var item in users)
{
if (currentButton.Content is Grid grid)
{
if (grid.Children[0] is TextBlock textBlock)
{
if (textBlock.Text == item.UserName)
{
if (item.IsActive)
{
if (inputText == item.Password)
{
var userName = _mainWindow.FindControl<Button>("UserName");
userName.Content = item.UserName;
Program.currentUser = item;
if (item.IsAdmin == true)
{
_mainWindow.holdingRegister.resetError = 0;
_mainWindow.restBoard = true;
_mainWindow.FindControl<ContentControl>("ContentArea").Content = new Admin(_mainWindow, item);
return;
}
else
{
_mainWindow.FindControl<ContentControl>("ContentArea").Content = new Recipe(_mainWindow, item);
InputTextBox.Text = string.Empty;
return;
}
}
else
{
_mainWindow.TextCenter.HorizontalAlignment = HorizontalAlignment.Center;
_mainWindow.footerMsg.Text = "Wrong Password!!";
_mainWindow.footerMsg.IsVisible = true;
_mainWindow.footer.Background = Avalonia.Media.Brushes.Red;
_mainWindow.footerMsg.Foreground = Avalonia.Media.Brushes.White;
_mainWindow.footerMsg.HorizontalAlignment = HorizontalAlignment.Center;
_mainWindow.footerDateContainer.IsVisible = false;
_mainWindow.footerStartBtn.IsVisible = false;
}
}
else
{
var userName = _mainWindow.FindControl<Button>("UserName");
userName.Content = item.UserName;
Program.currentUser = item;
if (item.IsAdmin == true)
{
_mainWindow.holdingRegister.resetError = 0;
_mainWindow.restBoard = true;
_mainWindow.FindControl<ContentControl>("ContentArea").Content = new Admin(_mainWindow, item);
return;
}
else
{
_mainWindow.FindControl<ContentControl>("ContentArea").Content = new Recipe(_mainWindow, item);
InputTextBox.Text = string.Empty;
return;
}
}
}
}
}
}
}
// Display or use the input text
// Clear the text after showing the message
InputTextBox.Text = string.Empty;
}
private void OnKeyClick(object? sender, RoutedEventArgs e)
{
if (sender is Button button)
{
// Append the button's content to the input box
InputTextBox.Text += button.Content?.ToString();
}
}
private void OnBackClick(object? sender, RoutedEventArgs e)
{
if (!string.IsNullOrEmpty(InputTextBox.Text))
{
// Remove the last character from the text box
InputTextBox.Text = InputTextBox.Text.Remove(InputTextBox.Text.Length - 1);
}
}
private void ResetButtonColor(Button button)
{
button.BorderBrush = Avalonia.Media.Brushes.White;
var textBlock = button.Content as TextBlock;
if (textBlock != null)
{
textBlock.Foreground = Avalonia.Media.Brushes.Black;
}
// Reset the color of the TextBlock inside the button
}
private void addDynamicButtons()
{
var users = _userRepo.ReadUsers();
var grid = this.FindControl<Grid>("DynamicGrid");
int userIdex = 0;
if (users.Count < 2)
{
for (int i = 0; i < (int)Math.Ceiling((double)users.Count / 2); i++) // Example: 20 rows
{
grid.RowDefinitions.Add(new RowDefinition { Height = GridLength.Auto });
// Add content for each column
for (int col = 0; col < 2; col++)
{
// StackPanel for the LED indicator dots
var indicatorPanel = new StackPanel
{
Orientation = Orientation.Horizontal,
HorizontalAlignment = HorizontalAlignment.Center,
Margin = new Thickness(10),
Spacing = 10
};
// Adding the indicator dots dynamically
if (users[userIdex + col].IsAdmin)
{
var colors = new[] { Brush.Parse("#A4275D"), Brush.Parse("#A4275D"), Brush.Parse("#A4275D") };
foreach (var color in colors)
{
indicatorPanel.Children.Add(new Rectangle
{
Width = 30,
Height = 10,
Fill = color,
RadiusX = 3,
RadiusY = 3,
Margin = new Thickness(3),
VerticalAlignment = VerticalAlignment.Bottom,
});
}
}
else if (users[userIdex + col].CanEdit)
{
var colors = new[] { Brush.Parse("#A4275D"), Brush.Parse("#A4275D") };
foreach (var color in colors)
{
indicatorPanel.Children.Add(new Rectangle
{
Width = 30,
Height = 10,
Fill = color,
RadiusX = 3,
RadiusY = 3,
Margin = new Thickness(3),
VerticalAlignment = VerticalAlignment.Bottom,
});
}
}
else
{
var colors = new[] { Brush.Parse("#A4275D") };
foreach (var color in colors)
{
indicatorPanel.Children.Add(new Rectangle
{
Width = 30,
Height = 10,
Fill = color,
RadiusX = 3,
RadiusY = 3,
Margin = new Thickness(3),
VerticalAlignment = VerticalAlignment.Bottom,
});
}
}
// Create a Grid for button content with two rows:
// Row 0 (star) holds the text (centered) and Row 1 (auto) holds the indicator dots at the bottom.
var buttonContent = new Grid();
buttonContent.RowDefinitions.Add(new RowDefinition { Height = new GridLength(1, GridUnitType.Star) });
buttonContent.RowDefinitions.Add(new RowDefinition { Height = GridLength.Auto });
// TextBlock centered in first row
var textBlock = new TextBlock
{
Padding = new Thickness(10),
Text = users[userIdex + col].UserName,
FontSize = 40,
FontWeight = FontWeight.Normal,
Foreground = Avalonia.Media.Brushes.Black,
HorizontalAlignment = HorizontalAlignment.Center,
VerticalAlignment = VerticalAlignment.Center,
};
// Place the text in the first row
Grid.SetRow(textBlock, 0);
// Place the indicator panel in the second row
Grid.SetRow(indicatorPanel, 1);
// Add both elements to the grid
buttonContent.Children.Add(textBlock);
buttonContent.Children.Add(indicatorPanel);
// Create the button with the new content layout
var button = new Button
{
Width = 290,
Height = 190,
Margin = new Thickness(10),
Content = buttonContent,
Tag = users[userIdex + col].IsActive ? "1" : "0",
CornerRadius = new CornerRadius(10),
Background = Avalonia.Media.Brushes.White,
HorizontalAlignment = HorizontalAlignment.Center,
VerticalAlignment = VerticalAlignment.Bottom,
};
button.Click += OnUserButtonClick;
grid.Children.Add(button);
Grid.SetRow(button, i);
Grid.SetColumn(button, col);
}
userIdex += 2;
}
}
else
{
for (int i = 0; i < (int)Math.Ceiling((double)users.Count / 2); i++) // Example: 20 rows
{
grid.RowDefinitions.Add(new RowDefinition { Height = GridLength.Auto });
// Add content for each column
for (int col = 0; col < 2; col++)
{
// StackPanel for the LED indicator dots
var indicatorPanel = new StackPanel
{
Orientation = Orientation.Horizontal,
HorizontalAlignment = HorizontalAlignment.Center,
Margin = new Thickness(10),
Spacing = 10
};
// Adding the indicator dots dynamically
if (users[userIdex + col].IsAdmin)
{
var colors = new[] { Brush.Parse("#A4275D"), Brush.Parse("#A4275D"), Brush.Parse("#A4275D") };
foreach (var color in colors)
{
indicatorPanel.Children.Add(new Rectangle
{
Width = 30,
Height = 10,
Fill = color,
RadiusX = 3,
RadiusY = 3,
Margin = new Thickness(3),
VerticalAlignment = VerticalAlignment.Bottom,
});
}
}
else if (users[userIdex + col].CanEdit)
{
var colors = new[] { Brush.Parse("#A4275D"), Brush.Parse("#A4275D") };
foreach (var color in colors)
{
indicatorPanel.Children.Add(new Rectangle
{
Width = 30,
Height = 10,
Fill = color,
RadiusX = 3,
RadiusY = 3,
Margin = new Thickness(3),
VerticalAlignment = VerticalAlignment.Bottom,
});
}
}
else
{
var colors = new[] { Brush.Parse("#A4275D") };
foreach (var color in colors)
{
indicatorPanel.Children.Add(new Rectangle
{
Width = 30,
Height = 10,
Fill = color,
RadiusX = 3,
RadiusY = 3,
Margin = new Thickness(3),
VerticalAlignment = VerticalAlignment.Bottom,
});
}
}
// Create a Grid for button content with two rows:
// Row 0 (star) holds the text (centered) and Row 1 (auto) holds the indicator dots at the bottom.
var buttonContent = new Grid();
buttonContent.RowDefinitions.Add(new RowDefinition { Height = new GridLength(1, GridUnitType.Star) });
buttonContent.RowDefinitions.Add(new RowDefinition { Height = GridLength.Auto });
// TextBlock centered in first row
var textBlock = new TextBlock
{
Padding = new Thickness(10),
Text = users[userIdex + col].UserName,
FontSize = 40,
FontWeight = FontWeight.Normal,
Foreground = Avalonia.Media.Brushes.Black,
HorizontalAlignment = HorizontalAlignment.Center,
VerticalAlignment = VerticalAlignment.Center,
};
// Place the text in the first row
Grid.SetRow(textBlock, 0);
// Place the indicator panel in the second row
Grid.SetRow(indicatorPanel, 1);
// Add both elements to the grid
buttonContent.Children.Add(textBlock);
buttonContent.Children.Add(indicatorPanel);
// Create the button with the new content layout
var button = new Button
{
Width = 290,
Height = 190,
Margin = new Thickness(10),
Tag = users[userIdex + col].IsActive ? "1" : "0",
Content = buttonContent,
CornerRadius = new CornerRadius(10),
Background = Avalonia.Media.Brushes.White,
HorizontalAlignment = HorizontalAlignment.Center,
VerticalAlignment = VerticalAlignment.Bottom,
};
button.Click += OnUserButtonClick;
grid.Children.Add(button);
Grid.SetRow(button, i);
Grid.SetColumn(button, col);
}
userIdex += 2;
}
}
}
private void setDefaultUsers()
{
string filePath = DataPathManager.GetDataFilePath("Users.csv");
List<UserTable> users = new List<UserTable>();
if (!File.Exists(filePath))
{
string csvHeader = "ID,UserName,Password,CanEdit,IsAdmin,IsActive";
users.Add(new UserTable
{
Id = 1,
UserName = "ADMIN",
Password = "1111",
CanEdit = true,
IsAdmin = true,
IsActive = false
}
);
users.Add(new UserTable
{
Id = 2,
UserName = "CHEF",
Password = "2222",
CanEdit = true,
IsAdmin = false,
IsActive = false
}
);
users.Add(new UserTable
{
Id = 3,
UserName = "OPERATOR1",
Password = "3333",
CanEdit = false,
IsAdmin = false,
IsActive = false
}
);
users.Add(new UserTable
{
Id = 4,
UserName = "OPERATOR2",
Password = "4444",
CanEdit = false,
IsAdmin = false,
IsActive = false
}
);
List<string> lines = new List<string>();
foreach (var item in users)
{
lines.Add(string.Join(",", [item.Id, item.UserName, item.Password, item.CanEdit ? "1" : "0", item.IsAdmin ? "1" : "0", item.IsActive ? "1" : "0"]));
}
File.WriteAllLines(filePath, new string[] { csvHeader });
File.AppendAllLines(filePath, lines);
}
}
private void setDefaultRecipe()
{
string filePath = DataPathManager.GetDataFilePath("Recipe.csv");
List<RecipeTable> recipes = new List<RecipeTable>();
if (!File.Exists(filePath))
{
string csvHeader = "ID,Name,TankTemp,FountainTemp,Mixer,Fountain,MoldHeater,Vibration,VibHeater,Pedal,PedalOnTime,PedalOffTime,HeatingGoal,CoolingGoal,PouringGoal";
recipes.Add(new RecipeTable
{
Id = 1,
Name = "MILK",
Mixer = false,
Fountain = false,
MoldHeater = false,
Vibration = false,
VibHeater = false,
Pedal = false
}
);
List<string> lines = new List<string>();
foreach (var item in recipes)
{
if (item != null)
{
lines.Add(string.Join(",", [1, item.Name, item.TankTemp, item.FountainTemp, item.Mixer.Value ? "1" : "0", item.Fountain.Value ? "1" : "0", item.MoldHeater.Value ? "1" : "0", item.Vibration.Value ? "1" : "0", item.VibHeater.Value ? "1" : "0", item.Pedal.Value ? "1" : "0", item.PedalOnTime, item.PedalOffTime, item.HeatingGoal, item.CoolingGoal, item.PouringGoal]));
}
}
File.WriteAllLines(filePath, new string[] { csvHeader });
File.AppendAllLines(filePath, lines);
}
}
private void setDefaultMachine()
{
string filePath = DataPathManager.GetDataFilePath("Machine.csv");
MachineTable machine = new MachineTable();
if (!File.Exists(filePath))
{
string csvHeader = "ID,TankMaxHeat,PumbMaxHeat,PumbDelay,MixerDelay,HeatingDelay,CoolingDelay,PouringDelay,PumbMinHeat,AbsMaxTemp,AbsMinTemp,PreHeatingTemp,SetTemp1,SetTemp2,SetTemp3,SetTemp4";
string line = string.Join(",", ["1", machine.TankMaxHeat, machine.PumbMaxHeat, machine.PumbDelay, machine.MixerDelay, machine.HeatingDelay, machine.CoolingDelay, machine.PouringDelay, machine.PumbMinHeat, machine.AbsMaxHeat, machine.AbsMinHeat, machine.PreHeatingTemp, machine.setTemp1, machine.setTemp2, machine.setTemp3, machine.setTemp4]);
File.WriteAllLines(filePath, new string[] { csvHeader });
File.AppendAllText(filePath, line);
}
}
private void SetDefaultMapping()
{
string filePath = DataPathManager.GetDataFilePath("Mapping.csv");
if (!File.Exists(filePath))
{
string csvHeader = "Id,Name,Address,IsRead,BitNumbers";
string[] defaultMappings =
{
string.Join(",", "1", "Pedal", "1", "1", "0"),
string.Join(",", "2", "Cover Sensor", "1", "1", "1"),
string.Join(",", "3", "E-Stop", "1", "1", "2"),
string.Join(",", "4", "Tank Bottom Temp", "8", "1", "8"),
string.Join(",", "5", "Tank Wall Temp", "9", "1", "9"),
string.Join(",", "6", "Pump Temp", "10", "1", "10"),
string.Join(",", "7", "Fountain Temp", "11", "1", "11"),
string.Join(",", "8", "Vibrator Heater", "2", "0", "0"),
string.Join(",", "9", "Mold Heater", "2", "0", "1"),
string.Join(",", "10", "Alarm", "2", "0", "2"),
string.Join(",", "11", "Vibrator", "1", "0", "0"),
string.Join(",", "12", "Water", "1", "0", "1"),
string.Join(",", "13", "Compressor", "1", "0", "2"),
string.Join(",", "14", "HELIX Heater", "1", "0", "3"),
string.Join(",", "15", "Tank Heater Bottom", "1", "0", "4"),
string.Join(",", "16", "Tank Heater Wall", "1", "0", "5"),
string.Join(",", "17", "Mixer", "3", "0", "0"),
string.Join(",", "18", "Helix", "3", "0", "1")
};
File.WriteAllLines(filePath, new[] { csvHeader }.Concat(defaultMappings));
}
}
private void SetDefaultConfigration()
{
string filePath = DataPathManager.GetDataFilePath("Configration.csv");
if (!File.Exists(filePath))
{
string csvHeader = "Id,Max,Min,H_out,FC_out,SC_out,kp,ki,kd,kl,Name,I_Nuet,I_Mot1,I_Mot2,FC_Threshold,HeatConRange";
string[] defaultConfigrations =
{
string.Join(",", "1", $"70", "0", "4", "-1", "-1", "50", "30", "20", "0","Tank Heater Bottom","14","3","3","0.3","10.0"),
string.Join(",", "2", $"70", "0", "5", "-1", "-1", "50", "30", "20", "0","Tank Heater Wall","0","0","0","0.3","10.0"),
string.Join(",", "3", $"70", $"-10", "3", "2|1", "1", "50", "30", "20", "0","HELIX Heater","0","0","0","0.3","10.0"),
string.Join(",", "4", $"70", "0", "3", "2|1", "1", "50", "30", "20", "0","","0","0","0","0.3","5")
};
File.WriteAllLines(filePath, new[] { csvHeader }.Concat(defaultConfigrations));
}
}
private void setDefaultSettings()
{
_mainWindow.minimizeBtn.IsVisible = false;
//Set Track Up
_mainWindow.HomeTrack.IsVisible = true;
//_mainWindow.HomePolygon.Stroke = Brush.Parse("#A4275D");
_mainWindow.RecipeSelTrack.IsVisible = false;
_mainWindow.RecipeEditTrack.IsVisible = false;
_mainWindow.RecipePanelTrack.IsVisible = false;
_mainWindow.RunInterfaceTrack.IsVisible = false;
_mainWindow.SettingTrack.IsVisible = false;
_mainWindow.TitleBtn.IsVisible = false;
_mainWindow.DiagnosticsTrack.IsVisible = false;
_mainWindow.AdvanceSettingsTrack.IsVisible = false;
_mainWindow.SoftwareTrack.IsVisible = false;
_mainWindow.version.IsVisible = false;
_mainWindow.ManualControlTrack.IsVisible = false;
//Set Footer
_mainWindow.footerMsg.Text = "";
_mainWindow.footerMsg.MaxWidth = 1000;
_mainWindow.footer.Background = Avalonia.Media.Brushes.WhiteSmoke;
_mainWindow.footerMsg.Foreground = Avalonia.Media.Brushes.Black;
_mainWindow.footerDate.Text = DateTime.Now.ToString("dd/MM/yyyy");
_mainWindow.footerTime.Text = DateTime.Now.ToString("hh:mm tt");
_mainWindow.footerDateContainer.IsVisible = true;
_mainWindow.footerStartBtn.IsVisible = false;
_mainWindow.adminBtns.IsVisible = false;
_mainWindow.chefBtns.IsVisible = false;
}
private void SetDefaultErrorSettings()
{
string filePath = DataPathManager.GetDataFilePath("ErrorSettings.csv");
if (!File.Exists(filePath))
{
ErrorSettingsTable error = new ErrorSettingsTable
{
Id = 1,
gridFreq = 50,
phaseNumber = 3,
extPower = true,
phaseVoltage = 220
};
string csvHeader = "Id,gridFreq,phaseNumber,extPower,phaseVoltage";
string line = string.Join(",", new[] { error.Id.ToString(), error.gridFreq.ToString(), error.phaseNumber.ToString(), error.extPower ? "1" : "0", error.phaseVoltage.ToString() });
File.WriteAllLines(filePath, new[] { csvHeader, line });
}
}
private void SetDefaultScreen()
{
string filePath = DataPathManager.GetDataFilePath("Screen.csv");
if (!File.Exists(filePath))
{
ScreeenTable screen = new ScreeenTable
{
Id = 1,
brightness = 100,
dimSec = 3300,
offSec = 3600,
port = "",
boundRate = 19200,
parity = 1,
stopBits = 0,
sendingTime = 50,
warningLimit = 1,
errorLimit = 2
};
string csvHeader = "Id,Brightness,DimSec,OffSec,Port,BoundRate,Parity,StopBits,SendingTime,WarningLimit,ErrorLimit";
string line = string.Join(",", new[] {
screen.Id.ToString(),
screen.brightness.ToString(),
screen.dimSec.ToString(),
screen.offSec.ToString(),
screen.port,
screen.boundRate.ToString(),
screen.parity.ToString(),
screen.stopBits.ToString(),
screen.sendingTime.ToString(),
screen.warningLimit.ToString(),
screen.errorLimit.ToString()
});
File.WriteAllLines(filePath, new[] { csvHeader, line });
}
}
}

View File

@@ -0,0 +1,535 @@
<UserControl xmlns="https://github.com/avaloniaui"
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"
Width="1280"
Height="620"
Background="#B3B3B3"
x:Class="DaireApplication.ManualControl">
<Grid RowDefinitions="*">
<Grid Grid.Row="0" ColumnDefinitions="*,Auto,*">
<Grid Grid.Column="0" RowDefinitions="2*,0.9*,2*" Margin="0,0,-100,0">
<!--1st box-->
<StackPanel Grid.Row="0" HorizontalAlignment="Right" VerticalAlignment="Center">
<Border
Width="290"
Height="150"
Background="#f9f9f9"
CornerRadius="10"
Padding="5,10">
<StackPanel Spacing="5">
<TextBlock
FontSize="15"
HorizontalAlignment="Center"
Foreground="#ff0000"
FontWeight="Medium">HELIX HEATING CONTROL</TextBlock>
<!--Temp Control-->
<StackPanel Orientation="Horizontal" Spacing="5">
<Border
Width="100"
Height="63"
Background="#e6e6e6"
CornerRadius="5"
Padding="5"
Tag="t3"
PointerPressed="ShowNumberKeyBoard">
<StackPanel Spacing="7">
<TextBlock
FontSize="15"
HorizontalAlignment="Center"
Foreground="#666666">SET TEMP.</TextBlock>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
<TextBlock
x:Name="setHelixText"
FontSize="23.5"
HorizontalAlignment="Center"
Foreground="#af196f">+0</TextBlock>
<TextBlock
FontSize="23.5"
HorizontalAlignment="Center"
Foreground="#af196f">°C</TextBlock>
</StackPanel>
</StackPanel>
</Border>
<Border
Width="100"
Height="63"
Background="#e6e6e6"
CornerRadius="5"
Padding="5">
<StackPanel Spacing="7">
<TextBlock
FontSize="15"
HorizontalAlignment="Center"
Foreground="#666666">REAL TEMP.</TextBlock>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
<TextBlock
x:Name="pumbRealTemp"
FontSize="23.5"
HorizontalAlignment="Center"
Foreground="#000000">
0
</TextBlock>
<TextBlock
FontSize="23.5"
HorizontalAlignment="Center"
Foreground="#000000">°C</TextBlock>
</StackPanel>
</StackPanel>
</Border>
<StackPanel Spacing="3">
<Border Width="70"
Height="30"
Background="#e6e6e6"
CornerRadius="5"
Padding="5">
<StackPanel Spacing="9">
<TextBlock FontSize="15"
HorizontalAlignment="Center"
Foreground="#231f20">AUTO</TextBlock>
<!-- Underline -->
<Rectangle Fill="#666666" Height="5" Width="60" Margin="0,-15,0,0"></Rectangle>
</StackPanel>
</Border>
<Border Width="70"
Height="30"
Background="#e6e6e6"
CornerRadius="5"
Padding="5">
<StackPanel Spacing="9">
<TextBlock FontSize="15"
HorizontalAlignment="Center"
Foreground="#231f20">ON/OFF</TextBlock>
<!-- Underline -->
<Rectangle Fill="#666666" Height="5" Width="60" Margin="0,-15,0,0"></Rectangle>
</StackPanel>
</Border>
</StackPanel>
</StackPanel>
<Border Width="276"
Height="40"
Background="#e6e6e6"
CornerRadius="5"
Padding="5">
<StackPanel Spacing="13">
<TextBlock
FontSize="19"
Foreground="#231f20"
HorizontalAlignment="Center">HELIX MOTOR ON / OFF</TextBlock>
<!-- Underline -->
<Rectangle Fill="#666666" Height="5" Width="265" Margin="0,-15,0,0"></Rectangle>
</StackPanel>
</Border>
</StackPanel>
</Border>
</StackPanel>
<!--2ed box-->
<StackPanel Grid.Row="1" HorizontalAlignment="Right" >
<Border
Width="290"
Height="55"
Background="#f9f9f9"
CornerRadius="10"
Padding="5">
<StackPanel>
<TextBlock FontSize="15"
Foreground="#800000"
HorizontalAlignment="Center"
FontWeight="Medium">TANK WALL TEMPERETURE</TextBlock>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
<TextBlock
x:Name="tankWallRealTemp"
FontSize="23"
FontWeight="DemiBold"
Foreground="#333333"
>0</TextBlock>
<TextBlock FontSize="23"
FontWeight="DemiBold"
Foreground="#333333"
>°C</TextBlock>
</StackPanel>
</StackPanel>
</Border>
</StackPanel>
<!--3rd box-->
<StackPanel Grid.Row="2" HorizontalAlignment="Right" >
<Border
Width="290"
Height="150"
Background="#f9f9f9"
CornerRadius="10"
Padding="5,10">
<StackPanel Spacing="5">
<TextBlock
FontSize="15"
HorizontalAlignment="Center"
Foreground="#ff0000"
FontWeight="Medium">TANK HEATING CONTROL</TextBlock>
<!--Temp Control-->
<StackPanel Orientation="Horizontal" Spacing="5">
<Border
Width="100"
Height="63"
Background="#e6e6e6"
CornerRadius="5"
Padding="5"
Tag="t1"
PointerPressed="ShowNumberKeyBoard">
<StackPanel Spacing="7">
<TextBlock
FontSize="15"
HorizontalAlignment="Center"
Foreground="#666666">SET TEMP.</TextBlock>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
<TextBlock
x:Name="setTankBtmText"
FontSize="23.5"
HorizontalAlignment="Center"
Foreground="#af196f">+0</TextBlock>
<TextBlock
FontSize="23.5"
HorizontalAlignment="Center"
Foreground="#af196f">°C</TextBlock>
</StackPanel>
</StackPanel>
</Border>
<Border
Width="100"
Height="63"
Background="#e6e6e6"
CornerRadius="5"
Padding="5">
<StackPanel Spacing="7">
<TextBlock
FontSize="15"
HorizontalAlignment="Center"
Foreground="#666666">REAL TEMP.</TextBlock>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
<TextBlock
x:Name="tankBtmRealTemp"
FontSize="23.5"
HorizontalAlignment="Center"
Foreground="#000000">0</TextBlock>
<TextBlock
FontSize="23.5"
HorizontalAlignment="Center"
Foreground="#000000">°C</TextBlock>
</StackPanel>
</StackPanel>
</Border>
<StackPanel Spacing="3">
<Border Width="70"
Height="30"
Background="#e6e6e6"
CornerRadius="5"
Padding="5">
<StackPanel Spacing="9">
<TextBlock FontSize="15"
HorizontalAlignment="Center"
Foreground="#231f20">AUTO</TextBlock>
<!-- Underline -->
<Rectangle Fill="#666666" Height="5" Width="60" Margin="0,-15,0,0"></Rectangle>
</StackPanel>
</Border>
<Border Width="70"
Height="30"
Background="#e6e6e6"
CornerRadius="5"
Padding="5">
<StackPanel Spacing="9">
<TextBlock FontSize="15"
HorizontalAlignment="Center"
Foreground="#231f20">ON/OFF</TextBlock>
<!-- Underline -->
<Rectangle Fill="#666666" Height="5" Width="60" Margin="0,-15,0,0"></Rectangle>
</StackPanel>
</Border>
</StackPanel>
</StackPanel>
<Border Width="276"
Height="40"
Background="#e6e6e6"
CornerRadius="5"
Padding="5">
<StackPanel Spacing="13">
<TextBlock
FontSize="19"
Foreground="#231f20"
HorizontalAlignment="Center">HELIX MOTOR ON / OFF</TextBlock>
<!-- Underline -->
<Rectangle Fill="#666666" Height="5" Width="265" Margin="0,-15,0,0"></Rectangle>
</StackPanel>
</Border>
</StackPanel>
</Border>
</StackPanel>
</Grid>
<Grid Grid.Column="1" Height="596" Width="484">
<Grid.Background >
<ImageBrush Source="/Assets/ManualControlMachine.png" />
</Grid.Background>
</Grid>
<Grid Grid.Column="2" RowDefinitions="*,0*,*,*" HorizontalAlignment="Left">
<Border Width="290"
Height="103"
Background="#f9f9f9"
CornerRadius="10"
HorizontalAlignment="Left"
Margin="-140,0,0,0"
Padding="5">
<StackPanel>
<TextBlock FontSize="15"
Foreground="#0000ff"
FontWeight="Medium"
HorizontalAlignment="Center">CHOCOLATE COOLING CONTROL</TextBlock>
<StackPanel Orientation="Horizontal" Spacing="5">
<Border
Width="100"
Height="63"
Background="#e6e6e6"
CornerRadius="5"
Padding="5"
Tag="t4"
PointerPressed="ShowNumberKeyBoard">
<StackPanel Spacing="7">
<TextBlock
FontSize="15"
HorizontalAlignment="Center"
Foreground="#666666">SET TEMP.</TextBlock>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
<TextBlock
x:Name="setChocolateText"
FontSize="23.5"
HorizontalAlignment="Center"
Foreground="#af196f">+0</TextBlock>
<TextBlock
FontSize="23.5"
HorizontalAlignment="Center"
Foreground="#af196f">°C</TextBlock>
</StackPanel>
</StackPanel>
</Border>
<Border
Width="100"
Height="63"
Background="#e6e6e6"
CornerRadius="5"
Padding="5">
<StackPanel Spacing="7">
<TextBlock
FontSize="15"
HorizontalAlignment="Center"
Foreground="#666666">REAL TEMP.</TextBlock>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
<TextBlock
x:Name="ChocolateRealTemp"
FontSize="23.5"
HorizontalAlignment="Center"
Foreground="#000000">0</TextBlock>
<TextBlock
FontSize="23.5"
HorizontalAlignment="Center"
Foreground="#000000">°C</TextBlock>
</StackPanel>
</StackPanel>
</Border>
<StackPanel Spacing="3">
<Border Width="70"
Height="30"
Background="#e6e6e6"
CornerRadius="5"
Padding="5">
<StackPanel Spacing="9">
<TextBlock FontSize="15"
HorizontalAlignment="Center"
Foreground="#231f20">AUTO</TextBlock>
<!-- Underline -->
<Rectangle Fill="#666666" Height="5" Width="60" Margin="0,-15,0,0"></Rectangle>
</StackPanel>
</Border>
<Border Width="70"
Height="30"
Background="#e6e6e6"
CornerRadius="5"
Padding="5">
<StackPanel Spacing="9">
<TextBlock FontSize="15"
HorizontalAlignment="Center"
Foreground="#231f20">ON/OFF</TextBlock>
<!-- Underline -->
<Rectangle Fill="#666666" Height="5" Width="60" Margin="0,-15,0,0"></Rectangle>
</StackPanel>
</Border>
</StackPanel>
</StackPanel>
</StackPanel>
</Border>
<Border Width="150"
Height="90"
Background="#f9f9f9"
Grid.Row="1" CornerRadius="10"
Padding="5"
PointerPressed="ToggleMoldHeaterClick"
>
<StackPanel>
<TextBlock FontSize="15"
Foreground="#666666"
HorizontalAlignment="Center">MOLD HEATER</TextBlock>
<TextBlock x:Name="MoldHeaterStatus" FontSize="47"
Foreground="#231f20"
HorizontalAlignment="Center">OFF</TextBlock>
<!-- Underline -->
<Rectangle x:Name="MoldHeaterUnderline" Fill="#666666" Height="5" Width="110" Margin="0,-10,0,0"></Rectangle>
</StackPanel>
</Border>
<Border Width="150"
Height="90"
Background="#f9f9f9"
Grid.Row="2" CornerRadius="10"
Padding="5"
PointerPressed="ToggleVibrationClick"
>
<StackPanel>
<TextBlock FontSize="15"
Foreground="#666666"
HorizontalAlignment="Center">VIBRATION</TextBlock>
<TextBlock x:Name="VibrationStatus" FontSize="47"
Foreground="#231f20"
HorizontalAlignment="Center">OFF</TextBlock>
<!-- Underline -->
<Rectangle x:Name="VibrationUnderline" Fill="#666666" Height="5" Width="110" Margin="0,-10,0,0"></Rectangle>
</StackPanel>
</Border>
<Border Width="150"
Height="90"
Background="#f9f9f9"
Grid.Row="3" CornerRadius="10"
VerticalAlignment="Top"
Margin="0,-20,0,0"
Padding="5"
PointerPressed="ToggleVibHeaterClick"
>
<StackPanel>
<TextBlock FontSize="15"
Foreground="#666666"
HorizontalAlignment="Center">VIB. HEATER</TextBlock>
<TextBlock x:Name="VibHeaterStatus" FontSize="47"
Foreground="#231f20"
HorizontalAlignment="Center">OFF</TextBlock>
<!-- Underline -->
<Rectangle x:Name="VibHeaterUnderline" Fill="#666666" Height="5" Width="110" Margin="0,-10,0,0"></Rectangle>
</StackPanel>
</Border>
</Grid>
</Grid>
<!--number keyBoard-->
<Border x:Name="keyBoardPopup"
Background="#80000000"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
IsVisible="False"
ZIndex="50"
PointerPressed="OnPopupOverlayPointerPressed">
<Grid MaxWidth="500" MaxHeight="500" HorizontalAlignment="Center" VerticalAlignment="Center"
Margin="0,0,0,0"
PointerPressed="InnerPopupPointerPressed">
<Border x:Name="PopupControl"
BorderThickness="2"
CornerRadius="10"
Padding="10"
PointerPressed="InnerPopupPointerPressed">
<StackPanel VerticalAlignment="Center" HorizontalAlignment="Center" Spacing="10">
<!-- Popup Content (Keypad etc.) -->
<Grid IsVisible="True">
<Grid.Styles>
<Style Selector="Button">
<Setter Property="Background" Value="White"/>
<Setter Property="CornerRadius" Value="20"/>
<Setter Property="Width" Value="100"/>
<Setter Property="Height" Value="100"/>
<Setter Property="FontSize" Value="50"/>
<Setter Property="Foreground" Value="Black"/>
<Setter Property="VerticalContentAlignment" Value="Center"/>
<Setter Property="HorizontalContentAlignment" Value="Center"/>
</Style>
<Style Selector="Button:pointerover /template/ContentPresenter">
<Setter Property="Foreground" Value="Black"/>
<Setter Property="Background" Value="White"/>
<Setter Property="CornerRadius" Value="20"/>
<Setter Property="RenderTransform" Value="scale(1.11)"/>
</Style>
</Grid.Styles>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Grid Grid.Row="1" Margin="10">
<Grid.RowDefinitions>
<RowDefinition Height="1*"/>
<RowDefinition Height="1*"/>
<RowDefinition Height="1*"/>
<RowDefinition Height="1*"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="1*"/>
<ColumnDefinition Width="1*"/>
<ColumnDefinition Width="1*"/>
<ColumnDefinition Width="1*"/>
</Grid.ColumnDefinitions>
<!-- Keypad Buttons -->
<Button Content="1" Grid.Row="0" Grid.Column="0" FontSize="24" Background="White" Margin="5" Click="OnKeyClick"/>
<Button Content="2" Grid.Row="0" Grid.Column="1" FontSize="24" Background="White" Margin="5" Click="OnKeyClick"/>
<Button Content="3" Grid.Row="0" Grid.Column="2" FontSize="24" Background="White" Margin="5" Click="OnKeyClick"/>
<Button Content="4" Grid.Row="1" Grid.Column="0" FontSize="24" Background="White" Margin="5" Click="OnKeyClick"/>
<Button Content="5" Grid.Row="1" Grid.Column="1" FontSize="24" Background="White" Margin="5" Click="OnKeyClick"/>
<Button Content="6" Grid.Row="1" Grid.Column="2" FontSize="24" Background="White" Margin="5" Click="OnKeyClick"/>
<Button Content="7" Grid.Row="2" Grid.Column="0" FontSize="24" Background="White" Margin="5" Click="OnKeyClick"/>
<Button Content="8" Grid.Row="2" Grid.Column="1" FontSize="24" Background="White" Margin="5" Click="OnKeyClick"/>
<Button Content="9" Grid.Row="2" Grid.Column="2" FontSize="24" Background="White" Margin="5" Click="OnKeyClick"/>
<Button Content="BACK" Grid.Row="3" Grid.Column="0" FontSize="20" Background="#D3D3D3" Margin="5" Click="OnBackClick"/>
<Button Content="0" Grid.Row="3" Grid.Column="1" FontSize="24" Background="White" Margin="5" Click="OnKeyClick"/>
<Button x:Name="enterBtn" Content="ENTER" Grid.Row="3" Grid.Column="2" FontSize="20" Background="#A4275D" Foreground="White" Margin="5" Click="EnterClick"/>
<Button Content="-" Grid.Row="3" Grid.Column="3" FontSize="50" Background="White" Foreground="Black"
Margin="5" Click="OnKeyClick"/>
<Button Content="+" Grid.Row="2" Grid.Column="3" FontSize="50" Background="White" Foreground="Black"
Margin="5" Click="OnKeyClick"/>
<Button Content="." Grid.Row="1" Grid.Column="3" FontSize="50" Background="White" Foreground="Black"
Margin="5" Click="OnKeyClick"/>
</Grid>
</Grid>
</StackPanel>
</Border>
</Grid>
</Border>
</Grid>
</UserControl>

View File

@@ -0,0 +1,266 @@
using Avalonia;
using Avalonia.Controls;
using Avalonia.Input;
using Avalonia.Interactivity;
using Avalonia.LogicalTree;
using Avalonia.Markup.Xaml;
using Avalonia.Media;
using DaireApplication.DataBase;
using DaireApplication.ViewModels;
using DaireApplication.Views;
using System;
using System.Collections.Generic;
using System.Reflection.PortableExecutable;
namespace DaireApplication;
public partial class ManualControl : UserControl
{
private MainWindow? _mainWindow;
bool isNegative = false;
TextBlock targetText = new TextBlock();
float oldValue = 0;
public MachineTable _machine { get; set; }
public ManualControl()
{
InitializeComponent();
}
public ManualControl(MainWindow mainWindow)
{
_mainWindow = mainWindow;
_machine = new MachineTable();
InitializeComponent();
setDefaultSettings();
getUiElementes();
}
private void setDefaultSettings()
{
_mainWindow.minimizeBtn.IsVisible = false;
//Set Track Up
_mainWindow.HomeTrack.IsVisible = true;
//_mainWindow.HomePolygon.Stroke = Avalonia.Media.Brushes.Black;
_mainWindow.RecipeSelTrack.IsVisible = false;
_mainWindow.RunInterfaceTrack.IsVisible = false;
_mainWindow.RecipePanelTrack.IsVisible = true;
_mainWindow.RecipePanelPolygon.Stroke = Avalonia.Media.Brushes.Black;
_mainWindow.RecipeEditTrack.IsVisible = false;
_mainWindow.DiagnosticsTrack.IsVisible = false;
_mainWindow.AdvanceSettingsTrack.IsVisible = false;
_mainWindow.SoftwareTrack.IsVisible = false;
_mainWindow.SettingTrack.IsVisible = false;
_mainWindow.TitleBtn.IsVisible = false;
_mainWindow.ManualControlTrack.IsVisible = true;
_mainWindow.ManualControlPolygon.Stroke = Brush.Parse("#A4275D");
//_mainWindow.Title.Text = _recipeTable.Name;
//Set Footer
_mainWindow.footerMsg.IsVisible = false;
_mainWindow.footer.Background = Avalonia.Media.Brushes.WhiteSmoke;
_mainWindow.footerDate.Text = DateTime.Now.ToString("dd/MM/yyyy");
_mainWindow.footerTime.Text = DateTime.Now.ToString("hh:mm tt");
_mainWindow.footerDateContainer.IsVisible = true;
_mainWindow.footerStartBtn.IsVisible = false;
_mainWindow.adminBtns.IsVisible = true;
_mainWindow.version.IsVisible = false;
_mainWindow.chefBtns.IsVisible = false;
}
private void ToggleMoldHeaterClick(object? sender, PointerPressedEventArgs e)
{
if (MoldHeaterStatus.Text == "ON")
{
_mainWindow.moldHeaterMotor = 0;
//MoldHeaterStatus.Text = "OFF";
//MoldHeaterUnderline.Fill = Brush.Parse("#666666");
}
else
{
_mainWindow.moldHeaterMotor = 1;
//MoldHeaterStatus.Text = "ON";
//MoldHeaterUnderline.Fill = Brush.Parse("#A4275D");
}
}
private void ToggleVibrationClick(object? sender, PointerPressedEventArgs e)
{
if (VibrationStatus.Text == "ON")
{
_mainWindow.vibrationMotor = 0;
//VibrationStatus.Text = "OFF";
//VibrationUnderline.Fill = Brush.Parse("#666666");
}
else
{
_mainWindow.vibrationMotor = 1;
//VibrationStatus.Text = "ON";
//VibrationUnderline.Fill = Brush.Parse("#A4275D");
}
}
private void ToggleVibHeaterClick(object? sender, PointerPressedEventArgs e)
{
if (VibHeaterStatus.Text == "ON")
{
_mainWindow.vibHeaterMotor = 0;
//VibHeaterStatus.Text = "OFF";
//VibHeaterUnderline.Fill = Brush.Parse("#666666");
}
else
{
_mainWindow.vibHeaterMotor = 1;
//VibHeaterStatus.Text = "ON";
//VibHeaterUnderline.Fill = Brush.Parse("#A4275D");
}
}
private void OnPopupOverlayPointerPressed(object sender, PointerPressedEventArgs e)
{
if (isNegative)
{
targetText.Text = "-" + oldValue.ToString("0.0");
}
else
{
targetText.Text = "+" + oldValue.ToString("0.0");
}
keyBoardPopup.IsVisible = false;
}
private void InnerPopupPointerPressed(object? sender, PointerPressedEventArgs e)
{
e.Handled = true;
}
private void OnKeyClick(object? sender, RoutedEventArgs e)
{
if (sender is Button button)
{
if ((button.Content == "+" || button.Content == "-") && targetText.Text.Length > 0)
{
}
else if ((targetText.Text.Length == 0 && button.Content == ".") || (targetText.Text.Contains(".") && button.Content == "."))
{
}
else
{
targetText.Text += button.Content;
}
}
}
private void OnBackClick(object? sender, RoutedEventArgs e)
{
if (!string.IsNullOrEmpty(targetText.Text))
{
// Remove the last character from the text box
targetText.Text = targetText.Text.Remove(targetText.Text.Length - 1, 1);
//number = number.Remove(number.Length - 1);
}
}
private async void EnterClick(object? sender, RoutedEventArgs e)
{
var tankBtm = _mainWindow._mapping.Find(x => x.Name.ToLower() == "Tank Bottom Temp".ToLower());
var pumb = _mainWindow._mapping.Find(x => x.Name.ToLower() == "Pump Temp".ToLower());
var fount = _mainWindow._mapping.Find(x => x.Name.ToLower() == "Fountain Temp".ToLower());
List<int> setTempValues = new List<int>();
setTempValues.AddRange([_mainWindow.holdingRegister.setTemp1, _mainWindow.holdingRegister.setTemp2, _mainWindow.holdingRegister.setTemp3, _mainWindow.holdingRegister.setTemp4]);
if (sender is Button button)
{
if (!string.IsNullOrEmpty(targetText.Text))
{
float number = float.Parse(targetText.Text);
if (char.IsDigit(targetText.Text[0]))
{
targetText.Text = "+" + number.ToString("0.0");
}
else
{
targetText.Text = number.ToString("0.0");
}
var machine = _machine.ReadMachine();
if (button.Tag.ToString() == "t1")
{
foreach (var item in tankBtm.BitNumbers)
{
setTempValues[item - 8] = (int)(number * 10);
}
machine.setTemp1 = number;
}
else if (button.Tag.ToString() == "t3")
{
foreach (var item in pumb.BitNumbers)
{
setTempValues[item - 8] = (int)(number * 10);
}
machine.setTemp3 = number;
}
else if (button.Tag.ToString() == "t4")
{
foreach (var item in fount.BitNumbers)
{
setTempValues[item - 8] = (int)(number * 10);
}
machine.setTemp4 = number;
}
_mainWindow.holdingRegister.setTemp1 = setTempValues[0];
_mainWindow.holdingRegister.setTemp2 = setTempValues[1];
_mainWindow.holdingRegister.setTemp3 = setTempValues[2];
_mainWindow.holdingRegister.setTemp4 = setTempValues[3];
_machine.UpdateMachine(machine);
getUiElementes();
keyBoardPopup.IsVisible = false;
await _mainWindow.WriteToSerialAsync("DiagnosticsEnter");
}
}
}
private void ShowNumberKeyBoard(object? sender, PointerPressedEventArgs e)
{
if (sender is Border border)
{
//var parent = border.Parent as StackPanel;
//var brother = parent.Children[0] as Border;
//targetButton = brother.Child as Button;
if (border.Tag?.ToString() == "t1")
{
targetText = setTankBtmText;
}
else if (border.Tag?.ToString() == "t3")
{
targetText = setHelixText;
}
else if (border.Tag?.ToString() == "t4")
{
targetText = setChocolateText;
}
enterBtn.Tag = border.Tag;
isNegative = targetText.Text.StartsWith("-");
var x = targetText.Text.Substring(1);
oldValue = float.Parse(x);
targetText.Text = "";
keyBoardPopup.IsVisible = true;
}
}
private void getUiElementes()
{
var machine = _machine.ReadMachine();
setTankBtmText.Text = char.IsDigit(machine.setTemp1.ToString()[0]) ? "+" + machine.setTemp1.ToString() : machine.setTemp1.ToString("0.0");
setHelixText.Text = char.IsDigit(machine.setTemp3.ToString()[0]) ? "+" + machine.setTemp3.ToString() : machine.setTemp3.ToString("0.0");
setChocolateText.Text = char.IsDigit(machine.setTemp4.ToString()[0]) ? "+" + machine.setTemp4.ToString() : machine.setTemp4.ToString("0.0");
}
}

View File

@@ -0,0 +1,341 @@
<UserControl xmlns="https://github.com/avaloniaui"
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"
Width="1200"
x:Class="DaireApplication.Recipe">
<Grid RowDefinitions="*">
<!-- Main Area-->
<Grid Grid.Row="0" ColumnDefinitions="Auto,1.5*" >
<Grid Grid.Column="1" >
<Grid x:Name="machinePic" Height="698" Width="465" >
<Grid.Background >
<ImageBrush Source="/Assets/Machine.png" Stretch="UniformToFill"/>
</Grid.Background>
</Grid>
</Grid>
<Grid Grid.Column="0" RowDefinitions="Auto,*">
<StackPanel Margin="10,50,0,10" Grid.Row="0" HorizontalAlignment="Center" >
<Label Foreground="#333333" FontSize="40" FontWeight="Normal" x:Name="RecipeTitle">Recipe SELECTION</Label>
</StackPanel>
<ScrollViewer Grid.Row="1" HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto" Margin="0,0">
<Grid x:Name="DynamicGrid">
<!-- Define three columns -->
<Grid.ColumnDefinitions>
<ColumnDefinition Width="1*"/>
<ColumnDefinition Width="1*"/>
<ColumnDefinition Width="1*"/>
</Grid.ColumnDefinitions>
<Grid.Styles>
<Style Selector="Button">
<Setter Property="Background" Value="White"></Setter>
</Style>
<Style Selector="Button:pointerover /template/ContentPresenter">
<Setter Property="RenderTransform" Value="scale(1.11)"></Setter>
<Setter Property="Background" Value="White"></Setter>
</Style>
</Grid.Styles>
<!-- Dynamic rows will be generated programmatically in code-behind -->
</Grid>
</ScrollViewer>
</Grid>
</Grid>
<!-- Overlay Background for Add Popup -->
<Border x:Name="PopupOverlay" Background="#80000000" Grid.RowSpan="3" IsVisible="False" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" ZIndex="99" PointerPressed="OnPopupOverlayPointerPressed">
<!-- Popup User Control -->
<!-- Module for Name Entry -->
<Grid x:Name="NameModule" PointerPressed="" HorizontalAlignment="Center" VerticalAlignment="Top" Margin="20" IsVisible="True">
<Border Background="White" CornerRadius="10" Padding="20" BorderThickness="1" ZIndex="101" BorderBrush="#CCC">
<StackPanel Spacing="15">
<!-- Label for Text Input -->
<!-- Label -->
<TextBlock x:Name="foucs" Text="Enter Recipe Name:"
FontSize="18"
FontWeight="Bold"
Foreground="#333"
Margin="0,0,0,8" />
<Border x:Name="nameBorder">
<TextBox x:Name="NameInput"
Width="300"
Height="30"
BorderBrush="#CCC"
BorderThickness="1"
MaxLength="9"
></TextBox>
</Border>
<!-- Local styles for this specific TextBox -->
<!-- Button Panel -->
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right" Spacing="10">
<!-- Save Button -->
<Button x:Name="SaveButton"
Content="Save"
FontSize="16"
Padding="10,5"
Click="saveRecipeClick"
Foreground="White" >
<Button.Background>
<LinearGradientBrush StartPoint="0,0" EndPoint="1,0">
<GradientStop Color="#A4275D" Offset="0" />
<GradientStop Color="#A4275D" Offset="1" />
</LinearGradientBrush>
</Button.Background>
<Button.Effect>
</Button.Effect>
</Button>
<!-- Cancel Button -->
<Button x:Name="CancelButton"
Content="Cancel"
FontSize="16"
Padding="10,5"
Background="Gray"
Foreground="White"
Click="OnPopupOverlayPointerPressed">
<Button.Effect>
</Button.Effect>
</Button>
</StackPanel>
</StackPanel>
</Border>
</Grid>
</Border>
<!-- Overlay Background for Delet Popup -->
<Border x:Name="managePopupOverlay" Background="#80000000" Grid.RowSpan="3" IsVisible="False" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" ZIndex="99" PointerPressed="OnDeletePopupOverlayPointerPressed">
<!-- Popup User Control -->
<!-- Module for Name Entry -->
<Grid PointerPressed="" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="20" IsVisible="True">
<Border Background="White" CornerRadius="10" Padding="20" BorderThickness="1" ZIndex="101" BorderBrush="#CCC">
<StackPanel Spacing="15">
<!-- Label for Text Input -->
<!-- Label -->
<TextBlock Text="modify the action "
FontSize="20"
FontWeight="Bold"
Foreground="Red"
Margin="0,0,0,8"
HorizontalAlignment="Center"/>
<!-- Button Panel -->
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center" Spacing="10">
<!-- update Button -->
<Button
Name="updateActionBtn"
Content="Update"
FontSize="16"
Padding="10,5"
Click="UpdateActionClick"
Foreground="White" >
<Button.Background>
<LinearGradientBrush StartPoint="0,0" EndPoint="1,0">
<GradientStop Color="#A4275D" Offset="0" />
<GradientStop Color="#A4275D" Offset="1" />
</LinearGradientBrush>
</Button.Background>
</Button>
<!-- delete Button -->
<Button
Name="deleteActionBtn"
Content="Delete"
FontSize="16"
Padding="10,5"
Click="deleteActionClick"
Foreground="White"
Background="Red">
</Button>
<!-- No Button -->
<Button
Content="Cancel"
FontSize="16"
Padding="10,5"
Background="Gray"
Foreground="White"
Click="OnDeletePopupOverlayPointerPressed">
<Button.Effect>
</Button.Effect>
</Button>
</StackPanel>
</StackPanel>
</Border>
</Grid>
</Border>
<!-- Overlay Background for Add Popup -->
<Border x:Name="updatePopupOverlay" Background="#80000000" Grid.RowSpan="3" IsVisible="False" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" ZIndex="99" PointerPressed="OnDeletePopupOverlayPointerPressed">
<!-- Popup User Control -->
<!-- Module for Name Entry -->
<Grid PointerPressed="" HorizontalAlignment="Center" VerticalAlignment="Top" Margin="20" IsVisible="True">
<Border Background="White" CornerRadius="10" Padding="20" BorderThickness="1" ZIndex="101" BorderBrush="#CCC">
<StackPanel Spacing="15">
<!-- Label for Text Input -->
<!-- Label -->
<TextBlock Text="Rename:"
FontSize="18"
FontWeight="Bold"
Foreground="#333"
Margin="0,0,0,8" />
<Border x:Name="updateBorder">
<TextBox x:Name="updateInput"
Width="300"
Height="30"
BorderBrush="#CCC"
BorderThickness="1"
MaxLength="9"
>
<!-- Local styles for this specific TextBox -->
<TextBox.Styles>
<!-- Normal (unfocused) style -->
<Style Selector="TextBox">
<Setter Property="Background" Value="White" />
<Setter Property="Foreground" Value="Black" />
</Style>
</TextBox.Styles>
</TextBox>
</Border>
<!-- Button Panel -->
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right" Spacing="10">
<!-- Save Button -->
<Button x:Name="saveUpdateBtn"
Content="Save"
FontSize="16"
Padding="10,5"
Click="SaveUpdateClick"
Foreground="White" >
<Button.Background>
<LinearGradientBrush StartPoint="0,0" EndPoint="1,0">
<GradientStop Color="#A4275D" Offset="0" />
<GradientStop Color="#A4275D" Offset="1" />
</LinearGradientBrush>
</Button.Background>
</Button>
<!-- Cancel Button -->
<Button x:Name="cancelBtn"
Content="Cancel"
FontSize="16"
Padding="10,5"
Background="Gray"
Foreground="White"
Click="OnDeletePopupOverlayPointerPressed">
<Button.Effect>
</Button.Effect>
</Button>
</StackPanel>
</StackPanel>
</Border>
</Grid>
</Border>
<!-- Overlay Background for Delet Popup -->
<Border x:Name="DeletePopupOverlay" Background="#80000000" Grid.RowSpan="3" IsVisible="False" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" ZIndex="99" PointerPressed="OnDeletePopupOverlayPointerPressed">
<!-- Popup User Control -->
<!-- Module for Name Entry -->
<Grid PointerPressed="" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="20" IsVisible="True">
<Border Background="White" CornerRadius="10" Padding="20" BorderThickness="1" ZIndex="101" BorderBrush="#CCC">
<StackPanel Spacing="15">
<!-- Label for Text Input -->
<!-- Label -->
<TextBlock Text="Delete Warning!!"
FontSize="20"
FontWeight="Bold"
Foreground="Red"
Margin="0,0,0,8" />
<StackPanel>
<TextBlock x:Name="deleteMsg" Text="Are you sure?"
FontSize="16"
FontWeight="Bold"
Foreground="#333"
Margin="0,0,0,8" />
</StackPanel>
<!-- Button Panel -->
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center" Spacing="10">
<!-- yes Button -->
<Button
Content="Yes"
FontSize="16"
Padding="10,5"
Click="YesBtnClick"
Foreground="White" >
<Button.Background>
<LinearGradientBrush StartPoint="0,0" EndPoint="1,0">
<GradientStop Color="#A4275D" Offset="0" />
<GradientStop Color="#A4275D" Offset="1" />
</LinearGradientBrush>
</Button.Background>
<Button.Effect>
</Button.Effect>
</Button>
<!-- No Button -->
<Button
Content="No"
FontSize="16"
Padding="10,5"
Background="Gray"
Foreground="White"
Click="OnDeletePopupOverlayPointerPressed">
<Button.Effect>
</Button.Effect>
</Button>
</StackPanel>
</StackPanel>
</Border>
</Grid>
</Border>
</Grid>
</UserControl>

View File

@@ -0,0 +1,719 @@
using Avalonia;
using Avalonia.Controls;
using Avalonia.Controls.ApplicationLifetimes;
using Avalonia.Input;
using Avalonia.Interactivity;
using Avalonia.Media;
using Avalonia.Threading;
using AvaloniaApplication1.DataBase;
using DaireApplication.Views;
using ReactiveUI;
using System;
using System.Diagnostics;
using System.Linq;
using System.Runtime.InteropServices;
using System.Threading.Tasks;
namespace DaireApplication;
public partial class Recipe : UserControl
{
Button recipeButton = new Button();
private bool _isLongPress;
private MainWindow? _mainWindow;
private UserTable? _currentUser;
private RecipeTable _recipeTable=new RecipeTable();
private Process? _keyboardProcess;
public Recipe()
{
InitializeComponent();
}
public Recipe(MainWindow mainWindow,UserTable currentUser)
{
_currentUser = currentUser;
_mainWindow = mainWindow;
InitializeComponent();
nameBorder.AddHandler(InputElement.PointerPressedEvent, OnTextBoxFocused, RoutingStrategies.Tunnel, handledEventsToo: true);
updateBorder.AddHandler(InputElement.PointerPressedEvent, OnTextBoxFocused, RoutingStrategies.Tunnel, handledEventsToo: true);
setDefaultSettings();
addDynamicButtons();
}
private async void OnRecipeClick(object? sender, RoutedEventArgs e)
{
if (_isLongPress)
{
// Reset the flag for future interactions.
_isLongPress = false;
// Ignore this click since a long press was detected.
return;
}
if (sender is Button button)
{
if (_currentUser.CanEdit)
{
_mainWindow.FindControl<ContentControl>("ContentArea").Content = new RecipeEdit(_mainWindow, _currentUser, _recipeTable.ReadRecipesById(button.Name));
}
else
{
_mainWindow.FindControl<ContentControl>("ContentArea").Content = new Settings(_mainWindow, _currentUser, _recipeTable.ReadRecipesById(button.Name));
_mainWindow.restBoard = true;
}
}
}
private async void deleteActionClick(object? sender, RoutedEventArgs e)
{
if (sender is Button button)
{
deleteMsg.Text = $"You are about to delete {button.Tag}";
DeletePopupOverlay.IsVisible = true;
}
}
private async void UpdateActionClick(object? sender, RoutedEventArgs e)
{
if (sender is Button button)
{
var text = recipeButton.Content as TextBlock;
updateInput.Text = $"{text.Text}";
updatePopupOverlay.IsVisible = true;
}
}
private void OnLongRecipeClick(object? sender, RoutedEventArgs e)
{
if (e is HoldingRoutedEventArgs args)
{
if (args.HoldingState == HoldingState.Started)
{
_isLongPress = true;
if (sender is Button button)
{
var targetText= button.Content as TextBlock;
deleteActionBtn.Tag = targetText.Text;
managePopupOverlay.IsVisible = true;
recipeButton = button;
//recipeButton = button;
//if (button.Content is TextBlock targetText)
//{
// deleteMsg.Text = $"You are about to delete {targetText.Text}";
//}
}
args.Handled = true;
}
else if (args.HoldingState == HoldingState.Completed)
{
_isLongPress = false;
}
}
}
private void CloseKeyboard()
{
try
{
if (_keyboardProcess != null)
{
// Kill the keyboard process
_keyboardProcess.Kill();
_keyboardProcess.Dispose();
_keyboardProcess = null;
// Force kill any remaining keyboard processes
var processKill = new Process
{
StartInfo = new ProcessStartInfo
{
FileName = "killall",
Arguments = "-9 onboard matchbox-keyboard florence", // Common Linux on-screen keyboards
UseShellExecute = false,
CreateNoWindow = true
}
};
processKill.Start();
processKill.WaitForExit(1000);
processKill.Dispose();
}
}
catch (Exception ex)
{
Console.WriteLine($"Error closing keyboard: {ex.Message}");
}
}
public void AttachHandlers(Button button)
{
if (button != null)
{
button.Holding += OnLongRecipeClick;
button.PointerPressed += (sender, e) =>
{
// Simulate a long press on any pointer (mouse or touch)
var point = e.GetPosition(button);
OnLongRecipeClick(sender, new HoldingRoutedEventArgs(HoldingState.Started, point, e.Pointer.Type));
};
button.PointerReleased += (sender, e) =>
{
// End simulated long press
var point = e.GetPosition(button);
OnLongRecipeClick(sender, new HoldingRoutedEventArgs(HoldingState.Completed, point, e.Pointer.Type));
};
}
}
private async void OnAddRecipeClick(object? sender, RoutedEventArgs e)
{
if (sender is Button button)
{
PopupOverlay.IsVisible = true;
}
}
private async void OnPopupOverlayPointerPressed(object? sender, RoutedEventArgs e)
{
PopupOverlay.IsVisible = false;
}
private async void OnDeletePopupOverlayPointerPressed(object? sender, RoutedEventArgs e)
{
DeletePopupOverlay.IsVisible = false;
managePopupOverlay.IsVisible = false;
updatePopupOverlay.IsVisible = false;
}
private async void YesBtnClick(object? sender, RoutedEventArgs e)
{
var result = _recipeTable.DeleteRecipe(recipeButton.Name);
if (result)
{
addDynamicButtons();
DeletePopupOverlay.IsVisible= false;
managePopupOverlay.IsVisible = false;
}
else
{
}
}
private async void SaveUpdateClick(object? sender, RoutedEventArgs e)
{
if (!_recipeTable.DoesNameExist(updateInput.Text))
{
var recipe = _recipeTable.ReadRecipesById(recipeButton.Name);
recipe.Name = updateInput.Text;
var result = _recipeTable.UpdateRecipe(recipe);
if (result)
{
addDynamicButtons();
managePopupOverlay.IsVisible = false;
updatePopupOverlay.IsVisible = false;
CloseKeyboard();
}
else
{
}
}
else
{
CloseKeyboard();
await MainWindow.MessageBox.Show(_mainWindow, "this name is already in use", "Error");
_mainWindow.Topmost = false;
_mainWindow.Focus();
_mainWindow.Activate();
}
}
private void showPopUp(object? sender, RoutedEventArgs e)
{
if (sender is Button button)
{
recipeButton = button;
button.Foreground = Brush.Parse("#A4275D");
PopupOverlay.IsVisible = true;
// Append the button's content to the input box
//InputTextBox.Text += button.Content?.ToString();
}
}
private async void saveRecipeClick(object? sender, RoutedEventArgs e)
{
if (sender is Button button)
{
if (!string.IsNullOrEmpty(NameInput.Text))
{
if (!_recipeTable.DoesNameExist(NameInput.Text))
{
RecipeTable data = new RecipeTable();
data.Name = NameInput.Text;
data.Mixer = false;
data.Fountain = false;
data.MoldHeater = false;
data.Vibration = false;
data.VibHeater = false;
data.Pedal = false;
var result = _recipeTable.AddRecipe(data);
if (result)
{
addDynamicButtons();
CloseKeyboard();
NameInput.Text = "";
PopupOverlay.IsVisible = false;
}
else
{
}
}
else
{
CloseKeyboard();
await MainWindow.MessageBox.Show(_mainWindow, "this name is already in use", "Error");
_mainWindow.Topmost = false;
_mainWindow.Activate();
}
}
}
}
private (string? fileName, string args) GetKeyboardCommand()
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
return ("osk.exe", "");
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
return ("onboard", ""); // or "florence", "matchbox-keyboard"
return (null, "");
}
private async void OnTextBoxFocused(object? sender, PointerPressedEventArgs e)
{
if (_keyboardProcess is { HasExited: false })
return;
var (fileName, args) = GetKeyboardCommand();
if (fileName is null)
return;
_keyboardProcess = new Process
{
StartInfo = new ProcessStartInfo
{
FileName = fileName,
Arguments = args,
UseShellExecute = true
},
EnableRaisingEvents = true
};
try
{
_keyboardProcess.Start();
Dispatcher.UIThread.Post(() =>
{
if (sender is Border border)
{
var textbox= border.Child as TextBox;
textbox.SelectionStart = 0;
textbox.SelectionEnd = textbox.Text?.Length ?? 0;
}
});
}
catch
{
// fail silently if keyboard not found
}
}
private void OnPopupOverlayPointerPressed(object sender, PointerPressedEventArgs e)
{
// Close the popup when clicking outside of it
recipeButton.Foreground = Avalonia.Media.Brushes.Black;
PopupOverlay.IsVisible = false;
}
private void setDefaultSettings()
{
//set recipe title
if (_currentUser.CanEdit)
{
RecipeTitle.Content = "RECIPE EDIT/ADD PANEL";
}
else
{
RecipeTitle.Content = "RECIPE SELECTION";
}
//Set Track Up
_mainWindow.HomeTrack.IsVisible = true;
_mainWindow.RecipeSelTrack.IsVisible = false;
_mainWindow.RecipePanelTrack.IsVisible = false;
if (_currentUser.CanEdit)
{
_mainWindow.RecipePanelTrack.IsVisible = true;
_mainWindow.RecipePanelPolygon.Stroke = Brush.Parse("#A4275D");
}
else
{
_mainWindow.RecipeSelTrack.IsVisible = true;
_mainWindow.RecipeSelPolygon.Stroke = Brush.Parse("#A4275D");
}
//_mainWindow.HomePolygon.Stroke = Avalonia.Media.Brushes.Black;
_mainWindow.RecipeEditTrack.IsVisible = false;
_mainWindow.RunInterfaceTrack.IsVisible = false;
_mainWindow.SettingTrack.IsVisible = false;
_mainWindow.TitleBtn.IsVisible = false;
_mainWindow.DiagnosticsTrack.IsVisible = false;
_mainWindow.SoftwareTrack.IsVisible = false;
//Set Footer
if (_currentUser.CanEdit)
{
_mainWindow.footerMsg.Text = "Long press to delete recipe";
_mainWindow.footerMsg.IsVisible = true;
_mainWindow.chefBtns.IsVisible = true;
}
else
{
_mainWindow.footerMsg.Text = "Select a recipe to start";
_mainWindow.footerMsg.IsVisible = true;
}
_mainWindow.ManualControlTrack.IsVisible = false;
_mainWindow.footerMsg.MaxWidth = 1000;
_mainWindow.footer.Background = Avalonia.Media.Brushes.WhiteSmoke;
_mainWindow.footerMsg.Foreground = Brush.Parse("#A4275D");
_mainWindow.footerDate.Text = DateTime.Now.ToString("dd/MM/yyyy");
_mainWindow.footerTime.Text = DateTime.Now.ToString("hh:mm tt");
_mainWindow.footerDateContainer.IsVisible = true;
_mainWindow.footerStartBtn.IsVisible = false;
_mainWindow.adminBtns.IsVisible = false;
}
private void addDynamicButtons()
{
var recipes= _recipeTable.ReadRecipes();
var grid = this.FindControl<Grid>("DynamicGrid");
grid.Children.Clear();
int lastRow = 0;
int lastCol = 0;
int colIndexForExtraData = 0;
int recipeIndex = 0;
try
{
if (recipes.Count<3)
{
// Add dynamic rows
for (int i = 0; i < (int)Math.Ceiling((double)recipes.Count / 3); i++) // Example: 20 rows
{
lastRow = i;
grid.RowDefinitions.Add(new RowDefinition { Height = GridLength.Auto });
// Add content for each column
for (int col = 0; col < recipes.Count; col++)
{
lastCol = col;
var text = new TextBlock
{
Padding = new Thickness(10),
Text = recipes[recipeIndex + col].Name,
VerticalAlignment = Avalonia.Layout.VerticalAlignment.Center,
HorizontalAlignment = Avalonia.Layout.HorizontalAlignment.Center,
FontSize = 31,
FontWeight=FontWeight.Normal,
Foreground = Avalonia.Media.Brushes.Black
};
var button = new Button
{
Width = 210,
Height = 160,
Margin = new Thickness(3),
Content = text,
Name = recipes[recipeIndex + col].Id.ToString(),
CornerRadius = new CornerRadius(10),
Background = Avalonia.Media.Brushes.White,
HorizontalAlignment = Avalonia.Layout.HorizontalAlignment.Center,
VerticalAlignment = Avalonia.Layout.VerticalAlignment.Center,
};
button.Click += OnRecipeClick;
if (_currentUser.CanEdit)
{
//button.Holding += OnLongRecipeClick;
AttachHandlers(button);
//button.DoubleTapped += OnDoubleRecipeClick;
}
grid.Children.Add(button);
Grid.SetRow(button, i);
Grid.SetColumn(button, col);
}
recipeIndex += 3;
}
if (_currentUser.CanEdit)
{
var Plus = new TextBlock
{
Padding = new Thickness(10),
Text = "+",
VerticalAlignment = Avalonia.Layout.VerticalAlignment.Center,
HorizontalAlignment = Avalonia.Layout.HorizontalAlignment.Center,
FontSize = 100,
Foreground = Brush.Parse("#A4275D")
};
var AddButtun = new Button
{
Width = 210,
Height = 160,
Margin = new Thickness(3),
Content = Plus,
CornerRadius = new CornerRadius(10),
Background = Avalonia.Media.Brushes.White,
HorizontalAlignment = Avalonia.Layout.HorizontalAlignment.Center,
VerticalAlignment = Avalonia.Layout.VerticalAlignment.Center,
VerticalContentAlignment = Avalonia.Layout.VerticalAlignment.Center,
HorizontalContentAlignment = Avalonia.Layout.HorizontalAlignment.Center,
Padding = new Thickness(0, 0, 0, 15),
};
AddButtun.Click += OnAddRecipeClick;
if (lastCol < 2)
{
grid.Children.Add(AddButtun);
Grid.SetRow(AddButtun, lastRow);
Grid.SetColumn(AddButtun, lastCol + 1);
}
else
{
grid.RowDefinitions.Add(new RowDefinition { Height = GridLength.Auto });
grid.Children.Add(AddButtun);
Grid.SetRow(AddButtun, lastRow + 1);
Grid.SetColumn(AddButtun, 0);
}
}
}
else
{
// Add dynamic rows
for (int i = 0; i < (int)Math.Floor((double)recipes.Count / 3); i++) // Example: 20 rows
{
lastRow = i;
grid.RowDefinitions.Add(new RowDefinition { Height = GridLength.Auto });
// Add content for each column
for (int col = 0; col < 3; col++)
{
lastCol = col;
var text = new TextBlock
{
Padding = new Thickness(10),
Text = recipes[recipeIndex + col].Name,
VerticalAlignment = Avalonia.Layout.VerticalAlignment.Center,
HorizontalAlignment = Avalonia.Layout.HorizontalAlignment.Center,
FontSize = 31,
FontWeight = FontWeight.Normal,
Foreground = Avalonia.Media.Brushes.Black
};
var button = new Button
{
Width = 210,
Height = 160,
Margin = new Thickness(3),
Content = text,
Name = recipes[recipeIndex + col].Id.ToString(),
CornerRadius = new CornerRadius(10),
Background = Avalonia.Media.Brushes.White,
HorizontalAlignment = Avalonia.Layout.HorizontalAlignment.Center,
VerticalAlignment = Avalonia.Layout.VerticalAlignment.Center,
};
button.Click += OnRecipeClick;
if (_currentUser.CanEdit)
{
//button.Holding += OnLongRecipeClick;
AttachHandlers(button);
//button.DoubleTapped += OnDoubleRecipeClick;
}
grid.Children.Add(button);
Grid.SetRow(button, i);
Grid.SetColumn(button, col);
}
recipeIndex += 3;
}
for (int i = 0; i < recipes.Count -recipeIndex; i++)
{
var text = new TextBlock
{
Padding = new Thickness(10),
Text = recipes[recipeIndex + i].Name,
VerticalAlignment = Avalonia.Layout.VerticalAlignment.Center,
HorizontalAlignment = Avalonia.Layout.HorizontalAlignment.Center,
FontSize = 31,
FontWeight = FontWeight.Normal,
Foreground = Avalonia.Media.Brushes.Black
};
var button = new Button
{
Width = 210,
Height = 160,
Margin = new Thickness(3),
Content = text,
Name = recipes[recipeIndex + i].Id.ToString(),
CornerRadius = new CornerRadius(10),
Background = Avalonia.Media.Brushes.White,
HorizontalAlignment = Avalonia.Layout.HorizontalAlignment.Center,
VerticalAlignment = Avalonia.Layout.VerticalAlignment.Center,
};
button.Click += OnRecipeClick;
if (_currentUser.CanEdit)
{
//button.Holding += OnLongRecipeClick;
AttachHandlers(button);
//button.DoubleTapped += OnDoubleRecipeClick;
}
if (lastCol < 2)
{
lastCol += 1;
grid.Children.Add(button);
Grid.SetRow(button,lastRow);
Grid.SetColumn(button, lastCol);
}
else
{
grid.RowDefinitions.Add(new RowDefinition { Height = GridLength.Auto });
grid.Children.Add(button);
Grid.SetRow(button, lastRow + 1);
Grid.SetColumn(button, colIndexForExtraData);
colIndexForExtraData += 1;
}
}
if (_currentUser.CanEdit)
{
var Plus = new TextBlock
{
Padding = new Thickness(10),
Text = "+",
VerticalAlignment = Avalonia.Layout.VerticalAlignment.Center,
HorizontalAlignment = Avalonia.Layout.HorizontalAlignment.Center,
FontSize = 100,
Foreground = Brush.Parse("#A4275D"),
};
var AddButtun = new Button
{
Width = 210,
Height = 160,
Margin = new Thickness(3),
Content = Plus,
CornerRadius = new CornerRadius(10),
Background = Avalonia.Media.Brushes.White,
VerticalContentAlignment = Avalonia.Layout.VerticalAlignment.Center,
HorizontalContentAlignment = Avalonia.Layout.HorizontalAlignment.Center,
HorizontalAlignment = Avalonia.Layout.HorizontalAlignment.Center,
VerticalAlignment = Avalonia.Layout.VerticalAlignment.Center,
Padding = new Thickness(0,0,0,15),
};
AddButtun.Click += OnAddRecipeClick;
if (lastCol < 2)
{
grid.Children.Add(AddButtun);
Grid.SetRow(AddButtun, lastRow);
Grid.SetColumn(AddButtun, lastCol + 1);
}
else
{
grid.RowDefinitions.Add(new RowDefinition { Height = GridLength.Auto });
grid.Children.Add(AddButtun);
Grid.SetRow(AddButtun, lastRow + 1);
Grid.SetColumn(AddButtun, colIndexForExtraData);
}
}
}
}
catch (Exception)
{
}
}
}

View File

@@ -0,0 +1,232 @@
<UserControl xmlns="https://github.com/avaloniaui"
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"
x:Class="DaireApplication.RecipeEdit"
Width="1200"
mc:Ignorable="d" >
<Grid>
<!-- Main Content (machine picture on left, etc.) -->
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="2*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<!-- Machine Picture on Left -->
<Grid Grid.Column="0">
<Grid x:Name="machinePic" IsVisible="True" Width="937" Height="567">
<Grid.Background>
<ImageBrush Source="/Assets/TemperingGraphics.png"/>
</Grid.Background>
</Grid>
</Grid>
<!-- (Optional additional content on right if needed) -->
</Grid>
<!-- Popup Overlay -->
<Border x:Name="PopupOverlay"
Background="#80000000"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
IsVisible="False"
ZIndex="50"
PointerPressed="OnPopupOverlayPointerPressed">
<Grid MaxWidth="500" MaxHeight="500" HorizontalAlignment="Center" VerticalAlignment="Center">
<Border x:Name="PopupControl"
BorderThickness="2"
CornerRadius="10"
Padding="10"
PointerPressed="OnPopupOverlayPointerPressed">
<StackPanel VerticalAlignment="Center" HorizontalAlignment="Center" Spacing="10">
<!-- Popup Content (Keypad etc.) -->
<Grid IsVisible="True">
<Grid.Styles>
<Style Selector="Button">
<Setter Property="Background" Value="White"/>
<Setter Property="CornerRadius" Value="20"/>
<Setter Property="Width" Value="100"/>
<Setter Property="Height" Value="100"/>
<Setter Property="FontSize" Value="50"/>
<Setter Property="Foreground" Value="Black"/>
<Setter Property="VerticalContentAlignment" Value="Center"/>
<Setter Property="HorizontalContentAlignment" Value="Center"/>
</Style>
<Style Selector="Button:pointerover /template/ContentPresenter">
<Setter Property="Foreground" Value="Black"/>
<Setter Property="Background" Value="White"/>
<Setter Property="CornerRadius" Value="20"/>
<Setter Property="RenderTransform" Value="scale(1.11)"/>
</Style>
</Grid.Styles>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Grid Grid.Row="1" Margin="10">
<Grid.RowDefinitions>
<RowDefinition Height="1*"/>
<RowDefinition Height="1*"/>
<RowDefinition Height="1*"/>
<RowDefinition Height="1*"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="1*"/>
<ColumnDefinition Width="1*"/>
<ColumnDefinition Width="1*"/>
</Grid.ColumnDefinitions>
<!-- Keypad Buttons -->
<Button Content="1" Grid.Row="0" Grid.Column="0" FontSize="24" Background="White" Margin="5" Click="OnKeyClick"/>
<Button Content="2" Grid.Row="0" Grid.Column="1" FontSize="24" Background="White" Margin="5" Click="OnKeyClick"/>
<Button Content="3" Grid.Row="0" Grid.Column="2" FontSize="24" Background="White" Margin="5" Click="OnKeyClick"/>
<Button Content="4" Grid.Row="1" Grid.Column="0" FontSize="24" Background="White" Margin="5" Click="OnKeyClick"/>
<Button Content="5" Grid.Row="1" Grid.Column="1" FontSize="24" Background="White" Margin="5" Click="OnKeyClick"/>
<Button Content="6" Grid.Row="1" Grid.Column="2" FontSize="24" Background="White" Margin="5" Click="OnKeyClick"/>
<Button Content="7" Grid.Row="2" Grid.Column="0" FontSize="24" Background="White" Margin="5" Click="OnKeyClick"/>
<Button Content="8" Grid.Row="2" Grid.Column="1" FontSize="24" Background="White" Margin="5" Click="OnKeyClick"/>
<Button Content="9" Grid.Row="2" Grid.Column="2" FontSize="24" Background="White" Margin="5" Click="OnKeyClick"/>
<Button Content="BACK" Grid.Row="3" Grid.Column="0" FontSize="20" Background="#D3D3D3" Margin="5" Click="OnBackClick"/>
<Button Content="0" Grid.Row="3" Grid.Column="1" FontSize="24" Background="White" Margin="5" Click="OnKeyClick"/>
<Button Content="ENTER" Grid.Row="3" Grid.Column="2" FontSize="20" Background="#A4275D" Foreground="White" Margin="5" Click="EnterClick"/>
</Grid>
</Grid>
</StackPanel>
</Border>
</Grid>
</Border>
<!-- Overlay Container for the Three Buttons (always at the right side) -->
<StackPanel x:Name="ButtonOverlayContainer"
Orientation="Vertical"
HorizontalAlignment="Right"
VerticalAlignment="Center"
Margin="0,0,20,20"
Spacing="20"
ZIndex="100"
>
<Border CornerRadius="10"
Background="White"
Padding="20"
Margin="20"
Width="270"
Height="400" ZIndex="49" >
<!-- Use a Grid with RowDefinitions to position elements -->
<Grid ZIndex="49">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<!-- First button -->
<RowDefinition Height="9*" />
<!-- Spacer to push content to bottom -->
<RowDefinition Height="Auto" />
<!-- Second button -->
<RowDefinition Height="3*" />
<!-- Spacer to push content to bottom -->
<RowDefinition Height="Auto" />
<!-- Third button -->
<RowDefinition Height="7*" />
<!-- Spacer to push content to bottom -->
<RowDefinition Height="Auto" />
<!-- Arrow + label at bottom -->
</Grid.RowDefinitions>
<Grid.Styles>
<Style Selector="Button:pointerover /template/ContentPresenter">
<Setter Property="Foreground" Value="Black"></Setter>
<Setter Property="Background" Value="LightGray"></Setter>
</Style>
</Grid.Styles>
<Grid.Styles>
<Style Selector="Button:disabled /template/ContentPresenter" >
<Setter Property="Background" Value="Gray"/>
<Setter Property="Foreground" Value="White"/>
</Style>
</Grid.Styles>
<!-- Red Button for Heating -->
<Button Grid.Row="0" x:Name="heatingBtn"
Background="#FFFF5252"
Foreground="White"
FontSize="25"
Padding="10,5"
BorderThickness="0"
Width="230"
HorizontalAlignment="Center"
HorizontalContentAlignment="Center"
CornerRadius="10"
Click="showPopUp"
>
<StackPanel Spacing="5" Orientation="Horizontal">
<TextBlock>HEATING: </TextBlock>
<TextBlock x:Name="heatingValue"></TextBlock>
<TextBlock> °C</TextBlock>
</StackPanel>
</Button>
<TextBlock Grid.Row="1" TextWrapping="WrapWithOverflow" VerticalAlignment="Center" FontWeight="Normal" FontSize="14" Foreground="Red" x:Name="tempErrorMsg">
</TextBlock>
<!-- Brown Button for Pouring -->
<Button Grid.Row="2" x:Name="pouringBtn"
Background="#FF795548"
Foreground="White"
FontSize="25"
Padding="10,5"
BorderThickness="0"
Width="230"
HorizontalAlignment="Center"
HorizontalContentAlignment="Center"
CornerRadius="10"
Click="showPopUp" >
<StackPanel Spacing="5" Orientation="Horizontal">
<TextBlock>POURING: </TextBlock>
<TextBlock x:Name="pouringValue"></TextBlock>
<TextBlock> °C</TextBlock>
</StackPanel>
</Button>
<!-- Blue Button for Cooling -->
<Button Grid.Row="4" x:Name="coolingBtn"
Classes="NotEnabled"
FontSize="25"
Background="#FF448AFF"
Foreground="White"
Padding="10,5"
BorderThickness="0"
Width="230"
HorizontalAlignment="Center"
CornerRadius="10"
HorizontalContentAlignment="Center"
Click="showPopUp" >
<StackPanel Spacing="5" Orientation="Horizontal">
<TextBlock>COOLING: </TextBlock>
<TextBlock x:Name="coolingValue"></TextBlock>
<TextBlock> °C</TextBlock>
</StackPanel>
</Button>
<!-- Arrow and 'EDIT HERE' Label at the Bottom -->
<StackPanel Grid.Row="6" HorizontalAlignment="Center">
<TextBlock Text="↑"
FontSize="50"
FontWeight="Normal"
HorizontalAlignment="Center"
Foreground="Black"/>
<TextBlock Text="EDIT HERE"
FontSize="30"
FontWeight="Normal"
HorizontalAlignment="Center"
Foreground="Black"
/>
</StackPanel>
</Grid>
</Border>
</StackPanel>
</Grid>
</UserControl>

View File

@@ -0,0 +1,253 @@
using Avalonia;
using Avalonia.Controls;
using Avalonia.Input;
using Avalonia.Interactivity;
using Avalonia.Markup.Xaml;
using Avalonia.Media;
using AvaloniaApplication1.DataBase;
using DaireApplication.Views;
using System;
namespace DaireApplication;
public partial class RecipeEdit : UserControl
{
Button controllButton = new Button();
private MainWindow? _mainWindow;
private UserTable? _currentUser;
private RecipeTable? _recipeTable;
public RecipeEdit()
{
InitializeComponent();
}
public RecipeEdit(MainWindow mainWindow, UserTable currentUser,RecipeTable recipeTable)
{
_currentUser = currentUser;
_mainWindow = mainWindow;
_recipeTable=recipeTable;
InitializeComponent();
setDefaultSettings();
}
string oldNumber = "";
private void OnKeyClick(object? sender, RoutedEventArgs e)
{
if (sender is Button button)
{
var StackPanel = controllButton.Content as StackPanel;
var Label = StackPanel.Children;
if (Label[1] is TextBlock targetText)
{
//number += button.Content?.ToString();
targetText.Text += button.Content ;
}
// Append the button's content to the input box
//InputTextBox.Text += button.Content?.ToString();
}
}
private void OnBackClick(object? sender, RoutedEventArgs e)
{
var StackPanel = controllButton.Content as StackPanel;
var Label = StackPanel.Children;
if (Label[1] is TextBlock targetText)
{
if (!string.IsNullOrEmpty(targetText.Text))
{
// Remove the last character from the text box
targetText.Text = targetText.Text.Remove(targetText.Text.Length -1, 1);
//number = number.Remove(number.Length - 1);
}
}
}
private void EnterClick(object? sender, RoutedEventArgs e)
{
// <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>
RecipeTable recipe = new RecipeTable
{
Id = _recipeTable.Id,
Name = _recipeTable.Name,
TankTemp = _recipeTable.TankTemp,
FountainTemp = _recipeTable.FountainTemp,
Mixer = _recipeTable.Mixer ?? false,
Fountain = _recipeTable.Fountain ?? false,
MoldHeater = _recipeTable.MoldHeater ?? false,
Vibration = _recipeTable.Vibration ?? false,
VibHeater = _recipeTable.VibHeater ?? false,
Pedal = _recipeTable.Pedal ?? false,
PedalOnTime = _recipeTable.PedalOnTime,
PedalOffTime = _recipeTable.PedalOffTime,
HeatingGoal = _recipeTable.HeatingGoal,
CoolingGoal = _recipeTable.CoolingGoal,
PouringGoal = _recipeTable.PouringGoal
};
var heatingStackPanel = heatingBtn.Content as StackPanel;
var heatingText = (heatingStackPanel?.Children[1] as TextBlock)?.Text;
var coolingStackPanel = coolingBtn.Content as StackPanel;
var coolingText = (coolingStackPanel?.Children[1] as TextBlock)?.Text;
var stackPanel = controllButton.Content as StackPanel;
var label = stackPanel?.Children;
var targetText = label?[1] as TextBlock;
var activeTxt = label?[0] as TextBlock;
if (activeTxt == null || targetText == null)
return;
switch (activeTxt.Text)
{
case "HEATING:":
if (!string.IsNullOrEmpty(targetText.Text) && int.TryParse(targetText.Text, out int heatingValue))
{
if (heatingValue > 60)
{
tempErrorMsg.Text = "Heating Temperature must be lower than 60 <20>C";
return;
}
else if (heatingValue < 40)
{
tempErrorMsg.Text = "Heating Temperature must be greater than 40 <20>C";
return;
}
recipe.HeatingGoal = heatingValue;
}
break;
case "POURING:":
if (!string.IsNullOrEmpty(targetText.Text) && int.TryParse(targetText.Text, out int pouringValue))
{
if (string.IsNullOrEmpty(heatingText) || string.IsNullOrEmpty(coolingText))
{
tempErrorMsg.Text = "Enter heating and cooling temperature first";
return;
}
if (!int.TryParse(heatingText, out int heatingTemp) || !int.TryParse(coolingText, out int coolingTemp))
{
tempErrorMsg.Text = "Invalid temperature values";
return;
}
if (pouringValue > heatingTemp)
{
tempErrorMsg.Text = $"Pouring Temperature must be lower than Heating Temperature ({heatingTemp}<7D>C)";
return;
}
else if (pouringValue < coolingTemp)
{
tempErrorMsg.Text = $"Pouring Temperature must be greater than Cooling Temperature ({coolingTemp}<7D>C)";
return;
}
recipe.PouringGoal = pouringValue;
}
break;
case "COOLING:":
if (!string.IsNullOrEmpty(targetText.Text) && int.TryParse(targetText.Text, out int coolingValue))
{
if (coolingValue > 40)
{
tempErrorMsg.Text = "Cooling Temperature must be lower than 40 <20>C";
return;
}
else if (coolingValue < 20)
{
tempErrorMsg.Text = "Cooling Temperature must be greater than 20 <20>C";
return;
}
recipe.CoolingGoal = coolingValue;
}
break;
}
_recipeTable.UpdateRecipe(recipe);
tempErrorMsg.Text = "";
heatingBtn.IsEnabled = true;
coolingBtn.IsEnabled = true;
pouringBtn.IsEnabled = true;
PopupOverlay.IsVisible = false;
setDefaultSettings();
}
private void showPopUp(object? sender, RoutedEventArgs e)
{
if (sender is Button button)
{
heatingBtn.IsEnabled = false;
coolingBtn.IsEnabled = false;
pouringBtn.IsEnabled = false;
button.IsEnabled = true;
var StackPanel = button.Content as StackPanel;
var Label = StackPanel.Children;
if (Label[1] is TextBlock targetText)
{
oldNumber = targetText.Text;
}
controllButton = button;
PopupOverlay.IsVisible = true;
}
}
private void OnPopupOverlayPointerPressed(object sender, PointerPressedEventArgs e)
{
// Close the popup when clicking outside of it
//controllButton.Foreground = Avalonia.Media.Brushes.Black;
var StackPanel = controllButton.Content as StackPanel;
var Label = StackPanel.Children;
if (Label[1] is TextBlock targetText)
{
//number += button.Content?.ToString();
targetText.Text = oldNumber;
}
tempErrorMsg.Text = "";
heatingBtn.IsEnabled = true;
coolingBtn.IsEnabled = true;
pouringBtn.IsEnabled = true;
PopupOverlay.IsVisible = false;
}
private void setDefaultSettings()
{
//set Values
_recipeTable = _recipeTable.ReadRecipesById(_recipeTable.Id.ToString());
heatingValue.Text = _recipeTable?.HeatingGoal == 0 ? "" : _recipeTable?.HeatingGoal.ToString();
coolingValue.Text = _recipeTable?.CoolingGoal == 0 ? "" : _recipeTable?.CoolingGoal.ToString();
pouringValue.Text = _recipeTable?.PouringGoal == 0 ? "" : _recipeTable?.PouringGoal.ToString();
//Set Track Up
_mainWindow.HomeTrack.IsVisible = true;
//_mainWindow.HomePolygon.Stroke = Avalonia.Media.Brushes.Black;
_mainWindow.RecipePanelTrack.IsVisible = true;
_mainWindow.RecipePanelPolygon.Stroke = Avalonia.Media.Brushes.Black;
_mainWindow.RecipeEditTrack.IsVisible = true;
_mainWindow.RecipeEditPolygon.Stroke = Brush.Parse("#A4275D");
_mainWindow.RunInterfaceTrack.IsVisible = false;
_mainWindow.RecipeSelTrack.IsVisible = false;
_mainWindow.SettingTrack.IsVisible = false;
_mainWindow.DiagnosticsTrack.IsVisible = false;
_mainWindow.TitleBtn.IsVisible = true;
_mainWindow.Title.Text = _recipeTable.Name;
//Set Footer
_mainWindow.footerMsg.Text = "Select the tempereture to edit it";
_mainWindow.footer.Background = Avalonia.Media.Brushes.WhiteSmoke;
_mainWindow.footerMsg.Foreground = Brush.Parse("#A4275D");
_mainWindow.footerDate.Text = DateTime.Now.ToString("dd/MM/yyyy");
_mainWindow.footerTime.Text = DateTime.Now.ToString("hh:mm tt");
_mainWindow.footerDateContainer.IsVisible = true;
_mainWindow.footerStartBtn.IsVisible = false;
_mainWindow.adminBtns.IsVisible = false;
}
}

View File

@@ -0,0 +1,513 @@
<UserControl xmlns="https://github.com/avaloniaui"
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"
Width="1200"
Height="620"
Background="#b3b3b3"
x:Class="DaireApplication.Settings" FontFamily="Helvetica" >
<Grid RowDefinitions="*">
<!-- Main Area-->
<Grid Grid.Row="0">
<Grid.Styles>
<Style Selector="Button">
<Setter Property="Background" Value="#F9F9F9"></Setter>
<Setter Property="CornerRadius" Value="50"></Setter>
<Setter Property="Width" Value="150"></Setter>
<Setter Property="Height" Value="90"></Setter>
<Setter Property="VerticalContentAlignment" Value="Center"></Setter>
<Setter Property="HorizontalContentAlignment" Value="Center"></Setter>
</Style>
<Style Selector="Button:pointerover /template/ContentPresenter">
<Setter Property="Background" Value="#F9F9F9"></Setter>
</Style>
<Style Selector="Button.SpecialButtonStyle:pointerover /template/ContentPresenter" >
<Setter Property="Background" Value="#E6E6E6"/>
<Setter Property="CornerRadius" Value="25"/>
</Style>
</Grid.Styles>
<Grid ColumnDefinitions="2*,1.4*,2.2*" >
<Grid Grid.Column="0" RowDefinitions="*,Auto,*,*" >
<Grid Grid.Row="1" Margin="5,0,0,0">
<StackPanel>
<TextBlock FontSize="18" TextWrapping="WrapWithOverflow" x:Name="mixerDelayTxt"
IsVisible="False"
Foreground="Black">Mixer
Delay: </TextBlock>
<TextBlock FontSize="25"
Margin="50,0,0,0"
x:Name="mixerDelayCounter"
IsVisible="False"
TextWrapping="WrapWithOverflow"
Foreground="Black">120</TextBlock>
</StackPanel>
</Grid>
<Grid Grid.Row="3" Margin="5,40,0,0">
<StackPanel>
<TextBlock FontSize="18" TextWrapping="WrapWithOverflow" x:Name="pedalDelayTxt"
IsVisible="False"
Foreground="Black">
Pedal OFF:
</TextBlock>
<TextBlock FontSize="25"
Margin="50,0,0,0"
x:Name="pedalDelayCounter"
IsVisible="False"
TextWrapping="WrapWithOverflow"
Foreground="Black">120</TextBlock>
</StackPanel>
</Grid>
<StackPanel>
<TextBlock FontSize="18" TextWrapping="WrapWithOverflow" x:Name="coolingDelayTxt"
IsVisible="False"
Foreground="Black">Cooling Delay: </TextBlock>
<TextBlock FontSize="25"
Margin="50,0,0,0"
x:Name="coolingDelayCounter"
IsVisible="False"
TextWrapping="WrapWithOverflow"
Foreground="Black">120</TextBlock>
</StackPanel>
</Grid>
<Grid Grid.Column="2"
RowDefinitions="*,Auto,*,*" ZIndex="200"
Margin="0,0,0,0" >
<Grid Grid.Row="1" Margin="305,0,0,0" ZIndex="200">
<StackPanel>
<TextBlock FontSize="18" TextWrapping="" x:Name="fountainDelayTxt"
IsVisible="False"
Foreground="Black">Fountain Delay: </TextBlock>
<TextBlock FontSize="25"
Margin="50,0,0,0"
IsVisible="False"
Foreground="Black"
x:Name="fountainDelayCounter"
TextWrapping="WrapWithOverflow">120</TextBlock>
<TextBlock FontSize="18" TextWrapping="" x:Name="fountainTargetTxt"
IsVisible="False"
Foreground="Black">Target Temp: </TextBlock>
<TextBlock FontSize="25"
Margin="50,0,0,0"
IsVisible="False"
Foreground="Black"
x:Name="fountainTagetTemp"
TextWrapping="WrapWithOverflow">120</TextBlock>
</StackPanel>
</Grid>
</Grid>
<Grid HorizontalAlignment="Center" Grid.Column="0" VerticalAlignment="Center" RowDefinitions="*,7*" Margin="40,0,0,20" ZIndex="100">
<StackPanel Grid.Row="1" Orientation="Vertical" >
<!--Tank Temp -->
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right" >
<Button IsEnabled="False" Margin="10" CornerRadius="10" >
<Button.Styles>
<!-- Custom Style for Disabled Button -->
<Style Selector="Button:disabled /template/ContentPresenter">
<Setter Property="Background" Value="#E6E6E6"/>
<Setter Property="Foreground" Value="#231F20"/>
</Style>
</Button.Styles>
<StackPanel Width="150" Height="90" Spacing="5">
<Label CornerRadius="25" FontSize="15.5"
FontWeight="Normal" Foreground="#8D8D8D" HorizontalContentAlignment="Center"
Margin="0,5,0,-5">TANK TEMP</Label>
<StackPanel
Spacing="-10"
Orientation="Horizontal"
Margin="0,-5,0,0"
HorizontalAlignment="Center"
VerticalAlignment="Center">
<Label x:Name="TankTempValue" FontSize="35" FontWeight="Normal"
HorizontalContentAlignment="Center"
VerticalContentAlignment="Center">-100.0</Label>
<Label FontSize="40" FontWeight="Normal" >°C</Label>
</StackPanel>
</StackPanel>
</Button>
</StackPanel>
<!--Mixer -->
<StackPanel Orientation="Horizontal" >
<Button x:Name="mixerBtn" CornerRadius="10" Margin="10" >
<StackPanel x:Name="MixerSP">
<Label FontSize="15.5" FontWeight="Normal" HorizontalContentAlignment="Center" Foreground="#666666">MIXER</Label>
<Label FontSize="47" FontWeight="Normal" HorizontalContentAlignment="Center" Foreground="#ff231f20" Margin="0,-15,0,0">OFF</Label>
<!-- Underline -->
<Rectangle Fill="#666666" Height="5" Width="110" Margin="0,-15,0,0"></Rectangle>
</StackPanel>
</Button>
</StackPanel>
<!--Recipe Setting -->
<StackPanel Orientation="Horizontal" x:Name="recipeSettings" >
<Button CornerRadius="10" Margin="10" Padding="0">
<StackPanel Spacing="-7">
<Label FontSize="15" HorizontalContentAlignment="Center" Foreground="#AF196F" Margin="0,0,0,1">RECIPE SETTINGS</Label>
<Grid RowDefinitions="*">
<Grid Grid.Row="0" ColumnDefinitions="Auto,*,Auto">
<Label Grid.Column="0" FontSize="15" FontWeight="Normal" HorizontalContentAlignment="Center" Foreground="#000000">Heating:</Label>
<Label Grid.Column="1" x:Name="heatingValue" FontSize="15" FontWeight="Normal" HorizontalContentAlignment="Center" Foreground="#000000">47.0</Label>
<Label Grid.Column="2" FontSize="15" FontWeight="Normal" HorizontalContentAlignment="Center" Foreground="#000000">°C</Label>
</Grid>
</Grid>
<Grid RowDefinitions="*">
<Grid Grid.Row="0" ColumnDefinitions="Auto,*,Auto">
<Label Grid.Column="0" FontSize="15" FontWeight="Normal" HorizontalContentAlignment="Center" Foreground="#000000">Pouring:</Label>
<Label Grid.Column="1" x:Name="pouringValue" FontSize="15" FontWeight="Normal" HorizontalContentAlignment="Center" Foreground="#000000">47.0</Label>
<Label Grid.Column="2" FontSize="15" FontWeight="Normal" HorizontalContentAlignment="Center" Foreground="#000000">°C</Label>
</Grid>
</Grid>
<Grid RowDefinitions="*">
<Grid Grid.Row="0" ColumnDefinitions="Auto,*,Auto">
<Label Grid.Column="0" FontSize="15" FontWeight="Normal" HorizontalContentAlignment="Center" Foreground="#000000">Cooling:</Label>
<Label Grid.Column="1" x:Name="coolingValue" FontSize="15" FontWeight="Normal" HorizontalContentAlignment="Center" Foreground="#000000">47.0</Label>
<Label Grid.Column="2" FontSize="15" FontWeight="Normal" HorizontalContentAlignment="Center" Foreground="#000000">°C</Label>
</Grid>
</Grid>
<StackPanel Orientation="Horizontal">
</StackPanel>
</StackPanel>
</Button>
</StackPanel>
<StackPanel HorizontalAlignment="Center" Width="150" Height="200">
<!-- Pedal Container -->
<Button Background="#F9F9F9" CornerRadius="10" Width="150" Height="200" VerticalContentAlignment="Center" HorizontalContentAlignment="Center">
<StackPanel Orientation="Vertical" HorizontalAlignment="Center" Height="200" Width="150">
<!-- Pedal Title -->
<TextBlock Margin="7" Text="PEDAL" FontSize="15" FontWeight="Normal"
VerticalAlignment="Top" HorizontalAlignment="Center" Foreground="#666666" />
<!-- Auto Mode Button -->
<Button Background="#E6E6E6" CornerRadius="5" HorizontalAlignment="Center" Padding="0" Width="130" Height="50" Click="PedalBtn">
<StackPanel Width="130" x:Name="PedalSP">
<TextBlock x:Name="pedalStateTxt" Text="AUTO" Foreground="#231F20" FontSize="26.5" FontWeight="Normal" HorizontalAlignment="Center"/>
<!-- Underline -->
<Rectangle x:Name="pedalUnderLine" Fill="#A4275D" Height="5" Width="90" Margin="0,-3,0,0"/>
</StackPanel>
</Button>
<StackPanel x:Name="PedalAutoContainer" >
<!-- Pedal Off Time -->
<StackPanel.Styles>
<Style Selector="Button:disabled /template/ContentPresenter">
<Setter Property="Background" Value="#B3B3B3"/>
<Setter Property="Foreground" Value="#A4275D"/>
</Style>
<Style Selector="Button:pointerover /template/ContentPresenter">
<Setter Property="Background" Value="#E6E6E6"></Setter>
<Setter Property="Foreground" Value="#A4275D"></Setter>
</Style>
</StackPanel.Styles>
<TextBlock Text="PEDAL OFF TIME" Foreground="Gray" FontSize="15" FontWeight="Normal" HorizontalAlignment="Center"/>
<Grid RowDefinitions="*" Margin="5,0">
<Grid Grid.Row="0" ColumnDefinitions="Auto,*,Auto">
<Button Classes="PedalOn" Grid.Column="0" Content="" Background="#E6E6E6" Foreground="#A4275D"
Width="35" Height="35" CornerRadius="18" FontSize="16"
Click="adjustPedalTime"/>
<StackPanel Grid.Column="1" Orientation="Horizontal" HorizontalAlignment="Center">
<TextBlock x:Name="PedalOnTime" Text="4" FontSize="23.5" FontWeight="Normal" Foreground="Black" HorizontalAlignment="Center" VerticalAlignment="Center"/>
<TextBlock Text="s" FontSize="23.5" FontWeight="Normal" Foreground="Black" HorizontalAlignment="Center" VerticalAlignment="Center"/>
</StackPanel>
<Button Classes="PedalOn" Grid.Column="2" Content="+" Background="#E6E6E6" Foreground="#A4275D"
Width="35" Height="35" CornerRadius="18" FontSize="16" Click="adjustPedalTime"/>
</Grid>
</Grid>
<!-- Pedal On Time -->
<TextBlock Text="PEDAL ON TIME" Foreground="Gray" FontSize="15" FontWeight="Normal" HorizontalAlignment="Center"/>
<Grid RowDefinitions="*" Margin="5,0">
<Grid Grid.Row="0" ColumnDefinitions="Auto,*,Auto">
<Button Classes="PedalOff" Grid.Column="0" Content="" Background="#E6E6E6" Foreground="#A4275D"
Width="35" Height="35" CornerRadius="18" FontSize="16" Click="adjustPedalTime"/>
<StackPanel Grid.Column="1" Orientation="Horizontal" HorizontalAlignment="Center">
<TextBlock x:Name="PedalOffTime" Text="4" FontSize="23.5" FontWeight="Normal" Foreground="Black" HorizontalAlignment="Center" VerticalAlignment="Center"/>
<TextBlock Text=" s" FontSize="23.5" FontWeight="Normal" Foreground="Black" HorizontalAlignment="Center" VerticalAlignment="Center"/>
</StackPanel>
<Button Classes="PedalOff" Grid.Column="2" Content="+" Background="#E6E6E6" Foreground="#A4275D"
Width="35" Height="35" CornerRadius="18" FontSize="16" Click="adjustPedalTime"/>
</Grid>
</Grid>
</StackPanel>
</StackPanel>
</Button>
</StackPanel>
</StackPanel>
</Grid>
<Grid Grid.Column="1" Height="596" Width="605" IsVisible="True">
<Grid.Background >
<ImageBrush Source="/Assets/TemperingMachine.png" />
</Grid.Background>
</Grid>
<Grid Grid.Column="2" RowDefinitions="*,12*" HorizontalAlignment="Center" Margin="0,0,15,0">
<StackPanel Grid.Row="1" Orientation="Vertical" HorizontalAlignment="Left" >
<!--Fountain Temp -->
<StackPanel Orientation="Horizontal" >
<Button IsEnabled="False" Width="150" Height="90" Margin="10" CornerRadius="10" Padding="0">
<Button.Styles>
<!-- Custom Style for Disabled Button -->
<Style Selector="Button:disabled /template/ContentPresenter">
<Setter Property="Background" Value="#E6E6E6"/>
</Style>
</Button.Styles>
<StackPanel Spacing="5">
<Label FontSize="14.5" FontWeight="Normal" HorizontalContentAlignment="Center" Foreground="#787878" >CHOCOLATE TEMP</Label>
<StackPanel
Spacing="-10"
Orientation="Horizontal"
Margin="0,-10,0,0" HorizontalAlignment="Center"
VerticalAlignment="Center">
<Label x:Name="FountainTempValue" FontSize="35" Foreground="#262223" VerticalAlignment="Center" >-100.0</Label>
<Label FontSize="40" Foreground="#262223" VerticalAlignment="Center" >°C</Label>
</StackPanel>
</StackPanel>
</Button>
</StackPanel>
<Button x:Name="fountainBtn" Margin="10" Content="on" Width="150" Height="90" CornerRadius="10">
<StackPanel x:Name="FountainSP">
<Label FontSize="15" FontWeight="Normal" HorizontalContentAlignment="Center" Foreground="#666666">CHOCOLATE</Label>
<Label FontSize="47" FontWeight="Normal" HorizontalContentAlignment="Center" Margin="0,-15,0,0" Foreground="#231F20">ON</Label>
<!-- Underline -->
<Rectangle Fill="#A4275D" Height="5" Width="110" Margin="0,-15,0,0"></Rectangle>
</StackPanel>
</Button>
<!--MOLD HEATER-->
<Button x:Name="moldHeaterBtn" Margin="10" Content="on" Width="150" Height="90" CornerRadius="10"
Click="toggelOnOffClick">
<StackPanel x:Name="MoldHeaterSP">
<Label FontSize="15" FontWeight="Normal" HorizontalContentAlignment="Center" Foreground="#666666">MOLD HEATER</Label>
<Label FontSize="47" FontWeight="Normal" HorizontalContentAlignment="Center" Margin="0,-15,0,0" Foreground="#231F20">ON</Label>
<!-- Underline -->
<Rectangle Fill="#A4275D" Height="5" Width="110" Margin="0,-15,0,0"></Rectangle>
</StackPanel>
</Button>
<!--Vibration-->
<Button x:Name="vibrationBtn" Margin="10" Content="on" Width="150" Height="90" CornerRadius="10"
Click="toggelOnOffClick">
<StackPanel x:Name="VibrationSP">
<Label FontSize="15" FontWeight="Normal" HorizontalContentAlignment="Center" Foreground="#666666">VIBRATION</Label>
<Label FontSize="47" FontWeight="Normal" HorizontalContentAlignment="Center" Margin="0,-15,0,0" Foreground="#231F20">ON</Label>
<!-- Underline -->
<Rectangle Fill="#A4275D" Height="5" Width="110" Margin="0,-15,0,0"></Rectangle>
</StackPanel>
</Button>
<!--VIBHeater-->
<Button x:Name="vibHeaterBtn" Margin="10" Content="on" Width="150" Height="90" CornerRadius="10"
Click="toggelOnOffClick">
<StackPanel x:Name="VibHeaterSP">
<Label FontSize="15" FontWeight="Normal" HorizontalContentAlignment="Center" Foreground="#666666"
>VIB. HEATER</Label>
<Label FontSize="47" FontWeight="Normal" HorizontalContentAlignment="Center" Margin="0,-15,0,0" Foreground="#231F20">ON</Label>
<!-- Underline -->
<Rectangle Fill="#A4275D" Height="5" Width="110" Margin="0,-15,0,0"></Rectangle>
</StackPanel>
</Button>
</StackPanel>
</Grid>
</Grid>
</Grid>
<!-- Overlay Background for Delet Popup -->
<Border x:Name="DeletePopupOverlay" Background="#80000000" Grid.RowSpan="3" IsVisible="False" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" ZIndex="99" PointerPressed="OnIgnorePopupOverlayPointerPressed">
<!-- Popup User Control -->
<!-- Module for Name Entry -->
<Grid PointerPressed="" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="20" IsVisible="True">
<Border Background="White" CornerRadius="10" Padding="20" BorderThickness="1" ZIndex="101" BorderBrush="#CCC">
<StackPanel Spacing="15">
<!-- Label for Text Input -->
<!-- Label -->
<TextBlock Text="Exit Warning!!"
FontSize="20"
FontWeight="Bold"
Foreground="Red"
Margin="0,0,0,8" />
<StackPanel>
<TextBlock x:Name="deleteMsg" Text="Are you sure?"
FontSize="16"
FontWeight="Bold"
Foreground="#333"
Margin="0,0,0,8" />
</StackPanel>
<!-- Button Panel -->
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center" Spacing="10">
<!-- yes Button -->
<Button
Content="Yes"
FontSize="16"
Padding="10,5"
Click="YesBtnClick"
Foreground="White" >
<Button.Background>
<LinearGradientBrush StartPoint="0,0" EndPoint="1,0">
<GradientStop Color="#A4275D" Offset="0" />
<GradientStop Color="#A4275D" Offset="1" />
</LinearGradientBrush>
</Button.Background>
<Button.Styles>
<Style Selector="Button.SpecialButtonStyle:pointerover /template/ContentPresenter">
<Setter Property="Background" Value="#A4275D"/>
<Setter Property="Foreground" Value="White"/>
</Style>
</Button.Styles>
</Button>
<!-- No Button -->
<Button
Content="No"
FontSize="16"
Padding="10,5"
Background="Gray"
Foreground="White"
Click="OnIgnorePopupOverlayPointerPressed">
<Button.Styles>
<Style Selector="Button.SpecialButtonStyle:pointerover /template/ContentPresenter">
<Setter Property="Background" Value="Gray"/>
<Setter Property="Foreground" Value="White"/>
</Style>
</Button.Styles>
</Button>
</StackPanel>
</StackPanel>
</Border>
</Grid>
</Border>
<!-- Overlay Background for Delet Popup -->
<Border x:Name="tempErrorPopupOverlay" Background="#80000000" Grid.RowSpan="3" IsVisible="False" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" ZIndex="99" PointerPressed="">
<!-- Popup User Control -->
<!-- Module for Name Entry -->
<Grid PointerPressed="" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="20" IsVisible="True">
<Border Background="White" CornerRadius="10" Padding="20" BorderThickness="1" ZIndex="101" BorderBrush="#CCC">
<StackPanel Spacing="15">
<!-- Label for Text Input -->
<!-- Label -->
<TextBlock Text="Temperature Error!!"
FontSize="20"
FontWeight="Bold"
Foreground="Red"
Margin="0,0,0,8" />
<StackPanel>
<TextBlock x:Name="tempErrorMsg" Text="Error locating temperature do you want to stop?"
FontSize="16"
FontWeight="Bold"
Foreground="#333"
Margin="0,0,0,8" />
</StackPanel>
<!-- Button Panel -->
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center" Spacing="10">
<!-- yes Button -->
<Button
Content="Yes"
FontSize="16"
Padding="10,5"
Click="ErrorYesBtnClick"
Foreground="White" >
<Button.Background>
<LinearGradientBrush StartPoint="0,0" EndPoint="1,0">
<GradientStop Color="#A4275D" Offset="0" />
<GradientStop Color="#A4275D" Offset="1" />
</LinearGradientBrush>
</Button.Background>
<Button.Styles>
<Style Selector="Button.SpecialButtonStyle:pointerover /template/ContentPresenter">
<Setter Property="Background" Value="#A4275D"/>
<Setter Property="Foreground" Value="White"/>
</Style>
</Button.Styles>
</Button>
<!-- No Button -->
<Button
Content="No"
FontSize="16"
Padding="10,5"
Background="Gray"
Foreground="White"
Click="HideTempErrorPopUp">
<Button.Styles>
<Style Selector="Button.SpecialButtonStyle:pointerover /template/ContentPresenter">
<Setter Property="Background" Value="Gray"/>
<Setter Property="Foreground" Value="White"/>
</Style>
</Button.Styles>
</Button>
</StackPanel>
</StackPanel>
</Border>
</Grid>
</Border>
</Grid>
</UserControl>

View File

@@ -0,0 +1,388 @@
using Avalonia;
using Avalonia.Controls;
using Avalonia.Controls.Documents;
using Avalonia.Controls.Shapes;
using Avalonia.Input;
using Avalonia.Interactivity;
using Avalonia.Markup.Xaml;
using Avalonia.Media;
using AvaloniaApplication1.DataBase;
using DaireApplication.DataBase;
using DaireApplication.ViewModels;
using DaireApplication.Views;
using System;
using System.Drawing;
using System.Reflection.PortableExecutable;
using System.Threading;
namespace DaireApplication;
public partial class Settings : UserControl
{
Button controllButton = new Button();
private MainWindow? _mainWindow;
private UserTable? _currentUser;
public RecipeTable? _recipeTable;
private MachineTable _machine;
public string ActiveColor { get; set; } = "#A4275D";
public string PassiveColor { get; set; } = "#666666";
public Settings()
{
InitializeComponent();
}
public Settings(MainWindow mainWindow, UserTable currentUser,RecipeTable recipeTable)
{
_currentUser = currentUser;
_mainWindow = mainWindow;
_recipeTable = recipeTable;
_machine = new MachineTable();
_machine = _machine.ReadMachine();
InitializeComponent();
setDefaultSettings();
setDafaultValues();
mixerBtn.Click += _mainWindow.MotorClick;
fountainBtn.Click += _mainWindow.FountainClick;
}
private void toggelOnOffClick(object? sender, RoutedEventArgs e)
{
if (sender is Button button)
{
var StackPanel = button.Content as StackPanel;
var Label = StackPanel.Children;
var underLine = Label[2] as Avalonia.Controls.Shapes.Rectangle;
var titelLable = Label[0] as Label;
if (Label[1] is Label targetLable)
{
if (targetLable.Content == "ON")
{
if (titelLable.Content == "MOLD HEATER")
{
_mainWindow.moldHeaterMotor = 0;
}
if (titelLable.Content == "VIBRATION")
{
_mainWindow.vibrationMotor = 0;
}
if (titelLable.Content == "VIB. HEATER")
{
_mainWindow.vibHeaterMotor = 0;
}
}
else
{
if (titelLable.Content == "MOLD HEATER")
{
_mainWindow.moldHeaterMotor = 1;
}
if (titelLable.Content == "VIBRATION")
{
_mainWindow.vibrationMotor = 1;
}
if (titelLable.Content == "VIB. HEATER")
{
_mainWindow.vibHeaterMotor = 1;
}
}
}
}
}
private void PedalBtn(object? sender, RoutedEventArgs e)
{
if (sender is Button button)
{
var StackPanel = button.Content as StackPanel;
var Label = StackPanel.Children;
var underLine = Label[1] as Avalonia.Controls.Shapes.Rectangle;
if (Label[0] is TextBlock targetLable)
{
if (targetLable.Text == "AUTO")
{
if (_mainWindow.pedalOnTimer!=null )
{
_mainWindow.pedalOnTimer.Change(Timeout.Infinite, Timeout.Infinite);
_mainWindow.pedalOnTimer = null;
_mainWindow.pedalOnSeconds = 0;
}
if (_mainWindow.pedalOffTimer!=null)
{
_mainWindow.pedalOffTimer.Change(Timeout.Infinite, Timeout.Infinite);
_mainWindow.pedalOffTimer = null;
_mainWindow.pedalOffSeconds = 0;
}
_mainWindow.pedalMotor = 0;
targetLable.Text = "MANUAL";
underLine.Fill = Brush.Parse("#666666");
PedalAutoContainer.IsEnabled = false;
_recipeTable.Pedal = true;
}
else
{
_mainWindow.pedalMotor = 1;
_mainWindow.pedalState = -1;
_mainWindow.setPedalTimerOnce = 1;
_mainWindow.pedalOnSeconds = 0;
_mainWindow.pedalOffSeconds = 0;
targetLable.Text = "AUTO";
underLine.Fill = Brush.Parse("#A4275D");
PedalAutoContainer.IsEnabled = true;
_recipeTable.Pedal = false;
}
_recipeTable.UpdateRecipe(_recipeTable);
}
}
}
private void adjustPedalTime(object? sender, RoutedEventArgs e)
{
if (sender is Button button)
{
if (button.Classes[0].ToString()== "PedalOff")
{
if (button.Content == "")
{
if (Int32.Parse(PedalOffTime.Text) > 0)
{
PedalOffTime.Text = (Int32.Parse(PedalOffTime.Text) - 1).ToString();
}
}
else if (button.Content == "+")
{
PedalOffTime.Text = (Int32.Parse(PedalOffTime.Text) + 1).ToString();
}
_recipeTable.PedalOffTime = Int32.Parse(PedalOffTime.Text);
_recipeTable.UpdateRecipe(_recipeTable);
}
else
{
if (button.Content == "")
{
if (Int32.Parse(PedalOnTime.Text) > 0)
{
PedalOnTime.Text = (Int32.Parse(PedalOnTime.Text) - 1).ToString();
}
}
else if (button.Content == "+")
{
if (int.TryParse(PedalOnTime.Text, out int value))
{
if (value < 9)
{
PedalOnTime.Text = (value + 1).ToString();
}
}
}
_recipeTable.PedalOnTime = Int32.Parse(PedalOnTime.Text);
_recipeTable.UpdateRecipe(_recipeTable);
}
_recipeTable = _recipeTable.ReadRecipesById(_recipeTable.Id.ToString());
}
}
private async void OnIgnorePopupOverlayPointerPressed(object? sender, RoutedEventArgs e)
{
DeletePopupOverlay.IsVisible = false;
}
private async void HideTempErrorPopUp(object? sender, RoutedEventArgs e)
{
_mainWindow.pauseTimer = false;
_mainWindow.pauseTempTracking = false; // Allow process to continue after clicking "No"
_mainWindow.tempWarningAccepted = true; // User accepted the temperature warning
tempErrorPopupOverlay.IsVisible = false;
}
private async void YesBtnClick(object? sender, RoutedEventArgs e)
{
if (sender is Button button)
{
if (DeletePopupOverlay.Tag=="home")
{
_mainWindow.resetAll();
// rest the board
_mainWindow.restBoard = true;
_mainWindow.UserName.Content = "Select User";
_mainWindow.footerMsg.Text = "";
_mainWindow.ContentArea.Content = new Home(_mainWindow);
}
else if (DeletePopupOverlay.Tag == "recipeSel")
{
_mainWindow.resetAll();
// rest the board
_mainWindow.restBoard = true;
_mainWindow.footerMsg.Text = "";
_mainWindow.ContentArea.Content = new Recipe(_mainWindow, Program.currentUser);
}
}
}
private async void ErrorYesBtnClick(object? sender, RoutedEventArgs e)
{
if (sender is Button button)
{
//_mainWindow.pause = true;
//_mainWindow.pauseTempTracking = true;
//_mainWindow.pauseTimer = true;
// stop the recipe
_mainWindow.startRecipe = 0;
_mainWindow.Heating = 0;
_mainWindow.cooling = 0;
_mainWindow.pouring = 0;
_mainWindow.PumbOn = -1;
_mainWindow.pedalMotor = -1;
if (_mainWindow.heatingTimer != null)
{
_mainWindow.heatingTimer.Change(Timeout.Infinite, Timeout.Infinite);
_mainWindow.heatingSeconds = 0;
}
if (_mainWindow.coolingTimer != null)
{
_mainWindow.coolingTimer.Change(Timeout.Infinite, Timeout.Infinite);
_mainWindow.coolingSeconds = 0;
}
if (_mainWindow.pouringTimer != null)
{
_mainWindow.pouringTimer.Change(Timeout.Infinite, Timeout.Infinite);
_mainWindow.pouringSeconds = 0;
}
var fount = _mainWindow._mapping.Find(x => x.Name.ToLower() == "Pump".ToLower());
if (fount != null)
{
if (fount.BitNumbers.Count > 0)
{
foreach (var bit in fount.BitNumbers)
{
_mainWindow.holdingRegister.motor &= (ushort)~(1 << bit);
}
}
}
_mainWindow.holdingRegister.setTemp1 = -10000;
_mainWindow.holdingRegister.setTemp2 = -10000;
_mainWindow.holdingRegister.setTemp3 = -10000;
_mainWindow.holdingRegister.setTemp4 = -10000;
await _mainWindow.WriteToSerialAsync("ErrorYesBtnClick");
tempErrorPopupOverlay.IsVisible = false;
_mainWindow.footerMsg.Text = "Recipe Stoped";
_mainWindow.recipeStartBtn.Content = "START RECIPE";
}
}
private void setDefaultSettings()
{
//Set Track Up
_mainWindow.HomeTrack.IsVisible = true;
//_mainWindow.HomePolygon.Stroke = Avalonia.Media.Brushes.Black;
_mainWindow.RecipeSelTrack.IsVisible = true;
_mainWindow.RecipeSelPolygon.Stroke = Avalonia.Media.Brushes.Black;
_mainWindow.RunInterfaceTrack.IsVisible = true;
_mainWindow.RunInterfacePolygon.Stroke = Brush.Parse("#A4275D");
_mainWindow.RecipePanelTrack.IsVisible = false;
_mainWindow.RecipeEditTrack.IsVisible = false;
_mainWindow.SettingTrack.IsVisible = false;
_mainWindow.DiagnosticsTrack.IsVisible = false;
_mainWindow.TitleBtn.IsVisible = true;
_mainWindow.Title.Text = _recipeTable.Name;
//Set Footer
_mainWindow.footerMsg.Text = "Ready";
_mainWindow.footerMsg.MaxWidth = 500;
_mainWindow.footer.Background = Avalonia.Media.Brushes.WhiteSmoke;
_mainWindow.footerMsg.Foreground = Avalonia.Media.Brushes.Green;
_mainWindow.footerDate.Text = DateTime.Now.ToString("dd/MM/yyyy");
_mainWindow.footerTime.Text = DateTime.Now.ToString("hh:mm tt");
_mainWindow.footerDateContainer.IsVisible = true;
_mainWindow.footerStartBtn.IsVisible = true;
_mainWindow.adminBtns.IsVisible = false;
}
private void setDafaultValues()
{
//Recipe Settings
heatingValue.Content = _recipeTable.HeatingGoal;
coolingValue.Content = _recipeTable.CoolingGoal;
pouringValue.Content = _recipeTable.PouringGoal;
//tankTemp
TankTempValue.Content = _recipeTable?.TankTemp;
//mixer
var mixerChildren= MixerSP.Children;
var mixerLable = mixerChildren[1] as Label;
mixerLable.Content = _recipeTable.Mixer.Value ? "ON" : "OFF";
var mixerUnderLine = mixerChildren[2] as Avalonia.Controls.Shapes.Rectangle;
mixerUnderLine.Fill = _recipeTable.Mixer.Value ? Brush.Parse(ActiveColor) : Brush.Parse(PassiveColor);
//pedal
var pedalChildren = PedalSP.Children;
var pedalText = pedalChildren[0] as TextBlock;
var pedalUnderLine = pedalChildren[1] as Avalonia.Controls.Shapes.Rectangle;
if (_recipeTable.Pedal.Value)
{
pedalText.Text = "MANUAL";
pedalUnderLine.Fill = Brush.Parse(PassiveColor);
PedalAutoContainer.IsEnabled = false;
}
else
{
pedalText.Text = "AUTO";
pedalUnderLine.Fill = Brush.Parse(ActiveColor);
PedalAutoContainer.IsEnabled = true;
}
PedalOffTime.Text = _recipeTable.PedalOffTime.ToString();
PedalOnTime.Text = _recipeTable.PedalOnTime.ToString();
//fountain Temp
FountainTempValue.Content = _recipeTable?.FountainTemp;
//fountain
var fountainChildren = FountainSP.Children;
var fountainLable = fountainChildren[1] as Label;
fountainLable.Content = _recipeTable.Fountain.Value ? "ON" : "OFF";
var fountainUnderLine = fountainChildren[2] as Avalonia.Controls.Shapes.Rectangle;
fountainUnderLine.Fill = _recipeTable.Fountain.Value ? Brush.Parse(ActiveColor) : Brush.Parse(PassiveColor);
//mold Heater
var moldHeaterChildren = MoldHeaterSP.Children;
var moldHeaterLable = moldHeaterChildren[1] as Label;
moldHeaterLable.Content = _recipeTable.MoldHeater.Value ? "ON" : "OFF";
var moldHeaterUnderLine = moldHeaterChildren[2] as Avalonia.Controls.Shapes.Rectangle;
moldHeaterUnderLine.Fill = _recipeTable.MoldHeater.Value ? Brush.Parse(ActiveColor) : Brush.Parse(PassiveColor);
// vibration
var vibrationChildren = VibrationSP.Children;
var vibrationLable = vibrationChildren[1] as Label;
vibrationLable.Content = _recipeTable.Vibration.Value ? "ON" : "OFF";
var vibrationUnderLine = vibrationChildren[2] as Avalonia.Controls.Shapes.Rectangle;
vibrationUnderLine.Fill = _recipeTable.Vibration.Value ? Brush.Parse(ActiveColor) : Brush.Parse(PassiveColor);
// vib heater
var vibHeaterChildren = VibHeaterSP.Children;
var vibHeaterLable = vibHeaterChildren[1] as Label;
vibHeaterLable.Content = _recipeTable.VibHeater.Value ? "ON" : "OFF";
var vibHeaterUnderLine = vibHeaterChildren[2] as Avalonia.Controls.Shapes.Rectangle;
vibHeaterUnderLine.Fill = _recipeTable.VibHeater.Value ? Brush.Parse(ActiveColor) : Brush.Parse(PassiveColor);
}
}

View File

@@ -0,0 +1,783 @@
<UserControl xmlns="https://github.com/avaloniaui"
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:DaireApplication"
x:DataType="local:Software"
Width="1280" Height="620" Background="#b3b3b3"
x:Class="DaireApplication.Software"
>
<UserControl.Styles>
<Style Selector="ComboBox.noArrow">
<Setter Property="Template">
<ControlTemplate TargetType="ComboBox">
<Grid>
<ToggleButton x:Name="PART_Button"
Focusable="False"
ClickMode="Press"
IsChecked="{Binding IsDropDownOpen,
RelativeSource={RelativeSource TemplatedParent},
Mode=TwoWay}"
Background="#E6E6E6"
Width="210" Height="40">
<Border Background="#E6E6E6"
CornerRadius="8"
Padding="0,0">
<ContentPresenter x:Name="PART_SelectionBoxPresenter"
Content="{TemplateBinding SelectionBoxItem}"
HorizontalAlignment="Center"
VerticalAlignment="Center"
FontSize="20"
Foreground="#af196f"/>
</Border>
</ToggleButton>
<Popup x:Name="PART_Popup"
PlacementTarget="{Binding #PART_Button}"
Placement="Bottom"
IsOpen="{Binding IsDropDownOpen,
RelativeSource={RelativeSource TemplatedParent},
Mode=TwoWay}">
<Border Background="White"
BorderBrush="Gray"
BorderThickness="1">
<ScrollViewer>
<ItemsPresenter />
</ScrollViewer>
</Border>
</Popup>
</Grid>
</ControlTemplate>
</Setter>
</Style>
<Style Selector="TextBlock.lbl">
<Setter Property="Foreground" Value="#000000"/>
</Style>
<Style Selector="ComboBoxItem">
<Setter Property="Foreground" Value="Black"/>
<Setter Property="Background" Value="Transparent"/>
</Style>
<Style Selector="ComboBoxItem:selectable:checked">
<Setter Property="Foreground" Value="#af196f"/>
</Style>
<Style Selector="ComboBoxItem:pointerover">
<Setter Property="Foreground" Value="#af196f"/>
<Setter Property="Background" Value="Transparent"/>
</Style>
</UserControl.Styles>
<Grid RowDefinitions="*">
<Grid Grid.Row="0" ColumnDefinitions="Auto,*">
<Border Grid.Column="0" Padding="10">
<StackPanel Spacing="8">
<!--box-->
<Border Width="222" Height="224" Background="#f9f9f9" CornerRadius="10" Padding="10" ZIndex="100" >
<StackPanel Spacing="5">
<TextBlock
Foreground="#918f90"
FontSize="20.5" HorizontalAlignment="Center"
VerticalAlignment="Center">PASSWORDS RESET</TextBlock>
<!--row-->
<Border Width="210" Height="40" Background="#e6e6e6" CornerRadius="5">
<Button Background="Transparent"
Width="210"
Click="showChangePasswordPopUp">
<TextBlock
Foreground="#231f20"
FontSize="20.5"
VerticalAlignment="Center"
HorizontalAlignment="Center" Classes="user">
ADMINISTRATOR
</TextBlock>
</Button>
</Border>
<!--row-->
<Border Width="210" Height="40" Background="#e6e6e6" CornerRadius="5">
<Button Background="Transparent" Width="210"
Click="showChangePasswordPopUp">
<TextBlock Classes="user"
Foreground="#231f20"
FontSize="20.5"
VerticalAlignment="Center"
HorizontalAlignment="Center">
CHEF
</TextBlock>
</Button>
</Border>
<!--row-->
<Border Width="210" Height="40" Background="#e6e6e6" CornerRadius="5">
<Button Background="Transparent" Width="210" Click="showChangePasswordPopUp">
<TextBlock
Foreground="#231f20"
FontSize="20.5"
VerticalAlignment="Center"
HorizontalAlignment="Center" Classes="user">
OPERATOR1
</TextBlock>
</Button>
</Border>
<!--row-->
<Border Width="210" Height="40" Background="#e6e6e6" CornerRadius="5">
<Button Background="Transparent" Width="210" Click="showChangePasswordPopUp">
<TextBlock
Foreground="#231f20"
FontSize="20.5"
VerticalAlignment="Center"
HorizontalAlignment="Center" Classes="user">
OPERATOR2
</TextBlock>
</Button>
</Border>
</StackPanel>
</Border>
<!--box1 -->
<Border Width="222" Height="178" Background="#f9f9f9" CornerRadius="10" Padding="10" ZIndex="100">
<StackPanel Spacing="5">
<TextBlock
Foreground="#918f90"
FontSize="20.5"
HorizontalAlignment="Center"
VerticalAlignment="Center">SCREEN SETTINGS</TextBlock>
<!--row-->
<Border Width="210" Height="40" Background="#e6e6e6" CornerRadius="5" >
<Button Background="Transparent"
Width="210" Height="40" Click="showScreenPopUp" Tag="BRIGHTNESS" >
<Grid RowDefinitions="*">
<Grid Grid.Row="0" ColumnDefinitions="Auto,*">
<TextBlock
Foreground="#231f20"
FontSize="20.5"
VerticalAlignment="Center"
HorizontalAlignment="Center" Grid.Column="0">
BRIGHTNESS
</TextBlock>
<StackPanel Grid.Column="1" Orientation="Horizontal"
HorizontalAlignment="Right">
<TextBlock
Foreground="#af196f"
FontSize="20.5"
VerticalAlignment="Center"
HorizontalAlignment="Center"
x:Name="brightnessValue"
>
80
</TextBlock>
<TextBlock
Foreground="#af196f"
FontSize="20.5"
VerticalAlignment="Center"
HorizontalAlignment="Center">
%
</TextBlock>
</StackPanel>
</Grid>
</Grid>
</Button>
</Border>
<!--row-->
<Border Width="210" Height="40" Background="#e6e6e6" CornerRadius="5" >
<Button Background="Transparent"
Width="210"
Height="40" Click="showScreenPopUp" Tag="AUTO DIM">
<Grid RowDefinitions="*">
<Grid Grid.Row="0" ColumnDefinitions="Auto,*">
<TextBlock
Foreground="#231f20"
FontSize="20.5"
VerticalAlignment="Center"
HorizontalAlignment="Center" Grid.Column="0">
AUTO DIM
</TextBlock>
<StackPanel Grid.Column="1" Orientation="Horizontal"
Spacing="5" HorizontalAlignment="Right">
<TextBlock
Foreground="#af196f"
FontSize="20.5"
VerticalAlignment="Center"
HorizontalAlignment="Center"
x:Name="dimValue"
>
60
</TextBlock>
<TextBlock
Foreground="#af196f"
FontSize="20.5"
VerticalAlignment="Center"
HorizontalAlignment="Center">
Min
</TextBlock>
</StackPanel>
</Grid>
</Grid>
</Button>
</Border>
<!--row-->
<Border Width="210" Height="40" Background="#e6e6e6" CornerRadius="5" >
<Button Background="Transparent"
Width="210"
Height="40" Click="showScreenPopUp" Tag="AUTO OFF">
<Grid RowDefinitions="*">
<Grid Grid.Row="0" ColumnDefinitions="Auto,*">
<TextBlock
Foreground="#231f20"
FontSize="20.5"
VerticalAlignment="Center"
HorizontalAlignment="Center" Grid.Column="0">
AUTO OFF
</TextBlock>
<StackPanel Grid.Column="1" Orientation="Horizontal"
Spacing="5" HorizontalAlignment="Right">
<TextBlock
Foreground="#af196f"
FontSize="20.5"
VerticalAlignment="Center"
HorizontalAlignment="Center"
x:Name="offValue"
>
90
</TextBlock>
<TextBlock
Foreground="#af196f"
FontSize="20.5"
VerticalAlignment="Center"
HorizontalAlignment="Center">
Min
</TextBlock>
</StackPanel>
</Grid>
</Grid>
</Button>
</Border>
</StackPanel>
</Border>
<!--box-->
<Border Width="222" Height="178" Background="#f9f9f9" CornerRadius="10" Padding="10" >
<StackPanel Spacing="5">
<TextBlock
Foreground="#918f90"
FontSize="20.5"
HorizontalAlignment="Center"
VerticalAlignment="Center">COM SETTINGS</TextBlock>
<!--row-->
<Border Width="210" Height="40" Background="#e6e6e6" CornerRadius="5" Padding="0" >
<Grid RowDefinitions="*">
<Grid Grid.Row="0" ColumnDefinitions="Auto,*">
<ComboBox x:Name="portComboBox"
Margin="0"
Classes="noArrow"
SelectedIndex="0"
SelectedItem="{Binding SelectedPort}"
ItemsSource="{Binding SerialPorts, Mode=OneWay}"
SelectionChanged="portChanged" >
</ComboBox>
<StackPanel Grid.Column="1" Orientation="Horizontal"
HorizontalAlignment="Right">
</StackPanel>
</Grid>
</Grid>
</Border>
<!--row-->
<Border Width="210" Height="40" Background="#e6e6e6" CornerRadius="5" Padding="0" >
<Button Background="Transparent"
Width="210"
Click="showComPopUp">
<TextBlock
Foreground="#231f20"
FontSize="20.5"
VerticalAlignment="Center"
HorizontalAlignment="Center" >
COM Settings
</TextBlock>
</Button>
</Border>
<!--row-->
<Border Width="210" Height="40" Background="#e6e6e6" CornerRadius="5" Padding="0" >
<Button Background="Transparent"
Width="210"
Click="ShowTempPopUp">
<TextBlock
Foreground="#231f20"
FontSize="18.5"
VerticalAlignment="Center"
HorizontalAlignment="Center" >
Temperature Settings
</TextBlock>
</Button>
</Border>
</StackPanel>
</Border>
</StackPanel>
</Border>
<Grid Grid.Column="1"></Grid>
</Grid>
<!-- Overlay Background for Add Popup -->
<Border x:Name="passwordPopupOverlay" Background="#80000000" Grid.RowSpan="3" IsVisible="False" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" ZIndex="99" PointerPressed="hidePasswordPopUp">
<!-- Popup User Control -->
<!-- Module for Name Entry -->
<Grid x:Name="NameModule" HorizontalAlignment="Center" VerticalAlignment="Top" Margin="20" IsVisible="True" PointerPressed="InnerPopupPointerPressed">
<Border Background="White" CornerRadius="10" Padding="20" BorderThickness="1" ZIndex="101" BorderBrush="#CCC">
<StackPanel Spacing="15">
<!-- Label for Text Input -->
<!-- Label -->
<TextBlock x:Name="titelMsg" Text="New Addministrator Password:"
FontSize="18"
FontWeight="Bold"
Foreground="#333"
Margin="0,0,0,8" />
<Border Name="passwordBorder">
<TextBox x:Name="passwordInput"
Width="300"
Height="30"
BorderBrush="#CCC"
BorderThickness="1"
MaxLength="9"
Tag="password"
></TextBox>
</Border>
<!-- Local styles for this specific TextBox -->
<CheckBox x:Name="isActivePass" Content="Enable/Disable" Foreground="Black">
<CheckBox.Styles>
<Style Selector="CheckBox">
<Setter Property="Foreground" Value="Black"/>
<Setter Property="Background" Value="White"/>
<Setter Property="BorderBrush" Value="Black"/>
<Setter Property="BorderThickness" Value="1"/>
<Setter Property="Padding" Value="5"/>
<Setter Property="FontSize" Value="14"/>
</Style>
<Style Selector="CheckBox:checked">
<Setter Property="Foreground" Value="Teal"/>
</Style>
</CheckBox.Styles>
</CheckBox>
<!-- Button Panel -->
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right" Spacing="10">
<!-- Save Button -->
<Button x:Name="SaveButton"
Content="OK"
FontSize="16"
Padding="10,5"
Click="passwordSaveClick"
Foreground="White" >
<Button.Background>
<LinearGradientBrush StartPoint="0,0" EndPoint="1,0">
<GradientStop Color="#A4275D" Offset="0" />
<GradientStop Color="#A4275D" Offset="1" />
</LinearGradientBrush>
</Button.Background>
<Button.Effect>
</Button.Effect>
</Button>
<!-- Cancel Button -->
<Button x:Name="CancelButton"
Content="Cancel"
FontSize="16"
Padding="10,5"
Background="Gray"
Foreground="White"
Click="hidePasswordPopUp"
>
<Button.Effect>
</Button.Effect>
</Button>
</StackPanel>
</StackPanel>
</Border>
</Grid>
</Border>
<!-- Overlay Background for Add Popup -->
<Border x:Name="secreenPopupOverlay" Background="#80000000" Grid.RowSpan="3" IsVisible="False" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" PointerPressed="hideScreenPopUp">
<!-- Popup User Control -->
<!-- Module for Name Entry -->
<Grid PointerPressed="InnerPopupPointerPressed" HorizontalAlignment="Center" VerticalAlignment="Top" Margin="20" IsVisible="True">
<Border Background="White" CornerRadius="10" Padding="20" BorderThickness="1" ZIndex="101" BorderBrush="#CCC" >
<StackPanel Spacing="15">
<!-- Label for Text Input -->
<!-- Label -->
<TextBlock x:Name="titelSecreenMsg" Text="Enter Brightness percentage:"
FontSize="18"
FontWeight="Bold"
Foreground="#333"
Margin="0,0,0,8" />
<TextBlock x:Name="sliderValue" Margin="0,10,0,0" Foreground="Black">0</TextBlock>
<Slider x:Name="slider" Minimum="0" Maximum="120"
TickFrequency="1"
IsSnapToTickEnabled="True"
Background="Black"
ValueChanged="OnSliderValueChanged"/>
<!-- Button Panel -->
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right" Spacing="10">
<!-- Save Button -->
<Button x:Name="secreenSaveButton"
Content="OK"
FontSize="16"
Padding="10,5"
Click="screenSaveClick"
Foreground="White" >
<Button.Background>
<LinearGradientBrush StartPoint="0,0" EndPoint="1,0">
<GradientStop Color="#A4275D" Offset="0" />
<GradientStop Color="#A4275D" Offset="1" />
</LinearGradientBrush>
</Button.Background>
<Button.Effect>
</Button.Effect>
</Button>
<!-- Cancel Button -->
<Button x:Name="CancelScreenButton"
Content="Cancel"
FontSize="16"
Padding="10,5"
Background="Gray"
Foreground="White"
Click="hideScreenPopUp"
>
<Button.Effect>
</Button.Effect>
</Button>
</StackPanel>
</StackPanel>
</Border>
</Grid>
</Border>
<!-- Overlay Background for Com Settings Popup -->
<Border x:Name="comPopupOverlay" Background="#80000000" Grid.RowSpan="3" IsVisible="False" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" PointerPressed="hideComPopUp">
<!-- Popup User Control -->
<!-- Module for Name Entry -->
<Grid PointerPressed="InnerPopupPointerPressed" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="20" IsVisible="True">
<Border Background="White" CornerRadius="10" Padding="20" BorderThickness="1" ZIndex="101" BorderBrush="#CCC" >
<StackPanel Spacing="15">
<!-- Label for Text Input -->
<!-- Label -->
<TextBlock Text="Com Settings"
FontSize="18"
FontWeight="Bold"
Foreground="#333"
Margin="0,0,0,8" />
<StackPanel>
<StackPanel Orientation="Horizontal">
<TextBlock Margin="0,0,5,0" Foreground="Black">Bound Rate:</TextBlock>
</StackPanel>
<ComboBox
x:Name="boundRateComboBox"
Margin="0"
HorizontalAlignment="Center"
Classes="noArrow"
SelectedIndex="0"
>
<ComboBoxItem Tag="0" Content="9600"/>
<ComboBoxItem Tag="1" Content="14400"/>
<ComboBoxItem Tag="2" Content="19200"/>
<ComboBoxItem Tag="3" Content="28800"/>
<ComboBoxItem Tag="4" Content="38400"/>
<ComboBoxItem Tag="5" Content="57600"/>
<ComboBoxItem Tag="6" Content="115200"/>
</ComboBox>
</StackPanel>
<StackPanel>
<TextBlock Foreground="Black" Margin="0,0,0,5">Stop Bits:</TextBlock>
<ComboBox
x:Name="stopBitsComboBox"
Margin="0"
HorizontalAlignment="Center"
Classes="noArrow"
SelectedIndex="0"
>
<ComboBoxItem Tag="0" Content="0"/>
<ComboBoxItem Tag="1" Content="1"/>
<ComboBoxItem Tag="2" Content="2"/>
<ComboBoxItem Tag="3" Content="1.5"/>
</ComboBox>
</StackPanel>
<StackPanel>
<TextBlock Foreground="Black" Margin="0,0,0,5">Parity:</TextBlock>
<ComboBox
x:Name="parityComboBox"
Margin="0"
HorizontalAlignment="Center"
Classes="noArrow"
SelectedIndex="0"
>
<ComboBoxItem Tag="0" Content="NONE"/>
<ComboBoxItem Tag="1" Content="ODD"/>
<ComboBoxItem Tag="2" Content="EVEN"/>
<ComboBoxItem Tag="4" Content="SPACE"/>
<ComboBoxItem Tag="3" Content="MARK"/>
</ComboBox>
</StackPanel>
<StackPanel>
<TextBlock Foreground="Black" Margin="0,0,0,5">Packets Sending Intervals :</TextBlock>
<TextBox x:Name="sendingTimetxt"
BorderBrush="#CCC"
BorderThickness="1"
GotFocus="ShowNumberKeyBoard"
MaxLength="9"
></TextBox>
</StackPanel>
<!-- Button Panel -->
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right" Spacing="10">
<!-- Save Button -->
<Button x:Name="comSaveButton"
Content="OK"
FontSize="16"
Padding="10,5"
Click="comSaveClick"
Foreground="White" >
<Button.Background>
<LinearGradientBrush StartPoint="0,0" EndPoint="1,0">
<GradientStop Color="#A4275D" Offset="0" />
<GradientStop Color="#A4275D" Offset="1" />
</LinearGradientBrush>
</Button.Background>
<Button.Effect>
</Button.Effect>
</Button>
<!-- Cancel Button -->
<Button x:Name="CancelComButton"
Content="Cancel"
FontSize="16"
Padding="10,5"
Background="Gray"
Foreground="White"
Click="hideComPopUp"
>
<Button.Effect>
</Button.Effect>
</Button>
</StackPanel>
</StackPanel>
</Border>
</Grid>
</Border>
<!-- Overlay Background for Com Settings Popup -->
<Border x:Name="tempPopupOverlay" Background="#80000000" Grid.RowSpan="3" IsVisible="False" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" PointerPressed="hideTempPopUp">
<!-- Popup User Control -->
<!-- Module for Name Entry -->
<Grid PointerPressed="InnerPopupPointerPressed" HorizontalAlignment="Center" VerticalAlignment="Top" Margin="20" IsVisible="True">
<Border Background="White" CornerRadius="10" Padding="20" BorderThickness="1" ZIndex="101" BorderBrush="#CCC" >
<StackPanel Spacing="15">
<!-- Label for Text Input -->
<!-- Label -->
<StackPanel Spacing="10">
<TextBlock Foreground="Black" Margin="0,0,0,5">Warning Limit :</TextBlock>
<Border x:Name="warningBorder">
<TextBox x:Name="warningLimit"
BorderBrush="#CCC"
BorderThickness="1"
MaxLength="9"
></TextBox>
</Border>
<TextBlock Foreground="Black" Margin="0,0,0,5">Error Limit :</TextBlock>
<Border x:Name="errorBorder">
<TextBox x:Name="errorLimit"
BorderBrush="#CCC"
BorderThickness="1"
MaxLength="9"
></TextBox>
</Border>
</StackPanel>
<!-- Button Panel -->
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right" Spacing="10">
<!-- Save Button -->
<Button x:Name="tempSaveButton"
Content="OK"
FontSize="16"
Padding="10,5"
Click="tempSaveBtn"
Foreground="White" >
<Button.Background>
<LinearGradientBrush StartPoint="0,0" EndPoint="1,0">
<GradientStop Color="#A4275D" Offset="0" />
<GradientStop Color="#A4275D" Offset="1" />
</LinearGradientBrush>
</Button.Background>
<Button.Effect>
</Button.Effect>
</Button>
<!-- Cancel Button -->
<Button x:Name="CancelTempButton"
Content="Cancel"
FontSize="16"
Padding="10,5"
Background="Gray"
Foreground="White"
Click="hideTempPopUp"
>
<Button.Effect>
</Button.Effect>
</Button>
</StackPanel>
</StackPanel>
</Border>
</Grid>
</Border>
<!--number keyBoard-->
<Border x:Name="keyBoardPopup"
Background="#80000000"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
IsVisible="False"
ZIndex="50"
PointerPressed="OnPopupOverlayPointerPressed">
<Grid MaxWidth="500" MaxHeight="500" HorizontalAlignment="Right" VerticalAlignment="Center"
Margin="0,0,150,0">
<Border x:Name="PopupControl"
BorderThickness="2"
CornerRadius="10"
Padding="10"
PointerPressed="OnPopupOverlayPointerPressed">
<StackPanel VerticalAlignment="Center" HorizontalAlignment="Center" Spacing="10">
<!-- Popup Content (Keypad etc.) -->
<Grid IsVisible="True">
<Grid.Styles>
<Style Selector="Button">
<Setter Property="Background" Value="White"/>
<Setter Property="CornerRadius" Value="20"/>
<Setter Property="Width" Value="100"/>
<Setter Property="Height" Value="100"/>
<Setter Property="FontSize" Value="50"/>
<Setter Property="Foreground" Value="Black"/>
<Setter Property="VerticalContentAlignment" Value="Center"/>
<Setter Property="HorizontalContentAlignment" Value="Center"/>
</Style>
<Style Selector="Button:pointerover /template/ContentPresenter">
<Setter Property="Foreground" Value="Black"/>
<Setter Property="Background" Value="White"/>
<Setter Property="CornerRadius" Value="20"/>
<Setter Property="RenderTransform" Value="scale(1.11)"/>
</Style>
</Grid.Styles>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Grid Grid.Row="1" Margin="10">
<Grid.RowDefinitions>
<RowDefinition Height="1*"/>
<RowDefinition Height="1*"/>
<RowDefinition Height="1*"/>
<RowDefinition Height="1*"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="1*"/>
<ColumnDefinition Width="1*"/>
<ColumnDefinition Width="1*"/>
</Grid.ColumnDefinitions>
<!-- Keypad Buttons -->
<Button Content="1" Grid.Row="0" Grid.Column="0" FontSize="24" Background="White" Margin="5" Click="OnKeyClick"/>
<Button Content="2" Grid.Row="0" Grid.Column="1" FontSize="24" Background="White" Margin="5" Click="OnKeyClick"/>
<Button Content="3" Grid.Row="0" Grid.Column="2" FontSize="24" Background="White" Margin="5" Click="OnKeyClick"/>
<Button Content="4" Grid.Row="1" Grid.Column="0" FontSize="24" Background="White" Margin="5" Click="OnKeyClick"/>
<Button Content="5" Grid.Row="1" Grid.Column="1" FontSize="24" Background="White" Margin="5" Click="OnKeyClick"/>
<Button Content="6" Grid.Row="1" Grid.Column="2" FontSize="24" Background="White" Margin="5" Click="OnKeyClick"/>
<Button Content="7" Grid.Row="2" Grid.Column="0" FontSize="24" Background="White" Margin="5" Click="OnKeyClick"/>
<Button Content="8" Grid.Row="2" Grid.Column="1" FontSize="24" Background="White" Margin="5" Click="OnKeyClick"/>
<Button Content="9" Grid.Row="2" Grid.Column="2" FontSize="24" Background="White" Margin="5" Click="OnKeyClick"/>
<Button Content="BACK" Grid.Row="3" Grid.Column="0" FontSize="20" Background="#D3D3D3" Margin="5" Click="OnBackClick"/>
<Button Content="0" Grid.Row="3" Grid.Column="1" FontSize="24" Background="White" Margin="5" Click="OnKeyClick"/>
<Button Content="ENTER" Grid.Row="3" Grid.Column="2" FontSize="20" Background="#A4275D" Foreground="White" Margin="5" Click="EnterClick"/>
</Grid>
</Grid>
</StackPanel>
</Border>
</Grid>
</Border>
</Grid>
</UserControl>

View File

@@ -0,0 +1,698 @@
using Avalonia;
using Avalonia.Controls;
using Avalonia.Controls.ApplicationLifetimes;
using Avalonia.Input;
using Avalonia.Interactivity;
using Avalonia.LogicalTree;
using Avalonia.Markup.Xaml;
using Avalonia.Media;
using Avalonia.Threading;
using AvaloniaApplication1.DataBase;
using DaireApplication.DataBase;
using DaireApplication.ViewModels;
using DaireApplication.Views;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using System.IO.Ports;
using System.Linq;
using System.Numerics;
using System.Reflection.Emit;
using System.Reflection.PortableExecutable;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
namespace DaireApplication;
public partial class Software : UserControl
{
private MainWindow? _mainWindow;
public UserTable _user = new();
public ScreeenTable _screeen = new();
private Process? _keyboardProcess;
private bool _isWindowLoaded = false;
TextBox targetText = new TextBox();
int oldValue = 0;
bool _isAdvSetting;
bool _isFromManualControl;
public event PropertyChangedEventHandler? PropertyChanged;
private void RaisePropertyChanged([CallerMemberName] string? name = null) =>
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
public ObservableCollection<string> SerialPorts { get; } = new() { "Choose COM" };
private string? _selectedPort;
public string? SelectedPort
{
get => _selectedPort;
set
{
if (_selectedPort != value)
{
_selectedPort = value;
RaisePropertyChanged();
}
}
}
public Software(MainWindow mainWindow,bool isAdvSetting=false, bool isFromManualControl=false)
{
_mainWindow = mainWindow;
_isAdvSetting = isAdvSetting;
_isFromManualControl = isFromManualControl;
foreach (var port in SerialPort.GetPortNames())
{
SerialPorts.Add(port);
}
var screen = _screeen.ReadScreens()[0];
InitializeComponent();
this.Loaded += OnWindowLoaded;
if (SerialPorts.Count - 1 > 0)
{
if (!string.IsNullOrEmpty(screen.port))
{
SerialPorts[0] = "Close Comunication";
SelectedPort = screen.port;
}
else
{
SerialPorts[0] = "Choose COM";
SelectedPort = SerialPorts[0];
}
}
else
SelectedPort = SerialPorts[0];
DataContext = this;
setDefaultSettings();
showDefaultValues();
sendingTimetxt.AddHandler(TextInputEvent, OnTextInput, RoutingStrategies.Tunnel);
warningLimit.AddHandler(TextInputEvent, OnTextInput, RoutingStrategies.Tunnel);
errorLimit.AddHandler(TextInputEvent, OnTextInput, RoutingStrategies.Tunnel);
passwordBorder.AddHandler(InputElement.PointerPressedEvent, OnTextBoxFocused, RoutingStrategies.Tunnel, handledEventsToo: true);
warningBorder.AddHandler(InputElement.PointerPressedEvent, OnTextBoxFocused, RoutingStrategies.Tunnel, handledEventsToo: true);
errorBorder.AddHandler(InputElement.PointerPressedEvent, OnTextBoxFocused, RoutingStrategies.Tunnel, handledEventsToo: true);
AttachHandlers(_mainWindow.logoBtn, AdvanceSettingsView);
AttachHandlers(_mainWindow.UserName, CloseApplication);
}
public void AttachHandlers(Button button, System.EventHandler<Avalonia.Input.HoldingRoutedEventArgs> func)
{
if (button != null)
{
button.Holding += func;
button.PointerPressed += (sender, e) =>
{
// Simulate a long press on any pointer (mouse or touch)
var point = e.GetPosition(button);
func(sender, new HoldingRoutedEventArgs(HoldingState.Started, point, e.Pointer.Type));
};
button.PointerReleased += (sender, e) =>
{
// End simulated long press
var point = e.GetPosition(button);
func(sender, new HoldingRoutedEventArgs(HoldingState.Completed, point, e.Pointer.Type));
};
}
}
public Software()
{
InitializeComponent();
}
public void AdvanceSettingsView(object? sender, RoutedEventArgs e)
{
if (_mainWindow.ContentArea.Content == this)
{
_mainWindow.ContentArea.Content = new AdvanceSettings(_mainWindow,false,true);
}
}
public static void CloseApplication(object? sender, RoutedEventArgs e)
{
var lifetime = Application.Current?.ApplicationLifetime as IClassicDesktopStyleApplicationLifetime;
lifetime?.Shutdown(); // This should correctly shut down the application
}
private void OnWindowLoaded(object? sender, RoutedEventArgs e)
{
_isWindowLoaded = true;
}
private void OnTextInput(object? sender, TextInputEventArgs e)
{
if (sender is TextBox textBox)
{
string newText = textBox.Text + e.Text;
if (!Regex.IsMatch(newText, @"^\d*\.?\d*$"))
{
e.Handled = true;
}
}
}
private void hidePasswordPopUp(object sender, RoutedEventArgs e)
{
passwordInput.Text = "";
CloseKeyboard();
passwordPopupOverlay.IsVisible = false;
}
private async void passwordSaveClick(object? sender, RoutedEventArgs e)
{
var user = _user.ReadUsers().FirstOrDefault(x=>x.UserName.ToLower()==titelMsg.Tag.ToString().ToLower());
user.Password = passwordInput.Text;
user.IsActive = isActivePass.IsChecked.Value;
if (_user.UpdateUser(user))
{
//await MainWindow.MessageBox.Show(_mainWindow, "Password Changed Sucseccfully", "Sucsecc");
passwordInput.Text = "";
CloseKeyboard();
passwordPopupOverlay.IsVisible = false;
}
else
{
if (_keyboardProcess != null)
{
_keyboardProcess.Kill();
}
await MainWindow.MessageBox.Show(_mainWindow, "Password Does Not Changed Try Again", "Error");
_mainWindow.Topmost = false;
}
}
private void showChangePasswordPopUp(object? sender, RoutedEventArgs e)
{
if (sender is Button button)
{
var text = button.Content as TextBlock;
titelMsg.Text = $"New {text.Text} Password:";
titelMsg.Tag = text.Text;
var user = _user.ReadUsers().FirstOrDefault(x => x.UserName.ToLower() == titelMsg.Tag.ToString().ToLower());
isActivePass.IsVisible = true;
isActivePass.IsChecked = user.IsActive;
passwordPopupOverlay.IsVisible = true;
}
}
private void hideScreenPopUp(object sender, RoutedEventArgs e)
{
slider.Value = 0;
secreenPopupOverlay.IsVisible = false;
}
private async void screenSaveClick(object? sender, RoutedEventArgs e)
{
var screenData = _screeen.ReadScreens()?[0];
string brightnessPath = "/sys/class/backlight/backlight/brightness"; // Try backlight1 if this fails
if (titelSecreenMsg.Tag.ToString()== "BRIGHTNESS")
{
try
{
if (!string.IsNullOrEmpty(sliderValue.Text))
{
int brightnessValue = (int)(Int32.Parse(sliderValue.Text) / 100.0 * 255);
screenData.brightness = Int32.Parse(sliderValue.Text);
_screeen.UpdateScreen(screenData);
File.WriteAllText(brightnessPath, brightnessValue.ToString());
}
}
catch (Exception ex)
{
Console.WriteLine("Error: " + ex.Message);
}
}
else if (titelSecreenMsg.Tag.ToString() == "AUTO DIM")
{
if (!string.IsNullOrEmpty(sliderValue.Text))
{
if ((screenData?.offSec / 60.0) < float.Parse(sliderValue.Text))
{
if (_keyboardProcess != null)
{
_keyboardProcess.Kill();
}
await MainWindow.MessageBox.Show(_mainWindow, "AutoOff Value must be greater than AutoDim Value", "Error");
_mainWindow.Topmost = false;
return;
}
screenData.dimSec = float.Parse(sliderValue.Text) * 60;
_screeen.UpdateScreen(screenData);
}
}
else if (titelSecreenMsg.Tag.ToString() == "AUTO OFF")
{
if (!string.IsNullOrEmpty(sliderValue.Text))
{
if ((screenData?.dimSec / 60.0)> float.Parse(sliderValue.Text))
{
if (_keyboardProcess != null)
{
_keyboardProcess.Kill();
}
await MainWindow.MessageBox.Show(_mainWindow, "AutoOff Value must be greater than AutoDim Value", "Error");
_mainWindow.Topmost = false;
return;
}
screenData.offSec = float.Parse(sliderValue.Text) * 60;
_screeen.UpdateScreen(screenData);
}
}
showDefaultValues();
secreenPopupOverlay.IsVisible = false;
}
private void InnerPopupPointerPressed(object? sender, PointerPressedEventArgs e)
{
e.Handled = true;
}
private void showScreenPopUp(object? sender, RoutedEventArgs e)
{
if (sender is Button button)
{
var screenData = _screeen.ReadScreens()?[0];
if (button.Tag.ToString() == "BRIGHTNESS")
{
slider.Maximum = 100;
titelSecreenMsg.Text = $"Enter {button.Tag} percentage:";
titelSecreenMsg.Tag = button.Tag;
slider.Value = screenData.brightness;
secreenPopupOverlay.IsVisible = true;
}
if (button.Tag.ToString() == "AUTO DIM")
{
slider.Maximum = 120;
titelSecreenMsg.Text = $"Enter {button.Tag} value in min:";
titelSecreenMsg.Tag = button.Tag;
slider.Value = screenData.dimSec / 60;
secreenPopupOverlay.IsVisible = true;
}
if (button.Tag.ToString() == "AUTO OFF")
{
slider.Maximum = 120;
titelSecreenMsg.Text = $"Enter {button.Tag} value in min:";
titelSecreenMsg.Tag = button.Tag;
slider.Value = screenData.offSec / 60;
secreenPopupOverlay.IsVisible = true;
}
}
}
private void OnSliderValueChanged(object? sender, RoutedEventArgs e)
{
if (sender is Slider slider)
{
var parent = slider.Parent as StackPanel;
var targetText = parent.Children[1] as TextBlock;
targetText.Text= slider.Value.ToString();
//sliderValue.Text= slider.Value.ToString();
}
}
private void changeValueClick(object? sender, RoutedEventArgs e)
{
if (sender is Button button)
{
var parent = button.Parent as StackPanel;
var slider = parent.Children[1] as Slider;
var grandParent = parent.Parent as StackPanel;
var stack = grandParent.Children[0] as StackPanel;
var targetText = stack.Children[1] as TextBlock;
targetText.Text = slider.Value.ToString();
if (button.Content=="+") // +
{
slider.Value = Int32.Parse(targetText.Text) + 1;
}
else // -
{
if (Int32.Parse(targetText.Text)>0)
{
slider.Value = Int32.Parse(targetText.Text) - 1;
}
}
}
}
private void OnComSliderValueChanged(object? sender, RoutedEventArgs e)
{
if (sender is Slider slider)
{
var parent = slider.Parent.Parent as StackPanel;
var stack = parent.Children[0] as StackPanel;
var targetText = stack.Children[1] as TextBlock;
targetText.Text= slider.Value.ToString();
}
}
private void hideComPopUp(object sender, RoutedEventArgs e)
{
//comSlider.Value = 0;
comPopupOverlay.IsVisible = false;
}
private void hideTempPopUp(object sender, RoutedEventArgs e)
{
tempPopupOverlay.IsVisible = false;
}
private async void comSaveClick(object? sender, RoutedEventArgs e)
{
var screen = _screeen.ReadScreens()[0];
var boundRateItem = boundRateComboBox.SelectedItem as ComboBoxItem;
screen.boundRate = Int32.Parse(boundRateItem.Content.ToString());
var stopbitsItem = stopBitsComboBox.SelectedItem as ComboBoxItem;
screen.stopBits = Int32.Parse(stopbitsItem.Tag.ToString());
var parityItem = parityComboBox.SelectedItem as ComboBoxItem;
screen.parity = Int32.Parse(parityItem.Tag.ToString());
screen.sendingTime = Int32.Parse(sendingTimetxt.Text);
if (_screeen.UpdateScreen(screen))
{
_mainWindow.resetPort = true;
_mainWindow.footerMsg.Text = "Connecting.....";
_mainWindow.footerMsg.IsVisible = true;
comPopupOverlay.IsVisible = false;
}
}
private void showComPopUp(object? sender, RoutedEventArgs e)
{
var screen = _screeen.ReadScreens()[0];
boundRateComboBox.SelectedIndex=int.Parse(boundRateComboBox.Items.OfType<ComboBoxItem>().FirstOrDefault(item => item.Content?.ToString() == screen.boundRate.ToString()).Tag.ToString());
stopBitsComboBox.SelectedIndex = screen.stopBits;
parityComboBox.SelectedIndex = screen.parity;
sendingTimetxt.Text=screen.sendingTime.ToString();
comPopupOverlay.IsVisible = true;
}
private void ShowTempPopUp(object? sender, RoutedEventArgs e)
{
var screen = _screeen.ReadScreens()[0];
warningLimit.Text=screen.warningLimit.ToString();
errorLimit.Text=screen.errorLimit.ToString();
tempPopupOverlay.IsVisible = true;
}
private void tempSaveBtn(object? sender, RoutedEventArgs e)
{
var screen = _screeen.ReadScreens()[0];
screen.warningLimit = double.Parse(warningLimit.Text);
screen.errorLimit = double.Parse(errorLimit.Text);
_screeen.UpdateScreen(screen);
CloseKeyboard();
//if (_keyboardProcess != null)
//{
// _keyboardProcess.Kill();
//}
tempPopupOverlay.IsVisible=false;
}
private void portChanged(object? sender, RoutedEventArgs e)
{
if (!_isWindowLoaded)
return;
if (sender is ComboBox comboBox)
{
if (comboBox.SelectedItem is string selectedItem)
{
var screen = _screeen.ReadScreens()[0];
if (selectedItem.ToString()!= "Choose COM" && selectedItem.ToString()!= "Close Comunication")
{
screen.port = selectedItem.ToString();
_screeen.UpdateScreen(screen);
}
else
{
screen.port = "";
_screeen.UpdateScreen(screen);
}
boundRateComboBox.SelectedIndex = int.Parse(boundRateComboBox.Items.OfType<ComboBoxItem>().FirstOrDefault(item => item.Content?.ToString() == screen.boundRate.ToString()).Tag.ToString());
stopBitsComboBox.SelectedIndex = screen.stopBits;
parityComboBox.SelectedIndex = screen.parity;
sendingTimetxt.Text = screen.sendingTime.ToString();
this.comSaveButton.RaiseEvent(new RoutedEventArgs(Button.ClickEvent));
}
}
}
private (string? fileName, string args) GetKeyboardCommand()
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
return ("osk.exe", "");
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
return ("onboard", ""); // or "florence", "matchbox-keyboard"
return (null, "");
}
private async void OnTextBoxFocused(object? sender, PointerPressedEventArgs e)
{
if (_keyboardProcess is { HasExited: false })
return;
var (fileName, args) = GetKeyboardCommand();
if (fileName is null)
return;
_keyboardProcess = new Process
{
StartInfo = new ProcessStartInfo
{
FileName = fileName,
Arguments = args,
UseShellExecute = true,
WorkingDirectory = "/usr/bin"
},
EnableRaisingEvents = true
};
try
{
_keyboardProcess.Start();
Dispatcher.UIThread.Post(() =>
{
if (sender is Border border)
{
var textbox = border.Child as TextBox;
textbox.SelectionStart = 0;
textbox.SelectionEnd = textbox.Text?.Length ?? 0;
}
});
}
catch
{
// fail silently if keyboard not found
}
}
private void OnPopupOverlayPointerPressed(object sender, PointerPressedEventArgs e)
{
targetText.Text = oldValue.ToString();
CancelComButton.Focus();
keyBoardPopup.IsVisible = false;
}
private void OnKeyClick(object? sender, RoutedEventArgs e)
{
if (sender is Button button)
{
targetText.Text += button.Content;
}
}
private void ShowNumberKeyBoard(object? sender, RoutedEventArgs e)
{
targetText = sendingTimetxt;
oldValue = Int32.Parse(targetText.Text);
targetText.Text = "";
keyBoardPopup.IsVisible = true;
}
private void OnBackClick(object? sender, RoutedEventArgs e)
{
if (!string.IsNullOrEmpty(targetText.Text))
{
// Remove the last character from the text box
targetText.Text = targetText.Text.Remove(targetText.Text.Length - 1, 1);
}
}
private void EnterClick(object? sender, RoutedEventArgs e)
{
CancelComButton.Focus();
keyBoardPopup.IsVisible = false;
}
private void CloseKeyboard()
{
try
{
if (_keyboardProcess != null)
{
// Kill the keyboard process
_keyboardProcess.Kill();
_keyboardProcess.Dispose();
_keyboardProcess = null;
// Force kill any remaining keyboard processes
var processKill = new Process
{
StartInfo = new ProcessStartInfo
{
FileName = "killall",
Arguments = "-9 onboard matchbox-keyboard florence", // Common Linux on-screen keyboards
UseShellExecute = false,
CreateNoWindow = true
}
};
processKill.Start();
processKill.WaitForExit(1000);
processKill.Dispose();
}
}
catch (Exception ex)
{
Console.WriteLine($"Error closing keyboard: {ex.Message}");
}
}
private void setDefaultSettings()
{
_mainWindow.minimizeBtn.IsVisible = false;
var stackPanel = _mainWindow.HomeTrack.Parent as StackPanel;
if (_isFromManualControl)
{
// Special UI setup when called from ManualControl
_mainWindow.HomeTrack.IsVisible = true;
_mainWindow.HomePolygon.Stroke = Avalonia.Media.Brushes.Black;
_mainWindow.RecipeSelTrack.IsVisible = false;
_mainWindow.RunInterfaceTrack.IsVisible = false;
_mainWindow.RecipePanelTrack.IsVisible = true;
_mainWindow.RecipePanelPolygon.Stroke = Avalonia.Media.Brushes.Black;
_mainWindow.RecipeEditTrack.IsVisible = false;
_mainWindow.SettingTrack.IsVisible = false;
_mainWindow.AdvanceSettingsTrack.IsVisible = false;
_mainWindow.ManualControlTrack.IsVisible = true;
_mainWindow.ManualControlPolygon.Stroke = Avalonia.Media.Brushes.Black;
}
else
{
// Original logic for other callers
//Set Track Up
_mainWindow.HomeTrack.IsVisible = true;
_mainWindow.HomePolygon.Stroke = Avalonia.Media.Brushes.Black;
_mainWindow.RecipeSelTrack.IsVisible = false;
_mainWindow.RunInterfaceTrack.IsVisible = false;
_mainWindow.RecipePanelTrack.IsVisible = false;
_mainWindow.RecipeEditTrack.IsVisible = false;
if (_isAdvSetting)
{
_mainWindow.SettingTrack.IsVisible = false;
_mainWindow.AdvanceSettingsTrack.IsVisible = true;
_mainWindow.AdvanceSettingsPolygon.Stroke = Avalonia.Media.Brushes.Black;
}
else
{
_mainWindow.SettingTrack.IsVisible = true;
_mainWindow.SettingPolygon.Stroke = Avalonia.Media.Brushes.Black;
_mainWindow.AdvanceSettingsTrack.IsVisible = false;
}
}
_mainWindow.DiagnosticsTrack.IsVisible = false;
// Remove the button from its current position
stackPanel.Children.Remove(_mainWindow.SoftwareTrack);
// Add it back at the end of the StackPanel
stackPanel.Children.Add(_mainWindow.SoftwareTrack);
_mainWindow.SoftwareTrack.IsVisible = true;
_mainWindow.SoftwarePolygon.Stroke = Brush.Parse("#A4275D");
_mainWindow.TitleBtn.IsVisible = false;
//Set Footer
_mainWindow.footerMsg.IsVisible = false;
_mainWindow.footer.Background = Brush.Parse("#f2f2f2");
_mainWindow.footerDate.Text = DateTime.Now.ToString("dd/MM/yyyy");
_mainWindow.footerTime.Text = DateTime.Now.ToString("hh:mm tt");
_mainWindow.footerDateContainer.IsVisible = true;
_mainWindow.footerStartBtn.IsVisible = false;
_mainWindow.adminBtns.IsVisible = false;
}
private void showDefaultValues()
{
var users = _user.ReadUsers();
var allUIUsers = this.GetLogicalDescendants()
.OfType<TextBlock>()
.Where(cb => cb.Classes.Contains("user"))
.ToList();
for (int i = 0; i < allUIUsers.Count; i++)
{
allUIUsers[i].Text = users[i].UserName;
}
var screenData = _screeen.ReadScreens()?[0];
brightnessValue.Text = screenData?.brightness.ToString();
dimValue.Text = (screenData?.dimSec/60.0).ToString();
offValue.Text = (screenData?.offSec/60.0).ToString();
}
}