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,所以想写一个批处理来编 ...
随机推荐
- docker在windows,centos中的安装
centos安装方式,采用阿里云的镜像和安装脚本 或者到https://store.docker.com/search?type=edition&offering=community下载相应系 ...
- ecshop调用指定分类和个数的文章列表
举例如首页调用方法: 1.先打开index.php文件找到以下代码: $smarty->assign('new_articles', index_get_new_articles()); // ...
- 什么是Css Hack?ie6,7,8的hack分别是什么?
针对不同的浏览器写不同的CSS code的过程,就是CSS hack. 示例如下: 1 2 3 4 5 6 7 8 9 10 11 12 #test { width:300px; heig ...
- 解决kubuntu(KDE4.8.5桌面环境)找不到中文语言包
原始日期:2013-12-30 23:16 接触linux的想必都知道KDE平台,kde精美的界面是其一大特色,不过美中不足的是,很多新手在安装完KDE后,界面包括菜单选项等都是英文界面,对于英语水平 ...
- hibernate查询部分字段转换成实体bean
//hibernate查询部分字段转换成实体bean /** * 查询线路信息 */ @Override public List<Line> getSimpleLineListByTj(M ...
- Android 音乐播放
android简单音乐播放控制代码 这个几个月业余时间一直在做一个android项目,里面涉及到了音乐播放功能.很简单那种,播放.暂停.上一曲.下一曲.音量调节等. 音乐播放主要使用的对象是Media ...
- 探索Windows命令行系列(5):几个实用的命令例解
1.关机命令(shutdown) 2.管理 Windows 服务(sc) 3.管理任务进程(tasklist.taskkill) 4.显示 TCP/IP 配置值(ipconfig) 5.网络诊断工具( ...
- [leetcode-500-Keyboard Row]
Given a List of words, return the words that can be typed using letters of alphabet on only one row' ...
- 一个"2-SUM"问题
题目要求: Download the text file here. (Right click and save link as). The goal of this problem is to im ...
- JAVAEE——SSH三大框架整合(spring+struts2+hibernate)
一.整合原理 二.导包(41个) 1.hibernate (1)hibernate/lib/required (2)hibernate/lib/jpa | java persist api java的 ...