问题描述
protectedvoidDDlMore_SelectedIndexChanged(objectsender,EventArgse){intnum=0;stringmsg="";stringexperienceID="";SessionLoginlogin=base.Session["Login"]asSessionLogin;RegScriptscript=newRegScript(this.Page);for(inti=0;i<this.GridView1.Rows.Count;i++){stringstr9;CheckBoxbox=(CheckBox)this.GridView1.Rows[i].FindControl("CheckBox3");experienceID=this.GridView1.DataKeys[i].Value.ToString();int.Parse(newExperience().GetStatuByExperienceID(experienceID));if(box.Checked&&((str9=this.DDlMore.SelectedValue)!=null)){if(!(str9=="Lock")){if(str9=="UnLock"){gotoLabel_017C;}if(str9=="Move"){gotoLabel_0205;}if(str9=="collection"){gotoLabel_0476;}}else{this.pType=PowerType.DocumentLock;try{num++;if(login.MType!=0){if(!this.pow.HasFilePower(login.Id,experienceID,this.pType)){msg="您无权限执行此操作!";}else{newExperience().LockDocument(experienceID);msg="锁定成功!";}}else{newExperience().LockDocument(experienceID);msg="锁定成功!";}}catch(Exceptionexception){base.Response.Write("<script>alert('"+exception.Message+"');</script>");}}}continue;Label_017C:this.pType=PowerType.DocumentLock;try{num++;if(login.MType!=0){if(!this.pow.HasFilePower(login.Id,experienceID,this.pType)){msg="您无权限执行此操作!";}else{newExperience().UnLockDocument(experienceID);msg="解锁成功!";}}else{newExperience().UnLockDocument(experienceID);msg="解锁成功!";}}catch(Exceptionexception2){base.Response.Write("<script>alert('"+exception2.Message+"');</script>");}continue;Label_0205:this.pType=PowerType.DocumentMove;stringstr4=string.Empty;num++;if(login.MType!=0){for(intj=0;j<this.GridView1.Rows.Count;j++){CheckBoxbox2=(CheckBox)this.GridView1.Rows[j].FindControl("CheckBox3");stringdocId=this.GridView1.DataKeys[j].Value.ToString();if(box2.Checked&&this.pow.HasFilePower(login.Id,docId,this.pType)){str4=str4+this.GridView1.DataKeys[j].Value.ToString()+",";}}if(str4.Length>1){str4=str4.Substring(0,str4.Length-1);}if(str4!=string.Empty){stringurl=string.Concat(newobject[]{"../Experience/Experienc_Move.aspx?catalogid=",this.HiddenField1.Value,"&catalogType=",1,"&ExperienceID=",str4});base.Response.Redirect(url);}else{msg="您无法移动所选文件!";}}else{experienceID=string.Empty;for(intk=0;k<this.GridView1.Rows.Count;k++){CheckBoxbox3=(CheckBox)this.GridView1.Rows[k].FindControl("CheckBox3");if(box3.Checked){experienceID=experienceID+this.GridView1.DataKeys[k].Value.ToString()+",";}}if(str4.Length>1){str4=str4.Substring(0,str4.Length-1);}if(str4!=string.Empty){stringstr7=string.Concat(newobject[]{"../Experience/Experienc_Move.aspx?catalogid=",this.HiddenField1.Value,"&catalogType=",1,"&ExperienceID=",str4});base.Response.Redirect(str7);}else{msg="您无法移动所选文件!";}}continue;Label_0476:try{num++;stringid=login.Id;msg="收藏成功!";CollectDocmentcollect=newCollectDocment();collect.Id=collect.CreateId();collect.CollectTime=DateTime.Now;collect.UserId=login.Id;collect.DocId=experienceID;collect.DocType=1;collect.Collect(collect);}catch(Exceptionexception3){base.Response.Write("<script>alert('"+exception3.Message+"');</script>");}}if(num==0){MessageBox.Show(this,"您还没有选择任何文档记录!");}else{MessageBox.Show(this,msg);}script.RegisterJS("reloadleft","parent.leftFrame.location.href='"+"../Experience/Experienc_Left.aspx"+"';");this.BindExperience();script.RegisterJS("reloadthis","window.location.href='Experience_Right.aspx?catalogId="+this.HiddenField1.Value+"';");}上面这段代码,为什么不同的ID也可以进行锁定和删除。希望给点提示啊,谢谢了
解决方案
解决方案二:
protectedvoidGridView1_RowDeleting(objectsender,GridViewDeleteEventArgse){try{stringexperienceID=this.GridView1.DataKeys[e.RowIndex].Value.ToString();this.s=base.Session["Login"]asSessionLogin;this.pType=PowerType.DocumentRemove;newExperience().GetCatalogIDByExperienceID(experienceID);stringstatuByExperienceID=newExperience().GetStatuByExperienceID(experienceID);if(this.s.MType!=0){if(!this.pow.HasFilePower(this.s.Id,experienceID,this.pType)){MessageBox.myShow(this,"delete","您无权限执行此操作!");}elseif(statuByExperienceID=="0"){if(newExperience().DeleteExperience(experienceID)){MessageBox.myShow(this,"delete2","删除成功!");}else{MessageBox.myShow(this,"delete3","删除失败!");}}else{MessageBox.myShow(this,"edit","文档已锁定!");}}elseif(newExperience().DeleteExperience(experienceID)){MessageBox.myShow(this,"delete2","删除成功!");}else{MessageBox.myShow(this,"delete3","删除失败!");}this.BindExperience();}catch(Exception){MessageBox.myShow(this,"exec","删除失败!");}}
解决方案三:
这能看出来什么,自己的逻辑自己加断点一步一步的调试呗。
解决方案四:
不要用goto,用switch{case}还有,代码太多,关键代码找不到在哪里你在哪里判断的某个id可以执行什么权限??
解决方案五:
一大堆代码,没有注释我宁愿你不要放代码,只把关键的注释放出来,看逻辑哪里有错误
解决方案六:
我试了,你看我在权限时,是当前登陆用户,并且是创建当前文档的人都正确时,才能删除或解锁该文件。可是现在所有人都能对该文件进行解锁和删除啊
解决方案七:
我就是想知道,我定义的权限判定是不是有问题。这段代码就是对文档的解锁和删除进行判断。如果是登陆者,并且是创建文档的人if(!this.pow.HasFilePower(this.s.Id,experienceID,this.pType)),那么就可以进行操作,不过现在成了只要是登陆者就可以删除和解锁
解决方案八:
每一项messagebox后面加上return否则对话框是弹出了,可是最后的this.BindExperience();还是要执行
解决方案:
如果需要return的地方太多你可以在最开始定义个bool变量,然后在if里给它赋值最后执行语句的时候判断这个变量
解决方案:
是这个原因吗?我试一试、非常感谢
解决方案:
但是我觉得这个return可写可不写吧。