示例#1
0
        protected void btnDelete_Click(object sender, EventArgs e)
        {
            int    id        = int.Parse(this.hdnSelectedID.Value);
            string imagePath = string.Empty;

            if (id > 0)
            {
                try
                {
                    using (TransactionScope ts = new TransactionScope())
                    {
                        EmbroideryBO objEmbroider = new EmbroideryBO(this.ObjContext);
                        objEmbroider.ID = id;
                        objEmbroider.GetObject();

                        foreach (EmbroideryDetailsBO embDetail in objEmbroider.EmbroideryDetailssWhereThisIsEmbroidery)
                        {
                            // delete Image
                            EmbroideryDetailsBO objEmbroiderDetails = new EmbroideryDetailsBO(this.ObjContext);
                            objEmbroiderDetails.ID = embDetail.ID;
                            objEmbroiderDetails.GetObject();

                            foreach (EmbroideryImageBO image in objEmbroiderDetails.EmbroideryImagesWhereThisIsEmbroideryDetails)
                            {
                                imagePath = IndicoConfiguration.AppConfiguration.DataFolderName + "/EmbroideryImages/" + "/" + image.EmbroideryDetails.ToString() + "/" + image.Filename + image.Extension;

                                if (File.Exists(Server.MapPath(imagePath)))
                                {
                                    File.Delete(Server.MapPath(imagePath));
                                }

                                EmbroideryImageBO objEmbroideryImage = new EmbroideryImageBO(this.ObjContext);
                                objEmbroideryImage.ID = image.ID;
                                objEmbroideryImage.GetObject();

                                objEmbroideryImage.Delete();
                            }

                            objEmbroiderDetails.Delete();
                        }

                        objEmbroider.Delete();

                        this.ObjContext.SaveChanges();
                        ts.Complete();
                    }
                }
                catch (Exception ex)
                {
                    IndicoLogging.log.Error("Error occured while deleting From ViewEmbriderDetails.aspx", ex);
                }
            }
            this.PopulateDataGrid();
        }
        protected void btnDleteImage_Click(object sender, EventArgs e)
        {
            int    id          = int.Parse(this.hdnEmbImage.Value);
            string imagePath   = string.Empty;
            int    embDetailID = 0;

            if (id > 0)
            {
                try
                {
                    using (TransactionScope ts = new TransactionScope())
                    {
                        EmbroideryImageBO objEmbroideryImage = new EmbroideryImageBO(this.ObjContext);
                        objEmbroideryImage.ID = id;
                        objEmbroideryImage.GetObject();

                        embDetailID = objEmbroideryImage.EmbroideryDetails;
                        imagePath   = IndicoConfiguration.AppConfiguration.DataFolderName + "/EmbroideryImages/" + "/" + objEmbroideryImage.EmbroideryDetails.ToString() + "/" + objEmbroideryImage.Filename + objEmbroideryImage.Extension;

                        if (File.Exists(Server.MapPath(imagePath)))
                        {
                            File.Delete(Server.MapPath(imagePath));
                        }

                        objEmbroideryImage.Delete();

                        this.ObjContext.SaveChanges();
                        ts.Complete();
                    }
                }
                catch (Exception ex)
                {
                    IndicoLogging.log.Error("Error occured while deleting Embroidery Image AddEditEmbroidery.aspx Page", ex);
                }
            }

            this.hdnUploadFiles.Value   = string.Empty;
            this.hdnUploadFiles_1.Value = string.Empty;
            PopulateEmbroideryImage(embDetailID);
            ViewState["isCompareImage"] = false;
        }