VERSION 5.00
Object = "{5E9E78A0-531B-11CF-91F6-C2863C385E30}#1.0#0"; "MSFLXGRD.OCX"
Begin VB.Form Quot_Line_View 
   BorderStyle     =   3  'Fixed Dialog
   ClientHeight    =   7455
   ClientLeft      =   240
   ClientTop       =   495
   ClientWidth     =   8160
   ClipControls    =   0   'False
   ControlBox      =   0   'False
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MinButton       =   0   'False
   PaletteMode     =   1  'UseZOrder
   ScaleHeight     =   7455
   ScaleWidth      =   8160
   ShowInTaskbar   =   0   'False
   Visible         =   0   'False
   Begin MSFlexGridLib.MSFlexGrid Grid 
      Height          =   855
      Left            =   1440
      TabIndex        =   22
      Top             =   5340
      Visible         =   0   'False
      Width           =   4395
      _ExtentX        =   7752
      _ExtentY        =   1508
      _Version        =   393216
      Cols            =   6
      FixedCols       =   0
      FocusRect       =   0
      HighLight       =   0
   End
   Begin VB.TextBox ssp_code 
      Alignment       =   2  'Center
      BackColor       =   &H0080FFFF&
      Height          =   300
      Left            =   1320
      TabIndex        =   20
      Top             =   7080
      Width           =   765
   End
   Begin VB.TextBox txt_Status 
      Height          =   315
      Left            =   5220
      Locked          =   -1  'True
      TabIndex        =   16
      TabStop         =   0   'False
      Top             =   0
      Width           =   2775
   End
   Begin VB.Frame Frame1 
      Height          =   75
      Left            =   0
      TabIndex        =   15
      Top             =   420
      Width           =   8115
   End
   Begin VB.ComboBox cbo_Version 
      Height          =   315
      Left            =   3660
      Style           =   2  'Dropdown List
      TabIndex        =   14
      Top             =   0
      Width           =   615
   End
   Begin VB.TextBox txt_QuotCode 
      Height          =   315
      Left            =   720
      Locked          =   -1  'True
      TabIndex        =   13
      TabStop         =   0   'False
      Top             =   0
      Width           =   1935
   End
   Begin VB.ListBox lst_AddLine 
      Height          =   840
      Left            =   6360
      TabIndex        =   12
      Top             =   1080
      Width           =   1500
   End
   Begin VB.PictureBox pic_next25 
      AutoSize        =   -1  'True
      Height          =   480
      Left            =   2220
      ScaleHeight     =   420
      ScaleWidth      =   420
      TabIndex        =   10
      Top             =   6960
      Width           =   480
   End
   Begin VB.PictureBox ButtonBox 
      Appearance      =   0  'Flat
      AutoRedraw      =   -1  'True
      AutoSize        =   -1  'True
      BackColor       =   &H80000005&
      ClipControls    =   0   'False
      BeginProperty Font 
         Name            =   "Arial"
         Size            =   8.25
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      ForeColor       =   &H80000008&
      Height          =   6675
      Left            =   7450
      ScaleHeight     =   6645
      ScaleWidth      =   630
      TabIndex        =   0
      Top             =   720
      Width           =   665
      Begin VB.PictureBox pic_Order 
         Appearance      =   0  'Flat
         AutoSize        =   -1  'True
         BackColor       =   &H00FFFFFF&
         BorderStyle     =   0  'None
         DrawStyle       =   5  'Transparent
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ForeColor       =   &H80000008&
         Height          =   480
         Left            =   60
         ScaleHeight     =   480
         ScaleWidth      =   480
         TabIndex        =   9
         Top             =   1800
         Width           =   480
      End
      Begin VB.PictureBox pic_quit 
         Appearance      =   0  'Flat
         AutoSize        =   -1  'True
         BackColor       =   &H00FFFFFF&
         BorderStyle     =   0  'None
         DrawStyle       =   5  'Transparent
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ForeColor       =   &H80000008&
         Height          =   480
         Left            =   60
         ScaleHeight     =   480
         ScaleWidth      =   480
         TabIndex        =   3
         Top             =   4200
         Width           =   480
      End
      Begin VB.PictureBox pic_add 
         Appearance      =   0  'Flat
         AutoSize        =   -1  'True
         BackColor       =   &H00FFFFFF&
         BorderStyle     =   0  'None
         DrawStyle       =   5  'Transparent
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ForeColor       =   &H80000008&
         Height          =   480
         Left            =   60
         ScaleHeight     =   480
         ScaleWidth      =   480
         TabIndex        =   7
         Top             =   40
         Width           =   480
      End
      Begin VB.PictureBox pic_upd 
         Appearance      =   0  'Flat
         AutoSize        =   -1  'True
         BackColor       =   &H00FFFFFF&
         BorderStyle     =   0  'None
         DrawStyle       =   5  'Transparent
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ForeColor       =   &H80000008&
         Height          =   480
         Left            =   60
         ScaleHeight     =   480
         ScaleWidth      =   480
         TabIndex        =   2
         Top             =   600
         Width           =   480
      End
      Begin VB.PictureBox pic_delete 
         Appearance      =   0  'Flat
         AutoSize        =   -1  'True
         BackColor       =   &H00FFFFFF&
         BorderStyle     =   0  'None
         DrawStyle       =   5  'Transparent
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ForeColor       =   &H80000008&
         Height          =   480
         Left            =   60
         ScaleHeight     =   480
         ScaleWidth      =   480
         TabIndex        =   6
         Top             =   1200
         Width           =   480
      End
      Begin VB.PictureBox pic_print 
         Appearance      =   0  'Flat
         AutoSize        =   -1  'True
         BackColor       =   &H00FFFFFF&
         BorderStyle     =   0  'None
         DrawStyle       =   5  'Transparent
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ForeColor       =   &H80000008&
         Height          =   480
         Left            =   60
         ScaleHeight     =   480
         ScaleWidth      =   480
         TabIndex        =   5
         Top             =   3000
         Visible         =   0   'False
         Width           =   480
      End
      Begin VB.PictureBox pic_log 
         Appearance      =   0  'Flat
         AutoSize        =   -1  'True
         BackColor       =   &H00FFFFFF&
         BorderStyle     =   0  'None
         DrawStyle       =   5  'Transparent
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ForeColor       =   &H80000008&
         Height          =   480
         Left            =   60
         ScaleHeight     =   480
         ScaleWidth      =   480
         TabIndex        =   4
         Top             =   2400
         Width           =   480
      End
      Begin VB.PictureBox pic_refresh 
         AutoSize        =   -1  'True
         BackColor       =   &H00FFFFFF&
         BorderStyle     =   0  'None
         DrawStyle       =   5  'Transparent
         Height          =   480
         Left            =   60
         ScaleHeight     =   480
         ScaleWidth      =   480
         TabIndex        =   1
         Top             =   3600
         Width           =   480
      End
   End
   Begin MSFlexGridLib.MSFlexGrid Grid2 
      Height          =   6255
      Left            =   0
      TabIndex        =   21
      Top             =   660
      Width           =   7395
      _ExtentX        =   13044
      _ExtentY        =   11033
      _Version        =   393216
      Cols            =   6
      FixedCols       =   0
      SelectionMode   =   1
      AllowUserResizing=   1
   End
   Begin VB.Label lbl_Code 
      Caption         =   "Code"
      Height          =   315
      Left            =   120
      TabIndex        =   19
      Top             =   60
      Width           =   615
   End
   Begin VB.Label lbl_Status 
      Caption         =   "Status"
      Height          =   315
      Left            =   4500
      TabIndex        =   18
      Top             =   60
      Width           =   615
   End
   Begin VB.Label lbl_Version 
      Caption         =   "Version"
      Height          =   315
      Left            =   2940
      TabIndex        =   17
      Top             =   60
      Width           =   735
   End
   Begin VB.Label lbl_MessageCount 
      Height          =   312
      Left            =   8640
      TabIndex        =   11
      Top             =   5820
      Visible         =   0   'False
      Width           =   552
   End
   Begin VB.Label lbl_Rcd 
      Height          =   315
      Left            =   60
      TabIndex        =   8
      Top             =   7020
      Width           =   1155
   End
