private void btnOpen2_Click(object sender, EventArgs e) { OpenFileDialog OFD = new OpenFileDialog(); OFD.Filter = "JPeg Image|*.jpg|Bitmap Image|*.bmp|Gif Image|*.gif|PNG Image|*.png"; OFD.FilterIndex = 1; OFD.RestoreDirectory = true; OFD.FileName = string.Empty; if (OFD.ShowDialog() != DialogResult.OK) { return; } txtQRCodePath.Text = OFD.FileName; try { string txt = QRcodeHelper.Decode(txtQRCodePath.Text); txt = txt.Replace(Environment.NewLine, " "); if (txt.Length > 50) { txt = txt.Substring(0, 50); txt += "..."; } txtSearch.Text = txt; } catch (Exception ex) { txtSearch.Text = ""; MessageBox.Show(ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void listFileFounded_SelectedIndexChanged(object sender, EventArgs e) { if (lvFileSearch.SelectedItems.Count <= 0) { return; } try { Thread showThread = new Thread(() => { try { Invoke(new MethodInvoker(() => { label17.Text = "解码中"; })); string path = ""; Invoke(new MethodInvoker(() => { path = lvFileSearch.SelectedItems[0].SubItems[1].Text; })); string txt = QRcodeHelper.Decode(path); txt = txt.Replace("\r\n", " "); if (txt.Length > 50) { txt = txt.Substring(0, 50); txt += "..."; } Invoke(new MethodInvoker(() => { label17.Text = txt; })); } catch { Invoke(new MethodInvoker(() => { label17.Text = "解码失败"; })); } finally { } }); showThread.Start(); } catch { label17.Text = "解码失败"; } }
private void btnDecode_Click(object sender, EventArgs e) { try { string data = QRcodeHelper.Decode(picDecode.Image); //此处可以对decodedString进行解密 #region 解密 int encryption = cboDecryptAlgo.SelectedIndex; string key = txtDecodeKey.Text; switch (encryption) { case 0: //混合 string tempRSAKey = Operate.ReadWriteFile.File2String(OpenedFileName + ".key"); string tempKey = Encryption.RSA.Operate.Decrypt(tempRSAKey, cspPas); data = Encryption.DES.Operate.Decrypt(data, tempKey); break; case 1: //des //密钥为8位 if (String.IsNullOrEmpty(key)) { key = fixedKey[0]; } data = Encryption.DES.Operate.Decrypt(data, key); data = data.TrimEnd(); break; case 2: //RSA data = Encryption.RSA.Operate.Decrypt(data, cspPas); break; default: break; } #endregion txtDecodedData.Text = data; ShowStatusLabel(sender, e); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void btnSearch_Click(object sender, EventArgs e) { if (String.IsNullOrEmpty(txtSearch.Text) && String.IsNullOrEmpty(txtQRCodePath.Text)) { return; } Running = true; try { tabMain.AllowSelect = false; btnSearch.Enabled = false; btnRemove.Enabled = false; AutoResetEvent areFinish = new AutoResetEvent(false); Thread waitTime = new Thread(() => { DateTime dtStart = DateTime.Now; Invoke(new MethodInvoker(() => { toolStripStatusLabel2.Text = "正在搜索文件和解码二维码"; })); areFinish.WaitOne(); DateTime dtFinish = DateTime.Now; Invoke(new MethodInvoker(() => { toolStripStatusLabel2.Text = "搜索完成,所用时间:" + ((int)(dtFinish - dtStart).TotalSeconds).ToString("d") + "秒"; btnSearch.Enabled = true; btnRemove.Enabled = true; tabMain.AllowSelect = true; Running = false; })); }); waitTime.IsBackground = true; waitTime.Name = "计时线程"; waitTime.Start(); string source = String.Empty; if (String.IsNullOrEmpty(txtQRCodePath.Text)) { source = txtSearch.Text; } else { source = QRcodeHelper.Decode(txtQRCodePath.Text); } lvFileSearch.Items.Clear(); string Dir = txtSelectPath.Text; string SearchPattern = "*.jpg,*.png,*gif,*.bmp"; FileSearch fs = new FileSearch(Dir, SearchPattern, source, this); Thread searchFileThread = new Thread(() => { fs.Start(); areFinish.Set(); }); searchFileThread.IsBackground = true; searchFileThread.Name = "搜索主线程"; searchFileThread.Start(); } catch (Exception ex) { MessageBox.Show(ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); } }