private void btnDecrypt_Click(object sender, EventArgs e) { string gdbPath = txtGDBPath.Text; string errMsg; if (rbAccessGDB.Checked) { EncryptGDB.GDB_Crypt_Status status = EncryptGDB.CheckAccessGDBStatus(gdbPath); switch (status) { case EncryptGDB.GDB_Crypt_Status.GCS_NOT_AVAILABLE: DisplayMessage("Access地理数据库无效"); break; case EncryptGDB.GDB_Crypt_Status.GCS_ENCRYTED: if (EncryptGDB.DecryptAccessGDB(gdbPath, out errMsg)) { DisplayMessage("Access地理数据库解密成功"); } else { DisplayMessage(errMsg); } break; case EncryptGDB.GDB_Crypt_Status.GCS_NOT_CRYTED: DisplayMessage("Access地理数据库未加密,无需再次解密"); break; } DoCheckAccessGDBStatus(gdbPath); } else if (rbFileGDB.Checked) { EncryptGDB.GDB_Crypt_Status status = EncryptGDB.CheckFileGDBStatus(gdbPath); switch (status) { case EncryptGDB.GDB_Crypt_Status.GCS_NOT_AVAILABLE: DisplayMessage("文件地理数据库无效"); break; case EncryptGDB.GDB_Crypt_Status.GCS_ENCRYTED: if (EncryptGDB.DecryptFileGDB(gdbPath, out errMsg)) { DisplayMessage("文件地理数据库解密成功"); } else { DisplayMessage(errMsg); } break; case EncryptGDB.GDB_Crypt_Status.GCS_NOT_CRYTED: DisplayMessage("文件地理数据库未加密,无需再次解密"); break; } DoCheckFileGDBStatus(gdbPath); } }
protected override void OnClick() { string errMsg = string.Empty; string gdbPath = GetFileGDBPath(); if (Directory.Exists(gdbPath)) { EncryptGDB.GDB_Crypt_Status gdbStatus = EncryptGDB.CheckFileGDBStatus(gdbPath); switch (gdbStatus) { case EncryptGDB.GDB_Crypt_Status.GCS_NOT_AVAILABLE: DisplayMessage("文件地理数据库无效"); return; case EncryptGDB.GDB_Crypt_Status.GCS_ENCRYTED: //判断是否过期 DateTime encryptedTime = EncryptGDB.GetFileGDBEncryptedTime(gdbPath); if (encryptedTime < DateTime.Now) { DisplayMessage("文件地理数据库已过期"); return; } if (EncryptGDB.DecryptFileGDB(gdbPath, out errMsg)) { IWorkspace ws = OpenFileGDBWorkspace(gdbPath); Application.DoEvents(); //重新加密数据库 EncryptGDB.EncryptFileGDB(gdbPath, encryptedTime, out errMsg); if (ws != null) { FormSelectDatasets frmSelectDatasets = new FormSelectDatasets(ws); if (frmSelectDatasets.ShowDialog() == DialogResult.OK) { List <ILayer> layers = frmSelectDatasets.SelectedLayers; IEnvelope extent = frmSelectDatasets.SelectedExtent; AddLayersToMap(layers, extent); } } } else { DisplayMessage(errMsg); } break; case EncryptGDB.GDB_Crypt_Status.GCS_NOT_CRYTED: break; } } }
private void DoCheckAccessGDBStatus(string gdbPath) { EncryptGDB.GDB_Crypt_Status status = EncryptGDB.CheckAccessGDBStatus(gdbPath); switch (status) { case EncryptGDB.GDB_Crypt_Status.GCS_NOT_AVAILABLE: DisplayMessage("Access地理数据库无效"); break; case EncryptGDB.GDB_Crypt_Status.GCS_ENCRYTED: btnEncrypt.Enabled = false; dtpEncryptDate.Enabled = false; btnDecrypt.Enabled = true; break; case EncryptGDB.GDB_Crypt_Status.GCS_NOT_CRYTED: btnEncrypt.Enabled = true; dtpEncryptDate.Enabled = true; btnDecrypt.Enabled = false; break; } }