XML creation error



I am creating an application in vs 2010 using c# and I am having following error :


The first function (funCheckStatus) rotates in loop and whenever I apply debug point anywhere then all the XML files equal to loop number gets created.But when I remove the debug point , then only one file gets created and all other XMl files go missing.


The code is as follows :



//Function To check status and create xml files according to the conditions

public void funCheckStatus(int iExecCode)
{
DataTable dtStatus = new DataTable();
int iStatusCode;
string strQry = @"Select ExecStatusCode from dbo.tExecutionReport where dbo.tExecutionReport.ExecRptID = " +iExecCode;
objDal.funcSetDBConnection(strConn);
dtStatus = objDal.funcSelect(strQry,"TAB").Tables[0];
iStatusCode = Convert.ToInt32(dtStatus.Rows[0]["ExecStatusCode"].ToString());
if (iStatusCode == 4)
{
objXMLCreator.CreateOCRExecutionXML(iExecCode);
}
}

//Function to create xml file according to condition
public void CreateOCRExecutionXML(int iOCRExecCode)
{
try
{
objOCRXMLqueue = new OCRXMLPLCQueuor();
objOCRXMLqueue.funOCRXMLQueueOpen();
OCRExcutionXMLCreator(iOCRExecCode);//this function gather information and assign to xml data properties to create child nodes
objOCRXMLqueue.funOCRAddXMLToQueue();
objOCRXMLqueue.funOCRXMLQueueClose();
}
catch (Exception ex)
{
Console.WriteLine(ex.Message.ToString());
throw;
}
}

//Function to crate xml doc declaration along with reading save xml path
public void funOCRXMLQueueOpen()
{
int iXMLRouter = 0;
int iConnectionRouter = 0;
//Create the XML declaration and append it to the XML document
doc = new XmlDocument();
XmlDeclaration dec = doc.CreateXmlDeclaration("1.0", null, null);
doc.AppendChild(dec);//create the root element
root = doc.CreateElement(cnstStrXMLDtls);
doc.AppendChild(root);

StreamReader strmReader = new StreamReader("XXX.ini");
string strLine = "";
while (strLine != null)
{
strLine = strmReader.ReadLine();
if (strLine != null)
{
if (iXMLRouter > 0)
{
if (strLine.Trim() != "")
{
if (lstFolderPath.Count != 3)
{
string[] strSplit = strLine.Split(new string[] { "=" }, StringSplitOptions.None);
lstFolderPath.Add(strSplit[1]);
}
}
else
iXMLRouter = 0;
}
if (strLine == "[XML]")
iXMLRouter = 1;
}
}
strmReader.Close();
}


//Function to add child node data to xml file.
public void funOCRAddXMLToQueue()
{
XML = doc.CreateElement(cnstStrXML);
funOCRAddXMLField(clsGlobalConst.cnstStrXMLCode, this.XMLCode.ToString());
funOCRAddXMLField(clsGlobalConst.cnstStrTrayEntryCode, this.TrayEntryCode.ToString());
funOCRAddXMLField(clsGlobalConst.cnstStrOrderCode, this.OrderCode.ToString());
funOCRAddXMLField(clsGlobalConst.cnstStrAssetCode, this.AssetCode.ToString());
funOCRAddXMLField(clsGlobalConst.cnstStrScripCode, this.ScripCode.ToString());
funOCRAddXMLField(clsGlobalConst.cnstStrTransType, this.TransType.ToString());
funOCRAddXMLField(clsGlobalConst.cnstStrQtyPlaced, this.QtyPlaced.ToString());
funOCRAddXMLField(clsGlobalConst.cnstStrQtySliced, this.QtySliced.ToString());
funOCRAddXMLField(clsGlobalConst.cnstStrIsSliceOnSuccess, this.IsSliceOnSuccess.ToString());
funOCRAddXMLField(clsGlobalConst.cnstStrQtyOpen, this.QtyOpen.ToString());
funOCRAddXMLField(clsGlobalConst.cnstStrQtyRemaining, this.TotalOrderQty.ToString());
funOCRAddXMLField(clsGlobalConst.cnstStrPriceLimit, this.PriceLimit.ToString());
funOCRAddXMLField(clsGlobalConst.cnstStrStopLimit, this.StopLimit.ToString());
funOCRAddXMLField(clsGlobalConst.cnstStrOrderType, this.OrderType.ToString());
funOCRAddXMLField(clsGlobalConst.cnstStrPlaceType, this.PlaceType.ToString());
funOCRAddXMLField(clsGlobalConst.cnstStrOrderStatus, this.OrderStatus.ToString());
funOCRAddXMLField(clsGlobalConst.cnstStrTgtXMLCode, this.TgtXMLCode.ToString());
funOCRAddXMLField(clsGlobalConst.cnstStrCreator, this.Creator.ToString());
funOCRAddXMLField(clsGlobalConst.cnstStrTrader, this.Trader.ToString());
funOCRAddXMLField(clsGlobalConst.cnstStrBroker, this.Broker.ToString());
funOCRAddXMLField(clsGlobalConst.cnstStrBrokerName, this.BrokerName.ToString());
funOCRAddXMLField(clsGlobalConst.cnstStrCreatedDateTime, this.CreatedDateTime.ToString());
funOCRAddXMLField(clsGlobalConst.cnstStrTradeDate, this.TradeDate.ToString());
funOCRAddXMLField(clsGlobalConst.cnstStrSettlementDate, this.SettlementDate.ToString());
funOCRAddXMLField(clsGlobalConst.cnstStrStrategy, this.Strategy.ToString());
funOCRAddXMLField(clsGlobalConst.cnstStrIsManual, this.IsManual.ToString());
funOCRAddXMLField(clsGlobalConst.cnstStrMktCode, this.MktCode.ToString());
funOCRAddXMLField(clsGlobalConst.cnstStrStartTime, this.StartTime.ToString());
funOCRAddXMLField(clsGlobalConst.cnstStrEndTime, this.EndTime.ToString());
funOCRAddXMLField(clsGlobalConst.cnstStrStatusCode, this.StatusCode.ToString());
funOCRAddXMLField(clsGlobalConst.cnstStrCreatedBy, this.CreatedBy.ToString());
funOCRAddXMLField(clsGlobalConst.cnstStrCreatedDateTime, this.CreatedDateTime.ToString());

}
public void funOCRAddXMLField(string strAttribute, string strValue)
{
XmlElement PLCElement = doc.CreateElement(strAttribute);
PLCElement.InnerText = strValue.Trim();
XML.AppendChild(PLCElement);
root.AppendChild(XML);
}

public void funOCRXMLQueueClose()
{
StringBuilder XMLFileName = new StringBuilder();
XMLFileName.Append(cnstStrPLC);
XMLFileName.Append(LoggedUser.ToUpper());
XMLFileName.Append(DateTime.Now.Year.ToString() + "_");
XMLFileName.Append(DateTime.Now.Month.ToString() + "_");
XMLFileName.Append(DateTime.Now.Day.ToString() + "_");
XMLFileName.Append(DateTime.Now.Minute.ToString() + "_");
XMLFileName.Append(DateTime.Now.Second.ToString() + "_");

if (lstFolderPath.Count > 0)
{
DirectoryInfo DIR = new DirectoryInfo(lstFolderPath[0].ToString());
if (!DIR.Exists)
DIR.Create();
doc.Save(DIR.FullName + "/" + XMLFileName.ToString() + ".xml");
}

}

No comments:

Post a Comment