示例#1
0
        private void GetData(int id)
        {
            ProductSearchEngine.EntityClasses.ProductEntity product = new EntityClasses.ProductEntity(id);
            ProductTitle              = product.Title;
            ProductTitleTextBox.Text  = product.Title;
            ProductDetailTextBox.Text = product.DetailDescription;
            ProductFreeShippingStatusRadioButtonList.SelectedIndex = (bool)product.IsFreeShipping ? 1 : 0;
            ProductNewItemStatusRadioButtonList.SelectedIndex      = (bool)product.IsNewItem ? 1 : 0;
            ProductRedirectUrlTextBox.Text = product.RedirectUrl;
            ProductPriceTextBox.Text       = product.Price.ToString();


            CategoryDropDownList.DataSource     = new ProductSearchEngine.Business.Adapters.CategoryAdapter().GetMainCategories();
            CategoryDropDownList.DataTextField  = "Name";
            CategoryDropDownList.DataValueField = "Id";
            CategoryDropDownList.DataBind();

            CategoryDropDownList.Items.FindByValue(((int)new ProductSearchEngine.Business.Adapters.CategoryAdapter().GetMainCatehoryIdBySubCategoryId((int)product.CategoryId)).ToString()).Selected = true;
            CategoryDropDownList_DataBound();
            ListItem liSubCategory = SubCategoryDropDownList.Items.FindByValue(product.CategoryId.ToString());

            if (liSubCategory != null)
            {
                liSubCategory.Selected = true;
            }
            BrandDropDownList.DataSource     = new ProductSearchEngine.Business.Adapters.BrandAdapter().GetBrandList();
            BrandDropDownList.DataTextField  = "Name";
            BrandDropDownList.DataValueField = "Id";
            BrandDropDownList.DataBind();

            ListItem li = BrandDropDownList.Items.FindByValue(product.BrandId.ToString());

            if (li != null)
            {
                li.Selected = true;
            }

            ProductPhotosRepeater.DataSource = product.ProductPhotos;
            ProductPhotosRepeater.DataBind();

            ProductSpecificationsRepeater.DataSource = product.ProductSpecifications;
            ProductSpecificationsRepeater.DataBind();

            ProductKeywordRepeater.DataSource = product.ProductKeywords;
            ProductKeywordRepeater.DataBind();
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                CategoryDropDownList.DataSource     = categoryManager.GetAllCategory();
                CategoryDropDownList.DataTextField  = "Name";
                CategoryDropDownList.DataValueField = "Id";
                CategoryDropDownList.DataBind();
                CategoryDropDownList.Items.Insert(0, new ListItem("--Select Item--", "0"));


                CompanyDropDownList.DataSource     = companyManager.GetAllCompany();
                CompanyDropDownList.DataTextField  = "Name";
                CompanyDropDownList.DataValueField = "Id";
                CompanyDropDownList.DataBind();
                CompanyDropDownList.Items.Insert(0, new ListItem("--Select Item--", "0"));
            }
        }
示例#3
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                int id = int.TryParse(Request.QueryString["Id"], out int result) ? result : 0;

                JSONReadWrite  readWrite  = new JSONReadWrite();
                string         jsonString = readWrite.Read("products.json", "Data");
                List <Product> products   = JsonConvert.DeserializeObject <List <Product> >(jsonString);

                Product product = products.Where(p => p.ProductId == id).FirstOrDefault();

                if (product == null)
                {
                    Response.Redirect("/Views/Products/ProductsPage.aspx");
                }

                ProductIdField.Value           = product.ProductId.ToString();
                ProductNameTextBox.Text        = product.Title;
                ProductDescriptionTextBox.Text = product.Description;
                PriceTextBox.Text = product.Price.ToString();

                var categories    = products.GroupBy(g => g.Category.CategoryId).Select(s => s.FirstOrDefault().Category).ToList();
                var suppliers     = products.GroupBy(g => g.Supplier.SupplierId).Select(s => s.FirstOrDefault().Supplier).ToList();
                var manufacturers = products.GroupBy(g => g.Manufacturer.ManufacturerId).Select(s => s.FirstOrDefault().Manufacturer).ToList();

                CategoryDropDownList.DataSource    = categories;
                CategoryDropDownList.SelectedValue = product.Category.CategoryName;
                CategoryDropDownList.DataTextField = "CategoryName";
                CategoryDropDownList.DataBind();

                SupplierDropDownList.Items.Add(" ");
                SupplierDropDownList.DataSource    = suppliers;
                SupplierDropDownList.SelectedValue = product.Supplier.SupplierName;
                SupplierDropDownList.DataTextField = "SupplierName";
                SupplierDropDownList.DataBind();

                ManufacturerDropDownList.DataSource    = manufacturers;
                ManufacturerDropDownList.SelectedValue = product.Manufacturer.ManufacturerName;
                ManufacturerDropDownList.DataTextField = "ManufacturerName";
                ManufacturerDropDownList.DataBind();
            }
        }
