private void button2_Click(object sender, EventArgs e) { var customerId = (from c in dc.Customers // get the record from the db where c.Id == Program.custId select c).FirstOrDefault(); if (customerId != null) { contact cont = new contact(); //create new customer contact record of family type cont.first_name = strFName.Text; cont.last_name = strLName.Text; dc.contacts.InsertOnSubmit(cont); dc.SubmitChanges(); phone ph = new phone(); //create new phone record if (phoneNumM.Text != "" && areaCodeM.Text != "") { ph.phone_type = "נייד"; ph.area_code = areaCodeM.Text; ph.phone_num = phoneNumM.Text; dc.phones.InsertOnSubmit(ph); // dc.SubmitChanges(); } dc.SubmitChanges(); if (ph != null) { contact_phone cph = new contact_phone(); cph.contact_id = cont.ID; cph.phone_id = ph.ID; cph.status = "פעיל"; cph.type = ph.phone_type; dc.contact_phones.InsertOnSubmit(cph); } dc.SubmitChanges(); wh_address adr = new wh_address(); // new address record adr.city_name = cityName.Text; if (streetName.Text != "") { adr.street_name = streetName.Text; } if (houseNum.Text != "") { adr.house_num = int.Parse(houseNum.Text); } if (apartNum.Text != "") { adr.appartment_num = int.Parse(apartNum.Text); } if (postCode.Text != "") { adr.zip_code = postCode.Text; } dc.wh_addresses.InsertOnSubmit(adr); dc.SubmitChanges(); contact_address contaddr = new contact_address();//new contact address record contaddr.contact_id = cont.ID; contaddr.address_id = adr.ID; contaddr.status = "פעיל"; dc.contact_addresses.InsertOnSubmit(contaddr); dc.SubmitChanges(); customer_contact custcont = new customer_contact(); //add new contact to customer custcont.customer_id = Program.custId; custcont.contact_id = cont.ID; custcont.type = "מטפל ראשי"; custcont.status = "פעיל"; dc.customer_contacts.InsertOnSubmit(custcont); dc.SubmitChanges(); } }
private void saveButton_Click(object sender, EventArgs e) { if (strId.Text == "" || strFName.Text == "" || strLName.Text == "" || dateofBirth.Value == DateTime.Now || (!checkMale.Checked && !checkFemale.Checked) || ((phoneNumH.Text == "" || areaCodeH.Text == "") && (phoneNumM.Text == "" || areaCodeM.Text == ""))) { MessageBox.Show("לא מולאו כל שדות החובה"); if (strId.Text == "") { strId.BackColor = Color.Red; // color red if id is null } else { strId.BackColor = Color.White; } if (strFName.Text == "") { strFName.BackColor = Color.Red;// color red if first name is null } else { strFName.BackColor = Color.White; } if (strLName.Text == "") { strLName.BackColor = Color.Red;// color red if last name is null } else { strLName.BackColor = Color.White; } if (dateofBirth.Value == DateTime.Now) { dateofBirth.BackColor = Color.Red; } else { dateofBirth.BackColor = Color.White; } if (!checkMale.Checked && !checkFemale.Checked) { checkMale.BackColor = Color.Red; checkFemale.BackColor = Color.Red; } else { checkMale.BackColor = Color.White; checkFemale.BackColor = Color.White; } } else { var ans = (from cust in dc.Customers where cust.Id == strId.Text select cust).FirstOrDefault(); if (ans != null) { MessageBox.Show("מקבל שירות כבר קיים במערכת"); } else { Customer cust = new Customer(); //create new customer record cust.Id = strId.Text; cust.first_name = strFName.Text; cust.last_name = strLName.Text; cust.birthdate = dateofBirth.Value; if (checkMale.Checked) { cust.gender = "זכר"; } else { cust.gender = "נקבה"; } cust.marital_status = maritalStatus.Text; cust.comments = strComments.Text; cust.email_address = emailAdd.Text; cust.status_cd = "פעיל"; dc.Customers.InsertOnSubmit(cust); // dc.SubmitChanges(); phone ph = new phone(); //create new phone record if (phoneNumH.Text != "" && areaCodeH.Text != "") { ph.phone_type = "בית"; ph.area_code = areaCodeH.Text; ph.phone_num = phoneNumH.Text; dc.phones.InsertOnSubmit(ph); // dc.SubmitChanges(); } phone ph1 = new phone(); //create new phone record if (phoneNumM.Text != "" && areaCodeM.Text != "") { ph1.phone_type = "נייד"; ph1.area_code = areaCodeM.Text; ph1.phone_num = phoneNumM.Text; dc.phones.InsertOnSubmit(ph1); // dc.SubmitChanges(); } dc.SubmitChanges(); if (ph != null) { customer_phone cph = new customer_phone(); cph.customer_id = strId.Text; cph.phone_id = ph.ID; cph.status = "פעיל"; cph.type = ph.phone_type; dc.customer_phones.InsertOnSubmit(cph); } if (ph1 != null) { customer_phone cph1 = new customer_phone(); cph1.customer_id = strId.Text; cph1.phone_id = ph1.ID; cph1.status = "פעיל"; cph1.type = ph1.phone_type; dc.customer_phones.InsertOnSubmit(cph1); } dc.SubmitChanges(); wh_address adr = new wh_address(); // new address record adr.city_name = cityName.Text; if (streetName.Text != "") { adr.street_name = streetName.Text; } if (houseNum.Text != "") { adr.house_num = int.Parse(houseNum.Text); } if (apartNum.Text != "") { adr.appartment_num = int.Parse(apartNum.Text); } if (neighbName.Text != "") { adr.neighborhood = neighbName.Text; } if (postCode.Text != "") { adr.zip_code = postCode.Text; } dc.wh_addresses.InsertOnSubmit(adr); dc.SubmitChanges(); customer_address custaddr = new customer_address();//new customer address record custaddr.customer_id = strId.Text; custaddr.address_id = adr.ID; custaddr.status = "פעיל"; dc.customer_addresses.InsertOnSubmit(custaddr); dc.SubmitChanges(); nextButton.Enabled = true; } } }