Beispiel #1
0
        protected void Page_Load(object sender, System.EventArgs e)
        {
            try
            {
                Controller = new BBStoreController();

                taxUnitCost.PercentControl         = txtTaxPercent;
                taxOriginalUnitCost.PercentControl = txtTaxPercent;

                taxPriceUnitCost.PercentControl         = txtPriceTaxPercent;
                taxPriceOriginalUnitCost.PercentControl = txtPriceTaxPercent;

                LocaleController            lc  = new LocaleController();
                Dictionary <string, Locale> loc = lc.GetLocales(PortalId);

                //TODO: Panels ausblenden wenn kein Modul verwendet

                ModuleController objModules = new ModuleController();
                if (objModules.GetModuleByDefinition(PortalId, "BBStore Product Groups") == null)
                {
                    HasProductGroupModule = false;
                }

                if (objModules.GetModuleByDefinition(PortalId, "BBStore Product Features") == null)
                {
                    HasProductFeatureModule = false;
                }

                Hashtable storeSettings = Controller.GetStoreSettings(PortalId);
                if (storeSettings != null)
                {
                    _imageDir = (string)(storeSettings["ProductImageDir"] ?? "");
                }

                // If this is the first visit to the page
                if (Page.IsPostBack == false)
                {
                    // Show Supplier ?
                    if (storeSettings != null && storeSettings["SupplierRole"] != null && (string)storeSettings["SupplierRole"] != "-1")
                    {
                        pnlSupplier.Visible = true;
                        RoleController roleController = new RoleController();
                        //RoleInfo role = roleController.GetRole(Convert.ToInt32(storeSettings["SupplierRole"]), PortalId);
                        ArrayList          aUsers = roleController.GetUsersByRoleName(PortalId, (string)storeSettings["SupplierRole"]);
                        ListItemCollection users  = new ListItemCollection();
                        foreach (UserInfo user in aUsers)
                        {
                            users.Add(new ListItem(user.DisplayName, user.UserID.ToString()));
                        }
                        string selText = Localization.GetString("SelectSupplier.Text", this.LocalResourceFile);
                        users.Insert(0, new ListItem(selText, "-1"));
                        cboSupplier.DataSource     = users;
                        cboSupplier.DataValueField = "Value";
                        cboSupplier.DataTextField  = "Text";
                        cboSupplier.DataBind();
                    }

                    // Shipping Models
                    List <ShippingModelInfo> shippingModels = Controller.GetShippingModels(PortalId);

                    cboShippingModel.DataSource     = shippingModels;
                    cboShippingModel.DataValueField = "ShippingModelId";
                    cboShippingModel.DataTextField  = "Name";
                    cboShippingModel.DataBind();

                    string selUnitText = Localization.GetString("SelectUnit.Text", this.LocalResourceFile);
                    ddlUnit.Items.Add(new ListItem(selUnitText, "-1"));
                    foreach (UnitInfo unit in Controller.GetUnits(PortalId, CurrentLanguage, "Unit"))
                    {
                        ddlUnit.Items.Add(new ListItem(unit.Unit, unit.UnitId.ToString()));
                    }
                    ddlUnit.DataValueField = "Value";
                    ddlUnit.DataTextField  = "Text";
                    ddlUnit.DataBind();


                    // Set ProductGroups Visible / not Visible
                    //pnlProductGroup.Visible = HasProductGroupModule;

                    SimpleProductInfo SimpleProduct = null;

                    if (Request["productid"] != null)
                    {
                        ProductId = Convert.ToInt32(Request["productid"]);
                    }

                    // if product exists
                    if (ProductId > 0)
                    {
                        SimpleProduct = Controller.GetSimpleProductByProductId(PortalId, ProductId);
                    }

                    List <ILanguageEditorInfo> dbLangs = new List <ILanguageEditorInfo>();

                    if (SimpleProduct == null)
                    {
                        taxUnitCost.Value         = 0.00m;
                        taxUnitCost.Mode          = "gross";
                        txtTaxPercent.Text        = 0.0m.ToString();
                        taxOriginalUnitCost.Value = 0.00m;
                        taxOriginalUnitCost.Mode  = "gross";
                        ImageSelector.Url         = _imageDir + "This_fileName-Should_not_3xist";
                        cboSupplier.SelectedValue = "-1";
                        dbLangs.Add(new SimpleProductLangInfo()
                        {
                            Language = CurrentLanguage
                        });
                        lngSimpleProducts.Langs = dbLangs;
                        txtWeight.Text          = 0.000m.ToString();
                    }
                    else
                    {
                        // Fill in the Language information
                        foreach (SimpleProductLangInfo simpleProductLang in Controller.GetSimpleProductLangs(SimpleProduct.SimpleProductId))
                        {
                            dbLangs.Add(simpleProductLang);
                        }
                        lngSimpleProducts.Langs = dbLangs;


                        // Set Image Info
                        int fileId = -1;
                        if (!String.IsNullOrEmpty(SimpleProduct.Image))
                        {
                            try
                            {
                                IFileInfo file = FileManager.Instance.GetFile(PortalId, SimpleProduct.Image);
                                if (file != null)
                                {
                                    fileId = file.FileId;
                                }
                            }
                            catch (Exception)
                            {
                                fileId = -1;
                            }
                        }
                        string imageUrl = "";
                        if (fileId > -1)
                        {
                            imageUrl = "FileID=" + fileId.ToString();
                        }
                        else
                        {
                            imageUrl = _imageDir + "This_fileName-Should_not_3xist";
                        }

                        // Set other fields
                        txtItemNo.Text            = SimpleProduct.ItemNo;
                        txtTaxPercent.Text        = SimpleProduct.TaxPercent.ToString();
                        taxUnitCost.Mode          = "gross";
                        taxUnitCost.Value         = SimpleProduct.UnitCost;
                        taxOriginalUnitCost.Mode  = "gross";
                        taxOriginalUnitCost.Value = SimpleProduct.OriginalUnitCost;
                        chkDisabled.Checked       = SimpleProduct.Disabled;
                        chkHideCost.Checked       = SimpleProduct.HideCost;
                        chkNoCart.Checked         = SimpleProduct.NoCart;
                        cboSupplier.SelectedValue = SimpleProduct.SupplierId.ToString();
                        ddlUnit.SelectedValue     = SimpleProduct.UnitId.ToString();
                        ImageSelector.Url         = imageUrl;
                        imgImage.ImageUrl         = BBStoreHelper.FileNameToImgSrc(imageUrl, PortalSettings);
                        txtWeight.Text            = SimpleProduct.Weight.ToString();

                        // Set ShippingModel
                        List <ProductShippingModelInfo> productshippingModels = Controller.GetProductShippingModelsByProduct(SimpleProduct.SimpleProductId);
                        if (productshippingModels.Count > 0)
                        {
                            cboShippingModel.SelectedValue = productshippingModels[0].ShippingModelId.ToString();
                        }
                    }

                    // Treeview Basenode
                    TreeNode newNode = new TreeNode(Localization.GetString("treeProductGroups.Text", this.LocalResourceFile), "_-1");
                    newNode.SelectAction     = TreeNodeSelectAction.Expand;
                    newNode.PopulateOnDemand = true;
                    newNode.ImageUrl         = @"~\images\category.gif";
                    newNode.ShowCheckBox     = false;
                    treeProductGroup.Nodes.Add(newNode);
                    //newNode.Expanded = false;


                    // Product Price
                    Localization.LocalizeGridView(ref grdPriceList, LocalResourceFile);
                    grdPriceList.DataSource = ProductPrices;
                    grdPriceList.DataBind();

                    RoleController roleController1 = new RoleController();
                    //RoleInfo role = roleController.GetRole(Convert.ToInt32(storeSettings["SupplierRole"]), PortalId);
                    ArrayList          aRoles = roleController1.GetPortalRoles(PortalId);
                    ListItemCollection roles  = new ListItemCollection();
                    foreach (RoleInfo role in aRoles)
                    {
                        roles.Add(new ListItem(role.RoleName, role.RoleID.ToString()));
                    }
                    string selText1 = Localization.GetString("SelectRole.Text", this.LocalResourceFile);
                    roles.Insert(0, new ListItem(selText1, "-1"));
                    ddlPriceRoleId.DataSource     = roles;
                    ddlPriceRoleId.DataValueField = "Value";
                    ddlPriceRoleId.DataTextField  = "Text";
                    ddlPriceRoleId.DataBind();
                }
                if (HasProductFeatureModule)
                {
                    FeatureGrid.ProductId = ProductId;
                }
            }

            catch (Exception exc)
            {
                //Module failed to load
                Exceptions.ProcessModuleLoadException(this, exc);
            }
        }