17-06-20, 02:45 PM
(17-06-20, 02:33 PM)asemshahen5 كتب : ضعه قبل التكست الذي تريد عرض النتيجة به .
كود :
Dim _SumExchange As Double = 0
Dim _CountSum As Integer = 0
Dim _AvgExchange As Double = 0
da = New SqlDataAdapter("select sum(val),sum(val1*exchange_price) from inv,inv_sub where " & CondBranch & " currency_from=" & dtt.Rows(i)(0) & _
" and inv.proc_type=1 and inv_sub.proc_type=1 and inv.proc_id=inv_sub.proc_id and IS_Deleted=0", conn)
dt = New DataTable
da.Fill(dt)
If dt.Rows.Count > 0 And dt.Rows(0)(1).ToString <> "" Then
_SumExchange += Val(dt.Rows(0)(1))
_CountSum += Val(dt.Rows(0)(0))
End If
da = New SqlDataAdapter("select sum(val),sum(val1*exchange_price) from inv,inv_sub where " & CondBranch & " currency_from=" & dtt.Rows(i)(0) & _
" and inv.proc_type=3 and inv.proc_id=inv_sub.proc_id and IS_Deleted=0", conn)
dt = New DataTable
da.Fill(dt)
If dt.Rows.Count > 0 And dt.Rows(0)(1).ToString <> "" Then
_SumExchange += Val(dt.Rows(0)(1))
_CountSum += Val(dt.Rows(0)(0))
End If
Try
_AvgExchange = _SumExchange / _CountSum
_AvgExchange = Math.Floor(_AvgExchange * 100000000)
_AvgExchange = _AvgExchange / 100000000
dgvItems.Rows.Add()
Dim _unit As String = ""
If chkNormal.Checked Then
_unit = GetUnit(dtt.Rows(i)(0))
Else
_unit = GetUnitDefault(dtt.Rows(i)(0))
End If
Dim _perc As Double = 1
If chkDefault.Checked Then
_perc = GetUnitDefaultPerc(dtt.Rows(i)(0))
End If
dgvItems.Rows(dgvItems.Rows.Count - 1).Cells(0).Value = dtt.Rows(i)(0)
dgvItems.Rows(dgvItems.Rows.Count - 1).Cells(1).Value = GetCurrencyName(dtt.Rows(i)(0))
dgvItems.Rows(dgvItems.Rows.Count - 1).Cells(2).Value = Math.Round(Val(dtt.Rows(i)(1)) / _perc, 3)
dgvItems.Rows(dgvItems.Rows.Count - 1).Cells(3).Value = _unit
dgvItems.Rows(dgvItems.Rows.Count - 1).Cells(4).Value = String.Format("{0:0.#,##.##}", _AvgExchange)
dgvItems.Rows(dgvItems.Rows.Count - 1).Cells(5).Value = String.Format("{0:0.#,##.##}", Math.Round(_AvgExchange * Val(dtt.Rows(i)(1)), 4))
dgvItems.Rows(dgvItems.Rows.Count - 1).Cells(6).Value = String.Format("{0:0.#,##.##}", dtshow.Rows(0)("sale_price"))
dgvItems.Rows(dgvItems.Rows.Count - 1).Cells(7).Value = String.Format("{0:0.#,##.##}", Math.Round(Val(dtshow.Rows(0)("sale_price")) * Val(dtt.Rows(i)(1)), 4))
_sum += Math.Round(_AvgExchange * Val(dtt.Rows(i)(1)), 4)
_sum2 += Math.Round(Val(dtshow.Rows(0)("sale_price")) * Val(dtt.Rows(i)(1)), 4)
ProgressBar1.Value += 1
Catch ex As Exception
End Try
End If
Next
txtSum.Text = String.Format("{0:0.#,##.##}", _sum)
txtSum2.Text = String.Format("{0:0.#,##.##}", _sum2)
Catch ex As Exception
Finally
_Finished = True
End Try
End Subحيث ان
select sum(val اجمالى العدد
,sum(val1*exchange_price اجمالى الكمية فى السعر
from inv,inv_sub where من جدولين الفواتير
" & CondBranch & لما يساوى رقم الفرع
" currency_from=" & dtt.Rows(i)(0 لما يساوى رقم الصنف
لو ممكن التعديل على الكود نفسة للانها مش ماشية معايا
حيث سيتم العرض فى الداتا جريد
كل المطلوب انه ميعملش متوسط سعر التكلفة للصنف لكل كمية الصنف من يوم الشراء ولكن يحدد متوسط التكلفة بناء على اخر عمليتين شراء
" and inv.proc_type=1 and inv_sub.proc_type=1 and inv.proc_id=inv_sub.proc_id and IS_Deleted=0", conn)
