partial void DeleteKunde(Kunde instance);
/// <summary> /// Legt einen Outlook-Kontakt mit den Daten des übegebenen Kundenobjektes an. /// </summary> /// <param name="customer">Das Kundenobjekt, für das ein Kontakt in Outlook angelegt werden soll.</param> public static void AddOutlookContact(Kunde customer) { var app = new Microsoft.Office.Interop.Outlook.Application(); MAPIFolder contactsTargetFolder = GetCustomContactsFolder("NORKA", true); try { if (contactsTargetFolder != null) { var contact = (ContactItem)contactsTargetFolder.Items.Add(OlItemType.olContactItem); contact.Title = customer.Anrede; contact.FirstName = customer.Vorname; contact.LastName = customer.Name_Firma; contact.Email1Address = customer.Email2; contact.Email2Address = customer.Email1; contact.BusinessTelephoneNumber = customer.Telefon2; contact.BusinessFaxNumber = customer.Fax2; contact.HomeFaxNumber = customer.Fax1; contact.HomeTelephoneNumber = customer.Telefon1; contact.MailingAddressStreet = customer.Straße; contact.MailingAddressCity = customer.Ort; contact.MailingAddressCountry = customer.Land; contact.MailingAddressPostalCode = customer.PLZ; contact.Body = customer.Notiz; contact.WebPage = customer.Homepage; contact.MobileTelephoneNumber = customer.Mobil; contact.CustomerID = customer.KundeID.ToString(); contact.Save(); } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } finally { // Freigeben der COM-Objekte Marshal.ReleaseComObject(app); } }
partial void UpdateKunde(Kunde instance);
partial void InsertKunde(Kunde instance);
/// <summary> /// Initializes a new instance of the <see cref="Form_Kunde"/> class. /// Wird aufgerufen, wenn ein bestehender Kunde bearbeitet wird. /// </summary> /// <param name="p_Kunde">The p_ kunde.</param> public Form_Kunde(Kunde p_Kunde) { InitializeComponent(); tbxKundennummer.Text = p_Kunde.KundeID.ToString(); cbxAnrede.Text = p_Kunde.Anrede; tbxVorname.Text = p_Kunde.Vorname; tbxNameFirma.Text = p_Kunde.Name_Firma; tbxStrasse.Text = p_Kunde.Straße; tbxZusatz1.Text = p_Kunde.AdressZusatz1; tbxZusatz2.Text = p_Kunde.AdressZusatz2; tbxPLZL.Text = p_Kunde.PLZ; tbxLand.Text = p_Kunde.Land; tbxOrt.Text = p_Kunde.Ort; // tbxTelefon1.Text = p_Kunde.Telefon1; tbxTelefon2.Text = p_Kunde.Telefon2; // tbxFax1.Text = p_Kunde.Fax1; tbxFax2.Text = p_Kunde.Fax2; tbxMobil.Text = p_Kunde.Mobil; // tbxEmail1.Text = p_Kunde.Email1; tbxEmail2.Text = p_Kunde.Email2; tbxHomepage.Text = p_Kunde.Homepage; tbxMatchcode.Text = p_Kunde.Matchcode; switch (p_Kunde.Kategorie) { case "Kunde": cmbKunde.Checked = true; break; case "Privat": cmbPrivat.Checked = true; break; case "Verein": cmbVerein.Checked = true; break; } if (p_Kunde.Status != null) { cbxSperren.Checked = true; } tbxNotiz.Text = p_Kunde.Notiz; epNameFirma = new ErrorProvider(); epStrasse = new ErrorProvider(); epLand = new ErrorProvider(); epPLZ = new ErrorProvider(); epOrt = new ErrorProvider(); epVorname = new ErrorProvider(); //epEmail1 = new ErrorProvider(); epEmail2 = new ErrorProvider(); epNameFirma.BlinkStyle = ErrorBlinkStyle.AlwaysBlink; epStrasse.BlinkStyle = ErrorBlinkStyle.AlwaysBlink; epLand.BlinkStyle = ErrorBlinkStyle.AlwaysBlink; epPLZ.BlinkStyle = ErrorBlinkStyle.AlwaysBlink; epOrt.BlinkStyle = ErrorBlinkStyle.AlwaysBlink; epVorname.BlinkStyle = ErrorBlinkStyle.AlwaysBlink; // epEmail1.BlinkStyle = ErrorBlinkStyle.AlwaysBlink; epEmail2.BlinkStyle = ErrorBlinkStyle.AlwaysBlink; btnAenderungSp.Enabled = true; btnSpeicherSchließen.Enabled = true; plzCollection = new AutoCompleteStringCollection(); straßeCollection = new AutoCompleteStringCollection(); ortCollection = new AutoCompleteStringCollection(); fillAutoCompleteSourcePlz(); fillAutoCompleteSourceStraße(); fillAutoCompleteSourceOrt(); }
// ************************** // Events // ************************** private void btnKundeAnl_Click(object sender, EventArgs e) { int lastKundeId = 0; if (validateEingabe()) { using (DataBaseDataContext dbContext = new DataBaseDataContext()) { try { Kunde k = new Kunde { Anrede = cbxAnrede.Text == "" ? null : cbxAnrede.Text, Name_Firma = tbxNameFirma.Text == "" ? null : tbxNameFirma.Text, Straße = tbxStrasse.Text == "" ? null : tbxStrasse.Text, PLZ = tbxPLZL.Text == "" ? null : tbxPLZL.Text, Land = tbxLand.Text == "" ? null : tbxLand.Text, Ort = tbxOrt.Text == "" ? null : tbxOrt.Text, Vorname = tbxVorname.Text == "" ? null : tbxVorname.Text, AdressZusatz1 = tbxZusatz1.Text == "" ? null : tbxZusatz1.Text, AdressZusatz2 = tbxZusatz2.Text == "" ? null : tbxZusatz2.Text, Telefon1 = null,//tbxTelefon1.Text =="" ? null : tbxTelefon1.Text, Telefon2 = tbxTelefon2.Text == "" ? null : tbxTelefon2.Text, Fax1 = null,//tbxFax1.Text == "" ? null : tbxFax1.Text, Fax2 = tbxFax2.Text == "" ? null : tbxFax2.Text, Mobil = tbxMobil.Text == "" ? null : tbxMobil.Text, Email1 = null,//tbxEmail1.Text == "" ? null : tbxEmail1.Text, Email2 = tbxEmail2.Text == "" ? null : tbxEmail2.Text, Homepage = tbxHomepage.Text == "" ? null : tbxHomepage.Text, Matchcode = tbxMatchcode.Text == "" ? null : tbxMatchcode.Text, Notiz = tbxNotiz.Text == "" ? null : tbxNotiz.Text, Kategorie = cmbKunde.Checked ? "Kunde" : (cmbPrivat.Checked) ? "Privat" : (cmbVerein.Checked) ? "Verein" : null, Status = cbxSperren.Checked ? "gesperrt" : null }; if (checkKundeDublette(k) == 1) { dbContext.Kunde.InsertOnSubmit(k); dbContext.SubmitChanges(); lastKundeId = k.KundeID; if (cbxOutlookKontakt.Checked) { Func.AddOutlookContact(k); } this.clearEingabefelderKunde(); IsDefault = true; try { using (var sqlconnection = new SqlConnection(Properties.Settings.Default.NorkaConnectionString)) { var command = new SqlCommand(string.Format("SELECT KundeID, Anrede, Vorname, Name_Firma, Straße, AdressZusatz1, AdressZusatz2, PLZ, Ort, Land, Telefon2, Fax2, Mobil, Email2, Homepage, Matchcode, Kategorie, Status, Notiz FROM Kunde WHERE KundeID = {0}", lastKundeId), sqlconnection); var adapter = new SqlDataAdapter(command); var table = new DataTable(); Func.FUebersicht.slKunde.Text = string.Format("{0} Datensätze gefunden.", adapter.Fill(table)); Func.FUebersicht.dgrKunden.Columns.Clear(); Func.FUebersicht.dgrKunden.Columns.Add(new DataGridViewCheckBoxColumn() { HeaderText = "Markieren" }); Func.FUebersicht.dgrKunden.DataSource = table; } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } //Func.FUebersicht.tsItemAkualisieren.PerformClick(); } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } } } }
private int checkKundeDublette(Kunde kunde) { int result = 0; try { using (var sqlconnection = new SqlConnection(Properties.Settings.Default.NorkaConnectionString)) { var command = new SqlCommand(string.Format("SELECT KundeID, Anrede, Vorname, Name_Firma, Straße, AdressZusatz1, AdressZusatz2, PLZ, Ort, Land FROM Kunde WHERE plz = \'{0}\' and ort = \'{1}\' and straße = \'{2}\'", kunde.PLZ, kunde.Ort, kunde.Straße), sqlconnection); var adapter = new SqlDataAdapter(command); var table = new DataTable(); if (adapter.Fill(table) > 0) { Func.FKundeDubletten = new Form_Kunde_Dubletten(); Func.FKundeDubletten.dgrKundeDubletten.DataSource = table; if (Func.FKundeDubletten.ShowDialog() == DialogResult.Yes) { result = 1; } } else { result = 1; } //Func.FKundeDubletten.dgrKundeDubletten.DataSource = table; } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } return result; //Func.FUebersicht.tsItemAkualisieren.PerformClick(); }