Ejemplo n.º 1
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            //判断卡号是否合法
            if (string.IsNullOrEmpty(this.mtbCardNo.Text.Trim()))
            {
                MessageBox.Show("请输入合法的银行卡号!", "提示",
                                MessageBoxButtons.OK, MessageBoxIcon.Information);
                //让卡号输入框获得焦点
                this.mtbCardNo.Focus();
                return;
            }

            //构建要保存的银行卡对象
            BankCardClass bkInfo = new BankCardClass();

            bkInfo.Balance  = (decimal)this.nudBalance.Value;
            bkInfo.BankName = this.cmbBank.Text;
            bkInfo.CardNo   = this.mtbCardNo.Text.Trim();
            bkInfo.Name     = this.name;

            //保存新银行卡到数据库,根据结果提示
            if (BankCardSQL.AddBankCards(bkInfo))
            {
                MessageBox.Show("添加银行卡:" + bkInfo.CardNo + ",成功!", "提示",
                                MessageBoxButtons.OK, MessageBoxIcon.Information);
                this.DialogResult = DialogResult.OK;
            }
            else
            {
                MessageBox.Show("添加银行卡:" + bkInfo.CardNo + ",失败!", "提示",
                                MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
Ejemplo n.º 2
0
        private void btnDelCard_Click(object sender, EventArgs e)
        {
            //判断是否有选中的银行卡
            if (this.treeBankCard.SelectedNode == null)
            {
                MessageBox.Show(this, "请选中要删除的银行卡!", "提示",
                                MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            //获取选中的银行卡
            BankCardClass bk = (BankCardClass)this.treeBankCard.SelectedNode.Tag;

            //删除前确认
            if (MessageBox.Show(this, "你真的要删除银行卡:" + bk.CardNo + "?", "提示",
                                MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
            {
                return;
            }
            if (BankCardSQL.DeleteBankCard(bk.CardNo))
            {
                MessageBox.Show(this, "删除银行卡:" + bk.CardNo + ",成功!", "提示",
                                MessageBoxButtons.OK, MessageBoxIcon.Information);
                this.LoadBankCardList();
            }
            else
            {
                MessageBox.Show(this, "删除银行卡:" + bk.CardNo + ",失败!", "提示",
                                MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
Ejemplo n.º 3
0
        public static bool AddBankCards(BankCardClass bkInfo)
        {
            string        connString = @"Data Source=(LocalDB)\v11.0;AttachDbFilename=""E:\c++练习\MyMoneyAgent - 副本 (2) - 副本\MyMoneyAgent\MyMoney.mdf"";Integrated Security=True";
            SqlConnection conn       = new SqlConnection(connString);

            try
            {
                conn.Open();
                //执行删除命令
                string cmdTxt = string.Format("INSERT INTO [银行卡] VALUES('{0}','{1}','{2}',{3})",
                                              bkInfo.CardNo, bkInfo.Name, bkInfo.BankName, bkInfo.Balance);
                SqlCommand comm = new SqlCommand(cmdTxt, conn);
                comm.ExecuteNonQuery();
                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
            finally
            {
                //关闭连接
                conn.Close();
            }
        }
Ejemplo n.º 4
0
        public static bool MdyBankCards(BankCardClass bkInfo)
        {
            string        connString = @"Data Source=(LocalDB)\v11.0;AttachDbFilename=""E:\c++练习\MyMoneyAgent - 副本 (2) - 副本\MyMoneyAgent\MyMoney.mdf"";Integrated Security=True";
            SqlConnection conn       = new SqlConnection(connString);

            try
            {
                conn.Open();
                //执行删除命令
                string cmdTxt = string.Format("UPDATE [银行卡] SET [余额]={0} WHERE [卡号]='{1}'",
                                              bkInfo.Balance, bkInfo.CardNo);
                SqlCommand comm = new SqlCommand(cmdTxt, conn);
                comm.ExecuteNonQuery();
                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
            finally
            {
                //关闭连接
                conn.Close();
            }
        }
Ejemplo n.º 5
0
        private void treeBankCard_AfterSelect(object sender, TreeViewEventArgs e)
        {
            //获取选中银行卡
            BankCardClass bkInfo = (BankCardClass)e.Node.Tag;

            //清除原有内容
            this.dgvCardOps.Rows.Clear();
            //显示银行卡记录
            int newRowIndex = this.dgvCardOps.Rows.Add();

            this.dgvCardOps["colBankNo", newRowIndex].Value       = bkInfo.CardNo;
            this.dgvCardOps["colBankName", newRowIndex].Value     = bkInfo.BankName;
            this.dgvCardOps["colBankBanlance", newRowIndex].Value = bkInfo.Balance.ToString("f2") + "¥";
        }
Ejemplo n.º 6
0
        private void btnMdyBanlance_Click(object sender, EventArgs e)
        {
            //判断是否有选中的银行卡
            if (this.treeBankCard.SelectedNode == null)
            {
                MessageBox.Show(this, "请先选中要修改的银行卡!", "提示",
                                MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            //获取被选中的银行卡
            BankCardClass bkInfo = (BankCardClass)this.treeBankCard.SelectedNode.Tag;
            //创建修改对话框
            ModifyBankCardForm dlg = new ModifyBankCardForm(bkInfo);

            //显示修改银行卡余额界面,成功则重新加载银行卡列表
            if (dlg.ShowDialog(this) == DialogResult.OK)
            {
                this.LoadBankCardList();
            }
        }
Ejemplo n.º 7
0
        public static List <BankCardClass> LoadBankCardList(string name)
        {
            string        connString = @"Data Source=(LocalDB)\v11.0;AttachDbFilename=""E:\c++练习\MyMoneyAgent - 副本 (2) - 副本\MyMoneyAgent\MyMoney.mdf"";Integrated Security=True";
            SqlConnection conn       = new SqlConnection(connString);//创建链接对象

            try
            {
                conn.Open();
                List <BankCardClass> bkLst = new List <BankCardClass>();
                string        cmdTxt       = "SELECT [卡号], [开户银行], [余额] FROM [银行卡] WHERE [姓名]='" + name + "'";
                SqlCommand    comm         = new SqlCommand(cmdTxt, conn);
                SqlDataReader dr           = comm.ExecuteReader();
                while (dr.Read())
                {
                    string        id      = dr.GetString(0);
                    string        bk      = dr.GetString(1);
                    decimal       balance = dr.GetDecimal(2);
                    BankCardClass bkinfo  = new BankCardClass();
                    bkinfo.Balance  = balance;
                    bkinfo.BankName = bk;
                    bkinfo.CardNo   = id;
                    bkinfo.Name     = name;
                    bkLst.Add(bkinfo);
                }
                return(bkLst);
            }
            catch (Exception)
            {
                return(null);
            }
            finally
            {
                //关闭连接
                conn.Close();
            }
        }
Ejemplo n.º 8
0
 public ModifyBankCardForm(BankCardClass bkInfo)
 {
     InitializeComponent();
     this.bkInfo = bkInfo;
 }