using System; using System.Collections.Generic; using System.Data; using System.Data.SqlClient; using System.Linq; using BLL; using Newtonsoft.Json.Linq; using System.Web; namespace FineUIPro.Web.HJGL.HotHardManage { public partial class HotHardManageEdit : PageBase { #region 定义项 /// /// 硬度委托主键 /// public string HardTestReportId { get { return (string)ViewState["HardTestReportId"]; } set { ViewState["HardTestReportId"] = value; } } #endregion #region 加载页面 /// /// 加载页面 /// /// /// protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { this.ddlPageSize.SelectedValue = this.Grid1.PageSize.ToString(); this.HardTestReportId = string.Empty; 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.tvControlItem.Nodes.Clear(); TreeNode rootNode = new TreeNode(); rootNode.Text = "项目"; rootNode.NodeID = "0"; rootNode.ToolTip = "红色表示施工号下存在未打印的硬度委托记录"; rootNode.Expanded = true; rootNode.EnableClickEvent = true; this.tvControlItem.Nodes.Add(rootNode); //this.InitTreeMenu();//加载树 //this.tvControlItem.SelectedNodeID = "0"; //BindGrid(); } } #endregion protected void drpProjectId_SelectedIndexChanged(object sender, EventArgs e) { this.InitTreeMenu(); } #region 加载树 /// /// 加载树 /// private void InitTreeMenu() { this.tvControlItem.Nodes.Clear(); TreeNode rootNode = new TreeNode(); rootNode.Text = "项目"; rootNode.NodeID = "0"; rootNode.ToolTip = "红色表示施工号下存在未打印的硬度委托记录"; rootNode.Expanded = true; rootNode.EnableClickEvent = true; this.tvControlItem.Nodes.Add(rootNode); List projects = BLL.Base_ProjectService.GetOnProjectListByUserId(this.CurrUser.UserId, "1"); if (this.drpProjectId.SelectedValueArray.Length > 1 || (this.drpProjectId.SelectedValueArray.Length == 1 && this.drpProjectId.SelectedValue != "null")) { projects = projects.Where(x => this.drpProjectId.SelectedValueArray.Contains(x.ProjectId)).ToList(); } List trustLists = new List(); ///硬度委托单 if (!string.IsNullOrEmpty(this.txtDate.Text.Trim())) { if (this.rblPrint.SelectedValue == "2") //全部 { trustLists = (from x in Funs.DB.HJGL_CH_HardTestReport where x.HotHardCode.Contains(this.txtSearchNo.Text.Trim()) && x.TestDate.Value.Date == Funs.GetNewDateTime(this.txtDate.Text.Trim()) select x).ToList(); } else if (this.rblPrint.SelectedValue == "1") //已打印 { trustLists = (from x in Funs.DB.HJGL_CH_HardTestReport where x.HotHardCode.Contains(this.txtSearchNo.Text.Trim()) && x.IsPrintTrust == true && x.TestDate.Value.Date == Funs.GetNewDateTime(this.txtDate.Text.Trim()) select x).ToList(); } else if (this.rblPrint.SelectedValue == "0") //未打印 { trustLists = (from x in Funs.DB.HJGL_CH_HardTestReport where x.HotHardCode.Contains(this.txtSearchNo.Text.Trim()) && (x.IsPrintTrust == null || x.IsPrintTrust == false) && x.TestDate.Value.Date == Funs.GetNewDateTime(this.txtDate.Text.Trim()) select x).ToList(); } } else { if (this.rblPrint.SelectedValue == "2") //全部 { trustLists = (from x in Funs.DB.HJGL_CH_HardTestReport where x.HotHardCode.Contains(this.txtSearchNo.Text.Trim()) select x).ToList(); } else if (this.rblPrint.SelectedValue == "1") //已打印 { trustLists = (from x in Funs.DB.HJGL_CH_HardTestReport where x.HotHardCode.Contains(this.txtSearchNo.Text.Trim()) && x.IsPrintTrust == true select x).ToList(); } else if (this.rblPrint.SelectedValue == "0") //未打印 { trustLists = (from x in Funs.DB.HJGL_CH_HardTestReport where x.HotHardCode.Contains(this.txtSearchNo.Text.Trim()) && (x.IsPrintTrust == null || x.IsPrintTrust == false) select x).ToList(); } } foreach (var item in projects) { TreeNode rootUnitNode = new TreeNode();//定义根节点 if ((from x in trustLists where x.ProjectId == item.ProjectId && (x.IsPrintTrust == null || x.IsPrintTrust == false) select x).Count() > 0) //存在未打印的委托单 { rootUnitNode.Text = "" + item.ProjectCode + ""; } else { rootUnitNode.Text = item.ProjectCode; } rootUnitNode.NodeID = item.ProjectId; rootUnitNode.EnableClickEvent = true; rootUnitNode.EnableExpandEvent = true; rootUnitNode.ToolTip = item.ProjectName; rootUnitNode.CommandName = "项目名称"; rootNode.Nodes.Add(rootUnitNode); if (!string.IsNullOrEmpty(this.txtSearchNo.Text.Trim()) || !string.IsNullOrEmpty(this.txtDate.Text.Trim())) { var projectTrustLists = (from x in trustLists where x.ProjectId == item.ProjectId orderby x.HotHardCode descending select x).ToList(); if (projectTrustLists.Count > 0) { rootUnitNode.Expanded = true; this.BindNodes(rootUnitNode, projectTrustLists); } } else { TreeNode tn = new TreeNode(); tn.NodeID = "temp"; tn.Text = "正在加载..."; rootUnitNode.Nodes.Add(tn); } } } #endregion protected void tvControlItem_NodeExpand(object sender, TreeNodeEventArgs e) { if (e.Node.Nodes != null) { e.Node.Nodes.Clear(); } List trustLists = new List(); ///硬度委托单 if (!string.IsNullOrEmpty(this.txtDate.Text.Trim())) { if (this.rblPrint.SelectedValue == "2") //全部 { trustLists = (from x in Funs.DB.HJGL_CH_HardTestReport where x.HotHardCode.Contains(this.txtSearchNo.Text.Trim()) && x.TestDate.Value.Date == Funs.GetNewDateTime(this.txtDate.Text.Trim()) && x.ProjectId == e.Node.NodeID orderby x.HotHardCode descending select x).ToList(); } else if (this.rblPrint.SelectedValue == "1") //已打印 { trustLists = (from x in Funs.DB.HJGL_CH_HardTestReport where x.HotHardCode.Contains(this.txtSearchNo.Text.Trim()) && x.IsPrintTrust == true && x.TestDate.Value.Date == Funs.GetNewDateTime(this.txtDate.Text.Trim()) && x.ProjectId == e.Node.NodeID orderby x.HotHardCode descending select x).ToList(); } else if (this.rblPrint.SelectedValue == "0") //未打印 { trustLists = (from x in Funs.DB.HJGL_CH_HardTestReport where x.HotHardCode.Contains(this.txtSearchNo.Text.Trim()) && (x.IsPrintTrust == null || x.IsPrintTrust == false) && x.TestDate.Value.Date == Funs.GetNewDateTime(this.txtDate.Text.Trim()) && x.ProjectId == e.Node.NodeID orderby x.HotHardCode descending select x).ToList(); } } else { if (this.rblPrint.SelectedValue == "2") //全部 { trustLists = (from x in Funs.DB.HJGL_CH_HardTestReport where x.HotHardCode.Contains(this.txtSearchNo.Text.Trim()) && x.ProjectId == e.Node.NodeID orderby x.HotHardCode descending select x).ToList(); } else if (this.rblPrint.SelectedValue == "1") //已打印 { trustLists = (from x in Funs.DB.HJGL_CH_HardTestReport where x.HotHardCode.Contains(this.txtSearchNo.Text.Trim()) && x.IsPrintTrust == true && x.ProjectId == e.Node.NodeID orderby x.HotHardCode descending select x).ToList(); } else if (this.rblPrint.SelectedValue == "0") //未打印 { trustLists = (from x in Funs.DB.HJGL_CH_HardTestReport where x.HotHardCode.Contains(this.txtSearchNo.Text.Trim()) && (x.IsPrintTrust == null || x.IsPrintTrust == false) && x.ProjectId == e.Node.NodeID orderby x.HotHardCode descending select x).ToList(); } } trustLists = trustLists.Where(x => x.FileType == null || x.FileType == "T").ToList(); this.BindNodes(e.Node, trustLists); } #region 绑定树节点 /// /// 绑定树节点 /// /// private void BindNodes(TreeNode node, List hotHardLists) { foreach (var item in hotHardLists) { TreeNode newNode = new TreeNode(); if (item.IsPrintTrust == true) { //newNode.Text = item.HotHardCode + " " + item.HardTestReportCode; if (string.IsNullOrEmpty(item.TrustName)) { newNode.Text = item.HotHardCode; } else { newNode.Text = item.TrustName; } } else { //newNode.Text = "" + item.HotHardCode + " " + item.HardTestReportCode + ""; newNode.Text = "" + item.HotHardCode + ""; } newNode.NodeID = item.HardTestReportId; newNode.ToolTip = item.HotHardCode; newNode.CommandName = "委托单号"; newNode.EnableClickEvent = true; node.Nodes.Add(newNode); } } #endregion #region 点击TreeView /// /// 点击TreeView /// /// /// protected void tvControlItem_NodeCommand(object sender, TreeCommandEventArgs e) { this.HardTestReportId = tvControlItem.SelectedNodeID; this.BindGrid(); } #endregion #region 数据绑定 protected void TextBox_TextChanged(object sender, EventArgs e) { this.BindGrid(); } /// /// 数据绑定 /// private void BindGrid() { this.SetTextTemp(); this.PageInfoLoad(); ///页面输入提交信息 string strSql = string.Empty; string projectIds = BLL.Base_ProjectService.GetStrOnProjectIds(this.CurrUser.UserId, "1"); List listStr = new List(); if (this.tvControlItem.SelectedNode.CommandName == "委托单号") { strSql = @"SELECT * " + @" FROM dbo.HJGL_View_CH_HardTestReportItem AS Trust" + @" WHERE Trust.HardTestReportId=@HardTestReportId"; listStr.Add(new SqlParameter("@HardTestReportId", this.HardTestReportId)); } else if (this.tvControlItem.SelectedNode.CommandName == "项目名称") { strSql = @"SELECT * " + @" FROM dbo.HJGL_View_CH_HardTestReportItem AS Trust" + @" WHERE Trust.ProjectId= @ProjectId AND Trust.HardTestReportId is not null and (Trust.FileType='T' or Trust.FileType is null)"; listStr.Add(new SqlParameter("@ProjectId", this.HardTestReportId)); } else if (this.tvControlItem.SelectedNodeID == "0") //选择项目根节点 { strSql = @"SELECT * " + @" FROM dbo.HJGL_View_CH_HardTestReportItem AS Trust" + @" WHERE Trust.HardTestReportId is not null and CHARINDEX(Trust.ProjectId,@ProjectId)>0 "; listStr.Add(new SqlParameter("@ProjectId", projectIds)); } if (!string.IsNullOrEmpty(this.txtIsoNo.Text.Trim())) { strSql += @" and Trust.ISO_IsoNo like @IsoNo "; listStr.Add(new SqlParameter("@IsoNo", "%" + this.txtIsoNo.Text.Trim() + "%")); } if (!string.IsNullOrEmpty(this.txtJointNo.Text.Trim())) { strSql += @" and Trust.JOT_JointNo like @JointNo "; listStr.Add(new SqlParameter("@JointNo", "%" + this.txtJointNo.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.btnEdit.Hidden = true; this.btnDelete.Hidden = true; this.btnPrint.Hidden = true; this.btnPrint2.Hidden = true; this.SimpleForm1.Reset(); ///重置所有字段 var trust = Funs.DB.HJGL_View_CH_HardTestReport.FirstOrDefault(x => x.HardTestReportId == this.HardTestReportId); if (trust != null) { this.txtHotHardCode.Text = trust.HotHardCode; this.txtCH_TrustUnit.Text = trust.UnitName; this.txtSTE_Code.Text = trust.STE_Code; if (trust.TestDate != null) { this.txtTestDate.Text = string.Format("{0:yyyy-MM-dd}", trust.TestDate); } this.txtInstrumentType.Text = trust.InstrumentType; this.txtEquipmentName.Text = trust.EquipmentName; this.txtTestStandard.Text = trust.TestStandard; this.btnEdit.Hidden = false; if (trust.IsPrintTrust == true) { this.cbIsPrint.Checked = true; this.btnEdit.Hidden = true; } else { this.cbIsPrint.Checked = false; } this.btnPrint.Hidden = false; this.btnPrint2.Hidden = false; this.cbIsPrint.Hidden = false; this.btnDelete.Hidden = false; } } #endregion /// /// 情况 /// private void SetTextTemp() { this.txtHotHardCode.Text = string.Empty; this.txtCH_TrustUnit.Text = string.Empty; this.txtSTE_Code.Text = string.Empty; this.txtTestDate.Text = string.Empty; this.txtInstrumentType.Text = string.Empty; this.txtEquipmentName.Text = string.Empty; this.txtTestStandard.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 btnNew_Click(object sender, EventArgs e) { if (CommonService.GetAllButtonPowerList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, Const.HJGL_HotHardManageEditMenuId, Const.BtnAdd)) { this.SetTextTemp(); string window = String.Format("HotHardManageItemEdit.aspx?HardTestReportId={0}", string.Empty, "新增 - "); PageContext.RegisterStartupScript(Window1.GetSaveStateReference(this.hdHardTestReportId.ClientID) + Window1.GetShowReference(window)); } else { ShowNotify("您没有这个权限,请与管理员联系!", MessageBoxIcon.Warning); } } #region 编辑硬度委托 /// /// 编辑硬度委托 /// /// /// protected void btnEdit_Click(object sender, EventArgs e) { if (CommonService.GetAllButtonPowerList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, Const.HJGL_HotHardManageEditMenuId, Const.BtnSave)) { string window = String.Format("HotHardManageItemEdit.aspx?HardTestReportId={0}", this.HardTestReportId, "编辑 - "); PageContext.RegisterStartupScript(Window1.GetSaveStateReference(this.hdHardTestReportId.ClientID) + Window1.GetShowReference(window)); } else { ShowNotify("您没有这个权限,请与管理员联系!", MessageBoxIcon.Warning); } } #endregion #region 删除硬度委托 /// /// 删除硬度委托 /// /// /// protected void btnDelete_Click(object sender, EventArgs e) { if (CommonService.GetAllButtonPowerList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, Const.HJGL_HotHardManageEditMenuId, Const.BtnDelete)) { var trustManage = BLL.HJGL_CH_HardTestReportService.GetCH_HardTestReportByID(this.HardTestReportId); if (trustManage.IsPrintTrust == true || trustManage.IsPrintReport == true) { ShowNotify("硬度检验委托已打印,无法删除!", MessageBoxIcon.Warning); return; } var items = BLL.HJGL_CH_HardTestReportService.GetView_CH_HardTestReportItemByCH_HardTestReportID(this.HardTestReportId); bool b = true; //是否可以删除 foreach (var item in items) { if (item.HardNessValue1.HasValue || item.HardNessValue2.HasValue || item.HardNessValue3.HasValue) { b = false; break; } } if (b) { string projectId = trustManage.ProjectId; var hardTestReportItems = BLL.HJGL_CH_HardTestReportService.GetCH_HardTestReportItemByHotProessTrustID(this.HardTestReportId); foreach (var item in hardTestReportItems) { BLL.HJGL_CH_HardTestReportService.DeleteCH_HardTestReportItemByHotProessTrustId(item.HotProessTrustId,item.JOT_ID); } BLL.HJGL_CH_HardTestResultService.DeleteHardTestResultsyHardTestReportId(this.HardTestReportId); //BLL.HJGL_CH_HardTestReportService.DeleteCH_HardTestReportItemByCH_HardTestReportID(this.HardTestReportId); BLL.HJGL_CH_HardTestReportService.DeleteCH_HardTestReportByCH_HardTestReportID(this.HardTestReportId); BLL.Sys_LogService.AddLog(BLL.Const.System_3, projectId, this.CurrUser.UserId, "删除硬度委托"); Alert.ShowInTop("删除成功!", MessageBoxIcon.Success); this.InitTreeMenu(); this.Grid1.DataSource = null; this.Grid1.DataBind(); this.SetTextTemp(); } else { ShowNotify("硬度检验报告已录入数据,无法删除!", MessageBoxIcon.Warning); return; } } else { ShowNotify("您没有这个权限,请与管理员联系!", MessageBoxIcon.Warning); return; } } #endregion #endregion #region 关闭弹出窗口及刷新页面 /// /// 关闭弹出窗口 /// /// /// protected void Window1_Close(object sender, WindowCloseEventArgs e) { this.HardTestReportId = this.hdHardTestReportId.Text; this.BindGrid(); //this.InitTreeMenu(); this.hdHardTestReportId.Text = string.Empty; } /// /// 查询 /// /// /// protected void Tree_TextChanged(object sender, EventArgs e) { this.InitTreeMenu(); //this.BindGrid(); } #endregion #region 硬度委托表打印 /// /// 硬度委托表打印 /// /// /// protected void btnPrint_Click(object sender, EventArgs e) { if (!string.IsNullOrEmpty(this.HardTestReportId)) { Model.HJGL_CH_HardTestReport report = BLL.HJGL_CH_HardTestReportService.GetCH_HardTestReportByID(this.HardTestReportId); if (report != null) { report.IsPrintTrust = true; report.PrintTrustDate = DateTime.Now; report.TrustName = report.HotHardCode + "-" + string.Format("{0:yyyy-MM-dd}", DateTime.Now); BLL.HJGL_CH_HardTestReportService.UpdateCH_HardTestReport(report); this.cbIsPrint.Checked = true; } PageContext.RegisterStartupScript(Window2.GetShowReference(String.Format("../../Common/ReportPrint/ExReportPrint.aspx?ispop=1&reportId={0}&replaceParameter={1}&varValue={2}&projectId=0", BLL.Const.HJGL_HardCheckReportId, this.HardTestReportId, string.Empty, "打印 - "))); } else { ShowNotify("请选择硬度委托记录!", MessageBoxIcon.Warning); return; } } /// /// 硬度委托表打印 /// /// /// protected void btnPrint2_Click(object sender, EventArgs e) { if (!string.IsNullOrEmpty(this.HardTestReportId)) { Model.HJGL_CH_HardTestReport report = BLL.HJGL_CH_HardTestReportService.GetCH_HardTestReportByID(this.HardTestReportId); if (report != null) { report.IsPrintTrust = true; report.PrintTrustDate = DateTime.Now; report.TrustName = report.HotHardCode + "-" + string.Format("{0:yyyy-MM-dd}", DateTime.Now); BLL.HJGL_CH_HardTestReportService.UpdateCH_HardTestReport(report); this.cbIsPrint.Checked = true; } string varValue = HttpUtility.UrlEncodeUnicode(this.CurrUser.UserName); PageContext.RegisterStartupScript(Window2.GetShowReference(String.Format("../../Common/ReportPrint/ExReportPrint.aspx?ispop=1&reportId={0}&replaceParameter={1}&varValue={2}&projectId=0", BLL.Const.HJGL_HardCheckReport2Id, this.HardTestReportId, varValue, "打印 - "))); } else { ShowNotify("请选择硬度委托记录!", MessageBoxIcon.Warning); return; } } #endregion protected void cbIsPrint_CheckedChanged(object sender, CheckedEventArgs e) { if (this.tvControlItem.SelectedNode.CommandName == "委托单号") { Model.HJGL_CH_HardTestReport report = BLL.HJGL_CH_HardTestReportService.GetCH_HardTestReportByID(this.HardTestReportId); if (report != null) { if (this.cbIsPrint.Checked) { report.IsPrintTrust = true; report.PrintTrustDate = DateTime.Now; report.TrustName = report.HotHardCode + "-" + string.Format("{0:yyyy-MM-dd}", DateTime.Now); } else { report.IsPrintTrust = false; report.PrintTrustDate = null; report.TrustName = null; } BLL.HJGL_CH_HardTestReportService.UpdateCH_HardTestReport(report); } } } protected void rblPrint_SelectedIndexChanged(object sender, EventArgs e) { this.InitTreeMenu(); } } }