Esempio n. 1
0
        private void dcmDataDGV_SelectionChanged(object sender, EventArgs e)
        {
            if (dcmDataDGV.SelectedRows.Count == 0)
            {
                prevReqRespIndex = -1;
                parsingDataDGV.Rows.Clear();
                return;
            }

            var row      = dcmDataDGV.SelectedRows[0];
            var cell     = row.Cells[ColumnDataIndex];
            int rowIndex = row.Index;

            ResponseDataTag tag = cell.Tag as ResponseDataTag;

            if (tag == null)
            {
                if (row.Index + 1 < dcmDataDGV.Rows.Count)
                {
                    tag      = dcmDataDGV[ColumnDataIndex, row.Index + 1].Tag as ResponseDataTag;
                    rowIndex = row.Index + 1;
                }
            }

            if (tag != null)
            {
                if (prevReqRespIndex != rowIndex)
                {
                    parsingDataDGV.Rows.Clear();
                    Utils.DataGridViewAddRows(parsingDataDGV, tag.ParsedList);
                    prevReqRespIndex = rowIndex;
                }
            }
        }
Esempio n. 2
0
        internal void OnParsingDataIncomming(ParsingDataIncommingEventArgs e)
        {
            if (dcmDataDGV.InvokeRequired)
            {
                AddItemsCallback callback = new AddItemsCallback(OnParsingDataIncomming);
                dcmDataDGV.Invoke(callback, e);
            }
            else
            {
                dcmDataDGV.SuspendLayout();

                // 添加请求ID
                if (e.RequestData != null)
                {
                    dcmDataDGV.Rows.Add(new string[] { string.Format("Tx{0:X3}", e.RequestCanId),
                                                       Utils.HexArrayToString(e.RequestData) });
                }

                // 添加响应ID
                if (e.ResponseData != null)
                {
                    dcmDataDGV.Rows.Add(new string[] { string.Format("Rx{0:X3}", e.ResponseCanId),
                                                       Utils.HexArrayToString(e.ResponseData) });
                }
                else
                {
                    dcmDataDGV.Rows.Add(new string[] { "<Empty>", "<Empty>" });
                }

                // 设置响应数据前景色
                var cell = dcmDataDGV[ColumnDataIndex, dcmDataDGV.Rows.Count - 1];
                cell.Selected = true;

                // 添加、解析数据
                List <KeyValuePair <string, string> > itemsToAdd
                    = new List <KeyValuePair <string, string> >();
                itemsToAdd.AddRange(e.EntryList);
                ParseReceiveData(e, itemsToAdd);

                ResponseDataTag tag = new ResponseDataTag
                {
                    ParsedList      = itemsToAdd,
                    PostiveResponse = e.PostiveResponse
                };
                cell.Tag = tag;

                dcmDataDGV.ResumeLayout();

                // 手动通知选择变化
                dcmDataDGV_SelectionChanged(dcmDataDGV, EventArgs.Empty);
            }
        }
Esempio n. 3
0
        private void Save(string fileName)
        {
            FileStream   fs = null;
            StreamWriter sw = null;

            try
            {
                fs = new FileStream(fileName, FileMode.Create, FileAccess.Write);
                sw = new StreamWriter(fs, new UTF8Encoding(true)); //这儿加上BOM头目的是,excel只能识别带有bom头的UTF8内容,不该BOM头的识别不了

                int i = 0;

                //保存头
                sw.WriteLine(DcmLogHeader);

                foreach (DataGridViewRow row in dcmDataDGV.Rows)
                {
                    // 保存报文
                    Utils.DataGridViewSaveRow(sw, dcmDataDGV, row, ",", true);

                    if (++i == 2)
                    {
                        i = 0;

                        // 保存解析结果
                        ResponseDataTag tag = row.Cells[ColumnDataIndex].Tag as ResponseDataTag;
                        SaveResponseDataTag(sw, tag);
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(
                    string.Format("Save raw can data to file {0} failed: {1}", fileName, ex.Message),
                    "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                if (sw != null)
                {
                    sw.Close();
                }
                if (fs != null)
                {
                    fs.Close();
                }
            }
        }
Esempio n. 4
0
        private void SaveResponseDataTag(StreamWriter sw, ResponseDataTag tag)
        {
            foreach (var entry in tag.ParsedList)
            {
                sw.Write(EmptyCsvContent);
                sw.Write(CsvSeperator);
                sw.Write(entry.Key);
                sw.Write(CsvSeperator);
                sw.Write(entry.Value);
                sw.WriteLine();
            }

            sw.Write(EmptyCsvContent);
            sw.Write(CsvSeperator);
            sw.Write(EmptyCsvContent);
            sw.Write(CsvSeperator);
            sw.Write(tag.PostiveResponse);
            sw.WriteLine();
        }
Esempio n. 5
0
        private void Open(string fileName)
        {
            FileStream   fs = null;
            StreamReader sw = null;

            try
            {
                fs = new FileStream(fileName, FileMode.Open, FileAccess.Read);
                sw = new StreamReader(fs);

                string line = sw.ReadLine();
                if (!line.Equals(DcmLogHeader))
                {
                    throw new Exception("File content is valid dcm log");
                }

                dcmDataDGV.Rows.Clear();

                ResponseDataTag  tag  = null;
                DataGridViewCell cell = null;

                while ((line = sw.ReadLine()) != null)
                {
                    var fields = line.Split(CsvSeperator.ToCharArray());
                    if (fields.Length == 2) //报文数据
                    {
                        if (cell != null)
                        {
                            cell.Tag = tag;
                            tag      = null;
                        }

                        dcmDataDGV.Rows.Add(new string[] { fields[0], fields[1] });
                        cell = dcmDataDGV[dcmDataDGV.ColumnCount - 1, dcmDataDGV.Rows.Count - 1];
                    }
                    else if (fields.Length == 3)
                    {
                        if (tag == null)
                        {
                            tag            = new ResponseDataTag();
                            tag.ParsedList = new List <KeyValuePair <string, string> >();
                        }

                        if (fields[0].Equals(EmptyCsvContent) &&
                            fields[1].Equals(EmptyCsvContent))
                        {
                            bool result;
                            if (bool.TryParse(fields[2], out result))
                            {
                                tag.PostiveResponse = result;
                            }
                        }
                        else
                        {
                            tag.ParsedList.Add(
                                new KeyValuePair <string, string>(fields[1], fields[2]));
                        }
                    }

                    if (tag != null)
                    {
                        cell.Tag = tag;
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(
                    string.Format("Load dcm log file {0} failed: {1}", fileName, ex.Message),
                    "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                if (sw != null)
                {
                    sw.Close();
                }
                if (fs != null)
                {
                    fs.Close();
                }
            }
        }