Exemple #1
0
        internal override void RenderLabelView(WebGridHtmlWriter writer, RowCell cell)
        {
            string uniqueID = cell.CellClientId;

            if (ChartType == ChartType.HorizontalBar)
            {
                if (m_Image == null) // Draw using table
                {
                    StringBuilder bg = new StringBuilder(string.Empty);
                    if (BackgroundImage != null)
                    {
                        bg.AppendFormat(" background=\"{0}\"", BackgroundImage);
                    }
                    StringBuilder s = new StringBuilder(string.Empty);
                    s.AppendFormat("<table height=\"{0}\">", HeightEditableColumn);
                    if (m_StartImage != null)
                    {
                        s.AppendFormat(
                            "<td><img alt=\"{2}\" border=\"0\" src=\"{0}\"  height={1}/></td>", m_StartImage,
                            HeightEditableColumn, Title);
                    }
                    s.AppendFormat("<td width=\"{0}\" {1}></td>", BarWidth, bg);
                    if (m_EndImage != null)
                    {
                        s.AppendFormat(
                            "<td><img alt=\"{2}\" border=\"0\" src=\"{0}\"  height={1}/></td>", m_EndImage,
                            HeightEditableColumn, Title);
                    }
                    s.Append("</table>");
                    LabelHtml(s.ToString(), writer, cell);
                    return;
                }
                else // Draw using image
                {
                    StringBuilder s = new StringBuilder(string.Empty);
                    if (m_StartImage != null)
                    {
                        s.AppendFormat("<img alt=\"{2}\" border=\"0\" src=\"{0}\"  height={1}/>",
                                       m_StartImage, HeightEditableColumn, Title);
                    }
                    s.AppendFormat("<img alt=\"{3}\" border=\"0\" src=\"{0}\"  height={1} width={2}/>",
                                   m_Image, HeightEditableColumn, BarWidth, Title);
                    if (m_EndImage != null)
                    {
                        s.AppendFormat("<img alt=\"{2}\" border=\"0\" src=\"{0}\"  height={1}/>", m_EndImage,
                                       HeightEditableColumn, Title);
                    }

                    LabelHtml(s.ToString(), writer, cell);
                    return;
                }
            }
            if (ChartType == ChartType.HorizontalBar)
            {
                // 2005.01.09 - jorn, string optimization
                StringBuilder namesBuilder = new StringBuilder();
                string        values       = string.Empty;
                Table         t            = Grid.MasterTable;
                for (int i = 0; i < t.Rows.Count; i++)
                {
                    if (namesBuilder.Length != 0)
                    {
                        namesBuilder.Append(",");
                    }
                    if (values.Length != 0)
                    {
                        values += ",";
                    }
                    namesBuilder.Append(HttpUtility.UrlEncode(t.Rows[i][TitleColumn].Value.ToString(), Encoding.Default));
                    try
                    {
                        values +=
                            HttpUtility.UrlEncode(t.Rows[i][ValueColumn].Value.ToString().Replace(",", "."),
                                                  Encoding.Default);
                    }
                    catch
                    {
                        values += "0";
                    }
                }

                string width = "150";
                if (WidthEditableColumn.IsEmpty == false)
                {
                    width = WidthEditableColumn.Value.ToString();
                }
                string s =
                    string.Format(
                        "<img alt=\"{4}\" border=\"0\" src=\"?wgpiechart={0}&values={1}&names={2}&width={3}\"/>",
                        uniqueID, values, namesBuilder, width, Title);
                LabelHtml(s, writer, cell);
                return;
            }
            else
            {
                ArrayList values = new ArrayList();

                Table t = Grid.MasterTable;
                for (int i = 0; i < t.Rows.Count; i++)
                {
                    double val  = double.Parse(t.Rows[i][ValueColumn].Value.ToString());
                    string name = string.Empty;
                    if (t.Rows[i][TitleColumn].Value != null)
                    {
                        name = t.Rows[i][TitleColumn].Value.ToString();
                    }

                    ChartValue cv = new ChartValue(name, val);
                    values.Add(cv);

                    /*					if(names != string.Empty) names += ",";
                     *                  if(values != string.Empty) values += ",";
                     *                  names += HttpUtility.UrlEncode( t.Rows[i][ TitleColumn ].Value );
                     *                  try
                     *                  {
                     *                      values += HttpUtility.UrlEncode( t.Rows[i][ ValueColumn ].Value.Replace(",",".") );
                     *                  }
                     *                  catch
                     *                  {
                     *                      values += "0";
                     *                  }*/
                }

                int width = (int)WidthEditableColumn.Value;
                if (width < 16)
                {
                    width = 150;
                }
                int height = (int)HeightEditableColumn.Value;
                if (height < 16)
                {
                    height = 200;
                }

                //try
                //{
                Util.Chart c = new Util.Chart(ChartType, width, height);
                if (BackgroundImage != null && Grid.GotHttpContext)
                {
                    if (BackgroundImage.ToUpperInvariant().StartsWith("HTTP://") == false)
                    {
                        BackgroundImage = HttpContext.Current.Server.MapPath(BackgroundImage);
                    }
                    c.ChartBackground = new ChartBackground(BackgroundImage);
                }
                c.ShowPieValues          = false;
                c.ChartHeadline.Headline = Title;
                c.AddDataArray(values);
                c.RenderLabelBoard = TitleBoardOnChart;
                if (Grid.GotHttpContext)
                {
                    HttpContext.Current.Session[string.Format("{0}_{1}_img", Grid.ClientID, uniqueID)] = c.Render();
                }

                string s; //src=\"?wgchart=" + this.Grid.ColumnId + "_" + this.FormElementName + "_img\"
                if (Grid.GotHttpContext &&
                    HttpContext.Current.Request.Browser.Type.ToUpperInvariant().StartsWith("IE"))
                {
                    s =
                        string.Format(
                            "<img height=\"{0}\" width=\"{1}\"  src=\"{2}\" style=\"filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='?wgchart={3}_{4}_img', sizingMethod='scale');\" alt=\"{5}\" border=\"0\" />",
                            Unit.Pixel(height), Unit.Pixel(width), Grid.Page.ClientScript.GetWebResourceUrl(Grid.GetType(), "WebGrid.Resources.images.transparent.gif"), Grid.ClientID, uniqueID, Title);
                }
                else
                {
                    s =
                        string.Format("<img alt=\"{2}\" border=\"0\" src=\"?wgchart={0}_{1}_img\"/>",
                                      Grid.ClientID, uniqueID, Title);
                }
                LabelHtml(s, writer, cell);
                return;
            }

            /*
             * else		// impossible!!!
             * {
             *  return null;
             * }*/
        }
