Mitja Bonca 557 Nearly a Posting Maven


>I got written only the 2nd value (there is no the 1st).

This should not be a problem. Do not use multi-valued parameter. Use single value parameter.

This is not working. I have an array of values for the parameter. So it has to allow multiple values.
The only way would be to have for every value its own parameter. But this can not be - its too long code. How in case if I would like to pass 100 values? There is got to be some other way to pass an array of values to just ONE parameter. I think so.

Mitja Bonca 557 Nearly a Posting Maven

What exactly means "UBound" ?
As far as I read its an array of values, right?

I have put this code in all the formula fields.
Becuase now if I want to show two values out of all three, there is no more error, but I got written only the 2nd value (there is no the 1st).

And if I want to show all three values, there is only the 3rd one shown.
There is no 1st and 2nd values.

Sorry for asking so much, but this is my 1st time doing this, and I would like to learn it.

Mitja Bonca 557 Nearly a Posting Maven

I did that, and if I fill all three fields with values its all working fine.
But the error occurs when there is no value in the parameter. See attached image

On the 2nd image you can see how is my report made. In te 3rd section (details) I have put the formula fields.

Mitja Bonca 557 Nearly a Posting Maven

I did work a bit more with putting values into formula field on the report. And I got the values into them.

But I have one problem:

I did in the formula field:

{?Data} [1] + ' ' + {?Data} [2] + ' ' + {?Data} [3] -> This means the values are written into one line


if I did
{?Data} [1] + ' ' +
{?Data} [2] + ' ' +
{?Data} [3] -> I again get values written into one line


I would like to get the values written one under another.


How would I write the code for the into value empty:

If IsNull({?Storitve} [3]) OR {?Storitve} [3] = '' Then "Empty Parameter"
Else If{?Storitve} [3]
Mitja Bonca 557 Nearly a Posting Maven

One question for the report3:

Lets take a look at this code:

private void ViewThree_Load(object sender, EventArgs e)
        {
            DS a = new DS();
            string[] items = { "AA", "BB", "CC" };
            
            ReportThree1.SetDataSource(a);
            ReportThree1.SetParameterValue("data", items);

        }

Why you do not use DataSet a for values in the "data" parameter like:

ReportThree1.SetParameterValue("data", a);

This is how I have?
And maybe this is what I am doing wrong.

Mitja Bonca 557 Nearly a Posting Maven

I have included only those classes in which I have the code for showing the values in the crystal report viewer.

Mitja Bonca 557 Nearly a Posting Maven

I know its against the rules, I Just didn't want to post my project here. You asked me if I send you, so I did. Do I have to post it here again, or not? Would you look into my project what is wrong?

Mitja Bonca 557 Nearly a Posting Maven

Just sent you a private message.
Big thanks.

Mitja Bonca 557 Nearly a Posting Maven

On the image on the link bellow you can see that there is only 1st value written out on the report:

http://file.si/files/2237_yhswo/C%23_CrystalReport03.jpg

For the parameter "Vrsta storitve" are missing values "Two" and "Three".

Mitja Bonca 557 Nearly a Posting Maven

Is there anyone who would know why I still get only one value into parameter, even if I wrote the formula field, like it was explained in the upper posts.

Please.

Mitja Bonca 557 Nearly a Posting Maven

Thx, but again it shows only the 1st value! There are not 3 of them in the list (one under another).

I am still missing something, but what. Do I need to create aditional group field, to show the list of values? Becuase I have them now in Section3 (details). Could this be the reason of it?

Maybe the section is not extanding ? How to set one section (in my case I have Section3 -Details) to extend if more values need to be shown? Does crystal report do this automatically?

Mitja Bonca 557 Nearly a Posting Maven

There is something bothering me.
I have a "Parameter" which I bind to values that _I have to show on the report. So if I have to show more values one under another I have to do a formula field parameter. But I can not put this formula field parameter onto the report. There already is "Parameter".
I am not clear about how to connect these two parameters?

Mitja Bonca 557 Nearly a Posting Maven

>but it is showing ONLY the 1st value..

Create a formula field to check the value,
{?parameter}[index]

