Esempio n. 1
0
        //------------------------------------------------------------------------------------

        protected void lvItems_ItemDataBound(object sender, ListViewItemEventArgs e)
        {
            ListViewDataItem lv = e.Item as ListViewDataItem;

            EF.ImportedPod ip = lv.DataItem as EF.ImportedPod;

            System.Web.UI.HtmlControls.HtmlAnchor imageFile =
                lv.FindControl("ancImage") as System.Web.UI.HtmlControls.HtmlAnchor;

            System.Web.UI.HtmlControls.HtmlInputCheckBox chkDelete =
                lv.FindControl("chkDelete") as System.Web.UI.HtmlControls.HtmlInputCheckBox;

            if (lv.ItemType == ListViewItemType.DataItem)
            {
                // ImportedPods is the virtual directory. if this is not working make sure the virtual directory is present
                if (chkDelete != null && ip != null)
                {
                    chkDelete.Attributes.Add("ImportedPodId", ip.ImportedPodId.ToString());
                }

                if (imageFile != null && ip != null)
                {
                    string virtualPath = Server.MapPath("~/ImportedPods");
                    string actualPath  = "/ImportedPods" + Path.Combine(ip.ImageFolder.Replace(virtualPath, ""), ip.ImageName);
                    imageFile.HRef = actualPath;
                }
            }
        }
Esempio n. 2
0
        //------------------------------------------------------------------------------------

        protected void btnUpdateOrderIds_Click(object sender, EventArgs e)
        {
            // find the imported pods marked for deletion
            foreach (ListViewDataItem lv in this.lvItems.Items)
            {
                if (lv.ItemType == ListViewItemType.DataItem)
                {
                    HiddenField isDirty  = lv.FindControl("hidRowDirty") as HiddenField;
                    TextBox     txtOrder = lv.FindControl("txtOrderId") as TextBox;
                    // we need to grab the chkDelete control as it holds the ImportedPodId
                    System.Web.UI.HtmlControls.HtmlInputCheckBox chkDelete = lv.FindControl("chkDelete") as System.Web.UI.HtmlControls.HtmlInputCheckBox;

                    if (chkDelete != null && isDirty != null && isDirty.Value.ToUpper() == "TRUE")
                    {
                        int importedPodId = 0;
                        int.TryParse(chkDelete.Attributes["ImportedPodId"], out importedPodId);

                        EF.ImportedPod importedPod = (from ip in EF.DataContext.Current.ImportedPodSet
                                                      where ip.ImportedPodId == importedPodId
                                                      select ip).FirstOrDefault();

                        if (importedPod != null)
                        {
                            importedPod.OrderId           = txtOrder.Text;
                            importedPod.LastUpdatedDate   = DateTime.Now;
                            importedPod.LastUpdatedUserId = Page.User.Identity.Name;
                            EF.DataContext.Current.SaveChanges();
                        }
                    }
                }
            }

            this.RebindGrid();
        }
Esempio n. 3
0
        //------------------------------------------------------------------------------------

        protected void btnDelete_Click(object sender, EventArgs e)
        {
            // find the imported pods marked for deletion
            foreach (ListViewDataItem lv in this.lvItems.Items)
            {
                if (lv.ItemType == ListViewItemType.DataItem)
                {
                    System.Web.UI.HtmlControls.HtmlInputCheckBox chkDelete = lv.FindControl("chkDelete") as System.Web.UI.HtmlControls.HtmlInputCheckBox;

                    if (chkDelete != null && chkDelete.Checked)
                    {
                        int importedPodId = 0;
                        int.TryParse(chkDelete.Attributes["ImportedPodId"], out importedPodId);

                        EF.ImportedPod importedPod = (from ip in EF.DataContext.Current.ImportedPodSet
                                                      where ip.ImportedPodId == importedPodId
                                                      select ip).FirstOrDefault();

                        if (importedPod != null)
                        {
                            try
                            {
                                // delete the accompanying file
                                if (File.Exists(Path.Combine(importedPod.ImageFolder, importedPod.ImageName)))
                                {
                                    File.Delete(Path.Combine(importedPod.ImageFolder, importedPod.ImageName));
                                }
                            }
                            catch (System.IO.IOException ioex)
                            {
                                // we can delete the row from the table even if we couldn't delete the file.
                            }

                            EF.DataContext.Current.DeleteObject(importedPod);
                        }
                    }
                }
            }

            EF.DataContext.Current.SaveChanges();
            this.RebindGrid();
        }