zoukankan      html  css  js  c++  java
  • 添加新增 删除旧的 避免id自增过多

        /// <summary>
            
    ///  编辑关联分类 的属性 添加新值删除去掉的值
            
    /// </summary>
            
    /// <param name="IListNew">最新的分类信息</param>
            
    /// <returns>是否更新成功</returns>
            public bool Update(IList<CategoryAttributeInfo> IListNew, int categoryID)
            {
                IList
    <CategoryAttributeInfo> IListOld = new List<CategoryAttributeInfo>();//取出数据库里的分类
                IList<CategoryAttributeInfo> IListDel = new List<CategoryAttributeInfo>();//待删除的
                IList<CategoryAttributeInfo> IListAdd = new List<CategoryAttributeInfo>();//待添加的

                IListOld 
    = GetCategoryAttributeInfoList("CategoryID=" + categoryID, "");


                
    //对比取出 那些该删除 那些该添加
                foreach (CategoryAttributeInfo iListOld in IListOld)
                {
                    
    if (IListNew.Contains(iListOld))
                    {
                        IListNew.Remove(iListOld);
                    }
                    
    else
                    {
                        IListDel.Add(iListOld);
                    }

                }
                IListAdd 
    = IListNew;

                
    using (SqlTransaction sqlTran = SqlHelper.BeginTransaction())
                {
                    
    try
                    {
                        
    foreach (CategoryAttributeInfo CategoryAttributeInfo in IListDel)
                        {
                            SqlHelper.ExecuteNonQuery(sqlTran, 
    "delete  from t_CategoryAttribute where ID=" + CategoryAttributeInfo.ID, null);
                        }

                        
    //添加新增的 分类属性
                        foreach (CategoryAttributeInfo CategoryAttributeInfo in IListAdd)
                        {
                            Add(CategoryAttributeInfo);
                        }

                        sqlTran.Commit();
                        
    return true;

                    }
                    
    catch
                    {
                        sqlTran.Rollback();
                        
    return false;
                    }
                }

            }
  • 相关阅读:
    Nginx 利用 X-Accel-Redirect response.setHeader 控制文件下载
    Nginx 利用 X-Accel-Redirect response.setHeader 控制文件下载
    CentOS6.4 安装OpenResty和Redis 并在Nginx中利用lua简单读取Redis数据
    CentOS6.4 安装Sphinx 配置MySQL数据源
    在线编译
    Java 日期格式化工具类
    CentOS6.4 安装MongoDB
    yum安装高版本mysql(5.5)
    解决Windows Server 2003不认U盘或移动硬盘的问题
    配置tomcat日志分割
  • 原文地址:https://www.cnblogs.com/aaa6818162/p/1519836.html
Copyright © 2011-2022 走看看