lu
2024-11-08 1a080e99a3d5acd4fddb0ff658c369e2a33e41a9
DevApp/Gs.DevApp/DevFrm/QC/Frm_MesQaItemsDetect01Check.cs
@@ -5,12 +5,8 @@
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.Forms;
namespace Gs.DevApp.DevFrm.QC
@@ -28,9 +24,10 @@
            this.toolBarMenu1.btnZhiLiangFchkClick += ToolBarMenu1_btnZhiLiangFchkClick;
            this.toolBarMenu1.btnCaiGouChkClick += ToolBarMenu1_btnCaiGouChkClick;
            this.toolBarMenu1.btnCaiGouFchkClick += ToolBarMenu1_btnCaiGouFchkClick;
            this.toolBarMenu1.btnBoHuiClick += ToolBarMenu1_btnBoHuiClick;
            toolBarMenu1.btnLogClick += ToolBarMenu1_btnLogClick;
            gcMain.MouseDoubleClick += GcMain_MouseDoubleClick;
            gvMx1.FocusedRowChanged += GvMx1_FocusedRowChanged;
            gcMx1.MouseClick += GcMx1_MouseClick;
            getPageList(1, UtilityHelper.GetPageSize());
            pageBar1.PagerEvent += PageBar1_PagerEvent;
            gridView1.CustomDrawRowIndicator += (s, e) =>
@@ -47,16 +44,27 @@
                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();
            gvMx3.OptionsFind.ShowSearchNavButtons = false;
            gvMx3.OptionsView.ShowGroupPanel = false;
            txt_itemId.KeyFile = "id";
            txt_itemId.EditChanged += (s, e) =>
            {
                txt_itemModel.Text = this.txt_itemId.GetModel();
                txt_itemNo.Text = this.txt_itemId.GetCode();
            };
            ucUpFile1.UpChanged += UcUpFile1_UpChanged;
            xtraTabControl2.SelectedPageChanged += XtraTabControl2_SelectedPageChanged;
        }
        private void GcMx1_MouseClick(object sender, MouseEventArgs e)
        {
            string rowGuid = Gs.DevApp.ToolBox.UtilityHelper.GetCurrentDoubleRow(gvMx1, e, "guid");
            if (string.IsNullOrEmpty(rowGuid))
                return;
            getList12(rowGuid);
        }
        /// <summary>
        /// 双击事件
        /// </summary>
