Example #1
0
        public void QueueInsert()
        {
            DataTable dt = GetTableSchema();

            bulkCopy.BatchSize = dt.Rows.Count;
            bulkCopy.ColumnMappings.Add(0, 3);
            bulkCopy.ColumnMappings.Add(1, 5);
            bulkCopy.ColumnMappings.Add(2, 6);
            bulkCopy.ColumnMappings.Add(3, 16);
            bulkCopy.ColumnMappings.Add(4, 17);

            bulkCopy.ColumnMappings.Add(5, 1);
            while (true)
            {
                try
                {
                    WriteLog("成功:" + System.DateTime.Now.ToString("F"));
                    for (int i = 0; i < gpsList.Count; i++)
                    {
                        GPSData data = gpsList[i];
                        DataRow dr   = dt.NewRow();
                        //dr[0] = i;
                        dr[0] = data.PDAID;
                        dr[1] = data.QQSJ.ToString();
                        dr[2] = "1900-01-01 00:00:00.000";
                        //  dr[1] = DateTime.Parse(data.QQSJ.ToString());
                        //  dr[2] =  DateTime.Parse("1900-01-01 00:00:00.000");
                        dr[3] = data.LA;
                        dr[4] = data.LO;
                        dr[5] = 2;
                        dt.Rows.Add(dr);
                    }
                    duiJiangJiRecive += gpsList.Count;
                    gpsList.Clear();
                    if (dt != null && dt.Rows.Count != 0)
                    {
                        bulkCopy.WriteToServer(dt);
                        dt.Clear();
                    }

                    System.Threading.Thread.Sleep(1000 * 10);
                }
                catch (Exception ex)
                {
                    WriteLog("QueueInsert error:" + ex.Message);
                }
            }


            return;

            int xh = 1;

            while (xh == 1)
            {
                try
                {
                    for (int i = 0; i < gpsList.Count; i++)
                    {
                        GPSData data = gpsList[i];
                        //mut.WaitOne();
                        string intsetsql = "Insert into HistoryGps_Temp([PDAID],[QQSJ],[YDSJ],[Lo],[La],[DevType]) values(" +
                                           " '" + data.PDAID + "', '" + data.QQSJ.ToString() + "', '1900-01-01 00:00:00.000', '" + data.LO + "','" + data.LA + "','2')";
                        //WriteLog(intsetsql);
                        ExecuteNonQuery(intsetsql);

                        //mut.ReleaseMutex();
                        duiJiangJiRecive++;
                        gpsList.Remove(data);
                        //WriteLog(gpsList.Count.ToString());
                        System.Threading.Thread.Sleep(50);
                    }
                }
                catch (Exception ex)
                {
                    WriteLog("QueueInsert error:" + ex.Message);
                }
            }
        }
