Пример #1
0
        internal void Render(WebGridHtmlWriter mywriter)
        {
            // MasterWebGrid is using SlaveGridMenu.
            if (((m_Grid.SystemMessage.CriticalCount == 0 && m_Grid.MasterGrid != null && m_Grid.MasterWebGrid != null &&
                  m_Grid.m_IsGridInsideGrid == false &&
                  m_Grid.MasterWebGrid.DisplaySlaveGridMenu &&
                  (m_Grid.MasterWebGrid.ActiveMenuSlaveGrid == null ||
                   m_Grid.MasterWebGrid.ActiveMenuSlaveGrid.ClientID != m_Grid.ClientID))
                 ) ||
                (m_Grid.m_IsGridInsideGrid && m_Grid.MasterWebGrid != null &&
                 m_Grid.MasterWebGrid.m_HasRendered == false))
            {
                return;
            }
            if (m_Grid.HideIfEmptyGrid && m_Grid.MasterTable.Rows.Count == 0 && m_Grid.SystemMessage.CriticalCount == 0 &&
                !m_Grid.m_ActiveColumnFilter)
            {
                if (m_Grid.EmptyDataTemplate != null)
                {
                    mywriter.Write(m_Grid.EmptyDataTemplate);
                }
                return;
            }

            m_Grid.m_HasRendered = true;

            if (m_Grid.Tag["wgcsslink"] != null)
            {
                mywriter.Write(m_Grid.Tag.Get("wgcsslink"));
            }
            if (m_Grid.Tag["wgscriptstyles"] != null)
            {
                mywriter.Write(m_Grid.Tag.Get("wgscriptstyles"));
            }
            if (m_Grid.PreGridTemplate != null)
            {
                mywriter.Write(m_Grid.PreGridTemplate);
            }

            string width = string.Empty;

            if (m_Grid.Width.IsEmpty == false)
            {
                width = string.Format(" width=\"{0}\"", m_Grid.Width);
            }

            StringBuilder sb = new StringBuilder();
            StringWriter  sw = new StringWriter(sb);

            System.Web.UI.HtmlTextWriter renderBeginTag = new System.Web.UI.HtmlTextWriter(sw);

            m_Grid.RenderBeginTag(renderBeginTag);

            string webAttributes = sb.ToString();

            // Remove first tag which is always 'id='
            webAttributes = webAttributes.Remove(0, webAttributes.IndexOf("id="));
            // Clean up..
            webAttributes = webAttributes.Remove(0, webAttributes.IndexOf(" "));

            webAttributes = string.Format("<table{0}", webAttributes.Remove(webAttributes.Length - 1));

            #region slavegrid menu

            bool systemMessagetriggered = false;
            if (m_Grid.DisplayView == DisplayView.Detail && m_Grid.DisplaySlaveGridMenu && m_Grid.SlaveGrid.Count > 0 &&
                m_Grid.InternalId != null)
            {
                mywriter.Write("<!--WebGrid menu starts rendering -->\n");
                mywriter.Write("{0} class=\"wgmenu\" {1}  cellpadding=\"0\" cellspacing=\"0\" id=\"wgMenu_{2}\"><tr><td>",
                               webAttributes,
                               width, m_Grid.ClientID);
                if (m_Grid.SystemMessage.Count > 0)
                {
                    mywriter.Write(m_Grid.SystemMessage.RenderSystemMessage);
                    if (m_Grid.Scripts == null || !m_Grid.Scripts.DisableBookmark)
                    {
                        Grid.AddClientScript(mywriter, string.Format("bookmarkscroll.init();bookmarkscroll.scrollTo('wgSystemMessage_{0}')", m_Grid.ID));
                    }
                    mywriter.Write("</td></tr><tr><td>");
                    systemMessagetriggered = true;
                }

                /* cellpadding and cellspacing are fixed because CSS does not support similar behavior*/
                mywriter.Write("<table class=\"wgmenunavigation\" cellpadding=\"0\" cellspacing=\"0\"><tr align=\"left\">");
                bool createmenuspace = false;

                foreach (Grid slavegrid in m_Grid.SlaveGrid)
                {
                    if (createmenuspace)
                    {
                        mywriter.Write("<td class=\"wgmenuspacing\"></td>");
                    }
                    else
                    {
                        createmenuspace = true;
                    }

                    if (m_Grid.ActiveMenuSlaveGrid != slavegrid)
                    {
                        string colorstyle = null;
                        if (Grid.MenuInactiveColor != Color.Empty)
                        {
                            colorstyle = string.Format("style=\"background-color:{0}\"",
                                                       Grid.ColorToHtml(Grid.MenuInactiveColor));
                        }

                        if (m_Grid.IsUsingJQueryUICSSFramework)
                        {
                            mywriter.Write(
                                "<td id=\"wgmenu_{0}_{1}\">{2}</td>",
                                m_Grid.ClientID, slavegrid.ClientID, m_Grid.SlaveGrid.GetSlaveGridAnchor(slavegrid));
                        }
                        else
                        {
                            mywriter.Write(
                                "<td id=\"wgmenu_{0}_{1}\"><div class=\"wglefttab_off\"></div><div {2} class=\"wginactivemenu wgrighttab_off\">{3}</div></td>",
                                m_Grid.ClientID, slavegrid.ClientID, colorstyle,
                                m_Grid.SlaveGrid.GetSlaveGridAnchor(slavegrid));
                        }
                    }
                    else
                    {
                        string colorstyle = null;
                        if (Grid.MenuActiveColor != Color.Empty)
                        {
                            colorstyle =
                                string.Format("style=\"background-color:{0}\"", Grid.ColorToHtml(Grid.MenuActiveColor));
                        }

                        if (m_Grid.IsUsingJQueryUICSSFramework)
                        {
                            mywriter.Write(
                                "<td id=\"wgmenu_{0}_{1}\">{2}</td>",
                                m_Grid.ClientID, slavegrid.ClientID, m_Grid.SlaveGrid.GetSlaveGridAnchor(slavegrid));
                        }
                        else
                        {
                            mywriter.Write(
                                "<td id=\"wgmenu_{0}_{1}\"><div class=\"wglefttab_on\"></div><div {2} class=\"wgactivemenu wgrighttab_on\">{3}</div></td>",
                                m_Grid.ClientID, slavegrid.ClientID, colorstyle,
                                m_Grid.SlaveGrid.GetSlaveGridAnchor(slavegrid));
                        }
                    }
                }
                mywriter.Write("</tr></table></td></tr></table><br/>");
                mywriter.Write("<!--WebGrid menu finished rendering -->\n");
            }

            #endregion

            if (m_Grid.SystemMessage.Count > 0 && systemMessagetriggered == false)
            {
                mywriter.Write(m_Grid.SystemMessage.RenderSystemMessage);
                if (m_Grid.Scripts == null || !m_Grid.Scripts.DisableBookmark)
                {
                    Grid.AddClientScript(mywriter,
                                         string.Format("bookmarkscroll.init();bookmarkscroll.scrollTo('wgSystemMessage_{0}')",
                                                       m_Grid.ID));
                }
            }
            mywriter.Write("<!--WebGrid grid starts rendering -->\n");
            mywriter.Write("{0} {1} cellpadding=\"0\" class=\"wgmaingrid\" cellspacing=\"0\" id=\"wgContent_{2}\"><tr><td>",
                           webAttributes, width, m_Grid.ID);
            ApplyAjaxLoader(mywriter);
            if (m_Grid.SystemMessage.CriticalCount == 0)
            {
                switch (m_Grid.DisplayView)
                {
                case DisplayView.Grid:
                    if (m_Grid.AllowEditInGrid && m_Grid.PageIndex == 0 && m_Grid.Page != null)
                    {
                        if (m_Grid.EnableCallBack)
                        {
                            mywriter.Write(
                                "<input type=\"hidden\" id=\"{0}_where\" name=\"{0}_where\" value=\"{1}\" />",
                                m_Grid.ClientID, HttpUtility.UrlEncode(m_Grid.FilterExpression, Encoding.Default));
                        }
                        else
                        {
                            m_Grid.Page.ClientScript.RegisterHiddenField(
                                string.Format("{0}_where", m_Grid.ClientID),
                                HttpUtility.UrlEncode(m_Grid.FilterExpression, Encoding.Default));
                        }
                    }
                    RenderGrid(ref m_Grid, ref mywriter);
                    break;

                case DisplayView.Detail:

                    RenderDetail(ref m_Grid, ref mywriter);
                    break;
                }
            }

            mywriter.Write("</td></tr></table>");
            mywriter.Write("<!--WebGrid grid finished rendering -->\n");

            if (m_Grid.Page != null && (m_Grid.Scripts == null || !m_Grid.Scripts.DisableWebGridClientObject))
            {
                m_Grid.JsOnData.AppendLine();
                m_Grid.JsOnData.Append(WebGridClientObject.GetGridObject(m_Grid));
            }

            if (m_Grid.Scripts == null || !m_Grid.Scripts.DisableContextMenu)
            {
                m_Grid.GetContextMenuHtml(mywriter);
                Grid.AddClientScript(mywriter, string.Format(contextscript, m_Grid.ID));
            }
            if (m_Grid.ClientNotifications != null && m_Grid.ClientNotifications.Count > 0 && (m_Grid.Scripts == null || !m_Grid.Scripts.DisableClientNotification))
            {
                ClientNotification clientSettings = m_Grid.ClientNotification ?? Grid.DefaultClientNotification;

                if (clientSettings.HeaderText == null)
                {
                    clientSettings.HeaderText = m_Grid.Title;
                }
                if (clientSettings.HeaderText == null)
                {
                    clientSettings.HeaderText = string.Empty;
                }

                StringBuilder template = string.IsNullOrEmpty(clientSettings.Container)
                                             ?
                                         new StringBuilder(
                    "$(document).ready( function() {{ $.jGrowl(\"{0}\", {{ header: '")
                                             :
                                         new StringBuilder(
                    string.Format(
                        "$(document).ready( function() {{ $('#{0}').jGrowl(\"{0}\", {{ header: '",
                        clientSettings.Container));

                template.Append(clientSettings.HeaderText.Replace("\"", "\\"));
                template.AppendFormat("', sticky: {0}", clientSettings.Sticky.ToString().ToLower());
                template.AppendFormat(", life: {0}", clientSettings.LifeSpan);
                if (clientSettings.CloserTemplate != null)
                {
                    template.AppendFormat(", closerTemplate: '{0}'",
                                          clientSettings.CloserTemplate.Replace("\"", "\\"));
                }
                template.Append(", closer: " + clientSettings.Closer.ToString().ToLower());
                if (!string.IsNullOrEmpty(clientSettings.CssClass))
                {
                    template.AppendFormat(", theme: '{0}'", clientSettings.CssClass);
                }
                template.Append("}}); }});");

                if (m_Grid.ClientNotifications.Count > 0)
                {
                    foreach (string arg in m_Grid.ClientNotifications)
                    {
                        Grid.AddClientScript(mywriter,
                                             string.Format(template.ToString(), arg.Replace("\"", "\\")));
                    }
                }
            }

            if ((m_Grid.Scripts == null || !m_Grid.Scripts.DisableInputMask) && m_Grid.MaskedColumns.Count > 0)
            {
                StringBuilder masks = new StringBuilder();

                foreach (KeyValuePair <string, string> dictionary in m_Grid.MaskedColumns)
                {
                    if (masks.Length > 3)
                    {
                        masks.Append(", ");
                    }
                    masks.AppendFormat("{0}:{{ mask: {1} }}", dictionary.Key, dictionary.Value);
                }
                string options;
                if (m_Grid.MaskedInput != null)
                {
                    options = string.Format("{{selectCharsOnFocus: {0},textAlign: {1},autoTab:{2}, attr: '{3}'}}",
                                            MaskedInput.GetStringValue(m_Grid.MaskedInput.EnableSelectCharsOnFocus),
                                            MaskedInput.GetStringValue(m_Grid.MaskedInput.EnableTextAlign),
                                            MaskedInput.GetStringValue(m_Grid.MaskedInput.EnableAutoTab),
                                            m_Grid.MaskedInput.Attribute);
                }
                else
                {
                    options = "{selectCharsOnFocus: true,textAlign: false,autoTab:false, attr: 'alt'}";
                }

                Grid.AddClientScript(mywriter, string.Format(meiomask, m_Grid.ID, masks, options));
            }
            if (Anthem.Manager.IsCallBack && (m_Grid.Scripts == null || !m_Grid.Scripts.DisableHoverButtons))
            {
                Grid.AddClientScript(mywriter, Grid.HoverButtonScript);
            }
            if (m_Grid.JsOnData.Length > 2)
            {
                mywriter.Write(@"<script type=""text/javascript"">{0}</script>", m_Grid.JsOnData.ToString());
            }

            mywriter.Close();
            if (m_Grid.Trace.IsTracing)
            {
                m_Grid.Trace.Trace("Finish Render();");
            }
        }
