62,041
社区成员
发帖
与我相关
我的任务
分享
/// <summary> 同步企业信息(包括相关的证书信息)
/// 编码字段:Wat_ComInfo:Com_Des,Com_Brand;Wat_BreedWay:Bre_ProductType,Bre_OtherDes
/// </summary>
/// <param name="AreaCode">行政区号</param>
/// <returns></returns>
[WebMethod]
public string SyncComInfo(string AreaCode)
{
SyncCompanyInfo yci = new SyncCompanyInfo();
return yci.SaveComInfoToTXT(AreaCode);
}
using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.IO;
using System.Collections.Generic;
using MMFrame;
using FrameWork;
using FrameWork.Components;
using FrameWork.Facade;
using System.Xml;
using System.Runtime.Serialization.Json;
using System.Web.Script.Serialization;
using System.Collections;
using System.Text;
using System.Diagnostics;
using System.Threading;
/// <summary>
///SyncComInfo 的摘要说明
/// </summary>
public class SyncCompanyInfo
{
public SyncCompanyInfo()
{
//
//TODO: 在此处添加构造函数逻辑
//
}
public string SaveComInfoToTXT(string AreaCode)
{
string GUID = Common.GetGUID;
string Dir = System.Web.HttpContext.Current.Server.MapPath(Common.UpLoadDir);
string txtDir = Common.CreateDirectory(Dir, "SyncComInfo\\" + GUID);
System.Threading.Thread t = new System.Threading.Thread(() =>
{
WriteComInfoToTXT(AreaCode, txtDir);
});
t.IsBackground = true;
t.Start();
return "Public/SyncComInfo/" + GUID;
}
/// <summary> 企业信息写入TXT文件
///
/// </summary>
/// <param name="AreaCode"></param>
/// <returns></returns>
public void WriteComInfoToTXT(string AreaCode, string txtDir)
{
//try
//{
StreamWriter sr = null;
StreamWriter sw = null;
string strJson = "";
string txtPath = "";
if (!string.IsNullOrEmpty(AreaCode))
{
StringBuilder sbSQL = new StringBuilder();
sbSQL.AppendLine("select ValueID from Sys_FieldValue");
sbSQL.AppendLine("where V_F_Key = 'ProvinceCityZoneKey' and V_ParValueID = '922'");
sbSQL.AppendLine("and V_Code = '" + AreaCode + "'");
int recordCount = 0;
DataTable dt = new DataTable();
dt = BusinessSystem.getDataList(sbSQL.ToString(), out recordCount).Tables[0];
if (recordCount > 0)
{
//市级
string valueId = dt.Rows[0]["ValueID"].ToString();
sbSQL = new StringBuilder();
sbSQL.AppendLine("select V_Code from Sys_FieldValue");
sbSQL.AppendLine("where V_F_Key = 'ProvinceCityZoneKey' and V_ParValueID = '" + valueId + "'");
recordCount = 0;
dt = new DataTable();
dt = BusinessSystem.getDataList(sbSQL.ToString(), out recordCount).Tables[0];
for (int i = 0; i < recordCount; i++)
{
string code = dt.Rows[i]["V_Code"].ToString();
txtPath = txtDir + "\\" + code + ".txt";
strJson = WebServiceMethod.SyncComInfo(code);
StreamWriter srA = File.CreateText(txtPath);
srA.Close();
//写入TXT
StreamWriter swA = new StreamWriter(txtPath, false, System.Text.Encoding.Default);
swA.WriteLine(strJson);
swA.Close();
}
}
else
{
//区县级
txtPath = txtDir + "\\" + AreaCode + ".txt";
strJson = WebServiceMethod.SyncComInfo(AreaCode);
sr = File.CreateText(txtPath);
sr.Close();
//写入TXT
sw = new StreamWriter(txtPath, false, System.Text.Encoding.Default);
sw.WriteLine(strJson);
sw.Close();
}
//创建一个txt文件,用于平板判断Json是否生成完成
string txtIsFinish = txtDir + "\\" + "IsFinish.txt";
StreamWriter srF = File.CreateText(txtIsFinish);
srF.Close();
StreamWriter swF = new StreamWriter(txtIsFinish, false, System.Text.Encoding.Default);
swF.WriteLine("HelloWorld.");
swF.Close();
}
//}
//catch (Exception ex)
//{
// result = "False|" + ex.Message;
// FileTxtLogs.WriteLog("同步企业信息(" + AreaCode + ")出错!提示:" + ex.Message);
//}
}
}