Private Sub Command2_Click()
Dim Rs As New ADODB.Recordset
Dim SQLs As String
Dim S As Integer
If txtInNo.Text = "" Then
MsgBox "ادخل رقم الفاتورة", vbCritical, "رقم الفاتورة"
Exit Sub
End If
With Grid
SQLs = "Select * From Invoice where InvNo=" & Trim(txtInNo.Text) & ""
If RSS.State = adStateOpen Then RSS.Close
RSS.Open SQLs, CN, adOpenKeyset, adLockPessimistic
If RSS.RecordCount = 0 Then
Dim XN As Integer
Dim j As Integer
Dim JL As Integer
Dim sSQL As String
.Col = 1
.Row = 1
For XN = .Rows - 1 To 1 Step -1
sSQL = ""
For j = 1 To .Cols - 1
sSQL = sSQL & Trim(.TextMatrix(XN, j))
Next
If Trim(sSQL) = "" And .Rows > 2 Then
.RemoveItem XN
Else
Exit For
Exit Sub
End If
If .Rows <= 1 Then Exit For
Next
For XN = 1 To .Rows - 1
For j = 0 To .Cols - 1
If (.TextMatrix(XN, j) = "") Then
For JL = 0 To 5
.Row = XN
.Col = JL
.CellBackColor = vbRed
DoEvents
Sleep 11
'.CellBackColor = vbWhite
Next
Exit Sub
End If
Next
Next
For S = 1 To .Rows - 1
RSS.AddNew
RSS.Fields("InvNo") = txtInNo.Text
RSS.Fields("InvDate") = Format(Me.DTPicker1.Value, "dd/MMM/yyyy")
RSS.Fields("CutmrName") = Combo1.Text
RSS.Fields("InTyp") = Combo2.Text
RSS!Code = .TextMatrix(S, 0)
RSS!ItmName = .TextMatrix(S, 1)
RSS!Pak = .TextMatrix(S, 2)
RSS!Price = .TextMatrix(S, 3)
RSS!Qty = .TextMatrix(S, 4)
RSS!Amount = .TextMatrix(S, 5)
If Rs.State = 1 Then Rs.Close
Rs.Open "SELECT Qty FROM Items WHERE ItmCode =" & .TextMatrix(S, 0), CN, adOpenKeyset, adLockPessimistic
Rs![Qty] = Val(Rs![Qty]) - Val(.TextMatrix(S, 3))
Rs.Update
RSS.Update
Next
MsgBox "تم حفظ بيانات الفاتورة بنجاح ", vbInformation, "حفظ"
ClearAllA Me
lblTotal.Caption = ""
Call Grd
Else
MsgBox "يوجد خطأ اثناء الحفظ --- الفاتورة مسجلة من قبل", vbCritical, "خطأ"
End If
End With
End Sub