<UserControl xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:c="clr-namespace:System.Collections;assembly=mscorlib"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:cm="http://www.caliburnproject.org"
    xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"
    x:Class="SimpleCRM.ViewModels.OrderFormView" Height="500" Width="800">

    <UserControl.Resources>
        <Style x:Key="CustomerComboBoxFieldStyle" TargetType="{x:Type telerik:DataFormDataField}">
            <Setter Property="ContentTemplate">
                <Setter.Value>
                    <DataTemplate>
                        <telerik:RadComboBox/>
                    </DataTemplate>
                </Setter.Value>
            </Setter>
        </Style>

        <Style x:Key="calendarStyle" TargetType="telerik:RadCalendar">
            <Setter Property="AreWeekNumbersVisible" Value="False" />
        </Style>

        <DataTemplate x:Key="CustomItemTemplate">
            <StackPanel Orientation="Horizontal">
                <TextBlock Text="{Binding Name}"/>
            </StackPanel>
        </DataTemplate>

        <DataTemplate x:Key="MyTemplate">
            <Grid Margin="0">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition MinWidth="260" />
                    <ColumnDefinition MinWidth="260"/>
                    <ColumnDefinition MinWidth="260"/>
                </Grid.ColumnDefinitions>
                <Grid.RowDefinitions>
                    <RowDefinition MinHeight= "40" />
                    <RowDefinition MinHeight= "40"/>
                    <RowDefinition MinHeight= "40"/>
                    <RowDefinition Height= "Auto"/>
                    <RowDefinition Height= "Auto"/>
                </Grid.RowDefinitions>

                <telerik:DataFormDataField Grid.Column="0" Grid.Row="0" Label="发货单号:" DataMemberBinding="{Binding Code, Mode=TwoWay}" />
                <telerik:DataFormDataField Grid.Column="1" Grid.Row="0" Label="发货日期:" DataMemberBinding="{Binding Date, Mode=TwoWay}">
                    <telerik:RadDateTimePicker x:Name="datePicker" SelectedValue="{Binding CreateDate, Mode=TwoWay}"  InputMode="DatePicker"  CalendarStyle="{StaticResource calendarStyle}" />
                </telerik:DataFormDataField>
                <telerik:DataFormDataField Grid.Column="2" Grid.Row="0" Label="出货仓库:" DataMemberBinding="{Binding Warehouse, Mode=TwoWay}" />


                <telerik:DataFormDataField Grid.Column="0" Grid.Row="1" Label="客户名称:" DataMemberBinding="{Binding Customer, Mode=TwoWay}">
                    <telerik:RadComboBox x:Name="customerCombobox" IsEditable="True">
                    </telerik:RadComboBox>
                </telerik:DataFormDataField>
                <telerik:DataFormDataField Grid.Column="1" Grid.Row="1" Label="客户分类:" DataMemberBinding="{Binding CustomerType, Mode=TwoWay}" />


                <telerik:DataFormDataField Grid.Column="2" Grid.Row="1" Label="销售部门:" DataMemberBinding="{Binding SalesDepartment, Mode=TwoWay}">
                    <telerik:RadComboBox x:Name="salesDepartmentCombobox" IsEditable="True">
                    </telerik:RadComboBox>
                </telerik:DataFormDataField>
                <telerik:DataFormDataField Grid.Column="0" Grid.Row="2" Label="销 售 员:" DataMemberBinding="{Binding Saler, Mode=TwoWay}">
                    <telerik:RadComboBox x:Name="salerCombobox" IsEditable="True">
                    </telerik:RadComboBox>
                </telerik:DataFormDataField>
                <telerik:DataFormDataField Grid.Column="1" Grid.Row="2" Label="销售地区:" DataMemberBinding="{Binding SaleArea, Mode=TwoWay}">
                    <telerik:RadComboBox x:Name="provinceCombobox" IsEditable="True">
                    </telerik:RadComboBox>
                </telerik:DataFormDataField>

                <telerik:DataFormDataField Grid.Column="2" Grid.Row="2" Label="备   注:" DataMemberBinding="{Binding Remark, Mode=TwoWay}" />

                <StackPanel Orientation="Horizontal" Grid.Row="4" Grid.ColumnSpan="3" Width="760" Margin="0,10,0,0">

                    <telerik:RadGridView VerticalAlignment="Top" NewRowPosition="Bottom" GroupRenderMode="Flat"  CanUserInsertRows="True"  x:Name="radGridView" IsFilteringAllowed="False" CanUserSortColumns="False" ShowGroupPanel ="False" CanUserFreezeColumns="False" AutoGenerateColumns="False" CanUserDeleteRows="True"  Width="740" Height="280">
                        <telerik:RadGridView.Columns>

                            <telerik:GridViewDataColumn DataMemberBinding="{Binding RowNum}" Header="序号"/>
                            <telerik:GridViewDataColumn DataMemberBinding="{Binding Name}" Header="货物名称" Width="100"/>
                            <telerik:GridViewDataColumn DataMemberBinding="{Binding Unit}" Header="计量单位" Width="80"/>
                            <telerik:GridViewDataColumn DataMemberBinding="{Binding Acount}" Header="头数" Width="60"/>
                            <telerik:GridViewDataColumn DataMemberBinding="{Binding Gross}" Header="毛重" Width="60"/>
                            <telerik:GridViewDataColumn DataMemberBinding="{Binding Tare}" Header="皮重" Width="60"/>
                            <telerik:GridViewDataColumn DataMemberBinding="{Binding Suttle}" Header="净重" Width="60"/>
                            <telerik:GridViewDataColumn DataMemberBinding="{Binding Deduction}" Header="扣损" Width="60"/>
                            <telerik:GridViewDataColumn DataMemberBinding="{Binding TaxPrice}" Header="含税单价" Width="80"/>
                            <telerik:GridViewDataColumn DataMemberBinding="{Binding Total}" Header="价税合计" Width="80"/>
                            <telerik:GridViewDataColumn DataMemberBinding="{Binding Remark}" Header="备注"/>

                        </telerik:RadGridView.Columns>

                    </telerik:RadGridView>
                </StackPanel>
            </Grid>
        </DataTemplate>
    </UserControl.Resources>

    <telerik:RadDataForm  AutoEdit="True"  
                          AutoGenerateFields="False"                          
                          Margin="4" 
                          Header="添加出货单"                         
                          ItemsSource="{Binding Items}" 
                          ReadOnlyTemplate="{StaticResource MyTemplate}" 
                          EditTemplate="{StaticResource MyTemplate}" 
                          NewItemTemplate="{StaticResource MyTemplate}" 
                          CancelButtonContent="取消" 
                          CommitButtonContent="确定" 
                          CommandButtonsVisibility="Commit,Cancel"  
                          Height="490">
        <telerik:RadDataForm.CommitButtonStyle>
            <Style TargetType="telerik:RadButton" >
                <Setter Property="Width" Value="30"/>
            </Style>
        </telerik:RadDataForm.CommitButtonStyle>
    </telerik:RadDataForm>
</UserControl>