Esempio n. 1
0
 public static void CheckAlarmMaxHourInDB(int CardID, int InMineHour, int AllowInMineHour, DateTime Time)
 {
     try
     {
         using (SqlConnection conn = new SqlConnection(Global.DBConnStr))
         {
             conn.Open();
             using (SqlCommand comm = new SqlCommand("select Alarm_ID,Time from AlarmMaxHourTable where CardID = " + CardID + " order by Alarm_ID DESC", conn))
             {
                 using (SqlDataReader reader = comm.ExecuteReader())
                 {
                     if (reader.Read())
                     {
                         try
                         {
                             if (reader.IsDBNull(1))
                             {
                                 DB_Service.ExecuteSQL("insert into AlarmMaxHourTable (CardID,InMineHour,AllowInMineHour,Time) values (" + CardID + "," + InMineHour + "," + AllowInMineHour + ",'" + Time + "')");
                             }
                             else
                             {
                                 DateTime lastTime = reader.GetDateTime(1);
                                 TimeSpan ts       = Time - lastTime;
                                 if (ts.TotalMinutes > 30.0)
                                 {
                                     DB_Service.ExecuteSQL("insert into AlarmMaxHourTable (CardID,InMineHour,AllowInMineHour,Time) values (" + CardID + "," + InMineHour + "," + AllowInMineHour + ",'" + Time + "')");
                                 }
                             }
                         }
                         catch (Exception ex)
                         {
                             throw ex;
                         }
                         finally
                         {
                             reader.Close();
                         }
                     }
                     else
                     {
                         DB_Service.ExecuteSQL("insert into AlarmMaxHourTable (CardID,InMineHour,AllowInMineHour,Time) values (" + CardID + "," + InMineHour + "," + AllowInMineHour + ",'" + Time + "')");
                     }
                 }
             }
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Esempio n. 2
0
 public static void CheckAlarmMaxPersonInDB(int InMinePersonNum, int AllowMaxPersonNum, DateTime Time)
 {
     try
     {
         using (SqlConnection conn = new SqlConnection(Global.DBConnStr))
         {
             conn.Open();
             using (SqlCommand comm = new SqlCommand("select top 1 Time from AlarmMaxPersonTable order by Alarm_ID DESC", conn))
             {
                 using (SqlDataReader reader = comm.ExecuteReader())
                 {
                     if (reader.Read())
                     {
                         try
                         {
                             if (reader.IsDBNull(0))
                             {
                                 DB_Service.ExecuteSQL("insert into AlarmMaxPersonTable (RealPersonNum,AllowPersonNum,Time) values (" + InMinePersonNum + "," + AllowMaxPersonNum + ",'" + Time + "')");
                             }
                             else
                             {
                                 DateTime lastTime = reader.GetDateTime(0);
                                 TimeSpan ts       = Time - lastTime;
                                 if (ts.TotalMinutes > 5.0)
                                 {
                                     DB_Service.ExecuteSQL("insert into AlarmMaxPersonTable (RealPersonNum,AllowPersonNum,Time) values (" + InMinePersonNum + "," + AllowMaxPersonNum + ",'" + Time + "')");
                                 }
                             }
                         }
                         catch (Exception ex)
                         {
                             throw ex;
                         }
                         finally
                         {
                             reader.Close();
                         }
                     }
                     else
                     {
                         DB_Service.ExecuteSQL("insert into AlarmMaxPersonTable (RealPersonNum,AllowPersonNum,Time) values (" + InMinePersonNum + "," + AllowMaxPersonNum + ",'" + Time + "')");
                     }
                 }
             }
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }