Basf_EProject/EProject/FineUIPro.Web/EditorManage/KeyQuantityEditorEdit.aspx.cs

420 lines
19 KiB
C#

using BLL;
using NPOI.SS.Formula.Functions;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
namespace FineUIPro.Web.EditorManage
{
public partial class KeyQuantityEditorEdit : PageBase
{
#region
/// <summary>
/// 主键
/// </summary>
public string KeyQuantityId
{
get
{
return (string)ViewState["KeyQuantityId"];
}
set
{
ViewState["KeyQuantityId"] = value;
}
}
/// <summary>
/// 项目Id
/// </summary>
public string ProjectId
{
get
{
return (string)ViewState["ProjectId"];
}
set
{
ViewState["ProjectId"] = 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();
//BindGrid();
string view = Request.Params["view"];
if (view == "1")
{
this.btnSave.Hidden = true;
}
else
{
GetButtonPower();
}
BLL.QuantityDesctiptionService.InitIdentifierDropDownList(this.drpIdentifier, true);
Funs.FineUIPleaseSelect(this.drpDescipline);
Funs.FineUIPleaseSelect(this.drpQuantityDesctiption);
Funs.FineUIPleaseSelect(this.drpPlanMHRsUnit);
this.ProjectId = Request.Params["eProjectId"];
this.KeyQuantityId = Request.Params["keyQuantityId"];
if (!string.IsNullOrEmpty(this.KeyQuantityId))
{
Model.Editor_KeyQuantity keyQuantity = BLL.KeyQuantityService.GetKeyQuantityById(this.KeyQuantityId);
if (keyQuantity != null)
{
this.ProjectId = keyQuantity.EProjectId;
//this.drpKeyId.Value = keyQuantity.KeyId;
//var key = BLL.QuantityDesctiptionService.GetQuantityDesctiptionById(this.drpKeyId.Value);
//if (key != null)
//{
// if (!string.IsNullOrEmpty(key.DisciplinesWBSId))
// {
// var wbs = BLL.DisciplinesWBSService.GetDisciplinesWBSById(key.DisciplinesWBSId);
// if (wbs != null)
// {
// this.txtIdentifier.Text = wbs.DisciplinesWBSCode;
// this.txtDescipline.Text = wbs.DisciplinesWBSName;
// }
// this.txtPlanMHRsSummary.Text = BLL.KeyQuantityService.GetSumPlanMHRsByKeyId(this.drpKeyId.Value).ToString();
// double? actualHoursSum = (from x in Funs.DB.ManHours_Actual
// where x.EProjectId == this.ProjectId
// && x.Discipline == wbs.DisciplinesWBSName
// select x.Hours).Sum();
// this.txtActualMHRs.Text = actualHoursSum.ToString();
// }
// txtQuantityDesctiption.Text = key.QuantityDesctiption;
// txtPlanMHRsUnit.Text = key.PlanMHRsUnit.HasValue ? key.PlanMHRsUnit.ToString() : "";
//}
if (!string.IsNullOrEmpty(keyQuantity.Identifier))
{
this.drpIdentifier.Items.Clear();
BLL.QuantityDesctiptionService.InitIdentifierDropDownList(this.drpIdentifier, true);
this.drpIdentifier.SelectedValue = keyQuantity.Identifier;
if (!string.IsNullOrEmpty(keyQuantity.Descipline))
{
this.drpDescipline.Items.Clear();
BLL.QuantityDesctiptionService.InitDesciplineDropDownList(this.drpDescipline, true, keyQuantity.Identifier);
this.drpDescipline.SelectedValue = keyQuantity.Descipline;
if (!string.IsNullOrEmpty(keyQuantity.QuantityDesctiption))
{
this.drpQuantityDesctiption.Items.Clear();
BLL.QuantityDesctiptionService.InitQuantityDesctiptionDropDownList(this.drpQuantityDesctiption, true, keyQuantity.Identifier, keyQuantity.Descipline);
this.drpQuantityDesctiption.SelectedValue = keyQuantity.QuantityDesctiption;
if (keyQuantity.PlanMHRsUnit.HasValue)
{
this.drpPlanMHRsUnit.Items.Clear();
BLL.QuantityDesctiptionService.InitPlanMHRsUnitDropDownList(this.drpPlanMHRsUnit, true, keyQuantity.Identifier, keyQuantity.Descipline, keyQuantity.QuantityDesctiption);
this.drpPlanMHRsUnit.SelectedValue = keyQuantity.PlanMHRsUnit.ToString();
}
}
}
}
this.txtPlanMHRsSummary.Text = BLL.KeyQuantityService.GetSumPlanMHRsByKeyId(keyQuantity.EProjectId,keyQuantity.Identifier, keyQuantity.Descipline).ToString();
this.txtInputQuantity.Text = keyQuantity.InputQuantity.HasValue ? keyQuantity.InputQuantity.ToString() : "";
this.txtPlanMHRs.Text = keyQuantity.PlanMHRs.HasValue ? keyQuantity.PlanMHRs.ToString() : "";
double? actualHoursSum = (from x in Funs.DB.ManHours_Actual
where x.EProjectId == this.ProjectId
&& x.Discipline == keyQuantity.Descipline
select x.Hours).Sum();
this.txtActualMHRs.Text = actualHoursSum.ToString();
}
}
}
}
#endregion
#region
/// <summary>
/// 数据绑定
/// </summary>
//private void BindGrid()
//{
// string strSql = @"SELECT qd.KeyId,
// qd.DepartId,
// qd.DisciplinesWBSId,
// qd.QuantityDesctiption,
// qd.PlanMHRsUnit,
// d.DepartName,
// wbs.DisciplinesWBSCode,
// wbs.DisciplinesWBSName
// FROM Base_QuantityDesctiption qd
// left join Base_Depart as d on qd.DepartId = d.DepartId
// left join Base_DisciplinesWBS as wbs on wbs.DisciplinesWBSId = qd.DisciplinesWBSId WHERE 1=1";
// List<SqlParameter> listStr = new List<SqlParameter>();
// if (!string.IsNullOrEmpty(this.txtSearch.Text.Trim()))
// {
// strSql += " AND d.DepartName like @DepartName ";
// listStr.Add(new SqlParameter("@DepartName", "%" + this.txtSearch.Text.Trim() + "%"));
// }
// SqlParameter[] parameter = listStr.ToArray();
// DataTable tb = SQLHelper.GetDataTableRunText(strSql, parameter);
// // 2.获取当前分页数据
// //var table = this.GetPagedDataTable(Grid1, tb1);
// Grid1.RecordCount = tb.Rows.Count;
// 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_Sort(object sender, FineUIPro.GridSortEventArgs e)
//{
// Grid1.SortDirection = e.SortDirection;
// Grid1.SortField = e.SortField;
// BindGrid();
//}
/// <summary>
/// 筛选
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
//protected void txtSearch_TextChanged(object sender, EventArgs e)
//{
// BindGrid();
//}
#endregion
#region
protected void btnSave_Click(object sender, EventArgs e)
{
if (this.drpIdentifier.SelectedValue == BLL.Const._Null || string.IsNullOrEmpty(this.drpIdentifier.SelectedValue))
{
ShowAlert("Please select Identifier!", MessageBoxIcon.Warning);
return;
}
if (this.drpDescipline.SelectedValue == BLL.Const._Null || string.IsNullOrEmpty(this.drpDescipline.SelectedValue))
{
ShowAlert("Please select Descipline!", MessageBoxIcon.Warning);
return;
}
if (this.drpQuantityDesctiption.SelectedValue == BLL.Const._Null || string.IsNullOrEmpty(this.drpQuantityDesctiption.SelectedValue))
{
ShowAlert("Please select Quantity Desctiption!", MessageBoxIcon.Warning);
return;
}
Model.Editor_KeyQuantity newKeyQuantity = new Model.Editor_KeyQuantity();
//newKeyQuantity.KeyId = this.drpKeyId.Value;
newKeyQuantity.InputQuantity = Funs.GetNewDecimal(this.txtInputQuantity.Text);
newKeyQuantity.PlanMHRs = Funs.GetNewDecimal(this.txtPlanMHRs.Text);
newKeyQuantity.Identifier = this.drpIdentifier.SelectedText;
newKeyQuantity.Descipline = this.drpDescipline.SelectedText;
newKeyQuantity.QuantityDesctiption = this.drpQuantityDesctiption.SelectedText;
newKeyQuantity.PlanMHRsUnit = Funs.GetNewDecimal(this.drpPlanMHRsUnit.SelectedText);
if (!string.IsNullOrEmpty(this.KeyQuantityId))
{
newKeyQuantity.KeyQuantityId = this.KeyQuantityId;
BLL.KeyQuantityService.UpdateKeyQuantity(newKeyQuantity);
BLL.Sys_LogService.AddLog(this.CurrUser.UserId, "Modify Key Quantity Editor information!");
ShowNotify("Save Successfully!", MessageBoxIcon.Success);
}
else
{
newKeyQuantity.EProjectId = ProjectId;
this.KeyQuantityId = SQLHelper.GetNewID(typeof(Model.Editor_KeyQuantity));
newKeyQuantity.KeyQuantityId = this.KeyQuantityId;
BLL.KeyQuantityService.AddKeyQuantity(newKeyQuantity);
BLL.Sys_LogService.AddLog(this.CurrUser.UserId, "Add Key Quantity Editor information!");
ShowNotify("Save Successfully!", MessageBoxIcon.Success);
}
PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference());
}
#endregion
#region DropDownList下拉选择事件
/// <summary>
/// 部门下拉选择事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
//protected void drpKeyId_TextChanged(object sender, EventArgs e)
//{
// this.txtIdentifier.Text = string.Empty;
// this.txtDescipline.Text = string.Empty;
// this.txtQuantityDesctiption.Text = string.Empty;
// this.txtPlanMHRsUnit.Text = string.Empty;
// this.txtPlanMHRsSummary.Text = string.Empty;
// if (!string.IsNullOrEmpty(this.drpKeyId.Value))
// {
// var key = BLL.QuantityDesctiptionService.GetQuantityDesctiptionById(this.drpKeyId.Value);
// if (key != null)
// {
// if (!string.IsNullOrEmpty(key.DisciplinesWBSId))
// {
// var wbs = BLL.DisciplinesWBSService.GetDisciplinesWBSById(key.DisciplinesWBSId);
// if (wbs != null)
// {
// this.txtIdentifier.Text = wbs.DisciplinesWBSCode;
// this.txtDescipline.Text = wbs.DisciplinesWBSName;
// }
// decimal? s = BLL.KeyQuantityService.GetSumPlanMHRsByKeyId(this.drpKeyId.Value);
// this.txtPlanMHRsSummary.Text = (s + Funs.GetNewDecimal(this.txtPlanMHRs.Text)).ToString();
// double? actualHoursSum = (from x in Funs.DB.ManHours_Actual
// where x.EProjectId == this.ProjectId
// && x.Discipline == wbs.DisciplinesWBSName
// select x.Hours).Sum();
// this.txtActualMHRs.Text = actualHoursSum.ToString();
// }
// txtQuantityDesctiption.Text = key.QuantityDesctiption;
// txtPlanMHRsUnit.Text = key.PlanMHRsUnit.HasValue ? key.PlanMHRsUnit.ToString() : "";
// }
// }
//}
/// <summary>
/// Input Quantity输入事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void txtInputQuantity_TextChanged(object sender, EventArgs e)
{
this.txtPlanMHRs.Text = string.Empty;
this.txtPlanMHRsSummary.Text = string.Empty;
if (!string.IsNullOrEmpty(this.txtInputQuantity.Text.Trim()))
{
this.txtPlanMHRs.Text = (Funs.GetNewDecimal(this.txtInputQuantity.Text) * Funs.GetNewDecimal(this.drpPlanMHRsUnit.SelectedText)).ToString();
decimal? s = BLL.KeyQuantityService.GetSumPlanMHRsByKeyId(this.ProjectId ,this.drpIdentifier.SelectedValue, this.drpDescipline.SelectedValue);
if (s > 0)
{
this.txtPlanMHRsSummary.Text = (s + Funs.GetNewDecimal(this.txtPlanMHRs.Text)).ToString();
}
else
{
this.txtPlanMHRsSummary.Text = this.txtPlanMHRs.Text;
}
}
}
/// <summary>
/// Identifier 下拉选择
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void drpIdentifier_SelectedIndexChanged(object sender, EventArgs e)
{
drpDescipline.Items.Clear();
if (this.drpIdentifier.SelectedValue != BLL.Const._Null && !string.IsNullOrEmpty(this.drpIdentifier.SelectedValue))
{
BLL.QuantityDesctiptionService.InitDesciplineDropDownList(this.drpDescipline, true, this.drpIdentifier.SelectedValue);
}
else
{
Funs.FineUIPleaseSelect(this.drpDescipline);
}
this.drpDescipline.SelectedIndex = 0;
}
/// <summary>
/// Descipline下拉选择
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void drpDescipline_SelectedIndexChanged(object sender, EventArgs e)
{
this.txtActualMHRs.Text = string.Empty;
drpQuantityDesctiption.Items.Clear();
if (this.drpDescipline.SelectedValue != BLL.Const._Null && !string.IsNullOrEmpty(this.drpDescipline.SelectedValue))
{
BLL.QuantityDesctiptionService.InitQuantityDesctiptionDropDownList(this.drpQuantityDesctiption, true, this.drpIdentifier.SelectedValue, this.drpDescipline.SelectedValue);
double? actualHoursSum = (from x in Funs.DB.ManHours_Actual
where x.EProjectId == this.ProjectId
&& x.Discipline == this.drpDescipline.SelectedValue
select x.Hours).Sum();
this.txtActualMHRs.Text = actualHoursSum.ToString();
}
else
{
Funs.FineUIPleaseSelect(this.drpQuantityDesctiption);
}
this.drpQuantityDesctiption.SelectedIndex = 0;
}
/// <summary>
/// Quantity Desctiption下拉选择
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void drpQuantityDesctiption_SelectedIndexChanged(object sender, EventArgs e)
{
this.drpPlanMHRsUnit.Items.Clear();
if (this.drpQuantityDesctiption.SelectedValue != BLL.Const._Null && !string.IsNullOrEmpty(this.drpQuantityDesctiption.SelectedValue))
{
BLL.QuantityDesctiptionService.InitPlanMHRsUnitDropDownList(this.drpPlanMHRsUnit, true, this.drpIdentifier.SelectedValue, this.drpDescipline.SelectedValue, this.drpQuantityDesctiption.SelectedValue);
}
else
{
Funs.FineUIPleaseSelect(this.drpPlanMHRsUnit);
}
this.drpPlanMHRsUnit.SelectedIndex = 0;
}
#endregion
#region
/// <summary>
/// 菜单按钮权限
/// </summary>
private void GetButtonPower()
{
var buttonList = BLL.CommonService.GetAllButtonList(this.CurrUser.UserId, BLL.Const.KeyQuantityMenuId);
if (buttonList.Count() > 0)
{
if (buttonList.Contains(BLL.Const.BtnSave))
{
this.btnSave.Hidden = false;
}
}
}
#endregion
}
}