//internal static string GetSortExpr(PerformMemberActionArgs args)
		//{
		//  List<string> sortExpr = new List<string>();
			
		//  string lasthier = args.Member.HierarchyUniqueName;
		//  for (int i = 0; i < args.Ascendants.Count; i++)
		//  {
		//    var member = args.Ascendants[i];

		//    if (lasthier != member.HierarchyUniqueName)
		//    {
		//      lasthier = member.HierarchyUniqueName;
		//      sortExpr.Insert(0, member.UniqueName);
		//    }
		//  }
		//  sortExpr.Add(args.Member.UniqueName);
		//  return "("+string.Join(",",sortExpr.ToArray())+")";
		//}
		internal void SortByValue(PerformMemberActionArgs args)
		{
			var tuple = args.Member.GetAxisTuple();
			var measuresSort=MeasuresSort as SortByValueDescriptor;
			if (measuresSort == null)
			{
				measuresSort = new SortByValueDescriptor();
				measuresSort.Tuple=tuple;
				MeasuresSort = measuresSort;
				
			}
			else if (!measuresSort.CompareByTuple(tuple))
			{
				measuresSort.Tuple = tuple;
				measuresSort.Type = SortTypes.None;
			}
			
			if (MeasuresSort.Type == SortTypes.None)
				MeasuresSort.Type = SortTypes.Ascending;
			else if (MeasuresSort.Type == SortTypes.Ascending)
				MeasuresSort.Type = SortTypes.Descending;
			else if (MeasuresSort.Type == SortTypes.Descending)
				MeasuresSort.Type = SortTypes.None;
				
		}
 public override SortDescriptor Clone()
 {
     var target = new SortByValueDescriptor();
     target.Type = Type;
     foreach(var item in Tuple)
     target.Tuple.Add(item.Key, item.Value);
     return target;
 }
        public override SortDescriptor Clone()
        {
            var target = new SortByValueDescriptor();

            target.Type = Type;
            foreach (var item in Tuple)
            {
                target.Tuple.Add(item.Key, item.Value);
            }
            return(target);
        }
		void ShowSortPropertiesDialog(PivotTableSortTypes sortType, MemberControl member)
		{
			ModalDialog dlg;
			SortPropertiesControl sortControl;
			if (sortType == PivotTableSortTypes.SortByValue)
			{
				// Сортировку по значению делаем отдельным диалогом чтобы не думать о сохранении размеров
				if (m_SortByValueDialog == null)
				{
					m_SortByValueDialog = new ModalDialog() { Width = 500, Height = 400, MinHeight = 250, MinWidth = 180, DialogStyle = ModalDialogStyles.OKCancel };
					m_SortByValueDialog.Caption = Localization.SortingSettingsDialog_Caption;
					m_SortByValueDialog.DialogOk += new EventHandler<DialogResultArgs>(SortProperties_DialogOk);
					Panel panel1 = GetRootPanel(this);
					if (panel1 != null)
					{
						panel1.Children.Add(m_SortByValueDialog.Dialog.PopUpControl);
					}
				}

				if (m_SortByValueSettingsControl == null)
				{
					m_SortByValueSettingsControl = new SortPropertiesControl();
					m_SortByValueSettingsControl.CubeName = m_CSDescr != null ? m_CSDescr.CubeName : String.Empty;
					m_SortByValueSettingsControl.ConnectionID = m_CSDescr != null ? m_CSDescr.Connection.ConnectionID : String.Empty;
					m_SortByValueSettingsControl.GetOlapDataLoader += new EventHandler<GetIDataLoaderArgs>(CopyControl_GetMetadataLoader);
					m_SortByValueSettingsControl.LogManager = this.LogManager;

					m_SortByValueSettingsControl.LoadMeasures += new EventHandler<CustomEventArgs<EventArgs>>(m_SortSettingsControl_LoadMeasures);
					m_SortByValueDialog.Content = m_SortByValueSettingsControl;
				}
				sortControl = m_SortByValueSettingsControl;
				dlg = m_SortByValueDialog;
			}
			else
			{
				if (m_SortDialog == null)
				{
					m_SortDialog = new ModalDialog() { Width = 400, Height = 250, MinHeight = 215, MinWidth = 180, DialogStyle = ModalDialogStyles.OKCancel };
					m_SortDialog.Caption = Localization.SortingSettingsDialog_Caption;
					m_SortDialog.DialogOk += new EventHandler<DialogResultArgs>(SortProperties_DialogOk);
					Panel panel1 = GetRootPanel(this);
					if (panel1 != null)
					{
						panel1.Children.Add(m_SortDialog.Dialog.PopUpControl);
					}
				}

				if (m_SortSettingsControl == null)
				{
					m_SortSettingsControl = new SortPropertiesControl();
					m_SortSettingsControl.CubeName = m_CSDescr != null ? m_CSDescr.CubeName : String.Empty;
					m_SortSettingsControl.ConnectionID = m_CSDescr != null ? m_CSDescr.Connection.ConnectionID : String.Empty;
					m_SortSettingsControl.GetOlapDataLoader += new EventHandler<GetIDataLoaderArgs>(CopyControl_GetMetadataLoader);
					m_SortSettingsControl.LogManager = this.LogManager;

					m_SortSettingsControl.LoadMeasures += new EventHandler<CustomEventArgs<EventArgs>>(m_SortSettingsControl_LoadMeasures);
					m_SortDialog.Content = m_SortSettingsControl;
				}
				sortControl = m_SortSettingsControl;
				dlg = m_SortDialog;
			}

			if (dlg == null || sortControl == null)
				return;

			dlg.Tag = sortControl;
			sortControl.Tag = member;

			SortDescriptor sort = null;
			switch (sortType)
			{
				case PivotTableSortTypes.SortByProperty:
					if (m_CellSetProvider != null &&
									member != null &&
									member.Member != null)
					{
						sort = GetAxisPropertySort(member);
					}
					break;
				case PivotTableSortTypes.SortAxisByMeasure:
					sort = GetAxisByMeasureSort(member);
					break;
				case PivotTableSortTypes.SortByValue:
					// Получаем сортировку для противоположной оси. Если это сортировка по значению, то проверяем чтобы это была сортировка для данного элемента. Если нет, то создается новый дескриптор
					if (member is ColumnMemberControl || member is RowMemberControl)
					{
						var value_sort = GetAxisSort(member is ColumnMemberControl ? AreaType.RowsArea : AreaType.ColumnsArea) as SortByValueDescriptor;
						if (value_sort != null && member != null && member.Member != null && value_sort.CompareByTuple(member.Member.GetAxisTuple()))
						{
							sort = value_sort;
						}
					}

					if (sort == null)
					{
						sort = new SortByValueDescriptor();
						if (member != null && member.Member != null)
						{
							(sort as SortByValueDescriptor).Tuple = member.Member.GetAxisTuple();
						}
					}
					break;
			}

			sortControl.Initialize(sortType, sort);
			ShowDialog(dlg);
		}