I've got this code that creates a Table and a graph, the values have to be int for the graph. But in the table I want t display the values as... 1,000,000
How can I do this??

public partial class output : System.Web.UI.Page
{
    int max = 0;
    int current = 0;

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
                // create the table
            DataSet ds = GetGraph();
            outputView.DataSource = ds;
            outputView.DataBind();

                // create the graph
            SmoothLineChart chart1 = new SmoothLineChart();
            chart1.Line.Color = Color.Blue;
            chart1.Fill.Color = Color.Blue;
            chart1.Legend = "Construction Cash Flow";

            SmoothLineChart chart2 = new SmoothLineChart();
            chart2.Line.Color = Color.Green;
            chart2.Fill.Color = Color.Green;
            chart2.Legend = "Upper Probability Limit";

            SmoothLineChart chart3 = new SmoothLineChart();
            chart3.Line.Color = Color.Red;
            chart3.Fill.Color = Color.Red;
            chart3.Legend = "Lower Probability Limit";

            int total = max + 1000000;
            ChartControl1.YCustomEnd = total;

            if (total < 10000000)
                ChartControl1.YValuesInterval = 1000000;
            if(total > 10000000)
                ChartControl1.YValuesInterval = 1000000;
            if (total > 50000000)
                ChartControl1.YValuesInterval = 10000000;
            if (total > 80000000)
                ChartControl1.YValuesInterval = 100000000;
            if (total > 1000000000)
                ChartControl1.YValuesInterval = 100000000;
           
            foreach (DataRow row in ds.Tables[0].Rows)
            {
                chart1.Data.Add(new ChartPoint(row["Valuation Date"].ToString(), (int)row["Construction Cash Flow"]));
                chart2.Data.Add(new ChartPoint(row["Valuation Date"].ToString(), (int)row["Upper Probability Limit"]));
                chart3.Data.Add(new ChartPoint(row["Valuation Date"].ToString(), (int)row["Lower Probability Limit"]));
            }
            
