Exemple #1
0
        private void cmbCity_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (!this.needChange)
            {
                return;
            }
            if (cmbCity.SelectedIndex > 0)
            {
                int citySysNumber = System.Convert.ToInt32(cmbCity.SelectedValue);
                this.SelectedCitySysNo = citySysNumber.ToString();

                Facade.QueryCurrentAreaStructure(citySysNumber, (obj, args) =>
                {
                    if (args.FaultsHandle())
                    {
                        return;
                    }
                    this.needChange = false;
                    ViewModel       = AreaQueryTransform.Transform(args.Result);
                    //cmbArea.ItemsSource = ViewModel.DistrictAreaList;
                    this.SelectedCityName = ViewModel.CityeAreaList.Where(f => f.Key == citySysNumber.ToString()).FirstOrDefault().Value;
                    // this.SelectedCityName = ViewModel.CityeAreaList;
                    this.needChange = true;
                    //ClearValidationError(cmbArea);
                });
            }
            else
            {
                this.needChange = false;
                //cmbArea.ItemsSource = SingleSource;
                //cmbArea.SelectedIndex = 0;
                this.SelectedAreaSysNo = null;
                this.needChange        = true;
            }
        }
Exemple #2
0
        private void BindData()
        {
            string query = string.IsNullOrEmpty(this.SelectedAreaSysNo) ? "-999" : this.SelectedAreaSysNo;

            Facade.QueryCurrentAreaStructure(System.Convert.ToInt32(query), (obj, args) =>
            {
                if (args.FaultsHandle())
                {
                    return;
                }
                ViewModel = AreaQueryTransform.Transform(args.Result);

                string areaSysNo = null;
                if (!string.IsNullOrEmpty(this.SelectedAreaSysNo))
                {
                    areaSysNo = this.SelectedAreaSysNo;
                }

                this.needChange = false;

                cmbProvince.ItemsSource = ViewModel.ProvinceAreaList;
                cmbCity.ItemsSource     = ViewModel.CityeAreaList;
                //在给ComboBox的数据源赋值后,会触发SelectionChanged时间,导致SelectedAreaSysNo为null,所以需要把SelectedAreaSysNo先存起来
                //cmbArea.ItemsSource = ViewModel.DistrictAreaList;

                this.needChange = true;

                if (!string.IsNullOrEmpty(areaSysNo))
                {
                    this.SelectedAreaSysNo = areaSysNo;
                }

                if (string.IsNullOrEmpty(this.SelectedAreaSysNo))
                {
                    cmbProvince.SelectedIndex = 0;
                }
                else
                {
                    this.needChange = false;


                    cmbProvince.SelectedValue = ViewModel.CurrentArea.ProvinceSysNumber;
                    cmbCity.SelectedValue     = ViewModel.CurrentArea.CitySysNumber;

                    //cmbArea.SelectedValue = ViewModel.CurrentArea.SysNumber;

                    this.needChange = true;
                }
            });
        }
        //public void BindSelectedData()
        //{
        //    if (!string.IsNullOrEmpty(this.SelectedAreaSysNo) && cmbArea.ItemsSource != null)
        //    {
        //        return;
        //    }
        //    string query = string.IsNullOrEmpty(this.SelectedAreaSysNo) ? "-999" : this.SelectedAreaSysNo;
        //    //MessageBox.Show("第一步" + this.SelectedAreaSysNo ?? "");

        //    Facade.QueryCurrentAreaStructure_Old(System.Convert.ToInt32(query), (obj, args) =>
        //    {
        //        // MessageBox.Show("第二步"+this.SelectedAreaSysNo??"");
        //        if (args.FaultsHandle())
        //        {
        //            return;
        //        }
        //        ViewModel = AreaQueryTransform.Transform_Old(args.Result);

        //        string areaSysNo = null;
        //        if (!string.IsNullOrEmpty(this.SelectedAreaSysNo))
        //        {
        //            areaSysNo = this.SelectedAreaSysNo;
        //        }

        //        this.needChange = false;

        //        cmbProvince.ItemsSource = ViewModel.ProvinceAreaList;
        //        cmbCity.ItemsSource = ViewModel.CityeAreaList;
        //        //在给ComboBox的数据源赋值后,会触发SelectionChanged时间,导致SelectedAreaSysNo为null,所以需要把SelectedAreaSysNo先存起来
        //        cmbArea.ItemsSource = ViewModel.DistrictAreaList;
        //        //MessageBox.Show("第三步"+ViewModel.ProvinceAreaList.Count.ToString() + "," + ViewModel.CityeAreaList.Count.ToString() + "," + ViewModel.DistrictAreaList.Count.ToString());
        //        this.needChange = true;

        //        if (!string.IsNullOrEmpty(areaSysNo))
        //        {
        //            //MessageBox.Show("第四步" + areaSysNo);
        //            this.SelectedAreaSysNo = areaSysNo;
        //        }

        //        if (string.IsNullOrEmpty(this.SelectedAreaSysNo))
        //        {
        //            cmbProvince.SelectedIndex = 0;
        //        }
        //        else
        //        {
        //            this.needChange = false;

        //            //MessageBox.Show("第五步" + ViewModel.CurrentArea.ProvinceSysNumber + "," + ViewModel.CurrentArea.CitySysNumber + "," + ViewModel.CurrentArea.SysNumber);
        //            cmbProvince.SelectedValue = ViewModel.CurrentArea.ProvinceSysNumber;
        //            cmbCity.SelectedValue = ViewModel.CurrentArea.CitySysNumber;
        //            if (ViewModel.CurrentArea.DistrictName != null)
        //            {
        //                cmbArea.SelectedValue = ViewModel.CurrentArea.SysNumber;
        //            }
        //            else
        //            {
        //                cmbArea.SelectedIndex = 0;
        //            }


        //            this.needChange = true;
        //        }
        //    });
        //}

        /// <summary>
        /// 选择省事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void cmbProvince_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (!this.needChange)
            {
                return;
            }
            if (cmbProvince.SelectedIndex > 0)
            {
                int provinceSysNumber = System.Convert.ToInt32(cmbProvince.SelectedValue);
                this.SelectedProvinceSysNo = provinceSysNumber.ToString();
                Facade.QueryCurrentAreaStructure_Old(provinceSysNumber, (obj, args) =>
                {
                    if (args.FaultsHandle())
                    {
                        return;
                    }
                    this.needChange           = false;
                    ViewModel                 = AreaQueryTransform.Transform_Old(args.Result);
                    this.SelectedProvinceName = ViewModel.ProvinceAreaList.Where(f => f.Key == provinceSysNumber.ToString()).FirstOrDefault().Value;
                    cmbCity.ItemsSource       = ViewModel.CityeAreaList;
                    this.needChange           = true;
                    if (cmbCity.SelectedValue == null)
                    {
                        cmbArea.ItemsSource = this.SingleSource;
                        ClearValidationError(cmbArea);
                    }
                });
            }
            else
            {
                this.needChange       = false;
                cmbCity.ItemsSource   = SingleSource;
                cmbCity.SelectedIndex = 0;
                cmbArea.ItemsSource   = SingleSource;
                cmbArea.SelectedIndex = 0;
                this.needChange       = true;
            }
        }
        /// <summary>
        /// 绑定数据
        /// </summary>
        private void BindData()
        {
            string query = string.IsNullOrEmpty(this.SelectedAreaSysNo) ? "-999" : this.SelectedAreaSysNo;

            //MessageBox.Show("第一步" + this.SelectedAreaSysNo ?? "");
            if (query == "-999" && GetParentObject <UserControl>(this, "ucContactInfo") != null)
            {
                return;
            }
            Facade.QueryCurrentAreaStructure_Old(System.Convert.ToInt32(query), (obj, args) =>
            {
                //MessageBox.Show("第二步" + this.SelectedAreaSysNo ?? "");
                if (args.FaultsHandle())
                {
                    return;
                }
                ViewModel = AreaQueryTransform.Transform_Old(args.Result);

                string areaSysNo = null;
                if (!string.IsNullOrEmpty(this.SelectedAreaSysNo))
                //if (ViewModel.CurrentArea.SysNo.HasValue)
                {
                    areaSysNo = this.SelectedAreaSysNo;
                    //areaSysNo = ViewModel.CurrentArea.SysNo.ToString();
                }

                this.needChange = false;

                cmbProvince.ItemsSource = ViewModel.ProvinceAreaList;
                cmbCity.ItemsSource     = ViewModel.CityeAreaList;
                //在给ComboBox的数据源赋值后,会触发SelectionChanged时间,导致SelectedAreaSysNo为null,所以需要把SelectedAreaSysNo先存起来
                cmbArea.ItemsSource = ViewModel.DistrictAreaList;
                //MessageBox.Show("第三步" + ViewModel.ProvinceAreaList.Count.ToString() + "," + ViewModel.CityeAreaList.Count.ToString() + "," + ViewModel.DistrictAreaList.Count.ToString());
                this.needChange = true;

                if (!string.IsNullOrEmpty(areaSysNo))
                {
                    //MessageBox.Show("第四步" + areaSysNo);
                    this.SelectedAreaSysNo = areaSysNo;
                }

                if (string.IsNullOrEmpty(this.SelectedAreaSysNo))
                {
                    cmbProvince.SelectedIndex = 0;
                }
                else
                {
                    this.needChange = false;

                    //MessageBox.Show("第五步" + ViewModel.CurrentArea.ProvinceSysNumber + "," + ViewModel.CurrentArea.CitySysNumber + "," + ViewModel.CurrentArea.SysNumber);
                    cmbProvince.SelectedValue = ViewModel.CurrentArea.ProvinceSysNumber;
                    cmbCity.SelectedValue     = ViewModel.CurrentArea.CitySysNumber;
                    if (ViewModel.CurrentArea.DistrictName != null)
                    {
                        cmbArea.SelectedValue = ViewModel.CurrentArea.SysNumber;
                    }
                    else
                    {
                        cmbArea.SelectedIndex = 0;
                    }


                    this.needChange = true;
                }
            });
        }