ZHJA_HJGL/HJGL_ZH/FineUIPro.Web/common/BaseInfo/ProjectPlan.aspx.cs

501 lines
19 KiB
C#

using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Data;
using System.Linq;
using BLL;
namespace FineUIPro.Web.common.BaseInfo
{
public partial class ProjectPlan : PageBase
{
#region
/// <summary>
/// 加载页面
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
ddlPageSize.SelectedValue = Grid1.PageSize.ToString();
ddlPageSize.SelectedValue = Grid1.PageSize.ToString();
this.drpWeldType.DataTextField = "WeldTypeName";
this.drpWeldType.DataValueField = "WeldTypeId";
this.drpWeldType.DataSource = BLL.WeldTypeService.GetWeldTypeList();
this.drpWeldType.DataBind();
Funs.FineUIPleaseSelect(this.drpWeldType);
string projectId = Request.Params["ProjectId"];
if (!string.IsNullOrEmpty(projectId))
{
// 绑定表格
BindGrid();
}
}
}
#endregion
#region
/// <summary>
/// 绑定数据
/// </summary>
private void BindGrid()
{
string projectId = Request.Params["ProjectId"];
string strSql = @"SELECT ProjectPlan.ProjectPlanId,
ProjectPlan.ProjectId,
ProjectPlan.WeldId,
ProjectPlan.PlanAmount,
ProjectPlan.WeldRequire,
ProjectPlan.Remark,
Project.ProjectCode,
Project.ProjectName,
WeldInfo.WeldCode,
WeldInfo.WeldName,
WeldInfo.WeldSpec,
weldType.WeldTypeName
FROM dbo.Weld_ProjectPlan AS ProjectPlan
LEFT JOIN Base_Project AS Project ON Project.ProjectId = ProjectPlan.ProjectId
LEFT JOIN Weld_WeldInfo AS WeldInfo ON WeldInfo.WeldId = ProjectPlan.WeldId
LEFT JOIN dbo.Weld_WeldType weldType ON weldType.WeldTypeId = WeldInfo.WeldTypeId
WHERE ProjectPlan.ProjectId=@ProjectId";
List<SqlParameter> listStr = new List<SqlParameter>();
listStr.Add(new SqlParameter("@ProjectId", projectId));
if (drpWeldType.SelectedValue != BLL.Const._Null)
{
strSql += " AND WeldInfo.WeldTypeId = @WeldTypeId";
listStr.Add(new SqlParameter("@WeldTypeId", drpWeldType.SelectedValue));
}
if (!string.IsNullOrEmpty(this.txtName.Text.Trim()))
{
strSql += " AND WeldName LIKE @WeldName";
listStr.Add(new SqlParameter("@WeldName", "%" + this.txtName.Text.Trim() + "%"));
}
SqlParameter[] parameter = listStr.ToArray();
DataTable tb = SQLHelper.GetDataTableRunText(strSql, parameter);
// 2.获取当前分页数据
//var table = this.GetPagedDataTable(Grid1, tb1);
Grid1.RecordCount = tb.Rows.Count;
tb = GetFilteredTable(Grid1.FilteredData, tb);
var table = this.GetPagedDataTable(Grid1, tb);
Grid1.DataSource = table;
Grid1.DataBind();
}
#endregion
#region
/// <summary>
///
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Grid1_PageIndexChange(object sender, GridPageEventArgs e)
{
Grid1.PageIndex = e.NewPageIndex;
BindGrid();
}
/// <summary>
/// 分页下拉选择
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void ddlPageSize_SelectedIndexChanged(object sender, EventArgs e)
{
Grid1.PageSize = Convert.ToInt32(ddlPageSize.SelectedValue);
BindGrid();
}
/// <summary>
///
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Grid1_FilterChange(object sender, EventArgs e)
{
BindGrid();
}
/// <summary>
/// 排序
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Grid1_Sort(object sender, FineUIPro.GridSortEventArgs e)
{
Grid1.SortDirection = e.SortDirection;
Grid1.SortField = e.SortField;
BindGrid();
}
#endregion
protected void Grid1_RowDataBound(object sender, GridRowEventArgs e)
{
DataRowView row = e.DataItem as DataRowView;
decimal planAmount = 0;
if (row["PlanAmount"] != null && row["PlanAmount"].ToString() != "")
{
planAmount = Convert.ToDecimal(row["PlanAmount"]);
}
string weldId = row["WeldId"].ToString();
decimal totalStock = 0;
var stockIn = from x in Funs.DB.Weld_StockIn
where (x.Amount ?? 0 - x.UsingAmount ?? 0) > 0 && x.WeldId == weldId
select x;
if (stockIn.Count() > 0)
{
totalStock = stockIn.Sum(x => x.Amount ?? 0 - x.UsingAmount ?? 0);
}
if (totalStock < planAmount)
{
e.RowCssClass = "color1";
}
}
#region
/// <summary>
/// 删除
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnDelete_Click(object sender, EventArgs e)
{
if (CommonService.GetAllButtonPowerList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, Const.ProjectMenuId, Const.BtnDelete))
{
if (judgementDelete(hfFormID.Text, true))
{
BLL.ProjectPlanService.DeleteProjectPlanById(hfFormID.Text);
BLL.Sys_LogService.AddLog(BLL.Const.System_7, this.CurrUser.LoginProjectId, this.CurrUser.UserId, "删除项目计划");
// 重新绑定表格,并模拟点击[新增按钮]
BindGrid();
PageContext.RegisterStartupScript("onNewButtonClick();");
}
}
else
{
Alert.ShowInTop("您没有这个权限,请与管理员联系!", MessageBoxIcon.Warning);
return;
}
}
/// <summary>
/// 右键删除事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnMenuDelete_Click(object sender, EventArgs e)
{
if (CommonService.GetAllButtonPowerList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, Const.ProjectMenuId, Const.BtnDelete))
{
this.DeleteData();
}
else
{
Alert.ShowInTop("您没有这个权限,请与管理员联系!", MessageBoxIcon.Warning);
return;
}
}
/// <summary>
/// 删除方法
/// </summary>
private void DeleteData()
{
if (Grid1.SelectedRowIndexArray.Length > 0)
{
bool isShow = true;
if (Grid1.SelectedRowIndexArray.Length > 1)
{
isShow = false;
}
foreach (int rowIndex in Grid1.SelectedRowIndexArray)
{
string rowID = Grid1.DataKeys[rowIndex][0].ToString();
if (judgementDelete(rowID, isShow))
{
BLL.ProjectPlanService.DeleteProjectPlanById(rowID);
BLL.Sys_LogService.AddLog(BLL.Const.System_7, this.CurrUser.LoginProjectId, this.CurrUser.UserId, "删除项目计划");
ShowNotify("删除完成!", MessageBoxIcon.Success);
}
}
BindGrid();
PageContext.RegisterStartupScript("onNewButtonClick();");
}
}
#endregion
#region
/// <summary>
/// 右键编辑事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnMenuEdit_Click(object sender, EventArgs e)
{
this.EditData();
}
/// <summary>
/// 编辑数据方法
/// </summary>
private void EditData()
{
if (Grid1.SelectedRowIndexArray.Length == 0)
{
Alert.ShowInTop("请至少选择一条记录!", MessageBoxIcon.Warning);
return;
}
string Id = Grid1.SelectedRowID;
var projectPlan = BLL.ProjectPlanService.GetProjectPlanById(Id);
if (projectPlan != null)
{
if (!string.IsNullOrEmpty(projectPlan.WeldId))
{
this.hdWeldId.Text = projectPlan.WeldId;
Model.Weld_WeldInfo weldInfo = BLL.WeldInfoService.GetWeldInfoById(this.hdWeldId.Text);
if (weldInfo != null)
{
this.txtWeldCode.Text = weldInfo.WeldCode;
this.txtWeldName.Text = weldInfo.WeldName;
this.txtWeldSpec.Text = weldInfo.WeldSpec;
}
}
if (projectPlan.PlanAmount.HasValue)
{
this.txtPlanAmount.Text = projectPlan.PlanAmount.ToString();
}
this.txtWeldRequire.Text = projectPlan.WeldRequire;
this.txtRemark.Text = projectPlan.Remark;
hfFormID.Text = Id;
this.btnDelete.Enabled = true;
}
}
#endregion
#region
/// <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.ProjectMenuId, Const.BtnPlanEdit))
{
if (this.hdWeldId.Text == string.Empty)
{
Alert.ShowInTop("请选择焊材!", MessageBoxIcon.Warning);
return;
}
string projectId = Request.Params["ProjectId"];
var weld = BLL.ProjectPlanService.GetProjectPlanByWeldId(projectId, this.hdWeldId.Text);
decimal? planAmount= Funs.GetNewDecimal(this.txtPlanAmount.Text.Trim());
var stockIn = from x in Funs.DB.Weld_StockIn
where (x.Amount ?? 0 - x.UsingAmount ?? 0) > 0 && x.WeldId == this.hdWeldId.Text
select x;
if (stockIn.Count() > 0)
{
decimal totalStock = stockIn.Sum(x => x.Amount ?? 0 - x.UsingAmount ?? 0);
if (totalStock < planAmount)
{
PageContext.RegisterStartupScript(Confirm.GetShowReference("库存(" + totalStock + ")不足" + "点击确定继续保存,点取消放弃!",
String.Empty,
MessageBoxIcon.Question,
PageManager1.GetCustomEventReference(false, "Confirm_OK"), // 第一个参数 false 用来指定当前不是AJAX请求
PageManager1.GetCustomEventReference("Confirm_Cancel")));
}
else if (weld != null)
{
PageContext.RegisterStartupScript(Confirm.GetShowReference("此焊材的计划已录入,是否更新?" + "点击确定更新计划,点取消放弃!",
String.Empty,
MessageBoxIcon.Question,
PageManager1.GetCustomEventReference(false, "Confirm_OK"), // 第一个参数 false 用来指定当前不是AJAX请求
PageManager1.GetCustomEventReference("Confirm_Cancel")));
}
else
{
ComfirmSave(true);
}
}
else
{
Alert.ShowInTop("该焊材没有库存!", MessageBoxIcon.Warning);
return;
}
}
else
{
Alert.ShowInTop("您没有这个权限,请与管理员联系!", MessageBoxIcon.Warning);
return;
}
}
private void ComfirmSave(bool isComfirm)
{
if (isComfirm)
{
string strRowID = hfFormID.Text;
Model.Weld_ProjectPlan projectPlan = new Model.Weld_ProjectPlan();
projectPlan.ProjectId = Request.Params["ProjectId"];
if (!string.IsNullOrEmpty(this.hdWeldId.Text))
{
projectPlan.WeldId = this.hdWeldId.Text;
}
projectPlan.PlanAmount = Funs.GetNewDecimal(this.txtPlanAmount.Text.Trim());
projectPlan.WeldRequire = this.txtWeldRequire.Text.Trim();
projectPlan.Remark = this.txtRemark.Text.Trim();
if (string.IsNullOrEmpty(strRowID))
{
string projectId=Request.Params["ProjectId"];
var weld = BLL.ProjectPlanService.GetProjectPlanByWeldId(projectId, this.hdWeldId.Text);
if (weld == null)
{
strRowID = SQLHelper.GetNewID(typeof(Model.Weld_ProjectPlan));
projectPlan.ProjectPlanId = strRowID;
BLL.ProjectPlanService.AddProjectPlan(projectPlan);
BLL.Sys_LogService.AddLog(BLL.Const.System_7, this.CurrUser.LoginProjectId, this.CurrUser.UserId, "添加项目计划");
}
else
{
Alert.ShowInTop("该焊材已存在!", MessageBoxIcon.Warning);
return;
}
}
else
{
projectPlan.ProjectPlanId = strRowID;
BLL.ProjectPlanService.UpdateProjectPlan(projectPlan);
BLL.Sys_LogService.AddLog(BLL.Const.System_7, this.CurrUser.LoginProjectId, this.CurrUser.UserId, "修改项目计划");
}
// 重新绑定表格,并点击当前编辑或者新增的行
BindGrid();
ShowNotify("保存成功!", MessageBoxIcon.Success);
PageContext.RegisterStartupScript("onNewButtonClick();");
}
}
protected void PageManager1_CustomEvent(object sender, CustomEventArgs e)
{
if (e.EventArgument == "Confirm_OK")
{
ComfirmSave(true);
}
else if (e.EventArgument == "Confirm_Cancel")
{
ShowNotify("取消录入!");
}
}
#endregion
#region
/// <summary>
/// 判断是否可以删除
/// </summary>
/// <returns></returns>
private bool judgementDelete(string id, bool isShow)
{
string content = string.Empty;
//if (BLL.StockInitService.GetStockInitByWeldId(id) > 0)
//{
// content = "库存初始化中已经使用了该焊材,不能删除!";
//}
if (string.IsNullOrEmpty(content))
{
return true;
}
else
{
if (isShow)
{
Alert.ShowInTop(content, MessageBoxIcon.Error);
}
return false;
}
}
#endregion
#region
/// <summary>
/// 查询
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void TextBox_TextChanged(object sender, EventArgs e)
{
this.BindGrid();
}
protected void drpWeldType_SelectedIndexChanged(object sender, EventArgs e)
{
BindGrid();
}
#endregion
#region
/// <summary>
/// 查找焊材信息
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnSelectWeldId_Click(object sender, EventArgs e)
{
string window = String.Format("ProjectWeldMat.aspx", "编辑 - ");
PageContext.RegisterStartupScript(Window1.GetSaveStateReference(this.hdWeldId.ClientID) + Window1.GetShowReference(window));
}
/// <summary>
/// 关闭弹出窗口
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Window1_Close(object sender, WindowCloseEventArgs e)
{
if (!string.IsNullOrEmpty(this.hdWeldId.Text))//焊材ID
{
var weld = BLL.WeldInfoService.GetWeldInfoById(this.hdWeldId.Text);
if (weld != null)
{
this.txtWeldCode.Text = weld.WeldCode;
this.txtWeldName.Text = weld.WeldName;
this.txtWeldSpec.Text = weld.WeldSpec;
}
else
{
this.txtWeldCode.Text = string.Empty;
this.txtWeldName.Text = string.Empty;
this.txtWeldSpec.Text = string.Empty;
}
var planWeld = BLL.ProjectPlanService.GetProjectPlanByWeldId(Request.Params["ProjectId"], this.hdWeldId.Text);
if (planWeld != null)
{
hfFormID.Text = planWeld.ProjectPlanId;
txtPlanAmount.Text = planWeld.PlanAmount.HasValue ? planWeld.PlanAmount.Value.ToString() : "0";
txtWeldRequire.Text = planWeld.WeldRequire;
txtRemark.Text = planWeld.Remark;
}
}
else
{
this.txtWeldCode.Text = string.Empty;
this.txtWeldName.Text = string.Empty;
this.txtWeldSpec.Text = string.Empty;
}
}
#endregion
}
}