Click here to Skip to main content
15,896,557 members
Home / Discussions / C#
   

C#

 
GeneralRe: Creating web aplication NOT via IIS console Pin
Heath Stewart15-Jun-04 5:03
protectorHeath Stewart15-Jun-04 5:03 
GeneralRe: Creating web aplication NOT via IIS console Pin
michalJ15-Jun-04 8:09
michalJ15-Jun-04 8:09 
GeneralMessages of Child applications Pin
T i T i15-Jun-04 2:13
T i T i15-Jun-04 2:13 
GeneralRe: Messages of Child applications Pin
Dave Kreskowiak15-Jun-04 3:01
mveDave Kreskowiak15-Jun-04 3:01 
GeneralRe: Messages of Child applications Pin
Heath Stewart15-Jun-04 3:42
protectorHeath Stewart15-Jun-04 3:42 
Generali want toserialize DataTable typed filed into Xml Pin
Member 114126615-Jun-04 0:53
Member 114126615-Jun-04 0:53 
GeneralRe: i want toserialize DataTable typed filed into Xml Pin
Dave Kreskowiak15-Jun-04 3:05
mveDave Kreskowiak15-Jun-04 3:05 
GeneralRe: i want toserialize DataTable typed filed into Xml Pin
Member 114126616-Jun-04 21:06
Member 114126616-Jun-04 21:06 
using System;
using System.Xml;
using System.Xml.Serialization;
using System.IO;
using System.Collections;
using System.Data ;

/* The XmlRootAttribute allows you to set an alternate name
(PurchaseOrder) of the XML element, the element namespace; by
default, the XmlSerializer uses the class name. The attribute
also allows you to set the XML namespace for the element. Lastly,
the attribute sets the IsNullable property, which specifies whether
the xsi:null attribute appears if the class instance is set to
a null reference. */
[XmlRootAttribute("PurchaseOrder", Namespace="http://www.cpandl.com",
IsNullable = false)]
public class PurchaseOrder
{
public Address ShipTo;
public string OrderDate;
/* The XmlArrayAttribute changes the XML element name
from the default of "OrderedItems" to "Items". */
[XmlArrayAttribute("Items")]
public OrderedItem[] OrderedItems;
public decimal SubTotal;
public decimal ShipCost;
public decimal TotalCost;
}

public class Address
{
/* The XmlAttribute instructs the XmlSerializer to serialize the Name
field as an XML attribute instead of an XML element (the default
behavior). */
[XmlAttribute]
public string Name;
public string Line1;

/* Setting the IsNullable property to false instructs the
XmlSerializer that the XML attribute will not appear if
the City field is set to a null reference. */
[XmlElementAttribute(IsNullable = false)]
public string City;
public string State;
public string Zip;
}

public class OrderedItem
{
public string ItemName;
public string Description;
public decimal UnitPrice;
public int Quantity;
public decimal LineTotal;

/* Calculate is a custom method that calculates the price per item,
and stores the value in a field. */
public void Calculate()
{
LineTotal = UnitPrice * Quantity;
}
}

