using LiveChartsCore.SkiaSharpView.Extensions;
using LiveChartsCore;
using LogoForceTestApp.Modules.MainModule.Models;
using Prism.Events;
using Prism.Mvvm;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Timers;
using LiveChartsCore.SkiaSharpView.Painting;
using SkiaSharp;
using LiveChartsCore.Measure;
using Repository;
using Repository.Entiies;
using LiveChartsCore.SkiaSharpView;
using System.Collections.ObjectModel;
using LiveChartsCore.SkiaSharpView.VisualElements;
using LiveChartsCore.Defaults;
using FontFamily = System.Windows.Media.FontFamily;
using AutoMapper;
using System.Windows;
using ZXing.Maxicode;


namespace LogoForceTestApp.Modules.MainModule.ViewModels
{
    public class KBWindowViewModel : BindableBase
    {
        #region
        IRepository repository;
        private readonly IEventAggregator _eventAggregator;
        public ObservableCollection<HouseDto> MyHouse { get; set; }
        private readonly IMapper _mapper;
        //private readonly List<House> _myHouse;

        private string timeNow = DateTime.Now.ToString();
        public string TimeNow
        {
            get => timeNow;
            set { SetProperty(ref timeNow, value); }
        }
        private Timer _timer;
        public IEnumerable<ISeries> Series { get; set; }
        int[] outwork = new int[3];
        public string TotalPer { get; set; }
        public string ActualPer { get; set; }
        public string FallIllPer { get; set; }
        public string AbsenPer { get; set; }
        #region 产量
        public string BillNo { get; set; }
        public double AuxQty { get; set; } 
        public double Finished { get; set; } 

        private double _finishRate;

        public double FinishRate
        {
            get { return (Finished / Convert.ToDouble(AuxQty)) * 100;}
            set { SetProperty(ref _finishRate, value); }
        }
       
        #endregion

        #region 灯
        public string ImgLight1 { get; set; }//1号机
        public string ImgLight2 { get; set; }
        public string ImgLight3 { get; set; }
        public string ImgLight4 { get; set; }
        public string ImgLight5 { get; set; }
        public string ImgLight6 { get; set; }
        public string ImgLight7 { get; set; }
        public string ImgLight8 { get; set; }
        public string ImgLight9 { get; set; }
        public string ImgLight10 { get; set; }
        public string ImgLight11 { get; set; }
        public string ImgLight12 { get; set; }
        public string ImgLight13 { get; set; }
        public string ImgLight14 { get; set; }
        public string ImgLight15 { get; set; }//螺丝机
        public string ImgLight16 { get; set; }
        public string ImgLight17 { get; set; }
        public string ImgLight18 { get; set; }
        public string ImgLight19 { get; set; }
        public string ImgLight20 { get; set; }
        public string ImgLight21 { get; set; }//提升机
        public string ImgLight22 { get; set; }//检测机
        public string ImgLight23 { get; set; }//返修机
        #endregion
        public double TotalNum { get; set; } = 100;
        public double PassNum { get; set; } = 33;
        #endregion

        public KBWindowViewModel(IRepository repository, IEventAggregator eventAggregator,IMapper mapper)
        {
            this.repository = repository;
            this._eventAggregator = eventAggregator;
            Series = new List<ISeries>();
            #region timer
            _timer = new Timer();
            _timer.Interval = 3000;
            _timer.Elapsed += _timer_Elapsed;
            _timer.Start();
            this.repository = repository;
            #endregion

            #region chart显示文字
            string name = "微软雅黑";
            SKTypeface skTypeface = SKTypeface.FromFamilyName(name);
            if (skTypeface.FamilyName != name)
            {
                // 字体加载失败了
                skTypeface.Dispose();
            }
            FontFamily fontFamily = new(name);
            foreach (string familyNamesValue in fontFamily.FamilyNames.Values)
            {
                skTypeface = SKTypeface.FromFamilyName(familyNamesValue);
                if (skTypeface.FamilyName == familyNamesValue)
                    break;
                else
                {
                    skTypeface.Dispose();
                }
            }
            LiveChartsSkiaSharp.DefaultSKTypeface = skTypeface;

            #endregion
            _eventAggregator.GetEvent<AlarmEvent>().Subscribe(GetAlarmMessage);//接收另一个viewmodel的信息
            MyHouse = new ObservableCollection<HouseDto>();
            _mapper = mapper;
           
        }

