275 lines
9.1 KiB
C#
275 lines
9.1 KiB
C#
using BLL;
|
||
using System;
|
||
using System.Data;
|
||
using System.Linq;
|
||
|
||
namespace FineUIPro.Web.BaseInfo
|
||
{
|
||
public partial class FOOffset : 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();
|
||
// 绑定表格
|
||
BindGrid();
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 绑定数据
|
||
/// </summary>
|
||
private void BindGrid()
|
||
{
|
||
string strSql = @"SELECT * FROM Base_FOOffset";
|
||
// 2.获取当前分页数据
|
||
DataTable tb = SQLHelper.GetDataTableRunText(strSql, null);
|
||
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 btnDelete_Click(object sender, EventArgs e)
|
||
{
|
||
Model.Base_FOOffset offset = Funs.DB.Base_FOOffset.FirstOrDefault(x => x.FOOffsetId == hfFormID.Text);
|
||
if (offset != null)
|
||
{
|
||
Funs.DB.Base_FOOffset.DeleteOnSubmit(offset);
|
||
Funs.DB.SubmitChanges();
|
||
}
|
||
BLL.Sys_LogService.AddLog(this.CurrUser.UserId, "Delete FO Offset");
|
||
|
||
BindGrid();
|
||
}
|
||
/// <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();
|
||
|
||
Model.Base_FOOffset offset = Funs.DB.Base_FOOffset.FirstOrDefault(e => e.FOOffsetId == rowID);
|
||
if (offset != null)
|
||
{
|
||
Funs.DB.Base_FOOffset.DeleteOnSubmit(offset);
|
||
Funs.DB.SubmitChanges();
|
||
}
|
||
BLL.Sys_LogService.AddLog(this.CurrUser.UserId, "Delete FO Offset");
|
||
}
|
||
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 offset = Funs.DB.Base_FOOffset.FirstOrDefault(e => e.FOOffsetId == Id);
|
||
if (offset != null)
|
||
{
|
||
txtFONO.Text = offset.FO_NO;
|
||
this.txtOffset.Text = offset.Offset.HasValue ? offset.Offset.ToString() : "";
|
||
this.txtRemark.Text = offset.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)
|
||
{
|
||
string strRowID = hfFormID.Text;
|
||
if (!IsExitFONO(this.txtFONO.Text.Trim(), strRowID))
|
||
{
|
||
|
||
if (string.IsNullOrEmpty(strRowID))
|
||
{
|
||
Model.Base_FOOffset offset = new Model.Base_FOOffset
|
||
{
|
||
FO_NO = txtFONO.Text.Trim(),
|
||
Remark = this.txtRemark.Text.Trim()
|
||
};
|
||
offset.Offset = Funs.GetNewDecimal(this.txtOffset.Text.Trim());
|
||
offset.FOOffsetId = SQLHelper.GetNewID(typeof(Model.Base_FOOffset));
|
||
Funs.DB.Base_FOOffset.InsertOnSubmit(offset);
|
||
Funs.DB.SubmitChanges();
|
||
ShowNotify("Save successfully!", MessageBoxIcon.Success);
|
||
BLL.Sys_LogService.AddLog(this.CurrUser.UserId, "Add the FO Offset!");
|
||
}
|
||
else
|
||
{
|
||
Model.Base_FOOffset newOffset = Funs.DB.Base_FOOffset.FirstOrDefault(x => x.FOOffsetId == strRowID);
|
||
if (newOffset != null)
|
||
{
|
||
newOffset.FO_NO = txtFONO.Text.Trim();
|
||
newOffset.Offset = Funs.GetNewDecimal(this.txtOffset.Text.Trim());
|
||
newOffset.Remark = txtRemark.Text.Trim();
|
||
Funs.DB.SubmitChanges();
|
||
}
|
||
ShowNotify("Save successfully!", MessageBoxIcon.Success);
|
||
BLL.Sys_LogService.AddLog(this.CurrUser.UserId, "Modify the FO Offset!");
|
||
}
|
||
this.SimpleForm1.Reset();
|
||
// 重新绑定表格,并点击当前编辑或者新增的行
|
||
BindGrid();
|
||
//PageContext.RegisterStartupScript(String.Format("F('{0}').selectRow('{1}');", Grid1.ClientID, type.TypeId));
|
||
//PageContext.RegisterStartupScript("onNewButtonClick();");
|
||
}
|
||
else
|
||
{
|
||
ShowNotify("The FO NO entered already exists!", MessageBoxIcon.Warning);
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 权限设置
|
||
/// <summary>
|
||
/// 菜单按钮权限
|
||
/// </summary>
|
||
private void GetButtonPower()
|
||
{
|
||
var buttonList = BLL.CommonService.GetAllButtonList(this.CurrUser.UserId, BLL.Const.FOOffsetMenuId);
|
||
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
|
||
|
||
private bool IsExitFONO(string foNo, string id)
|
||
{
|
||
var q = Funs.DB.Base_FOOffset.FirstOrDefault(x => x.FO_NO == foNo && x.FOOffsetId != id);
|
||
if (q != null)
|
||
{
|
||
return true;
|
||
}
|
||
else
|
||
{
|
||
return false;
|
||
}
|
||
}
|
||
|
||
#region 增加按钮
|
||
/// <summary>
|
||
/// 增加按钮
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
protected void btnNew_Click(object sender, EventArgs e)
|
||
{
|
||
this.hfFormID.Text = string.Empty;
|
||
this.txtFONO.Text = string.Empty;
|
||
this.txtOffset.Text = string.Empty;
|
||
this.txtRemark.Text = string.Empty;
|
||
this.btnDelete.Enabled = false;
|
||
}
|
||
#endregion
|
||
|
||
#region Grid行选择事件
|
||
/// <summary>
|
||
/// Grid行选择事件
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
protected void Grid1_RowSelect(object sender, GridRowSelectEventArgs e)
|
||
{
|
||
EditData();
|
||
}
|
||
#endregion
|
||
}
|
||
} |