private Dictionary <string, string> callMeForFupImage()
    {
        string filename = "", files = "";
        Dictionary <string, string> dictNames = new Dictionary <string, string>();
        //if (Gallery_Image.HasFile)
        //{
        HttpFileCollection fileCollection = Request.Files;

        for (int i = 0; i < fileCollection.Count; i++)
        {
            //ctl00_ContentPlaceHolder1_fulp_Images//ctl00$ContentPlaceHolder1$fulp_Images
            if (fileCollection.Keys[i] != "ctl00$ContentPlaceHolder1$fulp")
            {
                HttpPostedFile uploadfile = fileCollection[i];

                if (uploadfile.ContentLength > 0)
                {
                    if (uploadfile.ContentLength > (1048576 * int.Parse(ConfigurationManager.AppSettings["ImageSize"].ToString())))
                    {
                        ScriptManager.RegisterStartupScript(this, this.GetType(), "ShowPopup", "toastr.error('Image size have exceeded the maximum size limit. Please upload large image below " + ConfigurationManager.AppSettings["ImageSize"].ToString() + " MB size.');", true);
                    }
                    else
                    {
                        Bitmap uploadedImage = new Bitmap(uploadfile.InputStream);
                        if (uploadedImage.Width >= Convert.ToInt16(ConfigurationManager.AppSettings["ProductImgWidth"].ToString()) && uploadedImage.Height >= Convert.ToInt16(ConfigurationManager.AppSettings["ProductImgHeight"].ToString()))
                        {
                            //filename = DateTime.Now.ToString("ddmmyyyyhhmmss") + uploadfile.FileName.ToString().Replace(" ", "-").Replace("&", "-").Replace("/", "-").Replace("<", "").Replace("'", "").Replace("#", "");
                            FileInfo FILE = new FileInfo(uploadfile.FileName);
                            filename = DAL.FormateText(txtTitle.Text) + "-" + (new Random()).Next(0, 100000) + FILE.Extension;
                            if (Path.GetExtension(filename) == "")
                            {
                                return(null);
                            }
                            //dictNames.Add(Path.GetFileName(uploadfile.FileName).Substring(0, uploadfile.FileName.LastIndexOf(".")), filename);
                            dictNames.Add(filename, "");
                            imageresize imgrez    = new imageresize();
                            int         maxWidth  = int.Parse(ConfigurationManager.AppSettings["ProductSmallImgWidth"].ToString());
                            int         maxHeight = int.Parse(ConfigurationManager.AppSettings["ProductSmallImgHeight"].ToString());
                            imgrez.GetScaledPicture(uploadedImage, maxWidth, maxHeight, "product", "small", filename);

                            maxWidth  = int.Parse(ConfigurationManager.AppSettings["ProductImgWidth"].ToString());
                            maxHeight = int.Parse(ConfigurationManager.AppSettings["ProductImgHeight"].ToString());
                            imgrez.GetScaledPicture(uploadedImage, maxWidth, maxHeight, "product", "medium", filename);

                            uploadedImage.Save(WorkingDirectory + "product\\large\\" + filename);
                        }
                        else
                        {
                            ScriptManager.RegisterStartupScript(this, this.GetType(), "ShowPopup", "toastr.error('Deal & Offers image width and height should be greater than " + ConfigurationManager.AppSettings["ProductImgHeight"].ToString() + "px and " + ConfigurationManager.AppSettings["ProductImgWidth"].ToString() + "px');", true);
                            Detail = ""; Image = "active"; Associate = "";
                        }
                    }
                }
            }
        }
        // }
        return(dictNames);
    }
