MessageBox.Show(CommonUtility.GetMessage(Messages.FromDate), Program.MODULE_NAME, MessageBoxButtons.OK, MessageBoxIcon.Stop);
<Message>
<Name>ReportTitle</Name>
<Value> Click to edit analysis title</Value>
</Message>
using System;
using System.Data;
using System.Windows.Forms;
using System.Xml;
using System.Collections;
namespace OceanManager.ANR.ReportDesignerUserInterface
{
public enum Messages
{
EmptySource,
Nodata,
UserOption,
ReportTitle,
FromDate,
ToDate,
ConfirmationMessage
}
public class CommonUtility
{
public static string DrpdwnSelectedValue = string.Empty;
/// <summary>
/// Fetch the message from the message file
/// </summary>
/// <param name="messageId">Message ID requested for data</param>
/// <returns></returns>
public static string GetMessage(Messages messageId)
{
string Path = string.Empty;
DataSet dsMessages = null;
try
{
Path = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
Path = System.IO.Path.Combine(Path, "Messages.xml");
dsMessages = new DataSet();
dsMessages.ReadXml(Path);
return dsMessages.Tables[0].Select("Name = '" + messageId.ToString() + "'")[0]["value"].ToString();
}
catch (Exception) //return no message in case not found
{
throw;
}
}
/// <summary>
/// return the xmlDocument
/// </summary>
/// <returns></returns>
public XmlDocument GetXmlDocument()
{
XmlDocument xmlDocument = new XmlDocument();
//Set the xml file path.
string xmlfilePath = Application.StartupPath.ToString();
xmlfilePath = xmlfilePath + "\\ReportCategories.xml";
if (System.IO.File.Exists(xmlfilePath))
{
xmlDocument.Load(xmlfilePath);
}
return xmlDocument;
}
/// <summary>
/// Update the Ip addressed in Report Categories xml file
/// </summary>
/// <param name="arr"></param>
public void UpdateReportCategories(object[] arr)
{
try
{
string xmlfilePath = Application.StartupPath.ToString() + "\\ReportCategories.xml";
// GetXmlDocument Returns the XmlDocument
XmlDocument xmlDocument = GetXmlDocument();
XmlNode rootNode;
ArrayList arrCon = new ArrayList();
bool IsUpdated = false;
int i;
string IPAddress = string.Empty;
string OldIPAddress = string.Empty;
string[] SplitCon = null;
string[] str = null;
string DataSource = string.Empty;
string Strcon = string.Empty;
string[] str1 = null;
string OtherAttr = string.Empty;
string[] KeyValue = null;
if (xmlDocument != null)
{
rootNode = xmlDocument.DocumentElement.LastChild;
//Last child node would be server locations.
//Check for the child nodes and load them into the navigation bar.
if (rootNode.Name != null && string.Compare(rootNode.Name, "ServerLocation", true) == 0)
{
foreach (var arrIP in arr)
{
IPAddress = string.Empty;
KeyValue = arrIP.ToString().Split(new string[] { "||" }, StringSplitOptions.RemoveEmptyEntries);
IPAddress = KeyValue[1].ToString();
foreach (XmlNode node in rootNode.ChildNodes)
{
if (node.InnerText.ToLower().Trim() == KeyValue[0].ToString().ToLower().Trim())
{
SplitCon = node.Attributes["constring"].Value.Split(';');
str = node.Attributes["constring"].Value.Split(';')[0].Split('=');
DataSource = string.Empty;
Strcon = string.Empty;
if (str[1].ToString().Contains("\\"))
{
str1 = str[1].Split('\\');
OldIPAddress = str1[0].ToString();
}
else
{
OldIPAddress = str[1].ToString();
}
// Checks if the IsUpdated is true or false.
// If the IsUpdated is true then the user want to update the values
// and if the IsUpdated is false then it will ask from the user whether to update the values or not
if (!IsUpdated)
{
if (OldIPAddress != IPAddress)
{
if (MessageBox.Show(CommonUtility.GetMessage(Messages.UserOption), Program.MODULE_NAME, MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) == DialogResult.OK)
{
IsUpdated = true;
}
else
{
break;
}
}
}
Strcon = node.Attributes["constring"].Value.ToString();
Strcon = Strcon.Replace(str1[0].ToString(), IPAddress);
node.Attributes["constring"].Value = Strcon;
arrCon.Add(KeyValue[0].ToString().ToLower().Trim() + "||" + Strcon);
}
}
}
}
xmlDocument.Save(xmlfilePath);
// The selected Server connection string is passed to the method UpdateAppConfig
// and it update the Connection string in the config file
// to make sure, next time the connection will be established with the database.
string[] Ips = null;
string connectionstr = string.Empty;
frmLogin objfrmLogin = new frmLogin();
foreach (var conStr in arrCon)
{
Ips = conStr.ToString().Split(new string[] { "||" }, StringSplitOptions.RemoveEmptyEntries);
if (Ips[0].ToString() == DrpdwnSelectedValue.ToString().ToLower().Trim())
{
connectionstr = Ips[1].ToString().Trim();
objfrmLogin.UpdateAppConfig(connectionstr);
break;
}
}
// sets the objects to null
objfrmLogin = null;
xmlDocument = null;
arrCon = null;
}
}
catch (Exception ex)
{
Utility.Log.WriteExceptions(ex, OceanManager.ANR.Utility.ExceptionPolicy.SystemExceptionsToLogFile, true, "");
}
}
}
}
No comments:
Post a Comment