Ejemplo n.º 1
0
        private void LoadMstOrdersFromDb(int recordsQuantity)
        {
            var       nc       = MST.MES.SqlOperations.ConnectDB.Nc12ToModelFullDict();
            DataTable sqlTable = SqlOperations.GetMstSmtRecordsFromDb(recordsQuantity, smtLine);
            var       smto     = MST.MES.SqlDataReaderMethods.SMT.GetOneOrder("");

            dataGridViewMstOrders.Columns["MstOrdersStart"].DefaultCellStyle.Format = "HH:mm dd-MMM";
            dataGridViewMstOrders.Columns["MstOrdersEnd"].DefaultCellStyle.Format   = "HH:mm dd-MMM";

            List <EfficiencyCalculation.OrderDataForEfficiencyStructure> ordersEff = new List <EfficiencyCalculation.OrderDataForEfficiencyStructure>();

            if (sqlTable.Rows.Count > 0)
            {
                HashSet <string> nc12ToModelList = new HashSet <string>();
                foreach (DataRow row in sqlTable.Rows)
                {
                    DateTime startDate = DateTime.Parse(row["DataCzasStart"].ToString().Trim());
                    DateTime endDate   = DateTime.Parse(row["DataCzasKoniec"].ToString().Trim());

                    string nc10       = row["Model"].ToString();
                    double qty        = 0;
                    string orderNo    = row["NrZlecenia"].ToString();
                    double efficiency = 0;

                    if (double.TryParse(row["IloscWykonana"].ToString(), out qty))
                    {
                        efficiency = Math.Round(EfficiencyCalculation.CalculateEfficiency(startDate, endDate, nc10, qty, true) * 100, 0);
                    }
                    string name = nc.ContainsKey(nc10 + "00") ? nc[nc10 + "00"] : nc10;
                    dataGridViewMstOrders.Rows.Insert(0, startDate, endDate, orderNo, nc10.Insert(4, " ").Insert(8, " "), qty, efficiency + "%", name);
                    nc12ToModelList.Add(nc10 + "00");

                    ordersEff.Add(new EfficiencyCalculation.OrderDataForEfficiencyStructure()
                    {
                        start = startDate, end = endDate, qty = qty, modelId = nc10
                    });

                    var owningShift  = DateTools.GetOrderOwningShift(startDate, endDate);
                    var currentShift = DateTools.whatDayShiftIsit(DateTime.Now);
                    //1878856
                    if (orderNo == "1878856")
                    {
                        ;
                    }
                    if (owningShift.fixedDate != currentShift.fixedDate)
                    {
                        if (owningShift.fixedDate.Date == currentShift.fixedDate.Date)
                        {
                            DgvTools.ColorDgvRow(dataGridViewMstOrders.Rows[0], Color.LightGray);
                        }
                        else
                        {
                            DgvTools.ColorDgvRow(dataGridViewMstOrders.Rows[0], Color.Silver);
                        }
                    }
                }
                //Dictionary<string, string> nc12toName = SqlOperations.nc12ToModelDict(nc12ToModelList.ToArray());

                //foreach (DataGridViewRow row in dataGridViewMstOrders.Rows)
                //{
                //    string nc12 = row.Cells["Column12NC"].Value.ToString().Replace(" ","") + "00";
                //    row.Cells["ColumnName"].Value = nc12toName[nc12];
                //}

                DgvTools.AutoSizeColumns(dataGridViewMstOrders, DataGridViewAutoSizeColumnMode.AllCells);

                EfficiencyRecordsForOrdersHistory.FillOutListView(lVMstEfficiencyRecord, ordersEff);
            }

            var eff = Math.Round(MstCurrentShiftEfficiency.CalculateCurrentShiftEff(currentMstOrder, dataGridViewMstOrders), 0);

            angularGauge1.Value = Math.Min(100, eff);
            labelCurrentShiftEfficiency.Text = $"Wydajność aktualnej zmiany: {eff}%";
        }
