private void CheckOutItems_Click(object sender, RoutedEventArgs e)
        {
            using (SqlConnection sqlConnection = new SqlConnection(connect))
            {
                sqlConnection.Open();
                ///Add the query here to update and insert the rows
                var selectedItems = CheckOutGrid.SelectedItems;
                foreach (DataRowView data in selectedItems)
                {
                    string query = "";

                    string query2 = "";
                    if (data["HeldAccount"].ToString() != null && data["HeldAccount"].ToString() != "")
                    {
                        string     finder           = "SELECT TOP 1[DATE] FROM Transactions Where ItemId =" + data["ItemId"] + "Order By TransId Desc";
                        SqlCommand cmd              = new SqlCommand(finder, sqlConnection);
                        var        originaldateTime = (System.DateTimeOffset)cmd.ExecuteScalar();
                        var        now              = DateTime.Now;
                        var        newTime          = now.Subtract(originaldateTime.DateTime);


                        query  = "UPDATE Items Set InStock = 0, HeldAccount = NULL WHERE ItemId = " + data["ItemId"];
                        query2 = "INSERT INTO Transactions([Return], CustomerId, Date, CheckedOut, ItemId, WasHold, DateDif) VALUES (0, " + (int)DataContext + ", Convert(datetime,'" + now + "'), Convert(datetime,'" + now + "')," + data["ItemId"] + ", 1, " + newTime.Days + ")";
                    }
                    else
                    {
                        query  = "UPDATE Items Set InStock = 0 WHERE ItemId = " + data["ItemId"];
                        query2 = "INSERT INTO Transactions([Return], CustomerId, Date, CheckedOut, ItemId) VALUES (0, " + (int)DataContext + ", Convert(datetime,'" + DateTime.Now + "'), Convert(datetime,'" + DateTime.Now + "')," + data["ItemId"] + ")";
                    }
                    SqlCommand update = new SqlCommand(query, sqlConnection);
                    update.ExecuteNonQuery();
                    update = new SqlCommand(query2, sqlConnection);
                    update.ExecuteNonQuery();
                }

                sqlConnection.Close();
            }
            var screen        = new PopulateUsers();
            var parentControl = this.FindAncestor <ParentControl>();

            parentControl?.ScreenSwap(screen);
        }
        private void HoldItems_Click(object sender, RoutedEventArgs e)
        {
            using (SqlConnection sqlConnection = new SqlConnection(connect))
            {
                sqlConnection.Open();
                var selectedItems = HoldGrid.SelectedItems;
                foreach (DataRowView data in selectedItems)
                {
                    string query = "UPDATE Items Set HeldAccount = " + (int)DataContext + "Where ItemId = " + data["ItemId"];


                    SqlCommand update = new SqlCommand(query, sqlConnection);
                    update.ExecuteNonQuery();
                }

                sqlConnection.Close();
            }
            var screen        = new PopulateUsers();
            var parentControl = this.FindAncestor <ParentControl>();

            parentControl?.ScreenSwap(screen);
        }
        private void CheckInItems_Click(object sender, RoutedEventArgs e)
        {
            using (SqlConnection sqlConnection = new SqlConnection(connect))
            {
                sqlConnection.Open();
                var selectedItems = CheckInGrid.SelectedItems;
                foreach (DataRowView dataRowView in selectedItems)
                {
                    string     query  = "INSERT INTO Transactions([Return], CustomerId, Date, ItemId) VALUES (1, " + dataRowView["CustomerId"] + ", Convert(datetime,'" + DateTime.Now + "'), " + dataRowView["ItemId"] + ")";
                    SqlCommand update = new SqlCommand(query, sqlConnection);
                    update.ExecuteNonQuery();

                    query  = "UPDATE Items Set InStock = 1 Where ItemId = " + dataRowView["ItemId"];
                    update = new SqlCommand(query, sqlConnection);
                    update.ExecuteNonQuery();
                }
                sqlConnection.Close();
            }

            var screen        = new PopulateUsers();
            var parentControl = this.FindAncestor <ParentControl>();

            parentControl?.ScreenSwap(screen);
        }
Пример #4
0
        private void PopulateUsers_Click(object sender, RoutedEventArgs e)
        {
            var screen = new PopulateUsers();

            ScreenSwap(screen);
        }