Beispiel #1
0
    public static int session_time(int day, int month, int year, int sec, int min, int hour, string id)
    {
        int          count_sec    = 0;
        int          count_min    = 0;
        int          count_hour   = 0;
        int          count_day    = 0;
        user_time    time_current = new user_time(day, month, year, sec, min, hour);
        database     Database     = new database();
        current_user CurrentUser  = new current_user(id);

        Database.open_connection();
        List <string> list;

        list = Database.get_from_datebase("data_start_Day, data_start_Month, data_start_Year, data_start_Hour, data_start_Min, data_start_Sec", "user_session", "where user_id='" + CurrentUser.Get_user_id() + "' and start_status='1'");
        if (list.LongCount() == 6)
        {
            int       Day              = int.Parse(list[0]);
            int       Month            = int.Parse(list[1]);
            int       Year             = int.Parse(list[2]);
            int       Hour             = int.Parse(list[3]);
            int       Min              = int.Parse(list[4]);
            int       Sec              = int.Parse(list[5]);
            user_time time_in_datebase = new user_time(Day, Month, Year, Sec, Min, Hour);
            user_time different        = new user_time();
            different  = time_in_datebase;
            count_day  = different.day_difference(time_current);
            count_hour = time_current.Get_hour() - time_in_datebase.Get_hour();
            count_min  = time_current.Get_min() - time_in_datebase.Get_min();
            count_sec  = time_current.Get_sec() - time_in_datebase.Get_sec();
            count_sec  = count_sec + (count_min + (count_hour + count_day * 24) * 60) * 60;
        }
        save_session_time(count_sec, id);
        return(count_sec);
    }
Beispiel #2
0
        // обновить что-то в базе
        public void update_datebase_user_session_finish_on_file(current_user user, user_time time)
        {
            string sql = string.Format("UPDATE user_recording" + " " +
                                       "set data_finish_Day=" + time.Get_day() + ", data_finish_Month=" + time.Get_month() +
                                       ", data_finish_Year=" + time.Get_year() + ", data_finish_Sec=" + time.Get_sec() +
                                       ", data_finish_Min=" + time.Get_min() + ", data_finish_Hour=" + time.Get_hour() + " "
                                       + "where user_id='" + user.Get_user_id() + "'" + " and data_finish_Hour=0;");

            using (SqlCommand cmd = new SqlCommand(sql, this.connect))
            {
                cmd.ExecuteNonQuery();
            }
        }
Beispiel #3
0
 // обновить запись сессии после нажатия кнопки стоп
 public void update_datebase_user_session_finish(current_user user, user_time time)
 {
     try
     {
         string sql = string.Format("UPDATE user_session" + " " +
                                    "set data_finish_Day=" + time.Get_day() + ", data_finish_Month=" + time.Get_month() +
                                    ", data_finish_Year=" + time.Get_year() + ", data_finish_Sec=" + time.Get_sec() +
                                    ", data_finish_Min=" + time.Get_min() + ", data_finish_Hour=" + time.Get_hour() + ", finish_status='true'" + ", "
                                    + "start_status='false'" + " " + "where user_id='" + user.Get_user_id() + "'" + ";");
         using (SqlCommand cmd = new SqlCommand(sql, this.connect))
         {
             cmd.ExecuteNonQuery();
         }
         update_datebase_user_session_finish_on_file(user, time);
     }
     catch (SqlException ex)
     { }
 }
