<%@ Page Language="C#" AutoEventWireup="true" CodeFile="ImageGallery.aspx.cs" Inherits="ImageGallery"
EnableEventValidation="false" MasterPageFile="User.master" Title="Your Album And Images" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
<span style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px;
font-weight: 900; color: #993300;">Upload Image</span> (<strong>Suggestion:</strong>
For fast Upload each Image file should be less than 1 MB)
<asp:ScriptManager ID="Scriptmanager1" runat="server">
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
Select File and click on finish.
<CuteWebUI:UploadAttachments InsertText="Select Images" runat="server" ID="Attachments1" FileTooLargeMsg="Image is large in size. please try smaller."
MultipleFilesUpload="true">
</CuteWebUI:UploadAttachments>
<span>(Maximum file size: 10M, Allowed file types: jpeg, jpg, gif, bmp) </span>
<asp:Button ID="uploadButton" runat="server" Text="Finish" OnClick="uploadButton_Click" />
<asp:Label ID="Label2" runat="server" Font-Bold="True" ForeColor="Red" Font-Names="Verdana"
<asp:Label ID="Label1" runat="server" Font-Names="Verdana" Font-Size="11px"></asp:Label>
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;
using System.Data.SqlClient;
using System.Drawing.Imaging;
using System.Collections.Generic;
using System.Net;
using System.Net.Mail;
using System.Net.Cache;
using System.Net.Mime;
using System.Net.NetworkInformation;
using CuteWebUI;
public partial class ImageGallery : System.Web.UI.Page
{
#region variables
static int catid = 0;
static int uniqueid = 0;
static int c = 0;
static int mem = 0;
static string filepath = "";
int w = 0, h = 0, w1 = 0, h1 = 0;
string filename;
static int count = 0;
int len12;
int j = 1, k = 1;
int fc = 0;
string[] names;
string[] files;
#endregion
#region event functions
protected void Page_Load(object sender, EventArgs e)
{
if (Session["uniqueid"] != null)
{
uniqueid = int.Parse(Session["uniqueid"].ToString());
catid = int.Parse(Session["catid"].ToString());
mem = getMember();
if (mem == 0)
{
c = countf();
showimage();
}
else
{
c = countf();
showimage();
}
}
else
{
Response.Redirect("Default.aspx");
}
}
protected void uploadButton_Click(object sender, EventArgs e)
{
try
{
foreach (AttachmentItem item in Attachments1.Items)
{
string dir = Server.MapPath("user_folder") + "\\" + uniqueid + "\\" + catid + "\\Temp\\image";
DirectoryInfo di = new DirectoryInfo(dir);
FileInfo[] arr = di.GetFiles("*.jpg");
if (arr.Length >= 20 && mem == 0)
{
Response.Write("<script>alert('Membership limit reached!!!Please update your membership.')</script>");
Label2.Text = "To upload your more image please update your membership";
}
else if (arr.Length >= 50 && mem == 1)
{
Response.Write("<script>alert('Membership limit reached!!!Please update your membership.')</script>");
Label2.Text = "To upload your more image please update your membership";
}
else if (arr.Length >= 50 && mem == 2)
{
Response.Write("<script>alert('Membership limit reached!!!Please update your membership.')</script>");
Label2.Text = "To upload your more image please update your membership";
}
else if (arr.Length >= 50 && mem == 3)
{
Response.Write("<script>alert('Membership limit reached!!!Please update your membership.')</script>");
Label2.Text = "To upload your more image please update your membership";
}
else if (arr.Length >= 50 && mem == 4)
{
Response.Write("<script>alert('Membership limit reached!!!Please update your membership.')</script>");
Label2.Text = "To upload your more image please update your membership";
}
else
{
item.CopyTo(Server.MapPath("user_folder") + "/" + uniqueid + "/" + catid + "/Temp/image/" + "\\" + item.FileGuid.ToString() + ".jpg");
Small(item.FileGuid.ToString() + ".jpg");
Big(item.FileGuid.ToString() + ".jpg");
}
}
Attachments1.DeleteAllAttachments();
//string dir = Server.MapPath("user_folder") + "\\" + uniqueid + "\\" + catid + "\\Temp\\image";
//DirectoryInfo di = new DirectoryInfo(dir);
//FileInfo[] arr = di.GetFiles("*.jpg");
//if (arr.Length >= 20 && mem == 0)
//{
// Response.Write("<script>alert('Membership limit reached!!!Please update your membership.')</script>");
// Label2.Text = "To upload your more image please update your membership";
//}
//else if (arr.Length >= 50 && mem == 1)
//{
// Response.Write("<script>alert('Membership limit reached!!!Please update your membership.')</script>");
// Label2.Text = "To upload your more image please update your membership";
//}
//else if (arr.Length >= 50 && mem == 2)
//{
// Response.Write("<script>alert('Membership limit reached!!!Please update your membership.')</script>");
// Label2.Text = "To upload your more image please update your membership";
//}
//else if (arr.Length >= 50 && mem == 3)
//{
// Response.Write("<script>alert('Membership limit reached!!!Please update your membership.')</script>");
// Label2.Text = "To upload your more image please update your membership";
//}
//else if (arr.Length >= 50 && mem == 4)
//{
// Response.Write("<script>alert('Membership limit reached!!!Please update your membership.')</script>");
// Label2.Text = "To upload your more image please update your membership";
//}
//else
//{
// uploadImage.SaveAs(Server.MapPath("user_folder") + "/" + uniqueid + "/" + catid + "/Temp/image/" + "\\" + uploadImage.FileName + "");
// Small(uploadImage.FileName);
// Big(uploadImage.FileName);
//}
//deletefiles();
//Response.Redirect("ImageGallery.aspx");
}
catch
{
Label2.Text = "Error Occured!!! Please try again later.";
Response.Write("<script>alert('Error Occured!!! Please try again later.')</script>");
}
}
#endregion
#region UserDefined Function
private void Small(string filename)
{
j = k = 1;
string dc = Server.MapPath("user_folder") + "\\" + uniqueid + "\\" + catid + "\\Small\\";
DirectoryInfo inc = new DirectoryInfo(dc);
FileInfo[] filesc = inc.GetFiles("*.jpg");
if (filesc.Length > 20 && mem == 0)
{
Label2.Text = "To upload your more image please update your membership";
}
else if (filesc.Length > 50 && mem == 1)
{
Label2.Text = "To upload your more image please update your membership";
}
else if (filesc.Length > 50 && mem == 2)
{
Label2.Text = "To upload your more image please update your membership";
}
else if (filesc.Length > 50 && mem == 3)
{
Label2.Text = "To upload your more image please update your membership";
}
else if (filesc.Length > 50 && mem == 4)
{
Label2.Text = "To upload your more image please update your membership";
}
else
{
System.Drawing.Image img9 =
System.Drawing.Image.FromFile(Server.MapPath("user_folder") + "\\" + uniqueid + "\\" + catid + "\\Temp\\image\\" + filename);
if (img9.Width >= 92)
{
w1 = 92;
if (img9.Height >= 92)
{
h1 = 92;
}
else
h1 = img9.Height;
}
else if (img9.Height >= 92)
{
h1 = 92;
if (img9.Width >= 92)
{
w1 = 92;
}
else
w1 = img9.Width;
}
else
{
w1 = img9.Width;
h1 = img9.Height;
}
System.Drawing.Graphics g1;
System.Drawing.Bitmap newImg1 = new System.Drawing.Bitmap(w1, h1);
g1 = System.Drawing.Graphics.FromImage(newImg1);
g1.DrawImage(img9, 0, 0, w1, h1);
string dir12 = Server.MapPath("user_folder") + "\\" + uniqueid + "\\" + catid + "\\Small\\";
while (File.Exists(dir12 + j.ToString() + ".jpg"))
{
j++;
}
ImageCodecInfo myImageCodecInfo;
Encoder myEncoder;
EncoderParameter myEncoderParameter;
EncoderParameters myEncoderParameters;
myImageCodecInfo = GetEncoderInfo("image/jpeg");
myEncoder = Encoder.Quality;
myEncoderParameters = new EncoderParameters(1);
myEncoderParameter = new EncoderParameter(myEncoder, 60L);
myEncoderParameters.Param[0] = myEncoderParameter;
newImg1.Save(Server.MapPath("user_folder") + "\\" + uniqueid + "\\" + catid + "\\Small\\" + j + ".jpg", myImageCodecInfo, myEncoderParameters);
DatabaseHelper das = new DatabaseHelper();
SqlDataReader dr1 = das.ExecuteReader("Select user_id,categoryId from profile_details where user_id=" + uniqueid);
while (dr1.Read())
{
if (dr1["categoryId"].ToString() != catid.ToString())
{
string dir123 = Server.MapPath("user_folder") + "\\" + dr1["user_id"].ToString() + "\\" + dr1["categoryId"].ToString() + "\\Small\\";
DirectoryInfo inf1 = new DirectoryInfo(dir123);
FileInfo[] files123 = inf1.GetFiles("*.jpg");
int count123 = files123.Length;
while (File.Exists(dir123 + k.ToString() + ".jpg"))
{
k++;
}
if (count123 < 11)
{
newImg1.Save(Server.MapPath("user_folder") + "\\" + dr1["user_id"].ToString() + "\\" + dr1["categoryId"].ToString() + "\\Small\\" + k + ".jpg", myImageCodecInfo, myEncoderParameters);
}
}
}
img9.Dispose();
}
}
private void Big(string filename)
{
j = k = 1;
string dc = Server.MapPath("user_folder") + "\\" + uniqueid + "\\" + catid + "\\Small\\";
DirectoryInfo inc = new DirectoryInfo(dc);
FileInfo[] filesc = inc.GetFiles("*.jpg");
if (filesc.Length > 20 && mem == 0)
{
Label2.Text = "To upload your more image please update your membership";
}
else if (filesc.Length > 50 && mem == 1)
{
Label2.Text = "To upload your more image please update your membership";
}
else if (filesc.Length > 50 && mem == 2)
{
Label2.Text = "To upload your more image please update your membership";
}
else if (filesc.Length > 50 && mem == 3)
{
Label2.Text = "To upload your more image please update your membership";
}
else if (filesc.Length > 50 && mem == 4)
{
Label2.Text = "To upload your more image please update your membership";
}
else
{
System.Drawing.Image img1 =
System.Drawing.Image.FromFile(Server.MapPath("images/") +
"logo.png");
System.Drawing.Image img2 =
System.Drawing.Image.FromFile(Server.MapPath("user_folder") + "\\" + uniqueid + "\\" + catid + "\\Temp\\image\\" + filename);
//if (img2.Width >= 700)
//{
// w = 700;
// if (img2.Height >= 800)
// {
// h = 800;
// }
// else
// h = img2.Height;
//}
//else if (img2.Height >= 800)
//{
// h = 800;
// if (img2.Width >= 700)
// {
// w = 700;
// }
// else
// w = img2.Width;
//}
//else
//{
w = img2.Width;
h = img2.Height;
//}
System.Drawing.Graphics g;
System.Drawing.Bitmap newImg = new System.Drawing.Bitmap(w, h);
g = System.Drawing.Graphics.FromImage(newImg);
g.DrawImage(img2, 0, 0, w, h);
g.DrawImage(img1, w - 245, h - 50, img1.Width, img1.Height);
string dre = Server.MapPath("user_folder") + "\\" + uniqueid + "\\" + catid + "\\Big\\";
while (File.Exists(dre + j.ToString() + ".jpg"))
{
j++;
}
ImageCodecInfo myImageCodecInfo1;
Encoder myEncoder1;
EncoderParameter myEncoderParameter1;
EncoderParameters myEncoderParameters1;
myImageCodecInfo1 = GetEncoderInfo("image/jpeg");
myEncoder1 = Encoder.Quality;
myEncoderParameters1 = new EncoderParameters(1);
myEncoderParameter1 = new EncoderParameter(myEncoder1, 60L);
myEncoderParameters1.Param[0] = myEncoderParameter1;
newImg.Save(Server.MapPath("user_folder") + "\\" + uniqueid + "\\" + catid + "\\Big\\" + j.ToString() + ".jpg", myImageCodecInfo1, myEncoderParameters1);
DatabaseHelper das = new DatabaseHelper();
SqlDataReader dr1 = das.ExecuteReader("Select user_id,categoryId from profile_details where user_id=" + uniqueid);
while (dr1.Read())
{
if (dr1["categoryId"].ToString() != catid.ToString())
{
string dre1 = Server.MapPath("user_folder") + "\\" + dr1["user_id"].ToString() + "\\" + dr1["categoryId"].ToString() + "\\Big\\";
DirectoryInfo di1 = new DirectoryInfo(dre1);
FileInfo[] files123 = di1.GetFiles("*.jpg");
int count123 = files123.Length + 1;
while (File.Exists(dre1 + k.ToString() + ".jpg"))
{
k++;
}
if (count123 < 11)
{
newImg.Save(Server.MapPath("user_folder") + "\\" + dr1["user_id"].ToString() + "\\" + dr1["categoryId"].ToString() + "\\Big\\" + k.ToString() + ".jpg", myImageCodecInfo1, myEncoderParameters1);
}
}
}
img2.Dispose();
}
}
private void deletefiles()
{
string temppath = Server.MapPath("UploaderTemp/");
string temppath1 = Server.MapPath("user_folder") + "\\" + uniqueid + "\\" + catid + "\\Temp\\image";
DirectoryInfo di = new DirectoryInfo(temppath);
DirectoryInfo di1 = new DirectoryInfo(temppath1);
FileInfo[] arr = di.GetFiles();
FileInfo[] arr1 = di1.GetFiles();
foreach (FileInfo f in arr)
{
File.Delete(f.FullName);
}
foreach (FileInfo f in arr1)
{
File.Delete(f.FullName);
}
}
private int getMember()
{
int m = 0;
string query = "";
DatabaseHelper das = new DatabaseHelper();
if ((catid >= 30 && catid <= 39) || (catid >= 120 && catid <= 138) || catid == 140)
{
query = "select membertype from c_profile_details where user_id=" + uniqueid + " and categoryid=" + catid;
}
else
{
query = "select membertype from profile_details where user_id=" + uniqueid + " and categoryid=" + catid;
}
SqlDataReader dr = das.ExecuteReader(query);
while (dr.Read())
{
m = int.Parse(dr["membertype"].ToString());
}
return m;
}
private int countf()
{
string dir = Server.MapPath("user_folder") + "\\" + uniqueid + "\\" + catid + "\\Big";
int numFiles;
files = Directory.GetFiles(dir);
numFiles = files.Length;
return numFiles;
}
private void showimage()
{
string html = "";
int i = 0;
string dir = Server.MapPath("user_folder") + "\\" + uniqueid + "\\" + catid + "\\Big";
DirectoryInfo di = new DirectoryInfo(dir);
FileInfo[] arr = di.GetFiles("*.jpg");
if (mem == 5)
{
Label1.Text = arr.Length.ToString() + " image out of unlimited ";
}
else if (mem == 0)
{
Label1.Text = arr.Length.ToString() + " image out of 20 ";
}
else
{
Label1.Text = arr.Length.ToString() + " image out of 50 ";
}
if (arr.Length > 0)
{
showImg.Visible = true;
html = "<table><tr>";
foreach (FileInfo f in arr)
{
if (i % 5 == 0)
{
html += "</tr><tr>";
}
html += "<td class=\"classified\"><img id='" + f.Name + "' src='" + "user_folder/" + uniqueid + "/" + catid + "/Small/" + f.Name + "' style='padding:2px 2px 2px 2px; border:1px solid #999999;'/><br/><br/><a href='DeleteImage.aspx?uid=" + uniqueid + "&name=" + f.Name + "&cid=" + catid + "'>Delete Photo</a></td>";
i++;
}
html += "</tr></table>";
showImg.InnerHtml = html;
}
else
showImg.Visible = false;
}
private static ImageCodecInfo GetEncoderInfo(String mimeType)
{
int j;
ImageCodecInfo[] encoders;
encoders = ImageCodecInfo.GetImageEncoders();
for (j = 0; j < encoders.Length; ++j)
{
if (encoders[j].MimeType == mimeType)
return encoders[j];
}
return null;
}
#endregion
}