file stream

hey guys i have a text file which stores value, i need to get and set values from the text file.

i have given this method that i have to use but i do not know how to create a class to hold the values. please help me code for this method

OrderData data = ReadData(steam);

i have the stream of the text file but do not know how to go about with the order data class. i am using c# coding

//Tries to open the user data, as shown in ORDER_ID.TXT file.
//OrderData refers to a struct or class that holds order data
OrderData data = ReadData(steam);

Open in new window


this is my text file

FIRST_NAME  = Mike
MIDDLE_NAME  = Johnson
LAST_NAME  = Kofman
CUSTOMER_ID =  14112
PRODUCT_DETAILS = MP_A4 Portrait
PRICE_LEFT_DECIMAL_POINT = 1189
PRICE_RIGHT_DECIMAL_POINT =39
DATE_TIME = 19145504122008
STREET =157th St.
DISTRICT = NY
CITY =New York
ZIP = 75443
STATE = NY
COUNTRY = America 
PHONE =  054533526
CELLULAR = 054533526
EMAIL = Kofman_Mike@hotmail.com
ATTEMPT_TO_UPLOAD =0
COVER_MATERIAL = Dark_Cover
COVER_COLOR = Gray
PAGE_COUNT = 40
COPIES = 1
COMMENT = 
FINISHING = 
COLOR_CORRECT = 0
IMAGE_COUNT = 7
CUSTOMER_TITLE = Mr.
CUSTOMER_BIRTHDATE = 00000023111972
USED_PRICING_FORMAT = 1
DECIMAL_SEPARATOR = .
BASIC_PAGES_PRICE = 454.00
ADDITIONAL_PAGES_PRICE = 155.00
ALBUM_BLOCK_PRICE = 564.00
COVER_PRICE = 200.00
COLOR_CORRECTION_PRICE = .00
FINISHING_PRICE = .00
ALBUM_PRICE = 1074.00
CD_PRICE = .00
ORDER_PRICE = 1074.00
TAX_NAME_1 = VAT
TAX_VALUE_1 = 107.40
TAX_NAME_2 = Shipment Tax
TAX_VALUE_2 = 2.99
ORDER_PRICE_INCLUDING_TAXES =1184.39
SHIPMENT_PRICE = 5.00
TOTAL_PRICE = 1189.39
DISCOUNT = .00
PAYED_AMOUNT = .00

Open in new window

JCWEBHOSTAsked:
Who is Participating?
 
Jaime OlivaresConnect With a Mentor Software ArchitectCommented:
OK, so you need a class like this:

public class OrderData : Dictionary<string, string>
{
   // some logic here
}

Then your ReadData method would be like:

public OrderData(Stream stream)
{
     string line;
     string[] elements;
     OrderData data = new OrderData();

      using (StreamReader sr = new StreamReader(stream))
      {
                while (sr.Peek() >= 0)
                {
                    line = sr.ReadLine();
                    elements = line.Split('=');
                    if (elements.Length == 2)
                          data[elements[0].Trim()] = elements[1].Trim();
                }
      }

      return data;
}
0
 
Jaime OlivaresSoftware ArchitectCommented:
I don't think .txt is the best way to handle data. The .net way is to use an .xml file. There are lots of facilities for read/write xml files. In this case, a Xml Serializer will do the job in few lines:

To write:
XmlSerializer ser = new XmlSerializer(typeof(OrderData));
TextWriter writer = new StreamWriter(xml_filename);
ser.Serialize(writer, the_OrderData_object);
writer.Close();

Open in new window

To read:
XmlSerializer ser = new XmlSerializer(typeof(OrderData));
Stream reader = new FileStream(xml_filename,FileMode.Open);
OrderData data = (OrderData)ser.Deserialize(reader);

Open in new window

0
 
JCWEBHOSTAuthor Commented:
this program using text file so i need it to use it, sorry.
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
Jaime OlivaresSoftware ArchitectCommented:
It will be more tricky. How is declared your OrderData class ?
0
 
JCWEBHOSTAuthor Commented:
i do not know i have given a intergation document from a company

Server side example class:
This example is a theoretical C# class, which demonstrates the order of methods. This class does not replace a sample code.
public class ServerSide
{
// This method is loaded when end-user enters the web payment page.
// We are assuming that the orderId is as appears in the brackets.
//
// Example: if a user entered
// https://MyCompany.com/checkout.aspx?id=424001
// then OnRecievedRequest(424001) will be triggered.
void OnRecievedRequest(string orderId)
{
//Retrieves file names as they should exist in the FTP folders
string payment_fileName =
GetPaymentFileNameFromOrderId(orderId);
string payment_result_fileName =
GetPaymentResultFileNameFromOrderId(orderId);
//Tries to open the ORDER_ID.TXT file
FileStream stream = OpenFile(payment_fileName);
if (stream == null)
{
RunErrorPage();
return;
}
//Tries to open the user data, as shown in ORDER_ID.TXT file.
//OrderData refers to a struct or class that holds order data
OrderData data = ReadData(steam);
if (data == null)
{
RunErrorPage();
return;
}
//Runs the payment page.
//This method should block the thread untill user has
//finished payment or aborted
bool hasPayed = RunPaymentPage(data);
//Sets the PAYED=1 / PAYED=0 depending on hasPayed, then writes
//the file to the Payment result FTP folder
SetConfirmation(stream, hasPayed);
//Saves the file onto the FTP confirmation.
//This side is critical since The user allready payed
if (SaveFile(stream, payment_result_fileName) == false)
{
RunErrorPage();
return;
}
// Runs a finished page.
// This page can be "Page has expired" or any web page
RunFinishedPage();
}

Open in new window

0
 
Jaime OlivaresSoftware ArchitectCommented:
Ok, it seems that you have to implement OrderData and ReadData by yourself.
You have two choices:
- OrderData to contain a dictionary with key and value, this will be simpler to implement, but will look a bit messy when you try to use a field (something like ReadData["fieldname"]
- OrderData to have fields with exact the same names as in the file, although it will be easier to handle the fields by name, it will present some maintenance problems if the file structure changes.
What do you prefer?
0
 
Alan WarrenApplications DeveloperCommented:
0
 
JCWEBHOSTAuthor Commented:
OrderData to contain a dictionary
0
 
Vee_ModCommented:
I've requested that this question be deleted for the following reason:

JCWEBHOST,<br />It appears as though you have posted duplicate questions.<br /><br />All Experts are advised to post their suggestions here:<br /><a href="http://www.experts-exchange.com/Q_27852027.html">http://www.experts-exchange.com/Q_27852027.html</a><br /><br />This version of the question is being deleted.<br /><br />Vee_Mod<br />Experts Exchange Moderator<br />
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.