Esempio n. 2
0
    protected void btn_Submit_Click(object sender, EventArgs e)
    {
        string filename = "", filenameresource = "";

        #region Resize Image

        if (fulp.HasFile)
        {
            if (fulp.PostedFile.ContentLength > (1048576 * int.Parse(ConfigurationManager.AppSettings["ImageSize"].ToString())))
            {
                ScriptManager.RegisterStartupScript(this, this.GetType(), "ShowPopup", "toastr.error('Image size have exceeded the maximum size limit. Please upload image below " + ConfigurationManager.AppSettings["ImageSize"].ToString() + " MB size.');", true);

                return;
            }

            Bitmap uploadedImage = new Bitmap(fulp.FileContent);

            if (uploadedImage.Width >= Convert.ToInt16(ConfigurationManager.AppSettings["PartnerImgWidth"].ToString()) && uploadedImage.Height >= Convert.ToInt16(ConfigurationManager.AppSettings["PartnerImgHeight"].ToString()))
            {
                filename = DateTime.Now.ToString("ddmmyyyyhhmmss") + fulp.FileName.ToString();
                filename = filename.Trim().Replace("(", "").Replace(")", "").Replace("[", "").Replace("]", "").Replace("#", "").Replace("$", "").Replace("%", "").Replace("@", "").Replace("&", "").Replace("'", "").Replace(" ", "");
                imageresize imgrez    = new imageresize();
                int         maxWidth  = int.Parse(ConfigurationManager.AppSettings["PartnerImgWidth"].ToString());
                int         maxHeight = int.Parse(ConfigurationManager.AppSettings["PartnerImgHeight"].ToString());

                imgrez.GetScaledPicture(uploadedImage, maxWidth, maxHeight, "Partner", "", filename);
                uploadedImage.Save(WorkingDirectory + "Partner\\" + filename);
            }
            else
            {
                ltrmessageimage.Visible = true;
                ltrmessageimage.Text    = "Brand Partner image width and height should be greater than " + ConfigurationManager.AppSettings["PartnerImgWidth"].ToString() + "px and " + ConfigurationManager.AppSettings["PartnerImgHeight"].ToString() + "px";
                return;
            }



            if (ViewState["img"] != null)
            {
                if (ViewState["img"].ToString() != "")
                {
                    try
                    {
                        if (System.IO.File.Exists(DAL.GetRootPath() + "\\webfiles\\Partner\\" + ViewState["img"].ToString()))
                        {
                            System.IO.File.Delete((DAL.GetRootPath() + "\\webfiles\\Partner\\" + ViewState["img"].ToString()));
                        }
                    }
                    catch (Exception ex)
                    { }
                }
            }
        }
        if (ViewState["img"] != null && filename == "")
        {
            filename = ViewState["img"].ToString();
        }
        #endregion



        if (!DAL.IsNumeric(Request.QueryString["id"]))
        {
            int sortorder = 1;
            #region ManageSortOrder

            string maxnum = (new DAL()).ExecuteScalar("Select max(sortorder) from Partner", CommandType.Text, null); // this query will fetch the maximum display order number from db
            if (maxnum != null && maxnum != "")
            {
                sortorder = int.Parse(maxnum.ToString()) + 1;
            }
            #endregion
            strQuery  = "insert into Partner(Visible,URL,image,sortorder,AddedDate,AddedIp) ";
            strQuery += "values('" + rbl_Visible.SelectedValue.ToString() + "','" + txtURL.Text.Replace("'", "''") + "','" + filename.ToString() + "',";
            strQuery += "" + sortorder + ",'" + DAL.GetDateWithFormat() + "','" + DAL.getIP() + "')";
            (new DAL()).ExecuteNonQuery(strQuery, CommandType.Text, null);
            msg = "Partner details has been added successully.";
            Response.Redirect("viewPartner.aspx?msg=" + msg);
        }
        else
        {
            strQuery  = "update Partner set Visible='" + rbl_Visible.SelectedValue.ToString() + "',URL='" + txtURL.Text.Replace("'", "''") + "',";
            strQuery += "image='" + filename.ToString() + "',";
            strQuery += "ModifyDate='" + DAL.GetDateWithFormat() + "',ModifyIp='" + DAL.getIP() + "' where id=" + Request.QueryString["id"].ToString();
            (new DAL()).ExecuteNonQuery(strQuery, CommandType.Text, null);
            msg = "Partner details has been modified successfully.";
            Response.Redirect("viewPartner.aspx?msg=" + msg);
        }
    }
