提交代码

This commit is contained in:
2024-02-21 15:14:53 +08:00
parent 2c6a615726
commit b3357fb53f
15 changed files with 1068 additions and 507 deletions
@@ -1,16 +1,20 @@
using Newtonsoft.Json.Linq;
using BLL;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.OleDb;
using System.IO;
using System.Web;
using System.Web.SessionState;
using System.Linq;
namespace FineUIPro.Web.AttachFile
{
/// <summary>
/// fileupload 的摘要说明
/// </summary>
public class fileupload : IHttpHandler, IRequiresSessionState
public class fileupload : PageBase, IHttpHandler, IRequiresSessionState
{
private void ResponseError(HttpContext context)
{
@@ -51,7 +55,10 @@ namespace FineUIPro.Web.AttachFile
// 文件名保存的服务器路径
string savedFileName = GetSavedFileName(fileName);
postedFile.SaveAs(context.Server.MapPath("~/" + attachPath + "/" + savedFileName));
if (owner.Contains("DriverRunPlanK"))
{
ImportXlsToData(context.Server.MapPath("~/" + attachPath + "/" + savedFileName));
}
string shortFileName = GetFileName(fileName);
string fileType = GetFileType(fileName);
if (!allowExtensions.Contains("." + fileType))
@@ -139,5 +146,108 @@ namespace FineUIPro.Web.AttachFile
return false;
}
}
#region Excel提取数据
/// <summary>
/// 从Excel提取数据--》Dataset
/// </summary>
/// <param name="filename">Excel文件路径名</param>
private void ImportXlsToData(string fileName)
{
try
{
string oleDBConnString = String.Empty;
oleDBConnString = "Provider=Microsoft.Jet.OLEDB.4.0;";
oleDBConnString += "Data Source=";
oleDBConnString += fileName;
oleDBConnString += ";Extended Properties=Excel 8.0;";
OleDbConnection oleDBConn = null;
OleDbDataAdapter oleAdMaster = null;
DataTable m_tableName = new DataTable();
DataSet ds = new DataSet();
oleDBConn = new OleDbConnection(oleDBConnString);
oleDBConn.Open();
m_tableName = oleDBConn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);
if (m_tableName != null && m_tableName.Rows.Count > 0)
{
m_tableName.TableName = m_tableName.Rows[0]["TABLE_NAME"].ToString().Trim();
}
string sqlMaster;
sqlMaster = " SELECT * FROM [" + m_tableName.TableName + "]";
oleAdMaster = new OleDbDataAdapter(sqlMaster, oleDBConn);
oleAdMaster.Fill(ds, "m_tableName");
oleAdMaster.Dispose();
oleDBConn.Close();
oleDBConn.Dispose();
AddDatasetToSQL(ds.Tables[0], 35);
}
catch (Exception exc)
{
//return null;
// return dt;
}
finally
{
}
}
#endregion
#region Dataset的数据导入数据库
/// <summary>
/// 将Dataset的数据导入数据库
/// </summary>
/// <param name="pds">数据集</param>
/// <param name="Cols">数据集行数</param>
/// <returns></returns>
private bool AddDatasetToSQL(DataTable pds, int Cols)
{
string result = string.Empty;
int ic, ir;
ic = pds.Columns.Count;
if (ic < Cols)
{
return false;
}
ir = pds.Rows.Count;
if (pds != null && ir > 0)
{
var driverRunPlan = (from x in Funs.DB.DriverRun_DriverRunPlan
where x.ProjectId == this.CurrUser.LoginProjectId
select x).FirstOrDefault();
int usedDays = 0;
if (driverRunPlan != null)
{
for (int i = 0; i < ir; i++)
{
string row34 = pds.Rows[i][34].ToString().Trim();
if (!string.IsNullOrEmpty(row34))
{
usedDays += Funs.GetNewIntOrZero(row34);
}
}
if (driverRunPlan.UsedDays == null)
{
driverRunPlan.UsedDays = usedDays;
}
else
{
driverRunPlan.UsedDays += usedDays;
}
Funs.DB.SubmitChanges();
}
}
else
{
}
return true;
}
#endregion
}
}