Basf_TCC7/HJGL/FineUIPro.Web/WelderManage/WelderTestInfoEdit.aspx.cs

118 lines
4.1 KiB
C#

using BLL;
using Microsoft.JScript;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace FineUIPro.Web.WelderManage
{
public partial class WelderTestInfoEdit : PageBase
{
private string Id = string.Empty;
private string welderId=string.Empty;
protected void Page_Load(object sender, EventArgs e)
{
this.welderId = Request.Params["WelderId"];
this.Id= Request.Params["id"];
if (!IsPostBack)
{
this.BindDrpInit();
this.GetWelderInfo();
if(!string.IsNullOrEmpty(this.Id))
this.GetTestInfo();
}
}
public void GetTestInfo() {
var result=Funs.DB.Welder_TestInfo.FirstOrDefault(t=>t.Id==this.Id);
if (result == null)
{
ShowNotify("请不要非法操作",MessageBoxIcon.Error);
return;
}
drpIsPass.SelectedValue = result.IsPass.ToString();
drpMaterial.SelectedValue=result.MaterialId.ToString();
drpWeldMethod.SelectedValue = result.WeldMethodId.ToString();
txtCheckDate.Text = result.CreatedDate.Value.ToString("yyyy-MM-dd");
txtRemark.Text = result.Remark.ToString();
}
private void GetWelderInfo()
{
var result = Funs.DB.Welder_Welder.FirstOrDefault(t => t.WelderId == this.welderId);
if(result == null)
{
return;
}
lbWedlerName.Text= result.WelderName;
lbWedlerCode.Text= result.WelderCode;
}
private void BindDrpInit()
{
var methodList = Funs.DB.Base_WeldingMethod.OrderBy(t=>t.WeldingMethodCode).ToList();
drpWeldMethod.DataSource= methodList;
drpWeldMethod.DataTextField = "WeldingMethodCode";
drpWeldMethod.DataValueField = "WeldingMethodId";
drpWeldMethod.DataBind();
drpWeldMethod.Items.Insert(0, new ListItem("请选择", ""));
var materList = Funs.DB.Base_Material.OrderBy(t=>t.MaterialCode).ToList();
drpMaterial.DataSource= materList;
drpMaterial.DataTextField = "MaterialCode";
drpMaterial.DataValueField = "MaterialId";
drpMaterial.DataBind();
drpMaterial.Items.Insert(0, new ListItem("请选择", ""));
}
protected void btnSave_Click(object sender, EventArgs e)
{
var result = SaveData();
if (result.Item1)
{
ShowNotify("保存成功", MessageBoxIcon.Success);
PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference());
}
else
{
ShowNotify(result.Item2, MessageBoxIcon.Error);
}
}
(bool,string) SaveData()
{
try
{
var input = new Model.Welder_TestInfo();
input.CreatedDate = System.Convert.ToDateTime(txtCheckDate.Text);
input.ProjectId = this.CurrUser.LoginProjectId;
input.WeldMethodId = drpWeldMethod.SelectedValue;
input.WelderId = this.welderId;
input.MaterialId = drpMaterial.SelectedValue;
input.Remark = txtRemark.Text.Trim();
input.IsPass = drpIsPass.SelectedValue == "是" ? true : false;
if (string.IsNullOrEmpty(this.Id))
{
BLL.WelderTestService.Add(input);
}
else
{
input.Id = this.Id;
BLL.WelderTestService.Edit(input);
}
return (true, "保存成功");
}
catch (Exception ex)
{
BLL.ErrLogInfo.WriteLog(ex, "保存焊工考试结果失败");
return (false, ex.Message);
}
}
}
}