// LabelReport.cpp : implementation file
//
#include "stdafx.h"
#include "secall.h"
#include "scmtool.h"
#include "AllPages.h"
#include "reports.h"
#include "LabelReport.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// LabelReport dialog
LabelReport::LabelReport(CWnd* pParent /*=NULL*/)
: CPropertyPage(LabelReport::IDD)
{
//{{AFX_DATA_INIT(LabelReport)
m_SortType = -1;
m_SDescripString = _T("");
m_SNameString = _T("");
//}}AFX_DATA_INIT
}
void LabelReport::DoDataExchange(CDataExchange* pDX)
{
CPropertyPage::DoDataExchange(pDX);
//{{AFX_DATA_MAP(LabelReport)
DDX_Control(pDX, ID_NAMESTRING, m_BNameString);
DDX_Control(pDX, ID_DESCRIPSTRING, m_BDescripString);
DDX_Control(pDX, IDC_NAMESTRING, m_NameString);
DDX_Control(pDX, IDC_DESCRIPSTRING, m_DescripString);
DDX_Control(pDX, IDC_DATESORT, m_SortTypeBotton);
DDX_Control(pDX, ID_BUTTON2, m_Syncl);
DDX_Control(pDX, ID_DELLBL, m_Delete);
DDX_Control(pDX, ID_PRINT, m_Print);
DDX_Control(pDX, ID_LQAT, m_Lconfig3);
DDX_Control(pDX, ID_LPRE, m_Lconfig0);
DDX_Control(pDX, ID_LPRD, m_Lconfig4);
DDX_Control(pDX, ID_LINT, m_Lconfig2);
DDX_Control(pDX, ID_LDEV, m_Lconfig1);
DDX_Control(pDX, ID_LABEL, m_Label);
DDX_Control(pDX, IDC_BUTTON1, m_ButLabel);
DDX_Control(pDX, ID_LABELTYPE, m_LabelType);
DDX_Control(pDX, ID_LMODULE, m_Lmodule);
DDX_Control(pDX, ID_LABEL_PROJECT, m_Lproject);
DDX_Radio(pDX, IDC_DATESORT, m_SortType);
DDX_CBString(pDX, ID_DESCRIPSTRING, m_SDescripString);
DDX_CBString(pDX, ID_NAMESTRING, m_SNameString);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(LabelReport, CPropertyPage)
//{{AFX_MSG_MAP(LabelReport)
ON_CBN_SELCHANGE(ID_LABEL_PROJECT, OnSelchangeLabelProject)
ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
ON_CBN_SELCHANGE(ID_LABELTYPE, OnSelchangeLabeltype)
ON_BN_CLICKED(ID_REPORT_LABEL, OnReportLabel)
ON_EN_KILLFOCUS(ID_LDATE, OnKillfocusLdate)
ON_EN_KILLFOCUS(ID_LDATETO, OnKillfocusLdateto)
ON_BN_CLICKED(ID_BUTTON2, OnButton2)
ON_BN_CLICKED(ID_DELLBL, OnDellabel)
ON_BN_CLICKED(ID_PRINT, OnPrint)
ON_COMMAND(ID_POPUP_SYNC, OnPopupSync)
ON_WM_CONTEXTMENU()
ON_COMMAND(ID_POPUP_REPORT, OnPopupReport)
ON_BN_CLICKED(IDC_DATESORT, OnDatesort)
ON_BN_CLICKED(IDC_PASSSORT, OnPasssort)
ON_WM_RBUTTONUP()
ON_BN_CLICKED(IDC_DESCRIPSTRING, OnDescripstring)
ON_BN_CLICKED(IDC_NAMESTRING, OnNamestring)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// LabelReport message handlers
BOOL LabelReport::OnInitDialog()
{
CPropertyPage::OnInitDialog();
m_Ldate.AttachEdit(ID_LDATE,(CWnd *)this);
m_Ldate.SetMask(_T("####/##/##"));
m_Ldateto.AttachEdit(ID_LDATETO,(CWnd *)this);
m_Ldateto.SetMask(_T("####/##/##"));
CString date=_T("");
date = CAllPages::GetDate();
m_Ldate.SetData(date );
m_Ldateto.SetData(date );
CString Buf;
CString project=_T("");
CString dir = "\\TempTxt\\mm.txt";
TCHAR* pFileName = dir.GetBuffer(0);
CAllPages::ConvertFileIntoString(pFileName,&Buf);
CAllPages::AddStringToCombo(&m_Lproject,Buf);
m_pIcon = AfxGetApp()->LoadIcon(IDI_PRINT);
m_Print.SetIcon(m_pIcon);
m_dIcon = AfxGetApp()->LoadIcon(IDI_DELETE);
m_Delete.SetIcon(m_dIcon);
m_sIcon = AfxGetApp()->LoadIcon(IDI_SYNC);
m_Syncl.SetIcon(m_sIcon);
m_ToolTipCtl = new CToolTipCtrl;
if(m_ToolTipCtl)
{
m_ToolTipCtl->Create(this);
m_ToolTipCtl->AddTool(&m_Print,_T("Print the Labels list"));
m_ToolTipCtl->AddTool(&m_Delete,_T("Delete All Label Reports"));
m_ToolTipCtl->AddTool(&m_Syncl,_T("Sync to a select Label"));
}
m_Lproject.SetCurSel(1);
m_LabelType.SetCurSel(2);
OnSelchangeLabelProject();
OnSelchangeLabeltype();
m_SortType = 0;
m_SortTypeBotton.SetCheck(true);
return TRUE; // return TRUE unless you set the focus to a control
}
BOOL LabelReport::PreTranslateMessage(MSG *pMsg)
{
m_ToolTipCtl->RelayEvent(pMsg);
//Shift+F10: show pop-up menu.
if ((((pMsg->message == WM_KEYDOWN || pMsg->message == WM_SYSKEYDOWN) && //If we hit a key and
(pMsg->wParam == VK_F10) && (GetKeyState(VK_SHIFT) & ~1)) != 0) || //it's Shift+F10 OR
(pMsg->message == WM_CONTEXTMENU)) //Natural keyboard key
{
CRect rect;
GetClientRect(rect);
ClientToScreen(rect);
CPoint point = rect.TopLeft();
// point.Offset(5, 5);
OnContextMenu(NULL, point);
return TRUE;
}
return CDialog::PreTranslateMessage(pMsg);
}
LabelReport::~LabelReport()
{
// WinHelp(0L, HELP_QUIT);
// CPropertyPage::OnDestroy();
if (::IsWindow(m_hWnd))
{
m_ToolTipCtl->DelTool(&m_Print);
m_ToolTipCtl->DelTool(&m_Delete);
m_ToolTipCtl->DelTool(&m_Syncl);
delete m_ToolTipCtl;
}
}
void LabelReport::OnSelchangeLabelProject()
{
CString Buffer=_T(""),ProName,Module=_T(""),Command=_T("");
CString dir = "\\TempTxt\\ll.txt";
TCHAR* pFileName = dir.GetBuffer(0);
int place = m_Lproject.GetCurSel( );
m_Label.ResetContent( );
m_Lproject.GetLBText(place,ProName);
ProName = ProName.Mid(0,(ProName.GetLength()));
if (ProName == "All")
{
m_Lmodule.EnableWindow(FALSE);
m_LabelType.DeleteString(1);
m_LabelType.SetCurSel(0);
return;
}
else
{
if(m_LabelType.GetCount() < 3)
m_LabelType.InsertString(1,_T("Module Labels"));
}
Command += CAllPages::tdl("-m");
Command += ProName;
Command += " DEV > " + CAllPages::GetCurDir() + dir;
CSCMToolApp::Waiting(Command,1,NULL,NULL);
CAllPages::ConvertFileIntoString(pFileName,&Buffer);
m_Lmodule.ResetContent( ); //clean the list box for another use
CAllPages::AddStringToList(&m_Lmodule,Buffer);
UpdateData(FALSE);
}
void LabelReport::OnButton1()
{
CString Command=_T(""),list=_T(""),Type,LabelType,ProName,module;
CString config[5];
CString date,dateto,Buf=_T(""),label;
int buffer[50],flag1 = 0,flag2 = 0;
Command += CAllPages::rep("-l");
int place = m_LabelType.GetCurSel( );
m_LabelType.GetLBText(place,LabelType);
if(LabelType == "All Labels") Type = _T("-all ");
else if (LabelType == "Official Build labels")
{
switch(m_SortType)
{
case 0:
Type = _T("-wb ");
break;
case 1:
Type = _T("-wbps ");
break;
}
}
else if (LabelType == "Module Labels") Type = _T("-sl ");
Command += Type;
place = m_Lproject.GetCurSel();
m_Lproject.GetLBText(place,ProName);
ProName.TrimRight();
if(ProName != "All")
{
Command += " -p " + ProName;
}
if(LabelType == "Module Labels")
{
int Count = m_Lmodule.GetCount( );//Count = Number of Items in the ListBox
m_Lmodule.GetSelItems(Count, buffer);
if(int SelCount = m_Lmodule.GetSelCount( ))
{
for(int i=0;i < SelCount;i++)
{
m_Lmodule.GetText(buffer[i], module );
list += " ";
list += module;
module.Empty();
}
Command += " -m " + list;
flag1 = 1;
}
else
{
MessageBox(_T("Choose module ( you can choose more than one )!"),_T("NSCM"),MB_ICONERROR);
return;
}
}
if(m_Lconfig0.GetCheck( )==1)
{
config[0] = "PRE ";
flag2=1;
}
if(m_Lconfig1.GetCheck( )==1)
{
config[1] = "DEV ";
flag2=1;
}
if(m_Lconfig2.GetCheck( )==1)
{
config[2] = "INT ";
flag2=1;
}
if(m_Lconfig3.GetCheck( )==1)
{
config[3] = "QAT ";
flag2=1;
}
if(m_Lconfig4.GetCheck( )==1)
{
config[4] = "PRD ";
flag2=1;
}
if(flag2) //search for the configuration
{
Command += " -c "+config[0]+config[1]+config[2]+config[3]+config[4];
}
m_Ldate.GetData(date);
m_Ldateto.GetData(dateto);
Command += " -d " + date + " " + dateto;
if(m_DescripString.GetCheck()) //if searching by description string
{
UpdateData(); // initialized the dialog
SetModified(TRUE);
CString SearchString;
int sel = m_BDescripString.GetCurSel();
if (sel == -1) //if it is a new string not selected one
{
SearchString = m_SDescripString;
m_BDescripString.AddString(SearchString);
}
else m_BDescripString.GetLBText(sel,SearchString);
while(! ( SearchString.IsEmpty() ) )
{
int slash = SearchString.ReverseFind(_T('\\'));
if(-1 == slash) {
Command += _T(" -ds ") + SearchString;
break;
}
if(_T('*') == SearchString.GetAt(slash+1)) //means finding \* - that mean not include
{
Command += _T(" -nds ") + SearchString.Mid(slash + 2);
SearchString = SearchString.Left(slash);
}
else
{
Command += _T(" -ds ") + SearchString.Mid(slash + 1);
SearchString = SearchString.Left(slash);
}
}
}
if(m_NameString.GetCheck()) //if searching by description string
{
UpdateData(); // initialized the dialog
SetModified(TRUE);
CString SearchString;
int sel = m_BNameString.GetCurSel();
if (sel == -1) //if it is a new string not selected one
{
SearchString = m_SNameString;
m_BNameString.AddString(SearchString);
}
else m_BNameString.GetLBText(sel,SearchString);
if(! ( SearchString.IsEmpty() ) )
Command += _T(" -ns ") + SearchString;
}
//-----------------------------------
CString dir = "\\TempTxt\\Labels.txt";
Command += " > " + CAllPages::GetCurDir() + dir;
CSCMToolApp::Waiting( Command,1,NULL,NULL);
TCHAR* pFileName = dir.GetBuffer(0);
CAllPages::ConvertFileIntoString(pFileName,&Buf);
m_Label.ResetContent( ); //clean the list box for another use
if(Buf.IsEmpty())
{
MessageBox(_T("There is no Label that matching to this request"),_T("NSCM"),MB_ICONWARNING);
return;
}
CAllPages::AddStringToList(&m_Label,Buf);
}
void LabelReport::OnSelchangeLabeltype()
{
CString Type;
m_Label.ResetContent();
int place = m_LabelType.GetCurSel();
m_LabelType.GetLBText(place,Type);
if(Type == "Module Labels")
{ m_Lmodule.EnableWindow(TRUE);
GetDlgItem(IDC_PASSSORT)->ShowWindow(false);
m_SortTypeBotton.ShowWindow(false);
}
else if(Type == "Official Build labels")
{
m_SortTypeBotton.ShowWindow(true);
GetDlgItem(IDC_PASSSORT)->ShowWindow(true);
m_Lmodule.EnableWindow(FALSE);
m_Lmodule.SetSel( -1 ,FALSE);
}
else
{
m_Lmodule.SetSel( -1 ,FALSE); //kill all the selections
m_Lmodule.EnableWindow(FALSE);
GetDlgItem(IDC_PASSSORT)->ShowWindow(false);
m_SortTypeBotton.ShowWindow(false);
}
}
void LabelReport::OnReportLabel()
{
#define BUFFER_SIZE 1000
if(m_Label.GetSelCount( )==0)
{
MessageBox(_T("Please, Choose Label first!!!"),_T("NSCM"),MB_ICONERROR);
return;
}
CString label,Command = _T(""),Buf=_T(""),date=_T("");
int place;
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);
place = m_Label.GetCurSel();
if( place>-1 )
{
int index;
m_Label.GetText(place , label );
index = label.Find(_T("'Create"))-11;
label = label.Left(index);
Command += CAllPages::rep("-lf -dt");
Command += label;
Command += " > " + CAllPages::GetCurDir() + "\\lbrep\\LReport" + date + ".txt";
CSCMToolApp::Waiting( Command,1,NULL,NULL);
Command.Empty();
CString dir = "\\lbrep\\LReport" + date + ".txt";
TCHAR* pFileName = dir.GetBuffer(0); //LPCTSTR (file);
CAllPages::ConvertFileIntoString(pFileName,&Buf);
if(Buf.IsEmpty())
{
MessageBox(_T("There are no files that matching to this request"),_T("NSCM"),MB_ICONWARNING);
CSCMToolApp::Waiting(CAllPages::Cmd() + " /c del " + CAllPages::GetCurDir() + dir ,1,NULL,NULL);
return;
}
Command += CAllPages::Cmd() +" /c notepad " + CAllPages::GetCurMFCDir()+ "\\lbrep\\LReport" + date + ".txt";
CSCMToolApp::RunProcess(Command,1,NULL,NULL);
}
else
{
AfxMessageBox(_T("There is no Label to Report./n"));
AfxMessageBox(_T("Please,Choose Label first by Clicking on \"Show Labels\" Button"));
return;
}
}
void LabelReport::OnKillfocusLdate()
{
CString from=_T(""),to=_T("");
m_Ldate.GetData(from);
m_Ldateto.GetData(to);
int space = from.Find(_T(" ")); //space can be only in the end
if(space>-1)
{
from = from.Left(space-1) + _T("0") + from.GetAt(space-1);
m_Ldate.SetData(from);
}
CString CurDate = CAllPages::GetDate();
CString day = from.Mid(6);
CString month = from.Mid(4,2);
if(from > CurDate || day > "31" || day == "00"||month > "12" || month == "00")
{
MessageBox(_T("Wrong Date!!"),_T("NSCM"),MB_ICONERROR);
m_Ldate.SetFocus();
return;
}
if(from > to)
{
MessageBeep(0xFFFFFFFF );
m_Ldateto.SetData(CurDate);
m_Ldateto.SetFocus();
return;
}
}
void LabelReport::OnKillfocusLdateto()
{
CString from,to;
m_Ldate.GetData(from);
m_Ldateto.GetData(to);
int space = to.Find(_T(" "));
if(space>-1)
{
to = to.Left(space-1) + _T("0") + to.GetAt(space-1);
m_Ldateto.SetData(to);
}
CString CurDate = CAllPages::GetDate();
CString day = from.Mid(6);
CString month = from.Mid(4,2);
if(day > "31" || day == "00"||month > "12" || month == "00")
{
MessageBox(_T("Wrong Date!!"),_T("NSCM"),MB_ICONERROR);
m_Ldateto.SetFocus();
return;
}
if(from > to)
{
MessageBeep(0xFFFFFFFF);
MessageBox(_T("Wrong Date!!"),_T("NSCM"),MB_ICONERROR);
m_Ldateto.SetData(CurDate);
return;
}
}
void LabelReport::OnButton2()
{
int place = m_Label.GetCurSel();
if(place == LB_ERR){MessageBox(_T("Please Choose Label first!!"),_T("NSCM"),MB_ICONERROR); return;}
CString LabelName=_T(""),Command;
m_Label.GetText(place,LabelName);
LabelName.TrimRight();
if(MessageBox(_T("Syncronize to ")+LabelName,_T("NSCM"),MB_ICONQUESTION|MB_YESNO)== IDNO) return;
Command = CAllPages::tdl("-s");
Command += LabelName;
CSCMToolApp::Waiting(Command,1,NULL,NULL);
}
void LabelReport::OnDellabel()
{
if(MessageBox(_T("Delete all the \"Label reports\" \n in ...\\NSCM\\lebrep ?"),_T("NSCM"),MB_ICONQUESTION|MB_YESNO)== IDNO) return;
CString Command;
Command += CAllPages::Cmd() + " /c del /q ";
Command += CAllPages::GetCurDir() + "\\lbrep\\*.*";
CSCMToolApp::RunProcess(Command,1,NULL,NULL);
}
void LabelReport::OnPrint()
{
int Count = m_Label.GetCount( ); //Count = Number of Items in the ListBox
if(Count == 0)
{
AfxMessageBox(_T("You Have to click on the <Show Labels> button first!!"));
return;
}
if(AfxMessageBox(_T("Print Label List?"),MB_YESNO)== IDNO) return;
CString label,list=_T(""),Command=_T("");
for(int i=0;i < Count;i++)
{
m_Label.GetText(i , label);
list += label + "\r\n";
label.Empty();
}
CString dir = CAllPages::GetCurMFCDir() + "\\lbrep\\Labellist.txt";
TCHAR* pFileName = dir.GetBuffer(0);
DWORD dwCount = list.GetLength();
TCHAR* lpBuf = list.GetBuffer(0);
CFile file;
CFileException e;
file.Open( pFileName, CFile::modeCreate | CFile::modeWrite , &e );
file.WriteHuge( lpBuf, dwCount );
file.Close();
Command = "notepad /p " + CAllPages::GetCurMFCDir() + "\\lbrep\\Labellist.txt";
CSCMToolApp::Waiting(Command,1,NULL,NULL);
file.Remove(pFileName);
return ;
}
void LabelReport::OnPopupSync()
{
OnButton2();
}
void LabelReport::OnContextMenu(CWnd* pWnd, CPoint point)
{
int sel = m_Label.GetCurSel( );
if(LB_ERR != sel)
{
CRect Item_rect,label_rect;
m_Label.GetItemRect( sel, &Item_rect );
m_Label.GetWindowRect( label_rect );
CPoint selpoint;
CPoint labelpoint = label_rect.TopLeft();
selpoint.x = point.x - labelpoint.x; // relative to the list-box
selpoint.y = point.y - labelpoint.y;
//CPoint selpoint(point.x-128,point.y-377);
int yes = Item_rect.PtInRect(selpoint);
if(yes)
{
CMenu menu;
VERIFY(menu.LoadMenu(IDR_LABEL_MENU));
CMenu* pPopup = menu.GetSubMenu(0);
ASSERT(pPopup != NULL);
CWnd* pWndPopupOwner = this;
// while (pWndPopupOwner->GetStyle() & WS_CHILD)
// pWndPopupOwner = pWndPopupOwner->GetParent();
pPopup->TrackPopupMenu(TPM_RIGHTBUTTON, point.x, point.y, pWndPopupOwner);
}
}
}
void LabelReport::OnPopupReport()
{
OnReportLabel() ;
}
void LabelReport::OnDatesort()
{
m_SortType = 0;
}
void LabelReport::OnPasssort()
{
m_SortType = 1;
}
void LabelReport::OnDescripstring()
{
if(!m_DescripString.GetCheck())
m_BDescripString.EnableWindow(FALSE);
else
m_BDescripString.EnableWindow(TRUE);
}
void LabelReport::OnNamestring()
{
if(!m_NameString.GetCheck())
m_BNameString.EnableWindow(FALSE);
else
m_BNameString.EnableWindow(TRUE);
}