using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using BLL;
using System.Web;
using NPOI.XSSF.UserModel;
using NPOI.SS.Util;
using System.IO;
using NPOI.SS.UserModel;
namespace FineUIPro.Web.HJGL.WeldingManage
{
public partial class JointInfo : PageBase
{
///
/// 定义集合
///
private static List list = new List();
#region 加载
///
/// 加载页面
///
///
///
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
this.ddlPageSize.SelectedValue = this.Grid1.PageSize.ToString();
this.InitTreeMenu();//加载树
Funs.FineUIPleaseSelect(this.drpRTState);
Funs.FineUIPleaseSelect(this.drpUTState);
Funs.FineUIPleaseSelect(this.drpMTState);
Funs.FineUIPleaseSelect(this.drpPTState);
Funs.FineUIPleaseSelect(this.drpPAUTState);
//显示列
Model.Sys_UserShowColumns c = BLL.Sys_UserShowColumnsService.GetColumnsByUserId(this.CurrUser.UserId, "2");
if (c != null)
{
this.GetShowColumn(c.Columns);
}
}
}
///
/// 显示的列
///
///
private void GetShowColumn(string column)
{
if (!string.IsNullOrEmpty(column))
{
this.Grid1.Columns[1].Hidden = true;
this.Grid1.Columns[2].Hidden = true;
this.Grid1.Columns[3].Hidden = true;
this.Grid1.Columns[4].Hidden = true;
this.Grid1.Columns[5].Hidden = true;
this.Grid1.Columns[6].Hidden = true;
this.Grid1.Columns[7].Hidden = true;
this.Grid1.Columns[8].Hidden = true;
this.Grid1.Columns[9].Hidden = true;
this.Grid1.Columns[10].Hidden = true;
this.Grid1.Columns[11].Hidden = true;
this.Grid1.Columns[12].Hidden = true;
this.Grid1.Columns[13].Hidden = true;
this.Grid1.Columns[14].Hidden = true;
this.Grid1.Columns[15].Hidden = true;
this.Grid1.Columns[16].Hidden = true;
this.Grid1.Columns[17].Hidden = true;
this.Grid1.Columns[18].Hidden = true;
this.Grid1.Columns[19].Hidden = true;
this.Grid1.Columns[20].Hidden = true;
this.Grid1.Columns[21].Hidden = true;
this.Grid1.Columns[22].Hidden = true;
this.Grid1.Columns[23].Hidden = true;
this.Grid1.Columns[24].Hidden = true;
this.Grid1.Columns[25].Hidden = true;
this.Grid1.Columns[26].Hidden = true;
this.Grid1.Columns[27].Hidden = true;
this.Grid1.Columns[28].Hidden = true;
this.Grid1.Columns[29].Hidden = true;
this.Grid1.Columns[30].Hidden = true;
this.Grid1.Columns[31].Hidden = true;
this.Grid1.Columns[32].Hidden = true;
this.Grid1.Columns[33].Hidden = true;
this.Grid1.Columns[34].Hidden = true;
this.Grid1.Columns[35].Hidden = true;
this.Grid1.Columns[36].Hidden = true;
List columns = column.Split(',').ToList();
foreach (var item in columns)
{
this.Grid1.Columns[Convert.ToInt32(item)].Hidden = false;
}
}
}
#endregion
#region 加载管线信息
///
/// 加载树
///
private void InitTreeMenu()
{
this.tvControlItem.Nodes.Clear();
TreeNode rootNode = new TreeNode();
rootNode.Text = "管线列表";
rootNode.NodeID = "0";
rootNode.Expanded = true;
this.tvControlItem.Nodes.Add(rootNode);
// var joints = from x in Funs.DB.HJGL_PW_JointInfo where x.ProjectId == this.CurrUser.LoginProjectId select x;
var iso = from x in Funs.DB.HJGL_PW_IsoInfo where x.ProjectId == this.CurrUser.LoginProjectId select x;
if (!string.IsNullOrEmpty(this.txtIsono.Text))
{
iso = iso.Where(e => e.ISO_IsoNo.Contains(this.txtIsono.Text.Trim()));
}
iso = iso.OrderBy(x => x.ISO_IsoNo);
if (iso.Count() > 0)
{
foreach (var q in iso)
{
int jotCount = (from x in Funs.DB.HJGL_PW_JointInfo where x.ISO_ID == q.ISO_ID select x).Count();
TreeNode newNode = new TreeNode();
newNode.NodeID = q.ISO_ID;
newNode.Text = q.ISO_IsoNo;
newNode.Text += "【" + jotCount.ToString() + "焊口】";
newNode.EnableClickEvent = true;
rootNode.Nodes.Add(newNode);
}
}
}
#endregion
#region 点击TreeView
///
/// 点击TreeView
///
///
///
protected void tvControlItem_NodeCommand(object sender, TreeCommandEventArgs e)
{
if (!string.IsNullOrEmpty(this.tvControlItem.SelectedNodeID))
{
this.lbTotalDine.Text = string.Empty;
this.lbDoneDine.Text = string.Empty;
this.lbHotNum.Text = string.Empty;
this.lbHotOKNum.Text = string.Empty;
var iso = BLL.HJGL_PW_IsoInfoService.GetIsoInfoByIsoInfoId(tvControlItem.SelectedNodeID);
{
if (iso != null)
{
lbDesignPress.Text = iso.ISO_DesignPress.HasValue ? iso.ISO_DesignPress.Value.ToString("F2").Trim() : "";
lbDesignTemperature.Text = iso.ISO_DesignTemperature.HasValue ? iso.ISO_DesignTemperature.Value.ToString("F2").Trim() : "";
var ste = BLL.HJGL_MaterialService.GetSteelBySteID(iso.STE_ID);
if (ste != null)
{
lbMat.Text = ste.STE_Code.Trim();
}
var ser = BLL.HJGL_MediumService.GetServiceBySERID(iso.SER_ID);
if (ser != null)
{
lbSer.Text = ser.SER_Code.Trim();
}
Model.SGGLDB db = Funs.DB;
var list = from x in db.HJGL_PW_JointInfo where x.ISO_ID == tvControlItem.SelectedNodeID select x;
this.lbTotalDine.Text = list.ToList().Sum(x => x.JOT_Size ?? 0).ToString("0.####");
this.lbDoneDine.Text = list.ToList().Sum(x => x.JOT_DoneDin ?? 0).ToString("0.####");
this.lbHotNum.Text = list.Count(x => x.IS_Proess == "1").ToString();
this.lbHotOKNum.Text = (from x in db.HJGL_CH_HotProessResult
join y in db.HJGL_PW_JointInfo on x.JOT_ID equals y.JOT_ID
where y.ISO_ID == tvControlItem.SelectedNodeID
select x.JOT_ID).Distinct().ToList().Count.ToString();
}
}
}
this.BindGrid();
}
#endregion
#region 数据绑定
///
/// 数据绑定
///
private void BindGrid()
{
string strSql = @"SELECT JOT_ID,ProjectId,JOT_JointNo,Sort1,Sort2,Sort3,Sort4,Sort5,JOTY_Group
,JOT_DailyReportNo,JOT_WeldDate,ISO_ID,ISO_IsoNo,STE_Name1,STE_Name2,WED_Code1,WED_Name1,WED_Code2
,(CASE WHEN STE_Name1 IS NOT NULL AND STE_Name2 IS NOT NULL and STE_Name1!=STE_Name2 THEN STE_Name1 + '/' + STE_Name2
WHEN STE_Name1 IS NOT NULL THEN STE_Name1 ELSE ISNULL(STE_Name2,'') END) AS STE_Name --材质
,WED_Name2,WLO_Code,(CASE WHEN WLO_Code='F' THEN '安装' WHEN WLO_Code='S' THEN '预制' ELSE '' END) AS WLO_Name
,JOT_DoneDin,IS_Compute,Component1,Component2,WeldMat,JointStatus
,(CASE WHEN JointStatus='1' THEN '点口' WHEN JointStatus='2' THEN '扩透' WHEN JointStatus='3' THEN '已切除' ELSE '' END) AS JointStatusName
,JOT_Dia,JOT_Size,JOT_Sch,JOT_FactSch,JOT_JointDesc,WeldSilk,JOTY_Name,WME_Name
,JST_Name,(CASE WHEN IS_Proess= '1' THEN '是' ELSE '否' END) AS IS_Proess
,JOT_PrepareTemp,JOT_CellTemp,JOT_LastTemp,JOT_JointAttribute,BatchCode,PointDate
,ProessTypes,JOT_Remark,NDTR_Name,Is_hj,If_dk,RT_States,UT_States,MT_States,PT_States,PAUT_States,HotProessResult
,(CASE WHEN IsSpecial=1 THEN '是' ELSE '否' END) AS IsSpecialName
FROM HJGL_View_JointInfo WHERE ProjectId= @ProjectId";
List listStr = new List();
listStr.Add(new SqlParameter("@ProjectId", this.CurrUser.LoginProjectId));
if (rbIsHj.SelectedValue == "0")
{
strSql += " AND ISO_ID =@ISO_ID";
listStr.Add(new SqlParameter("@ISO_ID", this.tvControlItem.SelectedNodeID));
}
if (rbIsHj.SelectedValue == "1")
{
strSql += " AND ISO_ID =@ISO_ID AND Is_hj=1";
listStr.Add(new SqlParameter("@ISO_ID", this.tvControlItem.SelectedNodeID));
}
if (rbIsHj.SelectedValue == "2")
{
strSql += " AND ISO_ID =@ISO_ID AND Is_hj=0";
listStr.Add(new SqlParameter("@ISO_ID", this.tvControlItem.SelectedNodeID));
}
if (!string.IsNullOrEmpty(this.txtJOT_JointNo.Text.Trim()))
{
strSql += " AND JOT_JointNo LIKE @JOT_JointNo";
listStr.Add(new SqlParameter("@JOT_JointNo", "%" + this.txtJOT_JointNo.Text.Trim() + "%"));
}
if (rbHotProessResult.SelectedValue == "1")
{
strSql += " AND HotProessResult = '合格'";
}
if (this.drpRTState.SelectedValue != BLL.Const._Null)
{
strSql += " AND RT_States = @RT_States";
listStr.Add(new SqlParameter("@RT_States", this.drpRTState.SelectedValue));
}
if (this.drpUTState.SelectedValue != BLL.Const._Null)
{
strSql += " AND UT_States = @UT_States";
listStr.Add(new SqlParameter("@UT_States", this.drpUTState.SelectedValue));
}
if (this.drpMTState.SelectedValue != BLL.Const._Null)
{
strSql += " AND MT_States = @MT_States";
listStr.Add(new SqlParameter("@MT_States", this.drpMTState.SelectedValue));
}
if (this.drpPTState.SelectedValue != BLL.Const._Null)
{
strSql += " AND PT_States = @PT_States";
listStr.Add(new SqlParameter("@PT_States", this.drpPTState.SelectedValue));
}
if (this.drpPAUTState.SelectedValue != BLL.Const._Null)
{
strSql += " AND PAUT_States = @PAUT_States";
listStr.Add(new SqlParameter("@PAUT_States", this.drpPAUTState.SelectedValue));
}
SqlParameter[] parameter = listStr.ToArray();
DataTable tb = SQLHelper.GetDataTableRunText(strSql, parameter);
// 2.获取当前分页数据
//var table = this.GetPagedDataTable(Grid1, tb1);
Grid1.RecordCount = tb.Rows.Count;
//this.Grid1.PageIndex = 0;
tb = GetFilteredTable(Grid1.FilteredData, tb);
var table = this.GetPagedDataTable(Grid1, tb);
Grid1.DataSource = table;
Grid1.DataBind();
if (!string.IsNullOrEmpty(this.hdPageMax.Text))
{
int newPageIndex = 0;
decimal c = Convert.ToDecimal(Math.Round(Convert.ToDecimal(Grid1.RecordCount) / Convert.ToDecimal(this.Grid1.PageSize), 2));
if (c.ToString().IndexOf(".") > 0 && c.ToString().Substring(c.ToString().IndexOf("."), c.ToString().Length - c.ToString().IndexOf(".")) != ".00")
{
string c1 = c.ToString().Substring(0, c.ToString().IndexOf("."));
newPageIndex = Convert.ToInt32(c1);
}
else
{
newPageIndex = Convert.ToInt32(c) - 1;
}
this.Grid1.PageIndex = newPageIndex;
var table2 = this.GetPagedDataTable(Grid1, tb);
Grid1.DataSource = table2;
Grid1.DataBind();
}
}
#endregion
#region 分页排序
#region 页索引改变事件
///
/// 页索引改变事件
///
///
///
protected void Grid1_PageIndexChange(object sender, GridPageEventArgs e)
{
BindGrid();
}
#endregion
#region 排序
///
/// 排序
///
///
///
protected void Grid1_Sort(object sender, GridSortEventArgs e)
{
BindGrid();
}
#endregion
#region 分页选择下拉改变事件
///
/// 分页选择下拉改变事件
///
///
///
protected void ddlPageSize_SelectedIndexChanged(object sender, EventArgs e)
{
Grid1.PageSize = Convert.ToInt32(ddlPageSize.SelectedValue);
BindGrid();
}
#endregion
protected void Grid1_RowDataBound(object sender, GridRowEventArgs e)
{
// DataRowView row = e.DataItem as DataRowView;
string jotid = Grid1.DataKeys[e.RowIndex][0].ToString();
var batchDetail = BLL.HJGL_BO_BatchDetailService.GetBatchDetailByJotId(jotid);
var hot = Funs.DB.HJGL_CH_HotProessTrustItem.FirstOrDefault(x => x.JOT_ID == jotid);
if (batchDetail != null)
{
var batch = BLL.HJGL_BO_BatchService.GetBatchById(batchDetail.BatchId);
WindowField joint = Grid1.FindColumn("JOT_JointNo") as WindowField;
if (batch.BatchIsClosed == true || hot != null)
{
e.CellCssClasses[joint.ColumnIndex] = "color";
}
}
}
#endregion
#region 焊口信息 维护事件
///
/// Grid双击事件
///
///
///
protected void Grid1_RowDoubleClick(object sender, GridRowClickEventArgs e)
{
if (BLL.CommonService.GetAllButtonPowerList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, BLL.Const.HJGL_JointInfoMenuId, BLL.Const.BtnModify))
{
PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("JointInfoEdit.aspx?JOT_ID={0}", Grid1.SelectedRowID, "编辑 - ")));
}
else
{
ShowNotify("您没有这个权限,请与管理员联系!", MessageBoxIcon.Warning);
}
}
///
/// 增加焊口信息
///
///
///
protected void btnNew_Click(object sender, EventArgs e)
{
if (CommonService.GetAllButtonPowerList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, Const.HJGL_JointInfoMenuId, Const.BtnAdd))
{
var isoInfo = BLL.HJGL_PW_IsoInfoService.GetIsoInfoByIsoInfoId(tvControlItem.SelectedNodeID);
if (isoInfo != null)
{
PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("JointInfoEdit.aspx?ISO_ID={0}", this.tvControlItem.SelectedNodeID, "新增 - ")));
}
else
{
ShowNotify("请先选择管线!", MessageBoxIcon.Warning);
}
}
else
{
ShowNotify("您没有这个权限,请与管理员联系!", MessageBoxIcon.Warning);
}
}
///
/// 批量增加焊口信息
///
///
///
protected void btnBatchAdd_Click(object sender, EventArgs e)
{
if (CommonService.GetAllButtonPowerList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, Const.HJGL_JointInfoMenuId, Const.BtnAdd))
{
var isoInfo = BLL.HJGL_PW_IsoInfoService.GetIsoInfoByIsoInfoId(tvControlItem.SelectedNodeID);
if (isoInfo != null)
{
this.hdPageMax.Text = "1";
PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("JointInfoBatchEdit.aspx?ISO_ID={0}", this.tvControlItem.SelectedNodeID, "新增 - ")));
}
else
{
ShowNotify("请先选择管线!", MessageBoxIcon.Warning);
}
}
else
{
ShowNotify("您没有这个权限,请与管理员联系!", MessageBoxIcon.Warning);
}
}
///
/// 焊口信息编辑
///
///
///
protected void btnMenuEdit_Click(object sender, EventArgs e)
{
if (BLL.CommonService.GetAllButtonPowerList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, BLL.Const.HJGL_JointInfoMenuId, BLL.Const.BtnModify))
{
if (Grid1.SelectedRowIndexArray.Length == 0)
{
Alert.ShowInTop("请选择一条记录!", MessageBoxIcon.Warning);
return;
}
PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("JointInfoEdit.aspx?JOT_ID={0}", Grid1.SelectedRowID, "维护 - ")));
}
else
{
ShowNotify("您没有这个权限,请与管理员联系!", MessageBoxIcon.Warning);
}
}
protected void btnMenuUpdate_Click(object sender, EventArgs e)
{
if (BLL.CommonService.GetAllButtonPowerList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, BLL.Const.HJGL_JointInfoMenuId, BLL.Const.BtnModify))
{
if (Grid1.SelectedRowIndexArray.Length == 0)
{
Alert.ShowInTop("请选择一条记录!", MessageBoxIcon.Warning);
return;
}
var jot = BLL.HJGL_PW_JointInfoService.GetJointInfoByJotID(Grid1.SelectedRowID);
if (!string.IsNullOrEmpty(jot.DReportID))
{
var batchDetail = BLL.HJGL_BO_BatchDetailService.GetBatchDetailByJotId(Grid1.SelectedRowID);
var hot = Funs.DB.HJGL_CH_HotProessTrustItem.FirstOrDefault(x => x.JOT_ID == Grid1.SelectedRowID);
if (batchDetail != null)
{
var batch = BLL.HJGL_BO_BatchService.GetBatchById(batchDetail.BatchId);
if (batch.BatchIsClosed == true || hot != null)
{
if (this.CurrUser.Account == Const.Gly)
{
PageContext.RegisterStartupScript(Window8.GetShowReference(String.Format("JointReportUpdate.aspx?JOT_ID={0}", Grid1.SelectedRowID, "维护 - ")));
}
else
{
ShowNotify("只有管理员才有更改的权限!", MessageBoxIcon.Warning);
}
}
else
{
PageContext.RegisterStartupScript(Window8.GetShowReference(String.Format("JointReportUpdate.aspx?JOT_ID={0}", Grid1.SelectedRowID, "维护 - ")));
}
}
}
else
{
ShowNotify("该焊口还未焊接!", MessageBoxIcon.Warning);
}
}
else
{
ShowNotify("您没有这个权限,请与管理员联系!", MessageBoxIcon.Warning);
}
}
///
/// 删除按钮
///
///
///
protected void btnMenuDelete_Click(object sender, EventArgs e)
{
if (CommonService.GetAllButtonPowerList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, Const.HJGL_JointInfoMenuId, Const.BtnDelete))
{
if (Grid1.SelectedRowIndexArray.Length == 0)
{
Alert.ShowInTop("请选择一条记录!", MessageBoxIcon.Warning);
return;
}
bool isShow = true;
if (Grid1.SelectedRowIndexArray.Length > 1)
{
isShow = false;
}
string err = string.Empty;
foreach (int rowIndex in Grid1.SelectedRowIndexArray)
{
string rowID = Grid1.DataKeys[rowIndex][0].ToString();
string content = judgementDelete(rowID, isShow);
if (string.IsNullOrEmpty(content))
{
Model.SGGLDB db = Funs.DB;
var hotProessTrustItem = db.HJGL_CH_HotProessTrustItem.FirstOrDefault(x => x.JOT_ID == rowID);
if (hotProessTrustItem != null)
{
db.HJGL_CH_HotProessTrustItem.DeleteOnSubmit(hotProessTrustItem);
}
var hotProessItem = db.HJGL_HotProessItem.FirstOrDefault(x => x.JOT_ID == rowID);
if (hotProessItem != null)
{
db.HJGL_HotProessItem.DeleteOnSubmit(hotProessItem);
}
var hotProessResult = db.HJGL_CH_HotProessResult.FirstOrDefault(x => x.JOT_ID == rowID);
if (hotProessResult != null)
{
db.HJGL_CH_HotProessResult.DeleteOnSubmit(hotProessResult);
}
db.SubmitChanges();
BLL.HJGL_BO_BatchDetailService.DeleteBatchDetail(rowID); //删除批明细
BLL.HJGL_PW_JointInfoService.DeleteJointInfo(rowID);
BLL.Sys_LogService.AddLog(BLL.Const.System_3, this.CurrUser.LoginProjectId, this.CurrUser.UserId, "删除焊口信息");
}
else
{
err += content;
}
}
if (string.IsNullOrEmpty(err))
{
Alert.ShowInTop("删除成功!", MessageBoxIcon.Success);
}
else
{
Alert.ShowInTop(err, MessageBoxIcon.Warning);
}
this.BindGrid();
}
else
{
ShowNotify("您没有这个权限,请与管理员联系!", MessageBoxIcon.Warning);
}
}
#endregion
#region 报表打印
///
/// 报表打印
///
///
///
protected void btnPrint_Click(object sender, EventArgs e)
{
#region 注释
//string isoId = this.tvControlItem.SelectedNodeID;
//var q = BLL.HJGL_PW_IsoInfoService.GetIsoInfoByIsoInfoId(isoId);
//if (q != null)
//{
// string varValue = string.Empty;
// var project = BLL.Base_ProjectService.GetProjectByProjectId(this.CurrUser.LoginProjectId);
// if (project != null)
// {
// varValue = project.ProjectName + "|管道";
// }
// if (!string.IsNullOrEmpty(varValue))
// {
// //varValue = Microsoft.JScript.GlobalObject.escape(varValue.Replace("/", ","));
// varValue = HttpUtility.UrlEncodeUnicode(varValue);
// }
// PageContext.RegisterStartupScript(Window2.GetShowReference(String.Format("../../Common/ReportPrint/ExReportPrint.aspx?ispop=1&reportId={0}&replaceParameter={1}&varValue={2}&projectId=0", BLL.Const.HJGL_JointInfoReportId, isoId, varValue)));
//}
//else
//{
// ShowNotify("请选择管线!", MessageBoxIcon.Warning);
// return;
//}
#endregion
string rootPath = Server.MapPath("~/") + Const.ExcelUrl;
//导出文件
string filePath = rootPath + DateTime.Now.ToString("yyyyMMddhhmmss") + "\\";
if (!Directory.Exists(filePath))
{
Directory.CreateDirectory(filePath);
}
string ReportFileName = filePath + "out.xlsx";
var project = Base_ProjectService.GetProjectByProjectId(this.CurrUser.LoginProjectId);
var isoList = from x in Funs.DB.HJGL_PW_IsoInfo where x.ProjectId == this.CurrUser.LoginProjectId select x;
if (isoList != null && isoList.Count() > 0)
{
int rowIndex = 0;
XSSFWorkbook hssfworkbook = new XSSFWorkbook();
XSSFSheet ws = (XSSFSheet)hssfworkbook.CreateSheet("焊接工作记录");
foreach (var item in isoList)
{
var listStr = new List();
listStr.Add(new SqlParameter("@IsoId", item.ISO_ID));
listStr.Add(new SqlParameter("@Flag", "0"));
SqlParameter[] parameter = listStr.ToArray();
var tb = SQLHelper.GetDataTableRunProc("HJGL_spJointWorkRecordNew", parameter);
if (tb.Rows.Count > 0)
{
var workIndex = Math.Ceiling((float)tb.Rows.Count / 11);
for (int i = 1; i <= workIndex; i++)
{
var pageTb = GetPageToDataTable(tb, i, 11);
ICellStyle style = hssfworkbook.CreateCellStyle();
style.BorderBottom = BorderStyle.Thin;
style.BorderLeft = BorderStyle.Thin;
style.BorderRight = BorderStyle.Thin;
style.BorderTop = BorderStyle.Thin;
style.VerticalAlignment = VerticalAlignment.Center;
style.Alignment = HorizontalAlignment.Center;
IFont font = hssfworkbook.CreateFont();
font.FontHeightInPoints = 7;
style.SetFont(font);
style.WrapText = true;
ws = ExcelCreateRow(ws, hssfworkbook, rowIndex, rowIndex + 18, style, 0, 12);
#region 头部
CellRangeAddress region = new CellRangeAddress(rowIndex, rowIndex + 1, 0, 2);
ws.AddMergedRegion(region);
ws.GetRow(rowIndex).GetCell(0).SetCellValue("SH/T 3503-J415-1");
region = new CellRangeAddress(rowIndex, rowIndex + 1, 3, 8);
ws.AddMergedRegion(region);
ws.GetRow(rowIndex).GetCell(3).SetCellValue("管道焊接工作记录" + (i > 1 ? "续" : "") + "");
region = new CellRangeAddress(rowIndex, rowIndex, 9, 10);
ws.AddMergedRegion(region);
ws.GetRow(rowIndex).GetCell(9).SetCellValue("工程名称:");
region = new CellRangeAddress(rowIndex, rowIndex, 11, 12);
ws.AddMergedRegion(region);
ws.GetRow(rowIndex).GetCell(11).SetCellValue(project.ProjectName);
region = new CellRangeAddress(rowIndex + 1, rowIndex + 1, 9, 10);
ws.AddMergedRegion(region);
ws.GetRow(rowIndex + 1).GetCell(9).SetCellValue("单位工程名称:");
region = new CellRangeAddress(rowIndex + 1, rowIndex + 1, 11, 12);
ws.AddMergedRegion(region);
ws.GetRow(rowIndex + 1).GetCell(11).SetCellValue("管道");
#endregion
#region 表格
var dataTit = rowIndex + 2;
//合并单元格
for (int hb = dataTit; hb <= dataTit + 11; hb++)
{
region = new CellRangeAddress(hb, hb, 0, 1);
ws.AddMergedRegion(region);
region = new CellRangeAddress(hb, hb, 8, 9);
ws.AddMergedRegion(region);
region = new CellRangeAddress(hb, hb, 10, 11);
ws.AddMergedRegion(region);
}
//列头
ws.GetRow(dataTit).GetCell(0).SetCellValue("管道编号/单线号");
ws.GetRow(dataTit).GetCell(2).SetCellValue("焊口\n编号");
ws.GetRow(dataTit).GetCell(3).SetCellValue("焊工\n代号");
ws.GetRow(dataTit).GetCell(4).SetCellValue("规格\nmm");
ws.GetRow(dataTit).GetCell(5).SetCellValue("材质");
ws.GetRow(dataTit).GetCell(6).SetCellValue("焊接位置");
ws.GetRow(dataTit).GetCell(7).SetCellValue("焊接方法");
ws.GetRow(dataTit).GetCell(8).SetCellValue("焊材牌号");
ws.GetRow(dataTit).GetCell(10).SetCellValue("实际预热\n温度℃");
ws.GetRow(dataTit).GetCell(12).SetCellValue("焊接日期");
//数据
for (int j = 0; j < pageTb.Rows.Count; j++)
{
int dataIndex = rowIndex + j + 3;
ws.GetRow(dataIndex).GetCell(0).SetCellValue(pageTb.Rows[j]["ISO_IsoNo"].ToString());
ws.GetRow(dataIndex).GetCell(2).SetCellValue(pageTb.Rows[j]["JOT_JointNo"].ToString());
ws.GetRow(dataIndex).GetCell(3).SetCellValue(pageTb.Rows[j]["WED_Code"].ToString());
ws.GetRow(dataIndex).GetCell(4).SetCellValue(pageTb.Rows[j]["JOT_JointDesc"].ToString());
ws.GetRow(dataIndex).GetCell(5).SetCellValue(pageTb.Rows[j]["STE_Code"].ToString());
ws.GetRow(dataIndex).GetCell(6).SetCellValue(pageTb.Rows[j]["weldLocal"].ToString());
ws.GetRow(dataIndex).GetCell(7).SetCellValue(pageTb.Rows[j]["WME_Name"].ToString());
ws.GetRow(dataIndex).GetCell(8).SetCellValue(pageTb.Rows[j]["WMT_MatName"].ToString());
ws.GetRow(dataIndex).GetCell(10).SetCellValue(pageTb.Rows[j]["JOT_PrepareTemp"].ToString());
ws.GetRow(dataIndex).GetCell(12).SetCellValue(pageTb.Rows[j]["WeldDate"].ToString());
}
#endregion
#region 尾部
if (i == 1)
{
var tailIndex = rowIndex + 14;
region = new CellRangeAddress(tailIndex, tailIndex, 0, 3);
ws.AddMergedRegion(region);
ws.GetRow(tailIndex).GetCell(0).CellStyle = style;
ws.GetRow(tailIndex).GetCell(1).CellStyle = style;
ws.GetRow(tailIndex).GetCell(2).CellStyle = style;
ws.GetRow(tailIndex).GetCell(3).CellStyle = style;
ws.GetRow(tailIndex).GetCell(0).SetCellValue("建设/监理单位");
ws.GetRow(tailIndex + 1).GetCell(0).SetCellValue("专业工程师:");
region = new CellRangeAddress(tailIndex + 4, tailIndex + 4, 1, 3);
ws.AddMergedRegion(region);
ws.GetRow(tailIndex + 4).GetCell(0).SetCellValue("日期:");
region = new CellRangeAddress(tailIndex, tailIndex, 4, 7);
ws.AddMergedRegion(region);
ws.GetRow(tailIndex).GetCell(4).CellStyle = style;
ws.GetRow(tailIndex).GetCell(5).CellStyle = style;
ws.GetRow(tailIndex).GetCell(6).CellStyle = style;
ws.GetRow(tailIndex).GetCell(7).CellStyle = style;
ws.GetRow(tailIndex).GetCell(4).SetCellValue("总承包单位");
ws.GetRow(tailIndex + 1).GetCell(4).SetCellValue("专业工程师:");
region = new CellRangeAddress(tailIndex + 4, tailIndex + 4, 5, 7);
ws.AddMergedRegion(region);
ws.GetRow(tailIndex + 4).GetCell(4).SetCellValue("日期:");
region = new CellRangeAddress(tailIndex, tailIndex, 8, 12);
ws.AddMergedRegion(region);
ws.GetRow(tailIndex).GetCell(8).CellStyle = style;
ws.GetRow(tailIndex).GetCell(9).CellStyle = style;
ws.GetRow(tailIndex).GetCell(10).CellStyle = style;
ws.GetRow(tailIndex).GetCell(11).CellStyle = style;
ws.GetRow(tailIndex).GetCell(12).CellStyle = style;
ws.GetRow(tailIndex).GetCell(8).SetCellValue("施工单位");
region = new CellRangeAddress(tailIndex + 1, tailIndex + 1, 8, 9);
ws.AddMergedRegion(region);
ws.GetRow(tailIndex + 1).GetCell(8).SetCellValue("记录人:");
region = new CellRangeAddress(tailIndex + 2, tailIndex + 2, 8, 9);
ws.AddMergedRegion(region);
ws.GetRow(tailIndex + 2).GetCell(8).SetCellValue("质量检查员:");
region = new CellRangeAddress(tailIndex + 3, tailIndex + 3, 8, 9);
ws.AddMergedRegion(region);
ws.GetRow(tailIndex + 3).GetCell(8).SetCellValue("焊接责任工程师:");
region = new CellRangeAddress(tailIndex + 4, tailIndex + 4, 8, 9);
ws.AddMergedRegion(region);
region = new CellRangeAddress(tailIndex + 4, tailIndex + 4, 10, 12);
ws.AddMergedRegion(region);
ws.GetRow(tailIndex + 4).GetCell(8).SetCellValue("日期:");
#region 底部边框线
ICellStyle bottomStyle = hssfworkbook.CreateCellStyle();
bottomStyle.BorderBottom = BorderStyle.Thin;
bottomStyle.BorderLeft = BorderStyle.None;
bottomStyle.BorderRight = BorderStyle.None;
bottomStyle.BorderTop = BorderStyle.None;
bottomStyle.VerticalAlignment = VerticalAlignment.Center;
bottomStyle.Alignment = HorizontalAlignment.Left;
bottomStyle.SetFont(font);
bottomStyle.WrapText = true;
ws.GetRow(tailIndex + 4).GetCell(0).CellStyle =
ws.GetRow(tailIndex + 4).GetCell(1).CellStyle =
ws.GetRow(tailIndex + 4).GetCell(2).CellStyle =
ws.GetRow(tailIndex + 4).GetCell(4).CellStyle =
ws.GetRow(tailIndex + 4).GetCell(5).CellStyle =
ws.GetRow(tailIndex + 4).GetCell(6).CellStyle =
ws.GetRow(tailIndex + 4).GetCell(8).CellStyle =
ws.GetRow(tailIndex + 4).GetCell(9).CellStyle =
ws.GetRow(tailIndex + 4).GetCell(10).CellStyle =
ws.GetRow(tailIndex + 4).GetCell(11).CellStyle = bottomStyle;
#endregion
#region 右侧边框线
ICellStyle rightStyle = hssfworkbook.CreateCellStyle();
rightStyle.BorderBottom = BorderStyle.None;
rightStyle.BorderLeft = BorderStyle.None;
rightStyle.BorderRight = BorderStyle.Thin;
rightStyle.BorderTop = BorderStyle.None;
rightStyle.VerticalAlignment = VerticalAlignment.Center;
rightStyle.Alignment = HorizontalAlignment.Left;
rightStyle.SetFont(font);
rightStyle.WrapText = true;
ws.GetRow(tailIndex + 1).GetCell(3).CellStyle =
ws.GetRow(tailIndex + 2).GetCell(3).CellStyle =
ws.GetRow(tailIndex + 3).GetCell(3).CellStyle =
ws.GetRow(tailIndex + 1).GetCell(7).CellStyle =
ws.GetRow(tailIndex + 2).GetCell(7).CellStyle =
ws.GetRow(tailIndex + 3).GetCell(7).CellStyle =
ws.GetRow(tailIndex + 1).GetCell(12).CellStyle =
ws.GetRow(tailIndex + 2).GetCell(12).CellStyle =
ws.GetRow(tailIndex + 3).GetCell(12).CellStyle = rightStyle;
#endregion
#region 底右边框线
ICellStyle botrigStyle = hssfworkbook.CreateCellStyle();
botrigStyle.BorderBottom = BorderStyle.Thin;
botrigStyle.BorderLeft = BorderStyle.None;
botrigStyle.BorderRight = BorderStyle.Thin;
botrigStyle.BorderTop = BorderStyle.None;
botrigStyle.VerticalAlignment = VerticalAlignment.Center;
botrigStyle.Alignment = HorizontalAlignment.Left;
botrigStyle.SetFont(font);
botrigStyle.WrapText = true;
ws.GetRow(tailIndex + 4).GetCell(3).CellStyle =
ws.GetRow(tailIndex + 4).GetCell(7).CellStyle =
ws.GetRow(tailIndex + 4).GetCell(12).CellStyle = botrigStyle;
#endregion
#region 左侧边框线
ICellStyle leftStyle = hssfworkbook.CreateCellStyle();
leftStyle.BorderBottom = BorderStyle.None;
leftStyle.BorderLeft = BorderStyle.Thin;
leftStyle.BorderRight = BorderStyle.None;
leftStyle.BorderTop = BorderStyle.None;
leftStyle.VerticalAlignment = VerticalAlignment.Center;
leftStyle.Alignment = HorizontalAlignment.Left;
leftStyle.SetFont(font);
leftStyle.WrapText = true;
ws.GetRow(tailIndex + 1).GetCell(0).CellStyle =
ws.GetRow(tailIndex + 2).GetCell(0).CellStyle =
ws.GetRow(tailIndex + 3).GetCell(0).CellStyle = leftStyle;
#endregion
#region 左下边框线
ICellStyle botleftStyle = hssfworkbook.CreateCellStyle();
botleftStyle.BorderBottom = BorderStyle.Thin;
botleftStyle.BorderLeft = BorderStyle.Thin;
botleftStyle.BorderRight = BorderStyle.None;
botleftStyle.BorderTop = BorderStyle.None;
botleftStyle.VerticalAlignment = VerticalAlignment.Center;
botleftStyle.Alignment = HorizontalAlignment.Left;
botleftStyle.SetFont(font);
botleftStyle.WrapText = true;
ws.GetRow(tailIndex + 4).GetCell(0).CellStyle = botleftStyle;
#endregion
}
#endregion
rowIndex += 27;
}
}
}
ws.ForceFormulaRecalculation = true;
using (FileStream filess = File.OpenWrite(ReportFileName))
{
hssfworkbook.Write(filess);
}
FileInfo filet = new FileInfo(ReportFileName);
Response.Clear();
Response.Charset = "GB2312";
Response.ContentEncoding = System.Text.Encoding.UTF8;
// 添加头信息,为"文件下载/另存为"对话框指定默认文件名
Response.AddHeader("Content-Disposition", "attachment; filename=" + Server.UrlEncode("管道焊接记录.xlsx"));
// 添加头信息,指定文件大小,让浏览器能够显示下载进度
Response.AddHeader("Content-Length", filet.Length.ToString());
// 指定返回的是一个不能被客户端读取的流,必须被下载
Response.ContentType = "application/ms-excel";
// 把文件流发送到客户端
Response.WriteFile(filet.FullName);
// 停止页面的执行
Response.End();
}
}
///
/// 打印焊接记录(新)
///
///
///
protected void btnPrintNew_Click(object sender, EventArgs e)
{
string initTemplatePath = "";
string rootPath = Server.MapPath("~/");
BLL.Common.FastReportService.ResetData();
string isoId = this.tvControlItem.SelectedNodeID;
var q = BLL.HJGL_PW_IsoInfoService.GetIsoInfoByIsoInfoId(isoId);
if (q != null)
{
string projectName = string.Empty;
var project = BLL.Base_ProjectService.GetProjectByProjectId(this.CurrUser.LoginProjectId);
if (project != null)
{
projectName = project.ProjectName;
}
List listStr = new List();
listStr.Add(new SqlParameter("@IsoId", isoId));
listStr.Add(new SqlParameter("@Flag", "0"));
SqlParameter[] parameter = listStr.ToArray();
DataTable tb = BLL.SQLHelper.GetDataTableRunProc("HJGL_spJointWorkRecordNew", parameter);
//tb.Columns.Add("index", typeof(System.Int32));
//foreach (DataRow row in tb.Rows)
//{
// try
// {
// row["index"] = int.Parse(System.Text.RegularExpressions.Regex.Replace(row["JOT_JointNo"].ToString(), @"[^0-9]+", ""));
// }
// catch (Exception ex)
// {
// row["index"] = 0;
// }
//}
//tb.Columns.Add("indexS", typeof(System.String));
//foreach (DataRow row in tb.Rows)
//{
// try
// {
// string jointNo = row["JOT_JointNo"].ToString().Substring(0, 1);
// row["indexS"] = (System.Text.RegularExpressions.Regex.Replace(jointNo, @"[^A-Z]+", "")).ToString();
// }
// catch (Exception ex)
// {
// row["indexS"] = string.Empty;
// }
//}
Dictionary keyValuePairs = new Dictionary();
keyValuePairs.Add("ProjectName", projectName);
BLL.Common.FastReportService.AddFastreportParameter(keyValuePairs);
DataTable dt = new DataTable();
dt.TableName = "Data";
dt.Columns.Add("ISO_IsoNo");
dt.Columns.Add("JOT_JointNo");
dt.Columns.Add("WED_Code");
dt.Columns.Add("JOT_JointDesc");
dt.Columns.Add("STE_Code");
dt.Columns.Add("weldLocal");
dt.Columns.Add("WME_Name");
dt.Columns.Add("WMT_MatName");
dt.Columns.Add("JOT_PrepareTemp");
dt.Columns.Add("WeldDate");
DataView dv = tb.DefaultView;//获取表视图
dv.Sort = "JOTY_Group,Sort1,Sort2,Sort3,Sort4,Sort5 ASC";//按照ID排序
tb = dv.ToTable();//转为表
DataRow[] rows = tb.DefaultView.ToTable().Select();
foreach (var row in rows)
{
var newRow = dt.NewRow();
newRow["ISO_IsoNo"] = row["ISO_IsoNo"].ToString();
newRow["JOT_JointNo"] = row["JOT_JointNo"].ToString();
newRow["WED_Code"] = row["WED_Code"].ToString();
newRow["JOT_JointDesc"] = row["JOT_JointDesc"].ToString();
newRow["STE_Code"] = row["STE_Code"].ToString();
newRow["weldLocal"] = row["weldLocal"].ToString();
newRow["WME_Name"] = row["WME_Name"].ToString();
newRow["WMT_MatName"] = row["WMT_MatName"].ToString();
newRow["JOT_PrepareTemp"] = row["JOT_PrepareTemp"].ToString();
newRow["WeldDate"] = row["WeldDate"].ToString();
dt.Rows.Add(newRow);
}
BLL.Common.FastReportService.AddFastreportTable(dt);
initTemplatePath = "File\\Fastreport\\管道焊接工作记录.frx";
if (File.Exists(rootPath + initTemplatePath))
{
PageContext.RegisterStartupScript(Window2.GetShowReference(String.Format("../../common/ReportPrint/Fastreport.aspx?ReportPath={0}", rootPath + initTemplatePath)));
}
//string page = Funs.GetPagesCountByPageSize(11, 16, tb.Rows.Count).ToString();
//varValue = varValue + "|" + page;
//if (!string.IsNullOrEmpty(varValue))
//{
// varValue = HttpUtility.UrlEncodeUnicode(varValue);
//}
//if (tb.Rows.Count <= 11)
//{
// PageContext.RegisterStartupScript(Window6.GetShowReference(String.Format("../../Common/ReportPrint/ExReportPrint.aspx?ispop=1&reportId={0}&replaceParameter={1}&varValue={2}&projectId=0", BLL.Const.HJGL_JointInfoNewReport1Id, isoId, varValue)));
//}
//else
//{
// PageContext.RegisterStartupScript(Window7.GetShowReference(String.Format("../../Common/ReportPrint/ExReportPrint.aspx?ispop=1&reportId={0}&replaceParameter={1}&varValue={2}&projectId=0", BLL.Const.HJGL_JointInfoNewReport2Id, isoId, varValue)));
// PageContext.RegisterStartupScript(Window6.GetShowReference(String.Format("../../Common/ReportPrint/ExReportPrint.aspx?ispop=1&reportId={0}&replaceParameter={1}&varValue={2}&projectId=0", BLL.Const.HJGL_JointInfoNewReport1Id, isoId, varValue)));
//}
}
else
{
ShowNotify("请选择管线!", MessageBoxIcon.Warning);
return;
}
}
#endregion
#region 文档名
///
/// 文档名
///
///
///
protected void btnFileName_Click(object sender, EventArgs e)
{
string isoId = this.tvControlItem.SelectedNodeID;
var q = BLL.HJGL_PW_IsoInfoService.GetIsoInfoByIsoInfoId(isoId);
if (q != null)
{
if (q != null)
{
string code = string.Empty;
string projectCode = BLL.Base_ProjectService.GetProjectCode(q.ProjectId);
code = projectCode + "-" + q.ISO_IsoNo + "-焊接记录";
PageContext.RegisterStartupScript(Window5.GetShowReference(String.Format("../CheckManage/FileCode.aspx?code={0}", HttpUtility.UrlEncodeUnicode(code), "编辑 - ")));
}
}
else
{
ShowNotify("请选择管线!", MessageBoxIcon.Warning);
return;
}
}
#endregion
#region 关闭弹出窗口及刷新页面
///
/// 关闭弹出窗口
///
///
///
protected void Window1_Close(object sender, WindowCloseEventArgs e)
{
this.InitTreeMenu();//加载树
this.BindGrid();
this.hdPageMax.Text = string.Empty;
}
protected void Window8_Close(object sender, WindowCloseEventArgs e)
{
this.BindGrid();
}
///
/// 关闭弹出窗口4
///
///
///
protected void Window4_Close(object sender, WindowCloseEventArgs e)
{
this.InitTreeMenu();//加载树
this.BindGrid();
//显示列
Model.Sys_UserShowColumns c = BLL.Sys_UserShowColumnsService.GetColumnsByUserId(this.CurrUser.UserId, "2");
if (c != null)
{
this.GetShowColumn(c.Columns);
}
}
///
/// 查询
///
///
///
protected void TextBox_TextChanged(object sender, EventArgs e)
{
this.BindGrid();
}
///
/// 查询
///
///
///
protected void Tree_TextChanged(object sender, EventArgs e)
{
this.InitTreeMenu();
this.BindGrid();
}
#endregion
#region 判断是否可删除
///
/// 判断是否可以删除
///
///
private string judgementDelete(string id, bool isShow)
{
string content = string.Empty;
//if (BLL.Funs.DB.HJGL_CH_HotProessTrustItem.FirstOrDefault(x => x.JOT_ID == id) != null
// || BLL.Funs.DB.HJGL_CH_HotProessResult.FirstOrDefault(x => x.JOT_ID == id) != null)
//{
// content = "该焊口已进行热处理委托,不能删除!";
//}
var joint = BLL.HJGL_PW_JointInfoService.GetJointInfoByJotID(id);
if (!string.IsNullOrEmpty(joint.DReportID))
{
content = "焊口"+joint.JOT_JointNo+"已提交焊接记录,不能删除!";
}
var batchDetail = BLL.HJGL_BO_BatchDetailService.GetBatchDetailByJotId(id);
if (batchDetail != null)
{
var batch = BLL.HJGL_BO_BatchService.GetBatchById(batchDetail.BatchId);
if (batch.BatchIsClosed == true)
{
content = "焊口"+ joint.JOT_JointNo + "所在批已关闭,不能删除!";
}
}
return content;
//if (string.IsNullOrEmpty(content))
//{
// return true;
//}
//else
//{
// if (isShow)
// {
// Alert.ShowInTop(content, MessageBoxIcon.Error);
// }
// return false;
//}
}
#endregion
#region 导出
///
/// 导出焊口信息
///
///
///
protected void btnOut_Click(object sender, EventArgs e)
{
var iso = BLL.HJGL_PW_IsoInfoService.GetIsoInfoByIsoInfoId(this.tvControlItem.SelectedNodeID);
if (iso != null)
{
var set = BLL.Project_SysSetService.GetSysSetBySetId("4", this.CurrUser.LoginProjectId);
if (set != null && set.IsAuto == true) ///是PDMS格式
{
PageContext.RegisterStartupScript(Window3.GetShowReference(String.Format("JointInfoOut2.aspx?ISO_ID={0}", this.tvControlItem.SelectedNodeID, "导出 - ")));
}
else
{
PageContext.RegisterStartupScript(Window3.GetShowReference(String.Format("JointInfoOut.aspx?ISO_ID={0}", this.tvControlItem.SelectedNodeID, "导出 - ")));
}
}
else
{
Alert.ShowInTop("请先选择一条管线!", MessageBoxIcon.Warning);
}
}
#endregion
#region 格式化字符串
///
/// 得到热处理类型
///
///
///
protected string ConvertProessTypes(object ProessTypes)
{
string proessTypes = string.Empty;
if (ProessTypes != null)
{
proessTypes = BLL.HJGL_PW_JointInfoService.ConvertProessTypes(ProessTypes.ToString());
}
return proessTypes;
}
#endregion
#region 选择要显示列
///
/// 选择显示列
///
///
///
protected void btnSelectColumn_Click(object sender, EventArgs e)
{
PageContext.RegisterStartupScript(Window4.GetShowReference(String.Format("JointInfoShowColumn.aspx", "显示列 - ")));
}
#endregion
#region 私有方法
///
/// 行和列
///
///
private XSSFSheet ExcelCreateRow(XSSFSheet ws, XSSFWorkbook hssfworkbook, int sRows, int eRows, ICellStyle style, int cStart, int cEnd)
{
for (int i = sRows; i <= eRows; i++)
{
ws.CreateRow(i);
ws.GetRow(i).HeightInPoints = i == sRows ? 30 : i == (sRows + 1) ? 27 : i == (sRows + 2) ? 28 : 21;
for (int j = cStart; j <= cEnd; j++)
{
ws.GetRow(i).CreateCell(j);
if (i < sRows + 14)
{
ws.GetRow(i).GetCell(j).CellStyle = style;
}
else
{
ICellStyle nstyle = hssfworkbook.CreateCellStyle();
nstyle.BorderBottom = BorderStyle.None;
nstyle.BorderLeft = BorderStyle.None;
nstyle.BorderRight = BorderStyle.None;
nstyle.BorderTop = BorderStyle.None;
nstyle.VerticalAlignment = VerticalAlignment.Center;
nstyle.Alignment = HorizontalAlignment.Left;
IFont font = hssfworkbook.CreateFont();
font.FontHeightInPoints = 7;
nstyle.SetFont(font);
nstyle.WrapText = true;
ws.GetRow(i).GetCell(j).CellStyle = nstyle;
}
}
}
return ws;
}
///
/// 数据分页
///
/// 数据源
/// 第几页
/// 每页多少条
///
private DataTable GetPageToDataTable(DataTable dt, int PageIndex, int PageSize)
{
if (PageIndex == 0)
return dt;//0页代表每页数据,直接返回
if (dt == null)
{
DataTable table = new DataTable();
return table;
}
DataTable newdt = dt.Copy();
newdt.Clear();//copy dt的框架
int rowbegin = (PageIndex - 1) * PageSize;
int rowend = PageIndex * PageSize;//要展示的数据条数
if (rowbegin >= dt.Rows.Count)
return newdt;//源数据记录数小于等于要显示的记录,直接返回dt
if (rowend > dt.Rows.Count)
rowend = dt.Rows.Count;
for (int i = rowbegin; i <= rowend - 1; i++)
{
DataRow newdr = newdt.NewRow();
DataRow dr = dt.Rows[i];
foreach (DataColumn column in dt.Columns)
{
newdr[column.ColumnName] = dr[column.ColumnName];
}
newdt.Rows.Add(newdr);
}
return newdt;
}
#endregion
///
/// 增口按钮
///
///
///
protected void btnMenuCopy_Click(object sender, EventArgs e)
{
this.CopyData();
}
///
/// 复制数据方法
///
private void CopyData()
{
if (BLL.CommonService.GetAllButtonPowerList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, BLL.Const.HJGL_JointInfoMenuId, BLL.Const.BtnModify))
{
if (Grid1.SelectedRowIndexArray.Length == 0)
{
Alert.ShowInTop("请至少选择一条记录!", MessageBoxIcon.Warning);
return;
}
PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("JointInfoCopy.aspx?JOT_ID={0}", Grid1.SelectedRowID, "维护 - ")));
}
else
{
Alert.ShowInTop("您没有这个权限,请与管理员联系!", MessageBoxIcon.Warning);
return;
}
}
#region Grid行点击事件
///
/// Grid1行点击事件
///
///
///
protected void Grid1_RowCommand(object sender, GridCommandEventArgs e)
{
string rowID = Grid1.DataKeys[e.RowIndex][0].ToString();
if (e.CommandName == "IsSelected")
{
CheckBoxField checkField = (CheckBoxField)Grid1.FindColumn("ckbIsSelected");
if (checkField.GetCheckedState(e.RowIndex))
{
if (!list.Contains(rowID))
{
list.Add(rowID);
}
}
else
{
if (list.Contains(rowID))
{
list.Remove(rowID);
}
}
}
}
#endregion
///
/// 批量增加焊口信息
///
///
///
protected void btnBatchDel_Click(object sender, EventArgs e)
{
if (CommonService.GetAllButtonPowerList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, Const.HJGL_JointInfoMenuId, Const.BtnDelete))
{
if (Grid1.SelectedRowIndexArray.Length == 0)
{
Alert.ShowInTop("请选择一条记录!", MessageBoxIcon.Warning);
return;
}
bool isShow = true;
if (Grid1.SelectedRowIndexArray.Length > 1)
{
isShow = false;
}
string err = string.Empty;
foreach (int rowIndex in Grid1.SelectedRowIndexArray)
{
string rowID = Grid1.DataKeys[rowIndex][0].ToString();
string content = judgementDelete(rowID, isShow);
if (string.IsNullOrEmpty(content))
{
Model.SGGLDB db = Funs.DB;
var hotProessTrustItem = db.HJGL_CH_HotProessTrustItem.FirstOrDefault(x => x.JOT_ID == rowID);
if (hotProessTrustItem != null)
{
db.HJGL_CH_HotProessTrustItem.DeleteOnSubmit(hotProessTrustItem);
}
var hotProessItem = db.HJGL_HotProessItem.FirstOrDefault(x => x.JOT_ID == rowID);
if (hotProessItem != null)
{
db.HJGL_HotProessItem.DeleteOnSubmit(hotProessItem);
}
var hotProessResult = db.HJGL_CH_HotProessResult.FirstOrDefault(x => x.JOT_ID == rowID);
if (hotProessResult != null)
{
db.HJGL_CH_HotProessResult.DeleteOnSubmit(hotProessResult);
}
db.SubmitChanges();
BLL.HJGL_BO_BatchDetailService.DeleteBatchDetail(rowID); //删除批明细
BLL.HJGL_PW_JointInfoService.DeleteJointInfo(rowID);
BLL.Sys_LogService.AddLog(BLL.Const.System_3, this.CurrUser.LoginProjectId, this.CurrUser.UserId, "删除焊口信息");
}
else
{
err += content;
}
}
if (string.IsNullOrEmpty(err))
{
Alert.ShowInTop("删除成功!", MessageBoxIcon.Success);
}
else
{
Alert.ShowInTop(err, MessageBoxIcon.Warning);
}
this.BindGrid();
}
else
{
ShowNotify("您没有这个权限,请与管理员联系!", MessageBoxIcon.Warning);
}
}
}
}