
نوشته شده توسط
__H2__
سلام
میشه بفرمائید برای چی در گزارش نیاز به جدول موقت دارید؟! و یک مثال هم بزنید؟
سلام دوست عزیز ، ممنون از توجهی که دارید
من می خوام در یک برنامه حسابداری یک گزارش تهیه کنم که به علت تنوع فیلتری که روی گزارش ایجاد می شود لازم هست در مرحله انجام شود که علت اصلی آن تداخل عملگر or با سایر دستورات می باشد.
PrivateSub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
If TextBox2.Text = ""And TextBox1.Text = ""And CheckBox1.Checked = FalseAnd CheckBox2.Checked = FalseAnd CheckBox3.Checked = FalseThen
MessageBoxFa.Show("لطفا ترکیب گزارش را مشخص کنید.", "هشدار", MessageBoxButtons.OK, MessageBoxIcon.Warning)
ExitSub
EndIf
'************************************************* ***********
Dim bol_where AsBoolean = False
Dim str_select AsString = ""
Dim sqlDtAdp AsNew Data.SqlClient.SqlDataAdapter("", con)
Dim sqlCom AsNew SqlClient.SqlCommand("", con)
If con.State = ConnectionState.Closed Then con.Open()
Dim DropText AsString = Nothing
DropText = "DROP TABLE #temp"
Try
With sqlCom
.Parameters.Clear()
.CommandText = DropText
.ExecuteNonQuery()
EndWith
Catch ex As Exception
EndTry
'************************************************* ****************************
str_select = "SELECT 'mbed' = SUM(bed_best.bed) - SUM(bed_best.best)," + _
" hesab.city,hesab.masir,bed_best.id, bed_best.complet_name, SUM(bed_best.bed) AS bed," + _
" SUM(bed_best.best) AS best INTO #temp FROM bed_best " + _
" INNER JOIN hesab ON bed_best.id = hesab.id_tafzil"' GROUP BY bed_best.id," + _
' " bed_best.complet_name,hesab.city,hesab.masir"
If TextBox2.Text <> ""Then' فیلتر برای شهر و مسیر
If ComboBox1.Text <> ""Then
If bol_where = TrueThen
str_select &= " and hesab.city=N'" & TextBox2.Text & "' and hesab.masir=N'" & ComboBox1.Text & "'"
Else
bol_where = True
str_select &= " where hesab.city=N'" & TextBox2.Text & "' and hesab.masir=N'" & ComboBox1.Text & "'"
EndIf
Else
If bol_where = TrueThen
str_select &= " and hesab.city=N'" & TextBox2.Text & "'"
Else
bol_where = True
str_select &= " where hesab.city=N'" & TextBox2.Text & "'"
EndIf
EndIf
EndIf
str_select &= " GROUP BY bed_best.id, bed_best.complet_name,hesab.city,hesab.masir"
'************************************************* ****************************
With sqlCom
.Parameters.Clear()
.CommandText = str_select
.ExecuteNonQuery()
EndWith
'************************************************* ****************************
bol_where = False
'************************************************* ****************************
str_select = "select id, complet_name,best,bed,mbed,city,masir from #temp "
If TextBox1.Text <> ""And TextBox1.Enabled = TrueThen
str_select &= " where complet_name=N'" & TextBox1.Text & "'"' فیلتر برای یک شخص مشخص
Else
If CheckBox1.Checked = TrueThen'افرادی بدهکار
If bol_where = TrueThen
str_select &= " or mbed>0 "
Else
bol_where = True
str_select &= " where mbed>0 "
EndIf
EndIf
If CheckBox2.Checked = TrueThen
If bol_where = TrueThen
str_select &= " or mbed<0 "'افراد بستانکار
Else
bol_where = True
str_select &= " where mbed<0 "
EndIf
EndIf
If CheckBox3.Checked = TrueThen' افراد بی حساب
If bol_where = TrueThen
str_select &= " or mbed=0 "
Else
bol_where = True
str_select &= " where mbed=0 "
EndIf
EndIf
EndIf
'************************************************* *********************************
Dim name_co AsString = ""
Dim cmd7 As SqlCommand = New SqlCommand("select name from k_af where id='7'", con)
Dim obj7 AsObject = cmd7.ExecuteScalar
If obj7 IsNot DBNull.Value = TrueAnd obj7 IsNotNothing = TrueThen
name_co = CType(obj7, String)
EndIf
'************************************************* ***
Dim info AsString = ""
Dim cmd11 As SqlCommand = New SqlCommand("select name from k_af where id='11'", con)
Dim obj11 AsObject = cmd11.ExecuteScalar
If obj11 IsNot DBNull.Value = TrueAnd obj11 IsNotNothing = TrueThen
info = CType(obj11, String)
EndIf
'************************************************* ***
da = New SqlClient.SqlDataAdapter(str_select, con)
ds = New DataSet
da.Fill(ds, "temp")
Dim cr2 AsNew RptBedBest
cr2.SetDataSource(ds.Tables("temp"))
If CheckBox4.Checked = TrueThen
cr2.SetParameterValue("name_co", name_co)
Else
cr2.SetParameterValue("name_co", "")
EndIf
If CheckBox5.Checked = TrueThen
cr2.SetParameterValue("info", info)
Else
cr2.SetParameterValue("info", "")
EndIf
cr2.SetParameterValue("date1", shamsi())
FrmRptdariaftani1.CrystalReportViewer1.ReportSourc e = cr2
FrmRptdariaftani1.Text = "بدهکاران و بستانکاران"
FrmRptdariaftani1.Show()
cr2.Clone()
EndSub
اینم تصویر فرمی که کاربر ترکیب گزارش را مشخص می کند. شاید با تصویر بهتر متوجه منظورم بشید . البته من می تونم با veiw هم این کار رو انجام بدم ولی باید به تعداد زیادی(برای هر گزارش یکی بسازم) این کار رو انجام بدم و در ضمن سرعت ایجاد و حذف temp table به نظر بیشتر باشه.

دو تا لینک گذاشته بودم اگه می شه به این تاپیک هم سری بزنید.https://barnamenevis.org/showthread.php?t=168146
بازم ممنون از کمکی که انجام می دید.