Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
bsmlo authored Aug 14, 2018
1 parent dfc4828 commit caf5990
Show file tree
Hide file tree
Showing 9 changed files with 155 additions and 44 deletions.
19 changes: 15 additions & 4 deletions Contracts.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:dbCon2"
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
mc:Ignorable="d"
d:DesignHeight="722" d:DesignWidth="1422"
Title="Contracts" Width="Auto" Height="Auto">
Expand All @@ -27,11 +28,12 @@
<DataGridTextColumn Header="Id" IsReadOnly="True" Binding="{Binding Id, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/>
<DataGridTextColumn Header="Status" Binding="{Binding Status, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/>
<DataGridTextColumn Header="Worker" Binding="{Binding Worker, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/>
<DataGridTemplateColumn Header="Date">
<DataGridTemplateColumn IsReadOnly="True" Header="Date">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate DataType="{x:Type TextBlock}">
<DatePicker x:Name="DataPicker1" SelectedDate="{Binding Path=Date, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" BorderThickness="0" CalendarClosed="DatePicker1_CalendarClosed" FirstDayOfWeek="Monday" LostFocus="DataPicker1_LostFocus"/>
</DataTemplate>
<DatePicker x:Name="DataPicker1" SelectedDate="{Binding Path=Date, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" BorderThickness="0" FirstDayOfWeek="Monday" CalendarClosed="DataPicker1_CalendarClosed">
</DatePicker>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTextColumn Header="Client" Binding="{Binding Client, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/>
Expand All @@ -40,11 +42,20 @@
<DataGridTemplateColumn Header="Expiry Date">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<DatePicker x:Name="DataPicker2" SelectedDate="{Binding ExpiryDate, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" BorderThickness="0" CalendarClosed="DataPicker1_CalendarClosed" FirstDayOfWeek="Monday" LostFocus="DataPicker2_LostFocus"/>
<DatePicker x:Name="DataPicker2" SelectedDate="{Binding ExpiryDate, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" BorderThickness="0" FirstDayOfWeek="Monday" CalendarClosed="DataPicker2_CalendarClosed_1"/>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTextColumn Header="Other" Binding="{Binding Other, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/>
<DataGridTemplateColumn>
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Button x:Name="DeleteRowBUtton" Background="#7F1C1C1C" Click="DeleteRowBUtton_Click">
<materialDesign:PackIcon Kind="Delete" VerticalAlignment="Center" Width="30" Height="30" HorizontalAlignment="Center"/>
</Button>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
</DataGrid.Columns>
</DataGrid>
</Grid>
Expand Down
74 changes: 55 additions & 19 deletions Contracts.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public partial class Contracts : Page
//Number of selected row-for seve data
string idOfSelectedRow = "";
int numberOfSelectedRow;
string actualSelectedDate = "";

