public override CONStructureDetail Execute(CONStructureDetail data, Actions action, Options option, string token) { try { if (action == Actions.Add || action == Actions.Modify || action == Actions.Remove || (action == Actions.Find && (option == Options.Me || option == Options.Exist))) { if ((action == Actions.Add || action == Actions.Modify) && option == Options.All) { BenginTransaction(); cONSQLDetailDl = new CONSQLDetailBLL(Work); } data = base.Execute(data, action, option, token); if (action == Actions.Find && option == Options.Me) { cONSQLDetailDl = new CONSQLDetailBLL(this.Work.Settings); data.SQLDetails = cONSQLDetailDl.FindAll(new CONSQLDetail { StructureDetailId = data.Id }, Options.All); } if ((action == Actions.Add || action == Actions.Modify) && option == Options.All) { AddDetails(data); } //if (option == Options.All) // Work.Commit(); return(data); } else if (action == Actions.Find && (option == Options.All || option == Options.Light)) { if (option == Options.All) { data.Entities = FindAll(data, Options.All); } else if (option == Options.Light) { data.Entities = FindAll(data, Options.Light); } return(data); } else { throw new NotImplementedException(GetLocalizedMessage(Language.DLACTIONNOTIMPLEMENT, action.ToString(), option.ToString())); } } catch (FaultException <BusinessException> f) { Rollback(); throw f; } catch (Exception e) { Rollback(); throw new BusinessException(e).GetFaultException(); } finally { Commit(); } }
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(); } }