initProject
This commit is contained in:
@@ -0,0 +1,320 @@
|
||||
using BLL;
|
||||
using System;
|
||||
using System.Data;
|
||||
using System.Linq;
|
||||
using System.Collections.Generic;
|
||||
using System.Data.SqlClient;
|
||||
|
||||
namespace FineUIPro.Web.BaseInfo
|
||||
{
|
||||
public partial class Department : 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();
|
||||
|
||||
BLL.DepartService.InitSupDepartDropDownList(this.drpSupCheckItem, true);
|
||||
BLL.Sys_UserService.InitUserDropDownList(drpDepartLeader, true);
|
||||
// 绑定表格
|
||||
BindGrid();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 绑定数据
|
||||
/// </summary>
|
||||
private void BindGrid()
|
||||
{
|
||||
string strSql = @"SELECT dep.DepartId,dep.DepartCode,dep.DepartName,dep.Remark ,
|
||||
(SELECT u.UserName FROM dbo.Sys_User u WHERE u.UserId=dep.DepartLeader) AS DepartLeader
|
||||
FROM dbo.Base_Depart dep WHERE 1=1";
|
||||
List<SqlParameter> listStr = new List<SqlParameter>();
|
||||
if (!string.IsNullOrEmpty(txtDepartNameS.Text))
|
||||
{
|
||||
strSql += " AND dep.DepartName like @DepartName";
|
||||
listStr.Add(new SqlParameter("@DepartName", "%" + this.txtDepartNameS.Text.Trim() + "%"));
|
||||
}
|
||||
strSql += " ORDER BY dep.DepartName";
|
||||
|
||||
SqlParameter[] parameter = listStr.ToArray();
|
||||
// 2.获取当前分页数据
|
||||
DataTable tb = SQLHelper.GetDataTableRunText(strSql, parameter);
|
||||
Grid1.RecordCount = tb.Rows.Count;
|
||||
var table = this.GetPagedDataTable(Grid1, tb);
|
||||
Grid1.DataSource = table;
|
||||
Grid1.DataBind();
|
||||
}
|
||||
|
||||
protected void btnSearch_Click(object sender, EventArgs e)
|
||||
{
|
||||
BindGrid();
|
||||
}
|
||||
|
||||
/// <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 btnDelete_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (judgementDelete(hfFormID.Text))
|
||||
{
|
||||
BLL.DepartService.DeleteDepartById(hfFormID.Text);
|
||||
BLL.Sys_LogService.AddLog(this.CurrUser.UserId, "Delete department");
|
||||
// 重新绑定表格,并模拟点击[新增按钮]
|
||||
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();
|
||||
if (judgementDelete(rowID))
|
||||
{
|
||||
BLL.DepartService.DeleteDepartById(rowID);
|
||||
BLL.Sys_LogService.AddLog(this.CurrUser.UserId, "Delete department");
|
||||
}
|
||||
}
|
||||
BindGrid();
|
||||
}
|
||||
}
|
||||
#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 depart = BLL.DepartService.GetDepartById(Id);
|
||||
if (depart != null)
|
||||
{
|
||||
this.txtDepartCode.Text = depart.DepartCode;
|
||||
this.txtDepartName.Text = depart.DepartName;
|
||||
this.txtRemark.Text = depart.Remark;
|
||||
if (!string.IsNullOrEmpty(depart.DepartLeader))
|
||||
{
|
||||
this.drpDepartLeader.SelectedValue = depart.DepartLeader;
|
||||
}
|
||||
if (!string.IsNullOrEmpty(depart.SupCheckItem))
|
||||
{
|
||||
this.drpSupCheckItem.SelectedValue = depart.SupCheckItem;
|
||||
}
|
||||
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 (!BLL.DepartService.IsExitDepartCode(this.txtDepartCode.Text.Trim(), strRowID) && !BLL.DepartService.IsExitDepartName(this.txtDepartName.Text.Trim(), strRowID))
|
||||
{
|
||||
Model.Base_Depart depart = new Model.Base_Depart
|
||||
{
|
||||
DepartCode = this.txtDepartCode.Text.Trim(),
|
||||
DepartName = this.txtDepartName.Text.Trim(),
|
||||
Remark = this.txtRemark.Text.Trim()
|
||||
};
|
||||
if (this.drpSupCheckItem.SelectedValue != BLL.Const._Null)
|
||||
{
|
||||
depart.SupCheckItem = this.drpSupCheckItem.SelectedValue;
|
||||
}
|
||||
else
|
||||
{
|
||||
depart.SupCheckItem = "0";
|
||||
}
|
||||
|
||||
if (this.drpDepartLeader.SelectedValue != BLL.Const._Null)
|
||||
{
|
||||
depart.DepartLeader = this.drpDepartLeader.SelectedValue;
|
||||
}
|
||||
else
|
||||
{
|
||||
depart.DepartLeader = null;
|
||||
}
|
||||
if (string.IsNullOrEmpty(strRowID))
|
||||
{
|
||||
depart.DepartId = SQLHelper.GetNewID(typeof(Model.Base_Depart));
|
||||
BLL.DepartService.AddDepart(depart);
|
||||
BLL.Sys_LogService.AddLog(this.CurrUser.UserId, "Add the department");
|
||||
ShowNotify("Save Successfully!", MessageBoxIcon.Success);
|
||||
}
|
||||
else
|
||||
{
|
||||
depart.DepartId = strRowID;
|
||||
BLL.DepartService.UpdateDepart(depart);
|
||||
BLL.Sys_LogService.AddLog(this.CurrUser.UserId, "Modify the department");
|
||||
ShowNotify("Save Successfully!", MessageBoxIcon.Success);
|
||||
}
|
||||
this.SimpleForm1.Reset();
|
||||
// 重新绑定表格,并点击当前编辑或者新增的行
|
||||
BindGrid();
|
||||
//PageContext.RegisterStartupScript(String.Format("F('{0}').selectRow('{1}');", Grid1.ClientID, depart.DepartId));
|
||||
//PageContext.RegisterStartupScript("onNewButtonClick();");
|
||||
}
|
||||
else
|
||||
{
|
||||
ShowNotify("The BU.Code or BU.Name entered already exists!", MessageBoxIcon.Warning);
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 权限设置
|
||||
/// <summary>
|
||||
/// 菜单按钮权限
|
||||
/// </summary>
|
||||
private void GetButtonPower()
|
||||
{
|
||||
var buttonList = BLL.CommonService.GetAllButtonList(this.CurrUser.UserId, BLL.Const.DepartMenuId);
|
||||
if (buttonList.Count() > 0)
|
||||
{
|
||||
if (buttonList.Contains(BLL.Const.BtnAdd))
|
||||
{
|
||||
this.btnNew.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 Grid1_RowSelect(object sender, GridRowSelectEventArgs e)
|
||||
{
|
||||
this.EditData();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 清空文本框
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
protected void btnNew_Click(object sender, EventArgs e)
|
||||
{
|
||||
EmptyText();
|
||||
}
|
||||
|
||||
private void EmptyText()
|
||||
{
|
||||
this.hfFormID.Text = string.Empty;
|
||||
this.txtDepartCode.Text = string.Empty;
|
||||
this.txtDepartName.Text = string.Empty;
|
||||
this.txtRemark.Text = string.Empty;
|
||||
this.drpSupCheckItem.SelectedIndex = 0;
|
||||
this.drpDepartLeader.SelectedIndex = 0;
|
||||
this.btnDelete.Enabled = false;
|
||||
}
|
||||
|
||||
#region 判断是否可删除
|
||||
|
||||
/// <summary>
|
||||
/// 判断是否可以删除
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
private bool judgementDelete(string departId)
|
||||
{
|
||||
string content = "";
|
||||
|
||||
var depart = (from x in Funs.DB.Sys_User where x.DepartId == departId select x).ToList();
|
||||
if (depart.Count > 0)
|
||||
{
|
||||
content = "用户中已经使用了该部门,不能删除!";
|
||||
}
|
||||
if (content == "")
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
ShowNotify(content);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user