/// <summary>
/// WebServiceDataDown 的摘要说明
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class WebServiceDataDown : System.Web.Services.WebService {
public WebServiceDataDown () {
//如果使用设计的组件,请取消注释以下行
//InitializeComponent();
}
#region 导入数据到ACCESS并压缩文件
[WebMethod]
public void LoadDataToAccess()
{
DataSet ds = GetDataFromSQL();
InsertDataToAccess(ds);
WinrarFile();
}
#endregion
#region 从SQL数据库里读取数据
[WebMethod]
protected DataSet GetDataFromSQL()
{
string sqlstr = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
string sql = String.Empty;
SqlConnection con = new SqlConnection(sqlstr);
DataSet ds = new DataSet();
#region SYYQXX
sql = "SELECT SYBH,YQBH,YQMC,GG,DW,MZSXSL FROM SYYQXX";
SqlDataAdapter da_SYYQXX = new SqlDataAdapter(sql, con);
da_SYYQXX.Fill(ds, "SYYQXX");
#endregion
return ds;
}
#endregion
#region 把数据插入到ACCESS数据库
[WebMethod]
protected void InsertDataToAccess(DataSet ds)
{
string ole = String.Empty;
string SourcePath = Server.MapPath("UpDownload\\MyDownload\\WorkData\\BaseCode.mdb");
string oleconstr = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" + SourcePath + "; User ID=admin;";
OleDbConnection olecon = new OleDbConnection(oleconstr);
olecon.Open();
foreach (DataTable dt in ds.Tables)
{
switch (dt.TableName)
{
case "":
。。。
break;
…
#region SYYQXX
case "SYYQXX":
OleDbCommand olecom_SYYQXX = new OleDbCommand("DELETE FROM SYYQXX", olecon);
olecom_SYYQXX.ExecuteNonQuery();
OleDbDataAdapter oleda_SYYQXX = new OleDbDataAdapter("SELECT SYBH,YQBH,YQMC,GG,DW,MZSXSL FROM SYYQXX", olecon);
DataSet oleds_SYYQXX = new DataSet();
oleda_SYYQXX.Fill(oleds_SYYQXX, "SYYQXX");
for (int i = 0; i < ds.Tables["SYYQXX"].Rows.Count; i++)
{
DataRow dr = oleds_SYYQXX.Tables[0].NewRow();
dr["SYBH"] = ds.Tables["SYYQXX"].Rows[i]["SYBH"];
dr["YQBH"] = ds.Tables["SYYQXX"].Rows[i]["YQBH"];
dr["YQMC"] = ds.Tables["SYYQXX"].Rows[i]["YQMC"];
dr["GG"] = ds.Tables["SYYQXX"].Rows[i]["GG"];
dr["DW"] = ds.Tables["SYYQXX"].Rows[i]["DW"];
dr["MZSXSL"] = ds.Tables["SYYQXX"].Rows[i]["MZSXSL"];
oleds_SYYQXX.Tables[0].Rows.Add(dr);
}
OleDbCommandBuilder builderSYYQXX = new OleDbCommandBuilder(oleda_SYYQXX);
oleda_SYYQXX.Update(oleds_SYYQXX, "SYYQXX");
oleds_SYYQXX.Dispose();
break;
#endregion
default :
break;
}
}
olecon.Close();
}
#endregion
#region 压缩文件
[WebMethod]
protected void WinrarFile()
{
try
{
if (File.Exists(Server.MapPath("UpDownload\\MyDownload\\BaseCode.zip")))
{
File.Delete(Server.MapPath("UpDownload\\MyDownload\\BaseCode.zip"));
}
string strtxtPath = Server.MapPath("UpDownload\\MyDownload\\WorkData\\BaseCode.mdb");
string strzipPath = Server.MapPath("UpDownload\\MyDownload\\BaseCode.zip");
System.Diagnostics.Process Process1 = new System.Diagnostics.Process();
Process1.StartInfo.FileName = "Winrar.exe";
Process1.StartInfo.CreateNoWindow = true;
Process1.StartInfo.Arguments = " a -ep " + strzipPath + " " + strtxtPath;
Process1.Start();
Process1.Dispose();
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
}
评论