Commit 15cc6ad0 authored by M3156's avatar M3156
Browse files

reordering the code and adding screenshots of the UI

parent 8a95298a
No preview for this file type
......@@ -21,13 +21,16 @@ namespace iTool
/// </summary>
public partial class AddAToolWindow : Window
{
#region PROPERTIES
private List<string> conditions = new List<string>() { "Poor", "Ok", "Good", "Pristine" };
private List<string> categories = new List<string>() { "Hionta", "Hitsauskoneet", "Juottaminen", "Käsityökalut", "Leikkaustyökalut", "Leikkuuterät", "Mittavälineet", "Paineilma", "Poranterät", "Työkalujen säilyttäminen", "Työpajan varustus", "Työstökoneet", "Sähkötyökalut" };
private string path;
private string imgFile;
private string dirPath;
private string relativePath;
#endregion
#region METHODS
public AddAToolWindow()
{
InitializeComponent();
......@@ -41,108 +44,122 @@ namespace iTool
cbToolCondition.ItemsSource = conditions;
}
private void Reset()
{
txtToolName.Text = "";
cbToolCategories.SelectedValue = null;
cbToolCondition.SelectedValue = null;
txtPrice.Text = "";
txtDescription.Text = "";
txtBrowseToolImage.Text = "";
imgAddTool.Source = new BitmapImage(new Uri(@"F:\iTool\iTool\iTool\images\no_picture_tool.png", UriKind.RelativeOrAbsolute));
}
#endregion
#region EVENTHANDLERS
private void btnBrowseToolImage_Click(object sender, RoutedEventArgs e)
{
OpenFileDialog dlg = new OpenFileDialog();
dlg.Title = "Select a tool image";
dlg.InitialDirectory = "c:\\";
dlg.Filter = "All supported graphics |*.jpg;*.jpeg;*.png|All files (*.*)|*.*";
dlg.RestoreDirectory = true;
Nullable<bool> result = dlg.ShowDialog(); // näyttää dialogin
if (result == true)
{
txtBrowseToolImage.Text = dlg.FileName;
}
if (string.IsNullOrEmpty(txtBrowseToolImage.Text))
try
{
dlg.FileName = "images/no_picture_tool.png";
}
OpenFileDialog dlg = new OpenFileDialog();
dlg.Title = "Select a tool image";
dlg.InitialDirectory = "c:\\";
dlg.Filter = "All supported graphics |*.jpg;*.jpeg;*.png|All files (*.*)|*.*";
dlg.RestoreDirectory = true;
Nullable<bool> result = dlg.ShowDialog(); // näyttää dialogin
if (result == true)
{
txtBrowseToolImage.Text = dlg.FileName;
}
if (string.IsNullOrEmpty(txtBrowseToolImage.Text))
{
dlg.FileName = "images/no_picture_tool.png";
}
imgAddTool.Stretch = Stretch.Fill;
Uri u = new Uri(dlg.FileName, UriKind.RelativeOrAbsolute);
imgAddTool.Source = new BitmapImage(new Uri(dlg.FileName, UriKind.RelativeOrAbsolute));
string i = imgAddTool.Source.ToString().Split('/')[imgAddTool.Source.ToString().Split('/').Length - 1];
//path = $@"F:\iTool\iTool\iTool\images\{i}";
path = $@"images\{i}";
if (File.Exists(path))
{
int x = 0;
for (; File.Exists(path);)
imgAddTool.Stretch = Stretch.Fill;
Uri u = new Uri(dlg.FileName, UriKind.RelativeOrAbsolute);
imgAddTool.Source = new BitmapImage(new Uri(dlg.FileName, UriKind.RelativeOrAbsolute));
string i = imgAddTool.Source.ToString().Split('/')[imgAddTool.Source.ToString().Split('/').Length - 1];
//path = $@"F:\iTool\iTool\iTool\images\{i}";
path = $@"images\{i}";
if (File.Exists(path))
{
path = $@"images\{x}{i}";
//path = $@"F:\iTool\iTool\iTool\images\{x}{i}";
imgFile = $"{x}{i}";
x++;
int x = 0;
for (; File.Exists(path);)
{
path = $@"images\{x}{i}";
//path = $@"F:\iTool\iTool\iTool\images\{x}{i}";
imgFile = $"{x}{i}";
x++;
}
}
}
else
{
imgFile = path.Split('\\')[path.Split('\\').Length - 1];
}
else
{
imgFile = path.Split('\\')[path.Split('\\').Length - 1];
}
// relaatiivinen polku images kansioon
relativePath = $"{Directory.GetParent(Environment.CurrentDirectory).Parent.FullName}\\{path}";
// relaatiivinen polku images kansioon
relativePath = $"{Directory.GetParent(Environment.CurrentDirectory).Parent.FullName}\\{path}";
// polku valituun kuvatiedostoon
dirPath = $@"{System.IO.Path.GetDirectoryName(dlg.FileName)}\{System.IO.Path.GetFileName(dlg.FileName)}";
// polku valituun kuvatiedostoon
dirPath = $@"{System.IO.Path.GetDirectoryName(dlg.FileName)}\{System.IO.Path.GetFileName(dlg.FileName)}";
}
catch
{
throw;
}
}
private void btnAddaToolToMysql_Click(object sender, RoutedEventArgs e)
{
if (txtToolName.Text.Length == 0)
{
lblToolError.Content = "Enter a tool name";
txtToolName.Focus();
}
else if (cbToolCategories.SelectedValue is null)
{
lblToolError.Content = "Select a category";
cbToolCategories.Focus();
}
else if (cbToolCondition.SelectedValue is null)
try
{
lblToolError.Content = "Select a condition";
cbToolCondition.Focus();
}
else if (string.IsNullOrEmpty(txtPrice.Text) || !float.TryParse(txtPrice.Text, out float f))
{
lblToolError.Content = "Enter a price, has to be a number";
txtPrice.Focus();
}
else if (string.IsNullOrEmpty(txtDescription.Text))
{
lblToolError.Content = "Enter a description";
txtDescription.Focus();
}
else
{
int cID = DB.GetToolCategoryID(cbToolCategories.SelectedValue.ToString());
DB.AddAToolToMysql(txtToolName.Text, cID, txtDescription.Text, Active.UserID, cbToolCondition.SelectedValue.ToString(), float.Parse(txtPrice.Text), imgFile);
lblToolError.Content = "You have successfully added a tool for rent!";
Active.profile.dgMyTools.ItemsSource = DB.GetOwnedToolsFromMysql();
if (!string.IsNullOrEmpty(txtBrowseToolImage.Text))
if (txtToolName.Text.Length == 0)
{
System.IO.File.Copy(dirPath, relativePath, true);
File.SetAttributes(relativePath, FileAttributes.Normal);
lblToolError.Content = "Enter a tool name";
txtToolName.Focus();
}
Reset();
}
}
else if (cbToolCategories.SelectedValue is null)
{
lblToolError.Content = "Select a category";
cbToolCategories.Focus();
}
else if (cbToolCondition.SelectedValue is null)
{
lblToolError.Content = "Select a condition";
cbToolCondition.Focus();
}
else if (string.IsNullOrEmpty(txtPrice.Text) || !float.TryParse(txtPrice.Text, out float f))
{
lblToolError.Content = "Enter a price, has to be a number";
txtPrice.Focus();
}
else if (string.IsNullOrEmpty(txtDescription.Text))
{
lblToolError.Content = "Enter a description";
txtDescription.Focus();
}
else
{
int cID = DB.GetToolCategoryID(cbToolCategories.SelectedValue.ToString());
DB.AddAToolToMysql(txtToolName.Text, cID, txtDescription.Text, Active.UserID, cbToolCondition.SelectedValue.ToString(), float.Parse(txtPrice.Text), imgFile);
lblToolError.Content = "You have successfully added a tool for rent!";
Active.profile.dgMyTools.ItemsSource = DB.GetOwnedToolsFromMysql();
private void Reset()
{
txtToolName.Text = "";
cbToolCategories.SelectedValue = null;
cbToolCondition.SelectedValue = null;
txtPrice.Text = "";
txtDescription.Text = "";
txtBrowseToolImage.Text = "";
imgAddTool.Source = new BitmapImage(new Uri(@"F:\iTool\iTool\iTool\images\no_picture_tool.png", UriKind.RelativeOrAbsolute));
if (!string.IsNullOrEmpty(txtBrowseToolImage.Text))
{
System.IO.File.Copy(dirPath, relativePath, true);
File.SetAttributes(relativePath, FileAttributes.Normal);
}
Reset();
}
}
catch
{
throw;
}
}
private void Window_KeyUp(object sender, KeyEventArgs e)
......@@ -153,5 +170,6 @@ namespace iTool
addRandomTools.ShowDialog();
}
}
#endregion
}
}
......@@ -19,80 +19,97 @@ namespace iTool
/// </summary>
public partial class AddRandomTools : Window
{
#region METHODS
public AddRandomTools()
{
InitializeComponent();
}
private void BtnGenerate_Click(object sender, RoutedEventArgs e)
{
var result = MessageBox.Show($"Do you really want to generate and add to database {txtToolAmount.Text} random tools?", "Add random tools to database", MessageBoxButton.YesNo);
if (result == MessageBoxResult.Yes)
{
Generate();
lblInfo.Content = $"You have added {txtToolAmount.Text} random tools into database";
}
else
{
lblInfo.Content = $"You did nothing";
}
}
private void Generate()
{
List<int> userIDs = DB.GetUserIDsFromMysql();
List<string> conditions = new List<string>() { "Poor", "Ok", "Good", "Pristine" };
List<string> categories = new List<string>() { "Hionta", "Hitsauskoneet", "Juottaminen", "Käsityökalut", "Leikkaustyökalut", "Leikkuuterät", "Mittavälineet", "Paineilma", "Poranterät", "Työkalujen säilyttäminen", "Työpajan varustus", "Työstökoneet", "Sähkötyökalut" };
List<string> toolNames = new List<string>() { "Saha", "Vasara", "Ruuvimeisseli", "Porakone", "Hiontaterä", "Kirves", "Miekka", "Työkaluboksi", "Pora", "Rautasaha", "Moottorisaha", "Ruoholeikkuri", "Jakoavain", "Pihdit", "Jeesusteippi", "Mittanauha", "Rakennuskynä", "Lapio", "Vatupassi", "Lumikola", "Laasta", "Pensseli"};
float[] f1 = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20 };
float[] f2 = { 0.1F, 0.2F, 0.3F, 0.4F, 0.5F, 0.6F, 0.7F, 0.8F, 0.9F };
List<int> toolCategoryIDs = DB.GetToolCategoryIDs();
Random rand = new Random();
try
{
List<int> userIDs = DB.GetUserIDsFromMysql();
List<string> conditions = new List<string>() { "Poor", "Ok", "Good", "Pristine" };
List<string> categories = new List<string>() { "Hionta", "Hitsauskoneet", "Juottaminen", "Käsityökalut", "Leikkaustyökalut", "Leikkuuterät", "Mittavälineet", "Paineilma", "Poranterät", "Työkalujen säilyttäminen", "Työpajan varustus", "Työstökoneet", "Sähkötyökalut" };
List<string> toolNames = new List<string>() { "Saha", "Vasara", "Ruuvimeisseli", "Porakone", "Hiontaterä", "Kirves", "Miekka", "Työkaluboksi", "Pora", "Rautasaha", "Moottorisaha", "Ruoholeikkuri", "Jakoavain", "Pihdit", "Jeesusteippi", "Mittanauha", "Rakennuskynä", "Lapio", "Vatupassi", "Lumikola", "Laasta", "Pensseli" };
float[] f1 = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20 };
float[] f2 = { 0.1F, 0.2F, 0.3F, 0.4F, 0.5F, 0.6F, 0.7F, 0.8F, 0.9F };
List<int> toolCategoryIDs = DB.GetToolCategoryIDs();
Random rand = new Random();
for (int i = 0; i < int.Parse(txtToolAmount.Text) ; i++)
for (int i = 0; i < int.Parse(txtToolAmount.Text); i++)
{
int userID = userIDs[rand.Next(userIDs.Count)];
string tName = toolNames[rand.Next(toolNames.Count)];
string tCondition = conditions[rand.Next(conditions.Count)];
int tCategory = toolCategoryIDs[rand.Next(toolCategoryIDs.Count)];
float tPrice = f1[rand.Next(f1.Length)] + f2[rand.Next(f2.Length)];
string tDescription = LoremIpsum(3, 8, 1, 2, 1);
string toolImage = "";
var p = tPrice;
DB.AddAToolToMysql(tName, tCategory, tDescription, userID, tCondition, p, toolImage);
}
}
catch
{
int userID = userIDs[rand.Next(userIDs.Count)];
string tName = toolNames[rand.Next(toolNames.Count)];
string tCondition = conditions[rand.Next(conditions.Count)];
int tCategory = toolCategoryIDs[rand.Next(toolCategoryIDs.Count)];
float tPrice = f1[rand.Next(f1.Length)] + f2[rand.Next(f2.Length)];
string tDescription = LoremIpsum(3,8,1,2,1);
string toolImage = "";
var p = tPrice;
DB.AddAToolToMysql(tName,tCategory,tDescription,userID,tCondition,p,toolImage);
throw;
}
}
static string LoremIpsum(int minWords, int maxWords, int minSentences, int maxSentences, int numParagraphs)
{
try
{
var words = new[] { "lorem", "ipsum", "dolor", "sit", "amet", "consectetuer", "adipiscing", "elit", "sed", "diam", "nonummy", "nibh", "euismod", "tincidunt", "ut", "laoreet", "dolore", "magna", "aliquam", "erat" };
var words = new[] { "lorem", "ipsum", "dolor", "sit", "amet", "consectetuer", "adipiscing", "elit", "sed", "diam", "nonummy", "nibh", "euismod", "tincidunt", "ut", "laoreet", "dolore", "magna", "aliquam", "erat" };
var rand = new Random();
int numSentences = rand.Next(maxSentences - minSentences)
+ minSentences + 1;
int numWords = rand.Next(maxWords - minWords) + minWords + 1;
var rand = new Random();
int numSentences = rand.Next(maxSentences - minSentences)
+ minSentences + 1;
int numWords = rand.Next(maxWords - minWords) + minWords + 1;
StringBuilder result = new StringBuilder();
StringBuilder result = new StringBuilder();
for (int p = 0; p < numParagraphs; p++)
{
//result.Append("<p>");
for (int s = 0; s < numSentences; s++)
for (int p = 0; p < numParagraphs; p++)
{
for (int w = 0; w < numWords; w++)
//result.Append("<p>");
for (int s = 0; s < numSentences; s++)
{
if (w > 0) { result.Append(" "); }
result.Append(words[rand.Next(words.Length)]);
for (int w = 0; w < numWords; w++)
{
if (w > 0) { result.Append(" "); }
result.Append(words[rand.Next(words.Length)]);
}
result.Append(". ");
}
result.Append(". ");
//result.Append("</p>");
}
//result.Append("</p>");
return result.ToString();
}
catch
{
throw;
}
}
#endregion
#region EVENTHANDLERS
private void BtnGenerate_Click(object sender, RoutedEventArgs e)
{
var result = MessageBox.Show($"Do you really want to generate and add to database {txtToolAmount.Text} random tools?", "Add random tools to database", MessageBoxButton.YesNo);
return result.ToString();
if (result == MessageBoxResult.Yes)
{
Generate();
lblInfo.Content = $"You have added {txtToolAmount.Text} random tools into database";
}
else
{
lblInfo.Content = $"You did nothing";
}
}
#endregion
}
}
......@@ -19,9 +19,13 @@ namespace iTool
/// </summary>
public partial class CommentWindow : Window
{
#region PROPERTIES
private List<Comment> comments;
private List<User> users;
private int? selectedComment = null;
#endregion
#region METHODS
public CommentWindow()
{
InitializeComponent();
......@@ -36,48 +40,28 @@ namespace iTool
IniComments();
}
private void TxtComment_KeyUp(object sender, KeyEventArgs e)
private void AddComment()
{
if (e.Key == Key.Enter)
try
{
AddComment();
string body = txtComment.Text;
string query;
if (selectedComment == null)
query = $"INSERT INTO comment (commentDate, commentText, userID, commentParentID, toolID) VALUES (CURRENT_TIMESTAMP,'{body}',{Active.UserID},null,{Active.ToolID});";
else
query = $"INSERT INTO comment (commentDate, commentText, userID, commentParentID, toolID) VALUES (CURRENT_TIMESTAMP,'{body}',{Active.UserID},{selectedComment},{Active.ToolID});";
DB.AddCommentToMysql(query);
lbxComments.Items.Clear();
comments = DB.GetCommentsFromMysql(Active.ToolID);
IniComments();
}
}
private void lbxComments_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
StackPanel selected = (StackPanel)lbxComments.SelectedItem;
if (selected != null)
catch
{
Label l = (Label)selected.Children[0];
string content = l.Content.ToString();
selectedComment = int.Parse(content.Split('#')[content.Split('#').Length - 1]);
}
lblCommentMessages.Content = $"Comment #{selectedComment} is selected, reply to it by typing a comment and pressing 'Enter'";
}
private void btnComment_Click(object sender, RoutedEventArgs e)
{
}
private void AddComment()
{
string body = txtComment.Text;
string query;
if(selectedComment == null)
query = $"INSERT INTO comment (commentDate, commentText, userID, commentParentID, toolID) VALUES (CURRENT_TIMESTAMP,'{body}',{Active.UserID},null,{Active.ToolID});";
else
query = $"INSERT INTO comment (commentDate, commentText, userID, commentParentID, toolID) VALUES (CURRENT_TIMESTAMP,'{body}',{Active.UserID},{selectedComment},{Active.ToolID});";
DB.AddCommentToMysql(query);
lbxComments.Items.Clear();
comments = DB.GetCommentsFromMysql(Active.ToolID);
IniComments();
throw;
}
}
private User GetUser(int userID)
......@@ -101,77 +85,110 @@ namespace iTool
private void IniComments()
{
foreach (Comment item in comments)
try
{
if (item.CommentParentID == null)
foreach (Comment item in comments)
{
//User u = DB.GetToolOwnerFromMysql(item.userID);
User u = GetUser(item.userID);
Label lbComment = new Label();
lbComment.Content = $"Comment #{item.CommentID}";
lbComment.FontSize = 12;
lbComment.FontWeight = FontWeights.Bold;
Label l = new Label();
l.Content = $"{u.FirstName} {u.LastName}, User ID: #{u.UserID} {item.DateTime.ToString()}";
l.FontSize = 12;
l.FontWeight = FontWeights.Bold;
TextBlock txbComment1 = new TextBlock();
txbComment1.Text = item.Text;
txbComment1.VerticalAlignment = VerticalAlignment.Top;
txbComment1.HorizontalAlignment = HorizontalAlignment.Left;
txbComment1.FontSize = 12;
txbComment1.TextWrapping = TextWrapping.Wrap;
StackPanel spComment = new StackPanel();
spComment.Margin = new Thickness(0, 10, 10, 10);
spComment.Orientation = Orientation.Vertical;
spComment.HorizontalAlignment = HorizontalAlignment.Left;
spComment.Children.Add(lbComment);
spComment.Children.Add(l);
spComment.Children.Add(txbComment1);
lbxComments.Items.Add(spComment);
}
foreach (Comment reply in comments)
{
if (reply.CommentParentID == item.CommentID)
if (item.CommentParentID == null)
{
//User us = DB.GetToolOwnerFromMysql(reply.userID);
User us = GetUser(reply.userID);
//User u = DB.GetToolOwnerFromMysql(item.userID);
User u = GetUser(item.userID);
Label lbComment = new Label();
lbComment.Content = $"Comment #{reply.CommentID}";
lbComment.Content = $"Comment #{item.CommentID}";
lbComment.FontSize = 12;
lbComment.FontWeight = FontWeights.Bold;
Label lb = new Label();
lb.Content = $"{us.FirstName} {us.LastName}, User ID: #{us.UserID} {item.DateTime.ToString()} In reply to comment #{item.CommentID}";
lb.FontSize = 12;
lb.FontWeight = FontWeights.Bold;
TextBlock reply1 = new TextBlock();
reply1.Text = reply.Text;
reply1.VerticalAlignment = VerticalAlignment.Top;
reply1.HorizontalAlignment = HorizontalAlignment.Left;
reply1.FontSize = 12;
reply1.TextWrapping = TextWrapping.Wrap;
StackPanel spReply = new StackPanel();
spReply.Margin = new Thickness(20, 10, 0, 0);
spReply.Orientation = Orientation.Vertical;
spReply.HorizontalAlignment = HorizontalAlignment.Left;
spReply.Children.Add(lbComment);
spReply.Children.Add(lb);
spReply.Children.Add(reply1);
lbxComments.Items.Add(spReply);
Label l = new Label();
l.Content = $"{u.FirstName} {u.LastName}, User ID: #{u.UserID} {item.DateTime.ToString()}";
l.FontSize = 12;
l.FontWeight = FontWeights.Bold;
TextBlock txbComment1 = new TextBlock();
txbComment1.Text = item.Text;
txbComment1.VerticalAlignment = VerticalAlignment.Top;
txbComment1.HorizontalAlignment = HorizontalAlignment.Left;
txbComment1.FontSize = 12;
txbComment1.TextWrapping = TextWrapping.Wrap;
StackPanel spComment = new StackPanel();
spComment.Margin = new Thickness(0, 10, 10, 10);
spComment.Orientation = Orientation.Vertical;
spComment.HorizontalAlignment = HorizontalAlignment.Left;
spComment.Children.Add(lbComment);
spComment.Children.Add(l);
spComment.Children.Add(txbComment1);
lbxComments.Items.Add(spComment);
}
foreach (Comment reply in comments)
{
if (reply.CommentParentID == item.CommentID)
{
//User us = DB.GetToolOwnerFromMysql(reply.userID);
User us = GetUser(reply.userID);
Label lbComment = new Label();
lbComment.Content = $"Comment #{reply.CommentID}";
lbComment.FontSize = 12;
lbComment.FontWeight = FontWeights.Bold;
Label lb = new Label();
lb.Content = $"{us.FirstName} {us.LastName}, User ID: #{us.UserID} {item.DateTime.ToString()} In reply to comment #{item.CommentID}";
lb.FontSize = 12;
lb.FontWeight = FontWeights.Bold;
TextBlock reply1 = new TextBlock();
reply1.Text = reply.Text;
reply1.VerticalAlignment = VerticalAlignment.Top;
reply1.HorizontalAlignment = HorizontalAlignment.Left;