zoukankan      html  css  js  c++  java
  • 餐桌项目删除餐桌

     1 using System;
     2 using System.Collections.Generic;
     3 using System.ComponentModel;
     4 using System.Data;
     5 using System.Drawing;
     6 using System.Linq;
     7 using System.Text;
     8 using System.Threading.Tasks;
     9 using System.Windows.Forms;
    10 using System.Data.SqlClient;
    11 
    12 
    13 namespace 餐厅复习
    14 {
    15     public partial class Form1 : Form
    16     {
    17         public Form1()
    18         {
    19             InitializeComponent();
    20         }
    21 
    22         private void Form1_Load(object sender, EventArgs e)
    23         {
    24             LoadDeskInfoByDelId(0);
    25 
    26         }
    27         string str = "Data Source=.;Initial Catalog=mysql;Integrated Security=True";
    28         private void LoadDeskInfoByDelId(int p)
    29         {
    30             //查询
    31             List<DeskInfo> list = new List<DeskInfo>();
    32             
    33             string sql = "select * from DeskInfo where DeskDelFlag =" + p;
    34             SqlConnection con = new SqlConnection(str);
    35             con.Open();
    36             SqlCommand cmd = new SqlCommand(sql, con);
    37             SqlDataReader reader = cmd.ExecuteReader();
    38             if (reader.HasRows)
    39             {
    40                 while (reader.Read())
    41                 {
    42                     list.Add(new DeskInfo()
    43                                    {
    44                                        DeskId = Convert.ToInt32(reader["DeskId"]),
    45                                        DeskName = reader["DeskName"].ToString(),
    46                                        DeskNamePinYin = reader["DeskNamePinYin"].ToString(),
    47                                        DeskNum = reader["DeskNum"].ToString()
    48                                    });
    49                 }
    50             }
    51             dgv.DataSource = list;
    52             dgv.Rows[0].Selected = false;
    53             dgv.AutoGenerateColumns = false;
    54 
    55             con.Dispose();
    56             cmd.Dispose();
    57             reader.Dispose();
    58         }
    59 
    60         private void btnOK_Click(object sender, EventArgs e)
    61         {
    62             //添加
    63             string sql = string.Format("insert into DeskInfo(DeskName,DeskNamePinYin,DeskDelFlag,DeskNum) values ('{0}','{1}',0,'{2}')",txtName.Text,txtPinYin.Text,txtNum.Text);
    64             SqlConnection con = new SqlConnection(str);
    65             con.Open();
    66             SqlCommand cmd = new SqlCommand(sql,con);
    67             cmd.ExecuteNonQuery();
    68             LoadDeskInfoByDelId(0);
    69             con.Dispose();
    70             cmd.Dispose();
    71         }
    72 
    73         private void btnDel_Click(object sender, EventArgs e)
    74         {
    75             //删除
    76             int delId = Convert.ToInt32(dgv.SelectedRows[0].Cells[0].Value);
    77             string sql = "update DeskInfo set DeskDelFlag = 1 where DeskId = " + delId;
    78             SqlConnection con = new SqlConnection(str);
    79             con.Open();
    80             SqlCommand cmd = new SqlCommand(sql,con);
    81             cmd.ExecuteNonQuery();
    82             LoadDeskInfoByDelId(0);
    83 
    84 
    85 
    86             con.Dispose();
    87             cmd.Dispose();
    88         }
    89 
    90 
    91 
    92     }
    93 }
  • 相关阅读:
    推荐一款作图工具
    web应用中幂等性的学习
    读书笔记:重构原则
    /usr/bin/ld: cannot find -lc错误原因及解决方法
    ar命令学习
    Linux下C语言编程中库的使用
    idea实战技巧
    intelj idea中除了Find Usage外的另一种查找级联调用的方法
    jenkins构建,拉取不到最新版本代码,报clock of the subversion server appears to be out of sync
    服务器出现大量close_wait,我们来说说到底是怎么回事?(以tomcat为例)
  • 原文地址:https://www.cnblogs.com/Jacklovely/p/5648432.html
Copyright © 2011-2022 走看看