private void ConfirmNewRecipe_FormClosing(object sender, FormClosingEventArgs e)
        {
            CreateNewRecipie cr = (CreateNewRecipie)this.Owner;

            cr.Enabled = true;
            this.Hide();
        }
        private void buttonCansel_Click(object sender, EventArgs e)
        {
            CreateNewRecipie cr = (CreateNewRecipie)this.Owner;

            cr.Enabled = true;
            this.Hide();
            success = false;
        }
Exemple #3
0
        private void новыйЧекToolStripMenuItem_Click(object sender, EventArgs e)
        {
            CreateNewRecipie cn = new CreateNewRecipie(user);

            cn.Owner     = this;
            this.Enabled = false;
            cn.ShowDialog();
            dataGridView2.Rows.Clear();
            AddToDGV();
        }
        private async void buttonConfirm_Click(object sender, EventArgs e)
        {
            HelperClass hc = new HelperClass();

            //Преобразование списка продуктов в строку
            string listString = JsonConvert.SerializeObject(list);

            closed = true;

            string connectToRecipies = @"Data Source = DESKTOP-NLAJBQI; Initial Catalog = Kass; Integrated Security = True";
            string sqlCommand        = "INSERT INTO Recipes(Id, Datetime, ProductList, Price, PaymentType, TakeAway, Comment, Cashier)" +
                                       " VALUES(@Id, @Datetime, @ProductList, @Price, @PaymentType, @TakeAway, @Comment, @Cashier)";

            using (SqlConnection connection = new SqlConnection(connectToRecipies))
            {
                await connection.OpenAsync();

                SqlCommand command = new SqlCommand("SELECT * FROM dbo.Recipes", connection);

                var reader = await command.ExecuteReaderAsync();

                if (reader.HasRows)
                {
                    reader.Close();
                    command.CommandText = "SELECT MAX(Id) FROM dbo.Recipes";
                    id = Convert.ToInt32(await command.ExecuteScalarAsync());
                    id++;
                }
                else
                {
                    id = 0;
                }
                reader.Close();

                command.CommandText = sqlCommand;
                command.Parameters.AddWithValue("@Id", id);
                command.Parameters.AddWithValue("@Datetime", datetime);
                command.Parameters.AddWithValue("@ProductList", listString);
                command.Parameters.AddWithValue("@Price", price);
                command.Parameters.AddWithValue("@PaymentType", paymentType);
                command.Parameters.AddWithValue("@TakeAway", takeAway);
                command.Parameters.AddWithValue("@Comment", Comment);
                command.Parameters.AddWithValue("@Cashier", cashier);

                await command.ExecuteNonQueryAsync();
            }


            foreach (var i in listBoxFinal.Items)
            {
                listBoxFinalStrings.Add(i.ToString());
            }

            //печать чека
            hc.PrintRecipie(datetime, price, paymentType, takeAway, listBoxFinalStrings, cashier);
            hc.SendRecipieToPrinter();


            CreateNewRecipie cr = (CreateNewRecipie)this.Owner;

            cr.Enabled = true;
            this.Hide();
            success = true;
        }