FormConfig.cs_200528

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Xml;
//using System.Text;
using MT8852B_Driver;
using System.IO;

namespace NRF52382_Test
{

public partial class FormConfig : Form
{
    FormMain frmMain = new FormMain();

    public void LoadXMLToDataGridView()
    {
        XmlTextReader xml = null;
        DataTable dt = null;
        string strMsg = "";
        try
        {
            dt = new DataTable();
            //添加列名
            dt.Columns.Add("TestCase", typeof(string));
            dt.Columns.Add("Parameter", typeof(string));
            dt.Columns.Add("Enable", typeof(string));
            //dt.Columns.Add("1", typeof(DataGridViewButtonColumn));
            //dt.Columns.Add("Description", typeof(string));

            string strJsonfile = System.Environment.CurrentDirectory + "\\TestSrcipt.xml";
            xml = new XmlTextReader(strJsonfile);
            xml.WhitespaceHandling = WhitespaceHandling.None;

            while (xml.Read())
            {
                if (xml.NodeType == XmlNodeType.Element)
                {
                    if (xml.Name == "COM")
                    {
                        tbCOM.Text = xml.ReadString();
                    }
                    if (xml.Name == "GPIB_Index")
                    {
                        List<string> ls = new List<string>();
                        string strTmp = xml.GetAttribute("Elements");
                        List<string> list = new List<string>(strTmp.Split(','));
                        list.ForEach(i => ls.Add(i));

                        string strCurrVaule = xml.ReadString();
                        ls.ForEach(x => cbGpibIndex.Items.Add(x.ToString()));
                        cbGpibIndex.SelectedIndex = cbGpibIndex.Items.IndexOf(strCurrVaule);

                        //cbGpibIndex.Text = xml.ReadString();
                    }
                    if (xml.Name == "GPIB_Address")
                    {
                        tbGpibAddress.Text = xml.ReadString();
                    }

                    if (xml.Name == "TestCase1" || xml.Name == "TestCase2" || xml.Name == "TestCase3" || xml.Name == "TestCase4" || xml.Name == "TestCase5" || xml.Name == "TestCase6" || xml.Name == "TestCase7" || xml.Name == "TestCase8" || xml.Name == "TestCase9")
                    {
                        DataRow dr = dt.NewRow();
                        string strCaseName = xml.GetAttribute("Name");
                        dr["TestCase"] = strCaseName;
                        string strVaule = xml.GetAttribute("Value");
                        dr["Parameter"] = strVaule;
                        string strEnable = xml.GetAttribute("Enable");                            
                        dr["Enable"] = strEnable;
                        dt.Rows.Add(dr);                          
                    }                        
                }                   
            }
            //创建DataSet对象,绑定数据
            DataSet ds = new DataSet();
            ds.Tables.Add(dt);
            dataGridView1.DataSource = dt;
            dataGridView1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells;

            //for(int i = 0;i<dt.Columns.Count-1;i++)
            {
                DataGridViewButtonColumn btn = new DataGridViewButtonColumn();
                btn.Name = "btnModify";
                btn.HeaderText = "修改";
                btn.DefaultCellStyle.NullValue = "修改";
                dataGridView1.Columns.Add(btn);
            }
        }
        catch (XmlException xmlEx)
        {
            strMsg = xmlEx.Message.ToString();
            MessageBox.Show(strMsg);
        }
        catch (DataException dataEx)
        {
            strMsg = dataEx.Message.ToString();
            MessageBox.Show(strMsg);
        }
        catch (SystemException sysEx)
        {
            strMsg = sysEx.Message.ToString();
            MessageBox.Show(strMsg);
        }
        finally
        {
            xml.Close();
        }
    }

