ZHJA_HJGL/HJGL_ZH/FineUIPro.Web/WeldMat/Stock/StockInitEdit.aspx.cs

352 lines
14 KiB
C#

using System;
using System.Linq;
using BLL;
namespace FineUIPro.Web.WeldMat.Stock
{
public partial class StockInitEdit : PageBase
{
#region
/// <summary>
/// 主键
/// </summary>
private string StockInId
{
get
{
return (string)ViewState["StockInId"];
}
set
{
ViewState["StockInId"] = 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.drpMaterialman.DataValueField = "UserId";
this.drpMaterialman.DataTextField = "UserName";
this.drpMaterialman.DataSource = BLL.Sys_UserService.GetUserList();
this.drpMaterialman.DataBind();
if (CurrUser.Account != Const.Gly)
{
BLL.UnitStoreService.InitUnitStoreDropDownList(drpUnitStore, CurrUser.UnitId, true);
}
else
{
BLL.UnitStoreService.InitUnitStoreDropDownList(drpUnitStore, null, true);
}
//this.drpSupplier.DataTextField = "Text";
//this.drpSupplier.DataValueField = "Value";
//this.drpSupplier.DataSource = BLL.SupplierService.GetSupplierList();
//this.drpSupplier.DataBind();
//Funs.FineUIPleaseSelect(this.drpSupplier);
this.StockInId = Request.Params["StockInId"];
if (!string.IsNullOrEmpty(this.StockInId))
{
Model.Weld_StockIn stockIn = BLL.StockInService.GetStockInById(this.StockInId);
if (stockIn != null)
{
if (!string.IsNullOrEmpty(stockIn.WeldId))
{
this.hdWeldId.Text = stockIn.WeldId;
var weld = BLL.WeldInfoService.GetWeldInfoById(stockIn.WeldId);
if (weld != null)
{
this.txtWeldName.Text = weld.WeldName;
//this.txtWeldCode.Text = weld.WeldCode;
this.txtWeldSpec.Text = weld.WeldSpec;
if (!string.IsNullOrEmpty(weld.WeldTypeId))
{
var weldType = BLL.WeldTypeService.GetWeldTypeById(weld.WeldTypeId);
if (weldType != null)
{
this.txtWeldType.Text = weldType.WeldTypeName;
this.txtWeldUnit.Text = weldType.WeldUnit;
}
}
}
if (stockIn.Amount.HasValue)
{
this.txtAmount.Text = stockIn.Amount.ToString();
}
if (stockIn.Weight.HasValue)
{
this.txtWeight.Text = stockIn.Weight.ToString();
}
if (stockIn.RecycleAmount.HasValue)
{
this.txtRecAmount.Text = stockIn.RecycleAmount.ToString();
}
if (stockIn.RecycleWeight.HasValue)
{
this.txtRecWeight.Text = stockIn.RecycleWeight.ToString();
}
this.txtWarrantybook.Text = stockIn.Warrantybook;
this.txtHeartNo.Text = stockIn.HeartNo;
if (!string.IsNullOrEmpty(stockIn.Materialman))
{
this.drpMaterialman.SelectedValue = stockIn.Materialman;
}
if (stockIn.InStockDate.HasValue)
{
this.txtInStockDate.Text = string.Format("{0:yyyy-MM-dd}", stockIn.InStockDate);
}
if (stockIn.ReviewDate.HasValue)
{
this.txtReviewDate.Text = string.Format("{0:yyyy-MM-dd}", stockIn.ReviewDate);
}
if (!string.IsNullOrEmpty(stockIn.UnitStoreId))
{
this.drpUnitStore.SelectedValue = stockIn.UnitStoreId;
}
}
}
}
else
{
this.drpMaterialman.SelectedValue = this.CurrUser.UserId;
this.txtInStockDate.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)
{
if (this.hdWeldId.Text == string.Empty)
{
Alert.ShowInTop("请选择焊材牌号!", MessageBoxIcon.Warning);
return;
}
if (drpUnitStore.SelectedValue == Const._Null)
{
Alert.ShowInTop("请选择单位仓库!", MessageBoxIcon.Warning);
return;
}
SaveData();
ShowNotify("保存成功!", MessageBoxIcon.Success);
PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference());
}
/// <summary>
/// 保存数据
/// </summary>
private void SaveData()
{
Model.Weld_StockIn stockIn = new Model.Weld_StockIn();
if (!string.IsNullOrEmpty(this.hdWeldId.Text))
{
stockIn.WeldId = this.hdWeldId.Text;
}
stockIn.Amount = Funs.GetNewDecimal(this.txtAmount.Text.Trim());
stockIn.Weight = Funs.GetNewDecimal(this.txtWeight.Text.Trim());
stockIn.RecycleAmount = Funs.GetNewDecimal(this.txtRecAmount.Text.Trim());
stockIn.RecycleWeight = Funs.GetNewDecimal(this.txtRecWeight.Text.Trim());
if (this.drpMaterialman.SelectedValue != BLL.Const._Null)
{
stockIn.Materialman = this.drpMaterialman.SelectedValue;
}
stockIn.InStockDate = Funs.GetNewDateTime(this.txtInStockDate.Text.Trim());
stockIn.ReviewDate = Funs.GetNewDateTime(this.txtReviewDate.Text.Trim());
stockIn.Warrantybook = this.txtWarrantybook.Text.Trim();
stockIn.HeartNo = txtHeartNo.Text.Trim();
if (this.drpUnitStore.SelectedValue != BLL.Const._Null)
{
stockIn.UnitStoreId = this.drpUnitStore.SelectedValue;
}
stockIn.Flag = "0";//初始化
if (!string.IsNullOrEmpty(this.StockInId))
{
stockIn.StockInId = this.StockInId;
var att = from x in Funs.DB.AttachFile where x.ToKeyId == this.StockInId select x;
if (att.Count() > 0)
{
stockIn.AttachUrl = att.First().AttachUrl;
}
var mat = from x in Funs.DB.Weld_UsingMat where x.StockInId == this.StockInId select x;
if (mat.Count() > 0)
{
// 焊材已有领用,不更新数量
BLL.StockInService.UpdateStockIn1(stockIn);
}
else
{
BLL.StockInService.UpdateStockIn(stockIn);
}
BLL.Sys_LogService.AddLog(Const.System_7, this.CurrUser.LoginProjectId, this.CurrUser.UserId, "修改库存初始化");
}
else
{
this.StockInId = SQLHelper.GetNewID(typeof(Model.Weld_StockIn));
stockIn.StockInId = this.StockInId;
BLL.StockInService.AddStockIn(stockIn);
var att = from x in Funs.DB.AttachFile where x.ToKeyId == this.StockInId select x;
if (att.Count() > 0)
{
BLL.StockInService.UpdateAttachFile(this.StockInId, att.First().AttachUrl);
}
BLL.Sys_LogService.AddLog(Const.System_7, this.CurrUser.LoginProjectId, this.CurrUser.UserId, "添加库存初始化");
}
}
#endregion
#region
/// <summary>
/// 上传附件资源
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnAttachUrl_Click(object sender, EventArgs e)
{
string edit = "0"; // 表示能打开附件上传窗口,但不能上传附件
if (BLL.CommonService.GetAllButtonPowerList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, BLL.Const.CLGL_StockInitMenuId, BLL.Const.BtnSave))
{
if (string.IsNullOrEmpty(this.StockInId))
{
if (this.hdWeldId.Text==string.Empty)
{
Alert.ShowInTop("请选择焊材牌号!", MessageBoxIcon.Warning);
return;
}
SaveData();
}
edit = "1";
PageContext.RegisterStartupScript(Window2.GetShowReference(String.Format("../../AttachFile/webuploader.aspx?toKeyId={0}&path=FileUpload/WeldMat/StockIn&menuId={1}&edit={2}", this.StockInId, Const.CLGL_StockInMenuId, edit)));
}
}
#endregion
#region
/// <summary>
/// 查找焊材信息
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnSelect_Click(object sender, EventArgs e)
{
string window = String.Format("ShowWeldInfo.aspx", "编辑 - ");
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;
if (!string.IsNullOrEmpty(weld.WeldTypeId))
{
var weldType = BLL.WeldTypeService.GetWeldTypeById(weld.WeldTypeId);
if (weldType != null)
{
this.txtWeldType.Text = weldType.WeldTypeName;
this.txtWeldUnit.Text = weldType.WeldUnit;
}
}
}
}
}
#endregion
#endregion
#region
/// <summary>
/// 输入数量自动带出重量
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void txtWeight_TextChanged(object sender, EventArgs e)
{
if (!string.IsNullOrEmpty(this.txtWeight.Text.Trim()))
{
if (!string.IsNullOrEmpty(this.hdWeldId.Text.Trim()))
{
var weld = BLL.WeldInfoService.GetWeldInfoById(this.hdWeldId.Text.Trim());
if (weld != null)
{
if (weld.ConvertValue.HasValue)
{
decimal? amountCov = Funs.GetNewDecimal(this.txtWeight.Text.Trim()) / weld.ConvertValue;
int amount = Convert.ToInt32(Math.Floor(amountCov.Value));
this.txtAmount.Text = amount.ToString();
}
else
{
this.txtAmount.Text = this.txtWeight.Text.Trim();
}
}
}
}
}
#endregion
#region
/// <summary>
/// 输入数量自动带出重量
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void txtRecWeight_TextChanged(object sender, EventArgs e)
{
if (!string.IsNullOrEmpty(this.txtRecWeight.Text.Trim()))
{
if (!string.IsNullOrEmpty(this.hdWeldId.Text.Trim()))
{
var weld = BLL.WeldInfoService.GetWeldInfoById(this.hdWeldId.Text.Trim());
if (weld != null)
{
if (weld.ConvertValue.HasValue)
{
decimal? amountCov = Funs.GetNewDecimal(this.txtRecWeight.Text.Trim()) / weld.ConvertValue;
int amount = Convert.ToInt32(Math.Floor(amountCov.Value));
this.txtRecAmount.Text = amount.ToString();
}
else
{
this.txtRecAmount.Text = this.txtRecWeight.Text.Trim();
}
}
}
}
}
#endregion
}
}