Click here to Skip to main content
15,897,891 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi guys!
I have a requirement in my website that would automatically generate strings and automatically increase by 5 if another record will be added. For example,if the user will select a code from a drop down list, it will automatically generate sub items code as shown below:

PPY-05 ---> PPY-CC-05
---> PPY-CC-10
---> PPY-CC-15

By the way, the first code (PPY-05) is taken from the database named milestone_code. So if the user would like to create sub items of that milestone_code, it will be PPY-CC-05, PPY-CC-10 and so on. Then this sub items will be saved into the database named check_code. This check_code will also have sub items. if the user will choose PPY-CC-05 from a drop down list the website will automatically generate their code like this one below:

PPY-CC-05 ---> PPY-CC-AC-05
---> PPY-CC-AC-10

all of the item codes should be added automatically by 5.

Can somebody help me? Hope you understand my problem :)
Posted
Comments
Sergey Alexandrovich Kryukov 22-Jul-14 2:18am    
What is the problem with that? What have you tried so far?
—SA
DarkDreamer08 22-Jul-14 2:27am    
actually I tried this one:

s = WebConfigurationManager.ConnectionStrings["AmicassaConnectionString2"].ConnectionString;
amicassa = new SqlConnection(s);
amicassa.Open();
SqlCommand cmdd = new SqlCommand("SELECT Milestone_Code FROM tblMilestone WHERE Milestone_Name = '" + dplmilestone_checklist.SelectedItem + "'", amicassa);
SqlDataReader drr = cmdd.ExecuteReader();
if (drr.HasRows)
{
while (drr.Read())
{
string aa = drr[0].ToString();
string[] parts = aa.Split('-');
int number = Int32.Parse(parts[1]) + 5;
string result = parts[0] + "-CC-" + number.ToString();
txtchecklist_code.Text = result;
}
}
drr.Close();
amicassa.Close();

but if I am going to add another sub item for the same milestone_code and save it, they' re both the same which should not be.

PPY-05---> PPY-CC-10
---> PPY-CC-10
It should not be like that.

How to do it?
strimpf 22-Jul-14 11:56am    
I just have a few questions:
1) How do we know how many sub items to create? Set number? User input?
2) Is it necessary to go to the database to get the milestone descriptor (Like PPY-05)? Wouldn't you have that value in your drop-down list already as part of the Name/value pair?
3) Are there more levels than "CC" and "CC-AC"? What are they/how are they determined?
4) Can the user select "PPY-CC-15" from the drop-down list and would the next one be "PPY-CC-AC-20" if they did?
-KGT
DarkDreamer08 22-Jul-14 21:47pm    
My answers:

1. the number of sub items will be based from the user input. but the user will not input the number of sub items. the system will just automatically create their codes when the user would like to add another record on that milestone.

2. I need to get the milestone_code from the database since the dropdownlist will display the milestone_name of each code. That's part of the project requirements.

3 and 4. Its only CC for check_code and CC-AC is for activity_code. They will be determined by this flow: at first page, the system will display a dropdownlist that contains the milestone_name. below this dropdownlist is a textbox for the check_code. if the user selects a milestone_name(for example is BOOKING), the corresponding milestone_code(which is BOO-05) of that milestone_name will be get to automatically create the check_code in the pattern of this,"BOO-CC-05" and then a save button to store the check_code. if the user wants to add another check_code from the same milestone_name: BOOKING, the check_code should be now like this:"BOO-CC-10". meaning, the system should validate if the check_code is already existing. if it is, then it will add another 5 to it. Likewise, a page that has the same setup will be for the generation of activity_code. same set up and process like the one I explained above. But there will be 2 dropdownlist for now. the first one is for the milestone_name and the other one is for the checklist _name. If I select a milestone_name, the second dropdownlist will display only the checklist_name that is related to that milestone_name. The check_code of that corresponding checklist_name will be get and will use for the generation of activity_code that will be placed in a textbox in a pattern like this:"BOO-CC-AC-05". Again, if the user wants to add another record, the system will validate if the activity_code exist and if yes, it will add another 5 to it.

1 solution

Hi,

Your requirement sounds interesting, but i am not sure where are you stuck
using StringBuilder , you can easily achieve this , keep the number part separate as you want to increase it for every new selection , and maintain a history of last asign number and code in different variables.

I am not sure how you are using the Database , but i hope you can do it easily. but still for your reference please see this link

http://msdn.microsoft.com/en-us/library/2839d5h5(v=vs.110).aspx[^]


I hope it solves your problem... please comment if it works for you :)
 
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