예제 #1
0
        public static FileCargaBean executeBC_XLS_instalacion(string Nombre, String spLogic)
        {
            FileCargaBean BE = new FileCargaBean();

            BE.archivo = Nombre;
            try
            {
                DataTable dt = SqlConnector.getDataTable(spLogic);
                foreach (DataRow row in dt.Rows)
                {
                    BE.subidos      = Int32.Parse(row[0].ToString());
                    BE.insertados   = Int32.Parse(row[1].ToString());
                    BE.actualizados = Int32.Parse(row[2].ToString());
                    BE.errorData    = (string)row[3];
                }
            }
            catch (Exception ex1)
            {
                if (ex1.ToString().Contains("Received an invalid column length from the bcp client for colid"))
                {
                    BE.errorExecute += "Uno de los registros excede la logitud de campo.";
                }
                else
                {
                    BE.errorExecute += ex1.Message;
                }
            }
            return(BE);
        }
예제 #2
0
        public static FileCargaBean executeBC_XLS(string dataFilePath, string tmpTable, string Nombre, String[][] mapping, String spLogic)
        {
            FileCargaBean BE = new FileCargaBean();

            BE.archivo = Nombre;
            try
            {
                String extension  = Path.GetExtension(dataFilePath);
                string tipoDriver = "Microsoft.Jet.OLEDB.4.0"; // Por defecto es el de 32 bits
                if (extension == ".xlsx")
                {
                    tipoDriver = "Microsoft.ACE.OLEDB.12.0";
                }
                String    excel_conexion = "Provider=" + tipoDriver + ";data source=" + dataFilePath + ";Extended Properties='Excel 8.0;HDR=YES;IMEX=1'";
                DataTable sourceData     = new DataTable();
                String    campos         = "";
                for (int i = 0; i < mapping.Length; i++)
                {
                    campos += mapping[i][0] + ",";
                }
                campos = campos.Remove(campos.Length - 1, 1);
                using (OleDbConnection conn =
                           new OleDbConnection(excel_conexion))
                {
                    conn.Open();
                    OleDbCommand command = new OleDbCommand(
                        @"SELECT " + campos + " FROM [" + Nombre + "$]", conn);
                    OleDbDataAdapter adapter = new OleDbDataAdapter(command);
                    adapter.Fill(sourceData);
                    conn.Close();
                }
                if (tmpTable == "dbo.TMP_Usuario")
                {
                    DataTable dtCloned = sourceData.Clone();
                    dtCloned.Columns["CLAVE"].DataType = typeof(String);
                    foreach (DataRow row in sourceData.Rows)
                    {
                        dtCloned.ImportRow(row);
                    }
                    sourceData = dtCloned;
                    foreach (DataRow dr in sourceData.Rows) // search whole table
                    {
                        dr["CLAVE"] = FormsAuthentication.HashPasswordForStoringInConfigFile(dr["CLAVE"].ToString(), "sha1");
                    }
                }
                SqlConnector.copyData(sourceData, mapping, tmpTable);

                DataTable dt = SqlConnector.getDataTable(spLogic);
                foreach (DataRow row in dt.Rows)
                {
                    BE.subidos      = Int32.Parse(row[0].ToString());
                    BE.insertados   = Int32.Parse(row[1].ToString());
                    BE.actualizados = Int32.Parse(row[2].ToString());
                    BE.errorData    = (string)row[3];
                }
            }
            catch (Exception ex1)
            {
                if (ex1.ToString().Contains("Received an invalid column length from the bcp client for colid"))
                {
                    BE.errorExecute += "Uno de los registros excede la logitud de campo.";
                }
                else
                {
                    BE.errorExecute += ex1.Message;
                }
            }
            return(BE);
        }
예제 #3
0
        public static List <FileCargaBean> ejecutarArchivoKML(String fileLocation)
        {
            List <FileCargaBean> lista = new List <FileCargaBean>();

            List <String> arrArchivosCargados = new List <String>();

            String[] extensions;
            //if (ConfigurationManager.AppSettings["DTSX"].Trim() == "1")
            extensions = new String[] { "*.kml" };
            //else
            //    extensions = new String[] { "*.xls" };

            foreach (String extension in extensions)
            {
                String[] filesArr = Directory.GetFiles(fileLocation, extension, SearchOption.TopDirectoryOnly);
                foreach (String file in filesArr)
                {
                    arrArchivosCargados.Add(file);
                }
            }

            //List<FileCargaBean> listaArchivos = new List<FileCargaBean>();
            FileCargaBean FileBean;

            String xml;

            foreach (String file in arrArchivosCargados)
            {
                FileBean = new FileCargaBean();
                try
                {
                    using (XmlSanitizingStream reader = new XmlSanitizingStream(new FileStream(file, FileMode.Open)))
                    {
                        xml = reader.ReadToEnd();
                    }

                    XmlDocument xmlDocument = new XmlDocument();

                    //xmlDocument.Load(file);
                    xmlDocument.LoadXml(xml);
                    xmlDocument.RemoveChild(xmlDocument.FirstChild);

                    int           num1            = 0;
                    int           num2            = 0;
                    int           num3            = 0;
                    int           num4            = 0;
                    XmlElement    documentElement = xmlDocument.DocumentElement;
                    StringBuilder stringBuilder   = new StringBuilder("<lp>");
                    foreach (XmlElement xmlElement in documentElement.FirstChild.ChildNodes)
                    {
                        if ("PLACEMARK".Equals(xmlElement.Name.ToUpper()))
                        {
                            ++num1;

                            string str = GeocercaController.registrarGeocercaAPartirDeXML(xmlElement.OuterXml);
                            if (str.Contains("|"))
                            {
                                string[] strArray = str.Split('|');
                                int      result1  = 0;
                                int.TryParse(strArray[0].ToString(), out result1);
                                num3 += result1;
                                int result2 = 0;
                                int.TryParse(strArray[1].ToString(), out result2);
                                num4 += result2;
                                ++num2;
                            }
                        }
                    }
                    FileBean.archivo      = file.Substring(file.LastIndexOf("\\") + 1, file.LastIndexOf(".") - file.LastIndexOf("\\") - 1);
                    FileBean.total        = num2;//num2;
                    FileBean.subidos      = num2;
                    FileBean.insertados   = num3;
                    FileBean.actualizados = num4;
                }
                catch (Exception e)
                {
                    FileBean.errorExecute += e.Message;
                }
                lista.Add(FileBean);
            }

            deleteDataFiles(fileLocation);

            return(lista);
        }