xuyi
10/18/2019 - 6:27 AM

Picker

private RsCustomerPicker customerPicker;

customerPicker = new RsCustomerPicker();
            comboCUSTOMER_ID = RadComboBoxExtension.CreateEditPickerBox<CrSaleContract, RsCustomerPicker>(t => t.CUSTOMER_NAME, s => s.CUSTOMER_NAME, customerPicker, validMaster);
            gridLayout.AddField<CrSaleContract>(p => p.CUSTOMER_NAME, "", StyleList.dataNullable, comboCUSTOMER_ID, "", 1, 2, validMaster);
            comboCUSTOMER_ID.SelectionChanged += comboCUSTOMER_ID_SelectionChanged;

private void comboCUSTOMER_ID_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
        {
            if (e.AddedItems.Count > 0)
            {
                var currentItem = this.gridLayout.DataContext as CrSaleContract;

                if (currentItem != null && this.customerPicker.CurrentItem != null)
                {
                    currentItem.CUSTOMER_ID = this.customerPicker.CurrentItem.CUSTOMER_ID;
                    currentItem.CUSTOMER_NAME = this.customerPicker.CurrentItem.CUSTOMER_NAME;
                }
            }
        }
<UserControl x:Class="HD.WPF.RSM.DataPickers.RsCustomerPicker"
             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:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:local="clr-namespace:HD.WPF.RSM.DataPickers"
              xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"
             mc:Ignorable="d">
    <telerik:RadBusyIndicator x:Name="busyIndicator">
        <Grid>
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="*"/>
                <RowDefinition Height="Auto"/>
            </Grid.RowDefinitions>
            <Border Grid.Row="0" BorderThickness="1" BorderBrush="Gray">
                <Grid x:Name="searchLayout" Margin="2,10,2,2">
                    <StackPanel Orientation="Horizontal" HorizontalAlignment="Left">
                        <telerik:RadButton x:Name="btnSearch" Content="查  询" Style="{StaticResource commonButton}" Click="btnSearch_Click" Margin="2,2,2,2"></telerik:RadButton>
                        <telerik:RadButton x:Name="btnConfirm" Content="确  认" Style="{StaticResource commonButton}" Click="btnConfirm_Click" Margin="2,2,2,2"></telerik:RadButton>
                    </StackPanel>
                </Grid>
            </Border>
            <telerik:RadGridView Grid.Row="1" Height="Auto" x:Name="gridView" AutoGenerateColumns="False" EnableLostFocusSelectedState="False"
                            ShowGroupPanel="False"
                            IsSynchronizedWithCurrentItem="False" CanUserSelect="True"
                            SelectionMode="Single"
                            IsReadOnly="True"
                             >
                <telerik:RadGridView.Columns>

                </telerik:RadGridView.Columns>
            </telerik:RadGridView>
            <telerik:RadDataPager Grid.Row="2" DisplayMode="FirstLastPreviousNext" x:Name="dataPager" PageSize="10" NumericButtonCount="10" IsTotalItemCountFixed="True" Style="{StaticResource RadDataPagerStyle_Ext}"  />
        </Grid>

    </telerik:RadBusyIndicator>
</UserControl>
using HD.CLT.RSM.DataContext;
using HD.CLT.RSM.DataObjects;
using HD.CLT.RSM.DataObjects.DataFilters;
using HD.CLT.RSM.DataObjects.DataModels;
using HD.Common.Utils.DataFilters;
using HD.Common.Utils.DataUtils;
using HD.WPF.Common.Asset.ResouceLists;
using HD.WPF.Common.Data.DataUtilities;
using HD.WPF.Common.Data.UI.Validation;
using HD.WPF.Ctrl.Extension;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using Telerik.Windows.Controls;

namespace HD.WPF.RSM.DataPickers
{
    public partial class RsCustomerPicker : UserControl
    {

