Exemple #1
0
        public void SwithRowAndColumns()
        {
            var result2 = new Resultset2();

            var coltotal = Columns.Count;
            var rowtotal = Lines.Count;

            var columns = new Data[rowtotal];
            var lines   = new Line[coltotal];



            for (int col = 0; col < coltotal; col++)
            {
                #region Headers
                for (int line = -1; line < rowtotal; line++)
                {
                    if (col == 0 && line == -1) // header
                    {
                        result2.AddColumn(Columns[col]);
                        continue;
                    }
                    else if (col == 0 && line >= 0)
                    {
                        result2.AddColumn(Lines[line].Data[col]);
                        continue;
                    }
                    else if (line == -1)
                    {
                        result2.AddData(Columns[col]);
                    }
                    else
                    {
                        result2.AddData(Lines[line].Data[col]);
                    }
                }
                #endregion
            }


            // Columns
            //for (int x = 0; x < coltotal; x++)
            //{
            //    if (x == 0)
            //        result2.AddColumn(Columns[x]); //result2.AddColumn(Columns[x].value, Columns[x].display);
            //    else
            //        result2.AddData(Columns[x].value, Columns[x].value, Columns[x].display);
            //}

            //// Lines
            //for (int y = 0; y < rowtotal; y++)
            //{
            //    for (int x = 0; x < coltotal; x++)
            //    {
            //        if (x == 0)
            //            result2.AddColumn(Lines[y].Data[x]); //result2.AddColumn(Lines[y].Data[x].value, Lines[y].Data[x].display);
            //        else
            //            result2.AddData(Lines[y].Data[x]); //result2.AddData(Lines[y].Data[x].value, Lines[y].Data[x].value, Lines[y].Data[x].display);

            //    }
            //}

            Columns = result2.Columns;
            Lines   = result2.Lines;
        }
Exemple #2
0
            /// <summary>
            /// Select top.
            /// </summary>
            /// <param name="limit">Limit query</param>
            /// <param name="dbase">Default database</param>
            /// <param name="sql">query</param>
            /// <param name="values">parameters of query</param>
            /// <returns></returns>
            public static Model.Resultset2 Top(int limit, string dbase, string sql, params dynamic[] values)
            {
                var auto = String.IsNullOrEmpty(dbase);

                using (var client = (IBaseClient)Activator.CreateInstance(__client, new object[] { auto }))
                {
                    if (!auto && client.ClientType != KCore.C.Database.ClientType.SAPClient)
                    {
                        client.Connect(dbase);
                    }

                    try
                    {
                        client.Connect(dbase);
                        Factory_v1.Scripts.Prepare(client.DataInfo.DBaseType, false, ref sql, values);

                        Scripts.Top(limit, ref sql);

                        if (client.DoQuery(sql, values))
                        {
                            var res = new Model.Resultset2("sap");
                            for (int i = 0; i < client.FieldCount; i++)
                            {
                                res.AddColumn(client.Field(i).Text);
                            }

                            while (client.Next(limit))
                            {
                                for (int i = 0; i < client.FieldCount; i++)
                                {
                                    res.AddData(client.Field(i).Text, client.Field(i).Value);
                                }
                            }

                            res.Property.Title = Factory.MyTags.GetHeaderTitle(ref sql);

                            var foo = Factory.MyTags.GetHeaderSwitch(ref sql);
                            res.Property.Switch = (!String.IsNullOrEmpty(foo), foo);
                            res.Property.Switch = (!String.IsNullOrEmpty(foo), foo);
                            res.Property.Search = Factory.MyTags.IsSearch(ref sql);

                            if (res.Property.Switch.transfor)
                            {
                                res.SwithRowAndColumns();
                            }

                            return(res);
                        }
                        else
                        {
                            return(null);
                        }
                    }
                    catch (SqlException ex)
                    {
                        var id = Diagnostic.Track(LOG, client.LastCommand, ex.StackTrace);
                        Diagnostic.Error(R.ID, LOG, id, ex.Message);
                        throw new KDBException(LOG, C.MessageEx.ErrorExecuteQuery4_1, id);
                    }
                }
            }