protected string BuilderParse(ParamUpdate param) { var data = param.GetData(); var tableName = data.Update.Length == 0 ? typeof(T).Name : data.Update; GetTableSchema(tableName); var sqlCols = new StringBuilder(); var dict = GetPersonDateForUpdate(); foreach (var column in data.Columns.Where(column => !dict.ContainsKey(column.Key.ToUpper()))) { var colData = ColumnSchema.FirstOrDefault(s => s.ColumnName.ToUpper() == column.Key.ToUpper()); if (colData == null) { continue; } if (column.Value == null) { sqlCols.AppendFormat("{0} = NULL,", column.Key); } else { sqlCols.AppendFormat("{0}={1},", column.Key, FormatParamValue(column.Value, colData.SqlTypeName)); } } //var properties = Utils.ZReflection.GetProperties(typeof(T)); foreach (var item in dict) { var colData = ColumnSchema.FirstOrDefault(s => s.ColumnName.ToUpper() == item.Key.ToUpper()); if (colData == null) { continue; } var updateValue = ""; if (data.Columns.ContainsKey(item.Key) && data.Columns[item.Key] != null && data.Columns[item.Key].ToString() != "") { //更新数据中包含UpdateDate值,且不为null,则使用数据中的值,否则取当前时间 updateValue = APP.DbProvider == DbProviderEnum.SqlServer ? string.Format("'{0}'", data.Columns[item.Key]) : string.Format( item.Key.ToUpper() == APP.FIELD_UPDATE_DATE ? "to_date('{0}' , 'yyyy-mm-dd hh24:mi:ss')" : "'{0}'", data.Columns[item.Key]); } sqlCols.AppendFormat("{0}={1},", item.Key, updateValue == "" ? item.Value : updateValue); } var updateSql = string.Format("UPDATE {0} SET {1} WHERE {2}", tableName, sqlCols.Remove(sqlCols.Length - 1, 1), data.WhereSql); return(updateSql); }
public ParamUpdate ToParamUpdate() { var settings = XElement.Parse(settingXml); var pUpdate = ParamUpdate.Instance().Update(getXmlElementValue(settings, "table")); var list = new List <string>(); ParseWhere(settings, (name, value, compare, variable, extend) => { pUpdate.AndWhere(name, value, compare, extend); list.Add(variable); }); parseColumns(settings, (name, value) => { if (list.IndexOf(name) < 0) { pUpdate.Column(name, value); } }); return(pUpdate); }