VERSION 5.00
Object = "{0D452EE1-E08F-101A-852E-02608C4D0BB4}#2.0#0"; "FM20.DLL"
Begin VB.Form Sales_project_Mtnc 
   BorderStyle     =   1  'Fixed Single
   Caption         =   "Sales Project"
   ClientHeight    =   6840
   ClientLeft      =   45
   ClientTop       =   330
   ClientWidth     =   8490
   ControlBox      =   0   'False
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MinButton       =   0   'False
   ScaleHeight     =   6840
   ScaleWidth      =   8490
   StartUpPosition =   3  'Windows Default
   Begin VB.CommandButton spp_save 
      Height          =   615
      Left            =   7020
      Style           =   1  'Graphical
      TabIndex        =   12
      Top             =   6180
      Width           =   615
   End
   Begin VB.CommandButton ssp_quit 
      Height          =   615
      Left            =   7740
      Style           =   1  'Graphical
      TabIndex        =   13
      Top             =   6180
      Width           =   615
   End
   Begin VB.PictureBox pic_PromisedCalendar 
      Appearance      =   0  'Flat
      BackColor       =   &H80000005&
      BorderStyle     =   0  'None
      ForeColor       =   &H80000008&
      Height          =   315
      Left            =   2580
      ScaleHeight     =   315
      ScaleWidth      =   255
      TabIndex        =   2
      Top             =   960
      Width           =   252
   End
   Begin VB.TextBox txt_ZIP 
      Height          =   315
      Left            =   5940
      TabIndex        =   8
      Top             =   2460
      Width           =   2415
   End
   Begin VB.TextBox txt_Comment 
      Height          =   2235
      Left            =   120
      MultiLine       =   -1  'True
      TabIndex        =   11
      Top             =   3840
      Width           =   8235
   End
   Begin VB.TextBox txt_address2 
      Height          =   315
      Left            =   1200
      TabIndex        =   6
      Top             =   1920
      Width           =   7155
   End
   Begin VB.TextBox txt_Address1 
      Height          =   315
      Left            =   1200
      TabIndex        =   5
      Top             =   1500
      Width           =   7155
   End
   Begin VB.TextBox txt_Size 
      Height          =   315
      Left            =   5940
      TabIndex        =   3
      Top             =   360
      Width           =   2415
   End
   Begin VB.TextBox txt_startdate 
      Height          =   315
      Left            =   1200
      Locked          =   -1  'True
      TabIndex        =   1
      Top             =   960
      Width           =   1395
   End
   Begin VB.TextBox txt_desc 
      Height          =   315
      Left            =   1200
      TabIndex        =   0
      Top             =   360
      Width           =   3435
   End
   Begin VB.TextBox txt_Town 
      Height          =   315
      Left            =   1200
      TabIndex        =   7
      Top             =   2460
      Width           =   2955
   End
   Begin MSForms.ComboBox cbo_Country 
      Height          =   315
      Left            =   1200
      TabIndex        =   9
      Top             =   2940
      Width           =   2955
      VariousPropertyBits=   679479323
      DisplayStyle    =   7
      Size            =   "5212;556"
      MatchEntry      =   1
      ShowDropButtonWhen=   2
      FontHeight      =   165
      FontCharSet     =   0
      FontPitchAndFamily=   2
   End
   Begin MSForms.ComboBox cbo_UnitOfMeasure 
      Height          =   315
      Left            =   5940
      TabIndex        =   4
      Top             =   960
      Width           =   2415
      VariousPropertyBits=   679479323
      DisplayStyle    =   7
      Size            =   "4260;556"
      MatchEntry      =   1
      ShowDropButtonWhen=   2
      FontHeight      =   165
      FontCharSet     =   0
      FontPitchAndFamily=   2
   End
   Begin VB.Label lbl_Comment 
      Caption         =   "Comments:"
      Height          =   315
      Left            =   180
      TabIndex        =   21
      Top             =   3540
      Width           =   1575
   End
   Begin VB.Label lbl_Zip 
      Caption         =   "ZIP:"
      Height          =   255
      Left            =   4980
      TabIndex        =   20
      Top             =   2460
      Width           =   735
   End
   Begin VB.Label lbl_Country 
      Caption         =   "Country:"
      Height          =   315
      Left            =   180
      TabIndex        =   19
      Top             =   3000
      Width           =   1035
   End
   Begin VB.Label lbl_Town 
      Caption         =   "Town:"
      Height          =   315
      Left            =   180
      TabIndex        =   18
      Top             =   2460
      Width           =   855
   End
   Begin VB.Label lbl_Address 
      Caption         =   "Address:"
      Height          =   255
      Left            =   180
      TabIndex        =   17
      Top             =   1560
      Width           =   1035
   End
   Begin VB.Label lbl_UnitOfMeasure 
      Caption         =   "Unit of measure:"
      Height          =   375
      Left            =   4740
      TabIndex        =   16
      Top             =   960
      Width           =   1155
   End
   Begin VB.Label lbl_Size 
      Caption         =   "Size:"
      Height          =   375
      Left            =   4740
      TabIndex        =   15
      Top             =   360
      Width           =   1035
   End
   Begin VB.Label lbl_StartDate 
      Caption         =   "Start date:"
      Height          =   195
      Left            =   180
      TabIndex        =   14
      Top             =   960
      Width           =   1095
   End
   Begin VB.Label lbl_Name 
      Caption         =   "Name:"
      Height          =   315
      Left            =   180
      TabIndex        =   10
      Top             =   360
      Width           =   915
   End
