209 lines
		
	
	
		
			6.5 KiB
		
	
	
	
		
			C#
		
	
	
	
		
		
			
		
	
	
			209 lines
		
	
	
		
			6.5 KiB
		
	
	
	
		
			C#
		
	
	
	
|  | using BLL; | |||
|  | using Model; | |||
|  | using System; | |||
|  | using System.Collections.Generic; | |||
|  | using System.Data.SqlClient; | |||
|  | using System.Data; | |||
|  | using System.IO; | |||
|  | using System.Linq; | |||
|  | using System.Web; | |||
|  | using System.Web.UI; | |||
|  | using System.Web.UI.WebControls; | |||
|  | 
 | |||
|  | namespace FineUIPro.Web.CQMS.WBS.Control | |||
|  | { | |||
|  |     public partial class PointCropping : PageBase | |||
|  |     { | |||
|  |         protected void Page_Load(object sender, EventArgs e) | |||
|  |         { | |||
|  |             if (!IsPostBack) | |||
|  |             { | |||
|  |                 DataBrid(); | |||
|  |             } | |||
|  |         } | |||
|  | 
 | |||
|  |         #region 数据绑定和事件 | |||
|  | 
 | |||
|  |         /// <summary> | |||
|  |         /// 数据绑定 | |||
|  |         /// </summary> | |||
|  |         public void DataBrid() | |||
|  |         { | |||
|  |             string strSql = @"select a.ControlId,a.ProjectId,a.ParentId,a.ControlCode,a.ControlLevel,a.PlanId,a.PlanTypeId,a.SubItemsId,a.DetectionItems,a.BasedCriterion,a.QualityRecordName,a.RecordNumber,a.Subcontractors,a.OperateTime,a.Sort from Control_PointCropping as a order by a.ControlLevel,a.Sort asc"; | |||
|  |             List<SqlParameter> listStr = new List<SqlParameter>(); | |||
|  |             listStr.Add(new SqlParameter("@ProjectId", this.CurrUser.LoginProjectId)); | |||
|  |             if (!string.IsNullOrEmpty(sDetectionItems.Text.Trim())) | |||
|  |             { | |||
|  |                 strSql += " and a.DetectionItems like '%@DetectionItems%'"; | |||
|  |                 listStr.Add(new SqlParameter("@DetectionItems", this.sDetectionItems.Text.Trim())); | |||
|  |             } | |||
|  |             SqlParameter[] parameter = listStr.ToArray(); | |||
|  |             DataTable tb = SQLHelper.GetDataTableRunText(strSql, parameter); | |||
|  |             Grid1.DataSource = tb; | |||
|  |             Grid1.DataBind(); | |||
|  |         } | |||
|  | 
 | |||
|  |         /// <summary> | |||
|  |         /// 行点击 事件 | |||
|  |         /// </summary> | |||
|  |         protected void Grid1_RowCommand(object sender, GridCommandEventArgs e) | |||
|  |         { | |||
|  |             if (e.CommandName == "Delete") | |||
|  |             { | |||
|  |                 string rowID = e.RowID; | |||
|  |                 DeleteRowByIDInternal(rowID); | |||
|  |                 DataBrid(); | |||
|  |                 ShowNotify("删除成功!"); | |||
|  |             } | |||
|  |         } | |||
|  | 
 | |||
|  |         /// <summary> | |||
|  |         /// 行加载事件 | |||
|  |         /// </summary> | |||
|  |         protected void Grid1_RowDataBound(object sender, GridRowEventArgs e) | |||
|  |         { | |||
|  |             int controlLevel = Grid1.DataKeys[e.RowIndex][2] != null ? int.Parse(Grid1.DataKeys[e.RowIndex][2].ToString()) : 2; | |||
|  |             if (controlLevel < 2) | |||
|  |             { | |||
|  |                 e.TreeNodeExpanded = true; | |||
|  |             } | |||
|  |         } | |||
|  | 
 | |||
|  |         #endregion | |||
|  | 
 | |||
|  |         #region 按钮 | |||
|  | 
 | |||
|  |         /// <summary> | |||
|  |         /// 搜索 | |||
|  |         /// </summary> | |||
|  |         protected void btnSearch_Click(object sender, EventArgs e) | |||
|  |         { | |||
|  |             DataBrid(); | |||
|  |         } | |||
|  | 
 | |||
|  |         /// <summary> | |||
|  |         /// 删除 | |||
|  |         /// </summary> | |||
|  |         protected void btnDelete_Click(object sender, EventArgs e) | |||
|  |         { | |||
|  |             if (Grid1.SelectedRowIndexArray.Length == 0) | |||
|  |             { | |||
|  |                 ShowNotify("至少选择一条数据!"); | |||
|  |                 return; | |||
|  |             } | |||
|  |             foreach (int rowIndex in Grid1.SelectedRowIndexArray) | |||
|  |             { | |||
|  |                 string rowID = Grid1.DataKeys[rowIndex][0].ToString(); | |||
|  |                 DeleteRowByIDInternal(rowID); | |||
|  |             } | |||
|  |             DataBrid(); | |||
|  |             ShowNotify("删除成功!"); | |||
|  | 
 | |||
|  |         } | |||
|  | 
 | |||
|  |         /// <summary> | |||
|  |         /// 新增 | |||
|  |         /// </summary> | |||
|  |         protected void btnAdd_Click(object sender, EventArgs e) | |||
|  |         { | |||
|  |             PageContext.RegisterStartupScript(Window1.GetShowReference($"PointCroppingEdit.aspx?ControlId=&ParentId=", "新增")); | |||
|  |         } | |||
|  | 
 | |||
|  |         /// <summary> | |||
|  |         /// 添加子级 | |||
|  |         /// </summary> | |||
|  |         protected void btnParentAdd_Click(object sender, EventArgs e) | |||
|  |         { | |||
|  |             if (Grid1.SelectedRowIndexArray.Length == 0) | |||
|  |             { | |||
|  |                 ShowNotify("请选择一条数据!", MessageBoxIcon.Warning); | |||
|  |                 return; | |||
|  |             } | |||
|  | 
 | |||
|  |             var rowIndex = Grid1.SelectedRowIndex; | |||
|  |             var rowId = Grid1.DataKeys[rowIndex][0].ToString(); | |||
|  |             var controlLevel = Grid1.DataKeys[rowIndex][2] != null ? Convert.ToInt32(Grid1.DataKeys[rowIndex][2]) : 1; | |||
|  |             if (controlLevel > 2) | |||
|  |             { | |||
|  |                 ShowNotify("最小节点无子节点!", MessageBoxIcon.Warning); | |||
|  |                 return; | |||
|  |             } | |||
|  |             PageContext.RegisterStartupScript(Window1.GetShowReference($"PointCroppingEdit.aspx?ControlId=&ParentId={rowId}", "添加子级")); | |||
|  |         } | |||
|  | 
 | |||
|  |         /// <summary> | |||
|  |         /// 编辑 | |||
|  |         /// </summary> | |||
|  |         protected void btnEdit_Click(object sender, EventArgs e) | |||
|  |         { | |||
|  |             if (Grid1.SelectedRowIndexArray.Length == 0) | |||
|  |             { | |||
|  |                 ShowNotify("请选择一条数据!", MessageBoxIcon.Warning); | |||
|  |                 return; | |||
|  |             } | |||
|  | 
 | |||
|  |             var rowIndex = Grid1.SelectedRowIndex; | |||
|  |             var rowId = Grid1.DataKeys[rowIndex][0].ToString(); | |||
|  |             var parentId = Grid1.DataKeys[rowIndex][1] != null ? Grid1.DataKeys[rowIndex][1].ToString() : string.Empty; | |||
|  |             PageContext.RegisterStartupScript(Window1.GetShowReference($"PointCroppingEdit.aspx?ControlId={rowId}&ParentId={parentId}", "编辑")); | |||
|  |         } | |||
|  | 
 | |||
|  |         /// <summary> | |||
|  |         /// 关闭 | |||
|  |         /// </summary> | |||
|  |         protected void Window1_Close(object sender, WindowCloseEventArgs e) | |||
|  |         { | |||
|  |             DataBrid(); | |||
|  |         } | |||
|  | 
 | |||
|  |         /// <summary> | |||
|  |         /// 右击修改 | |||
|  |         /// </summary> | |||
|  |         protected void btnMenuModify_Click(object sender, EventArgs e) | |||
|  |         { | |||
|  |             btnEdit_Click(sender, e); | |||
|  |         } | |||
|  | 
 | |||
|  |         /// <summary> | |||
|  |         /// 右击新增子级别 | |||
|  |         /// </summary> | |||
|  |         protected void btnMenuParentAdd_Click(object sender, EventArgs e) | |||
|  |         { | |||
|  |             btnParentAdd_Click(sender, e); | |||
|  |         } | |||
|  | 
 | |||
|  |         #endregion | |||
|  | 
 | |||
|  |         #region 私有方法 | |||
|  | 
 | |||
|  |         /// <summary> | |||
|  |         /// 根据行ID来删除行数据 | |||
|  |         /// </summary> | |||
|  |         private void DeleteRowByIDInternal(string rowID) | |||
|  |         { | |||
|  |             var model = Funs.DB.Control_PointCropping.FirstOrDefault(p => p.ControlId == rowID); | |||
|  |             if (model != null) | |||
|  |             { | |||
|  |                 Funs.DB.Control_PointCropping.DeleteOnSubmit(model); | |||
|  |                 GetDevice(rowID); | |||
|  |             } | |||
|  |             Funs.DB.SubmitChanges(); | |||
|  |         } | |||
|  | 
 | |||
|  |         /// <summary> | |||
|  |         /// 删除 | |||
|  |         /// </summary> | |||
|  |         private void GetDevice(string id) | |||
|  |         { | |||
|  |             var model = Funs.DB.Control_PointCropping.FirstOrDefault(p => p.ParentId == id); | |||
|  |             if (model != null) | |||
|  |             { | |||
|  |                 Funs.DB.Control_PointCropping.DeleteOnSubmit(model); | |||
|  |                 GetDevice(model.ControlId); | |||
|  |             } | |||
|  |         } | |||
|  | 
 | |||
|  |         #endregion | |||
|  | 
 | |||
|  |     } | |||
|  | } |