Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 4.0 aka C# 2010 > BOOK: Beginning Visual C# 2010
|
BOOK: Beginning Visual C# 2010
This is the forum to discuss the Wrox book Beginning Visual C# 2010 by Karli Watson, Christian Nagel, Jacob Hammer Pedersen, Jon D. Reid, Morgan Skinner, ; ISBN: 9780470502266
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning Visual C# 2010 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 5th, 2011, 01:25 AM
Registered User
 
Join Date: Jan 2011
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Post Help & advice needed on database display in *.csv format

Company period Sales
A Dec2010 0.729756526
B Dec2010 0.863636037
A Jan2011 0.86791111
B Jan2011 0.920546053
A Nov2010 0.830650517
B Nov2010 0.817534695
A Oct2010 0.827260316
B Oct2010 0.814205182
A Sep2010 0.998957223

Above is the database in sale.art format, i would like to save it to below*.csv format output.

Sales Target Expect A-Jan 2010 B-Jan 2010
Monthly 99.00% >


Would like to know where went wrong on below coding, becasue the csv file not able capture the data. Need someone advice & help. thanks.



Code:
#region using
using System;
using System.Collections.Generic;
using System.IO;
using DNALibrary;
#endregion

class Script 
{
	static public void Main(string[] args)
 {

string eatsRptWeekly = @"C:\Monthly\AllProd.art";
weekly(eatsRptWeekly);
  }

private static void weekly(string eats_weekly_file) {
		
Dictionary<string, EADataTable> dictEats = new Dictionary<string, EADataTable>();
dictEats = EADataTable.LoadARTFile(eats_weekly_file);

EADataTable dt_ind = new EADataTable();			
// Indicator Datatable
		
string indFile = Environment.CurrentDirectory + @"\Monthly WTD CSI.csv";
dt_ind.LoadCSVFile(indFile, true);

//set value for each yield indicator
int number_of_ind_in_csv =2; //Number of indicator in csv file
int dtsheet_count = 0; // Number of datasheets in report


//Erase all the previous data in the csv file
for (int i = 0; i < number_of_ind_in_csv; i++) {
	dt_ind.SetValue<string>(i, "A", null);
	dt_ind.SetValue<string>(i, "B", null);
            dt_ind.AddColumn(monthString(DateTime.Now.Month) + DateTime.Now.Year.ToString());
            dt_ind.AddColumn(monthString(DateTime.Now.AddMonths(-1).Month) + DateTime.Now.AddMonths(-1).Year.ToString());
            dt_ind.AddColumn(monthString(DateTime.Now.AddMonths(-2).Month) + DateTime.Now.AddMonths(-2).Year.ToString());
            dt_ind.AddColumn(monthString(DateTime.Now.AddMonths(-3).Month) + DateTime.Now.AddMonths(-3).Year.ToString());
            dt_ind.AddColumn(monthString(DateTime.Now.AddMonths(-4).Month) + DateTime.Now.AddMonths(-4).Year.ToString());
	
		}
		

foreach (string i in dictEats.Keys)			// i = key in dicEats
		{
if ((dtsheet_count < number_of_ind_in_csv) && (timeframe_flag == 0)) {  //Fill in value for WTD indicator
if (!dictEats[i].Attributes.ContainsKey("error")) {						//Check of data return or not
dictEats[i].SortByColumn("facility", EADataTable.SortOrder.ASCENDING);
				}
				//YIELD DATASHEET
if (dictEats[i].Attributes["indicator"].ToString() == "Yield") {
if (!dictEats[i].Attributes.ContainsKey("error")) {						//Check of data return or not
for (int j = 0; j <= dictEats[i].LastRow; j++) {
					
dt_ind.SetValue<string>(dtsheet_count, dictEats[i].GetValue<string>(j, "facility"), string.Format("{0:0.00%}", dictEats[i].GetValue<double>(j, "yield")));
						}
					}
else {	// If error (no data return) --> blank						
						dt_ind.SetValue<string>(dtsheet_count, "A", null);
						dt_ind.SetValue<string>(dtsheet_count, "B", null);
						}
				}				
		
dtsheet_count++;
if (dtsheet_count == number_of_ind_in_csv)	
				{
					timeframe_flag = 1;
					dtsheet_count = 0; //reset datasheet count
					continue;
				}
			}
		
        } 

		
		
		
		dt_ind.SaveCSVFile(indFile, true);

		
	
		Console.WriteLine("Wait");
		
		//Console.ReadLine();
		}

	

    private static string monthString(int month)
    {
        string thisMonth = string.Empty;

        if (month == 1) thisMonth = "Jan";
        else if (month == 2) thisMonth = "Feb";
        else if (month == 3) thisMonth = "Mar";
        else if (month == 4) thisMonth = "Apr";
        else if (month == 5) thisMonth = "May";
        else if (month == 6) thisMonth = "Jun";
        else if (month == 7) thisMonth = "Jul";
        else if (month == 8) thisMonth = "Aug";
        else if (month == 9) thisMonth = "Sep";
        else if (month == 10) thisMonth = "Oct";
        else if (month == 11) thisMonth = "Nov";
        else if (month == 12) thisMonth = "Dec";

        return thisMonth;
    }
	

	}





Similar Threads
Thread Thread Starter Forum Replies Last Post
Hello, New to ASP.net, Advice needed Top Hat ASP.NET 3.5 Basics 1 March 23rd, 2010 06:22 AM
Help Needed: Updating & Saving Database OnceANewbie BOOK: Beginning Visual Basic 2005 ISBN: 978-0-7645-7401-6 0 November 30th, 2008 10:05 PM
Positioning layers? Advice needed. Perkele Dreamweaver (all versions) 1 February 19th, 2007 02:43 PM
advice needed..please see sarah lee ASP.NET 1.0 and 1.1 Basics 1 September 5th, 2006 10:48 AM
Advice Needed Dsypher ASP.NET 2.0 Basics 1 January 31st, 2006 02:09 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.