Skip to content

Commit

Permalink
updated manage customer
Browse files Browse the repository at this point in the history
  • Loading branch information
thanhngan22 committed Jan 4, 2024
1 parent 4d70989 commit 83d75d7
Show file tree
Hide file tree
Showing 17 changed files with 989 additions and 52 deletions.
5 changes: 5 additions & 0 deletions BookShop2023/Source/BookShop2023/BUS/CustomerBUS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 25,11 @@ public List<Customer> loadAll()
return _customerDAO.loadAll();
}

public List<CustomerDataGrid> loadAllCustomerDataGrid()
{
return _customerDAO.loadAllCustomerDataGrid();
}

public Dictionary<int, Customer> CustomerDictionary ()
{
List<Customer> list = loadAll();
Expand Down
39 changes: 39 additions & 0 deletions BookShop2023/Source/BookShop2023/DAO/CustomerDAO.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 43,45 @@ public List<Customer> loadAll()
return _customerList;
}

public List<CustomerDataGrid> loadAllCustomerDataGrid()
{
List<CustomerDataGrid> _customerList = new List<CustomerDataGrid>();

var sql = "select cust.ID, cust.Name, cust.Address, cust.PhoneNumber, count(distinct o.ID) as TotalOrders, SUM(ISNULL(od.Total, 0)) AS TotalCost, count(distinct od.ProductID) as TotalProducts "
"FROM Customer AS cust\r\n"
"LEFT JOIN Orders AS o ON cust.ID = o.CustomerID\r\n"
"LEFT JOIN OrderDetail AS od ON od.OrderID = o.ID "
"group by cust.ID, cust.Name, cust.Address, cust.PhoneNumber "
"order by TotalCost DESC";

var command = new SqlCommand(sql, DB.Instance.Connection);

var reader = command.ExecuteReader();
int rank = 0;

while (reader.Read())
{
rank ;
CustomerDataGrid customer = new CustomerDataGrid()
{
Rank = rank,
ID = (int)reader["ID"],
Name = (string)reader["Name"],
Address = (string)reader["Address"],
PhoneNumber = (string)reader["PhoneNumber"],
TotalCost = Convert.ToInt32(reader["TotalCost"]),
TotalOrders = (int)reader["TotalOrders"],
TotalProducts = (int)reader["TotalProducts"]
};

_customerList.Add(customer);
}


reader.Close();
return _customerList;
}

public void InsertCustomer(Customer customer)
{
var sql = "";
Expand Down
6 changes: 4 additions & 2 deletions BookShop2023/Source/BookShop2023/DAO/StatisticsDAO.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 14,9 @@ public string getTotalRevenueUntilDate(DateTime src)
{
string sqlFormattedDate = src.ToString("yyyy-MM-dd");

var sql = "select convert(varchar,cast(SUM(do.Quantity * p.SellingPrice) as int), 1) as Revenue from OrderDetail do join Product p on do.ProductID = p.ID join Orders o on do.OrderID = o.ID where CreatedAt <= @SelectedDate;";
var sql = "select convert(varchar,cast(SUM(Total) as int), 1) as Revenue "
"from OrderDetail od join Orders o on od.OrderID = o.ID "
"where CreatedAt <= @SelectedDate ;";
var sqlParameter = new SqlParameter();
sqlParameter.ParameterName = "@SelectedDate";
sqlParameter.Value = sqlFormattedDate;
Expand All @@ -28,7 30,7 @@ public string getTotalRevenueUntilDate(DateTime src)
if (reader.Read())
{
if (reader["Revenue"].GetType() != typeof(DBNull))
result = (string)reader["Revenue"];
result = Convert.ToString (reader["Revenue"]);
}
reader.Close();
return result.ToString();
Expand Down
8 changes: 8 additions & 0 deletions BookShop2023/Source/BookShop2023/DTO/Customer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 13,12 @@ public class Customer
public string Address { get; set; }
public string PhoneNumber { get; set; }
}

public class CustomerDataGrid : Customer
{
public int Rank { get; set; }
public int TotalOrders { get; set; }
public int TotalCost { get; set; }
public int TotalProducts { get; set; }
}
}
33 changes: 23 additions & 10 deletions BookShop2023/Source/BookShop2023/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,4 1,5 @@
using Microsoft.IdentityModel.Tokens;
using BookShop2023.Views;
using Microsoft.IdentityModel.Tokens;
using ProjectMyShop.BUS;
using ProjectMyShop.Config;
using ProjectMyShop.Views;
Expand Down Expand Up @@ -35,6 36,7 @@ public MainWindow()
ManageOrder _manageOrderPage;
Statistics _statisticsPage;
ManageCategory _manageCategory;
ManageCustomer _manageCustomer;
Configuration _configPage;
Login login;
Button[] buttons;
Expand Down Expand Up @@ -91,13 93,11 @@ private void Window_Loaded(object sender, RoutedEventArgs e)
#region Mở dashboard cho admin: có cả thống kê chi tiêu, quản lý ...
private void openDashBoardAdmin()
{
dashboard = new Dashboard();
_manageOrderPage = new ManageOrder();
_manageCategory = new ManageCategory();


dashboardText.Text = greeting username;

Button[] buttons1 = new Button[] { dashboardButton, categoriesButton, productButton, orderButton, statButton, configButton };
Button[] buttons1 = new Button[] { dashboardButton, categoriesButton, productButton, orderButton, statButton, configButton, custButton, voucherButton };
buttons = buttons1;
if (AppConfig.GetValue(AppConfig.LastWindow) == "0")
{
Expand Down Expand Up @@ -131,6 131,12 @@ private void openDashBoardAdmin()
_manageProductPage = new ManageProduct();
pageNavigation.NavigationService.Navigate(_manageProductPage);
}
else if (AppConfig.GetValue(AppConfig.LastWindow) == "ManageCustomer")
{
changeButtonColor(custButton);
_manageCustomer = new ManageCustomer();
pageNavigation.NavigationService.Navigate(_manageCustomer);
}

}

