Файл: Разработка сайта компании ООО «Весна». (Продажа бытового инструмента).pdf

ВУЗ: Не указан

Категория: Курсовая работа

Дисциплина: Не указана

Добавлен: 11.03.2024

Просмотров: 56

Скачиваний: 0

ВНИМАНИЕ! Если данный файл нарушает Ваши авторские права, то обязательно сообщите нам.

// открытие вкладки Редактирование товаров

private void редактироватьТоварыToolStripMenuItem_Click(object sender, EventArgs e)

{

tabControl1.SelectedTab = tabPage3;

panel6.Visible = true;

int lastId = 0, needId = 0;

lastId = dataGridView5.RowCount-2;

needId = Convert.ToInt32(dataGridView5.Rows[lastId].Cells[0].Value);

textBox7.Text = Convert.ToString(needId+1);

}

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

private void dataGridView5_CellEndEdit(object sender, DataGridViewCellEventArgs e)

{

button4.Enabled = button5.Enabled = true;

}

// диалоговое окно, которое справшивает подтверждение на изменение данных

private void button4_Click(object sender, EventArgs e)

{

if(MessageBox.Show("Вы действительно хотите сохранить изменения?", "Сохранение",

MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)

{

tovarTableAdapter.Update(computerShopDataSet);

button4.Enabled = button5.Enabled = false;

}

//else tovarTableAdapter.Fill(computerShopDataSet.Tovar);

}

// удаление из корзины 1 выбраного товара

private void dataGridView3_CellDoubleClick(object sender, DataGridViewCellEventArgs e)

{

current33 = dataGridView3.CurrentRow.Index;

dataGridView3.Rows.RemoveAt(current33);

if (dataGridView3.RowCount == 1)

{

textBox3.Text = "0";

}

int current3, newPrice = 0;

try

{

current3 = dataGridView3.CurrentRow.Index;

newPrice = Convert.ToInt32(dataGridView3.Rows[current3].Cells[2].Value) * Convert.ToInt32(dataGridView3.Rows[current3].Cells[3].Value);

dataGridView3.Rows[current3].Cells[4].Value = newPrice;

// пересчет общей стоимости всей продажи

int allTotalPrice = 0;

for (int i = 0; i < dataGridView3.RowCount - 1; i++)

{

allTotalPrice += Convert.ToInt32(dataGridView3.Rows[i].Cells[4].Value);

textBox3.Text = allTotalPrice.ToString();

}

}

catch

{

label5.Text = "";

}

}

// отмена изменений

private void button5_Click(object sender, EventArgs e)

{

tovarTableAdapter.Fill(computerShopDataSet.Tovar);

button4.Enabled = button5.Enabled = false;

}

// выход из пользователя Продавец

private void изПользователяToolStripMenuItem_Click(object sender, EventArgs e)

{

this.Close();

Form1 f1 = new Form1();

f1.Show();

}

// выход из программы

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

{

this.Close();

Form1 f1 = new Form1();

f1.Close();

}

// добавление нового товара

private void button6_Click(object sender, EventArgs e)

{

int needInd = 0, needCost = 0, needKol = 0, needKat = 0, needPod = 0;

string needName;

if (textBox9.Text != "" && textBox10.Text != "" && textBox8.Text != "" &&

comboBox3.SelectedIndex > -1 && comboBox4.SelectedIndex > -1)

{

needInd = Convert.ToInt32(textBox7.Text);

needName = textBox8.Text;

needCost = Convert.ToInt32(textBox9.Text);


needKol = Convert.ToInt32(textBox10.Text);

switch (comboBox3.SelectedIndex)

{

case 0: needKat = 1; break;

case 1: needKat = 2; break;

case 2: needKat = 3; break;

case 3: needKat = 4; break;

}

switch (comboBox4.SelectedIndex)

{

case 0: needPod = 1; break;

case 1: needPod = 2; break;

case 2: needPod = 3; break;

case 3: needPod = 4; break;

case 4: needPod = 5; break;

case 5: needPod = 6; break;

case 6: needPod = 7; break;

case 7: needPod = 8; break;

case 8: needPod = 9; break;

case 9: needPod = 10; break;

}

tovarTableAdapter.Insert(needInd, needName, needCost, needKol, needKat, needPod);

//tovarTableAdapter.Update(computerShopDataSet);

tovarTableAdapter.Fill(computerShopDataSet.Tovar);

}

else

MessageBox.Show("Заполнены не все поля. \nПроверьте данные","Внимание!");

int lastId = 0, needId = 0;

lastId = dataGridView5.RowCount - 2;

needId = Convert.ToInt32(dataGridView5.Rows[lastId].Cells[0].Value);

textBox7.Text = Convert.ToString(needId + 1);

/*tovarTableAdapter.Update(computerShopDataSet);

tovarTableAdapter.Fill(computerShopDataSet.Tovar);*/

}

// удаление строки в таблице товар

private void dataGridView5_UserDeletingRow(object sender, DataGridViewRowCancelEventArgs e)

{

try

{

if (MessageBox.Show("Вы действительно хотите удалить строку?", "Сохранение",

MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)

{

int current, currentInd, currentCost, currentKol, currentKat, currentPod;

string currentName = "";

current = dataGridView5.CurrentRow.Index;

// формирование переменных

currentInd = Convert.ToInt32(dataGridView5.Rows[current].Cells[0].Value);

currentName = Convert.ToString(dataGridView5.Rows[current].Cells[1].Value);

currentCost = Convert.ToInt32(dataGridView5.Rows[current].Cells[2].Value);

currentKol = Convert.ToInt32(dataGridView5.Rows[current].Cells[3].Value);

currentKat = Convert.ToInt32(dataGridView5.Rows[current].Cells[4].Value);

currentPod = Convert.ToInt32(dataGridView5.Rows[current].Cells[5].Value);

// удаление нужной строки

tovarTableAdapter.Delete(currentInd, currentName, currentCost, currentKol, currentKat, currentPod);

}

}

catch

{

MessageBox.Show("Невозможно удалить товар, т.к. он имеется в продажах!", "Внимание!");

}

}

// обновление таблицы редактирования товаров

private void pictureBox1_Click(object sender, EventArgs e)

{

tovarTableAdapter.Fill(computerShopDataSet.Tovar);

int lastId = 0, needId = 0;

lastId = dataGridView5.RowCount - 2;

needId = Convert.ToInt32(dataGridView5.Rows[lastId].Cells[0].Value);

textBox7.Text = Convert.ToString(needId + 1);

}

private void pictureBox2_MouseMove(object sender, MouseEventArgs e)

{

Bitmap image1 = new Bitmap("img/update1.png");

pictureBox2.Image = image1;

}

private void pictureBox2_MouseLeave(object sender, EventArgs e)

{

Bitmap image1 = new Bitmap("img/update2.png");

pictureBox2.Image = image1;

}

private void pictureBox2_Click(object sender, EventArgs e)

{

goodTovarTableAdapter.Fill(computerShopDataSet.goodTovar);


}

private void вEXELToolStripMenuItem_Click(object sender, EventArgs e)

{

}

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

{

Microsoft.Office.Interop.Excel.Application ExcelApp = new Microsoft.Office.Interop.Excel.Application();

Microsoft.Office.Interop.Excel.Workbook ExcelWorkBook;

Microsoft.Office.Interop.Excel.Worksheet ExcelWorkSheet;

//Книга.

ExcelWorkBook = ExcelApp.Workbooks.Add(System.Reflection.Missing.Value);

//Таблица.

ExcelWorkSheet = (Microsoft.Office.Interop.Excel.Worksheet)ExcelWorkBook.Worksheets.get_Item(1);

ExcelApp.Cells[1, 1] = "ID таблицы";

ExcelApp.Cells[1, 2] = "Код продажи";

ExcelApp.Cells[1, 3] = "Наименование товара";

ExcelApp.Cells[1, 4] = "Количество";

ExcelApp.Cells[1, 5] = "Общая цена";

ExcelApp.Cells[1, 6] = "Дата продажи";

ExcelApp.Cells[1, 7] = "Продавец";

int n = 0;

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

{

n++;

for (int j = 0; j < dataGridView4.ColumnCount; j++)

{

ExcelApp.Cells[n + 1, j + 1] = dataGridView4.Rows[i].Cells[j].Value;

}

}

//Вызываем нашу созданную эксельку.

ExcelApp.Visible = true;

ExcelApp.UserControl = true;

}

}

}