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;
}
}