protected void btnGuardar_Click(object sender, EventArgs e) { try { ValidaVariables(); NegocioPF.Sociedad oSociedad = new NegocioPF.Sociedad(txtID.Text, txtNombre.Text, txtRFC.Text); oSociedad.BusinessArea = txtBusArea.Text; oSociedad.ControllingArea = txtContArea.Text; oSociedad.GeneralLeyerAccount = txtGralLeyerAcc.Text; oSociedad.CostCenter = txtCostCenter.Text; oSociedad.CuentaProveedor = txtCtaProv.Text; oSociedad.ValidaDatos(Session["Accion"].ToString()); oSociedad.Guardar(((Usuario)Session["oUsuario"]).Id); NegocioPF.Sociedades oSociedades = new NegocioPF.Sociedades(); oSociedades.Cargar(); grdSociedades.DataSource = oSociedades.Datos; grdSociedades.DataBind(); MessageBox(sender, e, ((Idioma)Session["oIdioma"]).Texto("MsgSociedadGuardada")); divDetalle.Visible = false; } catch (Exception ex) { MessageBox(sender, e, ((Idioma)Session["oIdioma"]).Texto(ex.Message)); } }
protected void btnAceptarAgregar_Click(object sender, EventArgs e) { try { NegocioPF.Factura oFactura = (Factura)Session["oFactura"]; if (oFactura.Existe()) { MessageBox(sender, e, ((Idioma)Session["oIdioma"]).Texto("MsgFactYaRegistrada")); return; } oFactura.Moneda = cboMoneda.SelectedValue; //Valida si existe el Emisor en el catálogo de proveedores NegocioPF.Proveedor oProveedor = new Proveedor(); oProveedor.Cargar(txtEmisor.Text.Substring(0, txtEmisor.Text.IndexOf(" "))); if (oProveedor.Nombre == "" || oProveedor.Nombre == null) { throw new Exception("MsgEmisorInexistente"); } //Valida que el receptor corresponda a la sociedad seleccionada NegocioPF.Sociedad oSociedad = new NegocioPF.Sociedad(cboSociedades.SelectedValue); oSociedad.Cargar(); if (oSociedad.RFC != txtReceptor.Text.Substring(0, txtReceptor.Text.IndexOf(" "))) { throw new Exception("MsgErrFactNoCorrSociedad"); } //Valida que la sociedad esté activa para el proveedor bool existe = false; foreach (string sociedad in oProveedor.Sociedades) { if (sociedad == cboSociedades.SelectedValue) { existe = true; } } if (!existe) { throw new Exception("MsgSocNoActProv"); } //Valida la fecha de la factura NegocioPF.Configuracion oConfig = new NegocioPF.Configuracion(); oConfig.Cargar(); DateTime dFechaMinima = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1); dFechaMinima = dFechaMinima.AddMonths(oConfig.MesesAtras * -1); DateTime dFechaMaxima = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day); dFechaMaxima = dFechaMaxima.AddMonths(oConfig.MesesAdelante); DateTime dFecha = new DateTime(Convert.ToInt32(txtFecha.Text.Substring(0, 4)), Convert.ToInt32(txtFecha.Text.Substring(5, 2)), Convert.ToInt32(txtFecha.Text.Substring(8, 2))); if (dFecha < dFechaMinima) { throw new Exception("MsgErrFactMuyAtrasada"); } if (dFecha > dFechaMaxima) { throw new Exception("MsgErrFactFecMuyAdelantada"); } if (oProveedor.RFC != oFactura.Emisor) { throw new Exception("MsgErrPedDifProv"); } //Establece el tipo de factura oFactura.TipoFactura = "NFI"; NegocioPF.Facturas oFacturas = (NegocioPF.Facturas)Session["oFacturas"]; DataRow r = oFacturas.Datos.Tables[0].NewRow(); r["id_sociedad"] = cboSociedades.SelectedValue; r["folio"] = 0; r["UUID"] = txtUUID.Text; r["folioFact"] = txtFactura.Text; r["emisor"] = txtEmisor.Text.Substring(0, txtEmisor.Text.IndexOf(" ")); r["receptor"] = txtReceptor.Text.Substring(0, txtReceptor.Text.IndexOf(" ")); r["ordenCompra"] = ""; r["fecha"] = txtFecha.Text; r["importe"] = txtImporte.Text; r["id_moneda"] = cboMoneda.SelectedValue; r["pdf"] = Session["pdf"].ToString(); r["xml"] = Session["xml"].ToString(); oFacturas.Datos.Tables[0].Rows.Add(r); oFacturas.Relacion.Add(oFactura); Session["oFacturas"] = oFacturas; grdFacturas.DataSource = oFacturas.Datos; grdFacturas.DataBind(); oViewer.Visible = false; divDetalle.Visible = false; divFacturas.Visible = true; btnAceptar.Visible = (oFacturas.Datos.Tables[0].Rows.Count > 0); btnCancelar.Visible = (oFacturas.Datos.Tables[0].Rows.Count > 0); divImportar.Visible = true; //ScriptManager.RegisterStartupScript(this, typeof(Page), "confirm", "<script>confirmation();</script>", false); } catch (Exception ex) { if (ex.Message.Substring(0, 3) == "Msg") { MessageBox(sender, e, ((Idioma)Session["oIdioma"]).Texto(ex.Message)); } else { MessageBox(sender, e, ex.Message); } } }