// TreeReport.cpp : implementation file
#include "stdafx.h"
#include "scmtool.h"
#include "TreeReport.h"
#include "AllPages.h"
#include "secall.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// TreeReport dialog
TreeReport::TreeReport(CWnd* pParent /*=NULL*/)
: CPropertyPage(TreeReport::IDD)
{
//{{AFX_DATA_INIT(TreeReport)
//}}AFX_DATA_INIT
}
void TreeReport::DoDataExchange(CDataExchange* pDX)
{
CPropertyPage::DoDataExchange(pDX);
//{{AFX_DATA_MAP(TreeReport)
DDX_Control(pDX, ID_DEL, m_Del);
DDX_Control(pDX, IDC_CHECK4, m_Check4);
DDX_Control(pDX, IDC_CHECK3, m_Check3);
DDX_Control(pDX, IDC_CHECK2, m_Check2);
DDX_Control(pDX, IDC_CHECK1, m_Check1);
DDX_Control(pDX, ID_PATH2, m_Path2);
DDX_Control(pDX, ID_PATH, m_Path);
DDX_Control(pDX, ID_BROWSER, m_Browser);
DDX_Control(pDX, ID_PROJECT_TYPE2, m_Project2);
DDX_Control(pDX, ID_PROJECT_TYPE, m_Project);
DDX_Control(pDX, ID_CONF_TYPE2, m_Config2);
DDX_Control(pDX, ID_CONF_TYPE, m_Config);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(TreeReport, CPropertyPage)
//{{AFX_MSG_MAP(TreeReport)
ON_BN_CLICKED(ID_BROWSER, OnBrowser)
ON_CBN_SELCHANGE(ID_PROJECT_TYPE, OnSelchangeProjectType)
ON_CBN_SELCHANGE(ID_CONF_TYPE, OnSelchangeConfType)
ON_CBN_SELCHANGE(ID_PROJECT_TYPE2, OnSelchangeProjectType2)
ON_CBN_SELCHANGE(ID_CONF_TYPE2, OnSelchangeConfType2)
ON_BN_CLICKED(ID_REPORT, OnReport)
ON_BN_CLICKED(ID_DEL, OnDel)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// TreeReport message handlers
BOOL TreeReport::OnInitDialog()
{
CPropertyPage::OnInitDialog();
CString Buf;
CString project=_T("");
CString dir =_T("\\TempTxt\\mm.txt");//mm - projects list
TCHAR* pFileName = dir.GetBuffer(0);
CAllPages::ConvertFileIntoString(pFileName,&Buf);
CAllPages::AddStringToCombo(&m_Project,Buf);
m_dIcon = AfxGetApp()->LoadIcon(IDI_DELETE);
m_Del.SetIcon(m_dIcon);
m_ToolTipCtl = new CToolTipCtrl;
if(m_ToolTipCtl)
{
m_ToolTipCtl->Create(this);
m_ToolTipCtl->AddTool(&m_Del,_T("Delete All tree reports"));
}
m_Project.SetCurSel(0);
OnSelchangeProjectType();
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
TreeReport::~TreeReport()
{
if (::IsWindow(m_hWnd))
{
m_ToolTipCtl->DelTool(&m_Del);
delete m_ToolTipCtl;
}
}
BOOL TreeReport::PreTranslateMessage(MSG *pMsg)
{
m_ToolTipCtl->RelayEvent(pMsg);
return CDialog::PreTranslateMessage(pMsg);
}
void TreeReport::OnBrowser()
{
CString project=_T(""),configuration=_T(""),Path,Buf;
int place = m_Project.GetCurSel();
m_Project.GetLBText(place,project);
project.TrimRight();
place = m_Config.GetCurSel();
m_Config.GetLBText(place,configuration);
configuration.TrimRight();
Path = _T("\\\\Ntserv5\\") ;
Path += project + _T("\\") + configuration + _T("\\") + project;
SECDirSelectDlg aDlg(_T("Select Directory"),NULL,NULL);
// Sets the initial directory to be displayed in the directory selection dialog.
aDlg.SetInitialDir( Path );
aDlg.DoModal();
CString SelectedPath=_T("");
// Retrieves the selected path.
aDlg.GetPath(SelectedPath);
place = SelectedPath.Find(_T("\\")+project);
SelectedPath = SelectedPath.Mid(place);
SelectedPath = _T("\\") + SelectedPath ;
m_Path.SetWindowText(_T(""));
m_Path.ReplaceSel(SelectedPath);
place = SelectedPath.Find(project+_T("\\") +configuration );//the second project like it\dev\it
int len1 = project.GetLength();
int len2 = configuration.GetLength();
SelectedPath = SelectedPath.Mid(place+len1+len2+len1+2);
place = m_Project2.GetCurSel();
m_Project2.GetLBText(place,project);
project.TrimRight();
place = m_Config2.GetCurSel();
m_Config2.GetLBText(place,configuration);
configuration.TrimRight();
m_Path2.SetWindowText(_T(""));
m_Path2.ReplaceSel(_T("\\\\")+project+_T("\\")+configuration+_T("\\")+ project + SelectedPath);
}
void TreeReport::OnSelchangeProjectType()
{
CString project=_T(""),configuration=_T(""),Command=_T(""),Buf=_T("");
m_Path.SetWindowText(_T(""));
int place = m_Project.GetCurSel();
m_Project.GetLBText(place,project);
project.TrimRight();
CString dir = _T("\\TempTxt\\pc.txt");
Command = CAllPages::rep(_T("-pc")) + project + _T(" > ") + CAllPages::GetCurDir() + dir;
CSCMToolApp::Waiting(Command,1,NULL,NULL);
TCHAR * pFileName = dir.GetBuffer(0);
CAllPages::ConvertFileIntoString(pFileName,&Buf);
m_Config.ResetContent();
CAllPages::AddStringToCombo(&m_Config,Buf);
int pdev;
if(-1==(pdev=m_Config.FindStringExact(-1, _T("dev"))))//find dev and choose it as priority
pdev = 0;
m_Config.SetCurSel(pdev);
m_Project2.ResetContent();
if(project == _T("Elite")) m_Project2.AddString(_T("Elite"));
else if(project == _T("IT") || project == _T("OFF202"))
{
m_Project2.AddString(_T("IT"));
m_Project2.AddString(_T("OFF202"));
}
m_Project2.SetCurSel(0);
m_Config.GetLBText(pdev,configuration);
m_Path.ReplaceSel(_T("\\\\") + project + _T("\\")+configuration+_T("\\") + project + _T("\\"));
m_Project2.EnableWindow(TRUE);
OnSelchangeProjectType2() ;
}
void TreeReport:: OnSelchangeConfType()
{
CString project=_T(""),configuration=_T(""),Path=_T(""),Rest=_T("");
int place = m_Project.GetCurSel();
m_Project.GetLBText(place,project);
project.TrimRight();
m_Path.GetWindowText(Path);
m_Path.SetWindowText(_T(""));
int len = project.GetLength();
Path = Path.Mid( 2 + len );
int index = Path.Find( project );
if(index>-1) Rest = Path.Mid( index );
place = m_Config.GetCurSel();
m_Config.GetLBText(place,configuration);
configuration.TrimRight();
m_Path.SetWindowText(_T(""));
m_Path.ReplaceSel(_T("\\\\") + project + _T("\\")+configuration+_T("\\")+Rest);
}
void TreeReport::OnSelchangeProjectType2()
{
CString project=_T(""),configuration=_T(""),Command=_T(""),Buf;
m_Path2.SetWindowText(_T(""));
int place = m_Project2.GetCurSel();
m_Project2.GetLBText(place,project);
project.TrimRight();
CString dir = _T("\\TempTxt\\pc.txt");
Command = CAllPages::rep(_T("-pc")) + project + _T(" > ") + CAllPages::GetCurDir() + dir;
CSCMToolApp::Waiting(Command,1,NULL,NULL);
TCHAR * pFileName = dir.GetBuffer(0);
CAllPages::ConvertFileIntoString(pFileName,&Buf);
m_Config2.ResetContent();
CAllPages::AddStringToCombo(&m_Config2,Buf);
m_Config2.EnableWindow( TRUE );
int pdev;
if(CB_ERR==(pdev=m_Config2.FindStringExact(-1 , _T("dev"))))
pdev=0;
m_Config2.SetCurSel(pdev);
m_Config2.GetLBText(pdev,configuration);
m_Path2.ReplaceSel(_T("\\\\") + project + _T("\\") +configuration+_T("\\")+project + _T("\\"));
}
void TreeReport::OnSelchangeConfType2()
{
CString project=_T(""),configuration=_T(""),Path=_T(""),Rest=_T("");
int place = m_Project2.GetCurSel();
m_Project2.GetLBText(place,project);
project.TrimRight();
m_Path2.GetWindowText(Path);
m_Path2.SetWindowText(_T(""));
int len = project.GetLength();
Path = Path.Mid( len + 2);
int index = Path.Find( project );
if(index>-1) Rest = Path.Mid( index );
place = m_Config2.GetCurSel();
m_Config2.GetLBText(place,configuration);
configuration.TrimRight();
m_Path2.SetWindowText(_T(""));
m_Path2.ReplaceSel(_T("\\\\") + project + _T("\\")+configuration+_T("\\")+Rest);
}
void TreeReport::OnReport()
{
CString date=_T(""),Buf,Com,Path1,Path2;
time_t osBinaryTime; // C run-time time (defined in <time.h>)
time( &osBinaryTime ) ; // Get the current time from the operating system.
CTime t( osBinaryTime );
int day = t.GetDay();
int month = t.GetMonth();
int year = t.GetYear();
int sec = t.GetSecond();
int min = t.GetMinute();
int hour = t.GetHour() ;
date.Format(_T("_%d%d%d_%d%d%d"),day,month,year,hour,min,sec);
m_Path.GetWindowText(Path1);
m_Path2.GetWindowText(Path2);
Path1 = CAllPages::ReplaceAll(Path1,_T("\\"),_T("/"));
Path2 = CAllPages::ReplaceAll(Path2,_T("\\"), _T("/"));
if(m_Check1.GetCheck()) Command(_T("-diffone3"),Path1,Path2,date);
if(m_Check2.GetCheck()) Command(_T("-diffone3"),Path2,Path1,date);
if(m_Check3.GetCheck()) Command(_T("-eql3"),Path1,Path2,date);
if(m_Check4.GetCheck()) Command(_T("-diff3"),Path1,Path2,date);
CString dir = _T("\\treerep\\TReport") + date + _T(".txt");
TCHAR *pFileName = dir.GetBuffer(0);
CAllPages::ConvertFileIntoString(pFileName,&Buf);
if(Buf.IsEmpty())
{
MessageBox(_T("There are no files that matching to this request"),_T("NSCM"),MB_ICONINFORMATION);
CSCMToolApp::Waiting(CAllPages::Cmd() + _T(" /c del /q ") + CAllPages::GetCurDir() + dir,1,NULL,NULL);
return;
}
Com = CAllPages::Cmd() + _T(" /c notepad ") + CAllPages::GetCurMFCDir() + _T("\\treerep\\TReport") + date + _T(".txt");
CSCMToolApp::RunProcess(Com,1,NULL,NULL);
}
void TreeReport::Command(CString Switch,CString Path1,CString Path2,CString Date)
{
CString Command = CAllPages::rep(Switch)+Path1 + _T("... ") + Path2+ _T("...");
Command += _T(" >> ") + CAllPages::GetCurDir()+_T("\\treerep\\TReport")+ Date + _T(".txt");
CSCMToolApp::Waiting( Command,1,NULL,NULL);
}
void TreeReport::OnDel()
{
if(MessageBox(_T("Delete all the Label reports \n in ...\\NSCM\\treerep ?"),_T("NSCM"),MB_ICONQUESTION|MB_YESNO)== IDNO)
return;
CString Command;
Command += CAllPages::Cmd() + _T(" /c del /q ");
Command += CAllPages::GetCurDir() + _T("\\treerep\\*.*");
CSCMToolApp::RunProcess(Command,1,NULL,NULL);
}