SGGL_SHJ/SGGL/FineUIPro.Web/PHTGL/Filing/BidDocumentsStandingBookIn....

399 lines
14 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using BLL;
using FineUIPro.Web.HJGL.WeldingManage;
using MiniExcelLibs;
using Model;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.OleDb;
using System.IO;
using System.Linq;
namespace FineUIPro.Web.PHTGL.Filing
{
public partial class BidDocumentsStandingBookIn : PageBase
{
#region
/// <summary>
/// 上传预设的虚拟路径
/// </summary>
private string initPath = Const.ExcelUrl;
/// <summary>
/// 安装组件集合
/// </summary>
public static List<Model.PHTGL_BidDocumentsStandingBook> BidDocStandingBookList = new List<Model.PHTGL_BidDocumentsStandingBook>();
/// <summary>
/// 错误集合
/// </summary>
public static string errorInfos = string.Empty;
public string Type
{
get
{
return (string)ViewState["Type"];
}
set
{
ViewState["Type"] = value;
}
}
#endregion
#region
/// <summary>
/// 加载页面
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
this.hdFileName.Text = string.Empty;
if (BidDocStandingBookList != null)
{
BidDocStandingBookList.Clear();
}
errorInfos = string.Empty;
Type = Request.Params["Type"];
}
}
#endregion
#region
/// <summary>
/// 审核
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnAudit_Click(object sender, EventArgs e)
{
try
{
Grid1.DataSource = null;
Grid1.DataBind();
if (this.fuAttachUrl.HasFile == false)
{
ShowNotify("请您选择Excel文件", MessageBoxIcon.Warning);
return;
}
string IsXls = Path.GetExtension(this.fuAttachUrl.FileName).ToString().Trim().ToLower();
if (IsXls != ".xlsx")
{
ShowNotify("只可以选择Excel文件", MessageBoxIcon.Warning);
return;
}
if (BidDocStandingBookList != null)
{
BidDocStandingBookList.Clear();
}
if (!string.IsNullOrEmpty(errorInfos))
{
errorInfos = string.Empty;
}
string rootPath = Server.MapPath("~/");
string initFullPath = rootPath + initPath;
if (!Directory.Exists(initFullPath))
{
Directory.CreateDirectory(initFullPath);
}
this.hdFileName.Text = BLL.Funs.GetNewFileName() + IsXls;
string filePath = initFullPath + this.hdFileName.Text;
this.fuAttachUrl.PostedFile.SaveAs(filePath);
ImportXlsToData(rootPath + initPath + this.hdFileName.Text);
if (string.IsNullOrEmpty(errorInfos))
{
if (!string.IsNullOrEmpty(this.hdFileName.Text))
{
if (BidDocStandingBookList.Count > 0)
{
this.Grid1.Hidden = false;
this.Grid1.DataIDField = "BidDocumentsStandingBookId";
this.Grid1.DataSource = BidDocStandingBookList;
this.Grid1.DataBind();
Grid1.RecordCount = BidDocStandingBookList.Count;
}
}
else
{
ShowNotify("请先审核要导入的文件!", MessageBoxIcon.Warning);
}
}
else
{
ShowNotify("请先将错误数据修正,再重新导入提交!", MessageBoxIcon.Warning);
}
}
catch (Exception ex)
{
Alert alert = new Alert
{
Message = "'" + ex.Message + "'",
Target = Target.Self
};
alert.Show();
//ShowNotify("'" + ex.Message + "'", MessageBoxIcon.Warning);
}
}
#region Excel提取数据
/// <summary>
/// 从Excel提取数据--》Dataset
/// </summary>
/// <param name="filename">Excel文件路径名</param>
private void ImportXlsToData(string fileName)
{
// var rows =Funs.LINQToDataTable(MiniExcel.Query(fileName).ToList()) ;
var ds = MiniExcel.Query(fileName).ToList();
var columns = MiniExcel.GetColumns(fileName);
var cnt = columns.Count;
var reposedata = AddDatasetToSQL(ds, cnt);
if (reposedata.code == 1)
{
ShowNotify("审核完成,请点击导入!", MessageBoxIcon.Success);
}
else
{
Alert alert = new Alert
{
Message = reposedata.message,
Target = Target.Self
};
alert.Show();
//ShowNotify(responeData.message, MessageBoxIcon.Success);
}
}
#endregion
#region Dataset的数据导入数据库
/// <summary>
/// 将Dataset的数据导入数据库
/// </summary>
/// <param name="pds">数据集</param>
/// <param name="Cols">数据集行数</param>
/// <returns></returns>
private Model.ResponeData AddDatasetToSQL(List<dynamic> pds, int count)
{
Model.ResponeData responeData = new Model.ResponeData();
// string result = string.Empty;
List<string> result = new List<string>();
//pds = BLL.Funs.FilterBlankLines(pds);
if (count < 15)
{
responeData.code = 0;
responeData.message = "导入Excel格式错误Excel只有" + count.ToString().Trim() + "列";
return responeData;
}
if (pds.Count > 0 && pds != null)
{
for (int i = 1; i < pds.Count; i++)
{
Model.PHTGL_BidDocumentsStandingBook _BidDocumentsStandingBook = new PHTGL_BidDocumentsStandingBook();
_BidDocumentsStandingBook.BidDocumentsStandingBookId = SQLHelper.GetNewID();
_BidDocumentsStandingBook.State = 0;
_BidDocumentsStandingBook.UnitId = this.CurrUser.UnitId;
_BidDocumentsStandingBook.DepartId = this.CurrUser.DepartId;
if (Type=="1")
{
_BidDocumentsStandingBook.ProjectId = this.CurrUser.LoginProjectId;
}
_BidDocumentsStandingBook.EPCCode = pds[i].A;
_BidDocumentsStandingBook.ProjectShortName = pds[i].B;
_BidDocumentsStandingBook.ProjectCode = pds[i].C;
_BidDocumentsStandingBook.IsOnLine = pds[i].D;
_BidDocumentsStandingBook.BidType = pds[i].E;
_BidDocumentsStandingBook.ActionPlanCode = pds[i].F;
_BidDocumentsStandingBook.BidDocumentsCode = pds[i].G;
_BidDocumentsStandingBook.BidProject = pds[i].H;
_BidDocumentsStandingBook.ShortListApprovalCode = pds[i].I;
_BidDocumentsStandingBook.ProposedInviter = pds[i].J;
_BidDocumentsStandingBook.Bidding_SendTime = pds[i].K;
_BidDocumentsStandingBook.Bidding_StartTime = pds[i].L;
_BidDocumentsStandingBook.ApprovePersonFormCode = pds[i].M;
_BidDocumentsStandingBook.BidWinner = pds[i].N;
_BidDocumentsStandingBook.SetSubReviewCode = pds[i].O;
_BidDocumentsStandingBook.BidNoticeCode= pds[i].P;
_BidDocumentsStandingBook.BidUnitFileCode= pds[i].Q;
BidDocStandingBookList.Add(_BidDocumentsStandingBook);
//if (col24 != null)
//{
//}
//else
//{
// result.Add("第" + (i + 1).ToString() + "行," + "壁厚" + "," + "此项为必填项!" + "|");
//}
}
if (result.Count > 0)
{
BidDocStandingBookList.Clear();
// result = result.Substring(0, result.LastIndexOf("|"));
errorInfos = string.Join("|", result.Distinct());
//Alert alert = new Alert();
//alert.Message = result;
//alert.Target = Target.Self;
//alert.Show();
responeData.code = 0;
responeData.message = errorInfos;
}
else
{
errorInfos = string.Empty;
}
}
else
{
responeData.code = 0;
responeData.message = "导入数据为空!";
}
return responeData;
}
#endregion
#endregion
#region
/// <summary>
/// 导入
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnImport_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(errorInfos))
{
if (!string.IsNullOrEmpty(this.hdFileName.Text))
{
if (BidDocStandingBookList.Count > 0)
{
this.Grid1.Hidden = false;
this.Grid1.DataIDField = "BidDocumentsStandingBookId";
this.Grid1.DataSource = BidDocStandingBookList;
this.Grid1.DataBind();
Grid1.RecordCount = BidDocStandingBookList.Count;
}
}
else
{
ShowNotify("请先审核要导入的文件!", MessageBoxIcon.Warning);
}
}
else
{
ShowNotify("请先将错误数据修正,再重新导入提交!", MessageBoxIcon.Warning);
}
}
#endregion
#region
/// <summary>
/// 提交
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnSave_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(errorInfos))
{
if (BidDocStandingBookList.Count > 0)
{
BidDocStandingBookService.AddBulkPHTGL_BidDocumentsStandingBook(BidDocStandingBookList);
}
int a = BidDocStandingBookList.Count();
string rootPath = Server.MapPath("~/");
string initFullPath = rootPath + initPath;
string filePath = initFullPath + this.hdFileName.Text;
if (filePath != string.Empty && System.IO.File.Exists(filePath))
{
System.IO.File.Delete(filePath);//删除上传的XLS文件
}
ShowNotify("导入成功!", MessageBoxIcon.Success);
PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference());
}
else
{
ShowNotify("请先将错误数据修正,再重新导入提交!", MessageBoxIcon.Warning);
}
}
#endregion
#region
public string ConvertPipelineId(object PipelineId)
{
string StateName = string.Empty;
if (!string.IsNullOrEmpty(PipelineId.ToString()))
{
if (PipelineId != null)
{
string txt = PipelineService.GetPipelineByPipelineId(PipelineId.ToString()).PipelineCode;
return txt;
}
return "";
}
return StateName;
}
#endregion
#region
/// <summary>
/// 下载模板按钮
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnDownLoad_Click(object sender, EventArgs e)
{
string rootPath = Server.MapPath("~/");
string uploadfilepath = rootPath + Const.BidDocumentsStandingBookIn;
string filePath = Const.BidDocumentsStandingBookIn;
string fileName = Path.GetFileName(filePath);
FileInfo info = new FileInfo(uploadfilepath);
long fileSize = info.Length;
Response.ClearContent();
Response.AddHeader("Content-Disposition", "attachment;filename=" + System.Web.HttpUtility.UrlEncode(fileName, System.Text.Encoding.UTF8));
Response.ContentType = "excel/plain";
Response.ContentEncoding = System.Text.Encoding.UTF8;
Response.AddHeader("Content-Length", fileSize.ToString().Trim());
Response.TransmitFile(uploadfilepath, 0, fileSize);
Response.End();
}
#endregion
#region
/// <summary>
/// 分页选择下拉改变事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void ddlPageSize_SelectedIndexChanged(object sender, EventArgs e)
{
Grid1.PageSize = Convert.ToInt32(ddlPageSize.SelectedValue);
this.Grid1.DataSource = BidDocStandingBookList;
this.Grid1.DataBind();
Grid1.RecordCount = BidDocStandingBookList.Count;
}
#endregion
}
}