{?data} [1]  <- 1st value
 {?data} [2]  <- 2nd value
  ....

Ok, but would you be please so kind and just explain me a bit more, that I would know what do I need to do this? What do I need a formula field?

For code belove that I just simply do as you did:

{?data} [1]
{?data} [2] .. or
{?data} [3]

to define where new value has to be placed?


And one more thing, how to connect this formula filed with The parameter (?parameter)?


This is how I did, but its not correct (i guess there is something missing):
http://file.si/files/2150_le4nn/C%23_crystalReport03_parametri.JPG

Mitja Bonca 557 Nearly a Posting Maven

>how to pass more values (to be shown one under another) in just one parameter.

cryRep.SetParameterValue("@data", new int[]{10,20,30,40});

I tried that before and today ones again, but it is showing ONLY the 1st value (in this case only number 10). There is no others. I am missing sometihng, something that will tell to the crystal report viewer that there is are multiple values. And I have checked the option "Allow multiple values" to true, so there has to be sometihng else. But what?

Mitja Bonca 557 Nearly a Posting Maven

I still didnt salve the problem. I am struck with the code 3 post above.
I can no succeed how to pass more values (to be shown one under another) in just one parameter.


Can someone help me out please?

Mitja Bonca 557 Nearly a Posting Maven

I have a problem of reading a dateTime column from a database. I set a parameter which is a datetime, but it does not read it. I am wondering what could be wrong.

This is how I have written a date and time in the database:
http://file.si/pthumbs/large/7216/C%23_datetime_Lista.JPG

And this is my code with the parameter. In the value "Datum" you can see I got the same date and time as it is in the database. But the reader (bralec) does not read it.

http://file.si/files/2081_glnve/C%23_datetime_Lista2.JPG

What could be wrong?

Mitja Bonca 557 Nearly a Posting Maven

I have:

Table1: Service:
- IDService
- ServiceName

Table2: Order:
- IDOrder
- IDServiceFK (foreigh key)

I have database table called "Service", in which I store service names.
Then I have another table called "Order", in which is the foreigh key of Service.

