Beispiel #1
0
        private void BtnExport_Click(object sender, EventArgs e)
        {
            string Id;
            int    n = ds.Tables[0].Rows.Count;

            if (dataGridView1.SelectedRows.Count > 0 && n > 0)
            {
                Id = dataGridView1.CurrentRow.Cells[0].Value.ToString();
                SaveFileDialog dialog = new SaveFileDialog();
                dialog.Filter           = "File (*.xls)|*.xls";
                dialog.Title            = "导出工件" + Id + "记录";
                dialog.InitialDirectory = Global.OutputPath;;
                dialog.FileName         = Id;
                if (dialog.ShowDialog() == DialogResult.OK)
                {
                    if (CommonMethods.GetFilePath(dialog.FileName))
                    {
                        for (int i = n - 1; i >= 0; i--)
                        {
                            var k = ds.Tables[0].Rows[i]["HoleNumber"];
                            var lstSingleCurve = new List <Model.Point>();
                            var Data           = ds.Tables[0].Rows[i]["Data"].ToString();
                            var MaxPressure    = Convert.ToSingle(ds.Tables[0].Rows[i]["MaxPressure"]);
                            //lstSingleCurve = CommonMethods.DesirializeListCompress(strings).ConvertAll(s => (Model.Point)s);
                            lstSingleCurve = CommonMethods.StringToList(Data);
                            NopiExcelHelper <Model.Point> .AddExcel(lstSingleCurve, dialog.FileName, "hole" + k.ToString(), MaxPressure);
                        }
                    }
                }
            }
        }
Beispiel #2
0
        public async Task LocalBatchExport()
        {
            if (_windowManager.ShowMessageBox("批量导出当前工件数据到Excel文件", "导出数据", MessageBoxButton.OKCancel,
                                              MessageBoxImage.Information) == MessageBoxResult.OK)
            {
                CanLocalBatchExport = false;
                await Task.Run(() =>
                {
                    if (_historyView.Workrecs.Count > 0)
                    {
                        foreach (var workerec in _historyView.Workrecs)
                        {
                            var fileName = Global.SystemPara.OutputPath + "Net" + workerec.SerialNo + ".xls";
                            using var db = new DrillContext();
                            var holerecs = db.Holerec.Where(h => h.SerialNo == workerec.SerialNo).ToList();
                            if (holerecs.Count > 0 && CommonMethods.GetFilePath(fileName))
                            {
                                Status = "正在导出工件" + workerec.SerialNo + "数据";
                                for (int i = 1; i < _historyView.Holerecs.Count + 1; i++)
                                {
                                    var points = new List <Models.Point>();
                                    points     = CommonMethods.StringToList(_historyView.Holerecs[i - 1].Data);
                                    NopiExcelHelper <Models.Point> .AddExcel(points, fileName, "hole" + i.ToString(),
                                                                             _historyView.Holerecs[i - 1].MaxPressure);
                                }
                            }
                        }
                    }
                });

                CanLocalBatchExport = true;
                Status = "";
            }
        }
Beispiel #3
0
        public async void BatchExport()
        {
            if (_windowManager.ShowMessageBox("Batch Export works' data to Excel", "Export data", MessageBoxButton.OKCancel,
                                              MessageBoxImage.Information) == MessageBoxResult.OK)
            {
                CanBatchExport = CanQuery = false;
                await Task.Run(() =>
                {
                    if (Workrecs.Count > 0)
                    {
                        foreach (var workerec in Workrecs)
                        {
                            var fileName = Global.SystemPara.OutputPath + workerec.SerialNo + ".xls";
                            using var db = new DrillContext();
                            var holerecs = db.Holerec.Where(h => h.SerialNo == workerec.SerialNo).ToList();
                            if (holerecs.Count > 0 && CommonMethods.GetFilePath(fileName))
                            {
                                Status = "Exporting work" + workerec.SerialNo + "'s data";
                                for (int i = 1; i < holerecs.Count + 1; i++)
                                {
                                    var points = new List <Models.Point>();
                                    points     = CommonMethods.StringToList(holerecs[i - 1].Data);
                                    NopiExcelHelper <Models.Point> .AddExcel(points, fileName, "hole" + i.ToString(),
                                                                             holerecs[i - 1].MaxPressure);
                                }
                            }
                        }
                    }
                });

                CanBatchExport = CanQuery = true;
                Status         = "";
            }
        }