End
Attribute VB_Name = "Quot_Line_View"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit

' gs_TableName is a string to handle special behaviour (e.g. = "Test_Overlay")
' gi_GridWidth(0..i..N) containt how large the column i must be displayed in the cmain window, 1 means that the column must'nt be displayed
'
Public mi_TopForm As Integer
Public mi_LeftForm As Integer

Dim mo_Fetch As Fetch

Dim mi_NbRows As Integer
Dim mi_Yav As Integer
Dim mb_ServerCursor As Boolean
Dim mb_AllowAdd As Boolean ' flag if the user can add new information
Dim mb_AllowUpd As Boolean ' flag if the user can update new information
Dim mb_AllowDel As Boolean ' flag if the user can delete new information
Dim ml_TotCount As Long

Private Sub FillLstAddLine()
    If lst_AddLine.ListCount > 0 Then Exit Sub
    
    lst_AddLine.AddItem "Comment line"
    lst_AddLine.ItemData(lst_AddLine.NewIndex) = 1
    If gut_Actor.MSC = OK Then
        lst_AddLine.AddItem "Existing item"
        lst_AddLine.ItemData(lst_AddLine.NewIndex) = 2
        lst_AddLine.AddItem "Metal item"
        lst_AddLine.ItemData(lst_AddLine.NewIndex) = 3
        lst_AddLine.AddItem "New item"
        lst_AddLine.ItemData(lst_AddLine.NewIndex) = 4
    End If
