コード例 #1
0
ファイル: User.cs プロジェクト: joao2605/cdap
        //Update log tracker
        public bool UpdateLogRecord(string ID, DateTime Login_Time, DateTime Logout_Time)
        {
            try
            {
                this.connection = DBHandler.getConnection();
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message.ToString());
            }

            bool status = false;

            if (connection.State.ToString() == "Closed")
            {
                connection.Open();
            }

            SqlCommand cmd = new SqlCommand("updateUserTrack", connection);

            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.Add("@UserID", SqlDbType.VarChar).Value      = ID;
            cmd.Parameters.Add("@loginTime", SqlDbType.DateTime).Value  = Login_Time;
            cmd.Parameters.Add("@logoutTime", SqlDbType.DateTime).Value = Logout_Time;

            try
            {
                cmd.ExecuteNonQuery();
                status = true;
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error" + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            connection.Close();
            return(status);
        }
コード例 #2
0
ファイル: User.cs プロジェクト: joao2605/cdap
        //Inset new User
        public bool InsertUser(User newUser)
        {
            try
            {
                this.connection = DBHandler.getConnection();
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message.ToString());
            }

            bool status = false;

            if (connection.State.ToString() == "Closed")
            {
                connection.Open();
            }

            SqlCommand newCmd = connection.CreateCommand();

            newCmd.Connection  = connection;
            newCmd.CommandType = CommandType.Text;
            newCmd.CommandText = "insert into Users values('" + newUser.userId + "','" + newUser.firstName + "','" + newUser.lastName + "','" + newUser.title + "','" + newUser.userLevel + "','" + newUser.username + "','" + newUser.password + "','" + newUser.email + "','" + newUser.createdDate + "','" + newUser.createdTime + "','" + newUser.photo + "')";
            try
            {
                newCmd.ExecuteNonQuery();
                status = true;
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error" + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            connection.Close();
            return(status);
        }
コード例 #3
0
ファイル: User.cs プロジェクト: joao2605/cdap
        //Insert log tracker
        public bool InsertLogRecord(string ID, DateTime Date)
        {
            try
            {
                this.connection = DBHandler.getConnection();
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message.ToString());
            }

            bool status = false;

            if (connection.State.ToString() == "Closed")
            {
                connection.Open();
            }

            SqlCommand newCmd = connection.CreateCommand();

            newCmd.Connection  = connection;
            newCmd.CommandType = CommandType.Text;
            newCmd.CommandText = "INSERT INTO User_Tracker VALUES('" + ID + "','" + Date + "','" + Date + "',0,'No')";
            try
            {
                newCmd.ExecuteNonQuery();
                status = true;
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error" + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            connection.Close();
            return(status);
        }
コード例 #4
0
ファイル: User.cs プロジェクト: joao2605/cdap
        //take the password according to the user name
        public DataSet getPassword(string userId)
        {
            try
            {
                this.connection = DBHandler.getConnection();
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message.ToString());
            }

            if (connection.State.ToString() == "Closed")
            {
                connection.Open();
            }

            DataSet        ds      = new DataSet();
            SqlDataAdapter adapter = new SqlDataAdapter("select user_level,password,user_name from Users where user_id='" + userId + "' ", connection);

            adapter.Fill(ds);

            connection.Close();
            return(ds);
        }
コード例 #5
0
ファイル: User.cs プロジェクト: joao2605/cdap
        //update User
        public bool UpdateUser(User editedUser)
        {
            try
            {
                this.connection = DBHandler.getConnection();
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message.ToString());
            }

            bool status = false;

            if (connection.State.ToString() == "Closed")
            {
                connection.Open();
            }

            SqlCommand newCmd = connection.CreateCommand();

            newCmd.Connection  = connection;
            newCmd.CommandType = CommandType.Text;
            newCmd.CommandText = "UPDATE Users SET user_id='" + editedUser.userId + "',first_name='" + editedUser.firstName + "',last_name='" + editedUser.lastName + "',title='" + editedUser.title + "',user_level='" + editedUser.userLevel + "',user_name='" + editedUser.username + "',password='******',email='" + editedUser.email + "',photograph='" + editedUser.photo + "' where user_id='" + editedUser.userId + "';";
            try
            {
                newCmd.ExecuteNonQuery();
                status = true;
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error" + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            connection.Close();
            return(status);
        }
コード例 #6
0
ファイル: User.cs プロジェクト: joao2605/cdap
        //Reset User
        public bool ResetUser(string user_ID, string user_name, string password)
        {
            try
            {
                this.connection = DBHandler.getConnection();
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message.ToString());
            }

            bool status = false;

            if (connection.State.ToString() == "Closed")
            {
                connection.Open();
            }

            SqlCommand newCmd = connection.CreateCommand();

            newCmd.Connection  = connection;
            newCmd.CommandType = CommandType.Text;
            newCmd.CommandText = "UPDATE Users SET user_name='" + user_name + "',password='******' WHERE user_id='" + user_ID + "';";
            try
            {
                newCmd.ExecuteNonQuery();
                status = true;
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error" + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            connection.Close();
            return(status);
        }
コード例 #7
0
 public DBAccess()
 {
     //get connection
     this.connection = DBHandler.getConnection();
 }
コード例 #8
0
        private void btnSignin_Click(object sender, EventArgs e)
        {
            if ((txtUserId.Text == "" || txtPassWord.Text == ""))
            {
                MessageBox.Show("Text fields must be filled", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            else
            {
                string EntUserID   = txtUserId.Text;
                string EntPassword = txtPassWord.Text;

                try
                {
                    this.connection = DBHandler.getConnection();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message.ToString());
                }

                if (connection.State.ToString() == "Closed")
                {
                    connection.Open();
                }

                DataSet DS = USR.getPassword(txtUserId.Text);

                foreach (DataRow row in DS.Tables[0].Rows)
                {
                    for (int i = 0; i < DS.Tables[0].Columns.Count; i++)
                    {
                        userlevel = row[0].ToString().Trim();
                        password  = row[1].ToString().Trim();
                        username  = row[2].ToString().Trim();
                    }
                }

                if (EntPassword == password)
                {
                    logDate = Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-ddThh:mm:sszzz"));
                    Main main = new Main(username, userlevel, txtUserId.Text, logDate);
                    main.Show();
                    this.Hide(); //DWHZYWAQSR

                    if (USR.InsertLogRecord(txtUserId.Text, logDate))
                    {
                        alertLogTracker.ContentText = "Login Tracked : " + logDate;
                        alertLogTracker.Show();
                    }
                    else
                    {
                        alertLogTracker.ContentText = "Failure Occured ..!";
                        alertLogTracker.Show();
                    }
                }
                else
                {
                    MessageBox.Show("Incorrect LogIn Information!Please Re-Enter Username and Password", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }