722 lines
29 KiB
C#
722 lines
29 KiB
C#
using Aspose.Words;
|
|
using Aspose.Words.Tables;
|
|
using BLL;
|
|
using Newtonsoft.Json.Linq;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Data;
|
|
using System.Data.SqlClient;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Web;
|
|
using System.Web.UI;
|
|
using System.Web.UI.WebControls;
|
|
|
|
namespace FineUIPro.Web.JGZL
|
|
{
|
|
public partial class NDTPerson : PageBase
|
|
{
|
|
#region 加载页面
|
|
/// <summary>
|
|
/// 加载页面
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
protected void Page_Load(object sender, EventArgs e)
|
|
{
|
|
if (!IsPostBack)
|
|
{
|
|
this.ddlPageSize.SelectedValue = this.Grid1.PageSize.ToString();
|
|
|
|
this.drpProjectId.DataTextField = "ProjectCode";
|
|
this.drpProjectId.DataValueField = "ProjectId";
|
|
this.drpProjectId.DataSource = BLL.Base_ProjectService.GetOnProjectListByUserId(this.CurrUser.UserId, "1");
|
|
this.drpProjectId.DataBind();
|
|
Funs.FineUIPleaseSelect(this.drpProjectId);
|
|
|
|
this.drpProjectId.SelectedValue = this.CurrUser.LoginProjectId;
|
|
this.InitTreeMenu();//加载树
|
|
this.tvControlItem.SelectedNodeID = this.drpProjectId.SelectedValue;
|
|
this.BindGrid();
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region 加载树项目
|
|
/// <summary>
|
|
/// 加载树
|
|
/// </summary>
|
|
private void InitTreeMenu()
|
|
{
|
|
this.tvControlItem.Nodes.Clear();
|
|
TreeNode rootNode = new TreeNode();
|
|
rootNode.Text = "项目";
|
|
rootNode.ToolTip = "项目";
|
|
rootNode.NodeID = "0";
|
|
rootNode.Expanded = true;
|
|
this.tvControlItem.Nodes.Add(rootNode);
|
|
|
|
List<Model.Base_Project> projects = BLL.Base_ProjectService.GetOnProjectListByUserId(this.CurrUser.UserId, "1");
|
|
if (this.drpProjectId.SelectedValue != BLL.Const._Null)
|
|
{
|
|
projects = projects.Where(e => e.ProjectId == this.drpProjectId.SelectedValue).ToList();
|
|
}
|
|
foreach (var item in projects)
|
|
{
|
|
TreeNode rootProjectNode = new TreeNode();//定义根节点
|
|
rootProjectNode.Text = item.ProjectCode;
|
|
rootProjectNode.NodeID = item.ProjectId;
|
|
rootProjectNode.EnableClickEvent = true;
|
|
rootProjectNode.Expanded = true;
|
|
rootProjectNode.ToolTip = item.ProjectName;
|
|
rootProjectNode.CommandName = "项目名称";
|
|
rootNode.Nodes.Add(rootProjectNode);
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region 点击TreeView
|
|
/// <summary>
|
|
/// 点击TreeView
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
protected void tvControlItem_NodeCommand(object sender, TreeCommandEventArgs e)
|
|
{
|
|
if (this.tvControlItem.SelectedNodeID != "0")
|
|
{
|
|
this.BindGrid();
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region 数据绑定
|
|
/// <summary>
|
|
/// 数据绑定
|
|
/// </summary>
|
|
private void BindGrid()
|
|
{
|
|
string projectId = this.tvControlItem.SelectedNodeID;
|
|
string strSql = @"SELECT * from JGZL_NDTPerson where 1=1";
|
|
List<SqlParameter> listStr = new List<SqlParameter>();
|
|
if (!string.IsNullOrEmpty(projectId))
|
|
{
|
|
strSql += " AND ProjectId = @ProjectId";
|
|
listStr.Add(new SqlParameter("@ProjectId", projectId));
|
|
}
|
|
if (!string.IsNullOrEmpty(this.txtPersonNameS.Text))
|
|
{
|
|
strSql += " AND PersonName like @PersonName";
|
|
listStr.Add(new SqlParameter("@PersonName", "%" + this.txtPersonNameS.Text + "%"));
|
|
}
|
|
SqlParameter[] parameter = listStr.ToArray();
|
|
DataTable tb = SQLHelper.GetDataTableRunText(strSql, parameter);
|
|
// 2.获取当前分页数据
|
|
Grid1.RecordCount = tb.Rows.Count;
|
|
//tb = GetFilteredTable(Grid1.FilteredData, tb);
|
|
var table = this.GetPagedDataTable(Grid1, tb);
|
|
Grid1.DataSource = table;
|
|
Grid1.DataBind();
|
|
|
|
#region 没有数据默认增加一行空白行
|
|
if (tb.Rows.Count == 0)
|
|
{
|
|
JArray teamGroupData = Grid1.GetMergedData();
|
|
List<JObject> list = new List<JObject>();
|
|
foreach (JObject teamGroupRow in teamGroupData)
|
|
{
|
|
JObject values = teamGroupRow.Value<JObject>("values");
|
|
list.Add(values);
|
|
}
|
|
|
|
JObject defaultObj = new JObject
|
|
{
|
|
{ "NDTPersonId", Guid.NewGuid() },
|
|
{ "ProjectId", projectId},
|
|
{ "PersonName", "" },
|
|
{ "CertificateNumber", "" },
|
|
{ "QualifiedProjectCode", "" },
|
|
{ "Levels", "" },
|
|
{ "ValidityDate", "" },
|
|
{
|
|
"Delete3",
|
|
String.Format("<a href=\"javascript:;\" onclick=\"{0}\"><img src=\"{1}\"/></a>",
|
|
GetDeleteScriptGrid1(), IconHelper.GetResolvedIconUrl(Icon.Delete))
|
|
}
|
|
};
|
|
list.Add(defaultObj);
|
|
Grid1.DataSource = list;
|
|
Grid1.DataBind();
|
|
}
|
|
#endregion
|
|
}
|
|
#endregion
|
|
|
|
#region 分页排序
|
|
#region 页索引改变事件
|
|
/// <summary>
|
|
/// 页索引改变事件
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
protected void Grid1_PageIndexChange(object sender, GridPageEventArgs e)
|
|
{
|
|
BindGrid();
|
|
}
|
|
#endregion
|
|
|
|
#region 排序
|
|
/// <summary>
|
|
/// 排序
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
protected void Grid1_Sort(object sender, GridSortEventArgs e)
|
|
{
|
|
BindGrid();
|
|
}
|
|
#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);
|
|
BindGrid();
|
|
}
|
|
#endregion
|
|
#endregion
|
|
|
|
#region 查询
|
|
///<summary>
|
|
///查询
|
|
///</summary>
|
|
///<param name="sender"></param>
|
|
///<param name="e"></param>
|
|
protected void drpProjectId_SelectedIndexChanged(object sender, EventArgs e)
|
|
{
|
|
this.tvControlItem.SelectedNodeID = this.drpProjectId.SelectedValue;
|
|
this.InitTreeMenu();
|
|
BindGrid();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 查询
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
protected void txtPersonNameS_TextChanged(object sender, EventArgs e)
|
|
{
|
|
BindGrid();
|
|
}
|
|
#endregion
|
|
|
|
#region 打印
|
|
/// <summary>
|
|
/// 打印
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
protected void btnPrint_Click(object sender, EventArgs e)
|
|
{
|
|
string projectId = this.tvControlItem.SelectedNodeID;
|
|
if (projectId != null)
|
|
{
|
|
string initTemplatePath = "";
|
|
string rootPath = Server.MapPath("~/");
|
|
BLL.Common.FastReportService.ResetData();
|
|
|
|
string strSql = @"SELECT * from JGZL_NDTPerson where ProjectId = @ProjectId";
|
|
List<SqlParameter> listStr = new List<SqlParameter>();
|
|
listStr.Add(new SqlParameter("@ProjectId", projectId));
|
|
if (!string.IsNullOrEmpty(this.txtPersonNameS.Text))
|
|
{
|
|
strSql += " and PersonName like @personName";
|
|
listStr.Add(new SqlParameter("@personName", "%" + this.txtPersonNameS.Text + "%"));
|
|
}
|
|
strSql += " order by ValidityDate desc";
|
|
SqlParameter[] parameter = listStr.ToArray();
|
|
DataTable tb = SQLHelper.GetDataTableRunText(strSql, parameter);
|
|
|
|
if (tb.Rows.Count > 0)
|
|
{
|
|
DataTable dt = new DataTable();
|
|
dt.TableName = "Data";
|
|
dt.Columns.Add("Num");
|
|
dt.Columns.Add("PersonName");
|
|
dt.Columns.Add("CertificateNumber");
|
|
dt.Columns.Add("QualifiedProjectCode");
|
|
dt.Columns.Add("Levels");
|
|
dt.Columns.Add("ValidityDate");
|
|
|
|
DataRow[] rows = tb.DefaultView.ToTable().Select();
|
|
int i = 0;
|
|
foreach (var row in rows)
|
|
{
|
|
var newRow = dt.NewRow();
|
|
newRow["Num"] = (i + 1).ToString();
|
|
newRow["PersonName"] = row["PersonName"].ToString();
|
|
newRow["CertificateNumber"] = row["CertificateNumber"].ToString();
|
|
newRow["QualifiedProjectCode"] = row["QualifiedProjectCode"].ToString();
|
|
newRow["Levels"] = row["Levels"].ToString();
|
|
string ValidityDate = string.Format("{0:yyyy-MM-dd}", row["ValidityDate"]);
|
|
newRow["ValidityDate"] = ValidityDate;
|
|
dt.Rows.Add(newRow);
|
|
i++;
|
|
}
|
|
BLL.Common.FastReportService.AddFastreportTable(dt);
|
|
|
|
Dictionary<string, string> keyValuePairs = new Dictionary<string, string>();
|
|
keyValuePairs.Add("ProjectName", BLL.Base_ProjectService.GetProjectByProjectId(projectId).ProjectName);
|
|
BLL.Common.FastReportService.AddFastreportParameter(keyValuePairs);
|
|
|
|
initTemplatePath = "File\\Fastreport\\JGZL\\无损检测人员登记表.frx";
|
|
if (File.Exists(rootPath + initTemplatePath))
|
|
{
|
|
PageContext.RegisterStartupScript(WindowPrint.GetShowReference(String.Format("../common/ReportPrint/Fastreport.aspx?ReportPath={0}", rootPath + initTemplatePath)));
|
|
}
|
|
}
|
|
else
|
|
{
|
|
Alert.ShowInTop("没有可打印的数据!", MessageBoxIcon.Warning);
|
|
return;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
Alert.ShowInTop("请选择项目!", MessageBoxIcon.Warning);
|
|
return;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region 维护
|
|
/// <summary>
|
|
/// 增加
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
protected void btnAdd_Click(object sender, EventArgs e)
|
|
{
|
|
if (!string.IsNullOrEmpty(this.tvControlItem.SelectedNodeID))
|
|
{
|
|
if (!string.IsNullOrEmpty(this.tvControlItem.SelectedNodeID))
|
|
{
|
|
JArray teamGroupData = Grid1.GetMergedData();
|
|
List<JObject> list = new List<JObject>();
|
|
foreach (JObject teamGroupRow in teamGroupData)
|
|
{
|
|
JObject values = teamGroupRow.Value<JObject>("values");
|
|
list.Add(values);
|
|
}
|
|
|
|
JObject defaultObj = new JObject
|
|
{
|
|
{ "NDTPersonId", Guid.NewGuid() },
|
|
{ "ProjectId", this.tvControlItem.SelectedNodeID },
|
|
{ "PersonName", "" },
|
|
{ "CertificateNumber", "" },
|
|
{ "QualifiedProjectCode", "" },
|
|
{ "Levels", "" },
|
|
{ "ValidityDate", "" },
|
|
{
|
|
"Delete3",
|
|
String.Format("<a href=\"javascript:;\" onclick=\"{0}\"><img src=\"{1}\"/></a>",
|
|
GetDeleteScriptGrid1(), IconHelper.GetResolvedIconUrl(Icon.Delete))
|
|
}
|
|
};
|
|
list.Add(defaultObj);
|
|
Grid1.DataSource = list;
|
|
Grid1.DataBind();
|
|
|
|
//PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("NDTPersonEdit.aspx?projectId={0}", this.tvControlItem.SelectedNodeID, "新增 - ")));
|
|
}
|
|
else
|
|
{
|
|
Alert.ShowInTop("请选择项目!", MessageBoxIcon.Warning);
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
|
|
protected void Grid1_PreDataBound(object sender, EventArgs e)
|
|
{
|
|
// 设置LinkButtonField的点击客户端事件
|
|
LinkButtonField deleteField = Grid1.FindColumn("Delete3") as LinkButtonField;
|
|
deleteField.OnClientClick = GetDeleteScriptGrid1();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 删除提示
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
private string GetDeleteScriptGrid1()
|
|
{
|
|
return Confirm.GetShowReference("删除选中行?", String.Empty, MessageBoxIcon.Question,
|
|
Grid1.GetDeleteSelectedRowsReference(), String.Empty);
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 双击编辑
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
//protected void Grid1_RowDoubleClick(object sender, GridRowClickEventArgs e)
|
|
//{
|
|
// if (BLL.CommonService.GetAllButtonPowerList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, BLL.Const.JGZL_NDTPersonMenuId, BLL.Const.BtnModify))
|
|
// {
|
|
// if (!string.IsNullOrEmpty(this.tvControlItem.SelectedNodeID))
|
|
// {
|
|
// if (!string.IsNullOrEmpty(this.Grid1.SelectedRowID))
|
|
// {
|
|
// PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("NDTPersonEdit.aspx?NDTPersonId={0}", this.Grid1.SelectedRowID, "编辑 - ")));
|
|
// }
|
|
// else
|
|
// {
|
|
// Alert.ShowInTop("请选择一条记录!", MessageBoxIcon.Warning);
|
|
// return;
|
|
// }
|
|
// }
|
|
// else
|
|
// {
|
|
// Alert.ShowInTop("请选择项目!", MessageBoxIcon.Warning);
|
|
// return;
|
|
// }
|
|
// }
|
|
// else
|
|
// {
|
|
// ShowNotify("您没有这个权限,请与管理员联系!", MessageBoxIcon.Warning);
|
|
// }
|
|
//}
|
|
|
|
/// <summary>
|
|
/// 右键编辑
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
//protected void btnMenuEdit_Click(object sender, EventArgs e)
|
|
//{
|
|
// if (BLL.CommonService.GetAllButtonPowerList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, BLL.Const.JGZL_NDTPersonMenuId, BLL.Const.BtnModify))
|
|
// {
|
|
// if (Grid1.SelectedRowIndexArray.Length == 0)
|
|
// {
|
|
// Alert.ShowInTop("请选择一条记录!", MessageBoxIcon.Warning);
|
|
// return;
|
|
// }
|
|
// PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("NDTPersonEdit.aspx?NDTPersonId={0}", Grid1.SelectedRowID, "维护 - ")));
|
|
// }
|
|
// else
|
|
// {
|
|
// Alert.ShowInTop("您没有这个权限,请与管理员联系!", MessageBoxIcon.Warning);
|
|
// }
|
|
//}
|
|
|
|
/// <summary>
|
|
/// 右键删除
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
//protected void btnMenuDelete_Click(object sender, EventArgs e)
|
|
//{
|
|
// if (CommonService.GetAllButtonPowerList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, Const.JGZL_NDTPersonMenuId, Const.BtnDelete))
|
|
// {
|
|
// if (Grid1.SelectedRowIndexArray.Length == 0)
|
|
// {
|
|
// Alert.ShowInTop("请选择一条记录!", MessageBoxIcon.Warning);
|
|
// return;
|
|
// }
|
|
|
|
// bool isShow = true;
|
|
// if (Grid1.SelectedRowIndexArray.Length > 1)
|
|
// {
|
|
// isShow = false;
|
|
// }
|
|
// bool isDelete = false;
|
|
// foreach (int rowIndex in Grid1.SelectedRowIndexArray)
|
|
// {
|
|
// string rowID = Grid1.DataKeys[rowIndex][0].ToString();
|
|
// if (judgementDelete(rowID, isShow))
|
|
// {
|
|
// isDelete = true;
|
|
// BLL.NDTPersonService.DeleteNDTPersonByNDTPersonId(rowID);
|
|
// BLL.Sys_LogService.AddLog(BLL.Const.System_3, this.CurrUser.LoginProjectId, this.CurrUser.UserId, "删除无损检测人员登记表");
|
|
// }
|
|
// }
|
|
// if (isDelete)
|
|
// {
|
|
// ShowNotify("删除成功!", MessageBoxIcon.Success);
|
|
// }
|
|
// this.BindGrid();
|
|
// }
|
|
// else
|
|
// {
|
|
// Alert.ShowInTop("您没有这个权限,请与管理员联系!", MessageBoxIcon.Warning);
|
|
// }
|
|
//}
|
|
|
|
#region 判断是否可删除
|
|
/// <summary>
|
|
/// 判断是否可以删除
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
//private bool judgementDelete(string id, bool isShow)
|
|
//{
|
|
// string content = string.Empty;
|
|
|
|
// if (string.IsNullOrEmpty(content))
|
|
// {
|
|
// return true;
|
|
// }
|
|
// else
|
|
// {
|
|
// if (isShow)
|
|
// {
|
|
// Alert.ShowInTop(content, MessageBoxIcon.Error);
|
|
// }
|
|
// return false;
|
|
// }
|
|
//}
|
|
#endregion
|
|
#endregion
|
|
|
|
#region 关闭弹出窗口及刷新页面
|
|
/// <summary>
|
|
/// 关闭弹出窗口
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
//protected void Window1_Close(object sender, WindowCloseEventArgs e)
|
|
//{
|
|
// this.InitTreeMenu();//加载树
|
|
// this.BindGrid();
|
|
//}
|
|
#endregion
|
|
|
|
#region 保存
|
|
protected void btnSave_Click(object sender, EventArgs e)
|
|
{
|
|
if (CommonService.GetAllButtonPowerList(this.CurrUser.LoginProjectId, this.CurrUser.UserId,
|
|
Const.JGZL_NDTPersonMenuId, Const.BtnSave))
|
|
{
|
|
saveItem();
|
|
ShowNotify("保存成功!", MessageBoxIcon.Success);
|
|
PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference());
|
|
}
|
|
else
|
|
{
|
|
Alert.ShowInTop("您没有这个权限,请与管理员联系!", MessageBoxIcon.Warning);
|
|
return;
|
|
}
|
|
}
|
|
|
|
void saveItem()
|
|
{
|
|
BLL.NDTPersonService.DeleteNDTPersonByProjectId(this.tvControlItem.SelectedNodeID);
|
|
List<Model.JGZL_NDTPerson> detailLists = new List<Model.JGZL_NDTPerson>();
|
|
JArray teamGroupData = Grid1.GetMergedData();
|
|
foreach (JObject teamGroupRow in teamGroupData)
|
|
{
|
|
JObject values = teamGroupRow.Value<JObject>("values");
|
|
int rowIndex = teamGroupRow.Value<int>("index");
|
|
Model.JGZL_NDTPerson newDetail = new Model.JGZL_NDTPerson
|
|
{
|
|
NDTPersonId = values.Value<string>("NDTPersonId"),
|
|
ProjectId = this.tvControlItem.SelectedNodeID,
|
|
PersonName = values.Value<string>("PersonName"),
|
|
CertificateNumber = values.Value<string>("CertificateNumber"),
|
|
QualifiedProjectCode = values.Value<string>("QualifiedProjectCode"),
|
|
Levels = values.Value<string>("Levels"),
|
|
ValidityDate = Funs.GetNewDateTime(values.Value<string>("ValidityDate")),
|
|
CompileMan = this.CurrUser.UserId,
|
|
CompileDate = DateTime.Now
|
|
};
|
|
detailLists.Add(newDetail);
|
|
}
|
|
try
|
|
{
|
|
if (detailLists.Count > 0)
|
|
{
|
|
Funs.DB.JGZL_NDTPerson.InsertAllOnSubmit(detailLists);
|
|
}
|
|
Funs.DB.SubmitChanges();
|
|
}
|
|
catch (Exception)
|
|
{
|
|
return;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region 导出按钮
|
|
/// 导出按钮
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
protected void btnOut_Click(object sender, EventArgs e)
|
|
{
|
|
string rootPath = Server.MapPath("~/");
|
|
string initTemplatePath = string.Empty;
|
|
string uploadfilepath = string.Empty;
|
|
string newUrl = string.Empty;
|
|
string filePath = string.Empty;
|
|
|
|
int maxrowCount = 22;
|
|
|
|
string projectId = this.tvControlItem.SelectedNodeID;
|
|
if (!string.IsNullOrEmpty(projectId))
|
|
{
|
|
string strSql = @"SELECT * from JGZL_NDTPerson where ProjectId = @ProjectId";
|
|
List<SqlParameter> listStr = new List<SqlParameter>();
|
|
listStr.Add(new SqlParameter("@ProjectId", projectId));
|
|
if (!string.IsNullOrEmpty(this.txtPersonNameS.Text))
|
|
{
|
|
strSql += " and PersonName like @personName";
|
|
listStr.Add(new SqlParameter("@personName", "%" + this.txtPersonNameS.Text + "%"));
|
|
}
|
|
strSql += " order by ValidityDate desc";
|
|
SqlParameter[] parameter = listStr.ToArray();
|
|
DataTable tb = SQLHelper.GetDataTableRunText(strSql, parameter);
|
|
|
|
initTemplatePath = Const.JGZL_NDTPersonUrl;
|
|
uploadfilepath = rootPath + initTemplatePath;
|
|
|
|
newUrl = uploadfilepath.Replace("无损检测人员登记表导出模板", "无损检测人员登记表");
|
|
if (File.Exists(newUrl))
|
|
{
|
|
File.Delete(newUrl);
|
|
}
|
|
File.Copy(uploadfilepath, newUrl);
|
|
//更新书签内容
|
|
Document doc = new Aspose.Words.Document(newUrl);
|
|
DocumentBuilder builder = new DocumentBuilder(doc);
|
|
|
|
Aspose.Words.Tables.Table table = (Aspose.Words.Tables.Table)doc.GetChild(NodeType.Table, 0, true);
|
|
|
|
Bookmark projectName = doc.Range.Bookmarks["ProjectName"];
|
|
if (projectName != null)
|
|
{
|
|
projectName.Text = BLL.Base_ProjectService.GetProjectByProjectId(projectId).ProjectName;
|
|
}
|
|
|
|
// 设置表头行重复显示
|
|
table.Rows[0].RowFormat.HeadingFormat = true;
|
|
table.Rows[1].RowFormat.HeadingFormat = true;
|
|
|
|
// 先记录页尾行,并从表格中移除
|
|
Row footerRow = table.Rows[table.Rows.Count - 2];
|
|
table.Rows.RemoveAt(table.Rows.Count - 2);
|
|
Row footerRow2 = table.Rows[table.Rows.Count - 1];
|
|
table.Rows.RemoveAt(table.Rows.Count - 1);
|
|
|
|
// 清空模板里的旧数据行,只保留2行表头(防止错位)
|
|
while (table.Rows.Count > 2)
|
|
{
|
|
table.Rows.RemoveAt(2);
|
|
}
|
|
Row headerRow = table.Rows[1]; // 字段名表头行
|
|
double[] colWidths = new double[6];
|
|
for (int i = 0; i < 6; i++)
|
|
{
|
|
colWidths[i] = headerRow.Cells[i].CellFormat.Width;
|
|
}
|
|
// 填充数据行
|
|
for (int i = 0; i < tb.Rows.Count; i++)
|
|
{
|
|
Row row = new Row(doc);
|
|
row.Cells.Add(CreateCell((i + 1).ToString(), doc, colWidths[0], "楷体", "10.5"));
|
|
row.Cells.Add(CreateCell(tb.Rows[i]["PersonName"].ToString(), doc, colWidths[1], "楷体", "10.5"));
|
|
row.Cells.Add(CreateCell(tb.Rows[i]["CertificateNumber"].ToString(), doc, colWidths[2], "楷体", "10.5"));
|
|
row.Cells.Add(CreateCell(tb.Rows[i]["QualifiedProjectCode"].ToString(), doc, colWidths[3], "楷体", "10.5"));
|
|
row.Cells.Add(CreateCell(tb.Rows[i]["Levels"].ToString(), doc, colWidths[4], "楷体", "10.5"));
|
|
row.Cells.Add(CreateCell(tb.Rows[i]["ValidityDate"].ToString(), doc, colWidths[5], "楷体", "10.5"));
|
|
table.Rows.Add(row);
|
|
}
|
|
// 不满一页,自动填充空白行
|
|
int realDataCount = tb.Rows.Count;
|
|
int needBlankRows = maxrowCount - realDataCount;
|
|
if (needBlankRows > 0)
|
|
{
|
|
for (int i = 0; i < needBlankRows; i++)
|
|
{
|
|
Row blankRow = new Row(doc);
|
|
blankRow.Cells.Add(CreateCell("", doc, colWidths[0], "楷体", "10.5"));
|
|
blankRow.Cells.Add(CreateCell("", doc, colWidths[1], "楷体", "10.5"));
|
|
blankRow.Cells.Add(CreateCell("", doc, colWidths[2], "楷体", "10.5"));
|
|
blankRow.Cells.Add(CreateCell("", doc, colWidths[3], "楷体", "10.5"));
|
|
blankRow.Cells.Add(CreateCell("", doc, colWidths[4], "楷体", "10.5"));
|
|
blankRow.Cells.Add(CreateCell("", doc, colWidths[5], "楷体", "10.5"));
|
|
table.Rows.Add(blankRow);
|
|
}
|
|
}
|
|
|
|
//把页尾行重新加回表格最后
|
|
table.Rows.Add(footerRow);
|
|
table.Rows.Add(footerRow2);
|
|
|
|
// 设置表格格式
|
|
table.AutoFit(AutoFitBehavior.FixedColumnWidths);
|
|
table.Alignment = TableAlignment.Center;
|
|
table.SetBorders(Aspose.Words.LineStyle.Single, 1, System.Drawing.Color.Black);
|
|
|
|
// 强制刷新所有单元格宽度,防止个别单元格宽度不生效
|
|
foreach (Row r in table.Rows)
|
|
{
|
|
foreach (Cell c in r.Cells)
|
|
{
|
|
c.CellFormat.Width = colWidths[c.ParentRow.Cells.IndexOf(c)];
|
|
}
|
|
}
|
|
doc.Save(newUrl);
|
|
|
|
string fileName = Path.GetFileName(newUrl);
|
|
FileInfo info = new FileInfo(newUrl);
|
|
long fileSize = info.Length;
|
|
Response.Clear();
|
|
Response.ContentType = "application/x-zip-compressed";
|
|
Response.AddHeader("Content-Disposition", "attachment;filename=" + System.Web.HttpUtility.UrlEncode(fileName, System.Text.Encoding.UTF8));
|
|
Response.AddHeader("Content-Length", fileSize.ToString());
|
|
Response.TransmitFile(newUrl, 0, fileSize);
|
|
Response.Flush();
|
|
Response.Close();
|
|
File.Delete(newUrl);
|
|
}
|
|
else
|
|
{
|
|
Alert.ShowInTop("请选择项目!", MessageBoxIcon.Warning);
|
|
return;
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 创建带字体、宽度的表格单元格
|
|
/// </summary>
|
|
private Cell CreateCell(string text, Document doc, double width, string fontName, string fontSize)
|
|
{
|
|
Cell cell = new Cell(doc);
|
|
cell.CellFormat.Width = width;
|
|
cell.CellFormat.LeftPadding = 2;
|
|
cell.CellFormat.RightPadding = 2;
|
|
cell.CellFormat.TopPadding = 2;
|
|
cell.CellFormat.BottomPadding = 2;
|
|
|
|
Paragraph para = new Paragraph(doc);
|
|
para.ParagraphFormat.Alignment = ParagraphAlignment.Center; // 居中
|
|
para.ParagraphFormat.SpaceAfter = 0;
|
|
para.ParagraphFormat.SpaceBefore = 0;
|
|
|
|
Run run = new Run(doc, text);
|
|
run.Font.Name = fontName; // 字体
|
|
run.Font.Size = Convert.ToDouble(fontSize); // 字号
|
|
|
|
para.AppendChild(run);
|
|
cell.AppendChild(para);
|
|
|
|
return cell;
|
|
}
|
|
#endregion
|
|
}
|
|
} |