public Contracts()
{
Expand Down Expand Up @@ -74,6 +75,7 @@ private void ContractsDataGrind_SelectionChanged(object sender, SelectionChanged
//check datagrind selection
private void CheckSelection()
{

try
{
numberOfSelectedRow = ContractsDataGrind.SelectedIndex;
Expand All @@ -94,22 +96,29 @@ private void CheckSelection()
private void SaveUpdate()
{
DataAccessContracts dataAccessContracts = new DataAccessContracts();

dataAccessContracts.AddNewContract(
idOfSelectedRow,
Items[numberOfSelectedRow].Status,
Items[numberOfSelectedRow].Worker,
Convert.ToDateTime(Items[numberOfSelectedRow].Date).ToString("yyyy-MM-dd"),
Items[numberOfSelectedRow].Client,
Items[numberOfSelectedRow].InvoiceStatus,
Convert.ToDateTime(Items[numberOfSelectedRow].ExpiryDate).ToString("yyyy-MM-dd"),
Items[numberOfSelectedRow].Other);

try
{
dataAccessContracts.AddNewContract(
idOfSelectedRow,
Items[numberOfSelectedRow].Status,
Items[numberOfSelectedRow].Worker,
Convert.ToDateTime(Items[numberOfSelectedRow].Date).ToString("yyyy-MM-dd"),
Items[numberOfSelectedRow].Client,
Items[numberOfSelectedRow].Contact,
Items[numberOfSelectedRow].InvoiceStatus,
Convert.ToDateTime(Items[numberOfSelectedRow].ExpiryDate).ToString("yyyy-MM-dd"),
Items[numberOfSelectedRow].Other);
}
catch
{
MessageBox.Show("Update Error");
}
RefreshContractItems();
}


private void DatePicker1_CalendarClosed(object sender, RoutedEventArgs e)
//Save date when close calendar
private void DataPicker2_CalendarClosed_1(object sender, RoutedEventArgs e)
{
CheckSelection();
if (idOfSelectedRow != "")
Expand All @@ -118,6 +127,7 @@ private void DatePicker1_CalendarClosed(object sender, RoutedEventArgs e)
}
}

//Save date when close calendar
private void DataPicker1_CalendarClosed(object sender, RoutedEventArgs e)
{
CheckSelection();
Expand All @@ -126,23 +136,49 @@ private void DataPicker1_CalendarClosed(object sender, RoutedEventArgs e)
SaveUpdate();
}
}

private void DataPicker1_LostFocus(object sender, RoutedEventArgs e)
/*
//Save date when keyboard input data
private void DataPicker1_GotFocus(object sender, RoutedEventArgs e)
{
CheckSelection();
if (idOfSelectedRow != "")
try
{
SaveUpdate();
actualSelectedDate = Convert.ToDateTime(Items[numberOfSelectedRow].Date).ToString("yyyy-MM-dd");
}
catch
{
actualSelectedDate = "";
}
}
//Save date when keyboard input data
private void DataPicker1_LostFocus(object sender, RoutedEventArgs e)
{
try
{
if (actualSelectedDate != "" && Convert.ToDateTime(Items[numberOfSelectedRow].Date).ToString("yyyy-MM-dd") != actualSelectedDate)
{
SaveUpdate();
}
}
catch
{
actualSelectedDate = "";
}
}
*/

private void DataPicker2_LostFocus(object sender, RoutedEventArgs e)
// Delete selected row
private void DeleteRowBUtton_Click(object sender, RoutedEventArgs e)
{
CheckSelection();
if (idOfSelectedRow != "")
if(idOfSelectedRow != null && idOfSelectedRow !="")
{
SaveUpdate();
DeleteContract dataAccessContracts = new DeleteContract();
dataAccessContracts.RemoveContract(idOfSelectedRow);
}

RefreshContractItems();
}

}
}
15 changes: 8 additions & 7 deletions DataAccessContracts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,10 @@ public List<ContractItem> GetContracts()
Status = reader["status"].ToString(),
Worker = reader["worker"].ToString(),
Date = reader["date"].ToString().Substring(0, reader["date"].ToString().IndexOf(" ")),
Contact = reader["contact"].ToString(),
Client = reader["client"].ToString(),
InvoiceStatus = reader["invoice_status"].ToString(),
ExpiryDate = reader["expiry_date"].ToString().Substring(0, reader["date"].ToString().IndexOf(" ")),
ExpiryDate = reader["expiry_date"].ToString().Substring(0, reader["expiry_date"].ToString().IndexOf(" ")),
Other = reader["other"].ToString()
};

Expand All @@ -60,9 +61,8 @@ public List<ContractItem> GetContracts()
return null;
}
}


public void AddNewContract(string id, string status, string worker, string date, string client, string invStat, string expiDate, string other)