End Sub

Private Sub FillParm()
    Quot_Line_Mtnc.ms_QuotationLanguage = gs_QuotationLanguageCode
    Grid.Row = Grid2.Row
    Grid.Col = 0
    Quot_Line_Mtnc.mi_QuotCode = gi_QuotationCode
    Grid.Col = 1
    Quot_Line_Mtnc.mi_Version = gi_QuotationVersion
    Grid.Col = 2
    Quot_Line_Mtnc.mi_Line = CInt(Grid.Text)
    Grid.Col = 3
    Quot_Line_Mtnc.mi_iConcurrency = CInt(Grid.Text)
    Grid.Col = 4
    Quot_Line_Mtnc.ms_QLDesc = Grid.Text
    Grid.Col = 5
    Quot_Line_Mtnc.ms_Type = Grid.Text
    Grid.Col = 6
    Quot_Line_Mtnc.mi_Order = CInt(Grid.Text)
    Grid.Col = 7
    Quot_Line_Mtnc.ms_UMCode = Grid.Text
    Grid.Col = 8
    Quot_Line_Mtnc.ms_QLUpdQuantity = Grid.Text
    Grid.Col = 9
    Quot_Line_Mtnc.ms_QLStandardPrice = Grid.Text
    Grid.Col = 10
    Quot_Line_Mtnc.ms_QLPrice = Grid.Text
    Grid.Col = 11
    Quot_Line_Mtnc.ms_QLAmount = Grid.Text
    Grid.Col = 13
    Quot_Line_Mtnc.ms_QLLeadTime = Grid.Text
    Grid.Col = 14
    Quot_Line_Mtnc.ms_QLPromisedShipping = Grid.Text
    Grid.Col = 15
    Quot_Line_Mtnc.ms_QLPlannedProduction = Grid.Text
    Grid.Col = 16
    Quot_Line_Mtnc.ms_PlantCode = Grid.Text
    Grid.Col = 17
    Quot_Line_Mtnc.ms_PlantDesc = Grid.Text
    Grid.Col = 18
    Quot_Line_Mtnc.ms_PlantConfirmation = Grid.Text
    Grid.Col = 19
    Quot_Line_Mtnc.ms_OrderConfirmation = Grid.Text
    Grid.Col = 22
    Quot_Line_Mtnc.ms_QLQuantity = Grid.Text
    Grid.Col = 23
    Quot_Line_Mtnc.ms_CurrCode = Grid.Text
End Sub

Private Sub cbo_Version_Click()
    MouseOff
    If Quotation_UpdateCommonInformation(txt_Status, cbo_Version) = OK Then
        FillGrid
    End If
    
    CheckSecurityAdd
    pic_delete.Visible = KO
    pic_upd.Visible = KO
    
    MouseOn
End Sub

