Exemplo n.º 1
0
 private void CBtn_Click(object sender, EventArgs e)
 {
     enter   = false;
     isEqual = false;
     ResultTxt.Clear();
     ResultLbl.Text = "";
     total          = 0;
 }
Exemplo n.º 2
0
        private void OperatorsClick(object sender, EventArgs e)
        {
            if (ResultTxt.Text != string.Empty)
            {
                //isEqual = false;

                lastIsOperator = -1;
                //firstme = false;

                if (sender is Button button)
                {
                    if (isOperator == false)
                    {
                        CalculateTotal();
                        firstTotal = false;
                        CallOperator(button);
                        isOperator = true;

                        //iki setir sonradan
                        ResultTxt.Clear();
                        ResultTxt.Text = total.ToString();
                    }
                    //if(lastIsOperator == 1)
                    //{
                    //    CallOperator(button);

                    //    lastIsOperator = 0;
                    //}
                }
            }

            //CalculateTotal();
            //lastIsOperator = -1;
            //firstTotal = false;
            //if (sender is Button button)
            //{
            //    if(isOperator==false)
            //    {
            //        CallOperator(button);
            //        isOperator = true;
            //    }
            //    //if(lastIsOperator == 1)
            //    //{
            //    //    CallOperator(button);

            //    //    lastIsOperator = 0;
            //    //}
            //}
        }
Exemplo n.º 3
0
 /// <summary>
 /// Called when the user presses the "Test" button. We perform the regex
 /// testing here and show the results to the user.
 /// </summary>
 /// <param name="sender">Event sender.</param>
 /// <param name="e">Event arguments.</param>
 private void TestBtn_Click(object sender, System.EventArgs e)
 {
     try {
         RegexTester tester = new RegexTester();
         using (new CursorChanger(this, Cursors.WaitCursor)) {
             ResultTxt.Text = tester.ModifyWithRegex(SampleTxt.Text, RegexTxt.Text,
                                                     ReplacementTxt.Text, IgnoreCaseChk.Checked);
         }
         // If we made it here, the regular expression is valid.
         InvalidNoticeLbl.Visible = false;
     } catch (RegexTesterException) {
         // Invalid regular expression.
         ResultTxt.Clear();
         InvalidNoticeLbl.Visible = true;
     }
 }
Exemplo n.º 4
0
        private void NumberClick(object sender, EventArgs e)
        {
            isEqual    = false;
            isOperator = false;
            if (sender is Button button)
            {
                if (lastIsOperator == -1)
                {
                    ResultTxt.Clear();
                }
                lastIsOperator  = 1;
                ResultTxt.Text += button.Text;

                //Random random = new Random();
                //double value = (random.NextDouble() * (9999.99 - 0.99) + 0.99);
                //double b = Math.Round(value, 2, MidpointRounding.ToEven);



                //if (firstme)
                //    ResultTxt.Text += button.Text;
                //else if (myqueue)
                //{
                //    ResultTxt.Text += button.Text;
                //    myqueue = false;
                //}
                //else if (myqueue == false)
                //    ResultTxt.Text = total.ToString();


                //if (lastIsOperator == -1)
                //    total += Double.Parse(button.Text);


                //isOperator = false;
                //ResultTxt.Text += total;
                //ResultTxt.Text += button.Text;
            }
        }
Exemplo n.º 5
0
        private void CalculateTotal()
        {
            if (Double.Parse(ResultTxt.Text) < 0 && enter == false)
            {
                ResultTxt.Text = (-Double.Parse(ResultTxt.Text)).ToString();
            }


            //if (firstTotal && enter==true)
            //{
            //    total -= Double.Parse(ResultTxt.Text);
            //    ResultTxt.Text = (-Double.Parse(ResultTxt.Text)).ToString();
            //}
            //if (firstTotal && enter==false)
            //    total += Double.Parse(ResultTxt.Text);


            if (firstTotal)
            {
                total += Double.Parse(ResultTxt.Text);
            }


            else if (select == 1)
            {
                total += Double.Parse(ResultTxt.Text);
            }
            else if (select == 2)
            {
                total -= Double.Parse(ResultTxt.Text);
            }
            else if (select == 3 && isEqual == false)
            {
                total *= Double.Parse(ResultTxt.Text);
            }
            else if (select == 3 && isEqual == true)
            {
                total += Double.Parse(ResultTxt.Text);
            }
            else
            {
                total /= Double.Parse(ResultTxt.Text);
                int a;
            }
            //if (ResultTxt.Text == "∞")
            //{
            //    ResultTxt.Clear();
            //    ResultLbl.Text = "";
            //    Application.Exit();
            //}
            //if(total==Double.NaN)
            //{
            //    ResultTxt.Clear();
            //    ResultLbl.Text = "";
            //    Application.Exit();
            //}
            if (Double.IsInfinity(total))
            {
                ResultTxt.Clear();
                ResultLbl.Text = "";
                Application.Exit();
            }
        }
