feat(clgl): 增加入库申请编辑与明细导入
支持入库申请信息维护、入库明细批量导入及模板下载, 完善材料入库业务流程,减少人工录入和明细维护成本。 增加焊口流转区段信息,并统一相关单位工程列表排序
This commit is contained in:
@@ -0,0 +1,391 @@
|
||||
using BLL;
|
||||
using Model;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace FineUIPro.Web.CLGL
|
||||
{
|
||||
public partial class InPlanMasterApplyEdit : PageBase
|
||||
{
|
||||
public string Id
|
||||
{
|
||||
get
|
||||
{
|
||||
return (string)ViewState["Id"];
|
||||
}
|
||||
set
|
||||
{
|
||||
ViewState["Id"] = value;
|
||||
}
|
||||
}
|
||||
|
||||
protected string MaterialInfoJson
|
||||
{
|
||||
get
|
||||
{
|
||||
var materialMap = GetMaterialList().ToDictionary(x => x.MaterialCode, x => new
|
||||
{
|
||||
x.Code,
|
||||
x.HeatNo,
|
||||
x.BatchNo,
|
||||
x.MaterialName,
|
||||
x.MaterialDef
|
||||
});
|
||||
return JsonConvert.SerializeObject(materialMap);
|
||||
}
|
||||
}
|
||||
|
||||
protected void Page_Load(object sender, EventArgs e)
|
||||
{
|
||||
if (!IsPostBack)
|
||||
{
|
||||
InitDrpList();
|
||||
Id = Request.Params["Id"];
|
||||
if (!string.IsNullOrEmpty(Id))
|
||||
{
|
||||
BindMaster();
|
||||
BindGrid(Id);
|
||||
}
|
||||
else
|
||||
{
|
||||
txtCreateMan.Text = this.CurrUser.PersonName;
|
||||
txtCreateDate.Text = DateTime.Now.ToString("yyyy-MM-dd");
|
||||
drpReqUnit.SelectedValue = this.CurrUser.UnitId;
|
||||
RefreshCusBillCode();
|
||||
BindGrid(string.Empty);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void InitDrpList()
|
||||
{
|
||||
drpWarehouse.DataTextField = "Key";
|
||||
drpWarehouse.DataValueField = "Value";
|
||||
drpWarehouse.DataSource = TwInOutplanmasterService.GetWarehouseCode(this.CurrUser.LoginProjectId);
|
||||
drpWarehouse.DataBind();
|
||||
|
||||
drpTypeInt.DataTextField = "Key";
|
||||
drpTypeInt.DataValueField = "Value";
|
||||
drpTypeInt.DataSource = TwConst.TypeIntMap.Where(x => x.Key.Contains("入库"));
|
||||
drpTypeInt.DataBind();
|
||||
|
||||
drpCategory.DataTextField = "Key";
|
||||
drpCategory.DataValueField = "Value";
|
||||
drpCategory.DataSource = TwConst.CategoryMap;
|
||||
drpCategory.DataBind();
|
||||
|
||||
UnitService.InitUnitDropDownList(drpReqUnit, this.CurrUser.LoginProjectId, true);
|
||||
|
||||
drpMaterialCodeEditor.DataTextField = "MaterialCode";
|
||||
drpMaterialCodeEditor.DataValueField = "MaterialCode";
|
||||
drpMaterialCodeEditor.DataSource = GetMaterialList();
|
||||
drpMaterialCodeEditor.DataBind();
|
||||
Funs.FineUIPleaseSelect(drpMaterialCodeEditor);
|
||||
}
|
||||
|
||||
private void BindMaster()
|
||||
{
|
||||
var queryModel = new Tw_InOutMasterOutput()
|
||||
{
|
||||
Id = Id,
|
||||
};
|
||||
var result = TwInOutplanmasterService.GetListData(queryModel).FirstOrDefault();
|
||||
if (result == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
txtCreateMan.Text = result.CreateManName;
|
||||
txtCreateDate.Text = result.CreateDate.HasValue ? result.CreateDate.Value.ToString("yyyy-MM-dd") : string.Empty;
|
||||
drpReqUnit.SelectedValue = result.ReqUnitId;
|
||||
drpTypeInt.SelectedValue = result.TypeInt.ToString();
|
||||
drpWarehouse.SelectedValue = result.WarehouseId;
|
||||
drpCategory.SelectedValue = result.Category.ToString();
|
||||
txtRemark.Text = result.Remark;
|
||||
txtCusBillCode.Text = result.CusBillCode;
|
||||
}
|
||||
|
||||
private void BindGrid(string inOutPlanMasterId)
|
||||
{
|
||||
if (string.IsNullOrEmpty(inOutPlanMasterId))
|
||||
{
|
||||
Grid2.DataSource = new List<Tw_InOutDetailOutput>();
|
||||
Grid2.DataBind();
|
||||
return;
|
||||
}
|
||||
|
||||
var queryModel = new Tw_InOutDetailOutput()
|
||||
{
|
||||
InOutPlanMasterId = inOutPlanMasterId
|
||||
};
|
||||
var tb = TwInOutplandetailService.GetByModle(queryModel).ToList();
|
||||
Grid2.DataSource = tb;
|
||||
Grid2.DataBind();
|
||||
}
|
||||
|
||||
protected void btnAddDetail_Click(object sender, EventArgs e)
|
||||
{
|
||||
Grid2.DataSource = GetGridDetailList(true);
|
||||
Grid2.DataBind();
|
||||
}
|
||||
|
||||
protected void btnImportStock_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (!Save(Const.BtnSave, false))
|
||||
{
|
||||
return;
|
||||
}
|
||||
PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("InPlanMasterDetailImport.aspx?Id={0}", Id, "导入- ")));
|
||||
}
|
||||
|
||||
protected void btnSave_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (Save(Const.BtnSave, false))
|
||||
{
|
||||
ShowNotify("保存成功!", MessageBoxIcon.Success);
|
||||
}
|
||||
}
|
||||
|
||||
protected void btnSubmit_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (Save(Const.BtnSubmit, true))
|
||||
{
|
||||
ShowNotify("提交成功!", MessageBoxIcon.Success);
|
||||
PageContext.RegisterStartupScript(ActiveWindow.GetHideRefreshReference());
|
||||
}
|
||||
}
|
||||
|
||||
private bool Save(string type, bool validateDetail)
|
||||
{
|
||||
if (!ValidateMaster())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
int state = type == Const.BtnSubmit ? (int)TwConst.State.待审核 : (int)TwConst.State.待提交;
|
||||
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,
|
||||
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
|
||||
};
|
||||
TwInOutplanmasterService.Add(model);
|
||||
}
|
||||
else
|
||||
{
|
||||
var model = TwInOutplanmasterService.GetById(Id);
|
||||
if (model == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
model.CusBillCode = txtCusBillCode.Text;
|
||||
model.WarehouseId = drpWarehouse.SelectedValue;
|
||||
model.WarehouseCode = drpWarehouse.SelectedText;
|
||||
model.Source = 1;
|
||||
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;
|
||||
TwInOutplanmasterService.Update(model);
|
||||
}
|
||||
|
||||
return SaveDetail(validateDetail);
|
||||
}
|
||||
|
||||
private bool ValidateMaster()
|
||||
{
|
||||
if (string.IsNullOrEmpty(drpWarehouse.SelectedValue) || drpWarehouse.SelectedValue == Const._Null)
|
||||
{
|
||||
Alert.ShowInTop("请选择仓库!", MessageBoxIcon.Warning);
|
||||
return false;
|
||||
}
|
||||
if (string.IsNullOrEmpty(drpTypeInt.SelectedValue) || drpTypeInt.SelectedValue == Const._Null)
|
||||
{
|
||||
Alert.ShowInTop("请选择入库类型!", MessageBoxIcon.Warning);
|
||||
return false;
|
||||
}
|
||||
/*if (string.IsNullOrEmpty(drpCategory.SelectedValue) || drpCategory.SelectedValue == Const._Null)
|
||||
{
|
||||
Alert.ShowInTop("请选择类别!", MessageBoxIcon.Warning);
|
||||
return false;
|
||||
}*/
|
||||
if (string.IsNullOrEmpty(txtCusBillCode.Text))
|
||||
{
|
||||
Alert.ShowInTop("请输入编号!", MessageBoxIcon.Warning);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private bool SaveDetail(bool validateDetail)
|
||||
{
|
||||
List<Tw_InOutDetailOutput> details = GetGridDetailList(false);
|
||||
if (validateDetail && details.Count == 0)
|
||||
{
|
||||
Alert.ShowInTop("请添加入库明细!", MessageBoxIcon.Warning);
|
||||
return false;
|
||||
}
|
||||
|
||||
List<string> keepIds = new List<string>();
|
||||
int sortIndex = 1;
|
||||
foreach (Tw_InOutDetailOutput item in details)
|
||||
{
|
||||
if (IsNullSelectValue(item.MaterialCode))
|
||||
{
|
||||
if (validateDetail)
|
||||
{
|
||||
Alert.ShowInTop("请选择材料主编码!", MessageBoxIcon.Warning);
|
||||
return false;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if (!item.PlanNum.HasValue || item.PlanNum <= 0)
|
||||
{
|
||||
if (validateDetail)
|
||||
{
|
||||
Alert.ShowInTop("计划入库数量必须大于0!", MessageBoxIcon.Warning);
|
||||
return false;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
// 明细只保存材料主编码和计划数量,其余材料信息由材料编码库联动显示。
|
||||
var detail = TwInOutplandetailService.GetById(item.Id);
|
||||
if (detail == null)
|
||||
{
|
||||
detail = new Tw_InOutPlanDetail
|
||||
{
|
||||
Id = string.IsNullOrEmpty(item.Id) ? SQLHelper.GetNewID() : item.Id,
|
||||
InOutPlanMasterId = Id,
|
||||
MaterialCode = item.MaterialCode,
|
||||
PlanNum = item.PlanNum,
|
||||
SortIndex = sortIndex++
|
||||
};
|
||||
TwInOutplandetailService.Add(detail);
|
||||
keepIds.Add(detail.Id);
|
||||
}
|
||||
else
|
||||
{
|
||||
detail.MaterialCode = item.MaterialCode;
|
||||
detail.PlanNum = item.PlanNum;
|
||||
detail.SortIndex = sortIndex++;
|
||||
TwInOutplandetailService.Update(detail);
|
||||
keepIds.Add(detail.Id);
|
||||
}
|
||||
}
|
||||
|
||||
var oldDetails = TwInOutplandetailService.GetByModle(new Tw_InOutDetailOutput { InOutPlanMasterId = Id }).ToList();
|
||||
foreach (var oldDetail in oldDetails.Where(x => !keepIds.Contains(x.Id)))
|
||||
{
|
||||
TwInOutplandetailService.DeleteById(oldDetail.Id);
|
||||
}
|
||||
BindGrid(Id);
|
||||
return true;
|
||||
}
|
||||
|
||||
private bool IsNullSelectValue(string value)
|
||||
{
|
||||
return string.IsNullOrEmpty(value) || value == Const._Null;
|
||||
}
|
||||
|
||||
private List<Tw_InOutDetailOutput> GetGridDetailList(bool addEmptyRow)
|
||||
{
|
||||
List<Tw_InOutDetailOutput> list = new List<Tw_InOutDetailOutput>();
|
||||
JArray teamGroupData = Grid2.GetMergedData();
|
||||
foreach (JObject teamGroupRow in teamGroupData)
|
||||
{
|
||||
JObject values = teamGroupRow.Value<JObject>("values");
|
||||
string id = teamGroupRow.Value<string>("id");
|
||||
string materialCode = values.Value<string>("MaterialCode");
|
||||
var material = MaterialCodeLibService.GetMaterialCodeLib(materialCode);
|
||||
list.Add(new Tw_InOutDetailOutput
|
||||
{
|
||||
Id = string.IsNullOrEmpty(id) ? SQLHelper.GetNewID() : id,
|
||||
InOutPlanMasterId = Id,
|
||||
MaterialCode = materialCode,
|
||||
Code = material == null ? values.Value<string>("Code") : material.Code,
|
||||
HeatNo = material == null ? values.Value<string>("HeatNo") : material.HeatNo,
|
||||
BatchNo = material == null ? values.Value<string>("BatchNo") : material.BatchNo,
|
||||
MaterialName = material == null ? values.Value<string>("MaterialName") : material.MaterialName,
|
||||
MaterialDef = material == null ? values.Value<string>("MaterialDef") : material.MaterialDef,
|
||||
PlanNum = values.Value<decimal?>("PlanNum")
|
||||
});
|
||||
}
|
||||
|
||||
if (addEmptyRow)
|
||||
{
|
||||
list.Add(new Tw_InOutDetailOutput
|
||||
{
|
||||
Id = SQLHelper.GetNewID(),
|
||||
InOutPlanMasterId = Id,
|
||||
PlanNum = 0
|
||||
});
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
protected void Grid2_RowCommand(object sender, GridCommandEventArgs e)
|
||||
{
|
||||
if (e.CommandName == "delete")
|
||||
{
|
||||
// 删除时保留当前表格中的未保存行,数据库明细在保存或提交时统一同步。
|
||||
List<Tw_InOutDetailOutput> details = GetGridDetailList(false)
|
||||
.Where(x => x.Id != e.RowID)
|
||||
.ToList();
|
||||
Grid2.DataSource = details;
|
||||
Grid2.DataBind();
|
||||
}
|
||||
}
|
||||
|
||||
protected void Window1_Close(object sender, WindowCloseEventArgs e)
|
||||
{
|
||||
BindGrid(Id);
|
||||
}
|
||||
|
||||
protected void drpTypeInt_SelectedIndexChanged(object sender, EventArgs e)
|
||||
{
|
||||
if (string.IsNullOrEmpty(Id))
|
||||
{
|
||||
RefreshCusBillCode();
|
||||
}
|
||||
}
|
||||
|
||||
private void RefreshCusBillCode()
|
||||
{
|
||||
txtCusBillCode.Text = TwInOutplanmasterService.GetDataInCusBillCode(
|
||||
this.CurrUser.LoginProjectId,
|
||||
UnitService.GetUnitByUnitId(drpReqUnit.SelectedValue)?.UnitCode,
|
||||
drpTypeInt.SelectedText,
|
||||
string.Empty,
|
||||
drpCategory.SelectedText);
|
||||
}
|
||||
|
||||
private List<HJGL_MaterialCodeLib> GetMaterialList()
|
||||
{
|
||||
return MaterialCodeLibService.GetMaterialCodeLibList()
|
||||
.Where(x => string.IsNullOrEmpty(x.ProjectId) || x.ProjectId == this.CurrUser.LoginProjectId)
|
||||
.OrderBy(x => x.MaterialCode)
|
||||
.ToList();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user