public class Test
{
public static void Main()
{
// Read and write purchase orders.
Test t = new Test();
t.CreatePO("po.xml");
t.ReadPO("po.xml");
t.CreatCol() ;
}

private void CreatCol()
{
XmlSerializer serializer =
new XmlSerializer(typeof(MyCoulumnClollectionClass));
TextWriter writer = new StreamWriter("Hadi.xml");
MyCoulumnClollectionClass d=new MyCoulumnClollectionClass() ;
SCol s1=new SCol() ;
s1.FieldName ="stud_no" ;
s1.DisplayName="stud_displayname";
d.Add(s1);

s1=new SCol() ;
s1.FieldName="FN2" ;
s1.DisplayName="DN2" ;
s1.AAAA="====" ;
d.Add(s1) ;
serializer.Serialize(writer, d);
writer.Close();
}
private void CreatePO(string filename)
{
// Create an instance of the XmlSerializer class;
// specify the type of object to serialize.
XmlSerializer serializer =
new XmlSerializer(typeof(PurchaseOrder));
TextWriter writer = new StreamWriter(filename);
PurchaseOrder po=new PurchaseOrder();

// Create an address to ship and bill to.
Address billAddress = new Address();
billAddress.Name = "Teresa Atkinson";
billAddress.Line1 = "1 Main St.";
billAddress.City = "AnyTown";
billAddress.State = "WA";
billAddress.Zip = "00000";
// Set ShipTo and BillTo to the same addressee.
po.ShipTo = billAddress;
po.OrderDate = System.DateTime.Now.ToLongDateString();

// Create an OrderedItem object.
OrderedItem i1 = new OrderedItem();
i1.ItemName = "Widget S";
i1.Description = "Small widget";
i1.UnitPrice = (decimal) 5.23;
i1.Quantity = 3;
i1.Calculate();

// Insert the item into the array.
OrderedItem [] items = {i1};
po.OrderedItems = items;
// Calculate the total cost.
decimal subTotal = new decimal();
foreach(OrderedItem oi in items)
{
subTotal += oi.LineTotal;
}
po.SubTotal = subTotal;
po.ShipCost = (decimal) 12.51;
po.TotalCost = po.SubTotal + po.ShipCost;
// Serialize the purchase order, and close the TextWriter.
serializer.Serialize(writer, po);
writer.Close();
}

protected void ReadPO(string filename)
{
// Create an instance of the XmlSerializer class;
// specify the type of object to be deserialized.
XmlSerializer serializer = new XmlSerializer(typeof(PurchaseOrder));
/* If the XML document has been altered with unknown
nodes or attributes, handle them with the
UnknownNode and UnknownAttribute events.*/
serializer.UnknownNode+= new
XmlNodeEventHandler(serializer_UnknownNode);
serializer.UnknownAttribute+= new
XmlAttributeEventHandler(serializer_UnknownAttribute);

// A FileStream is needed to read the XML document.
FileStream fs = new FileStream(filename, FileMode.Open);
// Declare an object variable of the type to be deserialized.
PurchaseOrder po;
/* Use the Deserialize method to restore the object's state with
data from the XML document. */
po = (PurchaseOrder) serializer.Deserialize(fs);
// Read the order date.
Console.WriteLine ("OrderDate: " + po.OrderDate);

// Read the shipping address.
Address shipTo = po.ShipTo;
ReadAddress(shipTo, "Ship To:");
// Read the list of ordered items.
OrderedItem [] items = po.OrderedItems;
Console.WriteLine("Items to be shipped:");
foreach(OrderedItem oi in items)
{
Console.WriteLine("\t"+
oi.ItemName + "\t" +
oi.Description + "\t" +
oi.UnitPrice + "\t" +
oi.Quantity + "\t" +
oi.LineTotal);
}
// Read the subtotal, shipping cost, and total cost.
Console.WriteLine("\t\t\t\t\t Subtotal\t" + po.SubTotal);
Console.WriteLine("\t\t\t\t\t Shipping\t" + po.ShipCost);
Console.WriteLine("\t\t\t\t\t Total\t\t" + po.TotalCost);
}

protected void ReadAddress(Address a, string label)
{
// Read the fields of the Address object.
Console.WriteLine(label);
Console.WriteLine("\t"+ a.Name );
Console.WriteLine("\t" + a.Line1);
Console.WriteLine("\t" + a.City);
Console.WriteLine("\t" + a.State);
Console.WriteLine("\t" + a.Zip );
Console.WriteLine();
}

protected void serializer_UnknownNode
(object sender, XmlNodeEventArgs e)
{
Console.WriteLine("Unknown Node:" + e.Name + "\t" + e.Text);
}

protected void serializer_UnknownAttribute
(object sender, XmlAttributeEventArgs e)
{
System.Xml.XmlAttribute attr = e.Attr;
Console.WriteLine("Unknown attribute " +
attr.Name + "='" + attr.Value + "'");
}
}



