Ejemplo n.º 1
0
        // задаем статус. возвращает последнюю активность
        private void SetClientStatus(int user_id, int status)
        {
            //
            bool usrHaveActivity;
            string[] latestActivity = {};

            Npg resCon;
            Npg connect = new Npg();
            resCon = connect.Connect();

            resCon.nNpgCmd = new Npgsql.NpgsqlCommand("SELECT pk, latest_activity_date, latest_activity_time FROM user_activity WHERE user_id = " + user_id, resCon.nNpgConn);

            NpgsqlDataReader dr = resCon.nNpgCmd.ExecuteReader();
            int i;

            try
            {
                while (dr.Read())
                {
                    for (i = 0; i < 1; i++)
                    {
                        latestActivity[i] = dr[i] + "";
                    }
                }

                usrHaveActivity = true;
            }
            catch
            { usrHaveActivity = false; }

            string insertStatus = "";

            if (usrHaveActivity == false)
            {
                string insertActivity = "INSERT INTO user_status (user_id, status_id, modify_) VALUES (" +
                    user_id +
                    ", " + status +
                    ", '" + DateTime.Now + "'" +
                    ")";
            }
            else
            {
                string insertActivity = "UPDATE user_status SET " +
                    " user_id = " + user_id +
                    ", status_id = " + status +
                    ", modify_ = " + DateTime.Now +
                    " WHERE user_id = " + user_id;
            }

            //richTextBox1.Text += insertStr;

            resCon.nNpgCmd = new Npgsql.NpgsqlCommand(insertStatus, resCon.nNpgConn);

            resCon.nNpgConn.Close();
        }
Ejemplo n.º 2
0
        private void SetLatestActivity(int user_id)
        {
            //
            string[] latestActivity = { };

            Npg resCon;
            Npg connect = new Npg();
            resCon = connect.Connect();

            string insertActivity = "UPDATE user_activity SET " +
                " user_id = " + user_id +
                ", latest_activity_date = " + DateTime.Now +
                ", latest_activity_time = " + DateTime.Now +
                " WHERE user_id = " + user_id;

            //richTextBox1.Text += insertStr;

            resCon.nNpgCmd = new Npgsql.NpgsqlCommand(insertActivity, resCon.nNpgConn);

            resCon.nNpgConn.Close();
        }
Ejemplo n.º 3
0
        // текущий статус клиента
        private int CurrentStatus(int user_id)
        {
            //
            int i, status = 500;

            Npg resCon;
            Npg connect = new Npg();
            resCon = connect.Connect();

            resCon.nNpgCmd = new Npgsql.NpgsqlCommand("SELECT status_id FROM user_status WHERE user_id = " + user_id, resCon.nNpgConn);

            try
            {
                NpgsqlDataReader dr = resCon.nNpgCmd.ExecuteReader();
                while (dr.Read())
                {
                    for (i = 0; i < 1; i++)
                    {
                        status = (int)dr[i];
                    }
                }
            }

            finally
            {
                resCon.nNpgConn.Close();
            }

            return status;
        }
Ejemplo n.º 4
0
        private string[] GetLatestActivity(int user_id)
        {
            //
            string[] latestActivity = { };

            Npg resCon;
            Npg connect = new Npg();
            resCon = connect.Connect();

            resCon.nNpgCmd = new Npgsql.NpgsqlCommand("SELECT pk, latest_activity_date, latest_activity_time FROM user_activity WHERE user_id = " + user_id, resCon.nNpgConn);

            NpgsqlDataReader dr = resCon.nNpgCmd.ExecuteReader();
            int i;

            try
            {
                while (dr.Read())
                {
                    for (i = 0; i < 1; i++)
                    {
                        latestActivity[i] = dr[i] + "";
                    }
                }
            }
            catch
            {
                SetLatestActivity(user_id);
            }

            //richTextBox1.Text += insertStr;
            resCon.nNpgConn.Close();

            return latestActivity;
        }
