Пример #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);
        }
Пример #2
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();
                }

            }
        }
Пример #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);
        }
Пример #4
0
        public ReadWriteCsv.CsvRow ToCsv()
        {
            ReadWriteCsv.CsvRow l = new ReadWriteCsv.CsvRow();

            l.Add(this.KYCRSP_FUNDNO.ToString());

            if(this.MCALDT == null || this.MCALDT.Year < 1900) l.Add(""); else l.Add(this.MCALDT.ToString("dd/MM/yyyy"));
            l.Add(this.FMRET);
            l.Add(this.FMTNA);
            l.Add(this.RmRf);
            l.Add(this.RmRfd);
            l.Add(this.SMB);
            l.Add(this.HML);
            l.Add(this.Mom);
            l.Add(this.RF);
            l.Add(this.Rfd);
            l.Add(this.FLOW);

            l.Add(this.FRONT_LOAD);
            if(this.Fflbegdt == null || this.Fflbegdt.Year < 1900) l.Add(""); else l.Add(this.Fflbegdt.ToString("dd/MM/yyyy"));
            if(this.Fflenddt == null || this.Fflenddt.Year < 1900) l.Add(""); else l.Add(this.Fflenddt.ToString("dd/MM/yyyy"));

            l.Add(this.REAR_LOAD);
            if(this.Frlbegdt == null || this.Frlbegdt.Year < 1900) l.Add(""); else l.Add(this.Frlbegdt.ToString("dd/MM/yyyy"));
            if(this.Frlenddt == null || this.Frlenddt.Year < 1900) l.Add(""); else l.Add(this.Frlenddt.ToString("dd/MM/yyyy"));

            l.Add(this.FEXP_RATIO);
            l.Add(this.FMGMT_FEE);
            l.Add(this.FTURN_RATIO);
            if(this.Ffebegdt == null || this.Ffebegdt.Year < 1900) l.Add(""); else l.Add(this.Ffebegdt.ToString("dd/MM/yyyy"));
            if(this.Ffeenddt == null || this.Ffeenddt.Year < 1900) l.Add(""); else l.Add(this.Ffeenddt.ToString("dd/MM/yyyy"));

            l.Add(this.TotalLoads.ToString());
            l.Add(this.r_rf.ToString());

            return l;
        }
Пример #5
0
        public ReadWriteCsv.CsvRow ToCsv()
        {
            ReadWriteCsv.CsvRow l = new ReadWriteCsv.CsvRow();
            l.Add(this.KycrspFundno.ToString());

            l.Add(this.FrontLoad == null ? "" : this.FrontLoad);
            if (this.Fflbegdt == null || this.Fflbegdt.Year < 1900) l.Add(""); else l.Add(this.Fflbegdt.ToString("dd/MM/yyyy"));
            if (this.Fflenddt == null || this.Fflenddt.Year < 1900) l.Add(""); else l.Add(this.Fflenddt.ToString("dd/MM/yyyy"));

            l.Add(this.RearLoad == null ? "" : this.RearLoad);
            if (this.Frlbegdt == null || this.Frlbegdt.Year < 1900) l.Add(""); else l.Add(this.Frlbegdt.ToString("dd/MM/yyyy"));
            if (this.Frlenddt == null || this.Frlenddt.Year < 1900) l.Add(""); else l.Add(this.Frlenddt.ToString("dd/MM/yyyy"));

            l.Add(this.FexpRatio == null ? "" : this.FexpRatio);
            l.Add(this.FmgmtFee == null ? "" : this.FmgmtFee);
            l.Add(this.FturnRatio == null ? "" : this.FturnRatio);
            if (this.Ffebegdt == null || this.Ffebegdt.Year < 1900) l.Add(""); else l.Add(this.Ffebegdt.ToString("dd/MM/yyyy"));
            if (this.Ffeenddt == null || this.Ffeenddt.Year < 1900) l.Add(""); else l.Add(this.Ffeenddt.ToString("dd/MM/yyyy"));

            if (this.MCALDT == null || this.MCALDT.Year < 1900) l.Add(""); else l.Add(this.MCALDT.ToString("dd/MM/yyyy"));
            //l.Add(this.FMRET == null ? "" : this.FMRET);
            //l.Add(this.RmRfd == null ? "" : this.RmRfd);
            //l.Add(this.SMB == null ? "" : this.SMB);
            //l.Add(this.HML == null ? "" : this.HML);
            //l.Add(this.Mom == null ? "" : this.Mom);
            //l.Add(this.Rfd == null ? "" : this.Rfd);
            //l.Add(this._b_RmRfd == null ? "" : this._b_RmRfd);
            //l.Add(this._b_SMB == null ? "" : this._b_SMB);
            //l.Add(this._b_HML == null ? "" : this._b_HML);
            //l.Add(this._b_Mom == null ? "" : this._b_Mom);
            //l.Add(this._b_cons == null ? "" : this._b_cons);
            //l.Add(this._p == null ? "" : this._p);

            l.Add(this.TotalLoads.ToString());

            return l;
        }
Пример #6
0
        public ReadWriteCsv.CsvRow ToCsv()
        {
            ReadWriteCsv.CsvRow l = new ReadWriteCsv.CsvRow();
            l.Add(this.KycrspFundno.ToString());

            l.Add(this.FrontLoad == null ? "" : this.FrontLoad);
            if (this.Fflbegdt == null || this.Fflbegdt.Year < 1900) l.Add(""); else l.Add(this.Fflbegdt.ToString("dd/MM/yyyy"));
            if (this.Fflenddt == null || this.Fflenddt.Year < 1900) l.Add(""); else l.Add(this.Fflenddt.ToString("dd/MM/yyyy"));

            l.Add(this.RearLoad == null ? "" : this.RearLoad);
            if (this.Frlbegdt == null || this.Frlbegdt.Year < 1900) l.Add(""); else l.Add(this.Frlbegdt.ToString("dd/MM/yyyy"));
            if (this.Frlenddt == null || this.Frlenddt.Year < 1900) l.Add(""); else l.Add(this.Frlenddt.ToString("dd/MM/yyyy"));

            l.Add(this.FexpRatio == null ? "" : this.FexpRatio);
            l.Add(this.FmgmtFee == null ? "" : this.FmgmtFee);
            l.Add(this.FturnRatio == null ? "" : this.FturnRatio);
            if (this.Ffebegdt == null || this.Ffebegdt.Year < 1900) l.Add(""); else l.Add(this.Ffebegdt.ToString("dd/MM/yyyy"));
            if (this.Ffeenddt == null || this.Ffeenddt.Year < 1900) l.Add(""); else l.Add(this.Ffeenddt.ToString("dd/MM/yyyy"));

            return l;
        }
Пример #7
0
        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);
                }
            }
        }
Пример #8
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();
            }
        }
Пример #9
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;
        }