Important Notice from AspDotNetStorefront
It is with dismay that we report that we have been forced, through the action of hackers, to shut off write-access to this forum. We are keen to leave the wealth of material available to you for research. We have opened a new forum from which our community of users can seek help, support and advice from us and from each other. To post a new question to our community, please visit: http://forums.vortx.com
Results 1 to 4 of 4

Thread: SQL search for products without an image?

  1. #1
    donato is offline Senior Member
    Join Date
    Jun 2009
    Posts
    215

    Default SQL search for products without an image?

    Does anyone know a query to do an SQL search for any product that doesn't have an image OR has a specific image, like the PICTURE UNAVAILABLE image?

    Thank you in advance. . .

    Cheers,

    ~D

  2. #2
    BFG 9000 is offline Senior Member
    Join Date
    Oct 2006
    Location
    South UK
    Posts
    882

    Default

    Save this into your /xmlpackages folder as missingimages.xml.config, then call it with http://yourdomain.com/e-missingimages.aspx

    C#/VB.NET Code:
    <?xml version="1.0" standalone="yes" ?>
    <package version="2.1" displayname="Missing Product Images" debug="false" includeentityhelper="false" allowengine="true">

    <query name="Products" rowElementName="Product">
    <sql>
    <![CDATA[
    select ProductID, Name, SEName, SKU,ImageFilenameOverride
    from product
    where issystem=0 and deleted=0 and published=1
    order by SKU
    ]]>
    </sql>
    </query>

    <PackageTransform>

    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:aspdnsf="urn:aspdnsf" exclude-result-prefixes="aspdnsf">
    <xsl:output method="html" omit-xml-declaration="yes" />

    <xsl:param name="LocaleSetting" select="/root/Runtime/LocaleSetting" />

    <xsl:template match="/">
    <h1>Products without images</h1>
    <table border="0" cellpadding="0" cellspacing="4" width="100%">
    <xsl:apply-templates select="/root/Products" />
    </table>

    </xsl:template>

    <xsl:template match="Products">
    <tr class="DarkCell">
    <td><font class="CondensedDarkCellText"><b>Product</b></font></td>
    <td><font class="CondensedDarkCellText"><b>SKU</b></font></td>
    <td><font class="CondensedDarkCellText"><b>Image</b></font></td>
    </tr>
    <xsl:apply-templates select="/root/Products/Product" />
    </xsl:template>

    <xsl:template match="Product">
    <xsl:param name="pName" select="aspdnsf:GetMLValue(Name)" />
    <xsl:param name="sename" select="aspdnsf:GetMLValue(SEName)" />
    <xsl:param name="URL">p-<xsl:value-of select="ProductID" disable-output-escaping="yes" />-<xsl:value-of select="$sename"/>.aspx</xsl:param>
    <xsl:param name="IconImageURL"><xsl:value-of select="aspdnsf:ProductImageUrl(ProductID, ImageFilenameOverride, SKU, 'icon', 0)"/></xsl:param>
    <xsl:param name="MediumImageURL"><xsl:value-of select="aspdnsf:ProductImageUrl(ProductID, ImageFilenameOverride, SKU, 'medium', 0)"/></xsl:param>
    <xsl:param name="LargeImageURL"><xsl:value-of select="aspdnsf:ProductImageUrl(ProductID, ImageFilenameOverride, SKU, 'large', 0)"/></xsl:param>
    <xsl:if test="contains($IconImageURL, 'nopicture')" >
    <tr>
    <td><a href="{$URL}"><xsl:value-of select="$pName" disable-output-escaping="yes"/></a></td>
    <td><xsl:value-of select="SKU" /></td>
    <td align="center" valign="bottom">Icon</td>
    </tr>
    </xsl:if>
    <xsl:if test="contains($MediumImageURL, 'nopicture')" >
    <tr>
    <td><a href="{$URL}"><xsl:value-of select="$pName" disable-output-escaping="yes"/></a></td>
    <td><xsl:value-of select="SKU" /></td>
    <td align="center" valign="bottom">Medium</td>
    </tr>
    </xsl:if>
    <xsl:if test="$LargeImageURL = ''" >
    <tr>
    <td><a href="{$URL}"><xsl:value-of select="$pName" disable-output-escaping="yes"/></a></td>
    <td><xsl:value-of select="SKU" /></td>
    <td align="center" valign="bottom">Large</td>
    </tr>
    </xsl:if>
    </xsl:template>

    </xsl:stylesheet>
    </PackageTransform>
    </package>

    TTFN

    BFG

  3. #3
    mgibbs is offline Senior Member
    Join Date
    Jan 2005
    Location
    Orange County, CA
    Posts
    194

    Default

    Nice solution BFG. Very elegant doing it as a XMLPackage.

    I had gone another route and wrote this utility to live in the admin section of the website as a traditional .aspx/.aspx.cs file.

    In the .aspx page, I set up two panels, one that contains a form to ask admin what size photos he is looking for, what type of photos and other limiters and the second to display the results.
    C#/VB.NET Code:
    <body>
        <
    asp:Label ID="lblErrorMessage" runat="server"></asp:Label><br />
        <
    form id="frmxaTools" runat="server">
        <
    asp:Panel ID="pnlDefault" runat="server" Width="100%"> <!-- Default Panel -->
            <!--
    You are logged in as: <asp:Label ID="lblWhoAreYou" runat="server"></asp:Label>-->
            <
    asp:Label ID="lblActionInfo" runat="server"></asp:Label>
        </
    asp:Panel>
        <
    asp:Panel ID="pnlCrawlResults" runat="Server" Width="100%" CssClass="CrawlResultsPanel">
            <
    h3>Crawl for missing images</h3>
            &
    nbsp;&nbsp;
            <
    asp:DropDownList ID="ddlImageSize" runat="server">
                <
    asp:ListItem Value="Large" Selected="True">Select size to check</asp:ListItem>
                <
    asp:ListItem Value="Large">Large</asp:ListItem>
                <
    asp:ListItem Value="Medium">Medium</asp:ListItem>
                <
    asp:ListItem Value="Icon">Icon</asp:ListItem>
            </
    asp:DropDownList>&nbsp;&nbsp;
            <
    asp:DropDownList ID="ddlEntity" runat="server">
                <
    asp:ListItem Value="Product" Selected="True">Products</asp:ListItem>
                <
    asp:ListItem Value="Section">Sections</asp:ListItem>
                <
    asp:ListItem Value="Category">Category</asp:ListItem>
            </
    asp:DropDownList>&nbsp;&nbsp;
            <
    br />
            &
    nbsp;&nbsp;&nbsp;<asp:Label ID="lblManufacturerID" AssociatedControlID="txtManufacturerID" runat="server" >Only show products from this manufacturer</asp:Label>&nbsp;<asp:Textbox ID="txtManufacturerID" runat="server" /> *<i>(product search only)</i><br />
            &
    nbsp;&nbsp;<asp:DropDownList ID="ddlShowPublished" runat="server">
                <
    asp:ListItem Value="All" Selected="True">Show regardless of Published Status</asp:ListItem>
                <
    asp:ListItem Value="Published">Published Only</asp:ListItem>
                <
    asp:ListItem Value="Unpublished">Unpublished Only</asp:ListItem>
            </
    asp:DropDownList>
            <
    asp:Button ID="btnStartCrawl" runat="server" Text="Begin Crawl" 
                
    onclick="btnStartCrawl_Click" />
            <
    h3>Results:</h3>
            <
    asp:Label ID="lblCrawlResults" runat="server"></asp:Label>
        </
    asp:Panel>
        </
    form>
    </
    body
    Then the .cs file reads as follows:
    C#/VB.NET Code:
    using System;
    using System.IO;
    using System.Data;
    using System.Data.OleDb;
    using System.Data.SqlClient;
    using System.Configuration;
    using System.Collections;
    using System.Net.Mail;
    using System.Text;
    using System.Text.RegularExpressions;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;
    using AspDotNetStorefrontCommon;

    namespace 
    AspDotNetStorefrontAdmin
    {

        public 
    partial class TBTools AspDotNetStorefront.SkinBase
        
    {
            
    bool debug false;
            private 
    int timeout;
            private 
    void Page_Init(object senderSystem.EventArgs e)
            {
                
    timeout Server.ScriptTimeout;
                
    Server.ScriptTimeout 3600;
            }
            protected 
    void Page_Load(object senderSystem.EventArgs e)
            {
                
    // Set up Panel visibility
                
    pnlDefault.Visible true;
                
    pnlCrawlResults.Visible true;
            }

            protected 
    void btnStartCrawl_Click(object senderEventArgs e)
            {
                
    string LookFor "";
                
    string path "";
                
    string dbo string.Empty;
                
    string ShowPublished string.Empty;
                
    string ShowUnpublished string.Empty; ;

                
    SectionTitle "XA-Tools | Crawl Products For No Images";

                
    path HttpContext.Current.Server.MapPath(String.Format("/images/{0}/"ddlEntity.SelectedValue));
                
    path += ddlImageSize.SelectedValue "\\";

                
    SqlConnection conn = new SqlConnection(ConfigurationManager.AppSettings["DBConn"]);
                try
                {
                    
    // Open the connection and Execute the SP
                    
    conn.Open();
                    if (
    debug)
                        
    lblErrorMessage.Text "Connection opened successfully <br />";

                    
    SqlCommand rdrCmd conn.CreateCommand();
                    if (
    txtManufacturerID.Text != String.Empty)
                        
    rdrCmd.CommandText String.Format("SELECT p.ProductID, p.ImageFileNameOverRide FROM {2}Product p INNER JOIN {2}ProductVariant pv ON p.ProductID=pv.ProductID INNER JOIN {2}ProductManufacturer pm ON p.ProductID=pm.ProductID WHERE p.Deleted=0 AND pv.Deleted=0 {0} AND pm.ManufacturerID = {1} ORDER BY p.ProductID DESC",
                            
    ShowPublished,
                            
    txtManufacturerID.Text,
                            
    dbo);
                    else
                    {
                        switch (
    ddlEntity.SelectedValue) {
                            case (
    "Product"):
                                switch (
    ddlShowPublished.SelectedValue)
                                {
                                    case (
    "All"):
                                        break;
                                    case (
    "Published"):
                                        
    ShowPublished " AND p.Published=1 and pv.Published=1";
                                        break;
                                    case (
    "Unpublished"):
                                        
    ShowUnpublished "AND p.Published=0 and pv.Published=0";
                                        break;
                                }
                                
    rdrCmd.CommandText String.Format("SELECT p.ProductID, p.ImageFileNameOverRide FROM {1}Product p INNER JOIN {1}ProductVariant pv ON p.ProductID=pv.ProductID WHERE p.Deleted=0 AND pv.Deleted=0 {0} ORDER BY p.ProductID DESC",
                                    
    ShowPublished,
                                    
    dbo);
                                break;
                            case (
    "Section"):
                                switch (
    ddlShowPublished.SelectedValue)
                                {
                                    case (
    "All"):
                                        break;
                                    case (
    "Published"):
                                        
    ShowPublished " AND Published=1";
                                        break;
                                    case (
    "Unpublished"):
                                        
    ShowUnpublished "AND Published=0";
                                        break;
                                }
                                
    rdrCmd.CommandText String.Format("SELECT SectionID, ImageFileNameOverRide FROM {1}Section WHERE Deleted=0 {0} ORDER BY SectionID DESC",
                                    
    ShowPublished,
                                    
    dbo);
                                break;
                            case (
    "Category"):
                                switch (
    ddlShowPublished.SelectedValue)
                                {
                                    case (
    "All"):
                                        break;
                                    case (
    "Published"):
                                        
    ShowPublished " AND Published=1";
                                        break;
                                    case (
    "Unpublished"):
                                        
    ShowUnpublished "AND Published=0";
                                        break;
                                }
                                
    rdrCmd.CommandText String.Format("SELECT CategoryID, ImageFileNameOverRide FROM {1}Category WHERE Deleted=0 {0} ORDER BY CategoryID DESC",
                                    
    ShowPublished,
                                    
    dbo);
                                break;
                        }
                    }
                    
    SqlDataReader dbReader rdrCmd.ExecuteReader();
                    
    lblErrorMessage.Text += "<br />Following is a comma-delimited string of ProductIDs without images:<br />";
                    while (
    dbReader.Read())
                    {
                        switch (
    ddlEntity.SelectedValue) {
                            case 
    "Product":
                                if (
    string.IsNullOrEmpty(dbReader["ImageFilenameOverRide"].ToString()))
                                    
    LookFor path dbReader["ProductID"].ToString() + ".jpg";
                                else
                                    
    LookFor path dbReader["ImageFilenameOverRide"].ToString();
                                if (!
    File.Exists(LookFor))
                                    
    lblErrorMessage.Text += String.Format(" {0},"dbReader["ProductID"].ToString());
                                break;
                            case 
    "Section":
                                if (
    string.IsNullOrEmpty(dbReader["ImageFilenameOverRide"].ToString()))
                                    
    LookFor path dbReader["SectionID"].ToString() + ".jpg";
                                else
                                    
    LookFor path dbReader["ImageFilenameOverRide"].ToString();
                                if (!
    File.Exists(LookFor))
                                    
    // lblErrorMessage.Text += String.Format("{0}: Unable to find {1}<br />", dbReader["ProductID"].ToString(), LookFor);
                                    
    lblErrorMessage.Text += String.Format(" {0},"dbReader["SectionID"].ToString());
                                break;
                            case 
    "Category":
                                if (
    string.IsNullOrEmpty(dbReader["ImageFilenameOverRide"].ToString()))
                                    
    LookFor path dbReader["CategoryID"].ToString() + ".jpg";
                                else
                                    
    LookFor path dbReader["ImageFilenameOverRide"].ToString();
                                if (!
    File.Exists(LookFor))
                                    
    // lblErrorMessage.Text += String.Format("{0}: Unable to find {1}<br />", dbReader["ProductID"].ToString(), LookFor);
                                    
    lblErrorMessage.Text += String.Format(" {0},"dbReader["CategoryID"].ToString());
                                break;

                        }
                    }
                    
    dbReader.Close();
                    
    // Close and dispose of db stuff
                    
    rdrCmd.Dispose();
                }
                catch (
    Exception ex// Some sort of failure occurred in opening connection or running Stored Procedure
                
    {
                    
    lblErrorMessage.Text String.Format("Whoops, something screwed up!<br />Database operations failed to perform properly. [{0}]<br />"ex.ToString());
                }
                
    finally
                
    {
                    
    conn.Close();
                    
    conn.Dispose();
                }

            }
        }

    Last edited by mgibbs; 07-05-2010 at 11:29 PM. Reason: removed stray "using" line
    EMM for AspDotNetStorefront - Communicate effectively with your customers

  4. #4
    chrismartz is offline Senior Member
    Join Date
    Apr 2010
    Posts
    339

    Default

    When I do a call to e-missingimages.aspx in my address bar, I get page cannot be found. Do I have to create the e-missingimages.aspx file?