Advertisement
Guest User

Untitled

a guest
May 4th, 2018
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 143.86 KB | None | 0 0
  1. using System;
  2. using System.Data.SqlClient;        // SQL Server Connection
  3. using System.Linq;
  4. using System.Security.Cryptography; // MD5, SHA256
  5. using System.Text;                  // For UTF8Encoding
  6. using System.Web;
  7. using System.Web.UI;
  8.  
  9. namespace iCARS.admin
  10. {
  11.     public partial class _default : System.Web.UI.Page
  12.     {
  13.         protected const string szConnectionString = "Data Source=ROBERT\\SQLEXPRESS;Initial Catalog=myDB;Integrated Security=True";
  14.         protected static string szLastErrorMessage = "";
  15.  
  16.         /*****************************************************************************
  17.         * Author:  Robert Milan
  18.         * Name:    _writeCookie
  19.         * Desc:    Saves authentication of a logged in admin
  20.         *
  21.         * Returns: None
  22.         *****************************************************************************/
  23.         protected void _writeCookie(string adUser, string adLVL, int nValue)
  24.         {
  25.             /* Create a cookie that lasts for 15 minutes */
  26.             HttpCookie hcAdmin = new HttpCookie("nimda");
  27.             hcAdmin["aduser"] = adUser;
  28.             hcAdmin["adlvl"] = adLVL;
  29.             hcAdmin["auth"] = nValue.ToString();
  30.             hcAdmin.Expires = DateTime.Now.AddMinutes(15);
  31.  
  32.             /* Save cookie */
  33.             Page.Response.Cookies.Add(hcAdmin);
  34.         }
  35.  
  36.  
  37.         /*****************************************************************************
  38.          * Author:  Robert Milan
  39.          * Name:    _cryptMD5
  40.          * Desc:    Encrypts a string into the MD5 encryption
  41.          *
  42.          * Returns: MD5 HASH in uppercase format
  43.          *****************************************************************************/
  44.         protected string _cryptMD5(string szText)
  45.         {
  46.             // Calculate MD5
  47.             byte[] btPWDEncoding = new UTF8Encoding().GetBytes(szText);
  48.             byte[] btMD5Hash = ((HashAlgorithm)CryptoConfig.CreateFromName("MD5")).ComputeHash(btPWDEncoding);
  49.  
  50.             // Convert MD5 to all uppercase and return it
  51.             return BitConverter.ToString(btMD5Hash).Replace("-", String.Empty).ToUpper();
  52.         }
  53.  
  54.  
  55.         /*****************************************************************************
  56.          * Author:  Robert Milan
  57.          * Name:    _cryptSHA256
  58.          * Desc:    Encrypts a string into the SHA256 encryption
  59.          *
  60.          * Returns: SHA256 encoding in Base64 Encoded format
  61.          *****************************************************************************/
  62.         protected string _cryptSHA256(string szText)
  63.         {
  64.             byte[] btPWDEncoding = Encoding.UTF8.GetBytes(szText);
  65.  
  66.             HashAlgorithm haSHA256 = new SHA256Managed();
  67.             haSHA256.TransformFinalBlock(btPWDEncoding, 0, btPWDEncoding.Length);
  68.  
  69.             return Convert.ToBase64String(haSHA256.Hash);
  70.         }
  71.  
  72.  
  73.         /*****************************************************************************
  74.          * Author:  Robert Milan
  75.          * Name:    _encryptPWD
  76.          * Desc:    Encrypts a a double encoding to confuse SQL Injectors incase
  77.          *              access to the database is gained making it more difficult
  78.          *              to figure out the correct hash to the password.
  79.          *
  80.          * Returns: Double encoded encryption string.
  81.          *****************************************************************************/
  82.         protected string _encryptPWD(string szText)
  83.         {
  84.             return _cryptMD5(_cryptSHA256(szText));
  85.         }
  86.  
  87.  
  88.         /*****************************************************************************
  89.          * Author:  Robert Milan
  90.          * Name:    _authAdmin
  91.          * Desc:    Checks the password against the database of a admin.
  92.          *
  93.          * Returns: 0 if the password is correct, -1 if the password is incorrect.
  94.          *****************************************************************************/
  95.         protected int _authAdmin(string adUser, string adPass)
  96.         {
  97.             SqlConnection scConn = new SqlConnection(szConnectionString);
  98.             SqlCommand scStatement = new SqlCommand(String.Format("SELECT password FROM [dbo].[admin] WHERE username='{0}'", adUser, _encryptPWD(adPass)), scConn);
  99.  
  100.             Boolean blnAuth = false;
  101.             try
  102.             {
  103.                 scConn.Open();
  104.                 SqlDataReader sdr = scStatement.ExecuteReader();
  105.  
  106.                 while (sdr.Read())
  107.                 {
  108.                     if (sdr[0].ToString() == _encryptPWD(adPass)) { blnAuth = true; }
  109.                 }
  110.             }
  111.             catch (Exception m)
  112.             {
  113.                 szLastErrorMessage = m.Message;
  114.             }
  115.             finally
  116.             {
  117.                 scConn.Close();
  118.             }
  119.  
  120.             if (blnAuth == true) { return 0; } else { return -1; }
  121.         }
  122.  
  123.  
  124.         /*****************************************************************************
  125.          * Author:  Robert Milan
  126.          * Name:    _getAdminIndex
  127.          * Desc:    Retreives an admin index from the admin table and
  128.          *              then returns it.
  129.          *
  130.          * Returns: "ERROR!" if an error occurred or admin is not found. Otherwise, it
  131.          *              will return the data in the data field selected.
  132.          *****************************************************************************/
  133.         protected int _getAdminIndex(string szUsername)
  134.         {
  135.             SqlConnection scConn = new SqlConnection(szConnectionString);
  136.             SqlCommand scStatement = new SqlCommand(String.Format("select * from admin where username='{0}'", szUsername), scConn);
  137.  
  138.             int nRet = -1;
  139.  
  140.             try
  141.             {
  142.                 scConn.Open();
  143.  
  144.                 SqlDataReader sdr = scStatement.ExecuteReader();
  145.  
  146.                 sdr.Read();
  147.                 nRet = Convert.ToInt32(sdr[0]);
  148.             }
  149.             catch (Exception m)
  150.             {
  151.                 szLastErrorMessage = m.Message;
  152.             }
  153.             finally
  154.             {
  155.                 scConn.Close();
  156.             }
  157.  
  158.             return nRet;
  159.         }
  160.  
  161.  
  162.         /*****************************************************************************
  163.          * Author:  Robert Milan
  164.          * Name:    _getBrandIndex
  165.          * Desc:    Retreives a brand index from the brand table and
  166.          *              then returns it.
  167.          *
  168.          * Returns: "ERROR!" if an error occurred or admin is not found. Otherwise, it
  169.          *              will return the data in the data field selected.
  170.          *****************************************************************************/
  171.         protected int _getBrandIndex(string szName)
  172.         {
  173.             SqlConnection scConn = new SqlConnection(szConnectionString);
  174.             SqlCommand scStatement = new SqlCommand(String.Format("select * from brand where name='{0}'", szName), scConn);
  175.  
  176.             int nRet = -1;
  177.  
  178.             try
  179.             {
  180.                 scConn.Open();
  181.  
  182.                 SqlDataReader sdr = scStatement.ExecuteReader();
  183.  
  184.                 sdr.Read();
  185.                 nRet = Convert.ToInt32(sdr[0]);
  186.             }
  187.             catch (Exception m)
  188.             {
  189.                 szLastErrorMessage = m.Message;
  190.             }
  191.             finally
  192.             {
  193.                 scConn.Close();
  194.             }
  195.  
  196.             return nRet;
  197.         }
  198.  
  199.  
  200.         /*****************************************************************************
  201.          * Author:  Robert Milan
  202.          * Name:    _getBrandIndex
  203.          * Desc:    Retreives a brand index from the brand table and
  204.          *              then returns it.
  205.          *
  206.          * Returns: "ERROR!" if an error occurred or admin is not found. Otherwise, it
  207.          *              will return the data in the data field selected.
  208.          *****************************************************************************/
  209.         protected int _getCategoryIndex(string szName, int nBrandID)
  210.         {
  211.             SqlConnection scConn = new SqlConnection(szConnectionString);
  212.             SqlCommand scStatement = new SqlCommand(String.Format("select * from category where name='{0}' and brand_id={1}", szName, nBrandID), scConn);
  213.  
  214.             int nRet = -1;
  215.  
  216.             try
  217.             {
  218.                 scConn.Open();
  219.  
  220.                 SqlDataReader sdr = scStatement.ExecuteReader();
  221.  
  222.                 sdr.Read();
  223.                 nRet = Convert.ToInt32(sdr[0]);
  224.             }
  225.             catch (Exception m)
  226.             {
  227.                 szLastErrorMessage = m.Message;
  228.             }
  229.             finally
  230.             {
  231.                 scConn.Close();
  232.             }
  233.  
  234.             return nRet;
  235.         }
  236.  
  237.  
  238.         /*****************************************************************************
  239.          * Author:  Robert Milan
  240.          * Name:    _getAdminField
  241.          * Desc:    Retreives an admin from the admin table and then returns
  242.          *              a piece of the admin field based on nField (0 to 5).
  243.          *
  244.          * Returns: "ERROR!" if an error occurred or admin is not found. Otherwise, it
  245.          *              will return the data in the data field selected.
  246.          *****************************************************************************/
  247.         protected string _getAdminField(int nIndex, int nField)
  248.         {
  249.             SqlConnection scConn = new SqlConnection(szConnectionString);
  250.             SqlCommand scStatement = new SqlCommand(String.Format("select * from admin where id='{0}'", nIndex), scConn);
  251.  
  252.             string szTemp = "";
  253.  
  254.             try
  255.             {
  256.                 scConn.Open();
  257.  
  258.                 SqlDataReader sdr = scStatement.ExecuteReader();
  259.  
  260.                 sdr.Read();
  261.  
  262.                 for (int n = 0; n <= 5; n++) { if (n == nField) { szTemp = sdr[n].ToString(); } }
  263.             }
  264.             catch (Exception m)
  265.             {
  266.                 szLastErrorMessage = m.Message;
  267.                 szTemp = "ERROR!";
  268.             }
  269.             finally
  270.             {
  271.                 scConn.Close();
  272.             }
  273.  
  274.             return szTemp;
  275.         }
  276.  
  277.  
  278.         /*****************************************************************************
  279.          * Author:  Robert Milan
  280.          * Name:    _getBrandField
  281.          * Desc:    Retreives an admin from the admin table and then returns
  282.          *              a piece of the admin field based on nField (0 to 5).
  283.          *
  284.          * Returns: "ERROR!" if an error occurred or admin is not found. Otherwise, it
  285.          *              will return the data in the data field selected.
  286.          *****************************************************************************/
  287.         protected string _getBrandField(int nIndex, int nField)
  288.         {
  289.             SqlConnection scConn = new SqlConnection(szConnectionString);
  290.             SqlCommand scStatement = new SqlCommand(String.Format("select * from brand where id='{0}'", nIndex), scConn);
  291.  
  292.             string szTemp = "";
  293.  
  294.             try
  295.             {
  296.                 scConn.Open();
  297.  
  298.                 SqlDataReader sdr = scStatement.ExecuteReader();
  299.  
  300.                 sdr.Read();
  301.  
  302.                 for (int n = 0; n <= 2; n++) { if (n == nField) { szTemp = sdr[n].ToString(); } }
  303.             }
  304.             catch (Exception m)
  305.             {
  306.                 szLastErrorMessage = m.Message;
  307.                 szTemp = "ERROR!";
  308.             }
  309.             finally
  310.             {
  311.                 scConn.Close();
  312.             }
  313.  
  314.             return szTemp;
  315.         }
  316.  
  317.  
  318.         /*****************************************************************************
  319.         * Author:  Robert Milan
  320.         * Name:    _getBrandField
  321.         * Desc:    Retreives an admin from the admin table and then returns
  322.         *              a piece of the admin field based on nField (0 to 5).
  323.         *
  324.         * Returns: "ERROR!" if an error occurred or admin is not found. Otherwise, it
  325.         *              will return the data in the data field selected.
  326.         *****************************************************************************/
  327.         protected string _getCategoryField(int nIndex, int nField)
  328.         {
  329.             SqlConnection scConn = new SqlConnection(szConnectionString);
  330.             SqlCommand scStatement = new SqlCommand(String.Format("select * from category where id='{0}'", nIndex), scConn);
  331.  
  332.             string szTemp = "";
  333.  
  334.             try
  335.             {
  336.                 scConn.Open();
  337.  
  338.                 SqlDataReader sdr = scStatement.ExecuteReader();
  339.  
  340.                 sdr.Read();
  341.  
  342.                 for (int n = 0; n <= 2; n++) { if (n == nField) { szTemp = sdr[n].ToString(); } }
  343.             }
  344.             catch (Exception m)
  345.             {
  346.                 szLastErrorMessage = m.Message;
  347.                 szTemp = "ERROR!";
  348.             }
  349.             finally
  350.             {
  351.                 scConn.Close();
  352.             }
  353.  
  354.             return szTemp;
  355.         }
  356.  
  357.  
  358.         /*****************************************************************************
  359.          * Author:  Robert Milan
  360.          * Name:    _addAdmin
  361.          * Desc:    Adds an admin into the database.
  362.          *
  363.          * Returns: (int) -1 if it fails, 0 if it succeeds.
  364.          *****************************************************************************/
  365.         protected int _addAdmin(string adUser, string adPass, string adFName, string adLName, string adLVL)
  366.         {
  367.             SqlConnection scConn = new SqlConnection(szConnectionString);
  368.             SqlCommand scStatement = new SqlCommand("INSERT [dbo].[admin] ([username], [password], [fname], [lname], [lvl]) VALUES (@aduser, @adpass, @fname, @lname, @adlvl)", scConn);
  369.  
  370.             try
  371.             {
  372.                 scStatement.Parameters.AddWithValue("@aduser", adUser);
  373.                 scStatement.Parameters.AddWithValue("@adpass", _encryptPWD(adPass));
  374.                 scStatement.Parameters.AddWithValue("@fname", adFName);
  375.                 scStatement.Parameters.AddWithValue("@lname", adLName);
  376.                 scStatement.Parameters.AddWithValue("@adlvl", adLVL);
  377.  
  378.                 scStatement.Connection = scConn;
  379.                 scConn.Open();
  380.  
  381.                 scStatement.ExecuteNonQuery();
  382.             }
  383.             catch (Exception m)
  384.             {
  385.                 szLastErrorMessage = m.Message;
  386.                 return -1;
  387.             }
  388.             finally
  389.             {
  390.                 scConn.Close();
  391.             }
  392.  
  393.             return 0;
  394.         }
  395.  
  396.  
  397.         /*****************************************************************************
  398.          * Author:  Robert Milan
  399.          * Name:    _addBrand
  400.          * Desc:    Adds a brand into the database.
  401.          *
  402.          * Returns: (int) -1 if it fails, 0 if it succeeds.
  403.          *****************************************************************************/
  404.         protected int _addBrand(string szName, string szDescription)
  405.         {
  406.             SqlConnection scConn = new SqlConnection(szConnectionString);
  407.             SqlCommand scStatement = new SqlCommand("INSERT [dbo].[brand] ([name], [description]) VALUES (@BRAND, @DESC)", scConn);
  408.  
  409.             try
  410.             {
  411.                 scStatement.Parameters.AddWithValue("@BRAND", szName);
  412.                 scStatement.Parameters.AddWithValue("@DESC", szDescription);
  413.  
  414.                 scStatement.Connection = scConn;
  415.                 scConn.Open();
  416.  
  417.                 scStatement.ExecuteNonQuery();
  418.             }
  419.             catch (Exception m)
  420.             {
  421.                 szLastErrorMessage = m.Message;
  422.                 return -1;
  423.             }
  424.             finally
  425.             {
  426.                 scConn.Close();
  427.             }
  428.  
  429.             return 0;
  430.         }
  431.  
  432.  
  433.         /*****************************************************************************
  434.          * Author:  Robert Milan
  435.          * Name:    _addCategory
  436.          * Desc:    Adds a category into the database.
  437.          *
  438.          * Returns: (int) -1 if it fails, 0 if it succeeds.
  439.          *****************************************************************************/
  440.         protected int _addCategory(string szName, int nBrandIndex)
  441.         {
  442.             SqlConnection scConn = new SqlConnection(szConnectionString);
  443.             SqlCommand scStatement = new SqlCommand("INSERT [dbo].[category] ([name], [brand_id]) VALUES (@catName, @bID)", scConn);
  444.  
  445.             try
  446.             {
  447.                 scStatement.Parameters.AddWithValue("@catName", szName);
  448.                 scStatement.Parameters.AddWithValue("@bID", nBrandIndex.ToString());
  449.  
  450.                 scStatement.Connection = scConn;
  451.                 scConn.Open();
  452.  
  453.                 scStatement.ExecuteNonQuery();
  454.             }
  455.             catch (Exception m)
  456.             {
  457.                 szLastErrorMessage = m.Message;
  458.                 return -1;
  459.             }
  460.             finally
  461.             {
  462.                 scConn.Close();
  463.             }
  464.  
  465.             return 0;
  466.         }
  467.  
  468.  
  469.         /*****************************************************************************
  470.          * Author:  Robert Milan
  471.          * Name:    _addAdmin
  472.          * Desc:    Adds an admin into the database.
  473.          *
  474.          * Returns: (int) -1 if it fails, 0 if it succeeds.
  475.          *****************************************************************************/
  476.         protected int _addItem(string szName, string szDescription, double fPrice, int nCatID, int nRatingID, int nLength, int nWidth, int nWeight, string szShippingInfo)
  477.         {
  478.             SqlConnection scConn = new SqlConnection(szConnectionString);
  479.             SqlCommand scStatement = new SqlCommand("INSERT [dbo].[item] ([name], [description], [price], [cat_id], [rating_id], [length], [width], [weight], [shipping_info]) VALUES (@iName, @iDesc, @iPrice, @iCID, @iRID, @iLength, @iWidth, @iWeight, @iShippingInfo)", scConn);
  480.  
  481.             try
  482.             {
  483.                 scStatement.Parameters.AddWithValue("@iName", szName);
  484.                 scStatement.Parameters.AddWithValue("@iDesc", szDescription);
  485.                 scStatement.Parameters.AddWithValue("@iPrice", fPrice.ToString());
  486.                 scStatement.Parameters.AddWithValue("@iCID", nCatID.ToString());
  487.                 scStatement.Parameters.AddWithValue("@iRID", nRatingID.ToString());
  488.                 scStatement.Parameters.AddWithValue("@iLength", nLength.ToString());
  489.                 scStatement.Parameters.AddWithValue("@iWidth", nWeight.ToString());
  490.                 scStatement.Parameters.AddWithValue("@iWeight", nWeight.ToString());
  491.                 scStatement.Parameters.AddWithValue("@iShippingInfo", szShippingInfo);
  492.  
  493.                 scStatement.Connection = scConn;
  494.                 scConn.Open();
  495.  
  496.                 scStatement.ExecuteNonQuery();
  497.             }
  498.             catch (Exception m)
  499.             {
  500.                 szLastErrorMessage = m.Message;
  501.                 return -1;
  502.             }
  503.             finally
  504.             {
  505.                 scConn.Close();
  506.             }
  507.  
  508.             return 0;
  509.         }
  510.  
  511.  
  512.         /*****************************************************************************
  513.          * Author:  Robert Milan
  514.          * Name:    _editAdmin
  515.          * Desc:   Edits an admin in the database
  516.          *
  517.          * Returns: (int) -1 if it fails, 0 if it succeeds.
  518.          *****************************************************************************/
  519.         protected int _editAdmin(int adID, string adUser, string adPass, string adFName, string adLName, string adLVL)
  520.         {
  521.             /////////////////////////////
  522.             ////////////////////////////////////
  523.             //////////////////////////////////////////////////////error
  524.             ////////////////////////////////////////
  525.             SqlConnection scConn = new SqlConnection(szConnectionString);
  526.             SqlCommand scStatement = new SqlCommand("UPDATE admin SET username=@adUSER, password=@adPASS, fname=@adFNAME, lname=@adLNAME, lvl=@adLVL WHERE id=@adID", scConn);
  527.  
  528.             scStatement.Parameters.AddWithValue("@adUSER", adUser);
  529.             scStatement.Parameters.AddWithValue("@adPASS", adPass);
  530.             scStatement.Parameters.AddWithValue("@adFNAME", adFName);
  531.             scStatement.Parameters.AddWithValue("@adLNAME", adLName);
  532.             scStatement.Parameters.AddWithValue("@adLVL", adLVL);
  533.             scStatement.Parameters.AddWithValue("@adID", adID.ToString());
  534.  
  535.             try
  536.             {
  537.                 scStatement.Connection = scConn;
  538.                 scConn.Open();
  539.  
  540.                 scStatement.ExecuteNonQuery();
  541.             }
  542.             catch (Exception m)
  543.             {
  544.                 szLastErrorMessage = m.Message;
  545.                 return -1;
  546.             }
  547.             finally
  548.             {
  549.                 scConn.Close();
  550.             }
  551.  
  552.             return 0;
  553.         }
  554.  
  555.  
  556.         /*****************************************************************************
  557.          * Author:  Robert Milan
  558.          * Name:    _editBrand
  559.          * Desc:   Edits a Brand in the database
  560.          *
  561.          * Returns: (int) -1 if it fails, 0 if it succeeds.
  562.          *****************************************************************************/
  563.         protected int _editBrand(int adID, string szName, string szDesc)
  564.         {
  565.             /////////////////////////////
  566.             ////////////////////////////////////
  567.             //////////////////////////////////////////////////////error
  568.             ////////////////////////////////////////
  569.             SqlConnection scConn = new SqlConnection(szConnectionString);
  570.             SqlCommand scStatement = new SqlCommand("UPDATE brand SET name=@brNAME, description=@brDESC WHERE id=@brID", scConn);
  571.  
  572.             scStatement.Parameters.AddWithValue("@brNAME", szName);
  573.             scStatement.Parameters.AddWithValue("@brDESC", szDesc);
  574.             scStatement.Parameters.AddWithValue("@brID", adID.ToString());
  575.  
  576.             try
  577.             {
  578.                 scStatement.Connection = scConn;
  579.                 scConn.Open();
  580.  
  581.                 scStatement.ExecuteNonQuery();
  582.             }
  583.             catch (Exception m)
  584.             {
  585.                 szLastErrorMessage = m.Message;
  586.                 return -1;
  587.             }
  588.             finally
  589.             {
  590.                 scConn.Close();
  591.             }
  592.  
  593.             return 0;
  594.         }
  595.  
  596.  
  597.         /*****************************************************************************
  598.          * Author:  Robert Milan
  599.          * Name:    _editCategory
  600.          * Desc:   Edits a category in the database
  601.          *
  602.          * Returns: (int) -1 if it fails, 0 if it succeeds.
  603.          *****************************************************************************/
  604.         protected int _editCategory(int ID, string szName, int nBrandID)
  605.         {
  606.             /////////////////////////////
  607.             ////////////////////////////////////
  608.             //////////////////////////////////////////////////////error
  609.             ////////////////////////////////////////
  610.             SqlConnection scConn = new SqlConnection(szConnectionString);
  611.             SqlCommand scStatement = new SqlCommand("UPDATE category SET name=@catNAME, brand_id=@BrandID WHERE id=@ID", scConn);
  612.  
  613.             scStatement.Parameters.AddWithValue("@catNAME", szName);
  614.             scStatement.Parameters.AddWithValue("@BrandID", nBrandID.ToString());
  615.             scStatement.Parameters.AddWithValue("@ID", ID.ToString());
  616.  
  617.             try
  618.             {
  619.                 scStatement.Connection = scConn;
  620.                 scConn.Open();
  621.  
  622.                 scStatement.ExecuteNonQuery();
  623.             }
  624.             catch (Exception m)
  625.             {
  626.                 szLastErrorMessage = m.Message;
  627.                 return -1;
  628.             }
  629.             finally
  630.             {
  631.                 scConn.Close();
  632.             }
  633.  
  634.             return 0;
  635.         }
  636.  
  637.  
  638.         /*****************************************************************************
  639.          * Author:  Robert Milan
  640.          * Name:    _deleteAdmin
  641.          * Desc:    deletes an admin from the database.
  642.          *
  643.          * Returns: (int) -1 if it fails, 0 if it succeeds.
  644.          *****************************************************************************/
  645.         protected int _deleteAdmin(int adID)
  646.         {
  647.             SqlConnection scConn = new SqlConnection(szConnectionString);
  648.             SqlCommand scStatement = new SqlCommand("DELETE FROM admin WHERE id=@adID", scConn);
  649.  
  650.             scStatement.Parameters.AddWithValue("@adID", adID.ToString());
  651.  
  652.             try
  653.             {
  654.                 scStatement.Connection = scConn;
  655.                 scConn.Open();
  656.  
  657.                 scStatement.ExecuteNonQuery();
  658.             }
  659.             catch (Exception m)
  660.             {
  661.                 szLastErrorMessage = m.Message;
  662.                 return -1;
  663.             }
  664.             finally
  665.             {
  666.                 scConn.Close();
  667.             }
  668.  
  669.             return 0;
  670.         }
  671.  
  672.  
  673.         /*****************************************************************************
  674.          * Author:  Robert Milan
  675.          * Name:    _deleteBrand
  676.          * Desc:    deletes an brand from the database.
  677.          *
  678.          * Returns: (int) -1 if it fails, 0 if it succeeds.
  679.          *****************************************************************************/
  680.         protected int _deleteBrand(int brandID)
  681.         {
  682.             SqlConnection scConn = new SqlConnection(szConnectionString);
  683.             SqlCommand scStatement = new SqlCommand("DELETE FROM brand WHERE id=@brandID", scConn);
  684.  
  685.             scStatement.Parameters.AddWithValue("@brandID", brandID.ToString());
  686.  
  687.             try
  688.             {
  689.                 scStatement.Connection = scConn;
  690.                 scConn.Open();
  691.  
  692.                 scStatement.ExecuteNonQuery();
  693.             }
  694.             catch (Exception m)
  695.             {
  696.                 szLastErrorMessage = m.Message;
  697.                 return -1;
  698.             }
  699.             finally
  700.             {
  701.                 scConn.Close();
  702.             }
  703.  
  704.             return 0;
  705.         }
  706.  
  707.  
  708.         /*****************************************************************************
  709.         * Author:  Robert Milan
  710.         * Name:    _deleteCategory
  711.         * Desc:    deletes a category from the database.
  712.         *
  713.         * Returns: (int) -1 if it fails, 0 if it succeeds.
  714.         *****************************************************************************/
  715.         protected int _deleteCategory(int catID)
  716.         {
  717.             SqlConnection scConn = new SqlConnection(szConnectionString);
  718.             SqlCommand scStatement = new SqlCommand("DELETE FROM category WHERE id=@catID", scConn);
  719.  
  720.             scStatement.Parameters.AddWithValue("@catID", catID.ToString());
  721.  
  722.             try
  723.             {
  724.                 scStatement.Connection = scConn;
  725.                 scConn.Open();
  726.  
  727.                 scStatement.ExecuteNonQuery();
  728.             }
  729.             catch (Exception m)
  730.             {
  731.                 szLastErrorMessage = m.Message;
  732.                 return -1;
  733.             }
  734.             finally
  735.             {
  736.                 scConn.Close();
  737.             }
  738.  
  739.             return 0;
  740.         }
  741.  
  742.  
  743.         /*****************************************************************************
  744.          * Author:  Robert Milan
  745.          * Name:    _deleteItem
  746.          * Desc:    deletes a item from the database.
  747.          *
  748.          * Returns: (int) -1 if it fails, 0 if it succeeds.
  749.          *****************************************************************************/
  750.         protected int _deleteItem(int itemID)
  751.         {
  752.             SqlConnection scConn = new SqlConnection(szConnectionString);
  753.             SqlCommand scStatement = new SqlCommand("DELETE FROM item WHERE id=@itemID", scConn);
  754.  
  755.             scStatement.Parameters.AddWithValue("@itemID", itemID.ToString());
  756.  
  757.             try
  758.             {
  759.                 scStatement.Connection = scConn;
  760.                 scConn.Open();
  761.  
  762.                 scStatement.ExecuteNonQuery();
  763.             }
  764.             catch (Exception m)
  765.             {
  766.                 szLastErrorMessage = m.Message;
  767.                 return -1;
  768.             }
  769.             finally
  770.             {
  771.                 scConn.Close();
  772.             }
  773.  
  774.             return 0;
  775.         }
  776.  
  777.  
  778.         /*****************************************************************************
  779.          * Author:  Robert Milan
  780.          * Name:    _displayAdminPage
  781.          * Desc:    Display's the admin panel
  782.          *
  783.          * Returns: None.
  784.          *****************************************************************************/
  785.         protected void _displayAdminPage()
  786.         {
  787.             string szPage = "\n<table style=\"text-align: center; margin-left: 10%; margin-right: 10%; width: 80%;\">\n";
  788.             szPage += "   <tr style=\"font-weight: bold; text-decoration: underline;\">\n";
  789.             szPage += "      <td class=\"dark\">ID</td>\n";
  790.             szPage += "      <td class=\"dark\">Username</td>\n";
  791.             szPage += "      <td class=\"dark\">Password HASH</td>\n";
  792.             szPage += "      <td class=\"dark\">First Name</td>\n";
  793.             szPage += "      <td class=\"dark\">Last Name</td>\n";
  794.             szPage += "      <td class=\"dark\">Level</td>\n";
  795.             szPage += "      <td class=\"dark\"></td>\n";
  796.             szPage += "   </tr>\n";
  797.  
  798.             string adUSER = "";
  799.             string adLVL = "";
  800.             string adAUTH = "";
  801.  
  802.             int nCookieExist = 0;
  803.             if (Request.Cookies["nimda"] != null)
  804.             {
  805.                 if (Request.Cookies["nimda"]["aduser"] != null) { adUSER = Request.Cookies["nimda"]["aduser"]; }
  806.                 if (Request.Cookies["nimda"]["adlvl"] != null) { adLVL = Request.Cookies["nimda"]["adlvl"]; }
  807.                 if (Request.Cookies["nimda"]["auth"] != null) { adAUTH = Request.Cookies["nimda"]["auth"]; }
  808.  
  809.                 nCookieExist = 1;
  810.             }
  811.  
  812.             if (nCookieExist == 1)
  813.             {
  814.                 SqlConnection scConn = new SqlConnection(szConnectionString);
  815.                 SqlCommand scStatement = new SqlCommand("SELECT * from admin", scConn);
  816.  
  817.                 try
  818.                 {
  819.                     scConn.Open();
  820.  
  821.                     SqlDataReader sdr = scStatement.ExecuteReader();
  822.                     while (sdr.Read())
  823.                     {
  824.                         szPage += "   <tr>\n";
  825.                         szPage += "      <td class=\"lite\">" + sdr[0].ToString() + "</td>\n";
  826.                         szPage += "      <td class=\"lite\">" + sdr[1].ToString() + "</td>\n";
  827.                         szPage += "      <td class=\"lite\">" + sdr[2].ToString() + "</td>\n";
  828.                         szPage += "      <td class=\"lite\">" + sdr[3].ToString() + "</td>\n";
  829.                         szPage += "      <td class=\"lite\">" + sdr[4].ToString() + "</td>\n";
  830.  
  831.                         /*****************************************************************************
  832.                          * Display the proper title based on the current admin level.                *
  833.                          /****************************************************************************/
  834.                         string szTemp = "";
  835.                         if (sdr[5].ToString() == "0") { szTemp = "Moderator"; }
  836.                         if (sdr[5].ToString() == "1") { szTemp = "Admin"; }
  837.                         if (sdr[5].ToString() == "2") { szTemp = "Super Admin"; }
  838.  
  839.                         szPage += "      <td class=\"lite\">" + szTemp + "</td>\n";
  840.                         /*****************************************************************************
  841.                          *****************************************************************************/
  842.  
  843.                         szTemp = "";
  844.  
  845.                         // Current admin level of the current entry we are grabbing from the db
  846.                         Int32.TryParse(sdr[5].ToString(), out int nADType);
  847.  
  848.                         // Get the current level of the admin whose logged in
  849.                         Int32.TryParse(adLVL, out int nADCurr);
  850.  
  851.                         if ((nADCurr < nADType) || (nADCurr == nADType))
  852.                         {
  853.                             szPage += "      <td class=\"lite\"><a href=\"default.aspx?pid=admin&act=edit&id=" + sdr[0].ToString() + "\">EDIT</a></td>\n";
  854.                         }
  855.                         else
  856.                         {
  857.                             szPage += "      <td class=\"lite\"><a href=\"default.aspx?pid=admin&act=edit&id=" + sdr[0].ToString() + "\">EDIT</a> | <a href=\"default.aspx?pid=admin&act=delete&id=" + sdr[0].ToString() + "\">DELETE</a></td>\n";
  858.                         }
  859.  
  860.                         szPage += "   </tr>\n";
  861.                     }
  862.                 }
  863.                 catch (Exception m)
  864.                 {
  865.                     szLastErrorMessage = m.Message;
  866.                 }
  867.                 finally
  868.                 {
  869.                     scConn.Close();
  870.                 }
  871.             }
  872.  
  873.             szPage += "</table>\n";
  874.  
  875.  
  876.             /**************************************************************
  877.              * If the admin is authorized and a super admin, then we      *
  878.              *    can allow them to have access to add a admin            *
  879.              *    to the database.                                        *
  880.              /*************************************************************/
  881.  
  882.             if ((adLVL == "2") && (adAUTH == "1"))
  883.             {
  884.                 szPage += "<br />\n<hr />\n<br />\n";
  885.                 szPage += "\n<form id=\"frmLogin\" method=\"post\">\n";
  886.                 szPage += "   <input type=\"hidden\" id=\"op\" name=\"op\" value=\"admin\">\n";
  887.                 szPage += "   <input type=\"hidden\" id=\"act\" name=\"act\" value=\"add\">";
  888.                 szPage += "<table style=\"text-align: center; margin-left: 10%; margin-right: 10%; width: 80%;\">\n";
  889.                 szPage += "   <tr style=\"font-weight: bold; text-decoration: underline;\">\n";
  890.                 szPage += "      <td class=\"dark\">\n";
  891.                 szPage += "         <h1>ADD ADMIN</h1>\n";
  892.                 szPage += "         <br />\n";
  893.                 szPage += "         <table style=\"margin: auto; width: 100 %;\">\n";
  894.                 szPage += "            <tr>\n";
  895.                 szPage += "               <td style=\"text-align: right; width: 40%;\">Username:&nbsp;</td>\n";
  896.                 szPage += "               <td style=\"text-align: left; width: 60%;\"><input style=\"width: 300px;\" id=\"adUSER\" name=\"adUSER\" type=\"text\" /></td>\n";
  897.                 szPage += "            </tr>\n";
  898.                 szPage += "            <tr>\n";
  899.                 szPage += "               <td style=\"text-align: right; width: 40%;\">Password:&nbsp;</td>\n";
  900.                 szPage += "               <td style=\"text-align: left; width: 60%;\"><input style=\"width: 300px;\" id=\"adPASS\" name=\"adPASS\" type=\"text\" /></td>\n";
  901.                 szPage += "            </tr>\n";
  902.                 szPage += "            <tr>\n";
  903.                 szPage += "               <td style=\"text-align: right; width: 40%;\">Confirm Password:&nbsp;</td>\n";
  904.                 szPage += "               <td style=\"text-align: left; width: 60%;\"><input style=\"width: 300px;\" id=\"adCONF\" name=\"adCONF\" type=\"text\" /></td>\n";
  905.                 szPage += "            </tr>\n";
  906.                 szPage += "            <tr>\n";
  907.                 szPage += "               <td style=\"text-align: right; width: 40%;\">First Name:&nbsp;</td>\n";
  908.                 szPage += "               <td style=\"text-align: left; width: 60%;\"><input style=\"width: 300px;\" id=\"adFNAME\" name=\"adFNAME\" type=\"text\" /></td>\n";
  909.                 szPage += "            </tr>\n";
  910.                 szPage += "            <tr>\n";
  911.                 szPage += "               <td style=\"text-align: right; width: 40%;\">Last Name:&nbsp;</td>\n";
  912.                 szPage += "               <td style=\"text-align: left; width: 60%;\"><input style=\"width: 300px;\" id=\"adLNAME\" name=\"adLNAME\" type=\"text\" /></td>\n";
  913.                 szPage += "            </tr>\n";
  914.                 szPage += "            <tr>\n";
  915.                 szPage += "               <td style=\"text-align: right; width: 40%;\">[0, 1, or 2] Level:&nbsp;</td>\n";
  916.                 szPage += "               <td style=\"text-align: left; width: 60%;\"><input style=\"width: 300px;\" id=\"adLVL\" name=\"adLVL\" type=\"text\" /></td>\n";
  917.                 szPage += "            </tr>\n";
  918.                 szPage += "            <tr>\n";
  919.                 szPage += "               <td style=\"text-align: right; width: 40%;\"></td>\n";
  920.                 szPage += "               <td style=\"text-align: left; width: 60%;\"><div style=\"width: 301px; text-align: right;\"><input style=\"width: 100px;\" id=\"btnAddAdmin\" name=\"submit\" type=\"submit\" value=\"Add Admin\" /></div></td>\n";
  921.                 szPage += "            </tr>\n";
  922.                 szPage += "         </table>\n";
  923.                 szPage += "      </td>\n";
  924.                 szPage += "   </tr>\n";
  925.                 szPage += "</table></form>\n";
  926.                 szPage += "<br />\n";
  927.             }
  928.  
  929.             _content.InnerHtml = szPage;
  930.         }
  931.  
  932.  
  933.         /*****************************************************************************
  934.          * Author:  Robert Milan
  935.          * Name:    _displayBrandPage
  936.          * Desc:    Display's the brand panel
  937.          *
  938.          * Returns: None.
  939.          *****************************************************************************/
  940.         protected void _displayBrandPage()
  941.         {
  942.             string szPage = "\n<table style=\"text-align: center; margin-left: 10%; margin-right: 10%; width: 80%;\">\n";
  943.             szPage += "   <tr style=\"font-weight: bold; text-decoration: underline;\">\n";
  944.             szPage += "      <td class=\"dark\">ID</td>\n";
  945.             szPage += "      <td class=\"dark\">Name</td>\n";
  946.             szPage += "      <td class=\"dark\">Description</td>\n";
  947.             szPage += "      <td class=\"dark\"></td>\n";
  948.             szPage += "   </tr>\n";
  949.  
  950.             string adUSER = "";
  951.             string adLVL = "";
  952.             string adAUTH = "";
  953.  
  954.             int nCookieExist = 0;
  955.             if (Request.Cookies["nimda"] != null)
  956.             {
  957.                 if (Request.Cookies["nimda"]["aduser"] != null) { adUSER = Request.Cookies["nimda"]["aduser"]; }
  958.                 if (Request.Cookies["nimda"]["adlvl"] != null) { adLVL = Request.Cookies["nimda"]["adlvl"]; }
  959.                 if (Request.Cookies["nimda"]["auth"] != null) { adAUTH = Request.Cookies["nimda"]["auth"]; }
  960.  
  961.                 nCookieExist = 1;
  962.             }
  963.  
  964.             if (nCookieExist == 1)
  965.             {
  966.                 SqlConnection scConn = new SqlConnection(szConnectionString);
  967.                 SqlCommand scStatement = new SqlCommand("SELECT * from brand", scConn);
  968.  
  969.                 try
  970.                 {
  971.                     scConn.Open();
  972.  
  973.                     SqlDataReader sdr = scStatement.ExecuteReader();
  974.                     while (sdr.Read())
  975.                     {
  976.                         szPage += "   <tr>\n";
  977.                         szPage += "      <td class=\"lite\">" + sdr[0].ToString() + "</td>\n";
  978.                         szPage += "      <td class=\"lite\">" + sdr[1].ToString() + "</td>\n";
  979.                         szPage += "      <td class=\"lite\">" + sdr[2].ToString() + "</td>\n";
  980.  
  981.                         // Current admin level of the current entry we are grabbing from the db
  982.                         Int32.TryParse(adLVL, out int nADType);
  983.  
  984.                         if (nADType == 0) // Moderators can edit but not delete
  985.                         {
  986.                             szPage += "      <td class=\"lite\"><a href=\"default.aspx?pid=brand&act=edit&id=" + sdr[0].ToString() + "\">EDIT</a></td>\n";
  987.                         }
  988.                         else
  989.                         {
  990.                             szPage += "      <td class=\"lite\"><a href=\"default.aspx?pid=brand&act=edit&id=" + sdr[0].ToString() + "\">EDIT</a> | <a href=\"default.aspx?pid=brand&act=delete&id=" + sdr[0].ToString() + "\">DELETE</a></td>\n";
  991.                         }
  992.  
  993.                         szPage += "   </tr>\n";
  994.                     }
  995.                 }
  996.                 catch (Exception m)
  997.                 {
  998.                     szLastErrorMessage = m.Message;
  999.                 }
  1000.                 finally
  1001.                 {
  1002.                     scConn.Close();
  1003.                 }
  1004.             }
  1005.             else
  1006.             {
  1007.                 Response.Redirect("default.aspx");
  1008.             }
  1009.  
  1010.             szPage += "</table>\n";
  1011.  
  1012.  
  1013.             /**************************************************************
  1014.              * If the admin is authorized and a super admin, then we      *
  1015.              *    can allow them to have access to add a admin            *
  1016.              *    to the database.                                        *
  1017.              /*************************************************************/
  1018.  
  1019.             if (adAUTH == "1")
  1020.             {
  1021.                 szPage += "<br />\n<hr />\n<br />\n";
  1022.                 szPage += "\n<form id=\"frmAddBrand\" method=\"post\">\n";
  1023.                 szPage += "   <input type=\"hidden\" id=\"op\" name=\"op\" value=\"brand\">\n";
  1024.                 szPage += "   <input type=\"hidden\" id=\"act\" name=\"act\" value=\"add\">";
  1025.                 szPage += "<table style=\"text-align: center; margin-left: 10%; margin-right: 10%; width: 80%;\">\n";
  1026.                 szPage += "   <tr style=\"font-weight: bold; text-decoration: underline;\">\n";
  1027.                 szPage += "      <td class=\"dark\">\n";
  1028.                 szPage += "         <h1>ADD BRAND</h1>\n";
  1029.                 szPage += "         <br />\n";
  1030.                 szPage += "         <table style=\"margin: auto; width: 100 %;\">\n";
  1031.                 szPage += "            <tr>\n";
  1032.                 szPage += "               <td style=\"text-align: right; width: 40%;\">Brand Name:&nbsp;</td>\n";
  1033.                 szPage += "               <td style=\"text-align: left; width: 60%;\"><input style=\"width: 300px;\" id=\"brName\" name=\"brName\" type=\"text\" /></td>\n";
  1034.                 szPage += "            </tr>\n";
  1035.                 szPage += "            <tr>\n";
  1036.                 szPage += "               <td style=\"text-align: right; width: 40%;\">Brand Description:&nbsp;</td>\n";
  1037.                 szPage += "               <td style=\"text-align: left; width: 60%;\"><input style=\"width: 300px;\" id=\"brDesc\" name=\"brDesc\" type=\"text\" /></td>\n";
  1038.                 szPage += "            </tr>\n";
  1039.                 szPage += "            <tr>\n";
  1040.                 szPage += "               <td style=\"text-align: right; width: 40%;\"></td>\n";
  1041.                 szPage += "               <td style=\"text-align: left; width: 60%;\"><div style=\"width: 301px; text-align: right;\"><input style=\"width: 100px;\" id=\"btnAddBrand\" name=\"submit\" type=\"submit\" value=\"Add Brand\" /></div></td>\n";
  1042.                 szPage += "            </tr>\n";
  1043.                 szPage += "         </table>\n";
  1044.                 szPage += "      </td>\n";
  1045.                 szPage += "   </tr>\n";
  1046.                 szPage += "</table></form>\n";
  1047.                 szPage += "<br />\n";
  1048.             }
  1049.  
  1050.             _content.InnerHtml = szPage;
  1051.         }
  1052.  
  1053.  
  1054.         /*****************************************************************************
  1055.          * Author:  Robert Milan
  1056.          * Name:    _displayCategoryPage
  1057.          * Desc:    Display's the category panel
  1058.          *
  1059.          * Returns: None.
  1060.          *****************************************************************************/
  1061.         protected void _displayCategoryPage()
  1062.         {
  1063.             string szPage = "\n<table style=\"text-align: center; margin-left: 10%; margin-right: 10%; width: 80%;\">\n";
  1064.             szPage += "   <tr style=\"font-weight: bold; text-decoration: underline;\">\n";
  1065.             szPage += "      <td class=\"dark\">ID</td>\n";
  1066.             szPage += "      <td class=\"dark\">Name</td>\n";
  1067.             szPage += "      <td class=\"dark\">Brand ID (Name)</td>\n";
  1068.             szPage += "      <td class=\"dark\"></td>\n";
  1069.             szPage += "   </tr>\n";
  1070.  
  1071.             string adUSER = "";
  1072.             string adLVL = "";
  1073.             string adAUTH = "";
  1074.  
  1075.             int nCookieExist = 0;
  1076.             if (Request.Cookies["nimda"] != null)
  1077.             {
  1078.                 if (Request.Cookies["nimda"]["aduser"] != null) { adUSER = Request.Cookies["nimda"]["aduser"]; }
  1079.                 if (Request.Cookies["nimda"]["adlvl"] != null) { adLVL = Request.Cookies["nimda"]["adlvl"]; }
  1080.                 if (Request.Cookies["nimda"]["auth"] != null) { adAUTH = Request.Cookies["nimda"]["auth"]; }
  1081.  
  1082.                 nCookieExist = 1;
  1083.             }
  1084.  
  1085.             if (nCookieExist == 1)
  1086.             {
  1087.                 SqlConnection scConn = new SqlConnection(szConnectionString);
  1088.                 SqlCommand scStatement = new SqlCommand("SELECT * from category order by brand_id", scConn);
  1089.  
  1090.                 try
  1091.                 {
  1092.                     scConn.Open();
  1093.  
  1094.                     SqlDataReader sdr = scStatement.ExecuteReader();
  1095.                     while (sdr.Read())
  1096.                     {
  1097.                         // Get the index of the brand so we can lookup its name
  1098.                         Int32.TryParse(sdr[2].ToString(), out int nIndex);
  1099.  
  1100.                         szPage += "   <tr>\n";
  1101.                         szPage += "      <td class=\"lite\">" + sdr[0].ToString() + "</td>\n";
  1102.                         szPage += "      <td class=\"lite\">" + sdr[1].ToString() + "</td>\n";
  1103.                         szPage += "      <td class=\"lite\">" + sdr[2].ToString() + " (" + _getBrandField(Convert.ToInt32(sdr[2].ToString()), 1) + ")</td>\n";
  1104.  
  1105.                         // Current admin level of the current entry we are grabbing from the db
  1106.                         Int32.TryParse(adLVL, out int nADType);
  1107.  
  1108.                         if (nADType == 0) // Moderators can edit but not delete
  1109.                         {
  1110.                             szPage += "      <td class=\"lite\"><a href=\"default.aspx?pid=category&act=edit&id=" + sdr[0].ToString() + "\">EDIT</a></td>\n";
  1111.                         }
  1112.                         else
  1113.                         {
  1114.                             szPage += "      <td class=\"lite\"><a href=\"default.aspx?pid=category&act=edit&id=" + sdr[0].ToString() + "\">EDIT</a> | <a href=\"default.aspx?pid=category&act=delete&id=" + sdr[0].ToString() + "\">DELETE</a></td>\n";
  1115.                         }
  1116.  
  1117.                         szPage += "   </tr>\n";
  1118.                     }
  1119.                 }
  1120.                 catch (Exception m)
  1121.                 {
  1122.                     szLastErrorMessage = m.Message;
  1123.                 }
  1124.                 finally
  1125.                 {
  1126.                     scConn.Close();
  1127.                 }
  1128.             }
  1129.             else
  1130.             {
  1131.                 Response.Redirect("default.aspx?pid=category");
  1132.             }
  1133.  
  1134.             szPage += "</table>\n";
  1135.  
  1136.  
  1137.             /**************************************************************
  1138.              * If the admin is authorized and a super admin, then we      *
  1139.              *    can allow them to have access to add a admin            *
  1140.              *    to the database.                                        *
  1141.              /*************************************************************/
  1142.  
  1143.             if (adAUTH == "1")
  1144.             {
  1145.                 szPage += "<br />\n<hr />\n<br />\n";
  1146.                 szPage += "\n<form id=\"frmAddCategory\" method=\"post\">\n";
  1147.                 szPage += "   <input type=\"hidden\" id=\"op\" name=\"op\" value=\"category\">\n";
  1148.                 szPage += "   <input type=\"hidden\" id=\"act\" name=\"act\" value=\"add\">";
  1149.                 szPage += "<table style=\"text-align: center; margin-left: 10%; margin-right: 10%; width: 80%;\">\n";
  1150.                 szPage += "   <tr style=\"font-weight: bold; text-decoration: underline;\">\n";
  1151.                 szPage += "      <td class=\"dark\">\n";
  1152.                 szPage += "         <h1>ADD CATEGORY</h1>\n";
  1153.                 szPage += "         <br />\n";
  1154.                 szPage += "         <table style=\"margin: auto; width: 100 %;\">\n";
  1155.                 szPage += "            <tr>\n";
  1156.                 szPage += "               <td style=\"text-align: right; width: 40%;\">Category Name:&nbsp;</td>\n";
  1157.                 szPage += "               <td style=\"text-align: left; width: 60%;\"><input style=\"width: 300px;\" id=\"catName\" name=\"catName\" type=\"text\" /></td>\n";
  1158.                 szPage += "            </tr>\n";
  1159.  
  1160.  
  1161.  
  1162.                 SqlConnection scConn = new SqlConnection(szConnectionString);
  1163.                 SqlCommand scStatement = new SqlCommand("SELECT * from brand", scConn);
  1164.  
  1165.                 try
  1166.                 {
  1167.                     scConn.Open();
  1168.  
  1169.                     SqlDataReader sdr = scStatement.ExecuteReader();
  1170.  
  1171.  
  1172.                     szPage += "   <tr>\n";
  1173.                     szPage += "      <td style=\"text-align: right; width: 40%;\">Select a Brand:&nbsp;</td>\n";
  1174.                     szPage += "      <td style=\"text-align: left; width: 60%;\">\n";
  1175.                     szPage += "         <select id=\"bid\" name=\"bid\">\n";
  1176.                     while (sdr.Read())
  1177.                     {
  1178.                         szPage += "            <option value=\"" + sdr[1].ToString() + "\">" + sdr[1].ToString() + "</option>\n";
  1179.                     }
  1180.                    
  1181.                     szPage += "      </td>\n   </tr>\n";
  1182.                 }
  1183.                 catch (Exception m)
  1184.                 {
  1185.                     szLastErrorMessage = m.Message;
  1186.                 }
  1187.                 finally
  1188.                 {
  1189.                     scConn.Close();
  1190.                 }
  1191.  
  1192.  
  1193.                 szPage += "         <tr>\n";
  1194.                 szPage += "            <td style=\"text-align: right; width: 40%;\"></td>\n";
  1195.                 szPage += "            <td style=\"text-align: left; width: 60%;\"><div style=\"width: 301px; text-align: right;\"><input style=\"width: 100px;\" id=\"btnAddCat\" name=\"submit\" type=\"submit\" value=\"Add Category\" /></div></td>\n";
  1196.                 szPage += "         </tr>\n";
  1197.                 szPage += "      </table>\n";
  1198.                 szPage += "      </td>\n";
  1199.                 szPage += "   </tr>\n";
  1200.                 szPage += "</table></form>\n";
  1201.                 szPage += "<br />\n";
  1202.             }
  1203.  
  1204.             _content.InnerHtml = szPage;
  1205.         }
  1206.  
  1207.  
  1208.         /*****************************************************************************
  1209.          * Author:  Robert Milan
  1210.          * Name:    _displayItemPage
  1211.          * Desc:    Display's the item panel
  1212.          *
  1213.          * Returns: None.
  1214.          *****************************************************************************/
  1215.         protected void _displayItemPage()
  1216.         {
  1217.             string szPage = "\n<table style=\"text-align: center; margin-left: 10%; margin-right: 10%; width: 80%;\">\n";
  1218.             szPage += "   <tr style=\"font-weight: bold; text-decoration: underline;\">\n";
  1219.             szPage += "      <td class=\"dark\">ID</td>\n";
  1220.             szPage += "      <td class=\"dark\">Name</td>\n";
  1221.             szPage += "      <td class=\"dark\">Description</td>\n";
  1222.             szPage += "      <td class=\"dark\">Price</td>\n";
  1223.             szPage += "      <td class=\"dark\">Cat ID (Name)</td>\n";
  1224.             szPage += "      <td class=\"dark\">Length</td>\n";
  1225.             szPage += "      <td class=\"dark\">Width</td>\n";
  1226.             szPage += "      <td class=\"dark\">Weight</td>\n";
  1227.             szPage += "      <td class=\"dark\">Shipping Info</td>\n";
  1228.             szPage += "      <td class=\"dark\"></td>\n";
  1229.             szPage += "   </tr>\n";
  1230.  
  1231.             string adUSER = "";
  1232.             string adLVL = "";
  1233.             string adAUTH = "";
  1234.  
  1235.             int nCookieExist = 0;
  1236.             if (Request.Cookies["nimda"] != null)
  1237.             {
  1238.                 if (Request.Cookies["nimda"]["aduser"] != null) { adUSER = Request.Cookies["nimda"]["aduser"]; }
  1239.                 if (Request.Cookies["nimda"]["adlvl"] != null) { adLVL = Request.Cookies["nimda"]["adlvl"]; }
  1240.                 if (Request.Cookies["nimda"]["auth"] != null) { adAUTH = Request.Cookies["nimda"]["auth"]; }
  1241.  
  1242.                 nCookieExist = 1;
  1243.             }
  1244.  
  1245.             if (nCookieExist == 1)
  1246.             {
  1247.                 SqlConnection scConn = new SqlConnection(szConnectionString);
  1248.                 SqlCommand scStatement = new SqlCommand("SELECT * from item", scConn);
  1249.  
  1250.                 try
  1251.                 {
  1252.                     scConn.Open();
  1253.  
  1254.                     SqlDataReader sdr = scStatement.ExecuteReader();
  1255.                     while (sdr.Read())
  1256.                     {
  1257.                         // Get the index of the brand so we can lookup its name
  1258.  
  1259.                         szPage += "   <tr>\n";
  1260.                         szPage += "      <td class=\"lite\">" + sdr[0].ToString() + "</td>\n";
  1261.                         szPage += "      <td class=\"lite\">" + sdr[1].ToString() + "</td>\n";
  1262.                         szPage += "      <td class=\"lite\">" + sdr[2].ToString() + "</td>\n";
  1263.                         szPage += "      <td class=\"lite\">" + sdr[3].ToString() + "</td>\n";
  1264.                         szPage += "      <td class=\"lite\">" + sdr[4].ToString() + " (" + _getCategoryField(Convert.ToInt32(sdr[4].ToString()), 1) + ")</td>\n";
  1265.                         szPage += "      <td class=\"lite\">" + sdr[5].ToString() + "</td>\n";
  1266.                         szPage += "      <td class=\"lite\">" + sdr[6].ToString() + "</td>\n";
  1267.                         szPage += "      <td class=\"lite\">" + sdr[7].ToString() + "</td>\n";
  1268.                         szPage += "      <td class=\"lite\">" + sdr[8].ToString() + "</td>\n";
  1269.  
  1270.                         // Current admin level of the current entry we are grabbing from the db
  1271.                         Int32.TryParse(adLVL, out int nADType);
  1272.  
  1273.                         if (nADType == 0) // Moderators can edit but not delete
  1274.                         {
  1275.                             szPage += "      <td class=\"lite\"><a href=\"default.aspx?pid=item&act=edit&id=" + sdr[0].ToString() + "\">EDIT</a></td>\n";
  1276.                         }
  1277.                         else
  1278.                         {
  1279.                             szPage += "      <td class=\"lite\"><a href=\"default.aspx?pid=item&act=edit&id=" + sdr[0].ToString() + "\">EDIT</a> | <a href=\"default.aspx?pid=item&act=delete&id=" + sdr[0].ToString() + "\">DELETE</a></td>\n";
  1280.                         }
  1281.  
  1282.                         szPage += "   </tr>\n";
  1283.                     }
  1284.                 }
  1285.                 catch (Exception m)
  1286.                 {
  1287.                     szLastErrorMessage = m.Message;
  1288.                 }
  1289.                 finally
  1290.                 {
  1291.                     scConn.Close();
  1292.                 }
  1293.             }
  1294.             else
  1295.             {
  1296.                 Response.Redirect("default.aspx?pid=category");
  1297.             }
  1298.  
  1299.             szPage += "</table>\n";
  1300.  
  1301.  
  1302.             /**************************************************************
  1303.              * If the admin is authorized and a super admin, then we      *
  1304.              *    can allow them to have access to add a admin            *
  1305.              *    to the database.                                        *
  1306.              /*************************************************************/
  1307.  
  1308.             if (adAUTH == "1")
  1309.             {
  1310.                 szPage += "<br />\n<hr />\n<br />\n";
  1311.                 szPage += "\n<form id=\"frmAddItem\" method=\"post\">\n";
  1312.                 szPage += "   <input type=\"hidden\" id=\"op\" name=\"op\" value=\"item\">\n";
  1313.                 szPage += "   <input type=\"hidden\" id=\"act\" name=\"act\" value=\"add\">";
  1314.                 szPage += "<table style=\"text-align: center; margin-left: 10%; margin-right: 10%; width: 80%;\">\n";
  1315.                 szPage += "   <tr style=\"font-weight: bold; text-decoration: underline;\">\n";
  1316.                 szPage += "      <td class=\"dark\">\n";
  1317.                 szPage += "         <h1>ADD ITEM</h1>\n";
  1318.                 szPage += "         <br />\n";
  1319.                 szPage += "         <table style=\"margin: auto; width: 100 %;\">\n";
  1320.                 szPage += "            <tr>\n";
  1321.                 szPage += "               <td style=\"text-align: right; width: 40%;\">Item Name:&nbsp;</td>\n";
  1322.                 szPage += "               <td style=\"text-align: left; width: 60%;\"><input style=\"width: 300px;\" id=\"iName\" name=\"iName\" type=\"text\" /></td>\n";
  1323.                 szPage += "            </tr>\n";
  1324.                 szPage += "            <tr>\n";
  1325.                 szPage += "               <td style=\"text-align: right; width: 40%;\">Item Description:&nbsp;</td>\n";
  1326.                 szPage += "               <td style=\"text-align: left; width: 60%;\"><input style=\"width: 300px;\" id=\"iDesc\" name=\"iDesc\" type=\"text\" /></td>\n";
  1327.                 szPage += "            </tr>\n";
  1328.                 szPage += "            <tr>\n";
  1329.                 szPage += "               <td style=\"text-align: right; width: 40%;\">Item Price:&nbsp;</td>\n";
  1330.                 szPage += "               <td style=\"text-align: left; width: 60%;\"><input style=\"width: 300px;\" id=\"iPrice\" name=\"iPrice\" type=\"text\" /></td>\n";
  1331.                 szPage += "            </tr>\n";
  1332.  
  1333.  
  1334.                 SqlConnection scConn = new SqlConnection(szConnectionString);
  1335.                 SqlCommand scStatement = new SqlCommand("SELECT * from category", scConn);
  1336.  
  1337.                 try
  1338.                 {
  1339.                     scConn.Open();
  1340.  
  1341.                     SqlDataReader sdr = scStatement.ExecuteReader();
  1342.  
  1343.  
  1344.                     szPage += "   <tr>\n";
  1345.                     szPage += "      <td style=\"text-align: right; width: 40%;\">Select a Category:&nbsp;</td>\n";
  1346.                     szPage += "      <td style=\"text-align: left; width: 60%;\">\n";
  1347.                     szPage += "         <select id=\"cid\" name=\"cid\" style=\"width: 301px;\">\n";
  1348.                     while (sdr.Read())
  1349.                     {
  1350.                         szPage += "            <option value=\"" + sdr[1].ToString() + "\">" + sdr[1].ToString() + "</option>\n";
  1351.                     }
  1352.  
  1353.                     szPage += "      </td>\n   </tr>\n";
  1354.                 }
  1355.                 catch (Exception m)
  1356.                 {
  1357.                     szLastErrorMessage = m.Message;
  1358.                 }
  1359.                 finally
  1360.                 {
  1361.                     scConn.Close();
  1362.                 }
  1363.  
  1364.                 szPage += "            <tr>\n";
  1365.                 szPage += "               <td style=\"text-align: right; width: 40%;\">Item Length:&nbsp;</td>\n";
  1366.                 szPage += "               <td style=\"text-align: left; width: 60%;\"><input style=\"width: 300px;\" id=\"iLength\" name=\"iLength\" type=\"text\" /></td>\n";
  1367.                 szPage += "            </tr>\n";
  1368.                 szPage += "            <tr>\n";
  1369.                 szPage += "               <td style=\"text-align: right; width: 40%;\">Item Width:&nbsp;</td>\n";
  1370.                 szPage += "               <td style=\"text-align: left; width: 60%;\"><input style=\"width: 300px;\" id=\"iWidth\" name=\"iWidth\" type=\"text\" /></td>\n";
  1371.                 szPage += "            </tr>\n";
  1372.                 szPage += "            <tr>\n";
  1373.                 szPage += "               <td style=\"text-align: right; width: 40%;\">Item Weight:&nbsp;</td>\n";
  1374.                 szPage += "               <td style=\"text-align: left; width: 60%;\"><input style=\"width: 300px;\" id=\"iWeight\" name=\"iWeight\" type=\"text\" /></td>\n";
  1375.                 szPage += "            </tr>\n";
  1376.                 szPage += "            <tr>\n";
  1377.                 szPage += "               <td style=\"text-align: right; width: 40%;\">Item Shipping Information:&nbsp;</td>\n";
  1378.                 szPage += "               <td style=\"text-align: left; width: 60%;\"><input style=\"width: 300px;\" id=\"iShInfo\" name=\"iShInfo\" type=\"text\" /></td>\n";
  1379.                 szPage += "            </tr>\n";
  1380.                 szPage += "         <tr>\n";
  1381.                 szPage += "            <td style=\"text-align: right; width: 40%;\"></td>\n";
  1382.                 szPage += "            <td style=\"text-align: left; width: 60%;\"><div style=\"width: 301px; text-align: right;\"><input style=\"width: 100px;\" id=\"btnAddItem\" name=\"submit\" type=\"submit\" value=\"Add Item\" /></div></td>\n";
  1383.                 szPage += "         </tr>\n";
  1384.                 szPage += "      </table>\n";
  1385.                 szPage += "      </td>\n";
  1386.                 szPage += "   </tr>\n";
  1387.                 szPage += "</table></form>\n";
  1388.                 szPage += "<br />\n";
  1389.             }
  1390.  
  1391.             _content.InnerHtml = szPage;
  1392.         }
  1393.  
  1394.  
  1395.         /*****************************************************************************
  1396.          * All content is setup through the page load.
  1397.          *****************************************************************************/
  1398.         protected void Page_Load(object sender, EventArgs e)
  1399.         {
  1400.             /********************************
  1401.              * Check if cookies are enabled *
  1402.              /*******************************/
  1403.             if (!Request.Browser.Cookies)
  1404.             {
  1405.                 _content.InnerHtml = "Cookies are not enabled on your web browser, please enable cookies and then return to the admin page!";
  1406.                 return;
  1407.             }
  1408.            
  1409.  
  1410.  
  1411.             /************************************************************************************************************************
  1412.             /* We need to check for admin privs. If there is no login info, saved cookie, ect..... We need to display a login form. *
  1413.              ************************************************************************************************************************/
  1414.             int nIsAdmin = 0;
  1415.             if (Request.Cookies["nimda"] != null)
  1416.             {
  1417.                 if (Request.Cookies["nimda"]["auth"].ToString() == "1") { nIsAdmin = 1; }
  1418.                 if (nIsAdmin != 1)
  1419.                     return;
  1420.             }
  1421.  
  1422.  
  1423.             /*****************************************************************************
  1424.              * Check for a post message, if there is one then we need to handle options  *
  1425.              *    as we are working with admin privs. such as add, edit, delete.         *
  1426.              *****************************************************************************/
  1427.             if (!this.IsPostBack)
  1428.             {
  1429.                 /*  Check for admin authentication before displaying the admin page  */
  1430.                 if (nIsAdmin == 1)
  1431.                 {
  1432.                     // Determine what page we are looking at
  1433.                     if (Request.QueryString.Count != 0)
  1434.                     {
  1435.                         // Ensure we have a page identifier
  1436.                         if (Request.QueryString["pid"] != null)
  1437.                         {
  1438.                             // Handle the admin panel
  1439.                             if (Request.QueryString["pid"].ToLower() == "admin")
  1440.                             {
  1441.                                 if (Request.QueryString["act"] != null)
  1442.                                 {
  1443.                                     string szACT = Request.QueryString["act"].ToString().ToLower();
  1444.                                     if (szACT == "edit")
  1445.                                     {
  1446.                                         if (Request.QueryString["id"] != null)
  1447.                                         {
  1448.                                             if (int.TryParse(Request.QueryString["id"].ToString(), out int nIndex))
  1449.                                             {
  1450.                                                 string szUSER = _getAdminField(nIndex, 1);
  1451.                                                 //string szPASS = _getAdminField(nIndex, 2);
  1452.                                                 string szFNAME = _getAdminField(nIndex, 3);
  1453.                                                 string szLNAME = _getAdminField(nIndex, 4);
  1454.                                                 string szLVL = _getAdminField(nIndex, 5);
  1455.  
  1456.                                                 string szPage = "";
  1457.                                                 szPage += "\n<form id=\"frmEdit\" method=\"post\">\n";
  1458.                                                 szPage += "   <input type=\"hidden\" id=\"op\" name=\"op\" value=\"admin\">\n";
  1459.                                                 szPage += "   <input type=\"hidden\" id=\"act\" name=\"act\" value=\"edit\">\n";
  1460.                                                 szPage += "   <input type=\"hidden\" id=\"id\" name=\"id\" value=\"" + nIndex.ToString() + "\">\n";
  1461.                                                 szPage += "<table style=\"text-align: center; margin-left: 10%; margin-right: 10%; width: 80%;\">\n";
  1462.                                                 szPage += "   <tr style=\"font-weight: bold; text-decoration: underline;\">\n";
  1463.                                                 szPage += "      <td class=\"dark\">\n";
  1464.                                                 szPage += "         <h1>EDIT ADMIN</h1>\n";
  1465.                                                 szPage += "         <br />\n";
  1466.                                                 szPage += "         <table style=\"margin: auto; width: 100 %;\">\n";
  1467.                                                 szPage += "            <tr>\n";
  1468.                                                 szPage += "               <td style=\"text-align: right; width: 40%;\">Username:&nbsp;</td>\n";
  1469.                                                 szPage += "               <td style=\"text-align: left; width: 60%;\"><input style=\"width: 300px;\" id=\"adUSER\" name=\"adUSER\" type=\"text\" value=\"" + szUSER + "\" /></td>\n";
  1470.                                                 szPage += "            </tr>\n";
  1471.                                                 szPage += "            <tr>\n";
  1472.                                                 szPage += "               <td style=\"text-align: right; width: 40%;\">Password (No change in left blank):&nbsp;</td>\n";
  1473.                                                 szPage += "               <td style=\"text-align: left; width: 60%;\"><input style=\"width: 300px;\" id=\"adPASS\" name=\"adPASS\" type=\"text\" value=\"\" /></td>\n";
  1474.                                                 szPage += "            </tr>\n";
  1475.                                                 szPage += "            <tr>\n";
  1476.                                                 szPage += "               <td style=\"text-align: right; width: 40%;\">First Name:&nbsp;</td>\n";
  1477.                                                 szPage += "               <td style=\"text-align: left; width: 60%;\"><input style=\"width: 300px;\" id=\"adFNAME\" name=\"adFNAME\" type=\"text\" value=\"" + szFNAME + "\" /></td>\n";
  1478.                                                 szPage += "            </tr>\n";
  1479.                                                 szPage += "            <tr>\n";
  1480.                                                 szPage += "               <td style=\"text-align: right; width: 40%;\">Last Name:&nbsp;</td>\n";
  1481.                                                 szPage += "               <td style=\"text-align: left; width: 60%;\"><input style=\"width: 300px;\" id=\"adLNAME\" name=\"adLNAME\" type=\"text\" value=\"" + szLNAME + "\" /></td>\n";
  1482.                                                 szPage += "            </tr>\n";
  1483.                                                 szPage += "            <tr>\n";
  1484.                                                 szPage += "               <td style=\"text-align: right; width: 40%;\">[0, 1, or 2] Level:&nbsp;</td>\n";
  1485.                                                 szPage += "               <td style=\"text-align: left; width: 60%;\"><input style=\"width: 300px;\" id=\"adLVL\" name=\"adLVL\" type=\"text\" value=\"" + szLVL + "\" /></td>\n";
  1486.                                                 szPage += "            </tr>\n";
  1487.                                                 szPage += "            <tr>\n";
  1488.                                                 szPage += "               <td style=\"text-align: right; width: 40%;\">All changes are final once you click 'Edit Admin'!</td>\n";
  1489.                                                 szPage += "               <td style=\"text-align: left; width: 60%;\"><div style=\"width: 301px; text-align: right;\"><input style=\"width: 100px;\" id=\"btnEditAdmin\" name=\"submit\" type=\"submit\" value=\"Edit Admin\" /></div></td>\n";
  1490.                                                 szPage += "            </tr>\n";
  1491.                                                 szPage += "         </table>\n";
  1492.                                                 szPage += "      </td>\n";
  1493.                                                 szPage += "   </tr>\n";
  1494.                                                 szPage += "</table></form>\n";
  1495.  
  1496.                                                 _content.InnerHtml = szPage;
  1497.                                             }
  1498.                                             else
  1499.                                             {
  1500.                                                 Response.Redirect("default.aspx");
  1501.                                             }
  1502.                                         }
  1503.                                         else
  1504.                                         {
  1505.                                             Response.Redirect("default.aspx");
  1506.                                         }
  1507.                                     }
  1508.  
  1509.  
  1510.                                     else if (szACT == "delete")
  1511.                                     {
  1512.                                         if (Request.QueryString["id"] != null)
  1513.                                         {
  1514.                                             if (int.TryParse(Request.QueryString["id"].ToString(), out int nIndex))
  1515.                                             {
  1516.                                                 string szPage = "";
  1517.                                                 szPage += "\n<form id=\"frmDelete\" method=\"post\">\n";
  1518.                                                 szPage += "   <input type=\"hidden\" id=\"op\" name=\"op\" value=\"admin\">\n";
  1519.                                                 szPage += "   <input type=\"hidden\" id=\"act\" name=\"act\" value=\"delete\">\n";
  1520.                                                 szPage += "   <input type=\"hidden\" id=\"id\" name=\"id\" value=\"" + nIndex.ToString() + "\">\n";
  1521.                                                 szPage += "<table style=\"text-align: center; margin-left: 10%; margin-right: 10%; width: 80%;\">\n";
  1522.                                                 szPage += "   <tr style=\"font-weight: bold; text-decoration: none;\">\n";
  1523.                                                 szPage += "      <td class=\"dark\">\n";
  1524.                                                 szPage += "         <h1>DELETE ADMIN</h1>\n";
  1525.                                                 szPage += "         <br />\n";
  1526.                                                 szPage += "         <table style=\"margin: auto; width: 100 %;\">\n";
  1527.                                                 szPage += "            <tr>\n";
  1528.                                                 szPage += "               <td style=\"text-align: left; width: 60%;\">Are you sure you want to delete '" + _getAdminField(nIndex, 1) + "'?:&nbsp;&nbsp;<input style=\"width: 100px;\" id=\"btnDeleteAdmin\" name=\"submit\" type=\"submit\" value=\"Delete\" /></td>\n";
  1529.                                                 szPage += "            </tr>\n";
  1530.                                                 szPage += "         </table>\n";
  1531.                                                 szPage += "      </td>\n";
  1532.                                                 szPage += "   </tr>\n";
  1533.                                                 szPage += "</table></form>\n";
  1534.  
  1535.                                                 _content.InnerHtml = szPage;
  1536.                                             }
  1537.                                             else
  1538.                                             {
  1539.                                                 Response.Redirect("default.aspx");
  1540.                                             }
  1541.                                         }
  1542.                                         else
  1543.                                         {
  1544.                                             Response.Redirect("default.aspx");
  1545.                                         }
  1546.                                     }
  1547.                                 }
  1548.                                 else
  1549.                                 {
  1550.                                     // No identifier, display default page.
  1551.                                     _displayAdminPage();
  1552.                                 }
  1553.                             }
  1554.                             /*****************************************************************************
  1555.                              *****************************************************************************
  1556.                              *****************************************************************************/
  1557.                             else if (Request.QueryString["pid"].ToLower() == "brand")
  1558.                             {
  1559.                                 if (Request.QueryString["act"] != null)
  1560.                                 {
  1561.                                     string szACT = Request.QueryString["act"].ToString().ToLower();
  1562.                                     if (szACT == "edit")
  1563.                                     {
  1564.                                         if (Request.QueryString["id"] != null)
  1565.                                         {
  1566.                                             if (int.TryParse(Request.QueryString["id"].ToString(), out int nIndex))
  1567.                                             {
  1568.                                                 string szName = _getBrandField(nIndex, 1);
  1569.                                                 string szDesc = _getBrandField(nIndex, 2);
  1570.  
  1571.                                                 string szPage = "";
  1572.                                                 szPage += "\n<form id=\"frmEdit\" method=\"post\">\n";
  1573.                                                 szPage += "   <input type=\"hidden\" id=\"op\" name=\"op\" value=\"brand\">\n";
  1574.                                                 szPage += "   <input type=\"hidden\" id=\"act\" name=\"act\" value=\"edit\">\n";
  1575.                                                 szPage += "   <input type=\"hidden\" id=\"id\" name=\"id\" value=\"" + nIndex.ToString() + "\">\n";
  1576.                                                 szPage += "<table style=\"text-align: center; margin-left: 10%; margin-right: 10%; width: 80%;\">\n";
  1577.                                                 szPage += "   <tr style=\"font-weight: bold; text-decoration: underline;\">\n";
  1578.                                                 szPage += "      <td class=\"dark\">\n";
  1579.                                                 szPage += "         <h1>EDIT BRAND</h1>\n";
  1580.                                                 szPage += "         <br />\n";
  1581.                                                 szPage += "         <table style=\"margin: auto; width: 100 %;\">\n";
  1582.                                                 szPage += "            <tr>\n";
  1583.                                                 szPage += "               <td style=\"text-align: right; width: 40%;\">Brand Name:&nbsp;</td>\n";
  1584.                                                 szPage += "               <td style=\"text-align: left; width: 60%;\"><input style=\"width: 300px;\" id=\"brName\" name=\"brName\" type=\"text\" value=\"" + szName + "\" /></td>\n";
  1585.                                                 szPage += "            </tr>\n";
  1586.                                                 szPage += "            <tr>\n";
  1587.                                                 szPage += "               <td style=\"text-align: right; width: 40%;\">Brand Description:&nbsp;</td>\n";
  1588.                                                 szPage += "               <td style=\"text-align: left; width: 60%;\"><input style=\"width: 300px;\" id=\"brDesc\" name=\"brDesc\" type=\"text\" value=\"" + szDesc + "\" /></td>\n";
  1589.                                                 szPage += "            </tr>\n";
  1590.                                                 szPage += "            <tr>\n";
  1591.                                                 szPage += "               <td style=\"text-align: right; width: 40%;\">All changes are final once you click 'Edit Brand'!</td>\n";
  1592.                                                 szPage += "               <td style=\"text-align: left; width: 60%;\"><div style=\"width: 301px; text-align: right;\"><input style=\"width: 100px;\" id=\"btnEditBrand\" name=\"submit\" type=\"submit\" value=\"Edit Brand\" /></div></td>\n";
  1593.                                                 szPage += "            </tr>\n";
  1594.                                                 szPage += "         </table>\n";
  1595.                                                 szPage += "      </td>\n";
  1596.                                                 szPage += "   </tr>\n";
  1597.                                                 szPage += "</table></form>\n";
  1598.  
  1599.                                                 _content.InnerHtml = szPage;
  1600.                                             }
  1601.                                             else
  1602.                                             {
  1603.                                                 Response.Redirect("default.aspx?pid=brand");
  1604.                                             }
  1605.                                         }
  1606.                                         else
  1607.                                         {
  1608.                                             Response.Redirect("default.aspx?pid=brand");
  1609.                                         }
  1610.                                     }
  1611.  
  1612.  
  1613.                                     else if (szACT == "delete")
  1614.                                     {
  1615.                                         if (Request.QueryString["id"] != null)
  1616.                                         {
  1617.                                             if (int.TryParse(Request.QueryString["id"].ToString(), out int nIndex))
  1618.                                             {
  1619.                                                 string szPage = "";
  1620.                                                 szPage += "\n<form id=\"frmDelete\" method=\"post\">\n";
  1621.                                                 szPage += "   <input type=\"hidden\" id=\"op\" name=\"op\" value=\"brand\">\n";
  1622.                                                 szPage += "   <input type=\"hidden\" id=\"act\" name=\"act\" value=\"delete\">\n";
  1623.                                                 szPage += "   <input type=\"hidden\" id=\"id\" name=\"id\" value=\"" + nIndex.ToString() + "\">\n";
  1624.                                                 szPage += "<table style=\"text-align: center; margin-left: 10%; margin-right: 10%; width: 80%;\">\n";
  1625.                                                 szPage += "   <tr style=\"font-weight: bold; text-decoration: none;\">\n";
  1626.                                                 szPage += "      <td class=\"dark\">\n";
  1627.                                                 szPage += "         <h1>DELETE BRAND</h1>\n";
  1628.                                                 szPage += "         <br />\n";
  1629.                                                 szPage += "         <table style=\"margin: auto; width: 100 %;\">\n";
  1630.                                                 szPage += "            <tr>\n";
  1631.                                                 szPage += "               <td style=\"text-align: left; width: 60%;\">Are you sure you want to delete '" + _getBrandField(nIndex, 1) + "'?:&nbsp;&nbsp;<input style=\"width: 100px;\" id=\"btnDeleteBrand\" name=\"submit\" type=\"submit\" value=\"Delete\" /></td>\n";
  1632.                                                 szPage += "            </tr>\n";
  1633.                                                 szPage += "         </table>\n";
  1634.                                                 szPage += "      </td>\n";
  1635.                                                 szPage += "   </tr>\n";
  1636.                                                 szPage += "</table></form>\n";
  1637.  
  1638.                                                 _content.InnerHtml = szPage;
  1639.                                             }
  1640.                                             else
  1641.                                             {
  1642.                                                 Response.Redirect("default.aspx?pid=brand");
  1643.                                             }
  1644.                                         }
  1645.                                         else
  1646.                                         {
  1647.                                             Response.Redirect("default.aspx?pid=brand");
  1648.                                         }
  1649.                                     }
  1650.                                 }
  1651.                                 else
  1652.                                 {
  1653.                                     // No identifier, display default page.
  1654.                                     _displayBrandPage();
  1655.                                 }
  1656.                             }
  1657.                             /*****************************************************************************
  1658.                              *****************************************************************************
  1659.                              *****************************************************************************/
  1660.                             else if (Request.QueryString["pid"].ToLower() == "category")
  1661.                             {
  1662.                                 if (Request.QueryString["act"] != null)
  1663.                                 {
  1664.                                     string szACT = Request.QueryString["act"].ToString().ToLower();
  1665.                                     if (szACT == "edit")
  1666.                                     {
  1667.                                         if (Request.QueryString["id"] != null)
  1668.                                         {
  1669.                                             if (int.TryParse(Request.QueryString["id"].ToString(), out int nIndex))
  1670.                                             {
  1671.                                                 string szName = _getCategoryField(nIndex, 1);
  1672.                                                 string szBrandID = _getCategoryField(nIndex, 2);
  1673.  
  1674.                                                 string szPage = "";
  1675.                                                 szPage += "\n<form id=\"frmEdit\" method=\"post\">\n";
  1676.                                                 szPage += "   <input type=\"hidden\" id=\"op\" name=\"op\" value=\"category\">\n";
  1677.                                                 szPage += "   <input type=\"hidden\" id=\"act\" name=\"act\" value=\"edit\">\n";
  1678.                                                 szPage += "   <input type=\"hidden\" id=\"id\" name=\"id\" value=\"" + nIndex.ToString() + "\">\n";
  1679.                                                 szPage += "<table style=\"text-align: center; margin-left: 10%; margin-right: 10%; width: 80%;\">\n";
  1680.                                                 szPage += "   <tr style=\"font-weight: bold; text-decoration: underline;\">\n";
  1681.                                                 szPage += "      <td class=\"dark\">\n";
  1682.                                                 szPage += "         <h1>EDIT CATEGORY</h1>\n";
  1683.                                                 szPage += "         <br />\n";
  1684.                                                 szPage += "         <table style=\"margin: auto; width: 100 %;\">\n";
  1685.                                                 szPage += "            <tr>\n";
  1686.                                                 szPage += "               <td style=\"text-align: right; width: 40%;\">Category Name:&nbsp;</td>\n";
  1687.                                                 szPage += "               <td style=\"text-align: left; width: 60%;\"><input style=\"width: 300px;\" id=\"catName\" name=\"catName\" type=\"text\" value=\"" + szName + "\" /></td>\n";
  1688.                                                 szPage += "            </tr>\n";
  1689.  
  1690.  
  1691.  
  1692.                                                 SqlConnection scConn = new SqlConnection(szConnectionString);
  1693.                                                 SqlCommand scStatement = new SqlCommand("SELECT * from brand", scConn);
  1694.  
  1695.                                                 try
  1696.                                                 {
  1697.                                                     scConn.Open();
  1698.  
  1699.                                                     SqlDataReader sdr = scStatement.ExecuteReader();
  1700.  
  1701.  
  1702.                                                     szPage += "   <tr>\n";
  1703.                                                     szPage += "      <td style=\"text-align: right; width: 40%;\">Brand:&nbsp;</td>\n";
  1704.                                                     szPage += "      <td style=\"text-align: left; width: 60%;\">\n";
  1705.                                                     szPage += "         <select id=\"bid\" name=\"bid\">\n";
  1706.                                                     while (sdr.Read())
  1707.                                                     {
  1708.                                                         if (sdr[1].ToString() == _getBrandField(Convert.ToInt32(szBrandID), 1))
  1709.                                                         {
  1710.                                                             szPage += "            <option value=\"" + sdr[1].ToString() + "\" selected>" + sdr[1].ToString() + "</option>\n";
  1711.                                                         }
  1712.                                                         else
  1713.                                                         {
  1714.                                                             szPage += "            <option value=\"" + sdr[1].ToString() + "\">" + sdr[1].ToString() + "</option>\n";
  1715.                                                         }
  1716.                                                        
  1717.                                                     }
  1718.  
  1719.                                                     szPage += "      </td>\n   </tr>\n";
  1720.                                                 }
  1721.                                                 catch (Exception m)
  1722.                                                 {
  1723.                                                     szLastErrorMessage = m.Message;
  1724.                                                 }
  1725.                                                 finally
  1726.                                                 {
  1727.                                                     scConn.Close();
  1728.                                                 }
  1729.  
  1730.                                                 szPage += "            <tr>\n";
  1731.                                                 szPage += "               <td style=\"text-align: right; width: 40%;\">All changes are final once you click 'Edit Category'!</td>\n";
  1732.                                                 szPage += "               <td style=\"text-align: left; width: 60%;\"><div style=\"width: 301px; text-align: right;\"><input style=\"width: 100px;\" id=\"btnEditBrand\" name=\"submit\" type=\"submit\" value=\"Edit Brand\" /></div></td>\n";
  1733.                                                 szPage += "            </tr>\n";
  1734.                                                 szPage += "         </table>\n";
  1735.                                                 szPage += "      </td>\n";
  1736.                                                 szPage += "   </tr>\n";
  1737.                                                 szPage += "</table></form>\n";
  1738.  
  1739.                                                 _content.InnerHtml = szPage;
  1740.                                             }
  1741.                                             else
  1742.                                             {
  1743.                                                 Response.Redirect("default.aspx?pid=category");
  1744.                                             }
  1745.                                         }
  1746.                                         else
  1747.                                         {
  1748.                                             Response.Redirect("default.aspx?pid=category");
  1749.                                         }
  1750.                                     }
  1751.  
  1752.  
  1753.                                     else if (szACT == "delete")
  1754.                                     {
  1755.                                         if (Request.QueryString["id"] != null)
  1756.                                         {
  1757.                                             if (int.TryParse(Request.QueryString["id"].ToString(), out int nIndex))
  1758.                                             {
  1759.                                                 string szPage = "";
  1760.                                                 szPage += "\n<form id=\"frmDelete\" method=\"post\">\n";
  1761.                                                 szPage += "   <input type=\"hidden\" id=\"op\" name=\"op\" value=\"category\">\n";
  1762.                                                 szPage += "   <input type=\"hidden\" id=\"act\" name=\"act\" value=\"delete\">\n";
  1763.                                                 szPage += "   <input type=\"hidden\" id=\"id\" name=\"id\" value=\"" + nIndex.ToString() + "\">\n";
  1764.                                                 szPage += "<table style=\"text-align: center; margin-left: 10%; margin-right: 10%; width: 80%;\">\n";
  1765.                                                 szPage += "   <tr style=\"font-weight: bold; text-decoration: none;\">\n";
  1766.                                                 szPage += "      <td class=\"dark\">\n";
  1767.                                                 szPage += "         <h1>DELETE CATEGORY</h1>\n";
  1768.                                                 szPage += "         <br />\n";
  1769.                                                 szPage += "         <table style=\"margin: auto; width: 100 %;\">\n";
  1770.                                                 szPage += "            <tr>\n";
  1771.                                                 szPage += "               <td style=\"text-align: left; width: 60%;\">Are you sure you want to delete '" + _getCategoryField(nIndex, 1) + "'?:&nbsp;&nbsp;<input style=\"width: 100px;\" id=\"btnDeleteCategory\" name=\"submit\" type=\"submit\" value=\"Delete\" /></td>\n";
  1772.                                                 szPage += "            </tr>\n";
  1773.                                                 szPage += "         </table>\n";
  1774.                                                 szPage += "      </td>\n";
  1775.                                                 szPage += "   </tr>\n";
  1776.                                                 szPage += "</table></form>\n";
  1777.  
  1778.                                                 _content.InnerHtml = szPage;
  1779.                                             }
  1780.                                             else
  1781.                                             {
  1782.                                                 Response.Redirect("default.aspx?pid=category");
  1783.                                             }
  1784.                                         }
  1785.                                         else
  1786.                                         {
  1787.                                             Response.Redirect("default.aspx?pid=category");
  1788.                                         }
  1789.                                     }
  1790.                                 }
  1791.                                 else
  1792.                                 {
  1793.                                     // No identifier, display default page.
  1794.                                     _displayCategoryPage();
  1795.                                 }
  1796.                             }
  1797.                             /*****************************************************************************
  1798.                              *****************************************************************************
  1799.                              *****************************************************************************/
  1800.                             else if (Request.QueryString["pid"].ToLower() == "item")
  1801.                             {
  1802.                                 _displayItemPage();
  1803.                             }
  1804.                             /*****************************************************************************
  1805.                              *****************************************************************************
  1806.                              *****************************************************************************/
  1807.                             else if (Request.QueryString["pid"].ToLower() == "logout")
  1808.                             {
  1809.                                 HttpCookie hcAdmin = new HttpCookie("nimda");
  1810.                                 hcAdmin.Expires = DateTime.Now.AddDays(-1d);
  1811.  
  1812.                                 Page.Response.Cookies.Add(hcAdmin);
  1813.                                 Response.Redirect("default.aspx");
  1814.                             }
  1815.                             /*****************************************************************************
  1816.                              *****************************************************************************
  1817.                              *****************************************************************************/
  1818.                             else
  1819.                             {
  1820.                                 _displayAdminPage();
  1821.                             }
  1822.                         }
  1823.                     }
  1824.                     else
  1825.                     {
  1826.                         _displayAdminPage();
  1827.                     }
  1828.                    
  1829.                 }
  1830.                 else // Display login Form
  1831.                 {
  1832.                     string szPage = "";
  1833.  
  1834.                     szPage = "\n<form id=\"frmLogin\" method=\"post\">\n";
  1835.                     szPage += "   <input type=\"hidden\" id=\"op\" name=\"op\" value=\"login\">\n";
  1836.                     szPage += "   <table style=\"text-align: center; margin-left: 10%; margin-right: 10%; width: 80%;\">\n";
  1837.                     szPage += "      <tr style=\"font-weight: bold;\">\n";
  1838.                     szPage += "         <td class=\"dark\">\n";
  1839.                     szPage += "            <h1>Admin Login</h1>\n";
  1840.                     szPage += "            <br />\n";
  1841.                     szPage += "            <table style=\"margin: auto; width: 100%;\">\n";
  1842.                     szPage += "               <tr>\n";
  1843.                     szPage += "                  <td style=\"text-align: right; width: 50%;\">Username:&nbsp;</td>\n";
  1844.                     szPage += "                  <td style=\"text-align: left; width: 50%;\">\n";
  1845.                     szPage += "                     <input style=\"width: 300px;\" name=\"aduser\" id=\"aduser\" type=\"text\" />\n";
  1846.                     szPage += "                  </td>\n";
  1847.                     szPage += "               </tr>\n";
  1848.                     szPage += "               <tr>\n";
  1849.                     szPage += "                  <td style=\"text-align: right; width: 50%;\">Password:&nbsp;</td>\n";
  1850.                     szPage += "                  <td style=\"text-align: left; width: 50%;\">\n";
  1851.                     szPage += "                     <input style=\"width: 300px;\" name=\"adpass\" id=\"aduser\" type=\"text\" />\n";
  1852.                     szPage += "                  </td>\n";
  1853.                     szPage += "               </tr>\n";
  1854.                     szPage += "               <tr>\n";
  1855.                     szPage += "                  <td style=\"text-align: right; width: 50%;\">&nbsp;</td>\n";
  1856.                     szPage += "                  <td style=\"text-align: left; width: 50%;\">\n";
  1857.                     szPage += "                     <div style=\"width: 301px; text-align: right;\"><input style=\"width: 100px;\" id=\"btnLogin\" type=\"submit\" value=\"Login\" /></div></td>\n";
  1858.                     szPage += "               </tr>\n";
  1859.                     szPage += "            </table>\n";
  1860.                     szPage += "         </td>\n";
  1861.                     szPage += "      </tr>\n";
  1862.                     szPage += "   </table>\n";
  1863.                     szPage += "</form>\n";
  1864.  
  1865.                     _content.InnerHtml = szPage;
  1866.                 }
  1867.             }
  1868.             else
  1869.             {
  1870.                 /*****************************************************************************
  1871.                  * We have received a post back, we need to grab variables from the header.  *
  1872.                  *                                                                           *
  1873.                  *    (operation) op = admin, brand, category, item                          *
  1874.                  *    (action) act = add, remove, edit                                       *
  1875.                  *                                                                           *
  1876.                  *    Each operation has its own set of params that can be pulled from       *
  1877.                  *      the header to add, remove, edit things from each category.           *
  1878.                  /****************************************************************************/
  1879.                 if (Request.Form["op"] == null)
  1880.                 {
  1881.                     _content.InnerHtml = "<div style=\"text-align: center;\">A unknown error has occurred!<br /> <a href=\"default.aspx\">CLICK HERE</a> to return to the main page.</div>";
  1882.                     return;
  1883.                 }
  1884.  
  1885.                 // Grab the OPERATION PARAM
  1886.                 string szOP = Request.Form["op"].ToString();
  1887.                 szOP = szOP.ToLower();
  1888.                
  1889.                 // clear content
  1890.                 _content.InnerHtml = null;
  1891.  
  1892.                 // Reset error counter
  1893.                 int nErrFound = 0;
  1894.  
  1895.                 /*************************************************
  1896.                 /* Handle admin operations                       *
  1897.                  *************************************************/
  1898.                 if (szOP == "login")
  1899.                 {
  1900.                     /* Ensure the user entered some info */
  1901.                     if (!(Request.Form["aduser"].Length > 0)) { nErrFound = 1; }
  1902.                     if (!(Request.Form["adpass"].Length > 0)) { nErrFound = 1; }
  1903.  
  1904.                     if (nErrFound == 0)
  1905.                     {
  1906.                         /* Now, lets try to authenticate the user */
  1907.                         if (_authAdmin(Request.Form["aduser"], Request.Form["adpass"]) == 0)
  1908.                         {
  1909.                             // User/Pass = correct, so save to cooke and authenticate the user.
  1910.                             int nIndex = _getAdminIndex(Request.Form["aduser"]);
  1911.  
  1912.                             _writeCookie(Request.Form["aduser"], _getAdminField(nIndex, 5), 1);
  1913.  
  1914.                             // Reload the page so that we can display to their admin options
  1915.                             Response.Redirect("default.aspx");
  1916.                         }
  1917.                         else // nErrFound = 1; then we have an error.
  1918.                         {
  1919.                             // User/Pass = correct, so save to cooke and authenticate the user.
  1920.                             int nIndex = _getAdminIndex(Request.Form["aduser"].ToString());
  1921.                             _content.InnerHtml += "\n<div style =\"text-align: center;\">Invalid username or password!<br /><a href=\"default.aspx\" style=\"text-decoration: underline;\">Click here</a> to return to the login screen.</div>\n";
  1922.                         }
  1923.                     }
  1924.                     else
  1925.                     {
  1926.                         /*******************************************
  1927.                          * Error occurred, display it to the user! *
  1928.                          *******************************************/
  1929.                         _content.InnerHtml = "\n<div style =\"text-align: center;\">\n";
  1930.                         if (!(Request.Form["aduser"].Length > 0)) { _content.InnerHtml += "   Enter a valid username!<br />\n"; }
  1931.                         if (!(Request.Form["adpass"].Length > 0)) { _content.InnerHtml += "   Enter a valid password!<br />\n"; }
  1932.  
  1933.                         _content.InnerHtml += "\n   <br /><a href=\"default.aspx\" style=\"text-decoration: underline;\">Click here</a> to return to the login screen.\n";
  1934.                         _content.InnerHtml += "</div>";
  1935.                     }
  1936.                 }
  1937.  
  1938.                 if (szOP == "admin")
  1939.                 {
  1940.                     // Ensure that "act" exists
  1941.                     if (Request.Form["act"].Length > 0)
  1942.                     {
  1943.                         // Return "act" in lowercase
  1944.                         string szAct = Request.Form["act"].ToString().ToLower();
  1945.  
  1946.                         // Add a admin
  1947.                         if (szAct == "add")
  1948.                         {
  1949.                             nErrFound = 0;
  1950.  
  1951.                             // Make sure all values passed from the form
  1952.                             if (Request.Form["adUSER"] == null) { nErrFound = 1; }
  1953.                             if (Request.Form["adPASS"] == null) { nErrFound = 1; }
  1954.                             if (Request.Form["adCONF"] == null) { nErrFound = 1; }
  1955.                             if (Request.Form["adFNAME"] == null) { nErrFound = 1; }
  1956.                             if (Request.Form["adLNAME"] == null) { nErrFound = 1; }
  1957.                             if (Request.Form["adLVL"] == null) { nErrFound = 1; }
  1958.  
  1959.                             if (nErrFound == 1)
  1960.                             {
  1961.                                 Response.Redirect("default.aspx");
  1962.                             }
  1963.  
  1964.                             if (nErrFound == 0)
  1965.                             {
  1966.                                 string szUser = Request.Form["adUSER"];
  1967.                                 string szPass = Request.Form["adPASS"];
  1968.                                 string szConf = Request.Form["adCONF"];
  1969.                                 string szFName = Request.Form["adFNAME"];
  1970.                                 string szLName = Request.Form["adLNAME"];
  1971.                                 string szLVL = Request.Form["adLVL"];
  1972.  
  1973.                                 string szPage = "<div style=\"text-align: center;\">[ ERROR ]<hr style=\"width: 300px;\"/>\n";
  1974.                                 if (szUser.Length == 0)
  1975.                                 {
  1976.                                     nErrFound = 1;
  1977.                                     szPage += "<div style=\"color: #FF0000\">You need to enter a &#34;username!&#34;</div><br />\n";
  1978.                                 }
  1979.  
  1980.  
  1981.                                 if (szPass.Length == 0)
  1982.                                 {
  1983.                                     nErrFound = 1;
  1984.                                     szPage += "<div style=\"color: #FF0000\">You need to enter a &#34;password!&#34;</div><br />\n";
  1985.                                 }
  1986.  
  1987.                                 if (szConf.Length == 0)
  1988.                                 {
  1989.                                     nErrFound = 1;
  1990.                                     szPage += "<div style=\"color: #FF0000\">You need to confirm your &#34;password!&#34;</div><br />\n";
  1991.                                 }
  1992.  
  1993.                                 if (szPass.ToLower() != szConf.ToLower())
  1994.                                 {
  1995.                                     nErrFound = 1;
  1996.                                     szPage += "<div style=\"color: #FF0000\">Your &#34;password&#34; and &#34;password confirmation&#34; do not match!</div><br />\n";
  1997.                                 }
  1998.  
  1999.                                 if (szFName.Length == 0)
  2000.                                 {
  2001.                                     nErrFound = 1;
  2002.                                     szPage += "<div style=\"color: #FF0000\">You need to enter a &#34;first name!&#34;</div><br />\n";
  2003.                                 }
  2004.  
  2005.                                 if (szLName.Length == 0)
  2006.                                 {
  2007.                                     nErrFound = 1;
  2008.                                     szPage += "<div style=\"color: #FF0000\">You need to enter a &#34;last name!&#34;</div><br />\n";
  2009.                                 }
  2010.  
  2011.                                 Boolean blnRet = Int32.TryParse(szLVL, out int nLVL);
  2012.                                 if (blnRet == false)
  2013.                                 {
  2014.                                     nErrFound = 1;
  2015.                                     szPage += "<div style=\"color: #FF0000\">You need to enter a valid number, alphanumeric values are not allowed for &#34;level!&#34;</div><br />\n";
  2016.                                 }
  2017.  
  2018.                                 if (Enumerable.Range(0, 3).Contains(nLVL) == false)
  2019.                                 {
  2020.                                     nErrFound = 1;
  2021.                                     szPage += "<div style=\"color: #FF0000\">You need to enter a valid number between of (0, 1, or 2) for &#34;level!&#34;</div><br />\n";
  2022.                                 }
  2023.  
  2024.                                 //// CHECK IF ADMIN EXISTS ////
  2025.                                 if ((nErrFound == 0) && (_getAdminIndex(szUser) > -1))
  2026.                                 {
  2027.                                     nErrFound = 1;
  2028.                                     szPage += "<div style=\"color: #FF0000\">[[[ !!!ADMIN ALREADY EXISTS!!! ]]]</div><br />\n";
  2029.                                 }
  2030.  
  2031.                                 //////////////////////////
  2032.                                 if (nErrFound == 1)
  2033.                                 {
  2034.                                     _content.InnerHtml = szPage + "<hr style=\"width: 300px;\"/><a href=\"default.aspx\" style=\"text-decoration: underline;\">Click here</a> to go back.</div>";
  2035.                                 }
  2036.                                 else
  2037.                                 {
  2038.                                     // Add the admin, if a error occurs adding the admin then we let the end-user know an error has occurred.
  2039.                                     if (_addAdmin(szUser, szPass, szFName, szLName, szLVL) != -1)
  2040.                                     {
  2041.                                         Response.Redirect("default.aspx");
  2042.                                     }
  2043.                                     else
  2044.                                     {
  2045.                                         _content.InnerHtml = "<div style=\"text-align: center;\">[ ERROR ]<hr style=\"width: 300px;\"/>\n<div style=\"color: #FF0000\">Error creating the admin &#34;" + szUser + ".&#34;</div><br />\n";
  2046.                                     }
  2047.                                 }
  2048.                             }
  2049.                             else
  2050.                             {
  2051.                                 _content.InnerHtml = "<div style=\"text-align: center;\">An unknown error has occurred!<a href=\"default.aspx\" style=\"text-decoration: underline;\">Click here</a> to go back.</div>";
  2052.                             }
  2053.                         }
  2054.  
  2055.                         // Edit a admin
  2056.                         else if (szAct == "edit")
  2057.                         {
  2058.                             if (Request.Form["id"] != null)
  2059.                             {
  2060.                                 nErrFound = 0;
  2061.  
  2062.                                 // Make sure all values passed from the form
  2063.                                 if (Request.Form["adUSER"] == null) { nErrFound = 1; }
  2064.                                 if (Request.Form["adPASS"] == null) { nErrFound = 1; }
  2065.                                 if (Request.Form["adFNAME"] == null) { nErrFound = 1; }
  2066.                                 if (Request.Form["adLNAME"] == null) { nErrFound = 1; }
  2067.                                 if (Request.Form["adLVL"] == null) { nErrFound = 1; }
  2068.  
  2069.                                 if (nErrFound == 1)
  2070.                                 {
  2071.                                     _content.InnerHtml = Request.Form.ToString();
  2072.                                     return;
  2073.                                 }
  2074.  
  2075.                                 if (nErrFound == 0)
  2076.                                 {
  2077.                                     string szPass = "";
  2078.                                     if (Request.Form["adPass"] != null) { szPass = Request.Form["adPass"]; }
  2079.  
  2080.                                     string szUser = Request.Form["adUser"];
  2081.                                     string szLName = Request.Form["adFName"];
  2082.                                     string szFName = Request.Form["adLName"];
  2083.                                     string szLVL = Request.Form["adLVL"];
  2084.  
  2085.                                     string szPage = "<div style=\"text-align: center;\">[ ERROR ]<hr style=\"width: 300px;\"/>\n";
  2086.                                     if (szUser.Length == 0)
  2087.                                     {
  2088.                                         nErrFound = 1;
  2089.                                         szPage += "<div style=\"color: #FF0000\">You need to enter a &#34;username!&#34;</div><br />\n";
  2090.                                     }
  2091.  
  2092.  
  2093.                                     if (szPass.Length == 0)
  2094.                                     {
  2095.                                         nErrFound = 1;
  2096.                                         szPage += "<div style=\"color: #FF0000\">You need to enter a &#34;password!&#34;</div><br />\n";
  2097.                                     }
  2098.  
  2099.                                     if (szFName.Length == 0)
  2100.                                     {
  2101.                                         nErrFound = 1;
  2102.                                         szPage += "<div style=\"color: #FF0000\">You need to enter a &#34;first name!&#34;</div><br />\n";
  2103.                                     }
  2104.  
  2105.                                     if (szLName.Length == 0)
  2106.                                     {
  2107.                                         nErrFound = 1;
  2108.                                         szPage += "<div style=\"color: #FF0000\">You need to enter a &#34;last name!&#34;</div><br />\n";
  2109.                                     }
  2110.  
  2111.                                     Boolean blnRet = Int32.TryParse(szLVL, out int nLVL);
  2112.                                     if (blnRet == false)
  2113.                                     {
  2114.                                         nErrFound = 1;
  2115.                                         szPage += "<div style=\"color: #FF0000\">You need to enter a valid number, alphanumeric values are not allowed for &#34;level!&#34;</div><br />\n";
  2116.                                     }
  2117.  
  2118.                                     if (Enumerable.Range(0, 3).Contains(nLVL) == false)
  2119.                                     {
  2120.                                         nErrFound = 1;
  2121.                                         szPage += "<div style=\"color: #FF0000\">You need to enter a valid number between of (0, 1, or 2) for &#34;level!&#34;</div><br />\n";
  2122.                                     }
  2123.  
  2124.                                     //////////////////////////
  2125.                                     if (nErrFound == 1)
  2126.                                     {
  2127.                                         _content.InnerHtml = szPage + "<hr style=\"width: 300px;\"/><a href=\"default.aspx?pid=admin&act=edit&id=" + Request.QueryString["id"] + "\" style=\"text-decoration: underline;\">Click here</a> to go back.</div>";
  2128.                                     }
  2129.  
  2130.  
  2131.                                     if (int.TryParse(Request.Form["id"].ToString(), out int nIndex))
  2132.                                     {
  2133.                                         // Grab the password and check if it's blank or had data
  2134.                                         string szPWD = szPass;
  2135.                                         if (szPWD.Length > 0) // It has data so it's a new password that needs encrypted
  2136.                                         {
  2137.                                             szPWD = _encryptPWD(szPWD);
  2138.                                         }
  2139.                                         else
  2140.                                         {
  2141.                                             // It doesn't have data so grab the old password to re-enter into the database
  2142.                                             szPWD = _getAdminField(nIndex, 2);
  2143.                                         }
  2144.  
  2145.                                         // edit the admin table
  2146.                                         if (_editAdmin(nIndex, Request.Form["adUser"].ToString(), szPWD, Request.Form["adFName"].ToString(), Request.Form["adLName"].ToString(), Request.Form["adLVL"].ToString()) == 0)
  2147.                                         {
  2148.                                             Response.Redirect("default.aspx");
  2149.                                         }
  2150.                                         else
  2151.                                         {
  2152.                                             _content.InnerHtml = "<div style=\"text-align: center;\">Error: " + szLastErrorMessage + "<a href=\"default.aspx?pid=admin&act=edit&id=" + nIndex.ToString() + "\" style=\"text-decoration: underline;\">Click here</a> to go back.</div>";
  2153.                                         }
  2154.                                     }
  2155.                                     else
  2156.                                     {
  2157.                                         _content.InnerHtml = "<div style=\"text-align: center;\">An unknown error has occurred!<a href=\"default.aspx?pid=admin&act=edit&id=" + nIndex.ToString() + "\" style=\"text-decoration: underline;\">Click here</a> to go back.</div>";
  2158.                                     }
  2159.  
  2160.                                 }
  2161.                                 else
  2162.                                 {
  2163.                                     Response.Redirect("default.aspx");
  2164.                                 }
  2165.                             }
  2166.                         }
  2167.  
  2168.                         // Remove a admin
  2169.                         else if (szAct == "delete")
  2170.                         {
  2171.                             if (Request.Form["id"] != null)
  2172.                             {
  2173.                                 if (int.TryParse(Request.Form["id"].ToString(), out int nIndex))
  2174.                                 {
  2175.                                     // delete admin from the table
  2176.                                     if (_deleteAdmin(nIndex) == 0)
  2177.                                     {
  2178.                                         Response.Redirect("default.aspx");
  2179.                                     }
  2180.                                     else
  2181.                                     {
  2182.                                         _content.InnerHtml = "<div style=\"text-align: center;\">Error: " + szLastErrorMessage + "<a href=\"default.aspx?pid=admin&act=delete&id=" + nIndex.ToString() + "\" style=\"text-decoration: underline;\">Click here</a> to go back.</div>";
  2183.                                     }
  2184.                                 }
  2185.                                 else
  2186.                                 {
  2187.                                     _content.InnerHtml = "<div style=\"text-align: center;\">An unknown error has occurred!<a href=\"default.aspx?pid=admin&act=delete&id=" + nIndex.ToString() + "\" style=\"text-decoration: underline;\">Click here</a> to go back.</div>";
  2188.                                 }
  2189.                             }
  2190.                             else
  2191.                             {
  2192.                                 Response.Redirect("default.aspx");
  2193.                             }
  2194.                         }
  2195.                         else
  2196.                         {
  2197.                             Response.Redirect("default.aspx");
  2198.                         }
  2199.                     }
  2200.                 }
  2201.  
  2202.                 if (szOP == "brand")
  2203.                 {
  2204.                     // Ensure that "act" exists
  2205.                     if (Request.Form["act"].Length > 0)
  2206.                     {
  2207.                         // Return "act" in lowercase
  2208.                         string szAct = Request.Form["act"].ToString().ToLower();
  2209.  
  2210.                         // Add a admin
  2211.                         if (szAct == "add")
  2212.                         {
  2213.                             nErrFound = 0;
  2214.  
  2215.                             // Make sure all values passed from the form
  2216.                             if (Request.Form["brName"] == null) { nErrFound = 1; }
  2217.                             if (Request.Form["brDesc"] == null) { nErrFound = 1; }
  2218.  
  2219.                             if (nErrFound == 1)
  2220.                             {
  2221.                                 Response.Redirect("default.aspx?pid=brand");
  2222.                             }
  2223.  
  2224.                             if (nErrFound == 0)
  2225.                             {
  2226.                                 string szName = Request.Form["brName"];
  2227.                                 string szDesc = Request.Form["brDesc"];
  2228.  
  2229.                                 string szPage = "<div style=\"text-align: center;\">[ ERROR ]<hr style=\"width: 300px;\"/>\n";
  2230.                                 if (szName.Length == 0)
  2231.                                 {
  2232.                                     nErrFound = 1;
  2233.                                     szPage += "<div style=\"color: #FF0000\">You need to enter a &#34;brand name!&#34;</div><br />\n";
  2234.                                 }
  2235.  
  2236.  
  2237.                                 if (szDesc.Length == 0)
  2238.                                 {
  2239.                                     nErrFound = 1;
  2240.                                     szPage += "<div style=\"color: #FF0000\">You need to enter a &#34;brand description!&#34;</div><br />\n";
  2241.                                 }
  2242.  
  2243.                                 if (_getBrandIndex(szName) != -1)
  2244.                                 {
  2245.                                     nErrFound = 1;
  2246.                                     szPage += "<div style=\"color: #FF0000\">The &#34;brand name&#34; you entered already exists!</div><br />\n";
  2247.                                 }
  2248.                            
  2249.  
  2250.                                 //////////////////////////
  2251.                                 if (nErrFound == 1)
  2252.                                 {
  2253.                                     _content.InnerHtml = szPage + "<hr style=\"width: 300px;\"/><a href=\"default.aspx?pid=brand\" style=\"text-decoration: underline;\">Click here</a> to go back.</div>";
  2254.                                 }
  2255.                                 else
  2256.                                 {
  2257.                                     // Add the admin, if a error occurs adding the admin then we let the end-user know an error has occurred.
  2258.                                     if (_addBrand(szName, szDesc) != -1)
  2259.                                     {
  2260.                                         Response.Redirect("default.aspx?pid=brand");
  2261.                                     }
  2262.                                     else
  2263.                                     {
  2264.                                         _content.InnerHtml = "<div style=\"text-align: center;\">[ ERROR: " + szLastErrorMessage + " ]<hr style=\"width: 300px;\"/>\n<div style=\"color: #FF0000\">Error creating the brand name &#34;" + szName + ".&#34;<br /><a href=\"default.aspx?pid=brand\" style=\"text-decoration: underline;\">Click here</a> to go back.</div><br />\n";
  2265.                                     }
  2266.                                 }
  2267.                             }
  2268.                             else
  2269.                             {
  2270.                                 _content.InnerHtml = "<div style=\"text-align: center;\">An unknown error has occurred!<a href=\"default.aspx?pid=brand\" style=\"text-decoration: underline;\">Click here</a> to go back.</div>";
  2271.                             }
  2272.                         }
  2273.  
  2274.  
  2275.                         // Edit a admin
  2276.                         else if (szAct == "edit")
  2277.                         {
  2278.                             if (Request.Form["id"] != null)
  2279.                             {
  2280.                                 nErrFound = 0;
  2281.  
  2282.                                 // Make sure all values passed from the form
  2283.                                 if (Request.Form["brName"] == null) { nErrFound = 1; }
  2284.                                 if (Request.Form["brDesc"] == null) { nErrFound = 1; }
  2285.  
  2286.                                 if (nErrFound == 1)
  2287.                                 {
  2288.                                     _content.InnerHtml = Request.Form.ToString();
  2289.                                     return;
  2290.                                 }
  2291.  
  2292.                                 if (nErrFound == 0)
  2293.                                 {
  2294.                                     string szName = Request.Form["brName"];
  2295.                                     string szDesc = Request.Form["brDesc"];
  2296.  
  2297.  
  2298.                                     string szPage = "<div style=\"text-align: center;\">[ ERROR ]<hr style=\"width: 300px;\"/>\n";
  2299.                                     if (szName.Length == 0)
  2300.                                     {
  2301.                                         nErrFound = 1;
  2302.                                         szPage += "<div style=\"color: #FF0000\">You need to enter a &#34;brand name!&#34;</div><br />\n";
  2303.                                     }
  2304.  
  2305.                                     //////////////////////////
  2306.                                     if (nErrFound == 1)
  2307.                                     {
  2308.                                         _content.InnerHtml = szPage + "<hr style=\"width: 300px;\"/><a href=\"default.aspx?pid=brand&act=edit&id=" + Request.QueryString["id"] + "\" style=\"text-decoration: underline;\">Click here</a> to go back.</div>";
  2309.                                     }
  2310.  
  2311.  
  2312.                                     if (int.TryParse(Request.Form["id"].ToString(), out int nIndex))
  2313.                                     {
  2314.  
  2315.                                         // edit the brand table
  2316.                                         if (_editBrand(nIndex, szName, szDesc) == 0)
  2317.                                         {
  2318.                                             Response.Redirect("default.aspx?pid=brand");
  2319.                                         }
  2320.                                         else
  2321.                                         {
  2322.                                             _content.InnerHtml = "<div style=\"text-align: center;\">Error: " + szLastErrorMessage + "<a href=\"default.aspx?pid=brand&act=edit&id=" + nIndex.ToString() + "\" style=\"text-decoration: underline;\">Click here</a> to go back.</div>";
  2323.                                         }
  2324.                                     }
  2325.                                     else
  2326.                                     {
  2327.                                         _content.InnerHtml = "<div style=\"text-align: center;\">An unknown error has occurred!<a href=\"default.aspx?pid=brand&act=edit&id=" + nIndex.ToString() + "\" style=\"text-decoration: underline;\">Click here</a> to go back.</div>";
  2328.                                     }
  2329.  
  2330.                                 }
  2331.                                 else
  2332.                                 {
  2333.                                     Response.Redirect("default.aspx?pid=brand");
  2334.                                 }
  2335.                             }
  2336.                         }
  2337.  
  2338.  
  2339.                         // Remove a admin
  2340.                         else if (szAct == "delete")
  2341.                         {
  2342.                             if (Request.Form["id"] != null)
  2343.                             {
  2344.                                 if (int.TryParse(Request.Form["id"].ToString(), out int nIndex))
  2345.                                 {
  2346.                                     // delete admin from the table
  2347.                                     if (_deleteBrand(nIndex) == 0)
  2348.                                     {
  2349.                                         Response.Redirect("default.aspx?pid=brand");
  2350.                                     }
  2351.                                     else
  2352.                                     {
  2353.                                         _content.InnerHtml = "<div style=\"text-align: center;\">Error: " + szLastErrorMessage + "<a href=\"default.aspx?pid=brand&act=delete&id=" + nIndex.ToString() + "\" style=\"text-decoration: underline;\">Click here</a> to go back.</div>";
  2354.                                     }
  2355.                                 }
  2356.                                 else
  2357.                                 {
  2358.                                     _content.InnerHtml = "<div style=\"text-align: center;\">An unknown error has occurred!<a href=\"default.aspx?pid=brand&act=delete&id=" + nIndex.ToString() + "\" style=\"text-decoration: underline;\">Click here</a> to go back.</div>";
  2359.                                 }
  2360.                             }
  2361.                             else
  2362.                             {
  2363.                                 Response.Redirect("default.aspx?pid=brand");
  2364.                             }
  2365.                         }
  2366.                         else
  2367.                         {
  2368.                             Response.Redirect("default.aspx?pid=brand");
  2369.                         }
  2370.                     }
  2371.                 }
  2372.  
  2373.                 if (szOP == "category")
  2374.                 {
  2375.                     // Ensure that "act" exists
  2376.                     if (Request.Form["act"].Length > 0)
  2377.                     {
  2378.                         // Return "act" in lowercase
  2379.                         string szAct = Request.Form["act"].ToString().ToLower();
  2380.  
  2381.                         // Add a admin
  2382.                         if (szAct == "add")
  2383.                         {
  2384.                             // catName, bid
  2385.  
  2386.                             nErrFound = 0;
  2387.  
  2388.                             // Make sure all values passed from the form
  2389.                             if (Request.Form["catName"] == null) { nErrFound = 1; }
  2390.                             if (Request.Form["bid"] == null) { nErrFound = 1; }
  2391.  
  2392.                             if (nErrFound == 1)
  2393.                             {
  2394.                                 Response.Redirect("default.aspx?pid=category");
  2395.                             }
  2396.  
  2397.                             if (nErrFound == 0)
  2398.                             {
  2399.                                 string szName = Request.Form["catName"];
  2400.                                 string szBrandID = Request.Form["bid"];
  2401.  
  2402.                                 string szPage = "<div style=\"text-align: center;\">[ ERROR ]<hr style=\"width: 300px;\"/>\n";
  2403.                                 if (szName.Length == 0)
  2404.                                 {
  2405.                                     nErrFound = 1;
  2406.                                     szPage += "<div style=\"color: #FF0000\">You need to enter a &#34;category name!&#34;</div><br />\n";
  2407.                                 }
  2408.  
  2409.                                 if (szBrandID.Length == 0)
  2410.                                 {
  2411.                                     nErrFound = 1;
  2412.                                     szPage += "<div style=\"color: #FF0000\">You need to enter a &#34;brand name!&#34;</div><br />\n";
  2413.                                 }
  2414.  
  2415.                                 if (_getCategoryIndex(szName, _getBrandIndex(szBrandID)) != -1)
  2416.                                 {
  2417.                                     nErrFound = 1;
  2418.                                     szPage += "<div style=\"color: #FF0000\">The &#34;category name&#34; you entered already exists!</div><br />\n";
  2419.                                 }
  2420.  
  2421.  
  2422.                                 //////////////////////////
  2423.                                 if (nErrFound == 1)
  2424.                                 {
  2425.                                     _content.InnerHtml = szPage + "<hr style=\"width: 300px;\"/><a href=\"default.aspx?pid=category\" style=\"text-decoration: underline;\">Click here</a> to go back.</div>";
  2426.                                 }
  2427.                                 else
  2428.                                 {
  2429.                                     // Add the admin, if a error occurs adding the admin then we let the end-user know an error has occurred.
  2430.                                     if (_addCategory(szName, _getBrandIndex(szBrandID)) != -1)
  2431.                                     {
  2432.                                         Response.Redirect("default.aspx?pid=category");
  2433.                                     }
  2434.                                     else
  2435.                                     {
  2436.                                         _content.InnerHtml = "<div style=\"text-align: center;\">[ ERROR: " + szLastErrorMessage + " ]<hr style=\"width: 300px;\"/>\n<div style=\"color: #FF0000\">Error creating the category name &#34;" + szName + ".&#34;<br /><a href=\"default.aspx?pid=category\" style=\"text-decoration: underline;\">Click here</a> to go back.</div><br />\n";
  2437.                                     }
  2438.                                 }
  2439.                             }
  2440.                             else
  2441.                             {
  2442.                                 _content.InnerHtml = "<div style=\"text-align: center;\">An unknown error has occurred!<a href=\"default.aspx?pid=category\" style=\"text-decoration: underline;\">Click here</a> to go back.</div>";
  2443.                             }
  2444.                         }
  2445.  
  2446.  
  2447.                         // Edit a admin
  2448.                         else if (szAct == "edit")
  2449.                         {
  2450.                             if (Request.Form["id"] != null)
  2451.                             {
  2452.                                 nErrFound = 0;
  2453.  
  2454.                                 // Make sure all values passed from the form
  2455.                                 if (Request.Form["catName"] == null) { nErrFound = 1; }
  2456.                                 if (Request.Form["bid"] == null) { nErrFound = 1; }
  2457.  
  2458.                                 if (nErrFound == 1)
  2459.                                 {
  2460.                                     _content.InnerHtml = Request.Form.ToString() + "<hr>" + szLastErrorMessage;
  2461.                                     return;
  2462.                                 }
  2463.  
  2464.                                 if (nErrFound == 0)
  2465.                                 {
  2466.                                     string szName = Request.Form["catName"];
  2467.                                     string szBrandID = Request.Form["bid"];
  2468.  
  2469.  
  2470.                                     string szPage = "<div style=\"text-align: center;\">[ ERROR ]<hr style=\"width: 300px;\"/>\n";
  2471.                                     if (szName.Length == 0)
  2472.                                     {
  2473.                                         nErrFound = 1;
  2474.                                         szPage += "<div style=\"color: #FF0000\">You need to enter a &#34;category name!&#34;</div><br />\n";
  2475.                                     }
  2476.  
  2477.                                     //////////////////////////
  2478.                                     if (nErrFound == 1)
  2479.                                     {
  2480.                                         _content.InnerHtml = szPage + "<hr style=\"width: 300px;\"/><a href=\"default.aspx?pid=category&act=edit&id=" + Request.QueryString["id"] + "\" style=\"text-decoration: underline;\">Click here</a> to go back.</div>";
  2481.                                     }
  2482.  
  2483.  
  2484.                                     if (int.TryParse(Request.Form["id"].ToString(), out int nIndex))
  2485.                                     {
  2486.  
  2487.                                         // edit the brand table
  2488.                                         if (_editCategory(nIndex, szName, _getBrandIndex(szBrandID)) == 0)
  2489.                                         {
  2490.                                             Response.Redirect("default.aspx?pid=category");
  2491.                                         }
  2492.                                         else
  2493.                                         {
  2494.                                             _content.InnerHtml = "<div style=\"text-align: center;\">Error: " + szLastErrorMessage + "<a href=\"default.aspx?pid=category&act=edit&id=" + nIndex.ToString() + "\" style=\"text-decoration: underline;\">Click here</a> to go back.</div>";
  2495.                                         }
  2496.                                     }
  2497.                                     else
  2498.                                     {
  2499.                                         _content.InnerHtml = "<div style=\"text-align: center;\">An unknown error has occurred!<a href=\"default.aspx?pid=category&act=edit&id=" + nIndex.ToString() + "\" style=\"text-decoration: underline;\">Click here</a> to go back.</div>";
  2500.                                     }
  2501.  
  2502.                                 }
  2503.                                 else
  2504.                                 {
  2505.                                     Response.Redirect("default.aspx?pid=category");
  2506.                                 }
  2507.                             }
  2508.                         }
  2509.  
  2510.  
  2511.                         // Remove a admin
  2512.                         else if (szAct == "delete")
  2513.                         {
  2514.                             if (Request.Form["id"] != null)
  2515.                             {
  2516.                                 if (int.TryParse(Request.Form["id"].ToString(), out int nIndex))
  2517.                                 {
  2518.                                     // delete admin from the table
  2519.                                     if (_deleteCategory(nIndex) == 0)
  2520.                                     {
  2521.                                         Response.Redirect("default.aspx?pid=category");
  2522.                                     }
  2523.                                     else
  2524.                                     {
  2525.                                         _content.InnerHtml = "<div style=\"text-align: center;\">Error: " + szLastErrorMessage + "<a href=\"default.aspx?pid=category&act=delete&id=" + nIndex.ToString() + "\" style=\"text-decoration: underline;\">Click here</a> to go back.</div>";
  2526.                                     }
  2527.                                 }
  2528.                                 else
  2529.                                 {
  2530.                                     _content.InnerHtml = "<div style=\"text-align: center;\">An unknown error has occurred!<a href=\"default.aspx?pid=category&act=delete&id=" + nIndex.ToString() + "\" style=\"text-decoration: underline;\">Click here</a> to go back.</div>";
  2531.                                 }
  2532.                             }
  2533.                             else
  2534.                             {
  2535.                                 Response.Redirect("default.aspx?pid=category");
  2536.                             }
  2537.                         }
  2538.                         else
  2539.                         {
  2540.                             Response.Redirect("default.aspx?pid=category");
  2541.                         }
  2542.                     }
  2543.                 }
  2544.  
  2545.                 if (szOP == "item")
  2546.                 {
  2547.                     // Ensure that "act" exists
  2548.                     if (Request.Form["act"].Length > 0)
  2549.                     {
  2550.                         // Return "act" in lowercase
  2551.                         string szAct = Request.Form["act"].ToString().ToLower();
  2552.  
  2553.                         // Add a admin
  2554.                         if (szAct == "add")
  2555.                         {
  2556.                             _content.InnerHtml = Request.Form.ToString().Substring(Request.Form.ToString().IndexOf("&op="));
  2557.                             // catName, bid
  2558.                             /*
  2559.                             nErrFound = 0;
  2560.  
  2561.                             // Make sure all values passed from the form
  2562.                             if (Request.Form["catName"] == null) { nErrFound = 1; }
  2563.                             if (Request.Form["bid"] == null) { nErrFound = 1; }
  2564.  
  2565.                             if (nErrFound == 1)
  2566.                             {
  2567.                                 Response.Redirect("default.aspx?pid=item");
  2568.                             }
  2569.  
  2570.                             if (nErrFound == 0)
  2571.                             {
  2572.                                 string szName = Request.Form["catName"];
  2573.                                 string szBrandID = Request.Form["bid"];
  2574.  
  2575.                                 string szPage = "<div style=\"text-align: center;\">[ ERROR ]<hr style=\"width: 300px;\"/>\n";
  2576.                                 if (szName.Length == 0)
  2577.                                 {
  2578.                                     nErrFound = 1;
  2579.                                     szPage += "<div style=\"color: #FF0000\">You need to enter a &#34;item name!&#34;</div><br />\n";
  2580.                                 }
  2581.  
  2582.  
  2583.  
  2584.                                 if (_getCategoryIndex(szName, _getBrandIndex(szBrandID)) != -1)
  2585.                                 {
  2586.                                     nErrFound = 1;
  2587.                                     szPage += "<div style=\"color: #FF0000\">The &#34;category name&#34; you entered already exists!</div><br />\n";
  2588.                                 }
  2589.  
  2590.  
  2591.                                 //////////////////////////
  2592.                                 if (nErrFound == 1)
  2593.                                 {
  2594.                                     _content.InnerHtml = szPage + "<hr style=\"width: 300px;\"/><a href=\"default.aspx?pid=item\" style=\"text-decoration: underline;\">Click here</a> to go back.</div>";
  2595.                                 }
  2596.                                 else
  2597.                                 {
  2598.                                     // Add the admin, if a error occurs adding the admin then we let the end-user know an error has occurred.
  2599.                                     //if (_addCategory(szName, _getBrandIndex(szBrandID)) != -1)
  2600.                                     //{
  2601.                                     //    Response.Redirect("default.aspx?pid=item");
  2602.                                     //}
  2603.                                     //else
  2604.                                     //{
  2605.                                     //    _content.InnerHtml = "<div style=\"text-align: center;\">[ ERROR: " + szLastErrorMessage + " ]<hr style=\"width: 300px;\"/>\n<div style=\"color: #FF0000\">Error creating the item name &#34;" + szName + ".&#34;<br /><a href=\"default.aspx?pid=item\" style=\"text-decoration: underline;\">Click here</a> to go back.</div><br />\n";
  2606.                                     //}
  2607.                                 }
  2608.                             }
  2609.                             else
  2610.                             {
  2611.                                 _content.InnerHtml = "<div style=\"text-align: center;\">An unknown error has occurred!<a href=\"default.aspx?pid=item\" style=\"text-decoration: underline;\">Click here</a> to go back.</div>";
  2612.                             }*/
  2613.                         }
  2614.  
  2615.  
  2616.                         // Edit a admin
  2617.                         else if (szAct == "edit")
  2618.                         {
  2619.                             if (Request.Form["id"] != null)
  2620.                             {
  2621.                                 nErrFound = 0;
  2622.  
  2623.                                 // Make sure all values passed from the form
  2624.                                 if (Request.Form["catName"] == null) { nErrFound = 1; }
  2625.                                 if (Request.Form["bid"] == null) { nErrFound = 1; }
  2626.  
  2627.                                 if (nErrFound == 1)
  2628.                                 {
  2629.                                     _content.InnerHtml = Request.Form.ToString() + "<hr>" + szLastErrorMessage;
  2630.                                     return;
  2631.                                 }
  2632.  
  2633.                                 if (nErrFound == 0)
  2634.                                 {
  2635.                                     string szName = Request.Form["catName"];
  2636.                                     string szBrandID = Request.Form["bid"];
  2637.  
  2638.  
  2639.                                     string szPage = "<div style=\"text-align: center;\">[ ERROR ]<hr style=\"width: 300px;\"/>\n";
  2640.                                     if (szName.Length == 0)
  2641.                                     {
  2642.                                         nErrFound = 1;
  2643.                                         szPage += "<div style=\"color: #FF0000\">You need to enter a &#34;category name!&#34;</div><br />\n";
  2644.                                     }
  2645.  
  2646.                                     //////////////////////////
  2647.                                     if (nErrFound == 1)
  2648.                                     {
  2649.                                         _content.InnerHtml = szPage + "<hr style=\"width: 300px;\"/><a href=\"default.aspx?pid=item&act=edit&id=" + Request.QueryString["id"] + "\" style=\"text-decoration: underline;\">Click here</a> to go back.</div>";
  2650.                                     }
  2651.  
  2652.  
  2653.                                     if (int.TryParse(Request.Form["id"].ToString(), out int nIndex))
  2654.                                     {
  2655.  
  2656.                                         // edit the brand table
  2657.                                         if (_editCategory(nIndex, szName, _getBrandIndex(szBrandID)) == 0)
  2658.                                         {
  2659.                                             Response.Redirect("default.aspx?pid=item");
  2660.                                         }
  2661.                                         else
  2662.                                         {
  2663.                                             _content.InnerHtml = "<div style=\"text-align: center;\">Error: " + szLastErrorMessage + "<a href=\"default.aspx?pid=item&act=edit&id=" + nIndex.ToString() + "\" style=\"text-decoration: underline;\">Click here</a> to go back.</div>";
  2664.                                         }
  2665.                                     }
  2666.                                     else
  2667.                                     {
  2668.                                         _content.InnerHtml = "<div style=\"text-align: center;\">An unknown error has occurred!<a href=\"default.aspx?pid=item&act=edit&id=" + nIndex.ToString() + "\" style=\"text-decoration: underline;\">Click here</a> to go back.</div>";
  2669.                                     }
  2670.  
  2671.                                 }
  2672.                                 else
  2673.                                 {
  2674.                                     Response.Redirect("default.aspx?pid=item");
  2675.                                 }
  2676.                             }
  2677.                         }
  2678.  
  2679.  
  2680.                         // Remove a admin
  2681.                         else if (szAct == "delete")
  2682.                         {
  2683.                             if (Request.Form["id"] != null)
  2684.                             {
  2685.                                 if (int.TryParse(Request.Form["id"].ToString(), out int nIndex))
  2686.                                 {
  2687.                                     // delete admin from the table
  2688.                                     if (_deleteCategory(nIndex) == 0)
  2689.                                     {
  2690.                                         Response.Redirect("default.aspx?pid=category");
  2691.                                     }
  2692.                                     else
  2693.                                     {
  2694.                                         _content.InnerHtml = "<div style=\"text-align: center;\">Error: " + szLastErrorMessage + "<a href=\"default.aspx?pid=category&act=delete&id=" + nIndex.ToString() + "\" style=\"text-decoration: underline;\">Click here</a> to go back.</div>";
  2695.                                     }
  2696.                                 }
  2697.                                 else
  2698.                                 {
  2699.                                     _content.InnerHtml = "<div style=\"text-align: center;\">An unknown error has occurred!<a href=\"default.aspx?pid=category&act=delete&id=" + nIndex.ToString() + "\" style=\"text-decoration: underline;\">Click here</a> to go back.</div>";
  2700.                                 }
  2701.                             }
  2702.                             else
  2703.                             {
  2704.                                 Response.Redirect("default.aspx?pid=category");
  2705.                             }
  2706.                         }
  2707.                         else
  2708.                         {
  2709.                             Response.Redirect("default.aspx?pid=item");
  2710.                         }
  2711.                     }
  2712.                 }
  2713.             }
  2714.  
  2715.             // Specify logout link, if an admin is logged in
  2716.             if (nIsAdmin == 1)
  2717.             {
  2718.                 _content.InnerHtml += "<hr><div class=\"bevel\" style=\"text-align: center;\">[<a href=\"default.aspx?pid=logout\" style=\"text-decoration: underline;\">Logout</a>]</div>";
  2719.             }
  2720.         }
  2721.     }
  2722. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement