private void btnDecrypt_Click(object sender, EventArgs e) { try { //to decrypt the file if (string.IsNullOrEmpty(txtFolderName.Text)) { throw new Exception("Select output folder"); } if (string.IsNullOrEmpty(txtFilePath.Text)) { throw new Exception("Select File to decrypt"); } if (string.IsNullOrEmpty(decrypExtension)) { throw new Exception("Select file decryption extention"); } dataCryptor.FileDetails(info.Name.Substring(0, info.Name.Length - info.Extension.Length), info.Extension, decrypExtension); dataCryptor.isDeletePlainFile(deleteFile); dataCryptor.DecryptFile(); MessageBox.Show("Decryption Successfull", "Completed"); checkDeleteFile.Checked = false; txtFilePath.Clear(); } catch (Exception ex) { MessageBox.Show(ex.Message, "Decryption Error"); } }
private void btnBackup_Click(object sender, EventArgs e) { try { if (string.IsNullOrEmpty(txtFolderName.Text)) { throw new Exception("Select folder to backup file"); } timer1.Enabled = true; timer1.Start(); FileInfo infor = new FileInfo(Application.StartupPath + "/CASHDESKDB.mdf"); info = new FileInfo(infor.FullName); dataCryptor.inPutFilePath(infor.FullName); dataCryptor.FileType(info.Extension); dataCryptor.FileType(info.Name.Substring(0, info.Name.Length - info.Extension.Length), info.Extension); dataCryptor.isDeletePlainFile(false); dataCryptor.EncryptFile(); FileInfo infor2 = new FileInfo(Application.StartupPath + "/CASHDESKDB_log.ldf"); info2 = new FileInfo(infor2.FullName); dataCryptor2.inPutFilePath(infor2.FullName); dataCryptor2.FileType(info2.Extension); dataCryptor2.FileType(info2.Name.Substring(0, info2.Name.Length - info2.Extension.Length), info2.Extension); dataCryptor2.isDeletePlainFile(false); dataCryptor2.EncryptFile(); MessageBox.Show("Backup Sucessfull", "Cashdesk", MessageBoxButtons.OK, MessageBoxIcon.Information); timer1.Stop(); pictureWait.Visible = false; lblWait.Visible = false; } catch (System.UnauthorizedAccessException) { MessageBox.Show("Access to File is denied for backup", "Cashdesk", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (Exception ex) { pictureWait.Visible = false; lblWait.Visible = false; timer1.Stop(); MessageBox.Show(ex.Message, "Cashdesk", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
private void btnimport_Click(object sender, EventArgs e) { try { lbInfor.Visible = true; //to decrypt the file if (string.IsNullOrEmpty(txtFileName.Text)) { throw new Exception("Select output folder"); } var dbname = txtFileName.Text.Substring(0, txtFileName.Text.LastIndexOf(".")).ToLower(); if (dbname == "cashdeskdb") { encFileExtension = ".mdf"; encFileName = "CASHDESKDB"; } else if (dbname == "cashdeskdb_log") { encFileExtension = ".ldf"; encFileName = "CASHDESKDB_log"; } dataCryptor.FileDetails(info.Name.Substring(0, info.Name.Length - info.Extension.Length), info.Extension, encFileExtension); dataCryptor.isDeletePlainFile(deleteFile); dataCryptor.DecryptFile(); File.SetAttributes(decrepted_file_path + "\\" + encFileName + encFileExtension, FileAttributes.Hidden); MessageBox.Show("Import Successfull", "Completed"); lbInfor.Visible = false; } catch (UnauthorizedAccessException) { MessageBox.Show("Access denied", "Import Error", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (Exception ex) { MessageBox.Show(ex.Message, "Import Error", MessageBoxButtons.OK, MessageBoxIcon.Information); lbInfor.Visible = false; } }