Hi
I have a problem in Windows Form. Let me explain in detail.
I have a listbox 1,combobox1,button1,button2,Richtextbox1 with me on my windows form.
Combobox1 contains the customer number
Listbox 1 contains the templates which are already created and stored in the DB.
so listbox contains the following.
1. Template1
2. Template2
3. Template3
** Next My combobox has all customer numbers retrieved from the database.
*-* When i select a template from listbox, (for ex template 1 ) and click on button 1, the template is displayed in the richtextbox.
Template looks as follows.
Dear
The project date is < Project date>
The Name of the project is
Thanks.
Next, when i select a customer number from combo box1 and click on button2, the values underlined in the template has to be replaced by the values from the DB realted to that customer number. So far i have done thsi replacement and it looks like this.
Dear Jason
The project date is 01/01/2008
The Name of the project is
Thanks.
MY MAIN PROBLEM STARTS HERE
Sometimes, for some of the customer numbers from combobox1, the out put is multiple sets of records.
For Ex, if the o/p of one of the customer number is 5 records, the template should repeat itself 5 times in richtext box( in separate pages) and the data like
it looks like this.
Dear sairam
The project date is 01/01/2007
The Name of the project is india
Thanks.
Dear sairam
The project date is 10/10/2009
The Name of the project is USA
Thanks.
Dear sairam
The project date is 04/11/2006
The Name of the project is
Thanks.
Dear Konala
The project date is 04/11/2001
The Name of the project is
Thanks.
Dear reddss
The project date is 04/01/2006
The Name of the project is
Thanks.
This how the o/p shud look like
Please Help me in this ....
Waiting for ur reply guys...
Mamta MPosted Oct 23, 2008, 6:24 AM
Hi sairam,
I tried your scenario here with an xml file storing the templates, the listbox getting populated with the templates and the combo box having customer ids from the table. To get the requisite content in the Rich text box this is what I tried here and it worked successfully.private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
string oldoldtext = template; // the template from the listbox
string newtext = "";richTextBox1.Clear();
Sqlconn.Open();
//get the selected customer idid = comboBox1.SelectedItem.ToString();
SqlCommand cmd = new SqlCommand("SELECT * from customer where custid='" +id+"'", Sqlconn); SqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()){
string name = reader.GetString(1); string project = reader.GetString(2); DateTime dt = reader.GetDateTime(3); string oldtext = oldoldtext; string text = oldtext.Insert(5, name); int index = text.IndexOf("Name");text = text.Insert(index+22, project); //to insert in the right place for project name, you can change the value 22 depending on ur reqt
newtext += text;
}
reader.Close();
Sqlconn.Close();
richTextBox1.Text = newtext;
}
Hope this helps.
Regards,
Mamta