zoukankan      html  css  js  c++  java
  • C#三层ATM-13.ATM开户

    ATM开户功能

    1. DAL-userInfo—GetModel

    /// <summary>

    /// 用身份证号查询得到一个对象实体

    /// </summary>

    public Model.userInfo GetModel(string PID)

            {

    StringBuilder strSql = new StringBuilder();

                strSql.Append("select  top 1  ");

                strSql.Append(" customerID,customerName,pID,telephone,address ");

                strSql.Append(" from userInfo ");

                strSql.Append(" where pID='" + PID + "'");

                Model.userInfo model = new Model.userInfo();

    DataSet ds = DbHelperSQL.Query(strSql.ToString());

    if (ds.Tables[0].Rows.Count > 0)

                {

    return DataRowToModel(ds.Tables[0].Rows[0]);

                }

    else

                {

    return null;

                }

            }

    /// <summary>

    /// 得到一个对象实体

    /// </summary>

    public Model.userInfo DataRowToModel(DataRow row)

    {

    Model.userInfo model=new Model.userInfo();

    if (row != null)

    {

    if(row["customerID"]!=null && row["customerID"].ToString()!="")

    {

    model.customerID=int.Parse(row["customerID"].ToString());

    }

    if(row["customerName"]!=null)

    {

    model.customerName=row["customerName"].ToString();

    }

    if(row["pID"]!=null)

    {

    model.pID=row["pID"].ToString();

    }

    if(row["telephone"]!=null)

    {

    model.telephone=row["telephone"].ToString();

    }

    if(row["address"]!=null)

    {

    model.address=row["address"].ToString();

    }

    }

    return model;

    }

    2. DAL-userInfo—Add

    /// <summary>

    /// 增加一条数据

    /// </summary>

    public int Add(Model.userInfo model)

    {

    StringBuilder strSql=new StringBuilder();

    StringBuilder strSql1=new StringBuilder();

    StringBuilder strSql2=new StringBuilder();

    if (model.customerName != null)

    {

    strSql1.Append("customerName,");

    strSql2.Append("'"+model.customerName+"',");

    }

    if (model.pID != null)

    {

    strSql1.Append("pID,");

    strSql2.Append("'"+model.pID+"',");

    }

    if (model.telephone != null)

    {

    strSql1.Append("telephone,");

    strSql2.Append("'"+model.telephone+"',");

    }

    if (model.address != null)

    {

    strSql1.Append("address,");

    strSql2.Append("'"+model.address+"',");

    }

    strSql.Append("insert into userInfo(");

    strSql.Append(strSql1.ToString().Remove(strSql1.Length - 1));

    strSql.Append(")");

    strSql.Append(" values (");

    strSql.Append(strSql2.ToString().Remove(strSql2.Length - 1));

    strSql.Append(")");

    strSql.Append(";select @@IDENTITY");

    object obj = DbHelperSQL.GetSingle(strSql.ToString());

    if (obj == null)

    {

    return 0;

    }

    else

    {

    return Convert.ToInt32(obj);

    }

    }

    3. DAL- transInfo—Add  (若此方法已经有了,就不要加了)

    /// <summary>

    /// 增加一条数据

    /// </summary>

    public bool Add(Model.transInfo model)

    {

    StringBuilder strSql=new StringBuilder();

    StringBuilder strSql1=new StringBuilder();

    StringBuilder strSql2=new StringBuilder();

    if (model.transDate != null)

    {

    strSql1.Append("transDate,");

    strSql2.Append("'"+model.transDate+"',");

    }

    if (model.cardID != null)

    {

    strSql1.Append("cardID,");

    strSql2.Append("'"+model.cardID+"',");

    }

    if (model.transType != null)

    {

    strSql1.Append("transType,");

    strSql2.Append("'"+model.transType+"',");

    }

    if (model.transMoney != null)

    {

    strSql1.Append("transMoney,");

    strSql2.Append(""+model.transMoney+",");

    }

    if (model.remark != null)

    {

    strSql1.Append("remark,");

    strSql2.Append("'"+model.remark+"',");

    }

    strSql.Append("insert into transInfo(");

    strSql.Append(strSql1.ToString().Remove(strSql1.Length - 1));

    strSql.Append(")");

    strSql.Append(" values (");

    strSql.Append(strSql2.ToString().Remove(strSql2.Length - 1));

    strSql.Append(")");

    int rows=DbHelperSQL.ExecuteSql(strSql.ToString());

    if (rows > 0)

    {

    return true;

    }

    else

    {

    return false;

    }

    }

    4. DAL- cardinfo—Add

    /// <summary>

    /// 获取最新开卡人的账号

    /// </summary>

    /// <returns></returns>

    public string getMaxCardID()

            {

    string s = "";

    string sql = "select top 1 cardID from cardinfo order by openDate desc";

    object obj=  DbHelperSQL.GetSingle(sql);

    if (!Object.Equals(obj, null))

                {

                    s = obj.ToString();

                }

    return s;

            }

    /// <summary>

    /// 增加一条数据

    /// </summary>

    public bool Add(Model.cardinfo model,out string cardID)

    {

    StringBuilder strSql=new StringBuilder();

    StringBuilder strSql1=new StringBuilder();

    StringBuilder strSql2=new StringBuilder();

                cardID = "";

    //62212611  。1-6表示银行 7-8省份。9-15位才是自己的账户号,最后一位仍然是校验码  。中间7位

    //获取最新的银行卡号。新卡的账号。是卡号9-15位的数字+1.。最后一位是随机数

    string ss=  getMaxCardID();

    if (ss == "") { cardID = "622126110000001"; } //第一个开卡的人

    else

                {

    int   xx = int.Parse(ss.Substring(8, 7)) + 1;

    if (xx == 10000000) { return false; }//超额了

                    cardID = ss.Substring(0, 8) + xx.ToString("D7");

                }

    Random r = new Random();

                cardID = cardID + r.Next(0, 10);

                model.cardID= cardID;

    if (model.cardID != null)

    {

    strSql1.Append("cardID,");

    strSql2.Append("'"+model.cardID+"',");

    }

    if (model.curType != null)

    {

    strSql1.Append("curType,");

    strSql2.Append("'"+model.curType+"',");

    }

    if (model.savingType != null)

    {

    strSql1.Append("savingType,");

    strSql2.Append("'"+model.savingType+"',");

    }

    if (model.openDate != null)

    {

    strSql1.Append("openDate,");

    strSql2.Append("'"+model.openDate+"',");

    }

    if (model.openMoney != null)

    {

    strSql1.Append("openMoney,");

    strSql2.Append(""+model.openMoney+",");

    }

    if (model.balance != null)

    {

    strSql1.Append("balance,");

    strSql2.Append(""+model.balance+",");

    }

    if (model.pass != null)

    {

    strSql1.Append("pass,");

    strSql2.Append("'"+model.pass+"',");

    }

    if (model.IsReportLoss != null)

    {

    strSql1.Append("IsReportLoss,");

    strSql2.Append(""+(model.IsReportLoss? 1 : 0) +",");

    }

    if (model.customerID != null)

    {

    strSql1.Append("customerID,");

    strSql2.Append(""+model.customerID+",");

    }

    strSql.Append("insert into cardinfo(");

    strSql.Append(strSql1.ToString().Remove(strSql1.Length - 1));

    strSql.Append(")");

    strSql.Append(" values (");

    strSql.Append(strSql2.ToString().Remove(strSql2.Length - 1));

    strSql.Append(")");

    int rows=DbHelperSQL.ExecuteSql(strSql.ToString());

    if (rows > 0)

    {

    //增加交易记录

                    Model.transInfo t = new Model.transInfo();

                    t.cardID = model.cardID;

                    t.transDate = model.openDate;

                    t.transMoney = model.openMoney;

                    t.transType = "存入";

                    t.remark = "开户存入";

                    DAL.transInfo dalt = new DAL.transInfo();

                    dalt.Add(t);

    return true;

    }

    else

    {

    return false;

    }

    }

    5. BLL- userinfo—GetModel

    public Model.userInfo GetModel(string PID)

            {

    return dal.GetModel(PID);

            }

    6. BLL- userinfo—Add

    /// <summary>

    /// 增加一条数据

    /// </summary>

    public int  Add(Model.userInfo model)

    {

    return dal.Add(model);

    }

    7. BLL- cardinfo—Add

    /// <summary>

    /// 增加一条数据

    /// </summary>

    public bool Add(Model.cardinfo model,out string CardID)

    {

    return dal.Add(model,out CardID);

    }

    8. WinF- NewCard窗体-增加字段

    private int CustomerID = 0;//用户ID

    public string CardID;//卡号

    9. WinF- NewCard窗体-查询身份证按钮

    private void button1_Click(object sender, EventArgs e)

            {

                label8.Text ="";

                textBox2.Text ="";

                textBox3.Text = "";

                textBox4.Text = "";

    string pid = textBox1.Text;

                BLL.userInfo bll = new BLL.userInfo();

                Model.userInfo model= bll.GetModel(pid);

    if (model != null)

                {

                    textBox2.Text = model.customerName;

                    textBox3.Text = model.telephone;

                    textBox4.Text = model.address;

                    CustomerID = model.customerID;

                    label8.Text ="老客户,基本信息不用重填";

                }

    else

                { label8.Text=  "新客户,请填基本信息"; }

            }

    10. WinF- NewCard窗体-开户按钮

    private void button2_Click(object sender, EventArgs e)

            {

                label9.Text = "";

    string acctype=comboBox1.Text;

    decimal opennnum=numericUpDown1.Value;

    string pwd = textBox5.Text;

                Model.cardinfo model = new Model.cardinfo();

                model.cardID ="";

                model.curType = "RMB";

                model.customerID = CustomerID;

                model.IsReportLoss = false;

                model.savingType = acctype;

                model.openDate = DateTime.Now;

                model.openMoney = opennnum;

                model.balance = opennnum;

                model.pass = pwd;

    bool openOK;

    if (CustomerID != 0)//身份证已注册

                {

                    BLL.cardinfo bll = new BLL.cardinfo();

                    openOK= bll.Add(model,out CardID);

                }

    else

                {

    string name = textBox2.Text;

    string pid = textBox1.Text;

    string tel = textBox3.Text;

    string add = textBox4.Text;

                    Model.userInfo modelU = new Model.userInfo();

                    modelU.customerID = 0;

                    modelU.customerName = name;

                    modelU.pID = pid;

                    modelU.telephone = tel;

                    modelU.address = add;

                    BLL.userInfo bllU = new BLL.userInfo();

                    CustomerID= bllU.Add(modelU);

                    model.customerID = CustomerID;

                    BLL.cardinfo bll = new BLL.cardinfo();

                    openOK = bll.Add(model, out CardID);

                }

    if (openOK) {

                    label9.Text = "注册成功,卡号是:" + CardID + ",请前去登录!";

    Clipboard.SetText(CardID);//剪贴板

                }

    else { label9.Text = "注册失败,下次再来!"; }

            }

    11. WinF- main窗体-开户菜单

    private void 新开户ToolStripMenuItem_Click(object sender, EventArgs e)

            {

    NewCard nc = new NewCard();

                nc.ShowDialog();

            }

  • 相关阅读:
    两套经典的用户画像-梁宁
    准研一假期的减脂半自律计划
    网络科学导论【第六章】读书脑图
    常见规则网络
    网络科学导论【第五章】读书脑图
    复杂网络链路预测的研究现状及展望
    Python之@property详解及底层实现介绍
    Python触发异常
    一份较认可的文献阅读方案
    HITS算法简介
  • 原文地址:https://www.cnblogs.com/lingr/p/5563572.html
Copyright © 2011-2022 走看看