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.

492 lines
7.8 KiB

  1. /*++
  2. Copyright (c) 1994-95 Microsoft Corporation
  3. Module Name:
  4. dlicdlg.cpp
  5. Abstract:
  6. Delete license dialog implementation.
  7. Author:
  8. Don Ryan (donryan) 05-Mar-1995
  9. Environment:
  10. User Mode - Win32
  11. Revision History:
  12. --*/
  13. #include "stdafx.h"
  14. #include "llsmgr.h"
  15. #include "dlicdlg.h"
  16. #ifdef _DEBUG
  17. #undef THIS_FILE
  18. static char BASED_CODE THIS_FILE[] = __FILE__;
  19. #endif
  20. BEGIN_MESSAGE_MAP(CDeleteLicenseDialog, CDialog)
  21. //{{AFX_MSG_MAP(CDeleteLicenseDialog)
  22. ON_NOTIFY(UDN_DELTAPOS, IDC_DEL_LICENSE_SPIN, OnDeltaPosSpin)
  23. ON_EN_UPDATE(IDC_DEL_LICENSE_QUANTITY, OnUpdateQuantity)
  24. //}}AFX_MSG_MAP
  25. END_MESSAGE_MAP()
  26. CDeleteLicenseDialog::CDeleteLicenseDialog(CWnd* pParent /*=NULL*/)
  27. : CDialog(CDeleteLicenseDialog::IDD, pParent)
  28. /*++
  29. Routine Description:
  30. Constructor for dialog.
  31. Arguments:
  32. pParent - owner window.
  33. Return Values:
  34. None.
  35. --*/
  36. {
  37. //{{AFX_DATA_INIT(CDeleteLicenseDialog)
  38. m_strComment = _T("");
  39. m_nLicenses = 0;
  40. m_nLicensesMin = 0;
  41. m_strProduct = _T("");
  42. //}}AFX_DATA_INIT
  43. m_pProduct = NULL;
  44. m_nTotalLicenses = 0;
  45. m_bAreCtrlsInitialized = FALSE;
  46. m_fUpdateHint = UPDATE_INFO_NONE;
  47. }
  48. void CDeleteLicenseDialog::DoDataExchange(CDataExchange* pDX)
  49. /*++
  50. Routine Description:
  51. Called by framework to exchange dialog data.
  52. Arguments:
  53. pDX - data exchange object.
  54. Return Values:
  55. None.
  56. --*/
  57. {
  58. CDialog::DoDataExchange(pDX);
  59. //{{AFX_DATA_MAP(CDeleteLicenseDialog)
  60. DDX_Control(pDX, IDC_DEL_LICENSE_COMMENT, m_cmtEdit);
  61. DDX_Control(pDX, IDC_DEL_LICENSE_SPIN, m_spinCtrl);
  62. DDX_Control(pDX, IDC_DEL_LICENSE_QUANTITY, m_licEdit);
  63. DDX_Control(pDX, IDOK, m_okBtn);
  64. DDX_Control(pDX, IDCANCEL, m_cancelBtn);
  65. DDX_Text(pDX, IDC_DEL_LICENSE_COMMENT, m_strComment);
  66. DDX_Text(pDX, IDC_DEL_LICENSE_QUANTITY, m_nLicenses);
  67. DDV_MinMaxLong(pDX, m_nLicenses, m_nLicensesMin, m_nTotalLicenses);
  68. DDX_Text(pDX, IDC_DEL_LICENSE_PRODUCT, m_strProduct);
  69. //}}AFX_DATA_MAP
  70. }
  71. void CDeleteLicenseDialog::InitCtrls()
  72. /*++
  73. Routine Description:
  74. Initializes dialog controls.
  75. Arguments:
  76. None.
  77. Return Values:
  78. None.
  79. --*/
  80. {
  81. m_strProduct = m_pProduct->m_strName;
  82. UpdateData(FALSE); // upload...
  83. m_spinCtrl.SetRange(0, UD_MAXVAL);
  84. m_cmtEdit.LimitText(256);
  85. m_licEdit.SetFocus();
  86. m_licEdit.SetSel(0,-1);
  87. m_licEdit.LimitText(6);
  88. m_bAreCtrlsInitialized = TRUE;
  89. }
  90. void CDeleteLicenseDialog::InitDialog(CProduct* pProduct, int nTotalLicenses)
  91. /*++
  92. Routine Description:
  93. Initializes dialog.
  94. Arguments:
  95. pProduct - product object.
  96. nTotalLicenses - total licenses for product.
  97. Return Values:
  98. None.
  99. --*/
  100. {
  101. ASSERT(nTotalLicenses > 0);
  102. VALIDATE_OBJECT(pProduct, CProduct);
  103. m_pProduct = pProduct;
  104. m_nTotalLicenses = nTotalLicenses;
  105. }
  106. void CDeleteLicenseDialog::AbortDialogIfNecessary()
  107. /*++
  108. Routine Description:
  109. Displays status and aborts if connection lost.
  110. Arguments:
  111. None.
  112. Return Values:
  113. None.
  114. --*/
  115. {
  116. theApp.DisplayLastStatus();
  117. if (IsConnectionDropped(LlsGetLastStatus()))
  118. {
  119. AbortDialog(); // bail...
  120. }
  121. }
  122. void CDeleteLicenseDialog::AbortDialog()
  123. /*++
  124. Routine Description:
  125. Aborts dialog.
  126. Arguments:
  127. None.
  128. Return Values:
  129. None.
  130. --*/
  131. {
  132. m_fUpdateHint = UPDATE_INFO_ABORT;
  133. EndDialog(IDABORT);
  134. }
  135. BOOL CDeleteLicenseDialog::OnInitDialog()
  136. /*++
  137. Routine Description:
  138. Message handler for WM_INITDIALOG.
  139. Arguments:
  140. None.
  141. Return Values:
  142. Returns false if focus set manually.
  143. --*/
  144. {
  145. CDialog::OnInitDialog();
  146. PostMessage(WM_COMMAND, ID_INIT_CTRLS);
  147. return TRUE;
  148. }
  149. void CDeleteLicenseDialog::OnOK()
  150. /*++
  151. Routine Description:
  152. Deletes a license for product.
  153. Arguments:
  154. None.
  155. Return Values:
  156. None.
  157. --*/
  158. {
  159. if (!IsQuantityValid())
  160. return;
  161. if (m_strProduct.IsEmpty())
  162. return;
  163. CString strConfirm;
  164. CString strLicenses;
  165. strLicenses.Format(_T("%d"), m_nLicenses);
  166. AfxFormatString2(
  167. strConfirm,
  168. IDP_CONFIRM_DELETE_LICENSE,
  169. strLicenses,
  170. m_strProduct
  171. );
  172. if (AfxMessageBox(strConfirm, MB_YESNO) != IDYES)
  173. return;
  174. BeginWaitCursor(); // hourglass...
  175. NTSTATUS NtStatus;
  176. LLS_LICENSE_INFO_0 LicenseInfo0;
  177. TCHAR szUserBuffer[256];
  178. DWORD dwUserBuffer = sizeof(szUserBuffer);
  179. if (::GetUserName(szUserBuffer, &dwUserBuffer))
  180. {
  181. LicenseInfo0.Product = MKSTR(m_strProduct);
  182. LicenseInfo0.Quantity = -m_nLicenses;
  183. LicenseInfo0.Date = 0; // ignored...
  184. LicenseInfo0.Admin = szUserBuffer;
  185. LicenseInfo0.Comment = MKSTR(m_strComment);
  186. NtStatus = ::LlsLicenseAdd(
  187. LlsGetActiveHandle(),
  188. 0,
  189. (LPBYTE)&LicenseInfo0
  190. );
  191. if (NtStatus == STATUS_UNSUCCESSFUL)
  192. {
  193. //
  194. // Some licenses for this product have already
  195. // been deleted so we just pass back success so
  196. // that we can return to the summary list...
  197. //
  198. NtStatus = STATUS_SUCCESS;
  199. AfxMessageBox(IDP_ERROR_NO_LICENSES);
  200. }
  201. LlsSetLastStatus(NtStatus); // called api...
  202. if (NT_SUCCESS(NtStatus))
  203. {
  204. m_fUpdateHint = UPDATE_LICENSE_DELETED;
  205. EndDialog(IDOK);
  206. }
  207. else
  208. {
  209. AbortDialogIfNecessary(); // display error...
  210. }
  211. }
  212. else
  213. {
  214. LlsSetLastStatus(::GetLastError());
  215. AbortDialogIfNecessary(); // display error...
  216. }
  217. EndWaitCursor(); // hourglass...
  218. }
  219. BOOL CDeleteLicenseDialog::OnCommand(WPARAM wParam, LPARAM lParam)
  220. /*++
  221. Routine Description:
  222. Message handler for WM_COMMAND.
  223. Arguments:
  224. wParam - message specific.
  225. lParam - message specific.
  226. Return Values:
  227. Returns true if message processed.
  228. --*/
  229. {
  230. if (wParam == ID_INIT_CTRLS)
  231. {
  232. if (!m_bAreCtrlsInitialized)
  233. {
  234. InitCtrls();
  235. }
  236. ::SafeEnableWindow(
  237. &m_okBtn,
  238. &m_cancelBtn,
  239. CDialog::GetFocus(),
  240. (BOOL)(m_nTotalLicenses > 0)
  241. );
  242. return TRUE; // processed...
  243. }
  244. return CDialog::OnCommand(wParam, lParam);
  245. }
  246. void CDeleteLicenseDialog::OnDeltaPosSpin(NMHDR* pNMHDR, LRESULT* pResult)
  247. /*++
  248. Routine Description:
  249. Notification handler for UDN_DELTAPOS.
  250. Arguments:
  251. pNMHDR - notification header.
  252. pResult - return code.
  253. Return Values:
  254. None.
  255. --*/
  256. {
  257. UpdateData(TRUE); // get data
  258. m_nLicenses += ((NM_UPDOWN*)pNMHDR)->iDelta;
  259. if (m_nLicenses < 0)
  260. {
  261. m_nLicenses = 0;
  262. ::MessageBeep(MB_OK);
  263. }
  264. else if (m_nLicenses > m_nTotalLicenses)
  265. {
  266. m_nLicenses = m_nTotalLicenses;
  267. ::MessageBeep(MB_OK);
  268. }
  269. UpdateData(FALSE); // set data
  270. *pResult = 1; // handle ourselves...
  271. }
  272. void CDeleteLicenseDialog::OnUpdateQuantity()
  273. /*++
  274. Routine Description:
  275. Message handler for EN_UPDATE.
  276. Arguments:
  277. None.
  278. Return Values:
  279. None.
  280. --*/
  281. {
  282. long nLicensesOld = m_nLicenses;
  283. if (!IsQuantityValid())
  284. {
  285. m_nLicenses = nLicensesOld;
  286. UpdateData(FALSE);
  287. m_licEdit.SetFocus();
  288. m_licEdit.SetSel(0,-1);
  289. ::MessageBeep(MB_OK);
  290. }
  291. }
  292. BOOL CDeleteLicenseDialog::IsQuantityValid()
  293. /*++
  294. Routine Description:
  295. Wrapper around UpdateData(TRUE).
  296. Arguments:
  297. None.
  298. Return Values:
  299. VT_BOOL.
  300. --*/
  301. {
  302. BOOL bIsValid;
  303. m_nLicensesMin = 1; // raise minimum...
  304. bIsValid = UpdateData(TRUE);
  305. m_nLicensesMin = 0; // reset minimum...
  306. return bIsValid;
  307. }