Esempio n. 3
0
    protected void btn_Submit_Click(object sender, EventArgs e)
    {
        #region Resize Image For Website

        if (DAL.IsNumeric(Request.QueryString["id"]))
        {
            filename = ViewState["img"].ToString();
        }

        //  this.Form.Enctype = "multipart/form-data";
        if (FUplarge.HasFile)
        {
            if (FUplarge.PostedFile.ContentLength > (1048576 * int.Parse(ConfigurationManager.AppSettings["ImageSize"].ToString())))
            {
                ScriptManager.RegisterStartupScript(this, this.GetType(), "ShowPopup", "toastr.success('Image size have exceeded the maximum size limit. Please upload large image below " + ConfigurationManager.AppSettings["Gallerylimittext"].ToString() + " MB size.');", true);
                return;
            }
            Bitmap uploadedImage = new Bitmap(FUplarge.FileContent);


            filename = DateTime.Now.ToString("ddmmyyyyhhmmss") + FUplarge.FileName.ToString();
            filename = filename.Trim().Replace("(", "").Replace(")", "").Replace("[", "").Replace("]", "").Replace("#", "").Replace("$", "").Replace("%", "").Replace("@", "").Replace("&", "").Replace("'", "").Replace(" ", "");
            imageresize imgrez = new imageresize();
            if (ddlposition.SelectedValue.ToString() == "1")
            {
                if (uploadedImage.Width == int.Parse(ConfigurationManager.AppSettings["teaserSidewidth"].ToString()) && uploadedImage.Height == int.Parse(ConfigurationManager.AppSettings["teaserSideHeight"].ToString()))
                { //left teaser
                    int maxWidth  = int.Parse(ConfigurationManager.AppSettings["teaserSidewidth"].ToString());
                    int maxHeight = int.Parse(ConfigurationManager.AppSettings["teaserSideHeight"].ToString());
                    imgrez.GetScaledPicture(uploadedImage, maxWidth, maxHeight, "teaser", "", filename);
                }
                else
                {
                    ltrmessageimage.Visible = true;
                    ltrmessageimage.Text    = "Advertisement Banner image width and height should be " + ConfigurationManager.AppSettings["teaserSidewidth"].ToString() + "px and " + ConfigurationManager.AppSettings["teaserSideHeight"].ToString() + "px";
                    return;
                }
            }
            else if (ddlposition.SelectedValue.ToString() == "2")
            {
                if (uploadedImage.Width == int.Parse(ConfigurationManager.AppSettings["teaserMiddlewidth"].ToString()) && uploadedImage.Height == int.Parse(ConfigurationManager.AppSettings["teaserMiddleHeight"].ToString()))
                {  //Middle teaser
                    int maxWidth1  = int.Parse(ConfigurationManager.AppSettings["teaserMiddlewidth"].ToString());
                    int maxHeight1 = int.Parse(ConfigurationManager.AppSettings["teaserMiddleHeight"].ToString());
                    imgrez.GetScaledPicture(uploadedImage, maxWidth1, maxHeight1, "teaser", "", filename);
                }
                else
                {
                    ltrmessageimage.Visible = true;
                    ltrmessageimage.Text    = "Advertisement Banner image width and height should be " + ConfigurationManager.AppSettings["teaserMiddlewidth"].ToString() + "px and " + ConfigurationManager.AppSettings["teaserMiddleHeight"].ToString() + "px";
                    return;
                }
            }

            else if (ddlposition.SelectedValue.ToString() == "3")
            {
                if (uploadedImage.Width == int.Parse(ConfigurationManager.AppSettings["teaserBottomwidth"].ToString()) && uploadedImage.Height == int.Parse(ConfigurationManager.AppSettings["teaserBottomHeight"].ToString()))
                {  //Right teaser
                    int maxWidth2  = int.Parse(ConfigurationManager.AppSettings["teaserBottomwidth"].ToString());
                    int maxHeight2 = int.Parse(ConfigurationManager.AppSettings["teaserBottomHeight"].ToString());
                    imgrez.GetScaledPicture(uploadedImage, maxWidth2, maxHeight2, "teaser", "", filename);
                }
                else
                {
                    ltrmessageimage.Visible = true;
                    ltrmessageimage.Text    = "Advertisement Banner image width and height should be " + ConfigurationManager.AppSettings["teaserBottomwidth"].ToString() + "px and " + ConfigurationManager.AppSettings["teaserBottomHeight"].ToString() + "px";
                    return;
                }
            }
        }
        #endregion

        if (!DAL.IsNumeric(Request.QueryString["id"]))
        {
            strQuery = "insert into teaser(Visible,url,image,position,AddedDate,AddedIp) ";//stateid,cityid,

            strQuery += "values('" + rbl_Visible.SelectedValue.ToString() + "','" + txturl.Text.Replace("'", "''") + "','" + filename.Replace("'", "''") + "','" + ddlposition.SelectedValue.ToString() + "',";
            strQuery += "'" + DAL.GetDateWithFormat() + "','" + DAL.getIP() + "')";
            (new DAL()).ExecuteNonQuery(strQuery, CommandType.Text, null);
            msg = "Teaser details has been added successully.";
            Response.Redirect("viewadvt.aspx?msg=" + msg);
        }
        else
        {
            strQuery  = "update teaser set Visible='" + rbl_Visible.SelectedValue.ToString() + "',position='" + ddlposition.SelectedValue.ToString() + "',";
            strQuery += "Image='" + filename.Replace("'", "''") + "',url='" + txturl.Text.Replace("'", "''") + "',";
            strQuery += "ModifyDate='" + DAL.GetDateWithFormat() + "',ModifyIp='" + DAL.getIP() + "' where id=" + Request.QueryString["id"].ToString();
            (new DAL()).ExecuteNonQuery(strQuery, CommandType.Text, null);
            msg = "Advertisement Banner details has been modified successfully.";
            #region Delete Image
            if (ViewState["img"] != null && ViewState["img"].ToString() != "" && filename != "" && ViewState["img"].ToString() != filename)
            {
                try
                {
                    if (File.Exists(DAL.GetRootPath() + "\\webfiles\\teaser\\" + ViewState["img"].ToString()))
                    {
                        File.Delete(DAL.GetRootPath() + "\\webfiles\\teaser\\" + ViewState["img"].ToString());
                    }
                }
                catch (Exception ex)
                {
                    // do nothing
                }
            }
            #endregion
        }

        Response.Redirect("viewadvt.aspx?msg=" + msg);
    }
    protected void btn_Submit_Click(object sender, EventArgs e)
    {
        if (txtSellPrice.Text == "")
        {
            txtSellPrice.Text = txtCostPrice.Text;
        }
        if (txtPerweek.Text == "")
        {
            txtPerweek.Text = "0";
        }
        if (txtCostPrice.Text != "" && txtSellPrice.Text != "")
        {
            if (double.Parse(txtCostPrice.Text) < double.Parse(txtSellPrice.Text))
            {
                ScriptManager.RegisterStartupScript(this, this.GetType(), "ShowPopup", "toastr.error('Sell Price Cannot be greater than Cost Price.');", true);
                Detail = "active"; Image = ""; Associate = "";
                return;
            }
        }
        if (txtCostPrice.Text != "" && txtPerweek.Text != "")
        {
            if (double.Parse(txtCostPrice.Text) < double.Parse(txtPerweek.Text))
            {
                ScriptManager.RegisterStartupScript(this, this.GetType(), "ShowPopup", "toastr.error('Per Week Price Cannot be greater than Cost Price.');", true);
                Detail = "active"; Image = ""; Associate = "";
                return;
            }
        }
        if (txtSellPrice.Text != "" && txtPerweek.Text != "")
        {
            if (double.Parse(txtSellPrice.Text) < double.Parse(txtPerweek.Text))
            {
                ScriptManager.RegisterStartupScript(this, this.GetType(), "ShowPopup", "toastr.error('Per Week Price Cannot be greater than Sell Price.');", true);
                Detail = "active"; Image = ""; Associate = "";
                return;
            }
        }
        string filename = ""; int sortorder = 1;

        if (DAL.IsNumeric(Request.QueryString["id"]))
        {
            filename = ViewState["img"].ToString();
        }
        #region Resize Image

        if (fulp.HasFile)
        {
            if (fulp.PostedFile.ContentLength > (1048576 * int.Parse(ConfigurationManager.AppSettings["ImageSize"].ToString())))
            {
                ScriptManager.RegisterStartupScript(this, this.GetType(), "ShowPopup", "toastr.error('Image size have exceeded the maximum size limit. Please upload image below " + ConfigurationManager.AppSettings["ImageSize"].ToString() + " MB size.');", true);
                Detail = "active"; Image = ""; Associate = "";
                return;
            }

            //filename = DateTime.Now.ToString("ddmmyyyyhhmmss") + fulp.FileName.ToString().Replace(" ", "-").Replace("&", "-").Replace("/", "-").Replace("<", "").Replace("<", "").Replace("'", "").Replace("#", "");
            Bitmap uploadedImage = new Bitmap(fulp.FileContent);
            if (uploadedImage.Width >= Convert.ToInt16(ConfigurationManager.AppSettings["ProductImgWidth"].ToString()) && uploadedImage.Height >= Convert.ToInt16(ConfigurationManager.AppSettings["ProductImgHeight"].ToString()))
            {
                FileInfo FILE = new FileInfo(fulp.FileName);
                filename = DAL.FormateText(txtTitle.Text.Replace("\"", "")) + "-" + DateTime.Now.ToString("ssms") + FILE.Extension;
                imageresize imgrez    = new imageresize();
                int         maxWidth  = int.Parse(ConfigurationManager.AppSettings["ProductSmallImgWidth"].ToString());
                int         maxHeight = int.Parse(ConfigurationManager.AppSettings["ProductSmallImgHeight"].ToString());
                imgrez.GetScaledPicture(uploadedImage, maxWidth, maxHeight, "product", "small", filename);

                maxWidth  = int.Parse(ConfigurationManager.AppSettings["ProductImgWidth"].ToString());
                maxHeight = int.Parse(ConfigurationManager.AppSettings["ProductImgHeight"].ToString());
                imgrez.GetScaledPicture(uploadedImage, maxWidth, maxHeight, "product", "medium", filename);

                uploadedImage.Save(WorkingDirectory + "product\\large\\" + filename);
            }
            else
            {
                ScriptManager.RegisterStartupScript(this, this.GetType(), "ShowPopup", "toastr.error('Deal & Offers image width and height should be greater than " + ConfigurationManager.AppSettings["ProductImgHeight"].ToString() + "px and " + ConfigurationManager.AppSettings["ProductImgWidth"].ToString() + "px');", true);
                Detail = "active"; Image = ""; Associate = "";
                return;
            }

            if (ViewState["img"] != null)
            {
                if (ViewState["img"].ToString() != "")
                {
                    try
                    {
                        if (System.IO.File.Exists(DAL.GetRootPath() + "\\webfiles\\product\\small\\" + ViewState["img"].ToString()))
                        {
                            System.IO.File.Delete((DAL.GetRootPath() + "\\webfiles\\product\\small\\" + ViewState["img"].ToString()));
                        }
                        if (System.IO.File.Exists(DAL.GetRootPath() + "\\webfiles\\product\\medium\\" + ViewState["img"].ToString()))
                        {
                            System.IO.File.Delete((DAL.GetRootPath() + "\\webfiles\\product\\medium\\" + ViewState["img"].ToString()));
                        }
                        if (System.IO.File.Exists(DAL.GetRootPath() + "\\webfiles\\product\\large\\" + ViewState["img"].ToString()))
                        {
                            System.IO.File.Delete((DAL.GetRootPath() + "\\webfiles\\product\\large\\" + ViewState["img"].ToString()));
                        }
                    }
                    catch (Exception ex)
                    { }
                }
            }
        }

        #endregion
        if (!DAL.IsNumeric(Request.QueryString["id"]))
        {
            string code = (new DAL()).ExecuteScalar("Select count(*) from deal where productcode='" + txtProductCode.Text + "'", CommandType.Text, null); // this query will fetch the maximum display order number from db
            if (code != "0")
            {
                ScriptManager.RegisterStartupScript(this, this.GetType(), "ShowPopup", "toastr.error('Deal & Offers Code already used.');", true);
                Detail = "active"; Image = ""; Associate = "";
                return;
            }

            #region ManageSortOrder

            string maxnum = (new DAL()).ExecuteScalar("Select max(sortorder) from Product where catid=" + ddl_Category.SelectedValue.ToString() + "", CommandType.Text, null); // this query will fetch the maximum display order number from db
            if (maxnum != null && maxnum != "")
            {
                sortorder = int.Parse(maxnum.ToString()) + 1;
            }
            #endregion
            strQuery  = "insert into deal(Visible,featured,Title,productcode,catid,image,costprice,sellprice,description,Perweek,sortorder,AddedDate,AddedIp) ";
            strQuery += "values('" + rbl_Visible.SelectedValue.ToString() + "',";
            strQuery += "'" + rblFeatured.SelectedValue.ToString() + "','" + txtTitle.Text.Replace("'", "''") + "',";
            strQuery += "'" + txtProductCode.Text.Replace("'", "''") + "','" + ddl_Category.SelectedValue.ToString() + "','" + filename + "',";
            strQuery += "" + txtCostPrice.Text.Replace("'", "''") + "," + txtSellPrice.Text.Replace("'", "''") + ",";
            strQuery += "'" + Editor_Description.Text.Replace("'", "''") + "','" + txtPerweek.Text.Replace("'", "''") + "'," + sortorder + ",'" + DAL.GetDateWithFormat() + "','" + DAL.getIP() + "')";
            (new DAL()).ExecuteNonQuery(strQuery, CommandType.Text, null);
            msg = "Deal and Offers details has been added successully.";
            Response.Redirect("viewProduct.aspx?msg=" + msg);
        }
        else
        {
            string code = (new DAL()).ExecuteScalar("Select count(*) from deal where id<>" + Request.QueryString["id"].ToString() + " and productcode='" + txtProductCode.Text + "'", CommandType.Text, null); // this query will fetch the maximum display order number from db
            if (code != "0")
            {
                ScriptManager.RegisterStartupScript(this, this.GetType(), "ShowPopup", "toastr.error('Deal & Offers Code already used.');", true);
                Detail = "active"; Image = ""; Associate = "";
                return;
            }
            strQuery  = "update deal set Visible='" + rbl_Visible.SelectedValue.ToString() + "',";
            strQuery += "featured='" + rblFeatured.SelectedValue.ToString() + "',image='" + filename + "',Title='" + txtTitle.Text.Replace("'", "''") + "',";
            strQuery += "productcode='" + txtProductCode.Text.Replace("'", "''") + "',catid='" + ddl_Category.SelectedValue.ToString() + "',";
            strQuery += "costprice=" + txtCostPrice.Text.Replace("'", "''") + ",sellprice=" + txtSellPrice.Text.Replace("'", "''") + ",";
            strQuery += "description='" + Editor_Description.Text.Replace("'", "''") + "',Perweek='" + txtPerweek.Text.Replace("'", "''") + "',";
            strQuery += "ModifyDate='" + DAL.GetDateWithFormat() + "',ModifyIp='" + DAL.getIP() + "' where id=" + Request.QueryString["id"].ToString();

            #region check category sort order
            if ((ViewState["catid"] != null && ViewState["catid"].ToString() != ddl_Category.SelectedValue.ToString()))
            {
                string strQuery1 = "update deal set sortorder=sortorder-1 where Catid=" + ViewState["catid"].ToString() + " and sortorder>" + ViewState["sortorder"].ToString();
                new DAL().ExecuteNonQuery(strQuery1, CommandType.Text, null);

                string maxnum = (new DAL()).ExecuteScalar("Select max(sortorder) from deal where Catid=" + ddl_Category.SelectedValue.ToString() + " and id<>" + Request.QueryString["id"].ToString(), CommandType.Text, null); // this query will fetch the maximum display order number from db
                if (maxnum != null && maxnum != "")
                {
                    sortorder = int.Parse(maxnum.ToString()) + 1;
                }

                strQuery1 = "update deal set sortorder=" + sortorder + " where id=" + Request.QueryString["id"].ToString();
                new DAL().ExecuteNonQuery(strQuery1, CommandType.Text, null);
            }

            #endregion

            (new DAL()).ExecuteNonQuery(strQuery, CommandType.Text, null);
            msg = "Deal and Offers details has been modified successfully.";
            Response.Redirect("viewProduct.aspx?msg=" + msg);
        }
    }
