ZHJA_HJGL/HJGL_ZH/FineUIPro.Web/HJGL/HotHardManage/HardReportSet.aspx.cs

412 lines
21 KiB
C#

using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using BLL;
using System.Windows.Forms;
using Newtonsoft.Json.Linq;
using AspNet = System.Web.UI.WebControls;
namespace FineUIPro.Web.HJGL.HotHardManage
{
public partial class HardReportSet : PageBase
{
#region
/// <summary>
/// 选择集合
/// </summary>
public List<string> SelectList
{
get
{
return (List<string>)ViewState["SelectList"];
}
set
{
ViewState["SelectList"] = value;
}
}
#endregion
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
SelectList = new List<string>();
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;
//var projects = BLL.Base_ProjectService.GetProjectListByUserIdAndState(this.CurrUser.UserId, this.drpIsProjectClosed.SelectedValue);
//RadioButtonList1.DataTextField = "ProjectCode";
//RadioButtonList1.DataValueField = "ProjectId";
//RadioButtonList1.DataSource = projects;
//RadioButtonList1.DataBind();
this.drpIsoNo.DataTextField = "ISO_IsoNo";
this.drpIsoNo.DataValueField = "ISO_ID";
Funs.FineUIPleaseSelect(this.drpIsoNo);
//this.txtPointDate.Text = string.Format("{0:yyyy-MM}", DateTime.Now);
//CheckBoxField cbVI = Grid1.FindColumn("IsVI") as CheckBoxField;
//cbVI.HeaderText = "<i class=\"ui-icon f-grid-checkbox myheadercheckbox\"></i>&nbsp;外观检验";
this.InitTreeMenu();//加载树
}
}
#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.SelectedValueArray.Length > 1 || (this.drpProjectId.SelectedValueArray.Length == 1 && this.drpProjectId.SelectedValue != "null"))
{
projects = projects.Where(x => this.drpProjectId.SelectedValueArray.Contains(x.ProjectId)).ToList();
}
//var hardTestReportItemSets = from x in Funs.DB.HJGL_View_CH_HardTestReportItemSet where x.HardTestReportId == null select x;
string strR = @"SELECT DISTINCT JointInfo.ProjectId
FROM dbo.HJGL_PW_JointInfo AS JointInfo
LEFT JOIN dbo.HJGL_CH_HardTestReportItem AS ReportItem ON JointInfo.JOT_ID = ReportItem.JOT_ID
WHERE ReportItem.IsShow=1 AND ReportItem.HardTestReportId IS NULL";
DataTable dt = SQLHelper.GetDataTableRunText(strR, null);
foreach (var item in projects)
{
// var projectHardTestReportItemSets = hardTestReportItemSets.Where(x => x.ProjectId == item.ProjectId);
TreeNode rootProjectNode = new TreeNode();//定义根节点
if (dt.Select("ProjectId='"+item.ProjectId+"'").Count()>0)
{
rootProjectNode.Text = "<font color='#FF7575'>" + item.ProjectCode + "</font>";
}
else
{
rootProjectNode.Text = item.ProjectCode;
}
rootProjectNode.NodeID = item.ProjectId;
rootProjectNode.ToolTip = item.ProjectName;
rootProjectNode.CommandName = "项目名称";
rootProjectNode.EnableClickEvent = true;
rootNode.Nodes.Add(rootProjectNode);
}
}
#endregion
protected void drpProjectId_SelectedIndexChanged(object sender, EventArgs e)
{
this.InitTreeMenu();
}
#region
/// <summary>
/// 生成硬度检测报告
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnGenerating_Click(object sender, EventArgs e)
{
if (CommonService.GetAllButtonPowerList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, Const.HJGL_HardReportSetMenuId, Const.BtnGenerate))
{
int[] selections = Grid1.SelectedRowIndexArray;
int i = 0; //检验数量
int flag = 0; //打印标记
JArray mergedData = Grid1.GetMergedData();
string jot_id = string.Empty, hardTestReportId = string.Empty, hardTestReportItemId = string.Empty, hardTestReportItemId2 = string.Empty, hardTestReportItemId3 = string.Empty, isoidLog = string.Empty, jointIdLog = string.Empty;
List<string> steCodes = new List<string>();
foreach (JObject mergedRow in mergedData)
{
JObject values = mergedRow.Value<JObject>("values");
int rowIndex = mergedRow.Value<int>("index");
if (selections.Contains(rowIndex))
{
steCodes.Add(values.Value<string>("STE_Code").ToString());
}
}
if (steCodes.Distinct().Count() > 1)
{
ShowNotify("必须是相同材质的焊缝才能生成报告!", MessageBoxIcon.Warning);
return;
}
foreach (JObject mergedRow in mergedData)
{
string status = mergedRow.Value<string>("status");
JObject values = mergedRow.Value<JObject>("values");
int rowIndex = mergedRow.Value<int>("index");
if (selections.Contains(rowIndex))
{
jot_id = Grid1.DataKeys[rowIndex][3].ToString();
hardTestReportItemId = Grid1.DataKeys[rowIndex][0].ToString();
hardTestReportItemId2 = Grid1.DataKeys[rowIndex][1].ToString();
hardTestReportItemId3 = Grid1.DataKeys[rowIndex][2].ToString();
Model.HJGL_PW_JointInfo joint = BLL.HJGL_PW_JointInfoService.GetJointInfoByJotID(jot_id);
Model.HJGL_PW_IsoInfo iso = BLL.HJGL_PW_IsoInfoService.GetIsoInfoByIsoInfoId(joint.ISO_ID);
if (isoidLog != joint.ISO_ID) //新管线的记录
{
flag = 0;
Model.HJGL_CH_HardTestReport oldHardTestReport = BLL.HJGL_CH_HardTestReportService.GetCH_HardTestReportByID(hardTestReportId);
if (oldHardTestReport != null) //更新之前硬度检验报告的热处理状态和检验数量
{
oldHardTestReport.HotProessState = "消应力热处理";
oldHardTestReport.TestCount = i;
BLL.HJGL_CH_HardTestReportService.UpdateCH_HardTestReport(oldHardTestReport);
}
i = 0; //检验数量清零
i++; //检验数量+1
isoidLog = joint.ISO_ID;
hardTestReportId = SQLHelper.GetNewID(typeof(Model.HJGL_CH_HardTestReport));
//生成硬度委托及硬度检验报告记录
Model.HJGL_CH_HardTestReport hardTestReport = new Model.HJGL_CH_HardTestReport();
hardTestReport.HardTestReportId = hardTestReportId;
hardTestReport.HardTestReportCode = BLL.SQLHelper.RunProcNewIdByProjectId("SpGetNewCodeByProjectId", "dbo.HJGL_CH_HardTestReport", "HardTestReportCode", joint.ProjectId, BLL.Base_ProjectService.GetProjectCode(joint.ProjectId) + "-");
hardTestReport.ProjectId = joint.ProjectId;
hardTestReport.ISO_ID = iso.ISO_ID;
hardTestReport.TestDate = DateTime.Now;
hardTestReport.TrustUnitId = iso.BSU_ID;
hardTestReport.TestStandard = "GB/T17394.1-2014";
hardTestReport.STE_ID = iso.STE_ID;
Model.Project_Sys_Set equipment = BLL.Project_SysSetService.GetSysSetBySetId("6", joint.ProjectId);
if (equipment != null)
{
hardTestReport.EquipmentId = equipment.SetValue;
Model.HJGL_BS_Equipment eq = BLL.HJGL_EquipmentService.GetEquipmentById(equipment.SetValue);
if (eq != null)
{
hardTestReport.InstrumentType = eq.EquipmentName;
}
}
hardTestReport.ReportName = hardTestReport.HardTestReportCode + "-" + iso.ISO_IsoNo;
//项目承包单位信息
hardTestReport.ContractUnit = "镇海石化建安工程有限公司";
hardTestReport.TestMethod = "里氏硬度";
hardTestReport.FileType = "R"; //硬度检测报告
BLL.HJGL_CH_HardTestReportService.AddCH_HardTestReport(hardTestReport);
//回写焊口硬度委托时间
//BLL.HJGL_PW_JointInfoService.WriteBackHardTrustDate(jot_id, hardTestReport.TestDate);
}
else
{
i++; //检验数量+1
//回写焊口硬度委托时间
//BLL.HJGL_PW_JointInfoService.WriteBackHardTrustDate(jot_id, DateTime.Now);
}
//更新硬度报告明细信息
if (jointIdLog != jot_id)
{
jointIdLog = jot_id;
flag++; //打印标记+1
}
Model.HJGL_CH_HardTestReportItem item1 = BLL.HJGL_CH_HardTestReportService.GetCH_HardTestReportItemByID(hardTestReportItemId);
item1.HardTestReportId = hardTestReportId;
item1.HardNessValue = Funs.GetNewInt(values.Value<string>("HardNessValue1").ToString());
item1.Remark = values.Value<string>("Remark").ToString();
item1.Flag = flag;
BLL.HJGL_CH_HardTestReportService.UpdateCH_HardTestReportItem(item1);
Model.HJGL_CH_HardTestReportItem item2 = BLL.HJGL_CH_HardTestReportService.GetCH_HardTestReportItemByID(hardTestReportItemId2);
item2.HardTestReportId = hardTestReportId;
item2.HardNessValue = Funs.GetNewInt(values.Value<string>("HardNessValue2").ToString());
item2.Remark = values.Value<string>("Remark").ToString();
item2.Flag = flag;
BLL.HJGL_CH_HardTestReportService.UpdateCH_HardTestReportItem(item2);
Model.HJGL_CH_HardTestReportItem item3 = BLL.HJGL_CH_HardTestReportService.GetCH_HardTestReportItemByID(hardTestReportItemId3);
item3.HardTestReportId = hardTestReportId;
item3.HardNessValue = Funs.GetNewInt(values.Value<string>("HardNessValue3").ToString());
item3.Remark = values.Value<string>("Remark").ToString();
item3.Flag = flag;
BLL.HJGL_CH_HardTestReportService.UpdateCH_HardTestReportItem(item3);
if (flag == 3) //逢3重置标识
{
flag = 0;
}
}
}
//更新之前硬度检验报告的热处理状态和检验数量
Model.HJGL_CH_HardTestReport oldHardTestReport2 = BLL.HJGL_CH_HardTestReportService.GetCH_HardTestReportByID(hardTestReportId);
if (oldHardTestReport2 != null)
{
oldHardTestReport2.HotProessState = "消应力热处理";
oldHardTestReport2.TestCount = i;
Model.HJGL_PW_IsoInfo iso = BLL.HJGL_PW_IsoInfoService.GetIsoInfoByIsoInfoId(oldHardTestReport2.ISO_ID);
if (iso != null)
{
oldHardTestReport2.ReportName = BLL.SQLHelper.RunProcNewIdByProjectId("SpGetNewCodeByProjectId", "dbo.HJGL_CH_HardTestReport", "ReportName", iso.ProjectId, BLL.Base_ProjectService.GetProjectCode(iso.ProjectId) + "-" + iso.ISO_IsoNo + "-");
}
BLL.HJGL_CH_HardTestReportService.UpdateCH_HardTestReport(oldHardTestReport2);
}
BLL.Sys_LogService.AddLog(BLL.Const.System_3, this.CurrUser.LoginProjectId, this.CurrUser.UserId, "生成硬度检测报告!");
ShowNotify("成功生成硬度检测报告!", MessageBoxIcon.Success);
BindGrid();
}
else
{
ShowNotify("您没有这个权限,请与管理员联系!", MessageBoxIcon.Warning);
}
}
#endregion
#region TreeView
/// <summary>
/// 点击TreeView
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void tvControlItem_NodeCommand(object sender, TreeCommandEventArgs e)
{
var isoList = (from x in Funs.DB.HJGL_PW_IsoInfo
where x.ProjectId == this.tvControlItem.SelectedNodeID
select new { x.ISO_ID, x.ISO_IsoNo }).Distinct();
this.drpIsoNo.Items.Clear();
this.drpIsoNo.DataSource = isoList;
this.drpIsoNo.DataBind();
Funs.FineUIPleaseSelect(this.drpIsoNo);
this.drpIsoNo.SelectedValue = BLL.Const._Null;
this.BindGrid();
}
#endregion
/// <summary>
/// 查询
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void TextBox_TextChanged(object sender, EventArgs e)
{
this.BindGrid();
}
#region
#region
/// <summary>
/// 数据绑定
/// </summary>
private void BindGrid()
{
int[] selections = Grid1.SelectedRowIndexArray;
foreach (int rowIndex in selections)
{
SelectList.Add(Grid1.DataKeys[rowIndex][0] + "," + Grid1.DataKeys[rowIndex][1]);
}
string strSql = @"select * from dbo.HJGL_View_CH_HardTestReportItemSet Item
where Item.ProjectId=@ProjectId and HardTestReportId is null ";
List<SqlParameter> listStr = new List<SqlParameter>();
listStr.Add(new SqlParameter("@ProjectId", this.tvControlItem.SelectedNodeID));
if (this.drpIsoNo.SelectedValue != BLL.Const._Null)
{
strSql += " AND Item.ISO_ID = @IsoId";
listStr.Add(new SqlParameter("@IsoId", this.drpIsoNo.SelectedValue));
}
SqlParameter[] parameter = listStr.ToArray();
DataTable tb = SQLHelper.GetDataTableRunText(strSql, parameter);
Grid1.RecordCount = tb.Rows.Count;
tb = GetFilteredTable(Grid1.FilteredData, tb);
// 2.获取当前排序(如不分页要调用这个排序方法)
//var table = this.GetSortTable(Grid1, tb);
// 2.获取当前分页数据
var table = this.GetPagedDataTable(Grid1, tb);
Grid1.DataSource = table;
Grid1.DataBind();
}
#endregion
#endregion
#region
/// <summary>
/// 页索引改变事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Grid1_PageIndexChange(object sender, GridPageEventArgs e)
{
BindGrid();
}
#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();
}
#endregion
#region
/// <summary>
/// 排序
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Grid1_Sort(object sender, GridSortEventArgs e)
{
//Grid1.SortDirection = e.SortDirection;
//Grid1.SortField = e.SortField;
BindGrid();
}
#endregion
#region
/// <summary>
///
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnSave_Click(object sender, EventArgs e)
{
JArray mergedData = Grid1.GetMergedData();
string jot_id = string.Empty, hardTestReportId = string.Empty, hardTestReportItemId = string.Empty, hardTestReportItemId2 = string.Empty, hardTestReportItemId3 = string.Empty, isoidLog = string.Empty, jointIdLog = string.Empty;
foreach (JObject mergedRow in mergedData)
{
string status = mergedRow.Value<string>("status");
JObject values = mergedRow.Value<JObject>("values");
int rowIndex = mergedRow.Value<int>("index");
jot_id = Grid1.DataKeys[rowIndex][3].ToString();
hardTestReportItemId = Grid1.DataKeys[rowIndex][0].ToString();
hardTestReportItemId2 = Grid1.DataKeys[rowIndex][1].ToString();
hardTestReportItemId3 = Grid1.DataKeys[rowIndex][2].ToString();
Model.HJGL_PW_JointInfo joint = BLL.HJGL_PW_JointInfoService.GetJointInfoByJotID(jot_id);
Model.HJGL_PW_IsoInfo iso = BLL.HJGL_PW_IsoInfoService.GetIsoInfoByIsoInfoId(joint.ISO_ID);
Model.HJGL_CH_HardTestReportItem item1 = BLL.HJGL_CH_HardTestReportService.GetCH_HardTestReportItemByID(hardTestReportItemId);
item1.HardNessValue = Funs.GetNewInt(values.Value<string>("HardNessValue1").ToString());
item1.Remark = values.Value<string>("Remark").ToString();
BLL.HJGL_CH_HardTestReportService.UpdateCH_HardTestReportItem(item1);
Model.HJGL_CH_HardTestReportItem item2 = BLL.HJGL_CH_HardTestReportService.GetCH_HardTestReportItemByID(hardTestReportItemId2);
item2.HardNessValue = Funs.GetNewInt(values.Value<string>("HardNessValue2").ToString());
item2.Remark = values.Value<string>("Remark").ToString();
BLL.HJGL_CH_HardTestReportService.UpdateCH_HardTestReportItem(item2);
Model.HJGL_CH_HardTestReportItem item3 = BLL.HJGL_CH_HardTestReportService.GetCH_HardTestReportItemByID(hardTestReportItemId3);
item3.HardNessValue = Funs.GetNewInt(values.Value<string>("HardNessValue3").ToString());
item3.Remark = values.Value<string>("Remark").ToString();
BLL.HJGL_CH_HardTestReportService.UpdateCH_HardTestReportItem(item3);
}
ShowNotify("提交成功!", MessageBoxIcon.Success);
BindGrid();
}
#endregion
}
}