Monday, 3 June 2013

how to find dimension and size of a image in asp.net

<%@ Page Title="" Language="C#" MasterPageFile="~/ERP/ECOMMERCE/GLIZMORE/GlizmoreMaster.Master"
    AutoEventWireup="true" CodeBehind="GlizmoreImageDownload.aspx.cs" Inherits="Website.ERP.ECOMMERCE.GLIZMORE.GlizmoreImageDownload" %>
   
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">

</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <script language="javascript" type="text/javascript">
        $(document).ready(
function () {
    $('#<%=btnAdd.ClientID %>').click(
function () {
    if ($('#<%=txttitle.ClientID %>').val() == "") {
        alert('Title should n\'t blank.');
        $('#<%=txttitle.ClientID %>').focus();
        return false;
    }
    else if ($('#<%=fuimage.ClientID %>').val() == "") {
        alert('Image should n\'t blank.');
        $('#<%=fuimage.ClientID %>').focus();
        return false;
    }
    return true;
}
)
  

}
)

</script>

    <div>
        <div id="inneroutercontent">
            <div>
                <table border="0" width="585" align="center">
                    <tr>
                        <td align="right">
                            <p>
                                Title :</p>
                        </td>
                        <td>
                            <asp:TextBox ID="txttitle" runat="server" Width="300"></asp:TextBox>&nbsp;<asp:LinkButton
                                ID="lkbView" runat="server" Font-Underline="false" Text="View"
                                onclick="lkbView_Click"></asp:LinkButton>
                        </td>
                    </tr>
                    <tr>
                        <td align="right">
                            <p>
                                Image :</p>
                        </td>
                        <td>
                            <asp:FileUpload ID="fuimage" runat="server" Style="width: 304px" />
                        </td>
                    </tr>
                    <tr>
                        <td align="right" style="vertical-align:top">
                            <p>
                                Description :
                            </p>
                        </td>
                        <td>
                            <asp:TextBox ID="txtdescription" runat="server" Width="298" TextMode="MultiLine"></asp:TextBox>&nbsp;
                            <asp:Button ID="btnAdd" runat="server" Text="Add More" Width="80" OnClick="btnAdd_Click" /></li>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            &nbsp;
                        </td>
                        <td>
                            <asp:GridView ID="gvtemp" runat="server" Width="100%"
                                AutoGenerateColumns="False" onrowdeleting="gvtemp_RowDeleting">
                             
                                <Columns>
                                    <asp:TemplateField HeaderText="Sl No.">
                                        <ItemTemplate>
                                            <%#Container.DisplayIndex+1 %>
                                        </ItemTemplate>
                                    </asp:TemplateField>
                                    <asp:TemplateField HeaderText="TITLE">
                                    <ItemTemplate>
                                    <asp:Label ID="lbtitle" runat="server" Text='<%#Eval("Image_Title") %>'></asp:Label>
                                    </ItemTemplate>
                                    </asp:TemplateField>
                                    <asp:TemplateField HeaderText="IMAGE">
                                    <ItemTemplate>
                                      <asp:HiddenField ID="hfdesp" runat="server" Value='<%#Eval("Description") %>' />
                                    <asp:HiddenField ID="hfimage" runat="server" Value='<%#Eval("Image_Path") %>' />
                                    <asp:HiddenField ID="hfsize" runat="server" Value='<%#Eval("Size") %>' />
                                     <asp:HiddenField ID="hfDimention" runat="server" Value='<%#Eval("Dimension") %>' />
                                    <asp:Image Height="80" Width="80" runat="server" ID="imgimage1" ImageUrl='<%#"~/images/"+Eval("Image_Path") %>' />
                                    </ItemTemplate>
                                    </asp:TemplateField>
                                    <asp:CommandField HeaderText="REMOVE" ShowDeleteButton="True"
                                        ShowHeader="True" />
                                </Columns>
                               <HeaderStyle HorizontalAlign="Left" />
                               <RowStyle HorizontalAlign="Center" />
                            </asp:GridView>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            &nbsp;
                        </td>
                        <td>
                            <asp:Button ID="btnSave" runat="server" Text="Save" Width="80" OnClick="btnSave_Click"  />&nbsp;<asp:Button
                                ID="btnReset" runat="server" Text="Reset" Width="80" />
                        </td>
                    </tr>
                </table>

                <asp:Panel ID="pnlModal" runat="server" Width="800px" CssClass="ModalPopUpPanelCommonViewCRM"   Style="display: none">
                    <table width="100%" cellspacing="0" cellpadding="0">
                    <tr><td>
                      <div align="right" style="background-color: #7DA5DB; height: 30px" class="grid_top">
                        <asp:Button ID="btnClose" runat="server" Width="25" Text="X" CssClass="PoPUpCloseBtnCRM" CausesValidation="False"
                            ToolTip="Close" />
                    </div>
                     <asp:Button ID="btnview" runat="server" Text="Press" style="display:none" />
                    <div  class="grid">
                        <asp:GridView ID="gvimage" runat="server" Width="99%">
                        <Columns>
                        <asp:TemplateField HeaderText="Sl NO.">
                        <ItemTemplate>
                        <%#Container.DisplayIndex+1 %>
                        </ItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField  HeaderText="TITLE">
                        <ItemTemplate>
                        <asp:Label ID="lbtitle" runat="server" Text='<%#Eval("Image_Title") %>'></asp:Label>
                        </ItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="IMAGE">
                        <ItemTemplate>
                         <asp:HiddenField ID="hfimgid" runat="server" Value='<%#Eval("Image_ID") %>' />
                         <asp:HiddenField ID="hfdesp" runat="server" Value='<%#Eval("Description") %>' />
                                    <asp:HiddenField ID="hfimage" runat="server" Value='<%#Eval("Image_Path") %>' />
                                    <asp:HiddenField ID="hfsize" runat="server" Value='<%#Eval("Size") %>' />
                                     <asp:HiddenField ID="hfDimention" runat="server" Value='<%#Eval("Dimension") %>' />
                        <asp:Image ID="im" runat="server" Height="80" Width="80" ImageUrl='<%#"~/images/"+Eval("Image_Path") %>' />
                        </ItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="STATUS">
                        <ItemTemplate>
                        <asp:CheckBox ID="cb" runat="server" Checked='<%#Eval("Status") %>' />
                        </ItemTemplate>
                        </asp:TemplateField>
                        </Columns>
                        </asp:GridView>
                    </div>
                    </td></tr>
                    <tr  class="grid1"><td><asp:Button ID="btnmodify" runat="server" Text="Change"
                            Width="80" style="position:relative; left:380px; top:5px"
                            onclick="btnmodify_Click" /></td></tr>
          
                    </table>
                 
                </asp:Panel>
             
              
                <asp:ModalPopupExtender ID="ModalPopupExtender1" runat="server" TargetControlID="btnview"
                    PopupControlID="pnlModal" CancelControlID="btnClose" BackgroundCssClass="ModalBackgroundCSS">
                </asp:ModalPopupExtender>
            </div>
            <div id="rightcontact">
            </div>
            <div style="clear: both;">
            </div>
        </div>
    </div>
