// Before.cpp : implementation file
//

#include "stdafx.h"
#include "Test.h"
#include "Before.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CBefore dialog


CBefore::CBefore(CWnd* pParent /*=NULL*/)
	: CDialog(CBefore::IDD, pParent)
{
	//{{AFX_DATA_INIT(CBefore)
	m_crit = _T("");
	m_ed1 = _T("");
	m_ed2 = _T("");
	m_ed3 = _T("");
	m_method = _T("");
	//}}AFX_DATA_INIT
}


void CBefore::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CBefore)
	DDX_Text(pDX, IDC_EDIT1, m_crit);
	DDX_Text(pDX, IDC_EDIT2, m_ed1);
	DDX_Text(pDX, IDC_EDIT3, m_ed2);
	DDX_Text(pDX, IDC_EDIT4, m_ed3);
	DDX_Text(pDX, IDC_EDIT5, m_method);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CBefore, CDialog)
	//{{AFX_MSG_MAP(CBefore)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CBefore message handlers

BOOL CBefore::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	// TODO: Add extra initialization here
	char str[3][10];

	if(pDoc->Critery==0) 
	{ m_crit="Длина соединений";    
	  SortType=GetMin(pDoc->USumma[0],pDoc->USumma[1],pDoc->USumma[2]);	        
	  for(int i=0;i<3;i++)
		  	sprintf(str[i],"%d",pDoc->USumma[i]); 
	}
	  
	if(pDoc->Critery==1) 
	{ m_crit="Процент трассировки";
	  SortType=GetMax(pDoc->UPercent[0],pDoc->UPercent[1],pDoc->UPercent[2]);
	  for(int i=0;i<3;i++)
		  	sprintf(str[i],"%d",pDoc->UPercent[i]); 
	}
    
	if(pDoc->Critery==2) 
	{ m_crit="Время работы";        
	  SortType=GetMin(pDoc->UTime[0],pDoc->UTime[1],pDoc->UTime[2]);
	  for(int i=0;i<3;i++)
		  	sprintf(str[i],"%d",pDoc->UTime[i]); 
	}
	   	
	m_ed1=str[0];
	m_ed2=str[1];
	m_ed3=str[2];
	sprintf(str[0],"%d",SortType+1);
    m_method=str[0];
    
	UpdateData(false);
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

int CBefore::GetMax(int a,int b, int c)
{
   if ( (a>=b) && (a>=c) )      return(0);
   if ( (b>=a) && (b>=c) )      return(1);
   if ( (c>=a) && (c>=b) )      return(2);
   return(0);
}

int CBefore::GetMin(int a, int b,int c)
{
   if ( (a<=b) && (a<=c) )      return(0);
   if ( (b<=a) && (b<=c) )      return(1);
   if ( (c<=a) && (c<=b) )      return(2);
   return(0);

}
/*
int CBefore::GetMax(int (* adr)[3])
{
   if ( (*adr>=*(adr+1)) && (*adr>=*(adr+2)) )      return(0);
   if ( (*(adr+1)>=*adr) && (*(adr+1)>=*(adr+2)) )  return(1);
   if ( (*(adr+2)>=*adr) && (*(adr+2)>=*(adr+1)) )  return(2);
   return(0);
}

int CBefore::GetMin(int *)
{  if ( (*adr<=*(adr+1)) && (*adr<=*(adr+2)) )      return(0);
   if ( (*(adr+1)<=*adr) && (*(adr+1)<=*(adr+2)) )  return(1);
   if ( (*(adr+2)<=*adr) && (*(adr+2)<=*(adr+1)) )  return(2);
   return(0);

}
*/
void CBefore::OnCancel() 
{
	// TODO: Add extra cleanup here
	SortType=10;
	CDialog::OnCancel();
}
