/// <summary> /// ثبت اطلاعات /// </summary> private void Register() { int ID = Convert.ToInt32(MakeID()); try { Tankhah T = new Tankhah() { TankhahID = ID, TankhahName = Txt_FName.Text.Trim(), CreditCurrent = 0 }; db.Tankhahs.Add(T); foreach (var item in listBox_Tels.Items) { PhoneBook PB = new PhoneBook(); PB.PNumber = item.ToString(); PB.TankhahID = ID; db.PhoneBooks.Add(PB); } db.SaveChanges(); utility.Show_Message("اطلاعات این تنخواه با موفقیت ثبت شد", "ثبت"); GetData(); ShowData(); Clear(); } catch (DbUpdateException ex) { MessageBox.Show(SqlServerErrorManagment.ShowError(ex, "تنخواه"), "خطا", MessageBoxButtons.OK, MessageBoxIcon.Error); } catch (Exception ex) { MessageBox.Show(ex.Message, "خطا", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void RegisterTel(int _NewID) { try { if (listBox_Tels.Items.Count != 0) { String s; foreach (Object selecteditem in listBox_Tels.Items) { s = selecteditem as String; PhoneBook t = new PhoneBook() { ContractorID = _NewID, PNumber = s, }; db.PhoneBooks.Add(t); } db.SaveChanges(); } } catch (DbUpdateException ex) { MessageBox.Show(SqlServerErrorManagment.ShowError(ex, "پیمانکار"), "خطا", MessageBoxButtons.OK, MessageBoxIcon.Error); } catch (Exception ex) { MessageBox.Show(ex.Message, "خطا", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void Edit() { try { int ID = Convert.ToInt32(GridTankhah.Rows[Row].Cells[0].Value); Tankhah T = ListTankhah.Single(p => p.TankhahID == ID); T.TankhahName = Txt_FName.Text.Trim(); foreach (var item in T.PhoneBooks.ToList()) { T.PhoneBooks.Remove(item); } String s; foreach (Object selecteditem in listBox_Tels.Items) { s = selecteditem as String; PhoneBook t = new PhoneBook() { TankhahID = T.TankhahID, PNumber = s, }; db.PhoneBooks.Add(t); } db.SaveChanges(); List<PhoneBook> ListT = db.PhoneBooks.ToList<PhoneBook>(); foreach (var item in ListT) { if (item.TankhahID == null && item.ContractorID == null) db.PhoneBooks.Remove(item); } db.SaveChanges(); Btn_Register.Enabled = true; Btn_Edit.Enabled = false; utility.Show_Message("اطلاعات این تنخواه با موفقیت ویرایش شد", "ویرایش"); GetData(); ShowData(); Clear(); } catch (DbUpdateException ex) { MessageBox.Show(SqlServerErrorManagment.ShowError(ex, "تنخواه"), "خطا", MessageBoxButtons.OK, MessageBoxIcon.Error); } catch (Exception ex) { MessageBox.Show(ex.Message, "خطا", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void Edit() { try { Contractor C = ListContractor.Single(p => p.ContractorID == Convert.ToInt32(GridContractor.Rows[Row].Cells["ContractorID"].Value)); C.CName = Txt_FName.Text.Trim(); foreach (Skill item in C.Skills.ToList()) { C.Skills.Remove(item); } foreach (string item in listBox_Skill.Items) { Skill S = (from V in db.Skills where V.SkillName == item select V).FirstOrDefault(); C.Skills.Add(S); } foreach (var item in C.PhoneBooks.ToList()) { C.PhoneBooks.Remove(item); } String s; foreach (Object selecteditem in listBox_Tels.Items) { s = selecteditem as String; PhoneBook t = new PhoneBook() { ContractorID = C.ContractorID, PNumber = s, }; db.PhoneBooks.Add(t); } db.SaveChanges(); List<PhoneBook> ListT = db.PhoneBooks.ToList<PhoneBook>(); foreach (var item in ListT) { if (item.TankhahID == null && item.ContractorID == null) db.PhoneBooks.Remove(item); } db.SaveChanges(); utility.Show_Message("اطلاعات این پیمانکار با موفقیت ویرایش شد", "ویرایش"); GetData(); ShowDatainGrid(); Clear(); Btn_Edit.Enabled = false; } catch (DbUpdateException ex) { MessageBox.Show(SqlServerErrorManagment.ShowError(ex, "حرفه"), "خطا", MessageBoxButtons.OK, MessageBoxIcon.Error); } catch (Exception ex) { MessageBox.Show(ex.Message, "خطا", MessageBoxButtons.OK, MessageBoxIcon.Error); } }