stwr. NewLine = Separ("Итого ", DoChangeSell(textBoxSum. Text).ToString(), "ПМР", textBoxSum. Text, comboBox2.Text, " ") + "\r\n";

stwr. WriteLine();

stwr. NewLine = Separ("", "", "", "", "", "-") + "-----\r\n";

stwr. WriteLine();

stwr. NewLine = DateTime. Now + " --- " + "Код " + obmen_ValutTableAdapter. ScalarQueryID().ToString() + "\r\n";

stwr. WriteLine();

stwr. NewLine = " \r\n";

stwr. WriteLine();

stwr. NewLine = toolStripStatusLabel2.Text + toolStripStatusLabel1.Text + " ___________ \r\n";

stwr. WriteLine();

stwr. NewLine = " \r\n";

stwr. WriteLine();

stwr. NewLine = Separ("", "", "", "", "", "-") + "-----\r\n";

stwr. WriteLine();

}

stwr. Close();

}

catch (Exception exc)

{

if (MessageBox. Show("Ошибка подготовки к печати:\n" + exc. Message, "Ошибка", MessageBoxButtons. RetryCancel, MessageBoxIcon. Error) == DialogResult. Retry)

PrintCheckSell();

}

Printing();

}

// Вычисление длины строк

private string Separ(string str1, string str2, string str3, string str4, string str5, string sep)

{

int countSer = 0;

string temp = str1;

countSer = 5 - str1.Length;

for (int i = 0; i < countSer; i++)

temp += sep;

countSer = 15 - str2.Length;

for (int i = 0; i < countSer; i++)

temp += sep;

НЕ нашли? Не то? Что вы ищете?

temp += str2;

countSer = 5 - str3.Length;

for (int i = 0; i < countSer; i++)

temp += sep;

temp += str3;

countSer = 15 - str4.Length;

for (int i = 0; i < countSer; i++)

temp += sep;

temp += str4;

countSer = 5 - str5.Length;

for (int i = 0; i < countSer; i++)

temp += sep;

temp += str5;

countSer = 45 - temp. Length;

for (int i = 0; i < countSer; i++)

temp += sep;

return temp;

}

//метод распечатки файла

public void Printing()

{

try

{

streamToPrint = new StreamReader(filePath); // печать файла

try

{

printFont = new Font("Arial", 10);

PrintDocument pd = new PrintDocument();

pd. PrintPage += new PrintPageEventHandler(pd_PrintPage);

pd. Print();

}

finally

{

streamToPrint. Close();

}

}

catch (Exception ex)

{

MessageBox. Show(ex. Message, "Ошибка печати", MessageBoxButtons. OK, MessageBoxIcon. Error);

}

}

//метод добавления события распечатки

void pd_PrintPage(object sender, PrintPageEventArgs ev)

{

float linesPerPage = 0;

float yPos = 0;

int count = 0;

float leftMargin = ev. MarginBounds. Left;

float topMargin = ev. MarginBounds. Top;

String line = null;

// Calculate the number of lines per page.

linesPerPage = ev. MarginBounds. Height /

printFont. GetHeight(ev. Graphics);

// Iterate over the file, printing each line.

while (count < linesPerPage &&

((line = streamToPrint. ReadLine()) != null))

{

yPos = topMargin + (count * printFont. GetHeight(ev. Graphics));

ev. Graphics. DrawString(line, printFont, Brushes. Black,

leftMargin, yPos, new StringFormat());

count++;

}

// If more lines exist, print another page.

if (line!= null)

ev. HasMorePages = true;

else

ev. HasMorePages = false;

}

//Проверка правильности значений на ввод в графу получено

private void textBoxPolucheno_TextChanged(object sender, EventArgs e)

{

if (textBoxPolucheno. Text. StartsWith("-") == true || textBoxPolucheno. Text. StartsWith("0") == true)

{

MessageBox. Show("Ошибка ввода.", "Ошибка ввода данных", MessageBoxButtons. OK, MessageBoxIcon. Information);

textBoxPolucheno. Text = "";

}

}

// Запись в базу данных значений произведенной операции Покупки

private void button1_Click(object sender, EventArgs e)

{

try

{

if (textBoxPolucheno. Text == "" || comboBox1.Text == "" || textBoxSumma_Obmena. Text == "")

{

MessageBox. Show("Не все поля заполнены или не выбрана валюта обмена.\nПопробуйте еще раз.", "Ошибка ввода данных", MessageBoxButtons. OK, MessageBoxIcon. Information);

}

else

{

obmen_ValutTableAdapter. InsertQueryObmen_Valut(Convert. ToSingle(textBoxSumma_Obmena. Text), comboBox1.Text, "PMR", Convert. ToSingle(labelITOGO. Text), Convert. ToSingle(DoChangeBuy(textBoxSumma_Obmena. Text)), DateTime. Now. Date, toolStripStatusLabel1.Text, SelectKursBuy());

if (MessageBox. Show("Данные занесены в базу данных.\nХотите распечатать чек?", "База данных", MessageBoxButtons. YesNo, MessageBoxIcon. Information) == DialogResult. Yes)

{

PrintCheckBuy();

}

textBoxPolucheno. Text = "";

textBoxSumma_Obmena. Text = "";

labelITOGO. Text = "";

labelSdacha_po. Text = "";

comboBox1.Text = "";

}

}

catch (Exception ex)

{

MessageBox. Show(ex. Message, "Ошибка", MessageBoxButtons. OK, MessageBoxIcon. Error);

}

}

