| | |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Data; |
| | | using System.Diagnostics; |
| | | using System.Threading.Tasks; |
| | | using System.Windows.Forms; |
| | | |
| | | |
| | | |
| | | namespace Gs.DevApp.DevFrm.QC |
| | | { |
| | | public partial class MesQcExceptional : DevExpress.XtraEditors.XtraForm |
| | | { |
| | | string _webServiceName = "MesQcExceptionalManager/"; |
| | | List<FilterEntity> _filterList = new List<FilterEntity>(); |
| | | |
| | | |
| | | public void Initialize(string param) |
| | | { |
| | | // 使用param进行初始化工作 |
| | | Gs.DevApp.ToolBox.UtilityHelper.JumpTab(xtraTabControl1, 0); |
| | | getModel(param); |
| | | } |
| | | |
| | | |
| | | public MesQcExceptional() |
| | | { |
| | | InitializeComponent(); |
| | | this.toolBarMenu1.btnLoadClick += ToolBarMenu1_btnLoadClick; |
| | | this.toolBarMenu1.btnQueryClick += ToolBarMenu1_btnQueryClick; |
| | | toolBarMenu1.btnChkClick += ToolBarMenu1_btnChkClick; |
| | | |
| | | toolBarMenu1.btnLogClick += ToolBarMenu1_btnLogClick; |
| | | this.toolBarMenu1.btnEdtClick += ToolBarMenu1_btnEdtClick; |
| | | this.toolBarMenu1.btnSaveClick += ToolBarMenu1_btnSaveClick; |
| | | toolBarMenu1.btnFChkClick += ToolBarMenu1_btnFChkClick; |
| | | toolBarMenu1.btnChkClick += ToolBarMenu1_btnChkClick; |
| | | this.toolBarMenu1.btnEscClick += ToolBarMenu1_btnEscClick; |
| | | |
| | | this.toolBarMenu1.getXmlConfig(); |
| | | Gs.DevApp.ToolBox.UtilityHelper.SetGridViewParameterMx(gvMx1); |
| | | Gs.DevApp.ToolBox.UtilityHelper.SetGridViewParameter(gridView1, picCheckBox, this, "chkStatus", "", (value) => |
| | |
| | | }, lbGuid); |
| | | getPageList(1); |
| | | pageBar1.PagerEvent += PageBar1_PagerEvent; |
| | | |
| | | |
| | | |
| | | |
| | | } |
| | | |
| | | private void GridView1_ColumnFilterChanged(object sender, EventArgs e) |
| | |
| | | frm.UpdateParent += Frm_UpdateParent; |
| | | frm.ShowDialog(); |
| | | } |
| | | |
| | | |
| | | /// <summary> |
| | | /// 查询回调 |
| | | /// </summary> |
| | |
| | | _filterList = e.FilterList; |
| | | getPageList(1); |
| | | } |
| | | |
| | | |
| | | /// <summary> |
| | | /// 刷新事件 |
| | | /// </summary> |
| | |
| | | } |
| | | } |
| | | /// <summary> |
| | | /// 审核事件 |
| | | /// 审核事件 |
| | | /// </summary> |
| | | /// <param name="sender"></param> |
| | | /// <param name="e"></param> |
| | |
| | | { |
| | | _toolCk(1); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 反审核 |
| | | /// </summary> |
| | | /// <param name="sender"></param> |
| | | /// <param name="e"></param> |
| | | /// <exception cref="NotImplementedException"></exception> |
| | | private void ToolBarMenu1_btnFChkClick(object sender, EventArgs e) |
| | | { |
| | | _toolCk(0); |
| | | } |
| | | /// <summary> |
| | | /// 取消事件 |
| | | /// </summary> |
| | | /// <param name="sender"></param> |
| | | /// <param name="e"></param> |
| | | private void ToolBarMenu1_btnEscClick(object sender, EventArgs e) |
| | | { |
| | | Gs.DevApp.ToolBox.UtilityHelper.JumpTab(xtraTabControl1, 1); |
| | | } |
| | | /// <summary> |
| | | /// 修改事件 |
| | | /// </summary> |
| | | /// <param name="sender">事件发送者</param> |
| | | /// <param name="e">事件参数</param> |
| | | private void ToolBarMenu1_btnEdtClick(object sender, EventArgs e) |
| | | { |
| | | // 设置当前操作模式为编辑状态 |
| | | toolBarMenu1.currentAction = "edit"; |
| | | // 定义变量存储选中行的唯一标识和名称 |
| | | string rowGuid = "", rowName = ""; |
| | | // 从当前活动表格中获取选中行的关键信息 |
| | | // 参数说明: |
| | | // - xtraTabControl1:标签页控件,用于确定当前活动页 |
| | | // - lbGuid:显示GUID的标签控件 |
| | | // - txt_releaseNo:显示发布编号的文本框 |
| | | // - gridView1:主表格视图 |
| | | // - "releaseNo":要获取的列名 |
| | | (rowGuid, rowName) = UtilityHelper.GetCurrentRow(xtraTabControl1, lbGuid, txt_fBillNo, gridView1, "fBillNo"); |
| | | // 验证是否选中有效行 |
| | | if (string.IsNullOrEmpty(rowGuid)) |
| | | { |
| | | // 未选中时提示用户并终止操作 |
| | | ToolBox.MsgHelper.Warning("请先选择你要操作的行!"); |
| | | return; |
| | | } |
| | | // 导航到编辑页面(第4个标签页,索引从0开始) |
| | | Gs.DevApp.ToolBox.UtilityHelper.JumpTab(xtraTabControl1, 3); |
| | | // 根据当前活动标签页执行不同的初始化逻辑 |
| | | if (xtraTabControl1.SelectedTabPageIndex == 1) |
| | | { |
| | | // 如果是特定标签页(第2页),加载完整数据模型 |
| | | // 参数说明: |
| | | // - rowGuid:选中行的唯一标识 |
| | | getModel(rowGuid); |
| | | } |
| | | else |
| | | { |
| | | // 其他标签页的编辑模式初始化 |
| | | // 创建需要特殊处理的表格视图列表 |
| | | List<DevExpress.XtraGrid.Views.Grid.GridView> gvList = new List<DevExpress.XtraGrid.Views.Grid.GridView>(); |
| | | gvList.Add(gvMx1); // 添加明细表视图1 |
| | | |
| | | // 启用编辑模式下的所有控件 |
| | | // 参数说明: |
| | | // - this.layoutMx1.Controls:要启用的控件容器 |
| | | // - true:启用标志 |
| | | // - gvList:需要特殊处理的表格视图列表 |
| | | UtilityHelper.ChangeEnableByControl(this.layoutMx1.Controls, true, gvList); |
| | | |
| | | |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 保存 -按钮点击事件 处理异常单明细的保存逻辑 |
| | | /// </summary> |
| | | /// <param name="sender">事件发送者</param> |
| | | /// <param name="e">事件参数</param> |
| | | private void ToolBarMenu1_btnSaveClick(object sender, EventArgs e) |
| | | { |
| | | // 1. 初始化保存状态 |
| | | toolBarMenu1.isSetBtn = false; // 禁用工具栏按钮状态设置 |
| | | // 2. 构建请求对象 |
| | | var _obj = new |
| | | { |
| | | guid = UtilityHelper.ToGuid(lbGuid.Text.Trim()), //主表主建 |
| | | list = new List<dynamic>(), // 明细数据列表 |
| | | }; |
| | | // 3. 数据验证与准备 |
| | | gvMx1.CloseEditor(); // 关闭活动编辑器 |
| | | gvMx1.PostEditor(); // 提交编辑的值 |
| | | gvMx1.UpdateCurrentRow(); // 更新当前行数据 |
| | | // 验证明细是否为空 |
| | | if (gvMx1.DataRowCount <= 0) |
| | | { |
| | | MsgHelper.ShowError("明细不能为空,请选择你的异常单明细!"); |
| | | return; |
| | | } |
| | | // 4. 收集明细数据 |
| | | for (var i = 0; i < gvMx1.DataRowCount; i++) |
| | | { |
| | | |
| | | var row = gvMx1.GetDataRow(i); |
| | | if (row != null) |
| | | { |
| | | // 获取当前明细行的GUID |
| | | Guid? _guid = UtilityHelper.ToGuid(row["guid"].ToString()); |
| | | // 添加明细项到请求对象 |
| | | _obj.list.Add(new |
| | | { |
| | | Guid = _guid, |
| | | BatchQty = (row["batchQty"].ToString()), // 批次数量 |
| | | GfRkqty = (row["gfRkqty"].ToString()), // 合格入库数量 |
| | | LfRkqtyz = (row["lfRkqty"].ToString()), // 不合格入库数量 |
| | | HandResult = (row["handResult"].ToString()), // 选别类型 |
| | | ChooseType = (row["chooseType"].ToString()), // 处理意见 |
| | | Process = (row["process"].ToString()), // 退料方式 |
| | | |
| | | }); |
| | | } |
| | | } |
| | | // 5. 发送保存请求 |
| | | try |
| | | { |
| | | // 序列化对象并调用WebService |
| | | string strJson = UtilityHelper.HttpPost("", _webServiceName + "EditModel", JsonConvert.SerializeObject(_obj)); |
| | | // 解析返回结果 |
| | | ReturnModel<dynamic> _rtn = ToolBox.UtilityHelper.ReturnToDynamic(strJson); |
| | | ToolBox.MsgHelper.Warning("提示:" + _rtn.rtnMsg); |
| | | // 6. 处理保存成功逻辑 |
| | | if (_rtn.rtnCode > 0) |
| | | { |
| | | // 更新主表GUID |
| | | lbGuid.Text = _rtn.rtnData.outGuid; |
| | | // 恢复工具栏状态 |
| | | toolBarMenu1.isSetBtn = true; |
| | | // 禁用编辑控件 |
| | | List<DevExpress.XtraGrid.Views.Grid.GridView> gvList = new List<DevExpress.XtraGrid.Views.Grid.GridView>(); |
| | | gvList.Add(gvMx1); |
| | | UtilityHelper.ChangeEnableByControl(this.layoutMx1.Controls, false, gvList); |
| | | // 重置操作状态 |
| | | toolBarMenu1.currentAction = ""; |
| | | // 【新增刷新逻辑】保存成功后立即刷新当前模型数据和列表 |
| | | // 刷新当前单据详情 |
| | | getModel(lbGuid.Text.Trim()); |
| | | // 刷新列表页数据 |
| | | getPageList(this.pageBar1.CurrentPage); |
| | | |
| | | // 跳转到查看结果页面 |
| | | Gs.DevApp.ToolBox.UtilityHelper.JumpTab(xtraTabControl1, 6); |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | ToolBox.MsgHelper.Warning("提示:" + ex.Message); |
| | | } |
| | | } |
| | | |
| | | |
| | | /// <summary> |
| | | /// |
| | | /// </summary> |
| | |
| | | /// <param name="pageSize">每页几条</param> |
| | | private void getPageList(int curPage) |
| | | { |
| | | gcMain1.DataSource = null; |
| | | System.Text.StringBuilder _sbSqlWhere = new System.Text.StringBuilder(); |
| | | _sbSqlWhere.Append(" and arn.ReceiveOrgId in"); |
| | | _sbSqlWhere.Append(ToolBox.UtilityHelper.GetOrgWhere()); |
| | | _sbSqlWhere.Append(UtilityHelper.GetSearchWhere(_filterList)); |
| | | gcMain1.DataSource = null; var _sbSqlWhere = UtilityHelper.GetSearchWhere(_filterList); |
| | | PageQueryModel pgq = new PageQueryModel(curPage, this.pageBar1.RowsCount, "create_date", "asc", "", _sbSqlWhere.ToString()); |
| | | string json = JsonConvert.SerializeObject(pgq); |
| | | try |
| | |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | ToolBox.MsgHelper.ShowError("提示:" + ex.Message); |
| | | ToolBox.MsgHelper.Warning("提示:" + ex.Message); |
| | | } |
| | | } |
| | | |
| | | |
| | | /// <summary> |
| | | /// 读取实体 |
| | | /// 读取实体数据(根据唯一标识GUID加载详情,并将数据绑定到界面控件) |
| | | /// 功能:从服务端获取指定质量控制异常记录的详细信息,包括主数据和明细数据, |
| | | /// 并根据操作状态(查看/编辑)设置界面控件的可编辑性 |
| | | /// </summary> |
| | | /// <param name="strGuid"></param> |
| | | /// <param name="strGuid">实体的唯一标识(GUID格式的主键,用于定位具体记录)</param> |
| | | private void getModel(string strGuid) |
| | | { |
| | | // 定义变量标记当前是否为编辑状态(默认非编辑状态) |
| | | bool isEdit = false; |
| | | |
| | | // 若当前工具栏操作是"新增"(add),无需加载已有数据,直接返回 |
| | | // 原因:新增状态下应显示空白表单,而非加载历史数据 |
| | | if (toolBarMenu1.currentAction == "add") return; |
| | | |
| | | // 若当前工具栏操作是"编辑"(edit),将编辑状态标记为true |
| | | // 后续界面控件的可编辑性将基于此变量判断 |
| | | if (toolBarMenu1.currentAction == "edit") isEdit = true; |
| | | |
| | | // 校验参数:若未传入有效的GUID(用户未选择任何行),提示用户并终止执行 |
| | | if (string.IsNullOrEmpty(strGuid)) |
| | | { |
| | | MsgHelper.ShowError("请先选择你要操作的行!"); |
| | | // 弹出警告提示框,引导用户先选择操作行 |
| | | MsgHelper.Warning("请先选择你要操作的行!"); |
| | | return; |
| | | } |
| | | |
| | | // 构建请求参数对象:以匿名类形式封装要查询的实体主键(GUID) |
| | | // 该参数将用于向服务端请求对应的实体数据 |
| | | var _obj = new |
| | | { |
| | | guid = strGuid,//主建 |
| | | guid = strGuid,// 主键字段,服务端通过此值定位具体记录 |
| | | }; |
| | | |
| | | try |
| | | { |
| | | // 调用HTTP工具类发送POST请求,获取服务端返回的JSON数据 |
| | | // 参数说明: |
| | | // 第一个参数:空字符串(基础URL可能在UtilityHelper内部预设) |
| | | // 第二个参数:接口路径(结合_webServiceName前缀,完整路径为"MesQcExceptionalManager/GetModel") |
| | | // 第三个参数:将查询参数序列化为JSON字符串 |
| | | string strJson = UtilityHelper.HttpPost("", _webServiceName + "GetModel", JsonConvert.SerializeObject(_obj)); |
| | | |
| | | // 将服务端返回的JSON字符串转换为通用返回模型(ReturnModel) |
| | | // ReturnModel包含状态码(rtnCode)、消息(rtnMsg)、数据(rtnData)三个核心字段 |
| | | ReturnModel<dynamic> _rtn = ToolBox.UtilityHelper.ReturnToDynamic(strJson); |
| | | |
| | | // 检查服务端返回状态:rtnCode > 0 表示请求成功(业务层面的成功) |
| | | if (_rtn.rtnCode > 0) |
| | | { |
| | | // 提取返回数据中的实体详情(dynamic类型可动态访问字段,无需预先定义实体类) |
| | | dynamic dy = _rtn.rtnData; |
| | | |
| | | // 在界面的lbGuid标签上显示当前实体的GUID(用于标识当前操作的记录) |
| | | lbGuid.Text = strGuid; |
| | | |
| | | // 创建网格视图列表,包含需要处理的明细网格视图gvMx1 |
| | | // 后续将通过工具方法统一设置这些网格的属性(如可编辑性) |
| | | List<DevExpress.XtraGrid.Views.Grid.GridView> gvList = new List<DevExpress.XtraGrid.Views.Grid.GridView>(); |
| | | gvList.Add(gvMx1); |
| | | |
| | | // 调用工具方法批量设置界面控件的值和可编辑状态 |
| | | // 参数说明: |
| | | // this.layoutMx1.Controls:布局容器中的所有控件(文本框、下拉框等) |
| | | // dy:服务端返回的实体数据(用于为控件赋值) |
| | | // isEdit:是否为编辑状态(控制控件是否可编辑) |
| | | // gvList:需要同步设置的网格视图列表 |
| | | UtilityHelper.SetValueByObj(this.layoutMx1.Controls, dy, isEdit, gvList); |
| | | |
| | | |
| | | // 解析服务端返回的JSON,提取明细数据列表(存储在rtnData下的list字段中) |
| | | // 使用JObject解析JSON,便于提取嵌套结构的数据 |
| | | JObject _job = JObject.Parse(strJson); |
| | | JArray array = new JArray(); |
| | | // 遍历list数组中的所有元素,添加到新的JArray中(筛选明细数据) |
| | | foreach (var a in _job["rtnData"]["list"]) |
| | | { |
| | | array.Add(a); |
| | | } |
| | | |
| | | // 将明细数据的JSON数组转换为DataTable(适合作为网格控件的数据源) |
| | | DataTable dt = JsonConvert.DeserializeObject<DataTable>(array.ToString()); |
| | | |
| | | // 若明细数据存在(DataTable行数>0) |
| | | if (dt.Rows.Count > 0) |
| | | { |
| | | // 为网格控件gcMx1设置新的绑定上下文(BindingContext) |
| | | // 目的:避免与其他控件共享绑定上下文导致的数据刷新冲突 |
| | | gcMx1.BindingContext = new BindingContext(); |
| | | // 将明细数据绑定到网格控件gcMx1(gcMx1是GridControl,gvMx1是其对应的视图) |
| | | gcMx1.DataSource = dt; |
| | | // 强制初始化网格控件(确保列设置、样式等生效) |
| | | gcMx1.ForceInitialize(); |
| | | // 自动调整网格列宽,使列内容完全显示(优化视觉效果) |
| | | gvMx1.BestFitColumns(); |
| | | |
| | | // 调用工具方法设置网格布局(如限制最大列宽,避免列过宽导致界面混乱) |
| | | Gs.DevApp.ToolBox.UtilityHelper.SetGridLayout(gvMx1); |
| | | } |
| | | // 若明细数据不存在(无记录) |
| | | else |
| | | { |
| | | // 调用工具方法设置默认的网格结构(如空表时显示列标题但无数据行) |
| | | Gs.DevApp.ToolBox.UtilityHelper.SetDefaultTable(gcMx1, gvMx1); |
| | | } |
| | | } |
| | | // 服务端返回失败状态(rtnCode <= 0),显示服务端返回的错误消息 |
| | | else |
| | | ToolBox.MsgHelper.ShowError("提示:" + _rtn.rtnMsg); |
| | | ToolBox.MsgHelper.Warning("提示:" + _rtn.rtnMsg); |
| | | } |
| | | // 捕获执行过程中的异常(如网络错误、JSON解析失败等) |
| | | catch (Exception ex) |
| | | { |
| | | ToolBox.MsgHelper.ShowError("提示:" + ex.Message); |
| | | // 显示异常信息,便于调试和用户反馈 |
| | | ToolBox.MsgHelper.Warning("提示:" + ex.Message); |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 工具条事件 |
| | | /// </summary> |
| | | /// <param name="inFieldValue"></param> |
| | | /// <summary> |
| | | /// |
| | | /// </summary> |
| | | /// <param name="inFieldValue"></param> |
| | | |
| | | private void _toolCk(int _inFieldValue) |
| | | { |
| | | //toolBarMenu1.guidKey = ""; |
| | | //string rowGuid, rowName; |
| | | //(rowGuid, rowName) = UtilityHelper.GetCurrentRow(xtraTabControl1, |
| | | // lbGuid, txt_fBillNo, gridView1, "fBillNo"); |
| | | //toolBarMenu1.guidKey = rowGuid; |
| | | //if (string.IsNullOrEmpty(rowGuid)) |
| | | //{ |
| | | // MsgHelper.Warning("请先选择你要操作的行!"); |
| | | // return; |
| | | //} |
| | | //if (!MsgHelper.AskQuestion("你选择了【" + rowName + "】,确定操作吗?")) |
| | | // return; |
| | | //var frm = new MesQcExceptionalShow(rowGuid); |
| | | //frm.UpdateParent += (s, e) => |
| | | //{ |
| | | // int rowHandle = gridView1.LocateByValue(1, gridView1.Columns["guid"], rowGuid); |
| | | // gridView1.FocusedRowHandle = rowHandle; |
| | | // UtilityHelper.SetCheckIco(gridView1, "chkStatus", "checkBy", "checkDate", picCheckBox, this, _inFieldValue.ToString()); |
| | | //}; |
| | | //frm.ShowDialog(); |
| | | //return; |
| | | string strMsg = ""; |
| | | switch (_inFieldValue) |
| | | { |
| | |
| | | }; |
| | | try |
| | | { |
| | | var strJson = UtilityHelper.HttpPost("", |
| | | _webServiceName + "EditModelSubmit", |
| | | JsonConvert.SerializeObject(_obj)); |
| | | var strJson = UtilityHelper.HttpPost("", _webServiceName + "EditModelSubmit", JsonConvert.SerializeObject(_obj)); |
| | | var _rtn = UtilityHelper.ReturnToDynamic(strJson); |
| | | MsgHelper.Warning(_rtn.rtnData.outMsg.ToString()); |
| | | |
| | | if (_rtn.rtnCode > 0 && _rtn.rtnData.outSum * 1 > 0) |
| | | { |
| | | MsgHelper.ShowInformation(_rtn.rtnData.outMsg.ToString()); |
| | | if (xtraTabControl1.SelectedTabPageIndex == 1) |
| | | { |
| | | getModel(lbGuid.Text.Trim()); |
| | |
| | | gridView1.FocusedRowHandle = rowHandle; |
| | | UtilityHelper.SetCheckIco(gridView1, "chkStatus", "checkUser", "checkDate", picCheckBox, this, _inFieldValue.ToString()); |
| | | } |
| | | else |
| | | MsgHelper.ShowError(_rtn.rtnData.outMsg.ToString()); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | MsgHelper.ShowError("提示:" + ex.Message); |
| | | MsgHelper.Warning("提示:" + ex.Message); |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | } |
| | | } |