Exemplo n.º 1
0
        protected override void _bgWorker_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e)
        {
            IsBusy = true;
            if (_itemInfoTable == null || _itemInfoTable.Rows.Count == 0)
            {
                return;
            }

            App.Current.Dispatcher.Invoke((Action) delegate // <--- HERE
            {
                _corrRptItems.Clear();
                CorrContent.Clear();
            });

            lock (_itemInfoTable)
            {
                string[]  itemList = _itemInfoTable.Rows.Cast <DataRow>().Select(x => x.Field <string>("ITEM_LIST")).ToArray();
                string    start    = string.Format("{0:yyyy-MM-dd} {1}", StartDate.Date, StartTimeValue);
                string    end      = string.Format("{0:yyyy-MM-dd} {1}", EndDate.Date, EndTimeValue);
                DataTable rawdata  = Database.DBQueryTool.GetPivotDataForItemsCorrelation(SITE_ID, itemList, start, end);
                string    tmpDir   = System.IO.Path.Combine(Environment.GetEnvironmentVariable("tmp"), "Minitab");
                Array.ForEach(System.IO.Directory.GetFiles(tmpDir), System.IO.File.Delete); //刪除暫存區所有檔案
                Model.ItemsCorrelation rpt = new Model.ItemsCorrelation();
                rpt.RawData = rawdata;
                if (rpt.RawData != null && rpt.RawData.Rows.Count > 0)
                {
                    string[] itemNames = Database.DBQueryTool.GetFurnNameByItemList(string.Join(",", itemList));
                    rpt.Title = string.Join(", ", itemNames);
                    try
                    {
                        rpt.Execute(Project);
                    }
                    catch (ArgumentNullException argnullex)
                    {
                        throw new ArgumentNullException(argnullex.Message);
                    }
                    catch (Exception ex)
                    {
                        throw new Exception("Minitab run time error\r\n" + ex.Message);
                    }
                    App.Current.Dispatcher.Invoke((Action) delegate // <--- HERE
                    {
                        _corrRptItems.Add(rpt);
                    });
                }
            }
        }
Exemplo n.º 2
0
        private void _corrRptItems_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
        {
            List <Model.IReport> newItems;

            if (e.NewItems != null)
            {
                newItems = e.NewItems.Cast <Model.IReport>().ToList();
            }
            else
            {
                newItems = new List <Model.IReport>();
            }
            List <Model.IReport> oldItems;

            if (e.OldItems != null)
            {
                oldItems = e.OldItems.Cast <Model.IReport>().ToList();
            }
            else
            {
                oldItems = new List <Model.IReport>();
            }
            CorrReportContent tmpContent;

            switch (e.Action)
            {
            case System.Collections.Specialized.NotifyCollectionChangedAction.Add:
                for (int i = 0; i < newItems.Count; i++)
                {
                    Model.IReport rpt = newItems[i];
                    tmpContent = new CorrReportContent();
                    for (int j = 0; j < rpt.Contents.Count; j++)
                    {
                        Model.IRptOutput output = rpt.Contents[j];
                        switch (output.OType)
                        {
                        case Dashboard.Model.MtbOType.GRAPH:
                            if (output.Tag.ToString() == "Trend")
                            {
                                tmpContent.TrendChart             = Tool.BinaryToWPFImage(output.OutputInByteArr);
                                tmpContent.VisibilityOfTrendChart = true;
                            }
                            else
                            {
                                tmpContent.ScatterPlot             = Tool.BinaryToWPFImage(output.OutputInByteArr);
                                tmpContent.VisibilityOfScatterPlot = true;
                            }
                            break;

                        case Dashboard.Model.MtbOType.TABLE:
                            tmpContent.CorrTable = Tool.BinaryToDataTable(output.OutputInByteArr);
                            tmpContent.ShowTable = true;
                            break;

                        default:
                            break;
                        }
                    }
                    tmpContent.Title   = rpt.Title;
                    tmpContent.RawData = rpt.RawData;
                    CorrContent.Add(tmpContent);
                }
                break;

            case System.Collections.Specialized.NotifyCollectionChangedAction.Remove:
                CorrContent.Clear();
                break;

            case System.Collections.Specialized.NotifyCollectionChangedAction.Replace:
                for (int i = 0; i < newItems.Count; i++)
                {
                    Model.IReport rpt = newItems[i];
                    tmpContent = new CorrReportContent();
                    for (int j = 0; j < rpt.Contents.Count; j++)
                    {
                        Model.IRptOutput output = rpt.Contents[j];
                        switch (output.OType)
                        {
                        case Dashboard.Model.MtbOType.GRAPH:
                            if (output.Tag.ToString() == "Trend")
                            {
                                tmpContent.TrendChart = Tool.BinaryToWPFImage(output.OutputInByteArr);
                            }
                            else
                            {
                                tmpContent.ScatterPlot = Tool.BinaryToWPFImage(output.OutputInByteArr);
                            }
                            break;

                        case Dashboard.Model.MtbOType.TABLE:
                            tmpContent.CorrTable = Tool.BinaryToDataTable(output.OutputInByteArr);
                            break;

                        default:
                            break;
                        }
                    }
                    tmpContent.Title   = rpt.Title;
                    tmpContent.RawData = rpt.RawData;
                    CorrContent[e.OldStartingIndex + i] = tmpContent;
                }
                break;

            case System.Collections.Specialized.NotifyCollectionChangedAction.Move:
            case System.Collections.Specialized.NotifyCollectionChangedAction.Reset:
            default:
                break;
            }
        }
