Помощь в написании студенческих работ
Антистрессовый сервис

Тестирование. 
Обработка наборов данных на C#

РефератПомощь в написанииУзнать стоимостьмоей работы

Err = «Поле „Марка“ должно быть непустым»; Privatestringcountry; // Страна-производительавто. Privatevoid Form2_FormClosing (object sender, FormClosingEventArgs e). Поиск по марке авто", makeToFind, -1, -1).Trim (); StreamWritersw = newStreamWriter (name, false, Encoding. Default); If (d.ShowDialog () == System.Windows.Forms.DialogResult.Cancel). Text = «CarShop — «+ Path… Читать ещё >

Тестирование. Обработка наборов данных на C# (реферат, курсовая, диплом, контрольная)

Запуск программы, открытие файла, сортировка по году:

Тестирование. Обработка наборов данных на C#.

Сортировка по цене.

Тестирование. Обработка наборов данных на C#.

Создадим побочную форму Form1-стартовое меню:

Заключение

Тестирование. Обработка наборов данных на C#.

В ходе проделанной работы были закреплены знания основ программирования на языке C#, а также получены навыки работы с формой Data Grid View, сериализацией и десериализацией XML файла, bilding Sourse и binding Navigator, подключением встроенных ссылок, ресурсными папками, файловым менеджером, встроенными библиотеками и т. д. При выполнении курсовой работы были освоены все этапы создания программного комплекса от постановки задачи до практической реализации, сопровождающейся документацией и инструкциями по его использованию.

Библиографический список

  • 1. Культин. Н. Основы программирования в VicrosoftVisual С# 2010. — СПб.: БХВ-Петербург, 2011. — 368 с.: ил. + CD-ROM — (Самоучитель).
  • 2. Лабор В. В. Си Шарп: Создание приложений для Windows / В. В. Лабор — Мн.:Харвест, 2003.-384с.
  • 3. Прайс Д. Visual C#.NET Полное руководство / Д. Прайс, М. Гандерлой — К.: ВЕК+.СПб.:Коронапринт, К: НТИ. М.:Энтроп, 2008. 2008.-960с.
  • 4. Фленов. М. Библия C#. — 2-е изд., перераб. и доп. — СПб.: БХВ-Петербург, 2011. — 560 с.: ил. + CD_ROM.

Приложение 1

Тексты программных модулей Содержимое файла Car.cs.

using System;

usingSystem.Collections.Generic;

usingSystem.Linq;

usingSystem.Text;

usingSystem.Threading.Tasks;

usingSystem.Drawing;

namespaceCarsShowroom.

{.

publicclassCar.

{.

privateintid; // Уникальныйномеравто.

privatestringmake; // Маркаавто.

privatestringmodel; // Модельавто.

privateBitmapphoto; // Фотоавто.

privatestringcountry; // Страна-производительавто.

privateintyear; // Годвыпускаавто.

privateintpower; // Мощностьдвигателя.

privatedoubleprice; // Ценаавто.

publicCar ().

{ }.

// id.

publicint Id.

{.

get.

{.

return id;

}.

set.

{.

id = value;

}.

}.

// make.

publicstring Make.

{.

get.

{.

return make;

}.

set.

{.

make = value;

}.

}.

// model.

publicstring Model.

{.

get.

{.

return model;

}.

set.

{.

model = value;

}.

}.

// country.

publicstring Country.

{.

get.

{.

return country;

}.

set.

{.

country = value;

}.

}.

// power.

publicint Power.

{.

get.

{.

return power;

}.

set.

{.

power = value;

}.

}.

// year.

publicint Year.

{.

get.

{.

return year;

}.

set.

{.

year = value;

}.

}.

// price.

publicdouble Price.

{.

get.

{.

return price;

}.

set.

{.

price = value;

}.

}.

// photo.

publicBitmap Photo.

{.

get.

{.

return photo;

}.

set.

{.

photo = value;

}.

}.

}.

}.

Файл Form2.cs.

usingMicrosoft.VisualBasic;

using System;

usingSystem.Collections.Generic;

usingSystem.ComponentModel;

usingSystem.Data;

usingSystem.Drawing;

usingSystem.Linq;

usingSystem.Text;

