Wednesday, December 24, 2014

WPF ListView Data Display

In DAL write code like this:
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
public List<SaleInfo> LoadAllSaleList()
        {
            dataContext = new JSMSEntities();
            List<SaleInfo> saleList = new List<SaleInfo>();

            foreach (var p in (from c in dataContext.tbl_Sale 
                               select new 
                               { 
                                   c.SaleDateTime, 
                                   c.InvoiceNumber, 
                                   c.tbl_Customer.CustomerName, c.TotalAmount, 
                                   c.TotalPay, c.TotalDue 
                               }).Distinct())
            {
                SaleInfo allsaleObj = new SaleInfo();

                allsaleObj.SaleDateTime = (DateTime)p.SaleDateTime;
                allsaleObj.InvoiceNumber = p.InvoiceNumber;
                allsaleObj.CustomerName = p.CustomerName;
                allsaleObj.TotalAmount = (int)p.TotalAmount;
                allsaleObj.TotalPay = (int)p.TotalPay;
                allsaleObj.TotalDue = (int)p.TotalDue;

                saleList.Add(allsaleObj);
            }

            return saleList;
        }

In BLL write code like this :

1
2
3
4
public List<SaleInfo> LoadAllSaleList()
        {
            return _saleGetwayObj.LoadAllSaleList();
        }


In XAML add ListView like this:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
        <ListView 
 HorizontalAlignment="Left" 
 Height="509" 
 Margin="10,52,0,0" 
 VerticalAlignment="Top" 
 Width="624"
 x:Name="SaleListView">
            <ListView.View>
                <GridView AllowsColumnReorder="True">
                    <GridViewColumn DisplayMemberBinding="{Binding Id}" Header="" Width="0"/>
                    <GridViewColumn DisplayMemberBinding="{Binding SaleDateTime, StringFormat='yyyy-MM-dd'}" Header="Date" Width="120"/>
                    <GridViewColumn DisplayMemberBinding="{Binding InvoiceNumber}" Header="Invoice" Width="120"/>
                    <GridViewColumn DisplayMemberBinding="{Binding CustomerName}" Header="Name" Width="100"/>
                    <GridViewColumn DisplayMemberBinding="{Binding TotalAmount}" Header="Price" Width="90"/>
                    <GridViewColumn DisplayMemberBinding="{Binding TotalPay}" Header="Total Pay" Width="100"/>
                    <GridViewColumn DisplayMemberBinding="{Binding TotalDue}" Header="Total Due" Width="90"/>
                </GridView>
            </ListView.View>
        </ListView>


In UI add reference of BLL and ENTITY, then write code like this:

1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using BLL;
using ENTITY;

namespace JSMS.UI
{
    /// <summary>
    /// Interaction logic for SaleReportUI.xaml
    /// </summary>
    public partial class SaleReportUI : Window
    {
        List<SaleInfo> _allSaleListObj = new List<SaleInfo>();
        SaleManager _saleManagerObj = new SaleManager();
        public SaleReportUI()
        {
            InitializeComponent();

            LoadAllSaleList();
        }

        private void LoadAllSaleList()
        {
            _allSaleListObj = new List<SaleInfo>();
            _allSaleListObj = _saleManagerObj.LoadAllSaleList();

            SaleListView.Items.Clear();

            if (_allSaleListObj.Count > 0)
            {
                foreach (var item in _allSaleListObj)
                {
                    SaleListView.Items.Add(item);
                }
            }

        }
    }
}


No comments:

Post a Comment