Services are shown in the listView control. The listView shown checkBox control. So far I had only an option to choose only ONE item from the listView (only one item could be checked), because I have only one column name for it in the table Order (only one place - IDServiceFK). And the ID of this item (service`s name) was written into Order table (into service foreign key).

But I would like to change the code, which will allow user to select as many services from the list as he likes.
The problem is that I do not know how to do the Order table (how to insert all the IDs of selected services into Order table).

Should I do:

Table2 Order:
- IDOrder
- IDServiceFK1
- IDServiceFK2
- IDServiceFK3
- IDServiceFK4
- IDServiceFK5

and limit the selection on 5. If more then 5 selectred, user gets a warning message that he reached the max of selection.
In case if user does select less then 5, I just send a DBNull to the others.

What do you think? How can I get rid of this …

Mitja Bonca 557 Nearly a Posting Maven

How can I use a DataTable to save data into it? I have a listView with ticks, and when a tick is checked, I would like to put the data of the row into DataTable.
In the row I have a "ProductName" and it`s "Price".
I am doing this becuase the user can change the content of the listView, so when it comes back to previous list, where he checked a row, I would like that the row remains checked.
The easiest way I came up with, is to save the ticked row into DataTable, and when users changes list`s content, I will check every time the content of the DataTable, and if there is a row in it which equals with the actual shown list in a listView, I will check the row.

Does this have any sence? Or is there any better way of ticking previousely ticked rows?

Mitja Bonca 557 Nearly a Posting Maven

I got it. This is what I wanted:

decimal Znesek = 0;
                string danesDobiček = @"SELECT SUM(Znesek) FROM Plačilo WHERE (DatumPlačila >= @začetniČas) and (DatumPlačila < @končniČas)";
                using (SqlCommand cmd = new SqlCommand(danesDobiček, povezava))
                {
                    int ŠteviloDniRazmika = 1; 
                    DateTime ZačetniDatum = DateTime.Today; 
                    DateTime KončniDatum = ZačetniDatum.AddDays(ŠteviloDniRazmika);

                    cmd.Parameters.AddWithValue("@začetniČas", ZačetniDatum);
                    cmd.Parameters.AddWithValue("@končniČas", KončniDatum);
                    povezava.Open();
                    object objZnesek = cmd.ExecuteScalar();
                    if (objZnesek != DBNull.Value)
                        Znesek = Convert.ToDecimal(objZnesek);
                    povezava.Close();

Salved!

Mitja Bonca 557 Nearly a Posting Maven

I have dates and times stored in the database - the data type of DateTime (for example: 17.1.2010 16.23.34 - dd.MM.yyyy hh.mm.ss)
The parameter which I define it has too look ONLY of date ("dd.MM.yyyy"), because I want to get all the values on a specific date and the sum them up.

This is the reason why DateTime.Today doesn`t work, and either it doesn`t DateTime.Today.Date.

So how to declate that it will be correct, that the parameter will look only for date (without time)?
ReplyQuoteMark As AnswerEditDelete

decimal ListaPlačil = 0;
                string danesDobiček = @"SELECT SUM(Znesek) FROM Plačilo WHERE DatumPlačila = @danes";
                using (SqlCommand cmd = new SqlCommand(danesDobiček, povezava))
                {
                    cmd.Parameters.Add("@danes", SqlDbType.DateTime);
                    cmd.Parameters["@danes"].Value = DateTime.Today.Date; //This is not the correct parameter, thats why it does not read the database
                    povezava.Open();
                    object objListaPlačil = cmd.ExecuteScalar();
                    if (objListaPlačil != DBNull.Value)
                        ListaPlačil = Convert.ToDecimal(objListaPlačil);
                    povezava.Close();
                }
                return ListaPlačil;
Mitja Bonca 557 Nearly a Posting Maven
bool isChecking;
bool canCheck;
private void listView1_ItemCheck(object sender, ItemCheckEventArgs e)
{
    if (!isChecking && canCheck)
    {
        isChecking = true;
        foreach (ListViewItem item in listView1.Items)
        {
            item.Checked = false;
        }
        listView1.Items[e.Index].Checked = true;
        e.NewValue = CheckState.Checked;
        canCheck = false;
        isChecking = false;
    }
    else
    {
        if (isChecking)
        {
            e.NewValue = CheckState.Unchecked;
        }
        else
        {
            e.NewValue = e.CurrentValue;
        }
    }
}

private void listView1_MouseDoubleClick(object sender, MouseEventArgs e)
{
    // We can't unlock the lock if the value doesnt change.
    if (!listView1.GetItemAt(e.X, e.Y).Checked)
    {
        canCheck = true;
        listView1.GetItemAt(e.X, e.Y).Checked = true;
    }
}
Mitja Bonca 557 Nearly a Posting Maven

I am doing some more coding on listView, and I can not figurate it out how to salve the problem that there is always just one checkBox on the listView checked.

On the listView I have some names. When I load it there is already a checked name - so far so good.

But I would like to do the code, that when I will check another checkBox, this one has to check and the other one which was checked before, it has to uncheck.
Anyone knows how to help me out with this?

So that there will always be just one checkBox checked.

Mitja Bonca 557 Nearly a Posting Maven

No one knows how to salve this problem of adding more values to one parameter? Do I need to add any formula?
If so, how its gonna look? And you have to know I dont work with database in this example.

Mitja Bonca 557 Nearly a Posting Maven

EDIT:
As fas as I read I need to write a formula which can have multiple lines and it can grow. What to write it? I presume it goes to Forumla Field.

Mitja Bonca 557 Nearly a Posting Maven

Or I did something like this, but it is still not showing all the values, only the last one:

ParameterValues myParams = new ParameterValues();
            ParameterDiscreteValue pdv = new ParameterDiscreteValue();
            foreach (string myValue in AllMyValues)
            {
                pdv = new ParameterDiscreteValue();
                pdv.Value = myValue.ToString();
                myParams.Add(pdv);
            }
            cr.SetParameterValue("ParameterName", myParams);
            crystalReportViewer1.Refresh();

Whats am I doing wrong, that the values are not shown? Why there is only the last one shown? I have set the parameter (parameter name is "ParameterName") option "Allow multiple values" to true (checked it).

Mitja Bonca 557 Nearly a Posting Maven

I am doing a crystal report, and I would like to dinamiclly add parameters.

I did the code which adds the value to one parameter, which I have created in the crystalReportViewer:

CrystalReport1 cr = new CrystalReport1();
cr.SetParameterValue("ParameterName", ParameterValue);
crystalReportViewer1.ReportSource = cr;
crystalReportViewer1.Refresh();

But this is for only one value.

Now I would like to put more values for that ParameterName. This is the code I fould on this forum, but the problem is that I do not know what to pass for "ParameterFields paramFields":

This is where I get the ParameterNames:

foreach (string myParamName in allParamNames)
{
     AddParameter("myParameterField", myParameterName, /*WHAT COMES HERE? - to pass the 3rd value to the method bellow*/ );
}

private ParameterFields AddParameter 
   (string paramName, string paramValue,
   ParameterFields paramFields) //I do not know what to pass to here!
{
   ParameterField paramField= new ParameterField ();
   ParameterDiscreteValue paramDiscreteValue = new 
   ParameterDiscreteValue ();
   ParameterValues paramValues = new ParameterValues ();

   // Set the name of the parameter <strong class="highlight">to</strong> modify.
   paramField.ParameterFieldName = paramName;

   // Set a value <strong class="highlight">to</strong> the parameter.
   paramDiscreteValue.Value = paramValue;
   paramValues.Add (paramDiscreteValue);
   paramField.CurrentValues = paramValues;

   // Add the parameter <strong class="highlight">to</strong> the ParameterFields collection.
   paramFields.Add (paramField);
   return paramFields;
}
Mitja Bonca 557 Nearly a Posting Maven

Why when I save a float value into database (the data type is float as well), for example 24,62 in database is writen as 24,6200008392334. I have entered only 2 decimals, but in db there is plenty of them.

This is how I have:

string Together = textBoxAmount.Text;
string[] Seperated = Together.Split(' ');
float MyAmount = float.Parse(Seperated[0]);

In the "textBoxAmount.Text" it`s just a number with € sign. In my case 24,62 €.

Thats why I 1st do a seperation with whitesplace, that I get in array[0] only a string of 24,62. Then I convert it to float. But I do not add F mark correctly (for float).

Mitja Bonca 557 Nearly a Posting Maven

Got it, works great :)

