Ejemplo n.º 1
0
        protected void btnSave_Click(object sender, EventArgs e)   // Anand :- UspDMLMenuMaster
        {
            try
            {
                if (drpMenuCategory.SelectedValue == "0")
                {
                    ScriptManager.RegisterStartupScript(this, typeof(Page), "message", "alert('Please Select Menu Category!!')", true);
                }
                else
                {
                    SqlCommand     t_SQLCmd      = new SqlCommand();
                    byte[]         t_Image       = new byte[fileMenu.PostedFile.ContentLength];
                    HttpPostedFile t_ImageReader = fileMenu.PostedFile;

                    t_ImageReader.InputStream.Read(t_Image, 0, (int)fileMenu.PostedFile.ContentLength);

                    objMenuSchema.MenuName           = txtMenuName.Text;
                    objMenuSchema.MenuName_LL        = txtMenuName_LL.Text;
                    objMenuSchema.MenuName_UL        = txtMenuName_UL.Text;
                    objMenuSchema.IsNewflag          = chkIsNew.Checked;
                    objMenuSchema.Active             = chkActive.Checked;
                    objMenuSchema.IsEternalLink      = chkNewTab.Checked;
                    objMenuSchema.MetaDescription    = txtMDesc.Text;
                    objMenuSchema.MetaDescription_LL = txtMDesc_LL.Text;
                    objMenuSchema.MetaDescription_UL = txtMDesc_UL.Text;
                    objMenuSchema.MetaKeywords       = txtMKeywords.Text;
                    objMenuSchema.MetaKeywords_LL    = txtMKeyWords_LL.Text;
                    objMenuSchema.MetaKeywords_UL    = txtMKeyWords_UL.Text;
                    objMenuSchema.MenuImage          = t_Image;
                    objMenuSchema.SequenceNo         = Convert.ToInt32(txtSequence.Text);
                    objMenuSchema.MenuCategory       = drpMenuCategory.SelectedValue;
                    objMenuSchema.MenuType           = Convert.ToInt32(drpMenuType.SelectedValue);
                    objMenuSchema.MenuTypeValue      = txtMTValue.Text;

                    if (drpMenu.SelectedValue != "0")
                    {
                        if (drpSubMenu.SelectedValue != "0" && drpSubMenu.SelectedValue.Trim() != "")
                        {
                            objMenuSchema.Parentid = Convert.ToInt32(drpSubMenu.SelectedValue);
                        }
                        else
                        {
                            objMenuSchema.Parentid = Convert.ToInt32(drpMenu.SelectedValue);
                        }
                    }
                    else
                    {
                        objMenuSchema.Parentid = Convert.ToInt32(drpMenu.SelectedValue);
                    }

                    //t_SQLCmd.Parameters.Add("@RoleID", SqlDbType.UniqueIdentifier);
                    //t_SQLCmd.Parameters["@RoleID"].Value = DBNull.Value;

                    //t_SQLCmd.Parameters.Add("@CreatedBy", SqlDbType.Int);
                    //t_SQLCmd.Parameters["@CreatedBy"].Value = DBNull.Value;

                    objMenuSchema.PageHeading      = txtPageHead.Text;
                    objMenuSchema.PageHeading_LL   = txtPageHead_LL.Text;
                    objMenuSchema.PageHeading_UL   = txtPageHead_UL.Text;
                    objMenuSchema.PageTitle        = txtPageTitle.Text;
                    objMenuSchema.PageTitle_LL     = txtPageTitle_LL.Text;
                    objMenuSchema.PageTitle_UL     = txtPageTitle_UL.Text;
                    objMenuSchema.ForMobileVersion = chkmobileversion.Checked;

                    if (Request.QueryString["action"] == "edit")
                    {
                        valueid = Request.QueryString["shvid"];
                        //t_SQLCmd.Parameters.Add("@MenuID", SqlDbType.Int);
                        //t_SQLCmd.Parameters["@MenuID"].Value = valueid;
                        objMenuSchema.Menuid = Convert.ToInt32(valueid);
                        if (fileMenu.HasFile)
                        {
                            string filenameExt = fileMenu.FileName;
                            string fileExt     = System.IO.Path.GetExtension(fileMenu.FileName);
                            objMenuSchema.FileExt = fileExt;
                            if (fileExt == ".jpeg" || fileExt == ".jpg" || fileExt == ".PNG" || fileExt == ".png" || fileExt == ".bmp" || fileExt == ".tiff")
                            {
                                if (CommonFuntion.check_Extensions(filenameExt))
                                {
                                    Stream fs = null;
                                    fs = fileMenu.PostedFile.InputStream;
                                    BinaryReader br1       = new BinaryReader(fs);
                                    byte[]       filebytes = fileMenu.FileBytes;
                                    if (CommonFuntion.isValidFile(filebytes, CommonFuntion.FileType.Image, fileMenu.PostedFile.ContentType))
                                    {
                                        String ext       = fileMenu.FileName;
                                        String extention = ext.Substring(ext.IndexOf(".") + 1, 3);
                                        if (extention.ToLower() == "jpg" || extention.ToLower() == "jpeg" || extention.ToLower() == "bmp" || extention.ToLower() == "gif" || extention.ToLower() == "png")
                                        {
                                            objMenuSchema.ActionType = "edit";
                                            result = ObjmenuBL.SaveMenuDeatails(objMenuSchema);
                                            if (result != 0)
                                            {
                                                Clear();
                                                lblerror.Text = "";
                                                ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('Data saved Successfully !!!');window.location.href='MenuList.aspx'", true);
                                            }
                                            else
                                            {
                                                ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('Error !!!')", true);
                                            }
                                        }
                                    }
                                    else
                                    {
                                        lblerror.Text = "Please Upload Image File only";
                                    }
                                }
                                else
                                {
                                    lblerror.Text = "Please Upload Image File only";
                                }
                            }
                            else
                            {
                                lblerror.Text = "Please Upload Image File only";
                            }
                        }
                        else
                        {
                            objMenuSchema.ActionType = "edit";
                            result = ObjmenuBL.SaveMenuDeatails(objMenuSchema);
                            if (result != 0)
                            {
                                Clear();
                                lblerror.Text = "";
                                ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('Data saved Successfully !!!');window.location.href='MenuList.aspx'", true);
                            }
                            else
                            {
                                ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('Error !!!')", true);
                            }
                        }
                    }
                    else
                    {
                        if (fileMenu.HasFile)
                        {
                            Stream fs = null;
                            fs = fileMenu.PostedFile.InputStream;
                            BinaryReader br          = new BinaryReader(fs);
                            string       filenameExt = fileMenu.FileName;

                            string fileExt = System.IO.Path.GetExtension(fileMenu.FileName);
                            objMenuSchema.FileExt = fileExt;
                            if (fileExt == ".jpeg" || fileExt == ".jpg" || fileExt == ".PNG" || fileExt == ".png" || fileExt == ".bmp" || fileExt == ".tiff")
                            {
                                byte[] pdffile = fileMenu.FileBytes;
                                if (CommonFuntion.check_Extensions(filenameExt))
                                {
                                    if (CommonFuntion.isValidFile(pdffile, CommonFuntion.FileType.Image, fileMenu.PostedFile.ContentType))
                                    {
                                        String ext       = fileMenu.FileName;
                                        String extention = ext.Substring(ext.IndexOf(".") + 1, 3);
                                        if (extention.ToLower() == "jpg" || extention.ToLower() == "jpeg" || extention.ToLower() == "bmp" || extention.ToLower() == "gif" || extention.ToLower() == "png")
                                        {
                                            objMenuSchema.ActionType = "Insert";
                                            result = ObjmenuBL.SaveMenuDeatails(objMenuSchema);
                                            if (result != 0)
                                            {
                                                Clear();
                                                lblerror.Text = "";
                                                ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('Data saved Successfully !!!');window.location.href='MenuList.aspx'", true);
                                            }
                                            else
                                            {
                                                ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('Error !!!')", true);
                                            }
                                        }
                                    }
                                    else
                                    {
                                        lblerror.Text = "Please Upload Image File only";
                                    }
                                }
                                else
                                {
                                    lblerror.Text = "Please Upload Image File only";
                                }
                            }
                            else
                            {
                                lblerror.Text = "Please Upload Image File only";
                            }
                        }
                        else
                        {
                            objMenuSchema.ActionType = "Insert";
                            result = ObjmenuBL.SaveMenuDeatails(objMenuSchema);
                            if (result != 0)
                            {
                                Clear();
                                lblerror.Text = "";
                                ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('Data saved Successfully !!!');window.location.href='MenuList.aspx'", true);
                            }
                            else
                            {
                                ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('Error !!!')", true);
                            }
                        }
                    }
                }
            }
            catch (Exception ee)
            { throw ee; }
        }