356 lines
14 KiB
C#
356 lines
14 KiB
C#
using Aspose.Words;
|
|
using Aspose.Words.Tables;
|
|
using BLL;
|
|
using FineUIPro.Web.common.BaseInfo;
|
|
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;
|
|
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
|
|
|
|
namespace FineUIPro.Web.JGZL
|
|
{
|
|
public partial class QualifiedWelder : PageBase
|
|
{
|
|
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();
|
|
}
|
|
}
|
|
|
|
#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>
|
|
///<param name="sender"></param>
|
|
///<param name="e"></param>
|
|
protected void drpProjectId_SelectedIndexChanged(object sender, EventArgs e)
|
|
{
|
|
this.InitTreeMenu();
|
|
this.BindGrid();
|
|
}
|
|
#endregion
|
|
|
|
#region 数据绑定
|
|
/// <summary>
|
|
/// 数据绑定
|
|
/// </summary>
|
|
private void BindGrid()
|
|
{
|
|
List<SqlParameter> listStr = new List<SqlParameter>();
|
|
listStr.Add(new SqlParameter("@projectId", this.tvControlItem.SelectedNodeID));
|
|
if (!string.IsNullOrEmpty(this.txtName.Text.Trim()))
|
|
{
|
|
listStr.Add(new SqlParameter("@WED_Name", "%" + this.txtName.Text.Trim() + "%"));
|
|
}
|
|
SqlParameter[] parameter = listStr.ToArray();
|
|
DataTable tb = BLL.SQLHelper.GetDataTableRunProc("sp_rpt_WelderQualified", parameter);
|
|
|
|
// 2.获取当前分页数据
|
|
Grid1.RecordCount = tb.Rows.Count;
|
|
var table = this.GetPagedDataTable(Grid1, tb);
|
|
Grid1.DataSource = table;
|
|
Grid1.DataBind();
|
|
}
|
|
#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 btnPrint_Click(object sender, EventArgs e)
|
|
{
|
|
string projectId = this.tvControlItem.SelectedNodeID;
|
|
if (projectId != null)
|
|
{
|
|
string initTemplatePath = "";
|
|
string rootPath = Server.MapPath("~/");
|
|
BLL.Common.FastReportService.ResetData();
|
|
|
|
List<SqlParameter> listStr = new List<SqlParameter>();
|
|
listStr.Add(new SqlParameter("@projectId", projectId));
|
|
if (!string.IsNullOrEmpty(this.txtName.Text.Trim()))
|
|
{
|
|
listStr.Add(new SqlParameter("@WED_Name", "%" + this.txtName.Text.Trim() + "%"));
|
|
}
|
|
SqlParameter[] parameter = listStr.ToArray();
|
|
DataTable tb = BLL.SQLHelper.GetDataTableRunProc("sp_rpt_WelderQualified", parameter);
|
|
|
|
DataTable dt = new DataTable();
|
|
dt.TableName = "Data";
|
|
dt.Columns.Add("Number");
|
|
dt.Columns.Add("WED_Name");
|
|
dt.Columns.Add("WED_Code");
|
|
dt.Columns.Add("CertificateNo");
|
|
dt.Columns.Add("QualifiedProjectCode");
|
|
dt.Columns.Add("LimitDate");
|
|
|
|
tb.DefaultView.Sort = "Number asc";
|
|
DataRow[] rows = tb.DefaultView.ToTable().Select();
|
|
foreach (var row in rows)
|
|
{
|
|
var newRow = dt.NewRow();
|
|
newRow["Number"] = row["Number"].ToString();
|
|
newRow["WED_Name"] = row["WED_Name"].ToString();
|
|
newRow["WED_Code"] = row["WED_Code"].ToString();
|
|
newRow["CertificateNo"] = row["CertificateNo"].ToString();
|
|
newRow["QualifiedProjectCode"] = row["QualifiedProjectCode"].ToString();
|
|
newRow["LimitDate"] = row["LimitDate"].ToString();
|
|
dt.Rows.Add(newRow);
|
|
}
|
|
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);
|
|
}
|
|
}
|
|
#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;
|
|
|
|
string projectId = this.tvControlItem.SelectedNodeID;
|
|
if (!string.IsNullOrEmpty(projectId))
|
|
{
|
|
List<SqlParameter> listStr = new List<SqlParameter>();
|
|
listStr.Add(new SqlParameter("@projectId", projectId));
|
|
if (!string.IsNullOrEmpty(this.txtName.Text.Trim()))
|
|
{
|
|
listStr.Add(new SqlParameter("@WED_Name", "%" + this.txtName.Text.Trim() + "%"));
|
|
}
|
|
SqlParameter[] parameter = listStr.ToArray();
|
|
DataTable tb = BLL.SQLHelper.GetDataTableRunProc("sp_rpt_WelderQualified", parameter);
|
|
|
|
initTemplatePath = Const.JGZL_QualifiedWelderUrl;
|
|
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);
|
|
}
|
|
|
|
// 单位:磅 1.69cm ≈ 48磅
|
|
double col1 = 0.93 * 28.35; // 序号
|
|
double col2 = 1.7 * 28.35; // 焊工姓名
|
|
double col3 = 2.19 * 28.35; // 焊工代号
|
|
double col4 = 3.95 * 28.35; // 证书编号
|
|
double col5 = 6.04 * 28.35; // 合格项目代号
|
|
double col6 = 2.27 * 28.35; // 有效日期
|
|
|
|
for (int i = 0; i < tb.Rows.Count; i++)
|
|
{
|
|
//创建行
|
|
Row row = new Row(doc);
|
|
row.Cells.Add(CreateCell((i + 1).ToString(), doc, col1, "", ""));
|
|
row.Cells.Add(CreateCell(tb.Rows[i]["WED_Name"].ToString(), doc, col2, "", ""));
|
|
row.Cells.Add(CreateCell(tb.Rows[i]["WED_Code"].ToString(), doc, col3, "", ""));
|
|
row.Cells.Add(CreateCell(tb.Rows[i]["CertificateNo"].ToString(), doc, col4, "", ""));
|
|
row.Cells.Add(CreateCell(tb.Rows[i]["QualifiedProjectCode"].ToString(), doc, col5, "", ""));
|
|
row.Cells.Add(CreateCell(tb.Rows[i]["LimitDate"].ToString(), doc, col6, "", ""));
|
|
table.Rows.Add(row);
|
|
}
|
|
|
|
//把页尾行重新加回表格最后
|
|
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);
|
|
|
|
|
|
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;
|
|
}
|
|
}
|
|
private Cell CreateCell(string text, Document doc, double width, string bgColor, string align)
|
|
{
|
|
Cell cell = new Cell(doc);
|
|
cell.AppendChild(new Paragraph(doc));
|
|
cell.FirstParagraph.AppendChild(new Run(doc, text));
|
|
cell.CellFormat.Width = width;
|
|
return cell;
|
|
}
|
|
#endregion
|
|
|
|
protected void txtName_TextChanged(object sender, EventArgs e)
|
|
{
|
|
BindGrid();
|
|
}
|
|
}
|
|
} |