usingSystem.Threading.Tasks;

usingSystem.Windows.Forms;

using System. IO;

usingSystem.Xml.Serialization;

namespaceCarsShowroom.

{.

publicpartialclassForm2 :Form.

{.

privateXmlSerializerxmls = newXmlSerializer (typeof (List));

privatestringmakeToFind = «» ;

public Form2().

{.

InitializeComponent ();

carBindingSource.DataSource = newList ();

id2.Tag = 0;

year2.Tag = 1;

price2.Tag = 2;

}.

privatevoid dataGridView1_CellValidating (object sender, DataGridViewCellValidatingEventArgs e).

{.

if (dataGridView1.Rows[e.RowIndex]. IsNewRow).

return;

string err = «», s = e.FormattedValue.ToString ();

inti; double d;

switch (e.ColumnIndex).

{.

// id.

case 0:

// make.

case 1:

if (s == «»).

err = «Поле „Марка“ не должно быть пустым» ;

break;

// model.

case 2:

if (s == «»).

err = «Поле „Модель“ не должно быть пустым» ;

break;

// country.

case 3:

if (s == «»).

err = «Поле „Производитель“ не должно быть пустым» ;

break;

// power.

case 4:

if (!int.TryParse (s, outi)).

err = «Строку нельзя преобразовать в число» ;

elseif (i < 0).

err = «Отрицательные числа не допускаются» ;

break;

// year.

case 5:

if (!int.TryParse (s, outi)).

err = «Строку нельзя преобразовать в число» ;

elseif (i < 0).

err = «Отрицательные числа не допускаются» ;

break;

// price.

case 6:

if (!double.TryParse (s, out d)).

err = «Строку нельзя преобразовать в число» ;

elseif (d < 0).

err = «Отрицательные числа не допускаются» ;

break;

}.

e.Cancel = err ≠ «» ;

dataGridView1.Rows[e.RowIndex]. ErrorText = err;

}.

privatevoid dataGridView1_RowValidating (object sender, DataGridViewCellCancelEventArgs e).

{.

if (dataGridView1.Rows[e.RowIndex]. IsNewRow).

return;

string err = «» ;

if (dataGridView1[1, e. RowIndex]. Value == null).

err = «Поле „Марка“ должно быть непустым» ;

e.Cancel = err ≠ «» ;

dataGridView1.Rows[e.RowIndex]. ErrorText = err;

}.

privatevoidSaveData (string name).

{.

if (name == «» || dataGridView1. RowCount == 1).

return;

if (dataGridView1.CurrentRow.IsNewRow).

dataGridView1.CurrentCell =.

dataGridView1[0, dataGridView1. RowCount — 2];

StreamWritersw = newStreamWriter (name, false, Encoding. Default);

xmls.Serialize (sw, carBindingSource. DataSource);

sw.Close ();

}.

privatevoid new1_Click (object sender, EventArgs e).

{.

SaveData (saveFileDialog1.FileName);

carBindingSource.DataSource = newList ();

dataGridView1.CurrentCell = dataGridView1[0, 0];

saveFileDialog1.FileName = «» ;

Text = «CarShop» ;

foreach (DataGridViewRow row in dataGridView1. Rows).

{.

row.Height = 60;

}.

}.

privatevoid open1_Click (object sender, EventArgs e).

{.

openFileDialog1.FileName = «» ;

if (openFileDialog1.ShowDialog () == DialogResult. OK).

{.

SaveData (saveFileDialog1.FileName);

string s = openFileDialog1. FileName;

StreamReadersr = newStreamReader (s, Encoding. Default);

carBindingSource.SuspendBinding ();

carBindingSource.DataSource = xmls. Deserialize (sr);

carBindingSource.ResumeBinding ();

sr.Close ();

saveFileDialog1.FileName = s;

Text = «CarShop — «+ Path. GetFileNameWithoutExtension (s);

int n = dataGridView1. RowCount;

for (inti = 0; i< n; i++).

{.

dataGridView1.Rows[i]. Cells[1].Value = newBitmap (dataGridView1.Rows[i]. Cells[7].Value + «»);

dataGridView1.Rows[i]. Height = newBitmap (dataGridView1.Rows[i]. Cells[7].Value + «»).Height;

}.

}.

}.

privatevoid save1_Click (object sender, EventArgs e).

{.

if (saveFileDialog1.ShowDialog () == DialogResult. OK).

{.

string h = saveFileDialog1. FileName;

SaveData (h);

Text = «Car — «+ Path. GetFileNameWithoutExtension (h);

}.

}.

privatevoid Form2_FormClosing (object sender, FormClosingEventArgs e).

{.

SaveData (saveFileDialog1.FileName);

}.

privatevoid file1_DropDownOpening (object sender, EventArgs e).

{.

save1.Enabled = dataGridView1. RowCount > 1;

}.

privatevoid dataGridView1_CurrentCellDirtyStateChanged (object sender, EventArgs e).

{.

menuStrip1.Enabled = !dataGridView1.IsCurrentCellDirty;

int row = dataGridView1.CurrentRow.Index;

if (!dataGridView1.IsCurrentCellDirty&&.

(int)dataGridView1[" Id1″, row]. Value == 0).

{.

intmaxId = 0;

for (inti = 0; i< row; i++).

{.

int v = (int)dataGridView1[" Id1″, i]. Value;

if (maxId< v).

maxId = v;

}.

dataGridView1[" Id1″, row]. Value = maxId + 1;

}.

}.

privateintCompareById (Car a, Car b).

{.

returna.Id — b. Id;

}.

privateintCompareByYear (Car a, Car b).

{.

returna.Year.CompareTo (b.Year);

}.

privateintCompareByPrice (Car a, Car b).

{.

returna.Price.CompareTo (b.Price);

}.

privatevoid dataGridView1_RowEnter (object sender, DataGridViewCellEventArgs e).

{.

find1.Enabled = bindingNavigatorDeleteItem. Enabled= !dataGridView1.Rows[e.RowIndex]. IsNewRow;

}.

privatevoid year2_Click (object sender, EventArgs e).

{.

if (dataGridView1.RowCount == 1).

return;

dataGridView1.CurrentCell = dataGridView1[0, 0];

Comparison comp = CompareByYear;

switch ((int)(sender asToolStripMenuItem).Tag).

{.

case 0:

comp = CompareById;

break;

case 1:

comp = CompareByYear;

break;

case 2:

comp = CompareByPrice;

break;

}.

(carBindingSource.DataSourceasList).Sort (comp);

carBindingSource.ResetBindings (false);

}.

privatevoid find1_Click (object sender, EventArgs e).

{.

makeToFind = Interaction. InputBox («Введите начальную часть марки авто для поиска:» ,.

" Поиск по марке авто", makeToFind, -1, -1).Trim ();

if (makeToFind == «»).

return;

intind = (carBindingSource.DataSourceas.

List).FindIndex (dataGridView1.CurrentRow.Index, delegate (Car a).

{.

returna.Make.StartsWith (makeToFind,.

StringComparison.OrdinalIgnoreCase);

});

if (ind ≠ -1).

dataGridView1.CurrentCell = dataGridView1[1, ind];

else.

MessageBox.Show («Марка авто не найдена», «Поиск по марке авто»);

}.

privatevoid button1_Click1(object sender, EventArgs e).

{.

OpenFileDialog d = newOpenFileDialog ();

if (d.ShowDialog () == System.Windows.Forms.DialogResult.Cancel).

return;

Imageimg = Image. FromFile (d.FileName);

dataGridView1.CurrentCell.Value = img;

}.

}.

}.

Файл Form1.cs.

using System;

using System.Collections.Generic;

using System. ComponentModel;

using System. Data;

using System. Drawing;

using System. Linq;

using System. Text;

using System.Threading.Tasks;

using System.Windows.Forms;

namespace CarsShowroom.

{.

publicpartialclassForm1: Form.

{.

privateForm2 form2 = newForm2();

public Form1().

{.

InitializeComponent ();

}.

privatevoid button1_Click (object sender, EventArgs e).

{.

form2.Owner = this;

form2.ShowDialog ();

this.Close ();

}.

privatevoid button2_Click (object sender, EventArgs e).

{.

Application.Exit ();

}.

}.

}.

Показать весь текст
Заполнить форму текущей работой