</asp:Content>
C# CODE :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using Swash.BusinessLayer;
using Swash.Objects;

namespace Website.ERP.ECOMMERCE.GLIZMORE
{
    public partial class GlizmoreImageDownload : System.Web.UI.Page
    {
        #region
        DataTable dt = new DataTable();
        int i;
        #endregion
        protected void Page_Load(object sender, EventArgs e)
        {
         
            if (!IsPostBack)
            {
                fill();
            }

        }
        void fill()
        {
            gvimage.DataSource = ERPManagement.GetInstance.selectDImage();
            gvimage.DataBind();
        }
        protected void btnAdd_Click(object sender, EventArgs e)
        {
            if (fuimage.HasFile)
            {
                System.Drawing.Image img = System.Drawing.Image.FromFile(fuimage.PostedFile.FileName);
                fuimage.SaveAs(Server.MapPath("~/images/" + fuimage.FileName));
                List<Ecom_Downloadimage> obj = new List<Ecom_Downloadimage>();
                Ecom_Downloadimage obj1 = new Ecom_Downloadimage();
                obj1.Image_Title = txttitle.Text;
                obj1.Image_Path = fuimage.FileName.ToString();
                obj1.Description = txtdescription.Text;
                obj1.Size = (fuimage.PostedFile.ContentLength / 1024).ToString() +" KB";
                obj1.Dimension = img.Height.ToString() + "X" + img.Width.ToString()+" Pixel";
                obj.Add(obj1);
                txttitle.Text = "";
                txtdescription.Text = "";
                txttitle.Focus();
                for (i = 0; i < gvtemp.Rows.Count; i++)
                {
                    Ecom_Downloadimage obj2 = new Ecom_Downloadimage();
                    obj2.Image_Title = ((Label)gvtemp.Rows[i].Cells[1].FindControl("lbtitle")).Text;
                    obj2.Image_Path = ((HiddenField)gvtemp.Rows[i].Cells[2].FindControl("hfimage")).Value.ToString();
                    obj2.Description = ((HiddenField)gvtemp.Rows[i].Cells[2].FindControl("hfdesp")).Value.ToString();
                    obj2.Size = ((HiddenField)gvtemp.Rows[i].Cells[2].FindControl("hfsize")).Value.ToString();
                    obj2.Dimension = ((HiddenField)gvtemp.Rows[i].Cells[2].FindControl("hfDimention")).Value.ToString();
                    obj.Add(obj2);
                }
                ViewState["list"] = obj;
                gvtemp.DataSource = obj.ToList();
                gvtemp.DataBind();

            }
        }
        protected void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                if (ViewState["list"]!=null)
                {
                    ERPManagement.GetInstance.insertDImage(((List<Ecom_Downloadimage>)ViewState["list"]));
                    ScriptManager.RegisterClientScriptBlock(this, GetType(), "x", "result()", true);
                }
                else
                    ScriptManager.RegisterClientScriptBlock(this, GetType(), "x", "alert('Add item first.')", true);

            }
            catch (Exception ex)
            {
                ScriptManager.RegisterClientScriptBlock(this, GetType(), "x", "alert('" + ex.Message.ToString() + "')", true);
            }
        }

        protected void lkbView_Click(object sender, EventArgs e)
        {
            fill();
            ModalPopupExtender1.Show();
        }

        protected void btnmodify_Click(object sender, EventArgs e)
        {
            try
            {
                List<Ecom_Downloadimage> obj = new List<Ecom_Downloadimage>();
                for (int i = 0; i < gvimage.Rows.Count; i++)
                {
                    Ecom_Downloadimage obj1 = new Ecom_Downloadimage();
                    obj1.Image_ID = Convert.ToInt32(((HiddenField)gvimage.Rows[i].FindControl("hfimgid")).Value);
                    if (((CheckBox)gvimage.Rows[i].FindControl("cb")).Checked)
                        obj1.Status = true;
                    else
                        obj1.Status = false;
                    obj.Add(obj1);
                }
                ERPManagement.GetInstance.updateDImage(obj);
                ScriptManager.RegisterClientScriptBlock(this, GetType(), "x", "alert('Data changed sucessfully.')", true);
            }
            catch (Exception ex)
            {
                ScriptManager.RegisterClientScriptBlock(this, GetType(), "x", "alert('"+ex.Message.ToString()+"')", true);
            }

           
        }

        protected void gvtemp_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            List<Ecom_Downloadimage> lis=(List<Ecom_Downloadimage>)ViewState["list"];
            lis.RemoveAt(e.RowIndex);
            ViewState["list"] = lis;
            gvtemp.DataSource = lis;
            gvtemp.DataBind();
        }
    }
}

No comments:

Post a Comment