public void accountList <T>(AccountList <T> accountList) { //Build a query string string sql = string.Format("SELECT [userID],[userName],[password],[authLevel],[joinedDate],[isLoggedIn] FROM [OTF_Invoice].[dbo].[USERS]"); //Get a dataset from the query DataSet dataSet = DataProvider.GetDataSet(sql); //Create variables for dataset DataTable rotiTable = dataSet.Tables[0]; //Load roti list from the database accountItem nextAccount = null; foreach (DataRow parent in rotiTable.Rows) { nextAccount = new accountItem(); nextAccount.UserName = parent["userName"].ToString(); nextAccount.PassWord = parent["password"].ToString(); //Add the data item to the data list accountList.Add(nextAccount); } //Dispose of the dataset dataSet.Dispose(); }
private void button1_Click(object sender, EventArgs e) { m_Item = (accountItem)accountItemBindingSource.Current; if (m_Item == null) { return; } if (m_Item.Login()) { isLoggedIn = true; MessageBox.Show("Selamat ! Anda Berhasil Masuk"); this.Close(); } }
internal bool Login(accountItem loginAccount) { try { db.StartConnection(); //SqlConnection connection = new SqlConnection(Settings.Default.ConnectionString.ToString()); //connection.Open(); string sql = "SELECT Username FROM USERS WHERE password = @password"; SqlCommand command = new SqlCommand(sql, db.Koneksi); command.CommandType = System.Data.CommandType.Text; command.Parameters.Clear(); command.Parameters.AddWithValue("@password", encrypt.HashPassword(loginAccount.PassWord.Replace("'", ""))); string username = (string)command.ExecuteScalar(); command.Dispose(); db.CloseConnection(); if (username == loginAccount.UserName.Replace("'", "")) { sessionUser.Login(username); return(true); } else if (username == "") { MessageBox.Show("Password Salah !"); return(false); } else { MessageBox.Show("Username Salah !"); return(false); } } catch (Exception ex) { MessageBox.Show(ex.ToString()); return(false); } }
internal void CreateDatabasesRecord(accountItem newAccount) { try { //Create and open a connection db.StartConnection(); //Sql Query string sql = "INSERT INTO Users " + "(userID, userName, password, authLevel, JoinedDate) " + " VALUES " + "(@userID, @userName, @password, @authLevel, @joinedDate)"; //create and configure a command SqlCommand command = new SqlCommand(sql, db.Koneksi); //Adding value through parameter command.CommandType = System.Data.CommandType.Text; command.Parameters.Clear(); command.Parameters.AddWithValue("@userID", newAccount.UserID); command.Parameters.AddWithValue("@userName", newAccount.UserName); command.Parameters.AddWithValue("@password", encrypt.HashPassword(newAccount.PassWord)); command.Parameters.AddWithValue("@authLevel", newAccount.AuthLevel); command.Parameters.AddWithValue("@joinedDate", newAccount.JoinedDate); //execute the command command.ExecuteNonQuery(); //Close and dispose command.Dispose(); db.CloseConnection(); //db.Koneksi.Dispose(); } catch (SqlException ex) { MessageBox.Show(ex.Message.ToString()); } }
private void button1_Click(object sender, EventArgs e) { m_Item = (accountItem)accountItemBindingSource.Current; m_Item.JoinedDate = DateTime.Now; m_Item.CreateDatabaseRecord(); }