Inheritance: ExtenderControlBase
Esempio n. 1
0
    protected void dlRecipes_ItemDataBound(object sender, DataListItemEventArgs e)
    {
        if (e.Item.DataItem is KeyValuePair <int, Recipe> )
        {
            KeyValuePair <int, Recipe> recipe = (KeyValuePair <int, Recipe>)e.Item.DataItem;

            LinkButton lnkBtn = e.Item.FindControl("lnkRemove") as LinkButton;
            if (lnkBtn != null)
            {
                lnkBtn.Attributes["recipeId"] = recipe.Key.ToString();
            }

            //lnkBtn = e.Item.FindControl("lnkAddToMenu") as LinkButton;
            //if (lnkBtn != null)
            //{
            //    lnkBtn.Attributes["recipeId"] = recipe.Key.ToString();
            //}

            lnkBtn = e.Item.FindControl("lnkAddToMenu2") as LinkButton;
            if (lnkBtn != null)
            {
                lnkBtn.Attributes["recipeId"]   = recipe.Key.ToString();
                lnkBtn.Attributes["recipeName"] = recipe.Value.RecipeName;
                //lnkBtn.Attributes["recipeServings"] = recipe.Value.ExpectedServings.ToString();
            }

            HyperLink hyplink = e.Item.FindControl("lnkRecipeName") as HyperLink;
            if (hyplink != null)
            {
                hyplink.NavigateUrl = string.Format("~/RecipeDetails.aspx?RecipeId={0}", recipe.Key.ToString());
            }

            // for identification of relevant recipe after it was dropped on a cell in the table.

            Panel pnl = e.Item.FindControl("pnlItem") as Panel;
            if (pnl != null)
            {
                pnl.Attributes["recipeId"] = recipe.Key.ToString();
            }

            AjaxControlToolkit.ConfirmButtonExtender cbe = e.Item.FindControl("cbeRemoveMenuRecipe") as AjaxControlToolkit.ConfirmButtonExtender;
            if (cbe != null)
            {
                bool isRecipeInMenuMeals = false;
                foreach (Meal meal in this.CurrentMenu.Meals)
                {
                    if (meal.MealRecipes.SingleOrDefault(mr => mr.RecipeId == recipe.Key) != null)
                    {
                        isRecipeInMenuMeals = true;
                    }
                }

                cbe.Enabled = isRecipeInMenuMeals;
            }
        }
    }
        private void UpdateDirectoryContentPanel()
        {
            FileManagerUpdatePanel.Triggers.Clear();
            DirectoryInfo directory = new DirectoryInfo(RootDir + RequestedPath);
            CurrentDirectoryDirectories = directory.GetDirectories();
            CurrentDirectoryFiles = directory.GetFiles();
            HtmlTableRow header = (HtmlTableRow)fileManagerFolderContentTable.Controls[0];
            fileManagerFolderContentTable.Controls.Clear();
            fileManagerFolderContentTable.Controls.Add(header);
            if (!string.IsNullOrEmpty(RequestedPath))
            {
                HtmlTableRow tr = new HtmlTableRow();
                tr.Attributes.Add("onmouseover", "onTableRowMouseOver(this)");
                tr.Attributes.Add("onmouseout", "onTableRowMouseLeft(this)");

                HtmlTableCell checkCell = new HtmlTableCell();

                checkCell.Attributes.Add("class", "fileManagerFolderContentTableSelectCell");
                tr.Controls.Add(checkCell);

                HtmlTableCell nameCell = new HtmlTableCell();
                LinkButton nameLinkButton = new LinkButton();
                nameLinkButton.Text = "..";
                nameLinkButton.ID = "..";
                if (nameLinkButton.Text.Length > 80)
                {
                    nameLinkButton.Text = nameLinkButton.Text.Substring(0, 80) + "...";
                }
                nameLinkButton.Click += new System.EventHandler(DirectoryContentLink_Click_Handler);
                nameCell.Controls.Add(nameLinkButton);
                nameCell.Attributes.Add("class", "fileManagerFolderContentTableNameCell");
                tr.Controls.Add(nameCell);

                HtmlTableCell lengthCell = new HtmlTableCell();
                lengthCell.InnerText = "Папка";
                lengthCell.Attributes.Add("class", "fileManagerFolderContentTableLengthCell");
                tr.Controls.Add(lengthCell);

                HtmlTableCell lastChangeCell = new HtmlTableCell();
                Literal LastChangeLiteral = new Literal();

                lastChangeCell.Controls.Add(LastChangeLiteral);
                lastChangeCell.Attributes.Add("class", "fileManagerFolderContentTableLastModificationCell");
                tr.Controls.Add(lastChangeCell);

                HtmlTableCell downloadCell = new HtmlTableCell();
                downloadCell.Attributes.Add("class", "fileManagerFolderContentTableDownloadCell");
                tr.Controls.Add(downloadCell);

                HtmlTableCell deleteCell = new HtmlTableCell();
                deleteCell.Attributes.Add("class", "fileManagerFolderContentTableDeleteCell");
                tr.Controls.Add(deleteCell);

                fileManagerFolderContentTable.Controls.Add(tr);
            }
            foreach (DirectoryInfo dir in CurrentDirectoryDirectories)
            {
                HtmlTableRow tr = new HtmlTableRow();
                tr.Attributes.Add("onmouseover", "onTableRowMouseOver(this)");
                tr.Attributes.Add("onmouseout", "onTableRowMouseLeft(this)");
                tr.Attributes.Add("onclick", "onTableRowClick(this, event);");

                HtmlTableCell checkCell = new HtmlTableCell();
                CheckBox check = new CheckBox();
                check.ID = dir.Name.GetHashCode() + "$Directory";
                checkCell.Controls.Add(check);
                if (SelectedDirectories.Contains(dir.Name))
                {
                    check.Checked = true;
                }
                check.Attributes.Add("onclick", "stopBubble(event);");
                checkCell.Attributes.Add("class", "fileManagerFolderContentTableSelectCell");
                tr.Controls.Add(checkCell);

                HtmlTableCell nameCell = new HtmlTableCell();
                LinkButton nameLinkButton = new LinkButton();
                nameLinkButton.Text = dir.Name;
                nameLinkButton.ID = dir.Name.GetHashCode().ToString();
                if (nameLinkButton.Text.Length > 80)
                {
                    nameLinkButton.Text = nameLinkButton.Text.Substring(0, 80) + "...";
                }
                nameLinkButton.Click += new System.EventHandler(DirectoryContentLink_Click_Handler);
                nameCell.Controls.Add(nameLinkButton);
                nameCell.Attributes.Add("class", "fileManagerFolderContentTableNameCell");
                tr.Controls.Add(nameCell);

                HtmlTableCell lengthCell = new HtmlTableCell();
                lengthCell.InnerText = "Папка";
                lengthCell.Attributes.Add("class", "fileManagerFolderContentTableLengthCell");
                tr.Controls.Add(lengthCell);

                HtmlTableCell lastChangeCell = new HtmlTableCell();
                Literal LastChangeLiteral = new Literal();
                LastChangeLiteral.Text = dir.LastWriteTime.ToString("dd MMM yyyy H:MM", CultureInfo.CreateSpecificCulture("en-US")).ToUpper();
                lastChangeCell.Controls.Add(LastChangeLiteral);
                lastChangeCell.Attributes.Add("class", "fileManagerFolderContentTableLastModificationCell");
                tr.Controls.Add(lastChangeCell);

                HtmlTableCell downloadCell = new HtmlTableCell();
                downloadCell.Attributes.Add("class", "fileManagerFolderContentTableDownloadCell");

                tr.Controls.Add(downloadCell);

                HtmlTableCell deleteCell = new HtmlTableCell();
                deleteCell.Attributes.Add("class", "fileManagerFolderContentTableDeleteCell");
                ImageButton deleteButton = new ImageButton();
                deleteButton.ImageUrl = "images/delete.png";
                deleteButton.ToolTip = "Удалить";
                deleteButton.AlternateText = "Удалить";
                deleteButton.ID = dir.Name.GetHashCode() + "_deleteButton";
                deleteButton.CommandName = dir.Name;
                deleteButton.Command += new System.Web.UI.WebControls.CommandEventHandler(DeleteButton_ClickHandler);

                ConfirmButtonExtender es = new ConfirmButtonExtender();
                es.ID = dir.Name.GetHashCode().ToString() + "_DeleteConfirmer";
                es.TargetControlID = deleteButton.ID;
                es.ConfirmText = "Вы дейстивтельно хотите удалить эту папку?";

                deleteCell.Controls.Add(es);

                deleteCell.Controls.Add(deleteButton);

                tr.Controls.Add(deleteCell);

                fileManagerFolderContentTable.Controls.Add(tr);
            }

            foreach (FileInfo file in CurrentDirectoryFiles)
            {
                HtmlTableRow tr = new HtmlTableRow();
                tr.Attributes.Add("onmouseover", "onTableRowMouseOver(this)");
                tr.Attributes.Add("onmouseout", "onTableRowMouseLeft(this)");
                tr.Attributes.Add("onclick", "onTableRowClick(this, event);");

                HtmlTableCell checkCell = new HtmlTableCell();
                CheckBox check = new CheckBox();
                check.Attributes.Add("onclick", "stopBubble(event);");
                check.ID = file.Name.GetHashCode() + "$File";
                if (SelectedFiles.Contains(file.Name))
                {
                    check.Checked = true;
                }
                checkCell.Controls.Add(check);
                checkCell.Attributes.Add("class", "fileManagerFolderContentTableSelectCell");
                tr.Controls.Add(checkCell);

                HtmlTableCell nameCell = new HtmlTableCell();
                HtmlAnchor nameLink = new HtmlAnchor();
                nameLink.ID = file.Name.GetHashCode() + "Link";
                nameLink.HRef = Request.AppRelativeCurrentExecutionFilePath + "?path=" + RequestedPath + "\\" + file.Name;
                nameLink.InnerText = file.Name;
                if (nameLink.InnerText.Length > 80)
                {
                    nameLink.InnerText = nameLink.InnerText.Substring(0, 80) + "...";
                }
                var nameLinkContainer = new HtmlGenericControl("div");
                nameLinkContainer.Controls.Add(nameLink);
                nameCell.Controls.Add(nameLinkContainer);
                nameCell.Attributes.Add("class", "fileManagerFolderContentTableNameCell");
                tr.Controls.Add(nameCell);

                HtmlTableCell lengthCell = new HtmlTableCell();
                Literal lengthLiteral = new Literal();
                long length = 0;
                if (Cache[file.FullName + "_Length"] != null)
                {
                    length = (long)Cache[file.FullName + "_Length"];
                }
                else
                {
                    length = file.Length;
                    CacheDependency cd = new CacheDependency(file.FullName);
                    Cache.Insert(file.FullName + "_Length", length, cd, DateTime.MaxValue, TimeSpan.FromMinutes(5));
                }
                lengthLiteral.Text = Math.Ceiling((double)length / 1024).ToString() + " КБ";
                lengthCell.Controls.Add(lengthLiteral);
                lengthCell.Attributes.Add("class", "fileManagerFolderContentTableLengthCell");
                tr.Controls.Add(lengthCell);

                HtmlTableCell lastChangeCell = new HtmlTableCell();
                Literal LastChangeLiteral = new Literal();
                DateTime lastChange;
                if (Cache[file.FullName + "_LastWriteTime"] != null)
                {
                    lastChange = (DateTime)Cache[file.FullName + "_LastWriteTime"];
                }
                else
                {
                    lastChange = file.LastWriteTime;
                    Cache.Insert(file.FullName + "_LastWriteTime", lastChange, null, DateTime.MaxValue, TimeSpan.FromMinutes(5));
                }
                LastChangeLiteral.Text = lastChange.ToString("dd MMM yyyy H:MM", CultureInfo.CreateSpecificCulture("en-US")).ToUpper();
                lastChangeCell.Controls.Add(LastChangeLiteral);
                lastChangeCell.Attributes.Add("class", "fileManagerFolderContentTableLastModificationCell");
                tr.Controls.Add(lastChangeCell);

                HtmlTableCell downloadCell = new HtmlTableCell();
                downloadCell.Attributes.Add("class", "fileManagerFolderContentTableDownloadCell");
                ImageButton downButton = new ImageButton();
                downButton.ImageUrl = "images/download.png";
                downButton.AlternateText = "Скачать";
                downButton.ToolTip = "Скачать";
                downButton.ID = file.Name + "_downlodButton";
                downButton.Attributes.Add("onclick", "downloadFile(event, \'" + RequestedPath + file.Name + "\');");
                downloadCell.Controls.Add(downButton);

                tr.Controls.Add(downloadCell);

                HtmlTableCell deleteCell = new HtmlTableCell();
                deleteCell.Attributes.Add("class", "fileManagerFolderContentTableDeleteCell");
                ImageButton deleteButton = new ImageButton();
                deleteButton.ImageUrl = "images/delete.png";
                deleteButton.ToolTip = "Удалить";
                deleteButton.AlternateText = "Удалить";
                deleteButton.ID = file.Name.GetHashCode() + "_deleteButton";
                deleteButton.CommandName = file.Name;
                deleteButton.Command += new System.Web.UI.WebControls.CommandEventHandler(DeleteButton_ClickHandler);
                deleteCell.Controls.Add(deleteButton);

                ConfirmButtonExtender es = new ConfirmButtonExtender();
                es.ID = file.Name.GetHashCode() + "_DeleteConfirmer";
                es.TargetControlID = deleteButton.ID;
                es.ConfirmText = "Вы дейстивтельно хотите удалить этот файл?";

                deleteCell.Controls.Add(es);

                deleteCell.Controls.Add(deleteButton);

                tr.Controls.Add(deleteCell);

                fileManagerFolderContentTable.Controls.Add(tr);

            }
        }
    protected void rptAdressItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        System.Globalization.CultureInfo         currentUI = System.Globalization.CultureInfo.CurrentUICulture;
        AjaxControlToolkit.ConfirmButtonExtender cbe       = new AjaxControlToolkit.ConfirmButtonExtender();
        cbe = (AjaxControlToolkit.ConfirmButtonExtender)e.Item.FindControl("ConfirmButtonDelete");

        if (cbe != null)
        {
            cbe.ConfirmText = GetString("msgconfirm");
        }

        var drv = (System.Data.DataRowView)e.Item.DataItem;

        if (drv != null)
        {
            int currentAdressID = ValidationHelper.GetInteger(drv["AddressID"], 0);
            if (currentAdressID > 0)
            {
                AddressInfo ai = AddressInfoProvider.GetAddressInfo(currentAdressID);
                if (ai != null)
                {
                    var ltlAdress = e.Item.FindControl("ltlAdress") as Literal;
                    if (ltlAdress != null)
                    {
                        int countryID = ai.AddressCountryID;
                        ltlAdress.Text = string.Format("{0}, {1}", ai.AddressName, MacroContext.CurrentResolver.ResolveMacros(CountryInfoProvider.GetCountryInfo(countryID).CountryDisplayName));
                    }

                    var txtnumero = e.Item.FindControl("txtnumero") as TextBox;
                    if (txtnumero != null)
                    {
                        txtnumero.Text    = ai.GetStringValue("AddressNumber", string.Empty).Trim();
                        txtnumero.ToolTip = GetString("numerorue");
                    }

                    var wmnumero = e.Item.FindControl("wmnumero") as AjaxControlToolkit.TextBoxWatermarkExtender;
                    if (wmnumero != null)
                    {
                        wmnumero.WatermarkText = GetString("numerorue");
                    }

                    var txtadresse1 = e.Item.FindControl("txtadresse1") as TextBox;
                    if (txtadresse1 != null)
                    {
                        txtadresse1.Text    = ai.AddressLine1.Trim();
                        txtadresse1.ToolTip = GetString("adresse1");
                    }

                    var wmadresse1 = e.Item.FindControl("wmadresse1") as AjaxControlToolkit.TextBoxWatermarkExtender;
                    if (wmadresse1 != null)
                    {
                        wmadresse1.WatermarkText = GetString("adresse1");
                    }

                    var txtadresse2 = e.Item.FindControl("txtadresse2") as TextBox;
                    if (txtadresse2 != null)
                    {
                        txtadresse2.Text    = ai.AddressLine2.Trim() == string.Empty ? string.Empty : ai.AddressLine2.Trim();
                        txtadresse2.ToolTip = GetString("adresse2");
                    }

                    var wmadresse2 = e.Item.FindControl("wmadresse2") as AjaxControlToolkit.TextBoxWatermarkExtender;
                    if (wmadresse2 != null)
                    {
                        wmadresse2.WatermarkText = GetString("adresse2");
                    }


                    var txtcp = e.Item.FindControl("txtcp") as TextBox;
                    if (txtcp != null)
                    {
                        txtcp.Text    = ai.AddressZip.Trim();
                        txtcp.ToolTip = GetString("cp");
                    }

                    var wmcp = e.Item.FindControl("wmcp") as AjaxControlToolkit.TextBoxWatermarkExtender;
                    if (wmcp != null)
                    {
                        wmcp.WatermarkText = GetString("cp");
                    }

                    var txtville = e.Item.FindControl("txtville") as TextBox;
                    if (txtville != null)
                    {
                        txtville.Text    = ai.AddressCity.Trim();
                        txtville.ToolTip = GetString("ville");
                    }

                    var wmville = e.Item.FindControl("wmville") as AjaxControlToolkit.TextBoxWatermarkExtender;
                    if (wmville != null)
                    {
                        wmville.WatermarkText = GetString("ville");
                    }

                    var txtCountry = e.Item.FindControl("txtCountry") as TextBox;
                    if (txtCountry != null)
                    {
                        txtCountry.Text = MacroContext.CurrentResolver.ResolveMacros(
                            GetString(CountryInfoProvider.GetCountryInfo(ai.AddressCountryID).CountryDisplayName));
                    }

                    var chkShippingAddr = e.Item.FindControl("chkShippingAddr") as CheckBox;
                    if (chkShippingAddr != null)
                    {
                        chkShippingAddr.Checked = ai.AddressIsShipping;
                    }

                    var chkBillingAddr = e.Item.FindControl("chkBillingAddr") as CheckBox;
                    if (chkBillingAddr != null)
                    {
                        chkBillingAddr.Checked = ai.AddressIsBilling;
                    }
                }
            }
        }
    }