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; using FineUIPro.Web.common.ProjectSet; using Newtonsoft.Json.Linq; namespace FineUIPro.Web.WeldingProcess.PMI { public partial class PMIDetectionEntry : PageBase { #region 定义项 /// /// 检测单主键 /// 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 加载树 /// /// 加载树 /// private void InitTreeMenu() { if (!string.IsNullOrEmpty(this.txtNDEDateMonth.Text.Trim())) { this.tvControlItem.Nodes.Clear(); List units = new List(); 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); } } /// /// 绑定树节点 /// /// private void BindNodes(TreeNode node) { DateTime startTime = Convert.ToDateTime(this.txtNDEDateMonth.Text.Trim() + "-01"); DateTime endTime = startTime.AddMonths(1); string searchCode = this.txtSearchCode.Text.Trim(); if (node.ToolTip == "Unit") { string unitId = node.NodeID; var ndt = from x in Funs.DB.PMI_Delegation where x.UnitId == unitId && x.ProjectId == this.CurrUser.LoginProjectId && x.DelegationDate >= startTime && x.DelegationDate <= endTime && (x.DelegationNo.Contains(searchCode) || searchCode == "") select x; //if (!string.IsNullOrWhiteSpace(searchCode)) // ndt = ndt.Where(q => q.DelegationNo.Contains(searchCode)); 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 /// /// 点击TreeView /// /// /// 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(); } /// /// 数据绑定 /// private void BindGrid() { if (!string.IsNullOrWhiteSpace(this.hdPMIId.Text) && this.tvControlItem.SelectedNode.ToolTip == "DelegationNo") { string strSql = string.Empty; List listStr = new List(); 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.PMIID = result.Id; strSql = @"SELECT *, (case status when 0 then '合格' else '不合格' end) StatusText 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.PMIID)); 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(); } } } } #region 加载页面输入提交信息 /// /// 加载页面输入提交信息 /// 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 == this.PMIID select new { DelegationNo = x.DelegationNo, DelegationDate = x.DelegationDate, InstallationName = n.InstallationName, UnitName = y.UnitName, DetectionMethod = "PMI光谱分析", Tabler = x.Tabler, Remark = x.Remark, DetectionStandard = x.DetectionStandard, }).ToList(); if (pageInfo.Count > 0) { this.txtDelegationNo.Text = pageInfo[0].DelegationNo; this.txtDelegationDate.Text = pageInfo[0].DelegationDate.Value.ToString("yyyy-MM-dd"); this.txtInstallationName.Text = pageInfo[0].InstallationName; this.txtUnitName.Text = pageInfo[0].UnitName; this.txtDetectionMethod.Text = pageInfo[0].DetectionMethod; this.txtTabler.Text = BLL.Sys_UserService.GetUserNameByUserId(pageInfo[0].Tabler); this.txtRemark.Text = pageInfo[0].Remark; this.txtDetectionStandard.Text = pageInfo[0].DetectionStandard; } } #endregion /// /// 清空 /// 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; this.txtDetectionStandard.Text = string.Empty; } #endregion #region 分页排序 #region 页索引改变事件 /// /// 页索引改变事件 /// /// /// protected void Grid1_PageIndexChange(object sender, GridPageEventArgs e) { BindGrid(); } #endregion #region 排序 /// /// 排序 /// /// /// protected void Grid1_Sort(object sender, GridSortEventArgs e) { BindGrid(); } #endregion #region 分页选择下拉改变事件 /// /// 分页选择下拉改变事件 /// /// /// protected void ddlPageSize_SelectedIndexChanged(object sender, EventArgs e) { Grid1.PageSize = Convert.ToInt32(ddlPageSize.SelectedValue); BindGrid(); } #endregion #endregion #region 关闭弹出窗口及刷新页面 /// /// 查询 /// /// /// protected void Tree_TextChanged(object sender, EventArgs e) { this.InitTreeMenu(); //this.BindGrid(); } #endregion #region 格式化字符串 /// /// 获取缺陷 /// /// /// 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 /// /// /// /// /// protected void btnSave_Click(object sender, EventArgs e) { if (!CommonService.GetAllButtonPowerList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, Const.PMIDetectionEntryMenuId, Const.BtnSave)) { ShowNotify("您没有这个权限,请与管理员联系!"); return; } if (Grid1.GetModifiedData().Count > 0) { JArray teamGroupData = Grid1.GetMergedData(); foreach (JObject teamGroupRow in teamGroupData) { string status = teamGroupRow.Value("status"); if (status == "modified") { JObject values = teamGroupRow.Value("values"); string id = teamGroupRow.Value("id"); Model.PMI_DelegationDetails onePMIDelegationDetails = Funs.DB.PMI_DelegationDetails.FirstOrDefault(p => p.Id == id); if (onePMIDelegationDetails == null) continue; //检测日期(缺失) string checkTime = values.Value("checkTime"); if (string.IsNullOrWhiteSpace(checkTime)) onePMIDelegationDetails.CheckTime = null; else onePMIDelegationDetails.CheckTime = Convert.ToDateTime(checkTime); //报告日期 string reportTime = values.Value("reportTime"); if (string.IsNullOrWhiteSpace(reportTime)) onePMIDelegationDetails.ReportTime = null; else onePMIDelegationDetails.ReportTime = Convert.ToDateTime(reportTime); //报告编号 onePMIDelegationDetails.ReportNo = values.Value("reportNo").ToString(); //是否合格 0合格 1不合格 string statusText = values.Value("StatusText"); if (statusText == "合格") onePMIDelegationDetails.Status = 0; else onePMIDelegationDetails.Status = 1; Funs.DB.SubmitChanges(); } } this.BindGrid(); } ShowNotify(Resources.Lan.SaveSuccessfully, MessageBoxIcon.Success); } } }