        private void _timer_Elapsed(object sender, ElapsedEventArgs e)
        {
            TimeNow = DateTime.Now.ToString();

            var ename = new string[10] { "张", "王", "李", "赵", "刘", "张", "王", "李", "赵", "刘" };
            ShowPerson(ename);
            
            double[] dou = new double[] { 500, 200, 600, 800, 100, 200, 300 };
            SerLine(dou);


            _eventAggregator.GetEvent<QuestEvent>().Subscribe(ShowProcess);
            ShowHouse();
            ShowQuality();
            ShowOutWork();
            AlarmOK();
            double d = Convert.ToDouble(((PassNum / TotalNum) * 100).ToString("0.00"));
            PassRate(d);
        }
        #region 合格率
        public void PassRate(double passRate)
        {
            Series = GaugeGenerator.BuildSolidGauge(
           new GaugeItem(passRate, series =>
           {
               series.Fill = new SolidColorPaint(SKColors.YellowGreen);
               series.DataLabelsSize = 23;
               series.DataLabelsPaint = new SolidColorPaint(SKColors.LightPink);
               series.DataLabelsPosition = PolarLabelsPosition.ChartCenter;
               series.InnerRadius = 40;
           }),
           new GaugeItem(GaugeItem.Background, series =>
           {
               series.InnerRadius = 40;
               series.Fill = new SolidColorPaint(new SKColor(100, 181, 246, 90));
           }));
        }
        #endregion

        #region 出勤率

        public void ShowOutWork()
        {
            try
            {
                string str = DateTime.Now.ToString("yyyy/MM/dd");
                var list = repository.GetFirstDefault<OutofWork>(c => c.DateOutWork == str);
                if (list != null)
                {
                    outwork[0] = list.Actual;
                    outwork[1] = list.FallIll;
                    outwork[2] = list.Absenteeism;
                    int total = outwork[2] + outwork[1] + outwork[0];
                    OutWork(outwork[2], outwork[1], outwork[0],total);

                    string a = ((double)outwork[0] / (double)total).ToString("P");
                    string b = ((double)outwork[1] / (double)total).ToString("P");
                    string c = ((double)outwork[2] / (double)total).ToString("P");
                    TotalPer = $"应到人数:{total}";
                    ActualPer = $"实到人数:{outwork[0]}【{a}】";
                    FallIllPer = $"请假人数:{outwork[1]}【{b}】";
                    AbsenPer = $"旷工人数:{outwork[2]}【{c}】";
    }
            }
            catch (Exception ex)
            {

            }
        }
        public IEnumerable<ISeries> Series12 { get; set; }
        public double GaugeTotal12 { get; set; }
        public double InitialRotation12 { get; set; }
        public double MaxAngle12 { get; set; }
        /// <summary>
        /// "旷工人数","请假人数" ,"实到人数","应到人数"
        /// </summary>
        /// <param name="a"></param>
        /// <param name="b"></param>
        /// <param name="c"></param>
        /// <param name="d"></param>
        public void OutWork(int a, int b, int c,int d)
        {
            GaugeTotal12 = d;//最大数
            InitialRotation12 = 90;
            MaxAngle12 = 270;

            void SetStyle12(string name, PieSeries<ObservableValue> series)
            {
                series.Name = name;
                series.DataLabelsPosition = PolarLabelsPosition.Start;
                series.DataLabelsFormatter =
                    point => $"{point.Context.Series.Name} {point.Coordinate.PrimaryValue}";
                series.DataLabelsSize = 16;
                series.InnerRadius = 20;
                series.RelativeInnerRadius = 4;
                series.RelativeOuterRadius = 4;
                series.DataLabelsPaint = new SolidColorPaint(new SKColor(150, 150, 150));
            }

            Series12 = GaugeGenerator.BuildSolidGauge(
                new GaugeItem(a, series => SetStyle12("旷工人数", series)),
                new GaugeItem(b, series => SetStyle12("请假人数", series)),
                new GaugeItem(c, series => SetStyle12("实到人数", series)),
                new GaugeItem(d, series => SetStyle12("应到人数", series)),
                new GaugeItem(GaugeItem.Background, series =>
                {
                    series.InnerRadius = 20;
                    series.RelativeInnerRadius = 10;
                    series.RelativeOuterRadius = 10;
                }));
        }
        //public IEnumerable<ISeries> SeriesOutWork { get; set; }
        //private static int _index = 0;
        //private static string[] _names = new[] { "实到", "请假", "旷工" };

