phoneWin
הקוד
public partial class phoneWin : Form
{
List<phoneTBL> currList;
List<contactTBL> allContacts;
public phoneWin()
{
InitializeComponent();
}
private void phoneWin_Load(object sender, EventArgs e)
{
loadContacts();
}
private void loadContacts()
{
allContacts = DBHelper.allContacts;
dgvContacts.DataSource = cbxContactsHidden.DataSource = allContacts;
}
private void cbxContactsHidden_SelectedIndexChanged(object sender, EventArgs e)
{
contactTBL selected = (contactTBL)cbxContactsHidden.SelectedItem;
if (selected != null)
{
currList = DBHelper.allPhones.Where(x => x.cID == selected.Id).ToList();
dgvPhones.DataSource = cbxPhoneHidden.DataSource = currList;
}
}
private void btnAddPhone_Click(object sender, EventArgs e)
{
contactTBL selected = (contactTBL)cbxContactsHidden.SelectedItem;
if (selected != null)
{
// need to check validation of phone number
string phoneStr = txbPhoneAdd.Text.Trim();
phoneTBL p1 = new phoneTBL();
p1.cID = selected.Id;
p1.phone = phoneStr;
DBHelper.addPhone(p1);
loadContacts();
cbxContactsHidden_SelectedIndexChanged(null, null);
txbPhoneAdd.Text = "";
}
}
}