Merge branch 'master' of http://192.168.10.111:8383/SIG
This commit is contained in:
@@ -14,7 +14,7 @@
|
||||
</asp:Content>
|
||||
<asp:Content ID="Content7" ContentPlaceHolderID="C" runat="Server">
|
||||
|
||||
<asp:UpdatePanel runat="server" ID="UpDetallesDia" UpdateMode="Conditional">
|
||||
<asp:UpdatePanel runat="server" ID="UpDetallesDia" UpdateMode="Conditional">
|
||||
<ContentTemplate>
|
||||
<div class="row">
|
||||
<div class="col-md-6">
|
||||
@@ -48,9 +48,13 @@
|
||||
<span class="caption-subject bold uppercase">Paso 2: Configuración </span>
|
||||
</div>
|
||||
<div class="tools">
|
||||
<asp:LinkButton ID="Lnkdoit" CssClass="btn btn-success" OnClick="Lnkdoit_Click" runat="server">Mostrar</asp:LinkButton>
|
||||
<a href="javascript:;" class="collapse" data-original-title="" title=""></a>
|
||||
</div>
|
||||
<div class="actions">
|
||||
<div class="btn-group">
|
||||
<asp:LinkButton ID="Lnkdoit" CssClass="btn btn-success" OnClick="Lnkdoit_Click" runat="server">Mostrar</asp:LinkButton>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="portlet-body rowpadding ">
|
||||
<div class="row">
|
||||
@@ -67,19 +71,19 @@
|
||||
<div class="row">
|
||||
<div class="col-md-3">
|
||||
<div class="form-group form-md-line-input input-iconright">
|
||||
<asp:TextBox CssClass="form-control" ID="TxtFilas" runat="server" Text="1" Enabled="false"></asp:TextBox>
|
||||
<asp:TextBox CssClass="form-control" ID="TxtFilas" runat="server" Text="1" ></asp:TextBox>
|
||||
<asp:Label runat="server" AssociatedControlID="TxtFilas" type="number" Text="Filas"></asp:Label>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-3">
|
||||
<div class="form-group form-md-line-input input-iconright">
|
||||
<asp:TextBox CssClass="form-control" ID="TxtInicia" runat="server" Text="1" Enabled="false"></asp:TextBox>
|
||||
<asp:TextBox CssClass="form-control" ID="TxtInicia" runat="server" Text="1" ></asp:TextBox>
|
||||
<asp:Label runat="server" AssociatedControlID="TxtInicia" type="number" Text="Fila inicial"></asp:Label>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-3">
|
||||
<div class="form-group form-md-line-input input-iconright">
|
||||
<asp:TextBox CssClass="form-control" ID="TxtColumnas" runat="server" Text="1" Enabled="false"></asp:TextBox>
|
||||
<asp:TextBox CssClass="form-control" ID="TxtColumnas" runat="server" Text="1" ></asp:TextBox>
|
||||
<asp:Label runat="server" AssociatedControlID="TxtColumnas" type="number" Text="Columnas"></asp:Label>
|
||||
</div>
|
||||
</div>
|
||||
@@ -88,12 +92,15 @@
|
||||
</div>
|
||||
</div>
|
||||
<div class="text-right">
|
||||
<asp:LinkButton ID="LnkContinuar" OnClick="LnkContinuar_Click" runat="server">Continuar</asp:LinkButton>
|
||||
<asp:LinkButton ID="LnkContinuar" CssClass="btn btn-success" OnClick="LnkContinuar_Click" runat="server">Continuar</asp:LinkButton>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<asp:GridView ID="GVDatos" data-cols="6" CssClass="table table-hover table-advance ScrollAD" runat="server">
|
||||
|
||||
</asp:GridView>
|
||||
</ContentTemplate>
|
||||
</asp:UpdatePanel>
|
||||
</asp:Content>
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Linq;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Web;
|
||||
using System.Web.UI;
|
||||
using System.Web.UI.WebControls;
|
||||
@@ -41,6 +44,16 @@ public partial class General_ExcelToBD : System.Web.UI.Page
|
||||
|
||||
set { ViewState["workBooks"] = value; }
|
||||
}
|
||||
private ConcurrentDictionary<string, string> ColumnsTitles
|
||||
{
|
||||
get
|
||||
{
|
||||
if (ViewState["ColumnsTitles"] == null) { return null; }
|
||||
else { return (ConcurrentDictionary<string, string>)ViewState["ColumnsTitles"]; }
|
||||
}
|
||||
|
||||
set { ViewState["ColumnsTitles"] = value; }
|
||||
}
|
||||
#endregion
|
||||
protected void Page_Load(object sender, EventArgs e)
|
||||
{
|
||||
@@ -64,21 +77,21 @@ public partial class General_ExcelToBD : System.Web.UI.Page
|
||||
workBooks.Add(new ADSWorksBooks() { Name = wokitem.Name, position = position++ });
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
DdlWorkBooks.DataSource = workBooks;
|
||||
DdlWorkBooks.DataBind();
|
||||
if (workBooks.Count > 0)
|
||||
{
|
||||
DdlWorkBooks.SelectedIndex = 0;
|
||||
DdlWorkBooks_SelectedIndexChanged(null,null);
|
||||
DdlWorkBooks_SelectedIndexChanged(null, null);
|
||||
}
|
||||
}
|
||||
|
||||
protected void DdlWorkBooks_SelectedIndexChanged(object sender, EventArgs e)
|
||||
{
|
||||
using (var workbook = new XLWorkbook(URLFile))
|
||||
{
|
||||
{
|
||||
|
||||
int Filas = 0;
|
||||
int columnas = 0;
|
||||
@@ -86,25 +99,151 @@ public partial class General_ExcelToBD : System.Web.UI.Page
|
||||
Filas = workSheet.LastColumnUsed().CellCount();
|
||||
columnas = workSheet.LastRowUsed().CellCount();
|
||||
TxtFilas.Text = Filas.ToString();
|
||||
TxtInicia.Text = "1";
|
||||
TxtColumnas.Text = Filas.ToString();
|
||||
TxtInicia.Text = "2";
|
||||
TxtColumnas.Text = "62";// columnas.ToString();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected void Lnkdoit_Click(object sender, EventArgs e)
|
||||
{
|
||||
|
||||
GVDatos.DataSource = GetDatosExcel();
|
||||
GVDatos.DataBind();
|
||||
}
|
||||
|
||||
protected void LnkContinuar_Click(object sender, EventArgs e)
|
||||
{
|
||||
int Filas = 0;
|
||||
int columnas = 0;
|
||||
DataSet ds = new DataSet();
|
||||
DataTable dtDatos = new DataTable();
|
||||
DataTable dt = GetDatosExcel();
|
||||
ds.DataSetName = "DSDatos";
|
||||
dtDatos.TableName = "TCol";
|
||||
dt.TableName = "TData";
|
||||
|
||||
dtDatos.Columns.Add(new DataColumn("Columnas", typeof(string)));
|
||||
dtDatos.Columns.Add(new DataColumn("LEN", typeof(int)));
|
||||
foreach (DataColumn item in dt.Columns)
|
||||
{
|
||||
DataRow drow = dtDatos.NewRow();
|
||||
drow["Columnas"] = item.ColumnName;
|
||||
int longitud = 0;
|
||||
foreach (DataRow dr in dt.Rows)
|
||||
{
|
||||
int length = dr[item.ColumnName].ToString().Length;
|
||||
|
||||
longitud = length > longitud ? length : longitud;
|
||||
}
|
||||
drow["LEN"] = longitud;
|
||||
dtDatos.Rows.Add(drow);
|
||||
}
|
||||
|
||||
ds.Tables.Add(dtDatos);
|
||||
ds.Tables.Add(dt);
|
||||
string xml = ds.GetXml();
|
||||
|
||||
using (ClsNominas objbase = new ClsNominas())
|
||||
{
|
||||
if (objbase.ExcelToBD(xml))
|
||||
{
|
||||
this.Alert("Información capturada", ModExtensiones.TipoMensaje.MsgInformacion);
|
||||
}
|
||||
}
|
||||
GVDatos.DataSource = dt;
|
||||
GVDatos.DataBind();
|
||||
|
||||
//this.Alert(string.Format("<div style=\"width:700px;\"><pre><xmp>{0}</xmp>\n</pre></br></div>", xml), ModExtensiones.TipoMensaje.MsgInformacion);
|
||||
|
||||
}
|
||||
public string validtitle(string Valor)
|
||||
{
|
||||
|
||||
Valor = Valor.Replace(" ", "_");
|
||||
Valor = Valor.Replace("$$$$", "_Money_");
|
||||
Valor = Valor.Replace("$$$", "_Money_");
|
||||
Valor = Valor.Replace("$$", "_Money_");
|
||||
Valor = Valor.Replace("$", "_Money_");
|
||||
Valor = Valor.Replace(".", string.Empty);
|
||||
Regex reg = new Regex("[*'\",&#^@]");
|
||||
Valor = reg.Replace(Valor, string.Empty);
|
||||
if (Valor.Trim().Length == 0)
|
||||
{
|
||||
Valor = "Val";
|
||||
}
|
||||
return Valor;
|
||||
}
|
||||
public DataTable GetDatosExcel()
|
||||
{
|
||||
|
||||
DataTable dtDatos = new DataTable();
|
||||
ColumnsTitles = new ConcurrentDictionary<string, string>();
|
||||
using (var workbook = new XLWorkbook(URLFile))
|
||||
{
|
||||
IXLWorksheet workSheet = workbook.Worksheet(DdlWorkBooks.SelectedValue.ToEntero());
|
||||
DateTime d = new DateTime();
|
||||
bool continuarFila = true;
|
||||
string validaValor;
|
||||
|
||||
int contadorValida = 0;
|
||||
bool haveTitles = chkcontieneTitulos.Checked;
|
||||
int FilaInicial = TxtInicia.Text.ToEntero() > 0 ? TxtInicia.Text.ToEntero() : 1;
|
||||
int ColumnaFinal = TxtColumnas.Text.ToEntero();
|
||||
int cFila = FilaInicial;
|
||||
int cCol = 1;
|
||||
|
||||
while (cCol <= ColumnaFinal)
|
||||
{
|
||||
string Valor = cCol.ToString();
|
||||
if (haveTitles)
|
||||
{
|
||||
Valor = workSheet.Cell(cFila, cCol).Value != null && workSheet.Cell(cFila, cCol).Value.GetType() == d.GetType() ? string.Format("{0:yyyy/MM/dd}", workSheet.Cell(cFila, cCol).Value) : workSheet.Cell(cFila, cCol).Value.ToString();
|
||||
Valor = validtitle(Valor);
|
||||
}
|
||||
if (!ColumnsTitles.TryAdd(Valor, Valor))
|
||||
{
|
||||
int x = 2;
|
||||
while (!ColumnsTitles.TryAdd(string.Format("{0}_{1}", Valor, x), Valor)) { x++; }
|
||||
Valor = string.Format("{0}_{1}", Valor, x);
|
||||
}
|
||||
dtDatos.Columns.Add(new DataColumn(Valor, typeof(string)));
|
||||
cCol++;
|
||||
}
|
||||
if (haveTitles)
|
||||
{
|
||||
cFila++;
|
||||
}
|
||||
while (continuarFila)
|
||||
{
|
||||
DataRow drow = dtDatos.NewRow();
|
||||
cCol = 1;
|
||||
validaValor = "";
|
||||
while (cCol <= ColumnaFinal)
|
||||
{
|
||||
string Valor = workSheet.Cell(cFila, cCol).Value != null && workSheet.Cell(cFila, cCol).Value.GetType() == d.GetType() ? string.Format("{0:yyyy/MM/dd}", workSheet.Cell(cFila, cCol).Value) : workSheet.Cell(cFila, cCol).Value.ToString();
|
||||
validaValor = string.Format("{0}{1}", validaValor, Valor);
|
||||
drow[cCol - 1] = Valor;
|
||||
cCol++;
|
||||
}
|
||||
if (validaValor.Trim() == "")
|
||||
{
|
||||
contadorValida++;
|
||||
if (contadorValida > 30)
|
||||
{
|
||||
continuarFila = false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
contadorValida = 0;
|
||||
dtDatos.Rows.Add(drow);
|
||||
}
|
||||
cFila++;
|
||||
if (cFila >= 1048576)
|
||||
{
|
||||
continuarFila = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return dtDatos;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user