Exemple #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.");
            }
        }
Exemple #2
0
        public int lastObj(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;
                dr = command.ExecuteReader();
                if (dr.HasRows)
                {
                    int count = 0;
                    while (dr.Read())
                    {
                        count++;
                    }

                    return(count);
                }
                else
                {
                    return(0);
                }
            }
            else
            {
                MessageBox.Show("Cannot connect to server. Contact administrator.");
                return(-1);
            }
        }
Exemple #3
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);
            }
        }
Exemple #4
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);
            }
        }
Exemple #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;
        }
Exemple #6
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);
            }
        }
Exemple #7
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;
        }
Exemple #8
0
        public string getPlan(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;
                dr = command.ExecuteReader();
                dr.Read();
                return(dr["name_Area"].ToString());
            }
            else
            {
                MessageBox.Show("Cannot connect to server. Contact administrator.");
                return("");
            }
        }
Exemple #9
0
        public DataTable getData(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();
                dt.Load(dr);
                return(dt);
            }
            else
            {
                MessageBox.Show("Cannot connect to server. Contact administrator.");
                return(dt);
            }
        }
Exemple #10
0
        private void pictureBox1_Click(object sender, EventArgs e)
        {
            if ((txtUser.Text != "") && (txtPass.Text != "") && (txtRePass.Text != "") &&
                (txtName.Text != "") && (txtIdCard.Text != ""))
            {
                if (txtPass.Text.Equals(txtRePass.Text))
                {
                    if (txtIdCard.TextLength == 13)
                    {
                        if (picCapture.Image == null)
                        {
                            MessageBox.Show("กรุณาถ่ายรูปพนักงาน", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                            return;
                        }

                        Cursor.Current = Cursors.WaitCursor;
                        char sex;
                        if (rdoM.Checked)
                        {
                            sex = 'M';
                        }
                        else
                        {
                            sex = 'F';
                        }

                        Image        img = picCapture.Image;
                        MemoryStream mem = new MemoryStream();
                        img.Save(mem, ImageFormat.Png);
                        byte[] imgByte = mem.ToArray();

                        string sql = "INSERT INTO tblEmployees " +
                                     "(User_Emp,Pass_Emp,Name_Emp,IdCard_Emp,Gender_Emp,Address_Emp,Age_Emp,Edu_Emp,img_Emp) " +
                                     "VALUES (@User_Emp, @Pass_Emp, @Name_Emp, @IdCard_Emp, @Gender_Emp, @Address_Emp, @Age_Emp, @Edu_Emp, @img_Emp)";

                        var db_conn = new db_connect();
                        if (db_conn.OpenConnection())
                        {
                            MySqlCommand cmd = new MySqlCommand(sql, db_conn.connection);
                            cmd.Parameters.Add("@User_Emp", MySqlDbType.VarChar, 30);
                            cmd.Parameters.Add("@Pass_Emp", MySqlDbType.VarChar, 30);
                            cmd.Parameters.Add("@Name_Emp", MySqlDbType.VarChar, 50);
                            cmd.Parameters.Add("@IdCard_Emp", MySqlDbType.VarChar, 13);
                            cmd.Parameters.Add("@Gender_Emp", MySqlDbType.VarChar, 1);
                            cmd.Parameters.Add("@Address_Emp", MySqlDbType.Text);
                            cmd.Parameters.Add("@Age_Emp", MySqlDbType.Int16, 2);
                            cmd.Parameters.Add("@Edu_Emp", MySqlDbType.VarChar, 20);
                            cmd.Parameters.Add("@img_Emp", MySqlDbType.MediumBlob);

                            cmd.Parameters["@User_Emp"].Value    = txtUser.Text;
                            cmd.Parameters["@Pass_Emp"].Value    = txtRePass.Text;
                            cmd.Parameters["@Name_Emp"].Value    = txtName.Text;
                            cmd.Parameters["@IdCard_Emp"].Value  = txtIdCard.Text;
                            cmd.Parameters["@Gender_Emp"].Value  = sex;
                            cmd.Parameters["@Address_Emp"].Value = txtAddress.Text;
                            cmd.Parameters["@Age_Emp"].Value     = Convert.ToInt32(numricAge.Value);
                            cmd.Parameters["@Edu_Emp"].Value     = cmbDegree.Text;
                            cmd.Parameters["@img_Emp"].Value     = imgByte;

                            int RowsAffected = cmd.ExecuteNonQuery();
                            if (RowsAffected > 0)
                            {
                                MessageBox.Show("บันทึกสำเร็จ", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            }
                            else
                            {
                                MessageBox.Show("กรุณาทำรายการใหม่", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            }
                            db_conn.connection.Close();
                            Cursor.Current = Cursors.Default;
                        }
                        else
                        {
                            MessageBox.Show("Cannot connect to server. Contact administrator.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            return;
                        }
                    }
                    else
                    {
                        MessageBox.Show("เลขบัตรประชาชนไม่ครบ 13 หลัก", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                }
                else
                {
                    MessageBox.Show("คุณใส่รหัสผ่านไม่ตรงกัน", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
            else
            {
                MessageBox.Show("คุณใส่ข้อมูลไม่ครบ", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }