TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Gunjan Manan
NA
46
9.1k
Xml file Content
Jun 18 2015 4:33 AM
Hi
I have an XML file like this:
<?xml version="1.0" encoding="UTF-8"?>
-<info unixTimeStamp="1432543721">
<idpr>1</idpr>
<kind dateTimeOperations="1432543721" diffmode="0">A</kind>-
<machine><id>9081</id>
<model>CM18B</model>
</machine><user idc="MP001"/>-<setnotes id="0">
-<bag seal="000000000006" status="0">
<note set="5">113</note>
<note set="10">40</note><note set="20">35</note><note set="50">169</note><note set="100">83</note><note set="200">0</note><note set="500">0</note></bag></setnotes><sec>2B466F343B0EE610E1982182B2ABE56845AA8DD089A5D9193E4CF7DDABA658709F494ED35B4641A98407AEF346E3FC2D2825A57D48F84B66E1A6455E590367CF76DEDB6602F360EF5CA6090B98F05D8341F7F2AD26F159218C8A208F5A1514418E00FE57496222354E8D5090BA14AB86713F35C1A2878E2B62573588EAFA9C884416FAFF0F099B7B8015603F68FF0F49778AECE2175B73BAAD5004DCD229706CDC6DF65A59692654099ED72AB2EDA847D803C2DE60194DFEC9E06A6A9816B0102A6BC845B0F8BC2C3A1EE234D88B1151C7D23E3F3A0CE1242845780CBC7CA914CC0458E5D4AA6169118B140AAB8A9E646F337C21CF1CDE6FDA6E85CD429ECCFE</sec></info>
and i want to fetch this file in my website that has a following code how can i do it
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.IO;
using System.Security.Permissions;
using Microsoft.Win32;
using System.Threading;
using System.Xml;
using System.Xml.Linq;
using System.Configuration;
using System.Data.SqlClient;
namespace Cash_Man_Web_Import
{
public partial class Form1 : Form
{
private string uwRegistryPath = "SOFTWARE\\MoneyPoint\\CashMan Web";
string srcurl = "";
string desturl = "";
string logurl = "";
RegistryKey registryKey = null;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
RegistryKey registryKey = Registry.LocalMachine.OpenSubKey(uwRegistryPath, true);
try
{
var p = registryKey.GetValue("srcfile");
}
catch (Exception er)
{
registryKey = Registry.LocalMachine.CreateSubKey(uwRegistryPath + "\\srcfile");
registryKey = Registry.LocalMachine.CreateSubKey(uwRegistryPath + "\\destfile");
registryKey = Registry.LocalMachine.CreateSubKey(uwRegistryPath + "\\logfile");
registryKey = Registry.LocalMachine.OpenSubKey(uwRegistryPath, true);
registryKey.SetValue("srcfile", "C:\\CashMan Web");
registryKey.SetValue("destfile", "C:\\CashMan WebImp");
registryKey.SetValue("logfile", "C:\\Logs");
}
fsw.Created += new FileSystemEventHandler(Start);
registryKey = Registry.LocalMachine.OpenSubKey(uwRegistryPath, true);
srcurl = (string)registryKey.GetValue("srcfile");
desturl = (string)registryKey.GetValue("destfile");
logurl = (string)registryKey.GetValue("logfile");
textBox1.Text = srcurl;
textBox2.Text = desturl;
textBox3.Text = logurl;
fsw.Path = @srcurl;
fsw.EnableRaisingEvents = true;
}
public void Start(object source, FileSystemEventArgs e)
{
System.Threading.Thread.Sleep(2000);
FileInfo f = new FileInfo(e.FullPath);
//MessageBox.Show(f.Name + "@" + f.FullName);
/*Console.WriteLine("File: " + e.FullPath + " " + e.ChangeType);
label1.Text = e.FullPath;*/
par p = new par();
p.Parse(srcurl + "\\" + f.Name, desturl, logurl);
//MessageBox.Show("done");
}
private void Browse_Click(object sender, EventArgs e)
{
DialogResult result = folderBrowserDialog1.ShowDialog();
if ((result == DialogResult.OK) && (desturl != @folderBrowserDialog1.SelectedPath) && (logurl != @folderBrowserDialog1.SelectedPath))
{
RegistryKey registryKey = Registry.LocalMachine.OpenSubKey(uwRegistryPath, true);
textBox1.Text = folderBrowserDialog1.SelectedPath;
fsw.Path = @folderBrowserDialog1.SelectedPath;
srcurl = @folderBrowserDialog1.SelectedPath;
registryKey.SetValue("srcfile", @folderBrowserDialog1.SelectedPath);
fsw.Path = @srcurl;
fsw.EnableRaisingEvents = true;
}
}
private void button1_Click(object sender, EventArgs e)
{
RegistryKey registryKey = Registry.LocalMachine.OpenSubKey(uwRegistryPath, true);
DialogResult result = folderBrowserDialog2.ShowDialog();
if ((result == DialogResult.OK) && (srcurl != @folderBrowserDialog2.SelectedPath) && (logurl != @folderBrowserDialog2.SelectedPath))
{
textBox2.Text = folderBrowserDialog2.SelectedPath;
desturl = @folderBrowserDialog2.SelectedPath;
registryKey.SetValue("destfile", @folderBrowserDialog2.SelectedPath);
}
}
private void button2_Click(object sender, EventArgs e)
{
RegistryKey registryKey = Registry.LocalMachine.OpenSubKey(uwRegistryPath, true);
DialogResult result = folderBrowserDialog3.ShowDialog();
if ((result == DialogResult.OK) && (srcurl != @folderBrowserDialog3.SelectedPath) && (desturl != @folderBrowserDialog3.SelectedPath))
{
textBox3.Text = folderBrowserDialog3.SelectedPath;
logurl = @folderBrowserDialog3.SelectedPath;
registryKey.SetValue("logfile", @folderBrowserDialog3.SelectedPath);
}
}
}
class par
{
/* public void FiveMinuteWiatFun(decimal Header)
{
string cashmanwebstring = ConfigurationManager.ConnectionStrings["CashManWebDBString"].ConnectionString;
string dnnstring = ConfigurationManager.ConnectionStrings["DnnDBString"].ConnectionString;
try
{
System.Threading.Thread.Sleep(300000);
SqlConnection con = new SqlConnection(cashmanwebstring);
if (con.State != System.Data.ConnectionState.Open)
{
con.Open();
}
SqlCommand m1 = new SqlCommand("UPDATE [CashManWebDB].[dbo].[Transaction_header]SET [Received] = 1 WHERE Cassette = (select Cassette from transaction_header where Transaction_Header_id = @h)", con);
SqlCommand m2 = new SqlCommand("INSERT INTO [CashManWebDB].[dbo].[Bank_received] VALUES (@p1 ,(select Cassette from transaction_header where Transaction_Header_id = @p2),getdate(),getdate(),'Processed',0.0)", con);
m1.Parameters.Add("@h", Header);
m2.Parameters.Add("@p1", Header);
m2.Parameters.Add("@p2", Header);
m1.ExecuteNonQuery();
m2.ExecuteNonQuery();
con.Close();
}
catch (Exception er)
{
}
}
*/
[PermissionSet(SecurityAction.Demand, Name = "FullTrust")]
public string Parse(string xmlUrl, string b_url, string logurl)
{
string cashmanwebstring = ConfigurationManager.ConnectionStrings["CashManWebDBString"].ConnectionString;
string dnnstring = ConfigurationManager.ConnectionStrings["DnnDBString"].ConnectionString;
SqlConnection con = null;
try
{
con = new SqlConnection(cashmanwebstring);
if (con.State != System.Data.ConnectionState.Open)
{
con.Open();
}
string currency = "";
string trans_name = "";
string trans_quan = "";
string trans_val = "";
string device = "";
string result = "";
string symbol = "";
string type = "";
string file_name = "";
string user = "";
string cassette = "";
string filesaved = "";
XmlDocument doc = new XmlDocument();
//System.Threading.Thread.Sleep(8000);
doc.Load(@xmlUrl);
XmlNode tempnode = doc.SelectSingleNode("/transaction");
if (tempnode.SelectSingleNode("status").InnerText == "out")
{
type = "collected";
}
else if (tempnode.SelectSingleNode("status").InnerText == "in")
{
type = "deposit";
}
result = result + "Device:" + tempnode.SelectSingleNode("device").InnerText + "\n";
device = tempnode.SelectSingleNode("device").InnerText;
result = result + "Currency:" + tempnode.SelectSingleNode("currency").InnerText + "\n";
XmlNode temp = tempnode.SelectSingleNode("currency");
currency = temp.SelectSingleNode("description").InnerText;
symbol = temp.SelectSingleNode("symbol").InnerText;
cassette = tempnode.SelectSingleNode("cassette").InnerText;
user = tempnode.SelectSingleNode("operator").InnerText;
filesaved = tempnode.SelectSingleNode("filename").InnerText;
SqlCommand m1 = new SqlCommand("BEGIN TRAN T1;", con);
m1.ExecuteNonQuery();
SqlCommand m2 = null;
if (type == "collected")
{
m2 = new SqlCommand("INSERT INTO [Transaction_header]([Obls_id],[Currency],[Transaction_status],[Date_time_created],[Date_time_modified],[Symbol],CIT_id,XML_Status,[Operator],[Cassette],[Filename], Received) VALUES ((select Obls_id from dbo.Organisation_Branch_Locations_Sources where Source_device_id = (select Source_device_id from Source_Devices where Source_device_name = '" + @device + "') and Active_flag = 1),'" + @currency + "','" + @type + "','" + DateTime.Now + "','" + DateTime.Now + "','" + @symbol + "',(select br.CIT_id from Organisation_Branch_Locations br, Organisation_Branch_Location_Sources obs, Source_Devices where br.Organisation_branch_location_id = obs.Organisation_branch_location_id and br.Organisation_id = obs.Organisation_id and obs.Source_device_id = (select Source_device_id from Source_Devices where Source_device_name = @p1) and obs.Active_flag = 1 group by br.Organisation_branch_location_id, br.Organisation_id, br.CIT_id),'Not sent',@o,@c,@f,0)", con);
}
else if (type == "deposit")
{
m2 = new SqlCommand("INSERT INTO [Transaction_header]([Obls_id],[Currency],[Transaction_status],[Date_time_created],[Date_time_modified],[Symbol],CIT_id,XML_Status,[Operator],[Cassette],[Filename], Received) VALUES ((select Obls_id from dbo.Organisation_Branch_Location_Sources where Source_device_id = (select Source_device_id from Source_Devices where Source_device_name = '" + @device + "') and Active_flag = 1),'" + @currency + "','" + @type + "','" + DateTime.Now + "','" + DateTime.Now + "','" + @symbol + "',1,'Not sent',@o,@c,@f,0)", con);
}
m2.Parameters.Add("@p1", device);
m2.Parameters.Add("@o", user);
m2.Parameters.Add("@f", filesaved);
m2.Parameters.Add("@c", cassette);
try
{
m2.ExecuteNonQuery();
}
catch (Exception e)
{
MessageBox.Show(e.ToString());
}
SqlCommand m3 = new SqlCommand("SELECT @@IDENTITY ", con);
decimal head_id = 0;
SqlDataReader rdr = null;
/*try
{*/
rdr = m3.ExecuteReader();
while (rdr.Read())
{
// var g = rdr.GetDecimal(0);
head_id = rdr.GetDecimal(0);
}
rdr.Close();
/* }
catch(Exception e)
{
Console.WriteLine(e.ToString());
rdr.Close();
}*/
tempnode = doc.SelectSingleNode("/transaction");
XmlNodeList transacationlist = tempnode.SelectNodes("transactionline");
int line = 1;
foreach (XmlNode node in transacationlist)
{
result = result + node.Attributes["type"].Value + ": \n";
trans_name = node.Attributes["type"].Value;
result = result + "quantity:" + node.SelectSingleNode("quantity").InnerText + "\n";
trans_quan = node.SelectSingleNode("quantity").InnerText;
result = result + "value:" + node.SelectSingleNode("value").InnerText + "\n";
trans_val = node.SelectSingleNode("value").InnerText;
SqlCommand ml = new SqlCommand("INSERT INTO [Transaction_line]([Transaction_header_id],[Transaction_line_id],[Product_name],[Value],[Quantity]) VALUES (" + @head_id + "," + @line + " ,'" + @trans_name + "'," + @trans_val + "," + @trans_quan + ")", con);
ml.ExecuteNonQuery();
line++;
}
SqlCommand mr = new SqlCommand("commit TRAN T1;", con);
mr.ExecuteNonQuery();
con.Close();
try
{
file_name = @b_url + "\\" + DateTime.Now.ToString("ddMMyy") + DateTime.Now.ToString("HHmmss") + "imported.xml";
File.Copy(@xmlUrl, @b_url + "\\" + DateTime.Now.ToString("ddMMyy") + DateTime.Now.ToString("HHmmss") + "imported.xml");
// System.Threading.Thread.Sleep(5000);
}
// Catch exception if the file was already copied.
catch (IOException copyError)
{
Console.WriteLine(copyError.Message);
}
File.Delete(xmlUrl);
// The FIVE MINUTE PROCESS
/*Thread five_minute = new Thread(() => this.FiveMinuteWiatFun(head_id));
if (type == "collected")
{
five_minute.Start();
}
*/
// The FIVE MINUTE PROCESS
System.IO.StreamWriter file = new System.IO.StreamWriter(@logurl + "\\log.txt", true);
file.WriteLine(result);
file.WriteLine();
file.WriteLine("File : " + file_name);
file.WriteLine();
file.WriteLine("Successfully completed");
file.WriteLine("==================================================================================================");
file.WriteLine("==================================================================================================");
file.WriteLine();
file.Close();
//Five Minute Process
/*
if (type == "collected")
{
five_minute.Join();
}
*/
return result;
}
catch (Exception e)
{
string err = DateTime.Now.ToString() + " " + e.ToString();
System.IO.StreamWriter file = new System.IO.StreamWriter(@logurl + "\\log.txt", true);
file.WriteLine(err);
file.WriteLine();
file.WriteLine("==================================================================================================");
file.WriteLine("==================================================================================================");
file.WriteLine();
file.Close();
MessageBox.Show(err);
return err;
}
}
}
}
Reply
Answers (
1
)
how to pass grid view row data to another gridview row
Less Than operator in LINQ join