Exemplo n.º 3
0
        protected override void _bgWorker_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e)
        {
            IsBusy = true;
            if (_itemInfoTable == null || _itemInfoTable.Rows.Count == 0)
            {
                return;
            }

            App.Current.Dispatcher.Invoke((Action) delegate // <--- HERE
            {
                _corrRptItems.Clear();
                CorrContent.Clear();
            });

            lock (_itemInfoTable)
            {
                string[]            itemList = _itemInfoTable.Rows.Cast <DataRow>().Select(x => x.Field <string>("ITEM_LIST")).ToArray();
                string              start    = string.Format("{0:yyyy-MM-dd} {1}", StartDate.Date, StartTimeValue);
                string              end      = string.Format("{0:yyyy-MM-dd} {1}", EndDate.Date, EndTimeValue);
                DataTable           rawdata;
                Model.BkCorrelation rpt;
                if (IsByPosition)
                {
                    rawdata = Database.DBQueryTool.GetPivotDataForMulBKCorrelation(SITE_ID, itemList, start, end);
                    rpt     = new Model.BKCorrelation2();
                }
                else
                {
                    //rawdata = OpenCSV(@"C:\Users\MinitabTeam\Downloads\20190104.csv");
                    rawdata = Database.DBQueryTool.GetPivotDataForBKCorrelation(SITE_ID, itemList, start, end);
                    rpt     = new Model.BkCorrelation();
                }

                string tmpDir = System.IO.Path.Combine(Environment.GetEnvironmentVariable("tmp"), "Minitab");
                Array.ForEach(System.IO.Directory.GetFiles(tmpDir), System.IO.File.Delete); //刪除暫存區所有檔案


                rpt.RawData = rawdata;
                if (rpt.RawData != null && rpt.RawData.Rows.Count > 0)
                {
                    string[] itemNames = Database.DBQueryTool.GetFurnNameByItemList(string.Join(",", itemList));
                    rpt.Title = string.Join(", ", itemNames);
                    try
                    {
                        rpt.Execute(Project);
                    }
                    catch (ArgumentNullException argnullex)
                    {
                        throw new ArgumentNullException(argnullex.Message);
                    }
                    catch (Exception ex)
                    {
                        throw new Exception("Minitab run time error\r\n" + ex.Message);
                    }
                    App.Current.Dispatcher.Invoke((Action) delegate // <--- HERE
                    {
                        //List<Model.IReport> _rptLst = new List<Model.IReport>();

                        if (rpt is Model.BKCorrelation2)
                        {
                            List <string> colNames = rawdata.Columns.Cast <DataColumn>()
                                                     .Select(x => x.ColumnName).Where(x => x != "SITE_ID" & x != "TIMESTAMP" & x != "RPT_TIMEHOUR" & x != "GROUP_ID").ToList();

                            /*
                             * 為了讓 View 的 ItemControl 顯示所有的內容且保有彈性,最後決定將原來的 rpt 依內容分拆
                             * 出多個 rpt 物件,每一個 rpt 只包含一個 IReport 物件,並且有獨立的 Title 名稱。
                             * Raw data 就指定放到第一個分拆的 rpt,讓匯出資料表功能可正常運作。
                             *
                             */
                            Model.IRptOutput item;
                            for (int i = 0; i < rpt.Contents.Count; i++)
                            {
                                item = rpt.Contents[i];
                                Model.BKCorrelation2 _tmpRpt = new Model.BKCorrelation2();

                                if (i == 0)
                                {
                                    _tmpRpt.RawData = rpt.RawData;
                                }

                                _tmpRpt.Flag = rpt.Flag;
                                _tmpRpt.AddContent(item);
                                //重新定義 Title
                                if (item.Tag.ToString() == "Trend")
                                {
                                    _tmpRpt.Title = colNames[i] + "時間趨勢圖";
                                }
                                else if (item.Tag.ToString() == "Scatter")
                                {
                                    _tmpRpt.Title = "各紡位 vs" + rpt.Title + "散佈圖";
                                }
                                else
                                {
                                    _tmpRpt.Title = "各紡位 vs" + rpt.Title + "相關係數表";
                                }

                                _corrRptItems.Add(_tmpRpt);
                            }
                        }
                        else
                        {
                            _corrRptItems.Add(rpt);
                        }


                        //
                    });
                }
            }
        }