            ChartControl1.Charts.Add(chart1);
            ChartControl1.Charts.Add(chart2);
            ChartControl1.Charts.Add(chart3);
            ChartControl1.RedrawChart();
        }
    }

    public DataSet GetGraph()
    {
        string f_id = Request.QueryString["f_id"];

        string strConnString =
            "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|calculator.mdb";

        OleDbConnection con = new OleDbConnection(strConnString);
        con.Open();

            // read from form_input table
        string strQuery = "select * from form_input where f_id=" + f_id;
        OleDbCommand cmd = new OleDbCommand(strQuery, con);
        OleDbDataReader reader = cmd.ExecuteReader();
        reader.Read();
        string start_str = reader["start"].ToString();
        DateTime start = DateTime.Parse(start_str);
        string end_str = reader["completion"].ToString();
        DateTime end = DateTime.Parse(end_str);
        string cost = reader["cost"].ToString();
        double b = double.Parse(cost);
        string validDay_str = reader["validation"].ToString();
        int validDay = Int32.Parse(validDay_str);
        string code = reader["code"].ToString();
        string holiday_str = reader["holiday"].ToString();
        int holiday = Int32.Parse(holiday_str);
        string symbol = reader["symbol"].ToString();

            // read from alpha_beta table
        string strQuery2 = "select * from alpha_beta where code=" + code;
        OleDbCommand cmd2 = new OleDbCommand(strQuery2, con);
        OleDbDataReader reader2 = cmd2.ExecuteReader();
        reader2.Read();
        string construction_a_str = reader2["construction_a"].ToString();
        string construction_b_str = reader2["construction_b"].ToString();
        string top_a_str = reader2["top_a"].ToString();
        string top_b_str = reader2["top_b"].ToString();
        string bottom_a_str = reader2["bottom_a"].ToString();
        string bottom_b_str = reader2["bottom_b"].ToString();

            // alpha_beta values
        double construction_a = double.Parse(construction_a_str);
        double construction_b = double.Parse(construction_b_str);
        double top_a = double.Parse(top_a_str);
        double top_b = double.Parse(top_b_str);
        double bottom_a = double.Parse(bottom_a_str);
        double bottom_b = double.Parse(bottom_b_str);

            // display
        DataSet ds = new DataSet();
        DataTable dt = ds.Tables.Add("Table");
        dt.Columns.Add(new DataColumn("Valuation Date", typeof(string)));
        dt.Columns.Add(new DataColumn("Construction Cash Flow", typeof(int)));
        dt.Columns.Add(new DataColumn("Upper Probability Limit", typeof(int)));
        dt.Columns.Add(new DataColumn("Lower Probability Limit", typeof(int)));

            // fill rows
        foreach (DateTime valuationDate in GetDates(start, end, validDay))
        {
            int numberOfDays = 0;
            if (valuationDate.Month == 12 || valuationDate.Month == 01)
            {
                numberOfDays = 14;
            }
            current += numberOfDays;

            DataRow row = dt.NewRow();
            row["Valuation Date"] = valuationDate.ToString("yyyy/MM/dd");
            row["Construction Cash Flow"] = Calculation(current, holiday, validDay, b, valuationDate, start, end, construction_a, construction_B);
            row["Upper Probability Limit"] = Calculation(current, holiday, validDay, b, valuationDate, start, end, top_a, top_B);
            row["Lower Probability Limit"] = Calculation(current, holiday, validDay, b, valuationDate, start, end, bottom_a, bottom_B);
            dt.Rows.Add(row);
        }

        reader2.Close();
        reader.Close();
        con.Close();
        return ds;
    }

    public int Calculation(int current, int holiday, int validDay, double b, DateTime validation,
        DateTime start, DateTime end, double alpha, double beta)
    {
        double t1;

            // check if last calculation
        if (validation > end)
        {
            System.TimeSpan sp_last =
                end.Subtract(start);
            t1 = sp_last.TotalDays;
        }
        else
        {
            System.TimeSpan sp_start =
                validation.Subtract(start);
            t1 = sp_start.TotalDays;
        }

            // end date(t2)
        System.TimeSpan sp_end =
            end.Subtract(start);
        double t2 = sp_end.TotalDays;

            // calculate t1 if holidays do apply
        if (holiday == 1)
        {
            int totalHolidays = 0;
            foreach (DateTime valuationDate in GetDates(start, end, validDay))
            {
                if (valuationDate.Month == 12 || valuationDate.Month == 01)
                {
                    totalHolidays += 14;
                }
            }

            t1 -= current;
            t2 -= totalHolidays;
        }
        else
        {
            t1 = t1;
        }

            // calculation
        double divide = (t1) / (t2);
        double minus1 = (1 - (divide));
        double pow1 = 1 - (Math.Pow(minus1, alpha));
        double calculation = Math.Round(b * (Math.Pow(pow1, beta)), 2);

        int myInt = (int)calculation;
        max = Math.Max(myInt, myInt);
        return myInt;
    }

    public List<DateTime> GetDates(DateTime startDate, DateTime endDate, int validDay)
    {
        if (startDate.Day > validDay - 15)
        {
            startDate = startDate.AddMonths(1);
        }

        TimeSpan span;
        span = endDate - startDate;

        List<DateTime> result = new List<DateTime>();

        DateTime dateToParse = DateTime.MinValue + span;

        int yearMonths = 0;
        if (dateToParse.Year > 0)
        {
            yearMonths = (dateToParse.Year - 1) * 12;
        }

        int monthCount = (yearMonths + dateToParse.Month) - 1;

        int lastRow = 0;
        if (endDate.Day > validDay)
        {
            lastRow = (monthCount + 2);
        }
        else
        {
            lastRow = monthCount;
        }

        for (int i = 0; i < lastRow; i++)
        {
            DateTime currDate = endDate.AddMonths(-(monthCount - i));
            int lastDayOfMonth = DateTime.DaysInMonth(currDate.Year, currDate.Month);
            currDate = new DateTime(currDate.Year, currDate.Month, lastDayOfMonth);
            if (currDate.Day <= validDay)
            {
                result.Add(currDate);
            }
            else
            {
                currDate = new DateTime(currDate.Year, currDate.Month, validDay);
                result.Add(currDate);
            }
        }

        return result;
    }
}
kvprajapati commented: 42 posts and don't know where to post asp.net question. -2

Recommended Answers

All 3 Replies

I didn't read your code, but i think what u want is

int.Parse(textBox1.Text).ToString("###,###,###");
for decimal or double

double.Parse(textBox1.Text).ToString("###,###,###.000");

Number of zeros at the end for how many decimals
Enjoy

You know you can just do this

OleDbDataReader reader = new OleDbCommand("select * from form_input where f_id=" + f_id, con).ExecuteReader();

instead of

string strQuery = "select * from form_input where f_id=" + f_id;
OleDbCommand cmd = new OleDbCommand(strQuery, con);
OleDbDataReader reader = cmd.ExecuteReader();

if solved please mark as solved.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.