Пример #1
0
        //开户
        private void button1_Click(object sender, EventArgs e)
        {
            Int64 num=Int64.Parse(textBox1.Text);
            string pwd = textBox2.Text;
            float balance = float.Parse(textBox3.Text);
            string type="";
            if (radioButton1.Checked) type = "world";
            if (radioButton2.Checked) type = "music";
            if (radioButton3.Checked) type = "travel";

            string name = textBox4.Text;
            string address = textBox5.Text;

            Int32 charge=0;
            if (radioButton4.Checked) charge = 10;
            if (radioButton5.Checked) charge = 20;
            if (radioButton6.Checked) charge = 30;

            //封装mobile类
            Mobile mobile = new Mobile();
            mobile.Mobilenumber = num;
            mobile.DateTimeOfMakeCard = DateTime.Now;
            mobile.LastTimePayFor = DateTime.Now;
            mobile.Mobiletype = type;
            mobile.Balance = balance;
            mobile.State = "on";
            mobile.Password = pwd;

            //封装customer类
            Customer customer = new Customer();
            customer.Name = name;
            customer.Address = address;

            //封装Charge类
            ChargeDao chargedao = new ChargeDao();
            Int32 chargeid = chargedao.getId("monthlypay", charge);
            if (chargeid == -1) { MessageBox.Show("保存Charge失败", "失败", MessageBoxButtons.OK, MessageBoxIcon.Error); return; }
            Test.Model.Rule rule = new Test.Model.Rule();
            rule.Chargeid = chargeid;
            rule.Mobilenumber = num;

            MainDao dao = new MainDao();
            string message=dao.save(mobile, customer,rule);
            MessageBox.Show(message, message, MessageBoxButtons.OK, MessageBoxIcon.None);
        }
Пример #2
0
        private void button1_Click(object sender, EventArgs e)
        {
            on = DateTime.Now;
            if (textBox1.Text == "")
            {
                MessageBox.Show("请输入要拨打的电话号码", "wrong", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            if (textBox2.Text == "")
            {
                MessageBox.Show("请输入用户自己的电话号码", "wrong", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            //判断该手机号码是否存在
            MobileDao mobileDao = new MobileDao();
            if (mobileDao.checknumexists(Int64.Parse(textBox1.Text)))
            {
                MessageBox.Show("你要拨打的号码不存在,请再次输入.", "wrong", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            if (mobileDao.checknumexists(Int64.Parse(textBox2.Text)))
            {
                MessageBox.Show("请准确输入你的手机号码", "wrong", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            if (mobileDao.checkState(Int64.Parse(textBox1.Text)))
            {
                MessageBox.Show("你要拨打的号码已经停机或者欠费", "wrong", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            if (mobileDao.checkState(Int64.Parse(textBox2.Text)))
            {
                MessageBox.Show("你的手机已经处于停机或者欠费状态", "wrong", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            //拨打电话前先检查用户手机余额(>=0.2)
            if (!mobileDao.checkBalance(Int64.Parse(textBox2.Text), 0.2f))
            {
                MessageBox.Show("用户余额不足0.2元是没有办法通信的", "wrong", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            this.timer1.Enabled = true;

            //拨打电话每分钟检查一次用户手机的余额
            TimerCallback timerDelegate = new TimerCallback(proxy);
            Mobile mobile = new Mobile();
            timer2 = new System.Threading.Timer(timerDelegate, mobile, 0, 60000);
        }