ZHJA_HJGL/HJGL_ZH/FineUIPro.Web/WeldMat/UsingSentMat/ShowStockIn.aspx.cs

308 lines
13 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;
using Newtonsoft.Json.Linq;
using BLL;
namespace FineUIPro.Web.WeldMat.UsingSentMat
{
public partial class ShowStockIn : PageBase
{
/// <summary>
/// 计划ID
/// </summary>
private string UsingPlanId
{
get
{
return (string)ViewState["UsingPlanId"];
}
set
{
ViewState["UsingPlanId"] = value;
}
}
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
this.UsingPlanId = Request.Params["UsingPlanId"];
var plan = BLL.UsingPlanService.GetUsingPlanById(this.UsingPlanId);
var welder = BLL.HJGL_PersonManageService.GetWelderByWenId(plan.UsingManOne);
decimal usedAmount = BLL.UsingMatService.GetUsingAmountSum(this.UsingPlanId);
string strUsing = string.Empty;
if (plan!=null && welder != null)
{
strUsing = "焊工:" + welder.WED_Code + "-" + welder.WED_Name + "计划领用焊材数量为:" + plan.Amount.Value.ToString();
}
if (usedAmount > 0)
{
strUsing = strUsing + "已领用:" + usedAmount.ToString();
}
this.lbUsingMatInfo.Text = strUsing;
// 绑定表格
BindGrid();
}
}
#region
/// <summary>
/// 绑定数据
/// </summary>
private void BindGrid()
{
var plan = BLL.UsingPlanService.GetUsingPlanById(this.UsingPlanId);
string strSql = @" SELECT StockIn.StockInId, StockIn.WeldId,StockIn.Warrantybook,
WeldInfo.WeldCode,WeldInfo.WeldName,WeldInfo.WeldSpec,WeldInfo.WeldTypeId,
WeldType.WeldTypeName,'根' AS WeldUnit,store.UnitStoreName,
(StockIn.Amount-ISNULL(StockIn.UsingAmount,0)) AS StockAmount,
StockIn.HeartNo, StockIn.RecycleAmount, @OneAmount as OneAmount
FROM Weld_StockIn AS StockIn
LEFT JOIN Weld_WeldInfo AS WeldInfo ON WeldInfo.WeldId = StockIn.WeldId
LEFT JOIN Weld_WeldType AS WeldType ON WeldType.WeldTypeId = WeldInfo.WeldTypeId
LEFT JOIN dbo.Weld_Supplier supplier ON supplier.SupplierId=StockIn.SupplierId
LEFT JOIN dbo.Weld_UnitStore store ON store.UnitStoreId = StockIn.UnitStoreId
WHERE (StockIn.Amount-ISNULL(StockIn.UsingAmount,0)+ISNULL(StockIn.RecycleAmount,0))>0
AND StockIn.WeldId=@WeldId AND store.UnitId=@UnitId";
List<SqlParameter> listStr = new List<SqlParameter>();
if (plan != null)
{
listStr.Add(new SqlParameter("@OneAmount", plan.Amount));
listStr.Add(new SqlParameter("@WeldId", plan.WeldId));
}
else
{
listStr.Add(new SqlParameter("@WeldId", null));
}
if (CurrUser.UnitId != null)
{
listStr.Add(new SqlParameter("@UnitId", CurrUser.UnitId));
}
else
{
listStr.Add(new SqlParameter("@UnitId", null));
}
SqlParameter[] parameter = listStr.ToArray();
DataTable tb = SQLHelper.GetDataTableRunText(strSql, parameter);
// 2.获取当前分页数据
Grid1.RecordCount = tb.Rows.Count;
//tb = GetFilteredTable(Grid1.FilteredData, tb);
var table = this.GetSortTable(Grid1, tb);
Grid1.DataSource = table;
Grid1.DataBind();
}
#endregion
#region
/// <summary>
/// 查询
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void TextBox_TextChanged(object sender, EventArgs e)
{
this.BindGrid();
}
#endregion
#region
/// <summary>
/// 确定按钮
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnSure_Click(object sender, EventArgs e)
{
if (Grid1.SelectedRowIndexArray.Length == 0)
{
Alert.ShowInTop("请至少选择一条记录!", MessageBoxIcon.Warning);
return;
}
string selectRowId = Grid1.SelectedRowID;
decimal oneAmount = 0;
decimal twoAmount = 0;
JArray mergedData = Grid1.GetMergedData();
foreach (JObject mergedRow in mergedData)
{
JObject values = mergedRow.Value<JObject>("values");
string stockInId = values.Value<string>("StockInId");
if (selectRowId==stockInId)
{
if (values.Value<string>("OneAmount") != "" && values.Value<string>("StockAmount") != "")
{
if (values.Value<decimal>("OneAmount") > values.Value<decimal>("StockAmount"))
{
Alert.ShowInTop("一次领用数量的库存不足!", MessageBoxIcon.Warning);
return;
}
}
if (values.Value<string>("TwoAmount") != "" && values.Value<string>("RecycleAmount") != "")
{
if (values.Value<decimal>("TwoAmount") > values.Value<decimal>("RecycleAmount"))
{
Alert.ShowInTop("二次领用数量的库存不足!", MessageBoxIcon.Warning);
return;
}
}
if (values.Value<string>("OneAmount") != "")
{
oneAmount = values.Value<decimal>("OneAmount");
}
if (values.Value<string>("TwoAmount") != "")
{
twoAmount = values.Value<decimal>("TwoAmount");
}
}
}
var plan = BLL.UsingPlanService.GetUsingPlanById(this.UsingPlanId);
if (plan != null)
{
var stockIn = BLL.StockInService.GetStockInById(selectRowId);
if (oneAmount + twoAmount > plan.Amount)
{
Alert.ShowInTop("领用数量要不能大于计划数量,请重新录入数量!", MessageBoxIcon.Warning);
return;
}
else
{
var mat = BLL.UsingMatService.GetUsingMatByPlanId(this.UsingPlanId);
if (mat == null)
{
Model.Weld_UsingMat usingMat = new Model.Weld_UsingMat();
usingMat.UsingMatId = SQLHelper.GetNewID(typeof(Model.Weld_UsingMat));
var project = BLL.Base_ProjectService.GetProjectByProjectId(plan.ProjectId);
usingMat.ProjectId = plan.ProjectId;
usingMat.UsingPlanId = this.UsingPlanId;
usingMat.Amount = oneAmount;
usingMat.TwoAmount = twoAmount;
usingMat.UsingMan = plan.UsingManOne;
usingMat.UsingDate = DateTime.Now;
usingMat.Warrantybook = stockIn.Warrantybook;
if (!string.IsNullOrEmpty(stockIn.Number))
{
usingMat.Number = stockIn.Number;
}
else
{
string perfix = project.ProjectCode + "-";
usingMat.Number = BLL.SQLHelper.RunProcNewIdByProjectId("SpGetNewCodeByProjectId", "dbo.Weld_UsingMat", "Number", plan.ProjectId, perfix);
}
usingMat.StockInId = selectRowId;
usingMat.UsePosition = plan.UsePosition;
usingMat.WeldId = plan.WeldId;
var user = BLL.StoremanInfoService.GetStoremanByUserId(CurrUser.UserId);
if (user != null)
{
usingMat.StoreMan = user.StoremanId;
}
if (usingMat.Amount + usingMat.TwoAmount > 0)
{
BLL.UsingMatService.AddUsingMat(usingMat);
// 修改库存已使用的数量
BLL.StockInService.UpdateStockInUsingAmount(usingMat.StockInId, usingMat.Amount, usingMat.TwoAmount);
}
else
{
ShowNotify("请填写领用数量!");
}
string window = String.Format("UsingMatCheck.aspx?keyId={0}&grid=1&isFinger=1&FingerOrFace={1}", usingMat.UsingMatId, "2", "编辑 - ");
PageContext.RegisterStartupScript(Window1.GetSaveStateReference(usingMat.UsingMan)
+ Window1.GetShowReference(window));
}
}
}
//if (Grid1.SelectedRowIndexArray.Length == 0)
//{
// Alert.ShowInTop("请至少选择一条记录!", MessageBoxIcon.Warning);
// return;
//}
//string[] selectRowId = Grid1.SelectedRowIDArray;
//string stockIds = string.Empty;
//foreach (string s in selectRowId)
//{
// stockIds = stockIds + s + ",";
//}
//string StockItem = string.Empty;
//decimal oneTotalNum = 0;
//decimal twoTotalNum = 0;
//JArray mergedData = Grid1.GetMergedData();
//foreach (JObject mergedRow in mergedData)
//{
// string oneAmount = "0";
// string twoAmount = "0";
// JObject values = mergedRow.Value<JObject>("values");
// string stockInId = values.Value<string>("StockInId");
// if (selectRowId.Contains(stockInId))
// {
// if (values.Value<string>("OneAmount") != "" && values.Value<string>("StockAmount") != "")
// {
// if (values.Value<decimal>("OneAmount") > values.Value<decimal>("StockAmount"))
// {
// Alert.ShowInTop("一次领用数量的库存不足!", MessageBoxIcon.Warning);
// return;
// }
// }
// if (values.Value<string>("TwoAmount") != "" && values.Value<string>("RecycleAmount") != "")
// {
// if (values.Value<decimal>("TwoAmount") > values.Value<decimal>("RecycleAmount"))
// {
// Alert.ShowInTop("二次领用数量的库存不足!", MessageBoxIcon.Warning);
// return;
// }
// }
// if (values.Value<string>("OneAmount") != "")
// {
// oneAmount = values.Value<string>("OneAmount");
// oneTotalNum = oneTotalNum + values.Value<decimal>("OneAmount");
// }
// if (values.Value<string>("TwoAmount") != "")
// {
// twoAmount = values.Value<string>("TwoAmount");
// twoTotalNum = twoTotalNum + values.Value<decimal>("TwoAmount");
// }
// StockItem = StockItem + stockInId + "," + oneAmount + "," + twoAmount + "|";
// }
//}
//var plan = BLL.UsingPlanService.GetUsingPlanById(this.UsingPlanId);
//if (oneTotalNum + twoTotalNum > plan.Amount)
//{
// Alert.ShowInTop("领用数量要不能大于计划数量,请重新录入数量!", MessageBoxIcon.Warning);
// return;
//}
//else
//{
// StockItem = StockItem.Substring(0, StockItem.Length - 1);
// string itemsString = this.UsingPlanId + "$" + StockItem;
// PageContext.RegisterStartupScript(ActiveWindow.GetWriteBackValueReference(itemsString)
// + ActiveWindow.GetHidePostBackReference());
//}
}
#endregion
}
}