Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

This is more of a strategic/structural question than an request for code.

Posted on 2003-03-10
10
Medium Priority
?
152 Views
Last Modified: 2010-04-01
This is more of a strategic/structural question than an request for code.
Thanks in advance for the help.

I've got a data driven site where I neet to be able to delete and modify records. The only problem: the data is held in a text file rather than a database.
-Each row in the text file represents a record.
-Each additional record is appended to the end of the file.

I want to set up an application to modify records through form based interface.
1)The user should be presented with a list of current records.
1a)The user chooses a record to edit/delete.
2)The user is presented with a form pre-filled with the records specs which they can change.
3)Submitting the form should make the appropriate changes.

So, in my little head, I can think of at least 2 hairbrained way to do this...
A)Input all info into form (step 1 above) with most info in hidden elements. Clicking on a record brings up a JavaScript subWindow (step 2 above) with info being pulled through JS from the parent window's hidden elements. Submitting the child window changes the hidden elements in the parent window. Submitting the parent window wipes clean the text file and recreates it based ALL the info in the parent's hidden form.

B) Step 1 is created from text file info. Clicking through to step 2 passes some sort of identifying info on to the the next page. The next page searches the text file for the matching record and presents it in a form. Submission of the form replaces ONLY the one line in the file. - Done.

A seems hokey and prone to errors plus, I don't like killing the whole text file and recreating it...
B seems better, but a lot more work...

Any help would be greatly appreciated as I have thought about this one long and hard!
Luke







 
0
Comment
Question by:chambers777
  • 5
  • 5
10 Comments
 
LVL 14

Expert Comment

by:kennethxu
ID: 8108205
1. deleting a record from file is very expensive. most database just put a mark on the record when the record is delete and the space is reused when new record is inserted.

2. you are actaully inventing a tiny database. when it come to concurrency issue, you got a whole world of code to do.

3. if concurrency is not a concern, I don't see problem of recreate the file as long as you don't have much records to handle. but I don't see that you have too much records because you was saying to display them on a page.

4. the record handling form don't have to be that complicated to use javascript. I'll give you an example.
0
 
LVL 14

Expert Comment

by:kennethxu
ID: 8108311
jsp grid:
=============

<%
/**************************************************/
String action=request.getParameter("action");
String[] itemname = request.getParameterValues("itemname");
String[] qty =  request.getParameterValues("qty");
String[] unit = request.getParameterValues("unit");
String[] unitprice = request.getParameterValues("unitprice");
String[] offerprice = request.getParameterValues("offerprice");
String[] chkbox = request.getParameterValues("chkbox");

boolean doDelete = "Delete Selected Item".equals( action );
boolean[] isChecked = null;

if( itemname != null ) isChecked = new boolean[ itemname.length ];
if( doDelete && chkbox != null ) {
   for( int jj = 0; jj<chkbox.length; jj ++ ) {
        int index = Integer.parseInt( chkbox[jj] );
        // out.println( "got " + index );
        isChecked[index] = true;
   }
}

if (action==null) action="";

/*****************************************************/
%>
<center>

<form method="post" name=formnewquote>

<% //if (action.equals("Submit")){ %>
<%  //@include file = "process_nq1.jsp"%>
<% //} %>

<h3>Item List</h3>

<!-- Start List of Item(s) -->
 <table>
   <tr>
     <th><div align="center"></div></td>
     <th>Item Name</td>
     <th>Qty</td>
     <th>Unit</td>
     <th>Unit Price</td>
     <th>Offer Price</td>
   </tr>
   <%
int ii = 0;
if (itemname!=null) {
   for (int k=0;k<isChecked.length;k++) {
      if ( ! ( doDelete && isChecked[k] ) ) {
        %>
   <tr>
     <td> <div align="center">
         <input type="checkbox" name="chkbox" value="<%=ii%>">
       </div></td>
     <td><div align="center">
         <input name="itemname" type=text value="<%=itemname[k]%>" size="17">
       </div></td>
     <td><div align="center">
         <input name="qty" type=text value="<%=qty[k]%>" size="5">
       </div></td>
     <td><div align="center">
       <select name="unit" >
           <option value="kg" <% if ("unit[k]".equals("kg")) out.println("selected");%>>Kg</option>
           <option value="ctn" <% if ("unit[k]".equals("kg")) out.println("selected");%>>Cartons</option>
           <option value="pkt" <% if ("unit[k]".equals("kg")) out.println("selected");%>>Packet</option>
           <option value="tons" <% if ("unit[k]".equals("kg")) out.println("selected");%>>Tons</option>
         </select>
       </div></td>
     <td><div align="center">
         <input name="unitprice" type=text value="<%=unitprice[k]%>" size="8">
       </div></td>
     <td><div align="center">
         <input name="offerprice" type=text value="<%=offerprice[k]%>" size="8">
       </div></td>
   </tr>
   <%
          ii ++;
      }
   } //for
} //if