Exemplo n.º 6
0
        private async void Button1_Click(object sender, EventArgs e)
        {
            using (_longOperation.Start())
            {
                await Task.Run(() =>
                {
                    string filePath      = this.encryFilePathTxt.Text.Trim();
                    string directoryPath = this.TargetDirectoryTxt.Text.Trim();

                    //检查是否选择了文件
                    if (filePath.Length == 0)
                    {
                        MessageBox.Show("Please select a file", "Info", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        return;
                    }
                    else
                    {
                        //检查选择文件是否存在
                        if (!File.Exists(filePath))
                        {
                            MessageBox.Show("Please select a valid file", "Info", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                            return;
                        }
                    }
                    //检查是否输入了输出目录
                    if (directoryPath.Length == 0)
                    {
                        MessageBox.Show("Please select target directory", "Info", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        return;
                    }
                    else
                    {
                        //检查输入的输出目录是否存在
                        if (!Directory.Exists(directoryPath))
                        {
                            Directory.CreateDirectory(directoryPath);
                        }
                    }
                    //检查是否输入了密码
                    if (this.passwordTxt.Text.Trim().Length == 0)
                    {
                        MessageBox.Show("Please input password", "Info", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        return;
                    }
                    //获取加密模式(因异步线程)
                    int CipherModeSelectedIndex = -1;
                    if (CipherModeComboBox.InvokeRequired)
                    {
                        CipherModeComboBox.Invoke(new MethodInvoker(delegate { CipherModeSelectedIndex = CipherModeComboBox.SelectedIndex; }));
                    }
                    //选择值为-1则表示未选择
                    if (CipherModeSelectedIndex == -1)
                    {
                        MessageBox.Show("Please select cipher mode", "Info", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        return;
                    }

                    //根据选择的加密模式设置RijndaelManaged算法所需的(enum枚举类型)
                    CipherMode cm = CipherMode.CBC;
                    switch (CipherModeArray[CipherModeSelectedIndex])
                    {
                    case "CBC":
                        cm = CipherMode.CBC;
                        break;

                    case "ECB":
                        cm = CipherMode.ECB;
                        break;

                    case "CFB":
                        cm = CipherMode.CFB;
                        break;
                    }
                    //filePath
                    //获取选择的文件名(包含后缀名)
                    string sourcefileName = filePath.Remove(0, filePath.LastIndexOf("\\") + 1);
                    //获取选择的文件名(不包含后缀名)
                    string sourceFileNameWithoutType = sourcefileName.Remove(sourcefileName.LastIndexOf("."));
                    //获取选择的文件类型名(包含"." 比如".txt")
                    string sourceFileType = sourcefileName.Remove(0, sourcefileName.LastIndexOf("."));

                    string desFileName  = String.Format(@"{0}\{1}", directoryPath, sourcefileName);
                    string tempFileName = sourceFileNameWithoutType;

                    //判断生成的加密文件是否存在,若存在则在文件名后加数字
                    bool needChangeFileName = true;
                    int fileIndex           = 0;
                    while (needChangeFileName)
                    {
                        if (File.Exists(String.Format("{0}{1}", desFileName, cipherFileType)))
                        {
                            desFileName = String.Format("{0}_{1}{2}", tempFileName, ++fileIndex, sourceFileType);
                        }
                        else
                        {
                            needChangeFileName = false;
                        }
                    }
                    //此处已经设定好输出文件完整路径及名称
                    desFileName = String.Format("{0}{1}", desFileName, cipherFileType);

                    //实例化一个EncryptDecryptHelper对象
                    EncryptDecryptHelper edHelper = new EncryptDecryptHelper(filePath, desFileName, this.passwordTxt.Text.Trim(), cm);

                    //添加进程运行时间工具Stopwatch
                    Stopwatch stopWatch = new Stopwatch();
                    stopWatch.Start();//开始计时
                    // 加密运算。rm得到运算结果
                    ResultMsg rm = edHelper.DescryptEncryptHandler(DescrptAndEncrypt.Encrypt);
                    stopWatch.Stop();                     //运算结束
                    TimeSpan ts      = stopWatch.Elapsed; //得到stopWatch所监测到的时间
                    StringBuilder sb = new StringBuilder();

                    //弹出消息框,告知用户结果
                    MessageBox.Show(rm.status ? "Succeed" : "Failure", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information);

                    //以下是记录一些稍微详细的信息,记录在界面右侧Textbox中
                    if (rm.status)
                    {
                        sb.Append(String.Format("{4}{5}Source Filename:{0}\r\nEncrypted Filename:{1}\r\nCipherMode:{2}\r\nOperation time:{3}ms", sourcefileName, desFileName, CipherModeArray[CipherModeSelectedIndex], ts.TotalMilliseconds, this.ResultTxt.Text.Length == 0 ? "" : "\r\n\r\n", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")));
                    }
                    else
                    {
                        sb.Append(String.Format("{0}{1}\r\n{2}", this.ResultTxt.Text.Length == 0 ? "" : "\r\n\r\n", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), rm.msg));
                    }
                    if (ResultTxt.InvokeRequired)
                    {
                        ResultTxt.Invoke(new MethodInvoker(delegate { this.ResultTxt.Text += sb.ToString(); }));
                    }
                });
            }
        }
Exemplo n.º 7
0
        //解密
        private async void button3_Click(object sender, EventArgs e)
        {
            using (_longOperation.Start())
            {
                await Task.Run(() =>
                {
                    string filePath      = this.descryFilePathTxt.Text.Trim();
                    string directoryPath = this.descTargetDirectoryTxt.Text.Trim();

                    //判断是否选择了文件
                    if (filePath.Length == 0)
                    {
                        MessageBox.Show("Please select a file", "Info", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        return;
                    }
                    else
                    {
                        //判断选择文件是否存在
                        if (!File.Exists(filePath))
                        {
                            MessageBox.Show("Please select a valid file", "Info", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                            return;
                        }
                    }
                    //检查选择的输出目录
                    if (directoryPath.Length == 0)
                    {
                        MessageBox.Show("Please select target directory", "Info", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        return;
                    }
                    else
                    {
                        //不存在则创建
                        if (!Directory.Exists(directoryPath))
                        {
                            Directory.CreateDirectory(directoryPath);
                        }
                    }

                    //检查输入的密码
                    if (this.descpasswordTxt.Text.Trim().Length == 0)
                    {
                        MessageBox.Show("Please input password", "Info", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        return;
                    }
                    //检查选择的加密模式
                    int CipherModeSelectedIndex = -1;
                    if (CipherModeComboBox.InvokeRequired)
                    {
                        CipherModeComboBox.Invoke(new MethodInvoker(delegate { CipherModeSelectedIndex = CipherModeComboBox.SelectedIndex; }));
                    }
                    if (CipherModeSelectedIndex == -1)
                    {
                        MessageBox.Show("Please select cipher mode", "Info", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        return;
                    }
                    //同解密,转换为RijndaelManaged所需要CipherMode的枚举类型
                    CipherMode cm = CipherMode.CBC;
                    switch (CipherModeArray[CipherModeSelectedIndex])
                    {
                    case "CBC":
                        cm = CipherMode.CBC;
                        break;

                    case "ECB":
                        cm = CipherMode.ECB;
                        break;

                    case "CFB":
                        cm = CipherMode.CFB;
                        break;
                    }
                    //filePath
                    //得到被加密文件名(包含后缀
                    string sourcefileName = filePath.Remove(0, filePath.LastIndexOf("\\") + 1).Replace(cipherFileType, "");
                    //得到被加密文件的名称(不包含后缀
                    string sourceFileNameWithoutType = sourcefileName.Remove(sourcefileName.LastIndexOf("."));
                    //得到被加密文件的后缀(包含"."
                    string sourceFileType = sourcefileName.Remove(0, sourcefileName.LastIndexOf("."));

                    //设置输出文件完整路径,处理方式和加密运算一致,即存在则加数字
                    string desFileName      = String.Format(@"{0}\{1}", directoryPath, sourceFileNameWithoutType);
                    string tempFileName     = desFileName;
                    bool needChangeFileName = true;
                    int fileIndex           = 0;
                    while (needChangeFileName)
                    {
                        if (File.Exists(String.Format("{0}{1}", desFileName, sourceFileNameWithoutType)))
                        {
                            desFileName = String.Format("{0}_{1}", tempFileName, ++fileIndex);
                        }
                        else
                        {
                            needChangeFileName = false;
                        }
                    }
                    //此处得到解密后文件路径
                    desFileName = String.Format("{0}{1}", desFileName, sourceFileType);
                    //实例化EncryptDecryptHelper
                    EncryptDecryptHelper edHelper = new EncryptDecryptHelper(filePath, desFileName, this.descpasswordTxt.Text.Trim(), cm);
                    //添加Stopwatch监测运行时间
                    Stopwatch stopWatch = new Stopwatch();
                    stopWatch.Start();//stopWatch开始监测
                    //开始加密,并得到结果rm
                    ResultMsg rm = edHelper.DescryptEncryptHandler(DescrptAndEncrypt.Descrpt);
                    stopWatch.Stop();                     //stopWatch停止检测
                    TimeSpan ts      = stopWatch.Elapsed; //得到stopWatch监测时间数据
                    StringBuilder sb = new StringBuilder();
                    //弹出消息框,告知运算结果
                    MessageBox.Show(rm.status ? "Succeed" : "Failure", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    if (rm.status)
                    {
                        sb.Append(String.Format("{4}{5}\r\nSource Filename:{0}\r\nDescrypted Filename:{1}\r\nCipherMode:{2}\r\nOperation time:{3}ms", sourcefileName, desFileName, CipherModeArray[CipherModeSelectedIndex], ts.TotalMilliseconds, this.ResultTxt.Text.Length == 0 ? "" : "\r\n\r\n", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")));
                    }
                    else
                    {
                        sb.Append(String.Format("{0}{1}\r\n{2}", this.ResultTxt.Text.Length == 0 ? "" : "\r\n\r\n", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), rm.msg));
                    }
                    if (ResultTxt.InvokeRequired)
                    {
                        ResultTxt.Invoke(new MethodInvoker(delegate { this.ResultTxt.Text += sb.ToString(); }));
                    }
                });
            }
        }