示例#4
0
        /// <summary>
        /// To bind category dropdownlist
        /// </summary>
        /// <param name="lastItemSelected"></param>
        protected void BindCategories(bool lastItemSelected)
        {
            BudgetEstimationBLL BudgetEstimationBLLobj = new BudgetEstimationBLL();

            CategoryDropDownList.DataSource     = BudgetEstimationBLLobj.getAllCategory();
            CategoryDropDownList.DataTextField  = "CategoryName";
            CategoryDropDownList.DataValueField = "CategoryID";
            CategoryDropDownList.DataBind();
            CategoryDropDownList.Items.Insert(0, new ListItem("--Select--", "0"));

            if (lastItemSelected)
            {
                CategoryDropDownList.Items[CategoryDropDownList.Items.Count - 1].Selected = true;
            }

            else
            {
                CategoryDropDownList.SelectedIndex = 0;
            }
        }
示例#5
0
        private void LoadData()
        {
            CategoryDropDownList.DataSource     = new ProductSearchEngine.Business.Adapters.CategoryAdapter().GetMainCategories();
            CategoryDropDownList.DataTextField  = "Name";
            CategoryDropDownList.DataValueField = "Id";
            CategoryDropDownList.DataBind();

            BrandDropDownList.DataSource     = new ProductSearchEngine.Business.Adapters.BrandAdapter().GetBrandList();
            BrandDropDownList.DataTextField  = "Name";
            BrandDropDownList.DataValueField = "Id";
            BrandDropDownList.DataBind();

            CategoryDropDownList.SelectedIndex = 0;

            SubCategoryDropDownList.DataSource     = new ProductSearchEngine.Business.Adapters.CategoryAdapter().GetSubCategories(int.Parse(CategoryDropDownList.SelectedValue));
            SubCategoryDropDownList.DataTextField  = "Name";
            SubCategoryDropDownList.DataValueField = "Id";
            SubCategoryDropDownList.DataBind();

            SubmitButton.Click += new EventHandler(SubmitButton_Click);
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            using (ProductContext context = new ProductContext())
            {
                var categories    = context.Categories.ToList();
                var suppliers     = context.Suppliers.ToList();
                var manufacturers = context.Manufacturers.ToList();

                CategoryDropDownList.DataSource    = categories;
                CategoryDropDownList.DataTextField = "CategoryName";
                CategoryDropDownList.ID            = "CategoryId";
                CategoryDropDownList.DataBind();

                SupplierDropDownList.DataSource    = suppliers;
                SupplierDropDownList.DataTextField = "SupplierName";
                SupplierDropDownList.ID            = "SupplierId";
                SupplierDropDownList.DataBind();

                ManufacturerDropDownList.DataSource    = manufacturers;
                ManufacturerDropDownList.DataTextField = "ManufacturerName";
                ManufacturerDropDownList.ID            = "ManufacturerId";
                ManufacturerDropDownList.DataBind();
            }
        }