// Расчет суммы

private void button2_Click(object sender, EventArgs e)

{

if (textBoxPolucheno. Text == "" || textBoxSumma_Obmena. Text == "" || comboBox1.Text == "")

{

MessageBox. Show("Не все поля заполнены или не выбрана валюта обмена.\nПопробуйте еще раз.", "Ошибка ввода данных", MessageBoxButtons. OK, MessageBoxIcon. Information);

}

else

{// Проверка на ввод суммы обмена ( полученная сумма > суммы обмена )

if (Convert. ToDouble(textBoxPolucheno. Text) >= Convert. ToDouble(textBoxSumma_Obmena. Text))

{

double sdacha = 0;

sdacha = Convert. ToDouble(textBoxPolucheno. Text) - Convert. ToDouble(textBoxSumma_Obmena. Text);

labelITOGO. Text = DoChangeBuy(textBoxSumma_Obmena. Text).ToString();

labelSdacha_po. Text = sdacha. ToString() + " " + comboBox1.Text;

}

else

{

MessageBox. Show("Не верный ввод данных", "Ошибка", MessageBoxButtons. OK, MessageBoxIcon. Information);

}

}

}

// Расчет про операции Продажа

private void button3_Click(object sender, EventArgs e)

{

if (textBoxSum. Text == "" || textBoxPolucheno_p. Text == "" || comboBox2.Text == "")

{

MessageBox. Show("Не все поля заполнены или не выбрана валюта обмена.\nПопробуйте еще раз.", "Ошибка ввода данных", MessageBoxButtons. OK, MessageBoxIcon. Information);

}

else

{

double sum = DoChangeSell(textBoxSum. Text);

if (Convert. ToDouble(textBoxPolucheno_p. Text) >= sum)

{

float c = (float)(Convert. ToDouble(textBoxPolucheno_p. Text) - sum);

labelSdacha. Text = c. ToString() + " руб. ПМР";

}

else

{

MessageBox. Show("Полученой суммы не достаточно.", "Ошибка ввода данных", MessageBoxButtons. OK, MessageBoxIcon. Information);

}

}

}

// Проверка на ввод даных в графу Сумма

private void textBoxSum_TextChanged(object sender, EventArgs e)

{

if (textBoxSum. Text. StartsWith("-") == true || textBoxSum. Text. StartsWith("0") == true)

{

MessageBox. Show("Ошибка ввода.", "Ошибка ввода данных", MessageBoxButtons. OK, MessageBoxIcon. Information);

textBoxSum. Text = "";

}

else

{

if (textBoxSum. Text!= "" && comboBox2.Text!= "")

{

labelStoimost. Text = DoChangeSell(textBoxSum. Text).ToString();

}

}

}

// Если получена сумма денег для произведения операции покупки валюты

private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)

{

if (textBoxSum. Text!= "")

{

labelStoimost. Text = DoChangeSell(textBoxSum. Text).ToString();

}

}

// Проверка на ввод даных в графу получено денег в продаже

private void textBoxPolucheno_p_TextChanged(object sender, EventArgs e)

{

if (textBoxPolucheno_p. Text. StartsWith("-") == true || textBoxPolucheno_p. Text. StartsWith("0") == true)

{

MessageBox. Show("Ошибка ввода.", "Ошибка ввода данных", MessageBoxButtons. OK, MessageBoxIcon. Information);

textBoxPolucheno_p. Text = "";

}

}

// Проверка на ввод даных в графу Сумма обмена в продаже

private void textBoxSumma_Obmena_TextChanged(object sender, EventArgs e)

{

if (textBoxSumma_Obmena. Text. StartsWith("-") == true || textBoxSumma_Obmena. Text. StartsWith("0") == true)

{

MessageBox. Show("Ошибка ввода.", "Ошибка ввода данных", MessageBoxButtons. OK, MessageBoxIcon. Information);

textBoxSumma_Obmena. Text = "";

}

}

// Произвести обмен и запись в базу данных

private void button4_Click(object sender, EventArgs e)