        private DataContext ctx;
        public RsCustomerPicker()
        {
            ctx = new DataContext();
            InitializeComponent();

            SmartTextBox txtCUSTOMER_ID = TextBoxExtension.CreateSearchTextBox<RsCustomer>(FilterOperation.Contains, p => p.CUSTOMER_ID);
            this.searchLayout.AddField<RsCustomer>(p => p.CUSTOMER_ID, "", StyleList.dataNullable, txtCUSTOMER_ID, "", 1, 1);

            SmartTextBox txtCUSTOMER_NAME = TextBoxExtension.CreateSearchTextBox<RsCustomer>(FilterOperation.Contains, p => p.CUSTOMER_NAME);
            this.searchLayout.AddField<RsCustomer>(p => p.CUSTOMER_NAME, "", StyleList.dataNullable, txtCUSTOMER_NAME, "", 1, 1);

            this.searchLayout.SetSearchLayout(90, 120, 2);

            gridView.CreateDataColumnWithBind<RsCustomer>(p => p.CUSTOMER_ID, "客户编号", 120, "", true, false);
            gridView.CreateDataColumnWithBind<RsCustomer>(p => p.CUSTOMER_NAME, "客户名称", 120, "", true, false);

            this.gridView.RegisterCellCopy();
            this.gridView.Sorting += gridView_Sorting;
            this.dataPager.PageIndexChanged += dataPager_PageIndexChanged;
            this.gridView.InitialColumnVisibilityMenu(this.GetType().FullName, AppObject.GetAppUser().UserId, (pageSize) => { this.dataPager.PageSize = pageSize; ReLoadData(); });

            this.Loaded += Page_Loaded;
        }

        private void Page_Loaded(object sender, RoutedEventArgs e)
        {
            InitialPage();
        }

        private FilterWrapper currentFilter;
        private async void InitialPage()
        {
            this.currentFilter = new FilterWrapper(RsCustomerProperty.CUSTOMER_ID.ToString());
            this.busyIndicator.IsBusy = true;
            await GetPageData(0);
            this.busyIndicator.IsBusy = false;
        }

        private async Task GetPageData(int pageIndex)
        {
            this.currentFilter.PageIndex = pageIndex;
            var wrapper = new
            {
                CurrentFilter = this.currentFilter
            };
            var resultItem = await ctx.GetPagedRsCustomer(wrapper);
            this.gridView.ItemsSource = resultItem.ResultItems;
            this.dataPager.ItemCount = resultItem.TotalRowCount;
            this.dataPager.PageIndex = pageIndex;
        }

        private async void dataPager_PageIndexChanged(object sender, PageIndexChangedEventArgs e)
        {
            this.busyIndicator.IsBusy = true;
            await GetPageData(e.NewPageIndex);
            this.busyIndicator.IsBusy = false;
        }

        private async void gridView_Sorting(object sender, RoutedEventArgs e)
        {
            this.busyIndicator.IsBusy = true;
            this.gridView.SetSortInfo(this.currentFilter);
            await GetPageData(0);
            this.busyIndicator.IsBusy = false;
        }

        private async void btnSearch_Click(object sender, RoutedEventArgs e)
        {
            this.currentFilter.CurrentFilter.FilterItems = searchLayout.GetFilterItems();
            this.busyIndicator.IsBusy = true;
            await GetPageData(0);
            this.busyIndicator.IsBusy = false;
        }

        private void gridView_SelectionChanged(object sender, SelectionChangeEventArgs e)
        {
            if (e.AddedItems.Count > 0)
            {
                this._currentItem = e.AddedItems[0] as RsCustomer;
            }
        }

        private RsCustomer _currentItem;
        public RsCustomer CurrentItem
        {
            get { return _currentItem; }
            set { _currentItem = value; }
        }

        private void btnConfirm_Click(object sender, RoutedEventArgs e)
        {
            if (this.gridView.SelectedItem == null)
            {
                MessageBox.Show("请选择至少一项");
                return;
            }
            this._currentItem = gridView.SelectedItem as RsCustomer;
            GetResultValue();
        }

        public void GetResultValue()
        {
            RadComboBox comboBox = null;
            if (this.Parent.GetType() == typeof(RadComboBox))
            {
                comboBox = this.Parent as RadComboBox;
            }
            if (this.Parent.GetType() == typeof(RadComboBoxItem))
            {
                comboBox = (this.Parent as RadComboBoxItem).Parent as RadComboBox;
            }
            if (comboBox != null)
            {
                CUSTOMER_ID = this._currentItem.CUSTOMER_ID;
                CUSTOMER_NAME = this._currentItem.CUSTOMER_NAME;
                comboBox.IsDropDownOpen = false;

                comboBox.SelectedItem = null;
                comboBox.SelectedItem = this;
            }
        }

        public string CUSTOMER_ID { set; get; }
        public string CUSTOMER_NAME { set; get; }

        private async void ReLoadData()
        {
            this.busyIndicator.IsBusy = true;
            await GetPageData(this.dataPager.PageIndex);
            this.busyIndicator.IsBusy = false;
        }

    }
}