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 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 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 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 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 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 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 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); } }