/// <summary> /// Erstellt eine neu Bankverbindung. /// </summary> /// <param name="dbContext">Datenbankkontext für die Transaktion.</param> /// <param name="name">Name der Bank.</param> /// <param name="accountnumber">Kontonummer der Bankverbindung.</param> /// <param name="bankcode">Bankleitzahl der Bank.</param> /// <param name="IBANNumber">Aktuelle IBAN Nummer</param> /// <returns>Die neue Bankverbindung.</returns> public static BankAccount CreateBankAccount(DataClasses1DataContext dbContext, string name, string accountnumber, string bankcode, string IBANNumber, string BICNumber) { if (string.IsNullOrEmpty(name)) { ////throw new Exception("Der Name der Bank darf nicht leer sein."); } var bankaccount = new BankAccount() { BankName = name, BankCode = bankcode, Accountnumber = accountnumber, IBAN = IBANNumber, BIC = BICNumber }; dbContext.BankAccount.InsertOnSubmit(bankaccount); dbContext.SubmitChanges(); dbContext.WriteLogItem("Bankverbindung angelegt.", LogTypes.INSERT, bankaccount.Id, "BankAccount"); return bankaccount; }
/// <summary> /// Erstelle einen neuen Fahrzeughalter /// </summary> /// <param name="name">Nachname</param> /// <param name="firstName">Vorname</param> /// <param name="bankAccountId">ID der Bankverbindung</param> /// <param name="contactId">ID des Kontaktdatensatzes</param> /// <param name="adressId">ID der Adresse</param> /// <param name="dbContext">DB Kontext</param> /// <returns>CarOwner</returns> public static CarOwner CreateCarOwner(string name, string firstName, BankAccount bankAccount, Contact contact, Adress adress, DataClasses1DataContext dbContext) { if (string.IsNullOrEmpty(name)) { ////throw new Exception("Der Name des Halters darf nicht leer sein."); } CarOwner owner = new CarOwner() { Name = name, FirstName = firstName, BankAccount = bankAccount, Contact = contact, Adress = adress }; dbContext.CarOwner.InsertOnSubmit(owner); dbContext.SubmitChanges(); dbContext.WriteLogItem("Halter " + name + " wurde angelegt.", LogTypes.INSERT, owner.Id, "CarOwner"); return owner; }
partial void DeleteBankAccount(BankAccount instance);
partial void UpdateBankAccount(BankAccount instance);
partial void InsertBankAccount(BankAccount instance);
protected void AddCustomerToDatabase() { using (TransactionScope ts = new TransactionScope()) { DataClasses1DataContext dbContext = new DataClasses1DataContext(((Guid)Session["CurrentUserId"])); try { BankAccount bankAccount = null; LargeCustomer lg = null; SmallCustomer sm = null; Adress newAdress = null; Adress newInvoiceAdress = null; Adress newSendAdress = null; if (rbtLargeCustomer.Checked == true) { var checkThisCustomer = dbContext.Customer.FirstOrDefault(q => q.CustomerNumber == txbLargeCustomerNumber.Text); if (checkThisCustomer == null) { decimal vat = 0; txbLargeCustomerVat.Text = txbLargeCustomerVat.Text.Trim(); txbLargeCustomerVat.Text = txbLargeCustomerVat.Text.Replace('.', ','); try { vat = decimal.Parse(txbLargeCustomerVat.Text); } catch { throw new Exception("Die MwSt muss eine Dezimalzahl sein"); } int zz = 0; txbLargeCustomerZahlungsziel.Text = txbLargeCustomerZahlungsziel.Text.Trim(); if (txbLargeCustomerZahlungsziel.Text != string.Empty) { try { zz = int.Parse(txbLargeCustomerZahlungsziel.SelectedValue); } catch { throw new Exception("Das Zahlungsziel ausgewählt sein"); } } Guid? myPersonId = null; if (txbLargeCustomerFirstname.Text != string.Empty || txbLargeCustomerName.Text != string.Empty || txbLargeCustomerZusatz.Text != string.Empty) { myPersonId = Person.CreatePerson(dbContext, txbLargeCustomerFirstname.Text, txbLargeCustomerName.Text, txbLargeCustomerSalutation.Text, txbLargeCustomerZusatz.Text).Id; } var newCustomer = LargeCustomer.CreateLargeCustomer(dbContext, txbCustomerName.Text, txbStreet.Text, txbStreetNumber.Text, ZipCode.Text, cmbCity.Text, cmbCountry.Text, PhoneNumer.Text, txbFax.Text, txbMobil.Text, txbEmailAdress.Text, vat, chbSendToMainLocation.Checked, chbSendViaMail.Checked, zz, txbLargeCustomerNumber.Text, txbLargeCustomerMatchcode.Text, txbLargeCustomerDebitorenNummer.Text, myPersonId, new Guid(rcbInvoiceType.SelectedValue), txbEvbNumber.Text); if (chbInvoiceSameAsAdress.Checked == true && chbSameAsDispatch.Checked == true) { newCustomer.Customer.InvoiceAdressId = newCustomer.Customer.AdressId; newCustomer.Customer.InvoiceDispatchAdressId = newCustomer.Customer.AdressId; } if (chbInvoiceSameAsAdress.Checked == false && chbSameAsDispatch.Checked == true) { newAdress = Adress.CreateAdress(txbLargeCustomerIAStreet.Text, txbLargeCustomerIAStreetNr.Text, cmbLargeCustomerIAZipCode.Text, cmbIAOrt.Text, cmbCountryIA.Text, dbContext); newCustomer.Customer.InvoiceAdressId = newAdress.Id; newCustomer.Customer.InvoiceDispatchAdressId = newCustomer.Customer.AdressId; } if (chbInvoiceSameAsAdress.Checked == true && chbSameAsDispatch.Checked == false) { newAdress = Adress.CreateAdress(txbLargeCustomerSendStreet.Text, txbLargeCustomerSendStreetNr.Text, cmbLargeCustomerSendZipCode.Text, cmbSendOrt.Text, cmbCountrySend.Text, dbContext); newCustomer.Customer.InvoiceAdressId = newCustomer.Customer.AdressId; newCustomer.Customer.InvoiceDispatchAdressId = newAdress.Id; } if (chbInvoiceSameAsAdress.Checked == false && chbSameAsDispatch.Checked == false) { newInvoiceAdress = Adress.CreateAdress(txbLargeCustomerIAStreet.Text, txbLargeCustomerIAStreetNr.Text, cmbLargeCustomerIAZipCode.Text, cmbIAOrt.Text, cmbCountryIA.Text, dbContext); newSendAdress = Adress.CreateAdress(txbLargeCustomerSendStreet.Text, txbLargeCustomerSendStreetNr.Text, cmbLargeCustomerSendZipCode.Text, cmbSendOrt.Text, cmbCountrySend.Text, dbContext); newCustomer.Customer.InvoiceAdressId = newInvoiceAdress.Id; newCustomer.Customer.InvoiceDispatchAdressId = newSendAdress.Id; } if (LCustomerAuftragNow.Checked == true) { newCustomer.OrderFinishedNoteSendType = 1; } if (LCustomerAuftragHourly.Checked == true) { newCustomer.OrderFinishedNoteSendType = 2; } if (LCustomerAuftragDayly.Checked == true) { newCustomer.OrderFinishedNoteSendType = 3; } else { newCustomer.OrderFinishedNoteSendType = 0; } if (chbLCustomerAuftragKunde.Checked == true) { newCustomer.SendOrderFinishedNoteToCustomer = true; } if (chbLCustomerAuftragStandort.Checked == true) { newCustomer.SendOrderFinishedNoteToLocation = true; } if (chbLCustomerLiefescheinCustomer.Checked == true) { newCustomer.SendPackingListToCustomer = true; } if (chbLCustomerLieferscheinStandort.Checked == true) { newCustomer.SendPackingListToLocation = true; } var costCenter = newCustomer.AddNewCostCenter(CostCenterName.Text, txbLargeCustomerCostCenterNumber.Text, dbContext); bankAccount = new BankAccount(); if (txbBankName.Text != string.Empty || txbLargeCustomerIBAN.Text != string.Empty) { bankAccount = BankAccount.CreateBankAccount(dbContext, txbBankName.Text, txbAccount.Text, txbBankCode.Text, txbLargeCustomerIBAN.Text, txbLargeCustomerBIC.Text); costCenter.BankAccountId = bankAccount.Id; } newCustomer.Customer.InternalId = Guid.NewGuid(); lg = newCustomer; dbContext.SubmitChanges(); ts.Complete(); resultMessage.BackColor = System.Drawing.Color.Green; resultMessage.Text = "Der Kunde wurde erfolgreich angelegt"; } else { resultMessage.BackColor = System.Drawing.Color.Red; resultMessage.Text = "Die Kundennummer existiert bereits"; } } if (rbtSmallCustomer.Checked == true) { var checkThisCustomer = dbContext.Customer.SingleOrDefault(q => q.CustomerNumber == txbSmallCustomerNumber.Text); if (checkThisCustomer == null) { decimal vat = 0; txbSmallCustomerVat.Text = txbSmallCustomerVat.Text.Trim(); txbSmallCustomerVat.Text = txbSmallCustomerVat.Text.Replace('.', ','); try { if (txbSmallCustomerVat.Text != string.Empty) vat = decimal.Parse(txbSmallCustomerVat.Text); } catch { throw new Exception("Die MwSt muss eine Dezimalzahl sein"); } int zz = 0; txbSmallCustomerZahlungsziel.Text = txbSmallCustomerZahlungsziel.Text.Trim(); if (txbSmallCustomerZahlungsziel.Text != string.Empty) { try { zz = int.Parse(txbSmallCustomerZahlungsziel.SelectedValue); } catch { throw new Exception("Das Zahlungsziel muss eine Gleitkommazahl sein"); } } var newSmallCustomer = SmallCustomer.CreateSmallCustomer(txbSmallCustomerVorname.Text, txbSmallCustomerNachname.Text, txbSmallCustomerTitle.Text, cmbSmallCustomerGender.SelectedValue, txbSmallCustomerStreet.Text, txbSmallCustomerNr.Text, txbSmallCustomerZipCode.Text, cmbSmallCustomerCity.Text, cmbSmallCustomerCountry.Text, txbSmallCustomerPhone.Text, txbSmallCustomerFax.Text, txbSmallCustomerMobil.Text, txbSmallCustomerEmail.Text, vat, zz, txbSmallCustomerNumber.Text, dbContext); newSmallCustomer.Customer.LogDBContext = dbContext; if (chbSmallCustomerRechnungsaderesse.Checked == true && chbSmallCustomerVersandadresse.Checked == true) { newSmallCustomer.Customer.InvoiceAdressId = newSmallCustomer.Customer.AdressId; newSmallCustomer.Customer.InvoiceDispatchAdressId = newSmallCustomer.Customer.AdressId; } if (chbSmallCustomerRechnungsaderesse.Checked == false && chbSmallCustomerVersandadresse.Checked == true) { newAdress = Adress.CreateAdress(txbsmallCustomerInvoiceStreet.Text, txbsmallCustomerInvoiceStreetNr.Text, cmbInvoiceZC.Text, cmbSmallCustomerInvoiceCity.Text, cmbSmallCustomerInvoiceCountry.Text, dbContext); newSmallCustomer.Customer.InvoiceAdressId = newAdress.Id; newSmallCustomer.Customer.InvoiceDispatchAdressId = newSmallCustomer.Customer.AdressId; } if (chbSmallCustomerRechnungsaderesse.Checked == true && chbSmallCustomerVersandadresse.Checked == false) { newAdress = Adress.CreateAdress(txbSmallCustomerSendStreet.Text, txbSmallCustomerSendStreetNr.Text, cmbSmallCustomerSendZip.Text, cmbSmallCustomerSendCity.Text, cmbSmallCustomerSendCountry.Text, dbContext); newSmallCustomer.Customer.InvoiceAdressId = newSmallCustomer.Customer.AdressId; newSmallCustomer.Customer.InvoiceDispatchAdressId = newAdress.Id; } if (chbSmallCustomerRechnungsaderesse.Checked == false && chbSmallCustomerVersandadresse.Checked == false) { newInvoiceAdress = Adress.CreateAdress(txbsmallCustomerInvoiceStreet.Text, txbsmallCustomerInvoiceStreetNr.Text, cmbInvoiceZC.Text, cmbSmallCustomerInvoiceCity.Text, cmbSmallCustomerInvoiceCountry.Text, dbContext); newSendAdress = Adress.CreateAdress(txbSmallCustomerSendStreet.Text, txbSmallCustomerSendStreetNr.Text, cmbSmallCustomerSendZip.Text, cmbSmallCustomerSendCity.Text, cmbSmallCustomerSendCountry.Text, dbContext); newSmallCustomer.Customer.InvoiceAdressId = newInvoiceAdress.Id; newSmallCustomer.Customer.InvoiceDispatchAdressId = newSendAdress.Id; } if (txbSmallCustomerKreditinstitut.Text != string.Empty || txbSmallCustomerAccountNumber.Text != string.Empty || txbSmallCustomerBankCode.Text != string.Empty || txbSmallCustomerIBANinfo.Text != string.Empty) { newSmallCustomer.LogDBContext = dbContext; var addBankAccount = BankAccount.CreateBankAccount(dbContext, txbSmallCustomerKreditinstitut.Text, txbSmallCustomerAccountNumber.Text, txbSmallCustomerBankCode.Text, txbSmallCustomerIBANinfo.Text, txbSmallCustomerBIC.Text); newSmallCustomer.BankAccountId = addBankAccount.Id; } sm = newSmallCustomer; dbContext.SubmitChanges(); ts.Complete(); resultMessage.BackColor = System.Drawing.Color.Green; resultMessage.Text = "Der Kunde wurde erfolgreich angelegt"; } else { resultMessage.BackColor = System.Drawing.Color.Red; resultMessage.Text = "Die Kundennummer existiert bereits"; } } } catch (Exception ex) { resultMessage.BackColor = System.Drawing.Color.Red; resultMessage.Text = "Fehler: "+ex.Message; dbContext.WriteLogItem("Add/Edit Customer Error: " + ex.Message, LogTypes.ERROR, "Customer"); } } }