    public void SaveXMLFromDataGridView()
    {
        string strTmp = "";
        string strMsg = "";
        string strJsonfile = System.Environment.CurrentDirectory + "\\TestSrcipt.xml";
        XmlDocument xml = null;
        try
        {
            xml = new XmlDocument();
            xml.Load(strJsonfile);

            XmlElement pXmlElement = xml.SelectSingleNode(@"configuration/BtTest/Init/COM") as XmlElement;
            pXmlElement.InnerText = tbCOM.Text;

            pXmlElement = xml.SelectSingleNode(@"configuration/BtTest/Init/GPIB_Index") as XmlElement;
            pXmlElement.InnerText = cbGpibIndex.Text;

            pXmlElement = xml.SelectSingleNode(@"configuration/BtTest/Init/GPIB_Address") as XmlElement;
            pXmlElement.InnerText = tbGpibAddress.Text;


            for (int i = 0; i < 9; i++)
            {
                string strTmp2 = string.Format("configuration/BtTest/TestCase/TestCase{0}", (i + 1));
                pXmlElement = xml.SelectSingleNode(strTmp2) as XmlElement;
                strTmp = dataGridView1["Parameter", i].Value.ToString();
                pXmlElement.SetAttribute("Value", strTmp);
                //pXmlElement.InnerText = strTmp;
            }
            xml.Save(strJsonfile);
            MessageBox.Show("数据保存成功!");
            this.Close();
        }
        catch (XmlException xmlEx)
        {
            strMsg = xmlEx.Message.ToString();
            MessageBox.Show(strMsg);
        }
        catch (DataException dataEx)
        {
            strMsg = dataEx.Message.ToString();
            MessageBox.Show(strMsg);
        }
        catch (SystemException sysEx)
        {
            strMsg = sysEx.Message.ToString();
            MessageBox.Show(strMsg);
        }
        finally
        {
        }
    }

    public FormConfig()
    {
        InitializeComponent();
        LoadXMLToDataGridView();
    }


    public FormConfig(FormMain formMain)
    {
        frmMain = formMain;
        InitializeComponent();
    }


    #region 直接删除指定目录下的所有文件及文件夹(保留目录)
    public static void DeleteDir(string file)
    {
        try
        {
            //去除文件夹和子文件的只读属性
            //去除文件夹的只读属性
            System.IO.DirectoryInfo fileInfo = new DirectoryInfo(file);
            fileInfo.Attributes = FileAttributes.Normal & FileAttributes.Directory;

            //去除文件的只读属性
            System.IO.File.SetAttributes(file, System.IO.FileAttributes.Normal);

            //判断文件夹是否还存在
            if (Directory.Exists(file))
            {
                foreach (string f in Directory.GetFileSystemEntries(file))
                {
                    if (File.Exists(f))
                    {
                        //如果有子文件删除文件
                        File.Delete(f);
                        Console.WriteLine(f);
                    }
                    else
                    {
                        //循环递归删除子文件夹
                        DeleteDir(f);
                    }
                }

                //删除空文件夹
                //Directory.Delete(file);
                Console.WriteLine(file);
            }

        }
        catch (Exception ex) // 异常处理
        {
            Console.WriteLine(ex.Message.ToString());// 异常信息
        }
    }

    #endregion

    //public delegate void ShowStatedelegate(string txt);//定义一个委托
    //public event mydelegate myevent;

   
    private void FormConfig_Load(object sender, EventArgs e)
    {
        LoadXMLToDataGridView();
        FormLogin frmLogin = new FormLogin();
        frmLogin.ShowDialog();
        if (frmLogin.DialogResult == DialogResult.OK)//如果登录框返回DialogResult.OK
        {
            //MessageBox.Show("正常登录");
        }
        else
        {
            this.Close();
        }
    }

    private void ReportClear_Click(object sender, EventArgs e)
    {
        //清除文件夹的所有文件
        DeleteDir(System.Environment.CurrentDirectory + "\\Log\\");
        DeleteDir(System.Environment.CurrentDirectory + "\\CSV\\");

        frmMain.tbPass.Text = "0";
        frmMain.tbFail.Text = "0";
        frmMain.tbTotal.Text = "0";
        frmMain.tbFYP.Text = "100%";
        frmMain.ResetFYP();
    }

    private void btSave_Click(object sender, EventArgs e)
    {
        SaveXMLFromDataGridView();
    }

