ZHJA_HJGL/HJGL_ZH/FineUIPro.Web/YLRQ/BaseInfo/DetectionTime.aspx.cs

314 lines
11 KiB
C#

using BLL;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace FineUIPro.Web.YLRQ.BaseInfo
{
public partial class DetectionTime : PageBase
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
ddlPageSize.SelectedValue = Grid1.PageSize.ToString();
// 绑定表格
BindGrid();
}
}
#region
/// <summary>
/// 绑定数据
/// </summary>
private void BindGrid()
{
string strSql = @"SELECT Id,DetectionTime,ProjectSoft,Remark,CreateId,CreateTime FROM dbo.PV_DetectionTime WHERE 1=1 ";
List<SqlParameter> listStr = new List<SqlParameter>();
if (!string.IsNullOrEmpty(this.txtsDetectionTime.Text.Trim()))
{
strSql += " AND DetectionTime LIKE @DetectionTime";
listStr.Add(new SqlParameter("@DetectionTime", "%" + this.txtsDetectionTime.Text.Trim() + "%"));
}
if (!string.IsNullOrEmpty(this.CurrUser.LoginSystemId))
{
strSql += " AND ProjectSoft=@ProjectSoft";
listStr.Add(new SqlParameter("@ProjectSoft", this.CurrUser.LoginSystemId));
}
SqlParameter[] parameter = listStr.ToArray();
DataTable tb = SQLHelper.GetDataTableRunText(strSql, parameter);
// 2.获取当前分页数据
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, "69D3A277-7D2B-47A1-9A60-AF5FCDDE2D74", Const.BtnDelete))
{
if (judgementDelete(hfFormID.Text, true))
{
BLL.HJGL_WeldService.DeleteJointType(hfFormID.Text);
BLL.Sys_LogService.AddLog(BLL.Const.System_4, 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, "69D3A277-7D2B-47A1-9A60-AF5FCDDE2D74", 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();
var pvDection = Funs.DB.PV_DetectionTime.FirstOrDefault(e => e.Id == rowID);
if (pvDection != null)
{
Funs.DB.PV_DetectionTime.DeleteOnSubmit(pvDection);
Funs.DB.SubmitChanges();
BLL.Sys_LogService.AddLog(BLL.Const.System_4, 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, "69D3A277-7D2B-47A1-9A60-AF5FCDDE2D74", 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 model = Funs.DB.PV_DetectionTime.FirstOrDefault(e => e.Id == Id);
if (model != null)
{
this.txtDetectionTime.Text = model.DetectionTime;
this.txtRemark.Text = model.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)
{
if (CommonService.GetAllButtonPowerList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, "69D3A277-7D2B-47A1-9A60-AF5FCDDE2D74", Const.BtnSave))
{
string strRowID = hfFormID.Text;
var deteion = Funs.DB.PV_DetectionTime.Count(p => p.DetectionTime == txtDetectionTime.Text.Trim() && p.Id != strRowID && p.ProjectSoft == this.CurrUser.LoginSystemId);
if (deteion > 0)
{
Alert.ShowInTop("此检测时机已存在!", MessageBoxIcon.Warning);
return;
}
if (string.IsNullOrEmpty(strRowID))
{
Model.PV_DetectionTime model = new Model.PV_DetectionTime();
model.Id = Guid.NewGuid().ToString();
model.DetectionTime = this.txtDetectionTime.Text.Trim();
model.Remark = this.txtRemark.Text.Trim();
model.ProjectSoft = this.CurrUser.LoginSystemId;
Funs.DB.PV_DetectionTime.InsertOnSubmit(model);
Funs.DB.SubmitChanges();
BLL.Sys_LogService.AddLog(BLL.Const.System_2, this.CurrUser.LoginProjectId, this.CurrUser.UserId, "添加检测时机信息");
}
else
{
Model.PV_DetectionTime model = Funs.DB.PV_DetectionTime.FirstOrDefault(p => p.Id == strRowID);
if (model != null)
{
model.DetectionTime = this.txtDetectionTime.Text.Trim();
model.Remark = this.txtRemark.Text.Trim();
model.ProjectSoft = this.CurrUser.LoginSystemId;
Funs.DB.SubmitChanges();
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 (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
}
}