コード例 #1
0
        public void violationcount()
        {
            try
            {
                SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder();
                builder.ConnectionString = ConfigurationManager.AppSettings["connsr"];


                using (SqlConnection connection = new SqlConnection(builder.ConnectionString))
                {
                    //select top 20 label, AvgConfidence, count, inserttime from visionkitcount order by inserttime desc;
                    connection.Open();
                    StringBuilder sb = new StringBuilder();
                    sb.Append("select top 20 ");
                    sb.Append("label,");
                    sb.Append("AvgConfidence, count, inserttime ");
                    sb.Append(" from visionkitcount");
                    sb.Append(" order by inserttime desc;");
                    String sql = sb.ToString();

                    alert al = new alert();

                    using (SqlCommand command = new SqlCommand(sql, connection))
                    {
                        using (SqlDataReader reader = command.ExecuteReader())
                        {
                            GridView1.DataSource = reader;
                            GridView1.DataBind();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                errortxt.Text  = "Error: " + ex.Message.ToString() + System.Environment.NewLine;
                errortxt.Text += "Error: " + ex.StackTrace.ToString() + System.Environment.NewLine;
                //throw ex;
            }
        }
コード例 #2
0
        public void violationcount()
        {
            try
            {
                SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder();
                builder.ConnectionString = ConfigurationManager.AppSettings["connsr"];


                using (SqlConnection connection = new SqlConnection(builder.ConnectionString))
                {
                    connection.Open();
                    StringBuilder sb = new StringBuilder();
                    sb.Append("select ");
                    sb.Append("label,");
                    sb.Append("count(*) as Count");
                    sb.Append(" from visionkitinputs");
                    sb.Append(" where EnqueuedTime between DATEADD(minute, -2, GETUTCDATE()) and GETUTCDATE()");
                    sb.Append(" group by label;");
                    String sql = sb.ToString();

                    alert al = new alert();

                    using (SqlCommand command = new SqlCommand(sql, connection))
                    {
                        using (SqlDataReader reader = command.ExecuteReader())
                        {
                            while (reader.Read())
                            {
                                if (reader.GetString(0).ToString().ToLower().Contains("person"))
                                {
                                    al.person = true;
                                }
                                if (reader.GetString(0).ToString().ToLower().Contains("vest"))
                                {
                                    al.vest = true;
                                }
                                if (reader.GetString(0).ToString().ToLower().Contains("hardhat"))
                                {
                                    al.hardhat = true;
                                }
                                if (reader.GetString(0).ToString().ToLower().Contains("safety"))
                                {
                                    al.safetyglass = true;
                                }
                            }

                            if (al.person && (!al.vest || !al.hardhat || !al.safetyglass))
                            {
                                alertcount++;
                                alertcountlbl.Text = alertcount.ToString();
                            }
                            if (al.person && (al.vest && al.hardhat && al.safetyglass))
                            {
                                safetycount++;
                                safetycountlbl.Text = safetycount.ToString();
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                errortxt.Text  = "Error: " + ex.Message.ToString() + System.Environment.NewLine;
                errortxt.Text += "Error: " + ex.StackTrace.ToString() + System.Environment.NewLine;
                //throw ex;
            }
        }