End
Attribute VB_Name = "Sales_project_Mtnc"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim ms_Code As String
Public b_UseWithCMain As Boolean
Public s_Data_Code As String
Public s_Data_Desc As String
Public i_Data_iConcurrency As Integer

Private Sub Cbo_country_DropButtonClick()
    If gs_TableName = "Quotation" Then
        LoadCombo "exec countries_cbo '" & gut_LangWork.Code & "'", cbo_country, KO
    Else
        LoadCombo "exec countries_cbo '" & gut_LangWork.Code & "'", cbo_country, OK
    End If
End Sub

Private Sub cbo_UnitOfMeasure_DropButtonClick()
    LoadCombo "exec unit_of_measure_cbo2 '" & gut_LangWork.Code & "'", cbo_UnitOfMeasure, OK
End Sub

Private Sub Form_Load()
    ' load pictures for button
    spp_save.Picture = LoadResPicture(RES_OK, 1)
    ssp_quit.Picture = LoadResPicture(RES_QUIT, 1)
    
    If gl_CodePage <> 1252 And gl_CodePage <> 0 Then ChangeCharset Me

    ' Get and fill all the captions
    GetCaptions
    ' Fill all the fields
    
    If gs_Action <> "Add" Then
        If b_UseWithCMain Then
            FillValueFromCMain
        Else
            FillValueFromSGBD
        End If
    End If
    ' Enable or disable the fields
    If gs_Action = "Add" Or gs_Action = "Update" Then
        FrameEnabled "Sales_project_Mtnc", OK
        pic_PromisedCalendar.Picture = LoadResPicture(RES_COMBOCOPY, 1)
    Else
        FrameEnabled "Sales_project_Mtnc", KO
        pic_PromisedCalendar.Picture = LoadResPicture(RES_COMBOCOPYGRAY, 1)
        spp_save.Enabled = OK
        ssp_quit.Enabled = OK
    End If
    If gs_Action = "MoreInfo" Then spp_save.Visible = KO
    cbo_UnitOfMeasure.Tag = UNLOADED
    cbo_country.Tag = UNLOADED
    MouseOn
End Sub

Private Sub GetCaptions()
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 'Mtnc_Sales_Proj', '" & 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_Name": lbl_Name = ls_Text
                Case "lbl_StartDate": lbl_StartDate = ls_Text
                Case "lbl_Size": lbl_Size = ls_Text
                Case "lbl_UnitOfMeasure": lbl_UnitOfMeasure = ls_Text
                Case "lbl_Address": lbl_Address = ls_Text
                Case "lbl_Town": lbl_Town = ls_Text
                Case "lbl_Country": lbl_Country = ls_Text
                Case "lbl_Zip": lbl_zip = ls_Text
                Case "lbl_Comment": lbl_comment = 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

Private Sub FillValueFromCMain()
    txt_Desc = gs_TableCode3
    txt_StartDate = gs_TableCode4
    txt_Size = gs_TableCode5
    If gs_TableCode6 <> "" Then MCombo_AddItemCode cbo_UnitOfMeasure, gs_TableCode6, gs_TableCode7
    txt_Address1 = gs_TableCode12
    txt_address2 = gs_TableCode13
    txt_Town = gs_TableCode9
    txt_ZIP = gs_TableCode8
    MCombo_AddItemCode cbo_country, gs_TableCode10, gs_TableCode11
    txt_comment = gs_TableCode14
End Sub

