ZHJA_HJGL/HJGL_ZH/FineUIPro.Web/WeldMat/UsingPlan/UsingPlanEdit.aspx.cs

701 lines
29 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using BLL;
namespace FineUIPro.Web.WeldMat.UsingPlan
{
public partial class UsingPlanEdit : PageBase
{
#region
/// <summary>
/// 主键
/// </summary>
private string UsingPlanId
{
get
{
return (string)ViewState["UsingPlanId"];
}
set
{
ViewState["UsingPlanId"] = value;
}
}
#endregion
#region
/// <summary>
/// 加载页面
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
this.btnClose.OnClientClick = ActiveWindow.GetHideReference();
this.drpProjectId.DataValueField = "ProjectId";
this.drpProjectId.DataTextField = "ProjectCode";
this.drpProjectId.DataSource = BLL.Base_ProjectService.GetOnProjectListByUserId(this.CurrUser.UserId, "1");
this.drpProjectId.DataBind();
Funs.FineUIPleaseSelect(this.drpProjectId);
this.drpOrderTime.DataTextField = "Text";
this.drpOrderTime.DataValueField = "Value";
this.drpOrderTime.DataSource = BLL.DropListService.OrderTimeList();
this.drpOrderTime.DataBind();
Funs.FineUIPleaseSelect(this.drpOrderTime);
///材质
this.drpSheet.DataTextField = "STE_Code";
this.drpSheet.DataValueField = "STE_ID";
this.drpSheet.DataSource = BLL.HJGL_MaterialService.GetSteelList();
this.drpSheet.DataBind();
Funs.FineUIPleaseSelect(this.drpSheet);
this.drpTeamGroup.Items.Clear();
Funs.FineUIPleaseSelect(this.drpTeamGroup);
this.drpUsePosition.Items.Clear();
Funs.FineUIPleaseSelect(this.drpUsePosition);
this.txtOrderDate.MinDate = DateTime.Now;
this.UsingPlanId = Request.Params["UsingPlanId"];
if (!string.IsNullOrEmpty(this.UsingPlanId))
{
Model.Weld_UsingPlan usingPlan = BLL.UsingPlanService.GetUsingPlanById(this.UsingPlanId);
if (usingPlan != null)
{
if (!string.IsNullOrEmpty(usingPlan.WeldId))
{
this.hdWeldId.Text = usingPlan.WeldId;
var weld = BLL.WeldInfoService.GetWeldInfoById(usingPlan.WeldId);
if (weld != null)
{
this.txtWeldName.Text = weld.WeldName;
this.txtWeldSpec.Text = weld.WeldSpec;
txtWeldCode.Text = weld.WeldCode;
}
if (!string.IsNullOrEmpty(usingPlan.ProjectId))
{
this.drpProjectId.SelectedValue = usingPlan.ProjectId;
var position = from x in Funs.DB.View_UsePosition
where x.ProjectId == usingPlan.ProjectId
select x;
if (position.Count() > 0)
{
this.drpUsePosition.Items.Clear();
this.drpUsePosition.DataValueField = "UsePosition";
this.drpUsePosition.DataTextField = "UsePosition";
this.drpUsePosition.DataSource = position;
this.drpUsePosition.DataBind();
Funs.FineUIPleaseSelect(this.drpUsePosition);
if (!string.IsNullOrEmpty(usingPlan.UsePosition))
{
this.drpUsePosition.SelectedValue = usingPlan.UsePosition;
}
}
else
{
this.drpUsePosition.Items.Clear();
Funs.FineUIPleaseSelect(this.drpUsePosition);
}
var unit = BLL.Base_UnitService.GetUnitCodeByProjectIdList(usingPlan.ProjectId);
if (unit.Count() > 0)
{
this.drpUsingUnit.Items.Clear();
this.drpUsingUnit.DataValueField = "UnitId";
this.drpUsingUnit.DataTextField = "UnitName";
this.drpUsingUnit.DataSource = unit;
this.drpUsingUnit.DataBind();
Funs.FineUIPleaseSelect(this.drpUsingUnit);
if (!string.IsNullOrEmpty(usingPlan.UsingUnit))
{
this.drpUsingUnit.SelectedValue = usingPlan.UsingUnit;
}
this.drpTeamGroup.Items.Clear();
this.drpTeamGroup.DataValueField = "TeamGroupId";
this.drpTeamGroup.DataTextField = "TeamGroupName";
this.drpTeamGroup.DataSource = BLL.Base_TeamGroupService.GetTeamGroupByUnit(usingPlan.ProjectId, usingPlan.UsingUnit);
this.drpTeamGroup.DataBind();
Funs.FineUIPleaseSelect(this.drpTeamGroup);
if (!string.IsNullOrEmpty(usingPlan.TeamGroupId))
{
this.drpTeamGroup.SelectedValue = usingPlan.TeamGroupId;
}
}
else
{
this.drpUsingUnit.Items.Clear();
Funs.FineUIPleaseSelect(this.drpUsingUnit);
}
}
if (usingPlan.Amount.HasValue)
{
this.txtAmount.Text = usingPlan.Amount.ToString();
}
if (usingPlan.InPutDate.HasValue)
{
this.txtInPutDate.Text = string.Format("{0:yyyy-MM-dd}", usingPlan.InPutDate);
}
if (usingPlan.OrderDate.HasValue)
{
this.txtOrderDate.Text = string.Format("{0:yyyy-MM-dd}", usingPlan.OrderDate);
}
if (!string.IsNullOrEmpty(usingPlan.OrderTime))
{
this.drpOrderTime.SelectedValue = usingPlan.OrderTime;
}
if (usingPlan.CancelDate.HasValue)
{
this.txtCancelDate.Text = string.Format("{0:yyyy-MM-dd}", usingPlan.CancelDate);
}
if (usingPlan.IsSteelStru == true)
{
drpIsSteelStru.SelectedValue = "1";
}
else
{
drpIsSteelStru.SelectedValue = "0";
}
txtCancelResult.Text = usingPlan.CancelResult;
this.rblIsCancel.SelectedValue = (usingPlan.IsCancel == true ? "true" : "false");
if (!string.IsNullOrEmpty(usingPlan.UsingManOne))
{
this.hdUsingMan1.Text = usingPlan.UsingManOne;
var welder = BLL.HJGL_PersonManageService.GetWelderByWenId(usingPlan.UsingManOne);
if (welder != null)
{
this.txtUsingManOne.Text = welder.WED_Name;
}
}
if (!string.IsNullOrEmpty(usingPlan.STE_ID))
{
drpSheet.SelectedValueArray = usingPlan.STE_ID.Split(',');
}
}
}
}
else
{
this.txtInPutDate.Text = string.Format("{0:yyyy-MM-dd}", DateTime.Now);
this.txtOrderDate.Text = string.Format("{0:yyyy-MM-dd}", DateTime.Now);
}
}
}
#endregion
#region
/// <summary>
/// 保存按钮
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnSave_Click(object sender, EventArgs e)
{
SaveData(false);
}
protected void btnSubmit_Click(object sender, EventArgs e)
{
SaveData(true);
}
/// <summary>
/// 保存数据
/// </summary>
private void SaveData(bool? isSubmit)
{
if (string.IsNullOrEmpty(this.hdWeldId.Text.Trim()))
{
Alert.ShowInTop("请选择焊材牌号!", MessageBoxIcon.Warning);
return;
}
if (this.drpProjectId.SelectedValue == BLL.Const._Null)
{
Alert.ShowInTop("请选择施工号!", MessageBoxIcon.Warning);
return;
}
if (this.drpUsePosition.SelectedValue == BLL.Const._Null && drpUsePosition.Text=="")
{
Alert.ShowInTop("请选择使用位置!", MessageBoxIcon.Warning);
return;
}
if (this.drpUsingUnit.SelectedValue == BLL.Const._Null)
{
Alert.ShowInTop("请选择使用单位!", MessageBoxIcon.Warning);
return;
}
if (this.drpTeamGroup.SelectedValue == BLL.Const._Null)
{
Alert.ShowInTop("请选择焊工班组!", MessageBoxIcon.Warning);
return;
}
if (string.IsNullOrEmpty(this.hdUsingMan1.Text.Trim()))
{
Alert.ShowInTop("请选择领料人!", MessageBoxIcon.Warning);
return;
}
if (this.drpSheet.SelectedValue == BLL.Const._Null)
{
Alert.ShowInTop("请选择焊件材质!", MessageBoxIcon.Warning);
return;
}
if (drpOrderTime.SelectedValue == Const._Null)
{
Alert.ShowInTop("请选择预约时间!", MessageBoxIcon.Warning);
return;
}
if (!string.IsNullOrEmpty(this.UsingPlanId))
{
var plan = BLL.UsingPlanService.GetUsingPlanById(this.UsingPlanId);
if (plan.IsFinish == true)
{
Alert.ShowInTop("该计划已完成,不能修改!", MessageBoxIcon.Warning);
return;
}
}
var weld = BLL.WeldInfoService.GetWeldInfoById(this.hdWeldId.Text.Trim());
if (weld != null)
{
var weldtype = BLL.WeldTypeService.GetWeldTypeById(weld.WeldTypeId);
var welder = BLL.HJGL_PersonManageService.GetWelderByWenId(hdUsingMan1.Text.Trim());
if (welder.MaxHanTiao != null && welder.MaxHanTiao != null)
{
if (!string.IsNullOrEmpty(this.txtAmount.Text.Trim()))
{
if (weldtype.WeldTypeName.Contains("焊条"))
{
if (Funs.GetNewDecimal(this.txtAmount.Text.Trim()) > welder.MaxHanTiao)
{
Alert.ShowInTop("超过该焊工的最大领用数量,请重新录入计划领用数量!", MessageBoxIcon.Warning);
return;
}
}
if (weldtype.WeldTypeName.Contains("焊丝"))
{
if (Funs.GetNewDecimal(this.txtAmount.Text.Trim()) > welder.MaxWeldingWire)
{
Alert.ShowInTop("超过该焊工的最大领用数量,请重新录入计划领用数量!", MessageBoxIcon.Warning);
return;
}
}
}
}
else if (!string.IsNullOrEmpty(weld.WeldSpec))
{
var spec = from x in Funs.DB.Weld_Specifications where x.Specifications == weld.WeldSpec && x.WeldTypeId == weld.WeldTypeId select x;
if (spec.Count() > 0)
{
if (!string.IsNullOrEmpty(this.txtAmount.Text.Trim()))
{
if (Funs.GetNewDecimal(this.txtAmount.Text.Trim()) > spec.First().MaxUsingNum)
{
Alert.ShowInTop("超过最大领用数量,请重新录入计划领用数量!", MessageBoxIcon.Warning);
return;
}
}
}
}
}
Model.Weld_UsingPlan usingPlan = new Model.Weld_UsingPlan();
if (!string.IsNullOrEmpty(this.hdWeldId.Text.Trim()))
{
usingPlan.WeldId = this.hdWeldId.Text.Trim();
}
if (this.drpProjectId.SelectedValue != BLL.Const._Null)
{
usingPlan.ProjectId = this.drpProjectId.SelectedValue;
}
if (drpUsePosition.SelectedValue!=null && drpUsePosition.SelectedValue != BLL.Const._Null )
{
usingPlan.UsePosition = this.drpUsePosition.SelectedValue;
}
else
{
if (drpUsePosition.Text != "")
{
usingPlan.UsePosition = drpUsePosition.Text.Trim();
}
}
if (this.drpUsingUnit.SelectedValue != BLL.Const._Null)
{
usingPlan.UsingUnit = this.drpUsingUnit.SelectedValue;
}
if (this.drpSheet.SelectedValue != BLL.Const._Null && this.drpSheet.SelectedValue != null)
{
List<string> texts = new List<string>();
List<string> values = new List<string>();
foreach (ListItem item in drpSheet.SelectedItemArray)
{
texts.Add(item.Text);
values.Add(item.Value);
}
usingPlan.STE_ID = String.Join(",", values);
usingPlan.STE_Name = String.Join(",", texts);
}
usingPlan.Amount = Funs.GetNewDecimal(this.txtAmount.Text.Trim());
if (!string.IsNullOrEmpty(this.hdUsingMan1.Text.Trim()))
{
usingPlan.UsingManOne = this.hdUsingMan1.Text.Trim();
}
usingPlan.InPutDate = Funs.GetNewDateTime(this.txtInPutDate.Text.Trim());
usingPlan.OrderDate = Funs.GetNewDateTime(this.txtOrderDate.Text.Trim());
if (this.drpOrderTime.SelectedValue != BLL.Const._Null)
{
usingPlan.OrderTime = this.drpOrderTime.SelectedValue;
}
if (this.drpTeamGroup.SelectedValue != BLL.Const._Null)
{
usingPlan.TeamGroupId = this.drpTeamGroup.SelectedValue;
}
usingPlan.CancelDate = Funs.GetNewDateTime(this.txtCancelDate.Text.Trim());
usingPlan.IsCancel = Convert.ToBoolean(this.rblIsCancel.SelectedValue);
usingPlan.CancelResult = this.txtCancelResult.Text.Trim();
usingPlan.IsSubmit = isSubmit;
usingPlan.InPutMan = CurrUser.UserId;
if (drpIsSteelStru.SelectedValue == "1")
{
usingPlan.IsSteelStru = true;
}
else
{
usingPlan.IsSteelStru = false;
}
var weldInfo = BLL.WeldInfoService.GetWeldInfoById(this.hdWeldId.Text.Trim());
if (WelderQueIsPass(this.hdUsingMan1.Text.Trim(), weldInfo.SteelType, usingPlan.IsSteelStru))
{
if (!string.IsNullOrEmpty(this.UsingPlanId))
{
var q = BLL.UsingPlanService.GetUsingPlanById(this.UsingPlanId);
usingPlan.UsingPlanId = this.UsingPlanId;
BLL.UsingPlanService.UpdateUsingPlan(usingPlan);
BLL.Sys_LogService.AddLog(Const.System_7, this.CurrUser.LoginProjectId, this.CurrUser.UserId, "修改领料计划录入");
PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference());
}
else
{
this.UsingPlanId = SQLHelper.GetNewID(typeof(Model.Weld_UsingPlan));
usingPlan.UsingPlanId = this.UsingPlanId;
BLL.UsingPlanService.AddUsingPlan(usingPlan);
BLL.Sys_LogService.AddLog(Const.System_7, this.CurrUser.LoginProjectId, this.CurrUser.UserId, "添加领料计划录入");
this.UsingPlanId = string.Empty;
this.txtAmount.Text = string.Empty;
this.txtWeldName.Text = string.Empty;
this.txtWeldSpec.Text = string.Empty;
}
#region 2 ()
// 在时间段内焊丝和焊条各一条超过2条需加个确认
//List<Model.Weld_UsingPlan> welderUsingPlan = BLL.UsingPlanService.GetWelderCurTimePlan(this.hdUsingMan1.Text.Trim(), usingPlan.OrderDate,this.drpOrderTime.SelectedValue);
//if (welderUsingPlan != null && welderUsingPlan.Count() > 2)
//{
// // 超过两条还未确认的记录
// var noConfirm = welderUsingPlan.Where(x => x.IsNeedConfirm == null);
// foreach (var q in noConfirm)
// {
// BLL.UsingPlanService.UpdateIsNeedConfirm(q.UsingPlanId, true);
// }
//}
//else
//{
// // 如修改时间段,则未超过两条,则不需要审核
// var noConfirm = welderUsingPlan.Where(x => x.IsNeedConfirm == true);
// foreach (var q in noConfirm)
// {
// BLL.UsingPlanService.UpdateIsNeedConfirm(q.UsingPlanId, null);
// }
//}
#endregion
if (isSubmit == true)
{
ShowNotify("提交成功!", MessageBoxIcon.Success);
}
else
{
ShowNotify("保存成功!", MessageBoxIcon.Success);
}
}
else
{
Alert.ShowInTop("焊工资质不符合!", MessageBoxIcon.Warning);
return;
}
}
#endregion
#region DropDownList下拉选择事件
/// <summary>
/// 是否作废选择事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void rblIsCancel_SelectedIndexChanged(object sender, EventArgs e)
{
if (this.rblIsCancel.SelectedValue == "true")
{
this.txtCancelDate.Text = string.Format("{0:yyyy-MM-dd}", DateTime.Now);
}
else
{
this.txtCancelDate.Text = string.Empty;
}
}
/// <summary>
/// 项目下拉选择事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void drpProjectId_OnSelectedIndexChanged(object sender, EventArgs e)
{
if (this.drpProjectId.SelectedValue != BLL.Const._Null)
{
var position = from x in Funs.DB.View_UsePosition
where x.ProjectId == drpProjectId.SelectedValue
select x;
//var pipe = from x in Funs.DB.HJGL_PW_IsoInfo
// join y in Funs.DB.Base_Unit on x.BSU_ID equals y.UnitId
// where x.ProjectId == drpProjectId.SelectedValue orderby y.UnitName, x.ISO_IsoNo
// select new { x.ISO_ID,x.ISO_IsoNo,y.UnitName };
if (position.Count() > 0)
{
this.drpUsePosition.Items.Clear();
this.drpUsePosition.DataValueField = "UsePosition";
this.drpUsePosition.DataTextField = "UsePosition";
this.drpUsePosition.DataSource = position;
this.drpUsePosition.DataBind();
Funs.FineUIPleaseSelect(this.drpUsePosition);
}
else
{
this.drpUsePosition.Items.Clear();
Funs.FineUIPleaseSelect(this.drpUsePosition);
}
var unit = BLL.Base_UnitService.GetUnitCodeByProjectIdList(drpProjectId.SelectedValue);
if (unit.Count() > 0)
{
this.drpUsingUnit.Items.Clear();
this.drpUsingUnit.DataValueField = "UnitId";
this.drpUsingUnit.DataTextField = "UnitName";
this.drpUsingUnit.DataSource = unit;
this.drpUsingUnit.DataBind();
Funs.FineUIPleaseSelect(this.drpUsingUnit);
}
else
{
this.drpUsingUnit.Items.Clear();
Funs.FineUIPleaseSelect(this.drpUsingUnit);
}
}
else
{
this.drpUsePosition.Items.Clear();
Funs.FineUIPleaseSelect(this.drpUsePosition);
this.drpUsingUnit.Items.Clear();
Funs.FineUIPleaseSelect(this.drpUsingUnit);
}
}
protected void drpUsingUnit_OnSelectedIndexChanged(object sender, EventArgs e)
{
if (this.drpUsingUnit.SelectedValue != BLL.Const._Null)
{
this.drpTeamGroup.Items.Clear();
this.drpTeamGroup.DataValueField = "TeamGroupId";
this.drpTeamGroup.DataTextField = "TeamGroupName";
this.drpTeamGroup.DataSource = BLL.Base_TeamGroupService.GetTeamGroupByUnit(drpProjectId.SelectedValue, drpUsingUnit.SelectedValue);
this.drpTeamGroup.DataBind();
Funs.FineUIPleaseSelect(this.drpTeamGroup);
}
else
{
this.drpTeamGroup.Items.Clear();
Funs.FineUIPleaseSelect(this.drpTeamGroup);
}
}
#endregion
#region
/// <summary>
/// 查找焊材信息
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnSelect_Click(object sender, EventArgs e)
{
string window = String.Format("ShowPlanWeld.aspx?projectId={0}", drpProjectId.SelectedValue, "编辑 - ");
PageContext.RegisterStartupScript(Window1.GetSaveStateReference(this.hdWeldId.ClientID) + Window1.GetShowReference(window));
}
#region
/// <summary>
/// 弹出编辑窗体关闭事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Window1_Close(object sender, WindowCloseEventArgs e)
{
if (!string.IsNullOrEmpty(this.hdWeldId.Text))
{
var weld = BLL.WeldInfoService.GetWeldInfoById(this.hdWeldId.Text);
if (weld != null)
{
this.txtWeldName.Text = weld.WeldName;
this.txtWeldSpec.Text = weld.WeldSpec;
txtWeldCode.Text = weld.WeldCode;
}
else
{
this.txtWeldName.Text = string.Empty;
this.txtWeldSpec.Text = string.Empty;
txtWeldCode.Text = string.Empty;
}
}
else
{
this.txtWeldName.Text = string.Empty;
this.txtWeldSpec.Text = string.Empty;
txtWeldCode.Text = string.Empty;
}
}
#endregion
#endregion
#region
/// <summary>
/// 查找领料人
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnSelectUsingMan_Click(object sender, EventArgs e)
{
string window = String.Format("ShowUsingMan.aspx?projectId={0}", drpProjectId.SelectedValue, "编辑 - ");
PageContext.RegisterStartupScript(Window2.GetSaveStateReference(hdUsingMan1.ClientID) + Window2.GetShowReference(window));
}
/// <summary>
/// 关闭领料人
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Window2_Close(object sender, WindowCloseEventArgs e)
{
if (!string.IsNullOrEmpty(hdUsingMan1.Text))//第一领料人
{
var welder = BLL.HJGL_PersonManageService.GetWelderByWenId(hdUsingMan1.Text.Trim());
if (welder != null)
{
this.txtUsingManOne.Text = welder.WED_Name;
}
else
{
this.txtUsingManOne.Text = string.Empty;
}
}
else
{
this.txtUsingManOne.Text = string.Empty;
}
}
/// <summary>
/// 判断焊工资质是否合格
/// </summary>
/// <param name="welderId"></param>
/// <param name="steelType"></param>
/// <returns></returns>
private bool WelderQueIsPass(string welderId, string steelType, bool? isSteelStru)
{
bool isPass = false;
List<Model.HJGL_BS_WelderQualifiedProject> qualifys = new List<Model.HJGL_BS_WelderQualifiedProject>();
if (isSteelStru == true)
{
qualifys = (from x in Funs.DB.HJGL_BS_WelderQualifiedProject
where x.WED_ID == welderId && x.LimitDate >= DateTime.Now && x.MaterialType != null
select x).ToList();
}
else
{
qualifys = (from x in Funs.DB.HJGL_BS_WelderQualifiedProject
where x.WED_ID == welderId && x.LimitDate >= DateTime.Now && x.MaterialType != null
&& (x.IsSteelStru == false || x.IsSteelStru == null)
select x).ToList();
}
foreach (var q in qualifys)
{
if (q.MaterialType.Contains(steelType))
{
isPass = true;
break;
}
}
return isPass;
}
#endregion
protected void drpSheet_OnSelectedIndexChanged(object sender, EventArgs e)
{
if (drpSheet.SelectedValueArray.Length > 1)
{
drpSheet.Items[0].Selected = false;
}
if (drpSheet.SelectedValueArray.Length == 0)
{
drpSheet.Items[0].Selected = true;
}
}
#region
/// <summary>
/// 上传附件资源
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
//protected void btnAttachUrl_Click(object sender, EventArgs e)
//{
// string edit = "0"; // 表示能打开附件上传窗口,但不能上传附件
// if (this.drpProjectId.SelectedValue == Const._Null)
// {
// ShowNotify("请选择项目!");
// }
// else
// {
// PageContext.RegisterStartupScript(Window3.GetShowReference(String.Format("../../AttachFile/webuploader.aspx?toKeyId={0}&path=FileUpload/BaseInfo/Project&menuId={1}&edit={2}", this.drpProjectId.SelectedValue, Const.ProjectMenuId, edit)));
// }
//}
#endregion
}
}