{

try

{

if (textBoxSum. Text == "" || comboBox2.Text == "" || textBoxSum. Text == "")

{

MessageBox. Show("Не все поля заполнены или не выбрана валюта обмена.\nПопробуйте еще раз.", "Ошибка ввода данных", MessageBoxButtons. OK, MessageBoxIcon. Information);

}

else

{

obmen_ValutTableAdapter. InsertQueryObmen_Valut(Convert. ToSingle(labelStoimost. Text), "PMR", comboBox2.Text, Convert. ToSingle(textBoxSum. Text), Convert. ToSingle(DoChangeSell(textBoxSum. Text)), DateTime. Now. Date, toolStripStatusLabel1.Text, SelectKursSell());

if (MessageBox. Show("Данные занесены в базу данных.\nХотите распечатать чек?", "База данных", MessageBoxButtons. YesNo, MessageBoxIcon. Information) == DialogResult. Yes)

{

PrintCheckSell(); // Распечатать чек

}

textBoxSum. Text = "";

textBoxPolucheno_p. Text = "";

labelStoimost. Text = "";

labelSdacha. Text = "";

comboBox2.Text = "";

}

}

catch (Exception ex)

{

MessageBox. Show(ex. Message, "Ошибка", MessageBoxButtons. OK, MessageBoxIcon. Error);

}

}

// Обновить таблицу обмена валют

private void button5_Click(object sender, EventArgs e)

{

try

{

obmen_ValutTableAdapter. Fill(changeDatabaseDataSet. Obmen_Valut);

}

catch (Exception ex)

{

MessageBox. Show(ex. Message, "Ошибка", MessageBoxButtons. OK, MessageBoxIcon. Error);

}

}

// Выборка данных об обмене валют за день

private void button6_Click(object sender, EventArgs e)

{

try

{

obmen_ValutTableAdapter. FillByDate(changeDatabaseDataSet. Obmen_Valut, DateTime. Now. Date);

double sumpribl = 0;

double pribl=0;

for (int i = 0; i < dataGridView1.Rows. Count; i++)

{

if (dataGridView1.Rows[i].Cells[1].Value. ToString() == "PMR")

{

switch (dataGridView1.Rows[i].Cells[5].Value. ToString())

{

case "USD":

pribl = Math. Abs(Convert. ToDouble(prodagaTableAdapter. ScalarQueryUSDProdaga()) - Convert. ToDouble(pokypkaTableAdapter. ScalarQueryUSDPokypka()));

break;

case "EUR":

pribl = Math. Abs(Convert. ToDouble(prodagaTableAdapter. ScalarQueryEURProdaga()) - Convert. ToDouble(pokypkaTableAdapter. ScalarQueryEURPokypka()));

break;

case "MDL":

pribl = Math. Abs(Convert. ToDouble(prodagaTableAdapter. ScalarQueryMDLProdaga()) - Convert. ToDouble(pokypkaTableAdapter. ScalarQueryMDLPokypka()));

break;

case "UAH":

pribl = Math. Abs(Convert. ToDouble(prodagaTableAdapter. ScalarQueryUAHProdaga()) - Convert. ToDouble(pokypkaTableAdapter. ScalarQueryUAHPokypka()));

break;

case "RUB":

pribl = Math. Abs(Convert. ToDouble(prodagaTableAdapter. ScalarQueryRUBProdaga()) - Convert. ToDouble(pokypkaTableAdapter. ScalarQueryRUBPokypka()));

break;

}

sumpribl += pribl * Convert. ToDouble(dataGridView1.Rows[i].Cells[2].Value);

}

else

{

switch (dataGridView1.Rows[i].Cells[1].Value. ToString())

{

case "USD":

pribl = Math. Abs(Convert. ToDouble(prodagaTableAdapter. ScalarQueryUSDProdaga()) - Convert. ToDouble(pokypkaTableAdapter. ScalarQueryUSDPokypka()));

break;

case "EUR":

pribl = Math. Abs(Convert. ToDouble(prodagaTableAdapter. ScalarQueryEURProdaga()) - Convert. ToDouble(pokypkaTableAdapter. ScalarQueryEURPokypka()));

break;

case "MDL":

pribl = Math. Abs(Convert. ToDouble(prodagaTableAdapter. ScalarQueryMDLProdaga()) - Convert. ToDouble(pokypkaTableAdapter. ScalarQueryMDLPokypka()));

break;

case "UAH":

pribl = Math. Abs(Convert. ToDouble(prodagaTableAdapter. ScalarQueryUAHProdaga()) - Convert. ToDouble(pokypkaTableAdapter. ScalarQueryUAHPokypka()));

break;

case "RUB":

pribl = Math. Abs(Convert. ToDouble(prodagaTableAdapter. ScalarQueryRUBProdaga()) - Convert. ToDouble(pokypkaTableAdapter. ScalarQueryRUBPokypka()));

break;

}

sumpribl += pribl * Convert. ToDouble(dataGridView1.Rows[i].Cells[0].Value);

}

}

labelpribl. Text = "Прибыль за день: " + Convert. ToInt32(sumpribl).ToString() + " руб.";

}

catch (Exception ex)

{

MessageBox. Show(ex. Message, "Ошибка", MessageBoxButtons. OK, MessageBoxIcon. Error);

}

}

