Leaked source code of windows server 2003
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.

495 lines
8.3 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. ASSERT(NULL != pNMHDR);
  259. m_nLicenses += ((NM_UPDOWN*)pNMHDR)->iDelta;
  260. if (m_nLicenses < 0)
  261. {
  262. m_nLicenses = 0;
  263. ::MessageBeep(MB_OK);
  264. }
  265. else if (m_nLicenses > m_nTotalLicenses)
  266. {
  267. m_nLicenses = m_nTotalLicenses;
  268. ::MessageBeep(MB_OK);
  269. }
  270. UpdateData(FALSE); // set data
  271. ASSERT(NULL != pResult);
  272. *pResult = 1; // handle ourselves...
  273. }
  274. void CDeleteLicenseDialog::OnUpdateQuantity()
  275. /*++
  276. Routine Description:
  277. Message handler for EN_UPDATE.
  278. Arguments:
  279. None.
  280. Return Values:
  281. None.
  282. --*/
  283. {
  284. long nLicensesOld = m_nLicenses;
  285. if (!IsQuantityValid())
  286. {
  287. m_nLicenses = nLicensesOld;
  288. UpdateData(FALSE);
  289. m_licEdit.SetFocus();
  290. m_licEdit.SetSel(0,-1);
  291. ::MessageBeep(MB_OK);
  292. }
  293. }
  294. BOOL CDeleteLicenseDialog::IsQuantityValid()
  295. /*++
  296. Routine Description:
  297. Wrapper around UpdateData(TRUE).
  298. Arguments:
  299. None.
  300. Return Values:
  301. VT_BOOL.
  302. --*/
  303. {
  304. BOOL bIsValid;
  305. m_nLicensesMin = 1; // raise minimum...
  306. bIsValid = UpdateData(TRUE);
  307. m_nLicensesMin = 0; // reset minimum...
  308. return bIsValid;
  309. }