基本信息
源码名称:智能计算器DEMO(含数字转中文、大写金额)
源码大小:0.07M
文件格式:.rar
开发语言:C#
更新时间:2019-06-19
   友情提示:(无需注册或充值,赞助后即可获取资源下载链接)

     嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):78630559

本次赞助数额为: 2 元 
   源码介绍

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace Counter
{
    public partial class Form1 : Form
    {
        string NowData = DateTime.Now.ToLongDateString();
        string NowTime = DateTime.Now.ToLongTimeString().ToString();
        string Q;
        double NewTB;
        double QQ;
        bool Tab1 = true;  //判定光标位置,TB_1为TRUE,TB_3为FALSE     
        public Form1()
        {
            InitializeComponent();
            System.Diagnostics.Trace.Listeners.Clear();
            System.Diagnostics.Trace.Listeners.Add(new System.Diagnostics.TextWriterTraceListener(NowData   "-Log.txt"));
            System.Diagnostics.Trace.AutoFlush = true;            
        }       

        private void Form1_Load(object sender, EventArgs e)
        {
            System.Diagnostics.Trace.WriteLine(NowTime   "-软件重启");
        }
     
        public void addNum(string num)
        {
            if (TB_1.Text!=""&&TB_2.Text!="")
            {
                TB_3.Text = TB_3.Text   num.ToString();
            }
            else
            {
                TB_1.Text = TB_1.Text   num.ToString();
            }            
        }

        private void BT_DEL_MouseDown(object sender, MouseEventArgs e)
        {
            if (Tab1)
            {
                if (TB_1.TextLength > 0)
                {
                    TB_1.Text = TB_1.Text.Substring(0, TB_1.Text.Length - 1);
                }
            }
            else
            {
                if (TB_3.TextLength > 0)
                {
                    TB_3.Text = TB_3.Text.Substring(0, TB_3.Text.Length - 1);
                }
            }
        }

        private void BT_P_Click(object sender, EventArgs e)
        {
            if ( Tab1 == true)
            {
                if (TB_1.TextLength < 1)
                {
                    TB_1.Text = "0.";
                }
                else if (TB_1.Text.IndexOf(".") <= 0)
                {
                    addNum(".");
                }
            }
            if (Tab1 == false)
            {
                if (TB_3.TextLength < 1)
                {
                    TB_3.Text = "0.";
                    if (TB_3.Text.IndexOf(".") <= 0)
                    {
                        addNum(".");
                    }
                }
            }
        }

        private void BT_0_Click(object sender, EventArgs e)
        {
            if (TB_1.Text != "" && TB_2.Text != "" && TB_3.Text != "" && TB_4.Text != "")
            {
                TB_2.Text = "";
                TB_3.Text = "";
                TB_4.Text = "";
                TB_1.Text = "0";
            }
            else
            {
                addNum("0");
            }
        }

        private void BT_1_Click(object sender, EventArgs e)
        {
            if (TB_1.Text != "" && TB_2.Text != "" && TB_3.Text != "" && TB_4.Text != "")
            {
                TB_2.Text = "";
                TB_3.Text = "";
                TB_4.Text = "";
                this.TB_1.Focus();
                Tab1 = true;
                TB_1.Text = "1";               
            }
            else
            {
                addNum("1");               
            }
        }

        private void BT_2_Click(object sender, EventArgs e)
        {
            if (TB_1.Text != "" && TB_2.Text != "" && TB_3.Text != "" && TB_4.Text != "")
            {
                TB_2.Text = "";
                TB_3.Text = "";
                TB_4.Text = "";
                this.TB_1.Focus();
                Tab1 = true;
                TB_1.Text = "2";
            }
            else
            {
                addNum("2");
            }
        }

        private void BT_3_Click(object sender, EventArgs e)
        {
            if (TB_1.Text != "" && TB_2.Text != "" && TB_3.Text != "" && TB_4.Text != "")
            {
                TB_2.Text = "";
                TB_3.Text = "";
                TB_4.Text = "";
              //  this.TB_1.Focus();
                Tab1 = true;
                TB_1.Text = "3";
            }
            else
            {
                addNum("3");
            }         
        }

        private void BT_4_Click(object sender, EventArgs e)
        {
            if (TB_1.Text != "" && TB_2.Text != "" && TB_3.Text != "" && TB_4.Text != "")
            {
                TB_2.Text = "";
                TB_3.Text = "";
                TB_4.Text = "";
                this.TB_1.Focus();
                Tab1 = true;
                TB_1.Text = "4";
            }
            else
            {
                addNum("4");
            }
        }

        private void BT_5_Click(object sender, EventArgs e)
        {
            if (TB_1.Text != "" && TB_2.Text != "" && TB_3.Text != "" && TB_4.Text != "")
            {
                TB_2.Text = "";
                TB_3.Text = "";
                TB_4.Text = "";
                this.TB_1.Focus();
                Tab1 = true;
                TB_1.Text = "5";
            }
            else
            {
                addNum("5");
            }
        }

        private void BT_6_Click(object sender, EventArgs e)
        {
            if (TB_1.Text != "" && TB_2.Text != "" && TB_3.Text != "" && TB_4.Text != "")
            {
                TB_2.Text = "";
                TB_3.Text = "";
                TB_4.Text = "";
                this.TB_1.Focus();
                Tab1 = true;
                TB_1.Text = "6";
            }
            else
            {
                addNum("6");
            }
        }

        private void BT_7_Click(object sender, EventArgs e)
        {
            if (TB_1.Text != "" && TB_2.Text != "" && TB_3.Text != "" && TB_4.Text != "")
            {
                TB_2.Text = "";
                TB_3.Text = "";
                TB_4.Text = "";
                this.TB_1.Focus();
                Tab1 = true;
                TB_1.Text = "7";
            }
            else
            {
                addNum("7");
            }
        }

        private void BT_8_Click(object sender, EventArgs e)
        {
            if (TB_1.Text != "" && TB_2.Text != "" && TB_3.Text != "" && TB_4.Text != "")
            {
                TB_2.Text = "";
                TB_3.Text = "";
                TB_4.Text = "";
                this.TB_1.Focus();
                Tab1 = true;
                TB_1.Text = "8";
            }
            else
            {
                addNum("8");
            }
        }

        private void BT_9_Click(object sender, EventArgs e)
        {
            if (TB_1.Text != "" && TB_2.Text != "" && TB_3.Text != "" && TB_4.Text != "")
            {
                TB_1.Text = "";
                TB_2.Text = "";
                TB_3.Text = "";
                TB_4.Text = "";
                this.TB_1.Focus();
                Tab1 = true;
                addNum("9");               
            }
            else
            {
                addNum("9");
            }
        }

        private void toolStripMenuItem1_Click(object sender, EventArgs e)
        {
            string dddd = NowData   "-Log.txt";
            if (File.Exists(dddd))
            {
                System.Diagnostics.Process.Start(NowData   "-Log.txt");
            }
        }

        private void TB_1_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (((int)e.KeyChar < 48 || (int)e.KeyChar > 57) && (int)e.KeyChar != 8 && (int)e.KeyChar != 46)
                e.Handled = true;
            if (TB_1.Text != "" && TB_2.Text != "" && TB_3.Text != "" && TB_4.Text != "")
            {
                TB_1.Text = "";
                TB_2.Text = "";
                TB_3.Text = "";
                TB_4.Text = "";
                this.TB_1.Focus();
                Tab1 = true;
            }

            if ((int)e.KeyChar == 46)      //小数点
            {
                if (TB_1.Text.Length <= 0)
                    e.Handled = true;   //小数点不能在第一位                     
                else if (TB_1.Text.IndexOf(".") >= 0)  //包含一个小数点
                {
                    e.Handled = true;
                }
            }
            if ((int)e.KeyChar == 48)    //数字0
            {
                if (TB_1.Text == "0")    //第一个数为0时
                {
                    e.Handled = true;
                }
            }
        }

        private void TB_3_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (((int)e.KeyChar < 48 || (int)e.KeyChar > 57) && (int)e.KeyChar != 8 && (int)e.KeyChar != 46)
                e.Handled = true;
            if (TB_1.Text != "" && TB_2.Text != "" && TB_3.Text != "" && TB_4.Text != ""&& e.Handled == false)
            {
                TB_1.Text = "";
                TB_2.Text = "";
                TB_3.Text = "";
                TB_4.Text = "";
                this.TB_1.Focus();
                Tab1 = true;
            }
            if ((int)e.KeyChar == 46)    //小数点
            {
                if (TB_3.Text.Length <= 0)
                    e.Handled = true;   //小数点不能在第一位                     
                else if (TB_1.Text.IndexOf(".") >= 0)  //包含一个小数点
                {
                    e.Handled = true;
                }
            }
            if ((int)e.KeyChar == 48)    //数字0
            {
                if(TB_3.Text == "0")     //第一个数为0时
                {
                    e.Handled = true;
                }
            }
        }

        private void BT_DIV_Click(object sender, EventArgs e)
        {
            if (TB_4.Text == "")
            {
                TB_2.Text = "÷";
                this.TB_3.Focus();
                Tab1 = false;
            }
            else
            {
                TB_1.Text = TB_4.Text;
                TB_2.Text = "";
                TB_3.Text = "";
                TB_2.Text = "÷";
                this.TB_3.Focus();
                Tab1 = false;
            }
        }

        private void BT_MUL_Click(object sender, EventArgs e)
        {
            if (TB_4.Text == "")
            {
                TB_2.Text = "×";
                this.TB_3.Focus();
                Tab1 = false;
            }
            else
            {
                TB_1.Text = TB_4.Text;
                TB_2.Text = "";
                TB_3.Text = "";
                TB_2.Text = "×";
                this.TB_3.Focus();
                Tab1 = false;
            }
        }

        private void BT_MIN_Click(object sender, EventArgs e)
        {
            if (TB_4.Text == "")
            {
                TB_2.Text = "-";
                this.TB_3.Focus();
                Tab1 = false;
            }
            else
            {
                TB_1.Text = TB_4.Text;
                TB_2.Text = "";
                TB_3.Text = "";                
                TB_2.Text = "-";              
                this.TB_3.Focus();
                Tab1 = false;
            }
        }

        private void BT_ADD_Click(object sender, EventArgs e)
        {
            if (TB_4.Text == "")
            {
                TB_2.Text = " ";
                this.TB_3.Focus();
                Tab1 = false;
            }
            else
            {
                TB_1.Text = TB_4.Text;
                TB_2.Text = "";
                TB_3.Text = "";
                TB_2.Text = " ";
                this.TB_3.Focus();
                Tab1 = false;
            }
        }

        private void BT_CLE_Click(object sender, EventArgs e)
        {
            TB_1.Text = "";
            TB_2.Text = "";
            TB_3.Text = "";
            TB_4.Text = "";
            TB_5.Text = "";
            this.TB_1.Focus();
            Tab1 = true;
        }

        private void BT_EQ_Click(object sender, EventArgs e)
        {
            try
            {
                double X1 = Convert.ToDouble(TB_1.Text);
                double Y1 = Convert.ToDouble(TB_3.Text);
                Count W1 = new Count();
                Count W2 = new Count(X1, Y1);
                if (TB_2.Text == " ")
                {
                    double result = W1.Add(W2);
                    TB_4.Text = Convert.ToString(result);
                    this.TB_1.Focus();
                    Tab1 = true;
                    System.Diagnostics.Trace.WriteLine(NowTime   "——"   TB_1.Text   
                                                       TB_2.Text   TB_3.Text   "="   TB_4.Text);
                }
                else if (TB_2.Text == "-")
                {
                    double result = W1.Min(W2);
                    TB_4.Text = Convert.ToString(result);
                    this.TB_1.Focus();
                    Tab1 = true;
                    System.Diagnostics.Trace.WriteLine(NowTime   "——"   TB_1.Text  
                                                       TB_2.Text   TB_3.Text   "="   TB_4.Text);
                }
                else if (TB_2.Text == "×")
                {
                    double result = W1.Mul(W2);
                    TB_4.Text = Convert.ToString(result);
                    this.TB_1.Focus();
                    Tab1 = true;
                    System.Diagnostics.Trace.WriteLine(NowTime   "——"   TB_1.Text  
                                                       TB_2.Text   TB_3.Text   "="   TB_4.Text);
                }
                else if (TB_2.Text == "÷")
                {
                    double result = W1.Div(W2);
                    TB_4.Text = Convert.ToString(result);
                    this.TB_1.Focus();
                    Tab1 = true;
                    System.Diagnostics.Trace.WriteLine(NowTime   "——"   TB_1.Text  
                                                       TB_2.Text   TB_3.Text   "="   TB_4.Text);
                }
                else
                {
                    MessageBox.Show("无算术符");
                }
            }
            catch(Exception Error)
            {
                System.Diagnostics.Trace.WriteLine(NowTime   "-"  Error.Message);
                MessageBox.Show("输入有误");
            }
        }

        private void Form1_KeyDown(object sender, KeyEventArgs e)
        {
            Keys KEY = e.KeyCode;
            switch (KEY)
            {
                case Keys.Enter:
                    BT_EQ_Click(sender, e);
                    e.Handled = true;
                    break;
                case Keys.Add:
                    BT_ADD_Click(sender, e);
                    e.Handled = true;
                    break;
                case Keys.Subtract:
                    BT_MIN_Click(sender, e);
                    e.Handled = true;
                    break;
                case Keys.Multiply:
                    BT_MUL_Click(sender, e);
                    e.Handled = true;
                    break;
                case Keys.Divide:
                    BT_DIV_Click(sender, e);
                    e.Handled = true;
                    break;
                case Keys.Space:
                    BT_CN_Click(sender, e);
                    e.Handled = true;
                    break;
                case Keys.ShiftKey:
                    BT_CLE_Click(sender, e);
                    e.Handled = true;
                    break;
                default:
                    break;
            }
        }

        private void BT_CN_Click(object sender, EventArgs e)
        {
            if (TB_4.Text != "")
            {
                 NewTB = Convert.ToDouble(TB_4.Text);
            }          
            else if (TB_1.Text != "")
            {
                NewTB = Convert.ToDouble(TB_1.Text);
            }
            if (NewTB >= 0 && NewTB - (int)NewTB == 0 && NewTB < 100000000) //无小数点
            {
                Q = Convert.ToString(NewTB);
                if (Q != null)
                {                   
                    if (NewTB >= 0 && NewTB < 100000000)
                    {
                        ToCn W1 = new ToCn();
                        ToCn W2 = new ToCn(Q);
                        string W = W1.Text(W2);
                        TB_5.Text = Convert.ToString(W);
                        System.Diagnostics.Trace.WriteLine(NowTime   "-"   TB_5.Text);
                    }
                }
            }
            if (NewTB >= 0 && NewTB - (int)NewTB != 0 && NewTB < 100000000) //有小数点
            {
                NewTB = (Int64)(NewTB * 100   0.5);  //四舍五入
                Q = Convert.ToString(NewTB);               
                if (NewTB >= 0 && NewTB < 100000000)
                {
                    ToCn W1 = new ToCn();
                    ToCn W2 = new ToCn(Q);
                    string W = W1.Text2(W2);
                    TB_5.Text = Convert.ToString(W);
                    System.Diagnostics.Trace.WriteLine(NowTime   "-"   TB_5.Text);
                }
            }
            else if (NewTB < 0)
            {
                MessageBox.Show("数值太小");
            }
            else if (NewTB >= 100000000)
            {
                MessageBox.Show("数值太大");
            }
        }

        private void toolStripMenuItem2_Click(object sender, EventArgs e)
        {
            new Form2().Show();
        }

        private void TB_5_DoubleClick(object sender, EventArgs e)
        {
            if (TB_5.Text != "")
            {
                Clipboard.SetText(TB_5.Text.Trim());
            }
        }

        private void TB_1_MouseClick(object sender, MouseEventArgs e)
        {
            this.TB_1.Focus();
            Tab1 = true;
        }

        private void TB_3_MouseClick(object sender, MouseEventArgs e)
        {
            this.TB_3.Focus();
            Tab1 = false;
        }
      
    }
}