Basf_EProject/EProject/FineUIPro.Web/BaseInfo/QuantityDesctiption.aspx.cs

374 lines
14 KiB
C#
Raw Normal View History

2024-12-13 15:54:19 +08:00
using BLL;
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Model;
using static NPOI.HSSF.Util.HSSFColor;
namespace FineUIPro.Web.BaseInfo
{
public partial class QuantityDesctiption : PageBase
{
#region
/// <summary>
/// 加载页面
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
GetButtonPower();//按钮权限
ddlPageSize.SelectedValue = Grid1.PageSize.ToString();
//部门(查询)
this.drpDepartmentIdS.DataTextField = "DepartName";
this.drpDepartmentIdS.DataValueField = "DepartId";
this.drpDepartmentIdS.DataSource = BLL.DepartService.GetDepartList();
this.drpDepartmentIdS.DataBind();
Funs.FineUIPleaseSelect(this.drpDepartmentIdS);
//部门
this.drpDepartId.DataTextField = "DepartName";
this.drpDepartId.DataValueField = "DepartId";
this.drpDepartId.DataSource = BLL.DepartService.GetDepartList();
this.drpDepartId.DataBind();
Funs.FineUIPleaseSelect(this.drpDepartId);
//专业(查询)
this.drpDescipline.DataTextField = "DisciplinesWBSName";
this.drpDescipline.DataValueField = "DisciplinesWBSId";
this.drpDescipline.DataSource = from x in Funs.DB.Base_DisciplinesWBS select x;
this.drpDepartId.DataBind();
Funs.FineUIPleaseSelect(this.drpDescipline);
//专业
this.drpDisciplinesWBSId.DataTextField = "DisciplinesWBSName";
this.drpDisciplinesWBSId.DataValueField = "DisciplinesWBSId";
this.drpDisciplinesWBSId.DataSource = from x in Funs.DB.Base_DisciplinesWBS select x;
this.drpDisciplinesWBSId.DataBind();
Funs.FineUIPleaseSelect(this.drpDisciplinesWBSId);
// 绑定表格
BindGrid();
}
}
/// <summary>
/// 绑定数据
/// </summary>
private void BindGrid()
{
string strSql = @"SELECT qua.KeyId,
qua.DepartId,
qua.DisciplinesWBSId,
qua.QuantityDesctiption,
qua.PlanMHRsUnit,
d.DepartName,
wbs.DisciplinesWBSCode,
wbs.DisciplinesWBSName
FROM Base_QuantityDesctiption as qua
left join Base_Depart as d on d.DepartId = qua.DepartId
left join Base_DisciplinesWBS as wbs on wbs.DisciplinesWBSId = qua.DisciplinesWBSId where 1=1";
List<SqlParameter> listStr = new List<SqlParameter>();
if (this.drpDepartmentIdS.SelectedValue != BLL.Const._Null && !string.IsNullOrEmpty(this.drpDepartmentIdS.SelectedValue))
{
strSql += " AND qua.DepartId=@DepartId ";
listStr.Add(new SqlParameter("@DepartId", this.drpDepartmentIdS.SelectedValue));
}
if (this.drpDescipline.SelectedValue != BLL.Const._Null && !string.IsNullOrEmpty(this.drpDescipline.SelectedValue))
{
strSql += " AND qua.DisciplinesWBSId=@disciplinesWBSId ";
listStr.Add(new SqlParameter("@disciplinesWBSId", this.drpDescipline.SelectedValue));
}
SqlParameter[] parameter = listStr.ToArray();
DataTable tb = SQLHelper.GetDataTableRunText(strSql, parameter);
Grid1.RecordCount = tb.Rows.Count;
var table = this.GetPagedDataTable(Grid1, tb);
Grid1.DataSource = table;
Grid1.DataBind();
}
/// <summary>
/// 改变索引事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Grid1_PageIndexChange(object sender, GridPageEventArgs e)
{
Grid1.PageIndex = e.NewPageIndex;
BindGrid();
}
#endregion
#region
/// <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();
}
#endregion
#region
/// <summary>
/// 增加按钮
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnAdd_Click(object sender, EventArgs e)
{
EmptyText();
}
#endregion
#region
/// <summary>
/// 清空文本框
/// </summary>
private void EmptyText()
{
this.hfFormID.Text = string.Empty;
this.drpDepartId.SelectedValue = Const._Null;
this.drpDisciplinesWBSId.SelectedValue = Const._Null;
this.txtDisciplinesWBSCode.Text = string.Empty;
this.txtQuantityDesctiption.Text = string.Empty;
this.txtPlanMHRsUnit.Text = string.Empty;
this.btnDelete.Enabled = false;
}
#endregion
#region
/// <summary>
/// 选择行事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Grid1_RowSelect(object sender, GridRowSelectEventArgs e)
{
EditData();
}
#endregion
#region
/// <summary>
/// 删除
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnDelete_Click(object sender, EventArgs e)
{
BLL.QuantityDesctiptionService.DeleteQuantityDesctiptionById(hfFormID.Text);
BLL.Sys_LogService.AddLog(this.CurrUser.UserId, "Delete the Key Quantity-QuantityDesctiption");
// 重新绑定表格,并模拟点击[新增按钮]
BindGrid();
//PageContext.RegisterStartupScript("onNewButtonClick();");
}
/// <summary>
/// 右键删除事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnMenuDelete_Click(object sender, EventArgs e)
{
this.DeleteData();
}
/// <summary>
/// 删除方法
/// </summary>
private void DeleteData()
{
if (Grid1.SelectedRowIndexArray.Length > 0)
{
foreach (int rowIndex in Grid1.SelectedRowIndexArray)
{
string rowID = Grid1.DataKeys[rowIndex][0].ToString();
BLL.QuantityDesctiptionService.DeleteQuantityDesctiptionById(rowID);
BLL.Sys_LogService.AddLog(this.CurrUser.UserId, "Delete the Key Quantity-QuantityDesctiption");
}
BindGrid();
EmptyText();
//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("Please select at least one record", MessageBoxIcon.Warning);
return;
}
string Id = Grid1.SelectedRowID;
var cons = BLL.QuantityDesctiptionService.GetQuantityDesctiptionById(Id);
if (cons != null)
{
if (!string.IsNullOrEmpty(cons.DepartId))
{
this.drpDepartId.SelectedValue = cons.DepartId;
}
if (!string.IsNullOrEmpty(cons.DisciplinesWBSId))
{
this.drpDisciplinesWBSId.SelectedValue = cons.DisciplinesWBSId;
var wbs = BLL.DisciplinesWBSService.GetDisciplinesWBSById(cons.DisciplinesWBSId);
if (wbs != null)
{
this.txtDisciplinesWBSCode.Text = wbs.DisciplinesWBSCode;
}
this.txtQuantityDesctiption.Text = cons.QuantityDesctiption;
this.txtPlanMHRsUnit.Text = cons.PlanMHRsUnit.HasValue ? cons.PlanMHRsUnit.ToString() : "";
}
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)
{
string strRowID = hfFormID.Text;
//if (this.drpDepartId.SelectedValue == BLL.Const._Null)
//{
// ShowNotify("Please select Department", MessageBoxIcon.Warning);
// return;
//}
if (this.drpDisciplinesWBSId.SelectedValue == BLL.Const._Null)
{
ShowNotify("Please select Descipline", MessageBoxIcon.Warning);
return;
}
if (!BLL.QuantityDesctiptionService.IsExitQuantityDesctiption(this.drpDepartId.SelectedValue, this.drpDisciplinesWBSId.SelectedValue, this.txtQuantityDesctiption.Text.Trim(), strRowID))
{
Model.Base_QuantityDesctiption cons = new Model.Base_QuantityDesctiption
{
QuantityDesctiption = this.txtQuantityDesctiption.Text.Trim(),
PlanMHRsUnit = Funs.GetNewDecimal(this.txtPlanMHRsUnit.Text)
};
if (this.drpDepartId.SelectedValue != BLL.Const._Null && !string.IsNullOrEmpty(this.drpDepartId.SelectedValue))
{
cons.DepartId = this.drpDepartId.SelectedValue;
}
if (this.drpDisciplinesWBSId.SelectedValue != BLL.Const._Null && !string.IsNullOrEmpty(this.drpDisciplinesWBSId.SelectedValue))
{
cons.DisciplinesWBSId = this.drpDisciplinesWBSId.SelectedValue;
}
if (string.IsNullOrEmpty(strRowID))
{
cons.KeyId = SQLHelper.GetNewID(typeof(Model.Base_QuantityDesctiption));
BLL.QuantityDesctiptionService.AddQuantityDesctiption(cons);
BLL.Sys_LogService.AddLog(this.CurrUser.UserId, "Add the Key Quantity-QuantityDesctiption");
ShowNotify("Save Successfully!", MessageBoxIcon.Success);
}
else
{
cons.KeyId = strRowID;
BLL.QuantityDesctiptionService.UpdateQuantityDesctiption(cons);
BLL.Sys_LogService.AddLog(this.CurrUser.UserId, "Modify the Key Quantity-QuantityDesctiption");
ShowNotify("Save Successfully!", MessageBoxIcon.Success);
}
this.SimpleForm1.Reset();
// 重新绑定表格,并点击当前编辑或者新增的行
BindGrid();
//PageContext.RegisterStartupScript(String.Format("F('{0}').selectRow('{1}');", Grid1.ClientID, cons.DisciplinesWBSId));
PageContext.RegisterStartupScript("onNewButtonClick();");
}
else
{
Alert.ShowInTop("The Quantity Desctiption already exists", MessageBoxIcon.Warning);
}
}
#endregion
#region
/// <summary>
/// 查询
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Text_TextChanged(object sender, EventArgs e)
{
BindGrid();
}
#endregion
#region
/// <summary>
/// 菜单按钮权限
/// </summary>
private void GetButtonPower()
{
var buttonList = BLL.CommonService.GetAllButtonList(this.CurrUser.UserId, BLL.Const.QuantityDesctiptionMenuId);
if (buttonList.Count() > 0)
{
if (buttonList.Contains(BLL.Const.BtnAdd))
{
this.btnAdd.Hidden = false;
}
if (buttonList.Contains(BLL.Const.BtnModify))
{
this.btnMenuEdit.Hidden = false;
}
if (buttonList.Contains(BLL.Const.BtnSave))
{
this.btnSave.Hidden = false;
}
if (buttonList.Contains(BLL.Const.BtnDelete))
{
this.btnDelete.Hidden = false;
}
}
}
#endregion
protected void drpDisciplinesWBSId_SelectedIndexChanged(object sender, EventArgs e)
{
this.txtDisciplinesWBSCode.Text = string.Empty;
if (this.drpDisciplinesWBSId.SelectedValue != BLL.Const._Null && !string.IsNullOrEmpty(this.drpDisciplinesWBSId.SelectedValue))
{
var dis = BLL.DisciplinesWBSService.GetDisciplinesWBSById(this.drpDisciplinesWBSId.SelectedValue);
if (dis != null)
{
this.txtDisciplinesWBSCode.Text = dis.DisciplinesWBSCode;
}
}
}
}
}