using DevExpress.XtraEditors;
|
using Gs.DevApp.ToolBox;
|
using Newtonsoft.Json;
|
using System;
|
using System.Collections.Generic;
|
using System.Data;
|
using System.Windows.Forms;
|
|
namespace Gs.DevApp.UserControl
|
{
|
// 继承自XtraForm,这是DevExpress提供的增强型表单控件
|
public partial class SelectCgMx : XtraForm
|
{
|
// Web服务名称常量,用于调用后端接口
|
private readonly string _webServiceName = "MesInvItemArnManager/";
|
// 供应商ID和收料组织ID的私有变量
|
private string suppId = "";
|
private string receiveOrgId = "";
|
|
/// <summary>
|
/// 构造函数
|
/// </summary>
|
/// <param name="_suppId">供应商ID参数</param>
|
/// <param name="_receiveOrgId">收料组织ID参数</param>
|
public SelectCgMx(string _suppId, string _receiveOrgId)
|
{
|
// 初始化表单控件
|
InitializeComponent();
|
|
// 为GridView的列标题绘制事件添加处理方法,使用自定义绘制
|
this.gridView1.CustomDrawColumnHeader += (s, e) => { Gs.DevApp.ToolBox.UtilityHelper.CustomDrawColumnHeader(s, e); };
|
|
// 为GridView的鼠标抬起事件添加处理方法,实现自定义交互
|
this.gridView1.MouseUp += (s, e) => {
|
Gs.DevApp.ToolBox.UtilityHelper.CustomMouseUp(s, e, gcMain, gridView1);
|
|
// 全选/取消全选后立即更新汇总,缩短延迟时间
|
System.Windows.Forms.Timer timer = new System.Windows.Forms.Timer();
|
timer.Interval = 80; // 缩短延迟确保操作完成后立即刷新
|
timer.Tick += (sender, args) =>
|
{
|
timer.Stop();
|
timer.Dispose();
|
UtilityHelper.RefreshConditionalSummary(gridView1); // 使用新的刷新方法
|
};
|
timer.Start();
|
};
|
|
// 配置复选列的排序和筛选选项,禁用排序和筛选功能
|
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;
|
|
// 设置单选按钮组默认选中第一项(采购类型)
|
radioGroup1.SelectedIndex = 0;
|
|
// 保存传入的供应商ID和收料组织ID
|
this.suppId = _suppId;
|
this.receiveOrgId = _receiveOrgId;
|
|
// 设置GridView的参数配置
|
Gs.DevApp.ToolBox.UtilityHelper.SetGridViewParameter(gridView1, null, null, null, "", null, null, false);
|
|
// 加载第一页数据
|
getPageList(1);
|
|
// 为"确定"按钮添加点击事件处理
|
btnIn.Click += (s, e) =>
|
{
|
// 提交编辑并更新当前行数据
|
gridView1.PostEditor();
|
gridView1.UpdateCurrentRow();
|
|
// 收集选中行的GUID
|
var list = new List<string>();
|
DataTable dt = this.gcMain.DataSource as DataTable;
|
{
|
foreach (DataRow dr in dt.Rows)
|
{
|
string checkBox = dr["chkInt"].ToString();
|
string _guid = dr["guid"].ToString();
|
// 检查是否选中
|
if (Gs.DevApp.ToolBox.UtilityHelper.ToCheck(checkBox))
|
{
|
list.Add(_guid);
|
}
|
}
|
}
|
|
// 触发回调事件,传递选中的GUID列表,然后关闭表单
|
UpdateParent?.Invoke(this, new UpdateParentEventArgs { StringList = list });
|
Close();
|
};
|
|
// 为单选按钮组添加选中项变化事件,切换时重新加载数据
|
radioGroup1.SelectedIndexChanged += (s, e) =>
|
{
|
getPageList(1);
|
};
|
|
/// <summary>
|
/// 条件汇总:只对选中(打勾)的行进行汇总
|
/// chkInt字段为true时才计算purchaseQty和wssl的合计
|
/// 使用一键式方法,包含条件汇总+实时刷新功能
|
/// </summary>
|
UtilityHelper.SetupCompleteConditionalSummary(gridView1, "chkInt", true, new string[] { "purchaseQty", "wssl" });
|
|
|
}
|
|
/// <summary>
|
/// 选择后的回调事件,用于向父窗体传递选中的数据
|
/// </summary>
|
public event EventHandler<UpdateParentEventArgs> UpdateParent;
|
|
/// <summary>
|
/// 从服务器获取分页数据并绑定到GridView
|
/// </summary>
|
/// <param name="curPage">当前页码</param>
|
private void getPageList(int curPage)
|
{
|
// 创建请求参数对象
|
var _obj = new
|
{
|
currentPage = curPage, // 当前页码
|
everyPageSize = 999999, // 每页记录数(这里设置了一个很大的值,可能是为了获取所有数据)
|
sortName = "", // 排序字段
|
keyWhere = "", // 查询条件
|
inBusType = (radioGroup1.SelectedIndex + 1), // 业务类型:1是采购,2是委外
|
inSupId = this.suppId, // 供应商ID
|
inReceiveOrgId = this.receiveOrgId, // 收料组织ID
|
};
|
|
// 将参数对象序列化为JSON字符串
|
var json = JsonConvert.SerializeObject(_obj);
|
|
try
|
{
|
// 调用Web服务获取数据
|
var strReturn = UtilityHelper.HttpPost("",
|
_webServiceName + "SelectForm", json);
|
|
// 解析返回结果为DataTable
|
var dd = UtilityHelper.ReturnToTablePage(strReturn);
|
var dt = dd.rtnData.list;
|
|
// 绑定数据到GridControl
|
gcMain.BindingContext = new BindingContext();
|
gcMain.DataSource = dt;
|
gcMain.ForceInitialize();
|
|
// 自动调整列宽并应用网格布局
|
gridView1.BestFitColumns();
|
Gs.DevApp.ToolBox.UtilityHelper.SetGridLayout(gridView1);
|
}
|
catch (Exception ex)
|
{
|
// 显示错误信息
|
MsgHelper.Warning("提示:" + ex.Message);
|
}
|
}
|
}
|
}
|