/// <summary>
        /// Reads a row of data from a CSV file
        /// </summary>
        /// <param name="row"></param>
        /// <returns></returns>
        public bool ReadRow(CsvRow row)
        {
            row.LineText = ReadLine();
            if (String.IsNullOrEmpty(row.LineText))
            {
                return(false);
            }

            int pos  = 0;
            int rows = 0;

            while (pos < row.LineText.Length)
            {
                string value;

                // Special handling for quoted field
                if (row.LineText[pos] == '"')
                {
                    // Skip initial quote
                    pos++;

                    // Parse quoted value
                    int start = pos;
                    while (pos < row.LineText.Length)
                    {
                        // Test for quote character
                        if (row.LineText[pos] == '"')
                        {
                            // Found one
                            pos++;

                            // If two quotes together, keep one
                            // Otherwise, indicates end of value
                            if (pos >= row.LineText.Length || row.LineText[pos] != '"')
                            {
                                pos--;
                                break;
                            }
                        }
                        pos++;
                    }
                    value = row.LineText.Substring(start, pos - start);
                    value = value.Replace("\"\"", "\"");
                }
                else
                {
                    // Parse unquoted value
                    int start = pos;
                    while (pos < row.LineText.Length && row.LineText[pos] != ',')
                    {
                        pos++;
                    }
                    value = row.LineText.Substring(start, pos - start);
                }

                // Add field to list
                if (rows < row.Count)
                {
                    row[rows] = value;
                }
                else
                {
                    row.Add(value);
                }
                rows++;

                // Eat up to and including next comma
                while (pos < row.LineText.Length && row.LineText[pos] != ',')
                {
                    pos++;
                }
                if (pos < row.LineText.Length)
                {
                    pos++;
                }
            }
            // Delete any unused items
            while (row.Count > rows)
            {
                row.RemoveAt(rows);
            }

            // Return true if any columns read
            return(row.Count > 0);
        }
Exemple #2
0
        private void gesture_delete_btn_Click(object sender, EventArgs e)
        {
            if (m_nWavingGestureIdx < 0)
            {
                MessageBox.Show("Please select waving gesture!", "Selected Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }
            else
            {
                m_strWavingGestureNames.RemoveAt(m_nWavingGestureIdx);
                m_strWavingGestureEvents.RemoveAt(m_nWavingGestureIdx);
                m_strWavingGestureParts.RemoveAt(m_nWavingGestureIdx);

                using (CsvFileWriter wavingGestureDataWriter = new CsvFileWriter(Application.StartupPath + "/TrainedData/WavingGestures/WavingGestures.csv"))
                {
                    for (int i = 0; i < m_strWavingGestureNames.Count; i++)
                    {
                        CsvRow row = new CsvRow();
                        row.Add(m_strWavingGestureNames[i]);
                        row.Add(m_strWavingGestureParts[i][0]);
                        row.Add(m_strWavingGestureParts[i][1]);
                        row.Add(m_strWavingGestureParts[i][2]);
                        row.Add(m_strWavingGestureEvents[i]);
                        wavingGestureDataWriter.WriteRow(row);
                    }
                }

                waving_gesture_list.Clear();
                m_wavingGestureImages.Images.Clear();

                for (int i = 0; i < m_strWavingGestureNames.Count; i++)
                {
                    try
                    {
                        Bitmap bitmap = (Bitmap)Image.FromFile(Application.StartupPath + "/TrainedData/TrainedGestures/" + m_strWavingGestureParts[i][0] + ".bmp");
                        m_wavingGestureImages.Images.Add(bitmap);
                    }
                    catch
                    {
                        Console.WriteLine("This is not an image file");
                    }
                }

                waving_gesture_list.View           = View.LargeIcon;
                m_wavingGestureImages.ImageSize    = new Size(32, 32);
                waving_gesture_list.LargeImageList = m_gestureImages;

                for (int i = 0; i < m_strWavingGestureNames.Count; i++)
                {
                    ListViewItem item = new ListViewItem();
                    item.ImageIndex = i;
                    item.Text       = m_strWavingGestureNames[i];
                    waving_gesture_list.Items.Add(item);
                }

                if (waving_gesture_list.Items.Count <= 0)
                {
                    gesture_edit_btn.Enabled   = false;
                    gesture_delete_btn.Enabled = false;
                }

                MessageBox.Show("Delete completed!", "Selected Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
        }