Files
HJGL_DS/HJGL_DS/FineUIPro.Web/JGZL/ProcessHandoverRecord.aspx.cs
T

404 lines
16 KiB
C#

using Aspose.Words;
using BLL;
using FastReport;
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 System.Windows.Forms;
namespace FineUIPro.Web.JGZL
{
public partial class ProcessHandoverRecord : PageBase
{
#region 定义项
/// <summary>
/// 主键
/// </summary>
private string RecordId
{
get
{
return (string)ViewState["RecordId"];
}
set
{
ViewState["RecordId"] = value;
}
}
/// <summary>
/// 项目Id
/// </summary>
private string ProjectId
{
get
{
return (string)ViewState["ProjectId"];
}
set
{
ViewState["ProjectId"] = value;
}
}
#endregion
#region 加载页面
/// <summary>
/// 加载页面
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
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.ProjectId = this.tvControlItem.SelectedNodeID;
DataInfo();//加载数据
//this.BindGrid();
}
}
private void DataInfo()
{
this.txtExecutionStandard.Text = string.Empty;
this.txtOrganizationalUnit.Text = string.Empty;
this.txtHandoverUnit.Text = string.Empty;
this.txtReceivingUnit.Text = string.Empty;
this.txtInspectionResults.Text = string.Empty;
this.txtReceivingUnitOpinions.Text = string.Empty;
var report = BLL.ProcessHandoverRecordService.GetProcessHandoverRecordByProjectId(this.ProjectId);
if (report != null)
{
this.RecordId = report.RecordId;
this.txtExecutionStandard.Text = report.ExecutionStandard;
this.txtOrganizationalUnit.Text = report.OrganizationalUnit;
this.txtHandoverUnit.Text = report.HandoverUnit;
this.txtReceivingUnit.Text = report.ReceivingUnit;
this.txtInspectionResults.Text = report.InspectionResults;
this.txtReceivingUnitOpinions.Text = report.ReceivingUnitOpinions;
}
else
{
//默认值
this.txtExecutionStandard.Text = "SH/T3501-2021";
var user = BLL.Sys_UserService.GetUsersByUserId(this.CurrUser.UserId);
if (user != null)
{
if (!string.IsNullOrEmpty(user.DepartId))
{
this.txtOrganizationalUnit.Text = BLL.Base_DepartService.GetDepart(user.DepartId).DepartName;
}
}
this.txtInspectionResults.Text = "本项目所有管道组成件及管道支撑件,均已按照设计要求的防腐等级完成防腐施工,施工工序完整合规,经外观检查、涂层厚度检测等专项验收,防腐质量全部合格,无漏涂、破损、瑕疵等问题,符合后续安装施工条件,现正式办理防腐工序交接,移交安装单位施工,相关质保资料一并移交。";
}
}
#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")
{
DataInfo();
//this.BindGrid();
}
}
#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.ProjectId = this.tvControlItem.SelectedNodeID;
this.InitTreeMenu();
DataInfo();
}
/// <summary>
/// 查询
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void TextBox_TextChanged(object sender, EventArgs e)
{
//this.BindGrid();
DataInfo();
}
#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();
DataTable dt = new DataTable();
dt.TableName = "Data";
dt.Columns.Add("ExecutionStandard");
dt.Columns.Add("OrganizationalUnit");
dt.Columns.Add("HandoverUnit");
dt.Columns.Add("ReceivingUnit");
dt.Columns.Add("InspectionResults");
dt.Columns.Add("ReceivingUnitOpinions");
//string id = this.Grid1.SelectedRowID;
//if (!string.IsNullOrEmpty(id))
//{
//var report = BLL.ProcessHandoverRecordService.GetProcessHandoverRecordById(id);
//if (report!=null)
//{
var newRow = dt.NewRow();
newRow["ExecutionStandard"] = txtExecutionStandard.Text.Trim();
newRow["OrganizationalUnit"] = txtOrganizationalUnit.Text.Trim();
newRow["HandoverUnit"] = txtHandoverUnit.Text.Trim();
newRow["ReceivingUnit"] = txtReceivingUnit.Text.Trim();
newRow["InspectionResults"] = txtInspectionResults.Text;
newRow["ReceivingUnitOpinions"] =txtReceivingUnitOpinions.Text;
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);
// 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))
// {
//PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("ProcessHandoverRecordEdit.aspx?projectId={0}", this.tvControlItem.SelectedNodeID, "新增 - ")));
// }
// else
// {
// Alert.ShowInTop("请选择项目!", MessageBoxIcon.Warning);
// return;
// }
//}
#endregion
#region 提交按钮
/// <summary>
/// 提交按钮
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnSave_Click(object sender, EventArgs e)
{
if (CommonService.GetAllButtonPowerList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, Const.JGZL_ProcessHandoverRecordMenuId, Const.BtnSave))
{
Model.JGZL_ProcessHandoverRecord newReport = new Model.JGZL_ProcessHandoverRecord();
newReport.ExecutionStandard = this.txtExecutionStandard.Text.Trim();
newReport.OrganizationalUnit = this.txtOrganizationalUnit.Text.Trim();
newReport.HandoverUnit = this.txtHandoverUnit.Text.Trim();
newReport.ReceivingUnit = this.txtReceivingUnit.Text.Trim();
newReport.InspectionResults = this.txtInspectionResults.Text.Trim();
newReport.ReceivingUnitOpinions = this.txtReceivingUnitOpinions.Text.Trim();
if (!string.IsNullOrEmpty(this.RecordId))
{
newReport.RecordId = this.RecordId;
BLL.ProcessHandoverRecordService.UpdateProcessHandoverRecord(newReport);
}
else
{
newReport.ProjectId = this.ProjectId;
newReport.CompileMan = this.CurrUser.UserId;
newReport.CompileDate = DateTime.Now;
newReport.Reviewer = this.CurrUser.UserId;
newReport.RevieweDate = DateTime.Now;
newReport.RecordId = SQLHelper.GetNewID(typeof(Model.JGZL_ProcessHandoverRecord));
this.RecordId = newReport.RecordId;
BLL.ProcessHandoverRecordService.AddProcessHandoverRecord(newReport);
}
ShowNotify("保存成功!", MessageBoxIcon.Success);
//PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference());
}
else
{
Alert.ShowInTop("您没有这个权限,请与管理员联系!", MessageBoxIcon.Warning);
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;
string projectId = this.tvControlItem.SelectedNodeID;
if (!string.IsNullOrEmpty(projectId))
{
initTemplatePath = Const.JGZL_ProcessHandoverRecordUrl;
uploadfilepath = rootPath + initTemplatePath;
newUrl = uploadfilepath.Replace("工序交接记录导出模板", "工序交接记录");
if (File.Exists(newUrl))
{
File.Delete(newUrl);
}
File.Copy(uploadfilepath, newUrl);
Document doc = new Aspose.Words.Document(uploadfilepath);
Bookmark projectName = doc.Range.Bookmarks["ProjectName"];
if (projectName != null)
{
projectName.Text = BLL.Base_ProjectService.GetProjectByProjectId(projectId).ProjectName;
}
Bookmark executionStandard = doc.Range.Bookmarks["ExecutionStandard"];
if (executionStandard != null)
{
executionStandard.Text = this.txtExecutionStandard.Text;
}
Bookmark organizationalUnit = doc.Range.Bookmarks["OrganizationalUnit"];
if (organizationalUnit != null)
{
organizationalUnit.Text = this.txtOrganizationalUnit.Text;
}
Bookmark handoverUnit = doc.Range.Bookmarks["HandoverUnit"];
if (handoverUnit != null)
{
handoverUnit.Text = this.txtHandoverUnit.Text;
}
Bookmark receivingUnit = doc.Range.Bookmarks["ReceivingUnit"];
if (receivingUnit != null)
{
receivingUnit.Text = this.txtReceivingUnit.Text;
}
Bookmark inspectionResults = doc.Range.Bookmarks["InspectionResults"];
if (inspectionResults != null)
{
inspectionResults.Text = this.txtInspectionResults.Text;
}
Bookmark receivingUnitOpinions = doc.Range.Bookmarks["ReceivingUnitOpinions"];
if (receivingUnitOpinions != null)
{
receivingUnitOpinions.Text = this.txtReceivingUnitOpinions.Text;
}
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;
}
}
#endregion
}
}