Ejemplo n.º 5
0
        public Npg Connect()
        {
            Npgsql.NpgsqlConnection NpgConn = null;
            Npgsql.NpgsqlCommand NpgCmd = null;
            String DbServer = "192.168.0.5";
            String UserName = "******";
            String UserPass = "******";
            String DbName = "postgres";
            NpgConn = new Npgsql.NpgsqlConnection("Server=" + DbServer + ";User Id=" + UserName + ";Password="******";Database=" + DbName + ";Encoding=UNICODE;");
            NpgConn.Open();

            Npg allNpg = new Npg { nNpgConn = NpgConn, nNpgCmd = NpgCmd };

            return allNpg;
        }
Ejemplo n.º 6
0
        // добавляем пользователя
        private void AddCustomerSystemInfo()
        {
            System.Diagnostics.Process process;
            process = System.Diagnostics.Process.GetCurrentProcess();

            PerformanceCounterCategory[] category = PerformanceCounterCategory.GetCategories();

            // takts and counts
            int core = (Int32)System.Environment.ProcessorCount;
            RegistryKey frecKey = Registry.LocalMachine;
            frecKey = frecKey.OpenSubKey(
               @"HARDWARE\DESCRIPTION\System\CentralProcessor\0", false);
            string Takt = frecKey.GetValue("~MHz").ToString();

            richTextBox1.Text +=
                "processor count: " + core +
                "\ntakt's :" + Takt;

            Npg resCon;
            Npg connect = new Npg();
            resCon = connect.Connect();

            string insertStr = "INSERT INTO customers_system_info (" +
                "user_id, process_name, process_id, paged_memory_size, none_paged_memory_size, peak_paged_memory_size, peak_virtual_memory_size, process_private_memory_size, all_private_memory_size, peak_working_set, responding, description, create_, takts, processor_count) VALUES (" +
                "1" +
                ", '" + process.ProcessName + "'" +
                ", " + process.Id +
                ", " + process.PagedMemorySize +
                ", " + process.NonpagedSystemMemorySize64 +
                ", " + process.PeakPagedMemorySize +
                ", " + process.PeakVirtualMemorySize +
                ", " + process.PrivateMemorySize +
                ", " + process.PrivateMemorySize64 +
                ", " + process.PeakWorkingSet +
                ", '" + process.Responding + "'" +
                ", 'test' ," +
                "'" +  DateTime.Now + "'" +
                ", '" + Takt + "'" +
                ", '" + core + "'" +
                ")";

            richTextBox1.Text += insertStr;

            resCon.nNpgCmd = new Npgsql.NpgsqlCommand(insertStr, resCon.nNpgConn);

            int rowsaffected;

            try
            {
                rowsaffected = resCon.nNpgCmd.ExecuteNonQuery();
                richTextBox1.Text += string.Format("\n\nIt was added {0} lines in table customers_system_info\n\n", rowsaffected);
            }
            finally
            {
                //NpgConn.Close();
            }

            //----------------------------------------- f**k

            resCon.nNpgCmd = new Npgsql.NpgsqlCommand("SELECT * FROM customers_system_info", resCon.nNpgConn);

            int i;

            try
            {
                NpgsqlDataReader dr = resCon.nNpgCmd.ExecuteReader();
                while (dr.Read())
                {
                    for (i = 0; i < dr.FieldCount; i++)
                    {
                        richTextBox1.Text += "\t" + dr.GetName(i) + " : " + dr[i] + "\n";
                        //richTextBox1.Text += "\n\ndr is: " + dr[i] + " \n";
                    }
                    richTextBox1.Text += "-------------------------------------\n";
                }
            }

            finally
            {
                resCon.nNpgConn.Close();
            }
        }
