public int AddPrimaryImage() { try { CDatabase Database = new CDatabase(); CImage NewImage = new CImage(); Database.InsertProductImage(this.ProductID, this.PrimaryImage.FileName, this.PrimaryImage.FileExtension, this.PrimaryImage.FileSize, this.PrimaryImage.FileBytes); return(0); } catch (Exception ex) { throw new Exception(ex.Message); } }
// Get Primary Image \ public CImage GetPrimaryImage(int intProductID) { try { SqlConnection Connection = null; if (OpenDBConnection(ref Connection) == 0) { SqlDataAdapter da = new SqlDataAdapter("uspSelectProductPrimaryImage", Connection); DataSet ds = new DataSet(); SetParameter(ref da, "@intProductID", intProductID, SqlDbType.Int); try { da.Fill(ds); } finally { CloseDBConnection(ref Connection); } // Load the primary Image CImage PrimaryImage = new CImage(); if (ds.Tables.Count != 0) { DataRow dr; dr = ds.Tables[0].Rows[0]; PrimaryImage.ImageID = (int)dr["intImageID"]; PrimaryImage.FileName = (string)dr["strFileName"]; PrimaryImage.FileExtension = (string)dr["strImageType"]; PrimaryImage.FileSize = (int)dr["intImageSize"]; PrimaryImage.FileBytes = (byte[])dr["ImageData"]; } return(PrimaryImage); } else { return(null); } } catch (Exception ex) { throw new Exception(ex.Message); } }
public int UpdatePrimaryImage() { try { CDatabase Database = new CDatabase(); CImage NewImage = new CImage(); int intImageID; NewImage = Database.GetPrimaryImage(this.ProductID); intImageID = NewImage.ImageID; Database.UpdateProductImage(intImageID, this.ProductID, this.PrimaryImage.FileName, this.PrimaryImage.FileExtension, this.PrimaryImage.FileSize, this.PrimaryImage.FileBytes); return(0); } catch (Exception ex) { throw new Exception(ex.Message); } }
// Insert Product image \ public int InsertProductImage(int intProductID, string strFileName, string strFileExtension, int intFileSize, byte[] bytes) { try { CImage NewImage = new CImage(); SqlConnection Connection = null; int intIsPrimary = 0; if (OpenDBConnection(ref Connection) == 0) { SqlCommand cm = new SqlCommand("uspAddImage", Connection); // If there is no primary image for the product, set this image to primary if (HasPrimaryImage(intProductID) == false) { intIsPrimary = 1; } ; SetParameter(ref cm, "@intProductID", intProductID, SqlDbType.Int); SetParameter(ref cm, "@blnPrimaryImage", intIsPrimary, SqlDbType.Bit); SetParameter(ref cm, "@strFileName", strFileName, SqlDbType.VarChar); SetParameter(ref cm, "@strImageType", strFileExtension, SqlDbType.VarChar); SetParameter(ref cm, "@intImageSize", intFileSize, SqlDbType.Int); SetParameter(ref cm, "@ImageData", bytes, SqlDbType.VarBinary); cm.ExecuteReader(); CloseDBConnection(ref Connection); return(0); //success } else { return(-1); // No database connection } } catch (Exception ex) { throw new Exception(ex.Message); } }