BTC USD 81,506.8 Gold USD 4,352.82
Time now: Jun 1, 12:00 AM

C#.Net : Logik untuk 4 conditon query

mutanic

Super Active Member
Messages
5,538
Joined
May 24, 2009
Messages
5,538
Reaction score
213
Points
73
Salam sume, sori aku tanya soalan noob camni...skrg ni aku nak wat if statement tp ntah apsal arini cpu aku overheat sket x dpt nak fikir betul2...

Contoh camni, aku ada :

Search by textbox1
Search by textbox2
Search by textbox3
Search by textbox4
Button Search

aku jadi blur nak wat if statement untuk 4 condition ni, contoh aku wat dlm bentuk "0" atau "1"..."0" bermakna textbox tu "null" & camtu sebaliknya kalu "1" bermakna textbox tu ada value...

0000 ~ Please fill in the textbox
1000 ~ textbox1 condition True(ada value) but the rest False(xda value)
1100 ~ textbox1 & textbox2 is True(ada value) but textbox3 & textbox4 is False(xda value)
1110 ~ textbox1, textbox2 & textbox3 is True(ada value) but textbox4 is False(xda value)
1111 ~ All textbox condition True(ada value)
dan seterusnya berapa maksimum condition yg aku bleh dpt...~X(~X(~X(

TQ sume di atas jasa korang, kalu ada cara yg memudahkan sila la propose kat aku...benda ni bila click button tu akan execute search function untuk query data berdasarkan condition2 ni...
 
X berapa nak pham maksud tt,
tp aku agak yg tt nk buat multiple search?

ada 4 input, so user boleh isi mna2 input tersebut lalu buat carian?
 
X berapa nak pham maksud tt,
tp aku agak yg tt nk buat multiple search?

ada 4 input, so user boleh isi mna2 input tersebut lalu buat carian?

a'aaa...betul la tu...sori kepala tgh blur ni...:)):)):))
 
a'aaa...betul la tu...sori kepala tgh blur ni...:)):)):))

hehe..
nk coding dlm c# xtaw la aku..

tp bg aku..x perlu nk compare satu2 input tu.

just make sure input ada value saja.

cth.

if txt1 && txt2 && txt3 && txt4 =='', prompt error.

klau salah satu ada value, go on with search.

ok x mcm ne?
 
agak2 ada yg aku miss x???:-?

attachment.php


aku dapat 16 condition?! :eek::eek::eek:
 
Last edited:
hehe..
nk coding dlm c# xtaw la aku..

tp bg aku..x perlu nk compare satu2 input tu.

just make sure input ada value saja.

cth.

if txt1 && txt2 && txt3 && txt4 =='', prompt error.

klau salah satu ada value, go on with search.

ok x mcm ne?
tu kalu sume null baru prompt bro, aku nak set query base on value kat object tu...#:-S

ntah apsal aku blur teruk sgt arini...~X(
 
haha...aku tak sukakan C# psl lambat dan bahasa ni mcm bahasa 'press button' serupalah dgn java.

tp ini le yg aku faham apa yg tt nak wat. aku kasi logik, tt cuba tukat ke c#.

// perika sama ada value ada ke tak
if ( chckbox1 atau chkbox2 atau chkbox3 atau chkbox4 == "") {
//buat sesuatu...
} else {
// mulakan carian...
}
 
Ni contoh query base on condition sebelum ni, tetiba change request tambah lagi satu condition...

Skrg ada :

txtLookupAccount
txtLookupCustomer
ddlLookupBC ~ baru masuk, cisss!!!
ddlLookupSector


if (!string.IsNullOrEmpty(txtLookupAccount.Text) && string.IsNullOrEmpty(txtLookupCustomer.Text) && ddlLookupSector.SelectedIndex == 0)
{ spQuery.Query = "<Where><Contains><FieldRef Name='AccountNo' /><Value Type='Text'>" + txtLookupAccount.Text + "</Value></Contains></Where>"; }

if (!string.IsNullOrEmpty(txtLookupAccount.Text) && !string.IsNullOrEmpty(txtLookupCustomer.Text) && ddlLookupSector.SelectedIndex == 0)
{ spQuery.Query = "<Where><And><Contains><FieldRef Name='AccountNo' /><Value Type='Text'>" + txtLookupAccount.Text + "</Value></Contains><Contains><FieldRef Name='Title' /><Value Type='Text'>" + txtLookupCustomer.Text + "</Value></Contains></And></Where>"; }

if (!string.IsNullOrEmpty(txtLookupAccount.Text) && !string.IsNullOrEmpty(txtLookupCustomer.Text) && ddlLookupSector.SelectedIndex > 0)
{ spQuery.Query = "<Where><And><Contains><FieldRef Name='AccountNo' /><Value Type='Text'>" + txtLookupAccount.Text + "</Value></Contains><And><Contains><FieldRef Name='Title' /><Value Type='Text'>" + txtLookupCustomer.Text + "</Value></Contains><Contains><FieldRef Name='Sector' /><Value Type='Choice'>" + ddlLookupSector.SelectedItem.Text + "</Value></Contains></And></And></Where>"; }

if (!string.IsNullOrEmpty(txtLookupAccount.Text) && string.IsNullOrEmpty(txtLookupCustomer.Text) && ddlLookupSector.SelectedIndex > 0)
{ spQuery.Query = "<Where><And><Contains><FieldRef Name='AccountNo' /><Value Type='Text'>" + txtLookupAccount.Text + "</Value></Contains><Contains><FieldRef Name='Sector' /><Value Type='Choice'>" + ddlLookupSector.SelectedItem.Text + "</Value></Contains></And></Where>"; }

if (string.IsNullOrEmpty(txtLookupAccount.Text) && !string.IsNullOrEmpty(txtLookupCustomer.Text) && ddlLookupSector.SelectedIndex == 0)
{ spQuery.Query = "<Where><Contains><FieldRef Name='Title' /><Value Type='Text'>" + txtLookupCustomer.Text + "</Value></Contains></Where>"; }

if (string.IsNullOrEmpty(txtLookupAccount.Text) && !string.IsNullOrEmpty(txtLookupCustomer.Text) && ddlLookupSector.SelectedIndex > 0)
{ spQuery.Query = "<Where><And><Contains><FieldRef Name='Title' /><Value Type='Text'>" + txtLookupCustomer.Text + "</Value></Contains><Contains><FieldRef Name='Sector' /><Value Type='Choice'>" + ddlLookupSector.SelectedItem.Text + "</Value></Contains></And></Where>"; }

if (string.IsNullOrEmpty(txtLookupAccount.Text) && string.IsNullOrEmpty(txtLookupCustomer.Text) && ddlLookupSector.SelectedIndex > 0)
{ spQuery.Query = "<Where><Contains><FieldRef Name='Sector' /><Value Type='Choice'>" + ddlLookupSector.SelectedItem.Text + "</Value></Contains></Where>"; }
 
Back
Top
Log in Register