|
|
Dude, look. Asking this question is just stupid. If you think our opinion is ever going to sway your instructors is ridiculous.
Again, your code doesn't meet the requirements, not even close.
You've asked this question twice now and come on on the losing end every time. The problem is not with the instructor. It's with you.
|
|
|
|
|
|
Your instructor is right. You could implement this in a dozen lines, using a generic. I'd award you extra credit if you catered for doubles not being 100% accurate in comparisons (there are ways to do this in a generic fashion).
|
|
|
|
|
|
Urgent assist required. Can someone help pls, i have scanned wifi data in C# that i have split into required form MAC,SSID and RSSi . i want when i push a button the results are inserted into an sql table that i already created. and if i push the buton again it stops inserting. I have tried several methods and could not get it to work, Will appreciate assist
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO.Ports;
namespace WICED_SERIALPORT_TEST
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
string[] ports = SerialPort.GetPortNames();
foreach (string port in ports)
{
comboBox1.Items.Add(port);
}
}
string t;
private void button2_Click(object sender, EventArgs e)
{
t = comboBox1.Text.ToString();
sErial(t);
}
SerialPort sp;
void sErial(string Port_name)
{
sp = new SerialPort(Port_name, 115200, Parity.None, 8, StopBits.One);
sp.DataReceived += new SerialDataReceivedEventHandler(DataReceivedHandler);
sp.Open();
}
private void DataReceivedHandler(object sender, SerialDataReceivedEventArgs e)
{
SerialPort sp = (SerialPort)sender;
string msg = string.Empty;
bool canCont = false;
while (!canCont)
{
msg += sp.ReadLine();
if (msg.Contains("Scan complete "))
{
canCont = true;
}
}
string[] msgArr = msg.Split('\r');
Invoke(new Action(() => listBox1.Items.Clear()));
List<string[]> list = new List<string[]>();
List<Networks> Scan = new List<Networks>();
for (int i = 0; i < msgArr.Length; i++)
{
list.Add(msgArr[i].Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries));
}
for (int i = 0; i < list.Count; i++)
{
if (i > 2)
{
if (list[i].Length > 4)
{
int numOfSplits = 0;
List<string> tempList = new List<string>();
for (int ii = 0; ii < list[i].Length; ii++)
{
if (numOfSplits < 6)
{
string[] temp1 = list[i][ii].Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
numOfSplits += temp1.Length;
for (int iii = 0; iii < temp1.Length; iii++)
{
tempList.Add(temp1[iii]);
}
}
else
{
tempList.Add(list[i][ii]);
}
}
Scan.Add(new Networks()
{
ID = Convert.ToInt32(tempList[0]),
NetworkType = tempList[1],
MAC = tempList[2],
RSSi = Convert.ToInt32(tempList[3]),
Rate = Convert.ToDouble(tempList[4]),
Channel = Convert.ToInt32(tempList[5]),
Security = tempList[6],
SSID = tempList[7],
});
}
}
}
if (msg != String.Empty)
{
Invoke(new Action(() => richTextBox1.AppendText(msg)));
}
for (int i = 0; i < Scan.Count; i++)
{
Invoke(new Action(() => listBox1.Items.Add(Scan[i].MAC)));
Invoke(new Action(() => listBox2.Items.Add(Scan[i].RSSi)));
Invoke(new Action(() => listBox3.Items.Add(Scan[i].SSID)));
msg = string.Empty;
list.Clear();
}
}
private void richTextBox1_TextChanged(object sender, EventArgs e)
{
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
}
private void richTextBox2_TextChanged(object sender, EventArgs e)
{
}
private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
}
private void Form1_Load(object sender, EventArgs e)
{
}
public SqlConnection con = new SqlConnection(@"Data Source=(LocalDB)\v11.0;AttachDbFilename=|DataDirectory|\AP_SCAN_DATA.mdf;Integrated Security=True");
private void button3_Click(object sender, EventArgs e)
{
using (SqlConnection connection = new SqlConnection(@"Data Source=(LocalDB)\v11.0;AttachDbFilename=|DataDirectory|\AP_SCAN_DATA.mdf;Integrated Security=True"))
{
using (SqlCommand command = new SqlCommand())
{
command.Connection = connection;
command.CommandType = CommandType.Text;
command.CommandText = "INSERT into LOCATIONSCAN ((Scan[i].SSID),(Scan[i].MAC), (Scan[i].RSSi)) VALUES (@SSID, @MAC, @RSSi)";
command.Parameters.AddWithValue("@SSID", listBox1);
command.Parameters.AddWithValue("@MAC", listBox2);
command.Parameters.AddWithValue("@RSSi",listBox3);
try
{
connection.Open();
int recordsAffected = command.ExecuteNonQuery();
}
catch(SqlException)
{
}
finally
{
connection.Close();
}
}
}
}
}
}
|
|
|
|
|
If I understood your question correctly, you should execute the insert statement inside the DataReceivedHandler method. Currently the user needs to push a button in order for a single insert to happen.
So remodel the logic so that the insert happens whenever you have new data ready AND you have a permission to insert (from a boolean variable). The button then again should just toggle the permission. So for this you need a single boolean variable and the button click will change it's value.
|
|
|
|
|
Sorry if i was not clear with my question .
The WIFI AP scan data is been received every 1500 millicesonds i want to push the button once to insert data into rows this could be upto 20 rows. and i want to then push the button to stop inserting data
i hope this made it a little clearer
|
|
|
|
|
Thanks for the additional explanation but again, shouldn't you use the button to toggle the saving on and off and let the data gathering insert the data whenever new data arrives?
|
|
|
|
|
|
Have the button toggle a Boolean value (i.e. On/Off), and at the end of the routine that reads the data, put a conditional call that calls the Add routine only if the Boolean value is set to on.
=========================================================
I'm an optoholic - my glass is always half full of vodka.
=========================================================
|
|
|
|
|
|
Olumide Adebayo wrote: command.CommandText = "INSERT into LOCATIONSCAN ((Scan[i].SSID),(Scan[i].MAC), (Scan[i].RSSi)) VALUES (@SSID, @MAC, @RSSi)";
That doesn't look like a valid SQL query. What are the column names in your LOCATIONSCAN table?
I would expect to see something more like:
INSERT into LOCATIONSCAN (SSID, MAC, RSSi) VALUES (@SSID, @MAC, @RSSi)
INSERT (Transact-SQL)[^]
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
thanks for the correction, i will try INSERT (Transact-SQL)
|
|
|
|
|
using UnityEngine;
using System.Collections;
namespace InaneGames {
public class HangMan : MonoBehaviour
{
public char str;
public GUISkin guiskin;
public enum State
{
IDLE,
NEXT_WORD
};
public static bool check;
public static bool FW=true;
public bool rc;
private State m_state;
public float nextWordTime = 1;
private float m_nextWordTime;
public TextAsset[] fileTexts;
public int scoreBonusPerLetter = 15;
public int scorePunishPerWrongLetter = 20;
public char mysteryLetter = '!';
private bool resetLivesOnCorrectWord = true;
public int lives;
public int maxQuestions = 8;
public string freeLetters = " ";
public AudioClip onCorrectAC;
public AudioClip onIncorrectAC;
public AudioClip onRightWordAC;
public AudioClip onLoseAC;
private string[] m_words;
private bool[] m_gotLetter;
private string m_currentWord;
private int m_wordIndex=0;
private string m_word = "";
private int m_lives;
private int m_score = 0;
public int highScore;
private HangManGUI m_hangManGUI;
public bool chooseRandomCategory = true;
public void OnGUI () {
GUI.skin = guiskin;
GUI.Label ( new Rect (0, 0, 300, 40), " High Scores:" + highScore);
}
public void Awake()
{
highScore = PlayerPrefs.GetInt ("High Score", 0);
m_lives = lives;
int r = Misc.getIntValue("CATEGORY_INDEX");
if(chooseRandomCategory)
{
r = Random.Range(0,fileTexts.Length-1);
}
TextAsset ta = fileTexts[r];
string str = ta.text.ToUpper();
m_words = str.Split('\n');
m_words = randomizeArray(m_words);
m_hangManGUI = gameObject.GetComponent<HangManGUI>();
setNextWord();
if(m_hangManGUI)
{
m_hangManGUI.init( ta.name, m_word,m_lives);
}
}
public bool checkIfWordContainsLetter(string str)
{
rc = false;
for(int i=0; i<m_currentWord.Length; i++)
{
string tmp = m_currentWord[i].ToString();
if(tmp.Equals(str))
{
m_gotLetter[i]=true;
rc=true;
}
}
return rc;
}
public void fillWord()
{
m_word = "";
for(int i=0; i<m_currentWord.Length; i++)
{
if(m_gotLetter[i])
{
m_word += m_currentWord[i];
}else{
m_word += mysteryLetter.ToString();
}
}
}
void Update()
{
if(m_score > highScore){
highScore = m_score;
PlayerPrefs.SetInt("High Score", highScore);
PlayerPrefs.Save();
}
if(m_state == State.NEXT_WORD)
{
handleNextWord();
}
}
void handleNextWord()
{
m_nextWordTime-=Time.deltaTime;
if(m_nextWordTime<0)
{
m_state = State.IDLE;
setNextWord();
if(resetLivesOnCorrectWord)
{
m_lives = lives;
}
m_hangManGUI.setLives(m_lives);
}
}
void onCorrectLetter()
{
fillWord ();
m_hangManGUI.setWord( m_word );
if(m_word.Equals(m_currentWord))
{
if(audio)
{
audio.PlayOneShot(onRightWordAC);
}
m_score += m_currentWord.Length * scoreBonusPerLetter;
m_hangManGUI.setScore (m_score);
m_nextWordTime = nextWordTime;
m_state = State.NEXT_WORD;
}else{
if(audio)
{
audio.PlayOneShot(onCorrectAC);
}
}
}
void onIncorretLetter()
{
m_lives--;
m_hangManGUI.setLives ( m_lives );
m_score -= scorePunishPerWrongLetter;
m_hangManGUI.setScore(m_score);
if (m_lives > 0) {
if (audio) {
audio.PlayOneShot (onIncorrectAC);
}
} else {
if (audio) {
audio.PlayOneShot (onLoseAC);
}
m_hangManGUI.setGameOver (false);
}
}
public void selectLetter(string str)
{
if(checkIfWordContainsLetter(str))
{
onCorrectLetter();
}else{
onIncorretLetter();
}
}
void setNextWord()
{
if(m_wordIndex+1 <= m_words.Length)
{
m_currentWord = m_words[m_wordIndex++];
m_word = "";
m_gotLetter = new bool[m_currentWord.Length];
for(int i=0; i<m_currentWord.Length; i++)
{
m_gotLetter[i]=false;
if(isFreeLetter(m_currentWord[i]))
{
m_word += m_currentWord[i].ToString();
m_gotLetter[i]=true;
}else{
m_word += mysteryLetter.ToString();
}
}
m_hangManGUI.clearButtons();
m_hangManGUI.setWord(m_word);
}else{
m_hangManGUI.setGameOver(true);
}
}
public bool isFreeLetter(char str)
{
rc = false;
for (int i=0; i<freeLetters.Length; i++) {
if (str == freeLetters [i]) {
rc = true;
}
}
return rc;
}
public bool wholeword(){
rc = true;
for (int j=0; j<freeLetters.Length; j++) {
if (str == freeLetters[j]){
rc=true;
}}
return rc;}
string[] randomizeArray(string[] arr)
{
for (int i = arr.Length - 1; i > 0; i--)
{
int r = Random.Range(0,i);
var tmp = arr[i];
arr[i] = arr[r];
arr[r] = tmp;
}
return arr;
}
}
}
|
|
|
|
|
Member 11448796 wrote: but i am facing different errors when i call it in update.. Sorry, but you need to provide both context and detail; we cannot guess what errors you receive.
|
|
|
|
|
how can i show a pop up of high scores for few seconds when high scores are achieved in c#
|
|
|
|
|
Something along the lines of
if (score > oldHighScore)
popupScore.Show(); As you have given no indication of what platform this is about as much help as we can offer. The techniques are different in ASP.NET and WPF, for instance.
|
|
|
|
|
Hi Codeproject users,
How add i category tabel to product frm combo box?
Thanks
|
|
|
|
|
It's impossible to answer your question without you supplying some context as to what you're trying to do.
Add a "category label"? To what? What kind of app are we talking about? Windows Forms? WPF? ASP.NET? MVC? What is this "product" you're talking about? I'm assuming you have a database behind this? How were the tables setup? ...? ...?
The quality of the answer you get is directly determined by the quality of the question you ask.
|
|
|
|
|
thank you.
i have visual studio 2010 with C# and relation.
(table)Client textbox:
ClientID ----->(relation table Order)ClientID
Name
Address
Housenumber
Zipcode
Phonenumber
Date
(table)Order datagridview:
OrderID
ClientID
Item
Qlt
Price
TotalePrice
Identity add -1 -2 -3 -4 -5 i want without "-" how dow i that?
thanks
|
|
|
|
|
Exact same problem. You're just assuming we can all just read your mind and see your screen.
Have a nice life.
|
|
|
|
|
|
With the complete lack of information you provided, nobody.
|
|
|
|
|
|