float myPrice = 0F;             
            for (int i = 0; i < listView1.Items.Count; i++)
            {
                if (listView1.Items[i].Checked && !String.IsNullOrEmpty(listViewLista.Items[i].SubItems[1].Text))
                {
                    myPrice = float.Parse(listView1.Items[i].SubItems[1].Text;
                }
                textBox1.Text = Convert.ToString(myPrice);
            }
Mitja Bonca 557 Nearly a Posting Maven
float myPrice = 0F;             
            for (int i = 0; i < listView1.Items.Count; i++)
            {
                if (listView1.Items[i].Checked)
                {
                    myPrice = float.Parse(listView1.Items[i].SubItems[1].Text;
                }
            }

I got a float number into variable "myPrice". How to SUM all which are selected together ( this + this + this..) and show the value in textBox1

Mitja Bonca 557 Nearly a Posting Maven

I have a listView, in 1st column is are article names, in 2nd column are prices of these articles (data type of float).
And I have checkBoxes. What I would like to do, is to count the prices in 2nd column of all selected rows.
And then the counted value to show in a tectBox.
How can I do that?

This is what I did, but I dont know how to count them?

for (int i = 0; i < listView1.Items.Count; i++)
            {
                if (listView1.Items[i].Checked)
                {
                    //when row checked is has to count here
                    //textBox1.Text += listView1.Items[i].SubItems[1].Text;
                }
            }

But this is not working correctly. It does not count prices together when selected the row.

And one more thing. Which method to use that the chekced rows will count in a real time.
An event handler "ItemCheck" it does not do that. It count the previous checked row when another is checked - so one step behind.

Mitja Bonca 557 Nearly a Posting Maven

Works:)

string DanesRezervacije = "SELECT Stranka.ImePriimek, Naročilo.ČasRezervacije FROM Stranka, Naročilo " +
                                      " WHERE Stranka.IDStranke = Naročilo.IDStrankeFK AND Naročilo.DatumRezervacije = @danes " +
                                      "ORDER BY Naročilo.ČasRezervacije ASC";
Mitja Bonca 557 Nearly a Posting Maven

I get into DataSet CostumerNames and Hours (type DateTime) of their registrations.
I would like to sort customers my time of registration (time of a day).

I show both in listView.
This is my code:

string DanesRezervacije = "SELECT Stranka.ImePriimek, Naročilo.RegisterTime FROM Stranka, Naročilo " +
                                    " WHERE Stranka.IDStranke = Naročilo.IDStrankeFK AND Naročilo.DatumRezervacije = @danes";
            // THIS IS NOT WORKING:  " + "ORDER BY Naročilo.DatumRezervacije ASC";
            da = new SqlDataAdapter(DanesRezervacije, povezava);
            da.SelectCommand.Parameters.Add("@danes", SqlDbType.DateTime).Value = DateTime.Today.Date;
            DataSet ds = new DataSet();
            da.Fill(ds, "DanašnjeRezervacije");
            foreach (DataRow dr in ds.Tables[0].Rows)
            {
                ListViewItem lvi = new ListViewItem(dr["ImePriimek"].ToString());
                lvi.SubItems.Add(Convert.ToDateTime(dr["RegisterTime"]).ToShortTimeString());
                listViewLista.Items.Add(lvi);
            }

                }
