private string GetDbTypeField(DataTable tb, int ColumnIndex) { string type = ""; if (tb.Columns[ColumnIndex].DataType == typeof(string)) { if (tb.Columns[ColumnIndex].MaxLength < 10) { type = string.Format("CHAR({0})", tb.Columns[ColumnIndex].MaxLength); } else if (tb.Columns[ColumnIndex].MaxLength >= 65535) { type = this.DefaultBigText; } else { type = string.Format("VARCHAR({0})", tb.Columns[ColumnIndex].MaxLength); } } else { type = DbScriptTypeList.GetDbScriptType(tb.Columns[ColumnIndex].DataType); } string s_NotNull = tb.Columns[ColumnIndex].AllowDBNull ? "" : " NOT NULL"; string PrimaryKey = IsPrimaryKey(tb.PrimaryKey, tb.Columns[ColumnIndex].ColumnName) ? " primary key" : ""; string AutoIncrement = tb.Columns[ColumnIndex].AutoIncrement ? " " + cnn.dbu.CmdAutoIncrement.ToUpper() : ""; return(type + s_NotNull + PrimaryKey + AutoIncrement); }
private void AtribuiCampos(int Row, DataSource ds, string[] Exceptions, bool UpdateMode) { #region Campos for (int j = 0; j < ds.Columns.Count; j++) { string col_name = ds.Columns[j].ColumnName; if (ExistsInList(Exceptions, col_name)) { continue; } //enmFieldType ft = cnn.dbu.GetFieldType(ds.Columns[j].DataType); enmFieldType ft = DbScriptTypeList.GetFieldType(ds.Columns[j].DataType); //Não atribui campos quando são valores default //para não dar problemas com chaves estrangeiras if (ds.GetField(Row, col_name) == null) { sb.AddField(col_name, null); continue; } // Precisa corrigir esta linha , está travada para colocar todos os campos no insert UpdateMode = true; switch (ft) { case enmFieldType.Int: { int Val = ds.GetField(Row, col_name).ToInt(); if (Val != 0 || UpdateMode) { sb.AddField(col_name, Val); } break; } case enmFieldType.Long: { long Val = ds.GetField(Row, col_name).ToLong(); if (Val != 0 || UpdateMode) { sb.AddField(col_name, Val); } break; } case enmFieldType.Decimal: { decimal Val = ds.GetField(Row, col_name).ToDecimal(); if (Val != 0 || UpdateMode) { sb.AddField(col_name, Val); } break; } case enmFieldType.DateTime: { DateTime val = ds.GetField(Row, col_name).ToDateTime(); if (val == DateTime.MinValue) { if (UpdateMode) { sb.AddField(col_name, null); } break; } bool IsDate = val.ToString("dd/MM/yyyy") != DateTime.MinValue.ToString("dd/MM/yyyy"); bool IsTime = val.ToString("HH:mm:ss") != "00:00:00"; if (IsDate && IsTime) { sb.AddField(col_name, val, enmFieldType.DateTime); break; } else if (IsDate && !IsTime) { sb.AddField(col_name, val, enmFieldType.Date); break; } else if (!IsDate && IsTime) { sb.AddField(col_name, val, enmFieldType.Time); break; } break; } case enmFieldType.Bool: { bool Val = ds.GetField(Row, col_name).ToBool(); if (Val != false || UpdateMode) { sb.AddField(col_name, Val); } break; } default: { if (!string.IsNullOrEmpty(col_name) || UpdateMode) { string Val = ds.GetField(Row, col_name).ToString(); if (!string.IsNullOrEmpty(Val)) { Val = Val.Trim(); } sb.AddField(col_name, Val); } break; } } } #endregion }