C#控制台应用程序之旅游资源与线路管理系统
利用C#语言及SQL Server数据库编写的一个简化版旅游资源与线路管理系统
数据库中包含三张表:hotel表、tourist_spot表、lines表
用户分为管理员和普通用户,管理员拥有最高权限,可以对三张表进行增、删、改、查,而普通用户拥有部分权限,只能进行查询操作
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using System.Data.SqlClient; namespace ConsoleApp1
{
class Program
{
static string[] Users = new string[] { "a123", "abcd","admin","driver" };
static void Main(string[] args)
{
string str_id = "",str_password="";
Console.WriteLine(" ********************************");
Console.WriteLine(" ****欢迎您使用旅游资源及线路管理系统****");
Console.WriteLine(" ********************************\n");
Console.WriteLine("请你验证身份,以便于我们为您提供更加优质的服务!");
Console.Write("请输入您的账号:");
str_id = Console.ReadLine();
Console.Write("请输入您的密码:");
str_password = Console.ReadLine();
if (str_id == "root" && str_password == "root")
{
do
{
RootMenu();
Console.WriteLine("请选择:1、继续 2、退出");
} while (Console.ReadLine() == "");
Environment.Exit();
}
else if(isUser(str_id.Trim()))
{
if(str_password.Trim()=="admin")
do
{
User();
Console.WriteLine("请选择:1、继续 2、退出");
} while (Console.ReadLine() == "");
Environment.Exit();
}
} //判断是否为普通用户
static bool isUser(string x)
{
foreach (string i in Users)
if (x == i)
return true;
else
continue;
return false;
} //root管理菜单
static void RootMenu()
{
Console.Clear();
Console.WriteLine("您是超级管理员,拥有最高权限");
Console.WriteLine(" 1、酒店信息管理");
Console.WriteLine(" 2、景点信息管理");
Console.WriteLine(" 3、线路信息管理");
bool bool1 = true;
do
{
Console.Write("请输入序号选择你要管理的内容:");
string str = Console.ReadLine();
switch (str)
{
case "":
Console.Clear();
Console.WriteLine("欢迎进行酒店信息管理");
Console.WriteLine("1、酒店信息添加");
Console.WriteLine("2、酒店信息删除");
Console.WriteLine("3、酒店信息修改");
Console.WriteLine("4、酒店信息查询");
Root();
break;
case "":
Console.Clear();
Console.WriteLine("欢迎进行景点信息管理");
Console.WriteLine("1、景点信息添加");
Console.WriteLine("2、景点信息删除");
Console.WriteLine("3、景点信息修改");
Console.WriteLine("4、景点信息查询");
Root();
break; ;
case "":
Console.Clear();
Console.WriteLine("欢迎进行线路信息管理");
Console.WriteLine("1、线路信息添加");
Console.WriteLine("2、线路信息删除");
Console.WriteLine("3、线路信息修改");
Console.WriteLine("4、线路信息查询");
Root();
break;
default:
bool1 = false;
break;
}
} while (!bool1);
} //root函数,具有所有数据操作的权限
static void Root(int x)
{
switch (x)
{
case :
{
Console.Write("请选择:");
string str = "";
str = Console.ReadLine();
switch (str.Trim())
{
case "":
HotelAdd();
break;
case "":
HotelDelete();
break;
case "":
HotelAlter();
break;
case "":
HotelSelect();
break;
default:
Console.Write("非法操作!");
return;
}
}
break; case :
{
Console.Write("请选择:");
string str = "";
str = Console.ReadLine();
switch (str.Trim())
{
case "":
Tourist_spotAdd();
break;
case "":
Tourist_spotDelete();
break;
case "":
Tourist_spotAlter();
break;
case "":
Tourist_spotSelect();
break;
default:
Console.Write("非法操作!");
return;
}
}
break;
case :
{
Console.Write("请选择:");
string str = "";
str = Console.ReadLine();
switch (str.Trim())
{
case "":
LinesAdd();
break;
case "":
LinesDelete();
break;
case "":
LinesAlter();
break;
case "":
LinesSelect();
break;
default:
Console.Write("非法操作!");
return;
}
}
break;
default:
{
Console.Write("非法操作!");
return;
}
}
} //user函数,具有查询功能
static void User()
{
Console.Clear();
Console.WriteLine("您是普通用户,拥有查询权限");
Console.WriteLine(" 1、查询酒店信息");
Console.WriteLine(" 2、查询景点信息");
Console.WriteLine(" 3、查询线路信息");
Console.Write("请输入序号选择您要查询的内容:");
string str = Console.ReadLine();
switch(str)
{
case "":
HotelSelect();
break;
case "":
Tourist_spotSelect();
break;
case "":
LinesSelect();
break;
default:
Console.WriteLine("非法输入!");
return;
}
} //hotel信息管理函数
#region
//hotel信息添加
static void HotelAdd()
{
Console.WriteLine("请输入你要添加的酒店信息");
Console.Write("酒店名称:");
string str_hotel_name = Console.ReadLine() ;
Console.Write("酒店地址:");
string str_hotel_addr = Console.ReadLine();
Console.Write("酒店电话:");
string str_hotel_tel = Console.ReadLine();
Console.Write("酒店价格:");
int int_hotel_price = Convert.ToInt32(Console.ReadLine());
string StrCon = @"Data Source = .;Initial Catalog=tourResour_lines;" +
"Integrated Security = True;";
SqlConnection sqlCon = new SqlConnection(StrCon);
sqlCon.Open();
string isStr = @"insert into hotel values('" + str_hotel_name +"','" + str_hotel_addr + "',"
+ str_hotel_tel + ","+int_hotel_price+")";
SqlCommand sqlCmd = new SqlCommand(isStr, sqlCon);
sqlCmd.ExecuteNonQuery();
Console.WriteLine("酒店信息添加成功!");
sqlCon.Close();
} //hotel信息删除
static void HotelDelete()
{
Console.WriteLine("请输入你要删除的酒店信息");
Console.Write("酒店名称:");
string str_hotel_name = Console.ReadLine();
string StrCon = @"Data Source = .;Initial Catalog=tourResour_lines;" +
"Integrated Security = True;";
SqlConnection sqlCon = new SqlConnection(StrCon);
sqlCon.Open();
string isStr = @"delete from hotel where hotel_name ='" + str_hotel_name + "'";
SqlCommand sqlCmd = new SqlCommand(isStr, sqlCon);
sqlCmd.ExecuteNonQuery();
Console.WriteLine("酒店信息删除成功!");
sqlCon.Close();
} //hotel信息修改
static void HotelAlter()
{
Console.WriteLine("请输入要修改的酒店名称:");
Console.Write("酒店名称:");
string str_hotel_name_before = Console.ReadLine();
Console.WriteLine("请输入修改后的酒店信息");
Console.Write("酒店名称:");
string str_hotel_name = Console.ReadLine();
Console.Write("酒店地址:");
string str_hotel_addr = Console.ReadLine();
Console.Write("酒店电话:");
string str_hotel_tel = Console.ReadLine();
Console.Write("酒店价格:");
int int_hotel_price = Convert.ToInt32(Console.ReadLine());
string StrCon = @"Data Source = .;Initial Catalog=tourResour_lines;" +
"Integrated Security = True;";
SqlConnection sqlCon = new SqlConnection(StrCon);
sqlCon.Open();
string isStr = @"update hotel set hotel_name ='" + str_hotel_name +
"',hotel_addr='" + str_hotel_addr + "',hotel_tel ='" + str_hotel_tel
+ "',hotel_price=" + int_hotel_price + " where hotel_name='" + str_hotel_name_before + "'";
SqlCommand sqlCmd = new SqlCommand(isStr, sqlCon);
sqlCmd.ExecuteNonQuery();
Console.WriteLine("酒店信息修改成功!");
sqlCon.Close();
} //hotel信息查询
static void HotelSelect()
{
Console.WriteLine("请输入你要查询的酒店地址");
Console.Write("酒店地址:");
string str_hotel_addr = Console.ReadLine();
string StrCon = @"Data Source = .;Initial Catalog=tourResour_lines;" +
"Integrated Security = True;";
SqlConnection sqlCon = new SqlConnection(StrCon);
sqlCon.Open();
string isStr = @"select * from hotel where hotel_addr ='" + str_hotel_addr + "'";
string sltResult = "";
SqlCommand sqlCmd = new SqlCommand(isStr, sqlCon);
SqlDataReader reader = sqlCmd.ExecuteReader();
Console.WriteLine("查询结果:");
if (reader.HasRows)
{
while(reader.Read())
{
//记录每一条记录
sltResult += "名称:"+reader["hotel_name"].ToString() +"\t电话:" + reader["hotel_tel"].ToString()
+"\t价格:"+ reader["hotel_price"].ToString() + "\n";
}
Console.WriteLine(sltResult);
}
Console.WriteLine("酒店信息查询成功!");
sqlCon.Close();
}
#endregion //tourist_spot信息管理函数
#region
//tourist_spot信息添加
static void Tourist_spotAdd()
{
Console.WriteLine("请输入你要添加的景点信息");
Console.Write("景点名称:");
string str_Tourist_spot_name = Console.ReadLine();
Console.Write("景点地址:");
string str_Tourist_spot_addr = Console.ReadLine();
Console.Write("景点价格:");
int int_Tourist_spot_price = Convert.ToInt32(Console.ReadLine());
string StrCon = @"Data Source = .;Initial Catalog=tourResour_lines;" +
"Integrated Security = True;";
SqlConnection sqlCon = new SqlConnection(StrCon);
sqlCon.Open();
string isStr = @"insert into tourist_spot values('" + str_Tourist_spot_name + "','" + str_Tourist_spot_addr +
"'," + int_Tourist_spot_price + ")";
SqlCommand sqlCmd = new SqlCommand(isStr, sqlCon);
sqlCmd.ExecuteNonQuery();
Console.WriteLine("酒店信息添加成功!");
sqlCon.Close();
} //tourist_spot信息删除
static void Tourist_spotDelete()
{
Console.WriteLine("请输入你要删除的景点信息");
Console.Write("景点名称:");
string str_tourist_spot_name = Console.ReadLine();
string StrCon = @"Data Source = .;Initial Catalog=tourResour_lines;" +
"Integrated Security = True;";
SqlConnection sqlCon = new SqlConnection(StrCon);
sqlCon.Open();
string isStr = @"delete from tourist_spot where tourist_spot_name ='" + str_tourist_spot_name + "'";
SqlCommand sqlCmd = new SqlCommand(isStr, sqlCon);
sqlCmd.ExecuteNonQuery();
Console.WriteLine("景点信息删除成功!");
sqlCon.Close();
} //tourist_spot信息修改
static void Tourist_spotAlter()
{
Console.WriteLine("请输入要修改的景点名称:");
Console.Write("景点名称:");
string str_Tourist_spot_name_before = Console.ReadLine();
Console.WriteLine("请输入修改后的景点信息");
Console.Write("景点名称:");
string str_Tourist_spot_name = Console.ReadLine();
Console.Write("景点地址:");
string str_Tourist_spot_addr = Console.ReadLine();
Console.Write("景点价格:");
int int_Tourist_spot_price = Convert.ToInt32(Console.ReadLine());
string StrCon = @"Data Source = .;Initial Catalog=tourResour_lines;" +
"Integrated Security = True;";
SqlConnection sqlCon = new SqlConnection(StrCon);
sqlCon.Open();
string isStr = @"update tourist_spot set tourist_spot_name ='" + str_Tourist_spot_name +
"',tourist_spot_addr='" + str_Tourist_spot_addr + "',tourist_spot_price=" +
int_Tourist_spot_price + " where tourist_spot_name='" + str_Tourist_spot_name_before + "'";
SqlCommand sqlCmd = new SqlCommand(isStr, sqlCon);
sqlCmd.ExecuteNonQuery();
Console.WriteLine("景点信息修改成功!");
sqlCon.Close();
} //tourist_spot信息查询
static void Tourist_spotSelect()
{
Console.Write("请输入你要查询的景点地址:");
string str_Tourist_spot_addr = Console.ReadLine();
string StrCon = @"Data Source = .;Initial Catalog=tourResour_lines;" +
"Integrated Security = True;";
SqlConnection sqlCon = new SqlConnection(StrCon);
sqlCon.Open();
string isStr = @"select * from tourist_spot where tourist_spot_addr ='" + str_Tourist_spot_addr + "'";
string sltResult = "";
SqlCommand sqlCmd = new SqlCommand(isStr, sqlCon);
SqlDataReader reader = sqlCmd.ExecuteReader();
Console.WriteLine("查询结果:");
if (reader.HasRows)
{
while (reader.Read())
{
//记录每一条记录
sltResult += "名称:" + reader["tourist_spot_name"].ToString()
+ "\t价格:" + reader["tourist_spot_price"].ToString() + "\n";
}
Console.WriteLine(sltResult);
}
Console.WriteLine("景点信息查询成功!");
sqlCon.Close();
}
#endregion //lines信息管理函数
#region
//lines信息添加
static void LinesAdd()
{
Console.WriteLine("请输入你要添加的线路信息");
Console.Write("车次号码:");
string str_lines_num = Console.ReadLine();
Console.Write("发车时间:");
string str_lines_time = Console.ReadLine();
Console.Write("火车起点:");
string str_lines_from = Console.ReadLine();
Console.Write("火车终点:");
string str_lines_to = Console.ReadLine();
string StrCon = @"Data Source = .;Initial Catalog=tourResour_lines;" +
"Integrated Security = True;";
SqlConnection sqlCon = new SqlConnection(StrCon);
sqlCon.Open();
string isStr = @"insert into lines values('" + str_lines_num + "','" + str_lines_time + "','" +
str_lines_from + "','" + str_lines_to + "')";
SqlCommand sqlCmd = new SqlCommand(isStr, sqlCon);
sqlCmd.ExecuteNonQuery();
Console.WriteLine("线路信息添加成功!");
sqlCon.Close();
} //lines信息删除
static void LinesDelete()
{
Console.WriteLine("请输入你要删除的线路信息");
Console.Write("车次号码:");
string str_lines_num = Console.ReadLine();
string StrCon = @"Data Source = .;Initial Catalog=tourResour_lines;" +
"Integrated Security = True;";
SqlConnection sqlCon = new SqlConnection(StrCon);
sqlCon.Open();
string isStr = @"delete from lines where lines_num =" + str_lines_num ;
SqlCommand sqlCmd = new SqlCommand(isStr, sqlCon);
sqlCmd.ExecuteNonQuery();
Console.WriteLine("线路信息删除成功!");
sqlCon.Close();
} //lines信息修改
static void LinesAlter()
{
Console.WriteLine("请输入你要修改的线路信息");
Console.Write("车次号码:");
string str_lines_num_before = Console.ReadLine();
Console.WriteLine("请输入修改后的线路信息");
Console.Write("车次号码:");
string str_lines_num = Console.ReadLine();
Console.Write("发车时间:");
string str_lines_time = Console.ReadLine();
Console.Write("火车起点:");
string str_lines_from = Console.ReadLine();
Console.Write("火车终点:");
string str_lines_to = Console.ReadLine();
string StrCon = @"Data Source = .;Initial Catalog=tourResour_lines;" +
"Integrated Security = True;";
SqlConnection sqlCon = new SqlConnection(StrCon);
sqlCon.Open();
string isStr = @"update lines set lines_num ='" + str_lines_num + "',lines_time='" +
str_lines_time + "',lines_from='" + str_lines_from + "',lines_to='" + str_lines_to
+ "' where lines_num=" + str_lines_num_before;
SqlCommand sqlCmd = new SqlCommand(isStr, sqlCon);
sqlCmd.ExecuteNonQuery();
Console.WriteLine("线路信息修改成功!");
sqlCon.Close();
} //lines信息查询
static void LinesSelect()
{
Console.Write("请输入你要查询的车次号码:");
string str_lines_num = Console.ReadLine();
string StrCon = @"Data Source = .;Initial Catalog=tourResour_lines;" +
"Integrated Security = True;";
SqlConnection sqlCon = new SqlConnection(StrCon);
sqlCon.Open();
string isStr = @"select * from lines where lines_num =" + str_lines_num ;
string sltResult = "";
SqlCommand sqlCmd = new SqlCommand(isStr, sqlCon);
SqlDataReader reader = sqlCmd.ExecuteReader();
Console.WriteLine("查询结果:");
if (reader.HasRows)
{
while (reader.Read())
{
//记录每一条记录
sltResult += "车次号码:" + reader["lines_num"].ToString() + "\t发车时间:" +
reader["lines_time"].ToString() + "\t起始地点:" + reader["lines_from"].ToString() +
"\t终点城市:"+reader["lines_to"].ToString() + "\n";
}
Console.WriteLine(sltResult);
}
Console.WriteLine("线路信息查询成功!");
sqlCon.Close();
}
#endregion
}
}
作者:耑新新,发布于 博客园
转载请注明出处,欢迎邮件交流:zhuanxinxin@aliyun.com
C#控制台应用程序之旅游资源与线路管理系统的更多相关文章
- asp.net mvc引用控制台应用程序exe
起因:有一个控制台应用程序和一个web程序,web程序想使用exe程序的方法,这个时候就需要引用exe程序. 报错:使用web程序,引用exe程序 ,vs调试没有问题,但是部署到iis就报错,如下: ...
- Win32程序和控制台应用程序的项目互转设置
一般情况下,如果是windows程序,那么WinMain是入口函数,在VS2010中新建项目为"win32项目" 如果是dos控制台程序,那么main是入口函数,在VS2010中新 ...
- 【C#】1.2 控制台应用程序学习要点
分类:C#.VS2015 创建日期:2016-06-14 教材:十二五国家级规划教材<C#程序设计及应用教程>(第3版) 一.要点概述 <C#程序设计及应用教程>(第3版)的第 ...
- 【C++】第1章 在VS2015中用C++编写控制台应用程序
分类:C++.VS2015 创建日期:2016-06-12 一.简介 看到不少人至今还在用VC 6.0开发工具学习C++,其实VC 6.0开发工具早就被淘汰了.这里仅介绍学习C++时推荐使用的两种开发 ...
- c#取得控制台应用程序根目录
1.取得控制台应用程序的根目录方法 方法1.Environment.CurrentDirectory 取得或设置当前工作目录的完整限定路径方法2.AppDomain.CurrentDomain.Bas ...
- Web应用程序或者WinForm程序 调用 控制台应用程序及参数传递
有时候在项目中,会调用一个控制台应用程序去处理一些工作.那在我们的程序中要怎么样做才能调用一个控制台应用程序并将参数传递过去,控制台程序执行完后,我们的程序又怎样获取返回值?代码如下:调用代码: ...
- vc2010 win32 控制台应用程序中文乱码
vc2010 win32 控制台应用程序中文乱码 在 vc2010 上用 win32 控制台程序写些测试代码调用 windows api ,处理错误信息时,发现用 wprintf 输出的错误信息出现了 ...
- c# 隐藏 控制台应用程序
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.D ...
- 如何编写一个编译c#控制台应用程序的批处理程序
如何编写一个编译c#控制台应用程序的批处理程序 2011-03-22 18:14 dc毒蘑菇 | 浏览 579 次 最近在网上看了一个教程,是学C#的,但是我的机子上装不上vs,所以想写一个批处理来编 ...
随机推荐
- python 标准库 -- unittest
一. unittest 单元测试 编写单元测试 示例代码 : import unittest from flask import current_app from app import create_ ...
- R语言包翻译——翻译
Shiny-cheatsheet ...
- RecycleView和CardView
一.RecycleView <android.support.v7.widget.RecyclerView android:id="@+id/my_recycler_view" ...
- js脚本中try与cache捕获异常处理
<script type="text/javascript"> function add_reason(elm){ try{ var pp=$('.pp').val() ...
- jQery的链式操作和商城简易导航栏
今天要记录的是jq的一些简单操作.项目的需求是做一个导航栏,单机不同的商品名称链接,显示相应的内容.用js来写的话相对代码量要多一些,选择jqrey一行则可以搞定,下面呢是我的代码和效果图 这个是初始 ...
- JS函数和对象(一)
在本文章中,将对JS中的函数和对象进行一些讲解,不对之处还请之处 一.JS中的函数 1.1无参函数 其形式如下代码所示 function box(){ alert("我是一个函数,只有被调用 ...
- JS运动框架的封装过程(一)
给大家出一道题,从起点A走到目的地B,一共用了1000毫秒,每一次是30毫秒,请问你在这里面得到了哪些信息? 信息有哪些呢? 第一个,总时长是:1000毫秒 第二个,多久时间走一次?30毫秒 第三个, ...
- str-字符串功能介绍
叨逼叨:字符串的各个功能修改不是本身,本身不变,会产生新的值,需要赋值给新的变量来接收 以下 "举例" 是解释每个功能的实例 "举例"下一行是pycharm ...
- Redis Pipeline原理分析
转载请注明出处:http://www.cnblogs.com/jabnih/ 1. 基本原理 1.1 为什么会出现Pipeline Redis本身是基于Request/Response协议的,正常情况 ...
- sublime使用总结
上周忙呀忙~ 周一到五在忙项目,周六日搬家 在帝都平均一年就要换一次房子,从开始找房子到成功住进去前前后后大约花了半个多月的时间 什么时候就有自己的小窝了-- 之前开发一直用的都是W ...