Example #1
0
        public DataTable Data_SelectColumnXY(DataTable mydt, string xvar, string yvar)
        {
            var coltypeX = mydt.Columns[xvar].DataType;
            var coltypeY = mydt.Columns[yvar].DataType;

            if (coltypeX.Name.ToLower() == "string")
            {
                var qry = mydt.AsEnumerable()
                          .Where(f => f.Field <string>(xvar) != null && f.Field <double?>(yvar) != null)
                          .Select(r => new
                {
                    id = r.Field <string>("id"),
                    x  = r.Field <string>(xvar),
                    y  = r.Field <double>(yvar)
                });

                DataTable data = CustomLINQtoDataSetMethods.CustomCopyToDataTable(qry);

                return(data);
            }
            else
            {
                var qry = mydt.AsEnumerable().Where(f => f.Field <double?>(xvar) != null && f.Field <double?>(yvar) != null)
                          .Select(r => new
                {
                    id = r.Field <string>("id"),
                    x  = r.Field <double>(xvar),
                    y  = r.Field <double>(yvar)
                });

                DataTable data = CustomLINQtoDataSetMethods.CustomCopyToDataTable(qry);

                return(data);
            }
        }
Example #2
0
        public DataTable GetAnalysisVars(int studyid)
        {
            if (dt_dict.HasRows())
            {
                int x   = 0;
                var qry = dt_dict.AsEnumerable().Where(f => f.Field <int>("inanalysis") > 0).Select(f => new
                {
                    ord_pos    = f.Field <double>("ord_pos"),
                    fldname    = f.Field <string>("fldname").ToLower(),
                    fieldlabel = f.Field <string>("fieldlabel")
                });

                DataTable dt_analysisvars = CustomLINQtoDataSetMethods.CustomCopyToDataTable(qry);
                return(dt_analysisvars);
            }
            return(null);
        }
Example #3
0
        public DataTable Data_SelectColumnX(DataTable mydt, string xvar)
        {
            //Convert to double and get rid of DBNull values
            //var origdata = dt.AsEnumerable().Select(x => (x[col.ColumnName] == DBNull.Value) ? -998877 : x[col.ColumnName]).ToList();
            //data = origdata.ConvertAll(x => Convert.ToDouble(x)).Where(x => x != -998877).ToList();


            var coltype = mydt.Columns[xvar].DataType;

            if (coltype.Name == "String")
            {
                var qry = mydt.AsEnumerable()
                          .Where(f => f.Field <string>(xvar) != null)
                          .Select(r => new
                {
                    id     = r.Field <string>("id"),
                    timept = r.Field <string>("timept"),
                    group  = r.Field <string>("group"),
                    x      = Convert.ToDouble(r.Field <string>(xvar))
                });

                DataTable data2 = CustomLINQtoDataSetMethods.CustomCopyToDataTable(qry);

                return(data2);
            }

            else
            {
                var qry = mydt.AsEnumerable()
                          .Where(f => f.Field <double?>(xvar) != null)
                          .Select(r => new
                {
                    id     = r.Field <string>("id"),
                    timept = r.Field <string>("timept"),
                    group  = r.Field <string>("group"),
                    x      = r.Field <double>(xvar)
                });

                //DataTable data = CustomLINQtoDataSetMethods.CustomCopyToDataTable(qry);
                DataTable data = qry.CustomCopyToDataTable();


                return(data);
            }
        }
Example #4
0
        public DataTable Data_SelectColumnXY(DataTable mydt, string xvar, string yvar, string seriesby, string colorsby)
        {
            var coltypeX = mydt.Columns[xvar].DataType;
            var coltypeY = mydt.Columns[yvar].DataType;

            if (colorsby == "none")
            {
                colorsby = seriesby;
            }
            else
            {
                var coltypeColors = mydt.Columns[colorsby].DataType;
                if (coltypeColors.Name.ToLower() != "string")
                {
                    mydt.ConvertColumnType(colorsby, typeof(string));
                }
            }


            if (coltypeX.Name.ToLower() == "datetime")
            {
                var qry = mydt.AsEnumerable()
                          .Where(f => f.Field <DateTime?>(xvar) != null && f.Field <double?>(yvar) != null)
                          .Select(r => new
                {
                    seriesby = r.Field <string>(seriesby),
                    colorsby = r.Field <string>(colorsby.ToString()),
                    id       = r.Field <string>("id"),
                    x        = r.Field <DateTime>(xvar),
                    y        = r.Field <double>(yvar)
                });

                DataTable data = CustomLINQtoDataSetMethods.CustomCopyToDataTable(qry);

                return(data);
            }

            else if (coltypeX.Name.ToLower() == "string")
            {
                var qry = mydt.AsEnumerable()
                          .Where(f => f.Field <string>(xvar) != null && f.Field <double?>(yvar) != null)
                          .Select(r => new
                {
                    seriesby = r.Field <string>(seriesby),
                    colorsby = r.Field <string>(colorsby).ToString(),
                    id       = r.Field <string>("id"),
                    x        = r.Field <string>(xvar),
                    y        = r.Field <double>(yvar)
                })
                          .OrderBy(o => o.x)
                          .ThenBy(o => o.id);

                DataTable data = CustomLINQtoDataSetMethods.CustomCopyToDataTable(qry);

                return(data);
            }
            else if (coltypeX.Name.ToLower() == "double")
            {
                var qry = mydt.AsEnumerable()
                          .Where(f => f.Field <double?>(xvar) != null && f.Field <double?>(yvar) != null)
                          .Select(r => new
                {
                    seriesby = r.Field <string>(seriesby),
                    colorsby = r.Field <string>(colorsby),
                    id       = r.Field <string>("id"),
                    x        = r.Field <double>(xvar),
                    y        = r.Field <double>(yvar)
                });

                DataTable data = CustomLINQtoDataSetMethods.CustomCopyToDataTable(qry);

                return(data);
            }
            else
            {
                return(null);
            }
        }