예제 #1
0
        //busqueda en sap de los datos proporcionados
        public void get_routes()
        {
            DataSet ds            = new DataSet();
            string  name_function = "Zmaestro_Rutas";

            try
            {
                IRfcFunction rfcFunction_Company = rfcRepository.CreateFunction(name_function.ToUpper());
                rfcFunction_Company.Invoke(rfcDestination);
                ds.Tables.Add(convert.toDataTable(rfcFunction_Company.GetTable("R_RUTA")));
                DataSet   dsCet          = new DataSet();
                DataTable dtCet          = new DataTable();
                DataSet   cetsPermitidos = new DataSet();
                string    sqlQuery       = "SELECT d.detalle_op FROM usuario u inner join detalle_usuario d "
                                           + "ON u.codigo_usuario = d.codigo_usuario WHERE u.usuario = '" + Session["usuario"] + "' AND d.maestro=4";
                dataAdapter = new SqlDataAdapter(sqlQuery, connection);
                dataAdapter.Fill(dsCet);
                DataTable table = new DataTable("Agencias");
                table.Columns.Add("codigo", typeof(Int32));
                table = dsCet.Tables[0];
                DataRow[] foundRow;
                DataRow[] foundRow1;

                foreach (DataRow dr in ds.Tables[0].Rows)
                {
                    foundRow  = table.Select("detalle_op = '" + dr[1].ToString() + "'");
                    foundRow1 = table.Select("detalle_op = 'ATOTAL'");
                    if (foundRow1.Length == 1)
                    {
                        DatosPermitidos dp = new DatosPermitidos();
                        dp.sala_venta = dr[1].ToString();
                        dp.cet        = dr[2].ToString();
                        dp.ruta       = dr[3].ToString();
                        datos.Add(dp);
                    }
                    else
                    {
                        for (int q = 0; q < foundRow.Length; q++)
                        {
                            DatosPermitidos dp = new DatosPermitidos();
                            dp.sala_venta = dr[1].ToString();
                            dp.cet        = dr[2].ToString();
                            dp.ruta       = dr[3].ToString();
                            datos.Add(dp);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine("<-- get_routes Error: " + ex.Message + " -->");
            }
        }
        //llena el combo de agencia
        public void cargoAgencia()
        {
            DataSet   ds            = new DataSet();
            string    name_function = "Zconsulta_Maestro_Detalle";
            DataTable dt            = new DataTable();
            string    sql           = "SELECT d.detalle_op FROM usuario u inner join detalle_usuario d "
                                      + "ON u.codigo_usuario = d.codigo_usuario WHERE u.usuario = '" + Session["usuario"] + "' AND d.maestro=4";

            try
            {
                dataAdapter    = new SqlDataAdapter(sql, connection);
                commandBuilder = new SqlCommandBuilder(dataAdapter);
                dataAdapter.Fill(dt);//contar rows

                IRfcFunction rfcFunction_Company = rfcRepository.CreateFunction(name_function.ToUpper());
                rfcFunction_Company.SetValue("I_Parametro", "SVENT");
                rfcFunction_Company.Invoke(rfcDestination);
                ds.Tables.Add(convert.toDataTable(rfcFunction_Company.GetTable("It_Datos")));
                DataRow[] foundRow;
                DataRow[] foundRow1;
                int       cont = 0;
                Session["sociedades"] = ds.Tables[0];
                foreach (DataRow dr in ds.Tables[0].Rows)
                {
                    foundRow  = dt.Select("detalle_op = '" + dr[0].ToString() + "'");
                    foundRow1 = dt.Select("detalle_op = 'ATOTAL'");
                    if (foundRow1.Length == 1)
                    {
                        cmbAgency.Items.Insert(cont, new ListItem(dr[1].ToString(), dr[0].ToString()));
                        cont++;
                    }
                    else
                    {
                        for (int q = 0; q < foundRow.Length; q++)
                        {
                            cmbAgency.Items.Insert(cont, new ListItem(dr[1].ToString(), dr[0].ToString()));
                            cont++;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine("Error cargoAgencia() --> " + ex.Message);
            }
        }
        //llena las agencias con SAP
        public void fill_Agency()
        {
            DataSet   ds            = new DataSet();
            string    name_function = "Zconsulta_Maestro_Detalle";
            DataTable dt            = new DataTable();
            string    sql           = "SELECT d.detalle_op FROM usuario u inner join detalle_usuario d "
                                      + "ON u.codigo_usuario = d.codigo_usuario WHERE u.usuario = '" + Session["usuario"] + "' AND d.maestro=4;";

            try
            {
                //Acá recupero los códigos de las agencias por usuario
                dataAdapter    = new SqlDataAdapter(sql, connection);
                commandBuilder = new SqlCommandBuilder(dataAdapter);
                dataAdapter.Fill(dt);//contar rows
                //Acá recupero la tabla de sap que contiene codigo y descripcion de las agencias
                IRfcFunction rfcFunction_Company = rfcRepository.CreateFunction(name_function.ToUpper());
                rfcFunction_Company.SetValue("I_Parametro", "SVENT");
                rfcFunction_Company.Invoke(rfcDestination);
                ds.Tables.Add(convert.toDataTable(rfcFunction_Company.GetTable("It_Datos")));
                //Acá hago match con codigo de sql y sap, seteo la descripcion al dropdown
                int       cont1 = 0;
                DataRow[] foundRow1;
                foreach (DataRow dr in dt.Rows)
                {
                    string permiso = dr[0].ToString();
                    if (permiso == "ATOTAL")
                    {
                        foreach (DataRow dr12 in ds.Tables[0].Rows)
                        {
                            //System.Diagnostics.Debug.WriteLine(dr12[1].ToString());
                            //System.Diagnostics.Debug.WriteLine(cont1);
                            cmbAgency.Items.Insert(cont1, new ListItem(dr12[1].ToString(), dr12[0].ToString()));
                            cont1++;
                        }
                    }
                    break;
                }
                DataRow[] foundRow;
                int       cont = 0;
                foreach (DataRow dr in ds.Tables[0].Rows)
                {
                    foundRow = dt.Select("detalle_op = '" + dr[0].ToString() + "'");

                    for (int q = 0; q < foundRow.Length; q++)
                    {
                        cmbAgency.Items.Insert(cont, new ListItem(dr[1].ToString(), dr[0].ToString()));
                        cont++;
                    }
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine("Error fill_agency() --> " + ex.Message);
            }
        }