Beispiel #1
0
        public FaultException <BusinessException> GetBusinessException()
        {
            BusinessException exception = new BusinessException("Validaciones de Negocio");

            foreach (string item in ExceptionMessages)
            {
                exception.AppMessageDetails.Add(item);
            }
            return(exception.GetFaultException());
        }
Beispiel #2
0
        public CONSQLDetail GetColumnsFromSQL(CONSQLDetail data)
        {
            MappingRules(data.SQL);
            if (!HasErrors)
            {
                Database              daacess           = new Database(UtilBLL.GetConnectionString(data.SQL.Connection), UtilBLL.GetConnectionDBType(data.SQL.Connection.DbType));
                SECConnectionBLL      dlConnection      = new SECConnectionBLL(Work.Settings);
                CONStructureDetailBLL dlStructureDetail = new CONStructureDetailBLL(Work.Settings);

                cONSQLDetailDl      = new CONSQLDetailBLL(Work.Settings);
                data.SQL.Connection = dlConnection.FindById(data.SQL.Connection);
                if (data.SQL != null && data.SQL.Id != 0 && !data.SQL.GenerateFile)
                {
                    List <CONSQLDetail> details = cONSQLDetailDl.FindAll(new CONSQLDetail {
                        SQL = data.SQL
                    }, Options.All);
                    foreach (CONSQLDetail item in details)
                    {
                        cONSQLDetailDl.Remove(item);
                    }
                }
                ResultList          result  = daacess.ExecuteQuery(data.SQL.SQLSentence, new List <SQLParameter>(), 1);
                List <CONSQLDetail> columns = new List <CONSQLDetail>();
                if (result.GetColumns() != null && result.GetColumns().Count > 0)
                {
                    for (int i = 0; i < result.GetColumns().Count; i++)
                    {
                        CONSQLDetail sqlColumn = new CONSQLDetail();
                        sqlColumn.Secuence = Int16.Parse(i.ToString());
                        sqlColumn.Field    = result.GetColumnName(i);
                        sqlColumn.DBType   = result.GetColumnType(i);
                        columns.Add(sqlColumn);
                    }
                }
                data.SQL.Structure.StructureDetails = dlStructureDetail.FindAll(new CONStructureDetail {
                    Structure = data.SQL.Structure
                }, Options.All);
                if (data.SQL.Structure.StructureDetails != null && data.SQL.Structure.StructureDetails.Count > 0)
                {
                    foreach (CONSQLDetail item in columns)
                    {
                        CONStructureDetail sDetail = data.SQL.Structure.StructureDetails.FirstOrDefault(x => x.Field.ToUpper() == item.Field.ToUpper());
                        if (data != null)
                        {
                            item.StructureDetail = sDetail;
                        }
                    }
                    if (columns.Count() < (data.SQL.Structure.StructureDetails.Count() - 4) && !data.SQL.GenerateFile)
                    {
                        string message = " Las columnas Pendientes de Mapeo son: \n";

                        List <CONStructureDetail> pending = new List <CONStructureDetail>();
                        for (int i = 4; i < data.SQL.Structure.StructureDetails.Count(); i++)
                        {
                            var exist = columns.FirstOrDefault(x => x.StructureDetail.Field.ToUpper() == data.SQL.Structure.StructureDetails[i].Field.ToUpper());
                            if (exist == null && data.SQL.Structure.StructureDetails[i].Visible)
                            {
                                pending.Add(data.SQL.Structure.StructureDetails[i]);
                            }
                        }

                        if (pending.Count > 0)
                        {
                            foreach (var item in pending)
                            {
                                message += item.Field + ",\n";
                            }
                            throw new Exception("La consulta SQL no tiene el nro de columnas minimo requerido. Nro Minimo de Columnas = " + (data.SQL.Structure.StructureDetails.Count()) + "\n" + message.ToUpper());
                        }
                    }
                }

                //List<CONStructureDetail> pendingMapping = new List<CONStructureDetail>();

                //foreach (CONStructureDetail item in data.SQL.Structure.StructureDetails)
                //{
                //    CONSQLDetail exist = columns.FirstOrDefault(x => x.StructureDetail.Id == item.Id);
                //    if (exist == null && item.Visible)
                //        pendingMapping.Add(item);
                //}
                //if (pendingMapping.Count > 0)
                //{
                //    data.ServerMessage = "Falta por mapear las columnas: ";
                //    foreach (CONStructureDetail item in pendingMapping)
                //    {
                //        data.ServerMessage += item.Field + ", ";
                //    }
                //    data.ServerMessage += "Por favor verifique e intente de nuevo.";
                //}
                data.Entities = columns;
                return(data);
            }
            else
            {
                Work.Rollback();
                BusinessException exception = new BusinessException(GetLocalizedMessage(Language.DLBUSINESSEXCEPTION));
                foreach (string item in ExceptionMessages)
                {
                    exception.AppMessageDetails.Add(item);
                }
                throw exception.GetFaultException();
            }
        }