示例#7
0
        /// <summary>
        /// Processes a list of files and passes them to the MultiAssetUploader class
        /// Files that come via the browser will not cause sub-categories to be created
        /// unless the file is a zip file in which case the paths in the zip file can be
        /// used to create sub-categories.
        /// </summary>
        /// <param name="filesToUpload">List of filenames to upload</param>
        /// <param name="saveMode">Move or Copy</param>
        /// <param name="IsBrowserUpload">Flag to indicate weather the file came via the browser</param>
        /// <param name="rootPath">The root path for directory scanning</param>
        private void ProcessUpload(IEnumerable <string> filesToUpload, BinaryFile.SaveMode saveMode, bool IsBrowserUpload, string rootPath)
        {
            ErrorList errors = new ErrorList();

            List <UploadedAssetResult> uploadResultList = null;

            rootPath = rootPath.ToLower();

            foreach (string fileName in filesToUpload)
            {
                // At this point we have a list of files containing one or more files to process.
                try
                {
                    // Wrap the uploaded file in a generic BinaryFile class for use in the business layer.
                    BinaryFile file = new BinaryFile(fileName, saveMode);

                    m_Logger.DebugFormat("Uploading file: {0}", file.FileName);

                    // Get the directory name where we're uploading from
                    string relativePath = new FileInfo(fileName).DirectoryName.ToLower();

                    // Strip out the root path if required; we don't need it for processing
                    if (!string.IsNullOrEmpty(relativePath) && !string.IsNullOrEmpty(rootPath))
                    {
                        rootPath = rootPath.Replace(rootPath, string.Empty);
                    }

                    // Initialize the asset uploader
                    MultiAssetUploader assetUploader = new MultiAssetUploader
                    {
                        BinaryFile               = file,
                        SourcePath               = IsBrowserUpload ? string.Empty : relativePath,
                        AssetTypeId              = AssetTypeDropDownList.GetSelectedId(),
                        TargetCategoryId         = CategoryDropDownList.GetSelectedId(),
                        CreateCategorySubFolders = SubFolderCheckBox.Checked,
                        UploadedBy               = CurrentUser,
                        SendEmailOnCompletion    = NotifyWhenProcessedCheckBox.Checked,
                        PreserveZipFile          = PreserveZipFileCheckBox.Checked,
                        DoNotProcessForPreview   = DoNotSubmitForPreviewCheckBox.Checked
                    };

                    assetUploader.BeforeSave += delegate(object aus, AssetEventArgs aue)
                    {
                        aue.Asset.Title             = Path.GetFileNameWithoutExtension(aue.Asset.Filename);
                        aue.Asset.Description       = "No description available";
                        aue.Asset.UsageRestrictions = string.Concat("(c) ", CurrentUser.CompanyName, " ", DateTime.Now.Year);
                    };

                    // Do the upload
                    assetUploader.Upload();

                    m_Logger.DebugFormat("Upload completed successfully");

                    // Get Processed Asset ID's
                    var processedAssetList = from uar in assetUploader.UploadedAssetResultList
                                             where (uar.FileStatus == FileStatus.Processed || (CurrentUser.UserRole == UserRole.SuperAdministrator && uar.FileStatus == FileStatus.DuplicateHash))
                                             select uar.Asset.AssetId.GetValueOrDefault();

                    // Add the assets to the session
                    foreach (int assetId in processedAssetList)
                    {
                        SessionInfo.Current.AdminSessionInfo.UploadedAssetsList.Add(assetId);
                    }

                    // Save the uploaded asset list to the logged in user
                    SiteUtils.SaveUploadedAssetListToCurrentUser();

                    // Toggle panels
                    FormPanel.Visible    = false;
                    SuccessPanel.Visible = true;

                    // Append the asset ID too, so we can jump straight to it
                    if (processedAssetList.LongCount() >= 1)
                    {
                        CatalogueAssetsHyperLink.NavigateUrl += "&AssetId=" + processedAssetList.First();
                    }

                    if (uploadResultList == null)
                    {
                        uploadResultList = assetUploader.UploadedAssetResultList;
                    }
                    else
                    {
                        uploadResultList.AddRange(assetUploader.UploadedAssetResultList);
                    }
                }
                catch (UnauthorizedAccessException uaEx)
                {
                    errors.Add(string.Format("Error uploading asset '{0}', {1}", fileName, uaEx.Message));
                }
                catch (DuplicateHashException dhex)
                {
                    // This exception will only be thrown for single asset uploads.

                    if (EntitySecurityManager.IsAssetRestricted(CurrentUser, dhex.Asset))
                    {
                        IList <Asset> list = new List <Asset> {
                            dhex.Asset
                        };
                        NotifyEngine.AssetUploadDuplicateHash(CurrentUser, list);
                    }

                    errors.Add(string.Format("Error uploading asset '{0}', {1}", fileName, dhex.Message));
                }
                catch (AssetUploadException auex)
                {
                    errors.Add(string.Format("Error uploading asset '{0}', {1}", fileName, auex.Message));
                }
                catch (InvalidAssetException iex)
                {
                    if (iex.Errors.Count > 0)
                    {
                        errors.Add(string.Format("Error uploading asset '{0}'", fileName));
                        errors.AddRange(iex.Errors);
                    }
                    else
                    {
                        errors.Add(string.Format("Error uploading asset '{0}', {1}", fileName, iex.Message));
                    }
                }
                catch (InvalidAssetFileException ifex)
                {
                    errors.Add(string.Format("Error saving asset '{0}', {1}", fileName, ifex.Message));
                }
                catch (ZipException zex)
                {
                    const string message = "An error occured";

                    string error = "It appears that the zip file is corrupt.  Please try re-creating the zip file and uploading again.";

                    if (CurrentUser.UserRole == UserRole.SuperAdministrator)
                    {
                        error += "<br /><br />" + zex;
                    }

                    errors.Add(string.Format("An error ocurred with file '{0}', {1}", fileName, error));
                    ExceptionHandler.HandleException(zex, message);
                }
                catch (Exception ex)
                {
                    const string message = "Unknown error occured when uploading asset(s)";
                    string       error   = (CurrentUser.UserRole == UserRole.SuperAdministrator) ? ex.ToString() : ex.Message;

                    errors.Add(string.Format("Unknown error occured when uploading asset '{0}', {1}", fileName, error));
                    ExceptionHandler.HandleException(ex, message);
                }
            }

            // Display errors if we have any
            if (errors.Count > 0)
            {
                MessageLabel1.SetErrorMessage("Errors occurred while uploading assets", errors);
            }

            if (uploadResultList != null && uploadResultList.Count > 0)
            {
                // Get the groups of files
                var statusList = (from result in uploadResultList
                                  select result.FileStatus).Distinct();

                // Sort the groups, push processed group to the top as this is the most important
                var sortedStatusList = from status in statusList
                                       let SortOrder = (status == FileStatus.Processed) ? 1 : 0
                                                       orderby SortOrder
                                                       select status;

                // Populate the groups with files
                var fileGroupList = from status in sortedStatusList
                                    select new FileGroup(status, from result in uploadResultList
                                                         where (result.FileStatus == status)
                                                         orderby result.Filename
                                                         select result.Filename);

                // Notify admins about any assets uploaded that were duplicates of an
                // existing asset and the upload user does not have access to that asset.
                var duplicateAssets = from result in uploadResultList
                                      where (result.FileStatus == FileStatus.DuplicateHash) && (EntitySecurityManager.IsAssetRestricted(CurrentUser, result.Asset))
                                      orderby result.Asset.AssetId
                                      select result.Asset;

                // Send the notification
                if (duplicateAssets.LongCount() > 0)
                {
                    NotifyEngine.AssetUploadDuplicateHash(CurrentUser, duplicateAssets);
                }

                // Bind the list
                UploadedFileListRepeater.DataSource = fileGroupList;
                UploadedFileListRepeater.DataBind();
            }
        }
