示例#1
0
        private void btnAddEmployee_Click(object sender, EventArgs e)
        {
            if (ValidationManageEmployeeAdd())
            {
                using (DBConnect db = new DBConnect())
                {
                    try
                    {
                        byte[]       imageBt = null;
                        FileStream   fstream = new FileStream(this.txtpicpath.Text, FileMode.Open, FileAccess.Read);
                        BinaryReader br      = new BinaryReader(fstream);
                        imageBt = br.ReadBytes((int)fstream.Length);

                        DialogResult d = MessageBox.Show("Are you sure want to add this Employee..?", "Confirm", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation);

                        if (d == DialogResult.Yes)
                        {
                            DateTime dt   = txtDatetime.Value;
                            String   date = dt.ToString("yyyy-MM-dd");
                            Console.WriteLine(en.EncryptString("1234"));
                            String q = "insert into employee(name,nic,dob,address,contactHome,contactMobile,jobRole,image,password,changedBy) values ('" + txtEmployeeName.Text + "','" + txtEmployeeNIC.Text + "','" + date + "','" + txtEmployeeAddress.Text + "','" + txtContactNoHome.Text + "','" + txtContactNoMobile.Text + "','" + comboJobRole.Text + "',@IMG,'" + en.EncryptString("1234") + "','" + this.loggedEmployeeID + "')";


                            MySqlCommand cmd = new MySqlCommand(q, db.con);
                            cmd.Parameters.Add(new MySqlParameter("@IMG", imageBt));
                            cmd.ExecuteNonQuery();



                            String          q1   = "SELECT * FROM employee WHERE name ='" + txtEmployeeName.Text + "'";
                            MySqlCommand    cmd1 = new MySqlCommand(q1, db.con);
                            MySqlDataReader r    = cmd1.ExecuteReader();

                            while (r.Read())
                            {
                                txtEmployeeID.Text = r[0].ToString();
                            }



                            MessageBox.Show("Employee Inserted Succesfully", "Done..!", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }
                    }


                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.StackTrace);
                    }
                }
            }
        }
示例#2
0
        private void btnUpdate_Click(object sender, EventArgs e)
        {
            EncryptAndDecrypt en = new EncryptAndDecrypt();

            if (txtNewPassword.Text.Length >= 4)
            {
                if (txtNewPassword.Text.Equals(txtRenewPassword.Text))
                {
                    if (oldPassword.Equals(en.EncryptString(txtCurrentPassword.Text)))
                    {
                        DialogResult d = MessageBox.Show("Are you sure you want to update your password...?", "Confirm", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
                        if (d == DialogResult.Yes)
                        {
                            DBConnect db = new DBConnect();

                            String       q   = "update employee set password = '******' where employeeNo ='" + id + "'";
                            MySqlCommand cmd = new MySqlCommand(q, db.con);
                            cmd.ExecuteNonQuery();
                            MessageBox.Show("Password updated successfully", "Done", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            this.Hide();
                        }
                    }
                    else
                    {
                        MessageBox.Show("Current Password is not valid", "Invalid Password", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        btnClear_Click(sender, e);
                    }
                }
                else
                {
                    MessageBox.Show("New password does not match. Please re-enter", "Invalid password", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    btnClear_Click(sender, e);
                }
            }
            else
            {
                MessageBox.Show("Password should be at least 4 characters", "Invalid Password", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
示例#3
0
        private void btnLogin_Click(object sender, EventArgs e)
        {
            try
            {
                DBConnect db = new DBConnect();

                String          q   = "SELECT * FROM employee WHERE employeeNo  ='" + txtEmployeeID.Text + "'";
                MySqlCommand    cmd = new MySqlCommand(q, db.con);
                MySqlDataReader r   = cmd.ExecuteReader();

                if (r.HasRows)
                {
                    while (r.Read())
                    {
                        String user     = r["name"].ToString();
                        String password = r["password"].ToString();
                        Console.WriteLine(password);
                        String jobRole = r["jobRole"].ToString();
                        Console.WriteLine(jobRole);
                        Console.WriteLine();
                        if (en.EncryptString(txtpassword.Text).Equals(password))
                        {
                            if (jobRole.Equals("Manager"))
                            {
                                Form1 f = new Form1(user, jobRole, txtEmployeeID.Text);
                                f.Show();
                                this.Hide();
                            }
                        }
                        else
                        {
                            MessageBox.Show("Incorrect Password. Please check and try again", "Sorry..", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        }
                    }
                }
                else
                {
                    MessageBox.Show("Incorrect Username. Please check and try again", "Sorry..", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.StackTrace);
            }
        }
示例#4
0
        private void btnLogin_Click(object sender, EventArgs e)
        {
            try
            {
                using (DBConnect db = new DBConnect())
                {
                    String          q   = "SELECT * FROM employee WHERE employeeNo  ='" + txtEmployeeID.Text + "'";
                    MySqlCommand    cmd = new MySqlCommand(q, db.con);
                    MySqlDataReader r   = cmd.ExecuteReader();

                    if (r.HasRows)
                    {
                        while (r.Read())
                        {
                            String user     = r["name"].ToString();
                            String password = r["password"].ToString();
                            Console.WriteLine(password);
                            String jobRole = r["jobRole"].ToString();
                            Console.WriteLine(jobRole);
                            Console.WriteLine();
                            if (en.EncryptString(txtpassword.Text).Equals(password))
                            {
                                if (jobRole.Equals("Manager"))
                                {
                                    Form1 f = new Form1(user, jobRole, txtEmployeeID.Text);
                                    f.Show();
                                    this.Hide();
                                }
                            }
                            else
                            {
                                MessageBox.Show("Incorrect Password. Please check and try again", "Sorry..", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                            }
                        }
                    }
                    else
                    {
                        MessageBox.Show("Incorrect Username. Please check and try again", "Sorry..", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    }
                }
                using (DBConnect db = new DBConnect())
                {
                    IPHostEntry host;
                    String      myIp = "";
                    host = Dns.GetHostEntry(Dns.GetHostName());

                    foreach (IPAddress ip in host.AddressList)
                    {
                        if (ip.AddressFamily.ToString() == "InterNetwork")
                        {
                            myIp = ip.ToString();
                            // MessageBox.Show(myIp);
                        }
                    }

                    String       q   = "INSERT INTO `userip`(`employeeNo`, `ip`) VALUES ('" + txtEmployeeID.Text + "','" + myIp + "') ON DUPLICATE KEY UPDATE ip = '" + myIp + "'";
                    MySqlCommand cmd = new MySqlCommand(q, db.con);
                    cmd.ExecuteNonQuery();
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.StackTrace);
            }
        }