protected void btnUDoc_Click(object sender, EventArgs e) { try { if (fp_Doc_xls.HasFile) { lblEL.Visible = false; btnUDoc.Enabled = false; fp_Doc_xls.Enabled = false; if (fp_Doc_xls.FileName.Contains(".xls") | fp_Doc_xls.FileName.Contains(".xlsx")) { var er = fp_Doc_xls.FileName.Contains(".xlsx") ? ExcelReaderFactory.CreateOpenXmlReader(fp_Doc_xls.PostedFile.InputStream) : ExcelReaderFactory.CreateBinaryReader(fp_Doc_xls.PostedFile.InputStream); var excp = er.AsDataSet().Tables["Vigencias"].AsEnumerable(); Int64 i64; int inserted = 0; int cont = 0; string res = ""; string tEx = ""; string ex = ""; DateTime dt; List <IVigenciaDTO> lEx = new List <IVigenciaDTO>(); ServCBloqueados serv = new ServCBloqueados(); foreach (var a in excp) { if (cont > 0) { if (a[0].ToString().CompareTo("") == 0 && a[1].ToString().CompareTo("") != 0) { lEx.Add(new VigenciaDTO(a[0].ToString(), a[1].ToString())); } else if (a[0].ToString().CompareTo("") != 0 && a[1].ToString().CompareTo("") == 0) { lEx.Add(new VigenciaDTO(a[0].ToString(), a[1].ToString())); } else { res = serv.insertValidity(a[0].ToString(), a[1].ToString(), ((IUsr)Session["Usr"]).usr.Pais.IdPais.ToString()); if (res.CompareTo("0") == 0) { lEx.Add(new VigenciaDTO(a[0].ToString(), a[1].ToString())); } if (res.CompareTo("1") == 0) { inserted++; } } } cont++; } if (cont < 1) { lblMsgLDB.Visible = false; lblELDB.Visible = false; lblEL.ForeColor = Color.Red; lblEL.Text = "El archivo no contiene datos Validos"; lblEL.Visible = true; } if (lEx.Count > 0) { gv_Error.DataSource = lEx; gv_Error.DataBind(); gv_Error.Visible = true; lblELDB.ForeColor = Color.Red; lblELDB.Text = "Datos no Cargados"; lblELDB.Visible = true; } if (lEx.Count == 0 && inserted == 0) { lblMsgLDB.Visible = false; lblELDB.Visible = false; lblEL.ForeColor = Color.Red; lblEL.Text = "El archivo no contiene datos"; lblEL.Visible = true; } else { if (inserted > 0 && lEx.Count == 0) { lblMsgLDB.Visible = false; lblELDB.Visible = false; lblEL.ForeColor = Color.Green; lblEL.Text = "Datos insertados correctamente"; lblEL.Visible = true; } } } else { lblMsgLDB.Visible = false; lblELDB.Visible = false; lblEL.Text = "Tipo de archivo no valido"; lblEL.Visible = true; } btnF.Visible = true; } else { lblMsgLDB.Visible = false; lblELDB.Visible = false; lblEL.Text = "Por favor seleccione un archivo de clientes a Cargar."; lblEL.Visible = true; } } catch (Exception exe) { btnUDoc.Enabled = true; fp_Doc_xls.Enabled = true; lblMsgLDB.Visible = false; lblELDB.Visible = false; lblEL.Text = "Se ha generado un error. Contacte al Administrador de la aplicación"; lblEL.Visible = true; //throw; } }
protected void gvCliBlo_RowCommand(object sender, GridViewCommandEventArgs e) { switch (e.CommandName) { case "Nuevo": { #region Nuevo Session["editOp"] = false; MpUp_MA.Hide(); gvCliBlo.EditIndex = -1; Session["dtDoc"] = null; DataTable dt = ((DataTable)Session["dtVigencia"]).Copy(); Session["RANew"] = Convert.ToInt32(e.CommandArgument.ToString()); if (dt.Rows[0][0].ToString() == "##" & gvCliBlo.Rows.Count == 1) { gvCliBlo.EditIndex = 0; gvCliBlo.DataSource = dt; gvCliBlo.DataBind(); } else { DataRow rw = dt.NewRow(); for (int i = 0; i <= dt.Columns.Count - 1; i++) { rw[i] = DBNull.Value; } dt.Rows.Add(rw); gvCliBlo.DataSource = dt; gvCliBlo.DataBind(); gvCliBlo.PageIndex = gvCliBlo.PageCount; gvCliBlo.DataBind(); gvCliBlo.EditIndex = gvCliBlo.Rows.Count - 1; gvCliBlo.DataBind(); } #endregion } break; case "Buscar": { #region Buscar Session["dtDoc"] = null; DataTable dt2 = ((DataTable)Session["dtVigencia"]).Copy(); if (dt2.Rows[0][0].ToString() == "##" & gvCliBlo.Rows.Count == 1) { return; } gvCliBlo.EditIndex = -1; gvCliBlo.DataSource = Session["dtVigencia"]; gvCliBlo.DataBind(); gv_Alertas.DataSource = new DataTable(); gv_Alertas.DataBind(); txtIdBusq.Text = String.Empty; txtMSGBusq.Text = String.Empty; lblId.Text = "Id:"; lblTxtCod.Text = "Codigo:"; txtIdBusq_TextBoxWatermarkExtender.WatermarkText = "Id"; txtMSGBusq_TextBoxWatermarkExtender.WatermarkText = "Cliente"; gv_Alertas.Visible = true; pnlMpBA.Visible = true; MpUp_MA.Show(); #endregion } break; case "Editar": { #region Editar Session["dtDoc"] = null; DataTable dt = ((DataTable)Session["dtVigencia"]).Copy(); ServCBloqueados serv = new ServCBloqueados(); string IdCli = gvCliBlo.Rows[Convert.ToInt32(e.CommandArgument.ToString())].Cells[0].Text.Trim(); Session["editOp"] = true; MpUp_MA.Hide(); if (dt.Rows[0][0].ToString() != "##") { Session["RANew"] = 0; gvCliBlo.EditIndex = Convert.ToInt32(e.CommandArgument.ToString()); gvCliBlo.DataSource = Session["dtVigencia"]; gvCliBlo.DataBind(); } ((TextBox)gvCliBlo.Rows[Convert.ToInt32(e.CommandArgument.ToString())].FindControl("txtIdCli")).Enabled = false; var itemSelected = serv.findClient(IdCli.ToString(), "8", ((IUsr)Session["Usr"]).usr.Pais.IdPais.ToString()); #endregion } break; case "Guardar": { #region Guardar var Id = gvCliBlo.Rows[Convert.ToInt32(e.CommandArgument.ToString())].Cells[0].Text.Trim(); var IdCli = ((TextBox)gvCliBlo.Rows[Convert.ToInt32(gvCliBlo.EditIndex)].FindControl("txtIdCli")).Text; var vigencia = ((TextBox)gvCliBlo.Rows[Convert.ToInt32(e.CommandArgument.ToString())].FindControl("txtVigencia")).Text.Trim(); ServCBloqueados serv = new ServCBloqueados(); switch (((int)Session["RANew"])) { case 0: { //Actualizar Cli string res = serv.updateValidyty(Id, IdCli, vigencia, ((IUsr)Session["Usr"]).usr.Pais.IdPais.ToString()); if (res.CompareTo("0") == 0) { lblEInsUp.ForeColor = Color.Red; lblEInsUp.Text = "No se ha podido realizar la modificación"; lblEInsUp.Visible = true; } else { Response.Redirect(Request.RawUrl); } } break; case 1: { //Nuevo Cli IdCli = ((TextBox)gvCliBlo.Rows[Convert.ToInt32(e.CommandArgument.ToString())].FindControl("txtIdCli")).Text.Trim(); string res = serv.insertValidity(IdCli, vigencia, ((IUsr)Session["Usr"]).usr.Pais.IdPais.ToString()); if (res.CompareTo("0") == 0) { lblEInsUp.ForeColor = Color.Red; lblEInsUp.Text = "El cliente ya se encuentra registrado"; lblEInsUp.Visible = true; } else { if (res.CompareTo("-1") == 0) { lblEInsUp.ForeColor = Color.Red; lblEInsUp.Text = "Datos Incorrectos"; lblEInsUp.Visible = true; } else { Response.Redirect(Request.RawUrl); } } } break; } #endregion } break; case "Borrar": { #region Borrar if (gvCliBlo.EditIndex != -1) { return; } var IdCli = gvCliBlo.Rows[Convert.ToInt32(e.CommandArgument.ToString())].Cells[0].Text.Trim(); ServCBloqueados serv = new ServCBloqueados(); string res = serv.deleteValidity(IdCli, ((IUsr)Session["Usr"]).usr.Pais.IdPais.ToString()); if (res.CompareTo("0") == 0) { lblEInsUp.ForeColor = Color.Red; lblEInsUp.Text = "No se pudo eliminar el Cliente"; lblEInsUp.Visible = true; } else { Response.Redirect(Request.RawUrl); } #endregion } break; case "Cancelar": { #region Cancelar MpUp_MA.Hide(); Session["dtDoc"] = null; lblEInsUp.Visible = false; Session["RANew"] = 0; gvCliBlo.EditIndex = -1; gvCliBlo.DataSource = Session["dtVigencia"]; gvCliBlo.DataBind(); #endregion } break; } }