using BLL; using System; using System.Data; using System.Linq; namespace FineUIPro.Web.BaseInfo { public partial class TaxRate : PageBase { #region 加载 /// /// 加载页面 /// /// /// protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { GetButtonPower();//按钮权限 ddlPageSize.SelectedValue = Grid1.PageSize.ToString(); // 绑定表格 BindGrid(); } } /// /// 绑定数据 /// private void BindGrid() { string strSql = @"SELECT * FROM Base_TaxRate"; // 2.获取当前分页数据 DataTable tb = SQLHelper.GetDataTableRunText(strSql, null); Grid1.RecordCount = tb.Rows.Count; var table = this.GetPagedDataTable(Grid1, tb); Grid1.DataSource = table; Grid1.DataBind(); } /// /// 改变索引事件 /// /// /// protected void Grid1_PageIndexChange(object sender, GridPageEventArgs e) { Grid1.PageIndex = e.NewPageIndex; BindGrid(); } #endregion #region 分页下拉选择 /// /// 分页下拉选择 /// /// /// protected void ddlPageSize_SelectedIndexChanged(object sender, EventArgs e) { Grid1.PageSize = Convert.ToInt32(ddlPageSize.SelectedValue); BindGrid(); } #endregion #region 删除 /// /// 删除 /// /// /// protected void btnDelete_Click(object sender, EventArgs e) { BLL.TaxRateService.DeleteTaxRateById(hfFormID.Text); BLL.Sys_LogService.AddLog(this.CurrUser.UserId, "Delete Tax Rate!"); // 重新绑定表格,并模拟点击[新增按钮] BindGrid(); } /// /// 右键删除事件 /// /// /// protected void btnMenuDelete_Click(object sender, EventArgs e) { this.DeleteData(); } /// /// 删除方法 /// private void DeleteData() { if (Grid1.SelectedRowIndexArray.Length > 0) { foreach (int rowIndex in Grid1.SelectedRowIndexArray) { string rowID = Grid1.DataKeys[rowIndex][0].ToString(); BLL.TaxRateService.DeleteTaxRateById(rowID); BLL.Sys_LogService.AddLog(this.CurrUser.UserId, "Delete Tax Rate"); } BindGrid(); } } #endregion #region 编辑 /// /// 右键编辑事件 /// /// /// protected void btnMenuEdit_Click(object sender, EventArgs e) { this.EditData(); } /// /// 编辑数据方法 /// private void EditData() { if (Grid1.SelectedRowIndexArray.Length == 0) { Alert.ShowInTop("Please select at least one record!", MessageBoxIcon.Warning); return; } string Id = Grid1.SelectedRowID; var taxRate = BLL.TaxRateService.GetTaxRateById(Id); if (taxRate != null) { this.txtTaxRate.Text = taxRate.TaxRate.HasValue ? taxRate.TaxRate.ToString() : ""; this.txtRemark.Text = taxRate.Remarks; hfFormID.Text = Id; this.btnDelete.Enabled = true; } } #endregion #region 保存 /// /// 保存按钮 /// /// /// protected void btnSave_Click(object sender, EventArgs e) { string strRowID = hfFormID.Text; if (!BLL.TaxRateService.IsExitTaxRate(this.txtTaxRate.Text.Trim(), strRowID)) { Model.Base_TaxRate taxRate = new Model.Base_TaxRate { Remarks = this.txtRemark.Text.Trim() }; taxRate.TaxRate = Funs.GetNewDecimal(this.txtTaxRate.Text.Trim()); if (string.IsNullOrEmpty(strRowID)) { taxRate.TaxRateId = SQLHelper.GetNewID(typeof(Model.Base_TaxRate)); BLL.TaxRateService.AddTaxRate(taxRate); ShowNotify("Save successfully!", MessageBoxIcon.Success); BLL.Sys_LogService.AddLog(this.CurrUser.UserId, "Add the Tax Rate!"); } else { taxRate.TaxRateId = strRowID; BLL.TaxRateService.UpdateTaxRate(taxRate); ShowNotify("Save successfully!", MessageBoxIcon.Success); BLL.Sys_LogService.AddLog(this.CurrUser.UserId, "Modify the Tax Rate!"); } this.SimpleForm1.Reset(); // 重新绑定表格,并点击当前编辑或者新增的行 BindGrid(); //PageContext.RegisterStartupScript(String.Format("F('{0}').selectRow('{1}');", Grid1.ClientID, type.TypeId)); //PageContext.RegisterStartupScript("onNewButtonClick();"); } else { ShowNotify("The Tax Rate entered already exists!", MessageBoxIcon.Warning); } } #endregion #region 权限设置 /// /// 菜单按钮权限 /// private void GetButtonPower() { var buttonList = BLL.CommonService.GetAllButtonList(this.CurrUser.UserId, BLL.Const.TaxRateMenuId); 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 #region 增加按钮 /// /// 增加按钮 /// /// /// protected void btnNew_Click(object sender, EventArgs e) { this.hfFormID.Text = string.Empty; this.txtTaxRate.Text = string.Empty; this.txtRemark.Text = string.Empty; this.btnDelete.Enabled = false; } #endregion #region Grid行选择事件 /// /// Grid行选择事件 /// /// /// protected void Grid1_RowSelect(object sender, GridRowSelectEventArgs e) { EditData(); } #endregion } }