Example #1
0
        //判断根节点是否相同,相同返回false,否则为true,带出相同的根节点ID
        public bool Get(Model.Project_Space model, out int getID)
        {
            int     sid     = 0;
            string  getName = "select * from Project_Space  where isChild=0";
            DataSet ds      = DbHelperSQL.Query(getName);
            bool    isExist = true;

            for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
            {
                if (ds.Tables[0].Rows[i]["name"].ToString() == Convert.ToString(model.Ps1name))
                {
                    isExist = false;
                    sid     = Convert.ToInt32(ds.Tables[0].Rows[i]["sid"]);

                    break;
                }
            }

            getID = sid;
            return(isExist);
        }
Example #2
0
        /*
         * /// <summary>
         * /// 分页获取数据列表
         * /// </summary>
         * public DataSet GetList(int PageSize,int PageIndex,string strWhere)
         * {
         *  SqlParameter[] parameters = {
         *          new SqlParameter("@tblName", SqlDbType.VarChar, 255),
         *          new SqlParameter("@fldName", SqlDbType.VarChar, 255),
         *          new SqlParameter("@PageSize", SqlDbType.Int),
         *          new SqlParameter("@PageIndex", SqlDbType.Int),
         *          new SqlParameter("@IsReCount", SqlDbType.Bit),
         *          new SqlParameter("@OrderType", SqlDbType.Bit),
         *          new SqlParameter("@strWhere", SqlDbType.VarChar,1000),
         *          };
         *  parameters[0].Value = "Project_Space";
         *  parameters[1].Value = "sid";
         *  parameters[2].Value = PageSize;
         *  parameters[3].Value = PageIndex;
         *  parameters[4].Value = 0;
         *  parameters[5].Value = 0;
         *  parameters[6].Value = strWhere;
         *  return DbHelperSQL.RunProcedure("UP_GetRecordByPage",parameters,"ds");
         * }*/

        #endregion  BasicMethod
        #region  ExtensionMethod


        /// <summary>
        ///
        /// </summary>
        /// <param name="insertList"></param>
        /// <param name="updateList"></param>
        /// <param name="delList"></param>
        /// <param name="psid">项目ID project</param>
        /// <returns></returns>
        public string Edit(List <Model.Project_Space> insertList, List <Model.Project_Space> updateList, List <Model.Project_Space> delList, List <Model.Project_Space> allList, int psid)
        {
            try
            {
                ArrayList     al    = new ArrayList();
                StringBuilder sbSql = new StringBuilder();
                //删除
                for (int i = 0; i < delList.Count; i++)
                {
                    sbSql = new StringBuilder();
                    Model.Project_Space model = delList[i];
                    sbSql.Append("delete from Project_Space where sid=" + model.Ps2sid + ";");
                    al.Add(sbSql.ToString());
                }

                //修改
                int sequence = 0;
                for (int i = 0; i < allList.Count; i++)
                {
                    sbSql = new StringBuilder();
                    Model.Project_Space model = allList[i];

                    if (allList[i].Ps1name != "")
                    {
                        if (allList[i].Ps1isChild == 0)
                        {
                            sbSql.Append("update Project_Space set name = '" + model.Ps1name.Trim() + "',sequence='" + 0 + "'");
                            sbSql.Append(" where sid = '" + model.Ps1sid + "'");
                            al.Add(sbSql.ToString());
                        }
                    }
                    if (allList[i].Ps1name != "")
                    {
                        if (i > 1)
                        {
                            if (allList[i].Ps1name != allList[i - 1].Ps1name)
                            {
                                sequence       = 1;
                                model.sequence = sequence;
                                sbSql.Append("update Project_Space set name = '" + model.Ps2name.Trim() + "',sequence='" + model.sequence + "'");
                                sbSql.Append(" where sid = '" + model.Ps2sid.ToString().Trim() + "'");
                                al.Add(sbSql.ToString());
                            }
                            else
                            {
                                sequence      += 1;
                                model.sequence = sequence;
                                sbSql.Append("update Project_Space set name = '" + model.Ps2name.Trim() + "',sequence='" + model.sequence + "'");
                                sbSql.Append(" where sid = '" + model.Ps2sid.ToString().Trim() + "'");
                                al.Add(sbSql.ToString());
                            }
                        }
                        else
                        {
                            sequence      += 1;
                            model.sequence = sequence;
                            sbSql.Append("update Project_Space set name = '" + model.Ps2name.Trim() + "',sequence='" + model.sequence + "'");
                            sbSql.Append(" where sid = '" + model.Ps2sid.ToString().Trim() + "'");
                            al.Add(sbSql.ToString());
                        }
                    }
                }

                ArrayList ar  = new ArrayList();
                int       n   = 0;
                int       num = 1; //计数器


                //添加
                int getID = 0;
                for (int i = 0; i < insertList.Count; i++)
                {
                    Model.Project_Space model = insertList[i];

                    //判断空间名字是否已经存在,true为不存在,否则不插入根节点
                    //Ps1name为根节点,Ps2name为子节点
                    if (insertList[i].Ps1name != "" && Get(insertList[i], out getID) == true)
                    {
                        //添加父类数据
                        sbSql = new StringBuilder();
                        sbSql.Append("insert into Project_Space(name,p_sid,sequence,parentID,isChild");
                        sbSql.Append(")values(");
                        sbSql.Append("'" + model.Ps1name.Trim() + "','" + psid + "',0,'" + model.parentID + "',0");
                        sbSql.Append(");select @@IDENTITY ");
                        ar.Add(DbHelperSQL.GetSingle(sbSql.ToString()));
                    }

                    if (model.Ps2name != "" && Get(insertList[i], out getID) == true)
                    {
                        //添加子类数据
                        sbSql = new StringBuilder();
                        sbSql.Append("insert into Project_Space(name,p_sid,sequence,parentID,isChild");
                        sbSql.Append(")values(");
                        sbSql.Append("'" + model.Ps2name.Trim() + "','" + psid + "'," + 0 + ",'" + ar[i] + "',1");
                        sbSql.Append(")");
                        al.Add(sbSql.ToString());
                    }
                    else
                    {
                        //添加子类数据
                        sbSql = new StringBuilder();
                        sbSql.Append("insert into Project_Space(name,p_sid,sequence,parentID,isChild");
                        sbSql.Append(")values(");
                        sbSql.Append("'" + model.Ps2name + "','" + psid + "'," + num++ + ",'" + getID + "',1");
                        sbSql.Append(")");
                        al.Add(sbSql.ToString());
                    }
                }

                DbHelperSQL.ExecuteSqlTran(al);

                return("success");
            }
            catch (Exception exc)
            {
                return(exc.Message);
            }
        }