Expand All @@ -141,17 147,15 @@ private void openDashBoardAdmin()
private void openDashBoardStaff()
{

dashboard = new Dashboard();
_manageOrderPage = new ManageOrder();
_manageCategory = new ManageCategory();


dashboardText.Text = greeting username;


// hide statistics
statButton.Visibility = Visibility.Collapsed;

Button[] buttons1 = new Button[] { dashboardButton, categoriesButton, productButton, orderButton, configButton };
Button[] buttons1 = new Button[] { dashboardButton, categoriesButton, productButton, orderButton, configButton, custButton, voucherButton };
buttons = buttons1;
if (AppConfig.GetValue(AppConfig.LastWindow) == "0")
{
Expand Down Expand Up @@ -180,6 184,12 @@ private void openDashBoardStaff()
_manageProductPage = new ManageProduct();
pageNavigation.NavigationService.Navigate(_manageProductPage);
}
else if (AppConfig.GetValue(AppConfig.LastWindow) == "ManageCustomer")
{
changeButtonColor(custButton);
_manageCustomer = new ManageCustomer();
pageNavigation.NavigationService.Navigate(_manageCustomer);
}

}

Expand Down Expand Up @@ -213,6 223,7 @@ private void productButton_Click(object sender, RoutedEventArgs e)
private void orderButton_Click(object sender, RoutedEventArgs e)
{
changeButtonColor(orderButton);
_manageOrderPage = new ManageOrder();
pageNavigation.NavigationService.Navigate(_manageOrderPage);
}

Expand All @@ -233,6 244,7 @@ private void configButton_Click(object sender, RoutedEventArgs e)
private void categoriesButton_Click(object sender, RoutedEventArgs e)
{
changeButtonColor(categoriesButton);
_manageCategory = new ManageCategory();
pageNavigation.NavigationService.Navigate(_manageCategory);
}
#endregion
Expand All @@ -245,7 257,8 @@ private void pageNavigation_Navigated(object sender, NavigationEventArgs e)
private void custButton_Click(object sender, RoutedEventArgs e)
{
changeButtonColor(custButton);
//...
_manageCustomer = new ManageCustomer();
pageNavigation.NavigationService.Navigate(_manageCustomer);
}

private void voucherButton_Click(object sender, RoutedEventArgs e)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 13,7 @@ public class OrderDataGridItemSource
public string CustomerAddress { get; set; }
public DateOnly CreatedAt { get; set; }
public string Status { get; set; }

public int FinalTotal { get; set; }
}
}
104 changes: 104 additions & 0 deletions BookShop2023/Source/BookShop2023/Views/AddCustomer.xaml
Original file line number Diff line number Diff line change
@@ -0,0 1,104 @@
<Window x:Class="BookShop2023.Views.AddCustomer"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
xmlns:local1="clr-namespace:ProjectMyShop.Converter"
WindowStartupLocation="CenterScreen"
Loaded="Window_Loaded"

