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

298 lines
11 KiB
C#

using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using BLL;
using System.Web;
using System.Collections;
using Model;
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
namespace FineUIPro.Web.WeldingProcess.PMI
{
public partial class PMIDetectionEntry : PageBase
{
#region
/// <summary>
/// 检测单主键
/// </summary>
public string PMIID
{
get
{
return (string)ViewState["PMIID"];
}
set
{
ViewState["PMIID"] = value;
}
}
#endregion
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
this.txtNDEDateMonth.Text = string.Format("{0:yyyy-MM}", DateTime.Now);
this.ddlPageSize.SelectedValue = this.Grid1.PageSize.ToString();
this.PMIID = string.Empty;
this.InitTreeMenu();//加载树
}
}
#region
/// <summary>
/// 加载树
/// </summary>
private void InitTreeMenu()
{
if (!string.IsNullOrEmpty(this.txtNDEDateMonth.Text.Trim()))
{
DateTime startTime = Convert.ToDateTime(this.txtNDEDateMonth.Text.Trim() + "-01");
DateTime endTime = startTime.AddMonths(1);
this.tvControlItem.Nodes.Clear();
List<Model.Base_Unit> units = new List<Model.Base_Unit>();
Model.Project_Unit pUnit = BLL.Project_UnitService.GetProject_UnitByProjectIdUnitId(this.CurrUser.LoginProjectId, this.CurrUser.UnitId);
if (pUnit == null || pUnit.UnitType == BLL.Const.UnitType_1 || pUnit.UnitType == BLL.Const.UnitType_2
|| pUnit.UnitType == BLL.Const.UnitType_3 || pUnit.UnitType == BLL.Const.UnitType_4
|| pUnit.UnitType == BLL.Const.UnitType_6)
{
units = (from x in Funs.DB.Base_Unit
join y in Funs.DB.Project_Unit on x.UnitId equals y.UnitId
where y.ProjectId == this.CurrUser.LoginProjectId && y.UnitType.Contains(BLL.Const.UnitType_5)
select x).ToList();
}
else
{
units.Add(BLL.Base_UnitService.GetUnit(this.CurrUser.UnitId));
}
if (units != null)
{
foreach (var unit in units)
{
TreeNode newNode = new TreeNode();//定义根节点
newNode.Text = unit.UnitName;
newNode.NodeID = unit.UnitId;
newNode.Expanded = true;
newNode.ToolTip = "Unit";
this.tvControlItem.Nodes.Add(newNode);
this.BindNodes(newNode);
}
}
else
{
Alert.ShowInTop(Resources.Lan.PleaseAddUnitFirst, MessageBoxIcon.Warning);
}
}
else
{
Alert.ShowInTop(Resources.Lan.PleaseSelectTrustMonth, MessageBoxIcon.Warning);
}
}
/// <summary>
/// 绑定树节点
/// </summary>
/// <param name="node"></param>
private void BindNodes(TreeNode node)
{
if (node.ToolTip == "Unit")
{
///装置
var install = (from x in Funs.DB.Project_Installation
join y in Funs.DB.PMI_Delegation on x.InstallationId equals y.InstallationId
where y.UnitId == node.NodeID && x.ProjectId == this.CurrUser.LoginProjectId
orderby x.InstallationCode
select x).Distinct();
foreach (var q in install)
{
TreeNode newNode = new TreeNode();
newNode.Text = q.InstallationName;
newNode.NodeID = q.InstallationId + "|" + node.NodeID;
newNode.ToolTip = "Installation";
node.Nodes.Add(newNode);
BindNodes(newNode);
}
}
else if (node.ToolTip == "Installation")
{
string[] unitAndInstallationArr= node.NodeID.Split('|');
var ndt = from x in Funs.DB.PMI_Delegation where x.UnitId == unitAndInstallationArr[1]
&& x.InstallationId == unitAndInstallationArr[0]
&& x.ProjectId == this.CurrUser.LoginProjectId select x;
foreach (var q in ndt)
{
TreeNode newNode = new TreeNode();
newNode.Text = q.DelegationNo;
newNode.NodeID = q.Id;
newNode.ToolTip = "DelegationNo";
newNode.EnableClickEvent = true;
node.Nodes.Add(newNode);
BindNodes(newNode);
}
}
}
#endregion
#region TreeView
/// <summary>
/// 点击TreeView
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void tvControlItem_NodeCommand(object sender, TreeCommandEventArgs e)
{
this.PMIID = tvControlItem.SelectedNodeID;
this.hdPMIId.Text = this.PMIID;
this.BindGrid();
}
#endregion
#region
protected void TextBox_TextChanged(object sender, EventArgs e)
{
this.BindGrid();
}
/// <summary>
/// 数据绑定
/// </summary>
private void BindGrid()
{
if (!string.IsNullOrWhiteSpace(this.hdPMIId.Text) && this.tvControlItem.SelectedNode.ToolTip == "DelegationNo")
{
this.SetTextTemp();
this.PageInfoLoad(); ///页面输入提交信息
}
}
#region
/// <summary>
/// 加载页面输入提交信息
/// </summary>
private void PageInfoLoad()
{
this.SimpleForm1.Reset(); ///重置所有字段
var pageInfo = (from x in Funs.DB.PMI_Delegation
join y in Funs.DB.Base_Unit on x.UnitId equals y.UnitId
join n in Funs.DB.Project_Installation on x.InstallationId equals n.InstallationId
join u in Funs.DB.Sys_User on x.DetectionStandard equals u.UserId into u1 //左连接查询
from u in u1.DefaultIfEmpty()
where x.Id==hdPMIId.Text
select new { DelegationNo=x.DelegationNo,
DelegationDate=x.DelegationDate,
InstallationName=n.InstallationName,
UnitName=y.UnitName,
DetectionMethod="待定",
Tabler=x.Tabler,
Remark=x.Remark,
}).ToList();
if (pageInfo.Count>0)
{
this.txtDelegationNo.Text = pageInfo[0].DelegationNo;
this.txtDelegationDate.Text = pageInfo[0].DelegationDate.ToString();
this.txtInstallationName.Text = pageInfo[0].InstallationName;
this.txtUnitName.Text = pageInfo[0].UnitName;
this.txtDetectionMethod.Text = pageInfo[0].DetectionMethod;
this.txtTabler.Text = pageInfo[0].Tabler;
this.txtRemark.Text = pageInfo[0].Remark;
}
}
#endregion
/// <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.txtTabler.Text = string.Empty;
this.txtRemark.Text = string.Empty;
}
#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 Tree_TextChanged(object sender, EventArgs e)
{
this.InitTreeMenu();
//this.BindGrid();
}
#endregion
#region
/// <summary>
/// 获取缺陷
/// </summary>
/// <param name="bigType"></param>
/// <returns></returns>
protected string ConvertCheckDefects(object CheckDefects)
{
string str = string.Empty;
if (CheckDefects != null)
{
HttpCookie lanCookie = Request.Cookies["SelectLan"];
if (lanCookie["lan"] == "zh-CN") //中文
{
str = BLL.Base_DefectService.GetDefectNameStrByDefectIdStr(CheckDefects.ToString());
}
else
{
str = BLL.Base_DefectService.GetDefectEngNameStrByDefectIdStr(CheckDefects.ToString());
}
}
return str;
}
#endregion
}
}