using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
//using System.Web.UI;
//using System.Web.UI.HtmlControls;
//using System.Web.UI.WebControls;
//using System.Web.UI.WebControls.WebParts;
using System.Data.Common;
using System.Data.SqlClient;
using digioz;
using digioz.FavoriteModule;

namespace digioz.FavoriteModule
{
    public class FavoriteInfoManagement
    {
        private static PortalSettings coPortalSettings;


        public static FavoriteInfoList GetFavoriteInfoList()
        {
            FavoriteInfoList loFavoriteInfoList = new FavoriteInfoList();
            coPortalSettings = PortalSettingsManagement.GetPortalSettings();

            if (coPortalSettings.DBRelational == true)
            {
                IDataRelational loDB = DataFactory.GetDataObject(coPortalSettings);
                FavoriteInfo loPictureInfo;
                DataTable loPictureTable;

                string lsSQL = "SELECT * FROM tblFavorites;";

                loDB.openConnection();
                loPictureTable = loDB.QueryDBDataset(lsSQL);
                loDB.closeConnection();

                foreach (DataRow loDR in loPictureTable.Rows)
                {
                    FavoriteInfo loFavoriteInfo = new FavoriteInfo();

                    loFavoriteInfo.ID = Convert.ToInt32(loDR["picture_id"]);
                    loFavoriteInfo.Type = (string)loDR["fav_type"];
                    loFavoriteInfo.TableID = (int)loDR["fav_table_id"];
                    loFavoriteInfo.FileName = (string)loDR["fav_name"];                  
                    

                    loFavoriteInfoList.Add(loFavoriteInfo);
                }
            }
            return loFavoriteInfoList;
        }
        public string GetFavoriteType(int psFavID, string psFavName)
        {
			coPortalSettings = PortalSettingsManagement.GetPortalSettings();
			string liType = string.Empty;
			
			 if (coPortalSettings.DBRelational == true)
            {
				IDataRelational loDB = DataFactory.GetDataObject(coPortalSettings);
                string lsSQL = String.Empty;

                lsSQL = "SELECT fav_type FROM tblFavorites WHERE fav_table_id = '" + psFavID + "' and fav_name = '" + psFavName + "'";

                loDB.openConnection();
                liType = Convert.ToString(loDB.ExecDBScalar(lsSQL));
                loDB.closeConnection();
            }
          
          return liType;
        }
                  
    }
}



