Link to home
Start Free TrialLog in
Avatar of chambers777
chambers777

asked on

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

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







 
Avatar of kennethxu
kennethxu

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.
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>
Avatar of chambers777

ASKER

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?
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?
ASKER CERTIFIED SOLUTION
Avatar of kennethxu
kennethxu

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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!
>> 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.
Gotcha.
I truly appreciate the help. This will be what I implement.
Very helpful!
my pleasure and happy coding :)