        //public void OutWork(int[] val)
        //{
        //    SeriesOutWork = val.AsPieSeries((value, series) =>
        //    {
        //        series.Name = _names[_index++ % _names.Length];
        //        series.DataLabelsPosition = LiveChartsCore.Measure.PolarLabelsPosition.Outer; // mark
        //        series.DataLabelsSize = 10;
        //        series.DataLabelsPaint = new SolidColorPaint(new SKColor(180, 180, 180));

        //        //series.DataLabelsFormatter =
        //        //   point =>
        //        //       $"This slide takes {point.Coordinate.PrimaryValue} " +
        //        //       $"out of {point.StackedValue!.Total} parts";
        //        //series.ToolTipLabelFormatter = point => $"{point.StackedValue!.Share:P2}";
        //        series.ToolTipLabelFormatter =
        //           point =>
        //           {
        //               var pv = point.Coordinate.PrimaryValue;
        //               var sv = point.StackedValue!;

        //               var a = $"{pv}/{sv.Total}{Environment.NewLine}{sv.Share:P2}";
        //               return a;
        //           };

        //        series.DataLabelsFormatter =
        //            point =>
        //            {
        //                var pv = point.Coordinate.PrimaryValue;
        //                var sv = point.StackedValue!;

        //                var a = $"{series.Name}{Environment.NewLine}{sv.Share:P2}";
        //                return a;
        //            };
        //    });

        //}

        #endregion

        #region 质量
        int[] qua1 = new int[10];int[] qua2 = new int[10]; int[] qua3 = new int[10];
        public void ShowQuality()
        {
            try
            {
                string str = DateTime.Now.ToString("yyyy/MM/dd");
                var list = repository.GetFirstDefault<Quality>(c => c.DateQuality == str);
                if (list != null)
                {
                    qua1[0] = list.Q1; qua1[1] = list.Q2; qua1[2] = list.Q3; qua1[3] = list.Q4; qua1[4] = list.Q5;
                    qua1[5] = list.Q6; qua1[6] = list.Q7; qua1[7] = list.Q8; qua1[8] = list.Q9; qua1[9] = list.Q10;
                    qua2[0] = list.Q11; qua2[1] = list.Q12; qua2[2] = list.Q13; qua2[3] = list.Q14; qua2[4] = list.Q15;
                    qua2[5] = list.Q16; qua2[6] = list.Q17; qua2[7] = list.Q18; qua2[8] = list.Q19; qua2[9] = list.Q20;
                    qua3[0] = list.Q21; qua3[1] = list.Q22; qua3[2] = list.Q23; qua3[3] = list.Q24; qua3[4] = list.Q25;
                    qua3[5] = list.Q26; qua3[6] = list.Q27; qua3[7] = list.Q28; qua3[8] = list.Q29; qua3[9] = list.Q30;
                    SerQuality1(qua1);
                    SerQuality2(qua2);
                    SerQuality3(qua3);
                }
            }
            catch (Exception)
            {

            }
        }
        #region 生产问题
        public void SerQuality1(int[] val)
        {
            SeriesQuality1[0].Values = val;
        }

        public ISeries[] SeriesQuality1 { get; set; } = new ISeries[]
        {
            new ColumnSeries<int>
            {
                Name = "数量",
                //Values = new[] {23, 27, 22, 29, 24 ,21,11,45,32,19},
                Stroke = null,
                DataLabelsPaint = new SolidColorPaint(new SKColor(180, 180, 180)),
                DataLabelsPosition = DataLabelsPosition.Top,
                Padding = 3,//每个条之间的距离

                //Fill = new LinearGradientPaint(
                //    new [] { new SKColor(255, 140, 148), new SKColor(220, 237, 194) },
                //    new SKPoint(0.5f, 0),
                //    new SKPoint(0.5f, 1))
                Fill = new LinearGradientPaint(new[]{new SKColor(255, 140, 148), new SKColor(220, 237, 194) })
            }
        };

