201 lines
6.2 KiB
C#
201 lines
6.2 KiB
C#
using BLL;
|
|
using Model;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Data;
|
|
using System.Data.SqlClient;
|
|
using System.Linq;
|
|
using System.Web;
|
|
using System.Web.UI;
|
|
using System.Web.UI.WebControls;
|
|
|
|
namespace FineUIPro.Web.TestRun.BeforeTestRun
|
|
{
|
|
public partial class DeviceRun : PageBase
|
|
{
|
|
protected void Page_Load(object sender, EventArgs e)
|
|
{
|
|
if (!IsPostBack)
|
|
{
|
|
DataBrid();
|
|
}
|
|
}
|
|
|
|
#region 数据绑定和事件
|
|
|
|
/// <summary>
|
|
/// 数据绑定
|
|
/// </summary>
|
|
public void DataBrid()
|
|
{
|
|
string strSql = @"select a.PreRunId,a.PreRunCode,a.PreRunName,b.ProjectId,b.ProjectName,a.PreRunLevel,
|
|
(case a.PreRunLevel when 1 then '装置' when 2 then '工序' when 3 then 'S系统' when 4 then 'SS子系统' else '' end) as RunLevelName,
|
|
a.ParentId,a.Remark,a.OperateTime,a.Sort
|
|
from PreRun_SysDevice as a
|
|
inner join Base_Project as b on a.ProjectId=b.ProjectId where a.ProjectId=@ProjectId ";
|
|
List<SqlParameter> listStr = new List<SqlParameter>();
|
|
listStr.Add(new SqlParameter("@ProjectId", this.CurrUser.LoginProjectId));
|
|
if (!string.IsNullOrEmpty(sRunName.Text.Trim()))
|
|
{
|
|
strSql += " and a.PreRunName=@PreRunName";
|
|
listStr.Add(new SqlParameter("@PreRunName", this.sRunName.Text.Trim()));
|
|
}
|
|
SqlParameter[] parameter = listStr.ToArray();
|
|
DataTable tb = SQLHelper.GetDataTableRunText(strSql, parameter);
|
|
Grid1.RecordCount = tb.Rows.Count;
|
|
var table = this.GetPagedDataTable(Grid1, tb);
|
|
Grid1.DataSource = table;
|
|
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)
|
|
{
|
|
|
|
}
|
|
|
|
#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($"DeviceRunEdit.aspx?RunId=&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 runLevel = Grid1.DataKeys[rowIndex][2] != null ? Convert.ToInt32(Grid1.DataKeys[rowIndex][2]) : 1;
|
|
if (runLevel > 3)
|
|
{
|
|
ShowNotify("最小节点无子节点!", MessageBoxIcon.Warning);
|
|
return;
|
|
}
|
|
PageContext.RegisterStartupScript(Window1.GetShowReference($"DeviceRunEdit.aspx?RunId=&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($"DeviceRunEdit.aspx?RunId={rowId}&ParentId={parentId}", "编辑"));
|
|
}
|
|
|
|
/// <summary>
|
|
/// 保存
|
|
/// </summary>
|
|
protected void btnSave_Click(object sender, EventArgs e)
|
|
{
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// 关闭
|
|
/// </summary>
|
|
protected void Window1_Close(object sender, WindowCloseEventArgs e)
|
|
{
|
|
DataBrid();
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region 私有方法
|
|
|
|
/// <summary>
|
|
/// 根据行ID来删除行数据
|
|
/// </summary>
|
|
private void DeleteRowByIDInternal(string rowID)
|
|
{
|
|
var model = Funs.DB.PreRun_SysDevice.FirstOrDefault(p => p.PreRunId == rowID);
|
|
if (model != null)
|
|
{
|
|
Funs.DB.PreRun_SysDevice.DeleteOnSubmit(model);
|
|
GetDevice(rowID);
|
|
}
|
|
Funs.DB.SubmitChanges();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 删除
|
|
/// </summary>
|
|
private void GetDevice(string id)
|
|
{
|
|
var model = Funs.DB.PreRun_SysDevice.FirstOrDefault(p => p.ParentId == id);
|
|
if (model != null)
|
|
{
|
|
Funs.DB.PreRun_SysDevice.DeleteOnSubmit(model);
|
|
GetDevice(model.PreRunId);
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
} |