a亚洲精品_精品国产91乱码一区二区三区_亚洲精品在线免费观看视频_欧美日韩亚洲国产综合_久久久久久久久久久成人_在线区

首頁 > 編程 > C# > 正文

c#數(shù)據(jù)綁定之?dāng)?shù)據(jù)轉(zhuǎn)化為信息的示例

2020-01-24 02:42:56
字體:
供稿:網(wǎng)友

目標(biāo)界面:

XAML代碼:

復(fù)制代碼 代碼如下:

<Grid Margin="2">
            <Grid.RowDefinitions>
                <RowDefinition  Height="Auto"/>
                <RowDefinition  Height="Auto"/>
                <RowDefinition  Height="Auto"/>
                <RowDefinition />
            </Grid.RowDefinitions>
            <GroupBox Header="Customer" Grid.Row="0" Padding="5">
                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition />
                        <RowDefinition />
                        <RowDefinition/>
                    </Grid.RowDefinitions>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="Auto"/>
                        <ColumnDefinition/>
                    </Grid.ColumnDefinitions>
                    <TextBlock Grid.Row="0" Grid.Column="0" Text="CustomerID" Margin="2" HorizontalAlignment="Right" VerticalAlignment="Center"/>
                    <TextBox Grid.Row="0" Grid.Column="1" Margin="2" Name="tbxCustomerID" Text="{Binding Path=CID}"/>
                    <TextBlock Grid.Row="1" Grid.Column="0" Text="CustomerName" Margin="2" HorizontalAlignment="Right" VerticalAlignment="Center"/>
                    <TextBox Grid.Row="1" Grid.Column="1" Margin="2" Name="tbxCustomerName" Text="{Binding Path=Name}"/>
                    <Button Grid.Row="2" Grid.Column="1" Content="Add New Customer" Margin="2" Name="btnAddCustomer" Padding="2" Click="btnAddCustomer_Click" />
                </Grid>
            </GroupBox>
            <GroupBox Header="Order" Grid.Row="1" Padding="5">
                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition />
                        <RowDefinition />
                        <RowDefinition />
                        <RowDefinition />
                        <RowDefinition />
                    </Grid.RowDefinitions>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="Auto"/>
                        <ColumnDefinition/>
                    </Grid.ColumnDefinitions>
                    <TextBlock Grid.Row="0" Grid.Column="0" Text="OrderID" Margin="2" HorizontalAlignment="Right" VerticalAlignment="Center"/>
                    <TextBox Grid.Row="0" Grid.Column="1" Margin="2" Name="tbxOrderID" Text="{Binding Path=OID}"/>
                    <TextBlock Grid.Row="1" Grid.Column="0" Text="OrderName" Margin="2" HorizontalAlignment="Right" VerticalAlignment="Center"/>
                    <TextBox Grid.Row="1" Grid.Column="1" Margin="2" Name="tbxOrderName" Text="{Binding Path=Customer}"/>
                    <TextBlock Grid.Row="2" Grid.Column="0" Text="Subtotal" Margin="2" HorizontalAlignment="Right" VerticalAlignment="Center"/>
                    <TextBox Grid.Row="2" Grid.Column="1" Margin="2" Name="tbxSubtotal" Text="{Binding Path=Subtotal}"/>
                    <TextBlock Grid.Row="3" Grid.Column="0" Text="TaxRate" Margin="2" HorizontalAlignment="Right" VerticalAlignment="Center"/>
                    <TextBox Grid.Row="3" Grid.Column="1" Margin="2" Name="tbxTaxRate" Text="{Binding Path=TaxRate}"/>
                    <Button Grid.Row="4" Grid.Column="1" Content="Add New Order" Margin="2" Name="btnAddOrder" Padding="2" Click="btnAddOrder_Click" />
                </Grid>
            </GroupBox>
            <ListView Name="lstDisplayCustomer" ItemsSource="{Binding}" Grid.Row="2"  Margin="2" MinHeight="150">
                <ListView.View>
                    <GridView>
                        <GridView.Columns>
                            <GridViewColumn  Header="CustomerID" DisplayMemberBinding="{Binding CID}"/>
                            <GridViewColumn Header="CustomerName" DisplayMemberBinding="{Binding Name}"/>
                            <GridViewColumn Header="Total" DisplayMemberBinding="{Binding OrderTotals}" />
                        </GridView.Columns>
                    </GridView>
                </ListView.View>
            </ListView>
            <ListView Name="lstDisplayOrder" ItemsSource="{Binding}" Grid.Row="3"  Margin="2" MinHeight="150">
                <ListView.View>
                    <GridView>
                        <GridView.Columns>
                            <GridViewColumn  Header="OrderID" DisplayMemberBinding="{Binding OID}"/>
                            <GridViewColumn Header="Customer" DisplayMemberBinding="{Binding Customer}"/>
                            <GridViewColumn Header="Subtotal" DisplayMemberBinding="{Binding Subtotal}"/>
                            <GridViewColumn Header="TaxRate"  DisplayMemberBinding="{Binding TaxRate}" />
                            <GridViewColumn Header="Total"    DisplayMemberBinding="{Binding Total}"/>
                        </GridView.Columns>
                    </GridView>
                </ListView.View>
            </ListView>
        </Grid>