// Обновление базы данных при переходе из вклодок

private void tabControl1_SelectedIndexChanged(object sender, EventArgs e)

{

try

{

obmen_ValutTableAdapter. Fill(changeDatabaseDataSet. Obmen_Valut);

}

catch (Exception ex)

{

MessageBox. Show(ex. Message, "Ошибка", MessageBoxButtons. OK, MessageBoxIcon. Error);

}

}

// вызов формы добавления кассира

private void кассирToolStripMenuItem_Click(object sender, EventArgs e)

{

Sotrudniki s = new Sotrudniki();

s. ShowDialog();

}

// вызов формы изменение валют покупки

private void покупкаToolStripMenuItem_Click(object sender, EventArgs e)

{

if (pokypkaTableAdapter. ScalarQueryDateChange() != DateTime. Now. Date)

{

ChangeBuy ChB = new ChangeBuy();

ChB. ShowDialog();

UpdateBuyLabels();

}

else

{

MessageBox. Show("Невозможно изменить данные.\nСегодня уже была произведена установка курса валют покупки.", "Ошибка", MessageBoxButtons. OK, MessageBoxIcon. Information);

}

}

// вызов формы изменение валют продажи

private void продажаToolStripMenuItem_Click(object sender, EventArgs e)

{

if (prodagaTableAdapter. ScalarQueryDateChange() != DateTime. Now. Date)

{

ChangeSell ChS = new ChangeSell();

ChS. ShowDialog();

UpdateSellLabels();

}

else

{

MessageBox. Show("Невозможно изменить данные.\nСегодня уже была произведена установка курса валют продажи.", "Ошибка", MessageBoxButtons. OK, MessageBoxIcon. Information);

}

}

private void выходToolStripMenuItem_Click(object sender, EventArgs e)

{

Application. Exit();

}

// вызов значения программе

private void оПрограммеToolStripMenuItem_Click(object sender, EventArgs e)

{

About ab = new About();

ab. ShowDialog();

}

private void сотрудникиToolStripMenuItem_Click(object sender, EventArgs e)

{

if (toolStripStatusLabel1.Text. Trim() == "Администратор")

{

Sotrudniki s = new Sotrudniki();

s. ShowDialog();

}

else MessageBox. Show("Только администратор имеет право добавлять сотрудников","Запрещено",MessageBoxButtons. OK, MessageBoxIcon. Information);

}

private void button7_Click(object sender, EventArgs e)

{

SqlConnection conn = new SqlConnection(TRPO_lab10.Properties. Settings. Default. ChangeDatabaseConnectionString);

if (conn. State!= ConnectionState. Open)

conn. Open();

string SQL = "Select * from Obmen_Valut WHERE (Data >= @date1) AND (Data <= @date2) ";

StreamWriter sw = new StreamWriter("Inf. html");

SqlDataReader reader = null;

sw. WriteLine("<HTML>");

sw. WriteLine("<HEAD>");

sw. WriteLine("<TITLE>Отчет о совершённых операциях</TITLE>");

sw. WriteLine("<META HTTP-EQUIV=Content-Type CONTENT=charset=UTF-8>");

sw. WriteLine("</HEAD>");

sw. WriteLine("<BODY>");

//sw. WriteLine("<BR><BR><BR><BR>");

sw. WriteLine("<TABLE width = 100% BORDER=1>");

sw. WriteLine("<caption>Отчет о совершённых операциях с по </caption>");

//sw. WriteLine("<BR><BR>");

if (reader!= null)

reader = null;

SqlCommand cmd = new SqlCommand(SQL, conn);

SqlParameter p1 = new SqlParameter("date1",dateTimePicker1.Value. Date);

p1.SqlDbType = SqlDbType. SmallDateTime;

SqlParameter p2 = new SqlParameter("date2", dateTimePicker1.Value. Date);

p1.SqlDbType = SqlDbType. SmallDateTime;

cmd. Parameters. Add(p1);

cmd. Parameters. Add(p2);

try

{//word

reader = cmd. ExecuteReader();

sw. Write("<TR>");

sw. Write("<TH bgcolor = #FFFFFF>№ Операции</TH>");

sw. Write("<TH bgcolor = #FFFFFF align = center>Получено</TH>");

sw. Write("<TH bgcolor = #FFFFFF align = center>Полученная валюта</TH>");

sw. Write("<TH bgcolor = #FFFFFF align = center>Выдано</TH>");

sw. Write("<TH bgcolor = #FFFFFF align = center>Выданная валюта</TH>");

sw. Write("<TH bgcolor = #FFFFFF align = center>Курс</TH>");

sw. Write("<TH bgcolor = #FFFFFF align = center>Сумма обмена</TH>");

sw. Write("<TH bgcolor = #FFFFFF align = center>Дата</TH>");

sw. Write("<TH bgcolor = #FFFFFF align = center>Кассир</TH>");

sw. WriteLine("</TR>");

sw. WriteLine("</TR>");

while (reader. Read())

{

sw. WriteLine("<TR>");

sw. Write("<TH>{0}\t</TH>", reader. GetInt32(0));

sw. Write("<TH>{0}\t</TH>", (Single)reader. GetValue(1));

sw. Write("<TH>{0}\t</TH>", reader. GetString(2));

sw. Write("<TH>{0}\t</TH>", (Single)reader. GetValue(5));

sw. Write("<TH>{0}\t</TH>", reader. GetString(3));

sw. Write("<TH>{0}\t</TH>", (Single)reader. GetValue(4));

sw. Write("<TH>{0}\t</TH>", (Single)reader. GetValue(6));

sw. Write("<TH>{0}\t</TH>", reader. GetDateTime(7).Date);

sw. Write("<TH>{0}\t</TH>", reader. GetString(8));

sw. WriteLine("</TR>");

}

}

catch (SqlException ex)

{

MessageBox. Show(ex. Message);

}

finally

{

if (reader!= null)

reader. Close();

}

sw. WriteLine(@"</table>");

sw. WriteLine("<br><br>");

sw. WriteLine("<br><br>");

sw. WriteLine("</BODY>");

sw. WriteLine("</HTML>");

sw. Close();

System. Diagnostics. Process. Start("IExplore. exe", Path. GetFullPath("Inf. html"));

}

}

}

