예제 #1
0
        protected void btnGuardar_Click(object sender, EventArgs e)
        {
            try
            {
                DataSet ds    = new DataSet();
                decimal total = 0;

                ds = Session["dtgPagos"] as DataSet;

                if (ds.Tables[0].Rows.Count > 0)
                {
                    if ((ds.Tables[0].Rows[ds.Tables[0].Rows.Count - 1][3]).ToString() == "TOTAL:" || (ds.Tables[0].Rows[ds.Tables[0].Rows.Count - 1][2]).ToString() == "TOTAL:")
                    {
                        ds.Tables[0].Rows[ds.Tables[0].Rows.Count - 1].Delete(); //--Borramos la fila del Total
                    }

                    for (int i = 0; i < ds.Tables[0].Rows.Count; i++) //Sumamos el Nuevo Total
                    {
                        total += Convert.ToDecimal(ds.Tables[0].Rows[i]["importe"].ToString());
                    }

                    if (Convert.ToDecimal(this.txtImporteTotal.Text) == total) //--Comparamos los Totales
                    {
                        //--///////BOTON GUARDAR, GUARDAR DETALLE PAGOS NUEVOS//////////////////////
                        if (btnGuardar.Text == "Guardar") //--Chequea si estamos guardando por primera vez pagos detalle
                        {
                            IGuiasTransfarmaco guiastransfarmaco = GuiasTransfarmacoFactory.GetGuiasTransfarmaco();
                            IUsuarios          usuario           = (IUsuarios)Session["Usuario"];
                            guiastransfarmaco.UsuarioID = usuario.UsuarioID;
                            guiastransfarmaco.DsPagos   = ds;
                            guiastransfarmaco.NroGuia   = Convert.ToInt32(this.txtGuiaID.Text);
                            guiastransfarmaco.GuiasTransfarmacoPagosID = 0;

                            if (guiastransfarmaco.GuardarDetallesPagos())
                            {
                                ScriptManager.RegisterClientScriptBlock(this.Page, this.Page.GetType(), "red‌​irect", "alert('Detalles de Pagos Guardados Correctamente');window.location='" + Request.ApplicationPath + "/GuiasTransfarmacoPagos.aspx?numeroguia=" + this.txtGuiaID.Text + "';", true);
                                btnGuardar.Enabled = true;
                            }
                            else
                            {
                                ScriptManager.RegisterClientScriptBlock(this.Page, this.Page.GetType(), "alert", "alert('Error al Guardar. Vuelva a intentarlo');", true);
                                btnGuardar.Enabled = true;
                            }
                        }
                        //--///////BOTON GUARDAR, MODIFICAR PAGOS YA GUARDADOS//////////////////////
                        else if (btnGuardar.Text == "Modificar")//---Si estamos guardando modificaciones de detalles pagos ya guardados.
                        {
                            IGuiasTransfarmaco guiastransfarmaco = GuiasTransfarmacoFactory.GetGuiasTransfarmaco();
                            IUsuarios          usuario           = (IUsuarios)Session["Usuario"];
                            guiastransfarmaco.UsuarioID = usuario.UsuarioID;
                            guiastransfarmaco.DsPagos   = ds;
                            guiastransfarmaco.NroGuia   = Convert.ToInt32(this.txtGuiaID.Text);
                            guiastransfarmaco.GuiasTransfarmacoPagosID = 0;

                            for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                            {
                                if (ds.Tables[0].Rows[i]["guiastransfarmacopagosid"].ToString() != "")
                                {
                                    guiastransfarmaco.GuiasTransfarmacoPagosID = Convert.ToInt32(ds.Tables[0].Rows[i]["guiastransfarmacopagosid"]);
                                }
                            }

                            if (guiastransfarmaco.GuiasTransfarmacoPagosID == 0)
                            {
                                DataSet dset = new DataSet();
                                dset = guiastransfarmaco.GetGuiasTransfarmacoPagosALL();

                                for (int i = 0; i < dset.Tables[0].Rows.Count; i++)
                                {
                                    if (dset.Tables[0].Rows[i]["guiastransfarmacopagosid"].ToString() != "")
                                    {
                                        guiastransfarmaco.GuiasTransfarmacoPagosID = Convert.ToInt32(dset.Tables[0].Rows[i]["guiastransfarmacopagosid"]);
                                    }
                                }
                            }

                            if (guiastransfarmaco.GuardarDetallesPagos())
                            {
                                ScriptManager.RegisterClientScriptBlock(this.Page, this.Page.GetType(), "red‌​irect", "alert('Detalles de Pagos Modificados Correctamente');window.location='" + Request.ApplicationPath + "/GuiasTransfarmacoPagos.aspx?numeroguia=" + this.txtGuiaID.Text + "';", true);
                                btnGuardar.Enabled = true;
                            }
                            else
                            {
                                ScriptManager.RegisterClientScriptBlock(this.Page, this.Page.GetType(), "alert", "alert('Error al Modificar. Vuelva a intentarlo');", true);
                                btnGuardar.Enabled = true;
                            }
                        }
                    }
                    else
                    {
                        ScriptManager.RegisterClientScriptBlock(this.Page, this.Page.GetType(), "alert", "alert('El Total de los Detalles debe ser igual al Total de la Guía.');", true);
                        btnGuardar.Enabled = true;
                    }
                }
                else
                {
                    btnGuardar.Enabled = true;
                    return;
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
예제 #2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                #region User IsAuthenticated
                if (Session["Usuario"] != null)
                {
                    this.usuario = (IUsuarios)Session["Usuario"];
                }

                if (User.Identity.IsAuthenticated)
                {
                    string       sOpcion = "guiasTransfarmacoObservacion";
                    SisPacK.Menu oMenu   = (SisPacK.Menu) this.FindControl("Menu1");
                    this.ValidarSeguridad(oMenu, sOpcion);
                }
                #endregion

                this.Session.Remove("dtgPagos");
                this.btnAgregar.Text    = "Agregar";
                this.btnGuardar.Visible = false;
                this.btnAgregar.Enabled = true;
                btnGuardar.Enabled      = true;
                IGuiasTransfarmaco guiastransfarmaco = GuiasTransfarmacoFactory.GetGuiasTransfarmaco();
                guiastransfarmaco.NroGuia = Convert.ToInt32(this.Request.QueryString["numeroguia"]) == null ? 0 : Convert.ToInt32(this.Request.QueryString["numeroguia"]);

                if (guiastransfarmaco.NroGuia != 0)
                {
                    this.btnAgregar.Visible = true;
                }

                try
                {
                    if (guiastransfarmaco.NroGuia != 0)
                    {
                        DataSet ds = new DataSet();
                        guiastransfarmaco.GuiasTransfarmacoObservacionID = 0;
                        guiastransfarmaco.FechaDesde = DateTime.Parse("1900-01-01 00:00:00.000");
                        guiastransfarmaco.FechaHasta = DateTime.Parse("1900-01-01 00:00:00.000");
                        ds = guiastransfarmaco.GetGuias();
                        for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                        {
                            this.txtGuiaID.Text        = ds.Tables[0].Rows[i]["numeroguia"].ToString();
                            this.txtImporteTotal.Text  = ds.Tables[0].Rows[i]["importetotalguia"].ToString();
                            this.txtFechaEmision.Text  = ds.Tables[0].Rows[i]["fechaemision"].ToString();
                            this.txtFechaEntrega.Text  = ds.Tables[0].Rows[i]["fechaentrega"].ToString();
                            this.txtObservaciones.Text = ds.Tables[0].Rows[i]["observacion"].ToString();
                        }
                        ds.Clear();
                        ds = guiastransfarmaco.GetGuiasTransfarmacoPagosALL();
                        decimal total = 0;

                        if (ds.Tables[0].Rows.Count > 0)
                        {
                            int contar = 1;
                            SisPackController.AdministrarGrillas.Configurar(this.dtgPagos, "tipo", 20);
                            ds.Tables[0].Columns.Add("detallenro", typeof(int));

                            for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                            {
                                total += Convert.ToDecimal(ds.Tables[0].Rows[i]["importe"].ToString());
                                ds.Tables[0].Rows[i]["detallenro"] = contar;
                                contar += 1;
                                if (ds.Tables[0].Rows[i]["tipo"].ToString() == "EF")
                                {
                                    ds.Tables[0].Rows[i]["tipo"] = "Efectivo";
                                }
                                else if (ds.Tables[0].Rows[i]["tipo"].ToString() == "CH")
                                {
                                    ds.Tables[0].Rows[i]["tipo"] = "Cheque";
                                }
                                else if (ds.Tables[0].Rows[i]["tipo"].ToString() == "TB")
                                {
                                    ds.Tables[0].Rows[i]["tipo"] = "Transferencia Bancaria";
                                }
                            }

                            this.Session["dtgPagos"] = ds;

                            DataRow dr1 = null;
                            dr1            = ds.Tables[0].NewRow();
                            dr1["tipo"]    = "TOTAL:";
                            dr1["importe"] = total.ToString();
                            ds.Tables[0].Rows.Add(dr1);

                            this.dtgPagos.DataSource       = ds;
                            this.dtgPagos.CurrentPageIndex = 0;
                            this.dtgPagos.DataBind();

                            this.btnGuardar.Visible = true;
                            this.btnGuardar.Text    = "Modificar";
                        }
                        else
                        {
                            this.btnGuardar.Visible = false;
                            this.btnGuardar.Text    = "Guardar";
                        }
                    }
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
        }