Beispiel #4
0
        public async void SingleExport()
        {
            SaveFileDialog dialog = new SaveFileDialog
            {
                Filter           = "File (*.xls)|*.xls",
                Title            = $"导出工件{Workrec.SerialNo}记录",
                InitialDirectory = Global.SystemPara.SavePath,
                FileName         = Workrec.SerialNo
            };

            if (dialog.ShowDialog() == true)
            {
                Global.SystemPara.SavePath = dialog.FileName.Substring(0, dialog.FileName.LastIndexOf("\\") + 1);
                var fileName = Global.SystemPara.SavePath + Workrec.SerialNo + ".xls";
                CommonMethods.WriteConfig();
                CanSingleExport = false;
                await Task.Run(() =>
                {
                    if (Workrec != null && Holerecs.Count > 0 && CommonMethods.GetFilePath(dialog.FileName))
                    {
                        for (var i = 1; i < Holerecs.Count + 1; i++)
                        {
                            var points = new List <Models.Point>();
                            points     = CommonMethods.StringToList(Holerecs[i - 1].Data);
                            NopiExcelHelper <Models.Point> .AddExcel(points, fileName, "hole" + i.ToString(),
                                                                     Holerecs[i - 1].MaxPressure);
                        }
                    }
                });

                CanSingleExport = true;
            }
        }
        public async void ExportExcel()
        {
            //导出曲线为图片
            SaveFileDialog dialog = new SaveFileDialog
            {
                Filter           = "File (*.xls)|*.xls",
                Title            = $"导出工件{Workrec.SerialNo}记录",
                InitialDirectory = Global.SystemPara.SavePath,
                FileName         = Workrec.SerialNo
            };

            if (dialog.ShowDialog() == DialogResult.OK)
            {
                Global.SystemPara.SavePath = dialog.FileName.Substring(0, dialog.FileName.LastIndexOf("\\") + 1);
                var fileName    = Global.SystemPara.SavePath + Workrec.SerialNo + ".xls";
                var pictureName = Global.SystemPara.SavePath + Workrec.SerialNo + "hole" + Holerec.HoleNumber + ".png";
                var pngExporter = new PngExporter {
                    Width = 600, Height = 800, Background = OxyColors.White
                };
                pngExporter.ExportToFile(SingleModel, pictureName);
                CommonMethods.WriteConfig();
                CanExportExcel = false;
                await Task.Run(() =>
                {
                    if (Workrec != null && Holerecs.Count > 0 && CommonMethods.GetFilePath(dialog.FileName))
                    {
                        for (int i = 1; i < Holerecs.Count + 1; i++)
                        {
                            var points = new List <Models.Point>();
                            points     = CommonMethods.StringToList(Holerecs[i - 1].Data);
                            NopiExcelHelper <Models.Point> .AddExcel(points, fileName, "hole" + i.ToString(),
                                                                     Holerecs[i - 1].MaxPressure);
                        }
                    }
                });

                CanExportExcel = true;
            }
        }