        public Axis[] XAxes1 { get; set; } =
        {
            new Axis
            {
                Labels = new string[] { "螺丝未上紧","3D人脸无效" ,"螺丝漏打" ,"显示屏幕漏光" ,"胶体未打好",
                    "对讲喇叭无声","执手过于松紧" ,"螺丝打变形" ,"理线错乱" ,"弹簧未装好" },
                LabelsPaint = new SolidColorPaint(new SKColor(100, 100, 100)),
                LabelsRotation = 90,
                TextSize = 12,
                ForceStepToMin = true,
                MinStep = 1
            }
        };
        public Axis[] YAxes1 { get; set; } =
        {
            new Axis
            {
                LabelsPaint = new SolidColorPaint(new SKColor(100, 100, 100)),
                MinLimit=0,
                //最小步长
                //ForceStepToMin = true,
                //MinStep = 5
            }
        };
        #endregion
        #region 工艺问题
        public void SerQuality2(int[] val)
        {
            SeriesQuality2[0].Values = val;
        }

        public ISeries[] SeriesQuality2 { get; set; } = new ISeries[]
        {
            new ColumnSeries<int>
            {
                Name = "数量",
                //Values = new[] {23, 27, 22, 29, 24 ,21,11,45,32,19},
                Stroke = null,
                DataLabelsPaint = new SolidColorPaint(new SKColor(180, 180, 180)),
                DataLabelsPosition = DataLabelsPosition.Top,
                Padding = 3,//每个条之间的距离

                //Fill = new LinearGradientPaint(
                //    new [] { new SKColor(255, 140, 148), new SKColor(220, 237, 194) },
                //    new SKPoint(0.5f, 0),
                //    new SKPoint(0.5f, 1))
                Fill = new LinearGradientPaint(new[]{new SKColor(255, 140, 148), new SKColor(220, 237, 194) })
            }
        };

        public Axis[] XAxes2 { get; set; } =
        {
            new Axis
            {
                Labels = new string[] {"对讲无声","执手问题" ,"壳体脚位不平衡" ,"前板锁芯两孔位不一致" ,"后板显示屏水印",
                    "电池异常耗电","喷漆过厚导致组装困难" ,"设计线路太长" ,"执手靠垫片改善" ,"锁芯顶杆没固定位置"},
                LabelsPaint = new SolidColorPaint(new SKColor(100, 100, 100)),
                LabelsRotation = 90,
                TextSize = 12,
                ForceStepToMin = true,
                MinStep = 1
            }
        };
        public Axis[] YAxes2 { get; set; } =
        {
            new Axis
            {
                LabelsPaint = new SolidColorPaint(new SKColor(100, 100, 100)),
                MinLimit=0,
                //最小步长
                //ForceStepToMin = true,
                //MinStep = 5
            }
        };
        #endregion
        #region 物料问题
        public void SerQuality3(int[] val)
        {
            SeriesQuality3[0].Values = val;
        }

        public ISeries[] SeriesQuality3 { get; set; } = new ISeries[]
        {
            new ColumnSeries<int>
            {
                Name = "数量",
                //Values = new[] {23, 27, 22, 29, 24 ,21,11,45,32,19},
                Stroke = null,
                DataLabelsPaint = new SolidColorPaint(new SKColor(180, 180, 180)),
                DataLabelsPosition = DataLabelsPosition.Top,
                Padding = 3,//每个条之间的距离

                //Fill = new LinearGradientPaint(
                //    new [] { new SKColor(255, 140, 148), new SKColor(220, 237, 194) },
                //    new SKPoint(0.5f, 0),
                //    new SKPoint(0.5f, 1))
                Fill = new LinearGradientPaint(new[]{new SKColor(255, 140, 148), new SKColor(220, 237, 194) })
            }
        };

        public Axis[] XAxes3 { get; set; } =
        {
            new Axis
            {
                Labels = new string[] {"面板变形","电机异常" ,"屏幕异常" ,"物料毛刺" ,"大屏上支架变形",
                    "壳料划痕","显示屏水印" , "壳体脚位不平横" ,"装饰圈气泡脱皮" ,"电池异常"},
                LabelsPaint = new SolidColorPaint(new SKColor(100, 100, 100)),
                LabelsRotation = 90,
                TextSize = 12,
                ForceStepToMin = true,
                MinStep = 1
            }
        };
        public Axis[] YAxes3 { get; set; } =
        {
            new Axis
            {
                LabelsPaint = new SolidColorPaint(new SKColor(100, 100, 100)),
                MinLimit=0,
                //最小步长
                //ForceStepToMin = true,
                //MinStep = 5
            }
        };
        #endregion