Enter. cs

using System;

using System. Collections. Generic;

using ponentModel;

using System. Data;

using System. Drawing;

using System. Text;

using System. Windows. Forms;

using System. Data. SqlClient;

namespace TRPO_lab10

{

public partial class Enter : Form

{

public Enter()

{

InitializeComponent();

}

bool b = false;

private void button1_Click(object sender, EventArgs e)

{

SqlConnection conn = new SqlConnection(TRPO_lab10.Properties. Settings. Default. ChangeDatabaseConnectionString);

if (conn. State!= ConnectionState. Open)

conn. Open();

SqlCommand cquery = new SqlCommand("Select PAS from Sotrudniki WHERE FAM='" + comboBox1.Text+"'", conn);

string pas = "";

try

{

pas = (string)cquery. ExecuteScalar();

}

catch (Exception ex)

{

if (MessageBox. Show(ex. Message, "Ошибка подключения", MessageBoxButtons. OK, MessageBoxIcon. Error) == DialogResult. OK)

Application. Exit();

}

if (pas. Trim() == textBox1.Text)

{

try

{

enterTableAdapter. InsertQueryEnter(comboBox1.Text, DateTime. Now);

b = true;

}

catch (Exception ex)

{

if (MessageBox. Show(ex. Message, "Ошибка подключения", MessageBoxButtons. OK, MessageBoxIcon. Error) == DialogResult. OK)

Application. Exit();

}

this. Close();

}

else

{

MessageBox. Show("Неверный пароль", "Ошибка подключения", MessageBoxButtons. OK, MessageBoxIcon. Warning);

}

}

private void Enter_Load(object sender, EventArgs e)

{

// TODO: This line of code loads data into the 'changeDatabaseDataSet. Sotrudniki' table. You can move, or remove it, as needed.

this. sotrudnikiTableAdapter. Fill(this. changeDatabaseDataSet. Sotrudniki);

try

{

// TODO: This line of code loads data into the 'changeDatabaseDataSet. Kassir' table. You can move, or remove it, as needed.

this. kassirTableAdapter. Fill(this. changeDatabaseDataSet. Kassir);

// TODO: This line of code loads data into the 'changeDatabaseDataSet. Enter' table. You can move, or remove it, as needed.

this. enterTableAdapter. Fill(this. changeDatabaseDataSet. Enter);

}

catch (Exception exc)

{

if (MessageBox. Show("" + exc. Message + "", "", MessageBoxButtons. RetryCancel, MessageBoxIcon. Error) == DialogResult. Retry)

{

LoadData();

}

else

Application. Exit();

}

}

private void LoadData()

{

try

{

this. kassirTableAdapter. Fill(this. changeDatabaseDataSet. Kassir);

this. enterTableAdapter. Fill(this. changeDatabaseDataSet. Enter);

}

catch (Exception exc)

{

if (MessageBox. Show("" + exc. Message + "", "", MessageBoxButtons. RetryCancel, MessageBoxIcon. Error) == DialogResult. Retry)

{

LoadData();

}

else

Application. Exit();

}

}

private void Enter_FormClosed(object sender, FormClosedEventArgs e)

{

if (b == false)

{

Application. Exit();

}

else

(new Main()).ShowDialog();

}

private void button2_Click(object sender, EventArgs e)

{

Application. Exit();

}

}

}

