using DevExpress.DataAccess.Wizard.Model;
|
using DevExpress.XtraGrid.Views.Grid;
|
using DevExpress.XtraGrid.Views.Grid.ViewInfo;
|
using Gs.DevApp.Entity;
|
using Gs.DevApp.ToolBox;
|
using Gs.DevApp.UserControl;
|
using Newtonsoft.Json;
|
using Newtonsoft.Json.Linq;
|
using System;
|
using System.Collections.Generic;
|
using System.Configuration;
|
using System.Data;
|
using System.Drawing;
|
using System.IO;
|
using System.Net.Http;
|
using System.Threading.Tasks;
|
using System.Windows.Controls;
|
using System.Windows.Forms;
|
|
namespace Gs.DevApp.DevFrm
|
{
|
public partial class Frm_MesQaItemsDetect01 : DevExpress.XtraEditors.XtraForm
|
{
|
string _webServiceName = "MesQaItemsDetect01Manager/";
|
List<FilterEntity> _filterList = new List<FilterEntity>();
|
public Frm_MesQaItemsDetect01()
|
{
|
InitializeComponent();
|
this.toolBarMenu1.btnAddClick += ToolBarMenu1_btnAddClick;
|
this.toolBarMenu1.btnEdtClick += ToolBarMenu1_btnEdtClick;
|
this.toolBarMenu1.btnSaveClick += ToolBarMenu1_btnSaveClick;
|
this.toolBarMenu1.btnLoadClick += ToolBarMenu1_btnLoadClick;
|
this.toolBarMenu1.btnDelClick += ToolBarMenu1_btnDelClick1;
|
this.toolBarMenu1.btnEscClick += ToolBarMenu1_btnEscClick;
|
this.toolBarMenu1.btnQueryClick += ToolBarMenu1_btnQueryClick;
|
this.toolBarMenu1.btnChkClick += ToolBarMenu1_btnChkClick;
|
gcMain.MouseDoubleClick += GcMain_MouseDoubleClick;
|
gvMx1.FocusedRowChanged += GvMx1_FocusedRowChanged;
|
getPageList(1, UtilityHelper.GetPageSize());
|
pageBar1.PagerEvent += PageBar1_PagerEvent;
|
gridView1.CustomDrawRowIndicator += (s, e) =>
|
{
|
if (e.Info.IsRowIndicator && e.RowHandle >= 0)
|
{
|
e.Info.DisplayText = (e.RowHandle + 1).ToString();
|
}
|
};
|
gridView1.CustomDrawEmptyForeground += (s, e) =>
|
{
|
string str = "暂未查找到匹配的数据!";
|
Font f = new Font("微软雅黑", 16);
|
Rectangle r = new Rectangle(gridView1.GridControl.Width / 2 - 100, e.Bounds.Top + 45, e.Bounds.Right - 5, e.Bounds.Height - 5);
|
e.Graphics.DrawString(str, f, Brushes.Gray, r);
|
};
|
//上传附件
|
btnUpSelect.Click += BtnUpSelect_Click;
|
btnUp.Click += BtnUp_Click;
|
//初始化物料选择和各种下拉
|
gvMx2.OptionsFind.ShowSearchNavButtons = false;
|
gvMx2.OptionsView.ShowGroupPanel = false;
|
_setIno();
|
txtJianYan.KeyDown += TxtJianYan_KeyDown;
|
}
|
|
private void TxtJianYan_KeyDown(object sender, KeyEventArgs e)
|
{
|
if (e.KeyCode == Keys.Enter)
|
{
|
string _strCmd = txtJianYan.Text.Trim().ToUpper();
|
string _strOK = "OK";
|
string _strNG = "NG";
|
if (!(_strCmd.StartsWith(_strOK) || _strCmd.StartsWith(_strNG)))
|
{
|
Gs.DevApp.ToolBox.MsgHelper.ShowError("命令输入错误:请正确使用OK 或 NG 命令!");
|
return;
|
}
|
if (!_strCmd.Contains("-"))
|
{
|
Gs.DevApp.ToolBox.MsgHelper.ShowError("命令输入错误:缺少 中画线!");
|
return;
|
}
|
string[] _ary = _strCmd.Split('-');
|
if (_ary.Length != 2)
|
{
|
Gs.DevApp.ToolBox.MsgHelper.ShowError("命令输入错误::请正确使用OK 或 NG 命令!");
|
return;
|
}
|
string _str1 = _ary[0];
|
if (!(_str1 == _strOK || _str1 == _strNG))
|
{
|
Gs.DevApp.ToolBox.MsgHelper.ShowError("命令输入错误:请正确使用OK 或 NG 命令!");
|
return;
|
}
|
string _str2 = _ary[1];
|
int n;
|
if (int.TryParse(_str2, out n))
|
{
|
|
}
|
else
|
{
|
Gs.DevApp.ToolBox.MsgHelper.ShowError("命令输入错误:请正确使用OK 或 NG 命令!");
|
return;
|
}
|
for (int i = 0; i < gvMx2.DataRowCount; i++)
|
{
|
gvMx2.SetRowCellValue(i, "fcheckResu", _str1);
|
gvMx2.SetRowCellValue(i, "fstand", _str1);
|
}
|
}
|
}
|
|
/// <summary>
|
/// 双击事件
|
/// </summary>
|
/// <param name="sender"></param>
|
/// <param name="e"></param>
|
private void GcMain_MouseDoubleClick(object sender, MouseEventArgs e)
|
{
|
string rowGuid = Gs.DevApp.ToolBox.UtilityHelper.GetCurrentDoubleRow(gridView1, e, "guid");
|
if (!string.IsNullOrEmpty(rowGuid))
|
getModel(rowGuid, false, 999);
|
}
|
/// <summary>
|
/// 分页事件
|
/// </summary>
|
/// <param name="curPage"></param>
|
/// <param name="pageSize"></param>
|
private void PageBar1_PagerEvent(int curPage, int pageSize)
|
{
|
getPageList(curPage, pageSize);
|
}
|
/// <summary>
|
/// 查询事件
|
/// </summary>
|
/// <param name="sender"></param>
|
/// <param name="e"></param>
|
private void ToolBarMenu1_btnQueryClick(object sender, EventArgs e)
|
{
|
Gs.DevApp.UserControl.ShowFilter frm = new Gs.DevApp.UserControl.ShowFilter(gridView1.Columns, _filterList);
|
frm.UpdateParent += Frm_UpdateParent;
|
frm.ShowDialog();
|
}
|
/// <summary>
|
/// 查询回调
|
/// </summary>
|
/// <param name="sender"></param>
|
/// <param name="e"></param>
|
private void Frm_UpdateParent(object sender, UpdateParentEventArgs e)
|
{
|
_filterList = e.FilterList;
|
getPageList(1, pageBar1.RowsCount);
|
}
|
private void ToolBarMenu1_btnChkClick(object sender, EventArgs e)
|
{
|
toolBarMenu1.guidKey = "";
|
string rowGuid, rowName;
|
(rowGuid, rowName) = UtilityHelper.GetCurrentRow(xtraTabControl1,
|
lbGuid, txt_releaseNo, gridView1);
|
toolBarMenu1.guidKey = rowGuid;
|
}
|
/// <summary>
|
/// 取消事件
|
/// </summary>
|
/// <param name="sender"></param>
|
/// <param name="e"></param>
|
private void ToolBarMenu1_btnEscClick(object sender, EventArgs e)
|
{
|
UtilityHelper.JumpToTab(xtraTabControl1, 0);
|
}
|
|
/// <summary>
|
/// 删除事件
|
/// </summary>
|
/// <param name="sender"></param>
|
/// <param name="e"></param>
|
private void ToolBarMenu1_btnDelClick1(object sender, EventArgs e)
|
{
|
string rowGuid = "", rowName = "";
|
(rowGuid, rowName) = UtilityHelper.GetCurrentRow(xtraTabControl1, lbGuid, txt_releaseNo, gridView1);
|
if (string.IsNullOrEmpty(rowGuid))
|
{
|
ToolBox.MsgHelper.Warning("请先选择你要操作的行!");
|
return;
|
}
|
if (!MsgHelper.AskQuestion("你选择了【" + rowName + "】,确定删除吗?"))
|
return;
|
List<dynamic> lst = new List<dynamic>();
|
lst.Add(rowGuid);
|
var _obj = lst;
|
try
|
{
|
string strJson = UtilityHelper.HttpPost("", _webServiceName + "DeleteModel", JsonConvert.SerializeObject(_obj));
|
ReturnModel<dynamic> _rtn = ToolBox.UtilityHelper.ReturnToDynamic(strJson);
|
if (_rtn.rtnCode > 0)
|
{
|
UtilityHelper.JumpToTab(xtraTabControl1, 0);
|
getPageList(1, UtilityHelper.GetPageSize());
|
}
|
ToolBox.MsgHelper.Warning("提示:" + _rtn.rtnMsg);
|
}
|
catch (Exception ex)
|
{
|
ToolBox.MsgHelper.Warning("提示:" + ex.Message);
|
}
|
}
|
|
/// <summary>
|
/// 刷新事件
|
/// </summary>
|
/// <param name="sender"></param>
|
/// <param name="e"></param>
|
private void ToolBarMenu1_btnLoadClick(object sender, EventArgs e)
|
{
|
UtilityHelper.JumpToTab(xtraTabControl1, 0);
|
getPageList(1, UtilityHelper.GetPageSize());
|
}
|
/// <summary>
|
/// 修改事件
|
/// </summary>
|
/// <param name="sender"></param>
|
/// <param name="e"></param>
|
private void ToolBarMenu1_btnEdtClick(object sender, EventArgs e)
|
{
|
string rowGuid = "", rowName = "";
|
(rowGuid, rowName) = UtilityHelper.GetCurrentRow(xtraTabControl1, lbGuid, txt_releaseNo, gridView1);
|
if (string.IsNullOrEmpty(rowGuid))
|
{
|
ToolBox.MsgHelper.Warning("请先选择你要操作的行!");
|
return;
|
}
|
getModel(rowGuid, true, 1);
|
}
|
/// <summary>
|
/// 新增事件
|
/// </summary>
|
/// <param name="sender"></param>
|
/// <param name="e"></param>
|
private void ToolBarMenu1_btnAddClick(object sender, EventArgs e)
|
{
|
UtilityHelper.JumpToTab(xtraTabControl1, 1);
|
lbGuid.Text = "";
|
List<DevExpress.XtraGrid.Views.Grid.GridView> gridViews = new List<DevExpress.XtraGrid.Views.Grid.GridView>();
|
gridViews.Add(gvMx1);
|
gridViews.Add(gvMx2);
|
UtilityHelper.CleanValueByControl(this.panel1.Controls, true, gridViews);
|
Gs.DevApp.ToolBox.UtilityHelper.SetDefaultTable(gcMx1, gvMx1);
|
}
|
/// <summary>
|
/// 保存事件
|
/// </summary>
|
/// <param name="sender"></param>
|
/// <param name="e"></param>
|
private void ToolBarMenu1_btnSaveClick(object sender, EventArgs e)
|
{
|
toolBarMenu1.isSetBtn = false;
|
//if (string.IsNullOrEmpty(txt_account.Text.Trim()))
|
{
|
Gs.DevApp.ToolBox.MsgHelper.Warning("登录账号不能为空!");
|
// txt_account.Focus();
|
return;
|
}
|
var _obj = new
|
{
|
guid = UtilityHelper.ToGuid(lbGuid.Text.Trim()), //主建
|
};
|
try
|
{
|
string strJson = UtilityHelper.HttpPost("", _webServiceName + "EditModel", JsonConvert.SerializeObject(_obj));
|
ReturnModel<dynamic> _rtn = ToolBox.UtilityHelper.ReturnToDynamic(strJson);
|
ToolBox.MsgHelper.Warning("提示:" + _rtn.rtnMsg);
|
if (_rtn.rtnCode > 0)
|
{
|
lbGuid.Text = _rtn.rtnData;
|
toolBarMenu1.isSetBtn = true;
|
UtilityHelper.ChangeEnableByControl(this.panel1.Controls, false);
|
}
|
}
|
catch (Exception ex)
|
{
|
ToolBox.MsgHelper.Warning("提示:" + ex.Message);
|
}
|
}
|
|
/// <summary>
|
///
|
/// </summary>
|
/// <param name="curPage">第几页</param>
|
/// <param name="pageSize">每页几条</param>
|
private async void getPageList(int curPage, int pageSize)
|
{
|
UcLoading _loading = new UcLoading();
|
System.Text.StringBuilder _sbSqlWhere = new System.Text.StringBuilder();
|
foreach (FilterEntity itm in _filterList)
|
{
|
_sbSqlWhere.Append(" and " + itm.fileId + itm.fileOper + "'" + itm.fileValue + "'");
|
}
|
PageQueryModel pgq = new PageQueryModel(curPage, pageSize, "create_date", "asc", "", _sbSqlWhere.ToString());
|
string json = JsonConvert.SerializeObject(pgq);
|
try
|
{
|
string strReturn = await UtilityHelper.HttpPostAsync("", _webServiceName + "GetListPage", json);
|
ReturnModel<PageListModel> dd = UtilityHelper.ReturnToTablePage(strReturn);
|
if (dd.rtnCode > 0)
|
{
|
DataTable dt = dd.rtnData.list;
|
gcMain.BindingContext = new BindingContext();
|
gcMain.DataSource = dt;
|
gcMain.ForceInitialize();
|
int dddd = dd.rtnData.pages;//总页
|
pageBar1.TotalPages = dddd;
|
pageBar1.RecordCount = dd.rtnData.total;//记录总数
|
pageBar1.CurrentPage = curPage;//当前页
|
pageBar1.RowsCount = pageSize;//每页显示
|
pageBar1.setTxt();
|
}
|
else
|
{
|
ToolBox.MsgHelper.ShowError("提示:" + dd.rtnMsg);
|
}
|
}
|
catch (Exception ex)
|
{
|
ToolBox.MsgHelper.Warning("提示:" + ex.Message);
|
}
|
_loading.Stop();
|
}
|
private void getModel(string strGuid, bool isEdit, int tabIdx)
|
{
|
if (string.IsNullOrEmpty(strGuid))
|
{
|
ToolBox.MsgHelper.Warning("请先选择你要操作的行!");
|
return;
|
}
|
UtilityHelper.JumpToTab(xtraTabControl1, tabIdx);
|
var _obj = new
|
{
|
guid = strGuid,//主建
|
};
|
try
|
{
|
string strJson = UtilityHelper.HttpPost("", _webServiceName + "GetModel", JsonConvert.SerializeObject(_obj));
|
ReturnModel<dynamic> _rtn = ToolBox.UtilityHelper.ReturnToDynamic(strJson);
|
if (_rtn.rtnCode > 0)
|
{
|
dynamic dy = _rtn.rtnData;
|
lbGuid.Text = strGuid;
|
List<DevExpress.XtraGrid.Views.Grid.GridView> gvList = new List<DevExpress.XtraGrid.Views.Grid.GridView>();
|
gvList.Add(gvMx1);
|
UtilityHelper.SetValueByObj(this.panel1.Controls, dy, isEdit, gvList);
|
JObject _job = JObject.Parse(strJson);
|
JArray array = new JArray();
|
foreach (var a in _job["rtnData"]["list5"])
|
{
|
array.Add(a);
|
}
|
DataTable dt = JsonConvert.DeserializeObject<DataTable>(array.ToString());
|
if (dt.Rows.Count > 0)
|
{
|
gcMx1.BindingContext = new BindingContext();
|
gcMx1.DataSource = dt;
|
gcMx1.ForceInitialize();
|
}
|
else
|
{
|
Gs.DevApp.ToolBox.UtilityHelper.SetDefaultTable(gcMx1, gvMx1);
|
}
|
}
|
else
|
ToolBox.MsgHelper.Warning("提示:" + _rtn.rtnMsg);
|
}
|
catch (Exception ex)
|
{
|
ToolBox.MsgHelper.Warning("提示:" + ex.Message);
|
}
|
}
|
|
|
|
#region 文件上传
|
|
/// <summary>
|
/// 选择上传文件
|
/// </summary>
|
/// <param name="sender"></param>
|
/// <param name="e"></param>
|
private void BtnUpSelect_Click(object sender, EventArgs e)
|
{
|
var openFileDialog = new OpenFileDialog();
|
// 设置初始目录
|
openFileDialog.InitialDirectory = "c:\\";
|
// 设置文件过滤选项,如:"文本文件 (*.txt)|*.txt|所有文件 (*.*)|*.*"
|
openFileDialog.Filter = "文本文件 (*.txt)|*.txt|所有文件 (*.*)|*.*";
|
// 设置标题
|
openFileDialog.Title = "选择文件";
|
// 显示对话框
|
var result = openFileDialog.ShowDialog();
|
// 确认用户没有取消操作
|
if (result == DialogResult.OK)
|
{
|
// 获取选中的文件路径
|
var filePath = openFileDialog.FileName;
|
Console.WriteLine($"选中的文件: {filePath}");
|
txtUpUrl.Text = filePath;
|
}
|
}
|
|
/// <summary>
|
/// 确定上传
|
/// </summary>
|
/// <param name="sender"></param>
|
/// <param name="e"></param>
|
private async void BtnUp_Click(object sender, EventArgs e)
|
{
|
var WebApiUrl = ConfigurationSettings.AppSettings.Get("WebApiUrl");
|
var address = WebApiUrl + "Upload/UploadFile";
|
var filePath = txtUpUrl.Text.Trim();
|
var apiUrl = address; // 替换为你的API地址
|
await UploadFileAsync(apiUrl, filePath);
|
}
|
|
private async Task UploadFileAsync(string url, string filePath)
|
{
|
UcLoading _loading = new UcLoading();
|
using (var httpClient = new HttpClient())
|
using (var form = new MultipartFormDataContent())
|
{
|
httpClient.DefaultRequestHeaders.Add("token",
|
UtilityHelper.GetBasicAuthTicket());
|
using (var fs = File.OpenRead(filePath))
|
using (var streamContent = new StreamContent(fs))
|
{
|
form.Add(streamContent, "file", Path.GetFileName(filePath));
|
var response = await httpClient.PostAsync(url, form);
|
var responseString =
|
await response.Content.ReadAsStringAsync();
|
MessageBox.Show(responseString);
|
}
|
}
|
_loading.Close();
|
}
|
|
#endregion
|
|
private void _setIno()
|
{
|
txt_itemId.KeyFile = "id";
|
txt_itemId.EditChanged += (s, e) =>
|
{
|
txt_itemModel.Text = this.txt_itemId.GetModel();
|
txt_itemNo.Text = this.txt_itemId.GetCode();
|
};
|
}
|
/// <summary>
|
/// 读取检验结果
|
/// </summary>
|
/// <param name="sender"></param>
|
/// <param name="e"></param>
|
private void GvMx1_FocusedRowChanged(object sender, DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventArgs e)
|
{
|
var myDataRow = gvMx1.GetDataRow(e.FocusedRowHandle);
|
if (myDataRow == null) return;
|
var _obj = new
|
{
|
parentGuid = UtilityHelper.ToGuid(lbGuid.Text.Trim()), //主建
|
guid = UtilityHelper.ToGuid(myDataRow["guid"].ToString()), //主建
|
//id = myDataRow["id"].ToString(),
|
id = -1,
|
checkQyt = myDataRow["checkQyt"].ToString(),
|
chkItem = myDataRow["fcheckItem"].ToString()
|
};
|
try
|
{
|
var strReturn = UtilityHelper.HttpPost("", _webServiceName + "GetCheckResultList12", JsonConvert.SerializeObject(_obj));
|
var dd = UtilityHelper.ReturnToList(strReturn);
|
var dt = dd.rtnData;
|
gcMx2.BindingContext = new BindingContext();
|
gcMx2.DataSource = dt;
|
gcMx2.ForceInitialize();
|
}
|
catch (Exception ex)
|
{
|
MsgHelper.Warning("提示:" + ex.Message);
|
}
|
}
|
}
|
}
|