Ejemplo n.º 1
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (!radioButtonOrder.Checked)
            {
                GetMeasuremntsForBoxOrPallet();
            }
            else
            {
                List <string> ordersList = new List <string>();
                foreach (var item in rTxtBox.Lines)
                {
                    string order = item.Trim();
                    if (order != "")
                    {
                        ordersList.Add(order);
                    }
                }
                measurementsDictionary = SqlOpeations.GetMeasurementsForOrderNo(ordersList);
            }

            if (measurementsDictionary.Count > 0)
            {
                if (SdcmCalculation.CheckTestMeasurements(measurementsDictionary, modelSPecification, ref currentModel, dataGridView1, labelInfo))
                {
                    button2.Enabled  = true;
                    panel1.BackColor = Color.Lime;

#if DEBUG
                    Charting.DrawHistogramChart(chart1, measurementsDictionary.Select(val => val.Value.Vf).ToList(), modelSPecification[currentModel].Vf_Min, modelSPecification[currentModel].Vf_Max);
#endif
                    if (!IfThisModelIsTridonic(currentModel))
                    {
                        MessageBox.Show("To nie jest model Tridoic!");
                        button2.Enabled = false;
                    }
                }
                else
                {
                    button2.Enabled = false;
                }

                //Charting.DrawHistogramChart(chart1, measurementsDictionary.Select(val => val.Value.Lm).ToList(), modelSPecification[currentModel].Lm_Min, modelSPecification[currentModel].Lm_Max);
            }
            else
            {
                MessageBox.Show("Brak tego ID w bazie.");
                button2.Enabled = false;
            }
        }
Ejemplo n.º 2
0
        public static void CreateExcelReport(Dictionary <string, PcbTesterMeasurements> measurements, ModelSpecification spec, string[] boxes, string user, string saveDefaultPath, DateTime shippingDate)
        {
            Chart vFChart = new Chart();

            vFChart.Name = "vFChart";
            SetUpChartParams(vFChart);
            Charting.DrawHistogramChart(vFChart, measurements.Select(val => val.Value.Vf).ToList(), spec.Vf_Min, spec.Vf_Max);
            Bitmap vfChartBmp = Charting.ConvertChartToBmp(vFChart);

            Chart lmChart = new Chart();

            lmChart.Name = "lmChart";
            SetUpChartParams(lmChart);
            Charting.DrawHistogramChart(lmChart, measurements.Select(val => val.Value.Lm).ToList(), spec.Lm_Min, spec.Lm_Max);
            Bitmap lmChartBmp = Charting.ConvertChartToBmp(lmChart);

            Chart lmWChart = new Chart();

            lmWChart.Name = "lmWChart";
            SetUpChartParams(lmWChart);
            Charting.DrawHistogramChart(lmWChart, measurements.Select(val => val.Value.LmW).ToList(), spec.LmW_Min, 0);
            Bitmap lmWChartBmp = Charting.ConvertChartToBmp(lmWChart);

            Chart criChart = new Chart();

            criChart.Name = "criChart";
            SetUpChartParams(criChart);
            Charting.DrawHistogramChart(criChart, measurements.Select(val => val.Value.Cri).ToList(), spec.CRI_Min, spec.CRI_Max);
            Bitmap criChartBmp = Charting.ConvertChartToBmp(criChart);

            Chart ellipseChart = new Chart();

            ellipseChart.Name = "ellipseChart";
            SetUpChartParams(ellipseChart);
            Charting.DrawElipse(ellipseChart, measurements, ElipseCalc.CalculateElipseBorder(measurements, spec));
            Bitmap ellipseChartBmp = Charting.ConvertChartToBmp(ellipseChart);

            string FilePath = @"cocTemplate.xlsx";
            string orderNo  = string.Join(",", measurements.Values.Select(m => m.OrderNo).Distinct().ToArray());

            if (File.Exists(FilePath))
            {
                var fs  = new FileStream(FilePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
                var pck = new OfficeOpenXml.ExcelPackage();
                try
                {
                    pck = new OfficeOpenXml.ExcelPackage(fs);
                }
                catch (Exception e) { MessageBox.Show(e.Message); }

                if (pck.Workbook.Worksheets.Count != 0)
                {
                    //foreach (OfficeOpenXml.ExcelWorksheet worksheet in pck.Workbook.Worksheets)
                    {
                        OfficeOpenXml.ExcelWorksheet worksheet = pck.Workbook.Worksheets[1];

                        worksheet.Cells[4, 7].Value  = spec.TridonicCustomerNumner;
                        worksheet.Cells[5, 7].Value  = spec.TridonicDescription;
                        worksheet.Cells[6, 7].Value  = spec.LgitName;
                        worksheet.Cells[7, 7].Value  = spec.LgitDescription;
                        worksheet.Cells[8, 2].Value  = shippingDate.ToString("dd.MM.yyyy");
                        worksheet.Cells[9, 1].Value  = "Batch no: " + orderNo;
                        worksheet.Cells[12, 4].Value = measurements.Count;
                        worksheet.Cells[13, 4].Value = measurements.Count;
                        worksheet.Cells[10, 6].Value = "If=" + spec.CurrentForward + "mA";
                        worksheet.Cells[16, 1].Value = "If=" + spec.CurrentForward + "mA";
                        worksheet.Cells[31, 7].Value = "@" + spec.CurrentForward + "mA";
                        worksheet.Cells[48, 1].Value = "Date: " + shippingDate.ToString("dd.MM.yyyy");
                        worksheet.Cells[48, 6].Value = "Signature: " + user;

                        OfficeOpenXml.Drawing.ExcelPicture vFchartPic = worksheet.Drawings.AddPicture("vfChartBmp", vfChartBmp);
                        vFchartPic.SetPosition(615, 3);
                        vFchartPic.SetSize(50);

                        OfficeOpenXml.Drawing.ExcelPicture lmChartPic = worksheet.Drawings.AddPicture("lmChartBmp", lmChartBmp);
                        lmChartPic.SetPosition(355, 3);
                        lmChartPic.SetSize(50);

                        OfficeOpenXml.Drawing.ExcelPicture lmWChartPic = worksheet.Drawings.AddPicture("lmWChartBmp", lmWChartBmp);
                        lmWChartPic.SetPosition(355, 200);
                        lmWChartPic.SetSize(50);

                        OfficeOpenXml.Drawing.ExcelPicture criChartPic = worksheet.Drawings.AddPicture("criChartBmp", criChartBmp);
                        criChartPic.SetPosition(615, 200);
                        criChartPic.SetSize(50);

                        OfficeOpenXml.Drawing.ExcelPicture ellipseChartPic = worksheet.Drawings.AddPicture("ellipseChartBmp", ellipseChartBmp);
                        ellipseChartPic.SetPosition(315, 395);
                        ellipseChartPic.SetSize(60);
                    }
                }

                using (SaveFileDialog saveDialog = new SaveFileDialog())
                {
                    saveDialog.DefaultExt       = ".xlsx";
                    saveDialog.FileName         = spec.TridonicCustomerNumner + " CofC " + shippingDate.ToString("dd.MM.yyyy") + " " + spec.LgitName + ".xlsx";
                    saveDialog.InitialDirectory = saveDefaultPath;
                    if (saveDialog.ShowDialog() == DialogResult.OK)
                    {
                        Stream stream = File.Create(saveDialog.FileName);
                        pck.SaveAs(stream);
                        stream.Close();
                        System.Diagnostics.Process.Start(saveDialog.FileName);
                    }
                }
            }
        }