Sotrudniki. cs

using System;

using System. Collections. Generic;

using ponentModel;

using System. Data;

using System. Drawing;

using System. Text;

using System. Windows. Forms;

namespace TRPO_lab10

{

public partial class Sotrudniki : Form

{

public Sotrudniki()

{

InitializeComponent();

}

private void Sotrudniki_Load(object sender, EventArgs e)

{

// TODO: This line of code loads data into the 'changeDatabaseDataSet. Sotrudniki' table. You can move, or remove it, as needed.

this. sotrudnikiTableAdapter. Fill(this. changeDatabaseDataSet. Sotrudniki);

}

private void button1_Click(object sender, EventArgs e)

{

try

{

if (textBox1.Text!= "" && textBox2.Text!= "" && textBox3.Text != "" && textBox4.Text!= "" && textBox5.Text!= "" && textBox6.Text!= "")

{

if (Convert. ToInt32(textBox4.Text) > 22 && Convert. ToInt32(textBox4.Text) < 45)

{

sotrudnikiTableAdapter. InsertQuerySotrudniki(textBox1.Text, textBox2.Text, textBox3.Text, Convert. ToInt32(textBox4.Text), textBox5.Text, textBox6.Text, textBoxPas. Text);

sotrudnikiTableAdapter. Fill(this. changeDatabaseDataSet. Sotrudniki);

MessageBox. Show("Запись занесена в базу данных!", "Сообщение", MessageBoxButtons. OK, MessageBoxIcon. Information);

textBox1.Text = "";

textBox2.Text = "";

textBox3.Text = "";

textBox4.Text = "";

textBox5.Text = "";

textBox6.Text = "";

}

else

{ MessageBox. Show("Возраст сотрудника не подходит! Значение должно быть в пределе от 22 лет до 45 ! ", "Ошибка!", MessageBoxButtons. OK, MessageBoxIcon. Error); }

}

else

{

MessageBox. Show("Не все поля заполнены!", "Ошибка!", MessageBoxButtons. OK, MessageBoxIcon. Error);

}

}

catch (Exception ex)

{

MessageBox. Show (ex. Message);

}

}

private void buttonDelete_Click(object sender, EventArgs e)

{

sotrudnikiTableAdapter. DeleteQuerySotrudniki(Convert. ToInt32(dataGridView1 .SelectedCells [0].Value ));

sotrudnikiTableAdapter. Fill(changeDatabaseDataSet. Sotrudniki );

sotrudnikiTableAdapter. Update(changeDatabaseDataSet. Sotrudniki);

}

private void buttonPoisk_Click(object sender, EventArgs e)

{

sotrudnikiTableAdapter. FillByPoiskFAM(changeDatabaseDataSet. Sotrudniki, textBoxPoisk. Text);

}

private void buttonVSE_Click(object sender, EventArgs e)

{

sotrudnikiTableAdapter. Fill(changeDatabaseDataSet. Sotrudniki);

sotrudnikiTableAdapter. Update(changeDatabaseDataSet. Sotrudniki);

}

private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)

{

}

private void button2_Click(object sender, EventArgs e)

{

}

}

}

ChangeSell. cs

using System;

using System. Collections. Generic;

using ponentModel;

using System. Data;

using System. Drawing;

using System. Text;

using System. Windows. Forms;

namespace TRPO_lab10

{

public partial class ChangeSell : Form

{

public ChangeSell()

{

InitializeComponent();

}

private void ChangeSell_Load(object sender, EventArgs e)

{

// TODO: This line of code loads data into the 'changeDatabaseDataSet. Prodaga' table. You can move, or remove it, as needed.

this. prodagaTableAdapter. Fill(this. changeDatabaseDataSet. Prodaga);

}

private void button1_Click(object sender, EventArgs e)

{

try

{

prodagaTableAdapter. UpdateQuery(Convert. ToDecimal(textBoxUSD. Text), Convert. ToDecimal(textBoxEUR. Text), Convert. ToDecimal(textBoxMDL. Text), Convert. ToDecimal(textBoxUAH. Text), Convert. ToDecimal(textBoxRUB. Text), DateTime. Now. Date);

this. Close();

}

catch (Exception ex)

{

MessageBox. Show(ex. Message, "Ошибка обновления", MessageBoxButtons. OK, MessageBoxIcon. Error);

}

}

private void textBoxUSD_TextChanged(object sender, EventArgs e)

{

if (textBoxUSD. Text == "-")

{

MessageBox. Show("Ошибка ввода.", "Ошибка ввода данных", MessageBoxButtons. OK, MessageBoxIcon. Information);

textBoxUSD. Text = "";

}

}

private void textBoxEUR_TextChanged(object sender, EventArgs e)

{

if (textBoxEUR. Text == "-")

{

MessageBox. Show("Ошибка ввода.", "Ошибка ввода данных", MessageBoxButtons. OK, MessageBoxIcon. Information);

textBoxEUR. Text = "";

}

}

private void textBoxMDL_TextChanged(object sender, EventArgs e)

{

if (textBoxMDL. Text == "-")

{

MessageBox. Show("Ошибка ввода.", "Ошибка ввода данных", MessageBoxButtons. OK, MessageBoxIcon. Information);

textBoxMDL. Text = "";

}

}

private void textBoxUAH_TextChanged(object sender, EventArgs e)

{

if (textBoxUAH. Text == "-")

{

MessageBox. Show("Ошибка ввода.", "Ошибка ввода данных", MessageBoxButtons. OK, MessageBoxIcon. Information);

textBoxUAH. Text = "";

}

}

private void textBoxRUB_TextChanged(object sender, EventArgs e)

{

if (textBoxRUB. Text == "-")

{

MessageBox. Show("Ошибка ввода.", "Ошибка ввода данных", MessageBoxButtons. OK, MessageBoxIcon. Information);

textBoxRUB. Text = "";

}

}

}

}

