Exemplo n.º 1
0
        public void Update(Log item)
        {
            if(item.ChangedPropertyCount>0)
                {
                    StringBuilder sqlbuilder = new StringBuilder();
                    sqlbuilder.Append("UPDATE [Logs] SET ");
                    Dictionary<string,string> cols =new Dictionary<string,string>();
                    cols.Add("Content","[Content]");
                    cols.Add("OperateCode","[OperateCode]");
                    cols.Add("LogType","[LogType]");
                    cols.Add("OperateUID","[OperateUID]");
                    cols.Add("OperateName","[OperateName]");
                    cols.Add("IPAddress","[IPAddress]");
                    cols.Add("OperateTime","[OperateTime]");
                    int i = 0;
                    //UPDATE COLUMNS
                    foreach (string p in item.ChangedPropertyList)
                    {
                        if(!cols.ContainsKey(p))
                        {
                            continue;
                        }
                        if (i > 0)
                        {
                            sqlbuilder.Append(",");
                        }
                        sqlbuilder.AppendFormat("{0}=@{1}", cols[p], p);
                        i++;
                    }
                    //WHERE;
                    sqlbuilder.Append(" WHERE [Id]=@Id");

                    List<SqlParameter> SPParams = new List<SqlParameter>();
                     SPParams.Add(new SqlParameter("@Id",item.Id));

                    if(item.IsChanged("Content"))
                    {
                        SPParams.Add(new SqlParameter("@Content",item.Content));
                    }
                    if(item.IsChanged("OperateCode"))
                    {
                        SPParams.Add(new SqlParameter("@OperateCode",item.OperateCode));
                    }
                    if(item.IsChanged("LogType"))
                    {
                        SPParams.Add(new SqlParameter("@LogType",item.LogType));
                    }
                    if(item.IsChanged("OperateUID"))
                    {
                        SPParams.Add(new SqlParameter("@OperateUID",item.OperateUID));
                    }
                    if(item.IsChanged("OperateName"))
                    {
                        SPParams.Add(new SqlParameter("@OperateName",item.OperateName));
                    }
                    if(item.IsChanged("IPAddress"))
                    {
                        SPParams.Add(new SqlParameter("@IPAddress",item.IPAddress));
                    }
                    if(item.IsChanged("OperateTime"))
                    {
                        SPParams.Add(new SqlParameter("@OperateTime",item.OperateTime));
                    }
                    base.ExecuteNonQuery(sqlbuilder.ToString(), SPParams.ToArray());
                }
        }