Exemple #2
0
        internal override void RenderLabelView(WebGridHtmlWriter writer, RowCell cell)
        {
            string uniqueID = cell.CellClientId;
            if (ChartType == ChartType.HorizontalBar)
            {
                if (m_Image == null) // Draw using table
                {
                    StringBuilder bg = new StringBuilder(string.Empty);
                    if (BackgroundImage != null)
                        bg.AppendFormat(" background=\"{0}\"", BackgroundImage);
                    StringBuilder s = new StringBuilder(string.Empty);
                    s.AppendFormat("<table height=\"{0}\">", HeightEditableColumn);
                    if (m_StartImage != null)
                        s.AppendFormat(
                            "<td><img alt=\"{2}\" border=\"0\" src=\"{0}\"  height={1}/></td>", m_StartImage,
                            HeightEditableColumn, Title);
                    s.AppendFormat("<td width=\"{0}\" {1}></td>", BarWidth, bg);
                    if (m_EndImage != null)
                        s.AppendFormat(
                            "<td><img alt=\"{2}\" border=\"0\" src=\"{0}\"  height={1}/></td>", m_EndImage,
                            HeightEditableColumn, Title);
                    s.Append("</table>");
                    LabelHtml(s.ToString(), writer, cell);
                    return;
                }
                else // Draw using image
                {
                    StringBuilder s = new StringBuilder(string.Empty);
                    if (m_StartImage != null)
                        s.AppendFormat("<img alt=\"{2}\" border=\"0\" src=\"{0}\"  height={1}/>",
                                       m_StartImage, HeightEditableColumn, Title);
                    s.AppendFormat("<img alt=\"{3}\" border=\"0\" src=\"{0}\"  height={1} width={2}/>",
                                   m_Image, HeightEditableColumn, BarWidth, Title);
                    if (m_EndImage != null)
                        s.AppendFormat("<img alt=\"{2}\" border=\"0\" src=\"{0}\"  height={1}/>", m_EndImage,
                                       HeightEditableColumn, Title);

                    LabelHtml(s.ToString(), writer, cell);
                    return;
                }
            }
            if (ChartType == ChartType.HorizontalBar)
            {
                // 2005.01.09 - jorn, string optimization
                StringBuilder namesBuilder = new StringBuilder();
                string values = string.Empty;
                Table t = Grid.MasterTable;
                for (int i = 0; i < t.Rows.Count; i++)
                {
                    if (namesBuilder.Length != 0) namesBuilder.Append(",");
                    if (values.Length != 0) values += ",";
                    namesBuilder.Append(HttpUtility.UrlEncode(t.Rows[i][TitleColumn].Value.ToString(), Encoding.Default));
                    try
                    {
                        values +=
                            HttpUtility.UrlEncode(t.Rows[i][ValueColumn].Value.ToString().Replace(",", "."),
                                                  Encoding.Default);
                    }
                    catch
                    {
                        values += "0";
                    }
                }

                string width = "150";
                if (WidthEditableColumn.IsEmpty == false)
                    width = WidthEditableColumn.Value.ToString();
                string s =
                    string.Format(
                        "<img alt=\"{4}\" border=\"0\" src=\"?wgpiechart={0}&values={1}&names={2}&width={3}\"/>",
                        uniqueID, values, namesBuilder, width, Title);
                LabelHtml(s, writer, cell);
                return;
            }
            else
            {
                ArrayList values = new ArrayList();

                Table t = Grid.MasterTable;
                for (int i = 0; i < t.Rows.Count; i++)
                {
                    double val = double.Parse(t.Rows[i][ValueColumn].Value.ToString());
                    string name = string.Empty;
                    if (t.Rows[i][TitleColumn].Value != null)
                        name = t.Rows[i][TitleColumn].Value.ToString();

                    ChartValue cv = new ChartValue(name, val);
                    values.Add(cv);

                    /*					if(names != string.Empty) names += ",";
                                        if(values != string.Empty) values += ",";
                                        names += HttpUtility.UrlEncode( t.Rows[i][ TitleColumn ].Value );
                                        try
                                        {
                                            values += HttpUtility.UrlEncode( t.Rows[i][ ValueColumn ].Value.Replace(",",".") );
                                        }
                                        catch
                                        {
                                            values += "0";
                                        }*/
                }

                int width = (int)WidthEditableColumn.Value;
                if (width < 16) width = 150;
                int height = (int)HeightEditableColumn.Value;
                if (height < 16) height = 200;

                //try
                //{
                Util.Chart c = new Util.Chart(ChartType, width, height);
                if (BackgroundImage != null && Grid.GotHttpContext)
                {
                    if (BackgroundImage.ToUpperInvariant().StartsWith("HTTP://") == false)
                        BackgroundImage = HttpContext.Current.Server.MapPath(BackgroundImage);
                    c.ChartBackground = new ChartBackground(BackgroundImage);
                }
                c.ShowPieValues = false;
                c.ChartHeadline.Headline = Title;
                c.AddDataArray(values);
                c.RenderLabelBoard = TitleBoardOnChart;
                if (Grid.GotHttpContext)
                    HttpContext.Current.Session[string.Format("{0}_{1}_img", Grid.ClientID, uniqueID)] = c.Render();

                string s; //src=\"?wgchart=" + this.Grid.ColumnId + "_" + this.FormElementName + "_img\"
                if (Grid.GotHttpContext &&
                    HttpContext.Current.Request.Browser.Type.ToUpperInvariant().StartsWith("IE"))
                    s =
                        string.Format(
                            "<img height=\"{0}\" width=\"{1}\"  src=\"{2}\" style=\"filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='?wgchart={3}_{4}_img', sizingMethod='scale');\" alt=\"{5}\" border=\"0\" />",
                            Unit.Pixel(height), Unit.Pixel(width), Grid.Page.ClientScript.GetWebResourceUrl(Grid.GetType(), "WebGrid.Resources.images.transparent.gif"), Grid.ClientID, uniqueID, Title);
                else
                {
                    s =
                        string.Format("<img alt=\"{2}\" border=\"0\" src=\"?wgchart={0}_{1}_img\"/>",
                                      Grid.ClientID, uniqueID, Title);
                }
                LabelHtml(s, writer, cell);
                return;
            }
            /*
            else		// impossible!!!
            {
                return null;
            }*/
        }