vb.net - serialization in c# calling methods -
this code book "network programming in .net using c# , vb.net"
what dont understand how _issuancedate,_deliverydate,_invoicedate,_paymentdate being set. in code there no explicit setting of value , yet xml file contains dates of all, , how purchaseorder class methods getting called ?
using system; using system.collections.generic; using system.componentmodel; using system.data; using system.drawing; using system.linq; using system.text; using system.windows.forms; using system.runtime.serialization.formatters.soap; using system.runtime.serialization.formatters.binary; using system.io; namespace serialization { public partial class form1 : form { public form1() { initializecomponent(); } private void form1_load(object sender, eventargs e) { } private void button1_click(object sender, eventargs e) { company vendor = new company(); company buyer = new company(); lineitem goods = new lineitem(); purchaseorder po = new purchaseorder(); vendor.name = "acme"; buyer.name = "wiley e coyete"; goods.description = "anti road runner gun"; goods.quantity = 1; goods.cost = 599.99; po.items = new lineitem[1]; po.items[0] = goods; po.buyer = buyer; po.vendor = vendor; soapformatter sf = new soapformatter(); filestream fs = file.create("c:\\users\\s ghosh\\desktop\\po.xml"); sf.serialize(fs, po); fs.close(); } private void button2_click(object sender, eventargs e) { soapformatter sf = new soapformatter(); filestream fs = file.openread("c:\\users\\s ghosh\\desktop\\po.xml"); purchaseorder po = (purchaseorder)sf.deserialize(fs); fs.close(); messagebox.show("customer " + po.buyer.name); po.show(); } } public enum purchaseorderstates { delivered, issued, invoiced, paid } [serializable()] public class company { public string name; public string address; public string phone; } [serializable()] public class lineitem { public string description; public int quantity; public double cost; } [serializable()] public class purchaseorder { private purchaseorderstates _purchaseorderstatus; private datetime _issuancedate; private datetime _deliverydate; private datetime _invoicedate; private datetime _paymentdate; public company buyer; public company vendor; public company reference; public lineitem[] items; public purchaseorder() { _purchaseorderstatus = purchaseorderstates.issued; _issuancedate = datetime.now; } public void recorddelivery() { if (_purchaseorderstatus == purchaseorderstates.issued) { _purchaseorderstatus = purchaseorderstates.delivered; _deliverydate = datetime.now; } } public void recordinvoice() { if (_purchaseorderstatus == purchaseorderstates.delivered) { _purchaseorderstatus = purchaseorderstates.invoiced; _invoicedate = datetime.now; } } public void recordpayment() { if (_purchaseorderstatus == purchaseorderstates.invoiced) { _purchaseorderstatus = purchaseorderstates.paid; _issuancedate = datetime.now; } } }
}
_issuancedate set in purchaseorder constructor
_issuancedate = datetime.now;
all other dates go default values.
Comments
Post a Comment