private void приходDataGridView_CellClick(object sender, DataGridViewCellEventArgs e) { int income = Convert.ToInt32(приходDataGridView.CurrentRow.Cells[0].Value); string Command = "Select Товары.Наименование, Цена_Закупки, Цена_Продажи, Количество FROM Состав_Прихода inner join Товары ON Товары.Код_Товара=Состав_Прихода.Код_Товара WHERE Номер_Прихода=" + income; StaticProcesser.FillDataGrid(Command, GoodsDataGrid); }
private void AddEditButton_Click(object sender, EventArgs e) { try { SqlParameter fio = new SqlParameter("fio", FioTextBox.Text); SqlParameter hired = new SqlParameter("hired", HiredDatePicker.Value.ToShortDateString()); SqlParameter dateOfBirth = new SqlParameter("dateOfBirth", BirthDatePicker.Value.ToShortDateString()); SqlParameter phoneNumber = new SqlParameter("phoneNumber", NumberTextBox.Text); SqlParameter title = new SqlParameter("title", TitleTextBox.Text); if (isChange) { SqlParameter codeOfWorker = new SqlParameter("codeOfWorker", CodeOfWorker); StaticProcesser.ExecuteCommand(CommandForUpdating, fio, hired, dateOfBirth, phoneNumber, title, codeOfWorker); } else { StaticProcesser.ExecuteCommand(CommandForAdding, fio, hired, dateOfBirth, phoneNumber, title); } this.Dispose(); } catch (Exception ex) { StaticHelper.ErrorNotifier(ex); } }
private void продажаDataGridView_CellContentClick(object sender, DataGridViewCellEventArgs e) { int cheque = Convert.ToInt32(продажаDataGridView.CurrentRow.Cells[0].Value); string Command = "Select Товары.Наименование,Состав_Продажи.Цена,Количество FROM Состав_Продажи inner join Товары ON Товары.Код_Товара=Состав_Продажи.Код_Товара Where Чек=" + cheque; StaticProcesser.FillDataGrid(Command, GoodsDataGrid); }
private void FormReportButton_Click(object sender, EventArgs e) { try { if (ReportsComboBox.SelectedIndex == 0) { StaticProcesser.FillDataGrid(CommandForReportAboutSupply, ReportDataGrid); } if (ReportsComboBox.SelectedIndex == 1) { CommandForReportAboutGenres = "Select Жанры.Наименование, SUM(Количество) AS Количество FROM Товары right join Состав_Продажи ON Состав_Продажи.Код_Товара = Товары.Код_Товара inner join Жанры ON Код_Жанра = Товары.Жанр inner join Продажа ON Продажа.Чек = Состав_Продажи.Чек Where Продажа.Дата>='" + StartDatePicker.Value.ToShortDateString() + "' And Продажа.Дата<='" + EndDatePicker.Value.ToShortDateString() + "' GROUP BY Жанры.Наименование"; StaticProcesser.FillDataGrid(CommandForReportAboutGenres, ReportDataGrid); } if (ReportsComboBox.SelectedIndex == 2) { CommandForReportAboutTypes = "Select Тип_Товара.Наименование, SUM(Количество) AS Количество FROM Товары right join Состав_Продажи ON Состав_Продажи.Код_Товара = Товары.Код_Товара inner join Тип_Товара ON Тип_Товара.Код_Типа=Товары.Тип_Товара inner join Продажа ON Продажа.Чек=Состав_Продажи.Чек Where Продажа.Дата>='" + StartDatePicker.Value.ToShortDateString() + "' and Продажа.Дата<='" + EndDatePicker.Value.ToShortDateString() + "' GROUP BY Тип_Товара.Наименование"; StaticProcesser.FillDataGrid(CommandForReportAboutTypes, ReportDataGrid); } if (ReportsComboBox.SelectedIndex == 3) { CommandForReportAboutFinance = "SELECT (Select SUM(Цена_Закупки*Количество)From Состав_Прихода left join Приход ON Приход.Номер_Прихода=Состав_Прихода.Номер_Прихода Where Приход.Дата>='" + StartDatePicker.Value.ToShortDateString() + "' and Приход.Дата<='" + EndDatePicker.Value.ToShortDateString() + "') AS [Сумма затрат на товары],(Select SUM(Сумма_Чека) FROM Продажа Where Дата>='" + StartDatePicker.Value.ToShortDateString() + "' and Дата<='" + EndDatePicker.Value.ToShortDateString() + "') AS [Выручка от продаж]"; StaticProcesser.FillDataGrid(CommandForReportAboutFinance, ReportDataGrid); } } catch (Exception ex) { StaticHelper.ErrorNotifier(ex); } }
private void AddButton_Click(object sender, EventArgs e) { try { SqlParameter type = new SqlParameter("type", TypeComboBox.SelectedValue); SqlParameter title = new SqlParameter("title", TitleTextBox.Text); SqlParameter price = new SqlParameter("price", SellPriceNumericUpDown.Value); string Command; if (aBook) { SqlParameter genre = new SqlParameter("genre", GenreComboBox.SelectedValue); Command = "Insert Into Товары (Тип_Товара,Жанр,Наименование,Цена, Остаток) VALUES (@type,@genre,@title,@price,0)"; StaticProcesser.ExecuteCommand(Command, type, genre, title, price); Data.priceOfBuy = (double)BuyPriceNumericUpDown.Value; this.Dispose(); } else { Command = "Insert Into Товары (Тип_Товара, Наименование, Цена, Остаток) VALUES (@type,@title,@price,0)"; StaticProcesser.ExecuteCommand(Command, type, title, price); Data.priceOfBuy = (double)BuyPriceNumericUpDown.Value; this.Dispose(); } } catch (Exception ex) { StaticHelper.ErrorNotifier(ex); } }
private void EnterButton_Click(object sender, EventArgs e) { try { if ((FioTextBox.Text != "" || FioTextBox.Text != " ") && (PhoneNumberTextBox.Text != "" || PhoneNumberTextBox.Text != " ")) { SqlParameter fio = new SqlParameter("fio", FioTextBox.Text); SqlParameter phoneNumber = new SqlParameter("phoneNumber", PhoneNumberTextBox.Text); string Command; if (isChange) { Command = "Update Постоянные_Клиенты SET ФИО = @fio, Телефон = @phoneNumber WHERE Номер_Карты = @cardNumber"; SqlParameter cardNumber = new SqlParameter("cardNumber", CardNumber); StaticProcesser.ExecuteCommand(Command, fio, phoneNumber, cardNumber); this.Dispose(); } else { Command = "Insert Into Постоянные_Клиенты (ФИО,Дата_Вручения,Телефон) VALUES (@fio,@date,@phoneNumber)"; SqlParameter date = new SqlParameter("date", DateTime.Now.ToShortDateString()); StaticProcesser.ExecuteCommand(Command, fio, date, phoneNumber); this.Dispose(); } } else { MessageBox.Show("Заполните все поля!"); } } catch (Exception ex) { StaticHelper.ErrorNotifier(ex); } }
private void Приход_Load(object sender, EventArgs e) { StaticProcesser.FillDataGrid(GoodsSelectCommand, dataGridView1); dataGridView1.Columns[0].Width = 60; dataGridView1.Columns[1].Width = 60; dataGridView1.Columns[2].Width = 40; dataGridView1.Columns[3].Width = 270; dataGridView1.Columns[4].Width = 50; dataGridView1.Columns[5].Width = 56; IncomingGoodsDataTable.Columns.Add("Код товара", typeof(int)); IncomingGoodsDataTable.Columns.Add("Наименование", typeof(string)); IncomingGoodsDataTable.Columns.Add("Цена закупки", typeof(double)); IncomingGoodsDataTable.Columns.Add("Цена продажи", typeof(double)); IncomingGoodsDataTable.Columns.Add("Количество", typeof(int)); dataGridView2.DataSource = IncomingGoodsDataTable; dataGridView2.Columns[0].Width = 75; dataGridView2.Columns[1].Width = 320; dataGridView2.Columns[2].Width = 90; dataGridView2.Columns[3].Width = 90; dataGridView2.Columns[4].Width = 80; }
private void FireButton_Click(object sender, EventArgs e) { try { if (label1.Visible == false) { ControlExtraControls(true); } else { var result = MessageBox.Show("Вы уверены, что хотите уволить этого сотрудника?", "Подтверждение увольнения", MessageBoxButtons.YesNo); if (result == DialogResult.Yes) { string Command = "Update Сотрудники SET Уволен=@fired Where Код_Сотрудника=@codeOfWorker"; SqlParameter fired = new SqlParameter("fired", FiredDatePicker.Value.ToShortDateString()); SqlParameter codeOfWorker = new SqlParameter("codeOfWorker", Convert.ToString(сотрудникиDataGridView.CurrentRow.Cells[0].Value)); StaticProcesser.ExecuteCommand(Command, fired, codeOfWorker); сотрудникиTableAdapter.Fill(this.bookWorldDataSet.Сотрудники); ControlExtraControls(false); } else { ControlExtraControls(false); } } } catch (Exception ex) { StaticHelper.ErrorNotifier(ex); } }
private void EnterButton_Click(object sender, EventArgs e) { string password = ""; if (LoginTextBox.Text == " " || PasswordTextBox.Text == " ") { MessageBox.Show("Не все поля заполнены"); LoginTextBox.Focus(); } int count = 0; string command = "Select Пароль from Пользователи Where Имя_Пользователя = @login"; SqlParameter p1 = new SqlParameter("login", LoginTextBox.Text); var reader = StaticProcesser.GetReader(command, p1); while (reader.Read()) { count++; try { password = reader.GetString(0); password = password.Replace(Environment.NewLine, ""); } catch (Exception ex) { StaticHelper.ErrorNotifier(ex); } } if (count == 0) { MessageBox.Show("Такого пользователя не существует"); LoginTextBox.Clear(); LoginTextBox.Focus(); PasswordTextBox.Clear(); reader.Close(); StaticProcesser.CloseConnection(); } else if (count == 1) { reader.Close(); StaticProcesser.CloseConnection(); string inputedPass = StaticProcesser.ComputeHash(PasswordTextBox.Text, new MD5CryptoServiceProvider()); if (password == inputedPass) { User.Login = LoginTextBox.Text; User.Access = 1; if (User.Login == "admin") { User.Access = 2; } this.Dispose(); } else { MessageBox.Show("Пароль введён не верно"); PasswordTextBox.Clear(); PasswordTextBox.Focus(); } } }
private void AddGood_Click(object sender, EventArgs e) { ДобавитьТовар f = new ДобавитьТовар(); f.ShowDialog(); StaticProcesser.FillDataGrid(GoodsSelectCommand, dataGridView1); BuyPriceNumericUpDown.Value = (decimal)Data.priceOfBuy; Data.priceOfBuy = 0; dataGridView1.CurrentCell = dataGridView1.Rows[dataGridView1.Rows.Count - 1].Cells[0]; }
private void SearchTextBox_TextChanged(object sender, EventArgs e) { if (SearchTextBox.Text != "" && SearchTextBox.Text != " ") { string Command = "Select Код_Товара AS [Код], Тип_Товара.Наименование AS [Тип],Жанры.Наименование AS Жанр,Товары.Наименование,Цена,Остаток FROM Товары inner join Тип_Товара ON Тип_Товара.Код_Типа = Товары.Тип_Товара left join Жанры ON Жанры.Код_Жанра = Товары.Жанр Where Товары.Наименование LIKE '%" + SearchTextBox.Text + "%'"; StaticProcesser.FillDataGrid(Command, товарыdataGridView); } else { StaticProcesser.FillDataGrid(comForListOfGoods, товарыdataGridView); } }
private void SearchTextBox_TextChanged(object sender, EventArgs e) { if (SearchTextBox.Text != "" && SearchTextBox.Text != " ") { string Command = "Select Код_Товара,Тип_Товара,Жанр,Наименование, Цена, Остаток From Товары Where Наименование LIKE '%" + SearchTextBox.Text + "%'"; StaticProcesser.FillDataGrid(Command, dataGridView1); } else { string Command = "Select Код_Товара,Тип_Товара,Жанр, Наименование, Цена,Остаток FROM Товары"; StaticProcesser.FillDataGrid(Command, dataGridView1); } }
private void SearchByFioTextBox_TextChanged(object sender, EventArgs e) { //"Select Код_Товара,Тип_Товара,Жанр,Наименование, Цена, Остаток From Товары Where Наименование LIKE '%"+SearchTextBox.Text+"%'"; try { string FullCommandForSearch; if (SearchByFioTextBox.Text == "" || SearchByFioTextBox.Text == " ") { постоянные_КлиентыDataGridView.DataSource = постоянные_КлиентыBindingSource; } else { FullCommandForSearch = CommandForSearch + SearchByFioTextBox.Text + "%'"; StaticProcesser.FillDataGrid(FullCommandForSearch, постоянные_КлиентыDataGridView); } } catch (Exception ex) { StaticHelper.ErrorNotifier(ex); } }
private void НоваяПродажа_Load(object sender, EventArgs e) { StaticProcesser.FillDataGrid(comForListOfGoods, this.товарыdataGridView); товарыdataGridView.Columns[0].Width = 28; товарыdataGridView.Columns[1].Width = 80; товарыdataGridView.Columns[2].Width = 80; товарыdataGridView.Columns[3].Width = 300; товарыdataGridView.Columns[4].Width = 50; товарыdataGridView.Columns[5].Width = 60; cheque.Columns.Add("Код товара", typeof(int)); cheque.Columns.Add("Наименование", typeof(string)); cheque.Columns.Add("Цена", typeof(double)); cheque.Columns.Add("Количество", typeof(int)); cheque.Columns.Add("Стоимость", typeof(double)); чекdataGridView.DataSource = cheque; чекdataGridView.Columns[0].Width = 60; чекdataGridView.Columns[1].Width = 300; чекdataGridView.Columns[2].Width = 80; чекdataGridView.Columns[3].Width = 79; чекdataGridView.Columns[4].Width = 79; }
private void ConfirmButton_Click(object sender, EventArgs e) { string Command; SqlParameter codeOfGood = new SqlParameter("codeOfGood", CodeOfGood); if (isPrice) { if (numericUpDown1.Value == 0) { MessageBox.Show("Не возможная цена!"); } else { Price = (double)numericUpDown1.Value; Command = "Update Товары Set Цена = @price WHERE Код_Товара=@codeOfGood"; SqlParameter price = new SqlParameter("price", Price); StaticProcesser.ExecuteCommand(Command, price, codeOfGood); this.Dispose(); } } else { if (TitleTextBox.Text != "" && TitleTextBox.Text != " ") { Title = TitleTextBox.Text; Command = "Update Товары SET Наименование = @title WHERE Код_Товара = @codeOfGood"; SqlParameter title = new SqlParameter("title", Title); StaticProcesser.ExecuteCommand(Command, title, codeOfGood); this.Dispose(); } else { MessageBox.Show("Не оставляйте поле пустым!"); } } }
private void DeleteButton_Click(object sender, EventArgs e) { try { string command = "Select Код_Товара FROM Товары Where Жанр=@id"; SqlParameter p1 = new SqlParameter("id", this.жанрыDataGridView.CurrentRow.Cells[0].Value); int amount = StaticProcesser.GetAmountOfRecords(command, p1); if (amount > 0) { MessageBox.Show("Сначала нужно избавиться от всех товаров с этим жанром"); } else { жанрыBindingSource.RemoveCurrent(); this.Validate(); this.tableAdapterManager.UpdateAll(bookWorldDataSet); MessageBox.Show("Запись успешно удалена"); } } catch (Exception ex) { StaticHelper.ErrorNotifier(ex); } }
private void AddEditButton_Click(object sender, EventArgs e) { try { if (isChange) { if ((PassTextBox.Text == "" || PassTextBox.Text == " ") && (ConfPassTextBox.Text == "" || ConfPassTextBox.Text == " ") && (LoginTextBox.Text != "" || LoginTextBox.Text != " ")) { string Command = "Update Пользователи SET Имя_Пользователя=@login Where Имя_Пользователя=@oldLogin"; SqlParameter newLogin = new SqlParameter("login", LoginTextBox.Text); SqlParameter oldLogin = new SqlParameter("oldLogin", Login); StaticProcesser.ExecuteCommand(Command, newLogin, oldLogin); this.Dispose(); } else { if (PassTextBox.Text == ConfPassTextBox.Text && LoginTextBox.Text != "" && LoginTextBox.Text != " ") { string newhashedPass = StaticProcesser.ComputeHash(PassTextBox.Text, new MD5CryptoServiceProvider()); SqlParameter newLogin = new SqlParameter("login", LoginTextBox.Text); SqlParameter newHashedPass = new SqlParameter("newHashedPass", newhashedPass); SqlParameter oldLogin = new SqlParameter("oldLogin", Login); string Command = "Update Пользователи SET Имя_Пользователя=@login, Пароль=@newHashedPass Where Имя_Пользователя=@oldLogin"; StaticProcesser.ExecuteCommand(Command, newLogin, newHashedPass, oldLogin); this.Dispose(); } } } else { if ((PassTextBox.Text == "" || PassTextBox.Text == " ") && (ConfPassTextBox.Text == "" || ConfPassTextBox.Text == " ") && (LoginTextBox.Text == "" || LoginTextBox.Text == " ")) { MessageBox.Show("Заполните все поля!"); LoginTextBox.Focus(); } else { if (PassTextBox.Text == ConfPassTextBox.Text) { string newhashedPass = StaticProcesser.ComputeHash(PassTextBox.Text, new MD5CryptoServiceProvider()); SqlParameter newLogin = new SqlParameter("login", LoginTextBox.Text); SqlParameter newHashedPass = new SqlParameter("newHashedPass", newhashedPass); string Command = "Insert INTO Пользователи (Имя_Пользователя,Пароль) VALUES (@login,@newHashedPass)"; StaticProcesser.ExecuteCommand(Command, newLogin, newHashedPass); this.Dispose(); } else { PassTextBox.Clear(); ConfPassTextBox.Clear(); PassTextBox.Focus(); MessageBox.Show("Пароли не совпадают!"); } } } } catch (Exception ex) { StaticHelper.ErrorNotifier(ex); } }
private void FormDocButton_Click(object sender, EventArgs e) { string place = "beginning"; try { string Command = "Insert Into Приход (Дата,Комментарий) VALUES (@date,@comment)"; SqlParameter p1 = new SqlParameter("date", DateTime.Now.ToShortDateString()); SqlParameter p2 = new SqlParameter("comment", CommentRichTextBox.Text); StaticProcesser.ExecuteCommand(Command, p1, p2); place = "added head"; Command = "With SRC AS (Select TOP(1) Номер_Прихода From Приход ORDER BY Номер_Прихода DESC) Select Номер_Прихода FROM SRC"; SqlDataReader reader = StaticProcesser.GetReader(Command); reader.Read(); int incID = reader.GetInt32(0); StaticProcesser.CloseConnection(); place = "got ID"; int codeOfGood; double priceOfBuy; double priceOfSell; int amount; string updCommand = "Update Товары SET Остаток=Остаток + @amount Where Код_Товара = @codeOfGood"; Command = "Insert Into Состав_Прихода (Номер_Прихода,Код_Товара,Количество,Цена_Закупки,Цена_Продажи) VALUES (@id,@codeOfGood,@amount,@priceOfBuy,@priceOfSell)"; SqlParameter id = new SqlParameter("id", incID); SqlParameter PcodeOfGood; SqlParameter PpriceOfBuy; SqlParameter PpriceOfSell; SqlParameter Pamount; for (int i = 0; i < dataGridView2.Rows.Count; i++) { codeOfGood = Convert.ToInt32(dataGridView2.Rows[i].Cells[0].Value); PcodeOfGood = new SqlParameter("codeOfGood", codeOfGood); priceOfBuy = Convert.ToDouble(dataGridView2.Rows[i].Cells[2].Value); PpriceOfBuy = new SqlParameter("priceOfBuy", priceOfBuy); priceOfSell = Convert.ToDouble(dataGridView2.Rows[i].Cells[3].Value); PpriceOfSell = new SqlParameter("priceOfSell", priceOfSell); amount = Convert.ToInt32(dataGridView2.Rows[i].Cells[4].Value); Pamount = new SqlParameter("amount", amount); StaticProcesser.ExecuteCommand(updCommand, Pamount, PcodeOfGood); StaticProcesser.ExecuteCommand(Command, id, PcodeOfGood, Pamount, PpriceOfBuy, PpriceOfSell); place = "Command executed " + i + " times"; } MessageBox.Show("Документ успешно сформирован"); StaticProcesser.FillDataGrid(GoodsSelectCommand, dataGridView1); IncomingGoodsDataTable.Clear(); dataGridView2.DataSource = IncomingGoodsDataTable; } catch (Exception ex) { MessageBox.Show(place); StaticHelper.ErrorNotifier(ex); } }
private void CreateExcelButton_Click(object sender, EventArgs e) { StaticProcesser.WriteExcel(ReportDataGrid); }
private void FormDocButton_Click(object sender, EventArgs e) { try { string place = "beginning"; bool hasCard; string Command = "INSERT INTO Продажа (Дата,Сумма_Чека) VALUES (@date,@chequeSum)"; Data.numberOfCard = 0; var result = MessageBox.Show("Спросите есть ли у клиента карта", "Наличие карты", MessageBoxButtons.YesNo); SqlParameter cardNumber = new SqlParameter(); if (result == DialogResult.No) { hasCard = false; } else { СправочникКлиенты f = new СправочникКлиенты(); f.ShowDialog(); if (Data.numberOfCard > 0) { hasCard = true; ApplyDiscount(); Command = "INSERT INTO Продажа (Дата,Номер_Карты,Сумма_Чека) VALUES (@date,@cardNumber,@chequeSum)"; cardNumber = new SqlParameter("cardNumber", Data.numberOfCard); } else { hasCard = false; } } MessageBox.Show("Итоговая стоимость = " + fullcost + " рублей"); SqlParameter date = new SqlParameter("date", DateTime.Now.ToShortDateString()); SqlParameter chequeSum = new SqlParameter("chequeSum", fullcost); if (hasCard) { StaticProcesser.ExecuteCommand(Command, date, cardNumber, chequeSum); } else { StaticProcesser.ExecuteCommand(Command, date, chequeSum); } place = "added head"; Command = "With SRC AS (Select TOP(1) Чек From Продажа ORDER BY Чек DESC) Select Чек FROM SRC"; SqlDataReader reader = StaticProcesser.GetReader(Command); reader.Read(); int chequeNumber = reader.GetInt32(0); StaticProcesser.CloseConnection(); place = "got chequeNumber"; double codeOfGood; double priceOfSell; int amount; string updCommand = "Update Товары SET Остаток=Остаток-@amount Where Код_Товара = @codeOfGood"; Command = "Insert INTO Состав_Продажи (Чек,Код_Товара,Цена,Количество) VALUES (@chequeNumber,@codeOfGood,@priceOfSell,@amount)"; SqlParameter PchequeNumber = new SqlParameter("chequeNumber", chequeNumber); SqlParameter PcodeOfGood; SqlParameter PpriceOfSell; SqlParameter Pamount; for (int i = 0; i < чекdataGridView.Rows.Count; i++) { codeOfGood = Convert.ToInt32(чекdataGridView.Rows[i].Cells[0].Value); PcodeOfGood = new SqlParameter("codeOfGood", codeOfGood); if (hasCard) { priceOfSell = Convert.ToDouble(чекdataGridView.Rows[i].Cells[2].Value) * Properties.Settings.Default.Discount; } else { priceOfSell = Convert.ToDouble(чекdataGridView.Rows[i].Cells[2].Value); } PpriceOfSell = new SqlParameter("priceOfSell", priceOfSell); amount = Convert.ToInt32(чекdataGridView.Rows[i].Cells[3].Value); Pamount = new SqlParameter("amount", amount); StaticProcesser.ExecuteCommand(updCommand, Pamount, PcodeOfGood); StaticProcesser.ExecuteCommand(Command, PchequeNumber, PcodeOfGood, PpriceOfSell, Pamount); place = "Command executed " + i + " times"; } MessageBox.Show("Документ успешно сформирован"); StaticProcesser.FillDataGrid(comForListOfGoods, товарыdataGridView); cheque.Clear(); чекdataGridView.DataSource = cheque; GetFullCost(); Data.numberOfCard = 0; } catch (Exception ex) { StaticHelper.ErrorNotifier(ex); } }
private void UpdateDataGrid() { string Command = "Select Код_Товара AS [Код товара], Тип_Товара.Наименование AS [Тип товара],Жанры.Наименование AS Жанр,Товары.Наименование,Цена,Остаток FROM Товары inner join Тип_Товара ON Тип_Товара.Код_Типа = Товары.Тип_Товара left join Жанры ON Жанры.Код_Жанра = Товары.Жанр"; StaticProcesser.FillDataGrid(Command, this.товарыDataGridView); }