Mitja Bonca 557 Nearly a Posting Maven

Finally did it:

DateTime čas = new DateTime(dateTimePicker1.Value.Year, dateTimePicker1.Value.Month, dateTimePicker1.Value.Day);
            
            for (DateTime Čas = čas.AddHours(7); Čas < čas.AddHours(19); Čas = Čas.AddMinutes(30))
            {
                dataGridView1.Rows.Add(Čas.ToShortTimeString());
            }

Works :)

Mitja Bonca 557 Nearly a Posting Maven

I would like to change my code here a bit, by including dateTimePicker. That the hous in the column will be displayed from it.

Becuase I need to save into database, the time based on the dateTimePicker, not from something else (like DateTime.Today).

I did this code, but it is not starting with 7am like I would like to. It starts with 00.00.

So how would this code be changed that will include dateTimePicker?

for (DateTime Čas = DateTime.Today.AddHours(7); Čas < DateTime.Today.AddHours(19); Čas = Čas.AddMinutes(30))
            {
                dataGridView1.Rows.Add(Čas.ToShortTimeString());
                i++; 
            }
Mitja Bonca 557 Nearly a Posting Maven

I inserted a value of DateTime into database, like "26.12.2009 11:50:00" .
Is it possible that the reader will read only the time of a day from this, without date?

So far I did only that it reads everything, date and time:

string myTime = Convert.ToDateTime(dataGridView1.Rows[IndexVrstica].Cells[0].Value).ToShortTimeString();
DateTime myTime2 = Convert.ToDateTime(myTime);

it has to be something like:

DateTime myTime2 = Convert.ToDateTime(myTime).ToShortTimeString();

but this is not ok, beucase I got an error, that it can not be transformed from date to string.

As I said, I would like that it reads only time. Is this possible?
If not, I will have to change some other thing, which I do not know how.

Mitja Bonca 557 Nearly a Posting Maven

Got to. It works:

public class Form1 : Form {//Do something like following in your form
    System.Windows.Forms.Timer myTimer = new System.Windows.Forms.Timer();
    StatusBar statusBar1 = new StatusBar();

    // This is the method to run when the timer is raised.
    private void TimerEventProcessor(Object myObject,
                                            EventArgs myEventArgs) {
       myTimer.Stop();
       statusBar1.Text="";
       myTimer.Tick -= TimerEventProcessor;
     }

    public void SetStatusBar() {
       /* Adds the event and the event handler for the method that will 
          process the timer event to the timer. */
       myTimer.Tick += new EventHandler(TimerEventProcessor);

       // Sets the timer interval to 5 seconds.
       myTimer.Interval = 5000;

       statusBar1.Text="Notification Message";
       myTimer.Start();
    }
 }
