Esempio n. 1
0
        public void SaveToDB(int dataproj_pk)
        {
            byte[] result;
            using (var stream = new MemoryStream())
            {
                var ser = new BinaryFormatter();
                ser.Serialize(stream, this);
                stream.Flush();
                result = stream.ToArray();

                SQL_utils sql = new SQL_utils("data");
                //sql.SaveChartOrder(dataproj_pk, result);
                sql.Close();
            }

            Debug.WriteLine(String.Format("This order is {0} bytes long", result.Length));

            DxChartOrder neworderC = new DxChartOrder();

            using (MemoryStream ms = new MemoryStream(result))
            {
                var ser2 = new BinaryFormatter();
                neworderC = (DxChartOrder)(ser2.Deserialize(ms));
            }
        }
Esempio n. 2
0
        private void LoadFromDB(int rptpk)
        {
            SQL_utils sql = new SQL_utils("data");
            DataTable dt  = sql.DataTable_from_SQLstring("select dataproj_pk, rpttitle, rptdesc, rptnum, rptfilename from dp.Report where rptpk=" + rptpk.ToString());

            rptnum   = Convert.ToInt32(dt.Rows[0]["rptnum"].ToString());
            rpttitle = dt.Rows[0]["rpttitle"].ToString();
            rptdesc  = dt.Rows[0]["rptdesc"].ToString();

            //Load the orders
            DataTable dt_orders = sql.DataTable_from_SQLstring("select orderpk, ordernum, ordertype, worksheet, filter, vars, objects, orderbinary from dp.ReportOrder where rptpk=" + rptpk.ToString());

            if (dt_orders.HasRows())
            {
                orders = new SessionOrders();

                foreach (DataRow row in dt_orders.Rows)
                {
                    byte[]       orderbytes = (byte[])(row["orderbinary"]);
                    DxChartOrder neworderC  = new DxChartOrder();
                    using (MemoryStream ms = new MemoryStream(orderbytes))
                    {
                        var ser2 = new BinaryFormatter();
                        neworderC = (DxChartOrder)(ser2.Deserialize(ms));
                        orders.chartorders.Add(neworderC);
                        orders.orders.Add(neworderC);
                    }
                }
            }


            sql.Close();
        }
Esempio n. 3
0
        public void DeleteOrder(int ordernum_todelete)
        {
            DxOrder order_to_del = null;

            try
            {
                order_to_del = this.orders.Where(o => o.ordernum == ordernum_todelete).First();

                foreach (DxOrder ord in this.orders)
                {
                    if (ord.ordernum > ordernum_todelete)
                    {
                        ord.ordernum--;
                    }
                }
            }
            catch (Exception ex) { }


            if (order_to_del != null)
            {
                OrderType otype = order_to_del.ordertype;
                this.orders.Remove(order_to_del);

                if (otype == OrderType.chart)
                {
                    DxChartOrder chartorder_to_del = null;
                    try
                    {
                        chartorder_to_del = this.chartorders.Where(o => o.ordernum == ordernum_todelete).First();
                    }
                    catch (Exception ex) { }
                    if (order_to_del != null)
                    {
                        this.chartorders.Remove(chartorder_to_del);
                    }
                }
                else if (otype == OrderType.table)
                {
                    DxTableOrder tableorder_to_del = null;
                    try
                    {
                        tableorder_to_del = this.tableorders.Where(o => o.ordernum == ordernum_todelete).First();
                    }
                    catch (Exception ex) { }
                    if (order_to_del != null)
                    {
                        this.tableorders.Remove(tableorder_to_del);
                    }
                }
            }
        }
Esempio n. 4
0
        public bool HasSameCharts(int idx1, int idx2)
        {
            if (idx1 == 0 & idx2 < idx1)
            {
                return(false);                                     //first one needs to be printed so false
            }
            if (chartorders.Count > idx1 & chartorders.Count > idx2)
            {
                DxChartOrder o1 = chartorders[idx1];
                DxChartOrder o2 = chartorders[idx2];

                bool b_vars      = (o1.dt_selectedvars == o2.dt_selectedvars) ? true : false;
                bool b_worksheet = (o1.worksheet == o2.worksheet) ? true : false;
                bool b_filter    = (o1.filter == o2.filter) ? true : false;
                bool hassame     = (b_vars & b_worksheet & b_filter) ? true : false;
                return(hassame);
            }
            else
            {
                return(false);
            }
        }
