Exemplo n.º 1
0
        public static string SaveLastPrintedTableToCSV(string filePath, DataTable dataTable)
        {
            bool exists = System.IO.Directory.Exists(filePath);



            //   using (System.IO.StreamWriter sr = new System.IO.StreamWriter(filePath, true, Encoding.UTF8))
            using (ReadWriteCsv.CsvFileWriter writer = new ReadWriteCsv.CsvFileWriter(filePath))
            {
                ReadWriteCsv.CsvRow header = new ReadWriteCsv.CsvRow();
                foreach (System.Data.DataColumn dataColumn in dataTable.Columns)
                {
                    header.Add(dataColumn.ColumnName);
                }
                writer.WriteRow(header);

                foreach (System.Data.DataRow dataRow in dataTable.Rows)
                {
                    ReadWriteCsv.CsvRow row = new ReadWriteCsv.CsvRow();
                    foreach (System.Data.DataColumn dataColumn in dataRow.Table.Columns)
                    {
                        row.Add(dataRow[dataColumn.ColumnName].ToString());
                    }
                    writer.WriteRow(row);
                }
            }

            return(filePath);
        }
Exemplo n.º 2
0
        public List<Point> oneHull(List<Point> coordinates, List<Point> Lupper,
            List<Point> Llower, int max_Width, int max_Height, int offset, int randomness = 25)
        {
            //ConvexHull CH = new ConvexHull();
            List<Point> ConvexHull = new List<Point>();

            // Creates new random points
            //if (randomness == 30)
            //{
            //    coordinates = squarePoints(coordinates);
            //}
            //else
            //{
            coordinates = createPoints(coordinates, max_Width, max_Height, offset, randomness);
            //}

            // Calls right turn method to find upper hull
            ConvexHull.AddRange(rightTurn(coordinates, Lupper));
            // Calls left turn method to find lower hull
            ConvexHull.AddRange(leftTurn(coordinates, Llower));

            try
            {
                using (ReadWriteCsv.CsvFileWriter writer = new ReadWriteCsv.CsvFileWriter("Blob.csv"))
                {
                    ReadWriteCsv.CsvRow row = new ReadWriteCsv.CsvRow();
                    for (int i = 0; i < ConvexHull.Count; i++)
                    {
                        row.Clear();
                        row.Add(ConvexHull.ElementAt(i).X.ToString());
                        row.Add(ConvexHull.ElementAt(i).Y.ToString());
                        writer.WriteRow(row);
                    }
                }
            }
            catch (IOException)
            {
                MessageBox.Show("The file you are trying to write to is open\nPlease close the file and try agian", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            return ConvexHull;
        }
Exemplo n.º 3
0
        public static bool DataTableToCSV(DataTable dt, string csvFile, bool writeColumnNames)
        {
            bool r = true;

            try
            {
                // Write sample data to CSV file
                using (ReadWriteCsv.CsvFileWriter writer = new ReadWriteCsv.CsvFileWriter(csvFile))
                {
                    //writing columnNames
                    if (writeColumnNames)
                    {
                        ReadWriteCsv.CsvRow rowCols = new ReadWriteCsv.CsvRow();
                        foreach (DataColumn c in dt.Columns)
                        {
                            rowCols.Add(c.ColumnName);
                        }
                        writer.WriteRow(rowCols);
                    }
                    foreach (DataRow dr in dt.Rows) //writing data.
                    {
                        ReadWriteCsv.CsvRow row = new ReadWriteCsv.CsvRow();
                        for (int j = 0; j < dt.Columns.Count; j++)
                        {
                            row.Add(dr[j].ToString());
                        }
                        writer.WriteRow(row);
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
                r = false;
            }
            return(r);
        }
Exemplo n.º 4
0
        /// <summary>
        /// I'm not exactly sure the use of this??
        /// All it does is create create a file 
        /// </summary>
        /// <param name="size"></param>
        public void RandomShape(Sizes size)
        {
            Random ran = new Random();

            int Max_Height = size.Window_Height;
            int max_Width = size.Window_Width;
            int offset = size.OFFSET;

            using (ReadWriteCsv.CsvFileWriter writer = new ReadWriteCsv.CsvFileWriter("Shape.csv"))
            {
                ReadWriteCsv.CsvRow row = new ReadWriteCsv.CsvRow();
                int numberOfShapes = ran.Next(15);

                for (int i = 0; i < numberOfShapes; i++)
                {
                    row.Add(ran.Next(max_Width).ToString());
                    row.Add(ran.Next(Max_Height).ToString());

                    writer.WriteRow(row);
                    row.Clear();
                }

            }
        }
Exemplo n.º 5
0
Arquivo: Form1.cs Projeto: the455/PSPM
        private void saveToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //Boolean meshCreated = false;
            SaveFileDialog saveFileDialog = new SaveFileDialog();

            if (saveFileDialog.ShowDialog() == DialogResult.OK)
            {
                String fileName = saveFileDialog.FileName;
                if (!fileName.Contains(".csv"))
                {
                    fileName = fileName + ".csv";
                }

                try
                {
                    using (ReadWriteCsv.CsvFileWriter writer = new ReadWriteCsv.CsvFileWriter(fileName))
                    {
                        ReadWriteCsv.CsvRow row = new ReadWriteCsv.CsvRow();

                        row.Add("50");
                        row.Add("50");
                        row.Add("20");
                        row.Add("20");
                        //Check if an object has been created
                        //If it hasn't save default values
                        if (mesh != null)
                        {
                            Logger.Debug("Slider: " + mesh.slider.ToString());
                            row.Add(mesh.slider.ToString());
                            row.Add(mesh.multi.ToString());
                            row.Add(mesh.shape1);
                            if (!mesh.shape2.Equals("(null)"))
                            {
                                row.Add(mesh.shape2);
                            }
                        }
                        else
                        {
                            row.Add("10");
                            row.Add("1");
                            row.Add("Square");
                        }
                        writer.WriteRow(row);
                    }
                }
                catch (IOException)
                {
                    MessageBox.Show("The file you are trying to write to is open\nPlease close the file and try agian", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
Exemplo n.º 6
0
        public void GenerateMesh(String shape)
        {
            // Write sample data to CSV file
            try
            {
                using (ReadWriteCsv.CsvFileWriter writer = new ReadWriteCsv.CsvFileWriter("Mesh.csv"))
                {
                    ReadWriteCsv.CsvRow row = new ReadWriteCsv.CsvRow();
                    row.Add("50");
                    row.Add("50");
                    row.Add("20");
                    row.Add("20");

                    //This number is for fineness
                    row.Add(tb_Thickness.Value.ToString());
                    slider = tb_Thickness.Value;

                    if (chk_MultiMesh.Checked)
                    {
                        row.Add("2");
                        multi = 2;
                    }
                    else
                    {
                        row.Add("1");
                        multi = 1;
                    }

                    //Need to store if it is a non uniform mesh and what they are
                    row.Add(shape);
                    shape1 = CheckShape(1);

                    if (chk_MultiMesh.Checked)
                    {
                        row.Add(CheckShape(2));
                        shape2 = CheckShape(2);
                    }
                    else
                    {
                        shape2 = "(null)";
                    }

                    //for (int j = 0; j < 5; j++)
                    // row.Add(String.Format("Column{0}", j));
                    writer.WriteRow(row);

                }
            }
            catch (IOException)
            {
                MessageBox.Show("The file you are trying to write to is open\nPlease close the file and try agian", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            if (_form1 != null)
            {
                _form1.DrawMesh();
            }
        }