Private Sub Form_Load()
Dim li_Count As Integer

    On Error GoTo Form_Load_Err
    
    Me.Left = mi_LeftForm
    Me.Top = mi_TopForm
    
    MouseOff
    
    If gl_CodePage <> 1252 And gl_CodePage <> 0 Then ChangeCharset Me

    ml_TotCount = 0
    
    Set mo_Fetch = New Fetch
    mo_Fetch.EnvironmentIdentifier = gl_Environment
    mo_Fetch.DatabaseIdentifier = gl_Database
    
    If gi_QuotationStatusCode = Quotation_Status.Archived _
       Or gi_QuotationStatusCode = Quotation_Status.closed _
       Or gi_QuotationStatusCode = Quotation_Status.Old_Version Then
    
        pic_add.Visible = KO
    End If
    
    pic_upd.Visible = KO
    pic_delete.Visible = KO
    
    pic_upd.Picture = LoadResPicture(RES_MODIFY, 1)
    pic_add.Picture = LoadResPicture(RES_ADD, 1)
    pic_delete.Picture = LoadResPicture(RES_DELETE, 1)
    pic_log.Picture = LoadResPicture(RES_LOG, 1)
    pic_print.Picture = LoadResPicture(RES_PRINT, 1)
    pic_quit.Picture = LoadResPicture(RES_QUIT, 1)
    pic_refresh.Picture = LoadResPicture(RES_REFRESH, 1)
    pic_next25.Picture = LoadResPicture(RES_DOWN, 1)
    
    Grid.Cols = 30
    gut_LangWork = gut_LangLogin
    InitMainColumns
    Permission
    ShowOrder
    MainCsts
    lst_AddLine.Visible = KO
    
    CheckSecurityAdd
    pic_delete.Visible = KO
    pic_upd.Visible = KO
    
    FillLstAddLine
    
    gi_GridWidth(0) = 1
    gi_GridWidth(1) = 1
    gi_GridWidth(2) = 1
    gi_GridWidth(3) = 1
    gi_GridWidth(4) = 2500
    gi_GridWidth(5) = 1
    gi_GridWidth(6) = 1
    gi_GridWidth(7) = 500
    gi_GridWidth(8) = 1000
    gi_GridWidth(9) = 1
    gi_GridWidth(10) = 1200
    gi_GridWidth(11) = 1
    gi_GridWidth(12) = 1
    gi_GridWidth(13) = 1200
    gi_GridWidth(14) = 1
    gi_GridWidth(15) = 1
    gi_GridWidth(16) = 1
    gi_GridWidth(17) = 1200
    gi_GridWidth(18) = 1000
    gi_GridWidth(19) = 1000
    gi_GridWidth(20) = 1
    gi_GridWidth(21) = 1
    gi_GridWidth(22) = 1
    gi_GridWidth(23) = 1
    For li_Count = 24 To 29
        gi_GridWidth(li_Count) = 1
    Next li_Count
    'ATTENTION initfields generate click events on cbo_Version
    ' FillGrid becomes useless
    InitFields
    MouseOn
    Exit Sub
    
Form_Load_Err:
    StdError
End Sub

Private Sub Form_Unload(Cancel As Integer)

    Set mo_Fetch = Nothing
    
    gut_LangWork = gut_LangLogin

End Sub

Private Sub Grid2_Click()
    
    pic_upd.Visible = KO
    pic_delete.Visible = KO
    
    If gl_NbLineDisplay > 0 And Grid2.Row > 0 Then
        If Grid2.Row = mi_Yav Then
            Grid2.HighLight = flexHighlightNever
            Grid2.FocusRect = flexFocusHeavy
            Grid2.Col = 0
            Grid2.Row = 0
        Else
            Grid2.HighLight = flexHighlightAlways
            Grid2.FocusRect = flexFocusNone
            
            If gi_QuotationStatusCode = Quotation_Status.Archived _
               Or gi_QuotationStatusCode = Quotation_Status.closed _
               Or gi_QuotationStatusCode = Quotation_Status.Old_Version _
               Or gi_QuotationStatusCode = Quotation_Status.Customer_changes_Quotation Then
                pic_upd.Visible = KO
                pic_delete.Visible = KO
            Else
                If gut_Actor.MSC = OK Then
                    pic_upd.Visible = OK
                    pic_delete.Visible = OK
                Else
                    Grid.Row = Grid2.Row
                    Grid.Col = 5
                    If Grid.Text = "Comment" Then
                        pic_upd.Visible = OK
                        pic_delete.Visible = OK
                    Else
                        If gut_Actor.Plant = OK Then
                            pic_upd.Visible = OK
                        Else
                            If gut_Actor.COS = OK And gi_QuotationStatusCode = Quotation_Status.Enter_customer_order Then
                                pic_upd.Visible = OK
                            Else
                                pic_upd.Visible = KO
                            End If
                        End If
                        pic_delete.Visible = KO
                    End If
                End If
            End If
        End If
        mi_Yav = Grid2.Row
    Else
        Grid2.HighLight = flexHighlightNever
        Grid2.FocusRect = flexFocusHeavy
        mi_Yav = 0
    End If