Beispiel #6
0
        static void Main(string[] args)
        {
            var path       = Directory.GetCurrentDirectory();
            var configpath = Path.Combine(path, "exportTemplate/StationOrderExportTemplate.xml");

            var source = new List <DedicatedOrderExportSourceModel>();

            for (int i = 1; i <= 100; i++)
            {
                var j = i / 2;

                var order = new DedicatedOrderExportSourceModel
                {
                    Adcode         = $"510100{j}",
                    CarType        = $"拼车{j}",
                    CityName       = $"成都{j}",
                    CreateTime     = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
                    CreatorName    = $"测试{j}",
                    DepartmentName = $"测试部门{j}",
                    Destination    = $"目的{j}",
                    FlighTime      = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
                    FlightNumber   = $"3u889{j}",
                    OrderId        = j.ToString(),
                    OrderState     = $"预约成功{j}",
                    OrderType      = $"接机{j}",
                    PeopleNumber   = j.ToString(),
                    Price          = j.ToString(),
                    ReadState      = "ReadState",
                    Starting       = $"起始地{j}",
                    UseTime        = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
                };
                source.Add(order);
            }
            var excelHelper = new NopiExcelHelper <DedicatedOrderExportSourceModel>("接送机订单", "sheet1");

            excelHelper.ExportToFile(configpath, source, "D:\\excel\\order.xls");
            Console.WriteLine("export success");
            Console.ReadLine();
        }
        /// <summary>
        /// 读到一个值后的处理(判断,保存数据,刷新画面曲线)
        /// </summary>
        public void DataTreating2()
        {
            //string FullFileName = Global.DateFilePath + Global.DateFileName1;
            var Point = new Models.Point()
            {
                x = Global.Point2.x,
                y = (short)(Global.Point2.y - 1000)
            };

            ActualPoint2.x = (float)Math.Round(Point.x * Global.SystemPara.con_factor_x, 1);
            ActualPoint2.y = (float)Math.Round(Point.y * Global.SystemPara.con_factor_y, 2);
            //测试状态
            if (Working2)
            {
                if (Global.Point2.x >= Global.SystemPara.con_chek_x && Global.Point2.y >= Global.SystemPara.con_chek_y)//进入压洞状态
                {
                    SubWorking2 = true;
                    CanStop2    = CanRedo2 = false;
                    if (Global.Point2.y > Global.MaxPressure2)        //设置最大压力
                    {
                        Global.MaxPressure2 = (short)Global.Point2.y; //其实没太大意义
                    }
                    var temppoint = new DataPoint(ActualPoint2.x, ActualPoint2.y);
                    LineSeries2.Points.Add(temppoint);
                    Global.lstPoint2.Add(Point);
                }
                // else if (Global.Point1.x < Global.SystemPara.con_chek_x || Global.Point1.y < Global.SystemPara.con_chek_y)//不在压洞状态
                else
                {
                    SubWorking2 = false;
                    CanStop2    = CanRedo2 = true;
                }

                if (LastSubWorking2 && !SubWorking2)//一个洞压完
                {
                    //调用异步写数据库和写数据文件代码
                    Workrec2.LastTime    = DateTime.Now;
                    Holerec2.MaxPressure = (float)Math.Round((Global.MaxPressure2 - 1000) * Global.SystemPara.con_factor_y, 2);
                    Holerec2.TestTime    = DateTime.Now;
                    Holerec2.SerialNo    = Workrec2.SerialNo;
                    Workrec2.HoleCount   = Holerec2.HoleNumber;
                    Holerec2.Data        = CommonMethods.ListToString(Global.lstPoint2);
                    Holerec2.MacId       = 2;
                    CommonMethods.AddHolerec(Holerec2); //向数据库写记录
                    CommonMethods.AddWorkrec(Workrec2); //向数据库写记录 大多数是UPDATE
                    if (Global.SystemPara.AutoOut)      //根据需要确定是否要写到excel文件中
                    {
                        var fileName = Global.SystemPara.OutputPath + Workrec2.SerialNo + ".xls";
                        if (CommonMethods.GetFilePath(fileName))
                        {
                            NopiExcelHelper <Models.Point> .AddExcel(Global.lstPoint2, fileName, "hole" + Global.HoleRecod2.HoleNumber.ToString(),
                                                                     (float)Global.HoleRecod2.MaxPressure);
                        }
                    }
                    Global.MaxPressure2 = 0;
                    Holerec2.HoleNumber++;
                }
                if (!SubWorking2)
                {
                    LineSeries2.Points.Clear();
                    Global.lstPoint2.Clear();
                }
                LastSubWorking2 = SubWorking2;
            }
            //非测试状态
            else
            {
                Global.lstPoint2.Clear();
                CanStop2  = CanRedo2 = false;
                CanStart2 = true;
            }
        }
        /// <summary>
        /// 读到一个值后的处理(判断,保存数据,刷新画面曲线)
        /// </summary>
        public void DataTreating1()
        {
            //string FullFileName = Global.DateFilePath + Global.DateFileName1;
            var Point = new Models.Point()
            {
                x = Global.Point1.x,
                y = (short)(Global.Point1.y - 1000)
            };

            ActualPoint1.x = (float)Math.Round(Point.x * Global.SystemPara.con_factor_x, 1);
            ActualPoint1.y = (float)Math.Round(Point.y * Global.SystemPara.con_factor_y, 2);
            //测试状态
            if (Working1)
            {
                if (Global.Point1.x >= Global.SystemPara.con_chek_x && Global.Point1.y >= Global.SystemPara.con_chek_y)//进入压洞状态
                {
                    SubWorking1 = true;
                    CanStop1    = CanRedo1 = false;
                    if (Global.Point1.y > Global.MaxPressure1)        //设置最大压力
                    {
                        Global.MaxPressure1 = (short)Global.Point1.y; //其实没太大意义
                    }
                    var temppoint = new DataPoint(ActualPoint1.x, ActualPoint1.y);
                    LineSeries1.Points.Add(temppoint);

                    Global.lstPoint1.Add(Point);
                }
                // else if (Global.Point1.x < Global.SystemPara.con_chek_x || Global.Point1.y < Global.SystemPara.con_chek_y)//不在压洞状态
                else
                {
                    SubWorking1 = false;
                    CanStop1    = CanRedo1 = true;
                }

                if (LastSubWorking1 && !SubWorking1)//一个洞压完
                {
                    //调用异步写数据库和写数据文件代码
                    Workrec1.LastTime    = DateTime.Now;
                    Holerec1.MaxPressure = (float)Math.Round((Global.MaxPressure1 - 1000) * Global.SystemPara.con_factor_y, 2);
                    Holerec1.TestTime    = DateTime.Now;
                    Holerec1.SerialNo    = Workrec1.SerialNo;
                    Workrec1.HoleCount   = Holerec1.HoleNumber;
                    Holerec1.Data        = CommonMethods.ListToString(Global.lstPoint1);
                    Holerec1.MacId       = 1;
                    CommonMethods.AddHolerec(Holerec1); //向数据库写记录
                    CommonMethods.AddWorkrec(Workrec1); //向数据库写记录 大多数是UPDATE
                    if (Global.SystemPara.AutoOut)      //根据需要确定是否要写到excel文件中
                    {
                        var fileName = Global.SystemPara.OutputPath + Workrec1.SerialNo + ".xls";
                        if (CommonMethods.GetFilePath(fileName))
                        {
                            NopiExcelHelper <Models.Point> .AddExcel(Global.lstPoint1, fileName, "hole" + Global.HoleRecod1.HoleNumber.ToString(),
                                                                     (float)Global.HoleRecod1.MaxPressure);
                        }
                    }
                    //这个地方要增加设置窗口重新测试按钮为不可用?
                    Global.MaxPressure1 = 0;
                    Holerec1.HoleNumber++;
                    #region 要删除
                    ReadValue.Distance = 0;
                    ReadValue.Pressure = 320;
                    ReadValue.IsMax    = false;
                    Thread.Sleep(10000);
                    #endregion
                }
                if (!SubWorking1)
                {
                    LineSeries1.Points.Clear();
                    Global.lstPoint1.Clear();
                }
                LastSubWorking1 = SubWorking1;
            }
            //非测试状态
            else
            {
                Global.lstPoint1.Clear();
                CanStop1  = CanRedo1 = false;
                CanStart1 = true;
            }
        }