private void ReadConfig()
{
string xFile = @"C:\PIH\PIHPharmacy\";
string strFilename = "PIHPharmacy.cfg";
XmlDocument xmlStartupFile = new XmlDocument();
if (!File.Exists(Path.Combine(xFile, strFilename)))
{
//initialize the Xml Text Writer
XmlTextWriter xmlWriter = new XmlTextWriter(Path.Combine(xFile, strFilename), Encoding.UTF8);
xmlWriter.Formatting = Formatting.Indented;
xmlWriter.Indentation = 4;
xmlWriter.WriteStartDocument(true);
xmlWriter.WriteComment("Developed by : Siriroj IT Team ");
xmlWriter.WriteStartElement("PIHMedicineLable"); //Root Element
xmlWriter.WriteStartElement("mServerName");
xmlWriter.WriteString("PIH-INTRANET\\SQLEXPRESS"); //Attribute Value
xmlWriter.WriteEndElement(); //End of dbName Element
xmlWriter.WriteStartElement("mDatabase");
xmlWriter.WriteString("PIHPharmacyDBTest"); //Attribute Value
xmlWriter.WriteEndElement(); //End of dbName Element
xmlWriter.WriteStartElement("mUser");
xmlWriter.WriteString("sa");
xmlWriter.WriteEndElement();
xmlWriter.WriteStartElement("mPassword");
xmlWriter.WriteString("siriroJ");
xmlWriter.WriteEndElement();
xmlWriter.WriteStartElement("extServerName");
xmlWriter.WriteString("192.168.0.121"); //Attribute Value
xmlWriter.WriteEndElement(); //End of dbName Element
xmlWriter.WriteStartElement("extDatabase");
xmlWriter.WriteString("MAIN"); //Attribute Value
xmlWriter.WriteEndElement(); //End of dbName Element
xmlWriter.WriteStartElement("extUser");
xmlWriter.WriteString("sa");
xmlWriter.WriteEndElement();
xmlWriter.WriteStartElement("extPassword");
xmlWriter.WriteString("ub!fighting#123");
xmlWriter.WriteEndElement();
xmlWriter.WriteStartElement("reportPath");
xmlWriter.WriteString(@"S:\Report\Pharmacy\");
xmlWriter.WriteEndElement();
xmlWriter.WriteStartElement("printerChecmoLabel");
xmlWriter.WriteString(@"\\IPAddress\PrinterName");
xmlWriter.WriteEndElement();
xmlWriter.WriteEndDocument();
xmlWriter.Flush();
xmlWriter.Close();
}
XmlTextReader reader = new XmlTextReader("PIHPharmacy.cfg");
while (reader.Read())
{
if (reader.NodeType == XmlNodeType.Element)
{
if (reader.Name == "mServerName")
{
generalClass.xMainServer = reader.ReadElementContentAsString();
}
if (reader.Name == "mDatabase")
{
generalClass.xMainDBName = reader.ReadElementContentAsString();
}
if (reader.Name == "mUser")
{
generalClass.xMainUserId = reader.ReadElementContentAsString();
}
if (reader.Name == "mPassword")
{
generalClass.xMainPassword = reader.ReadElementContentAsString();
}
if (reader.Name == "extServerName")
{
generalClass.xExtServer = reader.ReadElementContentAsString();
}
if (reader.Name == "extDatabase")
{
generalClass.xExtDBName = reader.ReadElementContentAsString();
}
if (reader.Name == "extUser")
{
generalClass.xExtUserId = reader.ReadElementContentAsString();
}
if (reader.Name == "extPassword")
{
generalClass.xExtPassword = reader.ReadElementContentAsString();
}
if (reader.Name == "reportPath")
{
generalClass.xReportLocation = reader.ReadElementContentAsString();
}
if (reader.Name == "printerChecmoLabel")
{
generalClass.xPrinterChemoLabel = reader.ReadElementContentAsString();
}
}
}
reader.Close();
}
No comments:
Post a Comment