using System; using System.Collections.Generic; using System.Data; using System.Data.SqlClient; using System.Linq; using BLL; namespace FineUIPro.Web.WeldingProcess.WeldingManage { public partial class WeldReport : PageBase { protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { this.txtMonth.Text = string.Format("{0:yyyy-MM}",DateTime.Now); this.ddlPageSize.SelectedValue = this.Grid1.PageSize.ToString(); this.InitTreeMenu();//加载树 } } #region 加载树装置-单位 /// /// 加载树 /// private void InitTreeMenu() { if (!string.IsNullOrEmpty(this.txtMonth.Text.Trim())) { DateTime startTime = Convert.ToDateTime(this.txtMonth.Text.Trim() + "-01"); DateTime endTime = startTime.AddMonths(1); this.tvControlItem.Nodes.Clear(); var weldReports = (from x in Funs.DB.Pipeline_WeldingDaily where x.ProjectId == this.CurrUser.LoginProjectId select x).ToList(); this.BindNodes(null, weldReports, startTime, endTime); } else { Alert.ShowInTop("请选择月份!", MessageBoxIcon.Warning); } } #endregion #region 绑定树节点 #region 绑定树节点 /// /// 绑定树节点 /// /// private void BindNodes(TreeNode node, List projectWeldReports, DateTime startTime, DateTime endTime) { if (node == null) { var installations = (from x in projectWeldReports join y in Funs.DB.Project_Installation on x.InstallationId equals y.InstallationId where x.WeldingDate >= startTime && x.WeldingDate < endTime select y).Distinct().ToList(); foreach (var q in installations) { TreeNode newNode = new TreeNode(); newNode.NodeID = q.InstallationId; newNode.Text = q.InstallationName; newNode.ToolTip = Resources.Lan.InstallationName; newNode.Expanded = true; this.tvControlItem.Nodes.Add(newNode); this.BindNodes(newNode, projectWeldReports, startTime, endTime); } } else if (node.ToolTip == Resources.Lan.InstallationName) { List units = null; var pUnitDepth = Funs.DB.Project_Unit.FirstOrDefault(x => x.UnitId == this.CurrUser.UnitId && x.ProjectId == this.CurrUser.LoginProjectId); if (pUnitDepth == null || pUnitDepth.UnitType.Contains(Const.UnitType_1) || pUnitDepth.UnitType.Contains(Const.UnitType_2) || pUnitDepth.UnitType.Contains(Const.UnitType_3) || pUnitDepth.UnitType.Contains(Const.UnitType_4)) { units = (from x in projectWeldReports join y in Funs.DB.Project_Installation on x.InstallationId equals y.InstallationId join z in Funs.DB.Base_Unit on x.UnitId equals z.UnitId where x.WeldingDate >= startTime && x.WeldingDate < endTime select z).Distinct().ToList(); } else { units = (from x in Funs.DB.Base_Unit where x.UnitId == this.CurrUser.UnitId select x).ToList(); } units = units.OrderBy(x => x.InTime).Distinct().ToList(); foreach (var q in units) { TreeNode newNode = new TreeNode(); newNode.Text = q.UnitName; newNode.NodeID = q.UnitId + "|" + node.NodeID; newNode.ToolTip = Resources.Lan.UnitName; newNode.EnableClickEvent = true; node.Nodes.Add(newNode); } } } #endregion #endregion #region 点击TreeView /// /// 点击TreeView /// /// /// protected void tvControlItem_NodeCommand(object sender, TreeCommandEventArgs e) { this.BindGrid(); } #endregion #region 查询 /// /// 查询 /// /// /// protected void btnQuery_Click(object sender, EventArgs e) { this.BindGrid(); } #endregion #region 数据绑定 /// /// 数据绑定 /// private void BindGrid() { if (this.tvControlItem.SelectedNode != null && this.tvControlItem.SelectedNode.ToolTip == Resources.Lan.UnitName) { string[] strs = this.tvControlItem.SelectedNodeID.Split('|'); DateTime startDate = Convert.ToDateTime(this.txtMonth.Text.Trim() + "-1"); DateTime endDate = startDate.AddMonths(1); string startDateStr = string.Format("{0:yyyy-MM-dd}", startDate); string endDateStr = string.Format("{0:yyyy-MM-dd}", endDate); string strSql = @"SELECT distinct d.WeldingDailyId,d.WeldingDailyCode,d.ProjectId, d.InstallationId,d.UnitId,d.WeldingDate,d.Tabler,d.TableDate,d.Remark FROM dbo.Pipeline_WeldingDaily d left join dbo.View_Pipeline_WeldJoint w on w.WeldingDailyId=d.WeldingDailyId WHERE 1=1 "; List listStr = new List { }; strSql += " AND d.ProjectId =@ProjectId"; listStr.Add(new SqlParameter("@ProjectId", this.CurrUser.LoginProjectId)); strSql += " AND d.InstallationId =@InstallationId"; listStr.Add(new SqlParameter("@InstallationId", strs[1])); strSql += " AND d.UnitId =@UnitId"; listStr.Add(new SqlParameter("@UnitId", strs[0])); strSql += " AND d.WeldingDate >=@startDateStr"; listStr.Add(new SqlParameter("@startDateStr", startDateStr)); strSql += " AND d.WeldingDate <@endDateStr"; listStr.Add(new SqlParameter("@endDateStr", endDateStr)); if (!string.IsNullOrEmpty(this.txtWeldingDate.Text.Trim())) { strSql += " AND d.WeldingDate = @WeldingDate"; listStr.Add(new SqlParameter("@WeldingDate", this.txtWeldingDate.Text.Trim())); } if (!string.IsNullOrEmpty(this.txtWeldingDailyCode.Text.Trim())) { strSql += " AND d.WeldingDailyCode LIKE @WeldingDailyCode"; listStr.Add(new SqlParameter("@WeldingDailyCode", "%" + this.txtWeldingDailyCode.Text.Trim() + "%")); } if (!string.IsNullOrEmpty(this.txtPipelineCode.Text.Trim())) { strSql += " AND w.PipelineCode LIKE @PipelineCode"; listStr.Add(new SqlParameter("@PipelineCode", "%" + this.txtPipelineCode.Text.Trim() + "%")); } if (!string.IsNullOrEmpty(this.txtWeldJointCode.Text.Trim())) { strSql += " AND w.WeldJointCode LIKE @WeldJointCode"; listStr.Add(new SqlParameter("@WeldJointCode", "%" + this.txtWeldJointCode.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(); } } #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 焊接日报 维护事件 /// /// Grid双击事件 /// /// /// protected void Grid1_RowDoubleClick(object sender, GridRowClickEventArgs e) { if (BLL.CommonService.GetAllButtonPowerList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, BLL.Const.HJGL_WeldReportMenuId, BLL.Const.BtnModify)) { PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("WeldReportEdit.aspx?WeldingDailyId={0}", Grid1.SelectedRowID, "编辑 - "))); } else { ShowNotify(Resources.Lan.NoPrivilegePrompt, MessageBoxIcon.Warning); } } /// /// 增加焊接日报 /// /// /// protected void btnNew_Click(object sender, EventArgs e) { if (CommonService.GetAllButtonPowerList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, Const.HJGL_WeldReportMenuId, Const.BtnAdd)) { PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("WeldReportEdit.aspx?ProjectId={0}", this.CurrUser.LoginProjectId, "新增 - "))); } else { ShowNotify(Resources.Lan.NoPrivilegePrompt, MessageBoxIcon.Warning); } } /// /// 焊接日报编辑 /// /// /// protected void btnMenuEdit_Click(object sender, EventArgs e) { if (BLL.CommonService.GetAllButtonPowerList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, BLL.Const.HJGL_WeldReportMenuId, BLL.Const.BtnModify)) { if (Grid1.SelectedRowIndexArray.Length == 0) { Alert.ShowInTop(Resources.Lan.SelectLeastOneRecord, MessageBoxIcon.Warning); return; } PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("WeldReportEdit.aspx?WeldingDailyId={0}", Grid1.SelectedRowID, "维护 - "))); } else { ShowNotify(Resources.Lan.NoPrivilegePrompt, MessageBoxIcon.Warning); } } /// /// 删除按钮 /// /// /// protected void btnMenuDelete_Click(object sender, EventArgs e) { if (CommonService.GetAllButtonPowerList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, Const.HJGL_WeldReportMenuId, Const.BtnDelete)) { if (Grid1.SelectedRowIndexArray.Length == 0) { Alert.ShowInTop(Resources.Lan.SelectLeastOneRecord, MessageBoxIcon.Warning); return; } else { string weldingDailyId = Grid1.SelectedRowID; if (!BLL.Batch_NDEItemService.IsCheckedByWeldingDaily(weldingDailyId)) { var weldJoints = BLL.Pipeline_WeldJointService.GetWeldlinesByWeldingDailyId(weldingDailyId); if (weldJoints.Count() > 0) { foreach (var item in weldJoints) { var updateWeldJoint = BLL.Pipeline_WeldJointService.GetWeldJointByWeldJointId(item.WeldJointId); if (updateWeldJoint != null) { updateWeldJoint.WeldingDailyId = null; updateWeldJoint.WeldingDailyCode = null; updateWeldJoint.CoverWelderId = null; updateWeldJoint.BackingWelderId = null; BLL.Pipeline_WeldJointService.UpdateWeldJoint(updateWeldJoint); // 删除焊口所在批和委托检测里信息 BLL.Batch_NDEItemService.DeleteAllNDEInfoToWeldJoint(item.WeldJointId); } } } BLL.Pipeline_WeldingDailyService.DeleteWeldingDailyByWeldingDailyId(weldingDailyId); BLL.Sys_LogService.AddLog(BLL.Const.System_3, this.CurrUser.LoginProjectId, this.CurrUser.UserId, Const.HJGL_WeldReportMenuId, Const.BtnDelete, weldingDailyId); ShowNotify(Resources.Lan.DeletedSuccessfully, MessageBoxIcon.Success); this.BindGrid(); } else { Alert.ShowInTop("该日报下已有焊口检测了,不能删除!", MessageBoxIcon.Warning); } } } else { Alert.ShowInTop(Resources.Lan.NoPrivilegePrompt, MessageBoxIcon.Warning); } } #endregion #region 关闭弹出窗口及刷新页面 /// /// 关闭弹出窗口 /// /// /// protected void Window1_Close(object sender, WindowCloseEventArgs e) { this.InitTreeMenu();//加载树 this.BindGrid(); } /// /// 查询 /// /// /// protected void TextBox_TextChanged(object sender, EventArgs e) { this.BindGrid(); } /// /// 查询 /// /// /// protected void Tree_TextChanged(object sender, EventArgs e) { this.InitTreeMenu(); this.BindGrid(); } #endregion #region 格式化字符串 /// /// 获取单位名称 /// /// /// protected string ConvertUnitName(object UnitId) { string name = string.Empty; if (UnitId != null) { var unit = BLL.Base_UnitService.GetUnit(UnitId.ToString()); if (unit != null) { name = unit.UnitName; } } return name; } /// /// 获取装置名称 /// /// /// protected string ConvertInstallationCode(object InstallationId) { string name = string.Empty; if (InstallationId != null) { var installation = BLL.Project_InstallationService.GetProject_InstallationByInstallationId(InstallationId.ToString()); if (installation != null) { name = installation.InstallationCode; } } return name; } /// /// 获取填报人 /// /// /// protected string ConvertTabler(object Tabler) { string name = string.Empty; if (Tabler != null) { var user = BLL.Sys_UserService.GetUsersByUserId(Tabler.ToString()); if (user != null) { name = user.UserName; } } return name; } #endregion } }