@@ -106,6 +114,24 @@
                lbGuid, txt_releaseNo, gridView1);
            toolBarMenu1.guidKey = rowGuid;
        }
        /// <summary>
        /// 驳回
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ToolBarMenu1_btnBoHuiClick(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_btnCaiGouFchkClick(object sender, EventArgs e)
        {
            toolBarMenu1.guidKey = "";
@@ -114,7 +140,11 @@
                lbGuid, txt_releaseNo, gridView1);
            toolBarMenu1.guidKey = rowGuid;
        }
        /// <summary>
        /// 采购审核
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ToolBarMenu1_btnCaiGouChkClick(object sender, EventArgs e)
        {
            toolBarMenu1.guidKey = "";
@@ -123,7 +153,11 @@
                lbGuid, txt_releaseNo, gridView1);
            toolBarMenu1.guidKey = rowGuid;
        }
        /// <summary>
        /// 质量反审核
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ToolBarMenu1_btnZhiLiangFchkClick(object sender, EventArgs e)
        {
            toolBarMenu1.guidKey = "";
@@ -132,7 +166,11 @@
                lbGuid, txt_releaseNo, gridView1);
            toolBarMenu1.guidKey = rowGuid;
        }
        /// <summary>
        /// 质量审核
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ToolBarMenu1_btnZhiLiangChkClick(object sender, EventArgs e)
        {
            toolBarMenu1.guidKey = "";
@@ -149,10 +187,12 @@
        /// <param name="e"></param>
        private void ToolBarMenu1_btnLoadClick(object sender, EventArgs e)
        {
            UtilityHelper.JumpToTab(xtraTabControl1, 0);
            getPageList(1, UtilityHelper.GetPageSize());
            if (xtraTabControl1.SelectedTabPageIndex == 1)
                getModel(lbGuid.Text.Trim(), false, 999);
            else
                getPageList(1, UtilityHelper.GetPageSize());
        }
        /// <summary>
        /// 
        /// </summary>
@@ -196,7 +236,7 @@
            }
            _loading.Stop();
        }
        private void getModel(string strGuid, bool isEdit, int tabIdx)
        private async void getModel(string strGuid, bool isEdit, int tabIdx)
        {
            if (string.IsNullOrEmpty(strGuid))
            {
@@ -204,13 +244,14 @@
                return;
            }
            UtilityHelper.JumpToTab(xtraTabControl1, tabIdx);
            UcLoading _loading = new UcLoading();
            var _obj = new
            {
                guid = strGuid,//主建
            };
            try
            {
                string strJson = UtilityHelper.HttpPost("", _webServiceName + "GetModel", JsonConvert.SerializeObject(_obj));
                string strJson = await UtilityHelper.HttpPostAsync("", _webServiceName + "GetModel", JsonConvert.SerializeObject(_obj));
                ReturnModel<dynamic> _rtn = ToolBox.UtilityHelper.ReturnToDynamic(strJson);
                if (_rtn.rtnCode > 0)
                {
@@ -231,6 +272,8 @@
                        gcMx1.BindingContext = new BindingContext();
                        gcMx1.DataSource = dt;
                        gcMx1.ForceInitialize();
                        ucUpFile1.parentGuid = lbGuid.Text.Trim();
                        getList12(dt.Rows[0]["guid"].ToString());
                    }
                    else
                    {
@@ -244,103 +287,71 @@
            {
                ToolBox.MsgHelper.Warning("提示:" + ex.Message);
            }
            _loading.Stop();
        }
        #region 文件上传
        /// <summary>
        ///     选择上传文件
        /// 选项卡切换
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void BtnUpSelect_Click(object sender, EventArgs e)
        private void XtraTabControl2_SelectedPageChanged(object sender, DevExpress.XtraTab.TabPageChangedEventArgs e)
        {
            var openFileDialog = new OpenFileDialog();
            // 设置初始目录
            openFileDialog.InitialDirectory = "c:\\";
            // 设置文件过滤选项,如:"文本文件 (*.txt)|*.txt|所有文件 (*.*)|*.*"
            openFileDialog.Filter = "文本文件 (*.txt)|*.txt|所有文件 (*.*)|*.*";
            // 设置标题
            openFileDialog.Title = "选择文件";
            // 显示对话框
            var result = openFileDialog.ShowDialog();
            // 确认用户没有取消操作
            if (result == DialogResult.OK)
            if (e.Page.Name == "tabMxPage3")
            {
                // 获取选中的文件路径
                var filePath = openFileDialog.FileName;
                Console.WriteLine($"选中的文件: {filePath}");
                txtUpUrl.Text = filePath;
                getFileList();
            }
        }
        /// <summary>
        ///     确定上传
        /// 上传后刷新文件列表
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private async void BtnUp_Click(object sender, EventArgs e)
        private void UcUpFile1_UpChanged(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);
            getFileList();
        }
        private async Task UploadFileAsync(string url, string filePath)
        private void getFileList()
        {
            UcLoading _loading = new UcLoading();
            using (var httpClient = new HttpClient())
            using (var form = new MultipartFormDataContent())
            System.Text.StringBuilder _sbSqlWhere = new System.Text.StringBuilder();
            _sbSqlWhere.Append(" and parent_Guid='" + lbGuid.Text.Trim() + "'");
            PageQueryModel pgq = new PageQueryModel(1, 100, "create_date", "asc", "", _sbSqlWhere.ToString());
            string json = JsonConvert.SerializeObject(pgq);
            try
            {
                httpClient.DefaultRequestHeaders.Add("token",
                    UtilityHelper.GetBasicAuthTicket());
                using (var fs = File.OpenRead(filePath))
                using (var streamContent = new StreamContent(fs))
                string strReturn = UtilityHelper.HttpPost("", "MesFile/GetListPage", json);
                ReturnModel<PageListModel> dd = UtilityHelper.ReturnToTablePage(strReturn);
                if (dd.rtnCode > 0)
                {
                    form.Add(streamContent, "file", Path.GetFileName(filePath));
                    var response = await httpClient.PostAsync(url, form);
                    var responseString =
                        await response.Content.ReadAsStringAsync();
                    MessageBox.Show(responseString);
                    DataTable dt = dd.rtnData.list;
                    gcMx3.BindingContext = new BindingContext();
                    gcMx3.DataSource = dt;
                    gcMx3.ForceInitialize();
                }
                else
                {
                    ToolBox.MsgHelper.ShowError("提示:" + dd.rtnMsg);
                }
            }
            _loading.Close();
        }
        #endregion
        private void _setIno()
        {
            txt_itemId.KeyFile = "id";
            txt_itemId.EditChanged += (s, e) =>
            catch (Exception ex)
            {
                txt_itemModel.Text = this.txt_itemId.GetModel();
                txt_itemNo.Text = this.txt_itemId.GetCode();
            };
                ToolBox.MsgHelper.Warning("提示:" + ex.Message);
            }
        }
        /// <summary>
        /// 读取检验结果
        /// 根据检验项目读取抽样结果
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void GvMx1_FocusedRowChanged(object sender, DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventArgs e)
        /// <param name="guid5"></param>
        private async void getList12(string guid5)
        {
            var myDataRow = gvMx1.GetDataRow(e.FocusedRowHandle);
            if (myDataRow == null) return;
            UcLoading _loading = new UcLoading();
            var _obj = new
            {
                parentGuid = UtilityHelper.ToGuid(lbGuid.Text.Trim()), //主建
                guid = UtilityHelper.ToGuid(myDataRow["guid"].ToString()), //主建
                checkQyt = myDataRow["checkQyt"].ToString(),
                chkItem = myDataRow["fcheckItem"].ToString()
                guid = UtilityHelper.ToGuid(guid5), //主建
            };
            try
            {
                var strReturn = UtilityHelper.HttpPost("", _webServiceName + "GetCheckResultList12", JsonConvert.SerializeObject(_obj));
                var strReturn = await UtilityHelper.HttpPostAsync("", _webServiceName + "GetModel12", JsonConvert.SerializeObject(_obj));
                var dd = UtilityHelper.ReturnToList(strReturn);
                var dt = dd.rtnData;
                gcMx2.BindingContext = new BindingContext();
@@ -351,7 +362,45 @@
            {
                MsgHelper.Warning("提示:" + ex.Message);
            }
            _loading.Stop();
        }
        private void repositoryItemButtonEdit1_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
        {
            var rowhandle = gvMx3.FocusedRowHandle;
            if (rowhandle < 0)
                return;
            if (e.Button.Index == 0)
            {
                var dr = gvMx3.GetDataRow(rowhandle);
                var mxGuid = dr["guid"].ToString();
                if (!MsgHelper.AskQuestion("你选择了1条数据,确定删除吗?"))
                    return;
                var strJson = "";
                var lst = new List<string>();
                lst.Add(mxGuid);
                try
                {
                    strJson = UtilityHelper.HttpPost("", "MesFile/DeleteModel",
                        JsonConvert.SerializeObject(lst));
                    var _rtn = UtilityHelper.ReturnToDynamic(strJson);
                    if (_rtn.rtnCode > 0) gvMx3.DeleteRow(rowhandle);
                    MsgHelper.Warning("提示:" + _rtn.rtnMsg);
                }
                catch (Exception ex)
                {
                    MsgHelper.Warning("提示:" + ex.Message);
                }
            }
        }
        private void repositoryItemButtonEdit2_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
        {
            var rowhandle = gvMx3.FocusedRowHandle;
            if (rowhandle < 0)
                return;
            if (e.Button.Index == 0)
            {
                MsgHelper.Warning("提示:" + "开发中");
            }
        }
    }
}