HJGL_DS/HJGL_DS/FineUIPro.Web/WeldMat/WeldMatDataBase/TemperatureAndHumidity.aspx.cs

319 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.WeldMat.WeldMatDataBase
{
public partial class TemperatureAndHumidity : 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();
BLL.UnitStoreService.InitUnitStoreDropDownList(drpUnitStoreId, null, true);
// 绑定表格
BindGrid();
}
}
/// <summary>
/// 绑定数据
/// </summary>
private void BindGrid()
{
string strSql = @"SELECT TemperatureAndHumidity.TemperatureAndHumidityId,
TemperatureAndHumidity.RecordDate,
TemperatureAndHumidity.Temperature,
TemperatureAndHumidity.Humidity,
TemperatureAndHumidity.RecordMan,
store.UnitStoreName
FROM dbo.HJGL_TemperatureAndHumidity AS TemperatureAndHumidity
LEFT JOIN dbo.Weld_UnitStore store ON store.UnitStoreId=TemperatureAndHumidity.UnitStoreId
WHERE 1=1 ";
List<SqlParameter> listStr = new List<SqlParameter>();
if (this.drpUnitStoreId.SelectedValue != BLL.Const._Null)
{
strSql += " AND TemperatureAndHumidity.UnitStoreId = @unitStoreId";
listStr.Add(new SqlParameter("@unitStoreId", drpUnitStoreId.SelectedValue));
}
if (!string.IsNullOrEmpty(this.txtRecordMan.Text.Trim()))
{
strSql += " AND TemperatureAndHumidity.RecordMan LIKE @RecordMan";
listStr.Add(new SqlParameter("@RecordMan", "%" + this.txtRecordMan.Text.Trim() + "%"));
}
if (!string.IsNullOrEmpty(this.txtStartDate.Text.Trim()))
{
strSql += " AND TemperatureAndHumidity.RecordDate >= @startDate";
listStr.Add(new SqlParameter("@startDate", this.txtStartDate.Text.Trim()));
}
if (!string.IsNullOrEmpty(this.txtEndDate.Text.Trim()))
{
strSql += " AND TemperatureAndHumidity.RecordDate <= @endDate";
listStr.Add(new SqlParameter("@endDate", this.txtEndDate.Text.Trim()));
}
SqlParameter[] parameter = listStr.ToArray();
DataTable tb = SQLHelper.GetDataTableRunText(strSql, parameter);
Grid1.RecordCount = tb.Rows.Count;
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();
}
#endregion
#region
/// <summary>
/// 排序
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Grid1_Sort(object sender, 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 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 Window1_Close(object sender, WindowCloseEventArgs e)
{
BindGrid();
}
#endregion
#region
/// <summary>
/// 增加按钮
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnNew_Click(object sender, EventArgs e)
{
if (BLL.CommonService.GetAllButtonPowerList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, BLL.Const.TemperatureAndHumidityMenuId, BLL.Const.BtnAdd))
{
PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("TemperatureAndHumidityEdit.aspx?id={0}", string.Empty, "编辑 - ")));
}
else
{
Alert.ShowInTop("您没有这个权限,请与管理员联系!", MessageBoxIcon.Warning);
return;
}
}
#endregion
#region
/// <summary>
/// 双击Grid事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Grid1_RowDoubleClick(object sender, GridRowClickEventArgs e)
{
this.EditData();
}
/// <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 (BLL.CommonService.GetAllButtonPowerList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, BLL.Const.TemperatureAndHumidityMenuId, BLL.Const.BtnModify))
{
if (Grid1.SelectedRowIndexArray.Length == 0)
{
Alert.ShowInTop("请至少选择一条记录!", MessageBoxIcon.Warning);
return;
}
string id = Grid1.SelectedRowID;
if (!string.IsNullOrEmpty(id))
{
var q = BLL.TemperatureAndHumidityService.GetTemperatureAndHumidityById(id);
if (q != null)
{
PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("TemperatureAndHumidityEdit.aspx?id={0}", id, "编辑 - ")));
}
}
}
else
{
Alert.ShowInTop("您没有这个权限,请与管理员联系!", MessageBoxIcon.Warning);
return;
}
}
#endregion
#region
/// <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 (BLL.CommonService.GetAllButtonPowerList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, BLL.Const.TemperatureAndHumidityMenuId, BLL.Const.BtnDelete))
{
bool isOK = false;
if (Grid1.SelectedRowIndexArray.Length == 1)
{
string rowID = Grid1.SelectedRowID.ToString();
if (this.judgementDelete(rowID))
{
BLL.TemperatureAndHumidityService.DeleteTemperatureAndHumidityById(rowID);
BLL.Sys_LogService.AddLog(BLL.Const.System_7, this.CurrUser.LoginProjectId, this.CurrUser.UserId, "删除焊材库温度湿度记录");
isOK = true;
}
}
else
{
Alert.ShowInTop("请选择要删除的记录!", MessageBoxIcon.Warning);
return;
}
this.BindGrid();
if (isOK == true)
{
ShowNotify("删除数据成功!", MessageBoxIcon.Success);
}
}
else
{
Alert.ShowInTop("您没有这个权限,请与管理员联系!", MessageBoxIcon.Warning);
return;
}
}
/// <summary>
/// 判断是否可删除
/// </summary>
/// <param name="rowID"></param>
/// <param name="isShow"></param>
/// <returns></returns>
private bool judgementDelete(string rowID)
{
string content = string.Empty;
var q = from x in Funs.DB.HJGL_TemperatureAndHumidityProject where x.TemperatureAndHumidityId == rowID select x;
if (q.Count() > 0)
{
string projectName = string.Empty;
foreach (var item in q)
{
var project = BLL.Base_ProjectService.GetProjectByProjectId(item.ProjectId);
if (project != null)
{
projectName += project.ProjectCode + ",";
}
}
if (!string.IsNullOrEmpty(projectName))
{
projectName = projectName.Substring(0, projectName.LastIndexOf(","));
}
content = "【" + projectName + "】使用了该焊材库温度湿度记录,不能删除!";
}
if (string.IsNullOrEmpty(content))
{
return true;
}
else
{
Alert.ShowInTop(content);
return false;
}
}
#endregion
#region
/// <summary>
/// 查询按钮
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnSearch_Click(object sender, EventArgs e)
{
BindGrid();
}
#endregion
#region
/// <summary>
/// 导入按钮
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnImport_Click(object sender, EventArgs e)
{
if (BLL.CommonService.GetAllButtonPowerList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, BLL.Const.TemperatureAndHumidityMenuId, BLL.Const.BtnSave))
{
PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("TemperatureAndHumidityDataIn.aspx", string.Empty, "导入 - ")));
}
else
{
Alert.ShowInTop("您没有这个权限,请与管理员联系!", MessageBoxIcon.Warning);
return;
}
}
#endregion
}
}