Пример #1
0
        private void staffLgn_Click(object sender, EventArgs e)
        {
            try
            {
                StaffMain staff = new StaffMain();
                string    pass;
                pass          = Eramake.eCryptography.Encrypt(stffPass.Text);
                stffPass.Text = Eramake.eCryptography.Decrypt(pass.ToString());
                if (stffUname.Text == "Username" || stffPass.Text == "Password")
                {
                    MessageBox.Show("Please fillup al fields.");
                    return;
                }

                else
                {
                    Connection con = new Connection();
                    con.Connect();
                    SqlCommand cmd = new SqlCommand();

                    cmd.CommandText = "Select * from staff where staff_username=@username AND staff_password=@password";
                    cmd.Parameters.AddWithValue("@username", stffUname.Text);
                    cmd.Parameters.AddWithValue("@password", pass);
                    cmd.Connection = Connection.con;

                    SqlDataAdapter adapt = new SqlDataAdapter(cmd);
                    DataSet        ds    = new DataSet();
                    adapt.Fill(ds);

                    int    count = ds.Tables[0].Rows.Count;
                    string str;

                    str = "select * from staff";
                    SqlCommand com = new SqlCommand();
                    com.Connection  = Connection.con;
                    com.CommandText = str;

                    if (count == 1)
                    {
                        this.getTheName(stffUname.Text);
                        StaffMain sm = new StaffMain();
                        sm.ID = id.Trim();
                        sm.MyUser();
                        this.Hide();
                        sm.ShowDialog();
                    }
                    else
                    {
                        MessageBox.Show("Login Failed!!! Try Again.");
                        stffPass.Text = "";
                        stffPass.Focus();
                        return;
                    }
                }
            }
            catch
            {
                MessageBox.Show("Invalid Server settings");
            }
        }