Private Sub FillValueFromSGBD()
'--------------------------------------------------
' Get then detailed data directly from the SGBD
'--------------------------------------------------
Dim ll_Statement As Long
Dim li_Status As Integer
Dim ls_Req As String
Dim ls_UM_Code As String
Dim ls_UM_Desc As String
Dim ls_CT_Code As String
Dim ls_CT_Desc As String

    On Error GoTo suite
    ls_Req = "EXEC Sales_Project_t_sel2 " & s_Data_Code & ", '" & 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
            txt_Desc = ODBCData(ll_Statement, 1)
            txt_StartDate = ODBCData(ll_Statement, 2)
            txt_Size = ODBCData(ll_Statement, 3)
            ls_UM_Code = ODBCData(ll_Statement, 4)
            ls_UM_Desc = ODBCData(ll_Statement, 5)
            If ls_UM_Code <> "" Then MCombo_AddItemCode cbo_UnitOfMeasure, ls_UM_Code, ls_UM_Desc
            txt_Address1 = ODBCData(ll_Statement, 6)
            txt_address2 = ODBCData(ll_Statement, 7)
            txt_Town = ODBCData(ll_Statement, 8)
            txt_ZIP = ODBCData(ll_Statement, 9)
            ls_CT_Code = ODBCData(ll_Statement, 10)
            ls_CT_Desc = ODBCData(ll_Statement, 11)
            MCombo_AddItemCode cbo_country, ls_CT_Code, ls_CT_Desc
            txt_comment = ODBCData(ll_Statement, 12)
            i_Data_iConcurrency = ODBCData(ll_Statement, 13)
        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 pic_PromisedCalendar_Click()
'--------------------------------------------------
' Open the calendar and get the start date
'--------------------------------------------------
On Error GoTo suite
    MouseOff
    gb_Return = KO
    gs_Date = Format(txt_StartDate, "dd/mm/yyyy")
    Dates.show 1
    If gb_Return Then
        If gs_Date <> "" Then
            txt_StartDate = gs_Date
        Else
            txt_StartDate = ""
        End If
    End If
    MouseOn
    Exit Sub
suite:
    StdError
    MouseOn
End Sub

Private Sub spp_save_Click()
'------------------------------------------------
' Write the informations to DB if everythings OK
'------------------------------------------------
    MouseOff
    gb_Return = KO
    If gs_Action <> "Delete" Then
        If Control <> OK Then
            MouseOn
            Exit Sub
        End If
    End If
    CreateRequest
    MouseOn
    If gb_Return = OK Then
        Unload Me
    End If
End Sub

Private Sub ssp_quit_Click()
    MouseOff
    Unload Me
    MouseOn
End Sub

Private Sub FrameEnabled(ms_Frame As String, mb_Enabled As Boolean)
Dim ls_Count As Integer
    For ls_Count = 0 To Me.Count - 1
        If Me.Controls(ls_Count).Container.Name = ms_Frame Then Me.Controls(ls_Count).Enabled = mb_Enabled
    Next
End Sub

Private Sub LoadCombo(ls_Req As String, cbo_Combo As msforms.ComboBox, BlankLine As Boolean)
'-------------------------------------------------------------
' Drop down a combo and load it if necessary with ls_req
'-------------------------------------------------------------
Dim ls_Code
    If cbo_Combo.Tag <> Loaded Then
        MouseOff
        ls_Code = MCombo_GetCode(cbo_Combo)
        cbo_Combo.Clear
        
        If BlankLine = OK Then MCombo_AddItemCode cbo_Combo, "None", "", OK
        
        MCombo_Fill cbo_Combo, ls_Req
        
        MCombo_CodeSelect(cbo_Combo) = ls_Code
        cbo_Combo.Tag = Loaded
        MouseOn
    End If
End Sub


Private Function Control() As Boolean
Dim lo_Component As Object
'------------------------------------------------------------------------
' Test the validity of all frames (mandatory values and numeric vbalues)
'------------------------------------------------------------------------

' Verify validity of numeric values
'--------------------------------------
    If Not CheckNumericValue(txt_Size.Text) Then
        txt_Size.SetFocus
        SendMessage 18, "Only numeric field is valid ", gut_LangLogin.Code
        Control = KO
        Exit Function
    End If
' Test if mandatory fields are OK
'----------------------------------
    Set lo_Component = Nothing
'    If gs_TableName = "Quotation" Then
        If MCombo_GetCode(cbo_country) = "None" Or MCombo_GetCode(cbo_country) = "" Or cbo_country.ListIndex = -1 Then Set lo_Component = cbo_country
        If txt_Town = "" Then Set lo_Component = txt_Town
'    End If
    If StrComp(txt_Town, " ") = 0 Then Set lo_Component = txt_Town
    If txt_Size <> "" And (MCombo_GetCode(cbo_UnitOfMeasure) = "None" Or cbo_UnitOfMeasure.ListIndex = -1) Then Set lo_Component = cbo_UnitOfMeasure
    If txt_Size = "" And MCombo_GetCode(cbo_UnitOfMeasure) <> "None" And cbo_UnitOfMeasure.ListIndex <> -1 Then Set lo_Component = txt_Size
    If txt_Desc = "" Then Set lo_Component = txt_Desc
    If txt_Size = "" Then Set lo_Component = txt_Size
    If StrComp(txt_Desc, " ") = 0 Then Set lo_Component = txt_Desc
    If TypeName(lo_Component) <> "Nothing" Then
        lo_Component.SetFocus
        SendMessage 8, "Value must be filled in", gut_LangLogin.Code
        Control = KO
        Exit Function
    End If
    Control = OK
End Function

Private Sub CreateRequest()
'-----------------------------------------------------------------------------------
' select, construct and execute the request for updating, adding or deleting a line
'-----------------------------------------------------------------------------------
Dim ls_Req As String
Dim lb_cancel As Boolean
On Error GoTo suite

    lb_cancel = KO
    
    If b_UseWithCMain Then
        ' Select and construct the request
        '---------------------------------
        Select Case gs_Action
            ' ADDING
            Case "Add":    ls_Req = "EXEC Sales_Project_Ins " & Parameter()
            'UPDATING
            Case "Update": ls_Req = "EXEC Sales_Project_Upd " & gs_TableCode & "," & Parameter() & "," & gs_TableCode2
            ' DELETING
            Case "Delete": MouseOn
                           If SendMessage(5, "Delete record ?", gut_LangLogin.Code, vbQuestion + vbYesNo, "Delete ") = vbYes Then
                               MouseOff
                               ls_Req = "exec Sales_Project_del " & gs_TableCode & "," & gs_TableCode2
                           Else
                               lb_cancel = OK
                           End If
        End Select
    Else
        ' Select and construct the request
        '---------------------------------
        Select Case gs_Action
            ' ADDING
            Case "Add":    ls_Req = "EXEC Sales_Project_Ins " & Parameter()
            'UPDATING
            Case "Update": ls_Req = "EXEC Sales_Project_Upd " & s_Data_Code & "," & Parameter() & "," & i_Data_iConcurrency
            ' DELETING
            Case "Delete": MouseOn
                           If SendMessage(5, "Delete record ?", gut_LangLogin.Code, vbQuestion + vbYesNo, "Delete ") = vbYes Then
                               MouseOff
                               ls_Req = "exec Sales_Project_del " & s_Data_Code & "," & i_Data_iConcurrency
                           Else
                               lb_cancel = OK
                           End If
        End Select
    End If
    If lb_cancel = KO Then
        ' Execute the request
        '---------------------
        li_Status = ExecuteRequest(ls_Req)
        If li_Status = SQL_SUCCESS Or li_Status = SQL_SUCCESS_WITH_INFO Then
            If b_UseWithCMain Then
                ' Update the parent grid with the new values
                '---------------------------------------------
                RefreshGrid
            Else
                Select Case gs_Action
                Case "Add"
                    s_Data_Code = ms_Code
                    s_Data_Desc = txt_Desc
                    i_Data_iConcurrency = 1
                Case "Update"
                    s_Data_Desc = txt_Desc
                    i_Data_iConcurrency = i_Data_iConcurrency + 1
                End Select
                gb_Return = OK
            End If
        End If
    End If
    Exit Sub
suite:
    StdError
End Sub

Public Function ExecuteRequest(ls_Req As String) As Integer
'----------------------------------------------------------
' Send the request ls_req to the server
' Change ms_Code if it's an insert request
'----------------------------------------------------------
Dim ll_Statement As Long
Dim li_Status As Integer
Dim ll_lngrows As Long
On Error GoTo suite
    If SQLSubmit(gl_Environment, gl_Database, ll_Statement, ls_Req) Then
        li_Status = SQLRowCount(ll_Statement, ll_lngrows)
        If ll_lngrows = 0 Then
            SendMessage 2, "Another user change the record", gut_LangLogin.Code
            li_Status = SQL_ERROR
        Else
            If gs_Action = "Add" Then
                ' Find the code
                li_Status = SQLFetch(ll_Statement)
                If li_Status = SQL_SUCCESS Or li_Status = SQL_SUCCESS_WITH_INFO Then
                    ms_Code = ODBCData(ll_Statement, 1)
                End If
            End If
            li_Status = SQL_SUCCESS
        End If
    Else
        Select Case gs_Action
            Case "Update": SendMessage 3, "Update failed", gut_LangLogin.Code
            Case "Delete": SendMessage 6, "Delete failed", gut_LangLogin.Code
            Case "Add": SendMessage 4, "Insert failed", gut_LangLogin.Code
        End Select
        li_Status = SQL_ERROR
    End If
    ExecuteRequest = li_Status
    li_Status = SQLFreeStatement(ll_Statement, SQL_DROP)
    Exit Function
suite:
    ExecuteRequest = li_Status
    li_Status = SQLFreeStatement(ll_Statement, SQL_DROP)
    StdError
End Function

Private Function Parameter() As String
Dim ls_ParamString As String
    If MCombo_GetCode(cbo_country) = "None" Or cbo_country.ListIndex = -1 Then
        ls_ParamString = "Null"
    Else
        ls_ParamString = "'" & MCombo_GetCode(cbo_country) & "'"
    End If
    If MCombo_GetCode(cbo_UnitOfMeasure) = "None" Or cbo_UnitOfMeasure.ListIndex = -1 Then
        ls_ParamString = ls_ParamString & ",Null"
    Else
        ls_ParamString = ls_ParamString & ",'" & MCombo_GetCode(cbo_UnitOfMeasure) & "'"
    End If
    ls_ParamString = ls_ParamString & ",'" & QuoteParam(txt_Desc) & "'"
    ls_ParamString = ls_ParamString & ",'" & FormatD(txt_StartDate, "mm/dd/yyyy") & "'"
    ls_ParamString = ls_ParamString & ",'" & QuoteParam(txt_Address1) & "'"
    ls_ParamString = ls_ParamString & ",'" & QuoteParam(txt_address2) & "'"
    ls_ParamString = ls_ParamString & ",'" & QuoteParam(txt_ZIP) & "'"
    ls_ParamString = ls_ParamString & ",'" & QuoteParam(txt_Town) & "'"
    If txt_Size = "" Then
        ls_ParamString = ls_ParamString & ",Null"
    Else
        ls_ParamString = ls_ParamString & "," & txt_Size
    End If
'    ls_ParamString = ls_ParamString & ",'" & QuoteParam(txt_comment) & "'" ' task 299.3
    Parameter = ls_ParamString
End Function

Public Sub RefreshGrid()
'--------------------------------------------
' Refresh the parent grid
'--------------------------------------------
Dim ls_Line As String
On Error GoTo suite:
    If gs_Action = "Update" Then gs_TableCode2 = gs_TableCode2 + 1
    If gs_Action = "Add" Then
        gs_TableCode = ms_Code
        gs_TableCode2 = "1"
    End If
    ls_Line = gs_TableCode & Chr(9) & gs_TableCode2 & Chr(9) & txt_Desc & Chr(9) & txt_StartDate & Chr(9) & _
                txt_Size & Chr(9) & MCombo_GetCode(cbo_UnitOfMeasure) & Chr(9) & cbo_UnitOfMeasure.value & Chr(9) & _
                txt_ZIP & Chr(9) & txt_Town & Chr(9) & MCombo_GetCode(cbo_country) & Chr(9) & cbo_country.value & Chr(9) & _
                txt_Address1 & Chr(9) & txt_address2 & Chr(9) & txt_comment & Chr(9) & gs_TableCode14 & Chr(9) & gs_TableCode15
    Select Case gs_Action
        Case "Add":     C_main.Grid.AddItem ls_Line
                        C_main.Grid.Row = C_main.Grid.Rows - 1
                        If gl_NbLineDisplay < 2 Then C_main.FillGrid
                        gb_Return = OK
        Case "Update":  C_main.Grid.RemoveItem C_main.Grid.Row
                        C_main.Grid.AddItem ls_Line, C_main.Grid.Row
                        gb_Return = OK
        Case "Delete":  C_main.Grid.RemoveItem C_main.Grid.Row
                        gb_Return = OK
        Case Else:      gb_Return = KO
    End Select
    Exit Sub
suite:
    If Err = 30015 Then
        Quot_Line_View.FillGrid
    Else
        StdError
    End If
End Sub


