Пример #1
0
        public void insertDamp(double damp)
        {
            var db_conn = new db_connect();

            if (db_conn.OpenConnection())
            {
                sql = "INSERT INTO tblDamp (damp,date_Damp) " +
                      "VALUES (" + damp + ",NOW())";
                command             = new MySqlCommand();
                command.CommandType = CommandType.Text;
                command.CommandText = sql;
                command.Connection  = db_conn.connection;
                dr = command.ExecuteReader();

                if (dr.RecordsAffected == 1)
                {
                    db_conn.CloseConnection();
                }
                else
                {
                    db_conn.CloseConnection();
                    MessageBox.Show("Error Save !!!");
                }
            }
            else
            {
                MessageBox.Show("Cannot connect to server. Contact administrator.");
            }
        }
Пример #2
0
        public DataTable chkUser(string sql)
        {
            DataTable dt      = new DataTable();
            var       db_conn = new db_connect();

            if (db_conn.OpenConnection())
            {
                command             = new MySqlCommand();
                command.CommandType = CommandType.Text;
                command.CommandText = sql;
                command.Connection  = db_conn.connection;
                dr = command.ExecuteReader();

                if (dr.HasRows)
                {
                    dt.Load(dr);
                    db_conn.CloseConnection();
                    MessageBox.Show("Login Successfully.", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return(dt);
                }
                else
                {
                    db_conn.CloseConnection();
                    MessageBox.Show("Username หรือ Password ผิด", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return(dt);
                }
            }
            else
            {
                MessageBox.Show("Cannot connect to server. Contact administrator.");
                return(dt);
            }
        }
Пример #3
0
        public bool tranData(string sql)
        {
            var db_conn = new db_connect();

            if (db_conn.OpenConnection())
            {
                command             = new MySqlCommand();
                command.CommandType = CommandType.Text;
                command.CommandText = sql;
                command.Connection  = db_conn.connection;

                if (command.ExecuteNonQuery() == 1)
                {
                    db_conn.CloseConnection();
                    return(true);
                }
                else
                {
                    db_conn.CloseConnection();
                    MessageBox.Show("Error Save !!!");
                    return(false);
                }
            }
            else
            {
                MessageBox.Show("Cannot connect to server. Contact administrator.");
                return(false);
            }
        }
Пример #4
0
        public List <DataTable> getLastData()
        {
            var db_conn = new db_connect();

            dts = new List <DataTable>();
            DataTable dt = new DataTable();

            if (db_conn.OpenConnection())
            {
                sql                 = "SELECT date_Temp FROM tblTemp ORDER BY id_Temp DESC LIMIT 1";
                command             = new MySqlCommand();
                command.CommandType = CommandType.Text;
                command.CommandText = sql;
                command.Connection  = db_conn.connection;
                dr = command.ExecuteReader();

                if (dr.HasRows)
                {
                    dt.Load(dr);
                    dts.Add(dt);
                }

                sql                 = "SELECT date_Damp FROM tblDamp ORDER BY id_Damp DESC LIMIT 1";
                command             = new MySqlCommand();
                command.CommandType = CommandType.Text;
                command.CommandText = sql;
                command.Connection  = db_conn.connection;

                db_conn.CloseConnection();
                if (db_conn.OpenConnection())
                {
                    dr = command.ExecuteReader();
                }

                if (dr.HasRows)
                {
                    dt = null;
                    dt = new DataTable();
                    dt.Load(dr);
                    dts.Add(dt);
                }

                db_conn.CloseConnection();
                return(dts);
            }
            else
            {
                dt = new DataTable("No table");
                dts.Add(dt);
                return(dts);
            }
        }
Пример #5
0
        private void frmMain_Load(object sender, EventArgs e)
        {
            UseWaitCursor = true;
            string    sql    = "SELECT * FROM tblTemp WHERE DATE(date_Temp) = CURDATE()";
            var       manage = new db_manage();
            DataTable dt     = manage.getData(sql);

            this.chartTemp.Series["Temperature"].Points.AddXY(convertDate(dt), dt.Rows.Count == 0 ? 0 : dt.Rows[0][1]);

            sql = "SELECT * FROM tblDamp WHERE DATE(date_Damp) = CURDATE()";
            dt  = manage.getData(sql);
            this.chartTemp.Series["Humidity"].Points.AddXY(convertDate(dt), dt.Rows.Count == 0 ? 0 : dt.Rows[0][1]);

            sql = "SELECT * FROM tblTemp WHERE DATE(date_Temp) = CURDATE() - 1";
            dt  = manage.getData(sql);
            this.chartTemp.Series["Temperature"].Points.AddXY(convertDate(dt), dt.Rows.Count == 0 ? 0 : dt.Rows[0][1]);

            sql = "SELECT * FROM tblDamp WHERE DATE(date_Damp) = CURDATE() - 1";
            dt  = manage.getData(sql);
            this.chartTemp.Series["Humidity"].Points.AddXY(convertDate(dt), dt.Rows.Count == 0 ? 0 : dt.Rows[0][1]);

            sql = "SELECT * FROM tblTemp WHERE DATE(date_Temp) = CURDATE() - 2";
            dt  = manage.getData(sql);
            this.chartTemp.Series["Temperature"].Points.AddXY(convertDate(dt), dt.Rows.Count == 0 ? 0 : dt.Rows[0][1]);

            sql = "SELECT * FROM tblDamp WHERE DATE(date_Damp) = CURDATE() - 2";
            dt  = manage.getData(sql);
            this.chartTemp.Series["Humidity"].Points.AddXY(convertDate(dt), dt.Rows.Count == 0 ? 0 : dt.Rows[0][1]);

            picEmp.Image   = imgEmp;
            lblNmeEmp.Text = nameEmp;

            var db_conn = new db_connect();

            if (db_conn.OpenConnection())
            {
                lblDBName.Text      = db_conn.connection.Database;
                lblDataSrc.Text     = db_conn.connection.DataSource;
                lblIP.Text          = Program.GetIP();
                lblServThread.Text  = db_conn.connection.ServerThread.ToString();
                lblServVersion.Text = db_conn.connection.ServerVersion;
                lblServState.Text   = db_conn.connection.State.ToString();
                lblHosting.Text     = "www.ppakorni.info";
                db_conn.CloseConnection();
            }
            else
            {
                lblDBName.Text      = $"Unknown";
                lblDataSrc.Text     = $"Unknown";
                lblIP.Text          = Program.GetIP();
                lblServThread.Text  = $"Unknown";
                lblServVersion.Text = $"Unknown";
                lblServState.Text   = $"Unknown";
                lblHosting.Text     = $"Unknown";
            }
            UseWaitCursor = false;
        }
Пример #6
0
        private void chkConnect()
        {
            Cursor.Current = Cursors.WaitCursor;
            var db_conn = new db_connect();

            if (db_conn.OpenConnection())
            {
                status_info.BackColor = Color.LimeGreen;
                status_db_name.Text   = $"The program is ready";
                db_conn.CloseConnection();
            }
            else
            {
                status_info.BackColor = Color.DarkOrange;
                status_db_name.Text   = $"The program is not ready";
            }
            Cursor.Current = Cursors.Default;
        }