/// <summary> /// Save the Remisier /// </summary> /// <param name="details">The details of the remisier to be saved</param> public static bool SaveRemisier(RemisierDetailsView details) { bool success = false; IDalSession session = NHSessionFactory.CreateSession(); IRemisier remisier = null; bool isNewRemisier = false; if (details.RemisierKey != int.MinValue) remisier = (IRemisier)RemisierMapper.GetRemisier(session, details.RemisierKey); else { remisier = new Remisier(); isNewRemisier = true; } remisier.Name = details.Name; remisier.InternalRef = details.InternalRef; if (details.OfficeAddress != null && details.OfficeAddress.CountryNeedsInitialization) details.OfficeAddress.Country = CountryMapper.GetCountry(session, details.OfficeAddress.CountryID); remisier.OfficeAddress = details.OfficeAddress; if (details.PostalAddress != null && details.PostalAddress.CountryNeedsInitialization) details.PostalAddress.Country = CountryMapper.GetCountry(session, details.PostalAddress.CountryID); remisier.PostalAddress = details.PostalAddress; remisier.ContactPerson = details.ContactPerson; remisier.Telephone.Number = details.Telephone; remisier.Fax.Number = details.Fax; if (!details.IsBankEmpty) { if (remisier.BankDetails == null) remisier.BankDetails = new BankDetails(); remisier.BankDetails.BankName = details.BankName; remisier.BankDetails.AccountNumber = details.BankAccountNumber; remisier.BankDetails.BankAccountName = details.BankAccountName; remisier.BankDetails.BankAddress.City = details.BankCity; if (details.BankID != int.MinValue) remisier.BankDetails.Bank = BankMapper.GetBank(session, details.BankID); } else remisier.BankDetails = null; if (details.ParentRemisierKey.HasValue) { remisier.ParentRemisier = RemisierMapper.GetRemisier(session, details.ParentRemisierKey.Value); remisier.ParentRemisierKickBackPercentage = details.ParentRemisierKickBackPercentage; } else { remisier.ParentRemisier = null; remisier.ParentRemisierKickBackPercentage = 0M; } if (isNewRemisier) success = RemisierMapper.Insert(session, remisier); else success = RemisierMapper.Update(session, remisier); session.Close(); return success; }
protected void btnSaveRemisier_Click(object sender, EventArgs e) { try { Page.Validate(); if (Page.IsValid) { RemisierDetailsView details = new RemisierDetailsView(); if (RemisierID != 0) details.RemisierKey = RemisierID; if (mvwAssetManager.ActiveViewIndex == 1) details.CompanyID = Utility.GetKeyFromDropDownList(ddlAssetManager); details.RemisierType = (RemisierTypes)Utility.GetKeyFromDropDownList(ddlRemisierType); details.Name = tbRemisierName.Text; details.InternalRef = tbInternalRef.Text; if (mvwBank.ActiveViewIndex == 0) details.BankID = Utility.GetKeyFromDropDownList(ddlBank); else details.BankName = tbBankName.Text; details.BankAccountNumber = tbTegenrekNR.Text; details.BankAccountName = tbTegenrekTNV.Text; details.BankCity = tbBankCity.Text; details.Telephone = tbTelephone.Text; details.Fax = tbFax.Text; details.Email = tbEmail.Text; if (ddlParentRemisier.SelectedValue != int.MinValue.ToString()) details.ParentRemisierKey = Utility.GetKeyFromDropDownList(ddlParentRemisier); if (!dbParentRemisierKickBackPercentage.IsEmpty) details.ParentRemisierKickBackPercentage = dbParentRemisierKickBackPercentage.Value; details.OfficeAddress = ucAddress.MainAddress; details.PostalAddress = ucAddress.PostAddress; details.DatumOvereenkomst = tbDatumOvereenkomst.Text; details.NummerOvereenkomst = tbNummerOvereenkomst.Text; details.NummerAFM = tbNummerAFM.Text; details.NummerKasbank = tbNummerKasbank.Text; if (!string.IsNullOrEmpty(tbCPLastName.Text) || !string.IsNullOrEmpty(tbCPInitials.Text) || !string.IsNullOrEmpty(tbCPMiddleName.Text) || !string.IsNullOrEmpty(tbCPTelephone.Text) || !string.IsNullOrEmpty(tbCPEmail.Text)) { Person p = new Person(); p.LastName = tbCPLastName.Text; p.Initials = tbCPInitials.Text; p.MiddleName = tbCPMiddleName.Text; p.Telephone = new TelephoneNumber(tbCPTelephone.Text); p.Email = tbCPEmail.Text; if (rbCPGender.SelectedIndex > -1) p.Gender = (Gender)Convert.ToInt32(rbCPGender.SelectedValue); details.ContactPerson = p; } details.IsActive = (chkIsActive.Visible ? chkIsActive.Checked : true); int key; if (RemisierAdapter.SaveRemisier(details, out key)) { RemisierID = key; showRemiserDetails(); } } } catch (Exception ex) { elbErrorMessage.Text = Utility.GetCompleteExceptionMessage(ex); } }
public static RemisierDetailsView GetRemisierDetails(int remisierID) { IDalSession session = NHSessionFactory.CreateSession(); try { RemisierDetailsView remisierDetailsView = null; IRemisier remisier = (IRemisier)RemisierMapper.GetRemisier(session, remisierID); if (remisier != null) { remisierDetailsView = new RemisierDetailsView(remisier); } //else // remisierDetailsView = new AccountDetailsView(LoginMapper.GetCurrentManagmentCompany(session).BaseCurrency); return remisierDetailsView; } finally { session.Close(); } }