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

585 lines
26 KiB
C#

using System;
using System.Collections.Generic;
using System.Data;
using System.Text;
using System.Data.SqlClient;
using System.Linq;
using BLL;
using Newtonsoft.Json.Linq;
using AspNet = System.Web.UI.WebControls;
namespace FineUIPro.Web.HJGL.HotHardManage
{
public partial class HardTestResult : PageBase
{
#region
/// <summary>
/// 硬度检验报告主键
/// </summary>
public string HardTestReportId
{
get
{
return (string)ViewState["HardTestReportId"];
}
set
{
ViewState["HardTestReportId"] = value;
}
}
#endregion
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
ddlPageSize.SelectedValue = 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.tvHardTestTrust.Nodes.Clear();
TreeNode rootNode = new TreeNode();
rootNode.Text = "项目";
rootNode.NodeID = "0";
rootNode.ToolTip = "绿色为结果全部反馈,黑色为未完全反馈";
rootNode.Expanded = true;
rootNode.EnableClickEvent = true;
this.tvHardTestTrust.Nodes.Add(rootNode);
//this.InitTreeMenu();//加载树
//this.tvHardTestTrust.SelectedNodeID = "0";
//BindGrid();
CheckBoxField cbf1 = Grid1.FindColumn("IsOK1") as CheckBoxField;
cbf1.HeaderText = "<i class=\"ui-icon f-grid-checkbox myheadercheckbox\"></i>&nbsp;硬度合格";
CheckBoxField cbf2 = Grid1.FindColumn("IsOK2") as CheckBoxField;
cbf2.HeaderText = "<i class=\"ui-icon f-grid-checkbox myheadercheckbox\"></i>&nbsp;硬度不合格";
}
}
protected void drpProjectId_SelectedIndexChanged(object sender, EventArgs e)
{
this.InitTreeMenu();
}
protected void TextBox_TextChanged(object sender, EventArgs e)
{
this.BindGrid();
}
private void BindGrid()
{
string strSql = string.Empty;
List<SqlParameter> listStr = new List<SqlParameter>();
string projectIds = BLL.Base_ProjectService.GetStrProjectIds(this.CurrUser.UserId, "1");
if (this.tvHardTestTrust.SelectedNode.CommandName == "报告编号")
{
strSql = @"SELECT *,newid() as New_ID FROM dbo.HJGL_View_CH_HardTestResult
WHERE HardTestReportId=@HardTestReportId";
listStr.Add(new SqlParameter("@HardTestReportId", this.tvHardTestTrust.SelectedNodeID));
}
else if (this.tvHardTestTrust.SelectedNode.CommandName == "项目名称")
{
strSql = @"SELECT *,newid() as New_ID FROM dbo.HJGL_View_CH_HardTestResult
WHERE ProjectId= @ProjectId AND HardTestReportId is not null and (FileType='R' or FileType is null)";
listStr.Add(new SqlParameter("@ProjectId", this.tvHardTestTrust.SelectedNodeID));
}
else if (this.tvHardTestTrust.SelectedNodeID == "0") //选择项目根节点 WHERE @ProjectId like '%'+ProjectId+'%' and HardTestReportId is not null";
{
strSql = @"SELECT *,newid() as New_ID FROM dbo.HJGL_View_CH_HardTestResult
WHERE CHARINDEX(ProjectId,@ProjectId)>0 and HardTestReportId is not null";
listStr.Add(new SqlParameter("@ProjectId", projectIds));
}
if (!string.IsNullOrEmpty(this.txtIsoNo.Text.Trim()))
{
strSql += @" and ISO_IsoNo like @IsoNo ";
listStr.Add(new SqlParameter("@IsoNo", "%" + this.txtIsoNo.Text.Trim() + "%"));
}
if (!string.IsNullOrEmpty(this.txtJointNo.Text.Trim()))
{
strSql += @" and JOT_JointNo like @JointNo ";
listStr.Add(new SqlParameter("@JointNo", "%" + this.txtJointNo.Text.Trim() + "%"));
}
if (this.rblState.SelectedValue == "1")
{
strSql += @" and IsOK =1 ";
}
else if (this.rblState.SelectedValue == "0")
{
strSql += @" and IsOK =0 ";
}
else if (this.rblState.SelectedValue == "3")
{
strSql += @" and IsOK is null and CannotCheck is null";
}
SqlParameter[] parameter = listStr.ToArray();
DataTable tb = SQLHelper.GetDataTableRunText(strSql, parameter);
// 2.获取当前分页数据
//var table = this.GetPagedDataTable(Grid1, tb1);
Grid1.RecordCount = tb.Rows.Count;
tb = GetFilteredTable(Grid1.FilteredData, tb);
var table = this.GetPagedDataTable(Grid1, tb);
Grid1.DataSource = table;
Grid1.DataBind();
for (int i = 0; i < this.Grid1.Rows.Count; i++)
{
Model.HJGL_CH_HardTestResult result = BLL.HJGL_CH_HardTestResultService.GetHardTestResultByHardTestReportIdAndJotID(this.Grid1.Rows[i].DataKeys[1].ToString(), this.Grid1.Rows[i].DataKeys[0].ToString());
if (result != null)
{
if (result.IsOK == true)
{
this.Grid1.Rows[i].Values[4] = BLL.Const._True;
this.Grid1.Rows[i].Values[5] = BLL.Const._False;
}
if (result.IsOK == false)
{
this.Grid1.Rows[i].Values[4] = BLL.Const._False;
this.Grid1.Rows[i].Values[5] = BLL.Const._True;
}
if (result.CannotCheck == true)
{
this.Grid1.Rows[i].Values[6] = BLL.Const._True;
}
//System.Web.UI.WebControls.DropDownList drpIsOK = (System.Web.UI.WebControls.DropDownList)(this.Grid1.Rows[i].FindControl("drpIsOK"));
//if (result.IsOK == true)
//{
// drpIsOK.SelectedValue = "1";
//}
//else if (result.IsOK == false)
//{
// drpIsOK.SelectedValue = "0";
//}
//else
//{
// drpIsOK.SelectedValue = "2";
//}
}
}
}
#region -
/// <summary>
/// 加载树
/// </summary>
private void InitTreeMenu()
{
this.tvHardTestTrust.Nodes.Clear();
TreeNode rootNode = new TreeNode();
rootNode.Text = "项目";
rootNode.NodeID = "0";
rootNode.ToolTip = "绿色为结果全部反馈,黑色为未完全反馈";
rootNode.Expanded = true;
rootNode.EnableClickEvent = true;
this.tvHardTestTrust.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();
}
List<Model.HJGL_CH_HardTestReport> trustLists = new List<Model.HJGL_CH_HardTestReport>(); ///硬度检验报告
trustLists = (from x in Funs.DB.HJGL_CH_HardTestReport
where x.HotHardCode.Contains(this.txtSearchNo.Text.Trim())
select x).ToList();
foreach (var item in projects)
{
TreeNode rootUnitNode = new TreeNode();//定义根节点
rootUnitNode.Text = item.ProjectCode;
rootUnitNode.NodeID = item.ProjectId;
rootUnitNode.EnableClickEvent = true;
rootUnitNode.EnableExpandEvent = true;
rootUnitNode.ToolTip = item.ProjectName;
rootUnitNode.CommandName = "项目名称";
rootNode.Nodes.Add(rootUnitNode);
if (!string.IsNullOrEmpty(this.txtSearchNo.Text.Trim()))
{
var projectTrustLists = (from x in trustLists
where x.ProjectId == item.ProjectId
&& (x.FileType == null || x.FileType == "T")
orderby x.HotHardCode descending
select x).ToList();
if (projectTrustLists.Count > 0)
{
rootUnitNode.Expanded = true;
this.BindNodes(rootUnitNode, projectTrustLists);
}
}
else
{
TreeNode tn = new TreeNode();
tn.NodeID = "temp";
tn.Text = "正在加载...";
rootUnitNode.Nodes.Add(tn);
}
}
}
#endregion
/// <summary>
/// 查询
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Tree_TextChanged(object sender, EventArgs e)
{
this.InitTreeMenu();
//this.BindGrid();
}
protected void tvControlItem_NodeExpand(object sender, TreeNodeEventArgs e)
{
if (e.Node.Nodes != null)
{
e.Node.Nodes.Clear();
}
var trustProjectLists = (from x in Funs.DB.HJGL_CH_HardTestReport
where x.HotHardCode.Contains(this.txtSearchNo.Text.Trim())
&& x.ProjectId == e.Node.NodeID
orderby x.HotHardCode descending
select x).ToList();
this.BindNodes(e.Node, trustProjectLists);
}
#region
/// <summary>
/// 绑定树节点
/// </summary>
/// <param name="node"></param>
private void BindNodes(TreeNode node, List<Model.HJGL_CH_HardTestReport> trustList)
{
foreach (var item in trustList)
{
TreeNode newNode = new TreeNode();
var hardTestReportShowItemsCount = (from x in Funs.DB.HJGL_CH_HardTestReportItem where x.HardTestReportId == item.HardTestReportId select x.JOT_ID).Distinct().Count();
var hardTestResults = from x in Funs.DB.HJGL_CH_HardTestResult where x.HardTestReportId == item.HardTestReportId && x.IsOK != null select x;
var cannotCheckHardTestResults = from x in Funs.DB.HJGL_CH_HardTestResult where x.HardTestReportId == item.HardTestReportId && x.CannotCheck == true select x;
if (hardTestReportShowItemsCount == (hardTestResults.Count() + cannotCheckHardTestResults.Count())) //单据数据全部反馈,记录为绿色
{
newNode.Text = "<font color='#009966'>" + item.HotHardCode + "</font>";
}
else
{
newNode.Text = item.HotHardCode;
}
newNode.NodeID = item.HardTestReportId;
newNode.ToolTip = item.HotHardCode;
newNode.CommandName = "报告编号";
newNode.EnableClickEvent = true;
node.Nodes.Add(newNode);
}
}
#endregion
#region
/// <summary>
/// Grid行点击事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Grid1_RowCommand(object sender, GridCommandEventArgs e)
{
if (e.CommandName == "CheckBox1")
{
CheckBoxField checkField = (CheckBoxField)Grid1.FindColumn(e.ColumnIndex);
bool checkState = checkField.GetCheckedState(e.RowIndex);
if (checkState == true)
{
CheckBoxField checkField2 = (CheckBoxField)Grid1.FindColumn(e.ColumnIndex + 1);
bool checkState2 = checkField2.GetCheckedState(e.RowIndex);
if (checkState2)
{
checkField2.SetCheckedState(e.RowIndex, false);
}
}
}
if (e.CommandName == "CheckBox2")
{
CheckBoxField checkField = (CheckBoxField)Grid1.FindColumn(e.ColumnIndex);
bool checkState = checkField.GetCheckedState(e.RowIndex);
this.hdIndex.Text = string.Empty;
if (checkState == true)
{
string isoNo = this.Grid1.Rows[e.RowIndex].Values[1].ToString();
string jointNo = this.Grid1.Rows[e.RowIndex].Values[2].ToString();
PageContext.RegisterStartupScript(Confirm.GetShowReference("是否确认管线" + isoNo + "的焊口" + jointNo + "硬度不合格?",
String.Empty,
MessageBoxIcon.Question,
PageManager1.GetCustomEventReference(false, "Confirm_OK"), // 第一个参数 false 用来指定当前不是AJAX请求
PageManager1.GetCustomEventReference("Confirm_Cancel")));
this.hdIndex.Text = e.RowIndex.ToString();
CheckBoxField checkField2 = (CheckBoxField)Grid1.FindColumn(e.ColumnIndex - 1);
bool checkState2 = checkField2.GetCheckedState(e.RowIndex);
if (checkState2)
{
checkField2.SetCheckedState(e.RowIndex, false);
}
}
}
}
#endregion
/// <summary>
/// 点口确定对话框
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void PageManager1_CustomEvent(object sender, CustomEventArgs e)
{
if (!string.IsNullOrEmpty(this.hdIndex.Text))
{
if (e.EventArgument == "Confirm_OK")
{
this.Grid1.Rows[Funs.GetNewIntOrZero(this.hdIndex.Text)].Values[5] = BLL.Const._True;
}
else if (e.EventArgument == "Confirm_Cancel")
{
this.Grid1.Rows[Funs.GetNewIntOrZero(this.hdIndex.Text)].Values[5] = BLL.Const._False;
}
}
}
#region TreeView
/// <summary>
/// 点击TreeView
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void tvHardTestTrust_NodeCommand(object sender, TreeCommandEventArgs e)
{
this.HardTestReportId = this.tvHardTestTrust.SelectedNodeID;
this.Grid1.DataSource = null;
this.Grid1.DataBind();
BindGrid();
}
#endregion
#region
/// <summary>
/// 页索引改变事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Grid1_PageIndexChange(object sender, GridPageEventArgs e)
{
Grid1.PageIndex = e.NewPageIndex;
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 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 btnView_Click(object sender, EventArgs e)
{
var report = BLL.HJGL_CH_HardTestReportService.GetCH_HardTestReportByID(this.HardTestReportId);
if (report != null)
{
PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("HardTestReportEdit.aspx?HardTestReportId={0}&type=view", this.HardTestReportId, "查看 - ")));
}
else
{
ShowNotify("请选择要处理的硬度检验报告记录!", MessageBoxIcon.Warning);
}
}
#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.HJGL_HardTestResultMenuId, Const.BtnSave))
{
//var report = BLL.HJGL_CH_HardTestReportService.GetCH_HardTestReportByID(this.HardTestReportId);
//if (report != null)
//{
var hardTestResults = from x in Funs.DB.HJGL_CH_HardTestResult select x;
for (int i = 0; i < this.Grid1.Rows.Count; i++)
{
string jot_id = this.Grid1.Rows[i].DataKeys[0].ToString();
string hardTestReportId = this.Grid1.Rows[i].DataKeys[1].ToString();
var hardTestResult = hardTestResults.FirstOrDefault(x => x.JOT_ID == jot_id && x.HardTestReportId == hardTestReportId);
if (hardTestResult != null)
{
Funs.DB.HJGL_CH_HardTestResult.DeleteOnSubmit(hardTestResult);
Funs.DB.SubmitChanges();
}
}
BLL.HJGL_CH_HardTestResultService.DeleteHardTestResultsyHardTestReportId(this.HardTestReportId);
var hardTestReportItems = from x in Funs.DB.HJGL_CH_HardTestReportItem select x;
var hotProessResults = from x in Funs.DB.HJGL_CH_HotProessResult select x;
JArray mergedData = Grid1.GetMergedData();
foreach (JObject mergedRow in mergedData)
{
Model.HJGL_CH_HardTestResult result = new Model.HJGL_CH_HardTestResult();
string status = mergedRow.Value<string>("status");
JObject values = mergedRow.Value<JObject>("values");
int rowIndex = mergedRow.Value<int>("index");
result.HardTestReportId = this.Grid1.Rows[rowIndex].DataKeys[1].ToString();
result.JOT_ID = values.Value<string>("JOT_ID").ToString();
CheckBoxField IsOK1 = (CheckBoxField)Grid1.FindColumn("IsOK1");
CheckBoxField IsOK2 = (CheckBoxField)Grid1.FindColumn("IsOK2");
bool b1 = IsOK1.GetCheckedState(rowIndex);
bool b2 = IsOK2.GetCheckedState(rowIndex);
if (b1)
{
result.IsOK = true;
result.ResultDate = DateTime.Now;
//硬度合格,更新热处理反馈结果也为合格
Model.HJGL_CH_HardTestReportItem hardTestReportItem = (from x in hardTestReportItems where x.HardTestReportId == result.HardTestReportId && x.JOT_ID == result.JOT_ID select x).FirstOrDefault();
if (hardTestReportItem != null)
{
Model.HJGL_CH_HotProessResult hotProessResult = (from x in hotProessResults where x.HotProessTrustId == hardTestReportItem.HotProessTrustId && x.JOT_ID == result.JOT_ID select x).FirstOrDefault();
if (hotProessResult != null)
{
hotProessResult.IsOK = true;
BLL.HJGL_CH_HotProessResultService.UpdateHotProessResult(hotProessResult);
Model.HJGL_PW_JointInfo joint = BLL.HJGL_PW_JointInfoService.GetJointInfoByJotID(hotProessResult.JOT_ID);
if (joint != null)
{
if (joint.HotProessResultOK == null)
{
//回写热处理合格及反馈时间
BLL.HJGL_PW_JointInfoService.WriteBackHardTestResultOKAndDate(joint.JOT_ID, true);
}
}
}
}
//回写硬度合格及反馈时间
BLL.HJGL_PW_JointInfoService.WriteBackHardTestResultOKAndDate(result.JOT_ID, true);
}
if (b2)
{
result.IsOK = false;
result.ResultDate = DateTime.Now;
//回写硬度合格及反馈时间
BLL.HJGL_PW_JointInfoService.WriteBackHardTestResultOKAndDate(result.JOT_ID, false);
}
CheckBoxField CannotCheck = (CheckBoxField)Grid1.FindColumn("CannotCheck");
bool b3 = CannotCheck.GetCheckedState(rowIndex);
if (b3)
{
result.CannotCheck = true;
}
result.Remark = values.Value<string>("Remark").ToString();
BLL.HJGL_CH_HardTestResultService.AddHardTestResult(result);
}
ShowNotify("提交成功!", MessageBoxIcon.Success);
//}
//else
//{
// ShowNotify("请选择要处理的硬度检验报告记录!", MessageBoxIcon.Warning);
//}
}
else
{
ShowNotify("您没有这个权限,请与管理员联系!", MessageBoxIcon.Warning);
}
}
#endregion
#region
/// 导出按钮
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnOut_Click(object sender, EventArgs e)
{
Response.ClearContent();
string filename = Funs.GetNewFileName();
Response.AddHeader("content-disposition", "attachment; filename=" + System.Web.HttpUtility.UrlEncode("硬度检验结果反馈" + filename, System.Text.Encoding.UTF8) + ".xls");
Response.ContentType = "application/excel";
Response.ContentEncoding = System.Text.Encoding.UTF8;
Response.Write(GetGridTableHtml(Grid1));
Response.End();
}
/// <summary>
/// 导出方法
/// </summary>
/// <param name="grid"></param>
/// <returns></returns>
private string GetGridTableHtml(Grid grid)
{
StringBuilder sb = new StringBuilder();
sb.Append("<meta http-equiv=\"content-type\" content=\"application/excel; charset=UTF-8\"/>");
sb.Append("<table cellspacing=\"0\" rules=\"all\" border=\"1\" style=\"border-collapse:collapse;\">");
sb.Append("<tr>");
this.Grid1.PageSize = 10000;
BindGrid();
foreach (GridColumn column in grid.Columns)
{
if (column.Hidden == false)
{
sb.AppendFormat("<td>{0}</td>", column.HeaderText);
}
}
sb.Append("</tr>");
foreach (GridRow row in grid.Rows)
{
sb.Append("<tr>");
foreach (GridColumn column in grid.Columns)
{
if (column.Hidden == false)
{
string html = row.Values[column.ColumnIndex].ToString();
if (column.ColumnID == "tfNumber")
{
html = (row.FindControl("labNumber") as AspNet.Label).Text;
}
if (html == "True")
{
html = "√";
}
if (html == "False")
{
html = "";
}
sb.AppendFormat("<td>{0}</td>", html);
}
}
sb.Append("</tr>");
}
sb.Append("</table>");
return sb.ToString();
}
#endregion
}
}