End Sub
Private Sub Grid2_DblClick()

MouseOff
If Grid2.HighLight = flexHighlightAlways Then
    Quot_Line_Mtnc.ms_Action = "Detail"
    FillParm
    Quot_Line_Mtnc.show 1
End If
MouseOn

End Sub
Private Sub Grid2_KeyUp(KeyCode As Integer, Shift As Integer)

Grid2.HighLight = flexHighlightNever
Grid2.FocusRect = flexFocusHeavy
Grid2.Row = 0
Grid2.Col = 0
pic_upd.Visible = KO
pic_delete.Visible = KO
End Sub

Private Sub lst_AddLine_Click()

On Error GoTo suite

MouseOff
If lst_AddLine.ListIndex = -1 Then Exit Sub
lst_AddLine.Visible = KO

Select Case lst_AddLine.ItemData(lst_AddLine.ListIndex)
Case 1:
    Quot_Line_Mtnc.ms_Type = "Comment"
Case 2:
    Quot_Line_Mtnc.ms_Type = "BaseItem"
Case 3:
    Quot_Line_Mtnc.ms_Type = "Metal"
Case 4:
    Quot_Line_Mtnc.ms_Type = "New"
End Select

Quot_Line_Mtnc.ms_QuotationLanguage = gs_QuotationLanguageCode
Quot_Line_Mtnc.mi_QuotCode = gi_QuotationCode
Quot_Line_Mtnc.mi_Version = gi_QuotationVersion
Quot_Line_Mtnc.ms_Action = "Add"

gb_Return = KO
Quot_Line_Mtnc.show 1
If gb_Return Then FillGrid3
MouseOn

Exit Sub

suite:
StdError
End Sub

Private Sub pic_add_Click()

MouseOff

If lst_AddLine.Visible = OK Then
    lst_AddLine.Visible = KO
Else
    lst_AddLine.Visible = OK
    lst_AddLine.ListIndex = -1
    lst_AddLine.SetFocus
End If

gb_Return = KO

MouseOn
Exit Sub

suite:
StdError
End Sub

Private Sub pic_next25_Click()

MouseOff
FillGrid2
FillGrid3
MouseOn

End Sub
Private Sub pic_delete_Click()

On Error GoTo suite

MouseOff
If Grid2.HighLight = flexHighlightNever Then
    SendMessage 1, "Please, first select a record.", gut_LangLogin.Code
Else
    gb_Return = KO
    Quot_Line_Mtnc.ms_Action = "Delete"
    FillParm
    If Quot_Line_Security = OK Then
    Quot_Line_Mtnc.show 1
    If gb_Return Then FillGrid3
End If
End If
If gb_Return Then FillGrid3
MouseOn
Exit Sub

suite:
Select Case Err
Case 30015
    If pic_next25.Visible Then
        pic_next25_Click
    Else
        Unload Me
    End If
Case Else
    StdError
    MouseOn
End Select
End Sub
Private Sub pic_log_Click()

On Error GoTo Histo_Err

MouseOff
Quotation_Historic

Exit Sub

Histo_Err:
    StdError
End Sub

Private Sub pic_Order_Click()
Dim ls_OldTableName As String

MouseOff
ls_OldTableName = gs_TableName
gs_TableName = "quot_line"
C_Order.ms_parameter = gi_QuotationCode & "," & gi_QuotationVersion
C_Order.show 1
If C_Order.mb_Return = OK Then FillGrid
gs_TableName = ls_OldTableName
MouseOn

End Sub

Private Sub pic_refresh_Click()

MouseOff
Quotation_Refresh txt_Status, cbo_Version, Me.Left, Me.Top
FillGrid
MouseOn

End Sub

Private Sub pic_upd_Click()

If Grid2.HighLight = flexHighlightNever Then
    SendMessage 1, "Please, first select a record.", gut_LangLogin.Code
        Exit Sub
    End If

    MouseOff
    gb_Return = KO
    Quot_Line_Mtnc.ms_Action = "Update"
    FillParm
    If Quot_Line_Security = OK Then
        Quot_Line_Mtnc.show 1
    
        If gb_Return Then FillGrid3
    End If