ChangeBuy. cs

using System;

using System. Collections. Generic;

using ponentModel;

using System. Data;

using System. Drawing;

using System. Text;

using System. Windows. Forms;

namespace TRPO_lab10

{

public partial class ChangeBuy : Form

{

public ChangeBuy()

{

InitializeComponent();

}

private void ChangeBuy_Load(object sender, EventArgs e)

{

// TODO: This line of code loads data into the 'changeDatabaseDataSet. Pokypka' table. You can move, or remove it, as needed.

this. pokypkaTableAdapter. Fill(this. changeDatabaseDataSet. Pokypka);

}

private void button1_Click(object sender, EventArgs e)

{

try

{

pokypkaTableAdapter. UpdateQuery(Convert. ToDecimal(textBoxUSD. Text), Convert. ToDecimal(textBoxEUR. Text), Convert. ToDecimal(textBoxMDL. Text), Convert. ToDecimal(textBoxUAH. Text), Convert. ToDecimal(textBoxRUB. Text),DateTime. Now. Date);

this. Close();

}

catch (Exception ex)

{

MessageBox. Show(ex. Message, "Ошибка обновления", MessageBoxButtons. OK, MessageBoxIcon. Error);

}

}

private void textBoxUSD_TextChanged(object sender, EventArgs e)

{

if (textBoxUSD. Text == "-")

{

MessageBox. Show("Ошибка ввода.", "Ошибка ввода данных", MessageBoxButtons. OK, MessageBoxIcon. Information);

textBoxUSD. Text = "";

}

}

private void textBoxEUR_TextChanged(object sender, EventArgs e)

{

if (textBoxEUR. Text == "-")

{

MessageBox. Show("Ошибка ввода.", "Ошибка ввода данных", MessageBoxButtons. OK, MessageBoxIcon. Information);

textBoxEUR. Text = "";

}

}

private void textBoxMDL_TextChanged(object sender, EventArgs e)

{

if (textBoxMDL. Text == "-")

{

MessageBox. Show("Ошибка ввода.", "Ошибка ввода данных", MessageBoxButtons. OK, MessageBoxIcon. Information);

textBoxMDL. Text = "";

}

}

private void textBoxUAH_TextChanged(object sender, EventArgs e)

{

if (textBoxUAH. Text == "-")

{

MessageBox. Show("Ошибка ввода.", "Ошибка ввода данных", MessageBoxButtons. OK, MessageBoxIcon. Information);

textBoxUAH. Text = "";

}

}

private void textBoxRUB_TextChanged(object sender, EventArgs e)

{

if (textBoxRUB. Text == "-")

{

MessageBox. Show("Ошибка ввода.", "Ошибка ввода данных", MessageBoxButtons. OK, MessageBoxIcon. Information);

textBoxRUB. Text = "";

}

}

}

}

ClassInterface. cs

using System;

using System. Collections. Generic;

using System. Text;

namespace Kursovaia

{

interface ClassInterfaceSotrudnik

{

void AddNewSotrudnik(int ID, string FAM, string IM, string OTCHECTVO, int Vozrast, string Adres, string Dopolnitel_inform, string PAS);

void UpdateSotrudnik(int ID, string FAM, string IM, string OTCHECTVO, int Vozrast, string Adres, string Dopolnitel_inform, string PAS);

void DeleteSotrudnik(int ID, string FAM);

void PoiskSotrudnik(string FAM);

}

interface ClassInterfaceKurs

{

void UpdateKursk(int ID, string FAM, string IM, string OTCHECTVO, int Vozrast, string Adres, string Dopolnitel_inform, string PAS);

}

interface ClassInterfaceObmen_Valut

{

void AddNewObmen_Valut(int ID, string FAM, string IM, string OTCHECTVO, int Vozrast, string Adres, string Dopolnitel_inform, string PAS);

void DeleteObmen_Valut(int ID, string FAM);

}

}

