/// <summary> /// Pega o comando de atualização /// </summary> /// <returns>Um DbCOmmand</returns> protected Tuple <string, List <TableAdapterField> > GetUpdateCommand() { var fields = new StringBuilder(); foreach (var column in Collumns.Where(p => !p.Key)) { fields.Append(fields.Length > 0 ? " , " : " "); fields.AppendLine("" + SetQuote(column.Name) + " = @" + column.Name + ""); } if (fields.Length == 0) { return(null); } var query = new StringBuilder(); query.AppendLine(" Update " + MakeFullTableName(DBName, TableName) + " SET "); query.AppendLine(fields.ToString()); query.AppendLine(" "); query.AppendLine(GetWhereCommand()); return(new Tuple <string, List <TableAdapterField> >( query.ToString(), GetParameters(Collumns) )); }
/// <summary> /// PReenche as colunms da atbela de acordo com as Campos TableAdapterFields /// Instanciano na classe base /// </summary> private void FillCollumns() { Collumns = TableAdapterColumns.GetCollumns(this); foreach (var item in Collumns.Where(c => c.Key)) { KeyFields.Add(item); } StateRecord = eState.eAdd; }
/// <summary> /// Pega o camando delete /// </summary> /// <returns>Um DbComando com o camando para excluir</returns> protected Tuple <string, List <TableAdapterField> > GetDeleteCommand() { var columns = Collumns.Where(p => p.Key).ToList(); var query = new StringBuilder(); query.AppendLine(" DELETE FROM " + MakeFullTableName(DBName, TableName) + " "); query.AppendLine(GetWhereCommand()); return(new Tuple <string, List <TableAdapterField> >( query.ToString(), GetParameters(columns))); }
/// <summary> /// Pega o comando de inserção /// </summary> /// <returns>Um Db command preenchiodo</returns> protected Tuple <string, List <TableAdapterField> > GetInsertCommand() { var fields = new StringBuilder(); var values = new StringBuilder(); var columns = Collumns.Where(p => !p.Identity && p.Value != null).ToList(); foreach (var column in columns) { if (fields.Length > 0) { fields.Append(" , "); values.Append(" , "); } else { fields.Append(" "); values.Append(" "); } fields.AppendLine(SetQuote(column.Name)); values.AppendFormat("@{0}", column.Name); } if (fields.Length == 0) { throw new Exception(string.Format("Não há campos definidos para o objeto [{0}]", this)); } var query = new StringBuilder(); query.AppendLine(" INSERT INTO " + MakeFullTableName(DBName, TableName) + " ( "); query.AppendLine(fields.ToString()); query.AppendLine(") VALUES ("); query.AppendLine(values.ToString()); query.AppendLine(") "); var parameters = GetParameters(columns); return(new Tuple <string, List <TableAdapterField> >( query.ToString(), parameters)); }