Beispiel #4
0
    public static bool checkTimeDelete(string id, int day, int month, int year, int sec, int min, int hour)
    {
        bool         boolean     = false;
        database     Database    = new database();
        current_user CurrentUser = new current_user(id);

        Database.open_connection();
        user_time     time_curent = new user_time(day, month, year, sec, min, hour);
        List <string> list;

        list = Database.get_from_datebase("data_start_Day, data_start_Month, data_start_Year, data_start_Hour, data_start_Min, data_start_Sec", "user_session", "where user_id='" + CurrentUser.Get_user_id() + "'");
        if (list != null)
        {
            if (list.LongCount() != 0)
            {
                user_time time_start = new user_time(int.Parse(list[0]), int.Parse(list[1]), int.Parse(list[2]), int.Parse(list[5]),
                                                     int.Parse(list[4]), int.Parse(list[3]));

                user_time different = new user_time();
                different = time_start;
                int count_day  = different.day_difference(time_curent);
                int count_hour = time_curent.Get_hour() - time_start.Get_hour();
                int count_min  = time_curent.Get_min() - time_start.Get_min();
                int count_sec  = time_curent.Get_sec() - time_start.Get_sec();
                count_sec = count_sec + (count_min + (count_hour + count_day * 24) * 60) * 60;

                if (count_sec < 60)
                {
                    Database.delete_datebase("user_recording", "where user_id='" + id + "' and data_finish_Day='0'");
                    boolean = true;
                }
            }
        }

        Database.close_connection();
        return(boolean);
    }