        #endregion

        #region 人员管理
        public List<Person> PerManage { get; set; }
        private List<Person> PerManage1 { get; set; }
        public void PerManagement(string ename, string proce, string wtime, int ling)
        {
            //PerManage = new List<Person>();//放在外面就累加,放这里就不累加一直刷
            PerManage1.Add(new Person { Id = new Guid(), EmployeeName = ename, ProProcess = proce, WorkTime = wtime, Yield = ling });
            var m = PerManage1.OrderByDescending(x => x.Yield).ToList();//降序
            PerManage = m;

        }
        public void ShowPerson(string[] ename)
        {
            PerManage = new List<Person>();
            PerManage1 = new List<Person>();
            Random ran = new Random();
            for (int i = 0; i < ename.Length; i++)
            {
                int n = ran.Next(500);
                PerManagement(ename[i], "工序1", DateTime.Now.Second.ToString(), n);
            }
        }

        #endregion

        #region 仓库
       
        public void ShowHouse()
        {
            try
            {
                string str = DateTime.Now.ToString("yyyy/MM/dd");
                //var list = repository.GetAllQuery<House>(c => c.DateH == str);//查一个集合
                var list = repository.GetFirstDefault<House>(c => c.DateH == str);
                if (list!=null)
                {
                    var dto = _mapper.Map<HouseDto>(list);
                    Application.Current.Dispatcher.Invoke(new Action(() =>
                    {
                        MyHouse.Clear();
                        MyHouse.Add(dto);
                        SerHouse(double.Parse(list.LackH), double.Parse(list.UsedH), double.Parse(list.TotalH));
                    }));
                   
                    
                }
            }
            catch (Exception ex)
            {

            }
        }
        public IEnumerable<ISeries> Series13 { get; set; }
        public double GaugeTotal13 { get; set; }
        public double InitialRotation13 { get; set; }
        public double MaxAngle13 { get; set; }
        /// <summary>
        /// "缺料订单数","已领料订单数" ,"当日订单数"
        /// </summary>
        /// <param name="a">小</param>
        /// <param name="b">中</param>
        /// <param name="c">最大</param>
        public void SerHouse(double a, double b, double c)
        {
            GaugeTotal13 = c;//最大数
            InitialRotation13 = 90;
            MaxAngle13 = 270;

            void SetStyle13(string name, PieSeries<ObservableValue> series)
            {
                series.Name = name;
                series.DataLabelsPosition = PolarLabelsPosition.Start;
                series.DataLabelsFormatter =
                    point => $"{point.Context.Series.Name} {point.Coordinate.PrimaryValue}";
                series.DataLabelsSize = 16;
                series.InnerRadius = 20;
                series.RelativeInnerRadius = 4;
                series.RelativeOuterRadius = 4;
                series.DataLabelsPaint = new SolidColorPaint(new SKColor(150, 150, 150));
            }

            Series13 = GaugeGenerator.BuildSolidGauge(
                new GaugeItem(a, series => SetStyle13("缺料订单数", series)),
                new GaugeItem(b, series => SetStyle13("已领料订单数", series)),
                new GaugeItem(c, series => SetStyle13("当日订单数", series)),
                new GaugeItem(GaugeItem.Background, series =>
                {
                    series.InnerRadius = 20;
                    series.RelativeInnerRadius = 10;
                    series.RelativeOuterRadius = 10;
                }));
        }

        #endregion

