using Gs.DevApp.ToolBox;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Data;
using System.Windows.Forms;
namespace Gs.DevApp.DevFrm.Ck
{
public partial class UcBlclSelect : DevExpress.XtraEditors.XtraForm
{
private readonly string _webServiceName = "WomdaaManager/";
private string daaId = "";
private string orgId = "";
///
/// 构造函数
///
/// daaGuid
/// 生产组织
public UcBlclSelect(string _daaGuid, string _orgId)
{
InitializeComponent();
InitializeGridSettings();
this.daaId = _daaGuid;
this.orgId = _orgId;
Gs.DevApp.ToolBox.UtilityHelper.SetGridViewParameter(gridView1, null, null, null, "", null, null, false);
getPageList(1);
SetupButtonClickEvent();
}
///
/// 重载构造函数 - 筛选掉kbsl为0的数据
///
/// daaGuid
/// 生产组织
/// 类型标识
public UcBlclSelect(string _daaGuid, string _orgId, string _type)
{
InitializeComponent();
InitializeGridSettings();
this.daaId = _daaGuid;
this.orgId = _orgId;
Gs.DevApp.ToolBox.UtilityHelper.SetGridViewParameter(gridView1, null, null, null, "", null, null, false);
getPageListWithFilter(1); // 使用过滤方法
SetupButtonClickEvent();
}
///
/// 初始化网格设置
///
private void InitializeGridSettings()
{
this.gridView1.CustomDrawColumnHeader += (s, e) => { Gs.DevApp.ToolBox.UtilityHelper.CustomDrawColumnHeader(s, e); };
this.gridView1.MouseUp += (s, e) => { Gs.DevApp.ToolBox.UtilityHelper.CustomMouseUp(s, e, gcMain, gridView1); };
this.colChkInt.OptionsColumn.AllowSort = DevExpress.Utils.DefaultBoolean.False;
this.colChkInt.OptionsFilter.AllowAutoFilter = false;
this.colChkInt.OptionsFilter.AllowFilter = false;
this.colChkInt.OptionsFilter.AllowInHeaderSearch = DevExpress.Utils.DefaultBoolean.False;
}
///
/// 设置按钮点击事件
///
private void SetupButtonClickEvent()
{
btnIn.Click += (s, e) =>
{
gridView1.PostEditor();
gridView1.UpdateCurrentRow();
var list = new List();
DataTable dt = this.gcMain.DataSource as DataTable;
{
foreach (DataRow dr in dt.Rows)
{
string checkBox = dr["chkInt"].ToString();
string _guid = dr["dabGuid"].ToString();
if (Gs.DevApp.ToolBox.UtilityHelper.ToCheck(checkBox))
{
list.Add(new
{
dabGuid = _guid,
dwName = dr["dwName"].ToString(),
itemModel = dr["itemModel"].ToString(),
itemName = dr["itemName"].ToString(),
itemNo = dr["itemNo"].ToString(),
gdh = dr["gdh"].ToString(),
kbsl = dr["kbsl"].ToString()
});
}
}
}
UpdateParent?.Invoke(this, new UpdateParentEventArgs { DynamicList = list });
Close();
};
}
///
/// 选择后的回调事件
///
public event EventHandler UpdateParent;
///
/// 获取页面数据(不过滤)
///
/// 第几页
private void getPageList(int curPage)
{
var _obj = new
{
currentPage = 1,
everyPageSize = 999999,
sortName = "",
keyWhere = "",
daaGuid = daaId
};
var json = JsonConvert.SerializeObject(_obj);
try
{
var strReturn = UtilityHelper.HttpPost("",
_webServiceName + "GetListSelectDab", json);
var dd = UtilityHelper.ReturnToTablePage(strReturn);
var dt = dd.rtnData.list;
gcMain.BindingContext = new BindingContext();
gcMain.DataSource = dt;
gcMain.ForceInitialize();
gridView1.BestFitColumns();
Gs.DevApp.ToolBox.UtilityHelper.SetGridLayout(gridView1);
}
catch (Exception ex)
{
MsgHelper.Warning("提示:" + ex.Message);
}
}
///
/// 获取页面数据并筛选掉kbsl为0的数据
///
/// 第几页
private void getPageListWithFilter(int curPage)
{
var _obj = new
{
currentPage = 1,
everyPageSize = 999999,
sortName = "",
keyWhere = "",
daaGuid = daaId
};
var json = JsonConvert.SerializeObject(_obj);
try
{
var strReturn = UtilityHelper.HttpPost("",
_webServiceName + "GetListSelectDab", json);
var dd = UtilityHelper.ReturnToTablePage(strReturn);
var dt = dd.rtnData.list;
// 筛选掉kbsl为0的数据
DataTable filteredDt = FilterZeroKbsl(dt);
gcMain.BindingContext = new BindingContext();
gcMain.DataSource = filteredDt;
gcMain.ForceInitialize();
gridView1.BestFitColumns();
Gs.DevApp.ToolBox.UtilityHelper.SetGridLayout(gridView1);
}
catch (Exception ex)
{
MsgHelper.Warning("提示:" + ex.Message);
}
}
///
/// 筛选掉kbsl为0的数据
///
/// 源数据表
/// 过滤后的数据表
private DataTable FilterZeroKbsl(DataTable sourceTable)
{
if (sourceTable == null || sourceTable.Rows.Count == 0)
return sourceTable;
// 创建新的DataTable来存储过滤后的数据
DataTable filteredTable = sourceTable.Clone();
foreach (DataRow row in sourceTable.Rows)
{
// 检查kbsl列是否存在且不为0
if (sourceTable.Columns.Contains("kbsl"))
{
object kbslValue = row["kbsl"];
decimal kbsl = 0;
// 尝试转换为decimal
if (kbslValue != null && kbslValue != DBNull.Value &&
decimal.TryParse(kbslValue.ToString(), out kbsl))
{
if (kbsl > 0) // 只保留kbsl大于0的行
{
filteredTable.ImportRow(row);
}
}
}
else
{
// 如果没有kbsl列,保留所有行
filteredTable.ImportRow(row);
}
}
return filteredTable;
}
}
}