mardi 5 mai 2015

Using of goto statement logic is not a good idea in .Net tech ..? [on hold]

I used goto statement to access a logic in my project. but my TL told this is not good sound of writing code, you have to change your logic in that project.

so i asked you experts give a suggestion which one is correct.

and my code is

For Each gvrow As GridViewRow In GrdView.Rows
                chk = DirectCast(gvrow.FindControl("chk_Artid"), CheckBox)
                lblArtId = DirectCast(gvrow.FindControl("lblArtId"), LinkButton)
                txtRemarks = DirectCast(gvrow.FindControl("txtRemarks"), TextBox)
                lblIss = DirectCast(gvrow.FindControl("lblIss"), Label)
                txtNumofFigures = DirectCast(gvrow.FindControl("txtNumofFigures"), TextBox)
                lblstage = DirectCast(gvrow.FindControl("lblstage"), Label)
                lblArtStageTypeID = DirectCast(gvrow.FindControl("hdnArtStageTypeID"), HiddenField)
                grph_Val = Is_graph_Update(lblstage.Text)
                If ViewState("chk_updt") = 1 Then    '''' IssueLevel Update
                    If chk.Checked = True Then
                        chk_Set = True
                        If txtNumofFigures.Text <> "" Then
                            If txtRemarks.Text <> "" Then

                                strQuery = "select Instruction from " & Init_Tables.gTblSplInstructions & " where AutoArtID='" & lblArtId.Text & "' and Iss='" & lblIss.Text & "' "
                                dt = RecordManager.GetRecord_Multiple_All(strQuery, "Temptable")
                                If dt.Rows.Count > 0 Then
                                    strQuery = "Update " & Init_Tables.gTblSplInstructions & " Set Instruction='" & txtRemarks.Text & "',EmpAutoID='" & SessionHandler.sUsrID & "' where AutoArtID='" & lblArtId.Text & "' and Iss='" & lblIss.Text & "' "
                                Else
                                    strQuery = "Insert into " & Init_Tables.gTblSplInstructions & " (AutoArtID,Iss,Stage,Instruction,DeptCode,InstDate,EmpAutoID) values('" & lblArtId.Text & "','" & lblIss.Text & "','" & lblstage.Text & "', '" & txtRemarks.Text & "', '|90|', '" & Format(Date.Now, "dd-MMM-yy") & " " & Date.Now.ToLongTimeString & "','" & SessionHandler.sUsrID & "')"
                                End If

                                StrUpdateQuery = "Update " & Init_Tables.gTblIssueInfo & " set Remarks='1' ,CorrFigs='" & txtNumofFigures.Text & "',Grapstatus=NULL,GraphArtStageTypeID=NULL where JBM_AutoID='" & lblArtId.Text & "' and RevFinStage like '%" & lblstage.Text & "%' and iss='" & lblIss.Text & "'"

                                RecordManager.UpdateRecord(strQuery)
                                RecordManager.UpdateRecord(StrUpdateQuery)
                                RecordManager.DeleteRecord("delete from " & Init_Tables.gTblJBM_Allocation & " where autoartid='" & lblArtId.Text & "' and Stage='" & lblstage.Text & "' and DeptCode=90 and status='0' and iss='" & lblIss.Text & "'")
                            Else
                                lblStatus.Text = "Enter any remarks."
                                Return
                            End If
                        Else
                            lblStatus.Text = "Enter the No.of figs."
                            Return
                        End If
                        GoTo Next_stage
                    End If


  End If
            Next

    Next_stage:

            For Each li As ListItem In chkArticle.Items   '' bala 30-mar-2015
                ChapterID = li.Text
                'qry = "select  * from  " & Init_Tables.gTblChapterInfo & " where JBM_AutoID='" & ViewState("lblArtId").ToString() & "'  and ChapterID='" & ChapterID & "'"
                qry = "select  * from  " & Init_Tables.gTblChapterInfo & " where JBM_AutoID='" & lblArtId.Text & "'  and ChapterID='" & ChapterID & "'"
                dt = RecordManager.GetRecord_Multiple_All(qry, "Temptable")

                If dt.Rows.Count > 0 Then
                    Autoart_ID = dt.Rows(0)("AutoArtID")
                End If

                If li.Selected = True Then
                    chk_Set_chapter = True

                    qry = " select * from JBM_ProdTempStatus where  AutoArtID ='" & Autoart_ID & "'"
                    dt.Rows.Clear()
                    dt = RecordManager.GetRecord_Multiple_All(qry, "JBM_ProdTempStatus")

                    If dt.Rows.Count > 0 Then
                        ''Update

                        qry = "Update JBM_ProdTempStatus set EmpAutoID='" & SessionHandler.sUsrID & "' ,  ProcessedDate='" & Format(DateTime.Now, "dd-MMM-yy hh:mm:ss") & "',Grapstatus=NULL  where  AutoArtID ='" & Autoart_ID & "'"
                        RecordManager.UpdateRecord(qry)
                    Else
                        ''Insert

                        qry = "insert into JBM_ProdTempStatus(EmpAutoID,AutoArtID,EmpArtStage,gProcess,nFigs,ProcessedDate,Jbm_AutoID,iss,Stage,ArtStageTypeID) values('" & SessionHandler.sUsrID & "' ,'" & Autoart_ID & "','" & Init_Barcode.gstrGraphics & "','GS03' ,'" & txtNumofFigures.Text & "','" & Format(DateTime.Now, "dd-MMM-yy hh:mm:ss") & "','" & lblArtId.Text & "'," & IIf(lblIss.Text = "", "NULL", "'" & lblIss.Text & "'") & ",'" & lblstage.Text.Trim() & "','" & lblArtStageTypeID.Value & "') "
                        RecordManager.UpdateRecord(qry)
                    End If


                    '  RecordManager.UpdateRecord(strQuery)
                ElseIf li.Selected = False Then
                    '' Delete

                    qry = "Delete from JBM_ProdTempStatus where  AutoArtID ='" & Autoart_ID & "' and JBM_AutoID='" & lblArtId.Text & "' "

                    RecordManager.UpdateRecord(qry)
                End If
            Next

Aucun commentaire:

Enregistrer un commentaire