1. Return event (1, Return to Silverlight page, 2, return to Web page)
private void Button_clickback (object sender, RoutedEventArgs e)
{
1. Return to Silverlight page:
This. Content = new Begincontrolchart (Stnameclick, strreportdate, false);//Add a parameter table name
2. Return to Web page
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 represents a relative path
}
2. Download Event
private void Btndown_click (object sender, RoutedEventArgs e)
{
Savetoimage (This.gridvisifire, Stnameclick);
}
private void Savetoimage (Grid ogrid, String stname)
{
Try
{
String schartname = "a"; Download picture name
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, +, stream);
Encoder. Encode ();
Back to the start
Stream. Seek (0, Seekorigin.begin);
return stream;
}
3. Print event (detailed reference: Silverlight Visifire Control chart making--silverlight background method print)
private void Btnprint_click (object sender, RoutedEventArgs e)
{
Start printing a picture, the Print dialog box appears
Printimage.print (Stnameclick);
}
4. Change time place name Event automatic Query Refresh page
Note : Define global variables public bool flag = FALSE;
flag, when all the controls on the page are assigned, assign the value: flag =true before querying
Change Time
private void Datestart_selecteddatechanged (object sender, SelectionChangedEventArgs e)
{
if (flag = = True)
{
Query ();
}
Else
{
Return
}
}
5. Chart shows data point events
Define global Variables public bool Isshowdata = FALSE;
Whether the chart displays data
private void Showdata_click (object sender, RoutedEventArgs e)
{
if (showdata.ischecked = = true)//tick
{
Isshowdata = true;
}
Else
{isshowdata = false;}
Query ();
}
6. Query button: (call 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)//Time control is invisible when time only displays the year
{
Strreportdate = This.dateYear.SelectedValue.ToString (). Substring (0, 4) + "0101";//The beginning of the current selected time year
}
Else
{
Strreportdate = this.dateStart.SelectedDate.Value.ToString ("YyyyMMdd");//Current selected value
}
Sxname = This.addressNameList.SelectionBoxItem.ToString ();//Current selected oilfield
Strmonth = strreportdate;
Svc. Getsinglechartdataasync (Strreportdate, Stnameclick, sxname);
}