Esempio n. 1
0
    protected void btn_AddImage1_Click(object sender, EventArgs e)
    {
        if (DropDownList2.SelectedItem.Text == "Gallery")
        {
            int    a            = 0;
            string path         = Server.MapPath("");
            string sid          = ddlColumn.SelectedValue.ToString();
            string OriginalName = FileUpload2.FileName.ToString();
            byte[] Filedata     = (byte[])FileUpload2.FileBytes;
            int    count        = Filedata.Length;

            Stream sr = FileUpload2.PostedFile.InputStream;
            sr.InitializeLifetimeService();
            sr.Read(Filedata, 0, count);

            if (System.IO.Path.GetExtension(OriginalName).ToLower() == ".jpg")
            {
                System.Drawing.Image img;
                img = System.Drawing.Image.FromStream(sr);
                if (FileUpload2.HasFile == true && FileUpload2.PostedFile.ContentLength != 0 && img.Height >= 128 && img.Width >= 128)
                {
                    try
                    {
                        if (DropDownList1.SelectedItem.Text == "Historical Spots")
                        {
                            GeneralBAL ph = new GeneralBAL();
                            a = ph.InsertSpotPhoto(sid, ("~/image/" + sid + "_HS_" + OriginalName), txtDecription.Text, txtImageTitle.Text);
                            FileStream fs = new FileStream(path + @"\image\" + sid + "_HS_" + OriginalName, FileMode.OpenOrCreate, FileAccess.Write);
                            fs.Write(Filedata, 0, count);
                            fs.Flush();
                            fs.Close();
                        }
                        else if (DropDownList1.SelectedItem.Text == "LP")
                        {
                            string     lpid = ddlColumn1.SelectedValue.ToString();
                            GeneralBAL ph   = new GeneralBAL();
                            a = ph.InsertLPPhoto(lpid, ("~/image/" + lpid + "_LP_" + OriginalName), txtDecription.Text, txtImageTitle.Text);
                            FileStream fs = new FileStream(path + @"\image\" + lpid + "_LP_" + OriginalName, FileMode.OpenOrCreate, FileAccess.Write);
                            fs.Write(Filedata, 0, count);
                            fs.Flush();
                            fs.Close();
                        }
                        else if (DropDownList1.SelectedItem.Text == "Festivals")
                        {
                            GeneralBAL ph = new GeneralBAL();
                            a = ph.InsertFestivalPhoto(sid, ("~/image/" + sid + "_Fest_" + OriginalName), txtDecription.Text, txtImageTitle.Text);
                            FileStream fs = new FileStream(path + @"\image\" + sid + "_Fest_" + OriginalName, FileMode.OpenOrCreate, FileAccess.Write);
                            fs.Write(Filedata, 0, count);
                            fs.Flush();
                            fs.Close();
                        }

                        if (a != 0)
                        {
                            Page.ClientScript.RegisterStartupScript(typeof(Page), "key", "alert('Photo Added.');location='GalleryManager.aspx';", true);
                        }
                        else
                        {
                            Page.ClientScript.RegisterStartupScript(typeof(Page), "key", "alert('Contact Administrator.');", true);
                        }
                    }
                    catch
                    {
                        Page.ClientScript.RegisterStartupScript(typeof(Page), "key", "alert('Some problem occured while adding the photo. Please contact administrator');location='GalleryManager.aspx';", true);
                    }
                }
                else
                {
                    Page.ClientScript.RegisterStartupScript(typeof(Page), "key", "alert('Please choose correct size and type photo .');location='GalleryManager.aspx';", true);
                }
            }
            else
            {
                Page.ClientScript.RegisterStartupScript(typeof(Page), "key", "alert('Please choose correct size and type photo .');location='GalleryManager.aspx';", true);
            }
        }
    }
Esempio n. 2
0
    protected void btn_AddImage1_Click(object sender, EventArgs e)
    {
        if (DropDownList2.SelectedItem.Text == "Gallery")
        {
            int a = 0;
            string path = Server.MapPath("");
            string sid = ddlColumn.SelectedValue.ToString();
            string OriginalName = FileUpload2.FileName.ToString();
            byte[] Filedata = (byte[])FileUpload2.FileBytes;
            int count = Filedata.Length;

            Stream sr = FileUpload2.PostedFile.InputStream;
            sr.InitializeLifetimeService();
            sr.Read(Filedata, 0, count);

            if (System.IO.Path.GetExtension(OriginalName).ToLower() == ".jpg")
            {
                System.Drawing.Image img;
                img = System.Drawing.Image.FromStream(sr);
                if (FileUpload2.HasFile == true && FileUpload2.PostedFile.ContentLength != 0 && img.Height >= 128 && img.Width >= 128)
                {
                    try
                    {
                        if (DropDownList1.SelectedItem.Text == "Historical Spots")
                        {
                            GeneralBAL ph = new GeneralBAL();
                            a = ph.InsertSpotPhoto(sid, ("~/image/" + sid + "_HS_" + OriginalName), txtDecription.Text, txtImageTitle.Text);
                            FileStream fs = new FileStream(path + @"\image\" + sid + "_HS_" + OriginalName, FileMode.OpenOrCreate, FileAccess.Write);
                            fs.Write(Filedata, 0, count);
                            fs.Flush();
                            fs.Close();
                        }
                        else if (DropDownList1.SelectedItem.Text == "LP")
                        {
                            string lpid = ddlColumn1.SelectedValue.ToString();
                            GeneralBAL ph = new GeneralBAL();
                            a = ph.InsertLPPhoto(lpid, ("~/image/" + lpid + "_LP_" + OriginalName), txtDecription.Text, txtImageTitle.Text);
                            FileStream fs = new FileStream(path + @"\image\" + lpid + "_LP_" + OriginalName, FileMode.OpenOrCreate, FileAccess.Write);
                            fs.Write(Filedata, 0, count);
                            fs.Flush();
                            fs.Close();
                        }
                        else if (DropDownList1.SelectedItem.Text == "Festivals")
                        {
                            GeneralBAL ph = new GeneralBAL();
                            a = ph.InsertFestivalPhoto(sid, ("~/image/" + sid + "_Fest_" + OriginalName), txtDecription.Text, txtImageTitle.Text);
                            FileStream fs = new FileStream(path + @"\image\" + sid + "_Fest_" + OriginalName, FileMode.OpenOrCreate, FileAccess.Write);
                            fs.Write(Filedata, 0, count);
                            fs.Flush();
                            fs.Close();
                        }

                        if (a != 0)
                            Page.ClientScript.RegisterStartupScript(typeof(Page), "key", "alert('Photo Added.');location='GalleryManager.aspx';", true);
                        else
                            Page.ClientScript.RegisterStartupScript(typeof(Page), "key", "alert('Contact Administrator.');", true);
                    }
                    catch
                    {
                        Page.ClientScript.RegisterStartupScript(typeof(Page), "key", "alert('Some problem occured while adding the photo. Please contact administrator');location='GalleryManager.aspx';", true);
                    }
                }
                else
                    Page.ClientScript.RegisterStartupScript(typeof(Page), "key", "alert('Please choose correct size and type photo .');location='GalleryManager.aspx';", true);
            }
            else
                Page.ClientScript.RegisterStartupScript(typeof(Page), "key", "alert('Please choose correct size and type photo .');location='GalleryManager.aspx';", true);
        }
    }