Ejemplo n.º 2
0
        public static void DrawEfficiencyChart(PictureBox pbChart, float newPoint)
        {
            if (pbChart.ClientRectangle.Width == 0)
            {
                return;
            }

            List <EfficiencyAtTime> allPoints = makeListOfPoints(newPoint);


            if (allPoints.Count > 0)
            {
                float maxVal = Math.Max(allPoints.Select(ef => ef.efficiency).ToList().Max(), 100);
                float minVal = allPoints.Select(ef => ef.efficiency).ToList().Min();

                float scale     = pbChart.ClientRectangle.Height / (float)((maxVal * 1.1));
                float xInterval = (float)(pbChart.ClientRectangle.Width - 10) / allPoints.Count;


                Bitmap DrawArea = new Bitmap(pbChart.ClientRectangle.Width, pbChart.ClientRectangle.Height);
                pbChart.Image = DrawArea;

                Graphics g;
                g = Graphics.FromImage(DrawArea);
                g.SmoothingMode = SmoothingMode.AntiAlias;

                Pen penEfficiencyThisShift     = new Pen(Brushes.Lime, 2);
                Pen penEfficiencyPreviousShift = new Pen(Brushes.LightYellow, 2);
                Pen penNorm = new Pen(Brushes.Gray, 1);
                LinearGradientBrush linearGradientBrushThisShift     = new LinearGradientBrush(new PointF(10, pbChart.ClientRectangle.Height - maxVal * scale), new PointF(10, pbChart.ClientRectangle.Height), Color.Lime, Color.Transparent);
                LinearGradientBrush linearGradientBrushPreviousShift = new LinearGradientBrush(new PointF(10, pbChart.ClientRectangle.Height - maxVal * scale), new PointF(10, pbChart.ClientRectangle.Height), Color.LightYellow, Color.Transparent);

                float startX = 10;
                float startY = pbChart.ClientRectangle.Height - allPoints[0].efficiency * scale;
                g.Clear(Color.Black);
                //GraphicsPath path = new GraphicsPath();
                //path.AddLine(10, pbChart.ClientRectangle.Height, 10, startY);

                g.DrawLine(penNorm, 10, pbChart.ClientRectangle.Height - 100 * scale, pbChart.ClientRectangle.Width, pbChart.ClientRectangle.Height - 100 * scale);
                g.DrawString("100%", MainForm.DefaultFont, Brushes.Gray, pbChart.ClientRectangle.Width - 40, pbChart.ClientRectangle.Height - 98 * scale);

                g.DrawString(allPoints[0].time.ToString("HH:mm"), MainForm.DefaultFont, Brushes.Gray, 0, pbChart.ClientRectangle.Height - 18);
                Debug.WriteLine("--- " + allPoints.Count + "points");

                List <PointF> thisShiftPoints     = new List <PointF>();
                List <PointF> previousShiftPoints = new List <PointF>();

                for (int i = 1; i < allPoints.Count; i++)
                {
                    float nextX = i * xInterval;
                    float nextY = pbChart.ClientRectangle.Height - allPoints[i].efficiency * scale;

                    if (allPoints[i].time > (DateTools.whatDayShiftIsit(DateTime.Now).fixedDate))
                    {
                        g.DrawLine(penEfficiencyThisShift, startX, startY, nextX, nextY);

                        if (thisShiftPoints.Count == 0)
                        {
                            thisShiftPoints.Add(new PointF(startX, startY));
                        }
                        thisShiftPoints.Add(new PointF(nextX, nextY));
                    }
                    else
                    {
                        g.DrawLine(penEfficiencyPreviousShift, startX, startY, nextX, nextY);

                        if (previousShiftPoints.Count == 0)
                        {
                            previousShiftPoints.Add(new PointF(startX, startY));
                        }
                        previousShiftPoints.Add(new PointF(nextX, nextY));
                    }
                    g.DrawString(allPoints[i].time.ToString("HH:mm"), MainForm.DefaultFont, Brushes.Gray, (float)i * xInterval - 20, pbChart.ClientRectangle.Height - 18);
                    g.DrawLine(penNorm, i * xInterval, pbChart.ClientRectangle.Height - 20, i * xInterval, pbChart.ClientRectangle.Height - allPoints[i].efficiency * scale);

                    //Debug.WriteLine($"line: ({startX}x{startY}) -> ({nextX}x{nextY})");
                    //g.DrawLine(penEfficiencyThisShift, startX, startY, nextX, nextY);
                    //g.DrawLine(penNorm, i * xInterval, pbChart.ClientRectangle.Height - 20, i * xInterval, pbChart.ClientRectangle.Height - allPoints[i].efficiency * scale);
                    //g.DrawString(allPoints[i].time.ToString("HH:mm"), MainForm.DefaultFont, Brushes.Gray, (float)i * xInterval - 20, pbChart.ClientRectangle.Height - 18);

                    //path.AddLine(startX, (float)Math.Round(startY,0), nextX, (float)Math.Round(nextY,0));

                    startX = nextX;
                    startY = nextY;
                }
                if (thisShiftPoints.Count > 0)
                {
                    thisShiftPoints.Insert(0, new PointF(thisShiftPoints.First().X, pbChart.ClientRectangle.Height));
                    thisShiftPoints.Add(new PointF(thisShiftPoints.Last().X, pbChart.ClientRectangle.Height));
                    thisShiftPoints.Add(new PointF(thisShiftPoints.First().X, pbChart.ClientRectangle.Height));

                    GraphicsPath thisShiftPath = new GraphicsPath();
                    thisShiftPath.AddLines(thisShiftPoints.ToArray());
                    g.FillPath(linearGradientBrushThisShift, thisShiftPath);
                }
                if (previousShiftPoints.Count > 0)
                {
                    previousShiftPoints.Insert(0, new PointF(previousShiftPoints.First().X, pbChart.ClientRectangle.Height));
                    previousShiftPoints.Add(new PointF(previousShiftPoints.Last().X, pbChart.ClientRectangle.Height));
                    previousShiftPoints.Add(new PointF(previousShiftPoints.First().X, pbChart.ClientRectangle.Height));

                    GraphicsPath prevShiftPath = new GraphicsPath();
                    prevShiftPath.AddLines(previousShiftPoints.ToArray());
                    g.FillPath(linearGradientBrushPreviousShift, prevShiftPath);
                }

                //path.AddLine(startX, startY, startX, pbChart.ClientRectangle.Height);
                //path.AddLine(startX, pbChart.ClientRectangle.Height, 10, pbChart.ClientRectangle.Height);



                //g.DrawLine(0,)

                //g.DrawLine(mypen, 0, 0, 200, 200);
                //g.Clear(Color.White);
                g.Dispose();
            }
        }