using System;
using System.Xml;
using System.IO;
using System.Threading;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.ServiceProcess;
using System.Text;
namespace ImageService
{
partial class Image : ServiceBase
{
private Thread MainThread;
public Image()
{
InitializeComponent();
MainThread = new Thread(new ThreadStart(ThreadFunc));
}
protected override void OnStart(string[] args)
{
// TODO: 在此处添加代码以启动服务。
MainThread.Start();
}
protected override void OnStop()
{
// TODO: 在此处添加代码以执行停止服务所需的关闭操作。
MainThread.Abort();
}
private void writeImagetToXml(string cardno)
{
string sql = "select * from vw_ejw_rk_czrk_zp where gmsfzh='" + cardno + "'";
databaseQ dao = new databaseQ();
DataSet ds = null;
string xmlPath = @"D:/ImageWrite/admin_czrk_photo.xml";
try
{
ds = dao.GetDataOra(sql,Constant.connectString);
if(ds.Tables[0].Rows.Count>0)
{
createXml(xmlPath);
DataSet dst = new DataSet();
dst.ReadXml(xmlPath);
if (dst.Tables[0].Rows.Count > 0)
{
dst.Tables[0].Rows[0]["PHOTO_JPG"] = ds.Tables[0].Rows[0]["zp"].ToString();
}
dst.AcceptChanges();
dst.WriteXml(xmlPath);
dst.Dispose();
}
}
catch (Exception ex)
{
}
finally
{
ds.Dispose();
}
}
private void ThreadFunc()
{
string xmlPath = @"D:/ImageRead/admin_czrk_photo.xml";
DataSet ds = new DataSet();
try
{
ds.ReadXml(xmlPath);
if(ds.Tables[0].Rows.Count>0)
{
string cardno = ds.Tables[0].Rows[0]["PHOTO_NO"].ToString();
writeImagetToXml(cardno);
}
}
catch (Exception ex)
{
}
finally
{
ds.Dispose();
}
File.Delete(xmlPath);
}
private void createXml(string xmlpath)
{
if (!File.Exists(xmlpath))
{
//File.Delete(xmlPath);
//生成跟节点
XmlDocument xdc = new XmlDocument();
XmlNode xnode = xdc.CreateNode(XmlNodeType.Element, "NewDataSet", "");
xdc.AppendChild(xnode);
//生成子接点
XmlElement ele = xdc.CreateElement("", "Table", "");
xnode.AppendChild(ele);
//生成三级子接点
XmlElement elee = xdc.CreateElement("", "PHOTO_USERID", "");
XmlText xtexte = xdc.CreateTextNode("admin");
elee.AppendChild(xtexte);
ele.AppendChild(elee);
//生成三级子接点
XmlElement elee1 = xdc.CreateElement("", "PHOTO_YWTYPE", "");
XmlText xtexte1 = xdc.CreateTextNode("常住人口");
elee.AppendChild(xtexte1);
ele.AppendChild(elee1);
//生成三级子接点
XmlElement elee2 = xdc.CreateElement("", "PHOTO_NO", "");
XmlText xtexte2 = xdc.CreateTextNode("110101195702264538");
elee.AppendChild(xtexte2);
ele.AppendChild(elee2);
//生成三级子接点
XmlElement elee3 = xdc.CreateElement("", "PHOTO_JPG", "");
ele.AppendChild(elee3);
xdc.Save(xmlpath);
}
}
}
}