Mitja Bonca 557 Nearly a Posting Maven

How can I show a message in the statusBar for 5 seconds?
I do some code, on the end I write out a message in statusBar (statusBar.Text = "Notification Message"; ).
But I want that is shown for only 5 seconds. Then it dissapears (with statusBar.Text = ""; )

How can I do this?

Mitja Bonca 557 Nearly a Posting Maven

This is how I got indexes for a cell:
In the DGW CellDoubleClick event I did:

int rowIndex = e.RowIndex;
int colIndex = e.ColumnIndex;

Got it. Thread salved!

Mitja Bonca 557 Nearly a Posting Maven

Sorry, but this is not what I want. I would like to get row and column indexes when I click on a cell. Lets say that before clicking I do not know the indexes. And after I double click (or maybe any other event), I need to get index for row and index for column.

Because I need to save this two indexes for each cell into database, if I want to show the value right there, in the same cell where I entered it.

Mitja Bonca 557 Nearly a Posting Maven

Thx for convincing me to use the dgw. I was thinking for 2 days what to do, or to stay on ListView or to go on dgw. Now I finally made my mind and I will change it right now.
btw, can I ask you how to get row and column indexes in DGW?

Mitja Bonca 557 Nearly a Posting Maven

How to get row and column index when I double click (or some other event) of a cell on a ListView?

Mitja Bonca 557 Nearly a Posting Maven

Thx. I got the reference to System.Windows.Controls.
But now there is a nother problem. I would like to use ListViewItem, but there is ambiguoulty between Forms and Controls references.
Take a look at this picture.

Mitja Bonca 557 Nearly a Posting Maven

What do I need that I can add a reference to System.Windows.Controls namespace?

Mitja Bonca 557 Nearly a Posting Maven

I would like to know if is possible to click on every single cell in a listView seperately, like in a datagridview? If I set a full row selection to false I am only able to select the cell in the 1st column. The point or this thread is, that I would like to select the 2nd, 3rd, and so on (if there are more columns). Is this possible, or am I forced to use DGW, where single cell selection is possible?

Mitja Bonca 557 Nearly a Posting Maven

I would like to do a seperated class with a method which will return CustomerID (this will be a select query from db), based on the Costumer`s name which would come into this method (it will come from a form1`s method - from a textBox).
I am not sure how to do all these connections that the name will come from form1 to CustomerID method in class1.
And then when CustomerID if found it has to pass it back to Form1.

So, from form1 to Customer method in class1 goes the name, and back from method to from1 goes id.
Is this possible?

Mitja Bonca 557 Nearly a Posting Maven

This is how I have a listView: PICTURE

For example, I have clicked on the 6th row (which is colored blue) and with a double click I want to insert "SomeName" into a 2nd column (called 1.rezervacija) beside the 9:30. How to do it so?

I need something else, with if statement, like

if(listView1.SelectedItem[0] and a 2nd column (1.rezervacija) is empty)
then insert a name,
else create a new column (2.rezervacija) and insert "SomeName"

I was trying with this, but it is not working (I got into Text the actually hour from the 1st column, instead the text from the 2nd column):

if (listView1.SelectedItems[0].SubItems[0].Text == String.Empty)
{
    //SubItems.Add() code
}
Mitja Bonca 557 Nearly a Posting Maven

thx, I didnt know that until now. Big thanks.
Cheers

bye, bye

Mitja Bonca 557 Nearly a Posting Maven

Just one more thing, when it goes over 12.30 (in the midday) then it goes back to 1.00, I would like to have 13.00. How to do that?

Mitja Bonca 557 Nearly a Posting Maven

yep :)

for (DateTime dt = DateTime.Today.AddHours(7); dt < DateTime.Today.AddHours(19); dt = dt.AddMinutes(30))
{}

thank you mate for a help.

Just one more thing, when it goes over 12.30 (in the midday) then it goes back to 1.00, I would like to have 13.00. How to do that?

Mitja Bonca 557 Nearly a Posting Maven

And how would it be if I want to start with 7.am and up to 6.pm)?
Becuase this code starts with 12.00.