public class SCol
{
// public string FiledName
// {
// get
// {
// return m_fieldName ;
// }
// }
// public void SetFiledName(string f)
// {
// m_fieldName=f ;
// }
[XmlElement(ElementName = "TaxRate")]
public string FieldName
{
get
{
return m_ ;
}
set
{
m_=value ;
}
}
public string DisplayName ;
// ***** in this property , xmlSerializer submit error ***
public DataTable m_columnTable ;
private string m_ ;
[XmlElement]
public string AAAA ;
}
public class MyCoulumnClollectionClass : CollectionBase
{
//[XmlElement(ElementName = "Collection")]
//[XmlArrayAttribute("Items")]
public SCol this[ int index ]
{
get
{
return( (SCol) List[index] );
}
set
{
List[index] = value;
}
}
public int Add( SCol value )
{
return( List.Add( value ) );
}

public int IndexOf( SCol value )
{
return( List.IndexOf( value ) );
}

public void Insert( int index, SCol value )
{
List.Insert( index, value );
}

public void Remove( SCol value )
{
List.Remove( value );
}

public bool Contains( SCol value )
{
// If value is not of type Int16, this will return false.
return( List.Contains( value ) );
}
}
Generalsaving collection automaticaly into form`s resource. Pin
Member 114126615-Jun-04 0:43
Member 114126615-Jun-04 0:43 
GeneralRe: saving collection automaticaly into form`s resource. Pin
Heath Stewart15-Jun-04 3:39
protectorHeath Stewart15-Jun-04 3:39 
GeneralRe: saving collection automaticaly into form`s resource. Pin
Member 114126616-Jun-04 20:56
Member 114126616-Jun-04 20:56 
QuestionProgram to generate UML-diagram? MS Visio? Pin
anderslundsgard15-Jun-04 0:02
anderslundsgard15-Jun-04 0:02 
AnswerRe: Program to generate UML-diagram? MS Visio? Pin
Heath Stewart15-Jun-04 3:33
protectorHeath Stewart15-Jun-04 3:33 
GeneralRe: Program to generate UML-diagram? MS Visio? Pin
anderslundsgard15-Jun-04 3:50
anderslundsgard15-Jun-04 3:50 
GeneralRe: Program to generate UML-diagram? MS Visio? Pin
Heath Stewart15-Jun-04 4:01
protectorHeath Stewart15-Jun-04 4:01 
Generalvariable columns count in datagrid Pin
morfo14-Jun-04 23:51
morfo14-Jun-04 23:51 
QuestionAddMetafileComment () ? Pin
sachinkalse14-Jun-04 23:23
sachinkalse14-Jun-04 23:23 
AnswerRe: AddMetafileComment () ? Pin
Colin Angus Mackay14-Jun-04 23:38
Colin Angus Mackay14-Jun-04 23:38 
GeneralRe: AddMetafileComment () ? Pin
sachinkalse14-Jun-04 23:48
sachinkalse14-Jun-04 23:48 
GeneralRe: AddMetafileComment () ? Pin
Heath Stewart15-Jun-04 3:31
protectorHeath Stewart15-Jun-04 3:31 
GeneralRe: AddMetafileComment () ? Pin
Dave Kreskowiak15-Jun-04 5:03
mveDave Kreskowiak15-Jun-04 5:03 
GeneralRe: AddMetafileComment () ? Pin
sachinkalse15-Jun-04 15:08
sachinkalse15-Jun-04 15:08 
GeneralRe: AddMetafileComment () ? Pin
Dave Kreskowiak15-Jun-04 15:28
mveDave Kreskowiak15-Jun-04 15:28 
GeneralGet trouble when binding data to combobox Pin
uyenchi14-Jun-04 23:19
uyenchi14-Jun-04 23:19 
GeneralRe: Get trouble when binding data to combobox Pin
dabuskol14-Jun-04 23:49
dabuskol14-Jun-04 23:49 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.