private void постоянныеКлиентыToolStripMenuItem_Click(object sender, EventArgs e) { if (СправочникКлиенты == null || СправочникКлиенты.IsDisposed) { СправочникКлиенты = new СправочникКлиенты() { MdiParent = this }; СправочникКлиенты.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); } }