База данных технологического оборудования для производства печатных плат
Базы данных для учета и контроля оборудования по производству печатных плат. Требования к системе, анализ предметной области. Информационные потребности пользователя. Логическая структура программы, алгоритм ее работы. Руководство системного программиста.
Рубрика | Программирование, компьютеры и кибернетика |
Вид | курсовая работа |
Язык | русский |
Дата добавления | 24.02.2015 |
Размер файла | 786,5 K |
Отправить свою хорошую работу в базу знаний просто. Используйте форму, расположенную ниже
Студенты, аспиранты, молодые ученые, использующие базу знаний в своей учебе и работе, будут вам очень благодарны.
namespace Motherboard
{
// / <summary>
// / Логика взаимодействия для MainWindow. xaml
// / </summary>
public partial class MainWindow: Window
{
public MainWindow ()
{
InitializeComponent ();
}
/*Объявляем строковую переменную и записываем в нее
строку подключения
Data Source - имя сервера, по стандарту (local)
Initial Catalog - имя БД
Integrated Security=-параметры безопасности
*/
private void exitBtn_Click (object sender, RoutedEventArgs e)
{
Close ();
}
public static string connStr = @"Data Source= (local); " +
"Initial Catalog = DB_motherboard; " +
"Integrated Security = True; ";
private void connBtn_Click (object sender, RoutedEventArgs e)
{
SqlConnection ConnectionToDB = new SqlConnection (connStr);
try
{
ConnectionToDB. Open ();
}
catch (SqlException se)
{
// messageBox. Content = se. Message;
ConnectionToDB. Close ();
ConnectionToDB. Dispose ();
ConnectionToDB = new SqlConnection (@"Server= (local); Integrated Security = True; ");
SqlCommand cmd = new SqlCommand ("RESTORE DATABASE DB_motherboard FROM DISK = '" + System. IO. Path. GetDirectoryName (System. Reflection. Assembly. GetExecutingAssembly (). Location) + "/DB_motherboard. bak' WITH REPLACE"
, ConnectionToDB);
ConnectionToDB. Open ();
cmd. ExecuteNonQuery ();
Thread. Sleep (10000);
ConnectionToDB. Close ();
ConnectionToDB. Dispose ();
ConnectionToDB = new SqlConnection (connStr);
ConnectionToDB. Open ();
// return;
}
finally
{
messageBox. Content = "Подключение к БД успешно прошло";
disconnBtn. IsEnabled = true;
connBtn. IsEnabled = false;
addBtn. IsEnabled = true;
removeBtn. IsEnabled = true;
editBtn. IsEnabled = true;
query1Btn. IsEnabled = true;
query2Btn. IsEnabled = true;
query3Btn. IsEnabled = true;
exportBtn. IsEnabled = true;
selectDB. IsEnabled = true;
DataTable dt = ConnectionToDB. GetSchema ("Tables");
selectDB. Items. Clear ();
foreach (DataRow item in dt. Rows)
{
string TableName = item ["TABLE_NAME"]. ToString ();
selectDB. Items. Add (TableName);
}
selectDB. Items. RemoveAt (0);
selectDB. SelectedIndex = 0;
ConnectionToDB. Close ();
ConnectionToDB. Dispose ();
}
}
private void disconnBtn_Click (object sender, RoutedEventArgs e)
{
SqlConnection ConnectionToDB = new SqlConnection (connStr);
try
{
ConnectionToDB. Close ();
ConnectionToDB. Dispose ();
}
catch (SqlException se)
{
messageBox. Content = se. Message;
return;
}
finally
{
disconnBtn. IsEnabled = false;
connBtn. IsEnabled = true;
addBtn. IsEnabled = false;
removeBtn. IsEnabled = false;
editBtn. IsEnabled = false;
query1Btn. IsEnabled = false;
query2Btn. IsEnabled = false;
query3Btn. IsEnabled = false;
exportBtn. IsEnabled = false;
selectDB. IsEnabled = false;
messageBox. Content = "Отключение от БД успешно прошло";
}
}
private void addBtn_Click (object sender, RoutedEventArgs e)
{
string tableName = selectDB. SelectedValue. ToString ();
// открываем новое окно
(new add (tableName)). Show ();
}
private void rmwBtn_Click (object sender, RoutedEventArgs e)
{
string tableName = selectDB. SelectedValue. ToString (),
field = "";
int selectedColumn = dataGrid1. CurrentCell. Column. DisplayIndex;
var selectedCell = dataGrid1. SelectedCells [0];
var cellContent = selectedCell. Column. GetCellContent (selectedCell. Item);
if (cellContent is TextBlock)
{
field = (cellContent as TextBlock). Text. ToString ();
}
SqlConnection conn = new SqlConnection (connStr);
try
{
conn. Open ();
}
catch (SqlException se)
{
messageBox. Content = se. Message;
return;
}
SqlCommand cmd = new SqlCommand ("Delete From " + tableName +
" where "+ dataGrid1. CurrentCell. Column. Header +" = @ID", conn);
SqlParameter param = new SqlParameter ();
param. ParameterName = "@ID";
param. Value = Convert. ToInt32 (field);
param. SqlDbType = SqlDbType. Int;
cmd. Parameters. Add (param);
try
{
cmd. ExecuteNonQuery ();
}
catch
{
messageBox. Content = "Ошибка, при выполнении запроса на удаление записи. Возможно запись уже удалена";
return;
}
messageBox. Content = "Запись успешно удалена. ";
// Thread. Sleep (5000);
dataGrid1. Items. Refresh ();
conn. Close ();
conn. Dispose ();
}
private void editBtn_Click (object sender, RoutedEventArgs e)
{
string tableName = selectDB. SelectedValue. ToString (),
field = "";
int selectedColumn = dataGrid1. CurrentCell. Column. DisplayIndex;
var selectedCell = dataGrid1. SelectedCells [0];
var cellContent = selectedCell. Column. GetCellContent (selectedCell. Item);
if (cellContent is TextBlock)
{
field = (cellContent as TextBlock). Text. ToString ();
}
// открываем новое окно
(new edit (tableName, field)). Show ();
}
private void exportBtn_Click (object sender, RoutedEventArgs e)
{
dataGrid1. SelectAllCells ();
dataGrid1. ClipboardCopyMode = DataGridClipboardCopyMode. IncludeHeader;
ApplicationCommands. Copy. Execute (null, dataGrid1);
dataGrid1. UnselectAllCells ();
String result = (string) Clipboard. GetData (DataFormats.commaSeparatedValue);
Clipboard. Clear ();
System. IO. StreamWriter file = new System. IO. StreamWriter ("c: \\test. csv");
file. WriteLine (result);
file. Close ();
messageBox. Content = "Экспорт БД успешно произведён. ";
// String result = (string) Clipboard. GetData (DataFormats.html);
}
private void selectDB_SelectionChanged (object sender, SelectionChangedEventArgs e)
{
switch (selectDB. SelectedIndex)
{
case 0:
{
queryAll ("Printers");
break;
};
case 1:
{
queryAll ("Staff");
break;
};
case 2:
{
queryAll ("Customers");
break;
};
case 3:
{
queryAll ("Boards");
break;
};
case 4:
{
queryAll ("Assemblies");
break;
};
case 5:
{
queryAll ("Mounters");
break;
};
case 6:
{
queryAll ("Productions");
break;
};
default: break;
}
}
private void queryAll (string tableName)
{
SqlConnection ConnectionToDB = new SqlConnection (connStr);
try
{
ConnectionToDB. Open ();
}
catch (SqlException se)
{
messageBox. Content = se. Message;
return;
}
SqlCommand cmd = new SqlCommand ("SELECT * FROM "+ tableName, ConnectionToDB);
/*Метод ExecuteReader () класса SqlCommand возврашает
объект типа SqlDataReader, с помошью которого мы можем
прочитать все строки, возврашенные в результате выполнения запроса
CommandBehavior. CloseConnection - закрываем соединение после запроса*/
using (SqlDataReader dr = cmd. ExecuteReader ())
{
// цикл по всем столбцам полученной в результате запроса таблицы
DataTable dtTable = new DataTable (tableName);
for (int i = 0; i < dr. FieldCount; i++)
{ /*метод GetName () класса SqlDataReader позволяет получить имя столбца
по номеру, который передается в качестве параметра, данному методу
и озночает номер столбца в таблице (начинается с 0) */
dtTable. Columns. Add (dr. GetName (i). ToString (). Trim ());
}
/*читаем данные из таблицы
чтение происходит только в прямом направлении
все прочитаные строки отбрасываюся */
while (dr. Read ())
{
/*метод GetValue () класса SqlDataReader позволяет получить значение столбца
по номеру, который передается в качестве параметра, данному методу
и озночает номер столбца в таблице (начинается с 0) */
if (tableName == "Customers")
dtTable. Rows. Add (dr. GetValue (0). ToString (). Trim (), dr. GetValue (1). ToString (). Trim ());
else if (tableName == "Boards")
dtTable. Rows. Add (dr. GetValue (0). ToString (). Trim (), dr. GetValue (1). ToString (). Trim (), dr. GetValue (2). ToString (). Trim (), dr. GetValue (3). ToString (). Trim (), dr. GetValue (4). ToString (). Trim ());
else if (tableName == "Productions")
dtTable. Rows. Add (dr. GetValue (0). ToString (). Trim (), dr. GetValue (1). ToString (). Trim (), dr. GetValue (2). ToString (). Trim (), dr. GetValue (3). ToString (). Trim (), dr. GetValue (4). ToString (). Trim (), dr. GetValue (5). ToString (). Trim ());
else
dtTable. Rows. Add (dr. GetValue (0). ToString (). Trim (), dr. GetValue (1). ToString (). Trim (), dr. GetValue (2). ToString (). Trim ());
Binding bind = new Binding ();
bind. Source = dtTable;
dataGrid1. SetBinding (DataGrid. ItemsSourceProperty, bind);
}
dataGrid1. Items. Refresh ();
}
ConnectionToDB. Close ();
ConnectionToDB. Dispose ();
}
private void query1_Click (object sender, RoutedEventArgs e)
{
string x = Interaction. InputBox ("Введите id сотрудника", "Запрос о сотрудниках", "", 10,10);
SqlConnection conn = new SqlConnection (connStr);
try
{
conn. Open ();
}
catch (SqlException se)
{
messageBox. Content = se. Message;
return;
}
string tableName = selectDB. SelectedValue. ToString ();
SqlCommand cmd = new SqlCommand ("Select Staff. [First Name], Staff. [Last Name], Productions. Date, Productions. Smena From Staff, Productions " +
"where Staff. [Staff_id] = @id And Staff. [Staff_id] = Productions. Staff_id", conn);
SqlParameter param = new SqlParameter ();
param. ParameterName = "@id";
param. Value = Convert. ToInt32 (x);
param. SqlDbType = SqlDbType. Int;
cmd. Parameters. Add (param);
using (SqlDataReader dr = cmd. ExecuteReader ())
{
DataTable dtTable = new DataTable ();
for (int i = 0; i < dr. FieldCount; i++)
{
dtTable. Columns. Add (dr. GetName (i). ToString (). Trim ());
}
while (dr. Read ())
{
dtTable. Rows. Add (dr. GetValue (0). ToString (). Trim (), dr. GetValue (1). ToString (). Trim (), dr. GetValue (2). ToString (). Trim (), dr. GetValue (3). ToString (). Trim ());
}
Binding bind = new Binding ();
bind. Source = dtTable;
dataGrid1. SetBinding (DataGrid. ItemsSourceProperty, bind);
dataGrid1. Items. Refresh ();
}
conn. Close ();
conn. Dispose ();
}
private void query2_Click (object sender, RoutedEventArgs e)
{
string x = Interaction. InputBox ("Введите id платы", "Запрос о сборках плат", "", 10,10);
SqlConnection conn = new SqlConnection (connStr);
try
{
conn. Open ();
}
catch (SqlException se)
{
messageBox. Content = se. Message;
return;
}
string tableName = selectDB. SelectedValue. ToString ();
SqlCommand cmd = new SqlCommand ("Select Boards. Name As [Board Name], Boards. Elements, Mounters. Name As [Mounter Name], Assemblies. Time From Boards, Assemblies, Mounters " +
"where Boards. [Board_id] = @id And Assemblies. [Board_id] = Boards. Board_id And Assemblies. [Mounter_id] = Mounters. Mounter_id", conn);
SqlParameter param = new SqlParameter ();
param. ParameterName = "@id";
param. Value = Convert. ToInt32 (x);
param. SqlDbType = SqlDbType. Int;
cmd. Parameters. Add (param);
using (SqlDataReader dr = cmd. ExecuteReader ())
{
DataTable dtTable = new DataTable ();
for (int i = 0; i < dr. FieldCount; i++)
{
dtTable. Columns. Add (dr. GetName (i). ToString (). Trim ());
}
while (dr. Read ())
{
dtTable. Rows. Add (dr. GetValue (0). ToString (). Trim (), dr. GetValue (1). ToString (). Trim (), dr. GetValue (2). ToString (). Trim (), dr. GetValue (3). ToString (). Trim ());
}
Binding bind = new Binding ();
bind. Source = dtTable;
dataGrid1. SetBinding (DataGrid. ItemsSourceProperty, bind);
dataGrid1. Items. Refresh ();
}
conn. Close ();
conn. Dispose ();
}
private void query3_Click (object sender, RoutedEventArgs e)
{
string start = Interaction. InputBox ("Введите начальную дату", "Запрос о продукции", "", 10,10),
end = Interaction. InputBox ("Введите конечную дату", "Запрос о продукции", "", 10,10);
SqlConnection conn = new SqlConnection (connStr);
try
{
conn. Open ();
}
catch (SqlException se)
{
messageBox. Content = se. Message;
return;
}
string tableName = selectDB. SelectedValue. ToString ();
SqlCommand cmd = new SqlCommand ("Select Productions. Date, Boards. Name As [Board Name], Mounters. Name As [Mounter Name], "+
"Printers. Name As [Printer Name], Staff. [First Name], Staff. [Last Name] From Boards, Mounters, Printers, Staff, Productions " +
"where Productions. [Board_id] = Boards. Board_id And Productions. [Mounter_id] = Mounters. Mounter_id And " +
"Productions. [Printer_id] = Printers. Printer_id And Productions. Staff_id = Staff. Staff_id And @start <= Productions. Date And Productions. Date <= @end", conn);
SqlParameter param = new SqlParameter ();
param. ParameterName = "@start";
param. Value = Convert. ToDateTime (start);
param. SqlDbType = SqlDbType. Date;
cmd. Parameters. Add (param);
param = new SqlParameter ();
param. ParameterName = "@end";
param. Value = Convert. ToDateTime (end);
param. SqlDbType = SqlDbType. Date;
cmd. Parameters. Add (param);
using (SqlDataReader dr = cmd. ExecuteReader ())
{
DataTable dtTable = new DataTable ();
for (int i = 0; i < dr. FieldCount; i++)
{
dtTable. Columns. Add (dr. GetName (i). ToString (). Trim ());
}
while (dr. Read ())
{
dtTable. Rows. Add (dr. GetValue (0). ToString (). Trim (), dr. GetValue (1). ToString (). Trim (), dr. GetValue (2). ToString (). Trim (), dr. GetValue (3). ToString (). Trim (), dr. GetValue (4). ToString (). Trim (), dr. GetValue (5). ToString (). Trim ());
}
Binding bind = new Binding ();
bind. Source = dtTable;
dataGrid1. SetBinding (DataGrid. ItemsSourceProperty, bind);
dataGrid1. Items. Refresh ();
}
conn. Close ();
conn. Dispose ();
}
}
}
8.2 Модуль окна "Добавить"
8.2.1 Файл представления add. xaml
<Window x: Class="Motherboard. add"
xmlns="http://schemas. microsoft.com/winfx/2006/xaml/presentation"
xmlns: x="http://schemas. microsoft.com/winfx/2006/xaml"
Title="Добавить информацию в базу" mc: Ignorable="d" xmlns: d="http://schemas. microsoft.com/expression/blend/2008" xmlns: mc="http://schemas. openxmlformats.org/markup-compatibility/2006" d: DesignHeight="260" d: DesignWidth="446" SizeToContent="WidthAndHeight">
<Grid>
<GroupBox Header="Введите данные" Height="216" HorizontalAlignment="Left" Name="groupBox3" VerticalAlignment="Top" Width="478"></GroupBox>
<Grid Name="gbGrid" Width="409" Margin="6,12,8,12">
<TextBox Height="23" HorizontalAlignment="Left" Margin="106,6,0,0" Name="Printer_id" VerticalAlignment="Top" Width="120" Visibility="Hidden" />
<TextBox Height="23" HorizontalAlignment="Left" Margin="106,35,0,0" Name="Name_printer" VerticalAlignment="Top" Width="120" Visibility="Hidden" />
<TextBox Height="23" HorizontalAlignment="Left" Margin="106,64,0,0" Name="Type_printer" VerticalAlignment="Top" Width="120" Visibility="Hidden" />
<TextBox Height="23" HorizontalAlignment="Left" Margin="106,6,0,0" Name="Mounter_id" VerticalAlignment="Top" Width="120" Visibility="Hidden" />
<TextBox Height="23" HorizontalAlignment="Left" Margin="106,35,0,0" Name="Name_mounter" VerticalAlignment="Top" Width="120" Visibility="Hidden" />
<TextBox Height="23" HorizontalAlignment="Left" Margin="106,64,0,0" Name="Speed" VerticalAlignment="Top" Width="120" Visibility="Hidden" />
<TextBox Height="23" HorizontalAlignment="Left" Margin="106,6,0,0" Name="Staff_id" VerticalAlignment="Top" Width="120" Visibility="Hidden" />
<TextBox Height="23" HorizontalAlignment="Left" Margin="106,35,0,0" Name="First_name" VerticalAlignment="Top" Width="120" Visibility="Hidden" />
<TextBox Height="23" HorizontalAlignment="Left" Margin="106,64,0,0" Name="Last_name" VerticalAlignment="Top" Width="120" Visibility="Hidden" />
<TextBox Height="23" HorizontalAlignment="Left" Margin="106,6,0,0" Name="Customer_id" VerticalAlignment="Top" Width="120" Visibility="Hidden" />
<TextBox Height="23" HorizontalAlignment="Left" Margin="106,35,0,0" Name="Name_customer" VerticalAlignment="Top" Width="120" Visibility="Hidden" />
<TextBox Height="23" HorizontalAlignment="Left" Margin="106,6,0,0" Name="Board_id" VerticalAlignment="Top" Width="120" Visibility="Hidden" />
<TextBox Height="23" HorizontalAlignment="Left" Margin="106,35,0,0" Name="Elements" VerticalAlignment="Top" Width="120" Visibility="Hidden" />
<TextBox Height="23" HorizontalAlignment="Left" Margin="106,64,0,0" Name="Customer_board" VerticalAlignment="Top" Width="120" Visibility="Hidden" />
<TextBox Height="23" HorizontalAlignment="Left" Margin="106,93,0,0" Name="Name_board" VerticalAlignment="Top" Width="120" Visibility="Hidden" />
<TextBox Height="23" HorizontalAlignment="Left" Margin="106,122,0,0" Name="Type_board" VerticalAlignment="Top" Width="120" Visibility="Hidden" />
<TextBox Height="23" HorizontalAlignment="Left" Margin="106,6,0,0" Name="Board_id_assembl" VerticalAlignment="Top" Width="120" Visibility="Hidden" />
<TextBox Height="23" HorizontalAlignment="Left" Margin="106,35,0,0" Name="Mounter_id_assembl" VerticalAlignment="Top" Width="120" Visibility="Hidden" />
<TextBox Height="23" HorizontalAlignment="Left" Margin="106,64,0,0" Name="Time" VerticalAlignment="Top" Width="120" Visibility="Hidden" />
<TextBox Height="23" HorizontalAlignment="Left" Margin="106,6,0,0" Name="Date" VerticalAlignment="Top" Width="120" Visibility="Hidden" />
<TextBox Height="23" HorizontalAlignment="Left" Margin="106,35,0,0" Name="Smena" VerticalAlignment="Top" Width="120" Visibility="Hidden" />
<TextBox Height="23" HorizontalAlignment="Left" Margin="106,64,0,0" Name="Board_id_prod" VerticalAlignment="Top" Width="120" Visibility="Hidden" />
<TextBox Height="23" HorizontalAlignment="Left" Margin="106,93,0,0" Name="Mounter_id_prod" VerticalAlignment="Top" Width="120" Visibility="Hidden" />
<TextBox Height="23" HorizontalAlignment="Left" Margin="106,122,0,0" Name="Printer_id_prod" VerticalAlignment="Top" Width="120" Visibility="Hidden" />
<TextBox Height="23" HorizontalAlignment="Left" Margin="106,151,0,0" Name="Staff_id_prod" VerticalAlignment="Top" Width="120" Visibility="Hidden" />
<Label Content="Printer id" Height="28" HorizontalAlignment="Left" Margin="6,6,0,0" Name="label1" VerticalAlignment="Top" Width="94" Visibility="Hidden" />
<Label Content="Name" Height="28" HorizontalAlignment="Left" Margin="6,35,0,0" Name="label2" VerticalAlignment="Top" Width="94" Visibility="Hidden" />
<Label Content="Type" Height="28" HorizontalAlignment="Left" Margin="6,64,0,0" Name="label3" VerticalAlignment="Top" Width="94" Visibility="Hidden" />
<Label Content="Mounter id" Height="28" HorizontalAlignment="Left" Margin="6,93,0,0" Name="label4" VerticalAlignment="Top" Width="94" Visibility="Hidden" />
<Label Content="Name" Height="28" HorizontalAlignment="Left" Margin="6,122,0,0" Name="label5" VerticalAlignment="Top" Width="94" Visibility="Hidden" />
<Label Content="Speed" Height="28" HorizontalAlignment="Left" Margin="6,151,0,0" Name="label6" VerticalAlignment="Top" Width="94" Visibility="Hidden" />
<Label Content="Staff id" Height="28" HorizontalAlignment="Left" Margin="6,6,0,0" Name="label7" VerticalAlignment="Top" Width="94" Visibility="Hidden" />
<Label Content="First Name" Height="28" HorizontalAlignment="Left" Margin="6,35,0,0" Name="label8" VerticalAlignment="Top" Width="94" Visibility="Hidden" />
<Label Content="Last Name" Height="28" HorizontalAlignment="Left" Margin="6,64,0,0" Name="label9" VerticalAlignment="Top" Width="94" Visibility="Hidden" />
<Label Content="Customer id" Height="28" HorizontalAlignment="Left" Margin="6,93,0,0" Name="label10" VerticalAlignment="Top" Width="94" Visibility="Hidden" />
<Label Content="Name" Height="28" HorizontalAlignment="Left" Margin="6,122,0,0" Name="label11" VerticalAlignment="Top" Width="94" Visibility="Hidden" />
<Label Content="Board id" Height="28" HorizontalAlignment="Left" Margin="6,151,0,0" Name="label12" VerticalAlignment="Top" Width="94" Visibility="Hidden" />
<Label Content="Elements" Height="28" HorizontalAlignment="Left" Margin="6,6,0,0" Name="label13" VerticalAlignment="Top" Width="94" Visibility="Hidden" />
<Label Content="Customer" Height="28" HorizontalAlignment="Left" Margin="6,35,0,0" Name="label14" VerticalAlignment="Top" Width="94" Visibility="Hidden" />
<Label Content="Name" Height="28" HorizontalAlignment="Left" Margin="6,64,0,0" Name="label15" VerticalAlignment="Top" Width="94" Visibility="Hidden" />
<Label Content="Type" Height="28" HorizontalAlignment="Left" Margin="6,93,0,0" Name="label16" VerticalAlignment="Top" Width="94" Visibility="Hidden" />
<Label Content="Board id" Height="28" HorizontalAlignment="Left" Margin="6,122,0,0" Name="label17" VerticalAlignment="Top" Width="94" Visibility="Hidden" />
<Label Content="Mounter id" Height="28" HorizontalAlignment="Left" Margin="6,151,0,0" Name="label18" VerticalAlignment="Top" Width="94" Visibility="Hidden" />
<Label Content="Time" Height="28" HorizontalAlignment="Left" Margin="6,6,0,0" Name="label19" VerticalAlignment="Top" Width="94" Visibility="Hidden" />
<Label Content="Date" Height="28" HorizontalAlignment="Left" Margin="6,35,0,0" Name="label20" VerticalAlignment="Top" Width="94" Visibility="Hidden" />
<Label Content="Smena" Height="28" HorizontalAlignment="Left" Margin="6,64,0,0" Name="label21" VerticalAlignment="Top" Width="94" Visibility="Hidden" />
<Label Content="Board id" Height="28" HorizontalAlignment="Left" Margin="6,93,0,0" Name="label22" VerticalAlignment="Top" Width="94" Visibility="Hidden" />
<Label Content="Mounter id" Height="28" HorizontalAlignment="Left" Margin="6,122,0,0" Name="label23" VerticalAlignment="Top" Width="94" Visibility="Hidden" />
<Label Content="Printer id" Height="28" HorizontalAlignment="Left" Margin="6,151,0,0" Name="label24" VerticalAlignment="Top" Width="94" Visibility="Hidden" />
<Label Content="Staff id" Height="28" HorizontalAlignment="Left" Margin="6,151,0,0" Name="label25" VerticalAlignment="Top" Width="94" Visibility="Hidden" />
<Button Content="Добавить" Height="23" HorizontalAlignment="Left" Margin="328,150,0,0" Name="addBtn" VerticalAlignment="Top" Width="75" Click="addBtn_Click" />
</Grid>
</Grid>
</Window>
8.2.2 Файл исходного кода add. xaml. cs
using System;
using System. Collections. Generic;
using System. Linq;
using System. Text;
using System. Windows;
using System. Windows. Controls;
using System. Windows. Data;
using System. Windows. Documents;
using System. Windows. Input;
using System. Windows. Media;
using System. Windows. Media. Imaging;
using System. Windows. Shapes;
using System. Data;
using System. Data. SqlClient;
namespace Motherboard
{
// / <summary>
// / Логика взаимодействия для add. xaml
// / </summary>
public partial class add: Window
{
static public string tblName;
public add (string tableName)
{
InitializeComponent ();
tblName = tableName;
createrControls (tblName);
}
private void createrControls (string tableName)
{
switch (tableName)
{
case "Printers":
{
label1. Visibility = Visibility. Visible;
label2. Visibility = Visibility. Visible;
label3. Visibility = Visibility. Visible;
Printer_id. Visibility = Visibility. Visible;
Name_printer. Visibility = Visibility. Visible;
Type_printer. Visibility = Visibility. Visible;
break;
}
case "Mounters":
{
label4. Visibility = Visibility. Visible;
label5. Visibility = Visibility. Visible;
label6. Visibility = Visibility. Visible;
Mounter_id. Visibility = Visibility. Visible;
Name_mounter. Visibility = Visibility. Visible;
Speed. Visibility = Visibility. Visible;
break;
}
case "Staff":
{
label7. Visibility = Visibility. Visible;
label8. Visibility = Visibility. Visible;
label9. Visibility = Visibility. Visible;
Staff_id. Visibility = Visibility. Visible;
First_name. Visibility = Visibility. Visible;
Last_name. Visibility = Visibility. Visible;
break;
}
case "Customers":
{
label10. Visibility = Visibility. Visible;
label11. Visibility = Visibility. Visible;
Customer_id. Visibility = Visibility. Visible;
Name_customer. Visibility = Visibility. Visible;
break;
}
case "Boards":
{
label12. Visibility = Visibility. Visible;
label13. Visibility = Visibility. Visible;
label14. Visibility = Visibility. Visible;
label15. Visibility = Visibility. Visible;
label16. Visibility = Visibility. Visible;
Board_id. Visibility = Visibility. Visible;
Elements. Visibility = Visibility. Visible;
Customer_board. Visibility = Visibility. Visible;
Name_board. Visibility = Visibility. Visible;
Type_board. Visibility = Visibility. Visible;
break;
}
case "Assemblies":
{
label17. Visibility = Visibility. Visible;
label18. Visibility = Visibility. Visible;
label19. Visibility = Visibility. Visible;
Board_id_assembl. Visibility = Visibility. Visible;
Mounter_id_assembl. Visibility = Visibility. Visible;
Time. Visibility = Visibility. Visible;
break;
}
case "Productions":
{
label20. Visibility = Visibility. Visible;
label21. Visibility = Visibility. Visible;
label22. Visibility = Visibility. Visible;
label23. Visibility = Visibility. Visible;
label24. Visibility = Visibility. Visible;
label25. Visibility = Visibility. Visible;
Date. Visibility = Visibility. Visible;
Smena. Visibility = Visibility. Visible;
Board_id_prod. Visibility = Visibility. Visible;
Mounter_id_prod. Visibility = Visibility. Visible;
Printer_id_prod. Visibility = Visibility. Visible;
Staff_id_prod. Visibility = Visibility. Visible;
break;
}
default: break;
}
}
private void addBtn_Click (object sender, RoutedEventArgs e)
{
string connStr = @"Data Source= (local); " +
"Initial Catalog = DB_motherboard; " +
"Integrated Security = True; ";
SqlConnection conn = new SqlConnection (connStr);
try
{
// пробуем подключится
conn. Open ();
}
catch (SqlException se)
{
MessageBox. Show ("%s", se. Message);
return;
}
switch (tblName)
{
case "Printers":
{
SqlCommand cmd = new SqlCommand ("Insert into Printers" +
" (Printer_id,Name,Type) Values (@Printer_id,@Name_printer,@Type_printer)", conn);
/*Работаем с параметрами (SqlParameter), эта техника позволяет уменьшить
кол-во ошибок и достичь большего быстродействия
но требует и больших усилий в написании кода*/
// объявляем объект класса SqlParameter
SqlParameter param = new SqlParameter ();
// задаем имя параметра
param. ParameterName = "@Printer_id";
// задаем значение параметра
param. Value = Convert. ToInt32 (Printer_id. Text);
// задаем тип параметра
param. SqlDbType = SqlDbType. Int;
// передаем параметр объекту класса SqlCommand
cmd. Parameters. Add (param);
// переопределяем объект класса SqlParameter
param = new SqlParameter ();
// задаем имя параметра
param. ParameterName = "@Name_printer";
// задаем значение параметра
param. Value = Name_printer. Text. ToString ();
// задаем тип параметра
param. SqlDbType = SqlDbType. Text;
// передаем параметр объекту класса SqlCommand
cmd. Parameters. Add (param);
// переопределяем объект класса SqlParameter
param = new SqlParameter ();
// задаем имя параметра
param. ParameterName = "@Type_printer";
// задаем значение параметра
param. Value = Convert. ToInt32 (Type_printer. Text);
// задаем тип параметра
param. SqlDbType = SqlDbType. Int;
// передаем параметр объекту класса SqlCommand
cmd. Parameters. Add (param);
try
{
cmd. ExecuteNonQuery ();
}
catch
{
MessageBox. Show ("Ошибка, при выполнении запроса на добавление записи");
return;
}
// закрвываем соединение
MessageBox. Show ("Запись успешно добавлена");
conn. Close ();
conn. Dispose ();
break;
}
case "Staff":
{
SqlCommand cmd = new SqlCommand ("Insert into Staff" +
" (Staff_id,First Name,Last Name) Values (@Staff_id,@First_name,@Last_name)", conn);
SqlParameter param = new SqlParameter ();
param. ParameterName = "@Staff_id";
param. Value = Convert. ToInt32 (Staff_id. Text);
param. SqlDbType = SqlDbType. Int;
cmd. Parameters. Add (param);
param = new SqlParameter ();
param. ParameterName = "@First_name";
param. Value = First_name. Text. ToString ();
param. SqlDbType = SqlDbType. Text;
cmd. Parameters. Add (param);
param = new SqlParameter ();
param. ParameterName = "@Last_name";
param. Value = Last_name. Text. ToString ();
param. SqlDbType = SqlDbType. Text;
cmd. Parameters. Add (param);
try
{
cmd. ExecuteNonQuery ();
}
catch
{
MessageBox. Show ("Ошибка, при выполнении запроса на добавление записи");
return;
}
MessageBox. Show ("Запись успешно добавлена");
conn. Close ();
conn. Dispose ();
break;
}
case "Mounters":
{
SqlCommand cmd = new SqlCommand ("Insert into Mounters" +
" (Mounter_id,Name,Speed) Values (@Mounter_id,@Name,@Speed)", conn);
SqlParameter param = new SqlParameter ();
param. ParameterName = "@Mounter_id";
param. Value = Convert. ToInt32 (Mounter_id. Text);
param. SqlDbType = SqlDbType. Int;
cmd. Parameters. Add (param);
param = new SqlParameter ();
param. ParameterName = "@Name";
param. Value = Name_mounter. Text. ToString ();
param. SqlDbType = SqlDbType. Text;
cmd. Parameters. Add (param);
param = new SqlParameter ();
param. ParameterName = "@Speed";
param. Value = Convert. ToInt32 (Speed. Text);
param. SqlDbType = SqlDbType. Int;
cmd. Parameters. Add (param);
try
{
cmd. ExecuteNonQuery ();
}
catch
{
MessageBox. Show ("Ошибка, при выполнении запроса на добавление записи");
return;
}
MessageBox. Show ("Запись успешно добавлена");
conn. Close ();
conn. Dispose ();
break;
}
case "Assemblies":
{
SqlCommand cmd = new SqlCommand ("Insert into Assemblies" +
" (Board_id,Mounter_id,Time) Values (@Board_id,@Mounter_id,@Time)", conn);
SqlParameter param = new SqlParameter ();
param. ParameterName = "@Board_id";
param. Value = Convert. ToInt32 (Board_id_assembl. Text);
param. SqlDbType = SqlDbType. Int;
cmd. Parameters. Add (param);
param = new SqlParameter ();
param. ParameterName = "@Mounter_id";
param. Value = Convert. ToInt32 (Mounter_id_assembl. Text);
param. SqlDbType = SqlDbType. Int;
cmd. Parameters. Add (param);
param = new SqlParameter ();
param. ParameterName = "@Time";
param. Value = Convert. ToInt32 (Time. Text);
param. SqlDbType = SqlDbType. Int;
cmd. Parameters. Add (param);
try
{
cmd. ExecuteNonQuery ();
}
catch
{
MessageBox. Show ("Ошибка, при выполнении запроса на добавление записи");
return;
}
MessageBox. Show ("Запись успешно добавлена");
conn. Close ();
conn. Dispose ();
break;
}
case "Customers":
{
SqlCommand cmd = new SqlCommand ("Insert into Customers" +
" (Customer_id,Name) Values (@Customer_id,@Name)", conn);
SqlParameter param = new SqlParameter ();
param. ParameterName = "@Customer_id";
param. Value = Convert. ToInt32 (Customer_id. Text);
param. SqlDbType = SqlDbType. Int;
cmd. Parameters. Add (param);
param = new SqlParameter ();
param. ParameterName = "@Name";
param. Value = Name_customer. Text. ToString ();
param. SqlDbType = SqlDbType. Text;
cmd. Parameters. Add (param);
try
{
cmd. ExecuteNonQuery ();
}
catch
{
MessageBox. Show ("Ошибка, при выполнении запроса на добавление записи");
return;
}
MessageBox. Show ("Запись успешно добавлена");
conn. Close ();
conn. Dispose ();
break;
}
case "Boards":
{
SqlCommand cmd = new SqlCommand ("Insert into Boards" +
" (Board_id,Elements,Customer_id,Name,Type) Values (@Board_id,@Elements,@Customer_id,@Name,@Type)", conn);
SqlParameter param = new SqlParameter ();
param. ParameterName = "@Board_id";
param. Value = Convert. ToInt32 (Board_id. Text);
param. SqlDbType = SqlDbType. Int;
cmd. Parameters. Add (param);
param = new SqlParameter ();
param. ParameterName = "@Elements";
param. Value = Convert. ToInt32 (Elements. Text);
param. SqlDbType = SqlDbType. Int;
cmd. Parameters. Add (param);
param = new SqlParameter ();
param. ParameterName = "@Customer_id";
param. Value = Convert. ToInt32 (Customer_board. Text);
param. SqlDbType = SqlDbType. Int;
cmd. Parameters. Add (param);
param = new SqlParameter ();
param. ParameterName = "@Name";
param. Value = Name_board. Text. ToString ();
param. SqlDbType = SqlDbType. Text;
cmd. Parameters. Add (param);
param = new SqlParameter ();
param. ParameterName = "@Type";
param. Value = Convert. ToInt32 (Type_board. Text);
param. SqlDbType = SqlDbType. Int;
cmd. Parameters. Add (param);
try
{
cmd. ExecuteNonQuery ();
}
catch
{
MessageBox. Show ("Ошибка, при выполнении запроса на добавление записи");
return;
}
MessageBox. Show ("Запись успешно добавлена");
conn. Close ();
conn. Dispose ();
break;
}
case "Productions":
{
SqlCommand cmd = new SqlCommand ("Insert into Productions" +
" (Date,Smena,Board_id,Mounter_id,Printer_id,Staff_id) Values (@Date,@Smena,@Board_id,@Mounter_id,@Printer_id,@Staff_id)", conn);
SqlParameter param = new SqlParameter ();
param. ParameterName = "@Date";
param. Value = Convert. ToDateTime (Date. Text);
param. SqlDbType = SqlDbType. DateTime;
cmd. Parameters. Add (param);
param = new SqlParameter ();
param. ParameterName = "@Smena";
param. Value = Convert. ToInt32 (Smena. Text);
param. SqlDbType = SqlDbType. Int;
cmd. Parameters. Add (param);
param = new SqlParameter ();
param. ParameterName = "@Board_id";
param. Value = Convert. ToInt32 (Board_id_prod. Text);
param. SqlDbType = SqlDbType. Int;
cmd. Parameters. Add (param);
param = new SqlParameter ();
param. ParameterName = "@Mounter_id";
param. Value = Convert. ToInt32 (Mounter_id_prod. Text);
param. SqlDbType = SqlDbType. Int;
cmd. Parameters. Add (param);
param = new SqlParameter ();
param. ParameterName = "@Printer_id";
param. Value = Convert. ToInt32 (Printer_id_prod. Text);
param. SqlDbType = SqlDbType. Int;
cmd. Parameters. Add (param);
param = new SqlParameter ();
param. ParameterName = "@Staff_id";
param. Value = Convert. ToInt32 (Staff_id_prod. Text);
param. SqlDbType = SqlDbType. Int;
cmd. Parameters. Add (param);
try
{
cmd. ExecuteNonQuery ();
}
catch
{
MessageBox. Show ("Ошибка, при выполнении запроса на добавление записи");
return;
}
MessageBox. Show ("Запись успешно добавлена");
conn. Close ();
conn. Dispose ();
break;
}
default: break;
}
}
}
}
8.3 Модуль окна "Изменить"
8.3.1 Файл представления edit. xaml
<Window x: Class="Motherboard. edit"
xmlns="http://schemas. microsoft.com/winfx/2006/xaml/presentation"
xmlns: x="http://schemas. microsoft.com/winfx/2006/xaml"
Title="Изменить информацию в базе" mc: Ignorable="d" xmlns: d="http://schemas. microsoft.com/expression/blend/2008" xmlns: mc="http://schemas. openxmlformats.org/markup-compatibility/2006" d: DesignHeight="260" d: DesignWidth="446" SizeToContent="WidthAndHeight">
<Grid>
<GroupBox Header="Введите данные" Height="216" HorizontalAlignment="Left" Name="groupBox3" VerticalAlignment="Top" Width="478"></GroupBox>
<Grid Name="gbGrid" Width="409" Margin="6,12,8,12">
<TextBox Height="23" HorizontalAlignment="Left" Margin="106,6,0,0" Name="Printer_id" VerticalAlignment="Top" Width="120" Visibility="Hidden" />
<TextBox Height="23" HorizontalAlignment="Left" Margin="106,35,0,0" Name="Name_printer" VerticalAlignment="Top" Width="120" Visibility="Hidden" />
<TextBox Height="23" HorizontalAlignment="Left" Margin="106,64,0,0" Name="Type_printer" VerticalAlignment="Top" Width="120" Visibility="Hidden" />
<TextBox Height="23" HorizontalAlignment="Left" Margin="106,6,0,0" Name="Mounter_id" VerticalAlignment="Top" Width="120" Visibility="Hidden" />
<TextBox Height="23" HorizontalAlignment="Left" Margin="106,35,0,0" Name="Name_mounter" VerticalAlignment="Top" Width="120" Visibility="Hidden" />
<TextBox Height="23" HorizontalAlignment="Left" Margin="106,64,0,0" Name="Speed" VerticalAlignment="Top" Width="120" Visibility="Hidden" />
<TextBox Height="23" HorizontalAlignment="Left" Margin="106,6,0,0" Name="Staff_id" VerticalAlignment="Top" Width="120" Visibility="Hidden" />
<TextBox Height="23" HorizontalAlignment="Left" Margin="106,35,0,0" Name="First_name" VerticalAlignment="Top" Width="120" Visibility="Hidden" />
<TextBox Height="23" HorizontalAlignment="Left" Margin="106,64,0,0" Name="Last_name" VerticalAlignment="Top" Width="120" Visibility="Hidden" />
<TextBox Height="23" HorizontalAlignment="Left" Margin="106,6,0,0" Name="Customer_id" VerticalAlignment="Top" Width="120" Visibility="Hidden" />
<TextBox Height="23" HorizontalAlignment="Left" Margin="106,35,0,0" Name="Name_customer" VerticalAlignment="Top" Width="120" Visibility="Hidden" />
<TextBox Height="23" HorizontalAlignment="Left" Margin="106,6,0,0" Name="Board_id" VerticalAlignment="Top" Width="120" Visibility="Hidden" />
<TextBox Height="23" HorizontalAlignment="Left" Margin="106,35,0,0" Name="Elements" VerticalAlignment="Top" Width="120" Visibility="Hidden" />
<TextBox Height="23" HorizontalAlignment="Left" Margin="106,64,0,0" Name="Customer_board" VerticalAlignment="Top" Width="120" Visibility="Hidden" />
<TextBox Height="23" HorizontalAlignment="Left" Margin="106,93,0,0" Name="Name_board" VerticalAlignment="Top" Width="120" Visibility="Hidden" />
<TextBox Height="23" HorizontalAlignment="Left" Margin="106,122,0,0" Name="Type_board" VerticalAlignment="Top" Width="120" Visibility="Hidden" />
<TextBox Height="23" HorizontalAlignment="Left" Margin="106,6,0,0" Name="Board_id_assembl" VerticalAlignment="Top" Width="120" Visibility="Hidden" />
<TextBox Height="23" HorizontalAlignment="Left" Margin="106,35,0,0" Name="Mounter_id_assembl" VerticalAlignment="Top" Width="120" Visibility="Hidden" />
<TextBox Height="23" HorizontalAlignment="Left" Margin="106,64,0,0" Name="Time" VerticalAlignment="Top" Width="120" Visibility="Hidden" />
<TextBox Height="23" HorizontalAlignment="Left" Margin="106,6,0,0" Name="Date" VerticalAlignment="Top" Width="120" Visibility="Hidden" />
<TextBox Height="23" HorizontalAlignment="Left" Margin="106,35,0,0" Name="Smena" VerticalAlignment="Top" Width="120" Visibility="Hidden" />
<TextBox Height="23" HorizontalAlignment="Left" Margin="106,64,0,0" Name="Board_id_prod" VerticalAlignment="Top" Width="120" Visibility="Hidden" />
<TextBox Height="23" HorizontalAlignment="Left" Margin="106,93,0,0" Name="Mounter_id_prod" VerticalAlignment="Top" Width="120" Visibility="Hidden" />
<TextBox Height="23" HorizontalAlignment="Left" Margin="106,122,0,0" Name="Printer_id_prod" VerticalAlignment="Top" Width="120" Visibility="Hidden" />
<TextBox Height="23" HorizontalAlignment="Left" Margin="106,151,0,0" Name="Staff_id_prod" VerticalAlignment="Top" Width="120" Visibility="Hidden" />
<Label Content="Printer id" Height="28" HorizontalAlignment="Left" Margin="6,6,0,0" Name="label1" VerticalAlignment="Top" Width="94" Visibility="Hidden" />
<Label Content="Name" Height="28" HorizontalAlignment="Left" Margin="6,35,0,0" Name="label2" VerticalAlignment="Top" Width="94" Visibility="Hidden" />
<Label Content="Type" Height="28" HorizontalAlignment="Left" Margin="6,64,0,0" Name="label3" VerticalAlignment="Top" Width="94" Visibility="Hidden" />
<Label Content="Mounter id" Height="28" HorizontalAlignment="Left" Margin="6,93,0,0" Name="label4" VerticalAlignment="Top" Width="94" Visibility="Hidden" />
<Label Content="Name" Height="28" HorizontalAlignment="Left" Margin="6,122,0,0" Name="label5" VerticalAlignment="Top" Width="94" Visibility="Hidden" />
<Label Content="Speed" Height="28" HorizontalAlignment="Left" Margin="6,151,0,0" Name="label6" VerticalAlignment="Top" Width="94" Visibility="Hidden" />
<Label Content="Staff id" Height="28" HorizontalAlignment="Left" Margin="6,6,0,0" Name="label7" VerticalAlignment="Top" Width="94" Visibility="Hidden" />
<Label Content="First Name" Height="28" HorizontalAlignment="Left" Margin="6,35,0,0" Name="label8" VerticalAlignment="Top" Width="94" Visibility="Hidden" />
<Label Content="Last Name" Height="28" HorizontalAlignment="Left" Margin="6,64,0,0" Name="label9" VerticalAlignment="Top" Width="94" Visibility="Hidden" />
<Label Content="Customer id" Height="28" HorizontalAlignment="Left" Margin="6,93,0,0" Name="label10" VerticalAlignment="Top" Width="94" Visibility="Hidden" />
<Label Content="Name" Height="28" HorizontalAlignment="Left" Margin="6,122,0,0" Name="label11" VerticalAlignment="Top" Width="94" Visibility="Hidden" />
<Label Content="Board id" Height="28" HorizontalAlignment="Left" Margin="6,151,0,0" Name="label12" VerticalAlignment="Top" Width="94" Visibility="Hidden" />
<Label Content="Elements" Height="28" HorizontalAlignment="Left" Margin="6,6,0,0" Name="label13" VerticalAlignment="Top" Width="94" Visibility="Hidden" />
<Label Content="Customer" Height="28" HorizontalAlignment="Left" Margin="6,35,0,0" Name="label14" VerticalAlignment="Top" Width="94" Visibility="Hidden" />
<Label Content="Name" Height="28" HorizontalAlignment="Left" Margin="6,64,0,0" Name="label15" VerticalAlignment="Top" Width="94" Visibility="Hidden" />
<Label Content="Type" Height="28" HorizontalAlignment="Left" Margin="6,93,0,0" Name="label16" VerticalAlignment="Top" Width="94" Visibility="Hidden" />
<Label Content="Board id" Height="28" HorizontalAlignment="Left" Margin="6,122,0,0" Name="label17" VerticalAlignment="Top" Width="94" Visibility="Hidden" />
<Label Content="Mounter id" Height="28" HorizontalAlignment="Left" Margin="6,151,0,0" Name="label18" VerticalAlignment="Top" Width="94" Visibility="Hidden" />
<Label Content="Time" Height="28" HorizontalAlignment="Left" Margin="6,6,0,0" Name="label19" VerticalAlignment="Top" Width="94" Visibility="Hidden" />
<Label Content="Date" Height="28" HorizontalAlignment="Left" Margin="6,35,0,0" Name="label20" VerticalAlignment="Top" Width="94" Visibility="Hidden" />
<Label Content="Smena" Height="28" HorizontalAlignment="Left" Margin="6,64,0,0" Name="label21" VerticalAlignment="Top" Width="94" Visibility="Hidden" />
<Label Content="Board id" Height="28" HorizontalAlignment="Left" Margin="6,93,0,0" Name="label22" VerticalAlignment="Top" Width="94" Visibility="Hidden" />
<Label Content="Mounter id" Height="28" HorizontalAlignment="Left" Margin="6,122,0,0" Name="label23" VerticalAlignment="Top" Width="94" Visibility="Hidden" />
<Label Content="Printer id" Height="28" HorizontalAlignment="Left" Margin="6,151,0,0" Name="label24" VerticalAlignment="Top" Width="94" Visibility="Hidden" />
<Label Content="Staff id" Height="28" HorizontalAlignment="Left" Margin="6,151,0,0" Name="label25" VerticalAlignment="Top" Width="94" Visibility="Hidden" />
<Button Content="Изменить" Height="23" HorizontalAlignment="Left" Margin="328,150,0,0" Name="addBtn" VerticalAlignment="Top" Width="75" Click="editBtn_Click" />
</Grid>
</Grid>
</Window>
8.3.2 Файл исходного кода edit. xaml. cs
using System;
using System. Collections. Generic;
using System. Linq;
using System. Text;
using System. Windows;
using System. Windows. Controls;
using System. Windows. Data;
using System. Windows. Documents;
using System. Windows. Input;
using System. Windows. Media;
using System. Windows. Media. Imaging;
using System. Windows. Shapes;
using System. Data;
using System. Data. SqlClient;
namespace Motherboard
{
// / <summary>
// / Логика взаимодействия для edit. xaml
// / </summary>
public partial class edit: Window
{
static public string tblName, key;
public edit (string tableName, string field)
{
InitializeComponent ();
tblName = tableName;
key = field;
createrControls (tblName);
}
private void createrControls (string tableName)
{
switch (tableName)
{
case "Printers":
{
label1. Visibility = Visibility. Visible;
label2. Visibility = Visibility. Visible;
label3. Visibility = Visibility. Visible;
Printer_id. Visibility = Visibility. Visible;
Name_printer. Visibility = Visibility. Visible;
Type_printer. Visibility = Visibility. Visible;
break;
}
case "Mounters":
{
label4. Visibility = Visibility. Visible;
label5. Visibility = Visibility. Visible;
label6. Visibility = Visibility. Visible;
Mounter_id. Visibility = Visibility. Visible;
Name_mounter. Visibility = Visibility. Visible;
Speed. Visibility = Visibility. Visible;
break;
}
case "Staff":
{
label7. Visibility = Visibility. Visible;
label8. Visibility = Visibility. Visible;
label9. Visibility = Visibility. Visible;
Staff_id. Visibility = Visibility. Visible;
First_name. Visibility = Visibility. Visible;
Last_name. Visibility = Visibility. Visible;
break;
}
case "Customers":
{
label10. Visibility = Visibility. Visible;
label11. Visibility = Visibility. Visible;
Customer_id. Visibility = Visibility. Visible;
Name_customer. Visibility = Visibility. Visible;
break;
}
case "Boards":
{
label12. Visibility = Visibility. Visible;
label13. Visibility = Visibility. Visible;
label14. Visibility = Visibility. Visible;
label15. Visibility = Visibility. Visible;
label16. Visibility = Visibility. Visible;
Board_id. Visibility = Visibility. Visible;
Elements. Visibility = Visibility. Visible;
Customer_board. Visibility = Visibility. Visible;
Name_board. Visibility = Visibility. Visible;
Type_board. Visibility = Visibility. Visible;
break;
}
case "Assemblies":
{
label17. Visibility = Visibility. Visible;
label18. Visibility = Visibility. Visible;
label19. Visibility = Visibility. Visible;
Board_id_assembl. Visibility = Visibility. Visible;
Mounter_id_assembl. Visibility = Visibility. Visible;
Time. Visibility = Visibility. Visible;
break;
}
case "Productions":
{
label20. Visibility = Visibility. Visible;
label21. Visibility = Visibility. Visible;
label22. Visibility = Visibility. Visible;
label23. Visibility = Visibility. Visible;
label24. Visibility = Visibility. Visible;
label25. Visibility = Visibility. Visible;
Date. Visibility = Visibility. Visible;
Smena. Visibility = Visibility. Visible;
Board_id_prod. Visibility = Visibility. Visible;
Mounter_id_prod. Visibility = Visibility. Visible;
Printer_id_prod. Visibility = Visibility. Visible;
Staff_id_prod. Visibility = Visibility. Visible;
break;
}
default: break;
}
}
private void editBtn_Click (object sender, RoutedEventArgs e)
{
string connStr = @"Data Source= (local); " +
"Initial Catalog = DB_motherboard; " +
"Integrated Security = True; ";
SqlConnection conn = new SqlConnection (connStr);
try
{
conn. Open ();
}
catch (SqlException se)
{
MessageBox. Show (se. Message);
return;
}
// основная команда
/*SqlCommand cmd = new SqlCommand ("Update " + tblName +
" set " + window. dataGrid1. CurrentCell. Column. Header + " = @ID", conn);
SqlParameter param = new SqlParameter ();
param. ParameterName = "@ID";
param. Value = Convert. ToInt32 (field);
param. SqlDbType = SqlDbType. Int;
cmd. Parameters. Add (param); */
//
switch (tblName)
{
case "Printers":
{
SqlCommand cmd = new SqlCommand ("UPDATE Printers " +
"SET Printer_id = @Printer_id, Name = @Name_printer, Type = @Type_printer WHERE Printer_id = @Key", conn);
SqlParameter param = new SqlParameter ();
param. ParameterName = "@Printer_id";
param. Value = Convert. ToInt32 (Printer_id. Text);
param. SqlDbType = SqlDbType. Int;
cmd. Parameters. Add (param);
param = new SqlParameter ();
param. ParameterName = "@Name_printer";
param. Value = Name_printer. Text. ToString ();
param. SqlDbType = SqlDbType. Text;
cmd. Parameters. Add (param);
param = new SqlParameter ();
param. ParameterName = "@Type_printer";
param. Value = Convert. ToInt32 (Type_printer. Text);
param. SqlDbType = SqlDbType. Int;
cmd. Parameters. Add (param);
param = new SqlParameter ();
param. ParameterName = "@Key";
param. Value = Convert. ToInt32 (key);
param. SqlDbType = SqlDbType. Int;
cmd. Parameters. Add (param);
try
{
cmd. ExecuteNonQuery ();
}
catch (SqlException se)
{
MessageBox. Show (se. Message,"Ошибка, при выполнении запроса на изменение записи");
return;
}
// закрвываем соединение
MessageBox. Show ("Запись успешно изменена");
conn. Close ();
conn. Dispose ();
break;
}
case "Staff":
{
SqlCommand cmd = new SqlCommand ("Update Staff" +
" (Staff_id,First Name,Last Name) Set (@Staff_id,@First_name,@Last_name)", conn);
SqlParameter param = new SqlParameter ();
param. ParameterName = "@Staff_id";
param. Value = Convert. ToInt32 (Staff_id. Text);
param. SqlDbType = SqlDbType. Int;
cmd. Parameters. Add (param);
param = new SqlParameter ();
param. ParameterName = "@First_name";
param. Value = First_name. Text. ToString ();
param. SqlDbType = SqlDbType. Text;
cmd. Parameters. Add (param);
param = new SqlParameter ();
param. ParameterName = "@Last_name";
param. Value = Last_name. Text. ToString ();
param. SqlDbType = SqlDbType. Text;
cmd. Parameters. Add (param);
try
{
cmd. ExecuteNonQuery ();
}
catch
{
MessageBox. Show ("Ошибка, при выполнении запроса на изменение записи");
return;
}
MessageBox. Show ("Запись успешно изменена");
conn. Close ();
conn. Dispose ();
break;
}
case "Mounters":
{
SqlCommand cmd = new SqlCommand ("Update Mounters" +
" (Mounter_id,Name,Speed) Set (@Mounter_id,@Name,@Speed)", conn);
SqlParameter param = new SqlParameter ();
param. ParameterName = "@Mounter_id";
param. Value = Convert. ToInt32 (Mounter_id. Text);
param. SqlDbType = SqlDbType. Int;
cmd. Parameters. Add (param);
param = new SqlParameter ();
param. ParameterName = "@Name";
param. Value = Name_mounter. Text. ToString ();
param. SqlDbType = SqlDbType. Text;
cmd. Parameters. Add (param);
param = new SqlParameter ();
param. ParameterName = "@Speed";
param. Value = Convert. ToInt32 (Speed. Text);
param. SqlDbType = SqlDbType. Int;
cmd. Parameters. Add (param);
try
{
cmd. ExecuteNonQuery ();
}
catch
{
MessageBox. Show ("Ошибка, при выполнении запроса на изменение записи");
return;
}
MessageBox. Show ("Запись успешно изменена");
conn. Close ();
conn. Dispose ();
break;
}
case "Assemblies":
{
SqlCommand cmd = new SqlCommand ("Update Assemblies" +
" (Board_id,Mounter_id,Time) Set (@Board_id,@Mounter_id,@Time)", conn);
SqlParameter param = new SqlParameter ();
param. ParameterName = "@Board_id";
param. Value = Convert. ToInt32 (Board_id_assembl. Text);
param. SqlDbType = SqlDbType. Int;
cmd. Parameters. Add (param);
param = new SqlParameter ();
param. ParameterName = "@Mounter_id";
param. Value = Convert. ToInt32 (Mounter_id_assembl. Text);
param. SqlDbType = SqlDbType. Int;
cmd. Parameters. Add (param);
param = new SqlParameter ();
param. ParameterName = "@Time";
param. Value = Convert. ToInt32 (Time. Text);
param. SqlDbType = SqlDbType. Int;
cmd. Parameters. Add (param);
try
{
cmd. ExecuteNonQuery ();
}
catch
{
MessageBox. Show ("Ошибка, при выполнении запроса на изменение записи");
return;
}
MessageBox. Show ("Запись успешно изменена");
conn. Close ();
conn. Dispose ();
break;
}
case "Customers":
{
SqlCommand cmd = new SqlCommand ("Update Customers" +
" (Customer_id,Name) Set (@Customer_id,@Name)", conn);
SqlParameter param = new SqlParameter ();
param. ParameterName = "@Customer_id";
param. Value = Convert. ToInt32 (Customer_id. Text);
param. SqlDbType = SqlDbType. Int;
cmd. Parameters. Add (param);
param = new SqlParameter ();
param. ParameterName = "@Name";
param. Value = Name_customer. Text. ToString ();
param. SqlDbType = SqlDbType. Text;
cmd. Parameters. Add (param);
try
{
cmd. ExecuteNonQuery ();
}
catch
{
MessageBox. Show ("Ошибка, при выполнении запроса на изменение записи");
return;
}
MessageBox. Show ("Запись успешно изменена");
conn. Close ();
conn. Dispose ();
break;
}
case "Boards":
{
SqlCommand cmd = new SqlCommand ("Update Boards" +
" (Board_id,Elements,Customer_id,Name,Type) Set (@Board_id,@Elements,@Customer_id,@Name,@Type)", conn);
SqlParameter param = new SqlParameter ();
param. ParameterName = "@Board_id";
param. Value = Convert. ToInt32 (Board_id. Text);
param. SqlDbType = SqlDbType. Int;
cmd. Parameters. Add (param);
param = new SqlParameter ();
param. ParameterName = "@Elements";
param. Value = Convert. ToInt32 (Elements. Text);
param. SqlDbType = SqlDbType. Int;
cmd. Parameters. Add (param);
param = new SqlParameter ();
param. ParameterName = "@Customer_id";
param. Value = Convert. ToInt32 (Customer_board. Text);
param. SqlDbType = SqlDbType. Int;
Подобные документы
Специфика создания баз данных, в которой хранится информация о производственных ресурсах для производства печатных плат. Характеристика, использование и работа с DBDesigner 4.0.5.6, PostgreSQL. Особенности написания запросов к базам данных на языке SQL.
курсовая работа [147,9 K], добавлен 13.08.2012Проектирование программного обеспечения для создания баз данных о работах студентов университета при помощи языка Visual Basic. Разработка интерфейса пользователя. Руководство для системного программиста. Краткое описание алгоритма работы с программой.
курсовая работа [2,6 M], добавлен 19.03.2010Логическая структура программы. Руководство системного программиста, пользователя. Требования к уровню обеспечения информационной безопасности. Цели и задачи защиты данных. Расчет себестоимости и отпускной цены системы. Техника безопасности, охрана труда.
дипломная работа [1,5 M], добавлен 27.06.2014Инфологическая и даталогическая модели предметной области. Проектирование функциональной структуры приложения, защиты базы данных. Алгоритмы решения задачи и их реализация. Разработка инструкций для сопровождающего программиста и для пользователя.
курсовая работа [2,5 M], добавлен 20.11.2013Алгоритм работы программы. Анализ предметной области. Структура таблиц БД "Библиотека". Инфологическое и даталогическое проектирование. Запросы для поиска и извлечения только требуемых данных. Формы для просмотра, добавления, изменения данных в таблицах.
курсовая работа [5,1 M], добавлен 14.06.2014Анализ предметной области. Обзор программ-аналогов. Рассмотрение средств решения поставленной задачи. Проектирование структуры программы и базовых алгоритмов. Изучение руководства программиста и пользователя. Проектирование структуры базы данных.
курсовая работа [1,0 M], добавлен 14.11.2017Технология деятельности техника-программиста на предприятии. Анализ предметной области. Обоснование выбора среды разработки. Сравнительный анализ методов сортировки данных. Проектирование базы данных. Методы, алгоритм и средства обработки данных.
отчет по практике [498,2 K], добавлен 03.05.2015Техническое задание на разработку программного продукта и требования к программе. Написание алгоритма работы и разработка интерфейса программы. Руководство системного программиста и оператора. Основные методы и принципы тестирования базы данных.
дипломная работа [2,7 M], добавлен 27.01.2013Анализ предметной области АИС "Подписка". Проектирование базы данных методом "Сущность-Связь" для разработанной функциональной модели. Описание таблиц базы данных. Выбор программного обеспечения, требования к нему. Краткое руководство пользователя.
курсовая работа [719,6 K], добавлен 15.09.2012Разработка базы данных с целью автоматизации процессов составления, ведения и распространения информации об расписании занятий в спортивном комплексе "Маяк". Анализ предметной области. Разработка алгоритмов работы программы и приложения пользователя.
дипломная работа [1,0 M], добавлен 12.07.2015