Exemplo n.º 1
0
        private void CreateChangesInfoFinal()
        {
            HelperClass hc = new HelperClass();

            if (!hc.CheckIfChangeOpen())
            {
                MessageBox.Show("Сначала откройте смену.");
                return;
            }

            string connectToChanges = @"Data Source = DESKTOP-NLAJBQI; Initial Catalog = Kass; Integrated Security = True";
            string sqlCommand       = "UPDATE dbo.Changes SET ChangesInfo = @list WHERE Id = @id";
            int    id = hc.GetIdCurrentChange();

            using (SqlConnection connection = new SqlConnection(connectToChanges))
            {
                connection.Open();
                SqlCommand command = new SqlCommand(sqlCommand, connection);

                string str = CreateChangesInfo();

                SqlParameter listParam = new SqlParameter("@list", str);
                command.Parameters.Add(listParam);
                SqlParameter idParam = new SqlParameter("@id", id);
                command.Parameters.Add(idParam);

                command.ExecuteNonQuery();
            }
        }
Exemplo n.º 2
0
        private void FillDGV()
        {
            HelperClass hc = new HelperClass();
            int         id = hc.GetIdCurrentChange();

            if (hc.CheckIfChangeOpen())
            {
                id--;
            }


            string connectToChanges = @"Data Source = DESKTOP-NLAJBQI; Initial Catalog = Kass; Integrated Security = True";
            string sqlExpr          = "SELECT * FROM dbo.Changes";

            using (SqlConnection connection = new SqlConnection(connectToChanges))
            {
                connection.Open();

                SqlCommand command = new SqlCommand(sqlExpr, connection);
                var        reader  = command.ExecuteReader();

                for (int i = 0; i <= id; i++)
                {
                    reader.Read();
                    dataGridView1.Rows.Add(reader.GetInt32(0), reader.GetDateTime(1), reader.GetDateTime(2), reader.GetString(3),
                                           reader.GetString(4), reader.GetInt32(5));
                }
            }
        }
Exemplo n.º 3
0
        public async void AddToDGV()
        {
            HelperClass hc = new HelperClass();

            if (!hc.CheckIfChangeOpen())
            {
                MessageBox.Show("Смена не открыта. Откройте ее в меню администратора и повторите попытку.");
                Application.Exit();
            }

            string         connectToRecipies = @"Data Source = DESKTOP-NLAJBQI; Initial Catalog = Kass; Integrated Security = True";
            string         sqlCommand        = "SELECT * FROM dbo.Recipes";
            string         place;
            List <Product> DBList = new List <Product>();

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

                SqlCommand command = new SqlCommand(sqlCommand, connection);
                var        reader  = await command.ExecuteReaderAsync();

                if (reader.HasRows)
                {
                    while (await reader.ReadAsync())
                    {
                        string str = reader.GetString(2);
                        DBList = JsonConvert.DeserializeObject <List <Product> >(str);
                        str    = "";
                        foreach (var i in DBList)
                        {
                            str += i.Name + " (x" + i.Amount + "), ";
                        }
                        str = str.TrimEnd(',', ' ');


                        if (reader.GetBoolean(5))
                        {
                            place = "На вынос";
                        }
                        else
                        {
                            place = "В кафе";
                        }

                        dataGridView2.Rows.Add(reader.GetInt32(0), reader.GetDateTime(1), str, reader.GetInt32(3),
                                               reader.GetString(4), place, reader.GetString(6), reader.GetString(7));
                    }
                }
            }
        }
Exemplo n.º 4
0
        private void OpenChange()
        {
            int         id = 0;
            HelperClass hc = new HelperClass();

            if (hc.CheckIfChangeOpen())
            {
                MessageBox.Show("Смена уже создана.");
                return;
            }
            else
            {
                id = hc.GetIdCurrentChange();

                if (id == -1)
                {
                    id = 0;
                }
                else
                {
                    id++;
                }
            }

            string   connectToChanges = @"Data Source = DESKTOP-NLAJBQI; Initial Catalog = Kass; Integrated Security = True";
            string   sqlCommand       = "INSERT INTO dbo.Changes (Id, DateTimeOpen) VALUES (@Id, @DateTimeOpen)";
            DateTime dateTime         = DateTime.Now.ToLocalTime();

            using (SqlConnection connection = new SqlConnection(connectToChanges))
            {
                connection.Open();
                SqlCommand command = new SqlCommand(sqlCommand, connection);

                command.Parameters.AddWithValue("@Id", id);

                command.Parameters.AddWithValue("@DateTimeOpen", dateTime);

                command.ExecuteNonQueryAsync();

                MessageBox.Show("Смена успешно создана.");
            }
        }
Exemplo n.º 5
0
        private void CloseChange()
        {
            HelperClass hc = new HelperClass();

            if (hc.CheckIfChangeOpen())
            {
                CreateChangesInfoFinal();
                CountAmountSelled();
                CountProceed();
                SetDateTimeCLose();
                TruncateTable();

                MessageBox.Show("Смена " + hc.GetIdCurrentChange().ToString() + " успешно закрыта.");

                dataGridView1.Rows.Clear();
                FillDGV();
            }
            else
            {
                MessageBox.Show("Сначала откройте смену");
            }
        }