MouseOn

End Sub
Private Sub pic_quit_Click()
    Unload Me
End Sub
Private Sub FillGrid3()

Dim li_Count As Integer
Dim li_Count2 As Integer
Dim li_Grid2Col As Integer

On Error GoTo suite

' Grid sizing (visible grid)
Grid.Row = 1
Grid.Col = 0
mi_NbRows = Grid.Rows
If Grid.Rows = 2 And Grid.Text = "" Then
    Grid2.Rows = 2
Else
    Grid2.Rows = mi_NbRows
End If
Grid2.Cols = 1
li_Grid2Col = -1
For li_Count = 0 To 29
    If gi_GridWidth(li_Count) > 1 Then
    ' Cols filling (visible grid)
        Grid.Col = li_Count
        li_Grid2Col = li_Grid2Col + 1
        Grid2.Cols = li_Grid2Col + 1
        Grid2.Col = li_Grid2Col
        Grid2.ColWidth(li_Grid2Col) = gi_GridWidth(li_Count)
        For li_Count2 = 0 To mi_NbRows - 1
            Grid.Row = li_Count2
            Grid2.Row = li_Count2
            Grid2.Text = Grid.Text
        Next li_Count2
    End If
Next li_Count
Grid.Row = 1
Grid.Col = 0

If Grid.Rows = 2 And Grid.Text = "" Then
    gl_NbLineDisplay = 0
Else
    gl_NbLineDisplay = mi_NbRows - 1
End If
If ml_TotCount <= 0 Then
    ssp_code = gl_NbLineDisplay
Else
    ssp_code = gl_NbLineDisplay & " / " & ml_TotCount
End If
Grid2.Row = 0
Grid2.Col = 0
mi_Yav = 0
Grid2.HighLight = flexHighlightNever    '= KO
Grid2.FocusRect = flexFocusHeavy
MouseOn
Exit Sub

suite:
StdError
End Sub
Public Sub FillGrid()
 ' Submit filling query (option mb_ServerCursor)
Dim ls_Req As String
Dim li_Count As Integer
Dim li_Status As Integer

On Error GoTo suite

MouseOff
pic_next25.Visible = KO
' Columns header (invisible grid)
Grid.Rows = 2
For li_Count = 0 To 29
    Grid.Col = li_Count
    Grid.Row = 0
    Grid.Text = gs_GridColumn(li_Count)
    Grid.Row = 1
    Grid.Text = ""
Next li_Count
' Submit filling query
ls_Req = "EXEC Quot_Line_t_sel " & gi_QuotationCode & "," & gi_QuotationVersion

li_Status = mo_Fetch.ExecuteQry(ls_Req, mb_ServerCursor)

If li_Status Then
    ml_TotCount = mo_Fetch.RowCount
End If

' Fills invisible grid / by 25 (option mb_ServerCursor)
mi_NbRows = 1
FillGrid2

' Fills visible grid
FillGrid3

Exit Sub

suite:
    StdError
End Sub

Private Sub FillGrid2()
' Fills invisible grid / by 25 (option mb_ServerCursor)
Dim li_Count, li_Count25 As Integer
Dim lb_Exit As Boolean
Dim i As Integer
Dim j As Integer
Dim li_NBcol As Integer

On Error GoTo suite

lb_Exit = False

li_NBcol = mo_Fetch.NbCol

'if the serverCursor is true, we must make only one round
'in the other case, we must read all the data
Do While (mb_ServerCursor = True And lb_Exit = False) Or (mb_ServerCursor = False And mi_NbRows <> ml_TotCount + 1)
    li_Count = mo_Fetch.FillMore
    If li_Count = 0 Then Exit Do
    For i = 1 To li_Count
        Grid.Rows = mi_NbRows + 1
        Grid.Row = mi_NbRows
        For j = 1 To li_NBcol
            Grid.Col = j - 1
            Grid.Text = mo_Fetch.GetData(i, j)
        Next
        mi_NbRows = mi_NbRows + 1
    Next
    lb_Exit = True
Loop

'we must make the "more 25" image visible or not
If li_Count = mo_Fetch.MaxRowCount And mi_NbRows <> ml_TotCount + 1 Then
    pic_next25.Visible = OK
Else
    pic_next25.Visible = KO
End If

Exit Sub

suite:
pic_next25.Visible = KO
StdError
End Sub

