コード例 #1
0
        public unsafe void QueSel(string _fn, DataGridView _dgCars)
        {
            int i, k;

            byte[]   wMark;
            Encoding enc8  = Encoding.UTF8;
            TbCars * bCars = stackalloc TbCars[1];

            byte[]     bbCars = new byte[sizeof(TbCars)];
            FileStream fCars  = File.OpenRead(_fn);

            _dgCars.RowCount = 3;
            i = 0;
            while (fCars.Read(bbCars, 0, bbCars.Length) == bbCars.Length)
            {
                Marshal.Copy(bbCars, 0, (IntPtr)bCars, bbCars.Length);
                wMark = new byte[30];
                for (k = 0; k < 30; k++)
                {
                    wMark[k] = bCars->Mark[k];
                }
                _dgCars.Rows[i].Cells[0].Value = enc8.GetString(wMark, 0, wMark.Length);
                _dgCars.Rows[i].Cells[1].Value = bCars->V.ToString();
                _dgCars.Rows[i].Cells[2].Value = bCars->S.ToString();
                i = i + 1;
            }
            fCars.Close();
        }
コード例 #2
0
        public unsafe void Convert(string _fn, DataGridView _dgErr)
        {
            int     i, j, Res;
            string  tmp;
            TbCars *bCars = stackalloc TbCars[1];

            byte[] bbCars = new byte[sizeof(TbCars)];

            string bCarsTXT;

            string[] rCar;
            System.IO.StreamReader fCatsTXT = new System.IO.StreamReader(_fn);
            tmp = "";
            for (i = 0; i <= _fn.IndexOf("."); i++)
            {
                tmp = tmp + _fn[i];
            }
            tmp = tmp + "dat";
            Console.WriteLine(tmp, _fn);
            FileStream fCars = File.OpenWrite(tmp);

            j = 0;
            while ((bCarsTXT = fCatsTXT.ReadLine()) != null)
            {
                rCar = bCarsTXT.Split(new Char[] { '/' });
                Console.Write("{0}", string.Join(" ", rCar));
                Console.WriteLine();
                if (rCar.Length == 3)
                {
                    for (i = 0; i < 30; i++)
                    {
                        bCars->Mark[i] = 32;
                    }
                    for (i = 0; i < rCar[0].Length; i++)
                    {
                        bCars->Mark[i] = System.Convert.ToByte(rCar[0][i]);
                    }
                    if (Double.TryParse(rCar[1], out bCars->V))
                    {
                        if (Int32.TryParse(rCar[2], out bCars->S))
                        {
                            Res = 0;
                        }
                        else
                        {
                            Res = 2;     // ошибка 2 типа.
                        }
                    }
                    else
                    {
                        Res = 1; // ошибка 1 типа.
                    }
                }                //then
                else
                {
                    Res = 3;     // ошибка 3 типа.
                }
                if (Res != 0)
                {
                    _dgErr.Visible  = true;
                    _dgErr.RowCount = _dgErr.RowCount + 1;
                    _dgErr.Rows[j].Cells[0].Value = Res.ToString() + " - " + bCarsTXT;
                    j = j + 1;
                }
                else
                {
                    Marshal.Copy((IntPtr)bCars, bbCars, 0, bbCars.Length);
                    fCars.Write(bbCars, 0, bbCars.Length);
                }
                Console.Write("{0}", string.Join(" ", bbCars));
            }
            fCars.Close();
        }