예제 #1
0
        private void GuardaCambiosReporte(appreportes model)
        {
            appreportesRepository _appreportesRepository = new appreportesRepository();
              if (model.Id_centro == 0)
            model.Id_centro = null;

              if (model.Id_app_reporte == 0)
            _appreportesRepository.Create(model);
              else
              {
            _appreportesRepository.Edit(model);
            EditCurrentQuery(model);
              }
              string[] split = (model.selectedFiedls == null ? new string[0] : model.selectedFiedls.Split(new Char[] { ',' }));
              string[] splitWhere = (model.selectedFiedlsWhere == null ? new string[0] : model.selectedFiedlsWhere.Split(new Char[] { ',' }));
              string[] splitOrder = (model.selectedFiedlsOrder == null ? new string[0] : model.selectedFiedlsOrder.Split(new Char[] { ',' }));

              ///Guarda los campos de la instrucci[on select
              for (int i = 0; i < split.Length; i++)
              {
            int start = split[i].IndexOf("(");
            int end = split[i].IndexOf(")");
            string result = string.Empty;
            string srfuncion = string.Empty;

            if (start != -1 && end != -1)
            {
              result = split[i].Substring(start + 1, end - start - 1);
              srfuncion = split[i].Substring(0, start);
            }
            appReport_Fields _appReport_Fields = new appReport_Fields();
            _appReport_Fields.Id_app_reporte = model.Id_app_reporte;

            if (result != string.Empty)
            {
              string[] split2 = split[i].Trim().Split(new Char[] { '|' });
              if (split2.Length == 1)
              {
            _appReport_Fields.Campo = result.Trim();
            _appReport_Fields.Funcion = srfuncion.Trim();
              }
              else
              {
            _appReport_Fields.Campo = result.Trim();
            _appReport_Fields.Funcion = srfuncion.Trim();
            _appReport_Fields.VerTotal = 1;
              }

            }
            else
            {
              string[] split2 = split[i].Trim().Split(new Char[] { '|' });
              if (split2.Length == 1)
            _appReport_Fields.Campo = split[i].Trim();
              else
              {
            _appReport_Fields.Campo = split2[0].Trim();
            _appReport_Fields.VerTotal = 1;
              }
            }

            _appReport_Fields.Orden = i + 1;
            model.appReport_Fields.Add(_appReport_Fields);
              }

              List<appReport_Fields> campoIdCentro = model.appReport_Fields.Where(e => e.Campo == "Id_centro").ToList();

              //if (campoIdCentro.Count() == 0)
              //{
              //  if (model.tieneCentro == true)
              //  {
              //    model.appReport_Fields.Add(
              //    new appReport_Fields
              //    {
              //      Campo = "Id_centro"
              //    });

              //  }
              //}
              ///Guarda los campos condicionales
              for (int i = 0; i < splitWhere.Length; i++)
              {
            appReport_where _appReport_where = new appReport_where();

            _appReport_where.Id_app_reporte = model.Id_app_reporte;
            string[] splitWhereField = splitWhere[i].Split(new Char[] { '.' });
            _appReport_where.Campo = splitWhereField[1].Trim();
            _appReport_where.Condicion = splitWhereField[2].Trim();
            _appReport_where.TipoParametro = splitWhereField[3].Trim();
            _appReport_where.Operacion = splitWhereField[0].Trim();

            if (splitWhereField.Length == 5)
              _appReport_where.Ultimo_valor = splitWhereField[4].Trim();

            model.appReport_where.Add(_appReport_where);
              }
              for (int i = 0; i < splitOrder.Length; i++)
              {
            appReport_Order _appReport_Order = new appReport_Order();
            _appReport_Order.Id_app_reporte = model.Id_app_reporte;
            string[] splitOrderField = splitOrder[i].Trim().Split(new Char[] { ' ' });
            _appReport_Order.Campo = splitOrderField[0].Trim();

            if (splitOrderField.Length > 1)
              _appReport_Order.Tipo_orden = splitOrderField[1].Trim();
            else
              _appReport_Order.Tipo_orden = "ASC";

            _appReport_Order.Orden = i + 1;
            model.appReport_Order.Add(_appReport_Order);

            appReport_Fields _appReport_Fields2 = model.appReport_Fields.SingleOrDefault(e => e.Campo == _appReport_Order.Campo);

            if (_appReport_Fields2 == null)
            {
              appReport_Fields _appReport_Fields = new appReport_Fields();
              _appReport_Fields.Campo = splitOrderField[0].Trim();

              int countFields = 0;

              if (model.appReport_Fields != null)
            countFields = model.appReport_Fields.Count() + 1;
              else
            countFields = 1;

              _appReport_Fields.Orden = countFields;

              model.appReport_Fields.Add(_appReport_Fields);
            }
              }

              _appreportesRepository.Edit(model);

              _appreportesRepository.Commit();
              _appReport_whereRepository.Commit();
              _appReport_OrderRepository.Commit();
              _appReport_FieldsRepository.Commit();
        }