Beispiel #1
0
        protected void ibExcel_Click(object sender, ImageClickEventArgs e)
        {
            //for (contador = 0; contador < GridView1.Rows.Count; contador++)
            //{
            //    GridViewRow row = GridView1.Rows[contador];
            //    if (row.Cells[2].Text != "&nbsp;")
            //    {

            //        double TirajeOT = Convert.ToDouble(row.Cells[2].Text);
            //        if (row.Cells[2].Text.Length > 3)
            //        {
            //            string to = TirajeOT.ToString("N0").Replace(",", ".");
            //            row.Cells[2].Text = to;
            //        }
            //        else
            //        {
            //            string to = TirajeOT.ToString("N0");
            //            row.Cells[2].Text = to;
            //        }
            //    }
            //    else
            //    {
            //        row.Cells[2].Text = "";
            //    }
            //    //cantidad  solicitada

            List <FillRate_Excel> lista = new List <FillRate_Excel>();

            for (int i = 0; i < RadGrid1.Items.Count; i++)
            {
                FillRate_Excel pro = new FillRate_Excel();

                if (RadGrid1.Items[i]["OT"].Text.ToUpper() == "&NBSP;")
                {
                    pro.OT = "";
                }
                else
                {
                    pro.OT = RadGrid1.Items[i]["OT"].Text.ToUpper();
                }
                if (RadGrid1.Items[i]["NombreOT"].Text.ToLower() == "&nbsp;")
                {
                    pro.NombreOT = "";
                }
                else
                {
                    pro.NombreOT = RadGrid1.Items[i]["NombreOT"].Text.ToLower();
                }
                if (RadGrid1.Items[i]["Tiraje"].Text == "&nbsp;")
                {
                    pro.Tiraje = "";
                }
                else
                {
                    pro.Tiraje = RadGrid1.Items[i]["Tiraje"].Text;
                }
                if (RadGrid1.Items[i]["Solitada"].Text == "&nbsp;")
                {
                    pro.Solitada = "";
                }
                else
                {
                    pro.Solitada = RadGrid1.Items[i]["Solitada"].Text;
                }
                if (RadGrid1.Items[i]["CantidadGenerada"].Text == "&nbsp;")
                {
                    pro.CantidadGenerada = "";
                }
                else
                {
                    pro.CantidadGenerada = RadGrid1.Items[i]["CantidadGenerada"].Text;
                }
                if (RadGrid1.Items[i]["FechaEntregada"].Text == "&nbsp;")
                {
                    pro.FechaEntregar = "";
                }
                else
                {
                    pro.FechaEntregar = RadGrid1.Items[i]["FechaEntregada"].Text;
                }
                if (RadGrid1.Items[i]["PuntoEntrega"].Text == "&nbsp;")
                {
                    pro.PuntoEntrega = "";
                }
                else
                {
                    pro.PuntoEntrega = RadGrid1.Items[i]["PuntoEntrega"].Text;
                }


                pro.PorcSobreTiraje = RadGrid1.Items[i]["DespachoTotal"].Text;
                pro.PorcSolicitado  = RadGrid1.Items[i]["PorcSolicitado"].Text;



                lista.Add(pro);
            }
            GridView GridView1 = new GridView();

            GridView1.DataSource = lista;
            GridView1.DataBind();


            GridView1.HeaderStyle.BackColor = System.Drawing.Color.Blue;
            GridView1.HeaderStyle.ForeColor = System.Drawing.Color.White;



            string nombre = "InformeFillRate" + DateTime.Now.ToShortDateString();


            ExportToExcel(nombre, GridView1);//GridView1);
        }
        //fillRate exportacion excel
        public List <FillRate_Excel> ListarFillRate_Excel(DateTime fechaInicio, DateTime fechaTermino, string OT = "", string NombreOT = "", string Cliente = "")
        {
            List <FillRate_Excel> lista = new List <FillRate_Excel>();
            Conexion   con = new Conexion();
            SqlCommand cmd = con.AbrirConexionProduccion();

            if (cmd != null)
            {
                cmd.CommandText = "ListarFillRate";
                cmd.CommandType = System.Data.CommandType.StoredProcedure;
                cmd.Parameters.AddWithValue("@fechaInicio", fechaInicio);
                cmd.Parameters.AddWithValue("@fechaTermino", fechaTermino);
                cmd.Parameters.AddWithValue("@Ot", OT);
                cmd.Parameters.AddWithValue("@NumeroOT", NombreOT);
                cmd.Parameters.AddWithValue("@Cliente", Cliente);
                SqlDataReader reader = cmd.ExecuteReader();

                int totalOt     = 0;
                int totalPuntos = 0;
                int porcrate    = 0;

                string ot = "";
                while (reader.Read())
                {
                    FillRate_Excel fill = new FillRate_Excel();

                    fill.OT = reader["QG_RMS_JOB_NBR"].ToString();

                    fill.NombreOT = reader["NM"].ToString();
                    int tiraje = Convert.ToInt32(reader["PRN_ORD_QTY"].ToString());
                    fill.Tiraje = reader["PRN_ORD_QTY"].ToString();          //tiraje.ToString("N0");
                    int solicitada = Convert.ToInt32(reader["CantidadSolicitada"].ToString());
                    fill.Solitada = reader["CantidadSolicitada"].ToString(); //solicitada.ToString("N0");

                    int CantSol = Convert.ToInt32(reader["TirajeGenerado"].ToString());
                    fill.CantidadGenerada = reader["TirajeGenerado"].ToString();//CantSol.ToString("N0");

                    DateTime fe = Convert.ToDateTime(reader["FechaModificacion"].ToString());
                    fill.FechaEntregar = fe.ToString("dd/MM/yyyy HH:mm");// Convert.ToDateTime(reader["FechaModificacion"].ToString());

                    DateTime fp = Convert.ToDateTime(reader["FechaProduccion"].ToString());
                    //fill.FechaEntregada = fp.ToString("dd/MM/yyyy HH:mm"); //Convert.ToDateTime(reader["FechaProduccion"].ToString());


                    //% total
                    //% total
                    bool algo            = false;
                    int  TotalDespachado = Convert.ToInt32(reader["DespachoTotal"].ToString());
                    if (tiraje == 0)
                    {
                        // TotalDespachado = 1;
                        TotalDespachado = 0;
                        algo            = true;
                    }
                    else
                    {
                        TotalDespachado = ((TotalDespachado * 100) / tiraje);
                    }
                    //  TotalDespachado = ((TotalDespachado * 100) / tiraje);

                    if (algo)
                    {
                        //fill.DespachoTotal = "Error";
                    }
                    else
                    {
                        // fill.DespachoTotal = TotalDespachado.ToString() + "%";
                    }
                    //  int TotalDespachado = Convert.ToInt32(reader["DespachoTotal"].ToString());
                    // if (tiraje == 0)
                    //{
                    //}
                    //else
                    //{
                    //    TotalDespachado = ((TotalDespachado * 100) / tiraje);
                    //}

                    //fill.DespachoTotal = TotalDespachado.ToString() + "%";

                    //fin
                    if (ot == fill.OT)
                    {
                        fill.PuntoEntrega = "0";
                    }
                    else
                    {
                        fill.PuntoEntrega = reader["contadorSucursal"].ToString(); //Convert.ToInt32(reader["contadorSucursal"].ToString());
                    }


                    //fill.PorcTiraje = reader["Porcentaje"].ToString();
                    /*******/
                    //cambios realizados el 13/11 error ot tiraje 0
                    int valor = Convert.ToInt32(reader["TirajeGenerado"].ToString());
                    if (solicitada > 0)
                    {
                        valor = ((valor * 100) / solicitada);
                    }
                    else
                    {
                        valor = 0;
                    }
                    fill.PorcSolicitado = valor.ToString() + "%";
                    if (fill.PorcSolicitado == "100%")
                    {
                        porcrate = porcrate + 1;
                    }
                    totalOt     = totalOt + 1;
                    totalPuntos = totalPuntos + Convert.ToInt32(fill.PuntoEntrega);
                    lista.Add(fill);
                    ot = fill.OT;
                }
                if (reader.Read() == false)
                {
                    FillRate_Excel fill = new FillRate_Excel();
                    //  fill.FechaEntregada = "";
                    fill.FechaEntregar = "";
                    fill.PuntoEntrega  = "";
                    //fill.DespachoTotal = "Total OTs :";
                    fill.PorcSolicitado = totalOt.ToString("N0").Replace(",", ".");
                    lista.Add(fill);
                    FillRate_Excel fill2 = new FillRate_Excel();
                    // fill2.FechaEntregada = null;
                    fill2.FechaEntregar = null;
                    fill2.PuntoEntrega  = null;
                    //fill2.DespachoTotal = "Punt. Entrega:";
                    fill2.PorcSolicitado = totalPuntos.ToString("N0").Replace(",", ".");
                    lista.Add(fill2);
                    FillRate_Excel fill3 = new FillRate_Excel();
                    // fill3.FechaEntregada = null;
                    fill3.FechaEntregar = null;
                    fill3.PuntoEntrega  = null;
                    // fill3.DespachoTotal = "Fill Rate OT";
                    try
                    {
                        double a   = Convert.ToDouble(porcrate);
                        double b   = Convert.ToDouble(totalOt);
                        double c   = ((a / b) * 100);
                        int    alo = Convert.ToInt32(c);
                        fill3.PorcSolicitado = alo.ToString() + "%";//
                    }
                    catch
                    {
                        fill3.PorcSolicitado = "%";// alo.ToString()
                    }
                    lista.Add(fill3);
                    FillRate_Excel fill4 = new FillRate_Excel();
                    //fill4.FechaEntregada = null;
                    fill4.FechaEntregar = null;
                    fill4.PuntoEntrega  = null;
                    //fill4.DespachoTotal = "Fill Rate Pto. Entrega";
                    fill4.PorcSolicitado = "100%";
                    lista.Add(fill4);
                }
            }
            con.CerrarConexion();
            return(lista);
        }