Click here to Skip to main content
15,896,111 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi all

for create a bill i want print first month and then days base on below syntax :

we have a 2 date : 1- start date 2- end date

i want print month and daye between this dates ...

suppose start date is 2009/05/12 and end date is 2013/03/11

i want first print 18 month between first and end date like this (start one month after start date 2012/06/12):

2009/06/12
2009/07/12
2009/08/12
2009/09/12
2009/10/12
.
.
.
2010/08/12
2010/09/12
2010/10/12

and after it print base on days like
2010/10/13
2010/10/14
2010/10/15
.
.
.
until end date (2013/03/11)

how do i this ?

i use this code :

private void showbill_Load(object sender, EventArgs e)
    {

        lbl_user_fullname.Text  = Class_Variables.bill_user_firstname + " " + Class_Variables.bill_user_lastname;
        lbl_debt_price.Text = Class_Variables.bill_dept_price;
        lbl_peyments_count.Text = Class_Variables.bill_debt_peyments_count;

        string debt_year = Class_Variables.bill_dept_date.Substring(0, 4);
        string debt_month = Class_Variables.bill_dept_date.Substring(5,2);
        string debt_day = Class_Variables.bill_dept_date.Substring(8,2);

        string current_date_year = Class_Variables.bill_current_date.Substring(0, 4);
        string current_date_month = Class_Variables.bill_current_date.Substring(5, 2);
        string current_date_day = Class_Variables.bill_current_date.Substring(8, 2);



        dtp_farsi.CustomFormat = "y/MM/dd";
        dtp_farsi.Format = BehComponents.DateTimePickerX.FormatDate.Custom;
        dtp_farsi.SetSelectedDate(BehComponents.CalendarTypes.Persian, Convert.ToInt32(debt_year), Convert.ToInt32(debt_month), Convert.ToInt32(debt_day));

        dtp_farsi2.CustomFormat = "y/MM/dd";
        dtp_farsi2.Format = BehComponents.DateTimePickerX.FormatDate.Custom;
        dtp_farsi2.SetSelectedDate(BehComponents.CalendarTypes.Persian, Convert.ToInt32(current_date_year), Convert.ToInt32(current_date_month), Convert.ToInt32(current_date_day));

        int debt_price = Convert.ToInt32( Class_Variables.bill_dept_price);
        int peyments_count = Convert.ToInt32(Class_Variables.bill_debt_peyments_count);

        string todaydate = dtp_farsi.Text;

        //colnames names
        string[] colnames = new string[5];

        colnames[0] = "no";
        colnames[1] = "date";
        colnames[2] = "delay days";
        colnames[3] = "delay percent";
        colnames[4] = "delay price";
        //--------------------------------------------------

        const int dim = 1000;


        string[,] array = new string[dim, 5];
        int peyment_count = 1;
        TimeSpan ts = new TimeSpan();
        TimeSpan ts2 = new TimeSpan();
        int daydiff = 31;
        int daydiff2 = 0;

        int while_loop_counter=0;


        while(daydiff > 30)
        {
            ts = dtp_farsi2.GetSelectedDateInPersianDateTime().Subtract(dtp_farsi.GetSelectedDateInPersianDateTime().AddMonths(while_loop_counter+1));
            daydiff = ts.Days;

            for (int j = 0; j < 5; j++)
            {
                if (j == 0)
                {
                    array[while_loop_counter, j] = (while_loop_counter + 1).ToString();
                }
                else
                {
                    //Column #1
                    array[while_loop_counter, 1] = dtp_farsi.GetSelectedDateInPersianDateTime().AddMonths(peyment_count).ToStringFormat("y/MM/dd");

                    //Column #2
                    ts2 = dtp_farsi2.GetSelectedDateInPersianDateTime().Subtract(dtp_farsi.GetSelectedDateInPersianDateTime().AddMonths(peyment_count));
                    daydiff2 = ts2.Days;
                    array[while_loop_counter, 2] = daydiff2.ToString();

                    //Column #3
                    switch (while_loop_counter + 1)
                    {
                        case 1:
                        case 2:
                        case 3:
                        case 4:
                        case 5:
                        case 6:
                        case 7:
                        case 8:
                        case 9: array[while_loop_counter, 3] = 26.ToString();
                            break;

                        case 10:
                        case 11:
                        case 12: array[while_loop_counter, 3] = 24.ToString();
                            break;

                        case 13:
                        case 14:
                        case 15:
                        case 16: array[while_loop_counter, 3] = 22.ToString();
                            break;

                        case 17:
                        case 18: array[while_loop_counter, 3] = 20.ToString();
                            break;

                        default: array[while_loop_counter, 3] = 28.ToString();
                            break;
                    }



                    //Column #4

                    if (while_loop_counter <= 18)
                    {
                        array[while_loop_counter, 4] = (((debt_price / peyments_count) * Convert.ToInt64(array[while_loop_counter, 3]) * Convert.ToInt64(array[while_loop_counter, 2])) / 36500).ToString();
                    }
                    else
                    {
                        array[while_loop_counter, 4] = (((debt_price / peyments_count) * Convert.ToInt64(array[while_loop_counter, 3]) * Convert.ToInt64(array[while_loop_counter, 2])) / 36500).ToString();
                    }


                }

            }
            peyment_count++;

        while_loop_counter++;
    }



        dgv_bill.DataSource = new Mommo.Data.ArrayDataView(array, colnames);



        }



please help me ...

thanks a lot
Posted
Updated 23-Aug-13 9:12am
v3
Comments
[no name] 23-Aug-13 14:53pm    
"how do i this"... how do you what? Print to a printer? Print to the screen? Print to something else? Add days to a DateTime? Add a month to a DateTime? Make a "for" loop for 1 month to 18 months? What have you tried to do for yourself?
[no name] 23-Aug-13 14:59pm    
I want to calculate the delay of client's debt
The formula is as follows:
Penalties are calculated on a monthly basis for 18 months
And then daily
i want show this information on datagrid ... i can it ... but my problem is in loop ...
how do show first 18 month in datagrid and after it show days (not month) ..
thanks a lot again
[no name] 23-Aug-13 15:04pm    
Okaaaaaaaaaaay.... what does any of that have to do with printing? Please update your question with the real actual problem that you are experiencing, the code that you have written that demonstrates the problem and clearly describe what it is that you are trying to do. I won't even bother trying to help you if you can't decide what you are trying to do first.
[no name] 23-Aug-13 15:10pm    
please check my code ...
1-i use Behcomponent component for persian date
2- use Mommo.Data to work array into datagrid
thanks

1 solution

C#
DateTime startDate = ...
DateTime currentDate = startDate.AddMonths(1);
DateTime endDate = ...

while (true)
{
    //Print current date or do whatever you need with it.

    if (currentDate.AddMonths(1) < endDate)
        currentDate = currentDate.AddMonths(1);
    else
        break;
}

if (currentDate < endDate)
{
    while(true)
    {
        currentDate = currentDate.AddDays(1);
        //Do whatever you need to do with the days.   
    }
}


Something like that, I didn't compile it, but that should work to do what you are after.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900