Esempio n. 5
0
    protected void btn_Submit_Click(object sender, EventArgs e)
    {
        int sortorder = 1;

        try
        {
            #region Resize Image For Website

            if (DAL.IsNumeric(Request.QueryString["id"]))
            {
                filename = ViewState["img"].ToString();
            }

            if (FUplarge.HasFile)
            {
                if (FUplarge.PostedFile.ContentLength > (1048576 * int.Parse(ConfigurationManager.AppSettings["ImageSize"].ToString())))
                {
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "ShowPopup", "toastr.error('Image size have exceeded the maximum size limit. Please upload large image below " + ConfigurationManager.AppSettings["Gallerylimittext"].ToString() + " MB size.');", true);
                    return;
                }
                Bitmap uploadedImage = new Bitmap(FUplarge.FileContent);

                if (uploadedImage.Width >= Convert.ToInt16(ConfigurationManager.AppSettings["PhotosmallWidth"].ToString()) && uploadedImage.Height >= Convert.ToInt16(ConfigurationManager.AppSettings["PhotosmallHeight"].ToString()))
                {
                    filename = DateTime.Now.ToString("ddmmyyyyhhmmss") + FUplarge.FileName.ToString();
                    filename = filename.Trim().Replace("(", "").Replace(")", "").Replace("[", "").Replace("]", "").Replace("#", "").Replace("$", "").Replace("%", "").Replace("@", "").Replace("&", "").Replace("'", "").Replace(" ", "");
                    imageresize imgrez    = new imageresize();
                    int         maxWidth  = int.Parse(ConfigurationManager.AppSettings["PhotoLargeWidth"].ToString());
                    int         maxHeight = int.Parse(ConfigurationManager.AppSettings["PhotoLargeHeight"].ToString());
                    imgrez.GetScaledPicture(uploadedImage, maxWidth, maxHeight, "photogallery", "large", filename);

                    maxWidth  = int.Parse(ConfigurationManager.AppSettings["PhotosmallWidth"].ToString());
                    maxHeight = int.Parse(ConfigurationManager.AppSettings["PhotosmallHeight"].ToString());
                    imgrez.GetScaledPicture(uploadedImage, maxWidth, maxHeight, "photogallery", "medium", filename);
                }
                else
                {
                    ltrmessageimage.Visible = true;
                    ltrmessageimage.Text    = "Photo image width and height should greater than " + ConfigurationManager.AppSettings["PhotosmallWidth"].ToString() + " and " + ConfigurationManager.AppSettings["PhotosmallHeight"].ToString() + "";
                    return;
                }
            }
            #endregion



            if (!DAL.IsNumeric(Request.QueryString["id"]))
            {
                #region ManageSortOrder

                object maxnum = (new DAL()).ExecuteScalar("Select max(sortorder) from PhotoGallery where catid= " + ddl_Category.SelectedValue, CommandType.Text, null); // this query will fetch the maximum display order number from db
                if (maxnum != null && maxnum.ToString() != "")
                {
                    sortorder = int.Parse(maxnum.ToString()) + 1;
                }

                #endregion

                strQuery = "insert into PhotoGallery(Catid,Visible,Image,Title,AddedDate,AddedIp,sortorder,contenttype) values(" + ddl_Category.SelectedValue.ToString() + "," + rbl_Visible.SelectedValue.ToString() + ",'" + filename.Replace("'", "''") + "','" + tbx_Title.Text.Replace("'", "''") + "','" + DAL.GetDateWithFormat() + "','" + DAL.getIP() + "'," + sortorder + ",1)";
                msg      = "Photo information has been added successfully.";
                (new DAL()).ExecuteNonQuery(strQuery, CommandType.Text, null);
            }
            else
            {
                strQuery = "update PhotoGallery set Catid='" + ddl_Category.SelectedValue.ToString() + "',Visible=" + rbl_Visible.SelectedValue.ToString() + ",Image='" + filename.Replace("'", "''") + "',title='" + tbx_Title.Text.Replace("'", "''") + "',ModifyDate='" + DAL.GetDateWithFormat() + "',ModifyIp='" + DAL.getIP() + "' where id=" + Request.QueryString["id"].ToString();
                msg      = "Photo information has been modified successfully.";
                (new DAL()).ExecuteNonQuery(strQuery, CommandType.Text, null);
                #region check category sort order
                if (ViewState["catid"] != null && ViewState["catid"].ToString() != ddl_Category.SelectedValue.ToString())
                {
                    strQuery = "update PhotoGallery set sortorder=sortorder-1 where Catid=" + ViewState["catid"].ToString() + " and sortorder>" + ViewState["sortorder"].ToString();
                    new DAL().ExecuteNonQuery(strQuery, CommandType.Text, null);

                    string maxnum = (new DAL()).ExecuteScalar("Select max(sortorder) from PhotoGallery where Catid=" + ddl_Category.SelectedValue.ToString() + " and id<>" + Request.QueryString["id"].ToString(), CommandType.Text, null); // this query will fetch the maximum display order number from db
                    if (maxnum != null && maxnum != "")
                    {
                        sortorder = int.Parse(maxnum.ToString()) + 1;
                    }

                    strQuery = "update PhotoGallery set sortorder=" + sortorder + " where id=" + Request.QueryString["id"].ToString();
                    new DAL().ExecuteNonQuery(strQuery, CommandType.Text, null);
                }
                #endregion
                #region Delete Image
                if (ViewState["img"] != null && ViewState["img"].ToString() != "" && filename != "" && ViewState["img"].ToString() != filename)
                {
                    try
                    {
                        if (File.Exists(DAL.GetRootPath() + "\\webfiles\\photogallery\\large\\" + ViewState["img"].ToString()))
                        {
                            File.Delete(DAL.GetRootPath() + "\\webfiles\\photogallery\\large\\" + ViewState["img"].ToString());
                        }

                        if (File.Exists(DAL.GetRootPath() + "\\webfiles\\photogallery\\medium\\" + ViewState["img"].ToString()))
                        {
                            File.Delete(DAL.GetRootPath() + "\\webfiles\\photogallery\\medium\\" + ViewState["img"].ToString());
                        }
                    }
                    catch (Exception ex)
                    {
                        // do nothing
                    }
                }
                #endregion
            }
            msg = "Photo information has been modified successfully.";
            Response.Redirect("viewgallery.aspx?msg=" + msg + "&tab=2");
        }
        catch (Exception ex)
        {
            Response.Write(ex.Message + "==" + ex.StackTrace);
        }
    }