Files
HJGL_DS/HJGL_DS/FineUIPro.Web/JGZL/ElectrostaticGrounding.aspx.cs
T

696 lines
28 KiB
C#

using BLL;
using Newtonsoft.Json.Linq;
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;
namespace FineUIPro.Web.JGZL
{
public partial class ElectrostaticGrounding : PageBase
{
#region
/// <summary>
/// 主键
/// </summary>
private string ElectrostaticGroundingId
{
get
{
return (string)ViewState["ElectrostaticGroundingId"];
}
set
{
ViewState["ElectrostaticGroundingId"] = value;
}
}
/// <summary>
/// 项目Id
/// </summary>
private string ProjectId
{
get
{
return (string)ViewState["ProjectId"];
}
set
{
ViewState["ProjectId"] = value;
}
}
/// <summary>
/// 定义集合
/// </summary>
private static List<Model.JGZL_ElectrostaticGrounding> items = new List<Model.JGZL_ElectrostaticGrounding>();
#endregion
#region
/// <summary>
/// 加载页面
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
this.ddlPageSize.SelectedValue = this.Grid1.PageSize.ToString();
this.drpProjectId.DataTextField = "ProjectCode";
this.drpProjectId.DataValueField = "ProjectId";
this.drpProjectId.DataSource = BLL.Base_ProjectService.GetOnProjectListByUserId(this.CurrUser.UserId, "1");
this.drpProjectId.DataBind();
Funs.FineUIPleaseSelect(this.drpProjectId);
this.drpProjectId.SelectedValue = this.CurrUser.LoginProjectId;
this.InitTreeMenu();//加载树
this.tvControlItem.SelectedNodeID = this.drpProjectId.SelectedValue;
this.ProjectId = this.tvControlItem.SelectedNodeID;
//管线
this.drpIsoId.DataTextField = "ISO_IsoNo";
this.drpIsoId.DataValueField = "ISO_IsoNo";
this.drpIsoId.DataSource = BLL.HJGL_PW_IsoInfoService.GetIsoInfoByProjectId(this.ProjectId);
this.drpIsoId.DataBind();
PageInfo();
}
}
private void PageInfo()
{
items.Clear();
if (!string.IsNullOrEmpty(this.ProjectId))
{
var reportLists = BLL.ElectrostaticGroundingService.GetElectrostaticGroundingLists(this.ProjectId);
if (reportLists.Count > 0)
{
var isoLists = BLL.HJGL_PW_IsoInfoService.GetIsoInfoByProjectId(this.ProjectId);
foreach (var item in isoLists)
{
var iso = (from x in Funs.DB.JGZL_ElectrostaticGrounding where x.ProjectId == this.ProjectId && x.PipelineCode == item.ISO_IsoNo select x).FirstOrDefault();
if (iso == null)
{
Model.JGZL_ElectrostaticGrounding newReport = new Model.JGZL_ElectrostaticGrounding();
newReport.ElectrostaticGroundingId = SQLHelper.GetNewID();
newReport.ProjectId = this.ProjectId;
newReport.PipelineCode = item.ISO_IsoNo;
reportLists.Add(newReport);
}
}
if (!string.IsNullOrEmpty(this.drpIsoId.SelectedValue) && this.drpIsoId.SelectedValue != BLL.Const._Null)
{
reportLists = reportLists.Where(x => x.PipelineCode.Contains(this.drpIsoId.SelectedValue)).ToList();
}
this.Grid1.DataSource = reportLists;
this.Grid1.DataBind();
}
else
{
var isoLists = BLL.HJGL_PW_IsoInfoService.GetIsoInfoByProjectId(this.ProjectId);
foreach (var iso in isoLists)
{
Model.JGZL_ElectrostaticGrounding newReport = new Model.JGZL_ElectrostaticGrounding();
newReport.ElectrostaticGroundingId = SQLHelper.GetNewID();
newReport.ProjectId = this.ProjectId;
newReport.PipelineCode = iso.ISO_IsoNo;
items.Add(newReport);
}
if (!string.IsNullOrEmpty(this.drpIsoId.SelectedValue) && this.drpIsoId.SelectedValue != BLL.Const._Null)
{
items = items.Where(x => x.PipelineCode.Contains(this.drpIsoId.SelectedValue)).ToList();
}
this.Grid1.DataSource = items;
this.Grid1.DataBind();
}
}
}
#endregion
#region
/// <summary>
/// 加载树
/// </summary>
private void InitTreeMenu()
{
this.tvControlItem.Nodes.Clear();
TreeNode rootNode = new TreeNode();
rootNode.Text = "项目";
rootNode.ToolTip = "项目";
rootNode.NodeID = "0";
rootNode.Expanded = true;
this.tvControlItem.Nodes.Add(rootNode);
List<Model.Base_Project> projects = BLL.Base_ProjectService.GetOnProjectListByUserId(this.CurrUser.UserId, "1");
if (this.drpProjectId.SelectedValue != BLL.Const._Null)
{
projects = projects.Where(e => e.ProjectId == this.drpProjectId.SelectedValue).ToList();
}
foreach (var item in projects)
{
TreeNode rootProjectNode = new TreeNode();//定义根节点
rootProjectNode.Text = item.ProjectCode;
rootProjectNode.NodeID = item.ProjectId;
rootProjectNode.EnableClickEvent = true;
rootProjectNode.Expanded = true;
rootProjectNode.ToolTip = item.ProjectName;
rootProjectNode.CommandName = "项目名称";
rootNode.Nodes.Add(rootProjectNode);
}
}
#endregion
#region TreeView
/// <summary>
/// 点击TreeView
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void tvControlItem_NodeCommand(object sender, TreeCommandEventArgs e)
{
if (this.tvControlItem.SelectedNodeID != "0")
{
this.ProjectId = this.tvControlItem.SelectedNodeID;
PageInfo();
//this.BindGrid();
}
}
#endregion
#region
/// <summary>
/// 数据绑定
/// </summary>
//private void BindGrid()
//{
// //string projectIds = BLL.Base_ProjectService.GetStrOnProjectIds(this.CurrUser.UserId, "1");
// string strSql = @"select g.ElectrostaticGroundingId,
// g.ProjectId,
// g.PipelineCode,
// g.ConnectionType,
// g.BWSpecification,
// g.BWMaterial,
// g.BWResistance,
// g.GWSpecification,
// g.GWMaterial,
// g.GWResistance,
// g.CompileMan,
// g.CompileDate,
// u.UserName as CompileManName
// from JGZL_ElectrostaticGrounding g
// left join Sys_User u on u.UserId=g.CompileMan where 1=1";
// List<SqlParameter> listStr = new List<SqlParameter>();
// if (!string.IsNullOrEmpty(this.tvControlItem.SelectedNodeID))
// {
// strSql += " AND g.ProjectId = @ProjectId";
// listStr.Add(new SqlParameter("@ProjectId", this.tvControlItem.SelectedNodeID));
// }
// //if (!string.IsNullOrEmpty(this.txtStartDate.Text))
// //{
// // strSql += " AND g.CompileDate >=@satartDate";
// // listStr.Add(new SqlParameter("@satartDate", Funs.GetNewDateTime(this.txtStartDate.Text)));
// //}
// //if (!string.IsNullOrEmpty(this.txtEndDate.Text))
// //{
// // strSql += " AND g.CompileDate <=@endDate";
// // listStr.Add(new SqlParameter("@endDate", Funs.GetNewDateTime(this.txtEndDate.Text)));
// //}
// //else
// //{
// // strSql += " AND CHARINDEX(ProjectId,@ProjectId)>0 ";
// // listStr.Add(new SqlParameter("@ProjectId", projectIds));
// //}
// SqlParameter[] parameter = listStr.ToArray();
// DataTable tb = SQLHelper.GetDataTableRunText(strSql, parameter);
// // 2.获取当前分页数据
// Grid1.RecordCount = tb.Rows.Count;
// //tb = GetFilteredTable(Grid1.FilteredData, tb);
// var table = this.GetPagedDataTable(Grid1, tb);
// Grid1.DataSource = table;
// Grid1.DataBind();
//}
#endregion
#region
#region
/// <summary>
/// 页索引改变事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Grid1_PageIndexChange(object sender, GridPageEventArgs e)
{
//BindGrid();
PageInfo();
}
#endregion
#region
/// <summary>
/// 排序
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Grid1_Sort(object sender, GridSortEventArgs e)
{
//BindGrid();
PageInfo();
}
#endregion
#region
/// <summary>
/// 分页选择下拉改变事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void ddlPageSize_SelectedIndexChanged(object sender, EventArgs e)
{
Grid1.PageSize = Convert.ToInt32(ddlPageSize.SelectedValue);
//BindGrid();
PageInfo();
}
#endregion
#endregion
#region
///<summary>
///查询
///</summary>
///<param name="sender"></param>
///<param name="e"></param>
protected void drpProjectId_SelectedIndexChanged(object sender, EventArgs e)
{
this.ProjectId= this.drpProjectId.SelectedValue;
this.InitTreeMenu();
this.tvControlItem.SelectedNodeID = this.ProjectId;
PageInfo();
//BindGrid();
}
/// <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 btnPrint_Click(object sender, EventArgs e)
{
//string projectId = this.tvControlItem.SelectedNodeID;
if (!string.IsNullOrEmpty(this.ProjectId))
{
string initTemplatePath = "";
string rootPath = Server.MapPath("~/");
BLL.Common.FastReportService.ResetData();
string strSql = @"select g.ElectrostaticGroundingId,
g.ProjectId,
g.PipelineCode,
g.ConnectionType,
g.BWSpecification,
g.BWMaterial,
g.BWResistance,
g.GWSpecification,
g.GWMaterial,
g.GWResistance,
g.CompileMan,
g.CompileDate,
u.UserName as CompileManName
from JGZL_ElectrostaticGrounding g
left join Sys_User u on u.UserId=g.CompileMan where g.ProjectId = @ProjectId";
List<SqlParameter> listStr = new List<SqlParameter>();
listStr.Add(new SqlParameter("@ProjectId", this.ProjectId));
if (!string.IsNullOrEmpty(this.drpIsoId.SelectedValue))
{
strSql += " and g.PipelineCode like @isoNo";
listStr.Add(new SqlParameter("@isoNo", "%" + this.drpIsoId.SelectedValue + "%"));
}
SqlParameter[] parameter = listStr.ToArray();
DataTable tb = SQLHelper.GetDataTableRunText(strSql, parameter);
if (tb.Rows.Count > 0)
{
DataTable dt = new DataTable();
dt.TableName = "Data";
dt.Columns.Add("PipelineCode");
dt.Columns.Add("ConnectionType");
dt.Columns.Add("BWSpecification");
dt.Columns.Add("BWMaterial");
dt.Columns.Add("BWResistance");
dt.Columns.Add("GWSpecification");
dt.Columns.Add("GWMaterial");
dt.Columns.Add("GWResistance");
tb.DefaultView.Sort = "PipelineCode ASC";
DataRow[] rows = tb.DefaultView.ToTable().Select();
foreach (var row in rows)
{
var newRow = dt.NewRow();
newRow["PipelineCode"] = row["PipelineCode"].ToString();
newRow["ConnectionType"] = row["ConnectionType"].ToString();
newRow["BWSpecification"] = row["BWSpecification"].ToString();
newRow["BWMaterial"] = row["BWMaterial"].ToString();
newRow["BWResistance"] = row["BWResistance"].ToString();
newRow["GWSpecification"] = row["GWSpecification"].ToString();
newRow["GWMaterial"] = row["GWMaterial"].ToString();
newRow["GWResistance"] = row["GWResistance"].ToString();
dt.Rows.Add(newRow);
}
BLL.Common.FastReportService.AddFastreportTable(dt);
Dictionary<string, string> keyValuePairs = new Dictionary<string, string>();
keyValuePairs.Add("ProjectName", BLL.Base_ProjectService.GetProjectByProjectId(this.ProjectId).ProjectName);
keyValuePairs.Add("CompileMan", tb.Rows[0]["CompileManName"].ToString());
if (!string.IsNullOrEmpty(tb.Rows[0]["CompileDate"].ToString()))
{
string compileDate = string.Format("{0:yyyy年MM月dd日}", tb.Rows[0]["CompileDate"]);
keyValuePairs.Add("CompileDate", compileDate);
}
BLL.Common.FastReportService.AddFastreportParameter(keyValuePairs);
initTemplatePath = "File\\Fastreport\\JGZL\\管道静电接地测试记录.frx";
if (File.Exists(rootPath + initTemplatePath))
{
PageContext.RegisterStartupScript(WindowPrint.GetShowReference(String.Format("../common/ReportPrint/Fastreport.aspx?ReportPath={0}", rootPath + initTemplatePath)));
}
}
else
{
Alert.ShowInTop("无打印数据!", MessageBoxIcon.Warning);
return;
}
}
else
{
Alert.ShowInTop("请选择项目!", MessageBoxIcon.Warning);
return;
}
}
#endregion
#region
/// <summary>
/// 增加
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnAdd_Click(object sender, EventArgs e)
{
if (!string.IsNullOrEmpty(this.tvControlItem.SelectedNodeID))
{
JArray teamGroupData = Grid1.GetMergedData();
List<JObject> list = new List<JObject>();
foreach (JObject teamGroupRow in teamGroupData)
{
JObject values = teamGroupRow.Value<JObject>("values");
list.Add(values);
}
JObject defaultObj = new JObject
{
{ "ElectrostaticGroundingId", Guid.NewGuid() },
{ "PipelineCode", "" },
{ "ConnectionType", "" },
{ "BWSpecification", "" },
{ "BWMaterial", "" },
{ "BWResistance", "" },
{ "GWSpecification", "" },
{ "GWMaterial", "" },
{ "GWResistance", "" },
{
"Delete3",
String.Format("<a href=\"javascript:;\" onclick=\"{0}\"><img src=\"{1}\"/></a>",
GetDeleteScriptGrid1(), IconHelper.GetResolvedIconUrl(Icon.Delete))
}
};
list.Add(defaultObj);
Grid1.DataSource = list;
Grid1.DataBind();
//PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("TeamWeldingInspectionEdit.aspx?projectId={0}", this.tvControlItem.SelectedNodeID, "新增 - ")));
}
else
{
Alert.ShowInTop("请选择项目!", MessageBoxIcon.Warning);
return;
}
}
protected void Grid1_PreDataBound(object sender, EventArgs e)
{
// 设置LinkButtonField的点击客户端事件
LinkButtonField deleteField = Grid1.FindColumn("Delete3") as LinkButtonField;
deleteField.OnClientClick = GetDeleteScriptGrid1();
}
/// <summary>
/// 删除提示
/// </summary>
/// <returns></returns>
private string GetDeleteScriptGrid1()
{
return Confirm.GetShowReference("删除选中行?", String.Empty, MessageBoxIcon.Question,
Grid1.GetDeleteSelectedRowsReference(), String.Empty);
}
/// <summary>
/// 双击编辑
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
//protected void Grid1_RowDoubleClick(object sender, GridRowClickEventArgs e)
//{
// if (BLL.CommonService.GetAllButtonPowerList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, BLL.Const.JGZL_ElectrostaticGroundingMenuId, BLL.Const.BtnModify))
// {
// if (!string.IsNullOrEmpty(this.tvControlItem.SelectedNodeID))
// {
// if (!string.IsNullOrEmpty(this.Grid1.SelectedRowID))
// {
// PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("ElectrostaticGroundingEdit.aspx?electrostaticGroundingId={0}", this.Grid1.SelectedRowID, "编辑 - ")));
// }
// else
// {
// Alert.ShowInTop("请选择一条记录!", MessageBoxIcon.Warning);
// return;
// }
// }
// else
// {
// Alert.ShowInTop("请选择项目!", MessageBoxIcon.Warning);
// return;
// }
// }
// else
// {
// ShowNotify("您没有这个权限,请与管理员联系!", MessageBoxIcon.Warning);
// }
//}
/// <summary>
/// 右键编辑
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
//protected void btnMenuEdit_Click(object sender, EventArgs e)
//{
// if (BLL.CommonService.GetAllButtonPowerList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, BLL.Const.JGZL_ElectrostaticGroundingMenuId, BLL.Const.BtnModify))
// {
// if (Grid1.SelectedRowIndexArray.Length == 0)
// {
// Alert.ShowInTop("请选择一条记录!", MessageBoxIcon.Warning);
// return;
// }
// PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("ElectrostaticGroundingEdit.aspx?electrostaticGroundingId={0}", Grid1.SelectedRowID, "维护 - ")));
// }
// else
// {
// Alert.ShowInTop("您没有这个权限,请与管理员联系!", MessageBoxIcon.Warning);
// }
//}
/// <summary>
/// 右键删除
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
//protected void btnMenuDelete_Click(object sender, EventArgs e)
//{
// if (CommonService.GetAllButtonPowerList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, Const.JGZL_ElectrostaticGroundingMenuId, Const.BtnDelete))
// {
// if (Grid1.SelectedRowIndexArray.Length == 0)
// {
// Alert.ShowInTop("请选择一条记录!", MessageBoxIcon.Warning);
// return;
// }
// bool isShow = true;
// if (Grid1.SelectedRowIndexArray.Length > 1)
// {
// isShow = false;
// }
// bool isDelete = false;
// foreach (int rowIndex in Grid1.SelectedRowIndexArray)
// {
// string rowID = Grid1.DataKeys[rowIndex][0].ToString();
// if (judgementDelete(rowID, isShow))
// {
// isDelete = true;
// BLL.ElectrostaticGroundingService.DeleteElectrostaticGroundingById(rowID);
// BLL.Sys_LogService.AddLog(BLL.Const.System_3, this.CurrUser.LoginProjectId, this.CurrUser.UserId, "删除管道静电接地测试记录");
// }
// }
// if (isDelete)
// {
// ShowNotify("删除成功!", MessageBoxIcon.Success);
// }
// this.BindGrid();
// }
// else
// {
// Alert.ShowInTop("您没有这个权限,请与管理员联系!", MessageBoxIcon.Warning);
// }
//}
#region
/// <summary>
/// 判断是否可以删除
/// </summary>
/// <returns></returns>
//private bool judgementDelete(string id, bool isShow)
//{
// string content = string.Empty;
// if (string.IsNullOrEmpty(content))
// {
// return true;
// }
// else
// {
// if (isShow)
// {
// Alert.ShowInTop(content, MessageBoxIcon.Error);
// }
// return false;
// }
//}
#endregion
#endregion
#region
/// <summary>
/// 关闭弹出窗口
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
//protected void Window1_Close(object sender, WindowCloseEventArgs e)
//{
// this.InitTreeMenu();//加载树
// this.BindGrid();
//}
#endregion
#region
/// <summary>
/// 查询
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Text_TextChanged(object sender, EventArgs e)
{
//DateTime startDate = Convert.ToDateTime(this.txtStartDate.Text);
//DateTime endDate = Convert.ToDateTime(this.txtEndDate.Text);
//if (startDate != null && endDate != null && startDate > endDate)
//{
// Alert.ShowInTop("开始时间不能大于结束时间!", MessageBoxIcon.Warning);
// return;
//}
//else
//{
// BindGrid();
//}
}
#endregion
#region
/// <summary>
/// 提交按钮
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnSave_Click(object sender, EventArgs e)
{
if (CommonService.GetAllButtonPowerList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, Const.JGZL_ElectrostaticGroundingMenuId, Const.BtnSave))
{
items.Clear();
BLL.ElectrostaticGroundingService.DeleteDeleteElectrostaticGroundingByProjectId(this.ProjectId);
JArray teamGroupData = Grid1.GetMergedData();
foreach (JObject teamGroupRow in teamGroupData)
{
JObject values = teamGroupRow.Value<JObject>("values");
int rowIndex = teamGroupRow.Value<int>("index");
Model.JGZL_ElectrostaticGrounding newDetail = new Model.JGZL_ElectrostaticGrounding
{
ElectrostaticGroundingId = values.Value<string>("ElectrostaticGroundingId"),
ProjectId = this.ProjectId,
PipelineCode = values.Value<string>("PipelineCode"),
ConnectionType = values.Value<string>("ConnectionType"),
BWSpecification = values.Value<string>("BWSpecification"),
BWMaterial = values.Value<string>("BWMaterial"),
BWResistance = Funs.GetNewDecimal(values.Value<string>("BWResistance")),
GWSpecification = values.Value<string>("GWSpecification"),
GWMaterial = values.Value<string>("GWMaterial"),
GWResistance = Funs.GetNewDecimal(values.Value<string>("GWResistance")),
CompileMan = this.CurrUser.UserId,
CompileDate = DateTime.Now
};
items.Add(newDetail);
}
try
{
if (items.Count > 0)
{
Funs.DB.JGZL_ElectrostaticGrounding.InsertAllOnSubmit(items);
}
Funs.DB.SubmitChanges();
}
catch (Exception)
{
return;
}
ShowNotify("保存成功!", MessageBoxIcon.Success);
//PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference());
}
else
{
Alert.ShowInTop("您没有这个权限,请与管理员联系!", MessageBoxIcon.Warning);
return;
}
}
#endregion
protected void drpIsoId_SelectedIndexChanged(object sender, EventArgs e)
{
PageInfo();
}
}
}