SGGL_SHJ/SGGL/FineUIPro.Web/HJGL/PreDesign/PackagingManageEdit.aspx.cs

266 lines
11 KiB
C#

using BLL;
using Model;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Linq;
namespace FineUIPro.Web.HJGL.PreDesign
{
public partial class PackagingManageEdit : PageBase
{
public string PackagingManageId
{
get
{
return (string)ViewState["PackagingManageId"];
}
set
{
ViewState["PackagingManageId"] = value;
}
}
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
PackagingManageId = Request.Params["PackagingManageId"];
TrainNumberManageService.InitDownListOfTrainNumber(drpTrainNumber, this.CurrUser.LoginProjectId, false);
drpTypeInt.DataTextField = "Key";
drpTypeInt.DataValueField = "Value";
drpTypeInt.DataSource = HJGLPackagingmanageService.TypeIntMap;
drpTypeInt.DataBind();
droCategoryInt.DataTextField = "Key";
droCategoryInt.DataValueField = "Value";
droCategoryInt.DataSource = HJGLPackagingmanageService.CategoryIntMap;
droCategoryInt.DataBind();
btnClose.OnClientClick = ActiveWindow.GetHideReference();
if (!string.IsNullOrEmpty(PackagingManageId))
{
var model = HJGLPackagingmanageService.GetHJGL_PackagingManageById(PackagingManageId);
HJGL_PackagingManageDetail filter = new HJGL_PackagingManageDetail
{
PackagingManageId = PackagingManageId
};
var packagingDetails = HJGLPackagingmanagedetailService.GetByQueryModle(filter);
drpTypeInt.Enabled = false;
txtPackagingCode.Text = model.PackagingCode;
dropPipelineComponentCode.Values = packagingDetails.Select(x=>x.PipelineComponentId).ToArray();
txtStackingPosition.Text = model.StackingPosition;
drpTrainNumber.SelectedValue = model.TrainNumberId;
drpTypeInt.SelectedValue = model.TypeInt.ToString();
droCategoryInt.SelectedValue = model.CategoryInt.ToString();
if (model.State == HJGLPackagingmanageService.state_0)
{
btnSave.Hidden = false;
}
}
else
{
drpTypeInt.Enabled = true;
btnSave.Hidden = false;
txtPackagingCode.Text = HJGLPackagingmanageService.GetNewPackagingCode(this.CurrUser.LoginProjectId);
}
drpTypeInt_SelectedIndexChanged(null, null);
}
}
private void BindGrid()
{
Grid1.DataSource = HJGL_PipelineComponentService.GetAcceptedPipelineComponent(CurrUser.LoginProjectId,
txtpipelineCode.Text.Trim(), txtpipelineComponentCode.Text.Trim(), txtflowingSection.Text.Trim());
Grid1.DataBind();
}
private void BindGrid2(string PackagingManageId)
{
Grid2.DataSource = HJGLPackagingmanagedetailService.GetPackagingData(PackagingManageId);
Grid2.DataBind();
}
protected void btnSave_Click(object sender, EventArgs e)
{
Save();
ShowNotify("保存成功!", MessageBoxIcon.Success);
PageContext.RegisterStartupScript(ActiveWindow.GetHideRefreshReference());
}
private void Save()
{
if (string.IsNullOrEmpty(PackagingManageId))
{
Model.HJGL_PackagingManage table = new Model.HJGL_PackagingManage();
PackagingManageId = SQLHelper.GetNewID();
table.PackagingManageId = PackagingManageId;
table.PackagingCode = txtPackagingCode.Text;
table.ProjectId = this.CurrUser.LoginProjectId;
table.StackingPosition = txtStackingPosition.Text;
table.State = 0;
//table.ContactName = txtContactName.Text;
//table.ContactPhone = txtContactPhone.Text;
table.TrainNumberId = drpTrainNumber.SelectedValue;
table.TypeInt = int.Parse(drpTypeInt.SelectedValue);
table.CategoryInt = int.Parse(droCategoryInt.SelectedValue);
table.CompileMan = this.CurrUser.PersonId;
table.CompileDate = DateTime.Now;
if (drpTypeInt.SelectedValue == ((int)HJGLPackagingmanageService.TypeInt.).ToString())
{
table.PipelineComponentId = string.Join(",", dropPipelineComponentCode.Values);
var newDetailList = new List<Model.HJGL_PackagingManageDetail>();
foreach (var item in dropPipelineComponentCode.Values)
{
var ComponentModel = BLL.HJGL_PipelineComponentService.GetPipelineComponentById(item);
if (ComponentModel != null)
{
var model = new Model.HJGL_PackagingManageDetail()
{
Id = SQLHelper.GetNewID(),
PackagingManageId = this.PackagingManageId,
PipelineId = ComponentModel.PipelineId,
PipelineComponentId = item,
CreateTime = DateTime.Now,
CreateUser = this.CurrUser.PersonId,
};
newDetailList.Add(model);
}
}
HJGLPackagingmanagedetailService.DeleteByPackagingManageId(this.PackagingManageId);
HJGLPackagingmanagedetailService.AddBulk(newDetailList);
}
BLL.HJGLPackagingmanageService.AddHJGL_PackagingManage(table);
}
else
{
Model.HJGL_PackagingManage table = BLL.HJGLPackagingmanageService.GetHJGL_PackagingManageById(PackagingManageId);
if (table != null)
{
table.PackagingCode = txtPackagingCode.Text;
table.ProjectId = this.CurrUser.LoginProjectId;
table.StackingPosition = txtStackingPosition.Text;
table.State = 0;
//table.ContactName = txtContactName.Text;
//table.ContactPhone =txtContactPhone.Text;
table.TrainNumberId = drpTrainNumber.SelectedValue;
table.TypeInt = int.Parse(drpTypeInt.SelectedValue);
table.CategoryInt = int.Parse(droCategoryInt.SelectedValue);
if (drpTypeInt.SelectedValue == ((int)HJGLPackagingmanageService.TypeInt.).ToString())
{
table.PipelineComponentId = string.Join(",", dropPipelineComponentCode.Values);
var newDetailList = new List<Model.HJGL_PackagingManageDetail>();
foreach (var item in dropPipelineComponentCode.Values)
{
var ComponentModel = BLL.HJGL_PipelineComponentService.GetPipelineComponentById(item);
if (ComponentModel != null)
{
var model = new Model.HJGL_PackagingManageDetail()
{
Id = SQLHelper.GetNewID(),
PackagingManageId = this.PackagingManageId,
PipelineId = ComponentModel.PipelineId,
PipelineComponentId = item,
CreateTime = DateTime.Now,
CreateUser = this.CurrUser.PersonId,
};
newDetailList.Add(model);
}
}
HJGLPackagingmanagedetailService.DeleteByPackagingManageId(this.PackagingManageId);
HJGLPackagingmanagedetailService.AddBulk(newDetailList);
}
}
BLL.HJGLPackagingmanageService.UpdateHJGL_PackagingManage(table);
}
SaveDetail();
}
private void SaveDetail()
{
//根据列表中的明细项添加
List<Model.PipelinePrefabricatedComponentsItem> detailLists = new List<Model.PipelinePrefabricatedComponentsItem>();
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 = HJGLPackagingmanagedetailService.GetModelById(id);
if (mdoel != null)
{
mdoel.Number = values.Value<decimal>("Number");
}
HJGLPackagingmanagedetailService.Update(mdoel);
}
}
protected void btnFind_Click1(object sender, EventArgs e)
{
BindGrid();
}
#region
/// <summary>
/// 选择按钮
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnSelect_Click(object sender, EventArgs e)
{
Save();
PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("PackagingManageSelect.aspx?PackagingManageId={0}&TypeInt={1}", PackagingManageId, drpTypeInt.SelectedValue, "选择- ")));
}
protected void btnSelectStock_Click(object sender, EventArgs e)
{
Save();
PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("PackagingManageSelectStock.aspx?PackagingManageId={0}", PackagingManageId, "选择- ")));
}
#endregion
protected void drpTypeInt_SelectedIndexChanged(object sender, EventArgs e)
{
if (drpTypeInt.SelectedValue == ((int)HJGLPackagingmanageService.TypeInt.).ToString())
{
dropPipelineComponentCode.Hidden = false;
Grid2.Hidden = true;
BindGrid();
}
else
{
dropPipelineComponentCode.Hidden = true;
Grid2.Hidden = false;
btnSelect.Hidden = false;
//btnSelectStock.Hidden = true;
BindGrid2(this.PackagingManageId);
}
}
protected void Grid2_RowCommand(object sender, GridCommandEventArgs e)
{
if (e.CommandName == "delete")
{
string id = e.RowID;
HJGLPackagingmanagedetailService.DeleteById(id);
BindGrid2(this.PackagingManageId);
}
}
protected void Window1_Close(object sender, WindowCloseEventArgs e)
{
BindGrid2(this.PackagingManageId);
}
}
}