429 lines
16 KiB
C#
429 lines
16 KiB
C#
using BLL;
|
|
using Model;
|
|
using Newtonsoft.Json.Linq;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
|
|
namespace FineUIPro.Web.CLGL
|
|
{
|
|
public partial class OutPlanMasterEdit : PageBase
|
|
{
|
|
/// <summary>
|
|
/// 单位工程主键
|
|
/// </summary>
|
|
public string UnitWorkId
|
|
{
|
|
get
|
|
{
|
|
return (string)ViewState["UnitWorkId"];
|
|
}
|
|
set
|
|
{
|
|
ViewState["UnitWorkId"] = value;
|
|
}
|
|
}
|
|
public string Id
|
|
{
|
|
get
|
|
{
|
|
return (string)ViewState["Id"];
|
|
}
|
|
set
|
|
{
|
|
ViewState["Id"] = value;
|
|
}
|
|
}
|
|
protected void Page_Load(object sender, EventArgs e)
|
|
{
|
|
if (!IsPostBack)
|
|
{
|
|
InitDrpList();
|
|
UnitWorkId = Request.Params["UnitWorkId"];
|
|
Id = Request.Params["Id"];
|
|
if (!string.IsNullOrEmpty(Id))
|
|
{
|
|
var queryModel = new Model.Tw_InOutMasterOutput()
|
|
{
|
|
Id = Id,
|
|
};
|
|
|
|
var result = BLL.TwInOutplanmasterService.GetListData(queryModel).FirstOrDefault();
|
|
if (!string.IsNullOrEmpty(result.WeldTaskId) && result.WeldTaskId.Contains("|"))
|
|
{
|
|
UnitWorkId = result.WeldTaskId.Split('|')[0];
|
|
|
|
}
|
|
else
|
|
{
|
|
UnitWorkId = result.WeldTaskId;
|
|
}
|
|
txtCreateMan.Text = result.CreateManName;
|
|
txtCreateDate.Text = result.CreateDate.Value.ToString("yyyy-MM-dd");
|
|
drpReqUnit.SelectedValue = result.ReqUnitId;
|
|
drpTypeInt.SelectedValue = result.TypeInt.ToString();
|
|
drpWarehouse.SelectedValue = result.WarehouseId;
|
|
drpTransferWarehouse.SelectedValue = result.TransferWarehouseId;
|
|
drpCategory.SelectedValue = result.Category.ToString();
|
|
txtRemark.Text = result.Remark;
|
|
txtCusBillCode.Text = result.CusBillCode;
|
|
|
|
drpCategory.Readonly = true;
|
|
BindGrid(Id);
|
|
}
|
|
else
|
|
{
|
|
txtCreateMan.Text = this.CurrUser.PersonName;
|
|
txtCreateDate.Text = DateTime.Now.ToString("yyyy-MM-dd");
|
|
drpReqUnit.SelectedValue = this.CurrUser.UnitId;
|
|
txtCusBillCode.Text = TwInOutplanmasterService.GetDataInCusBillCode(this.CurrUser.LoginProjectId, UnitService.GetUnitByUnitId(drpReqUnit.SelectedValue)?.UnitCode, drpTypeInt.SelectedText, UnitWorkService.getUnitWorkByUnitWorkId(UnitWorkId)?.UnitWorkCode, drpCategory.SelectedText);
|
|
}
|
|
|
|
drpTypeInt_SelectedIndexChanged(null, null);
|
|
}
|
|
|
|
}
|
|
private void InitDrpList()
|
|
{
|
|
|
|
drpWarehouse.DataTextField = "Key";
|
|
drpWarehouse.DataValueField = "Value";
|
|
drpWarehouse.DataSource = BLL.TwInOutplanmasterService.GetWarehouseCode(this.CurrUser.LoginProjectId);
|
|
drpWarehouse.DataBind();
|
|
|
|
drpTransferWarehouse.DataTextField = "Key";
|
|
drpTransferWarehouse.DataValueField = "Value";
|
|
drpTransferWarehouse.DataSource = BLL.TwInOutplanmasterService.GetWarehouseCode(this.CurrUser.LoginProjectId);
|
|
drpTransferWarehouse.DataBind();
|
|
Funs.FineUIPleaseSelect(drpTransferWarehouse);
|
|
|
|
string[] typeIntArr = { TwConst.TypeInt.散件出库.ToString(), TwConst.TypeInt.其他出库.ToString(), TwConst.TypeInt.调拨出库.ToString() };
|
|
drpTypeInt.DataTextField = "Key";
|
|
drpTypeInt.DataValueField = "Value";
|
|
drpTypeInt.DataSource = BLL.TwConst.TypeIntMap.Where(x => typeIntArr.Contains(x.Key));
|
|
drpTypeInt.DataBind();
|
|
UnitService.InitUnitDropDownList(drpReqUnit, this.CurrUser.LoginProjectId, true);
|
|
|
|
drpCategory.DataTextField = "Key";
|
|
drpCategory.DataValueField = "Value";
|
|
drpCategory.DataSource = BLL.TwConst.CategoryMap;
|
|
drpCategory.DataBind();
|
|
|
|
}
|
|
private void BindGrid(string inOutPlanMasterId)
|
|
{
|
|
if (drpTypeInt.SelectedValue == ((int)TwConst.TypeInt.散件出库).ToString())
|
|
{
|
|
var queryRelationModel = new Tw_InOutPlanDetail_Relation();
|
|
queryRelationModel.InOutPlanMasterId = Id;
|
|
var tb = TwInoutplandetailRelationService.GetListData(queryRelationModel, Grid1);
|
|
Grid1.DataSource = tb;
|
|
Grid1.DataBind();
|
|
}
|
|
else
|
|
{
|
|
var queryRelationModel = new Tw_InOutDetailOutput();
|
|
queryRelationModel.InOutPlanMasterId = Id;
|
|
var tb = TwInOutplandetailService.GetListData(queryRelationModel, Grid2);
|
|
Grid2.DataSource = tb;
|
|
Grid2.DataBind();
|
|
}
|
|
|
|
|
|
}
|
|
#region 选择按钮
|
|
/// <summary>
|
|
/// 选择按钮
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
protected void btnSelect_Click(object sender, EventArgs e)
|
|
{
|
|
if (!Save(Const.BtnSave)) return;
|
|
PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("OutPlanMasterSelect.aspx?UnitWorkId={0}&Id={1}", UnitWorkId, Id, "选择- ")));
|
|
|
|
}
|
|
protected void btnSelectStock_Click(object sender, EventArgs e)
|
|
{
|
|
if (!Save(Const.BtnSave)) return;
|
|
PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("OutPlanMasterSelectStock.aspx?UnitWorkId={0}&Id={1}", UnitWorkId, Id, "选择- ")));
|
|
|
|
}
|
|
protected void btnImportStock_Click(object sender, EventArgs e)
|
|
{
|
|
if (!Save(Const.BtnSave)) return;
|
|
PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("OutPlanMasterDetailImport.aspx?Id={0}", Id, "导入- ")));
|
|
|
|
}
|
|
#endregion
|
|
|
|
protected void btnSave_Click(object sender, EventArgs e)
|
|
{
|
|
if (Save(Const.BtnSave))
|
|
{
|
|
ShowNotify("保存成功!", MessageBoxIcon.Success);
|
|
}
|
|
}
|
|
|
|
protected void btnSubmit_Click(object sender, EventArgs e)
|
|
{
|
|
if (IsTransferType())
|
|
{
|
|
Tw_InOutPlanMaster currentModel = string.IsNullOrEmpty(Id) ? null : TwInOutplanmasterService.GetById(Id);
|
|
// 重复提交旧页面时直接查询配对结果,避免先保存而把已提交申请重置为待提交。
|
|
if (currentModel == null || currentModel.State == (int)TwConst.State.待提交)
|
|
{
|
|
if (!Save(Const.BtnSave)) return;
|
|
}
|
|
ResponeData result = TwInOutplanmasterService.SubmitTransferPlan(Id, drpTransferWarehouse.SelectedValue, GetDetailPlanNums());
|
|
if (result.code == 0)
|
|
{
|
|
Alert.ShowInTop(result.message, MessageBoxIcon.Warning);
|
|
return;
|
|
}
|
|
ShowNotify(result.message, MessageBoxIcon.Success);
|
|
}
|
|
else
|
|
{
|
|
if (!Save(Const.BtnSubmit)) return;
|
|
ShowNotify("提交成功!", MessageBoxIcon.Success);
|
|
}
|
|
PageContext.RegisterStartupScript(ActiveWindow.GetHideRefreshReference());
|
|
}
|
|
|
|
private bool Save(string type)
|
|
{
|
|
if (!ValidateMaster()) return false;
|
|
|
|
Tw_InOutPlanMaster currentModel = string.IsNullOrEmpty(Id) ? null : TwInOutplanmasterService.GetById(Id);
|
|
if (currentModel != null && !string.IsNullOrEmpty(currentModel.TransferBatchId) &&
|
|
currentModel.State != (int)TwConst.State.待提交)
|
|
{
|
|
Alert.ShowInTop("已提交的调拨申请不允许修改!", MessageBoxIcon.Warning);
|
|
return false;
|
|
}
|
|
|
|
int state = (int)TwConst.State.待提交;
|
|
switch (type)
|
|
{
|
|
case Const.BtnSave:
|
|
state = (int)TwConst.State.待提交;
|
|
break;
|
|
case Const.BtnSubmit:
|
|
state = (int)TwConst.State.待审核;
|
|
break;
|
|
}
|
|
|
|
if (string.IsNullOrEmpty(Id))
|
|
{
|
|
Id = Guid.NewGuid().ToString();
|
|
var model = new Tw_InOutPlanMaster()
|
|
{
|
|
Id = Id,
|
|
ProjectId = this.CurrUser.LoginProjectId,
|
|
CusBillCode = txtCusBillCode.Text,
|
|
WarehouseId = drpWarehouse.SelectedValue,
|
|
WarehouseCode = drpWarehouse.SelectedText,
|
|
WeldTaskId = UnitWorkId,
|
|
Source = 1,
|
|
CreateDate = DateTime.Now,
|
|
CreateMan = this.CurrUser.PersonId,
|
|
ReqUnitId = drpReqUnit.SelectedValue,
|
|
TypeInt = int.Parse(drpTypeInt.SelectedValue),
|
|
Remark = txtRemark.Text,
|
|
InOutType = (int)TwConst.InOutType.出库,
|
|
Category = int.Parse(drpCategory.SelectedValue),
|
|
State = state
|
|
};
|
|
SetTransferFields(model);
|
|
TwInOutplanmasterService.Add(model);
|
|
}
|
|
else
|
|
{
|
|
var model = currentModel;
|
|
model.CusBillCode = txtCusBillCode.Text;
|
|
model.WarehouseId = drpWarehouse.SelectedValue;
|
|
model.WarehouseCode = drpWarehouse.SelectedText;
|
|
// model.WeldTaskId = UnitWorkId;
|
|
model.Source = 1;
|
|
model.CreateDate = DateTime.Now;
|
|
model.CreateMan = this.CurrUser.PersonId;
|
|
model.ReqUnitId = drpReqUnit.SelectedValue;
|
|
model.TypeInt = int.Parse(drpTypeInt.SelectedValue);
|
|
model.Remark = txtRemark.Text;
|
|
model.InOutType = (int)TwConst.InOutType.出库;
|
|
model.Category = int.Parse(drpCategory.SelectedValue);
|
|
model.State = state;
|
|
SetTransferFields(model);
|
|
TwInOutplanmasterService.Update(model);
|
|
}
|
|
if (drpTypeInt.SelectedValue == ((int)TwConst.TypeInt.散件出库).ToString())
|
|
{
|
|
SaveDetail_Relation();
|
|
|
|
}
|
|
else
|
|
{
|
|
SaveDetail();
|
|
}
|
|
return true;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 调拨草稿保存对方仓库和稳定批次,切换为普通出库时清空调拨字段。
|
|
/// </summary>
|
|
private void SetTransferFields(Tw_InOutPlanMaster model)
|
|
{
|
|
if (IsTransferType())
|
|
{
|
|
model.TransferWarehouseId = drpTransferWarehouse.SelectedValue;
|
|
if (string.IsNullOrEmpty(model.TransferBatchId))
|
|
{
|
|
model.TransferBatchId = Guid.NewGuid().ToString();
|
|
}
|
|
}
|
|
else
|
|
{
|
|
model.TransferWarehouseId = null;
|
|
model.TransferBatchId = null;
|
|
}
|
|
}
|
|
|
|
private bool ValidateMaster()
|
|
{
|
|
if (string.IsNullOrEmpty(drpWarehouse.SelectedValue) || drpWarehouse.SelectedValue == Const._Null)
|
|
{
|
|
Alert.ShowInTop("请选择仓库!", MessageBoxIcon.Warning);
|
|
return false;
|
|
}
|
|
if (IsTransferType())
|
|
{
|
|
if (string.IsNullOrEmpty(drpTransferWarehouse.SelectedValue) || drpTransferWarehouse.SelectedValue == Const._Null)
|
|
{
|
|
Alert.ShowInTop("请选择调入仓库!", MessageBoxIcon.Warning);
|
|
return false;
|
|
}
|
|
if (drpTransferWarehouse.SelectedValue == drpWarehouse.SelectedValue)
|
|
{
|
|
Alert.ShowInTop("调出仓库和调入仓库不能相同!", MessageBoxIcon.Warning);
|
|
return false;
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
|
|
private bool IsTransferType()
|
|
{
|
|
return drpTypeInt.SelectedValue == ((int)TwConst.TypeInt.调拨出库).ToString();
|
|
}
|
|
|
|
private IDictionary<string, decimal> GetDetailPlanNums()
|
|
{
|
|
Dictionary<string, decimal> result = new Dictionary<string, decimal>();
|
|
foreach (JObject row in Grid2.GetMergedData())
|
|
{
|
|
JObject values = row.Value<JObject>("values");
|
|
result[row.Value<string>("id")] = values.Value<decimal>("PlanNum");
|
|
}
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 保存明细项
|
|
/// </summary>
|
|
private void SaveDetail_Relation()
|
|
{
|
|
|
|
//根据列表中的明细项添加
|
|
List<Model.Tw_InOutPlanDetail_Relation> detailLists = new List<Model.Tw_InOutPlanDetail_Relation>();
|
|
JArray teamGroupData = Grid1.GetMergedData();
|
|
foreach (JObject teamGroupRow in teamGroupData)
|
|
{
|
|
JObject values = teamGroupRow.Value<JObject>("values");
|
|
int rowIndex = teamGroupRow.Value<int>("index");
|
|
string id = teamGroupRow.Value<string>("id");
|
|
|
|
var mdoel = TwInoutplandetailRelationService.GetById(id);
|
|
if (mdoel != null)
|
|
{
|
|
mdoel.Number = values.Value<decimal>("Number");
|
|
}
|
|
TwInoutplandetailRelationService.Update(mdoel);
|
|
}
|
|
TwInOutplandetailService.GenInOutPlanDetailByInoutPlanMasterId(Id);
|
|
|
|
}
|
|
private void SaveDetail()
|
|
{
|
|
|
|
//根据列表中的明细项添加
|
|
List<Model.Tw_InOutPlanDetail> detailLists = new List<Model.Tw_InOutPlanDetail>();
|
|
JArray teamGroupData = Grid2.GetMergedData();
|
|
foreach (JObject teamGroupRow in teamGroupData)
|
|
{
|
|
JObject values = teamGroupRow.Value<JObject>("values");
|
|
int rowIndex = teamGroupRow.Value<int>("index");
|
|
string id = teamGroupRow.Value<string>("id");
|
|
|
|
var mdoel = TwInOutplandetailService.GetById(id);
|
|
if (mdoel != null)
|
|
{
|
|
mdoel.PlanNum = values.Value<decimal>("PlanNum");
|
|
}
|
|
TwInOutplandetailService.Update(mdoel);
|
|
}
|
|
|
|
}
|
|
protected void Grid1_RowCommand(object sender, GridCommandEventArgs e)
|
|
{
|
|
if (e.CommandName == "delete")
|
|
{
|
|
string id = e.RowID;
|
|
TwInoutplandetailRelationService.DeleteById(id);
|
|
TwInOutplandetailService.GenInOutPlanDetailByInoutPlanMasterId(Id);
|
|
BindGrid(Id);
|
|
}
|
|
}
|
|
protected void Grid2_RowCommand(object sender, GridCommandEventArgs e)
|
|
{
|
|
if (e.CommandName == "delete")
|
|
{
|
|
string id = e.RowID;
|
|
TwInOutplandetailService.DeleteById(id);
|
|
BindGrid(Id);
|
|
}
|
|
}
|
|
protected void Window1_Close(object sender, WindowCloseEventArgs e)
|
|
{
|
|
BindGrid(Id);
|
|
}
|
|
|
|
protected void drpTypeInt_SelectedIndexChanged(object sender, EventArgs e)
|
|
{
|
|
if (string.IsNullOrEmpty(Id))
|
|
{
|
|
txtCusBillCode.Text = TwInOutplanmasterService.GetDataInCusBillCode(this.CurrUser.LoginProjectId, UnitService.GetUnitByUnitId(drpReqUnit.SelectedValue)?.UnitCode, drpTypeInt.SelectedText, UnitWorkService.getUnitWorkByUnitWorkId(UnitWorkId)?.UnitWorkCode, drpCategory.SelectedText);
|
|
}
|
|
if (drpTypeInt.SelectedValue == ((int)TwConst.TypeInt.散件出库).ToString())
|
|
{
|
|
Grid1.Hidden = false;
|
|
Grid2.Hidden = true;
|
|
|
|
}
|
|
else
|
|
{
|
|
Grid1.Hidden = true;
|
|
Grid2.Hidden = false;
|
|
}
|
|
|
|
bool isTransfer = IsTransferType();
|
|
drpWarehouse.Label = isTransfer ? "调出仓库" : "仓库";
|
|
drpTransferWarehouse.Hidden = !isTransfer;
|
|
if (!isTransfer)
|
|
{
|
|
drpTransferWarehouse.SelectedValue = Const._Null;
|
|
}
|
|
}
|
|
}
|
|
}
|