Пример #2
0
        private void save_Click(object sender, EventArgs e)
        {
            myCamera.Stop();

            if (mi.Text.Length > 1)
            {
                MessageBox.Show("Initials must be 1 character!");
                mi.Focus();
            }
            else if (cnum.Text.Length > 11 || cnum.Text.Length < 11)
            {
                MessageBox.Show("Contact number must be 11 digits!");
                cnum.Focus();
            }
            else if (newUname.Text.Length < 4)
            {
                MessageBox.Show("Username must be 4 characters above!");
                newUname.Focus();
            }
            else
            {
                Connection conn = new Connection();
                conn.Connect();
                SqlCommand cmd3 = new SqlCommand();
                SqlCommand cmd2 = new SqlCommand();
                cmd2.Connection  = Connection.con;
                cmd2.CommandText = "update staff set staff_age = datediff(YY, staff_dob,GETDATE()) WHERE STAFF_ID = '" + ID + "'";
                cmd3.Connection  = Connection.con;

                string pass;
                pass             = Eramake.eCryptography.Encrypt(oldPass.Text);
                oldPass.Text     = Eramake.eCryptography.Decrypt(pass.ToString());
                newPass.Text     = Eramake.eCryptography.Encrypt(newPass.Text);
                confirmPass.Text = Eramake.eCryptography.Encrypt(confirmPass.Text);
                MemoryStream stream = new MemoryStream();
                if (ii == 1 && groupBox2.Enabled == true)
                {
                    cmd3.CommandText   = "UPDATE STAFF SET STAFF_FNAME =@fname ,STAFF_MNAME = @mname ,STAFF_LNAME = @lname,STAFF_CNUM = @cnum,STAFF_ADDRESS = @add,STAFF_DOB =@dob,STAFF_GENDER= @gender,STAFF_USERNAME = @username,STAFF_PASSWORD =@pass,STAFF_IMAGE = @pic,STAFF_QUESTION = @quest, STAFF_ANSWER = @ans WHERE STAFF_ID = '" + ID + "'";
                    profileImage.Image = resizeImage(profileImage.Image, new Size(177, 151));
                    profileImage.Image.Save(stream, System.Drawing.Imaging.ImageFormat.Jpeg);
                    byte[] pic = stream.ToArray();
                    cmd3.Parameters.AddWithValue("@fname", fname.Text);
                    cmd3.Parameters.AddWithValue("@mname", mi.Text);
                    cmd3.Parameters.AddWithValue("@lname", lname.Text);
                    cmd3.Parameters.AddWithValue("@cnum", cnum.Text);
                    cmd3.Parameters.AddWithValue("@add", address.Text);

                    cmd3.Parameters.AddWithValue("@dob", dob.Value);
                    cmd3.Parameters.AddWithValue("@gender", gender.Text);
                    cmd3.Parameters.AddWithValue("@pic", pic);
                    cmd3.Parameters.AddWithValue("@username", newUname.Text);
                    cmd3.Parameters.AddWithValue("@quest", question.Text);
                    cmd3.Parameters.AddWithValue("@ans", answer.Text);

                    if (pass == pasd && newPass.Text == confirmPass.Text && newPass.Text != "" && confirmPass.Text != "")
                    {
                        cmd3.Parameters.AddWithValue("@pass", newPass.Text);
                        if (newPass.Text.Length < 6)
                        {
                            MessageBox.Show("Password must be atleast 6 characters and above!");
                            cnum.Focus();
                        }
                        else
                        {
                            cmd3.ExecuteNonQuery();
                            cmd2.ExecuteNonQuery();
                            MessageBox.Show("Saved");
                            DisplayData();
                            EditBtn.Visible   = true;
                            save.Visible      = false;
                            cancelBtn.Visible = false;
                            Disable();
                            MessageBox.Show("You need to login again");
                            Application.Restart();
                            ii = 0;
                        }
                    }
                    else
                    {
                        notify.Text = "Password not matched!";
                    }
                }
                else if (ii == 1 && groupBox2.Enabled == false)
                {
                    cmd3.CommandText   = "UPDATE STAFF SET STAFF_FNAME =@fname ,STAFF_MNAME = @mname ,STAFF_LNAME = @lname,STAFF_CNUM = @cnum,STAFF_ADDRESS = @add,STAFF_DOB =@dob,STAFF_GENDER= @gender,STAFF_IMAGE = @pic,STAFF_USERNAME = @username,STAFF_QUESTION = @quest,STAFF_ANSWER = @ans  WHERE STAFF_ID = '" + ID + "'";
                    profileImage.Image = resizeImage(profileImage.Image, new Size(177, 151));
                    profileImage.Image.Save(stream, System.Drawing.Imaging.ImageFormat.Jpeg);
                    byte[] pic = stream.ToArray();
                    cmd3.Parameters.AddWithValue("@fname", fname.Text);
                    cmd3.Parameters.AddWithValue("@mname", mi.Text);
                    cmd3.Parameters.AddWithValue("@lname", lname.Text);
                    cmd3.Parameters.AddWithValue("@cnum", cnum.Text);
                    cmd3.Parameters.AddWithValue("@add", address.Text);

                    cmd3.Parameters.AddWithValue("@dob", dob.Value);
                    cmd3.Parameters.AddWithValue("@gender", gender.Text);
                    cmd3.Parameters.AddWithValue("@pic", pic);
                    cmd3.Parameters.AddWithValue("@username", newUname.Text);
                    cmd3.Parameters.AddWithValue("@quest", question.Text);
                    cmd3.Parameters.AddWithValue("@ans", answer.Text);
                    cmd3.ExecuteNonQuery();
                    cmd2.ExecuteNonQuery();
                    MessageBox.Show("Saved");
                    DisplayData();
                    EditBtn.Visible   = true;
                    save.Visible      = false;
                    cancelBtn.Visible = false;
                    MessageBox.Show("You need to login again");
                    Application.Restart();
                    Disable();
                    ii = 0;
                }
                else if (ii != 1 && groupBox2.Enabled == false)
                {
                    cmd3.CommandText = "UPDATE STAFF SET STAFF_FNAME =@fname ,STAFF_MNAME = @mname ,STAFF_LNAME = @lname,STAFF_CNUM = @cnum,STAFF_ADDRESS = @add,STAFF_DOB =@dob,STAFF_GENDER= @gender, STAFF_USERNAME = @username,STAFF_QUESTION = @quest,STAFF_ANSWER = @ans WHERE STAFF_ID = '" + ID + "'";
                    cmd3.Parameters.AddWithValue("@fname", fname.Text);
                    cmd3.Parameters.AddWithValue("@mname", mi.Text);
                    cmd3.Parameters.AddWithValue("@lname", lname.Text);
                    cmd3.Parameters.AddWithValue("@cnum", cnum.Text);
                    cmd3.Parameters.AddWithValue("@add", address.Text);
                    cmd3.Parameters.AddWithValue("@dob", dob.Value);
                    cmd3.Parameters.AddWithValue("@gender", gender.Text);
                    cmd3.Parameters.AddWithValue("@username", newUname.Text);
                    cmd3.Parameters.AddWithValue("@quest", question.Text);
                    cmd3.Parameters.AddWithValue("@ans", answer.Text);
                    // cmd3.Parameters.AddWithValue("@pic", SqlDbType.VarChar).Value = null;
                    cmd3.ExecuteNonQuery();
                    cmd2.ExecuteNonQuery();
                    DisplayData();
                    MessageBox.Show("Saved");
                    EditBtn.Visible   = true;
                    save.Visible      = false;
                    cancelBtn.Visible = false;
                    MessageBox.Show("You need to login again");
                    Application.Restart();
                    Disable();
                    ii = 0;
                }
                else if (ii != 1 && groupBox2.Enabled == true)
                {
                    cmd3.CommandText = "UPDATE STAFF SET STAFF_FNAME =@fname ,STAFF_MNAME = @mname ,STAFF_LNAME = @lname,STAFF_CNUM = @cnum,STAFF_ADDRESS = @add,STAFF_DOB =@dob,STAFF_GENDER= @gender, STAFF_USERNAME = @username, STAFF_PASSWORD = @pass,STAFF_QUESTION = @quest,STAFF_ANSWER = @ans WHERE STAFF_ID = '" + ID + "'";
                    cmd3.Parameters.AddWithValue("@fname", fname.Text);
                    cmd3.Parameters.AddWithValue("@mname", mi.Text);
                    cmd3.Parameters.AddWithValue("@lname", lname.Text);
                    cmd3.Parameters.AddWithValue("@cnum", cnum.Text);
                    cmd3.Parameters.AddWithValue("@add", address.Text);

                    cmd3.Parameters.AddWithValue("@dob", dob.Value);
                    cmd3.Parameters.AddWithValue("@gender", gender.Text);
                    cmd3.Parameters.AddWithValue("@username", newUname.Text);
                    cmd3.Parameters.AddWithValue("@quest", question.Text);
                    cmd3.Parameters.AddWithValue("@ans", answer.Text);
                    // cmd3.Parameters.AddWithValue("@pic", SqlDbType.VarChar).Value = null;
                    if (pass == pasd && newPass.Text == confirmPass.Text && newPass.Text != "" && confirmPass.Text != "")
                    {
                        cmd3.Parameters.AddWithValue("@pass", newPass.Text);
                        if (newPass.Text.Length < 6)
                        {
                            MessageBox.Show("Password must be atleast 6 characters and above!");
                            cnum.Focus();
                        }
                        else
                        {
                            cmd3.ExecuteNonQuery();
                            cmd2.ExecuteNonQuery();
                            MessageBox.Show("Saved");
                            DisplayData();
                            EditBtn.Visible   = true;
                            save.Visible      = false;
                            cancelBtn.Visible = false;
                            MessageBox.Show("You need to login again");
                            Application.Restart();
                            Disable();
                            ii = 0;
                        }
                    }
                    else
                    {
                        notify.Text = "Password not matched!";
                    }
                }
            }
            StaffMain sf = new StaffMain();

            sf.MyUser();
        }