public void AddNewContract(string id, string status, string worker, string date, string client, string contact, string invStat, string expiDate, string other)
{
try
{
Expand All @@ -79,6 +79,7 @@ public void AddNewContract(string id, string status, string worker, string date,
$"`worker` = '{worker}'," +
$"`date` = '{date}', " +
$"`client` = '{client}'," +
$"`contact` = '{contact}'," +
$"`invoice_status` = '{invStat}'," +
$"`expiry_date` = '{expiDate}'," +
$"`other` = '{other}'" +
Expand All @@ -98,9 +99,9 @@ public void AddNewContract(string id, string status, string worker, string date,
else if (id == "" && id != null)
{
command.CommandText = $"INSERT INTO `contracts` " +
$"(`status`, `worker`, `date`, `client`, `invoice_status`, `expiry_date`, `other`)" +
$"(`status`, `worker`, `date`, `client`, `contact`, `invoice_status`, `expiry_date`, `other`)" +
$"VALUES" +
$"('{status}', '{worker}', '{date}', '{client}','{invStat}', '{expiDate}', '{other}');";
$"('{status}', '{worker}', '{date}', '{client}', '{contact}', '{invStat}', '{expiDate}', '{other}');";

try
{
Expand All @@ -122,7 +123,7 @@ public void AddNewContract(string id, string status, string worker, string date,
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
MessageBox.Show("Can't Connect To DB!");

}
}
Expand Down
41 changes: 41 additions & 0 deletions DeleteContract.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using MySql.Data.MySqlClient;
using System.Windows;

namespace dbCon2
{
class DeleteContract
{
public void RemoveContract(string id)
{
try
{
using (MySqlConnection connection = new MySqlConnection(ConnectionSettings.ConectionVal()))
{
MySqlCommand command = connection.CreateCommand();

command.CommandText = $"DELETE FROM `baza_lektorow`.`contracts` WHERE `id`='{id}';";

try
{
connection.Open();
MySqlDataReader reader = command.ExecuteReader();
}
catch
{
MessageBox.Show("Can't Connect To DB!");
}
}
}
catch (Exception ex)
{
MessageBox.Show("Can't Connect To DB!");

}
}
}
}
1 change: 0 additions & 1 deletion LoginWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ private void LogInButton_Click(object sender, RoutedEventArgs e)

if (message == "OK")
{
//User LoggedIn = new User();
LoggedIn.Userset(accessUserDB.Name, accessUserDB.Rank, accessUserDB.ID, false);

message = "";
Expand Down
32 changes: 24 additions & 8 deletions MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -105,20 +105,36 @@
</Button>
</Grid>
<Grid Height="100" VerticalAlignment="Top" HorizontalAlignment="Left">
<Button x:Name="ButtonSearch" Height="100" Width="300" Background="#66673AB7" Content="Search" Click="ButtonSearch_Click"/>
<materialDesign:PackIcon Kind="DatabaseSearch" Foreground="#FF3A386C" VerticalAlignment="Center" Margin="21,33,0,37" Width="30" Height="30"/>
<Button x:Name="ButtonSearch" Height="100" Width="300" Background="#66673AB7" Click="ButtonSearch_Click">
<Grid>
<materialDesign:PackIcon Kind="DatabaseSearch" Foreground="#FF3A386C" VerticalAlignment="Center" Margin="0,0,228,0" Width="30" Height="30" />
<Label Content="Search" Margin="0" HorizontalAlignment="Center" VerticalAlignment="Center"/>
</Grid>
</Button>
</Grid>
<Grid Height="100" VerticalAlignment="Top" HorizontalAlignment="Left">
<Button x:Name="ButtonAddRemove" Height="100" Width="300" Content="Add Co-Worker" Background="#66673AB7" Click="ButtonAddRemove_Click"/>
<materialDesign:PackIcon Kind="Star" Foreground="#FF3A386C" VerticalAlignment="Center" Margin="21,34,0,36" Width="30" Height="30" />
<Button x:Name="ButtonAddRemove" Height="100" Width="300" Background="#66673AB7" Click="ButtonAddRemove_Click">
<Grid>
<materialDesign:PackIcon Kind="Star" Foreground="#FF3A386C" VerticalAlignment="Center" Margin="0,0,228,0" Width="30" Height="30" />
<Label Content="Add Co-Worker" Margin="0" HorizontalAlignment="Center" VerticalAlignment="Center" />
</Grid>
</Button>
</Grid>
<Grid Height="100" VerticalAlignment="Top" HorizontalAlignment="Left">
<Button x:Name="ButtonContracts" Height="100" Width="300" Content="Contracts Menager" Background="#66673AB7" Click="ButtonContracts_Click"/>
<materialDesign:PackIcon Kind="Calendar" Foreground="#FF3A386C" VerticalAlignment="Center" Margin="21,35,0,35" Width="30" Height="30" />
<Button x:Name="ButtonContracts" Height="100" Width="300" Background="#66673AB7" Click="ButtonContracts_Click">
<Grid>
<materialDesign:PackIcon Kind="Calendar" Foreground="#FF3A386C" VerticalAlignment="Center" Margin="0,0,228,0" Width="30" Height="30" />
<Label Content="Contracts Menager" Margin="0" HorizontalAlignment="Center" VerticalAlignment="Center" />
</Grid>
</Button>
</Grid>
<Grid Height="100" VerticalAlignment="Top" HorizontalAlignment="Left">
<Button x:Name="ButtonThingsToDo" Height="100" Width="300" Content="Things To Do" Background="#66673AB7" Click="ButtonThingsToDo_Click"/>
<materialDesign:PackIcon Kind="FormatListChecks" Foreground="#FF3A386C" VerticalAlignment="Center" Margin="21,33,0,37" Width="30" Height="30" />
<Button x:Name="ButtonThingsToDo" Height="100" Width="300" Background="#66673AB7" Click="ButtonThingsToDo_Click">
<Grid>
<materialDesign:PackIcon Kind="FormatListChecks" Foreground="#FF3A386C" VerticalAlignment="Center" Margin="0,0,228,0" Width="30" Height="30" />
<Label Content="Things To Do" Margin="0" HorizontalAlignment="Center" VerticalAlignment="Center" />
</Grid>
</Button>
</Grid>
</StackPanel>

Expand Down
11 changes: 6 additions & 5 deletions UserAccount.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,16 @@
<RadioButton Content="Create Admin Account" HorizontalAlignment="Center" Margin="32,206,32,0" VerticalAlignment="Top"/>
<Label Content="Add User" Margin="52,10,0,0" VerticalAlignment="Top" DataContextChanged="NameLabel_DataContextChanged" FontFamily="Global Sans Serif" FontSize="20" HorizontalAlignment="Left" Width="100"/>
</Grid>
<Grid x:Name="ChangePassGrind" Height="340" Margin="75,134,0,0" VerticalAlignment="Top" HorizontalAlignment="Left" Width="204">
<Button Content="Change" Margin="0,297,0,0" VerticalAlignment="Top" HorizontalAlignment="Left" Width="204"/>
<PasswordBox Height="24" Margin="10,140,0,0" VerticalAlignment="Top" HorizontalAlignment="Left" Width="177"/>
<PasswordBox Height="22" Margin="10,192,0,0" VerticalAlignment="Top" HorizontalAlignment="Left" Width="177"/>
<Grid x:Name="ChangePassGrind" Height="365" Margin="75,134,0,0" VerticalAlignment="Top" HorizontalAlignment="Left" Width="204">
<Button x:Name="ChangePasswordButton" Content="Change" Margin="0,323,0,0" VerticalAlignment="Top" HorizontalAlignment="Left" Width="204" Click="ChangePasswordButton_Click"/>
<PasswordBox Height="24" Margin="10,140,0,0" VerticalAlignment="Top" HorizontalAlignment="Left" Width="184"/>
<PasswordBox Height="22" Margin="10,192,0,0" VerticalAlignment="Top" HorizontalAlignment="Left" Width="184"/>
<Label Content="Change Password" Margin="10,10,0,0" VerticalAlignment="Top" DataContextChanged="NameLabel_DataContextChanged" FontFamily="Global Sans Serif" FontSize="20" HorizontalAlignment="Left" Width="184"/>
<Label Content="New Password" Margin="10,164,0,0" VerticalAlignment="Top" DataContextChanged="NameLabel_DataContextChanged" FontFamily="Global Sans Serif" FontSize="10" HorizontalAlignment="Left" Width="177"/>
<Label Content="Confirm Password" Margin="10,214,0,0" VerticalAlignment="Top" DataContextChanged="NameLabel_DataContextChanged" FontFamily="Global Sans Serif" FontSize="10" HorizontalAlignment="Left" Width="177"/>
<PasswordBox Height="24" Margin="10,62,0,0" VerticalAlignment="Top" HorizontalAlignment="Left" Width="177"/>
<PasswordBox Height="24" Margin="10,62,0,0" VerticalAlignment="Top" HorizontalAlignment="Left" Width="184"/>
<Label Content="Actual Password" Margin="10,86,0,0" VerticalAlignment="Top" DataContextChanged="NameLabel_DataContextChanged" FontFamily="Global Sans Serif" FontSize="10" HorizontalAlignment="Left" Width="177"/>
<Label x:Name="ChangeingPasswordInfo" Content="" HorizontalAlignment="Left" Margin="10,247,0,0" VerticalAlignment="Top" Width="184" Height="48"/>
</Grid>
</Grid>
</Page>
5 changes: 5 additions & 0 deletions UserAccount.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,10 @@ private void NameLabel_DataContextChanged(object sender, DependencyPropertyChang
{

}

private void ChangePasswordButton_Click(object sender, RoutedEventArgs e)
{

}
}
}
1 change: 1 addition & 0 deletions dbCon2.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@
<Compile Include="DataAccessToDo.cs" />
<Compile Include="DBRecordEdit.cs" />
<Compile Include="AccessUserDB.cs" />
<Compile Include="DeleteContract.cs" />
<Compile Include="UserAccount.xaml.cs">
<DependentUpon>UserAccount.xaml</DependentUpon>
</Compile>
Expand Down

0 comments on commit caf5990

Please sign in to comment.