328 lines
12 KiB
C#
328 lines
12 KiB
C#
|
using System;
|
|||
|
using System.Collections.Generic;
|
|||
|
using System.Linq;
|
|||
|
using BLL;
|
|||
|
using System.Data.SqlClient;
|
|||
|
using System.Data;
|
|||
|
|
|||
|
namespace FineUIPro.Web.HJGLServer.BaseInfo
|
|||
|
{
|
|||
|
public partial class MaterialGroup : 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();
|
|||
|
this.drpMaterialClassId.DataTextField = "MaterialClass";
|
|||
|
this.drpMaterialClassId.DataValueField = "MaterialClassId";
|
|||
|
this.drpMaterialClassId.DataSource = BLL.HJGL_MaterialClassService.GetMaterialClassList();
|
|||
|
this.drpMaterialClassId.DataBind();
|
|||
|
Funs.FineUIPleaseSelect(this.drpMaterialClassId);
|
|||
|
// 绑定表格
|
|||
|
BindGrid();
|
|||
|
}
|
|||
|
}
|
|||
|
#endregion
|
|||
|
|
|||
|
#region 绑定数据
|
|||
|
/// <summary>
|
|||
|
/// 绑定数据
|
|||
|
/// </summary>
|
|||
|
private void BindGrid()
|
|||
|
{
|
|||
|
string strSql = @"SELECT MG.MaterialGroupId,MG.MaterialGroupCode,MG.MaterialGroup,MG.Remark,MG.MaterialClassId,MC.MaterialClass"
|
|||
|
+ @" FROM dbo.HJGL_BS_MaterialGroup AS MG"
|
|||
|
+ @" LEFT JOIN HJGL_BS_MaterialClass AS MC ON MC.MaterialClassId = MG.MaterialClassId "
|
|||
|
+ @" WHERE 1=1";
|
|||
|
List<SqlParameter> listStr = new List<SqlParameter>();
|
|||
|
if (!string.IsNullOrEmpty(this.txtMaterialGroupCodeS.Text.Trim()))
|
|||
|
{
|
|||
|
strSql += " AND MG.MaterialGroupCode LIKE @MaterialGroupCode";
|
|||
|
listStr.Add(new SqlParameter("@MaterialGroupCode", "%" + this.txtMaterialGroupCodeS.Text.Trim() + "%"));
|
|||
|
}
|
|||
|
if (!string.IsNullOrEmpty(this.txtMaterialGroupS.Text.Trim()))
|
|||
|
{
|
|||
|
strSql += " AND MG.MaterialGroup LIKE @MaterialGroup";
|
|||
|
listStr.Add(new SqlParameter("@MaterialGroup", "%" + this.txtMaterialGroupS.Text.Trim() + "%"));
|
|||
|
}
|
|||
|
if (!string.IsNullOrEmpty(this.txtMaterialClassS.Text.Trim()))
|
|||
|
{
|
|||
|
strSql += " AND MC.MaterialClass LIKE @MaterialClass";
|
|||
|
listStr.Add(new SqlParameter("@MaterialClass", "%" + this.txtMaterialClassS.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
|
|||
|
|
|||
|
#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.HJGL_MaterialGroupMenuId, Const.BtnDelete))
|
|||
|
{
|
|||
|
if (judgementDelete(hfFormID.Text, true))
|
|||
|
{
|
|||
|
BLL.HJGL_MaterialGroupService.DeleteMaterialGroupById(hfFormID.Text);
|
|||
|
BLL.Sys_LogService.AddLog(BLL.Const.System_2, 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.HJGL_MaterialGroupMenuId, 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.HJGL_MaterialGroupService.DeleteMaterialGroupById(rowID);
|
|||
|
BLL.Sys_LogService.AddLog(BLL.Const.System_2, this.CurrUser.LoginProjectId, this.CurrUser.UserId, "删除焊评材质组别");
|
|||
|
Alert.ShowInTop("删除完成!", 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)
|
|||
|
{
|
|||
|
if (CommonService.GetAllButtonPowerList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, Const.HJGL_MaterialGroupMenuId, Const.BtnModify))
|
|||
|
{
|
|||
|
this.EditData();
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
Alert.ShowInTop("您没有这个权限,请与管理员联系!", MessageBoxIcon.Warning);
|
|||
|
return;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 编辑数据方法
|
|||
|
/// </summary>
|
|||
|
private void EditData()
|
|||
|
{
|
|||
|
if (Grid1.SelectedRowIndexArray.Length == 0)
|
|||
|
{
|
|||
|
Alert.ShowInTop("请至少选择一条记录!", MessageBoxIcon.Warning);
|
|||
|
return;
|
|||
|
}
|
|||
|
string Id = Grid1.SelectedRowID;
|
|||
|
var materialGroup = BLL.HJGL_MaterialGroupService.GetMaterialGroupById(Id);
|
|||
|
if (materialGroup != null)
|
|||
|
{
|
|||
|
this.txtMaterialGroupCode.Text = materialGroup.MaterialGroupCode;
|
|||
|
this.txtMaterialGroup.Text = materialGroup.MaterialGroup;
|
|||
|
this.txtRemark.Text = materialGroup.Remark;
|
|||
|
if (!string.IsNullOrEmpty(materialGroup.MaterialClassId))
|
|||
|
{
|
|||
|
this.drpMaterialClassId.SelectedValue = materialGroup.MaterialClassId.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)
|
|||
|
{
|
|||
|
if (CommonService.GetAllButtonPowerList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, Const.HJGL_MaterialGroupMenuId, Const.BtnSave))
|
|||
|
{
|
|||
|
string strRowID = hfFormID.Text;
|
|||
|
if (BLL.HJGL_MaterialGroupService.IsExitMaterialGroupCode(this.txtMaterialGroupCode.Text.Trim(), strRowID))
|
|||
|
{
|
|||
|
Alert.ShowInTop("此组别代号已存在!", MessageBoxIcon.Warning);
|
|||
|
return;
|
|||
|
}
|
|||
|
Model.HJGL_BS_MaterialGroup materialGroup = new Model.HJGL_BS_MaterialGroup();
|
|||
|
materialGroup.MaterialGroupCode = this.txtMaterialGroupCode.Text.Trim();
|
|||
|
materialGroup.MaterialGroup = this.txtMaterialGroupCode.Text.Trim();
|
|||
|
materialGroup.Remark = this.txtRemark.Text.Trim();
|
|||
|
if (this.drpMaterialClassId.SelectedValue != BLL.Const._Null)
|
|||
|
{
|
|||
|
materialGroup.MaterialClassId = this.drpMaterialClassId.SelectedValue;
|
|||
|
}
|
|||
|
if (string.IsNullOrEmpty(strRowID))
|
|||
|
{
|
|||
|
materialGroup.MaterialGroupId = SQLHelper.GetNewID(typeof(Model.HJGL_BS_MaterialGroup));
|
|||
|
BLL.HJGL_MaterialGroupService.AddMaterialGroup(materialGroup);
|
|||
|
BLL.Sys_LogService.AddLog(BLL.Const.System_2, this.CurrUser.LoginProjectId, this.CurrUser.UserId, "添加焊评材质组别");
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
materialGroup.MaterialGroupId = strRowID;
|
|||
|
BLL.HJGL_MaterialGroupService.UpdateMaterialGroup(materialGroup);
|
|||
|
BLL.Sys_LogService.AddLog(BLL.Const.System_2, this.CurrUser.LoginProjectId, this.CurrUser.UserId, "修改焊评材质组别");
|
|||
|
}
|
|||
|
// 重新绑定表格,并点击当前编辑或者新增的行
|
|||
|
BindGrid();
|
|||
|
|
|||
|
Alert.ShowInTop("提交成功!", MessageBoxIcon.Success);
|
|||
|
PageContext.RegisterStartupScript("onNewButtonClick();");
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
Alert.ShowInTop("您没有这个权限,请与管理员联系!", MessageBoxIcon.Warning);
|
|||
|
return;
|
|||
|
}
|
|||
|
}
|
|||
|
#endregion
|
|||
|
|
|||
|
#region 判断是否可删除
|
|||
|
/// <summary>
|
|||
|
/// 判断是否可以删除
|
|||
|
/// </summary>
|
|||
|
/// <returns></returns>
|
|||
|
private bool judgementDelete(string id, bool isShow)
|
|||
|
{
|
|||
|
string content = string.Empty;
|
|||
|
if (BLL.HJGL_MaterialService.GetSteelByMaterialGroup(id).Count() > 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();
|
|||
|
}
|
|||
|
#endregion
|
|||
|
}
|
|||
|
}
|