示例#8
0
        protected void Page_Load(object sender, EventArgs e)
        {
            int    startIndex, count;
            string selectedValue = "-1";

            lnkPrevious.Visible    = false;
            lnkNext.Visible        = false;
            lblNoProducts.Visible  = false;
            lblAmountError.Visible = false;

            /* Get the Service */
            IIoCManager     iocManager     = (IIoCManager)HttpContext.Current.Application["managerIoC"];
            IProductService productService = iocManager.Resolve <IProductService>();

            /* Get Start Index */
            try
            {
                startIndex = int.Parse(Request.Params.Get("startIndex"));
            }
            catch (ArgumentNullException)
            {
                startIndex = 0;
            }

            /* Get Count */
            try
            {
                count = int.Parse(Request.Params.Get("count"));
            }
            catch (ArgumentNullException)
            {
                count = Settings.Default.PracticaMaD_defaultCount;
            }

            /* Get keyword */
            string keyword = Request.Params.Get("keyword");

            if (keyword != null)
            {
                txtSearch.Text = keyword;

                /* Get category id */
                try
                {
                    long catId = long.Parse(Request.Params.Get("category"));

                    selectedValue = Request.Params.Get("category");

                    /* Get Products Info */
                    ProductBlock productBlock = productService.FindAllProductsByKeyword(keyword, catId, startIndex, count);

                    if (productBlock.Products.Count == 0)
                    {
                        lblNoProducts.Visible = true;
                    }
                    else
                    {
                        gvProducts.DataSource = productBlock.Products;
                        gvProducts.DataBind();

                        /* "Previous" link */
                        if ((startIndex - count) >= 0)
                        {
                            string url =
                                "~/Pages/Product/ProductSearch.aspx" + "?keyword=" + keyword + "&category=" + catId +
                                "&startIndex=" + (startIndex - count) + "&count=" + count;

                            lnkPrevious.NavigateUrl = Response.ApplyAppPathModifier(url);
                            lnkPrevious.Visible     = true;
                        }

                        /* "Next" link */
                        if (productBlock.ExistMoreProducts)
                        {
                            string url =
                                "~/Pages/Product/ProductSearch.aspx" + "?keyword=" + keyword + "&category=" + catId +
                                "&startIndex=" + (startIndex + count) + "&count=" + count;

                            lnkNext.NavigateUrl = Response.ApplyAppPathModifier(url);
                            lnkNext.Visible     = true;
                        }
                    }
                }
                catch (ArgumentNullException)
                {
                    /* Get Products Info */
                    ProductBlock productBlock = productService.FindAllProductsByKeyword(keyword, startIndex, count);

                    if (productBlock.Products.Count == 0)
                    {
                        lblNoProducts.Visible = true;
                    }
                    else
                    {
                        gvProducts.DataSource = productBlock.Products;
                        gvProducts.DataBind();

                        /* "Previous" link */
                        if ((startIndex - count) >= 0)
                        {
                            string url =
                                "~/Pages/Product/ProductSearch.aspx" + "?keyword=" + keyword +
                                "&startIndex=" + (startIndex - count) + "&count=" + count;

                            lnkPrevious.NavigateUrl = Response.ApplyAppPathModifier(url);
                            lnkPrevious.Visible     = true;
                        }

                        /* "Next" link */
                        if (productBlock.ExistMoreProducts)
                        {
                            string url =
                                "~/Pages/Product/ProductSearch.aspx" + "?keyword=" + keyword +
                                "&startIndex=" + (startIndex + count) + "&count=" + count;

                            lnkNext.NavigateUrl = Response.ApplyAppPathModifier(url);
                            lnkNext.Visible     = true;
                        }
                    }
                }
            }
            /* If there is no keyword, search all products */
            else
            {
                try
                {
                    long tagId = long.Parse(Request.Params.Get("tagId"));

                    /* Get Products Info */
                    ProductBlock productBlock = productService.FindAllProductsByTag(tagId, startIndex, count);

                    if (productBlock.Products.Count == 0)
                    {
                        lblNoProducts.Visible = true;
                    }
                    else
                    {
                        gvProducts.DataSource = productBlock.Products;
                        gvProducts.DataBind();

                        /* "Previous" link */
                        if ((startIndex - count) >= 0)
                        {
                            string url =
                                "~/Pages/Product/ProductSearch.aspx" + "?tagId=" + tagId + "startIndex=" + (startIndex - count) +
                                "&count=" + count;

                            lnkPrevious.NavigateUrl = Response.ApplyAppPathModifier(url);
                            lnkPrevious.Visible     = true;
                        }

                        /* "Next" link */
                        if (productBlock.ExistMoreProducts)
                        {
                            string url =
                                "~/Pages/Product/ProductSearch.aspx" + "?tagId=" + tagId + "startIndex=" + (startIndex + count) +
                                "&count=" + count;

                            lnkNext.NavigateUrl = Response.ApplyAppPathModifier(url);
                            lnkNext.Visible     = true;
                        }
                    }
                }
                catch (ArgumentNullException)
                {
                    /* Get Products Info */
                    ProductBlock productBlock = productService.FindAllProducts(startIndex, count);

                    if (productBlock.Products.Count == 0)
                    {
                        lblNoProducts.Visible = true;
                    }
                    else
                    {
                        gvProducts.DataSource = productBlock.Products;
                        gvProducts.DataBind();

                        /* "Previous" link */
                        if ((startIndex - count) >= 0)
                        {
                            string url =
                                "~/Pages/Product/ProductSearch.aspx" + "?startIndex=" + (startIndex - count) +
                                "&count=" + count;

                            lnkPrevious.NavigateUrl = Response.ApplyAppPathModifier(url);
                            lnkPrevious.Visible     = true;
                        }

                        /* "Next" link */
                        if (productBlock.ExistMoreProducts)
                        {
                            string url =
                                "~/Pages/Product/ProductSearch.aspx" + "?startIndex=" + (startIndex + count) +
                                "&count=" + count;

                            lnkNext.NavigateUrl = Response.ApplyAppPathModifier(url);
                            lnkNext.Visible     = true;
                        }
                    }
                }
            }

            if (!IsPostBack)
            {
                List <Category> categories = productService.FindAllCategories();

                // Create a table to store data for the DropDownList control.
                DataTable dt = new DataTable();

                // Define the columns of the table.
                dt.Columns.Add(new DataColumn("CategoryNameField", typeof(string)));
                dt.Columns.Add(new DataColumn("CategoryIdField", typeof(long)));

                // Populate the table.
                dt.Rows.Add(CreateRow("-", -1, dt));

                foreach (Category category in categories)
                {
                    dt.Rows.Add(CreateRow(category.categoryName, category.categoryId, dt));
                }

                // Create a DataView from the DataTable to act as the data source
                // for the DropDownList control.
                DataView dv = new DataView(dt);

                CategoryDropDownList.DataSource     = dv;
                CategoryDropDownList.DataTextField  = "CategoryNameField";
                CategoryDropDownList.DataValueField = "CategoryIdField";

                // Bind the data to the control.
                CategoryDropDownList.DataBind();

                // Set the default selected item.
                CategoryDropDownList.SelectedValue = selectedValue;
            }
        }