SGGL_SHJ/SGGL/FineUIPro.Web/CQMS/PersonManage/TestRecordEdit.aspx.cs

283 lines
11 KiB
C#

using BLL;
using Newtonsoft.Json.Linq;
using System;
using System.Data;
using System.Data.SqlClient;
using System.Collections.Generic;
using System.Linq;
using System.Web.UI.WebControls;
using AspNet = System.Web.UI.WebControls;
using Model;
namespace FineUIPro.Web.CQMS.PersonManage
{
public partial class TestRecordEdit : PageBase
{
/// <summary>
/// 主键
/// </summary>
public string TestPlanId
{
get
{
return (string)ViewState["TestPlanId"];
}
set
{
ViewState["TestPlanId"] = value;
}
}
/// <summary>
/// 办理类型
/// </summary>
public string State
{
get
{
return (string)ViewState["State"];
}
set
{
ViewState["State"] = value;
}
}
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
SitePerson_PersonService.InitProjectUserListByProjectUnitTypeDropDownList2(drpCheckMan, this.CurrUser.LoginProjectId, Const.ProjectUnitType_1 + "," + Const.ProjectUnitType_3 + "," + Const.ProjectUnitType_4, false);
BLL.UnitService.GetUnit2(this.drpCheckUnit, this.CurrUser.LoginProjectId, true);
this.drpWelder.DataTextField = "PersonName";
this.drpWelder.DataValueField = "PersonId";
this.drpWelder.DataSource = (from x in Funs.DB.SitePerson_Person where x.ProjectId == this.CurrUser.LoginProjectId && x.WorkPostId == Const.WorkPost_Welder && x.States == Const.ProjectPersonStates_1 && x.IsWeldAudit == true select x).ToList();
this.drpWelder.DataBind();
Funs.FineUIPleaseSelect(this.drpWelder);
TestPlanId = Request.Params["TestPlanId"];
if (!string.IsNullOrEmpty(TestPlanId))
{
Model.Welder_TestPlan TestPlan = BLL.CQMS_TestPlanService.GetTestPlanByTestPlanId(TestPlanId);
txtTestPlanCode.Text = TestPlan.TestPlanCode;
if (TestPlan.PlanTestDate != null)
{
txtPlanTestDate.Text = string.Format("{0:yyyy-MM-dd}", TestPlan.PlanTestDate);
}
var list = BLL.CQMS_TestPlanDetailService.getListData(this.TestPlanId);
List<string> strs = BLL.CQMS_TestPlanDetailService.getPersonIdList(this.TestPlanId);
if (strs.Count > 0)
{
this.drpWelder.SelectedValueArray = strs.ToArray();
}
if (TestPlan.RealTestDate != null)
{
txtRealTestDate.Text = string.Format("{0:yyyy-MM-dd}", TestPlan.RealTestDate);
}
Grid1.DataSource = list;
Grid1.DataBind();
}
else
{
string prefix = BLL.ProjectService.GetProjectCodeByProjectId(this.CurrUser.LoginProjectId) + "-HGKS-";
txtTestPlanCode.Text = BLL.SQLHelper.RunProcNewId("SpGetThreeNumber", "Welder_TestPlan", "TestPlanCode", prefix);
}
}
}
protected void Grid1_Sort(object sender, GridSortEventArgs e)
{
}
protected void WindowAtt_Close(object sender, WindowCloseEventArgs e)
{
}
/// <summary>
/// 时间转换
/// </summary>
/// <param name="date"></param>
/// <returns></returns>
public string ConvertDate(object date)
{
if (date != null)
{
return string.Format("{0:yyyy-MM-dd}", Convert.ToDateTime(date));
}
else
{
return null;
}
}
protected void btnSave_Click(object sender, EventArgs e)
{
if (validate())
{
Saveinspection("save");
}
}
/// <summary>
/// 保存
/// </summary>
public void Saveinspection(string saveType)
{
Model.Welder_TestPlan TestPlan = new Model.Welder_TestPlan();
TestPlan.ProjectId = this.CurrUser.LoginProjectId;
TestPlan.TestPlanCode = this.txtTestPlanCode.Text.Trim();
TestPlan.PlanTestDate = Funs.GetNewDateTime(this.txtPlanTestDate.Text.Trim());
TestPlan.RealTestDate = Funs.GetNewDateTime(this.txtRealTestDate.Text.Trim());
if (!string.IsNullOrEmpty(this.TestPlanId))
{
TestPlan.TestPlanId = this.TestPlanId;
CQMS_TestPlanService.UpdateTestPlan(TestPlan);
LogService.AddSys_Log(CurrUser, TestPlan.TestPlanCode, TestPlan.TestPlanId, Const.CQMSWelderTestPlanMenuId, "修改焊工考试记录");
}
var list = addGvList();
foreach (var item in list)
{
Model.Welder_TestPlanDetail detail = BLL.CQMS_TestPlanDetailService.GetTestPlanDetailByTestPlanIdAndPersonId(TestPlan.TestPlanId, item.PersonId);
detail.TestPlanId = TestPlan.TestPlanId;
detail.PersonId = item.PersonId;
detail.IsAppearanceOK = item.IsAppearanceOK;
detail.CheckMan = item.CheckMan;
detail.NDTResult = item.NDTResult;
detail.CheckUnit = item.CheckUnit;
detail.State = item.State;
BLL.CQMS_TestPlanDetailService.UpdateTestPlanDetail(detail);
if (detail.State == true) //考试合格后焊工进入焊接管理
{
Model.SitePerson_Person welder = BLL.SitePerson_PersonService.GetSitePersonByProjectIdPersonId(this.CurrUser.LoginProjectId, detail.PersonId);
if (welder != null)
{
welder.IsWeldOK = true;
BLL.SitePerson_PersonService.UpdateSitePersonWeldInfo(welder);
}
}
else
{
var onesDetail = Funs.DB.Welder_TestPlanDetail.FirstOrDefault(x => x.PersonId == detail.PersonId && x.TestPlanId != detail.TestPlanId && x.State == false);
if (onesDetail != null)
{
Model.SitePerson_Person welder = BLL.SitePerson_PersonService.GetSitePersonByProjectIdPersonId(this.CurrUser.LoginProjectId, detail.PersonId);
if (welder != null)
{
welder.States = Const.ProjectPersonStates_2;
Funs.DB.SubmitChanges();
}
}
}
}
PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference());
}
/// <summary>
/// 表格数据验证
/// </summary>
private bool validate()
{
bool res = false;
string err = string.Empty;
if (this.Grid1.Rows.Count == 0)
{
err += "请选择考试焊工!";
}
//var att = BLL.AttachFileService.GetAttachFileByToKeyId(this.TestPlanId);
//if (att == null)
//{
// err += "请上传质量证明文件!";
//}
foreach (JObject mergedRow in Grid1.GetMergedData())
{
JObject values = mergedRow.Value<JObject>("values");
string IsAppearanceOK = values.Value<string>("IsAppearanceOK");
string CheckMan = values.Value<string>("CheckMan");
string NDTResult = values.Value<string>("NDTResult");
string CheckUnit = values.Value<string>("CheckUnit");
if (string.IsNullOrEmpty(IsAppearanceOK))
{
err += "外观是否合格不能为空!";
}
if (string.IsNullOrEmpty(CheckMan))
{
err += "检查人不能为空!";
}
if (string.IsNullOrEmpty(NDTResult))
{
err += "无损检测结果不能为空!";
}
if (string.IsNullOrEmpty(CheckUnit))
{
err += "检测单位不能为空!";
}
}
if (!string.IsNullOrWhiteSpace(err))
{
Alert.ShowInTop(err, MessageBoxIcon.Warning);
}
else
{
res = true;
}
return res;
}
/// <summary>
/// 绑定表格保存到数据使用
/// </summary>
protected List<Model.Welder_TestPlanDetail> addGvList()
{
var persons = Funs.DB.SitePerson_Person.Where(x => x.ProjectId == this.CurrUser.LoginProjectId && x.States == Const.ProjectPersonStates_1 && x.RoleIds != null);
var units = from x in Funs.DB.Base_Unit select x;
List<Model.Welder_TestPlanDetail> details = new List<Model.Welder_TestPlanDetail>();
foreach (JObject mergedRow in Grid1.GetMergedData())
{
Model.Welder_TestPlanDetail detail = new Model.Welder_TestPlanDetail();
int i = mergedRow.Value<int>("index");
JObject values = mergedRow.Value<JObject>("values");
string PersonId = values.Value<string>("PersonId");
string IsAppearanceOK = values.Value<string>("IsAppearanceOK");
string CheckMan = values.Value<string>("CheckMan");
string NDTResult = values.Value<string>("NDTResult");
string CheckUnit = values.Value<string>("CheckUnit");
string State = values.Value<string>("State");
detail.PersonId = PersonId;
detail.IsAppearanceOK = IsAppearanceOK == "是" ? true : false;
var person = persons.FirstOrDefault(x => x.PersonName == CheckMan);
if (person != null)
{
detail.CheckMan = person.PersonId;
}
detail.NDTResult = NDTResult == "合格" ? true : false;
var unit = units.FirstOrDefault(x => x.UnitName == CheckUnit);
if (unit != null)
{
detail.CheckUnit = unit.UnitId;
}
detail.State = State == "合格" ? true : false;
details.Add(detail);
}
return details;
}
private string GetStringByArray(string[] array)
{
string str = string.Empty;
foreach (var item in array)
{
if (item != BLL.Const._Null)
{
str += item + ",";
}
}
if (!string.IsNullOrEmpty(str))
{
str = str.Substring(0, str.LastIndexOf(","));
}
return str;
}
}
}