silverlight visifire控件图表制作——silverlight 后台方法页面事件

1、返回事件 (1、返回silverlight页面,2、返回web页面)

        private void button_ClickBack(object sender, RoutedEventArgs e)
        {

    1、返回silverlight页面:

           this.Content = new BeginControlChart(sTNameClick, strReportDate, false);//增加个参数表名

    2、返回web页面                  

       HtmlWindow html = HtmlPage.Window;
string strUri = Application.Current.Host.Source.AbsoluteUri.Substring(0, Application.Current.Host.Source.AbsoluteUri.IndexOf("/ClientBin")) + "/Business/DataQuery/StoreQuery.aspx?IsStoreBack=true";
 html.Navigate(new Uri(strUri));
                //HtmlWindow html = HtmlPage.Window;
                //html.Navigate(new Uri("../Business/DataQuery/StoreQuery.aspx?IsStoreBack=true", UriKind.Relative));
                //Urikind.Relative表示相对路径

       }

2、下载事件

 private void btnDown_Click(object sender, RoutedEventArgs e)
        {
            SaveToImage(this.gridVisifire, sTNameClick);
        }

 

 private void SaveToImage(Grid oGrid, string sTName)
        {
            try
            {
                string sChartName = "a"; //下载图片名称
                WriteableBitmap bitmap = new WriteableBitmap(oGrid, null);
                if (bitmap != null)
                {
                    SaveFileDialog saveDlg = new SaveFileDialog();
                    saveDlg.Filter = "JPEG Files (*.jpeg)|*.jpeg";
                    saveDlg.DefaultExt = ".jpeg";
                    saveDlg.DefaultFileName = sChartName;//oGrid.Name;

                    if ((bool)saveDlg.ShowDialog())
                    {
                        using (Stream fs = saveDlg.OpenFile())
                        {
                            MemoryStream stream = GetImageStream(bitmap);
                            byte[] binaryData = new Byte[stream.Length];
                            long bytesRead = stream.Read(binaryData, 0, (int)stream.Length);
                            fs.Write(binaryData, 0, binaryData.Length);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

public static MemoryStream GetImageStream(WriteableBitmap bitmap)
        {
            byte[][,] raster = ReadRasterInformation(bitmap);
            return EncodeRasterInformationToStream(raster, ColorSpace.RGB);
        }

public static byte[][,] ReadRasterInformation(WriteableBitmap bitmap)
        {
            int width = bitmap.PixelWidth;
            int height = bitmap.PixelHeight;
            int bands = 3;
            byte[][,] raster = new byte[bands][,];
            for (int i = 0; i < bands; i++)
            {
                raster[i] = new byte[width, height];
            }
            for (int row = 0; row < height; row++)
            {
                for (int column = 0; column < width; column++)
                {
                    int pixel = bitmap.Pixels[width * row + column];
                    raster[0][column, row] = (byte)(pixel >> 16);
                    raster[1][column, row] = (byte)(pixel >> 8);
                    raster[2][column, row] = (byte)pixel;
                }
            }
            return raster;
        }

public static MemoryStream EncodeRasterInformationToStream(byte[][,] raster, ColorSpace colorSpace)
        {
            ColorModel model = new ColorModel { colorspace = ColorSpace.RGB };
            FluxJpeg.Core.Image img = new FluxJpeg.Core.Image(model, raster);

            //Encode the Image as a JPEG
            MemoryStream stream = new MemoryStream();
            FluxJpeg.Core.Encoder.JpegEncoder encoder = new FluxJpeg.Core.Encoder.JpegEncoder(img, 100, stream);
            encoder.Encode();

            // Back to the start
            stream.Seek(0, SeekOrigin.Begin);
            return stream;

        }

3、打印事件(详细参考:silverlight visifire控件图表制作——silverlight 后台方法打印)

 private void btnPrint_Click(object sender, RoutedEventArgs e)
        {
            //启动打印图片,出现打印对话框 
            printImage.Print(sTNameClick);
        }

4、更改时间地名 事件 自动查询刷新页面

注意:定义全局变量 public bool flag = false;

在构造方法中给页面控件赋默认选中值时会触发dateStart_SelectedDateChanged等方法,所以定义全局变量flag ,页面所有控件赋值完成后,赋值:flag =true 之后再进行查询

//更改时间
 private void dateStart_SelectedDateChanged(object sender, SelectionChangedEventArgs e)
        {
            if (flag == true)
            {
                Query();
            }
            else
            {
                return;
            }
        }

5、图表显示数据点事件

定义全局变量  public bool isShowData = false;

//图表是否显示数据
 private void showData_Click(object sender, RoutedEventArgs e)
        {
            if (showData.IsChecked == true) //勾选
            {
                isShowData = true;
            }
            else
            { isShowData = false; }
            Query();
        }

6、查询按钮:(调用wcf)

private void button_ClickQuery(object sender, RoutedEventArgs e)
      {
   DBServiceClient svc = new DBServiceClient();
       svc.GetSingleChartDataCompleted += new EventHandler<GetSingleChartDataCompletedEventArgs>(svc_GetSingleChartDataCompleted);
         string strReportDate = "";
   if (this.dateStart.Visibility == Visibility.Collapsed)//时间控件为不可见时 即时间只显示年份
          {
          strReportDate = this.dateYear.SelectedValue.ToString().Substring(0, 4) + "0101";//当前选定时间年份的年初
          }
    else
          {
          strReportDate = this.dateStart.SelectedDate.Value.ToString("yyyyMMdd");//当前选定值
  }
        sXName = this.addressNameList.SelectionBoxItem.ToString();//当前选定油田
         strMonth = strReportDate;
        svc.GetSingleChartDataAsync(strReportDate, sTNameClick, sXName);
      }

silverlight visifire控件图表制作——silverlight 后台方法页面事件,古老的榕树,5-wow.com

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。