C# 代碼:

復(fù)制代碼 代碼如下:

DataSet business = NewData();

        public MainWindow()
        {
            InitializeComponent();

        }

        private static DataSet NewData()
        {
            //-----build the parent table and add some data
            DataTable customer = new DataTable("Customer");
            customer.Columns.Add("CID", typeof(Int32));
            customer.Columns.Add("Name", typeof(string));
            //-------build the child table and add some data.
            DataTable orders = new DataTable("Order");
            orders.Columns.Add("OID", typeof(int));
            orders.Columns.Add("Customer", typeof(Int32));
            orders.Columns.Add("Subtotal", typeof(decimal));
            orders.Columns.Add("TaxRate", typeof(decimal));
            orders.Columns.Add("Total",typeof(decimal),"Subtotal*(1+TaxRate)");

            //-----Link the table within a Dataset.
            DataSet business = new DataSet();
            business.Tables.Add(customer);
            business.Tables.Add(orders);
            business.Relations.Add(customer.Columns["CID"],orders.Columns["Customer"]);
            customer.Columns.Add("OrderTotals" ,typeof(decimal),"Sum(Child.Total)");
            return business;
        }

        private void btnAddCustomer_Click(object sender, RoutedEventArgs e)
        {
           //Vist datatable customer.
            DataTable customer=business.Tables["Customer"];
            NewMember(customer);
            lstDisplayCustomer.DataContext = customer;
        }

        private DataTable NewMember(DataTable table)
        {
            DataRow newRow = table.NewRow();
            newRow["CID"] = tbxCustomerID.Text;
            newRow["Name"] = tbxCustomerName.Text;
            table.Rows.Add(newRow);
            return table;
        }

        private DataTable NewMemberOrder(DataTable table)
        {
            DataRow newRow = table.NewRow();
            newRow["OID"] = tbxOrderID.Text;
            newRow["Customer"] = tbxOrderName.Text;
            newRow["Subtotal"] = tbxSubtotal.Text;
            newRow["TaxRate"] = tbxTaxRate.Text;
            table.Rows.Add(newRow);
            return table;
        }

        private void btnAddOrder_Click(object sender, RoutedEventArgs e)
        {
            //Vist datatable order.
            DataTable order = business.Tables["Order"];
            NewMemberOrder(order);
            lstDisplayOrder.DataContext = order;
        }

發(fā)表評論 共有條評論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 亚洲欧美在线一区二区 | 美女张开腿视频网站免费 | 女国产精品视频一区二区三区 | 欧美日韩国产精品一区 | 天堂在线视频精品 | 久久国产精品久久久久久 | 九九色九九 | 亚洲成人精品在线 | 精品国产乱码久久久久久1区2区 | av手机在线播放 | 欧美人成在线观看 | 国产精品亚洲综合 | 男女免费在线观看视频 | 羞羞视频在线观免费观看 | 亚洲高清一区二区三区 | 国产精品成人一区二区三区夜夜夜 | 成人免费视频网站 | 欧美精品一区二区在线观看 | 国产一级大片 | 蜜桃av网址 | 欧美日韩中文 | 久久91| 欧美午夜精品一区二区三区 | 欧美xxxx片| 狠狠色噜噜狠狠狠8888米奇 | 久久精品国产v日韩v亚洲 | 欧美在线综合 | 日本成人一区二区三区 | 国产精品一区二区不卡视频 | 欧美日韩在线免费观看 | 亚洲精品久久 | 久久一级| 国产精品精品视频 | 毛片在线视频 | 日韩精品在线免费观看视频 | 色又黄又爽网站www久久 | 中文字幕视频在线观看 | 亚洲精品一区久久久久久 | 久久夜夜 | 国产午夜精品一区二区 | 久久精品国产清自在天天线 |