using System;
using System.Collections.Generic;
using BLL;
using System.Data.SqlClient;
using System.Data;
namespace FineUIPro.Web.HJGL.MaterialManage
{
public partial class UnitStore : PageBase
{
#region 加载页面
///
/// 加载页面
///
///
///
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
ddlPageSize.SelectedValue = Grid1.PageSize.ToString();
BindUnit(drpUnit);
BindUnit(drpUnitId);
// 绑定表格
BindGrid();
}
}
#endregion
#region 单位下拉框绑定
private void BindUnit(DropDownList dropName)
{
dropName.DataTextField = "UnitName";
dropName.DataValueField = "UnitId";
dropName.DataSource = UnitService.GetUnitByProjectIdUnitTypeList(this.CurrUser.LoginProjectId, string.Empty);
dropName.DataBind();
Funs.FineUIPleaseSelect(dropName);
}
#endregion
#region 绑定数据
///
/// 绑定数据
///
private void BindGrid()
{
string strSql = @"SELECT s.UnitStoreId,s.UnitId,s.UnitStoreCode,s.UnitStoreName,s.StorePosition ,u.UnitName
FROM dbo.Weld_UnitStore s
LEFT JOIN dbo.Base_Unit u ON u.UnitId = s.UnitId
WHERE ProjectId=@ProjectId";
List listStr = new List();
listStr.Add(new SqlParameter("@ProjectId", this.CurrUser.LoginProjectId));
if (this.drpUnit.SelectedValue != BLL.Const._Null)
{
strSql += " AND s.UnitId = @UnitId";
listStr.Add(new SqlParameter("@UnitId", this.drpUnit.SelectedValue));
}
SqlParameter[] parameter = listStr.ToArray();
DataTable tb = SQLHelper.GetDataTableRunText(strSql, parameter);
// 2.获取当前分页数据
//var table = this.GetPagedDataTable(Grid1, tb1);
Grid1.RecordCount = tb.Rows.Count;
tb = GetFilteredTable(Grid1.FilteredData, tb);
var table = this.GetPagedDataTable(Grid1, tb);
Grid1.DataSource = table;
Grid1.DataBind();
}
#endregion
#region 分页排序
///
///
///
///
///
protected void Grid1_PageIndexChange(object sender, GridPageEventArgs e)
{
Grid1.PageIndex = e.NewPageIndex;
BindGrid();
}
///
/// 分页下拉选择
///
///
///
protected void ddlPageSize_SelectedIndexChanged(object sender, EventArgs e)
{
Grid1.PageSize = Convert.ToInt32(ddlPageSize.SelectedValue);
BindGrid();
}
///
///
///
///
///
protected void Grid1_FilterChange(object sender, EventArgs e)
{
BindGrid();
}
///
/// 排序
///
///
///
protected void Grid1_Sort(object sender, FineUIPro.GridSortEventArgs e)
{
Grid1.SortDirection = e.SortDirection;
Grid1.SortField = e.SortField;
BindGrid();
}
#endregion
#region 删除事件
///
/// 删除
///
///
///
protected void btnDelete_Click(object sender, EventArgs e)
{
if (CommonService.GetAllButtonPowerList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, Const.HJGL_UnitStoreMenuId, Const.BtnDelete))
{
if (judgementDelete(hfFormID.Text, true))
{
var store = BLL.UnitStoreService.GetUnitStoreById(hfFormID.Text);
BLL.UnitStoreService.DeleteUnitStoreById(hfFormID.Text);
BLL.LogService.AddSys_Log(this.CurrUser, store.UnitStoreName, store.UnitStoreId, BLL.Const.HJGL_UnitStoreMenuId, "删除单位仓库");
// 重新绑定表格,并模拟点击[新增按钮]
BindGrid();
PageContext.RegisterStartupScript("onNewButtonClick();");
}
}
else
{
Alert.ShowInTop("您没有这个权限,请与管理员联系!", MessageBoxIcon.Warning);
return;
}
}
///
/// 右键删除事件
///
///
///
protected void btnMenuDelete_Click(object sender, EventArgs e)
{
if (CommonService.GetAllButtonPowerList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, Const.HJGL_UnitStoreMenuId, Const.BtnDelete))
{
this.DeleteData();
}
else
{
Alert.ShowInTop("您没有这个权限,请与管理员联系!", MessageBoxIcon.Warning);
return;
}
}
///
/// 删除方法
///
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();
if (judgementDelete(rowID, isShow))
{
var store = BLL.UnitStoreService.GetUnitStoreById(rowID);
BLL.UnitStoreService.DeleteUnitStoreById(rowID);
BLL.LogService.AddSys_Log(this.CurrUser, store.UnitStoreName, store.UnitStoreId, BLL.Const.HJGL_UnitStoreMenuId, "删除单位仓库");
ShowNotify("删除完成!", MessageBoxIcon.Success);
}
}
BindGrid();
PageContext.RegisterStartupScript("onNewButtonClick();");
}
}
#endregion
#region 编辑
///
/// 右键编辑事件
///
///
///
protected void btnMenuEdit_Click(object sender, EventArgs e)
{
if (CommonService.GetAllButtonPowerList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, Const.HJGL_UnitStoreMenuId, Const.BtnModify))
{
this.EditData();
}
else
{
Alert.ShowInTop("您没有这个权限,请与管理员联系!", MessageBoxIcon.Warning);
return;
}
}
///
/// 编辑数据方法
///
private void EditData()
{
if (Grid1.SelectedRowIndexArray.Length == 0)
{
Alert.ShowInTop("请至少选择一条记录!", MessageBoxIcon.Warning);
return;
}
string Id = Grid1.SelectedRowID;
var unitStore = BLL.UnitStoreService.GetUnitStoreById(Id);
if (unitStore != null)
{
if (!string.IsNullOrEmpty(unitStore.UnitId))
{
this.drpUnitId.SelectedValue = unitStore.UnitId;
}
this.txtUnitStoreCode.Text = unitStore.UnitStoreCode;
this.txtUnitStoreName.Text = unitStore.UnitStoreName;
txtStorePosition.Text = unitStore.StorePosition;
hfFormID.Text = Id;
this.btnDelete.Enabled = true;
}
}
#endregion
#region 提交按钮
///
/// 提交按钮
///
///
///
protected void btnSave_Click(object sender, EventArgs e)
{
if (CommonService.GetAllButtonPowerList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, Const.HJGL_UnitStoreMenuId, Const.BtnSave))
{
string strRowID = hfFormID.Text;
if (this.drpUnitId.SelectedValue == BLL.Const._Null)
{
Alert.ShowInTop("所属单不能为空!", MessageBoxIcon.Warning);
return;
}
if (BLL.UnitStoreService.IsExitUnitStore(this.drpUnitId.SelectedValue, this.txtUnitStoreCode.Text.Trim(), strRowID))
{
Alert.ShowInTop("此单位的仓库编码已存在!", MessageBoxIcon.Warning);
return;
}
Model.Weld_UnitStore store = new Model.Weld_UnitStore();
store.ProjectId = this.CurrUser.LoginProjectId;
store.UnitId = this.drpUnitId.SelectedValue;
store.UnitStoreCode = this.txtUnitStoreCode.Text.Trim();
store.UnitStoreName = this.txtUnitStoreName.Text.Trim();
store.StorePosition = txtStorePosition.Text.Trim();
if (string.IsNullOrEmpty(strRowID))
{
var stores = BLL.UnitStoreService.GetUnitStoreByUnitId(drpUnitId.SelectedValue);
if (stores.Count < 5)
{
strRowID = SQLHelper.GetNewID(typeof(Model.Weld_UnitStore));
store.UnitStoreId = strRowID;
BLL.UnitStoreService.AddUnitStore(store);
BLL.LogService.AddSys_Log(this.CurrUser, store.UnitStoreName, store.UnitStoreId, BLL.Const.HJGL_UnitStoreMenuId, "添加单位仓库");
}
else
{
Alert.ShowInTop("单位仓库最多只能创建5个!", MessageBoxIcon.Warning);
return;
}
}
else
{
store.UnitStoreId = strRowID;
BLL.UnitStoreService.UpdateUnitStore(store);
BLL.LogService.AddSys_Log(this.CurrUser, store.UnitStoreName, store.UnitStoreId, BLL.Const.HJGL_UnitStoreMenuId, "修改单位仓库");
}
// 重新绑定表格,并点击当前编辑或者新增的行
BindGrid();
ShowNotify("保存成功!", MessageBoxIcon.Success);
PageContext.RegisterStartupScript("onNewButtonClick();");
//PageContext.RegisterStartupScript(String.Format("F('{0}').selectRow('{1}');", Grid1.ClientID, UnitQualitySort.UnitQualitySortId));
}
else
{
Alert.ShowInTop("您没有这个权限,请与管理员联系!", MessageBoxIcon.Warning);
return;
}
}
#endregion
#region 判断是否可删除
///
/// 判断是否可以删除
///
///
private bool judgementDelete(string id, bool isShow)
{
string content = string.Empty;
//if (BLL.WeldInfoService.GetWeldInfoByWeldTypeId(id) > 0)
//{
// content = "焊材信息设置中已经使用了该焊材类型,不能删除!";
//}
if (string.IsNullOrEmpty(content))
{
return true;
}
else
{
if (isShow)
{
Alert.ShowInTop(content, MessageBoxIcon.Error);
}
return false;
}
}
#endregion
#region 查询
///
/// 查询
///
///
///
protected void TextBox_TextChanged(object sender, EventArgs e)
{
this.BindGrid();
}
#endregion
#region Grid行点击事件
///
/// Grid行点击事件
///
///
///
protected void Grid1_RowClick(object sender, GridRowClickEventArgs e)
{
this.EditData();
}
#endregion
}
}