Список литературы
1.Уотсон Карли, НейгелКристиан, Морган Скиннер :Visual С# 2008: базовый курс. : Пер. с англ. - М. : ООО "И.Д. Вильяме", 2009. - 1216 с.: ил. — Парал. тит. англ.
2. Фролов А.В, Фролов Г.В. «Визуальное проектирование приложений С#»
3.Троелсен Э. «Язык программирования С# 2010 и платформа .NET 4.0»
4.Ватсон Б. «С#4.0 на примерах».
Приложение 1: Текст программы
Главная форма:
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace Catalog
{
public partial class form_main : Form
{
private string _textFilters;
private DataSet _ds;
form_filter _frmSearch = null;
public form_main()
{
InitializeComponent();
}
private void searchgrid_TextChanged(List<field> fields)
{
System.Data.DataView dv = ((System.Data.DataView)dataGridView1.DataSource); //
_textFilters = "";
bool first = true;
foreach (field f in fields)
{
if (f.Value.Length > 0)
{
if (!first) _textFilters += " and ";
_textFilters += f.Field + " like '%" + f.Value + "%'";
first = false;
}
}
dv.RowFilter = _textFilters;
}
private void ResetSearchBTM_Click(object sender, EventArgs e)
{
_frmSearch = null;
_textFilters = "";
System.Data.DataView dv = ((System.Data.DataView)dataGridView1.DataSource); //
dv.RowFilter = _textFilters;
this.ResetSearchBTM.Visible = false;
this.Search.Enabled = true;
this.Search.BackColor = ResetSearchBTM.BackColor;
}
private void frmGrid_KeyDown(object sender, KeyEventArgs e)
{
if ((e.KeyCode == Keys.F) && (e.Modifiers == Keys.Control))
{
if (Search.Enabled)
Search_Click(null, null);
}
if ((e.KeyCode == Keys.O) && (e.Modifiers == Keys.Control))
{
Open_Click(null, null);
}
if ((e.KeyCode == Keys.S) && (e.Modifiers == Keys.Control))
{
Save_Click(null, null);
}
}
private void Search_Click(object sender, EventArgs e)
{
if (_frmSearch == null)
{
List<field> fields = new List<field>();
for (int i = 0; i < _ds.Tables[0].Columns.Count; i++)
{
if (_ds.Tables[0].Columns[i].DataType == typeof(string))
{
field f = new field();
f.Field = _ds.Tables[0].Columns[i].ColumnName;
f.FriendlyName = f.Field;
fields.Add(f);
}
}
_frmSearch = new form_filter(fields);
_frmSearch.TextChanged += new SearchContextChangedHandler(searchgrid_TextChanged);
}
_frmSearch.ShowDialog();
this.ResetSearchBTM.Visible = true;
}
private void Save_Click(object sender, EventArgs e)
{
SaveFileDialog saveFileFialog1 = new SaveFileDialog();
saveFileFialog1.Filter = "Xml files (*.xml) | *.xml";
if (saveFileFialog1.ShowDialog() == DialogResult.OK)
{
_ds.WriteXml(saveFileFialog1.FileName);
}
}
private void Open_Click(object sender, EventArgs e)
{
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
_ds = new DataSet();
try
{
_ds.ReadXml(openFileDialog1.OpenFile());
dataGridView1.DataSource = _ds.Tables[0].DefaultView;
}
catch (Exception ex)
{
MessageBox.Show(string.Format("Ошибка: {0}", ex.Message), "Error loading sample data", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
private void menu_about_Click(object sender, EventArgs e)
{
AboutBox1 info = new AboutBox1();
info.Show();
}
private void dataGridView1_Click(object sender, DataGridViewCellEventArgs e)
{
}
private void Exercise_Click(object sender, EventArgs e)
{
form_exercise ex = new form_exercise();
ex.Show();
}
private void form_main_Load(object sender, EventArgs e)
{
}
}
}
Форма поиска текста:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Collections;
namespace Catalog
{
public partial class form_filter : Form
{
public event SearchContextChangedHandler TextChanged;
private void BuildControls(List<field> fields)
{
int top = 10;
bool focused = false;
foreach (field f in fields)
{
Label label = new Label();
label.Text = f.FriendlyName + ":";
label.Top = top;
label.Left = 5;
label.AutoSize = true;
this.Controls.Add(label);
TextBox textbox = new TextBox();
textbox.TextChanged += new EventHandler(textBox_TextChanged);
textbox.Tag = f.Field;
textbox.Top = top;
textbox.Left = 85;
textbox.Width = this.Width - 80;
if (!focused)
{
textbox.Focus();
focused = true;
}
top += 35;
this.Controls.Add(textbox);
}
this.Height = top + 30;
}
public form_filter(List<field> fields)
{
InitializeComponent();
BuildControls(fields);
}
private List<field> GetFilterValues()
{
List<field> fields = new List<field>();
foreach (Control ctrl in this.Controls)
{
if (ctrl.GetType() == typeof(TextBox))
{
field f = new field();
f.Field = ctrl.Tag.ToString();
f.Value = ctrl.Text;
fields.Add(f);
}
}
return fields;
}
private void textBox_TextChanged(object sender, EventArgs e)
{
if (TextChanged != null)
TextChanged(GetFilterValues());
}
private void form_filter_Load(object sender, EventArgs e)
{
}
private void form_filter_KeyDown(object sender, KeyEventArgs e)
{
if ((e.KeyCode == Keys.Escape) || (e.KeyCode == Keys.Enter))
Close();
}
}
}
Форма редактора текста:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Text.RegularExpressions;
namespace Catalog
{
public partial class form_exercise : Form
{
public form_exercise()
{
InitializeComponent();
}
private void textBox1_TextChanged(object s, EventArgs e)
{
}
private void e_mail_Click(object sender, EventArgs e)
{
string sPattern = @"\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*";
string textToSearch = textBox1.Text;
Regex regex = new Regex( sPattern );
Match match = regex.Match(textToSearch);
string replacement = "(" + match.Value + ")";
textBox1.Text = regex.Replace(textBox1.Text, replacement);
}
private void Time_Click(object sender, EventArgs e)
{
string sPattern = @"[0-24]+:[0-59]+:[0-59]+";
string textToSearch = textBox1.Text;
Regex regex = new Regex(sPattern);
Match match = regex.Match(textToSearch);
if (match.Success)
{
string replacement = match.Value + "\tOK!";
textBox1.Text = regex.Replace(textBox1.Text, replacement);
}
else
{
textBox1.Text = DateTime.Now.ToString("HH:mm:ss");
}
}
private void form_exercise_Load(object sender, EventArgs e)
{
}
}
}
МИНИСТЕРСТВО ОБРАЗОВАНИЯ, НАУКИ, МОЛОДЁЖЫ И СПОРТА УКРАИНЫ
Одесский национальный политехнический университет
Институт компьютерных систем
Кафедра «Компьютерных интеллектуальных систем и сетей»
СИСТЕМНОЕ ПРОГРАММИРОВАНИЕ
Курсовой проект
АМКР.АЕ096.1010
Разработал: Кулибали С.
Проверил: Баськов И.А.
2012
АНОТАЦИЯ
Программа-обработчик для работы с XML файлом и его данными. Данная программа подключает данные каталога фильмов из xml-файла и выполняет над ними простейшие действия : поиск в данных, добавление и удаление фотографии в магазин. Кроме того, через данную программу возможно открывать любой xml-файл, а также реализован простейший текстовый редактор с возможностью исправления грамматических ошибок на основе регулярных выражений.