xinjiang/SGGL/FineUIPro.Web/HJGL/MaterialManage/EMaterialRegistEdit.aspx.cs

230 lines
11 KiB
C#

using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using BLL;
using Newtonsoft.Json.Linq;
namespace FineUIPro.Web.HJGL.MaterialManage
{
public partial class EMaterialRegistEdit : PageBase
{
#region
/// <summary>
/// 主键
/// </summary>
public string EMaterialRegistId
{
get
{
return (string)ViewState["EMaterialRegistId"];
}
set
{
ViewState["EMaterialRegistId"] = value;
}
}
private bool AppendToEnd = false;
#endregion
#region
/// <summary>
/// 加载页面
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
this.EMaterialRegistId = Request.Params["EMaterialRegistId"];
var project = BLL.ProjectService.GetProjectByProjectId(this.CurrUser.LoginProjectId);
if (project != null)
{
this.lblProjectName.Text = project.ProjectName;
}
if (!string.IsNullOrEmpty(this.EMaterialRegistId))
{
var electrode = BLL.HJGL_EMaterialRegistService.GetEMaterialRegistByID(this.EMaterialRegistId);
if (electrode != null)
{
this.txtUnitName.Text = electrode.UnitName;
this.txtEMaterialRegistCode.Text = electrode.EMaterialRegistCode;
this.txtEMaterialRegistDate.Text = string.Format("{0:yyyy-MM-dd}", electrode.EMaterialRegistDate);
this.txtDeliveryMan.Text = string.Format("{0:yyyy-MM-dd}", electrode.CompileDate);
}
}
else
{
this.txtEMaterialRegistDate.Text = string.Format("{0:yyyy-MM-dd}", System.DateTime.Now);
}
///制单人
///
this.drpWME_ID.DataTextField = "ConsumablesName";
this.drpWME_ID.DataValueField = "ConsumablesName";
this.drpWME_ID.DataSource = (from x in Funs.DB.Base_Consumables orderby x.ConsumablesCode select x).ToList();
this.drpWME_ID.DataBind();
// 删除选中单元格的客户端脚本
string deleteScript = GetDeleteScript();
// 新增数据初始值
JObject defaultObj = new JObject();
defaultObj.Add("WMT_MatName", "");
defaultObj.Add("SpecificationsModel", "");
defaultObj.Add("Models", "");
defaultObj.Add("UnitName", "");
defaultObj.Add("MaterialCount", "");
defaultObj.Add("ItemCode", "");
defaultObj.Add("Testrecords", "");
defaultObj.Add("Delete", String.Format("<a href=\"javascript:;\" onclick=\"{0}\"><img src=\"{1}\"/></a>", deleteScript, IconHelper.GetResolvedIconUrl(Icon.Delete)));
// 在第一行新增一条数据
btnNew.OnClientClick = Grid1.GetAddNewRecordReference(defaultObj, AppendToEnd);
// 删除选中行按钮
btnDelete.OnClientClick = Grid1.GetNoSelectionAlertReference("请至少选择一项!") + deleteScript;
// 绑定表格
this.BindGrid();
}
}
#endregion
#region
/// <summary>
/// 数据绑定
/// </summary>
private void BindGrid()
{
string strSql = @"SELECT EMaterialRegistItemId,EMaterialRegistId,SpecificationsModel,UnitName,MaterialCount,ItemCode,Testrecords,Models,Item.WMT_ID,ConsumablesName as WMT_MatName"
+ @" FROM HJGL_EMaterialRegistItem AS Item"
+ @" LEFT JOIN Base_Consumables AS WeldMaterial ON Item.WMT_ID = WeldMaterial.ConsumablesId"
+ @" WHERE EMaterialRegistId=@EMaterialRegistId";
SqlParameter[] parameter = new SqlParameter[]
{
new SqlParameter("@EMaterialRegistId",this.EMaterialRegistId),
};
DataTable tb = SQLHelper.GetDataTableRunText(strSql, parameter);
Grid1.DataSource = tb;
Grid1.DataBind();
}
#endregion
/// <summary>
///
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Grid1_PreDataBound(object sender, EventArgs e)
{
// 设置LinkButtonField的点击客户端事件
LinkButtonField deleteField = Grid1.FindColumn("Delete") as LinkButtonField;
deleteField.OnClientClick = GetDeleteScript();
}
/// <summary>
///
/// </summary>
/// <returns></returns>
private string GetDeleteScript()
{
if (!CommonService.GetAllButtonPowerList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, Const.HJGL_EMaterialRegistMenuId, Const.BtnDelete))
{
ShowNotify("您没有这个权限,请与管理员联系!");
return null;
}
else
{
return Confirm.GetShowReference("删除选中行?", String.Empty, MessageBoxIcon.Question, Grid1.GetDeleteSelectedRowsReference(), String.Empty);
}
}
#region
/// <summary>
/// 排序
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Grid1_Sort(object sender, GridSortEventArgs e)
{
BindGrid();
}
#endregion
/// <summary>
///
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnSave_Click(object sender, EventArgs e)
{
if (!CommonService.GetAllButtonPowerList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, Const.HJGL_EMaterialRegistMenuId, Const.BtnSave))
{
ShowNotify("您没有这个权限,请与管理员联系!");
return;
}
Model.HJGL_EMaterialRegist eMaterialRegist = new Model.HJGL_EMaterialRegist();
eMaterialRegist.EMaterialRegistCode = this.txtEMaterialRegistCode.Text.Trim();
eMaterialRegist.EMaterialRegistDate = Funs.GetNewDateTime(this.txtEMaterialRegistDate.Text);
eMaterialRegist.DeliveryMan = this.txtDeliveryMan.Text.Trim();
eMaterialRegist.UnitName = this.txtUnitName.Text.Trim();
eMaterialRegist.CompileMan = this.CurrUser.UserId;
eMaterialRegist.CompileDate = DateTime.Now;
eMaterialRegist.ProjectId = this.CurrUser.LoginProjectId;
//修改
if (!string.IsNullOrEmpty(this.EMaterialRegistId))
{
eMaterialRegist.EMaterialRegistId = this.EMaterialRegistId;
BLL.HJGL_EMaterialRegistService.UpdateEMaterialRegist(eMaterialRegist);
/// 删除到货明细
BLL.HJGL_EMaterialRegistService.DeleteEMaterialRegistItem(this.CurrUser.LoginProjectId, eMaterialRegist.Unit, this.EMaterialRegistId);
//BLL.Sys_LogService.AddLog(BLL.Const.System_7, this.CurrUser.LoginProjectId, this.CurrUser.UserId, "修改材料到货登记及验收记录!");
}
else //添加
{
eMaterialRegist.EMaterialRegistId = SQLHelper.GetNewID(typeof(Model.HJGL_EMaterialRegist));
this.EMaterialRegistId = eMaterialRegist.EMaterialRegistId;
BLL.HJGL_EMaterialRegistService.AddEMaterialRegist(eMaterialRegist);
//BLL.Sys_LogService.AddLog(BLL.Const.System_7, this.CurrUser.LoginProjectId, this.CurrUser.UserId, "添加材料到货登记及验收记录!");
}
if (Grid1.GetModifiedData().Count > 0)
{
JArray teamGroupData = Grid1.GetMergedData();
foreach (JObject teamGroupRow in teamGroupData)
{
//string status = teamGroupRow.Value<string>("status");
JObject values = teamGroupRow.Value<JObject>("values");
Model.HJGL_EMaterialRegistItem newItem = new Model.HJGL_EMaterialRegistItem();
newItem.EMaterialRegistId = this.EMaterialRegistId;
newItem.EMaterialRegistItemId = SQLHelper.GetNewID(typeof(Model.HJGL_EMaterialRegistItem));
var mat = Funs.DB.Base_Consumables.FirstOrDefault(x => x.ConsumablesName == values.Value<string>("WMT_MatName"));
if (mat != null)
{
newItem.WMT_ID = mat.ConsumablesId;
}
newItem.SpecificationsModel = values.Value<string>("SpecificationsModel");
newItem.Models = values.Value<string>("Models");
newItem.UnitName = values.Value<string>("UnitName");
newItem.MaterialCount = Funs.GetNewInt(values.Value<string>("MaterialCount"));
newItem.ItemCode = values.Value<string>("ItemCode");
newItem.Testrecords = values.Value<string>("Testrecords");
BLL.HJGL_EMaterialRegistService.AddEMaterialRegistItem(newItem);
if (newItem.MaterialCount.HasValue && !string.IsNullOrEmpty(newItem.WMT_ID))
{
BLL.HJGL_EMInventoryRecordsService.UpdateEMInventoryRecords(this.CurrUser.LoginProjectId, eMaterialRegist.Unit, newItem.WMT_ID, newItem.Models, newItem.SpecificationsModel, newItem.MaterialCount.Value);
}
}
}
Alert.ShowInTop("保存成功!", MessageBoxIcon.Success);
PageContext.RegisterStartupScript(ActiveWindow.GetHideRefreshReference());
}
}
}