xmlns:local="clr-namespace:BookShop2023.Views"
mc:Ignorable="d"
Title="Thêm khách hàng mới" Height="400" Width="600">
<Window.Resources>
<local1:CurrencyConverter x:Key="currencyConverter" />
</Window.Resources>


<materialDesign:Card Background="White" UniformCornerRadius="10" materialDesign:ShadowAssist.ShadowEdges="All" Padding="20,10,20,20">
<DockPanel LastChildFill="True">

<StackPanel Orientation="Vertical" DockPanel.Dock="Top">
<StackPanel Orientation="Horizontal">
<TextBlock Text="Khách hàng #" FontWeight="DemiBold" Foreground="Black" FontSize="16"/>
<TextBlock x:Name="OrderIDText" Text="{Binding ID}" FontWeight="DemiBold" Foreground="Black" FontSize="16"/>
</StackPanel>

</StackPanel>
<Grid Margin="0,20,0,0">
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="10"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<materialDesign:Card Background="White" UniformCornerRadius="10" materialDesign:ShadowAssist.ShadowEdges="All" Grid.Row="0"
Padding="10" BorderBrush="Gray" Margin="5">
<DockPanel LastChildFill="True">

<StackPanel Orientation="Vertical" DockPanel.Dock="Top">
<TextBlock Text="Thông tin khách hàng" FontWeight="DemiBold" Foreground="Black" FontSize="20" Margin="5,0,0,20" HorizontalAlignment="Center"/>
<DockPanel x:Name="CustomerInfo" LastChildFill="True">
<StackPanel Width="Auto" Orientation="Vertical" DockPanel.Dock="Left">
<StackPanel Width="Auto" Orientation="Horizontal" HorizontalAlignment="Left" Margin="0 0 0 10" >
<Label Content="Họ tên: " FontWeight="SemiBold" Width="60" FontSize="16" Margin="0 0 20 0"/>
<TextBox x:Name="CustomerNameText" Text="{Binding Name}" TextWrapping="Wrap" Width="400" FontSize="16"/>
</StackPanel>
<StackPanel Width="Auto" Orientation="Horizontal" Margin="0 0 0 10" >
<Label Content="Địa chỉ: " FontWeight="SemiBold" Width="60" FontSize="16" Margin="0 0 20 0" />
<TextBox x:Name="CustomerAddressText" Text="{Binding Address}" TextWrapping="Wrap" Width="400" FontSize="16"/>
</StackPanel>
<StackPanel Width="Auto" Orientation="Horizontal" HorizontalAlignment="Left" Margin="0 0 0 10">
<Label Content="SĐT: " FontWeight="SemiBold" Width="60" FontSize="16" Margin="0 0 20 0"/>
<TextBox x:Name="CustomerPhoneNumberText" Text="{Binding PhoneNumber}" TextWrapping="Wrap" Width="400" FontSize="16"/>
</StackPanel>
</StackPanel>




</DockPanel>
</StackPanel>
</DockPanel>
</materialDesign:Card>

<StackPanel Orientation="Horizontal" Grid.Row="3" HorizontalAlignment="Right" Margin="0,5,0,0">
<Button Name="SaveButton" Click="SaveButton_Click"
materialDesign:ButtonAssist.CornerRadius="5"
Background="LightGreen"
Foreground="Black"
materialDesign:ShadowAssist.ShadowEdges="All"
BorderBrush="DeepPink"
>
<Button.Content>
<StackPanel Orientation="Horizontal">
<materialDesign:PackIcon Kind="ContentSave"/>
<TextBlock Margin="5,-2" Text="Save"></TextBlock>
</StackPanel>
</Button.Content>
</Button>

<Button Name="ReturnButton" Click="ReturnButton_Click"
materialDesign:ButtonAssist.CornerRadius="5"
Background="LightGray"
BorderBrush="LightGray"
materialDesign:ShadowAssist.ShadowEdges="All"
Foreground="Gray"
Margin="5,0">
<Button.Content>
<StackPanel Orientation="Horizontal">
<materialDesign:PackIcon Kind="KeyboardReturn"/>
<TextBlock Margin="5,-2" Text="Cancel"></TextBlock>
</StackPanel>
</Button.Content>
</Button>
</StackPanel>
</Grid>
</DockPanel>
</materialDesign:Card>


</Window>
Loading

0 comments on commit 83d75d7

Please sign in to comment.