⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 admin_add.cs

📁 这是一个公交查询系统
💻 CS
字号:
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;

/// <summary>
/// Admin_Add 的摘要说明
/// </summary>
public class Admin_Add
{
	public Admin_Add()
	{
		//
		// TODO: 在此处添加构造函数逻辑
		//
	}
    public static SqlConnection createConn()
    {
        return new SqlConnection("server=(local);database=Bus;Integrated Security=true");
    }
    public static bool findBus(string zdz)
    {
        SqlConnection conn = Admin_Add.createConn();
        conn.Open();
        SqlCommand cmd = new SqlCommand("select count(*) from StationMessage where 终点站='" + zdz  + "'", conn);
        int count = Convert.ToInt32(cmd.ExecuteScalar());
        if (count > 0)
            return true;
        else
            return false;
        conn.Close();
    }
    public static bool insertBus(StationMessage S)
    {
       
        try
        {
            SqlConnection conn = Admin_Add.createConn();
            conn.Open();
            SqlCommand cmd = new SqlCommand("insert into StationMessage values('" + S.zdz + "','" + S.fbsj + "','" + S.tjzd + "','" + S.zxdh + "','" + S.cx + "',cast('" + S.pj + "' as money),'" + S.lc + "','" + S.cygs + "','" + S.bz + "')", conn);
            cmd.ExecuteNonQuery();
            conn.Close();
            return true;
        } 
        catch (Exception e)
        {
            return false;
        }
    }
    //将从数据库里检索出来的表返回
     public static DataTable selectAll()
     {
         SqlConnection conn = Admin_Add.createConn();
         SqlCommand cmd = new SqlCommand("select * from StationMessage", conn);
         SqlDataAdapter sda = new SqlDataAdapter();
         sda.SelectCommand = cmd;
         DataSet ds = new DataSet();
         sda.Fill(ds, "StationMessage");
         return ds.Tables["StationMessage"];
     }

    public static bool updateBus(string  S)
    {
        try
        {
            SqlConnection conn = Admin_Add.createConn();
            conn.Open();
            //SqlCommand cmd = new SqlCommand("update StationMessage set 终点站='" + S.zdz + "',发班时间='" + S.fbsj + "',途径站点='" + S.tjzd + "',咨询电话='" + S.zxdh + "',车型='" + S.cx + "',票价='" + S.pj + "',里程='" + S.lc + "',承运公司='" + S.cygs + "',备注='" + S.bz + "' where 终点站='" + S.zdz + "'", conn);
            SqlCommand cmd = new SqlCommand("update StationMessage set 终点站='" + S + "',发班时间='" + S + "',途径站点='" + S + "',咨询电话='" + S + "',车型='" + S + "',票价='" + S + "',里程='" + S + "',承运公司='" + S + "',备注='" + S + "' where 终点站='" + S + "'", conn);
            cmd.ExecuteNonQuery();
            conn.Close();
            return true;
        }
        catch (Exception e)
        {
            return false;
        }

    }

    public static bool deleteBus(string  S)
    {
        try
        {
            SqlConnection conn = Admin_Add.createConn();
            conn.Open();
            SqlCommand cmd = new SqlCommand("delete from StationMessage where 终点站='" + S + "'", conn);
            cmd.ExecuteNonQuery();
            conn.Close();
            return true;
        }
        catch (Exception e)
        {
            return false;
        }
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -