Пример #1
0
 /// <summary>
 /// Check license
 /// </summary>
 public void CheckLicense()
 {
     //if (Debugger.IsAttached) return;//*sign
     if (ExceptionCompany())
     {
         return;
     }
     try
     {
         string        message    = "";
         LicenseEntity objLicense = new LicenseEntity();
         string        pCode      = string.Empty;
         string        pKey       = string.Empty;
         DateTime      pDate      = CommonBL.GetTimeServer();
         DataTable     dtTemp     = objLicense.GetAll();
         if (dtTemp != null && dtTemp.Rows.Count > 0)
         {
             pCode = dtTemp.Rows[0]["LicenseCode"].ToString();
             pKey  = dtTemp.Rows[0]["LicenseKey"].ToString();
             //pDate = dtTemp.Rows[0]["CreatedDate"].To<DateTime>();
             string strCPUID      = "";
             string strMacAddress = objLicense.GetServerInformation(out strCPUID);
             var    hasValid      = BALicenseManager.CheckValidateLicense(pCode, pKey, pDate, strMacAddress, strCPUID);
             if (hasValid < 0)
             {
                 message = string.Format("{0}:Mã xác thực License Key không hợp lệ. Vui lòng liên hệ nhà cung cấp", hasValid);
                 new MessageBoxBA().Show(message, "Thông báo", MessageBoxButtonsBA.OK, MessageBoxIconBA.Error);
                 Application.Exit();
             }
             else if (hasValid > 1)
             {
                 message = string.Format("Bản quyền còn {0} ngày nữa sẽ hết hạn. Vui lòng liên hệ nhà cung cấp", hasValid);
                 new MessageBoxBA().Show(message, "Thông báo", MessageBoxButtonsBA.OK, MessageBoxIconBA.Warning);
             }
             else if (hasValid == 0)
             {
                 message = string.Format("Phần mềm đã hết hạn sử dụng. Bạn không được sử dụng phần mềm này nữa");
                 new MessageBoxBA().Show(message, "Thông báo", MessageBoxButtonsBA.OK, MessageBoxIconBA.Error);
                 Application.Exit();
             }
         }
         else
         {
             message = "Phần mềm đang chưa có bản quyền.";
             new MessageBoxBA().Show(message, "Thông báo", MessageBoxButtonsBA.OK, MessageBoxIconBA.Error);
             Application.Exit();
         }
     }
     catch (Exception ex)
     {
         LogError.WriteLogError("LicenseBL CheckLicense", ex);
         new MessageBoxBA().Show("Lỗi.Phần mềm đang chưa có bản quyền.", "Thông báo", MessageBoxButtonsBA.OK, MessageBoxIconBA.Error);
         Application.Exit();
     }
 }
Пример #2
0
 /// <summary>
 /// Lưu vào hệ thống các key
 /// </summary>
 private void btnConfirmLicense_Click(object sender, EventArgs e)
 {
     try
     {
         lblMsg.Text  = "";
         CheckSuccess = true;
         if (MacAddress == null)
         {
             string strCPUID = "";
             MacAddress = _objLicense.GetServerInformation(out strCPUID);
             CPUID      = strCPUID;
         }
         int licenseTime = BALicenseManager.CheckValidateLicense(txtCodeLicense.Text, txtKeyLicense.Text, DateTime.Now, MacAddress, CPUID);
         if (licenseTime >= 0)
         {
             int result = _objLicense.AuthoriseLicenseKey(txtAPIKey.Text, txtKeyLicense.Text, txtCodeLicense.Text, true, -1);
             if (result != 1)
             {
                 CheckSuccess = false;
             }
             else
             {
                 new MessageBoxBA().Show("Xác thực hệ thống thành công!");
             }
         }
         else
         {
             lblMsg.Text  = "Bản quyền không hợp lệ";
             CheckSuccess = false;
         }
     }
     catch (Exception ex)
     {
         new MessageBoxBA().Show("Lỗi");
         LogError.WriteLogError("btnConfirmLicense_Click:", ex);
         CheckSuccess = true;
     }
 }