Basf_TCC7/HJGL/FineUIPro.Web/WeldingProcess/PMI/PMIDelegation.aspx.cs

570 lines
21 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 System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Data;
using System.Linq;
using NPOI.SS.UserModel;
using NPOI.XSSF.UserModel;
namespace FineUIPro.Web.WeldingProcess.PMI
{
public partial class PMIDelegation : PageBase
{
#region
/// <summary>
/// PMI委托主键
/// </summary>
public string PMIDelegationId
{
get
{
return (string)ViewState["PMIDelegationId"];
}
set
{
ViewState["PMIDelegationId"] = value;
}
}
#endregion
#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.PMIDelegationId = string.Empty;
this.InitTreeMenu();//加载树
}
}
#endregion
#region
/// <summary>
/// 加载树
/// </summary>
private void InitTreeMenu()
{
string projectName = string.Empty;
var pro = BLL.Base_ProjectService.GetProjectByProjectId(this.CurrUser.LoginProjectId);
if (pro != null)
{
this.tvControlItem.Nodes.Clear();
TreeNode rootNode = new TreeNode();
rootNode.Text = "[" + pro.ProjectCode + "]" + pro.ProjectName;
rootNode.NodeID = "0";
rootNode.Expanded = true;
rootNode.EnableClickEvent = true;
this.tvControlItem.Nodes.Add(rootNode);
List<Model.PMI_Delegation> trustLists = new List<Model.PMI_Delegation>(); ///PMI委托单
if (!string.IsNullOrEmpty(this.txtSearchNo.Text.Trim()))
{
trustLists = (from x in Funs.DB.PMI_Delegation where x.ProjectId == CurrUser.LoginProjectId && x.DelegationNo.Contains(this.txtSearchNo.Text.Trim()) orderby x.DelegationNo select x).ToList();
}
else
{
trustLists = (from x in Funs.DB.PMI_Delegation where x.ProjectId == CurrUser.LoginProjectId orderby x.DelegationNo select x).ToList();
}
this.BindNodes(rootNode, trustLists);
}
}
#endregion
#region
/// <summary>
/// 绑定树节点
/// </summary>
/// <param name="node"></param>
private void BindNodes(TreeNode node, List<Model.PMI_Delegation> trustList)
{
foreach (var item in trustList)
{
TreeNode newNode = new TreeNode();
newNode.Text = item.DelegationNo;
newNode.NodeID = item.Id;
newNode.ToolTip = item.DelegationNo;
newNode.CommandName = Resources.Lan.RequestSheetNumber;
newNode.EnableClickEvent = true;
node.Nodes.Add(newNode);
}
}
#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.PMIDelegationId = tvControlItem.SelectedNodeID;
this.BindGrid();
}
}
#endregion
#region DropDownList下拉选择事件
/// <summary>
/// 项目下拉选择事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void drpProjectId_SelectedIndexChanged(object sender, EventArgs e)
{
this.InitTreeMenu();
}
#endregion
#region
/// <summary>
/// 数据绑定
/// </summary>
private void BindGrid()
{
string strSql = string.Empty;
List<SqlParameter> listStr = new List<SqlParameter>();
this.SetTextTemp();
this.PageInfoLoad(); ///页面输入提交信息
if (!string.IsNullOrEmpty(this.tvControlItem.SelectedNodeID))
{
var result = Funs.DB.PMI_Delegation.FirstOrDefault(t=>t.Id==this.tvControlItem.SelectedNodeID);
if (result != null)
{
this.PMIDelegationId = result.Id;
strSql = @"SELECT *FROM [View_PMI_DelegationDetails] WHERE ProjectId= @ProjectId AND PMIID=@PMIDelegationId ";
listStr.Add(new SqlParameter("@ProjectId", result != null ? result.ProjectId : this.CurrUser.LoginProjectId));
listStr.Add(new SqlParameter("@PMIDelegationId", this.PMIDelegationId));
if (!string.IsNullOrEmpty(this.txtIsoNo.Text.Trim()))
{
strSql += @" and PipelineCode like '%'+@PipelineCode+'%' ";
listStr.Add(new SqlParameter("@PipelineCode", this.txtIsoNo.Text.Trim()));
}
SqlParameter[] parameter = listStr.ToArray();
DataTable tb = SQLHelper.GetDataTableRunText(strSql, parameter);
// 2.获取当前分页数据
//var table = this.GetPagedDataTable(Grid1, tb1);
Grid1.RecordCount = tb.Rows.Count;
//tb = GetFilteredTable(Grid1.FilteredData, tb);
var table = this.GetPagedDataTable(Grid1, tb);
Grid1.DataSource = table;
Grid1.DataBind();
}
}
}
/// <summary>
/// 查询
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void TextBox_TextChanged(object sender, EventArgs e)
{
this.BindGrid();
}
#region
/// <summary>
/// 加载页面输入提交信息
/// </summary>
private void PageInfoLoad()
{
var trust =Funs.DB.PMI_Delegation.FirstOrDefault(t=>t.Id==this.PMIDelegationId);
if (trust != null)
{
this.txtDelegationNo.Text = trust.DelegationNo;
if (trust.DelegationDate.HasValue)
{
this.txtDelegationDate.Text = string.Format("{0:yyyy-MM-dd}", trust.DelegationDate);
}
if (!string.IsNullOrEmpty(trust.InstallationId))
{
this.txtInstallationName.Text = BLL.Project_InstallationService.GetProject_InstallationNameByInstallationId(trust.InstallationId);
}
if (!string.IsNullOrEmpty(trust.UnitId))
{
this.txtUnitName.Text = BLL.Base_UnitService.GetUnitNameByUnitId(trust.UnitId);
}
this.txtDetectionMethod.Text = "PMI光谱分析";
this.txtDetectionStandard.Text = trust.DetectionStandard;
if (!string.IsNullOrEmpty(trust.Tabler))
{
this.txtTabler.Text = BLL.Sys_UserService.GetUserNameByUserId(trust.Tabler);
}
this.txtRemark.Text = trust.Remark;
}
}
#endregion
#region
/// <summary>
/// 清空文本
/// </summary>
private void SetTextTemp()
{
this.txtDelegationNo.Text = string.Empty;
this.txtDelegationDate.Text = string.Empty;
this.txtInstallationName.Text = string.Empty;
this.txtUnitName.Text = string.Empty;
this.txtDetectionMethod.Text = string.Empty;
this.txtDetectionStandard.Text = string.Empty;
this.txtTabler.Text = string.Empty;
this.txtRemark.Text = string.Empty;
}
#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 PMI委托
/// <summary>
/// 增加PMI委托
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnNew_Click(object sender, EventArgs e)
{
if (CommonService.GetAllButtonPowerList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, Const.PMIDelegationMenuId, Const.BtnAdd))
{
this.SetTextTemp();
string window = String.Format("PMIDelegationEdit.aspx?PMIDelegationId={0}", string.Empty, "新增 - ") ;
PageContext.RegisterStartupScript(Window2.GetSaveStateReference(this.hdPMIDelegationId.ClientID)
+ Window2.GetShowReference(window));
}
else
{
ShowNotify(Resources.Lan.NoPrivilegePrompt, MessageBoxIcon.Warning);
}
}
#region PMI委托
/// <summary>
/// 编辑PMI委托
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnEdit_Click(object sender, EventArgs e)
{
if (CommonService.GetAllButtonPowerList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, Const.HotProessTrustMenuId, Const.BtnSave))
{
var trustManage = Funs.DB.PMI_Delegation.FirstOrDefault (t=>t.Id==this.PMIDelegationId);
if (trustManage != null)
{
string openUrl = String.Format("PMIDelegationEdit.aspx?PMIDelegationId={0}", this.PMIDelegationId, "编辑 - ");
PageContext.RegisterStartupScript(Window2.GetSaveStateReference(this.hdPMIDelegationId.ClientID)
+ Window2.GetShowReference(openUrl));
}
else
{
ShowNotify("请选择要处理的PMI委托", MessageBoxIcon.Warning);
}
}
else
{
ShowNotify(Resources.Lan.NoPrivilegePrompt, MessageBoxIcon.Warning);
}
}
#endregion
#region PMI委托
/// <summary>
/// 删除PMI委托
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnDelete_Click(object sender, EventArgs e)
{
if (CommonService.GetAllButtonPowerList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, Const.PMIDelegationMenuId, Const.BtnDelete))
{
var trustManage =Funs.DB.PMI_Delegation.FirstOrDefault (t=>t.Id==this.PMIDelegationId);
if (trustManage != null)
{
//删除主表数据
Funs.DB.PMI_Delegation.DeleteOnSubmit(trustManage);
//删除 明细表
var details = Funs.DB.PMI_DelegationDetails.Where(t => t.PMIId == trustManage.Id).ToList();
Funs.DB.PMI_DelegationDetails.DeleteAllOnSubmit(details);
Funs.DB.SubmitChanges();
Alert.ShowInTop(Resources.Lan.DeletedSuccessfully, MessageBoxIcon.Success);
this.InitTreeMenu();
SetTextTemp();
this.Grid1.DataSource = null;
this.Grid1.DataBind();
}
else
{
ShowNotify(Resources.Lan.PleaseSelectDeleteHotProessTrust, MessageBoxIcon.Warning);
}
}
else
{
ShowNotify(Resources.Lan.NoPrivilegePrompt, MessageBoxIcon.Warning);
return;
}
}
#endregion
#endregion
#region
/// <summary>
/// 关闭弹出窗口
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Window2_Close(object sender, WindowCloseEventArgs e)
{
this.InitTreeMenu();
this.BindGrid();
}
#region
/// <summary>
/// 查询
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Tree_TextChanged(object sender, EventArgs e)
{
this.InitTreeMenu();
}
#endregion
#endregion
protected void btnExport_Click(object sender, EventArgs e)
{
Alert.ShowInTop("待开发!", MessageBoxIcon.Warning);
return;
//if (CommonService.GetAllButtonPowerList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, Const.HJGL_BatchTrustMenuId, Const.BtnOut))
//{
// if (string.IsNullOrWhiteSpace(this.tvControlItem.SelectedNodeID))
// {
// Alert.ShowInTop("请选择委托单!", MessageBoxIcon.Warning);
// return;
// }
// string rootPath = Server.MapPath("~/") + Const.ExcelUrl;
// //导出文件
// string filePath = rootPath + DateTime.Now.ToString("yyyyMMddhhmmss") + "\\";
// if (!Directory.Exists(filePath))
// {
// Directory.CreateDirectory(filePath);
// }
// string ReportFileName = filePath + "out1.xlsx";
// int rowIndex = 0;
// XSSFWorkbook hssfworkbook = new XSSFWorkbook();
// XSSFSheet ws = new XSSFSheet();
// string trustBatchId = this.tvControlItem.SelectedNodeID;
//}
//else
//{
// ShowNotify(Resources.Lan.NoPrivilegePrompt, MessageBoxIcon.Warning);
//}
}
#region
/// <summary>
/// 获取某一列的所有值
/// </summary>
/// <typeparam name="T">列数据类型</typeparam>
/// <param name="dtSource">数据表</param>
/// <param name="filedName">列名</param>
/// <returns></returns>
public static List<T> GetColumnValues<T>(DataTable dtSource, string filedName)
{
return (from r in dtSource.AsEnumerable() select r.Field<T>(filedName)).ToList<T>();
}
/// <summary>
/// 无损检测委托单行和列
/// </summary>
/// <returns></returns>
private XSSFSheet WsExcelCreateRow(XSSFSheet ws, XSSFWorkbook hssfworkbook, int sRows, int eRows, ICellStyle style, int cStart, int cEnd, int excelpart, bool isnobk = false)
{
for (int i = sRows; i <= eRows; i++)
{
ws.CreateRow(i);
if (excelpart == 1)
{
ws.GetRow(i).HeightInPoints =
i == sRows ? 27.75f :
i == (sRows + 1) ? 25.5f :
i == (sRows + 2) ? 25.5f :
i == (sRows + 3) ? 25.5f :
i == (sRows + 4) ? 23.25f :
i == (sRows + 5) ? 23.25f :
i == (sRows + 6) ? 23.25f :
i == (sRows + 7) ? 23.25f :
i == (sRows + 8) ? 23.25f :
i == (sRows + 9) ? 23.25f :
i == (sRows + 10) ? 23.25f :
i == (sRows + 11) ? 23.25f :
i == (sRows + 12) ? 23.25f :
17f;
}
else if (excelpart == 2)
{
ws.GetRow(i).HeightInPoints = 25.5f;
}
else
{
ws.GetRow(i).HeightInPoints = 15.5f;
}
for (int j = cStart; j <= cEnd; j++)
{
ws.GetRow(i).CreateCell(j);
if (isnobk)
{
ws.GetRow(i).GetCell(j).CellStyle = CommonPrint.SetExcelStyle(hssfworkbook, BorderStyle.None, BorderStyle.None, BorderStyle.None, BorderStyle.None, VerticalAlignment.Center, HorizontalAlignment.Center, 10.5, true, false);
}
else
{
ws.GetRow(i).GetCell(j).CellStyle = style;
}
}
}
return ws;
}
/// <summary>
/// 材料及配件检测委托单行和列
/// </summary>
/// <returns></returns>
private XSSFSheet ClExcelCreateRow(XSSFSheet ws, XSSFWorkbook hssfworkbook, int sRows, int eRows, ICellStyle style, int cStart, int cEnd, bool istitle = false, bool isnobk = false)
{
for (int i = sRows; i <= eRows; i++)
{
ws.CreateRow(i);
if (istitle)
{
ws.GetRow(i).HeightInPoints =
i == sRows ? 27.75f :
i == (sRows + 1) ? 25f :
i == (sRows + 2) ? 21.75f :
i == (sRows + 3) ? 21.75f :
i == (sRows + 5) ? 28f :
14.75f;
}
else
{
ws.GetRow(i).HeightInPoints = 14.75f;
}
for (int j = cStart; j <= cEnd; j++)
{
ws.GetRow(i).CreateCell(j);
if (isnobk)
{
ws.GetRow(i).GetCell(j).CellStyle = CommonPrint.SetExcelStyle(hssfworkbook, BorderStyle.None, BorderStyle.None, NPOI.SS.UserModel.BorderStyle.None, NPOI.SS.UserModel.BorderStyle.None, VerticalAlignment.Center, HorizontalAlignment.Center, 10, true, false);
}
else
{
ws.GetRow(i).GetCell(j).CellStyle = style;
}
}
}
return ws;
}
/// <summary>
/// 查询指定条数分页
/// </summary>
/// <returns></returns>
public static DataTable GetPageToTable(DataTable dt, int StartNum, int EndNum)
{
//0页代表每页数据直接返回
if (EndNum == 0) return dt;
//数据源为空返回空DataTable
if (dt == null) return new DataTable();
DataTable newdt = dt.Copy();
newdt.Clear();//copy dt的框架
if (StartNum >= dt.Rows.Count)
return newdt;//源数据记录数小于等于要显示的记录直接返回dt
if (EndNum > dt.Rows.Count)
EndNum = dt.Rows.Count;
for (int i = StartNum; i <= EndNum - 1; i++)
{
DataRow newdr = newdt.NewRow();
DataRow dr = dt.Rows[i];
foreach (DataColumn column in dt.Columns)
{
newdr[column.ColumnName] = dr[column.ColumnName];
}
newdt.Rows.Add(newdr);
}
return newdt;
}
#endregion
#region
/// <summary>
/// 获取按钮权限
/// </summary>
/// <param name="button"></param>
/// <returns></returns>
private bool GetButtonPower(string button)
{
return BLL.CommonService.GetAllButtonPowerList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, BLL.Const.DailyReportCompleteMenuId, button);
}
#endregion
}
}