Private Sub Permission()
Dim ls_Perm As String
Dim ll_Statement As Long
Dim li_Status As Integer
Dim ls_Req As String

On Error GoTo suite

mb_AllowAdd = KO
mb_AllowDel = KO
mb_AllowUpd = KO
mb_ServerCursor = OK

ls_Req = "EXEC Check_Security 'Quot_Line', '" & prg.LoginName & "'"

If SQLSubmit(gl_Environment, gl_Database, ll_Statement, ls_Req) Then
    li_Status = SQL_SUCCESS
Else
    li_Status = SQL_ERROR
End If
Do While li_Status = SQL_SUCCESS Or li_Status = SQL_SUCCESS_WITH_INFO
    li_Status = SQLFetch(ll_Statement)
    If li_Status = SQL_SUCCESS Or li_Status = SQL_SUCCESS_WITH_INFO Then
        ls_Perm = ODBCData(ll_Statement, 1)
        If ls_Perm = "Update" Then
            mb_AllowUpd = OK
            mb_ServerCursor = KO
        End If
        If ls_Perm = "Delete" Then
            mb_AllowAdd = OK
            mb_ServerCursor = KO
        End If
        If ls_Perm = "Insert" Then
            mb_AllowDel = OK
            mb_ServerCursor = KO
        End If
    End If
Loop
li_Status = SQLFreeStatement(ll_Statement, SQL_DROP)

Exit Sub

suite:
StdError
li_Status = SQLFreeStatement(ll_Statement, SQL_DROP)
End Sub

Private Sub InitFields()
    Quotation_View_Load txt_QuotCode, txt_Status, cbo_Version
End Sub
Private Sub MainCsts()
Dim ls_Field As String
Dim ls_Text As String
Dim ll_Statement As Long
Dim li_Status As Integer
Dim ls_Req As String

    On Error GoTo suite
    
    ls_Req = "EXEC Screen_Csts 'main_quoteline','" & gut_LangLogin.Code & "'"
    
    If SQLSubmit(gl_Environment, gl_Database, ll_Statement, ls_Req) Then
        li_Status = SQL_SUCCESS
    Else
        li_Status = SQL_ERROR
    End If
    Do While li_Status = SQL_SUCCESS Or li_Status = SQL_SUCCESS_WITH_INFO
        li_Status = SQLFetch(ll_Statement)
        If li_Status = SQL_SUCCESS Or li_Status = SQL_SUCCESS_WITH_INFO Then
            ls_Field = ODBCData(ll_Statement, 1)
            ls_Text = ODBCData(ll_Statement, 2)
            Select Case ls_Field
            Case "title": 'Caption = ls_Text
            Case "lbl_record": lbl_Rcd = ls_Text
            Case "c0": gs_GridColumn(0) = ls_Text
            Case "c1": gs_GridColumn(1) = ls_Text
            Case "c2": gs_GridColumn(2) = ls_Text
            Case "c3": gs_GridColumn(3) = ls_Text
            Case "c4": gs_GridColumn(4) = ls_Text
            Case "c5": gs_GridColumn(5) = ls_Text
            Case "c6": gs_GridColumn(6) = ls_Text
            Case "c7": gs_GridColumn(7) = ls_Text
            Case "c8": gs_GridColumn(8) = ls_Text
            Case "c9": gs_GridColumn(9) = ls_Text
            Case "c10": gs_GridColumn(10) = ls_Text
            Case "c11": gs_GridColumn(11) = ls_Text
            Case "c12": gs_GridColumn(12) = ls_Text
            Case "c13": gs_GridColumn(13) = ls_Text
            Case "c14": gs_GridColumn(14) = ls_Text
            Case "c15": gs_GridColumn(15) = ls_Text
            Case "c16": gs_GridColumn(16) = ls_Text
            Case "c17": gs_GridColumn(17) = ls_Text
            Case "c18": gs_GridColumn(18) = ls_Text
            Case "c19": gs_GridColumn(19) = ls_Text
            Case "c20": gs_GridColumn(20) = ls_Text
            Case "c21": gs_GridColumn(21) = ls_Text
            Case "c22": gs_GridColumn(22) = ls_Text
            Case "c23": gs_GridColumn(23) = ls_Text
            Case "c24": gs_GridColumn(24) = ls_Text
            Case "c25": gs_GridColumn(25) = ls_Text
            Case "c26": gs_GridColumn(26) = ls_Text
            Case "c27": gs_GridColumn(27) = ls_Text
            Case "c28": gs_GridColumn(28) = ls_Text
            Case "c29": gs_GridColumn(29) = ls_Text
            End Select
        End If
    Loop
    li_Status = SQLFreeStatement(ll_Statement, SQL_DROP)
    Exit Sub
    