if( "Add".equals( action )  || itemname == null ) {
%>
   <tr>
     <td><div align="center">
         <input type="checkbox" name="chkbox" value="<%=ii%>">
       </div></td>
     <td><div align="center">
         <input name="itemname" type="text" size="17">
       </div></td>
     <td><div align="center">
         <input name="qty" type="text" size="5">
       </div></td>
     <td><div align="center">
       <select name="unit">
           <option value="kg">Kg</option>
           <option value="ctn">Cartons</option>
           <option value="pkt">Packet</option>
           <option value="tons">Tons</option>
         </select>
       </div></td>
     <td><div align="center">
         <input name="unitprice" type="text" size="8">
       </div></td>
     <td><div align="center">
         <input name="offerprice" type="text" size="8">
       </div></td>
   </tr>
   <% } %>
   <td colspan="6">
       <a href="javascript:checkall('formnewquote','chkbox',true)">All</a>/<a
       href="javascript:checkall('formnewquote','chkbox',false)">None</a>
   <input type=submit value="Delete Selected Item" name="action"></td>
   </tr>
   <tr>
     <td colspan="6"><input type=submit value="Add" name="action" ></td>
   </tr>
 </table>
</form>
</center>
0
 

Author Comment

by:chambers777
ID: 8112289
Thanks so much for your help.
Concurrency is not a huge concern. However, might it be a good idea to create a NEW file on each update.. deleting the old, and rename the new when the process has been sucessfully completed?
-Total records < 200.
-Why should delete be so expensive if I recreate the file? Wouldn't it be the same as update?
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:chambers777
ID: 8112323
Thanks so much for your help.
Concurrency is not a huge concern. However, might it be a good idea to create a NEW file on each update.. deleting the old, and rename the new when the process has been sucessfully completed?
-Total records < 200.
-Why should delete be so expensive if I recreate the file? Wouldn't it be the same as update?
0
 
LVL 14

Accepted Solution

by:
kennethxu earned 240 total points
ID: 8112693
>> deleting the old, and rename the new when the process has been sucessfully completed?
Yes, you are right!

>> -Total records < 200.
that's consider small to me.

>> -Why should delete be so expensive if I recreate the file? Wouldn't it be the same as update?
if you recreate the file, there is no cost on deleting. if you want to delete a line from existing file, that'll be very expensive.

I would go with this:
1. read all record into a jsp grid (my example is just to illustrate the idea, you'll need to customized it).
2. let user manipulate it, after he's done with the changes, sumit the whole thing.
3. based on what user submitted, create a new x.tmp file.
4. delete x.bak file, rename old file to x.bak, and rename x.tmp to x.

0
 

Author Comment

by:chambers777
ID: 8112974
I agree with all you have said.
200 records is quite small, so we should be safe.
I think I have everything I need, but I don't know what a "grid" is...
Only if you have time.
Thanks!
0
 
LVL 14

Expert Comment

by:kennethxu
ID: 8113357
>> I think I have everything I need, but I don't know what a "grid" is...
if you try out the example code I posted earlier, you know what I mean :) I said "grid" because it is like GUI's grid/table control.
0
 

Author Comment

by:chambers777
ID: 8113476
Gotcha.
I truly appreciate the help. This will be what I implement.
0
 

Author Comment

by:chambers777
ID: 8113482
Very helpful!
0
 
LVL 14

Expert Comment

by:kennethxu
ID: 8113758
my pleasure and happy coding :)
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I’m willing to make a bet that your organization stores sensitive data in your Windows File Servers; files and folders that you really don’t want making it into the wrong hands.
Welcome to 2018! Exciting things lie ahead in the world of tech. To start things off, we compiled great member articles on how to stay safe, ways to learn, and much more! Read on to start your new year right.
Integration Management Part 2
The Relationships Diagram is a good way to get an overall view of what a database is keeping track of. It is also where relationships are defined. A relationship specifies how two tables connect to each other. As you build tables in Microsoft Ac…
Suggested Courses
Course of the Month13 days, 3 hours left to enroll

579 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question