protected void grdParcel_RowUpdating(object sender, GridViewUpdateEventArgs e) { //find objects //Parcel parcel = DataSource[e.RowIndex]; var accountManager = new AccountManager(this); var txtEffectedDate = (grdParcel.Rows[e.RowIndex].FindControl("txtEffectedDate") as Date); var txtDueDate = (grdParcel.Rows[e.RowIndex].FindControl("txtGrdDueDate") as Date); var ucCurrFieldEffectedAmount = (grdParcel.Rows[e.RowIndex].FindControl("txtEffectedAmount") as CurrencyField); var txtIdentificationNumber = (grdParcel.Rows[e.RowIndex].FindControl("txtIdentificationNumber") as TextBox); var ddlCboAccountName = (grdParcel.Rows[e.RowIndex].FindControl("cboAccountName") as DropDownList); var ddlcboPaymentMethod = (grdParcel.Rows[e.RowIndex].FindControl("cboPaymentMethod") as DropDownList); var lblAmount = (grdParcel.Rows[e.RowIndex].FindControl("lblAmount") as Label); if (DataSource[e.RowIndex].ParcelId != 0) { // Update Mode, there is an object attached DataSource[e.RowIndex].Account = null; DataSource[e.RowIndex].PaymentMethod = null; DataSource[e.RowIndex].FinancierOperation = null; if (!String.IsNullOrEmpty(ddlCboAccountName.SelectedValue)) DataSource[e.RowIndex].Account = accountManager.GetAccount(Convert.ToInt32(ddlCboAccountName.SelectedValue), Page.Company.CompanyId); if (!String.IsNullOrEmpty(ddlcboPaymentMethod.SelectedValue)) { DataSource[e.RowIndex].PaymentMethod = accountManager.GetPaymentMethod(Convert.ToInt32(ddlcboPaymentMethod.SelectedValue)); if (Convert.ToInt32(ddlcboPaymentMethod.SelectedValue) == PaymentMethod.Boleto) { var financierOperation = accountManager.GetFinancierOperationBoleto(Page.Company.CompanyId); if (financierOperation != null) DataSource[e.RowIndex].FinancierOperation = financierOperation; } } } else { // Insert mode, so there is no object Attached DataSource[e.RowIndex].AccountId = null; DataSource[e.RowIndex].PaymentMethodId = null; DataSource[e.RowIndex].IdentificationNumber = String.Empty; if (!String.IsNullOrEmpty(ddlCboAccountName.SelectedValue)) DataSource[e.RowIndex].AccountId = accountManager.GetAccount(Convert.ToInt32(ddlCboAccountName.SelectedValue), Page.Company.CompanyId).AccountId; if (!String.IsNullOrEmpty(ddlcboPaymentMethod.SelectedValue)) { DataSource[e.RowIndex].PaymentMethodId = Convert.ToInt32(ddlcboPaymentMethod.SelectedValue); if (Convert.ToInt32(ddlcboPaymentMethod.SelectedValue) == PaymentMethod.Boleto) { var financierOperation = accountManager.GetFinancierOperationBoleto(Page.Company.CompanyId); if (financierOperation != null) DataSource[e.RowIndex].FinancierOperationId = financierOperation.FinancierOperationId; } } } if (!String.IsNullOrEmpty(txtIdentificationNumber.Text)) DataSource[e.RowIndex].IdentificationNumber = txtIdentificationNumber.Text; DataSource[e.RowIndex].EffectedAmount = Convert.ToDecimal(ucCurrFieldEffectedAmount.CurrencyValue); DataSource[e.RowIndex].Amount = Convert.ToDecimal(lblAmount.Text.Remove(0, 3)); DataSource[e.RowIndex].DueDate = txtDueDate.DateTime.Value; DataSource[e.RowIndex].EffectedDate = txtEffectedDate.DateTime; if (txtEffectedDate.DateTime.HasValue) { if (txtEffectedDate.DateTime.Value < DateTime.MinValue.Sql2005MinValue() || txtEffectedDate.DateTime.Value > DateTime.Now) { Page.ShowError(Exception.DateBiggerThanCurrentDate); e.Cancel = true; return; } } if (txtEffectedDate.DateTime.HasValue && ucCurrFieldEffectedAmount.CurrencyValue == 0) { Page.ShowError("Parcela não pode ser quitada com valor 0(zero)!"); e.Cancel = true; return; } BindGrid(-1); }
public void GerarArquivoRemessa(Int32 companyId, Int32 accountId, DateTime beginDate, DateTime endDate, Stream stream) { var accountManager = new AccountManager(this); var companyManager = new CompanyManager(this); Company company = companyManager.GetCompany(companyId); FinancierOperation operation = accountManager.GetFinancierOperationBoleto(companyId); Boletos boletos = ConvertInvoiceParcelsInBoleto(companyId, accountId, beginDate, endDate); var exportFile = new ArquivoRemessa(TipoArquivo.CNAB400); var cedente = new Cedente(company.LegalEntityProfile.CNPJ, company.LegalEntityProfile.CompanyName, operation.Account.Agency, Convert.ToString(operation.Account.AgencyDigit), operation.Account.AccountNumber, Convert.ToString(operation.Account.AccountNumberDigit)); exportFile.GerarArquivoRemessa(String.Empty, new Banco(Convert.ToInt32(operation.Account.Bank.BankNumber)), cedente, boletos, stream, 1); }