예제 #1
0
        //Output the CSV data to the console
        //
        public static bool Dump(ObjDataSet A)
        {
            for (Int32 I = 0; I < A.GetHeaderCount(); I++)
            {
                Console.Write(A.GetHeaderName(I));
                if (I < A.GetColumnCount())
                {
                    Console.Write(",");
                }
            }
            Console.WriteLine("");

            for (Int32 I = 0; I < A.GetRowCount(); I++)
            {
                ObjDataRow R = A.GetRow(I);

                Int32 Elementcnt = 1;
                foreach (String S in A.GetRow(I).GetRowData())
                {
                    Console.Write(S);
                    if (Elementcnt < A.GetColumnCount())
                    {
                        Console.Write(",");
                    }

                    Elementcnt++;
                }
                Console.WriteLine("");
            }
            return(true);
        }
예제 #2
0
        public bool Equals(ObjDataRow B, bool CaseSensitive)
        {
            if (Elements.Count() == B.Elements.Count())
            {
                for (Int32 I = 0; I < Elements.Count(); I++)
                {
                    if (!CaseSensitive)
                    {
                        if (!Elements[I].ToString().ToUpper().Equals(B.Elements[I].ToString().ToUpper()))
                        {
                            return(false);
                        }
                    }
                    else
                    {
                        if (!Elements[I].Equals(B.Elements[I]))
                        {
                            return(false);
                        }
                    }
                }
            }

            return(true);
        }
예제 #3
0
        public bool Contains(ObjDataRow R, bool CaseSensitive)
        {
            if (HasRow(R, CaseSensitive))
            {
                return(true);
            }

            return(false);
        }
예제 #4
0
        public static ObjDataSet Merge(ObjDataSet A, ObjDataSet B, String aFieldName, String bFieldname)
        {
            ObjDataSet Result = new ObjDataSet();

            Int32 aIndex = GetHeaderIndex(A, aFieldName);
            Int32 bIndex = GetHeaderIndex(A, aFieldName);

            //Need to merge headers - excluding the index from B
            //Add the Headers from A
            for (Int32 I = 0; I < A.GetHeaderCount(); I++)
            {
                Result.AddHeader(A.GetHeaderName(I), null);
            }


            //Add the headers from B
            for (Int32 I = 0; I < B.GetHeaderCount(); I++)
            {
                if (I != bIndex)
                {
                    Result.AddHeader(B.GetHeaderName(I), null);
                }
            }


            //Merge the data

            for (Int32 I = 0; I < A.GetRowCount(); I++)
            {
                ObjDataRow AR    = A.GetRow(I);
                String     AData = AR.GetRowElement(aIndex).ToString();

                ObjDataRow BR = FindRow(B, bIndex, AData);
                if (BR != null)
                {
                    List <Object> NewRowData      = new List <Object>();
                    Object[]      ExistingRowData = BR.GetRowData();

                    for (Int32 J = 0; J < ExistingRowData.Count(); J++)
                    {
                        if (J != bIndex)
                        {
                            NewRowData.Add(ExistingRowData[J]);
                        }
                    }
                    AR.Add(NewRowData.ToArray());
                    Result.Add(AR);
                }
            }



            return(Result);
        }
예제 #5
0
 private bool HasRow(ObjDataRow R, bool CaseSensitive)
 {
     for (Int32 I = 0; I < Rows.Count(); I++)
     {
         if (Rows[I].Equals(R, CaseSensitive))
         {
             return(true);
         }
     }
     return(false);
 }
예제 #6
0
        /* Merge two tables
         * Take all columns from A and B
         * Use A as the master index
         * Merge fields based on lookups between field A1 and B1
         */


        private static ObjDataRow FindRow(ObjDataSet A, Int32 cIndex, string Value)
        {
            ObjDataRow R = null;

            for (Int32 I = 0; I < A.GetRowCount(); I++)
            {
                R = A.GetRow(I);
                Object O = R.GetRowElement(cIndex);
                if (O.ToString().ToUpper() == Value.ToUpper())
                {
                    return(R);
                }
            }

            return(null);
        }
예제 #7
0
        public static bool Read(String Filename, out ObjDataSet FileStruct, bool header)
        {
            FileStruct = null;
            FileStruct = new ObjDataSet();
            try
            {
                System.IO.StreamReader file = new System.IO.StreamReader(Filename);
                //Read our header (if we have one)
                if (header)
                {
                    String   hText   = file.ReadLine();
                    String[] Headers = hText.Split(',');
                    foreach (String H in Headers)
                    {
                        FileStruct.AddHeader(H, null);
                    }
                }

                String   lText;
                String[] Cols;

                while (!file.EndOfStream)
                {
                    lText = file.ReadLine();
                    Cols  = lText.Split(',');
                    ObjDataRow R = new ObjDataRow();
                    R.Add(Cols);
                    FileStruct.Add(R);
                }

                file.Close();
                return(true);
            }
            catch (Exception E)
            {
                Console.WriteLine("Error reading file: " + E.Message);
                return(false);
            }

            return(false);
        }
예제 #8
0
        //Extract selected Fields from a given CSV file
        //
        public static ObjDataSet Extract(ObjDataSet A, String[] Fields)
        {
            ObjDataSet Result  = new ObjDataSet();
            List <int> Indexes = new List <int>();

            //Check which headers we need and the Index's of columns
            for (Int32 I = 0; I < A.GetHeaderCount(); I++)
            {
                foreach (String H in Fields)
                {
                    if (H.ToUpper() == A.GetHeaderName(I).ToUpper())
                    {
                        Result.AddHeader(A.GetHeaderName(I), null);
                        Indexes.Add(I);
                    }
                }
            }

            //Get the row data
            for (Int32 I = 0; I < A.GetRowCount(); I++)
            {
                ObjDataRow    R     = new ObjDataRow();
                List <Object> L     = new List <object>();
                Object []     RData = A.GetRow(I).GetRowData();

                for (Int32 ColData = 0; ColData < RData.Count(); ColData++)
                {
                    if (Indexes.Contains(ColData))
                    {
                        L.Add(RData[ColData]);
                    }
                }

                R.Add(L.ToArray());
                Result.Add(R);
            }


            return(Result);
        }
예제 #9
0
 public bool Add(ObjDataRow oRow)
 {
     Rows.Add(oRow);
     return(true);
 }