Beispiel #5
0
        public string[] get_records_for_month(int month, int year)
        {
            int[] month_days = new int[] { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
            //если текущий год високосный - устанавливаем в феврале 28 дней
            if (((year % 4 != 0) && (year % 100 == 0)) ||
                ((year % 100 != 0) && (year % 400 != 0)))
            {
                month_days[1] = 28;
            }
            database _database_ = new database();

            _database_.open_connection();
            List <string> list_curent_month;

            list_curent_month = _database_.get_from_datebase("data_start_Day, data_start_Month, data_start_Year, data_start_Sec, data_start_Min, data_start_Hour, data_finish_Day, data_finish_Month, data_finish_Year, data_finish_Sec, data_finish_Min, data_finish_Hour", "user_recording", "where user_id='" + user_id + "' and data_finish_Month=" + month + " and data_finish_Year=" + year + "");
            string[] records_for_month = new string[month_days[month - 1] * 2];
            if (list_curent_month != null)
            {
                if (list_curent_month.Count >= 0)
                {
                    string[] day_of_month = new string[month_days[month - 1]];
                    for (int i = 0; i < month_days[month - 1]; i++)
                    {
                        day_of_month[i]      = i + 1 + ":" + month + ":" + year;
                        records_for_month[i] = day_of_month[i];
                    }
                    int count_work            = 0;
                    int count_all_day_work    = 0;
                    int count_recording_month = list_curent_month.Count() / 12;
                    int pos = month_days[month - 1];
                    for (int zt = pos; zt < records_for_month.Length; zt++)
                    {
                        records_for_month[zt] = count_all_day_work.ToString();
                    }
                    int count_sec  = 0;
                    int count_min  = 0;
                    int count_hour = 0;
                    int count_day  = 0;
                    for (int i = 0; i < month_days[month - 1]; i++)
                    {
                        for (int x = 0; x < count_recording_month; x++)
                        {
                            if (day_of_month[i] == list_curent_month[x] + ":" + list_curent_month[x + count_recording_month] + ":" + list_curent_month[x + count_recording_month * 2])
                            {
                                user_time time_finish = new user_time(int.Parse(list_curent_month[x + count_recording_month * 6]),
                                                                      int.Parse(list_curent_month[x + count_recording_month * 7]),
                                                                      int.Parse(list_curent_month[x + count_recording_month * 8]),
                                                                      int.Parse(list_curent_month[x + count_recording_month * 9]),
                                                                      int.Parse(list_curent_month[x + count_recording_month * 10]),
                                                                      int.Parse(list_curent_month[x + count_recording_month * 11]));
                                user_time time_start = new user_time(int.Parse(list_curent_month[x]),
                                                                     int.Parse(list_curent_month[x + count_recording_month]),
                                                                     int.Parse(list_curent_month[x + count_recording_month * 2]),
                                                                     int.Parse(list_curent_month[x + count_recording_month * 3]),
                                                                     int.Parse(list_curent_month[x + count_recording_month * 4]),
                                                                     int.Parse(list_curent_month[x + count_recording_month * 5]));
                                user_time different = new user_time();
                                different              = time_start;
                                count_day              = different.day_difference(time_finish);
                                count_hour             = time_finish.Get_hour() - time_start.Get_hour();
                                count_min              = time_finish.Get_min() - time_start.Get_min();
                                count_sec              = time_finish.Get_sec() - time_start.Get_sec();
                                count_sec              = count_sec + (count_min + (count_hour + count_day * 24) * 60) * 60;
                                count_work             = count_sec;
                                count_all_day_work     = count_work + int.Parse(records_for_month[pos]);
                                records_for_month[pos] = count_all_day_work.ToString();
                                if (day_of_month[i] != list_curent_month[x + 1] + ":" + list_curent_month[x + 1 + count_recording_month] + ":" + list_curent_month[x + 1 + count_recording_month * 2])
                                {
                                    break;
                                }
                            }
                            else
                            {
                                count_work             = 0;
                                records_for_month[pos] = count_work.ToString();
                            }
                        }
                        pos++;
                    }
                }
            }
            _database_.close_connection();
            return(records_for_month);
        }
Beispiel #6
0
        // вставить запись сессии после нажатия кнопки старт
        public void insert_datbase_session_start(current_user CurrentUser, user_time time, database Database)
        {
            bool start       = true;
            bool finish      = false;
            bool connection  = true;
            int  finish_time = 0;

            try
            {
                List <string> list;
                list = Database.get_from_datebase("data_start_Day, data_start_Month, data_start_Year, data_start_Hour, data_start_Min, data_start_Sec", "user_session", "where user_id='" + CurrentUser.Get_user_id() + "' and start_status='1'");
                if (list == null || list.LongCount() == 0)
                {
                    string sql = string.Format("Insert Into user_session " + "(user_id, start_status, finish_status, connection_status, data_start_Day, data_start_Month, data_start_Year, data_start_Hour, data_start_Min, data_start_Sec, data_finish_Day, data_finish_Month, data_finish_Year, data_finish_Sec, data_finish_Min, data_finish_Hour)Values('{0}', '{1}','{2}','{3}','{4}','{5}','{6}','{7}', '{8}','{9}','{10}','{11}','{12}','{13}', '{14}', '{15}')",
                                               CurrentUser.Get_user_id(), start, finish, connection, time.Get_day(), time.Get_month(), time.Get_year(), time.Get_hour(), time.Get_min(), time.Get_sec(), finish_time, finish_time, finish_time, finish_time, finish_time, finish_time);
                    using (SqlCommand cmd = new SqlCommand(sql, this.connect))
                    {
                        cmd.ExecuteNonQuery();
                    }
                    insert_datebase_session_on_file(CurrentUser, time, Database);
                }
            }
            catch (SqlException ex)
            { }
        }
Beispiel #7
0
        // вставить записи в табличку записей
        public void insert_datebase_session_on_file(current_user CurrentUser, user_time time, database Database)
        {
            int    finish_time         = 0;
            int    count_hours_all     = 0;
            int    count_hours_for_day = 0;
            string type_created        = "button";

            try
            {
                string sql = string.Format("Insert Into user_recording " + "(user_id, data_start_Day, data_start_Month, data_start_Year, data_start_Hour, data_start_Min, data_start_Sec, data_finish_Day, data_finish_Month, data_finish_Year, data_finish_Sec, data_finish_Min, data_finish_Hour, type_created, count_hours_all, count_hours_for_day)Values('{0}', '{1}','{2}','{3}','{4}','{5}','{6}','{7}', '{8}','{9}','{10}','{11}','{12}', '{13}', '{14}', '{15}')",
                                           CurrentUser.Get_user_id(), time.Get_day(), time.Get_month(), time.Get_year(), time.Get_hour(), time.Get_min(), time.Get_sec(), finish_time, finish_time, finish_time, finish_time, finish_time, finish_time, type_created, count_hours_all, count_hours_for_day);
                using (SqlCommand cmd = new SqlCommand(sql, this.connect))
                {
                    cmd.ExecuteNonQuery();
                }
            }
            catch (SqlException ex)
            { }
        }