Friday, 22 February 2013

Image insert Into Textbox and button Not Using File Upload Control




 Databasee re Field Datatype =Image
 string CurrentFileName;
private void BtnBrowse_Click(object sender, EventArgs e)
        {
            try
            {
                OpenFileDialog open = new OpenFileDialog();
                open.Filter = "Image Files(*.jpg; *.jpeg; *.gif; *.bmp)|*.jpg; *.jpeg; *.gif; *.bmp";

                if (open.ShowDialog() == DialogResult.OK)
                {
                    PictureBoxDesign.Image = new Bitmap(open.FileName);
                    TxtDesignImage.Text = open.FileName;
                    CurrentFileName = open.SafeFileName;
                }
            }
            catch (Exception)
            {
                throw new ApplicationException("Image loading error....");
            }
        }

   private void RemoveImage()
        {
            string GetImage = (System.Environment.CurrentDirectory);
            GetImage = GetImage.Substring(0, GetImage.Length - GetImage.StartsWith("bin").ToString().Length - 4);

            GetImage += "ItemImage\\" + DGVMenu.CurrentRow.Cells[4].Value.ToString();
            if (DGVMenu.CurrentRow.Cells[4].Value.ToString() != null)
            {
                System.IO.File.Delete(GetImage);
            }
        }

   private void btnSave_Click(object sender, EventArgs e)
        {
   if (checkData() == true)
                {
                    if (checkDuplicateSave() == true)
                    {
                        if (menuid == 0)
                        {
                            TAGGING_Menu objMenu = new TAGGING_Menu();
                            objMenu.Menu_Name = TxtMenu.Text.Trim();
                            objMenu.Menu_Text = TxtMenuText.Text.Trim();
                            objMenu.Parent_Menu_ID = ParentMenuID;
                            objMenu.Sequence = int.Parse(CmbSequence.SelectedItem.ToString());
                            objMenu.Page_Name = TxtPageName.Text.Trim();
                            //------------Code For Save The Image -------------------------
                            if (TxtDesignImage.Text != "")
                            {
                                if (CurrentFileName != "" || CurrentFileName != null)
                                {
                                    if (CurrentFileName != TxtDesignImage.Text)
                                    {
                                        String sBLOBFilePath = TxtDesignImage.Text;
                                        FileStream fsBLOBFile = new FileStream(sBLOBFilePath, FileMode.Open, FileAccess.Read);
                                        Byte[] bytBLOBData = new Byte[fsBLOBFile.Length];
                                        fsBLOBFile.Read(bytBLOBData, 0, bytBLOBData.Length);
                                        fsBLOBFile.Close();
                                        objMenu.Icon = bytBLOBData;
                                    }
                                }
                            }
                            //------------End of Code For Save The Image ------------------
                            if (ChkStatus.Checked)
                            {
                                objMenu.Status = true;
                            }
                            else
                            {
                                objMenu.Status = false;
                            }
                            objMenu.Created_By = 1;
                            ERPManagement.GetInstance.InsertMenu(objMenu);
                            MessageBox.Show("Data saved successfully.", "KenCloud", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            fillGrid();
                            Reset();
                        }

}

No comments:

Post a Comment