55944d732a
排除 CreateModel.bat(含明文sa密码与本地服务器名,未入库)
316 lines
14 KiB
C#
316 lines
14 KiB
C#
using System;
|
||
using System.Collections.Generic;
|
||
using System.Data;
|
||
using System.Linq;
|
||
using System.Web;
|
||
|
||
namespace FineUIPro.Web.HSSE.PowerMG
|
||
{
|
||
/// <summary>
|
||
/// 配电箱信息实体(模拟数据阶段使用,接入数据库后可删除)
|
||
/// </summary>
|
||
public class PowerBoxInfo
|
||
{
|
||
/// <summary>
|
||
/// 主键
|
||
/// </summary>
|
||
public string PowerBoxId { get; set; }
|
||
|
||
/// <summary>
|
||
/// 配电箱编号
|
||
/// </summary>
|
||
public string PowerBoxCode { get; set; }
|
||
|
||
/// <summary>
|
||
/// 配电箱名称/型号
|
||
/// </summary>
|
||
public string PowerBoxName { get; set; }
|
||
|
||
/// <summary>
|
||
/// 类型(总配电箱/分配电箱/开关箱)
|
||
/// </summary>
|
||
public string BoxType { get; set; }
|
||
|
||
/// <summary>
|
||
/// 安装位置
|
||
/// </summary>
|
||
public string InstallPlace { get; set; }
|
||
|
||
/// <summary>
|
||
/// 额定容量(A)
|
||
/// </summary>
|
||
public string RatedCapacity { get; set; }
|
||
|
||
/// <summary>
|
||
/// 电压等级
|
||
/// </summary>
|
||
public string VoltageLevel { get; set; }
|
||
|
||
/// <summary>
|
||
/// 责任单位
|
||
/// </summary>
|
||
public string ManagerUnit { get; set; }
|
||
|
||
/// <summary>
|
||
/// 责任人
|
||
/// </summary>
|
||
public string ManagerMan { get; set; }
|
||
|
||
/// <summary>
|
||
/// 联系电话
|
||
/// </summary>
|
||
public string ManagerTel { get; set; }
|
||
|
||
/// <summary>
|
||
/// 状态(正常/停用/维修中)
|
||
/// </summary>
|
||
public string States { get; set; }
|
||
|
||
/// <summary>
|
||
/// 最近巡检日期
|
||
/// </summary>
|
||
public DateTime? LastCheckDate { get; set; }
|
||
|
||
/// <summary>
|
||
/// 备注
|
||
/// </summary>
|
||
public string Remark { get; set; }
|
||
}
|
||
|
||
/// <summary>
|
||
/// 配电箱管理页面(当前为模拟数据演示,数据存于 Session,后续接入数据库)
|
||
/// </summary>
|
||
public partial class PowerBox : PageBase
|
||
{
|
||
/// <summary>
|
||
/// 模拟数据Session键
|
||
/// </summary>
|
||
public const string MockSessionKey = "PowerBoxMockData";
|
||
|
||
#region 加载
|
||
/// <summary>
|
||
/// 加载页面
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
protected void Page_Load(object sender, EventArgs e)
|
||
{
|
||
if (!IsPostBack)
|
||
{
|
||
this.InitMockData();
|
||
this.btnNew.OnClientClick = Window1.GetShowReference("PowerBoxEdit.aspx") + "return false;";
|
||
this.ddlPageSize.SelectedValue = Grid1.PageSize.ToString();
|
||
this.BindGrid();
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 模拟数据(先以模拟数据演示,接入数据库后删除本区域代码)
|
||
/// <summary>
|
||
/// 初始化模拟数据(Session为空时生成)
|
||
/// </summary>
|
||
private void InitMockData()
|
||
{
|
||
if (Session[MockSessionKey] == null)
|
||
{
|
||
Session[MockSessionKey] = CreateMockData();
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 获取模拟数据列表(来自Session)
|
||
/// </summary>
|
||
private List<PowerBoxInfo> GetMockList()
|
||
{
|
||
return Session[MockSessionKey] as List<PowerBoxInfo>;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 生成初始模拟数据
|
||
/// </summary>
|
||
private List<PowerBoxInfo> CreateMockData()
|
||
{
|
||
List<PowerBoxInfo> list = new List<PowerBoxInfo>();
|
||
list.Add(new PowerBoxInfo { PowerBoxId = Guid.NewGuid().ToString(), PowerBoxCode = "PDX-001", PowerBoxName = "总配电箱1#(XL-21型)", BoxType = "总配电箱", InstallPlace = "项目部西侧配电房", RatedCapacity = "630", VoltageLevel = "380V", ManagerUnit = "河北安装一分公司", ManagerMan = "张建国", ManagerTel = "13800001201", States = "正常", LastCheckDate = new DateTime(2026, 1, 10), Remark = "" });
|
||
list.Add(new PowerBoxInfo { PowerBoxId = Guid.NewGuid().ToString(), PowerBoxCode = "PDX-002", PowerBoxName = "分配电箱1#楼", BoxType = "分配电箱", InstallPlace = "1#楼一层东侧", RatedCapacity = "250", VoltageLevel = "380V", ManagerUnit = "河北安装一分公司", ManagerMan = "李卫东", ManagerTel = "13800001202", States = "正常", LastCheckDate = new DateTime(2026, 1, 8), Remark = "" });
|
||
list.Add(new PowerBoxInfo { PowerBoxId = Guid.NewGuid().ToString(), PowerBoxCode = "PDX-003", PowerBoxName = "分配电箱2#楼", BoxType = "分配电箱", InstallPlace = "2#楼一层西侧", RatedCapacity = "250", VoltageLevel = "380V", ManagerUnit = "河北安装一分公司", ManagerMan = "李卫东", ManagerTel = "13800001203", States = "正常", LastCheckDate = new DateTime(2026, 1, 5), Remark = "" });
|
||
list.Add(new PowerBoxInfo { PowerBoxId = Guid.NewGuid().ToString(), PowerBoxCode = "PDX-004", PowerBoxName = "开关箱1-1", BoxType = "开关箱", InstallPlace = "1#楼三层南侧", RatedCapacity = "63", VoltageLevel = "380V", ManagerUnit = "河北安装一分公司", ManagerMan = "王强", ManagerTel = "13800001204", States = "正常", LastCheckDate = new DateTime(2026, 1, 12), Remark = "" });
|
||
list.Add(new PowerBoxInfo { PowerBoxId = Guid.NewGuid().ToString(), PowerBoxCode = "PDX-005", PowerBoxName = "开关箱1-2", BoxType = "开关箱", InstallPlace = "1#楼五层北侧", RatedCapacity = "63", VoltageLevel = "380V", ManagerUnit = "河北安装一分公司", ManagerMan = "王强", ManagerTel = "13800001205", States = "维修中", LastCheckDate = new DateTime(2025, 12, 28), Remark = "漏电保护器故障,待更换" });
|
||
list.Add(new PowerBoxInfo { PowerBoxId = Guid.NewGuid().ToString(), PowerBoxCode = "PDX-006", PowerBoxName = "总配电箱2#", BoxType = "总配电箱", InstallPlace = "生活区东侧", RatedCapacity = "400", VoltageLevel = "380V", ManagerUnit = "河北安装二分公司", ManagerMan = "刘志刚", ManagerTel = "13800001206", States = "正常", LastCheckDate = new DateTime(2026, 1, 11), Remark = "" });
|
||
list.Add(new PowerBoxInfo { PowerBoxId = Guid.NewGuid().ToString(), PowerBoxCode = "PDX-007", PowerBoxName = "分配电箱生活区", BoxType = "分配电箱", InstallPlace = "生活区食堂旁", RatedCapacity = "160", VoltageLevel = "380V", ManagerUnit = "河北安装二分公司", ManagerMan = "刘志刚", ManagerTel = "13800001207", States = "正常", LastCheckDate = new DateTime(2026, 1, 6), Remark = "" });
|
||
list.Add(new PowerBoxInfo { PowerBoxId = Guid.NewGuid().ToString(), PowerBoxCode = "PDX-008", PowerBoxName = "开关箱钢筋棚", BoxType = "开关箱", InstallPlace = "钢筋加工棚北侧", RatedCapacity = "63", VoltageLevel = "380V", ManagerUnit = "河北安装二分公司", ManagerMan = "赵磊", ManagerTel = "13800001208", States = "停用", LastCheckDate = new DateTime(2025, 12, 20), Remark = "钢筋棚搬迁后停用" });
|
||
list.Add(new PowerBoxInfo { PowerBoxId = Guid.NewGuid().ToString(), PowerBoxCode = "PDX-009", PowerBoxName = "分配电箱塔吊1#", BoxType = "分配电箱", InstallPlace = "1#塔吊基础旁", RatedCapacity = "250", VoltageLevel = "380V", ManagerUnit = "河北安装三分公司", ManagerMan = "孙立新", ManagerTel = "13800001209", States = "正常", LastCheckDate = new DateTime(2026, 1, 9), Remark = "" });
|
||
list.Add(new PowerBoxInfo { PowerBoxId = Guid.NewGuid().ToString(), PowerBoxCode = "PDX-010", PowerBoxName = "开关箱塔吊1#", BoxType = "开关箱", InstallPlace = "1#塔吊操作室", RatedCapacity = "40", VoltageLevel = "380V", ManagerUnit = "河北安装三分公司", ManagerMan = "孙立新", ManagerTel = "13800001210", States = "正常", LastCheckDate = new DateTime(2026, 1, 9), Remark = "" });
|
||
return list;
|
||
}
|
||
#endregion
|
||
|
||
#region 数据绑定
|
||
/// <summary>
|
||
/// 绑定数据
|
||
/// </summary>
|
||
private void BindGrid()
|
||
{
|
||
List<PowerBoxInfo> list = GetMockList();
|
||
if (list == null)
|
||
{
|
||
this.InitMockData();
|
||
list = GetMockList();
|
||
}
|
||
////查询条件过滤
|
||
string code = this.txtPowerBoxCode.Text.Trim();
|
||
if (!string.IsNullOrEmpty(code))
|
||
{
|
||
list = list.Where(x => x.PowerBoxCode.Contains(code)).ToList();
|
||
}
|
||
string name = this.txtPowerBoxName.Text.Trim();
|
||
if (!string.IsNullOrEmpty(name))
|
||
{
|
||
list = list.Where(x => x.PowerBoxName.Contains(name)).ToList();
|
||
}
|
||
if (!string.IsNullOrEmpty(this.ddlBoxType.SelectedValue))
|
||
{
|
||
list = list.Where(x => x.BoxType == this.ddlBoxType.SelectedValue).ToList();
|
||
}
|
||
if (!string.IsNullOrEmpty(this.ddlStates.SelectedValue))
|
||
{
|
||
list = list.Where(x => x.States == this.ddlStates.SelectedValue).ToList();
|
||
}
|
||
Grid1.RecordCount = list.Count;
|
||
var table = this.GetPagedDataTable(Grid1, list);
|
||
Grid1.DataSource = table;
|
||
Grid1.DataBind();
|
||
}
|
||
|
||
/// <summary>
|
||
/// 分页事件
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
protected void Grid1_PageIndexChange(object sender, GridPageEventArgs e)
|
||
{
|
||
this.BindGrid();
|
||
}
|
||
|
||
/// <summary>
|
||
/// 每页记录数下拉事件
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
protected void ddlPageSize_SelectedIndexChanged(object sender, EventArgs e)
|
||
{
|
||
this.Grid1.PageSize = Convert.ToInt32(this.ddlPageSize.SelectedValue);
|
||
this.BindGrid();
|
||
}
|
||
|
||
/// <summary>
|
||
/// 排序事件
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
protected void Grid1_Sort(object sender, GridSortEventArgs e)
|
||
{
|
||
this.BindGrid();
|
||
}
|
||
#endregion
|
||
|
||
#region 查询
|
||
/// <summary>
|
||
/// 查询
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
protected void TextBox_TextChanged(object sender, EventArgs e)
|
||
{
|
||
this.BindGrid();
|
||
}
|
||
#endregion
|
||
|
||
#region 编辑
|
||
/// <summary>
|
||
/// 双击行编辑事件
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
protected void Grid1_RowDoubleClick(object sender, GridRowClickEventArgs e)
|
||
{
|
||
this.EditData();
|
||
}
|
||
|
||
/// <summary>
|
||
/// 右键菜单编辑事件
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
protected void btnMenuEdit_Click(object sender, EventArgs e)
|
||
{
|
||
this.EditData();
|
||
}
|
||
|
||
/// <summary>
|
||
/// 编辑数据方法
|
||
/// </summary>
|
||
private void EditData()
|
||
{
|
||
if (Grid1.SelectedRowIndexArray.Length == 0)
|
||
{
|
||
Alert.ShowInTop("请至少选择一条记录!", MessageBoxIcon.Warning);
|
||
return;
|
||
}
|
||
string id = Grid1.SelectedRowID;
|
||
PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("PowerBoxEdit.aspx?PowerBoxId={0}", id)));
|
||
}
|
||
#endregion
|
||
|
||
#region 删除
|
||
/// <summary>
|
||
/// 右键菜单删除事件
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
protected void btnMenuDelete_Click(object sender, EventArgs e)
|
||
{
|
||
if (Grid1.SelectedRowIndexArray.Length > 0)
|
||
{
|
||
List<PowerBoxInfo> list = GetMockList();
|
||
foreach (int rowIndex in Grid1.SelectedRowIndexArray)
|
||
{
|
||
string rowID = Grid1.DataKeys[rowIndex][0].ToString();
|
||
list.RemoveAll(x => x.PowerBoxId == rowID);
|
||
}
|
||
Session[MockSessionKey] = list;
|
||
this.BindGrid();
|
||
ShowNotify("删除数据成功!", MessageBoxIcon.Success);
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 二维码
|
||
/// <summary>
|
||
/// 生成巡检二维码(模拟阶段:二维码内容为配电箱标识,接入数据库后可改为巡检URL)
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
protected void btnQR_Click(object sender, EventArgs e)
|
||
{
|
||
if (Grid1.SelectedRowIndexArray.Length == 0)
|
||
{
|
||
Alert.ShowInTop("请选择一条记录!", MessageBoxIcon.Warning);
|
||
return;
|
||
}
|
||
string id = Grid1.SelectedRowID;
|
||
List<PowerBoxInfo> list = GetMockList();
|
||
PowerBoxInfo info = list.FirstOrDefault(x => x.PowerBoxId == id);
|
||
if (info != null)
|
||
{
|
||
////二维码内容:配电箱标识(编号),后续可替换为巡检页面URL
|
||
string strValue = "powerbox$" + info.PowerBoxCode;
|
||
string urlName = info.PowerBoxCode;
|
||
string title = "配电箱:" + info.PowerBoxCode + " " + info.PowerBoxName;
|
||
PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("~/Controls/ShowQRImage.aspx?strValue={0}&urlName={1}&title={2}", strValue, urlName, System.Web.HttpUtility.UrlEncode(title)), "巡检二维码", 340, 400));
|
||
}
|
||
}
|
||
#endregion
|
||
}
|
||
}
|