2025-04-07 17:43:30 +08:00
using System ;
using System.Collections.Generic ;
using System.Data.SqlClient ;
using System.Data ;
using System.Linq ;
using BLL ;
namespace FineUIPro.Web.HJGL.MaterialManage
{
public partial class StockIn : PageBase
{
2025-04-14 15:31:57 +08:00
#region 定 义 项
/// <summary>
/// 项目主键
/// </summary>
public string ProjectId
{
get
{
return ( string ) ViewState [ "ProjectId" ] ;
}
set
{
ViewState [ "ProjectId" ] = value ;
}
}
#endregion
2025-04-07 17:43:30 +08:00
#region 加 载 页 面
/// <summary>
/// 加载页面
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Page_Load ( object sender , EventArgs e )
{
if ( ! IsPostBack )
{
2025-04-14 15:31:57 +08:00
this . ProjectId = this . CurrUser . LoginProjectId ;
if ( ! string . IsNullOrEmpty ( Request . Params [ "projectId" ] ) & & Request . Params [ "projectId" ] ! = this . CurrUser . LoginProjectId )
{
this . ProjectId = Request . Params [ "projectId" ] ;
}
this . ucTree . UnitId = this . CurrUser . UnitId ;
this . ucTree . ProjectId = this . ProjectId ;
if ( ! string . IsNullOrEmpty ( this . CurrUser . LoginProjectId ) )
{
this . panelLeftRegion . Hidden = true ;
////权限按钮方法
//this.GetButtonPower();
}
2025-04-07 17:43:30 +08:00
ddlPageSize . SelectedValue = Grid1 . PageSize . ToString ( ) ;
this . drpWeldType . DataTextField = "Text" ;
this . drpWeldType . DataValueField = "Value" ;
this . drpWeldType . DataSource = BLL . DropListService . HJGL_ConsumablesTypeList ( ) ;
this . drpWeldType . DataBind ( ) ;
Funs . FineUIPleaseSelect ( this . drpWeldType ) ;
// 绑定表格
BindGrid ( ) ;
}
}
2025-04-14 15:31:57 +08:00
/// <summary>
/// 公司级树加载
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void changeTree ( object sender , EventArgs e )
{
this . ProjectId = this . ucTree . ProjectId ;
if ( string . IsNullOrEmpty ( this . CurrUser . LoginProjectId ) )
{
btnNew . Hidden = true ;
}
//this.GetButtonPower();
this . BindGrid ( ) ;
}
2025-04-07 17:43:30 +08:00
/// <summary>
/// 绑定数据
/// </summary>
private void BindGrid ( )
{
2025-04-14 15:31:57 +08:00
if ( string . IsNullOrEmpty ( this . ProjectId ) )
{
return ;
}
2025-04-07 17:43:30 +08:00
string strSql = @"SELECT StockIn.StockInId,StockIn.WeldId,StockIn.Amount,StockIn.Weight,Users.UserName AS Materialman,StockIn.InStockDate,
ReviewDate,Weld.ConsumablesCode,Weld.ConsumablesName,Weld.SteelFormat,StockIn.Warrantybook, StockIn.HeartNo,
case Weld.ConsumablesType when '1' then '焊丝' when '2' then '焊条' when '3' then '焊剂' else '' end as WeldTypeName,Weld.WeldUnit,(unit.UnitName+'('+store.UnitStoreName+')') AS UnitStoreName,
(CASE WHEN (StockIn.AttachUrl!='' AND StockIn.AttachUrl IS NOT NULL) THEN '是' ELSE '否' END) IsUploadAttach
FROM dbo.Weld_StockIn AS StockIn
LEFT JOIN dbo.Base_Consumables AS Weld ON Weld.ConsumablesId=StockIn.WeldId
LEFT JOIN dbo.Sys_User AS Users ON Users.UserId=StockIn.Materialman
LEFT JOIN dbo.Weld_UnitStore store ON store.UnitStoreId=StockIn.UnitStoreId
LEFT JOIN dbo.Base_Unit unit ON unit.UnitId=store.UnitId
WHERE StockIn.Flag='1' and StockIn.ProjectId=@ProjectId " ;
List < SqlParameter > listStr = new List < SqlParameter > ( ) ;
2025-04-14 15:31:57 +08:00
listStr . Add ( new SqlParameter ( "@ProjectId" , this . ProjectId ) ) ;
2025-04-07 17:43:30 +08:00
if ( ! string . IsNullOrEmpty ( this . txtWeldName . Text . Trim ( ) ) )
{
strSql + = " AND Weld.ConsumablesCode LIKE @ConsumablesCode" ;
listStr . Add ( new SqlParameter ( "@ConsumablesCode" , "%" + this . txtWeldName . Text . Trim ( ) + "%" ) ) ;
}
if ( drpWeldType . SelectedValue ! = BLL . Const . _Null )
{
strSql + = " AND Weld.ConsumablesType = @WeldTypeId" ;
listStr . Add ( new SqlParameter ( "@WeldTypeId" , drpWeldType . SelectedValue ) ) ;
}
//if (CurrUser.Account != Const.Gly)
//{
// strSql += " AND store.UnitId = @UnitId";
// listStr.Add(new SqlParameter("@UnitId", CurrUser.UnitId));
//}
SqlParameter [ ] parameter = listStr . ToArray ( ) ;
DataTable tb = SQLHelper . GetDataTableRunText ( strSql , parameter ) ;
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_FilterChange ( object sender , EventArgs e )
{
BindGrid ( ) ;
}
#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 TextBox_TextChanged ( object sender , EventArgs e )
{
BindGrid ( ) ;
}
protected void drpWeldType_SelectedIndexChanged ( object sender , EventArgs e )
{
BindGrid ( ) ;
}
#endregion
#region 增 加 按 钮
/// <summary>
/// 增加按钮
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnNew_Click ( object sender , EventArgs e )
{
2025-04-14 15:31:57 +08:00
if ( BLL . CommonService . GetAllButtonPowerList ( this . ProjectId , this . CurrUser . UserId , BLL . Const . CLGL_StockInMenuId , BLL . Const . BtnAdd ) )
2025-04-07 17:43:30 +08:00
{
PageContext . RegisterStartupScript ( Window1 . GetShowReference ( String . Format ( "StockInEdit.aspx?StockInId={0}" , string . Empty , "编辑 - " ) ) ) ;
}
else
{
Alert . ShowInTop ( "您没有这个权限,请与管理员联系!" , MessageBoxIcon . Warning ) ;
return ;
}
}
#endregion
protected void btnMoveStore_Click ( object sender , EventArgs e )
{
2025-04-14 15:31:57 +08:00
if ( BLL . CommonService . GetAllButtonPowerList ( this . ProjectId , this . CurrUser . UserId , BLL . Const . CLGL_StockInMenuId , BLL . Const . BtnModify ) )
2025-04-07 17:43:30 +08:00
{
if ( CurrUser . UserId ! = Const . sysglyId & & CurrUser . UserId ! = Const . hfnbdId )
{
PageContext . RegisterStartupScript ( Window2 . GetShowReference ( String . Format ( "StockMove.aspx" , "移库 - " ) ) ) ;
}
else
{
Alert . ShowInTop ( "管理员不能操作!" , MessageBoxIcon . Warning ) ;
return ;
}
}
else
{
Alert . ShowInTop ( "您没有这个权限,请与管理员联系!" , MessageBoxIcon . Warning ) ;
return ;
}
}
#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 ( )
{
2025-04-14 15:31:57 +08:00
if ( BLL . CommonService . GetAllButtonPowerList ( this . ProjectId , this . CurrUser . UserId , BLL . Const . CLGL_StockInMenuId , BLL . Const . BtnModify ) )
2025-04-07 17:43:30 +08:00
{
if ( Grid1 . SelectedRowIndexArray . Length = = 0 )
{
Alert . ShowInTop ( "请至少选择一条记录!" , MessageBoxIcon . Warning ) ;
return ;
}
string id = Grid1 . SelectedRowID ;
if ( ! string . IsNullOrEmpty ( id ) )
{
var q = BLL . StockInService . GetStockInById ( id ) ;
if ( q . UnitStoreId ! = null )
{
var s = BLL . UnitStoreService . GetUnitStoreById ( q . UnitStoreId ) ;
//if (s != null && s.UnitId == CurrUser.UnitId)
//{
PageContext . RegisterStartupScript ( Window1 . GetShowReference ( String . Format ( "StockInEdit.aspx?StockInId={0}" , id , "编辑 - " ) ) ) ;
//}
//else
//{
// Alert.ShowInTop("非本单位的数据,不能修改!", MessageBoxIcon.Warning);
// return;
//}
}
}
}
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 ( )
{
2025-04-14 15:31:57 +08:00
if ( BLL . CommonService . GetAllButtonPowerList ( this . ProjectId , this . CurrUser . UserId , BLL . Const . CLGL_StockInMenuId , BLL . Const . BtnDelete ) )
2025-04-07 17:43:30 +08:00
{
if ( Grid1 . SelectedRowIndexArray . Length = = 1 )
{
string rowID = Grid1 . SelectedRowID . ToString ( ) ;
if ( this . judgementDelete ( rowID ) )
{
var q = BLL . StockInService . GetStockInById ( rowID ) ;
BLL . StockInService . DeleteStockInById ( rowID ) ;
BLL . LogService . AddSys_Log ( this . CurrUser , q . HeartNo , rowID , BLL . Const . CLGL_StockInMenuId , "删除焊材入库录入" ) ;
}
}
else
{
Alert . ShowInTop ( "请选择要删除的记录!" , MessageBoxIcon . Warning ) ;
return ;
}
this . BindGrid ( ) ;
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 . Weld_UsingMat where x . StockInId = = rowID select x ;
if ( q . Count ( ) > 0 )
{
content = "该入库材料已有领用,不能删除!" ;
}
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 btnImport_Click ( object sender , EventArgs e )
{
PageContext . RegisterStartupScript ( Window3 . GetShowReference ( String . Format ( "StockInImport.aspx" , "导入 - " ) ) ) ;
}
#endregion
}
}