Example #2
0
        public void DuiJiangJiDataHandler()
        {
            int xh = 1;

            if (ReceiveClient != null)
            {
                ReceiveClient.Close();
            }

            IPEndPoint remote = new IPEndPoint(IPAddress.Any, 0);

            ReceiveClient     = new UdpClient(6800);
            duiJiangJiRecive  = 0;
            duiJiangJiRecive1 = 0;
            while (xh == 1)
            {
                try
                {
                    //WriteLog("写入对讲机");
                    //Console.WriteLine("写入对讲机.");

                    /**
                     *                GPSData gps = new GPSData();
                     *                gps.PDAID = "331022000020670";
                     *                gps.QQSJ = DateTime.Parse("2017-07-05 00:00:01.000");
                     *                gps.YDSJ = DateTime.Parse("1900-01-01 00:00:00.000");
                     *                gps.LA = 121.36273;
                     *                gps.LO = 28.09808;
                     *                gpsList.Add(gps);
                     *
                     *                //WriteLog("issi:" + gps.PDAID + ";qqsj:" + gps.QQSJ.ToString() + ";YDSJ:" + gps.YDSJ.ToString() + ";LAT:" + gps.LA.ToString() + ";Lon:" + gps.LO.ToString());
                     *
                     *                //string selSql = string.Format("select * from [JingWuTong].[dbo].[HistoryGps] where PDAID='{0}' and QQSJ='{1}'", issi, dd);
                     *                //System.Data.DataTable dt = SQLHelper.ExecuteRead(CommandType.Text, selSql, "aa");
                     *                //if (dt.Rows.Count == 0)
                     *                //{
                     *                //    mut.WaitOne();
                     *                //    string intsetsql = "Insert into HistoryGps([PDAID],[QQSJ],[YDSJ],[Lo],[La],[DevType]) values(" +
                     *                //              " '" + issi + "', '" + dd.ToString() + "', '1900-01-01 00:00:00.000', '" + lat + "','" + lon + "','2')";
                     *
                     *                //    SQLHelper.ExecuteNonQuery(intsetsql);
                     *                //    duiJiangJiRecive++;
                     *                //    mut.ReleaseMutex();
                     *
                     *                //}
                     *                duiJiangJiRecive1++;
                     *                System.Threading.Thread.Sleep(10);
                     **/


                    byte[] bytes = null;
                    // GPSData data;

                    bytes = ReceiveClient.Receive(ref remote);

                    //WriteLog("bytes vales:" + ByteToString(bytes));

                    //string strBytes = "AA AA CC CC 03 00 35 00 00 00 35 37 36 31 31 32 30 31 00 00 00 00 00 00 00 00 00 00 00 00 18 44 A4 A6 5D 5C 5E 40 E1 25 38 F5 81 A8 3C 40 00 00 20 00 00 00 01 00 E1 07 08 04 0B 04 15 00 00";

                    //string strBytes = "aa aa cc cc 03 00 35 00 00 00 35 37 36 31 33 31 31 39 00 00 00 00 00 00 00 00 00 00 00 00 b6 80 d0 7a f8 56 5e 40 02 81 ce a4 4d 95 3c 40 00 00 43 00 00 00 01 00 e1 07 08 08 0e 1e 09 00 00";

                    //strBytes = strBytes.Replace(" ", "");
                    //bytes = DuiJiangJi.HexStrTobyte(strBytes);

                    string issi = System.Text.Encoding.ASCII.GetString(bytes, 10, 20);
                    issi = issi.Replace("\0", "");
                    //经度
                    double lon    = 0.00000;
                    Int32  size   = Marshal.SizeOf(typeof(double));
                    IntPtr buffer = Marshal.AllocHGlobal(size);
                    try
                    {
                        Marshal.Copy(DuiJiangJi.getBbytes(bytes, 30, 8), 0, buffer, size);
                        lon = (double)Marshal.PtrToStructure(buffer, typeof(double));
                    }
                    catch (Exception ex)
                    {
                        WriteLog(ex.Message);
                    }
                    finally
                    {
                        Marshal.FreeHGlobal(buffer);
                        //GC.Collect();
                    }

                    //纬度
                    double lat = 0.00000;
                    size   = Marshal.SizeOf(typeof(double));
                    buffer = Marshal.AllocHGlobal(size);
                    try
                    {
                        Marshal.Copy(DuiJiangJi.getBbytes(bytes, 38, 8), 0, buffer, size);
                        lat = (double)Marshal.PtrToStructure(buffer, typeof(double));
                    }
                    catch (Exception ex)
                    {
                        WriteLog(ex.Message);
                    }
                    finally
                    {
                        Marshal.FreeHGlobal(buffer);
                        //GC.Collect();
                    }

                    //年
                    ushort year = 1900;
                    size   = Marshal.SizeOf(typeof(ushort));
                    buffer = Marshal.AllocHGlobal(size);
                    try
                    {
                        Marshal.Copy(DuiJiangJi.getBbytes(bytes, 54, 2), 0, buffer, size);
                        year = (ushort)Marshal.PtrToStructure(buffer, typeof(ushort));
                    }
                    catch (Exception ex)
                    {
                        WriteLog(ex.Message);
                    }
                    finally
                    {
                        Marshal.FreeHGlobal(buffer);
                        //GC.Collect();
                    }

                    string time = year + "-" + DuiJiangJi.getBbytes(bytes, 56, 1)[0].ToString() + "-" + DuiJiangJi.getBbytes(bytes, 57, 1)[0].ToString() +
                                  " " + DuiJiangJi.getBbytes(bytes, 58, 1)[0].ToString() + ":" + DuiJiangJi.getBbytes(bytes, 59, 1)[0].ToString() + ":" + DuiJiangJi.getBbytes(bytes, 60, 1)[0].ToString();

                    DateTime dd = DateTime.Parse(time);
                    duiJiangJiRecive1++;

                    GPSData gps = new GPSData();
                    gps.PDAID = issi;
                    gps.QQSJ  = dd;
                    gps.YDSJ  = DateTime.Parse("1900-01-01 00:00:00.000");
                    gps.LA    = lat;
                    gps.LO    = lon;
                    gpsList.Add(gps);

                    //WriteLog("issi:" + gps.PDAID + ";qqsj:" + gps.QQSJ.ToString() + ";YDSJ:" + gps.YDSJ.ToString() + ";LAT:" + gps.LA.ToString() + ";Lon:" + gps.LO.ToString());

                    //string selSql = string.Format("select * from [JingWuTong].[dbo].[HistoryGps] where PDAID='{0}' and QQSJ='{1}'", issi, dd);
                    //System.Data.DataTable dt = SQLHelper.ExecuteRead(CommandType.Text, selSql, "aa");
                    //if (dt.Rows.Count == 0)
                    //{
                    //    mut.WaitOne();
                    //    string intsetsql = "Insert into HistoryGps([PDAID],[QQSJ],[YDSJ],[Lo],[La],[DevType]) values(" +
                    //              " '" + issi + "', '" + dd.ToString() + "', '1900-01-01 00:00:00.000', '" + lat + "','" + lon + "','2')";

                    //    SQLHelper.ExecuteNonQuery(intsetsql);
                    //    duiJiangJiRecive++;
                    //    mut.ReleaseMutex();

                    //}

                    System.Threading.Thread.Sleep(60);
                }
                catch (Exception ex)
                {
                    WriteLog(ex.Message);
                }
            }
        }