    private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
    {
        if (dataGridView1.Columns[e.ColumnIndex].Name == "btnModify" && e.RowIndex >= 0)
        {
            TxTestCase TxTestPara = new TxTestCase();
            RxTestCase RxTestPara = new RxTestCase();

            
            string strVaule = Convert.ToString(dataGridView1.CurrentRow.Cells[1].Value);
            List<string> listPara = new List<string>(strVaule.Split(','));
            TxTestPara.iTxBLEStandard = Convert.ToInt16(listPara[1]);
            TxTestPara.channel = (E_Channel)Convert.ToInt16(listPara[2]);
            TxTestPara.iRange = Convert.ToInt16(listPara[3]);
            TxTestPara.sFixedOffset = listPara[4];

            TxTestPara.iTrigger = Convert.ToInt16(listPara[5]);
            TxTestPara.sCapturePeriod = listPara[6];
            TxTestPara.sSyscWord0x = listPara[7];
            TxTestPara.iPayload = Convert.ToInt16(listPara[8]);
            TxTestPara.sAnternnaPattern = listPara[9];

            TxTestPara.IsTest_OutputPower = listPara[10] == "1" ? true : false;
            TxTestPara.IsTest_CarrierDrift = listPara[11] == "1" ? true : false;
            TxTestPara.IsTest_ModulationIndex = listPara[12] == "1" ? true : false;

            RxTestPara.iRxBLEStandard = Convert.ToInt16(listPara[14]);
            RxTestPara.channel = (E_Channel)Convert.ToInt16(listPara[15]);
            RxTestPara.sPowerLevel = listPara[16];
            RxTestPara.sLoss = listPara[17];
            RxTestPara.iPayload = Convert.ToInt16(listPara[18]);
            RxTestPara.sSyscWord0x = listPara[19];
            RxTestPara.sSpacing = listPara[20];
            RxTestPara.sPackets = listPara[21];
            RxTestPara.sCTELength = listPara[22];

            RxTestPara.iSlotDuration = Convert.ToInt16(listPara[23]);
            RxTestPara.iDirtyTransmitter = Convert.ToInt16(listPara[24]);
            RxTestPara.iAlternateBadCRC = Convert.ToInt16(listPara[25]);
                        

            string strTxRxEnable = Convert.ToString(dataGridView1.CurrentRow.Cells[2].Value);
            List<string> listRxTxEnable = new List<string>(strTxRxEnable.Split(','));
            if(listRxTxEnable[0] == "1")
            {
                TxTestPara.bTxCaseEnable = true;
            }
            else
            {
                TxTestPara.bTxCaseEnable = false;
            }
            if(listRxTxEnable[1] == "0")
            {
                RxTestPara.bRxCaseEnable = true;
            }
            else
            {
                RxTestPara.bRxCaseEnable = false;
            }
            FormTxRxParaConfig formTRCfg = new FormTxRxParaConfig(TxTestPara,RxTestPara);
             formTRCfg.ShowDialog();
        }          
    }
}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
System.DllNotFoundException HResult=0x80131524 Message=无法加载 DLL“yt_CPUCheck.dll”: 找不到指定的模块。 (异常来自 HRESULT:0x8007007E)。 Source=PaddleOCRSharp StackTrace: at PaddleOCRSharp.EngineBase.IsCPUSupport() at PaddleOCRSharp.PaddleOCREngine..ctor(OCRModelConfig config, OCRParameter parameter) at BasicDemoLineScan.Form1.button1_Click(Object sender, EventArgs e) in C:\Users\Administrator\Desktop\BasicDemoLineScan\BasicDemoLineScan.cs:line 1460 at System.Windows.Forms.Control.OnClick(EventArgs e) at System.Windows.Forms.Button.OnClick(EventArgs e) at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent) at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks) at System.Windows.Forms.Control.WndProc(Message& m) at System.Windows.Forms.ButtonBase.WndProc(Message& m) at System.Windows.Forms.Button.WndProc(Message& m) at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam) at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg) at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData) at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context) at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context) at BasicDemoLineScan.Program.Main() in C:\Users\Administrator\Desktop\BasicDemoLineScan\Program.cs:line 18
最新发布
07-17

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值