SGGL_JT/SUBQHSE/FineUIPro.Web/Customization/CNCCG/HSSE/InApproveManager/EquipmentInItemEdit.aspx.cs

464 lines
20 KiB
C#

using BLL;
using FineUIPro.Web.HSSE.InApproveManager;
using System;
using System.Collections.Generic;
using System.Data.Linq.SqlClient;
using System.Linq;
using System.Text;
namespace FineUIPro.Web.Customization.CNCCG.HSSE.InApproveManager
{
public partial class EquipmentInItemEdit : PageBase
{
#region
/// <summary>
/// 主表主键
/// </summary>
public string EquipmentInId
{
get
{
return (string)ViewState["EquipmentInId"];
}
set
{
ViewState["EquipmentInId"] = value;
}
}
/// <summary>
/// 主键
/// </summary>
public string EquipmentInItemId
{
get
{
return (string)ViewState["EquipmentInItemId"];
}
set
{
ViewState["EquipmentInItemId"] = value;
}
}
/// <summary>
/// 项目主键
/// </summary>
public string ProjectId
{
get
{
return (string)ViewState["ProjectId"];
}
set
{
ViewState["ProjectId"] = value;
}
}
#endregion
#region
/// <summary>
/// 加载页面
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
this.ProjectId = this.CurrUser.LoginProjectId;
btnClose.OnClientClick = ActiveWindow.GetHideReference();
this.InitDropDownList();
///机具设备下拉框
BLL.SpecialEquipmentService.InitSpecialEquipmentDropDownList(this.drpSpecialEquipmentId, true, true);
this.cbIsUsed.Checked = true;
this.EquipmentInId = Request.Params["EquipmentInId"];
this.EquipmentInItemId = Request.Params["EquipmentInItemId"];
if (!string.IsNullOrEmpty(this.EquipmentInItemId))
{
Model.InApproveManager_EquipmentInItem equipmentInItem = BLL.EquipmentInItemService.GetEquipmentInItemById(this.EquipmentInItemId);
if (equipmentInItem != null)
{
this.EquipmentInId = equipmentInItem.EquipmentInId;
if (!string.IsNullOrEmpty(equipmentInItem.SpecialEquipmentId))
{
this.drpSpecialEquipmentId.SelectedValue = equipmentInItem.SpecialEquipmentId;
}
this.txtSizeModel.Text = equipmentInItem.SizeModel;
this.txtOwnerCheck.Text = equipmentInItem.OwnerCheck;
if (!string.IsNullOrEmpty(equipmentInItem.SizeCode))
{
this.txtSizeCode.Text = equipmentInItem.SizeCode;
this.txtSizeCode.Hidden = false;
}
this.dropDetectionStatus.SelectedValue = equipmentInItem.DetectionStatus;
if (!string.IsNullOrEmpty(equipmentInItem.CheckDate))
{
this.txtCheckDate.SelectedDate = DateTime.Parse(equipmentInItem.CheckDate);
}
if (!string.IsNullOrEmpty(equipmentInItem.ProDate.ToString()))
{
this.dpProDate.SelectedDate = equipmentInItem.ProDate;
}
this.txtInspectionCycle.Text = equipmentInItem.InspectionCycle;
//this.txtValidityDateOfInspection.Text = equipmentInItem.ValidityDateOfInspection;
this.txtValidityDateOfInspection.Text = equipmentInItem.ValidityDateOfInspection.ToString();
if (!string.IsNullOrEmpty(equipmentInItem.UseRegDate))
{
this.txtUseRegDate.SelectedDate = DateTime.Parse(equipmentInItem.UseRegDate);
}
this.txtUseRegDepart.Text = equipmentInItem.UseRegDepart;
if (!string.IsNullOrEmpty(equipmentInItem.InDate))
{
this.txtInDate.SelectedDate = DateTime.Parse(equipmentInItem.InDate);
}
if (!string.IsNullOrEmpty(equipmentInItem.OutDate))
{
this.txtOutDate.SelectedDate = DateTime.Parse(equipmentInItem.OutDate);
}
this.txtOperatorName.Text = equipmentInItem.OperatorName;
this.txtSpecialCertificateNumber.Text = equipmentInItem.SpecialCertificateNumber;
this.txtRemark.Text = equipmentInItem.Remark;
if (equipmentInItem.IsUsed != true)
{
this.cbIsUsed.Checked = false;
}
btnEcheck.Hidden = false;
btnEhazard.Hidden = false;
}
}
if (!string.IsNullOrEmpty(this.EquipmentInId))
{
var equipmentIn = BLL.EquipmentInService.GetEquipmentInById(this.EquipmentInId);
if (equipmentIn != null)
{
this.ProjectId = equipmentIn.ProjectId;
if (this.ProjectId != this.CurrUser.LoginProjectId)
{
this.InitDropDownList();
}
if (!string.IsNullOrEmpty(equipmentIn.UnitId))
{
this.drpUnitId.SelectedValue = equipmentIn.UnitId;
this.droUseUnitId.SelectedValue = equipmentIn.UseUnitId;
}
if (!string.IsNullOrEmpty(equipmentIn.EquipmentInCode))
{
this.txtEquipmentInCode.Text = equipmentIn.EquipmentInCode;
//this.txtEquipmentInCode.Hidden = false;
}
}
}
else
{
////自动生成编码
//this.txtEquipmentInCode.Text = BLL.CodeRecordsService.ReturnCodeByMenuIdProjectId(BLL.Const.EquipmentInMenuId, this.ProjectId, this.CurrUser.UnitId);
if (!string.IsNullOrEmpty(CurrUser.UnitId))
{
drpUnitId.SelectedValue = CurrUser.UnitId;
}
}
cbIsUsed_CheckedChanged(null, null);
}
}
public string returnNums(int obj)
{
if (obj< 10) {
return "0" + obj.ToString();
} else {
return obj.ToString();
}
}
/// <summary>
/// 自动生成改编码 ZHXJJ+单位代码+设备编码+日期20230928+数量编号
/// </summary>
/// <returns></returns>
public string ReturnEqCode() {
var Ecode = "ZHXJJ";
var unitCode = Funs.DB.Base_Unit.FirstOrDefault(x => x.UnitId == drpUnitId.SelectedValue);
if (unitCode!=null)
{
Ecode += unitCode.UnitCode;//单位代码
}
//设备编码
var SpecialEquipmentCode = Funs.DB.Base_SpecialEquipment.FirstOrDefault(x => x.SpecialEquipmentId == drpSpecialEquipmentId.SelectedValue);
if (SpecialEquipmentCode!=null)
{
Ecode += SpecialEquipmentCode.SpecialEquipmentCode;
}
if (!string.IsNullOrEmpty(EquipmentInItemId))
{
var itemmodel = Funs.DB.InApproveManager_EquipmentInItem.FirstOrDefault(x => x.EquipmentInItemId == EquipmentInItemId);
if (itemmodel.CompileDate!=null)
{
Ecode += Convert.ToDateTime(itemmodel.CompileDate).Year.ToString() + returnNums(Convert.ToDateTime(itemmodel.CompileDate).Month)
+ returnNums(Convert.ToDateTime(itemmodel.CompileDate).Day);
var count = Funs.DB.InApproveManager_EquipmentInItem.Where(x => SqlMethods.DateDiffDay(x.CompileDate, Convert.ToDateTime(itemmodel.CompileDate)) == 0
&& x.SizeCode != "").ToList().Count;
Ecode += returnNums(count + 1);
return Ecode;
}
else
{
Ecode += DateTime.Now.Year.ToString() + returnNums(DateTime.Now.Month) + returnNums(DateTime.Now.Day);
//获取当天的特种设备数量
var count = Funs.DB.InApproveManager_EquipmentInItem.Where(x => SqlMethods.DateDiffDay(x.CompileDate, DateTime.Now) == 0 && x.SizeCode != "").ToList().Count;
Ecode += returnNums(count + 1);
return Ecode;
}
}
else {
Ecode += DateTime.Now.Year.ToString() + returnNums(DateTime.Now.Month) + returnNums(DateTime.Now.Day);
//获取当天的特种设备数量
var count = Funs.DB.InApproveManager_EquipmentInItem.Where(x => SqlMethods.DateDiffDay(x.CompileDate, DateTime.Now) == 0 && x.SizeCode != "").ToList().Count;
Ecode += returnNums(count + 1);
return Ecode;
}
}
/// <summary>
/// 初始化下拉框
/// </summary>
private void InitDropDownList()
{
UnitService.InitUnitDropDownList(this.drpUnitId, this.ProjectId, true);
UnitService.InitUnitDropDownList(this.droUseUnitId, this.ProjectId, true);
// UnitService.InitUnitByProjectIdUnitTypeDropDownList(this.drpUnitId, this.ProjectId, Const.ProjectUnitType_2, true);
// this.drpUnitId.Enabled = false;
}
#endregion
#region
/// <summary>
/// 保存按钮
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnSave_Click(object sender, EventArgs e)
{
if (this.drpUnitId.SelectedValue == BLL.Const._Null)
{
Alert.ShowInTop("请选择单位名称!", MessageBoxIcon.Warning);
return;
}
if (this.drpSpecialEquipmentId.SelectedValue == BLL.Const._Null)
{
Alert.ShowInTop("请选择设备!", MessageBoxIcon.Warning);
return;
}
if (this.droUseUnitId.SelectedValue == BLL.Const._Null)
{
Alert.ShowInTop("请选择使用单位!", MessageBoxIcon.Warning);
return;
}
if (this.dropDetectionStatus.SelectedValue == BLL.Const._Null)
{
Alert.ShowInTop("请选择检测状态!", MessageBoxIcon.Warning);
return;
}
SaveEquipmentInData();
SaveData();
PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference());
}
private void SaveEquipmentInData()
{
Model.InApproveManager_EquipmentIn equipmentIn = new Model.InApproveManager_EquipmentIn
{
ProjectId = this.ProjectId,
EquipmentInCode = this.txtEquipmentInCode.Text.Trim()
};
if (this.drpUnitId.SelectedValue != BLL.Const._Null)
{
equipmentIn.UnitId = this.drpUnitId.SelectedValue;
}
if (this.droUseUnitId.SelectedValue != BLL.Const._Null)
{
equipmentIn.UseUnitId = this.droUseUnitId.SelectedValue;
}
equipmentIn.State = BLL.Const.State_2;
equipmentIn.CompileMan = this.CurrUser.UserId;
equipmentIn.CompileDate = DateTime.Now;
if (!string.IsNullOrEmpty(this.EquipmentInId))
{
equipmentIn.EquipmentInId = this.EquipmentInId;
BLL.EquipmentInService.UpdateEquipmentIn(equipmentIn);
BLL.LogService.AddSys_Log(this.CurrUser, equipmentIn.EquipmentInCode, equipmentIn.EquipmentInId, BLL.Const.EquipmentInMenuId, BLL.Const.BtnModify);
}
else
{
this.EquipmentInId = SQLHelper.GetNewID(typeof(Model.InApproveManager_EquipmentIn));
equipmentIn.EquipmentInId = this.EquipmentInId;
BLL.EquipmentInService.AddEquipmentIn(equipmentIn);
BLL.LogService.AddSys_Log(this.CurrUser, equipmentIn.EquipmentInCode, equipmentIn.EquipmentInId, BLL.Const.EquipmentInMenuId, BLL.Const.BtnAdd);
}
// Project_HSSEData_HSSEService.StatisticalData(this.CurrUser.LoginProjectId, Project_HSSEData_HSSEService.HSSEDateType.ConstructionEquipment);
}
void SaveData()
{
Model.InApproveManager_EquipmentInItem equipmentInItem = new Model.InApproveManager_EquipmentInItem
{
EquipmentInId = this.EquipmentInId
};
if (this.drpSpecialEquipmentId.SelectedValue != BLL.Const._Null)
{
equipmentInItem.SpecialEquipmentId = this.drpSpecialEquipmentId.SelectedValue;
}
else
{
Alert.ShowInTop("请选择设备", MessageBoxIcon.Warning);
return;
}
equipmentInItem.SizeModel = this.txtSizeModel.Text.Trim();
equipmentInItem.OwnerCheck = this.txtOwnerCheck.Text.Trim();
//自动生成编码
if (string.IsNullOrEmpty(this.txtSizeCode.Text))
{
equipmentInItem.SizeCode = ReturnEqCode();
}
else
{
equipmentInItem.SizeCode = this.txtSizeCode.Text;
}
equipmentInItem.DetectionStatus = dropDetectionStatus.SelectedValue;
equipmentInItem.CheckDate = txtCheckDate.SelectedDate.ToString();
equipmentInItem.InspectionCycle = txtInspectionCycle.Text;
equipmentInItem.ValidityDateOfInspection = Convert.ToDateTime(txtValidityDateOfInspection.Text);
equipmentInItem.UseRegDate = txtUseRegDate.SelectedDate.ToString();
equipmentInItem.UseRegDepart = txtUseRegDepart.Text;
equipmentInItem.InDate = txtInDate.SelectedDate.ToString();
equipmentInItem.OutDate = txtOutDate.SelectedDate.ToString();
equipmentInItem.OperatorName = txtOperatorName.Text;
equipmentInItem.SpecialCertificateNumber = txtSpecialCertificateNumber.Text;
equipmentInItem.Remark = txtRemark.Text;
equipmentInItem.IsUsed = Convert.ToBoolean(this.cbIsUsed.Checked);
equipmentInItem.ProDate = dpProDate.SelectedDate;
//equipmentInItem.CompileMan = CurrUser.UserId;
equipmentInItem.CompileDate = DateTime.Now;
if (!string.IsNullOrEmpty(this.EquipmentInItemId))
{
equipmentInItem.EquipmentInItemId = this.EquipmentInItemId;
BLL.EquipmentInItemService.UpdateEquipmentInItem(equipmentInItem);
}
else
{
this.EquipmentInItemId = SQLHelper.GetNewID(typeof(Model.InApproveManager_EquipmentInItem));
equipmentInItem.EquipmentInItemId = this.EquipmentInItemId;
BLL.EquipmentInItemService.AddEquipmentInItem(equipmentInItem);
}
// Project_HSSEData_HSSEService.StatisticalData(this.CurrUser.LoginProjectId, Project_HSSEData_HSSEService.HSSEDateType.ConstructionEquipment);
}
#endregion
#region
/// <summary>
/// 上传附件检测报告
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnAttachUrl_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(this.EquipmentInItemId))
{
this.SaveData();
}
PageContext.RegisterStartupScript(WindowAtt.GetShowReference(String.Format("~/AttachFile/webuploader.aspx?toKeyId={0}&path=FileUpload/EquipmentInAttachUrl&menuId={1}", this.EquipmentInId+"_Item", BLL.Const.EquipmentInMenuId)));
}
/// <summary>
/// 上传附件登记证书
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnAttachUrl2_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(this.EquipmentInItemId))
{
this.SaveData();
}
PageContext.RegisterStartupScript(WindowAtt.GetShowReference(String.Format("~/AttachFile/webuploader.aspx?toKeyId={0}&path=FileUpload/EquipmentInAttachUrl&menuId={1}", this.EquipmentInId + "_Item_2", BLL.Const.EquipmentInMenuId)));
}
/// <summary>
/// 上传附件设备现场照片
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnAttachUrl3_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(this.EquipmentInItemId))
{
this.SaveData();
}
PageContext.RegisterStartupScript(WindowAtt.GetShowReference(String.Format("~/AttachFile/webuploader.aspx?toKeyId={0}&path=FileUpload/EquipmentInAttachUrl&menuId={1}", this.EquipmentInId + "_Item_3", BLL.Const.EquipmentInMenuId)));
}
/// <summary>
/// 上传附件设备档案
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnAttachUrl4_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(this.EquipmentInItemId))
{
this.SaveData();
}
PageContext.RegisterStartupScript(WindowAtt.GetShowReference(String.Format("~/AttachFile/webuploader.aspx?toKeyId={0}&path=FileUpload/EquipmentInAttachUrl&menuId={1}", this.EquipmentInId + "_Item_4", BLL.Const.EquipmentInMenuId)));
}
#endregion
#region
protected void btnEcheck_Click(object sender, EventArgs e) {
PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("~/Customization/CNCCG/HSSE/InApproveManager/EquipmentCheck.aspx?EquipmentInItemId={0}&rbStates=0",
this.EquipmentInItemId), "日常检查"));
}
protected void btnEhazard_Click(object sender, EventArgs e)
{
PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("~/Customization/CNCCG/HSSE/InApproveManager/EquipmentCheck.aspx?EquipmentInItemId={0}&rbStates=1",
this.EquipmentInItemId), "定期检查"));
}
#endregion
protected void cbIsUsed_CheckedChanged(object sender, CheckedEventArgs e)
{
if (cbIsUsed.Checked==true)
{
txtOutDate.SelectedDate = null;
txtOutDate.Enabled = false;
}
else
{
txtOutDate.Enabled = true ;
}
}
}
}