suite:
    StdError
    li_Status = SQLFreeStatement(ll_Statement, SQL_DROP)
End Sub
Public Sub DefaultLine()

On Error GoTo ErrDefaultLine

Quot_Line_Mtnc.ms_Type = "Comment"
Quot_Line_Mtnc.ms_QuotationLanguage = gs_QuotationLanguageCode
Quot_Line_Mtnc.mi_QuotCode = gi_QuotationCode
Quot_Line_Mtnc.mi_Version = gi_QuotationVersion
Quot_Line_Mtnc.ms_Action = "Add"

gb_Return = KO
Quot_Line_Mtnc.show 1
If gb_Return Then FillGrid3

Exit Sub

ErrDefaultLine:
StdError
End Sub

Private Sub lst_AddLine_LostFocus()
    If ActiveControl.Name <> "pic_add" Then lst_AddLine.Visible = KO
End Sub
Public Sub ShowOrder()
Dim ls_Req As String
Dim ll_Statement As Long
Dim li_Status As Integer

    On Error GoTo suite
    
    pic_Order.Visible = KO
    ls_Req = "TableSortedShow 'Quot_Line', '" & prg.LoginName & "'"
    If SQLSubmit(gl_Environment, gl_Database, ll_Statement, ls_Req) Then
        Do While li_Status = SQL_SUCCESS Or li_Status = SQL_SUCCESS_WITH_INFO
            li_Status = SQLFetch(ll_Statement)
            If li_Status = SQL_SUCCESS Or li_Status = SQL_SUCCESS_WITH_INFO Then
                pic_Order.Visible = OK
                pic_Order.Picture = LoadResPicture(RES_ORDER, 1)
            End If
        Loop
    End If
    li_Status = SQLFreeStatement(ll_Statement, SQL_DROP)
    Exit Sub
    
suite:
    StdError
    li_Status = SQLFreeStatement(ll_Statement, SQL_DROP)
End Sub

Public Function Quot_Line_Security() As Boolean
Dim ls_Req As String
Dim ll_Statement As Long
Dim li_Status As Integer
Dim ls_Return As String

On Error GoTo ErrQLS

Quot_Line_Security = KO
If gut_Actor.MSC = OK Or gut_Actor.COS = OK Then
    Quot_Line_Security = OK
    Exit Function
End If
If Quot_Line_Mtnc.ms_Type = "Comment" Then
    Quot_Line_Security = OK
    Exit Function
End If

ls_Req = "exec Quot_Line_Security " & gi_QuotationCode & ", " & gi_QuotationVersion _
    & ", " & Quot_Line_Mtnc.mi_Line & ", '" & prg.LoginName & "'"
If SQLSubmit(gl_Environment, gl_Database, ll_Statement, ls_Req) Then
    Do While li_Status = SQL_SUCCESS Or li_Status = SQL_SUCCESS_WITH_INFO
        li_Status = SQLFetch(ll_Statement)
        If li_Status = SQL_SUCCESS Or li_Status = SQL_SUCCESS_WITH_INFO Then
            ls_Return = ODBCData(ll_Statement, 1)
        End If
    Loop
End If
li_Status = SQLFreeStatement(ll_Statement, SQL_DROP)

If ls_Return = "OK" Then
    Quot_Line_Security = OK
Else
    Quot_Line_Security = KO
    SendMessage 130, "You aren't allowed to update or delete this line.", gut_LangLogin.Code
End If
Exit Function

ErrQLS:
    StdError
    li_Status = SQLFreeStatement(ll_Statement, SQL_DROP)
End Function

Sub CheckSecurityAdd()
    
    If gi_QuotationStatusCode = Quotation_Status.closed _
       Or gi_QuotationStatusCode = Quotation_Status.Old_Version _
       Or gi_QuotationStatusCode = Quotation_Status.Archived _
       Or gi_QuotationStatusCode = Quotation_Status.Customer_changes_Quotation Then
        pic_add.Visible = KO
    Else
        pic_add.Visible = OK
    End If

End Sub
