m0_46875729 2021-06-08 08:43 采纳率: 50%
浏览 42
已采纳

如何对一卡通系统进行优化?

  private void 确认充值_Click(object sender, EventArgs e)
        {
            try
            {
                string sql;
                string connString = @"Server=LAPTOP-8DBAVB04;Database=keke;Trusted_Connection=Yes;";
                SqlConnection myconn = new SqlConnection(connString);
                myconn.Open();
                SqlCommand mycomm = new SqlCommand();
                mycomm.Connection = myconn;
                sql = "insert into Recharge_record(userNo,boadminPwd,rechargeTime) values(@userNo,@boadminPwd,@rechargeTime)";
                mycomm.CommandText = sql;
                mycomm.Parameters.AddRange(
                new SqlParameter[]
                {
                new SqlParameter("@userNo",SqlDbType.VarChar){Value=this.卡No.Text},
                new SqlParameter("@boadminPwd",SqlDbType.Float){Value=this.money.Text},
                new SqlParameter("@rechargeTime",SqlDbType.VarChar){Value=DateTime.Now.ToString("yyyy-MM-dd") },
            });
                int cnt;
                cnt = mycomm.ExecuteNonQuery();
                if (cnt > 0)
                    MessageBox.Show("充值成功!");
                else
                    MessageBox.Show("充值失败!");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void 确认查询_Click(object sender, EventArgs e)
        {
            try
            {
                string sql;
                string connString = @"Server=LAPTOP-8DBAVB04;Database=keke;Trusted_Connection=Yes;";
                SqlConnection myconn = new SqlConnection(connString);
                myconn.Open();
                SqlCommand mycomm = new SqlCommand();
                mycomm.Connection = myconn;
                sql = "select * from Recharge_record where userNo like '%@userNo%'";
                sql = sql.Replace("@userNo", 输入框_查询.Text.Trim());
                mycomm.CommandText = sql;
                SqlDataAdapter dr = new SqlDataAdapter(mycomm);
                DataTable table = new DataTable();
                dr.Fill(table);
                this.查询框_充值记录.DataSource = table.DefaultView;
                myconn.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void 查询全部_Click(object sender, EventArgs e)
        {
            try
            {
                string sql;
                string connString = @"Server=LAPTOP-8DBAVB04;Database=keke;Trusted_Connection=Yes;";
                SqlConnection myconn = new SqlConnection(connString);
                myconn.Open();
                SqlCommand mycomm = new SqlCommand();
                mycomm.Connection = myconn;
                sql = "select userNo,boadminPwd,rechargeTime from Recharge_record";
                mycomm.CommandText = sql;
                SqlDataAdapter dr = new SqlDataAdapter(mycomm);
                DataTable table = new DataTable();
                dr.Fill(table);
                this.查询框_充值记录.DataSource = table.DefaultView;
                myconn.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void 卡No_TextChanged(object sender, EventArgs e)
        {
            int count = 卡No.Text.Length;
            if (count == 8)
            {
                try
                {
                    int.Parse(卡No.Text);
                }
                catch
                {
                    MessageBox.Show("只能输入数字!");
                    卡No.Text = null;
                }
            }
        }

        private void 充值金额_TextChanged(object sender, EventArgs e)
        {
            int imax = 200;
            if(money.Text !=null && money.Text != "")
            {
                if (int.Parse(money.Text) > imax)
                {
                    MessageBox.Show("充值金额不能大于200!");
                    money.Text = (0).ToString();
                }
            }
        }
 

  • 写回答

3条回答 默认 最新

  • CSDN专家-Fay 2021-06-08 08:44
    关注

    题主说的优化具体指什么,性能优化,功能优化,还是代码优化

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥170 如图所示配置eNSP
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改
  • ¥20 wireshark抓不到vlan
  • ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真
  • ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持
  • ¥15 stata安慰剂检验作图但是真实值不出现在图上
  • ¥15 c程序不知道为什么得不到结果
  • ¥15 键盘指令混乱情况下的启动盘系统重装