|
Юзер
Регистрация: 08.09.2007
Сообщений: 271
Репутация: 61
|
Написать программу «Автоматизированная информационная система на железнодорожном вокзале». Информационная система должна содержать сведения об отправлении поездов дальнего следования. Для каждого поезда указывается: номер поезда, станция назначения, время отправления.
Программа должна обеспечивать выбор с помощью меню и выполнение одной из следующих функций: - первоначальный ввод данных в информационную систему (с клавиатуры или из файла);
- вывод сведений по всем поездам;
- вывод сведений по поезду с запрошенным номерам;
- вывод сведений по тем поездам, которые следуют до запрошенной станции назначения.
Подскажите, пожалуйста, как реализовать удаление информации о выбранном рейсе или информации о всех рейсах сразу.
http://s017.radikal.ru/i417/1111/07/2014ad7475a9.jpg
Скрытый текст:
Form1:
Код:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Collections;
namespace WindowsFormsApplication14
{
public partial class Form1 : Form
{
/*
* класс рейса поездов
*/
public class reis
{
/*
* объявляем поля класса
*/
public String punkt_naznacheniya;
public String vremya_otpravleniya;
public int nomer_poezda;
public reis(String punkt_naznacheniya, String vremya_otpravleniya, int nomer_poezda)
{
this.punkt_naznacheniya = punkt_naznacheniya;
this.vremya_otpravleniya = vremya_otpravleniya;
this.nomer_poezda = nomer_poezda;
}
}
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
/*
* загрузка формы
*/
t_hour.Text = "Час";
t_min.Text = "Минута";
/*
* чтение данных из файла
*/
FileStream Stream2 = new FileStream("db.txt", FileMode.Open, FileAccess.Read);
StreamReader Reader = new StreamReader(Stream2);
string Str;
int y;
int z;
bool zxc = false;
do
{
Str = Reader.ReadLine();
if (Str != null)
{
if (zxc == true)
{
string[] arr = new string[3];
y = Str.IndexOf("\t");
z = 0;
do
{
arr[z] = Str.Substring(0, y);
Str = Str.Substring(y + 1, Str.Length - y - 1);
z++;
y = Str.IndexOf("\t");
}
while (y > -1);
string[] row = { arr[0], arr[1], Str };
poezda.Rows.Add(row);
}
zxc = true;
}
}
while (Str != null);
Reader.Close();
Stream2.Close();
}
private void button1_Click(object sender, EventArgs e)
{
/*
* добавление нового рейса в БД
*/
reis REIS = new reis(txt_punkt.Text, t_hour.Text+":"+t_min.Text, Int16.Parse(txt_nomer.Text));
FileStream Stream = new FileStream("db.txt", FileMode.Append, FileAccess.Write);
StreamWriter Writer = new StreamWriter(Stream);
Writer.WriteLine(REIS.punkt_naznacheniya+"\t"+REIS.vremya_otpravleniya+"\t"+REIS.nomer_poezda.ToString());
Writer.Close();
Stream.Close();
poezda.Rows.Clear();
/*
* считывание рейсов из файла
*/
FileStream Stream2 = new FileStream("db.txt", FileMode.Open, FileAccess.Read);
StreamReader Reader = new StreamReader(Stream2);
string Str;
int y;
int z;
bool zxc = false;
do
{
Str = Reader.ReadLine();
if (Str != null)
{
if (zxc == true)
{
string[] arr = new string[3];
y = Str.IndexOf("\t");
z = 0;
do
{
arr[z] = Str.Substring(0, y);
Str = Str.Substring(y + 1, Str.Length - y - 1);
z++;
y = Str.IndexOf("\t");
}
while (y > -1);
string[] row = { arr[0], arr[1], Str };
poezda.Rows.Add(row);
}
zxc = true;
}
}
while (Str != null);
Reader.Close();
Stream2.Close();
/*
* очищаем поля ввода
*/
txt_punkt.Text = "";
txt_nomer.Text = "";
t_hour.Text = "0";
t_min.Text = "00";
}
private void button2_Click(object sender, EventArgs e)
{
/*
* открытие формы поиска
*/
Form2 q = new Form2();
q.Show();
}
}
}
Form2 (тут осуществляется поиск):
Код:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Collections;
namespace WindowsFormsApplication14
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
private void Form2_Load_2(object sender, EventArgs e)
{
/*
* чтение данных из файла
*/
FileStream Stream2 = new FileStream("db.txt", FileMode.Open, FileAccess.Read);
StreamReader Reader = new StreamReader(Stream2);
string Str;
int y;
int z;
bool zxc = false;
do
{
Str = Reader.ReadLine();
if (Str != null)
{
if (zxc == true)
{
string[] arr = new string[3];
y = Str.IndexOf("\t");
z = 0;
do
{
arr[z] = Str.Substring(0, y);
Str = Str.Substring(y + 1, Str.Length - y - 1);
z++;
y = Str.IndexOf("\t");
}
while (y > -1);
string[] row = { arr[0], arr[1], Str };
poezda.Rows.Add(row);
}
zxc = true;
}
}
while (Str != null);
Reader.Close();
Stream2.Close();
}
private void button1_Click(object sender, EventArgs e)
{
/*
* поиск
*/
poisk.Rows.Clear();
int kol = poezda.Rows.Count;
kol--;
for (int i = 0; i < kol; i++)
{
if (radioButton1.Checked == true)
{
/*
* поиск по пункту назначения
*/
if (poezda.Rows[i].Cells[0].Value.ToString() == searcher.Text)
{
string[] str = { poezda.Rows[i].Cells[0].Value.ToString(), poezda.Rows[i].Cells[1].Value.ToString(), poezda.Rows[i].Cells[2].Value.ToString() };
poisk.Rows.Add(str);
}
}
else
{
/*
* поиск по номеру рейса
*/
if (poezda.Rows[i].Cells[2].Value.ToString() == searcher.Text)
{
string[] str = { poezda.Rows[i].Cells[0].Value.ToString(), poezda.Rows[i].Cells[1].Value.ToString(), poezda.Rows[i].Cells[2].Value.ToString() };
poisk.Rows.Add(str);
}
}
}
}
}
}
__________________
"Надежда умирает последней", - сказала Вера и застрелила Любовь...
Последний раз редактировалось Arantar; 23.11.2011 в 13:50.
|