YZ_BSF/HJGL/FineUIPro.Web/PublicInfo/BaseInfo/PipingClassDetail.aspx.cs

555 lines
22 KiB
C#
Raw Normal View History

2024-05-13 08:48:51 +08:00
using BLL;
using Model;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.IO;
using System.Linq;
namespace FineUIPro.Web.PublicInfo.BaseInfo
{
public partial class PipingClassDetail : PageBase
{
#region
/// <summary>
/// 加载页面
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
this.ddlPageSize.SelectedValue = Grid1.PageSize.ToString();
string pipingClassId = Request.Params["PipingClassId"];
if (!string.IsNullOrEmpty(pipingClassId))
{
var pipingClass = BLL.Base_PipingClassService.GetPipingClassByPipingClassId(pipingClassId);
if (pipingClass!=null)
{
this.lbPipingClassCode.Text = pipingClass.PipingClassCode;
}
}
// 绑定表格
this.BindGrid();
}
}
#endregion
#region
/// <summary>
/// 绑定数据
/// </summary>
private void BindGrid()
{
string strSql = @"SELECT PipingClassDetailId
,PipingClassId
,WeldTypeId
,DetectionTypeId
,DetectionRateId
,AcceptLevel
,SizeMin
,SizeMax
,ThicknessMin
,ThicknessMax
,PipingClassCode
,PipingClassName
,WeldTypeCode
,DetectionTypeCode
,DetectionRateCode
,(convert(varchar, SizeMin) + '-' + (convert(varchar, SizeMax))) as Size
,(convert(varchar, ThicknessMin) + '-' + (convert(varchar, ThicknessMax))) as Thickness"
+ @" FROM dbo.View_Base_PipingClassDetail WHERE PipingClassId=@PipingClassId";
List<SqlParameter> listStr = new List<SqlParameter>();
listStr.Add(new SqlParameter("@PipingClassId", Request.Params["PipingClassId"]));
SqlParameter[] parameter = listStr.ToArray();
DataTable tb = SQLHelper.GetDataTableRunText(strSql, parameter);
Grid1.RecordCount = tb.Rows.Count;
//tb = GetFilteredTable(Grid1.FilteredData, tb);
var table = this.GetPagedDataTable(Grid1, tb);
Grid1.DataSource = table;
Grid1.DataBind();
}
/// <summary>
/// 改变索引事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Grid1_PageIndexChange(object sender, GridPageEventArgs e)
{
BindGrid();
}
/// <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();
}
/// <summary>
/// 排序
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Grid1_Sort(object sender, FineUIPro.GridSortEventArgs e)
{
BindGrid();
}
/// <summary>
/// 关闭弹出窗口
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Window1_Close(object sender, EventArgs e)
{
BindGrid();
}
#endregion
#region
/// <summary>
/// 增加按钮事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnNew_Click(object sender, EventArgs e)
{
if (GetButtonPower(Const.BtnAdd))
{
PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("PipingClassDetailEdit.aspx?PipingClassId={0}", Request.Params["PipingClassId"], "新增 - ")));
}
else
{
Alert.ShowInTop(Resources.Lan.NoPrivilegePrompt, MessageBoxIcon.Warning);
return;
}
}
#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(Resources.Lan.SelectLeastOneRecord, MessageBoxIcon.Warning);
return;
}
////双击事件 编辑权限有:编辑页面,无:查看页面 或者状态是完成时查看页面
if (GetButtonPower(Const.BtnModify))
{
PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("PipingClassDetailEdit.aspx?PipingClassDetailId={0}", Grid1.SelectedRowID, "编辑 - ")));
}
else if (GetButtonPower(Const.BtnSee))
{
PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("PipingClassDetailView.aspx?PipingClassDetailId={0}", Grid1.SelectedRowID, "查看 - ")));
}
else
{
Alert.ShowInTop(Resources.Lan.NoPrivilegePrompt, MessageBoxIcon.Warning);
return;
}
}
#endregion
#region
/// <summary>
/// 右键删除事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnMenuDelete_Click(object sender, EventArgs e)
{
if (GetButtonPower(Const.BtnDelete))
{
if (Grid1.SelectedRowIndexArray.Length > 0)
{
string strShowNotify = string.Empty;
foreach (int rowIndex in Grid1.SelectedRowIndexArray)
{
string rowID = Grid1.DataKeys[rowIndex][0].ToString();
var getPipingClass = BLL.Base_PipingClassDetailService.GetPipingClassDetailById(rowID);
if (getPipingClass != null)
{
string cont = judgementDelete(rowID);
if (string.IsNullOrEmpty(cont))
{
BLL.Base_PipingClassDetailService.DeletePipingClassDetailById(rowID);
//BLL.LogService.AddLog(this.CurrUser.LoginProjectId, this.CurrUser.UserId, "删除管道等级信息");
}
//else
//{
// strShowNotify += Resources.Lan.PipingClass + "" + getPipingClass.PipingClassId + cont;
//}
}
}
BindGrid();
if (!string.IsNullOrEmpty(strShowNotify))
{
Alert.ShowInTop(strShowNotify, MessageBoxIcon.Warning);
}
else
{
ShowNotify(Resources.Lan.DeletedSuccessfully, MessageBoxIcon.Success);
}
}
}
else
{
Alert.ShowInTop(Resources.Lan.NoPrivilegePrompt, MessageBoxIcon.Warning);
return;
}
}
#region
/// <summary>
/// 判断是否可以删除
/// </summary>
/// <returns></returns>
private string judgementDelete(string id)
{
string content = string.Empty;
//if (Funs.DB.Project_ProjectUser.FirstOrDefault(x => x.UserId == id) != null)
//{
// content += "已在【项目用户】中使用,不能删除!";
//}
return content;
}
#endregion
#endregion
#region
/// <summary>
/// 查看按钮
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnView_Click(object sender, EventArgs e)
{
PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("PipingClassDetailView.aspx?PipingClassDetailId={0}", Grid1.SelectedRowID, "查看 - ")));
}
#endregion
#region
/// <summary>
/// 获取按钮权限
/// </summary>
/// <param name="button"></param>
/// <returns></returns>
private bool GetButtonPower(string button)
{
return BLL.CommonService.GetAllButtonPowerList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, BLL.Const.HJGL_PipingClassMenuId, button);
}
#endregion
#region
/// <summary>
/// 模板下载
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnDownLoad_Click(object sender, EventArgs e)
{
string rootPath = Server.MapPath("~/");
string uploadfilepath = rootPath + Const.PipeClassTemplateUrl;
string filePath = Const.PipeClassTemplateUrl;
string fileName = Path.GetFileName(filePath);
FileInfo info = new FileInfo(uploadfilepath);
long fileSize = info.Length;
Response.ClearContent();
Response.AddHeader("Content-Disposition", "attachment;filename=" + System.Web.HttpUtility.UrlEncode(fileName, System.Text.Encoding.UTF8));
Response.ContentType = "excel/plain";
Response.ContentEncoding = System.Text.Encoding.UTF8;
Response.AddHeader("Content-Length", fileSize.ToString().Trim());
Response.TransmitFile(uploadfilepath, 0, fileSize);
Response.End();
}
#endregion
#region
/// <summary>
/// 上传预设的虚拟路径
/// </summary>
private string initPath = Const.ExcelUrl;
/// <summary>
/// 错误集合
/// </summary>
public static string errorInfos = string.Empty;
#endregion
#region
/// <summary>
/// 导入
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnImport_Click(object sender, EventArgs e)
{
string message = string.Empty;
errorInfos = string.Empty;
List<Base_PipingClassDetail> pipeClass = new List<Base_PipingClassDetail>();
string pipingClassId = Request.Params["PipingClassId"];
try
{
if (this.fuAttachUrl.HasFile == false)
{
ShowNotify("请选择 Excel 文件!", MessageBoxIcon.Warning);
return;
}
string IsXls = Path.GetExtension(this.fuAttachUrl.FileName).ToString().Trim().ToLower();
if (IsXls != ".xls" && IsXls != ".xlsx")
{
ShowNotify("只能选择 Excel 文件!", MessageBoxIcon.Warning);
return;
}
if (pipeClass != null)
{
pipeClass.Clear();
}
if (!string.IsNullOrEmpty(errorInfos))
{
errorInfos = string.Empty;
}
string rootPath = Server.MapPath("~/");
string initFullPath = rootPath + initPath;
if (!Directory.Exists(initFullPath))
{
Directory.CreateDirectory(initFullPath);
}
//指定上传文件名称
this.hdFileName.Text = BLL.Funs.GetNewFileName() + IsXls;
//上传文件路径
string filePath = initFullPath + this.hdFileName.Text;
//文件上传服务器
this.fuAttachUrl.PostedFile.SaveAs(filePath);
//文件上传服务器后的名称
string fileName = rootPath + initPath + this.hdFileName.Text;
//读取Excel
DataSet ds = NPOIHelper.ExcelToDataSet(fileName, out errorInfos, true);
//验证Excel读取是否有误
if (!string.IsNullOrEmpty(errorInfos))
{
ShowNotify(errorInfos, MessageBoxIcon.Warning);
return;
}
//导入数据库
if (ds.Tables.Count > 0)
{
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
Base_PipingClassDetail d = new Base_PipingClassDetail();
#region
string pipingClassCode = ds.Tables[0].Rows[i]["PipingClassCode"].ToString();
if (pipingClassCode != null && !string.IsNullOrEmpty(pipingClassCode))
{
if (pipingClassCode == lbPipingClassCode.Text.Trim())
{
d.PipingClassId = pipingClassId;
}
else
{
errorInfos += (i + 2) + "行, 管道等级代号和选择的不一至!</br>";
}
}
else
{
errorInfos += (i + 2) + "行, 管道等级代号不能为空!</br>";
}
string weldTypeCode = ds.Tables[0].Rows[i]["WeldTypeCode"].ToString();
if (weldTypeCode != null && !string.IsNullOrEmpty(weldTypeCode))
{
var weldType= Funs.DB.Base_WeldType.FirstOrDefault(x => x.WeldTypeCode == weldTypeCode);
if (weldType != null)
{
d.WeldTypeId = weldType.WeldTypeId;
}
else
{
errorInfos += (i + 2) + "行, 焊缝类型代号不存在!</br>";
}
}
else
{
errorInfos += (i + 2) + "行, 焊缝类型代号不能为空!</br>";
}
string detectionTypeCode = ds.Tables[0].Rows[i]["DetectionTypeCode"].ToString();
if (detectionTypeCode != null && !string.IsNullOrEmpty(detectionTypeCode))
{
var detectionType = Funs.DB.Base_DetectionType.FirstOrDefault(x => x.DetectionTypeCode == detectionTypeCode);
if (detectionType != null)
{
d.DetectionTypeId = detectionType.DetectionTypeId;
}
else
{
errorInfos += (i + 2) + "行, 探伤类型代号不存在!</br>";
}
}
else
{
errorInfos += (i + 2) + "行, 探伤类型代号不能为空!</br>";
}
string detectionRateCode = ds.Tables[0].Rows[i]["DetectionRateCode"].ToString();
if (detectionRateCode != null && !string.IsNullOrEmpty(detectionRateCode))
{
var detectionRate = Funs.DB.Base_DetectionRate.FirstOrDefault(x => x.DetectionRateCode == detectionRateCode);
if (detectionRate != null)
{
d.DetectionRateId = detectionRate.DetectionRateId;
}
else
{
errorInfos += (i + 2) + "行, 探伤比例代号不存在!</br>";
}
}
else
{
errorInfos += (i + 2) + "行, 探伤比例代号不能为空!</br>";
}
decimal? diaMin = BLL.Funs.GetNewDecimal(ds.Tables[0].Rows[i]["DiaMin"].ToString());
if (diaMin != null)
{
d.SizeMin = diaMin;
}
else
{
errorInfos += (i + 2) + "行, [DiaMin] 不能为空并且为数字型!</br>";
}
decimal? diaMax = BLL.Funs.GetNewDecimal(ds.Tables[0].Rows[i]["DiaMax"].ToString());
if (diaMax != null)
{
d.SizeMax = diaMax;
}
else
{
errorInfos += (i + 2) + "行, [DiaMax] 不能为空并且为数字型!</br>";
}
decimal? thicknessMin = BLL.Funs.GetNewDecimal(ds.Tables[0].Rows[i]["ThicknessMin"].ToString());
if (thicknessMin != null)
{
d.ThicknessMin = thicknessMin;
}
else
{
errorInfos += (i + 2) + "行, [ThicknessMin] 不能为空并且为数字型!</br>";
}
decimal? thicknessMax = BLL.Funs.GetNewDecimal(ds.Tables[0].Rows[i]["ThicknessMax"].ToString());
if (thicknessMax != null)
{
d.ThicknessMax = thicknessMax;
}
else
{
errorInfos += (i + 2) + "行, [ThicknessMax] 不能为空并且为数字型!</br>";
}
string acceptLevel = ds.Tables[0].Rows[i]["AcceptLevel"].ToString();
if (!string.IsNullOrEmpty(acceptLevel))
{
if (acceptLevel != "" && acceptLevel != "Ⅱ" && acceptLevel != "Ⅲ" && acceptLevel != "Ⅳ" && acceptLevel != "")
{
errorInfos += (i + 2) + "行, [AcceptLevel] 格式应为Ⅰ,Ⅱ,Ⅲ,Ⅳ,Ⅴ五种!</br>";
}
else
{
d.AcceptLevel = acceptLevel;
}
}
pipeClass.Add(d);
#endregion
}
if (!string.IsNullOrEmpty(errorInfos))
{
ShowNotify(errorInfos, MessageBoxIcon.Warning);
return;
}
if (pipeClass.Count > 0)
{
BLL.Base_PipingClassDetailService.DeleteAllPipingClassDetail(pipingClassId);
foreach (var item in pipeClass)
{
Model.Base_PipingClassDetail detail = new Base_PipingClassDetail();
detail.PipingClassDetailId = SQLHelper.GetNewID(typeof(Model.Base_PipingClassDetail));
detail.PipingClassId = pipingClassId;
detail.WeldTypeId = item.WeldTypeId;
detail.DetectionTypeId = item.DetectionTypeId;
detail.DetectionRateId = item.DetectionRateId;
detail.SizeMin = item.SizeMin;
detail.SizeMax = item.SizeMax;
detail.ThicknessMin = item.ThicknessMin;
detail.ThicknessMax = item.ThicknessMax;
detail.AcceptLevel = item.AcceptLevel;
BLL.Base_PipingClassDetailService.AddPipingClassDetail(detail);
}
}
ShowNotify("导入成功!", MessageBoxIcon.Success);
PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference());
}
else
{
ShowAlert("No data!", MessageBoxIcon.Warning);
return;
}
}
catch (Exception ex)
{
ShowAlert("'" + ex.Message + "'", MessageBoxIcon.Warning);
}
}
#endregion
}
}