        #region 设备状态
        public void AlarmOK()
        {
            ImgLight1 = System.Windows.Forms.Application.StartupPath + @"\image\绿灯.png";
            ImgLight2 = System.Windows.Forms.Application.StartupPath + @"\image\绿灯.png";
            ImgLight3 = System.Windows.Forms.Application.StartupPath + @"\image\绿灯.png";
            ImgLight4 = System.Windows.Forms.Application.StartupPath + @"\image\绿灯.png";
            ImgLight5 = System.Windows.Forms.Application.StartupPath + @"\image\绿灯.png";
            ImgLight6 = System.Windows.Forms.Application.StartupPath + @"\image\绿灯.png";
            ImgLight7 = System.Windows.Forms.Application.StartupPath + @"\image\绿灯.png";
            ImgLight8 = System.Windows.Forms.Application.StartupPath + @"\image\绿灯.png";
            ImgLight9 = System.Windows.Forms.Application.StartupPath + @"\image\绿灯.png";
            ImgLight10 = System.Windows.Forms.Application.StartupPath + @"\image\绿灯.png";
            ImgLight11 = System.Windows.Forms.Application.StartupPath + @"\image\绿灯.png";
            ImgLight12 = System.Windows.Forms.Application.StartupPath + @"\image\绿灯.png";
            ImgLight13 = System.Windows.Forms.Application.StartupPath + @"\image\绿灯.png";
            ImgLight14 = System.Windows.Forms.Application.StartupPath + @"\image\绿灯.png";
        }
        private void GetAlarmMessage(Dictionary<string, string> dictionary)//dictionary 就是接收到的信息
        {
            var keys = new List<string>(dictionary.Keys);
            for (int i = 0; i < keys.Count; i++)
            {
                var key = keys[i];
                var value = dictionary[key];
                #region 号机
                //1号机
                if ((key == "D1101" && value == "报警"))
                {
                    ImgLight1 = System.Windows.Forms.Application.StartupPath + @"\image\红灯.png";
                }
                if ((key == "D1141.15" && value == "缺料"))
                {
                    ImgLight1 = System.Windows.Forms.Application.StartupPath + @"\image\黄灯.png";
                }
                
                //2号机
                if ((key == "D1102" && value == "报警"))
                {
                    ImgLight2 = System.Windows.Forms.Application.StartupPath + @"\image\红灯.png";
                }
                if ((key == "D1142.15" && value == "缺料"))
                {
                    ImgLight2 = System.Windows.Forms.Application.StartupPath + @"\image\黄灯.png";
                }
                
                //3号机
                if ((key == "D1103" && value == "报警"))
                {
                    ImgLight3 = System.Windows.Forms.Application.StartupPath + @"\image\红灯.png";
                }
                if ((key == "D1143.15" && value == "缺料"))
                {
                    ImgLight3 = System.Windows.Forms.Application.StartupPath + @"\image\黄灯.png";
                }
                
                //4号机
                if ((key == "D1104" && value == "报警"))
                {
                    ImgLight4 = System.Windows.Forms.Application.StartupPath + @"\image\红灯.png";
                }
                if ((key == "D1144.15" && value == "缺料"))
                {
                    ImgLight4 = System.Windows.Forms.Application.StartupPath + @"\image\黄灯.png";
                }
                
                //5号机
                if ((key == "D1105" && value == "报警"))
                {
                    ImgLight5 = System.Windows.Forms.Application.StartupPath + @"\image\红灯.png";
                }
                if ((key == "D1145.15" && value == "缺料"))
                {
                    ImgLight5 = System.Windows.Forms.Application.StartupPath + @"\image\黄灯.png";
                }
               
                //6号机
                if ((key == "D1106" && value == "报警"))
                {
                    ImgLight6 = System.Windows.Forms.Application.StartupPath + @"\image\红灯.png";
                }
                if ((key == "D1146.15" && value == "缺料"))
                {
                    ImgLight6 = System.Windows.Forms.Application.StartupPath + @"\image\黄灯.png";
                }
               
                //7号机
                if ((key == "D1110" && value == "报警"))
                {
                    ImgLight7 = System.Windows.Forms.Application.StartupPath + @"\image\红灯.png";
                }
                if ((key == "D1150.15" && value == "缺料"))
                {
                    ImgLight7 = System.Windows.Forms.Application.StartupPath + @"\image\黄灯.png";
                }
                
                //8号机
                if ((key == "D1111" && value == "报警"))
                {
                    ImgLight8 = System.Windows.Forms.Application.StartupPath + @"\image\红灯.png";
                }
                if ((key == "D1151.15" && value == "缺料"))
                {
                    ImgLight8 = System.Windows.Forms.Application.StartupPath + @"\image\黄灯.png";
                }
                
                //9号机
                if ((key == "D1112" && value == "报警"))
                {
                    ImgLight9 = System.Windows.Forms.Application.StartupPath + @"\image\红灯.png";
                }
                if ((key == "D1152.15" && value == "缺料"))
                {
                    ImgLight9 = System.Windows.Forms.Application.StartupPath + @"\image\黄灯.png";
                }
                
                //10号机
                if ((key == "D1113" && value == "报警"))
                {
                    ImgLight10 = System.Windows.Forms.Application.StartupPath + @"\image\红灯.png";
                }
                if ((key == "D1153.15" && value == "缺料"))
                {
                    ImgLight10 = System.Windows.Forms.Application.StartupPath + @"\image\黄灯.png";
                }
                
                //11号机
                if ((key == "D1117" && value == "报警"))
                {
                    ImgLight11 = System.Windows.Forms.Application.StartupPath + @"\image\红灯.png";
                }
                if ((key == "D1157.15" && value == "缺料"))
                {
                    ImgLight11 = System.Windows.Forms.Application.StartupPath + @"\image\黄灯.png";
                }
                
                //12号机
                if ((key == "D1118" && value == "报警"))
                {
                    ImgLight12 = System.Windows.Forms.Application.StartupPath + @"\image\红灯.png";
                }
                if ((key == "D1158.15" && value == "缺料"))
                {
                    ImgLight12 = System.Windows.Forms.Application.StartupPath + @"\image\黄灯.png";
                }
                
                //13号机
                if ((key == "D1119" && value == "报警"))
                {
                    ImgLight13 = System.Windows.Forms.Application.StartupPath + @"\image\红灯.png";
                }
                if ((key == "D1159.15" && value == "缺料"))
                {
                    ImgLight13 = System.Windows.Forms.Application.StartupPath + @"\image\黄灯.png";
                }
                
                //14号机
                if ((key == "D1120" && value == "报警"))
                {
                    ImgLight14 = System.Windows.Forms.Application.StartupPath + @"\image\红灯.png";
                }
                if ((key == "D1160.15" && value == "缺料"))
                {
                    ImgLight14 = System.Windows.Forms.Application.StartupPath + @"\image\黄灯.png";
                }
                
                #endregion
                #region 螺丝机
                //螺丝机1
                if ((key == "D1107" && value == "报警"))
                {
                    ImgLight15 = System.Windows.Forms.Application.StartupPath + @"\image\红灯.png";
                }
                if ((key == "D1107" && value == "正常"))
                {
                    ImgLight15 = System.Windows.Forms.Application.StartupPath + @"\image\绿灯.png";
                }
                //螺丝机2
                if ((key == "D1108" && value == "报警"))
                {
                    ImgLight16 = System.Windows.Forms.Application.StartupPath + @"\image\红灯.png";
                }
                if ((key == "D1108" && value == "正常"))
                {
                    ImgLight16 = System.Windows.Forms.Application.StartupPath + @"\image\绿灯.png";
                }
                //螺丝机3
                if ((key == "D1115" && value == "报警"))
                {
                    ImgLight17 = System.Windows.Forms.Application.StartupPath + @"\image\红灯.png";
                }
                if ((key == "D1115" && value == "正常"))
                {
                    ImgLight17 = System.Windows.Forms.Application.StartupPath + @"\image\绿灯.png";
                }
                //螺丝机4
                if ((key == "D1116" && value == "报警"))
                {
                    ImgLight18 = System.Windows.Forms.Application.StartupPath + @"\image\红灯.png";
                }
                if ((key == "D1116" && value == "正常"))
                {
                    ImgLight18 = System.Windows.Forms.Application.StartupPath + @"\image\绿灯.png";
                }
                //螺丝机5
                if ((key == "D1121" && value == "报警"))
                {
                    ImgLight19 = System.Windows.Forms.Application.StartupPath + @"\image\红灯.png";
                }
                if ((key == "D1121" && value == "正常"))
                {
                    ImgLight19 = System.Windows.Forms.Application.StartupPath + @"\image\绿灯.png";
                }
                //螺丝机6
                if ((key == "D1122" && value == "报警"))
                {
                    ImgLight20 = System.Windows.Forms.Application.StartupPath + @"\image\红灯.png";
                }
                if ((key == "D1122" && value == "正常"))
                {
                    ImgLight20 = System.Windows.Forms.Application.StartupPath + @"\image\绿灯.png";
                }
                #endregion
                //提升机
                if ((key == "D1100" && value == "报警") || (key == "D1124" && value == "报警") || (key == "D1125" && value == "报警"))
                {
                    ImgLight21 = System.Windows.Forms.Application.StartupPath + @"\image\红灯.png";
                }
                if ((key == "D1100" && value == "正常") || (key == "D1124" && value == "正常") || (key == "D1125" && value == "正常"))
                {
                    ImgLight21 = System.Windows.Forms.Application.StartupPath + @"\image\绿灯.png";
                }
                //检测
                if ((key == "D1166.0" && value == "缺料") || (key == "D1166.1" && value == "缺料") || (key == "D1166.2" && value == "缺料") || (key == "D1166.3" && value == "缺料"))
                {
                    ImgLight22 = System.Windows.Forms.Application.StartupPath + @"\image\黄灯.png";
                }
                if ((key == "D1166.0" && value == "正常") || (key == "D1166.1" && value == "正常") || (key == "D1166.2" && value == "正常") || (key == "D1166.3" && value == "正常"))
                {
                    ImgLight22 = System.Windows.Forms.Application.StartupPath + @"\image\绿灯.png";
                }
                //返修
                if ((key == "D1166.4" && value == "缺料") || (key == "D1166.5" && value == "缺料") || (key == "D1166.6" && value == "缺料"))
                {
                    ImgLight23 = System.Windows.Forms.Application.StartupPath + @"\image\黄灯.png";
                }
                if ((key == "D1166.4" && value == "正常") || (key == "D1166.5" && value == "正常") || (key == "D1166.6" && value == "正常"))
                {
                    ImgLight23 = System.Windows.Forms.Application.StartupPath + @"\image\绿灯.png";
                }
            }

        }
        #endregion

