示例#1
0
        //
        public static bool AddPayType(PayTypeItem item)
        {
            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}')",
                                              item.PayType, item.Description);
                SqlCommand comm = new SqlCommand(cmdTxt, conn);
                comm.ExecuteNonQuery();
                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
            finally
            {
                //关闭连接
                conn.Close();
            }
        }
示例#2
0
        private void btnDelType_Click(object sender, EventArgs e)
        {
            //如果没有选中任何方式,则不删除,直接退出
            if (this.lstUseType.SelectedItem == null)
            {
                return;
            }
            //获取选中的支付方式
            PayTypeItem item = (PayTypeItem)this.lstUseType.SelectedItem;

            //通过BankCardAccessor删除支付方式
            if (BankCardSQL.DeletePayType(item.PayType))
            {
                this.btnLoadType_Click(null, null);
                //删除成功提示成功
                MessageBox.Show(this, "删除支付方式:" + item.PayType + ",成功!", "提示",
                                MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else
            {
                //删除失败,提示失败
                MessageBox.Show(this, "删除支付方式:" + item.PayType + ",失败!", "提示",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
示例#3
0
        // 获取数据库中已有的方式列表
        public static List <PayTypeItem> LoadPayTypeList()
        {
            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 = "SELECT [方式], [说明] FROM [方式表] ";
                SqlCommand    comm   = new SqlCommand(cmdTxt, conn);
                SqlDataReader dr;
                dr = comm.ExecuteReader();
                List <PayTypeItem> typeList = new List <PayTypeItem>();
                while (dr.Read())
                {
                    PayTypeItem item = new PayTypeItem();
                    item.PayType     = dr.GetString(0);
                    item.Description = dr.GetString(1);
                    typeList.Add(item);
                }
                return(typeList);
            }
            catch (Exception)
            {
                return(null);
            }
            finally
            {
                //关闭连接
                conn.Close();
            }
        }
示例#4
0
 private void lstUseType_SelectedIndexChanged(object sender, EventArgs e)
 {
     //如果有选中的支付方式,则更新
     if (this.lstUseType.SelectedItem != null)
     {
         //获取选中的支付方式
         PayTypeItem item = (PayTypeItem)this.lstUseType.SelectedItem;
         //将支付方式的名称和说明显示到界面
         this.tbUseType.Text    = item.PayType;
         this.tbUseTypeDes.Text = item.Description;
     }
 }
示例#5
0
        private void btnAddType_Click(object sender, EventArgs e)
        {
            //检查方式名称的合法性
            if (string.IsNullOrEmpty(this.tbUseType.Text))
            {
                MessageBox.Show(this, "请输入正确的方式名称,不能已经存在,也不能为空!", "提示",
                                MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            //检查方式说明的合法性
            if (string.IsNullOrEmpty(this.tbUseTypeDes.Text))
            {
                MessageBox.Show(this, "请输入正确的方式说明,不能为空!", "提示",
                                MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            //创建方式对象
            PayTypeItem item = new PayTypeItem();

            //获取新方式数据
            item.PayType     = this.tbUseType.Text.Trim();
            item.Description = this.tbUseTypeDes.Text.Trim();
            //添加到数据库
            if (BankCardSQL.AddPayType(item))
            {
                //重新加载方式列表
                this.btnLoadType_Click(null, null);
                //删除成功提示成功
                MessageBox.Show(this, "添加支付方式:" + item.PayType + ",成功!", "提示",
                                MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else
            {
                //删除成功提示成功
                MessageBox.Show(this, "添加支付方式:" + item.PayType + ",失败!", "提示",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }