Exemplo n.º 1
0
        protected void bthAddCarousel_Click(object sender, EventArgs e)
        {
            lblErrorImage.Text = string.Empty;
            int sort;

            if (!CarouselLoad.HasFile)
            {
                ulValidationFailed.Visible = true;
                ulValidationFailed.InnerHtml += string.Format("<li>{0}</li>", Resource.Client_Feedback_WrongData);
                return;
            }

            if (CarouselLoad.HasFile && !FileHelpers.CheckImageExtension(CarouselLoad.FileName))
            {
                lblErrorImage.Text = Resource.Admin_ErrorMessage_WrongImageExtension;
                return;
            }

            int.TryParse(txtSortedCarousel.Text, out sort);

            if (string.IsNullOrEmpty(txtURL.Text))
                txtURL.Text = "#";

            var carousel = new Carousel { URL = txtURL.Text, SortOrder = sort, Enabled = true };
            int id = CarouselService.AddCarousel(carousel);

            try
            {
                if (CarouselLoad.HasFile)
                {
                    var tempName = PhotoService.AddPhoto(new Photo(0, id, PhotoType.Carousel) { OriginName = CarouselLoad.FileName });
                    if (!string.IsNullOrWhiteSpace(tempName))
                    {
                        using (System.Drawing.Image image = System.Drawing.Image.FromStream(CarouselLoad.PostedFile.InputStream))
                        {
                            FileHelpers.SaveResizePhotoFile(FoldersHelper.GetPathAbsolut(FolderType.Carousel, tempName), SettingsPictureSize.CarouselBigWidth, SettingsPictureSize.CarouselBigHeight, image);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Debug.LogError(ex, "Attempt to load not image file");
            }

            txtURL.Text = string.Empty;
            txtSortedCarousel.Text = string.Empty;
            Response.Redirect(UrlService.GetAdminAbsoluteLink("Carousel.aspx"));
        }
Exemplo n.º 2
0
        protected void Page_PreRender(object sender, EventArgs e)
        {
            if (grid.UpdatedRow != null)
            {
                int sortOrder = 0;
                if (int.TryParse(grid.UpdatedRow["SortOrder"], out sortOrder))
                {
                    var car = new Carousel()
                        {
                            CarouselID = SQLDataHelper.GetInt(grid.UpdatedRow["ID"]),
                            URL = grid.UpdatedRow["URL"],
                            SortOrder = sortOrder,
                            Enabled = SQLDataHelper.GetBoolean(grid.UpdatedRow["Enabled"])
                        };
                    CarouselService.UpdateCarousel(car);
                }
            }
            DataTable data = _paging.PageItems;
            while (data.Rows.Count < 1 && _paging.CurrentPageIndex > 1)
            {
                _paging.CurrentPageIndex--;
                data = _paging.PageItems;
            }

            var clmn = new DataColumn("IsSelected", typeof(bool)) { DefaultValue = _inverseSelection };
            data.Columns.Add(clmn);
            if ((_selectionFilter != null) && (_selectionFilter.Values != null))
            {
                for (int i = 0; i <= data.Rows.Count - 1; i++)
                {
                    int intIndex = i;
                    if (Array.Exists(_selectionFilter.Values, c => c == data.Rows[intIndex]["ID"].ToString()))
                    {
                        data.Rows[i]["IsSelected"] = !_inverseSelection;
                    }
                }
            }

            if (data.Rows.Count < 1)
            {
                goToPage.Visible = false;
            }

            grid.DataSource = data;
            grid.DataBind();

            pageNumberer.PageCount = _paging.PageCount;
            lblFound.Text = _paging.TotalRowsCount.ToString();
        }