        #region 生产进度
        public void SerLine(double[] val)
        {
            SeriesLine[0].Values = val.ToArray();
        }
       
        public ISeries[] SeriesLine { get; set; } =
        {
            new LineSeries<double>
            {
            Name = "产量",
            //Values = new []{ 4, 2, 8, 5, 3 },
            GeometrySize = 12,
            Stroke = new LinearGradientPaint(new[]{ new SKColor(45, 64, 89), new SKColor(255, 212, 96)}) { StrokeThickness = 5 },
            GeometryStroke = new LinearGradientPaint(new[]{ new SKColor(45, 64, 89), new SKColor(255, 212, 96)}) { StrokeThickness = 5 },
            Fill = null
            //Fill = new SolidColorPaint(new SKColor(255, 212, 96, 90))
            }
        };
        public LabelVisual PcTitle { get; set; } =
        new LabelVisual
        {
                Text = "近一周产量趋势",
                TextSize = 16,
                Padding = new LiveChartsCore.Drawing.Padding(15),
                Paint = new SolidColorPaint(new SKColor(47,152,255))
            };

        public DrawMarginFrame DrawMarginFrame => new()
        {
            Stroke = new SolidColorPaint(new SKColor(45, 64, 89), 2)
        };

        public Axis[] XAxesLine { get; set; } =
        {
            new Axis
            {
                Labels = new string[] { "1","2" ,"3" ,"4" ,"5","6","7"},
                LabelsPaint = new SolidColorPaint(new SKColor(100, 100, 100)),
                LabelsRotation = 0,
                ForceStepToMin = true,
                MinLimit=0,
                MinStep = 1
            }
        };
        public Axis[] YAxesLine { get; set; } =
        {
            new Axis
            {
                LabelsPaint = new SolidColorPaint(new SKColor(100, 100, 100)),
                MinLimit=0,
                //最小步长
                //ForceStepToMin = true,
                //MinStep = 5
            }
        };
        #endregion

        public void ShowProcess(string str)
        {
            var customRepo = new CustomRepository();
            try
            {
                //DateTime max = DateTime.Today.AddDays(1);
                //DateTime min = DateTime.Today.AddDays(-1);
                DateTime d = DateTime.Today;
                var list = customRepo.GetFirstDefault<ICMO>(c => c.FDate == d && c.FBillNo == str);
                if (list != null)
                {
                    BillNo = str;
                    AuxQty=(double)list.FAuxQty;
                }
            }
            catch (Exception ex)
            {

            }

        }

    }
}