-2
我創建了一個名爲DictionarySample的類來表示此類中的過程是應該複製幾個類似的Dicitionary功能我需要搜索爲特定的用戶生成的輸入創建的對象數組,並返回包含輸入的相同元素的內容之一
public class DictionarySample
{
public int idNumb {get; set;}
public string fn { get; set; }
public string ln { get; set; }
public string adr { get; set; }
public string bday { get; set; }
public int num { get; set; }
}
通過我已經在表單類中啓動的數組。
namespace Project
{
public partial class Form1 : Form
{
public int lastElementIndex = 0;
DictionarySample[] database = new DictionarySample[1000];
PriorityQueueSample[] line = new PriorityQueueSample[1000];
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
public void buttonApply_Click(object sender, EventArgs e)
{
bool digitCharactersInfirst = textBoxFirstName.Text.Any(char.IsDigit);
bool digitCharactersInlast = textBoxLastName.Text.Any(char.IsDigit);
if (String.IsNullOrEmpty(textBoxIDNumber.Text))
{
MessageBox.Show("Enter an ID Number.", "Invalid Input", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
}
else if (int.Parse(textBoxIDNumber.Text) < 100000 || int.Parse(textBoxIDNumber.Text) > 999999)
{
MessageBox.Show("Invalid ID Number.", "Invalid Input", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
}
else if (String.IsNullOrEmpty(textBoxFirstName.Text))
{
MessageBox.Show("Enter First Name.", "Invalid Input", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
}
else if (digitCharactersInfirst == true)
{
MessageBox.Show("First Name can't contain digits. Please re-enter Given Name.", "Invalid Input", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
textBoxFirstName.Text = String.Empty;
}
else if (String.IsNullOrEmpty(textBoxLastName.Text))
{
MessageBox.Show("Enter Last Name.", "Invalid Input", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
}
else if (digitCharactersInlast == true)
{
MessageBox.Show("Last Name can't contain digits. Please re-enter Surname.", "Invalid Input", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
textBoxLastName.Text = String.Empty;
}
else if (String.IsNullOrEmpty(textBoxAdr.Text))
{
MessageBox.Show("Enter Address.", "Invalid Input", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
}
else if (String.IsNullOrEmpty(textBoxBirthday.Text))
{
MessageBox.Show("Enter Date of Birth.", "Invalid Input", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
}
else
{
string c = "Proceed with the following Account Information? \n" + textBoxFirstName.Text + " " + textBoxLastName.Text + "," + textBoxIDNumber.Text + "\nAddress: " + textBoxAdr.Text + "\nBirthday: " + textBoxBirthday.Text;
DialogResult dialogResult = MessageBox.Show(c, "Verify information", MessageBoxButtons.YesNo);
if (dialogResult == DialogResult.Yes)
{
int a = int.Parse(textBoxIDNumber.Text);
lastElementIndex++;
DictionarySample d = new DictionarySample();
d.idNumb = a;
d.fn = textBoxFirstName.Text;
d.ln = textBoxLastName.Text;
d.adr = textBoxAdr.Text;
d.bday = textBoxBirthday.Text;
d.num = lastElementIndex;
database[lastElementIndex] = d;
textBoxIDNumber.Text = String.Empty;
textBoxFirstName.Text = String.Empty;
textBoxLastName.Text = String.Empty;
textBoxAdr.Text = String.Empty;
textBoxBirthday.Text = String.Empty;
string prio = "You may now Line-Up.\nYour priority number is:\t" + lastElementIndex;
MessageBox.Show(prio, "Take Note", MessageBoxButtons.OK);
}
else if (dialogResult == DialogResult.No)
{
}
}
程序是這樣的:它要求用戶爲IDNumber中,姓名,地址和生日,然後在內部根據其應用的順序,對生成優先數,其在的「應用」點擊按鈕將用戶信息存儲在我的數組名爲database中。
*在http://tinypic.com/r/vfgkyh/8
退房形式的屏幕截圖的用戶已申請後,他便不得不投入第二面板,在陣容點擊按鈕必須尋找自己的ID號碼數據庫中的ID號並返回相應的優先級號,然後將它們插入具有優先級隊列功能的另一個陣列中。
我這個陣容點擊按鈕當前的代碼去如下
private void buttonLineUp_Click(object sender, EventArgs e)
{
int temp = int.Parse(textBoxIDLINE.Text);
if (String.IsNullOrEmpty(textBoxIDLINE.Text))
{
MessageBox.Show("Enter an ID Number.", "Invalid Input", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
}
else if (int.Parse(textBoxIDLINE.Text) < 100000 || int.Parse(textBoxIDLINE.Text) > 999999)
{
MessageBox.Show("Invalid ID Number.", "Invalid Input", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
}
else
{
for (int looper = 0; looper < 500; looper++)
{
//if (d.idNumb.database[looper] == int.Parse(textBoxIDNumber.Text))
//{
//}
//int idnb = 0;
//int priorityk = 0;
foreach (DictionarySample d in database)
{
if (d.idNumb == int.Parse(textBoxIDNumber.Text))
{
PriorityQueueSample lin = new PriorityQueueSample();
lin.idNumber = d.idNumb;
lin.pnumb = d.num;
labeldisplay.Text = d.idNumb + "," + d.num;
}
}
}
}
我還沒有開始將數據輸入到時Queue陣列,因爲我無法從數據庫陣列訪問數據。請幫忙。
你的問題是什麼? – Blorgbeard 2015-03-18 20:52:15
@Blorgbeard嗨!如何訪問數據庫並搜索用戶輸入的d.idNumb元素,然後返回相應的d.num? – Superpoch8 2015-03-18 20:55:51
刪除所有裝飾並用尖頭的代碼問你問題。你的問題之一是,一切都是一團糟的代碼,沒有任何問題的分離。 – 2015-03-18 21:09:46