public string save(Mobile mobile,Customer customer,Rule rule) { MobileDao mobileDao = new MobileDao(); if(!mobileDao.save(mobile)) return "保存mobile失败"; CustomerDao customerDao = new CustomerDao(); customerDao.save(customer); Int32 customerid = customerDao.getId(); if (customerid == -1) return "保存Customer失败"; RuleDao ruleDao = new RuleDao(); if (!ruleDao.save(rule)) return "保存Rule失败"; Account account = new Account(); account.Mobilenumber = mobile.Mobilenumber; account.Customerid = customerid; AccountDao accountDao = new AccountDao(); if (!accountDao.save(account)) return "保存Account失败"; else return "开户成功"; }
private void button3_Click(object sender, EventArgs e) { Int64 num = Int64.Parse(textBox6.Text); string name; Int32 chargepermonth; if (checkBox1.Checked) { name = "gprs"; chargepermonth = 10; } else if (checkBox2.Checked) { name = "music"; chargepermonth = 2; } else { MessageBox.Show("请选择要开通的业务类型", "warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } ChargeDao chargedao = new ChargeDao(); Int32 chargeid = chargedao.getId(name, chargepermonth, 2); Test.Model.Rule rule = new Test.Model.Rule(); rule.Chargeid = chargeid; rule.Mobilenumber = num; RuleDao ruleDao = new RuleDao(); //首先判断是否已经开通了该业务 if (!ruleDao.check(num,chargeid)) { MessageBox.Show("你已经开通同该业务,无需重复操作", "wrong", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } MobileDao mobileDao = new MobileDao(); //然后判断用户的余额是否足够 if (!mobileDao.checkBalance(num,chargepermonth)) { MessageBox.Show("你的余额不足,无法开通该业务", "wrong", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } ruleDao.save(rule); //进行扣费 mobileDao.koufei(num,chargepermonth); MessageBox.Show("新业务开通成功,从即日起每个月进行相关扣费"); }