ClassNaslednikInterface. cs

using System;

using System. Collections. Generic;

using System. Text;

using System. Windows. Forms;

using System. Data;

using ponentModel;

using System. Data. OleDb;

using System. IO;

namespace Kursovaia

{

class ClassNaslednikInterfaceSotrudnik : ClassInterfaceSotrudnik

{

public static string KyrsovikConnectionString = "Provider = Microsoft. Jet. OLEDB.4.0;Data Source=" + @"D:\\Obmennik. mdb";

public static OleDbConnection con = new OleDbConnection(KyrsovikConnectionString);

#region ClassInterfaceSotrudnik Member

public void AddNewSotrudnik(int ID, string FAM, string IM, string OTCHECTVO, int Vozrast, string Adres, string Dopolnitel_inform, string PAS)

{

con. Open();

try

{

OleDbCommand InsCom = new OleDbCommand("INSERT INTO Sotrudnik VALUES(" + ID + ",'" + FAM + "','" + IM + "','" + OTCHECTVO + "','" + Vozrast + "','" + Adres + "','" + Dopolnitel_inform + "','" + PAS + "')", con);

if (InsCom. ExecuteNonQuery() == 1)

{

MessageBox. Show("Сведения успешно добавлены", "Добавление", MessageBoxButtons. OK);

DataTable Sotrudnik = new DataTable("Sotrudnik");

OleDbDataAdapter datAdapSotrudnik = new OleDbDataAdapter("Select* From Sotrudnik", con);

datAdapSotrudnik. Fill(Sotrudnik);

}

}

catch

{

MessageBox. Show("Вы неверно ввели значения полей. Проверьте пожалуйста еще раз.", "Ошибка добавления", MessageBoxButtons. OK, MessageBoxIcon. Error);

}

con. Close();

}

public void UpdateSotrudnik(int ID, string FAM, string IM, string OTCHECTVO, int Vozrast, string Adres, string Dopolnitel_inform, string PAS)

{

con. Open();

try

{

OleDbCommand UpdCom = new OleDbCommand("Update Sotrudnik ID ='" + ID + "'" + ", FAM ='" + FAM + "'" + ", IM ='" + IM + "'" + ", OTCHECTVO ='" + OTCHECTVO + "'" + ", Vozrast ='" + Vozrast + "'" + ", Adres ='" + Adres + "'" + ", Dopolnitel_inform ='" + Dopolnitel_inform + "'" + ", PAS ='" + PAS, con);

UpdCom. ExecuteNonQuery();

if (UpdCom. ExecuteNonQuery() == 1)

{

MessageBox. Show("Обновление прошло успешно", "Обновление", MessageBoxButtons. OK);

DataTable Sotrudnik = new DataTable("Sotrudnik");

OleDbDataAdapter datAdapSotrudnik = new OleDbDataAdapter("Select* From Sotrudnik", con);

datAdapSotrudnik. Fill(Sotrudnik);

}

}

catch

{

MessageBox. Show("Вы неверно ввели значения полей. Проверьте пожалуйста еще раз.", "Ошибка добавления", MessageBoxButtons. OK, MessageBoxIcon. Error);

}

con. Close();

}

public void DeleteSotrudnik(int ID, string FAM)

{

OleDbCommand cmd;

if (MessageBox. Show("Удалить текущую строку?", "???", MessageBoxButtons. YesNo, MessageBoxIcon. Question, MessageBoxDefaultButton. Button1) == DialogResult. Yes)

{

try

{

cmd = new OleDbCommand("Delete From Sotrudnik Where ID =" + ID + "AND FAM = '" + FAM + "'", con);

cmd. Connection. Open();

cmd. ExecuteNonQuery();

cmd. Connection. Close();

}

catch

{

MessageBox. Show("Ошибка при попытке удаления записи.", "Ошибка удаления", MessageBoxButtons. OK, MessageBoxIcon. Error);

}

}

}

public void PoiskSotrudnik(string FAM)

{

DataTable P = new DataTable("Sotrudnik");

P. Rows. Clear();

OleDbDataAdapter datAdapPoisk = new OleDbDataAdapter("SELECT* FROM Sotrudnik WHERE FAM ='" + FAM + "", con);

datAdapPoisk. SelectCommand. Connection. Open();

datAdapPoisk. SelectCommand. ExecuteNonQuery();

datAdapPoisk. SelectCommand. Connection. Close();

datAdapPoisk. Fill(P);

//Kursovaia. Form1.date = P;

}

#endregion

}

Из за большого объема этот материал размещен на нескольких страницах:
1 2 3