Ejemplo n.º 7
0
        // завершаем текушую сессию.
        private void ChangeSession(int status)
        {
            /*
             * statuses:
             *      1 - disabled;
             *      4 - waiting task;
            */

            // Получение имени компьютера.
            String host = System.Net.Dns.GetHostName();
            // Получение ip-адреса.
            System.Net.IPAddress ip = System.Net.Dns.GetHostByName(host).AddressList[0];
            //richTextBox1.Text += ip.ToString();

            Npg resCon;
            Npg connect = new Npg();
            resCon = connect.Connect();

            resCon.nNpgCmd = new Npgsql.NpgsqlCommand(("SELECT pk, user_id, user_name, create_ FROM users WHERE user_id = '" + ip + "' AND user_name = '" + host + "' ;"), resCon.nNpgConn);
            NpgsqlDataReader pk = resCon.nNpgCmd.ExecuteReader();

            string statusStr = "";
            if (status == 1)
            {
                statusStr = "\n\n session is over.\n\n";
            }
            else if (status == 4)
            {
                statusStr = "\n\n\t\t* " + DateTime.Now + " | session started \n";
            }

            pk.Read(); /// important to work!!

            string insertStr = "INSERT INTO user_status (user_id, status_id, modify_) VALUES (" +
                pk[0] +
                ", " + status +
                ", '" + DateTime.Now + "'" +
                ")";
            richTextBox1.Text += insertStr;

            resCon.nNpgCmd = new Npgsql.NpgsqlCommand(insertStr, resCon.nNpgConn);

            resCon.nNpgConn.Close();
        }
Ejemplo n.º 8
0
        private void button1_Click_1(object sender, EventArgs e)
        {
            int i;

            Npg resCon;
            Npg connect = new Npg();
            resCon = connect.Connect();

            resCon.nNpgCmd = new Npgsql.NpgsqlCommand("SELECT name, surname, addr, tel FROM data", resCon.nNpgConn);

            try
            {
                NpgsqlDataReader dr = resCon.nNpgCmd.ExecuteReader();
                while (dr.Read())
                {
                    for (i = 0; i < dr.FieldCount; i++)
                    {
                        richTextBox1.Text += "{" + i + "} : " + dr[i] + "\n";
                        //richTextBox1.Text += "\n\ndr is: " + dr[i] + " \n";
                    }
                    richTextBox1.Text += "-------------------------------------\n";
                }
            }

            finally
            {
                resCon.nNpgConn.Close();
            }
        }
Ejemplo n.º 9
0
        private void Authorization()
        {
            // Получение имени компьютера.
            String host = System.Net.Dns.GetHostName();
            // Получение ip-адреса.
            System.Net.IPAddress ip = System.Net.Dns.GetHostByName(host).AddressList[0];
            //richTextBox1.Text += ip.ToString();

            // авторизация пользователя. проверка, существует ли пользователь в системе. если нет - добавить.
            Npg resCon;
            Npg connect = new Npg();
            resCon = connect.Connect();

            resCon.nNpgCmd = new Npgsql.NpgsqlCommand(("SELECT pk, user_id, user_name, create_ FROM users WHERE user_id = '" + ip + "' AND user_name = '" + host + "' ;"), resCon.nNpgConn);

            int i;
            try
            {
                NpgsqlDataReader dr = resCon.nNpgCmd.ExecuteReader();
                while (dr.Read())
                {
                    for (i = 0; i < dr.FieldCount; i++)
                    {
                        richTextBox1.Text += "" + dr.GetName(i) + " : " + dr[i] + "\n";
                        //richTextBox1.Text += "\n\ndr is: " + dr[i] + " \n";
                    }
                    richTextBox1.Text += "\n\nuser is exist\n\n";
                }
            }
            catch
            {
                string insertStr = "INSERT INTO users (user_id, user_name, create_) VALUES (" +
                "'" + ip +
                "', '" + host +
                "', '" + DateTime.Now + "'" +
                ")";

                richTextBox1.Text += insertStr;

                resCon.nNpgCmd = new Npgsql.NpgsqlCommand(insertStr, resCon.nNpgConn);

                int rowsaffected;

                try
                {
                    rowsaffected = resCon.nNpgCmd.ExecuteNonQuery();
                    richTextBox1.Text += string.Format(insertStr + "\n\n user was added\n{0}\n", rowsaffected);
                }
                finally
                {
                    resCon.nNpgConn.Close();
                }
            }
        }