Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

417 lines
11 KiB

  1. //Copyright (c) 1998 - 1999 Microsoft Corporation
  2. /*++
  3. Module Name:
  4. AddKp.cpp
  5. Abstract:
  6. This Module contains the implementation of CAddKeyPack Dialog class
  7. (Dialog box used for adding keypacks)
  8. Author:
  9. Arathi Kundapur (v-akunda) 11-Feb-1998
  10. Revision History:
  11. --*/
  12. #include "stdafx.h"
  13. #include "defines.h"
  14. #include "LicMgr.h"
  15. #include "LSServer.h"
  16. #include "MainFrm.h"
  17. #include "AddKP.h"
  18. #include "LicAgrmt.h"
  19. #include "AddLic.h"
  20. #include "lsserver.h"
  21. #include "remlic.h"
  22. #ifdef _DEBUG
  23. #define new DEBUG_NEW
  24. #undef THIS_FILE
  25. static char THIS_FILE[] = __FILE__;
  26. #endif
  27. /////////////////////////////////////////////////////////////////////////////
  28. // CAddKeyPack dialog
  29. CAddKeyPack::CAddKeyPack(CWnd* pParent /*=NULL*/)
  30. : CDialog(CAddKeyPack::IDD, pParent)
  31. {
  32. //{{AFX_DATA_INIT(CAddKeyPack)
  33. m_KeypackType = _T("");
  34. m_TotalLicenses = 0;
  35. m_pKeyPackList = NULL;
  36. //}}AFX_DATA_INIT
  37. }
  38. CAddKeyPack::CAddKeyPack(KeyPackList *pKeyPackList, BOOL bIsUserAdmin,CWnd* pParent /*=NULL*/)
  39. : CDialog(CAddKeyPack::IDD, pParent)
  40. {
  41. //{{AFX_DATA_INIT(CAddKeyPack)
  42. m_KeypackType = _T("");
  43. m_TotalLicenses = 0;
  44. m_pKeyPackList = pKeyPackList;
  45. m_bIsUserAdmin = bIsUserAdmin;
  46. //}}AFX_DATA_INIT
  47. }
  48. void CAddKeyPack::DoDataExchange(CDataExchange* pDX)
  49. {
  50. CDialog::DoDataExchange(pDX);
  51. //{{AFX_DATA_MAP(CAddKeyPack)
  52. DDX_CBString(pDX, IDC_KEYPACK_TYPE, m_KeypackType);
  53. DDX_Control(pDX, IDC_KEYPACK_TYPE, m_LicenseCombo);
  54. DDX_Text(pDX,IDC_TOTAL_LICENSES,m_TotalLicenses);
  55. //}}AFX_DATA_MAP
  56. }
  57. BEGIN_MESSAGE_MAP(CAddKeyPack, CDialog)
  58. //{{AFX_MSG_MAP(CAddKeyPack)
  59. ON_BN_CLICKED(IDC_HELP2, OnHelp2)
  60. ON_CBN_SELCHANGE(IDC_KEYPACK_TYPE, OnSelchangeKeypackType)
  61. ON_BN_CLICKED(IDC_ADD, OnAddLicenses)
  62. ON_BN_CLICKED(IDC_REMOVE, OnRemoveLicenses)
  63. //}}AFX_MSG_MAP
  64. END_MESSAGE_MAP()
  65. /////////////////////////////////////////////////////////////////////////////
  66. // CAddKeyPack message handlers
  67. BOOL CAddKeyPack::OnInitDialog()
  68. {
  69. CDialog::OnInitDialog();
  70. // TODO: Add extra initialization here
  71. if(!m_bIsUserAdmin)
  72. {
  73. GetDlgItem(IDC_ADD)->EnableWindow(FALSE);
  74. GetDlgItem(IDC_REMOVE)->EnableWindow(FALSE);
  75. }
  76. //CString SKU1;
  77. //CString SKU2;
  78. CString SKU236;
  79. //SKU1.LoadString(IDS_SKU1);
  80. //SKU2.LoadString(IDS_SKU2);
  81. SKU236.LoadString(IDS_236_SKU);
  82. POSITION pos = m_pKeyPackList->GetHeadPosition();
  83. while(pos)
  84. {
  85. CKeyPack *pKeyPack = (CKeyPack *)m_pKeyPackList->GetNext(pos);
  86. if(NULL == pKeyPack)
  87. return FALSE;
  88. LSKeyPack sKeyPack = pKeyPack->GetKeyPackStruct();
  89. //if(((0 == SKU1.CompareNoCase(sKeyPack.szProductId)) ||
  90. // (0 == SKU2.CompareNoCase(sKeyPack.szProductId)))&&
  91. #if 0
  92. if(_tcsnicmp(sKeyPack.szProductId, SKU236.GetBuffer(0), SKU236.GetLength()) != 0)
  93. continue;
  94. #endif
  95. if( sKeyPack.ucKeyPackType == LSKEYPACKTYPE_TEMPORARY ||
  96. sKeyPack.ucKeyPackType == LSKEYPACKTYPE_FREE)
  97. {
  98. continue;
  99. }
  100. int nResult = m_LicenseCombo.AddString(sKeyPack.szProductDesc);
  101. if(nResult == CB_ERR || nResult == CB_ERRSPACE)
  102. return FALSE;
  103. }
  104. m_LicenseCombo.SetCurSel(0);
  105. OnSelchangeKeypackType();
  106. return TRUE; // return TRUE unless you set the focus to a control
  107. // EXCEPTION: OCX Property Pages should return FALSE
  108. }
  109. void CAddKeyPack::OnHelp2()
  110. {
  111. // TODO: Add your control notification handler code here
  112. AfxGetApp()->WinHelp(IDC_HELP2,HELP_CONTEXT );
  113. }
  114. void CAddKeyPack::OnOK()
  115. {
  116. // TODO: Add extra validation here
  117. //Validate the information Entered
  118. UpdateData();
  119. if(m_KeypackType.IsEmpty())
  120. {
  121. AfxMessageBox(IDS_INVALID_FIELDS);
  122. return;
  123. }
  124. //Ask the user to select number of Licenses he wants to add.
  125. CAddLicenses AddLicense;
  126. if(IDCANCEL == AddLicense.DoModal())
  127. return;
  128. //Display the License agreement
  129. CLicAgreement LicAgreement;
  130. CString TempString;
  131. TempString.LoadString(IDS_LIC_AGRMT);
  132. LicAgreement.m_License.Format((LPCTSTR)TempString,AddLicense.m_NumLicenses);
  133. if( IDCANCEL == LicAgreement.DoModal())
  134. return;
  135. else
  136. CDialog::OnOK();
  137. }
  138. void CAddKeyPack::OnSelchangeKeypackType()
  139. {
  140. // TODO: Add your control notification handler code here
  141. UpdateData();
  142. //Get the Current Selection.
  143. int nSelection = m_LicenseCombo.GetCurSel( );
  144. //Get the Product Description.
  145. CString ProdDesc;
  146. m_LicenseCombo.GetLBText(nSelection,ProdDesc);
  147. //Search and pickup the keypack with this product description.
  148. //Set the Edit box to display the total licenses.
  149. POSITION pos = m_pKeyPackList->GetHeadPosition();
  150. while(pos)
  151. {
  152. CKeyPack *pKeyPack = (CKeyPack *)m_pKeyPackList->GetNext(pos);
  153. if(NULL == pKeyPack)
  154. break;
  155. LSKeyPack sKeyPack = pKeyPack->GetKeyPackStruct();
  156. if(0 == ProdDesc.CompareNoCase(sKeyPack.szProductDesc))
  157. {
  158. m_TotalLicenses = sKeyPack.dwTotalLicenseInKeyPack;
  159. break;
  160. }
  161. }
  162. UpdateData(FALSE);
  163. return;
  164. }
  165. void CAddKeyPack::OnAddLicenses()
  166. {
  167. int nCount = m_LicenseCombo.GetCount( );
  168. CString ProdDesc, DescBeforeAddLicense;
  169. CKeyPack *pKeyPack = NULL;
  170. LSKeyPack sKeyPack;
  171. HRESULT hResult = ERROR_SUCCESS;
  172. BOOL bUpdateData = TRUE;
  173. CLicMgrApp *pApp = (CLicMgrApp*)AfxGetApp();
  174. ASSERT(pApp);
  175. if(NULL == pApp)
  176. {
  177. AfxMessageBox(IDS_INTERNAL_ERROR);
  178. return;
  179. }
  180. CMainFrame * pWnd = (CMainFrame *)pApp->m_pMainWnd ;
  181. ASSERT(pWnd);
  182. if(NULL == pWnd)
  183. {
  184. AfxMessageBox(IDS_INTERNAL_ERROR);
  185. return;
  186. }
  187. m_LicenseCombo.GetLBText(m_LicenseCombo.GetCurSel(),DescBeforeAddLicense);
  188. CAddLicenses AddLicense(this);
  189. if(IDOK == AddLicense.DoModal())
  190. {
  191. //Get the LicensePack to which the data has to be added.
  192. //Display the License agreement
  193. ProdDesc = AddLicense.m_LicensePack;
  194. GetKeyPack(ProdDesc,&pKeyPack);
  195. if(NULL == pKeyPack)
  196. {
  197. AfxMessageBox(IDS_INTERNAL_ERROR);
  198. return;
  199. }
  200. sKeyPack = pKeyPack->GetKeyPackStruct();
  201. if(0 != ProdDesc.CompareNoCase(DescBeforeAddLicense))
  202. {
  203. //User has changed selection in the AddLicenses Dialog.
  204. //reset the m_TotalLicenses and set bUpdateData to FALSE;
  205. m_TotalLicenses = sKeyPack.dwTotalLicenseInKeyPack;
  206. bUpdateData = FALSE;
  207. }
  208. CLicAgreement LicAgreement;
  209. CString TempString;
  210. TempString.LoadString(IDS_LIC_AGRMT);
  211. LicAgreement.m_License.Format((LPCTSTR)TempString,m_TotalLicenses + AddLicense.m_NumLicenses);
  212. if( IDCANCEL == LicAgreement.DoModal())
  213. return;
  214. SetCursor(LoadCursor(NULL,IDC_WAIT));
  215. hResult = pWnd->AddLicenses(pKeyPack,AddLicense.m_NumLicenses);
  216. if(ERROR_SUCCESS != hResult)
  217. {
  218. if(LSERVER_E_ACCESS_DENIED == hResult)
  219. AfxMessageBox(IDS_NO_ACCESS);
  220. else
  221. AfxMessageBox(IDS_INTERNAL_ERROR);
  222. return;
  223. }
  224. m_TotalLicenses = m_TotalLicenses + AddLicense.m_NumLicenses;
  225. sKeyPack = pKeyPack->GetKeyPackStruct();
  226. if((m_TotalLicenses != sKeyPack.dwTotalLicenseInKeyPack) && !bUpdateData)
  227. {
  228. TempString.Format(IDS_TOTAL_CHANGED,sKeyPack.dwTotalLicenseInKeyPack - AddLicense.m_NumLicenses,sKeyPack.dwTotalLicenseInKeyPack);
  229. AfxMessageBox(TempString);
  230. }
  231. m_TotalLicenses = sKeyPack.dwTotalLicenseInKeyPack;
  232. if(bUpdateData)
  233. {
  234. UpdateData(FALSE);
  235. }
  236. return;
  237. }
  238. }
  239. void CAddKeyPack::OnRemoveLicenses()
  240. {
  241. int nCount = m_LicenseCombo.GetCount( );
  242. CString ProdDesc,DescBeforeRemLicense;
  243. CKeyPack *pKeyPack = NULL;
  244. LSKeyPack sKeyPack;
  245. CString TempString;
  246. CString RemWarning;
  247. HRESULT hResult = ERROR_SUCCESS;
  248. CLicMgrApp *pApp = (CLicMgrApp*)AfxGetApp();
  249. ASSERT(pApp);
  250. if(NULL == pApp)
  251. {
  252. AfxMessageBox(IDS_INTERNAL_ERROR);
  253. return;
  254. }
  255. CMainFrame * pWnd = (CMainFrame *)pApp->m_pMainWnd ;
  256. ASSERT(pWnd);
  257. if(NULL == pWnd)
  258. {
  259. AfxMessageBox(IDS_INTERNAL_ERROR);
  260. return;
  261. }
  262. m_LicenseCombo.GetLBText(m_LicenseCombo.GetCurSel(),DescBeforeRemLicense);
  263. CRemoveLicenses RemLicense(this);
  264. if(IDOK == RemLicense.DoModal())
  265. {
  266. //Get the LicensePack to which the data has to be added.
  267. ProdDesc = RemLicense.m_LicensePack;
  268. GetKeyPack(ProdDesc,&pKeyPack);
  269. if(NULL == pKeyPack)
  270. {
  271. AfxMessageBox(IDS_INTERNAL_ERROR);
  272. return;
  273. }
  274. sKeyPack = pKeyPack->GetKeyPackStruct();
  275. if(RemLicense.m_NumLicenses > sKeyPack.dwTotalLicenseInKeyPack)
  276. {
  277. TempString.LoadString(IDS_REMOVE_MORE);
  278. RemWarning.Format((LPCTSTR)TempString, sKeyPack.dwNumberOfLicenses,RemLicense.m_NumLicenses);
  279. AfxMessageBox(RemWarning);
  280. return;
  281. }
  282. TempString.LoadString(IDS_REMOVE_WARNING);
  283. RemWarning.Format((LPCTSTR)TempString,RemLicense.m_NumLicenses,ProdDesc);
  284. if(IDNO == AfxMessageBox(RemWarning,MB_YESNO))
  285. return;
  286. hResult = pWnd->RemoveLicenses(pKeyPack,RemLicense.m_NumLicenses);
  287. if(ERROR_SUCCESS != hResult && LSERVER_I_REMOVE_TOOMANY != hResult)
  288. {
  289. if(LSERVER_E_ACCESS_DENIED == hResult)
  290. AfxMessageBox(IDS_NO_ACCESS);
  291. else
  292. AfxMessageBox(IDS_INTERNAL_ERROR);
  293. return;
  294. }
  295. if(LSERVER_I_REMOVE_TOOMANY == hResult)
  296. {
  297. sKeyPack = pKeyPack->GetKeyPackStruct();
  298. TempString.Format(IDS_REMOVE_TOOMANY,sKeyPack.dwTotalLicenseInKeyPack);
  299. AfxMessageBox(TempString);
  300. m_TotalLicenses = sKeyPack.dwTotalLicenseInKeyPack;
  301. UpdateData(FALSE);
  302. return;
  303. }
  304. m_TotalLicenses = m_TotalLicenses - RemLicense.m_NumLicenses;
  305. sKeyPack = pKeyPack->GetKeyPackStruct();
  306. if((m_TotalLicenses != sKeyPack.dwTotalLicenseInKeyPack) &&
  307. (0 == ProdDesc.CompareNoCase(DescBeforeRemLicense)))
  308. {
  309. TempString.Format(IDS_TOTAL_CHANGED,sKeyPack.dwTotalLicenseInKeyPack + RemLicense.m_NumLicenses,sKeyPack.dwTotalLicenseInKeyPack);
  310. AfxMessageBox(TempString);
  311. m_TotalLicenses = sKeyPack.dwTotalLicenseInKeyPack;
  312. }
  313. if(0 == ProdDesc.CompareNoCase(DescBeforeRemLicense))
  314. UpdateData(FALSE);
  315. return;
  316. }
  317. //Get the Product Description.
  318. }
  319. void CAddKeyPack::GetKeyPack(CString ProdDesc, CKeyPack ** ppKeyPack)
  320. {
  321. if(NULL == ppKeyPack)
  322. return;
  323. *ppKeyPack = NULL;
  324. if(NULL == m_pKeyPackList)
  325. return;
  326. CKeyPack * pKeyPack = NULL;
  327. LSKeyPack sKeyPack;
  328. POSITION pos = m_pKeyPackList->GetHeadPosition();
  329. while(pos)
  330. {
  331. pKeyPack = (CKeyPack *)m_pKeyPackList->GetNext(pos);
  332. if(NULL == pKeyPack)
  333. return;
  334. sKeyPack = pKeyPack->GetKeyPackStruct();
  335. if(0 == ProdDesc.CompareNoCase(sKeyPack.szProductDesc))
  336. {
  337. *ppKeyPack = pKeyPack;
  338. break;
  339. }
  340. }
  341. return;
  342. }