示例#1
0
        private async void _OpcProcessor_TagValidated(Models.Tag tag)
        {
            if (tag != null)
            {
                var pos  = MainLineCollection.FirstOrDefault(x => x.X == tag.Handle);
                var errp = MainLineCollection.Count(x => x.Y > LimSup || x.Y < LimInf);

                if (pos != null)
                {
                    await Task.Delay(_Delay).ContinueWith(async(h) =>
                    {
                        pos.Y = _gaugeXlValue;
                        await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal,
                                                  () =>
                        {
                            MainLineSeries.Refresh();
                            labelActual.Text         = _gaugeXlValue.ToString("00.00");
                            bool error               = errp > LimErr / 100 * MainLineCollection.Count;
                            WarningBanner.Background = error ? new SolidColorBrush(Windows.UI.Color.FromArgb(255, 255, 0, 0)) : new SolidColorBrush(Windows.UI.Color.FromArgb(255, 255, 255, 255));
                            var avg            = MainLineCollection.Average(x => x.Y);
                            labelPromedio.Text = avg.ToString("00.00");
                            labelPaso.Text     = "Pos. " + (MainLineCollection.IndexOf(pos) + 1);
                        });
                    });
                }
            }
        }
示例#2
0
 private async void ResetButton_Click(object sender, RoutedEventArgs e)
 {
     MainLineCollection.ToList().ForEach(x =>
     {
         x.Y = 0;
     });
     MainLineCollectionH.Clear();
     CountingCollection.Clear();
     cycleCount      = 0;
     CycleCount.Text = "-";
     await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal,
                               () =>
     {
         MainLineSeries.Refresh();
     });
 }
示例#3
0
        private async void ImprimirButton_Click(object sender, RoutedEventArgs e)
        {
            if (CountingCollection.Count <= 0)
            {
                var dialog = new MessageDialog("No se ha completado al menos un ciclo");
                await dialog.ShowAsync();

                return;
            }
            List <Models.Point> avgs = new List <Models.Point>();

            for (int i = 0; i < CountingCollection.First().Count; i++)
            {
                var p = new Models.Point(CountingCollection.First()[i].X, 0);
                avgs.Add(p);
            }

            var csvString = new System.Text.StringBuilder();

            CountingCollection.ForEach(y =>
            {
                var line = "";
                y.ForEach(x =>
                {
                    line += x.Y + ",";
                    avgs.First(z => z.X == x.X).Y += x.Y;
                });
                csvString.AppendLine(line);
            });
            avgs.ForEach(y =>
            {
                y.Y = y.Y / CountingCollection.Count;
            });
            avgs.ForEach(y =>
            {
                MainLineCollection.ToList().First(x => x.X == y.X).Y = y.Y;
            });
            await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal,
                                      () =>
            {
                MainLineSeries.Refresh();
            });

            LineChart.Width  = LineChart.ActualWidth;
            LineChart.Height = LineChart.ActualHeight;
            var bitmap = new RenderTargetBitmap();
            await bitmap.RenderAsync(LineChart, (int)LineChart.Width, (int)LineChart.Height);

            var pixelBuffer = await bitmap.GetPixelsAsync();

            var displayInformation = DisplayInformation.GetForCurrentView();
            var guid = Guid.NewGuid();
            var file = await ApplicationData.Current.LocalFolder.CreateFileAsync(guid + ".png", CreationCollisionOption.ReplaceExisting);

            var csvfile = await ApplicationData.Current.LocalFolder.CreateFileAsync(guid + ".csv", CreationCollisionOption.ReplaceExisting);

            using (var stream = await file.OpenAsync(FileAccessMode.ReadWrite))
            {
                var encoder = await Windows.Graphics.Imaging.BitmapEncoder.CreateAsync(Windows.Graphics.Imaging.BitmapEncoder.PngEncoderId, stream);

                encoder.SetPixelData(BitmapPixelFormat.Bgra8,
                                     BitmapAlphaMode.Premultiplied,
                                     (uint)LineChart.ActualWidth,
                                     (uint)LineChart.ActualHeight,
                                     displayInformation.RawDpiX,
                                     displayInformation.RawDpiY,
                                     pixelBuffer.ToArray());
                await encoder.FlushAsync();
            }
            using (var stream = await csvfile.OpenAsync(FileAccessMode.ReadWrite))
            {
                await stream.AsStreamForWrite().WriteAsync(System.Text.Encoding.ASCII.GetBytes(csvString.ToString()), 0, csvString.Length);
            }
            var page = new PageToPrint();
            var bmp  = new BitmapImage(new Uri("ms-appdata:///local/" + guid + ".png"));

            page.ScenarioImage.Source   = bmp;
            page.OrdenTextBlock.Text    = labelOrderCustName.Text.ToUpper();
            page.SkuTextBlock.Text      = labelOrderSku.Text;
            page.OperadorTextBlock.Text = labelOrderOperador.Text.ToUpper();
            page.TurnoTextBlock.Text    = labelOrderTurno.Text;
            page.LongitudTextBlock.Text = labelOrderLongitud.Text;
            page.AdhesivoTextBlock.Text = labelOrderAdhesivo.Text;
            page.AreaTextBlock.Text     = labelOrderArea.Text;
            var observaciones = new System.Text.StringBuilder();
            var ix            = 0;

            if (!string.IsNullOrEmpty(labelOrderObservaciones.Text))
            {
                while (true)
                {
                    var line = "";
                    try
                    {
                        line = labelOrderObservaciones.Text.Substring(ix, 60);
                        ix  += 60;
                        observaciones.AppendLine(line);
                    }
                    catch (ArgumentOutOfRangeException)
                    {
                        line = labelOrderObservaciones.Text.Substring(ix);
                        observaciones.AppendLine(line);
                        break;
                    }
                }
            }

            page.ObservacionesTextBlock.Text = observaciones.ToString();
            page.DensPromTextBlock.Text      = avgs.Average(x => x.Y).ToString("#0.00");

            var printHelper = new Services.PrintHelper(this);

            printHelper.StatusChanged += async(string message, int type) =>
            {
                printHelper.UnregisterForPrinting();
                printHelper = null;
                page.ScenarioImage.Source = null;
                try
                {
                    await file.DeleteAsync();
                }
                catch (Exception)
                {
                }
                ResetButton_Click(sender, e);
            };
            printHelper.RegisterForPrinting();
            printHelper.PreparePrintContent(page);
            await printHelper.ShowPrintUIAsync();
        }