Esempio n. 5
0
 public void SaveOrder(DxChartOrder order)
 {
     order.ordernum = orders.Count + 1;
     orders.Add(order);
     chartorders.Add(order);
 }
Esempio n. 6
0
        public void ProcessOrder(DxChartOrder order)
        {
            if (order.isOrderFilled)             //Already have batches
            {
                order.batches.Clear();
            }

            //Skip the_dpdata stuff if _dt is already populated
            if (_dt == null)
            {
                bool hassameworksheet = order.HasSameWorksheet(_dpdata);

                if (!hassameworksheet)
                {
                    //Need new DPData
                    _dataproject.selectedsheet = order.worksheet;
                    _dpdata = new DPData(_dataproject, order.filter);
                }


                bool hassamefilter = order.HasSameFilter(_dpdata);

                if (!hassamefilter)
                {
                    _dpdata.filter = order.filter;
                }

                _dt = _dpdata.dt;
            }

            //Each order will result in a list of batches
            //List<DxBatchOcharts> batchlist = new List<DxBatchOcharts>();
            List <DxChartBatch> batchlist = new List <DxChartBatch>();

            if (order.list_settings != null)
            {
                foreach (DxChartSettings settings in order.list_settings)
                {
                    #region Histogram
                    if (settings.outputtype == DxOutputtype.Histogram)
                    {
                        DxHistogramSettings mysettings = (DxHistogramSettings)settings;
                        DxChartBatch        batch      = new DxChartBatch(mysettings, dt);
                        PrepareBatch(batch, settings);
                        batchlist.Add(batch);
                    }
                    #endregion

                    #region Barchart
                    else if (settings.outputtype == DxOutputtype.Barchart)
                    {
                        DxBarchartSettings mysettings = (DxBarchartSettings)settings;
                        DxChartBatch       batch      = new DxChartBatch(mysettings, dt);
                        PrepareBatch(batch, settings);
                        batchlist.Add(batch);
                    }
                    #endregion

                    #region Scatterplot
                    else if (settings.outputtype == DxOutputtype.Scatterplot)
                    {
                        DxScatterplotSettings mysettings = (DxScatterplotSettings)settings;

                        if (mysettings.repeatedmeasVarname == "none")
                        {
                            //DxChartBatch batch = new DxChartBatch(mysettings, dt);
                            //PrepareBatch(batch, settings);
                            //batchlist.Add(batch);

                            foreach (XYpairType mode in mysettings.xypairtypes)
                            {
                                if (mode == XYpairType.AllVars_IgnoreLevelsOfRptMeas)
                                {
                                    mysettings.current_xypairtype = mode;
                                    //mysettings.maxCol = ncol1;
                                    //mysettings.maxRow = tmpvars.Count;
                                    mysettings.chartlayout         = DxLayout.Horizontal;
                                    mysettings.repeatedmeasVarname = "none";

                                    DxChartBatch batch1 = new DxChartBatch(mysettings, dt);
                                    PrepareBatch(batch1, (DxChartSettings)mysettings);
                                    batch1.batchtitle = String.Format("All variables (IGNORE Time/RptMeas)");
                                    batch1.maxCol     = batch1.charts.Count;
                                    batchlist.Add(batch1);
                                }
                            }
                        }
                        else if (mysettings.repeatedmeasVarname != "none")
                        {
                            List <string> repeatedmeas_levels = dt.AsEnumerable().Select(f => f.Field <string>(mysettings.repeatedmeasVarname)).Distinct().ToList();

                            List <string> analysisvars = new List <string>();
                            analysisvars.AddRange(mysettings.numvars);
                            if (mysettings.agevars != null)
                            {
                                analysisvars.AddRange(mysettings.agevars);
                            }

                            int n_rptmeas      = repeatedmeas_levels.Count;
                            int n_analysisvars = analysisvars.Count;

                            int ncol1 = utilStats.TriangleNumber(n_rptmeas);


                            List <string> tmpvars  = mysettings.analysisvars();
                            List <string> tmpvarsX = mysettings.analysisvarsX();
                            List <string> tmpvarsY = mysettings.analysisvarsY();


                            #region Process By Mode
                            foreach (XYpairType mode in mysettings.xypairtypes)
                            {
                                if (mode == XYpairType.AllVars_IgnoreLevelsOfRptMeas)
                                {
                                    mysettings.current_xypairtype = mode;
                                    //mysettings.maxCol = ncol1;
                                    //mysettings.maxRow = tmpvars.Count;
                                    mysettings.chartlayout         = DxLayout.Horizontal;
                                    mysettings.repeatedmeasVarname = "none";

                                    DxChartBatch batch1 = new DxChartBatch(mysettings, dt);
                                    PrepareBatch(batch1, (DxChartSettings)mysettings);
                                    batch1.batchtitle = String.Format("All variables (IGNORE Time/RptMeas)");
                                    batch1.maxCol     = batch1.charts.Count;
                                    batchlist.Add(batch1);
                                }

                                if (mode == XYpairType.SameVar_AcrossLevelsOfRptMeas)
                                {
                                    mysettings.current_xypairtype = mode;
                                    mysettings.maxCol             = ncol1;
                                    //mysettings.maxRow = tmpvars.Count;
                                    mysettings.chartlayout = DxLayout.Horizontal;

                                    //Loop over vars, make a batch for each one
                                    foreach (string v in tmpvars)
                                    {
                                        mysettings.manualXandYvars = true;
                                        mysettings.xvars           = new List <string> {
                                            v
                                        };
                                        mysettings.yvars = new List <string> {
                                            v
                                        };
                                        DxChartBatch batch1 = new DxChartBatch(mysettings, dt);
                                        PrepareBatch(batch1, (DxChartSettings)mysettings);
                                        batch1.batchtitle = String.Format("{0} ACROSS levels of {1}", v, mysettings.repeatedmeasVarname);
                                        batch1.maxCol     = batch1.charts.Count;
                                        batchlist.Add(batch1);
                                    }
                                }

                                if (mode == XYpairType.DiffVar_WithinLevelsOfRptMeas)
                                {
                                    //#2 - treat it as square
                                    mysettings.current_xypairtype = mode;
                                    //mysettings.numvars = tmpvars;
                                    mysettings.xvars = null;
                                    mysettings.yvars = null;

                                    mysettings.chartlayout = DxLayout.Upper;
                                    mysettings.maxRow      = tmpvars.Count;

                                    List <string> rptmeasLevels = dt.AsEnumerable().Select(f => f.Field <string>(mysettings.repeatedmeasVarname)).Distinct().ToList();

                                    List <string> tmpvars_with_id = new List <string>();
                                    tmpvars_with_id.AddRange(tmpvars);
                                    tmpvars_with_id.Add("id");

                                    DataSubsets dt_rptmeas = new DataSubsets(dt, tmpvars_with_id, mysettings.repeatedmeasVarname);

                                    //Loop across levels of the RptMeas
                                    foreach (DataSubset subset in dt_rptmeas.subsets)
                                    {
                                        DxChartBatch batch2 = new DxChartBatch(mysettings, subset.dt);
                                        PrepareBatch(batch2, (DxChartSettings)mysettings);
                                        batch2.batchtitle = String.Format("Variables WITHIN {0}: {1}", mysettings.repeatedmeasVarname, subset.Vals_ToString());
                                        batch2.maxCol     = batch2.charts.Count;
                                        batchlist.Add(batch2);
                                    }
                                }

                                if (mode == XYpairType.DiffVar_AcrossLevelsOfRptMeas)
                                {
                                    //#2 - back to original
                                    mysettings.current_xypairtype = mode;
                                    //mysettings.numvars = tmpvars;
                                    mysettings.xvars           = tmpvarsX;
                                    mysettings.yvars           = tmpvarsY;
                                    mysettings.manualXandYvars = true;
                                    mysettings.chartlayout     = DxLayout.Horizontal;

                                    List <string> rptmeasLevels = dt.AsEnumerable().Select(f => f.Field <string>(mysettings.repeatedmeasVarname))
                                                                  .Distinct().ToList();
                                    //HERE!!!!

                                    for (int i = 0; i < (rptmeasLevels.Count - 1); i++)
                                    {
                                        for (int j = i + 1; j < rptmeasLevels.Count; j++)
                                        {
                                            DataView dv = new DataView(dt);                                             // dt.AsDataView();
                                            dv.RowFilter = String.Format("{0} IN ('{1}','{2}')", mysettings.repeatedmeasVarname, rptmeasLevels[i], rptmeasLevels[j]);
                                            DataTable dt_sub = dv.ToTable();

                                            if (dt_sub.Rows.Count > 1)
                                            {
                                                DxChartBatch batch3 = new DxChartBatch(mysettings, dt_sub);
                                                PrepareBatch(batch3, (DxChartSettings)mysettings);
                                                batch3.batchtitle = String.Format("Variables ACROSS {0}:{1} & {2}", mysettings.repeatedmeasVarname, rptmeasLevels[i], rptmeasLevels[j]);
                                                batch3.maxCol     = batch3.charts.Count;
                                                batchlist.Add(batch3);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        #endregion
                    }
                    #endregion

                    #region Actogram
                    else if (settings.outputtype == DxOutputtype.Actogram)
                    {
                        DxActogramSettings mysettings = (DxActogramSettings)settings;
                        mysettings.outputtype = DxOutputtype.Actogram;

                        List <string> varnames = new List <string>()
                        {
                            "id"
                        };
                        varnames.AddRange(mysettings.numvars);
                        varnames.Add(mysettings.xaxisvar);
                        varnames.Add(mysettings.colorvar);
                        varnames.RemoveAll(item => item == "variable");
                        varnames.RemoveAll(item => item == "none");


                        DataSubsets subsets = new DataSubsets(dt, varnames, new List <string> {
                            mysettings.panelvar
                        });

                        DxChartBatch batch2 = new DxChartBatch(DxOutputtype.Actogram, mysettings);

                        foreach (DataSubset subset in subsets.subsets)
                        {
                            mysettings.date_txt = subset.dt.AsEnumerable().Min(f => f.Field <string>("report_date"));

                            DxChartBatch subbatch = new DxChartBatch(mysettings, subset.dt, subset.Cols_and_Vals_ToString());

                            foreach (DxChart sub in subbatch.charts)
                            {
                                batch2.charts.Add(sub);
                            }
                        }
                        PrepareBatch(batch2, mysettings);
                        batchlist.Add(batch2);
                    }
                    #endregion

                    #region Lineplot
                    else if (settings.outputtype == DxOutputtype.Lineplot)
                    {
                        DxLineplotSettings mysettings = (DxLineplotSettings)settings;

                        //NO Panels
                        if (mysettings.panelvar == "none" | mysettings.panelvar == "variable")
                        {
                            DxChartBatch batch1 = new DxChartBatch(mysettings, dt, " ");
                            PrepareBatch(batch1, settings);
                            batchlist.Add(batch1);
                        }
                        else
                        {
                            List <string> varnames = new List <string>()
                            {
                                "id"
                            };
                            varnames.AddRange(mysettings.numvars);
                            varnames.Add(mysettings.xaxisvar);
                            varnames.Add(mysettings.colorvar);
                            varnames.RemoveAll(item => item == "variable");
                            varnames.RemoveAll(item => item == "none");


                            DataSubsets subsets = new DataSubsets(dt, varnames, new List <string> {
                                mysettings.panelvar
                            });

                            DxChartBatch batch2 = new DxChartBatch(DxOutputtype.Lineplot, mysettings);
                            batch2.vars = mysettings.numvars;
                            foreach (DataSubset subset in subsets.subsets)
                            {
                                DxChartBatch subbatch = new DxChartBatch(mysettings, subset.dt, subset.Cols_and_Vals_ToString());

                                foreach (DxChart sub in subbatch.charts)
                                {
                                    batch2.charts.Add(sub);
                                }
                            }
                            PrepareBatch(batch2, mysettings);
                            batchlist.Add(batch2);
                        }
                    }
                    #endregion
                }
            }

            order.batches.AddRange(batchlist);

            //The invoice serves as a table of contents for what was actually created
            order.PrepareInvoice();
        }