Esempio n. 1
0
        public AdministrationEDSC.ActivityImageDetailDTDataTable GetImages()
        {
            if (ImageUploaded != 0)
            {
                var dt = new AdministrationEDSC.ActivityImageDetailDTDataTable();
                foreach (DataListItem item in dtImageLib.Items)
                {
                    var dr = dt.NewActivityImageDetailDTRow();
                    if (item.ItemType == ListItemType.Item || item.ItemType == ListItemType.AlternatingItem)
                    {
                        Image       imgUpload      = item.FindControl("imgUpload") as Image;
                        HiddenField hdnImageStream = item.FindControl("hdnImageStream") as HiddenField;
                        HiddenField hdnImageSize   = item.FindControl("hdnImageSize") as HiddenField;
                        HiddenField hdnID          = item.FindControl("hdnID") as HiddenField;

                        Label lblName = item.FindControl("lblName") as Label;
                        dr.ID              = Convert.ToInt32(hdnID.Value);
                        dr.ActivityID      = 0;
                        dr.ActivityImageID = 0;
                        dr.ImageStream     = Convert.FromBase64String(hdnImageStream.Value);
                        dr.Filename        = lblName.Text;
                        dr.ImageTitle      = "";
                        dr.Description     = "";
                        dr.isPrimaryImage  = false;
                        dr.Filesize        = Convert.ToInt32(hdnImageSize.Value);
                        dt.AddActivityImageDetailDTRow(dr);
                    }
                }
                return(dt);
            }
            else
            {
                return(null);
            }
        }
Esempio n. 2
0
        protected void lnkSave_Click(object sender, EventArgs e)
        {
            var dt = new AdministrationEDSC.ActivityImageDetailDTDataTable();
            AdministrationDAC dac = new AdministrationDAC();

            foreach (DataListItem item in DataList1.Items)
            {
                SetDataListItemMode(item, false);

                Label       lblImageDescription = item.FindControl("lblImageDescription") as Label;
                Label       lblImageTitle       = item.FindControl("lblImageTitle") as Label;
                TextBox     txtImageTitle       = item.FindControl("txtImageTitle") as TextBox;
                TextBox     ckImageDescription  = item.FindControl("txtImageDescription") as TextBox;
                HiddenField hdnImageID          = item.FindControl("hdnImageID") as HiddenField;
                HiddenField hdnActvityImageID   = item.FindControl("hdnImageInfoID") as HiddenField;
                HiddenField hdnFilesize         = item.FindControl("hdnFilesize") as HiddenField;
                HiddenField hdnFilename         = item.FindControl("hdnFilename") as HiddenField;
                HiddenField hdnMainImage        = item.FindControl("hdnMainImage") as HiddenField;

                var dr = dt.NewActivityImageDetailDTRow();
                dr.ID              = Convert.ToInt32(hdnImageID.Value);
                dr.ImageTitle      = txtImageTitle.Text;
                dr.Filename        = hdnFilename.Value;
                dr.isPrimaryImage  = Convert.ToBoolean(hdnMainImage.Value);
                dr.Description     = ckImageDescription.Text;
                dr.ActivityID      = Convert.ToInt32(hdnActivityID.Value);
                dr.ActivityImageID = Convert.ToInt32(hdnActvityImageID.Value);
                dr.Filesize        = Convert.ToInt32(hdnFilesize.Value);
                dt.AddActivityImageDetailDTRow(dr);
            }
            foreach (var dr in dt)
            {
                dac.UpdateActivityImage(dr);
            }

            foreach (DataListItem item in DataList1.Items)
            {
                SetDataListItemMode(item, false);
            }
            Refresh();
        }
Esempio n. 3
0
        protected void imgBtnUpload_Click(object sender, EventArgs e)
        {
            ImageUploaded = 0;
            var drInfo = new AdministrationDAC().RetrieveActivityImageInformation(ActivityID);

            CheckActivityImage();
            if (fileUpload1.HasFile)     // CHECK IF ANY FILE HAS BEEN SELECTED.
            {
                var dt = new AdministrationEDSC.ActivityImageDetailDTDataTable();
                if (System.Text.RegularExpressions.Regex.IsMatch(fileUpload1.PostedFile.ContentType, "image/\\S+"))
                {
                    int iFailedCnt         = 0;
                    HttpFileCollection hfc = Request.Files;
                    lblUploadStatus.Text = "Select <b>" + hfc.Count + "</b> file(s)";

                    if (hfc.Count <= 10)    // 10 FILES RESTRICTION.
                    {
                        for (int i = 0; i <= hfc.Count - 1; i++)
                        {
                            HttpPostedFile hpf = hfc[i];
                            if (hpf.ContentLength > 0)
                            {
                                string sFileName = Path.GetFileName(hpf.FileName);
                                string sFileExt  = Path.GetExtension(hpf.FileName);

                                SizeUploaded = SizeUploaded + Convert.ToInt32(hpf.ContentLength / 1024);
                                if (SizeUploaded <= drInfo.FreeStorage)
                                {
                                    var dr = dt.NewActivityImageDetailDTRow();

                                    dr.ActivityID      = ActivityID;
                                    dr.ActivityImageID = drInfo.ID;
                                    dr.ImageStream     = new BCUtility.ImageHandler().ReadFully(hpf.InputStream);
                                    dr.Filename        = sFileName;
                                    dr.Filesize        = hpf.ContentLength / 1024;
                                    dr.ImageTitle      = "";
                                    dr.Description     = "";
                                    dt.AddActivityImageDetailDTRow(dr);

                                    ImageUploaded += 1;
                                }
                                else
                                {
                                    iFailedCnt           += 1;
                                    lblUploadStatus.Text += "</br><b>" + iFailedCnt + "</b> file(s) could not be uploaded. Maximum Size per activity is" + SystemConstants.MaxActivityImageStorage + " Kb";
                                }
                            }
                        }

                        lblUploadStatus.Text = "<b>" + ImageUploaded + "</b> file(s) uploaded.";
                    }
                    else
                    {
                        lblUploadStatus.Text = "Max. 10 files allowed.";
                    }


                    if (ImageUploaded > 0)
                    {
                        drInfo.ImageAmount           = drInfo.ImageAmount + ImageUploaded;
                        drInfo.StorageUsed           = drInfo.StorageUsed + SizeUploaded;
                        drInfo.FreeStorage           = SystemConstants.MaxActivityImageStorage - drInfo.StorageUsed;
                        divUploadSuccessfull.Visible = true;

                        new AdministrationBFC().CreateActivityImages(ActivityID, drInfo, dt);
                    }
                }
                else
                {
                    lblUploadStatus.Text = "Only image files are accepted.";
                }
            }
            else
            {
                lblUploadStatus.Text = "No files selected.";
            }
            lblUploadStatus.Visible = true;
        }