CNCEC_SUBQHSE_WUHUAN/SGGL/FineUIPro.Web/CQMS/WBS/Control/DivisionSubProjects.aspx.cs

219 lines
7.2 KiB
C#

using BLL;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using static FineUIPro.Web.CQMS.WBS.Control.DivisionSubProjects;
namespace FineUIPro.Web.CQMS.WBS.Control
{
public partial class DivisionSubProjects : PageBase
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
DataBrid();
}
}
#region
/// <summary>
/// 数据绑定
/// </summary>
public void DataBrid()
{
string strSql = @"select * from(select a.DivisionId,a.ProjectId,a.ParentId,a.DivisionLevel,a.BranchEngineeringCode,a.BranchEngineeringName,a.SubBranchEngineeringName,a.ProEngineeringCode,a.ProEngineeringName,a.ProEngineeringNum,a.Remark,a.AddUser,a.OperateTime,a.Sort,a.Status from Division_SubProjects as a where isnull(a.ProjectId,'')='' ";
string strSql1 = @"select a.DivisionId,a.ProjectId,a.ParentId,a.DivisionLevel,a.BranchEngineeringCode,a.BranchEngineeringName,a.SubBranchEngineeringName,a.ProEngineeringCode,a.ProEngineeringName,a.ProEngineeringNum,a.Remark,a.AddUser,a.OperateTime,a.Sort,a.Status from Division_SubProjects 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));
SqlParameter[] parameter = listStr.ToArray();
var zxsql = strSql + " union all " + strSql1 + " ) as t order by t.Sort,t.DivisionLevel asc";
DataTable tb = SQLHelper.GetDataTableRunText(zxsql, 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)
{
var states = int.Parse(Grid1.DataKeys[e.RowIndex][3].ToString());
GridColumn isDelete = Grid1.FindColumn("Delete");
if (states == 0)
{
e.CellAttributes[isDelete.ColumnIndex]["data-yc"] = "yc";
}
}
#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($"DivisionSubProjectsEdit.aspx?DivisionId=&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 > 2)
{
ShowNotify("最小节点无子节点!", MessageBoxIcon.Warning);
return;
}
PageContext.RegisterStartupScript(Window1.GetShowReference($"DivisionSubProjectsEdit.aspx?DivisionId=&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($"DivisionSubProjectsEdit.aspx?DivisionId={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.Division_SubProjects.FirstOrDefault(p => p.DivisionId == rowID);
if (model != null)
{
Funs.DB.Division_SubProjects.DeleteOnSubmit(model);
GetDevice(rowID);
}
Funs.DB.SubmitChanges();
}
/// <summary>
/// 删除
/// </summary>
private void GetDevice(string id)
{
var model = Funs.DB.Division_SubProjects.FirstOrDefault(p => p.ParentId == id);
if (model != null)
{
Funs.DB.Division_SubProjects.DeleteOnSubmit(model);
GetDevice(model.DivisionId);
}
}
/// <summary>
/// 判断是否为空
/// </summary>
/// <returns></returns>
public bool StrIsNumm(object value)
{
bool result = false;
if (value == null) result = true;
if (string.IsNullOrWhiteSpace(value.ToString())) result = true;
return result;
}
#endregion
}
}