protected void BtnGenConsumo_Click(object sender, EventArgs e) { string Msj = ""; string _TIDO = "GDI"; string _Modalidad = "PHPRO"; string _Empresa = "01"; string _Endo = "76829725-8"; string _Sudo = "PHU"; string _Kofudo = "CMP"; string _ListaPre = "TABPP02C"; _DETALLE = new List <DetalleConsumo>(); Validadores val = new Validadores(); foreach (GridViewRow row in GrdDetalle.Rows) { DetalleConsumo detalle = new DetalleConsumo { _NUMOT = row.Cells[0].Text, _CODIGO = row.Cells[1].Text, _CANTIDADF = val.ParseoDouble(row.Cells[2].Text), _UNIDADC = row.Cells[3].Text, _TIPO = row.Cells[4].Text, _NIVELSUP = row.Cells[5].Text, _SUBNREG = row.Cells[6].Text, _OPERACION = row.Cells[7].Text, _SUOT = row.Cells[8].Text, _KOFUCRE = row.Cells[9].Text, _IDPOTD = row.Cells[10].Text, _IDPOTL = row.Cells[11].Text, _MODO = row.Cells[12].Text, _TIMODO = row.Cells[13].Text, _TIPOUNI = row.Cells[14].Text, _UNIDAD = row.Cells[15].Text, _TAMODO = val.ParseoDouble(row.Cells[16].Text), _PPPRPMSUC = val.ParseoDouble(row.Cells[17].Text), _CODMAQ = row.Cells[18].Text, }; _DETALLE.Add(detalle); } int total = GrdDetalle.Rows.Count; bool CrearDoc = true; GenerarMAEDDOyMAEEDO generar = new GenerarMAEDDOyMAEEDO(); int contador = 1; bool Doitem = false; double t = Convert.ToDouble(total) / 28; int CantDoc = Convert.ToInt32(Math.Ceiling(t)); string[] DocList = new string[CantDoc]; foreach (var item in _DETALLE) { if (CrearDoc) { GenerarDocumento Doc = new GenerarDocumento(_Empresa, _Modalidad, _TIDO); if (Doc.IsSuccess) { DateTime HOY = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day); Tablas.MAEEDO MAEEDO = new Tablas.MAEEDO { EMPRESA = _Empresa, TIDO = _TIDO, IDMAEEDO = Doc.IDMAEEDO, NUDO = Doc.NroDocumento, ENDO = _Endo, SUENDO = "", ENDOFI = "", TIGEDO = "I", SUDO = _Sudo, LUVTDO = "", FEEMDO = HOY, KOFUDO = _Kofudo, ESDO = "C", ESPGDO = "S", CAPRAD = 0, MEARDO = "N", MODO = item._MODO, TIMODO = item._TIMODO, TAMODO = item._TAMODO, NUCTAP = 0, VACTDTNEDO = 0, NUIVDO = 0, POIVDO = 0, NUIMDO = 0, VAIMDO = 0, POPIDO = 0, VAPIDO = 0, FE01VEDO = DateTime.Now, FEULVEDO = DateTime.Now, FEER = DateTime.Now, NUVEDO = 0, VAABDO = 0, MARCA = "", NUTRANSMI = "", NUCOCO = "", KOTU = "1", LIBRO = "", LCLV = val.ParseoDateTime("0"), ESFADO = "", KOTRPCVH = "", NULICO = "", PERIODO = "", NUDONODEFI = false, TRANSMASI = "", POIVARET = 0, VAIVARET = 0, RESUMEN = "", LAHORA = DateTime.Now, KOFUAUDO = "", KOOPDO = "", ESPRODDO = "", DESPACHO = 0, HORAGRAB = (DateTime.Now.Hour * 60 + DateTime.Now.Minute) * 60, RUTCONTACT = "", SUBTIDO = "", TIDOELEC = false, ESDOIMP = "", CUOGASDIF = "0", BODESTI = "", PROYECTO = "", FECHATRIB = val.ParseoDateTime("0"), NUMOPERVEN = "0", BLOQUEAPAG = "", VALORRET = 0, FLIQUIFCV = val.ParseoDateTime("0"), VADEIVDO = 0, KOCANAL = "", KOCRYPT = Doc.KOCRYPT, LEYZONA = "", KOSIFIC = "", LISACTIVA = _ListaPre, KOFUAUTO = "", SUENDOFI = "", VAIVDOZF = 0, ENDOMANDA = "", FLUVTCALZA = "", ARCHIXML = "", IDXML = "0", SERIENUDO = "", VALORAJU = "0", }; generar.GetMAEEDO(MAEEDO); CantDoc--; DocList[CantDoc] = MAEEDO.NUDO; Doitem = true; } else { Doitem = false; Msj = "Hubo un error al tratar de generar el documento"; break; } } if (Doitem) { string _NULIDO = contador.ToString(); generar.AddItemMAEDDO(item); } if (contador == 28) { if (total > 28) { total = total - 28; } CrearDoc = true; contador = 1; bool[] retorno = generar.LuzCamaraAccion(); if (!retorno[0] && !retorno[1]) { if (!retorno[0]) { Msj = "Error al intentar generar el encabezado del documento"; } if (!retorno[1]) { Msj = "Error al intentar ingresar un item"; } break; } } else if (contador == total) { bool[] retorno = generar.LuzCamaraAccion(); if (!retorno[0] && !retorno[1]) { if (!retorno[0]) { Msj = "Error al intentar generar el encabezado del documento"; } if (!retorno[1]) { Msj = "Error al intentar ingresar un item"; } break; } else { Msj = "El consumo ha sido creado exitosamente con la(s) siguiente(s) " + _TIDO + ": " + string.Join(", ", DocList); } } else { CrearDoc = false; contador++; } } ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "myalert", "alert('" + Msj + "'); window.location='" + Page.ResolveUrl("~/View/Planificacion/Consumo.aspx") + "';", true); }