예제 #1
0
        public static FormControl creatForm(TCPUDPServer gui)
        {
            if (instance == null || instance.IsDisposed)
            {
                instance = new FormControl(gui);
            }


            return(instance);
        }
예제 #2
0
        public FormControl(TCPUDPServer gui)
        {
            InitializeComponent();
            m_gui = gui;
            InitWindow();

            m_radar         = new CRadarData();
            timer1.Interval = 1000;
            timer1.Start();
        }
예제 #3
0
        private void SaveData(MySql.Data.MySqlClient.MySqlConnection connection, List <string> dynamicSqlCommandCollection, TCPUDPServer controlObject, DateTime Sample, int FrameIndex, int ParamIndex, byte AtnDataType, byte[] Atn1Data, byte[] Atn2Data, byte[] Atn3Data, byte[] Atn4Data, byte[] Atn5Data, byte[] Atn6Data, byte[] Atn7Data, byte[] Atn8Data)
        {
            // 开始事务处理
            MySql.Data.MySqlClient.MySqlTransaction transaction = connection.BeginTransaction();
            MySql.Data.MySqlClient.MySqlCommand     command     = connection.CreateCommand();
            try
            {
                command.Parameters.AddWithValue("@Sample", Sample);
                command.Parameters.AddWithValue("@FrameIndex", FrameIndex);
                command.Parameters.AddWithValue("@ParamIndex", ParamIndex);
                command.Parameters.AddWithValue("@AtnDataType", AtnDataType);
                command.Parameters.AddWithValue("@Atn1Data", Atn1Data);
                command.Parameters.AddWithValue("@Atn2Data", Atn2Data);
                command.Parameters.AddWithValue("@Atn3Data", Atn3Data);
                command.Parameters.AddWithValue("@Atn4Data", Atn4Data);
                command.Parameters.AddWithValue("@Atn5Data", Atn5Data);
                command.Parameters.AddWithValue("@Atn6Data", Atn6Data);
                command.Parameters.AddWithValue("@Atn7Data", Atn7Data);
                command.Parameters.AddWithValue("@Atn8Data", Atn8Data);
                // 批量更新
                foreach (string cmd in dynamicSqlCommandCollection)
                {
                    command.CommandText = cmd;



                    command.ExecuteNonQuery();
                }

                // 提交数据入库
                transaction.Commit();
                //if (controlObject != null)
                //{
                //    // 提交错误日志
                //    // controlObject.AddStatusString("动态数据入库操作成功。动态目标数量[" + dynamicSqlCommandCollection.Count.ToString() + "]");
                //    if (dynamicSqlCommandCollection.Count != 0)
                //    {
                //        this.Invoke(new updateControlDelegate(updateControl), "动态数据入库操作成功。动态目标数量[" + dynamicSqlCommandCollection.Count.ToString() + "]");
                //    }
                //    //  this.Invoke(new updateControlDelegate(updateControl), "动态数据入库操作成功。动态目标数量[" + dynamicSqlCommandCollection.Count.ToString() + "]");
                //}
            }
            catch (Exception ex)
            {
                // 放弃当前的数据入库操作
                transaction.Rollback();
                //if (controlObject != null)
                //{
                //   // this.Invoke(new updateControlDelegate(updateControl), "动态数据入库操作失败。\r\n错误信息为:" + ex.ToString());
                //    // 提交错误日志
                //    //controlObject.AddStatusString("动态数据入库操作失败。\r\n错误信息为:" + ex.ToString());
                //}
                Console.WriteLine(ex);
            }
        }
예제 #4
0
        void FastTest()
        {
            List <string> m_sql = new List <string>();
            DateTime      now   = DateTime.Now;

            byte[]    data     = new byte[1024000];
            byte[]    dataNull = new byte[0];
            string    strData  = "";
            Stopwatch sw       = new Stopwatch();

            for (int i = 0; i < data.Length; i++)
            {
                data[i] = 2;
                //strData = strData + data[i].ToString();
            }
            DateTime Sample      = now;
            int      FrameIndex  = 0;
            int      ParamIndex  = 0;
            byte     AtnDataType = 1;


            int id = 0;

            for (int i = 0; i < 1; i++)
            {
                String historyCommandString = "insert into hfradar.radarsample";
                ////  String historyCommandString = "insert into vesseldatabase.carrecordstable";
                historyCommandString += " (Sample,FrameIndex,ParamIndex,AtnDataType,Atn1Data,Atn2Data,Atn3Data,Atn4Data,Atn5Data,Atn6Data,Atn7Data,Atn8Data)";
                historyCommandString += "values (@Sample,@FrameIndex,@ParamIndex,@AtnDataType,@Atn1Data,@Atn2Data,@Atn3Data,@Atn4Data,@Atn5Data,@Atn6Data,@Atn7Data,@Atn8Data)";
                //historyCommandString += i + ",'";
                //historyCommandString += now.ToString() + "','";
                //historyCommandString += strData + "');";
                m_sql.Add(historyCommandString);
            }



            try
            {
                // 获取对象

                TCPUDPServer controlObject = (TCPUDPServer)this;
                // 尝试打开数据库连接
                MySql.Data.MySqlClient.MySqlConnection connection = new MySql.Data.MySqlClient.MySqlConnection(TCPUDPServer.DatabaseConnectionString);
                connection.Open();
                if (connection.State == ConnectionState.Open)
                {
                    try
                    {
                        //// 复制数据缓冲区的数据
                        //List<string> dynamicSqlCommandCollection = null;

                        //CopyBufferCommands(ref dynamicSqlCommandCollection);


                        // 判断是否有数据需要操作
                        if ((m_sql != null))
                        {
                            // 保存所有的数据项
                            sw.Start();
                            int j = 0;
                            SaveData(connection, m_sql, controlObject, now, FrameIndex, ParamIndex, AtnDataType, data, dataNull, dataNull, dataNull, dataNull, dataNull, dataNull, dataNull);
                            sw.Stop();
                            //获取运行时间间隔
                            //  TimeSpan ts = sw.Elapsed;
                            //获取运行时间[毫秒]
                            long times = sw.ElapsedMilliseconds;
                            //获取运行的总时间
                            long times2 = sw.ElapsedTicks;
                        }
                        else
                        {
                            // 空数据...
                            //controlObject.AddStatusString("数据集合为空, 入库操作无效。");
                        }
                    }
                    catch (Exception ex)
                    {
                        System.Diagnostics.Debug.WriteLine(ex.ToString());
                    }
                    finally
                    {
                        // 关闭数据库连接
                        connection.Close();
                    }
                }
                // 释放资源
                connection.Dispose();
            }
            catch (System.Exception ex)
            {
            }
        }