Пример #2
0
        internal static void CreateFilterByColumns(Grid grid, WebGridHtmlWriter writer, int[] sortedColumnID)
        {
            grid.m_RowsAdded++;
            writer.Write(
                grid.IsUsingJQueryUICSSFramework
                    ? "<tr class=\"ui-widget wgrow\" id=\"{0}r{1}\">"
                    : "<tr class=\"wgrow\" id=\"{0}r{1}\">", grid.ID, grid.m_RowsAdded);
            for (int ii = 0; ii < sortedColumnID.Length; ii++)
            {
                Column column = grid.MasterTable.Columns[sortedColumnID[ii]];
                if (column.FilterByColumnCollection.Count == 0)
                {
                    string columnstyle = string.Empty;
                    string columnId    = string.Format(" id=\"{0}{1}r{2}\"", grid.ID, column.ColumnId, grid.m_RowsAdded);
                    if (grid.MasterTable.Columns[column.ColumnId].WidthColumnHeaderTitle != Unit.Empty)
                    {
                        columnstyle =
                            string.Format("style=\"width: {0};\"",
                                          grid.MasterTable.Columns[column.ColumnId].WidthColumnHeaderTitle);
                    }
                    writer.Write("<th {0} {1}>&nbsp;</th>", columnstyle, columnId);
                    continue;
                }

                ColumnHeader addcolumn = new ColumnHeader
                {
                    m_Class       = string.Format("{0} wggridcell", column.CssClassTitle),
                    m_Align       = column.GridAlign,
                    m_VAlign      = VerticalPosition.bottom,
                    m_ColumnWidth =
                        grid.MasterTable.Columns[column.ColumnId].WidthColumnHeaderTitle,
                    m_GridRowCount = grid.m_RowsAdded,

                    m_GridId = grid.ID
                };

                addcolumn.RenderBeginTag(writer, column, null, "<th");

                string selectedValue = null;
                if (Grid.GotHttpContext &&
                    HttpContext.Current.Request.Form[string.Format("ddl{0}", column.ClientHeaderId)] != null)
                {
                    selectedValue =
                        HttpUtility.HtmlEncode(
                            HttpContext.Current.Request.Form[string.Format("ddl{0}", column.ClientHeaderId)]);
                    grid.State(string.Format("ddl{0}", column.ClientHeaderId), selectedValue);
                }
                else if (grid.GetState(string.Format("ddl{0}", column.ClientHeaderId)) != null)
                {
                    selectedValue = grid.GetState(string.Format("ddl{0}", column.ClientHeaderId)) as string;
                }
                bool isdate = false;
                if (grid.MasterTable.Columns[column.ColumnId].ColumnType == ColumnType.DateTime)
                {
                    isdate = true;
                }

                string eventScript = string.Empty;
                if (grid.Page != null)
                {
                    string link = grid.EnableCallBack && !column.ForcePostBack ? Asynchronous.GetCallbackEventReference(grid,
                                                                                                                        string.Format("ElementPostBack!ddl{0}",
                                                                                                                                      column.ColumnId), false,
                                                                                                                        string.Empty, string.Empty) : grid.Page.ClientScript.GetPostBackEventReference(grid,
                                                                                                                                                                                                       string.Format("ElementPostBack!ddl{0}",
                                                                                                                                                                                                                     column.ColumnId));
                    eventScript = string.Format(" onchange=\"{0}\" ", link);
                }
                string style = grid.MasterTable.Columns[column.ColumnId].WidthColumnHeaderTitle != Unit.Empty ? "class=\"wgeditfield wgselectbox \"" : " class=\"wgeditfield wgselectbox \" ";

                if (!isdate)
                {
                    StringBuilder dropdownbox = new StringBuilder("<select ");
                    dropdownbox.AppendFormat("{0} name=\"ddl{1}\" id=\"ddl{1}\" {2}><option value=\"\" selected=\"selected\">{3}</option>", style, column.ClientHeaderId, eventScript, column.Grid.GetSystemMessage("EmptySearchFilter"));

                    if (grid.Scripts == null || !grid.Scripts.DisableSelectMenu)
                    {
                        Grid.AddClientScript(writer, string.Format("$(document).ready(function() {{$('#ddl{0}').selectmenu({{maxHeight: {2},style:'dropdown',width: {1}}});}});", column.ClientHeaderId, column.WidthColumnHeaderTitle.Value, 400));
                    }


                    int i = 0;
                    while (i < column.FilterByColumnCollection.Count)
                    {
                        string _value = HttpUtility.HtmlEncode(column.FilterByColumnCollection[i]);
                        string _title = HttpUtility.HtmlEncode(column.FilterByColumnCollection.GetKey(i));
                        if (selectedValue != null && selectedValue == _value)
                        {
                            dropdownbox.AppendFormat("<option selected=\"selected\" value=\"{0}\">{1}</option>",
                                                     HttpUtility.HtmlEncode(column.FilterByColumnCollection[i]), _title);
                        }
                        else
                        {
                            dropdownbox.AppendFormat("<option value=\"{0}\">{1}</option>",
                                                     HttpUtility.HtmlEncode(column.FilterByColumnCollection[i]), _title);
                        }
                        i++;
                    }

                    writer.Write(dropdownbox);
                    writer.Write("</select> ");
                }
                else
                {
                    if (grid.DatabaseConnectionType != DataBaseConnectionType.SqlConnection)
                    {
                        throw new GridException(
                                  string.Format("'FilterByColumn' property for 'DateTime' ({0}) columns are only supported by 'SqlConnection' connection strings.", column.ColumnId));
                    }
                    writer.Write("<span style=\"white-space: nowrap;vertical-align:middle;\">");

                    string filter = ((WebGrid.DateTime)grid.MasterTable.Columns[column.ColumnId]).SearchFilter;

                    if (string.IsNullOrEmpty(filter))
                    {
                        StringBuilder s = new StringBuilder(string.Empty);
                        s.AppendFormat(
                            "<a class=\"wglinkfield\" href=\"?DateFilter={0}\">{1}</a>",
                            grid.MasterTable.Columns[column.ColumnId].ColumnId,
                            column.Grid.GetSystemMessage("DateTimeSearch"));
                        writer.Write(s);
                    }
                    else
                    {
                        StringBuilder s = new StringBuilder(string.Empty);
                        s.AppendFormat(
                            "<a class=\"wglinkfield\" href=\"#\"   onclick=\"javascript:WGdisableDateTimeSearch('{0}');\";return false;\">{1}</a>",
                            column.ColumnId, column.Grid.GetSystemMessage("DateTimeSearchReset"));
                        writer.Write(s);
                    }
                    // From date
                    writer.Write("</span>");
                }
                addcolumn.RenderEndTag(writer, "</th>");
            }

            writer.Write("</tr>");
        }