using System; using System.Collections.Generic; using System.Data; using System.Data.SqlClient; using System.Linq; using BLL; using Newtonsoft.Json.Linq; namespace FineUIPro.Web.HJGL.RepairManage { public partial class RepairManageEdit : PageBase { #region 定义项 /// /// 返修委托主键 /// public string CH_RepairID { get { return (string)ViewState["CH_RepairID"]; } set { ViewState["CH_RepairID"] = value; } } #endregion #region 加载页面 /// /// 加载页面 /// /// /// protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { this.drpIsProjectClosed.DataTextField = "Text"; this.drpIsProjectClosed.DataValueField = "Value"; this.drpIsProjectClosed.DataSource = BLL.DropListService.IsTrueOrFalseDrpList(); this.drpIsProjectClosed.DataBind(); Funs.FineUIPleaseSelect(this.drpIsProjectClosed); this.drpIsProjectClosed.SelectedValue = BLL.Const._False; var projects = BLL.Base_ProjectService.GetProjectListByUserIdAndState(this.CurrUser.UserId, this.drpIsProjectClosed.SelectedValue, "1"); RadioButtonList1.DataTextField = "ProjectCode"; RadioButtonList1.DataValueField = "ProjectId"; RadioButtonList1.DataSource = projects; RadioButtonList1.DataBind(); this.drpNdtType.DataTextField = "NDT_Code"; this.drpNdtType.DataValueField = "NDT_ID"; this.drpNdtType.DataSource = BLL.HJGL_TestingService.GetNDTTypeNameList(); this.drpNdtType.DataBind(); Funs.FineUIPleaseSelect(this.drpNdtType); this.drpIsPrint.DataTextField = "Text"; this.drpIsPrint.DataValueField = "Value"; this.drpIsPrint.DataSource = BLL.DropListService.IsTrueOrFalseDrpList(); this.drpIsPrint.DataBind(); Funs.FineUIPleaseSelect(this.drpIsPrint); this.ddlPageSize.SelectedValue = this.Grid1.PageSize.ToString(); this.InitTreeMenu();//加载树 } } #endregion #region 加载树项目 /// /// 加载树 /// 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 trustLists = new List(); string selectProjectIds = String.Join("|", DropDownBox1.Values); //选择显示的项目 List projects = BLL.Base_ProjectService.GetProjectListByUserIdAndState(this.CurrUser.UserId, this.drpIsProjectClosed.SelectedValue, "1"); if (CurrUser.Account == Const.Gly) { //projects= } if (selectProjectIds.Length > 6) //勾选了显示项目 { projects = projects.Where(x => selectProjectIds.Contains(x.ProjectId)).ToList(); } foreach (var item in projects) { TreeNode rootProjectNode = new TreeNode();//定义根节点 rootProjectNode.Text = item.ProjectCode; rootProjectNode.NodeID = item.ProjectId; rootProjectNode.Expanded = true; rootProjectNode.ToolTip = "项目名称"; rootNode.Nodes.Add(rootProjectNode); trustLists = (from x in Funs.DB.HJGL_CH_Repair where x.ProjectId == item.ProjectId //&& x.CH_TrustType == "1" select x).ToList(); // 筛选关闭的批 if (this.drpIsPrint.SelectedValue != "null") { if (Convert.ToBoolean(drpIsPrint.SelectedValue)) { trustLists = (from x in trustLists where x.CH_PrintDate != null select x).ToList(); } else { trustLists = (from x in trustLists where x.CH_PrintDate == null select x).ToList(); } } // 筛选探伤类型 if (this.drpNdtType.SelectedValue != "null") { trustLists = (from x in trustLists where x.NDT_ID == drpNdtType.SelectedValue select x).ToList(); } this.BindNodes(rootProjectNode, trustLists); } } #endregion #region 绑定树节点 /// /// 绑定树节点 /// /// private void BindNodes(TreeNode node, List trustLists) { if (node.ToolTip == "项目名称") { var trustMonth = (from x in trustLists select string.Format("{0:yyyy-MM}", x.RepairTrustDate)).Distinct(); foreach (var item in trustMonth) { TreeNode newNode = new TreeNode(); newNode.Text = item; newNode.NodeID = item + "|" + node.NodeID; ; newNode.ToolTip = "月份"; node.Nodes.Add(newNode); this.BindNodes(newNode, trustLists); } } else if (node.ToolTip == "月份") { var dReports = from x in trustLists where string.Format("{0:yyyy-MM}", x.RepairTrustDate) == node.Text orderby x.CH_RepairNo descending select x; foreach (var item in dReports) { TreeNode newNode = new TreeNode(); if (!string.IsNullOrEmpty(item.CH_RepairNo)) { newNode.Text = string.Format("{0:yyyy-MM-dd}", item.RepairTrustDate) + " " + item.CH_RepairNo; } else { newNode.Text = "未知"; } newNode.NodeID = item.CH_RepairID; newNode.EnableClickEvent = true; node.Nodes.Add(newNode); } } } #endregion #region 点击TreeView /// /// 点击TreeView /// /// /// protected void tvControlItem_NodeCommand(object sender, TreeCommandEventArgs e) { this.SetTextTemp(); this.CH_RepairID = tvControlItem.SelectedNodeID; this.PageInfoLoad(); ///页面输入提交信息 e.Node.ParentNode.Expanded = true; } #endregion #region 数据绑定 /// /// 数据绑定 /// private void BindGrid() { string strSql = @"SELECT repairItem.CH_RepairItemId ,repairItem.CH_RepairID ,repairItem.JOT_ID ,repair.NDT_ID ,repairItem.DefectNature ,repairItem.FilmNum ,IsoInfo.ISO_IsoNo ,(JointInfo.JOT_JointNo+repairRecord.RepairMark) AS JOT_JointNo ,repairRecord.RepairMark ,repairItem.Remark ,CAST(JointInfo.JOT_Dia AS Decimal(18,2)) AS JOT_Dia ,JointInfo.JOT_Sch ,JointInfo.WLO_Code ,WeldMethod.WME_Name ,batch.BatchCode ,JointInfo.Sort1,JointInfo.Sort2,JointInfo.Sort3,JointInfo.Sort4,JointInfo.Sort5 FROM HJGL_CH_RepairItem AS repairItem LEFT JOIN dbo.HJGL_CH_Repair AS repair ON repair.CH_RepairID = repairItem.CH_RepairID LEFT JOIN dbo.HJGL_CH_RepairItemRecord AS repairRecord ON repairRecord.RepairItemRecordId = repairItem.RepairItemRecordId LEFT JOIN dbo.HJGL_PW_JointInfo AS JointInfo ON JointInfo.JOT_ID = repairItem.JOT_ID LEFT JOIN dbo.HJGL_PW_IsoInfo AS IsoInfo ON JointInfo.ISO_ID = IsoInfo.ISO_ID LEFT JOIN dbo.HJGL_BS_WeldMethod AS WeldMethod ON WeldMethod.WME_ID=JointInfo.WME_ID LEFT JOIN dbo.HJGL_BO_Batch AS batch ON batch.BatchId = repair.BatchId WHERE 1=1"; List listStr = new List(); if (!string.IsNullOrEmpty(this.tvControlItem.SelectedNodeID)) { strSql += " AND repairItem.CH_RepairID = @CH_RepairID"; listStr.Add(new SqlParameter("@CH_RepairID", this.tvControlItem.SelectedNodeID)); } 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() { var repair = BLL.HJGL_RepairService.GetCH_RepairByID(this.CH_RepairID); if (repair != null) { this.txtCH_RepairNo.Text = repair.CH_RepairNo; if (!string.IsNullOrEmpty(repair.CH_TrustUnit)) { var unit = BLL.Base_UnitService.GetUnit(repair.CH_TrustUnit); if (unit != null) { this.drpCH_TrustUnit.Text = unit.UnitName; } } if (!string.IsNullOrEmpty(repair.InstallationId)) { var install = BLL.Project_InstallationService.GetInstallationByInstallationId(repair.InstallationId); if (install != null) { this.drpInstallationId.Text = install.InstallationName; } } this.txtCH_TrustType.Text = repair.CH_TrustType == "1" ? "委托" : "扩透"; this.txtRepairTrustDate.Text = string.Format("{0:yyyy-MM-dd}", repair.RepairTrustDate); if (repair.CH_PrintDate != null) { ckbIsPrint.Checked = true; this.lbPrintDate.Text = repair.CH_PrintDate.Value.ToString(); this.lbPrinter.Text = repair.CH_Printer.Trim(); } if (!string.IsNullOrEmpty(repair.CH_Tabler)) { var hotHardMan = BLL.Sys_UserService.GetUsersByUserId(repair.CH_Tabler); if (hotHardMan != null) { this.drpCH_Tabler.Text = hotHardMan.UserName; } } if (!string.IsNullOrEmpty(repair.CH_CheckUnit)) { var checkUnit = BLL.Base_UnitService.GetUnit(repair.CH_CheckUnit); if (checkUnit != null) { this.drpCH_CheckUnit.Text = checkUnit.UnitName; } } if (!string.IsNullOrEmpty(repair.BatchId)) { var batch = BLL.HJGL_BO_BatchService.GetBatchById(repair.BatchId); if (batch != null) { if (!string.IsNullOrEmpty(batch.NDTR_ID)) { var ndt = BLL.HJGL_DetectionService.GetNDTRateByNDTRID(batch.NDTR_ID); if (ndt != null) { this.drpCH_NDTRate.Text = ndt.NDTR_Name; } } } } if (!string.IsNullOrEmpty(repair.NDT_ID)) { var test = BLL.HJGL_TestingService.GetTestingByTestingId(repair.NDT_ID); if (test != null) { this.drpCH_NDTMethod.Text = test.NDT_Name; } } if (!string.IsNullOrEmpty(repair.CH_AcceptGrade)) { var acceptGrade = BLL.HJGL_TrustManageEditService.GetAcceptGradeList().FirstOrDefault(x => x.Value == repair.CH_AcceptGrade); if (acceptGrade != null) { this.drpCH_AcceptGrade.Text = acceptGrade.Text; } } this.txtCH_NDTCriteria.Text = repair.CH_NDTCriteria; this.txtCH_ItemName.Text = repair.CH_ItemName; if (!string.IsNullOrEmpty(repair.CH_SlopeType)) { var slopeType = BLL.HJGL_GrooveService.GetSlopeTypeByJSTID(repair.CH_SlopeType); if (slopeType != null) { this.drpCH_SlopeType.Text = slopeType.JST_Name; } } if (!string.IsNullOrEmpty(repair.CH_WeldMethod)) { var weldMethod = BLL.HJGL_WeldingMethodService.GetWeldMethodByWMEID(repair.CH_WeldMethod); if (weldMethod != null) { this.drpCH_WeldMethod.Text = weldMethod.WME_Name; } } this.txtCH_Remark.Text = repair.CH_Remark; BindGrid(); } } #endregion #region 清空文本框 /// /// 清空文本框 /// private void SetTextTemp() { this.txtCH_RepairNo.Text = string.Empty; this.drpCH_TrustUnit.Text = string.Empty; this.drpInstallationId.Text = string.Empty; this.txtCH_TrustType.Text = string.Empty; this.txtRepairTrustDate.Text = string.Empty; this.drpCH_Tabler.Text = string.Empty; this.lbPrintDate.Text = string.Empty; this.lbPrinter.Text = string.Empty; this.drpCH_CheckUnit.Text = string.Empty; this.drpCH_NDTRate.Text = string.Empty; this.drpCH_NDTMethod.Text = string.Empty; this.drpCH_AcceptGrade.Text = string.Empty; this.txtCH_NDTCriteria.Text = string.Empty; this.txtCH_ItemName.Text = string.Empty; this.drpCH_SlopeType.Text = string.Empty; this.drpCH_WeldMethod.Text = string.Empty; this.txtCH_Remark.Text = string.Empty; } #endregion #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 返修委托 维护事件 #region 编辑返修委托 /// /// 编辑返修委托 /// /// /// protected void btnEdit_Click(object sender, EventArgs e) { if (CommonService.GetAllButtonPowerList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, Const.HJGL_RepairManageEditMenuId, Const.BtnSave)) { var repair = BLL.HJGL_RepairService.GetCH_RepairByID(this.CH_RepairID); if (repair != null) { string window = String.Format("RepairManageItemEdit.aspx?RepairID={0}", this.CH_RepairID, "编辑 - "); PageContext.RegisterStartupScript(Window1.GetSaveStateReference(this.hdCH_RepairID.ClientID) + Window1.GetShowReference(window)); } else { Alert.ShowInTop("请选择要修改的返修委托记录!", MessageBoxIcon.Warning); } } else { Alert.ShowInTop("您没有这个权限,请与管理员联系!", MessageBoxIcon.Warning); } } #endregion #region 删除返修委托 /// /// 删除返修委托 /// /// /// protected void btnDelete_Click(object sender, EventArgs e) { if (CommonService.GetAllButtonPowerList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, Const.HJGL_RepairManageEditMenuId, Const.BtnDelete)) { var repair = BLL.HJGL_RepairService.GetCH_RepairByID(this.CH_RepairID); if (repair != null) { BLL.HJGL_RepairItemService.DeleteCH_RepairItemByCH_RepairID(this.CH_RepairID); BLL.HJGL_RepairService.DeleteRepairByCH_RepairID(this.CH_RepairID); BLL.Sys_LogService.AddLog(BLL.Const.System_3, this.CurrUser.LoginProjectId, this.CurrUser.UserId, "删除返修委托"); ShowNotify("删除成功!", MessageBoxIcon.Success); this.InitTreeMenu(); this.PageInfoLoad(); } else { Alert.ShowInTop("请选择要删除的返修委托记录!", MessageBoxIcon.Warning); } } else { Alert.ShowInTop("您没有这个权限,请与管理员联系!", MessageBoxIcon.Warning); return; } } #endregion #endregion #region 关闭弹出窗口及刷新页面 /// /// 关闭弹出窗口 /// /// /// protected void Window1_Close(object sender, WindowCloseEventArgs e) { this.CH_RepairID = this.hdCH_RepairID.Text; this.InitTreeMenu();//加载树 this.PageInfoLoad(); this.tvControlItem.SelectedNodeID = this.CH_RepairID; if (this.tvControlItem.SelectedNode.ParentNode != null) { this.tvControlItem.SelectedNode.ParentNode.Expanded = true; } this.hdCH_RepairID.Text = string.Empty; } #endregion #region 查询 /// /// 查询 /// /// /// //protected void Tree_TextChanged(object sender, EventArgs e) //{ // this.InitTreeMenu(); // this.PageInfoLoad(); //} protected void drpNdtType_SelectedIndexChanged(object sender, EventArgs e) { this.InitTreeMenu(); } protected void drpIsPrint_SelectedIndexChanged(object sender, EventArgs e) { this.InitTreeMenu(); } #endregion /// /// 打印信息修改 /// /// /// protected void ckbIsPrint_OnCheckedChanged(object sender, EventArgs e) { if (!string.IsNullOrEmpty(this.CH_RepairID)) { Model.HJGL_CH_Repair repair = BLL.HJGL_RepairService.GetCH_RepairByID(this.CH_RepairID); if (ckbIsPrint.Checked) { repair.CH_PrintDate = DateTime.Now.Date; repair.CH_Printer = this.CurrUser.UserName; } else { repair.CH_PrintDate = null; repair.CH_Printer = null; } BLL.HJGL_RepairService.PrintCH_Repair(repair); this.SetTextTemp(); this.PageInfoLoad(); } else { Alert.ShowInTop("请选择委托单", MessageBoxIcon.Information); return; } } #region 报表打印 /// /// 报表打印 /// /// /// protected void btnPrint_Click(object sender, EventArgs e) { if (!string.IsNullOrEmpty(this.tvControlItem.SelectedNodeID)) { Model.HJGL_CH_Repair repair = BLL.HJGL_RepairService.GetCH_RepairByID(this.CH_RepairID); repair.CH_PrintDate = DateTime.Now.Date; repair.CH_Printer = this.CurrUser.UserName; BLL.HJGL_RepairService.PrintCH_Repair(repair); this.SetTextTemp(); this.PageInfoLoad(); string projectId = string.Empty; string project = tvControlItem.SelectedNode.ParentNode.NodeID; if (!string.IsNullOrEmpty(project)) { string[] ps = project.Split('|'); if (ps.Count() > 1) { projectId = ps[1]; } } PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("../../Common/ReportPrint/ExReportPrint.aspx?ispop=1&reportId={0}&replaceParameter={1}&varValue={2}&projectId=0", BLL.Const.HJGL_RepairReportId, this.tvControlItem.SelectedNodeID, null, "打印 - "))); } else { Alert.ShowInTop("请选择委托单", MessageBoxIcon.Information); return; } } protected void btnPrint2_Click(object sender, EventArgs e) { if (!string.IsNullOrEmpty(this.tvControlItem.SelectedNodeID)) { Model.HJGL_CH_Repair repair = BLL.HJGL_RepairService.GetCH_RepairByID(this.CH_RepairID); repair.CH_PrintDate = DateTime.Now.Date; repair.CH_Printer = this.CurrUser.UserName; BLL.HJGL_RepairService.PrintCH_Repair(repair); this.SetTextTemp(); this.PageInfoLoad(); string projectId = string.Empty; string project = tvControlItem.SelectedNode.ParentNode.NodeID; if (!string.IsNullOrEmpty(project)) { string[] ps = project.Split('|'); if (ps.Count() > 1) { projectId = ps[1]; } } PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("../../Common/ReportPrint/ExReportPrint.aspx?ispop=1&reportId={0}&replaceParameter={1}&varValue={2}&projectId=0", BLL.Const.HJGL_SubUnitRepairReportId, this.tvControlItem.SelectedNodeID, null, "打印 - "))); } else { Alert.ShowInTop("请选择委托单", MessageBoxIcon.Information); return; } } #endregion protected void drpIsProjectClosed_SelectedIndexChanged(object sender, EventArgs e) { DropDownBox1.Values = new string[0]; DropDownBox1.Text = string.Empty; var projects = BLL.Base_ProjectService.GetProjectListByUserIdAndState(this.CurrUser.UserId, this.drpIsProjectClosed.SelectedValue, "1"); RadioButtonList1.DataTextField = "ProjectCode"; RadioButtonList1.DataValueField = "ProjectId"; RadioButtonList1.DataSource = projects; RadioButtonList1.DataBind(); this.InitTreeMenu(); } protected void DropDownBox1_TextChanged(object sender, EventArgs e) { this.InitTreeMenu(); } } }