PDA

View Full Version : سوال: مشکل ذر یک IF تو در تو



NasimBamdad
پنج شنبه 16 آذر 1391, 12:01 عصر
یکسری کد IF دارم که متاسفانه کار نمی کنه . یعنی خروجی و دستورات رو درست اجرا نمی کنه


if (checkBox1.Checked && checkBox3.Checked)

MessageBox.Show("1-3");

else if (checkBox1.Checked && checkBox2.Checked && checkBox3.Checked)

MessageBox.Show("1-2-3");

else if (checkBox1.Checked && checkBox2.Checked && checkBox3.Checked && checkBox4.Checked)

MessageBox.Show("1-2-3-4");

else if (checkBox2.Checked && checkBox3.Checked)

MessageBox.Show("2-3");

else if (checkBox2.Checked && checkBox3.Checked && checkBox4.Checked)

MessageBox.Show("2-3-4");

else if (checkBox3.Checked)

MessageBox.Show("3");

else if (checkBox3.Checked && checkBox4.Checked)

MessageBox.Show("3-4");

else if (checkBox1.Checked && checkBox3.Checked && checkBox4.Checked)

MessageBox.Show("1-3-4");
else
MessageBox.Show("NOT");


من می خواهم که اون CheckBox هایی که در شرط های IF و Else If اومده اگر اجرا شد ، و نتیجه TRUE شد ، اون MessageBox نمایش داده بشه .

اما این طور نمیشه ، یعنی مثلا وقتی CheckBox1 , CheckBox2 , CheckBox3 چک می خوره ، قسمتی که مربوط به CheckBox3 هست رو اجرا می کنه .

کجای کارم اشتباه هست ؟

saeed.8350028
پنج شنبه 16 آذر 1391, 12:20 عصر
خوب دوست من باید هم جواب نده مثلا زمانی که checkBox1.Checked && checkBox2.Checked && checkBox3.Checked درست باشه حتما checkBox1.Checked && checkBox3.Checked هم درست هست پس همون اولی اجرا می شه و چون شما else گذاشتی پس دومی اجرا نمی شه.
دقیقا بگو چی می خوای تا شاید راه بهتر به نظرمون برسه.
البته می تونی شرط هایی که مقادیر بیشتری را چک می کنند را بالا تر بیاری مثلا توی مثال بالا اول دومین شرط را بیاری.
یا مثلا اول checkBox1 را چک کنی اگه درست بود حالا checkBox2 را چک کنی اگه درست بود جواب 1,2 و اگه دومی اشتباه بود جواب 1. خوب همین را واسه 3 تا بسط بده.
موفق باشی.

zarrinnegar
پنج شنبه 16 آذر 1391, 12:22 عصر
شما باید در تمامی شرط ها مقدار 4 تا چک باکس رو کنترل کنید و اونی رو که نمیخواهید با مقدار false چک کنید وگر نه شرط ها با هم تداخل میکنن
مثلا اگر 1 و 2و 3 رو تیک زده باشید همون اول که 1 و 3 رو چک میکنید شرط بررسی و پیغام ظاهر میشه و از شرط میاد بیرون در صورتیکه شما میخواهید در قسمت مربوط به 1و2و3 اون رو چک کنید


if (chechbox1.checked && checkbox2.checked && chechbox3.cheched && !chechbox4.checked)
messagebox.show("1,2,3");

NasimBamdad
پنج شنبه 16 آذر 1391, 16:34 عصر
لطفا این عکس رو ببینید

لیــــــــــــنــــــــــ ـــــــک (http://www.pcmupload.com/di-P8PC.jpg)

یکسری CheckBox دارم که در هر سری کاربر یکی یا شاید 2 تا ، کلا معلوم نیست ، یا این CheckBox ها کار می کنه و گزارش می سازه

هر سری از این CheckBox ها هم یکسری کد خواهند داشت مثل زیر

int day = Convert.ToInt32(txtProNet1.VDate.Substring(8, 2));
int mon = Convert.ToInt32(txtProNet1.VDate.Substring(5, 2));
int year = Convert.ToInt32(txtProNet1.VDate.Substring(0, 4));
System.Globalization.PersianCalendar pc = new System.Globalization.PersianCalendar();
DateTime dtz = Convert.ToDateTime((pc.ToDateTime(year, mon, day, 0, 0, 0, 0).ToString().Substring(0, 10)));

int day2 = Convert.ToInt32(txtProNet2.VDate.Substring(8, 2));
int mon2 = Convert.ToInt32(txtProNet2.VDate.Substring(5, 2));
int year2 = Convert.ToInt32(txtProNet2.VDate.Substring(0, 4));
System.Globalization.PersianCalendar pc2 = new System.Globalization.PersianCalendar();
DateTime dtz2 = Convert.ToDateTime((pc2.ToDateTime(year2, mon2, day2, 0, 0, 0, 0).ToString().Substring(0, 10)));
stiReport1.Load("Reports\\surgery_list_spec_daily_bime_surgeon_surg ery.mrt");

stiReport1.Dictionary.Variables["V1"].Value = Convert.ToString(dtz);
stiReport1.Dictionary.Variables["V2"].Value = Convert.ToString(dtz2);
stiReport1.Dictionary.Variables["V3"].Value = txtProNet1.VDate;
stiReport1.Dictionary.Variables["V4"].Value = txtProNet2.VDate;
stiReport1.Dictionary.Variables["V5"].Value = comboBox3.Text;
stiReport1.Dictionary.Variables["V6"].Value = Convert.ToString(comboBox1.SelectedValue);
stiReport1.Dictionary.Variables["V7"].Value = Convert.ToString(comboBox4.SelectedValue);
stiReport1.Dictionary.Variables["V8"].Value = Convert.ToString(comboBox3.SelectedValue);
stiReport1.Show();


حالا من باید پیش بینی کنم این 4 تا CheckBox که در هر سری باید و الزام هست که در هر انتخاب و ساخت گزارش ، حتما و حتما و حتما CheckBox3 چک خورده باشه ، چند حالت خواهند داشت .

بعد گزارش مربوط رو براش بسازم !

NasimBamdad
پنج شنبه 16 آذر 1391, 17:02 عصر
یعنی چیدمان های چک خوردن چک باکس رو با احتساب اینکه در هر سری چک باکس 3 باید چک بخوره ، چه حالت های خواهد داشت .

NasimBamdad
پنج شنبه 16 آذر 1391, 17:39 عصر
برای CheckBox 4 چی ؟ چه کدی باید بنویسم ؟

saeed.8350028
پنج شنبه 16 آذر 1391, 19:04 عصر
دوست من پست 3 کاملا صحیح گفته و مشکل شما را حل می کنه.

NasimBamdad
شنبه 18 آذر 1391, 09:56 صبح
if (checkBox1.Checked && checkBox3.Checked && !checkBox2.Checked && !checkBox4.Checked)
{
int day = Convert.ToInt32(txtProNet1.VDate.Substring(8, 2));
int mon = Convert.ToInt32(txtProNet1.VDate.Substring(5, 2));
int year = Convert.ToInt32(txtProNet1.VDate.Substring(0, 4));
System.Globalization.PersianCalendar pc = new System.Globalization.PersianCalendar();
DateTime dtz = Convert.ToDateTime((pc.ToDateTime(year, mon, day, 0, 0, 0, 0).ToString().Substring(0, 10)));

int day2 = Convert.ToInt32(txtProNet2.VDate.Substring(8, 2));
int mon2 = Convert.ToInt32(txtProNet2.VDate.Substring(5, 2));
int year2 = Convert.ToInt32(txtProNet2.VDate.Substring(0, 4));
System.Globalization.PersianCalendar pc2 = new System.Globalization.PersianCalendar();
DateTime dtz2 = Convert.ToDateTime((pc2.ToDateTime(year2, mon2, day2, 0, 0, 0, 0).ToString().Substring(0, 10)));
stiReport1.Load("Reports\\surgery_list_spec_daily_bime_surgeon.mrt");

stiReport1.Dictionary.Variables["V1"].Value = Convert.ToString(dtz);
stiReport1.Dictionary.Variables["V2"].Value = Convert.ToString(dtz2);
stiReport1.Dictionary.Variables["V3"].Value = txtProNet1.VDate;
stiReport1.Dictionary.Variables["V4"].Value = txtProNet2.VDate;
stiReport1.Dictionary.Variables["V5"].Value = comboBox3.Text;
stiReport1.Dictionary.Variables["V6"].Value = Convert.ToString(comboBox1.SelectedValue);
stiReport1.Dictionary.Variables["V7"].Value = Convert.ToString(comboBox3.SelectedValue);
stiReport1.Show();
}

else if (checkBox1.Checked && checkBox2.Checked && checkBox3.Checked && !checkBox4.Checked)
{
int day = Convert.ToInt32(txtProNet1.VDate.Substring(8, 2));
int mon = Convert.ToInt32(txtProNet1.VDate.Substring(5, 2));
int year = Convert.ToInt32(txtProNet1.VDate.Substring(0, 4));
System.Globalization.PersianCalendar pc = new System.Globalization.PersianCalendar();
DateTime dtz = Convert.ToDateTime((pc.ToDateTime(year, mon, day, 0, 0, 0, 0).ToString().Substring(0, 10)));

int day2 = Convert.ToInt32(txtProNet2.VDate.Substring(8, 2));
int mon2 = Convert.ToInt32(txtProNet2.VDate.Substring(5, 2));
int year2 = Convert.ToInt32(txtProNet2.VDate.Substring(0, 4));
System.Globalization.PersianCalendar pc2 = new System.Globalization.PersianCalendar();
DateTime dtz2 = Convert.ToDateTime((pc2.ToDateTime(year2, mon2, day2, 0, 0, 0, 0).ToString().Substring(0, 10)));
stiReport1.Load("Reports\\surgery_list_spec_daily_bime_surgeon_takm ili.mrt");

stiReport1.Dictionary.Variables["V1"].Value = Convert.ToString(dtz);
stiReport1.Dictionary.Variables["V2"].Value = Convert.ToString(dtz2);
stiReport1.Dictionary.Variables["V3"].Value = txtProNet1.VDate;
stiReport1.Dictionary.Variables["V4"].Value = txtProNet2.VDate;
stiReport1.Dictionary.Variables["V5"].Value = comboBox3.Text;
stiReport1.Dictionary.Variables["V6"].Value = Convert.ToString(comboBox1.SelectedValue);
stiReport1.Dictionary.Variables["V7"].Value = Convert.ToString(comboBox2.SelectedValue);
stiReport1.Dictionary.Variables["V8"].Value = Convert.ToString(comboBox3.SelectedValue);
stiReport1.Show();
}
else if (checkBox1.Checked && checkBox2.Checked && checkBox3.Checked && checkBox4.Checked)
{
int day = Convert.ToInt32(txtProNet1.VDate.Substring(8, 2));
int mon = Convert.ToInt32(txtProNet1.VDate.Substring(5, 2));
int year = Convert.ToInt32(txtProNet1.VDate.Substring(0, 4));
System.Globalization.PersianCalendar pc = new System.Globalization.PersianCalendar();
DateTime dtz = Convert.ToDateTime((pc.ToDateTime(year, mon, day, 0, 0, 0, 0).ToString().Substring(0, 10)));

int day2 = Convert.ToInt32(txtProNet2.VDate.Substring(8, 2));
int mon2 = Convert.ToInt32(txtProNet2.VDate.Substring(5, 2));
int year2 = Convert.ToInt32(txtProNet2.VDate.Substring(0, 4));
System.Globalization.PersianCalendar pc2 = new System.Globalization.PersianCalendar();
DateTime dtz2 = Convert.ToDateTime((pc2.ToDateTime(year2, mon2, day2, 0, 0, 0, 0).ToString().Substring(0, 10)));
stiReport1.Load("Reports\\surgery_list_spec_daily_bime_surgeon_takm ili_surgery.mrt");

stiReport1.Dictionary.Variables["V1"].Value = Convert.ToString(dtz);
stiReport1.Dictionary.Variables["V2"].Value = Convert.ToString(dtz2);
stiReport1.Dictionary.Variables["V3"].Value = txtProNet1.VDate;
stiReport1.Dictionary.Variables["V4"].Value = txtProNet2.VDate;
stiReport1.Dictionary.Variables["V5"].Value = comboBox3.Text;
stiReport1.Dictionary.Variables["V6"].Value = Convert.ToString(comboBox1.SelectedValue);
stiReport1.Dictionary.Variables["V7"].Value = Convert.ToString(comboBox2.SelectedValue);
stiReport1.Dictionary.Variables["V8"].Value = Convert.ToString(comboBox3.SelectedValue);
stiReport1.Dictionary.Variables["V9"].Value = Convert.ToString(comboBox4.SelectedValue);
stiReport1.Show();
}
else if (checkBox3.Checked && !checkBox1.Checked && !checkBox2.Checked && !checkBox4.Checked)
{
int day = Convert.ToInt32(txtProNet1.VDate.Substring(8, 2));
int mon = Convert.ToInt32(txtProNet1.VDate.Substring(5, 2));
int year = Convert.ToInt32(txtProNet1.VDate.Substring(0, 4));
System.Globalization.PersianCalendar pc = new System.Globalization.PersianCalendar();
DateTime dtz = Convert.ToDateTime((pc.ToDateTime(year, mon, day, 0, 0, 0, 0).ToString().Substring(0, 10)));

int day2 = Convert.ToInt32(txtProNet2.VDate.Substring(8, 2));
int mon2 = Convert.ToInt32(txtProNet2.VDate.Substring(5, 2));
int year2 = Convert.ToInt32(txtProNet2.VDate.Substring(0, 4));
System.Globalization.PersianCalendar pc2 = new System.Globalization.PersianCalendar();
DateTime dtz2 = Convert.ToDateTime((pc2.ToDateTime(year2, mon2, day2, 0, 0, 0, 0).ToString().Substring(0, 10)));
stiReport1.Load("Reports\\surgery_list_spec_daily_surgeon.mrt");

stiReport1.Dictionary.Variables["V1"].Value = Convert.ToString(dtz);
stiReport1.Dictionary.Variables["V2"].Value = Convert.ToString(dtz2);
stiReport1.Dictionary.Variables["V3"].Value = txtProNet1.VDate;
stiReport1.Dictionary.Variables["V4"].Value = txtProNet2.VDate;
stiReport1.Dictionary.Variables["V5"].Value = comboBox3.Text;
stiReport1.Dictionary.Variables["V6"].Value = Convert.ToString(comboBox3.SelectedValue);
stiReport1.Show();
}
else if (checkBox3.Checked && checkBox4.Checked && !checkBox1.Checked && !checkBox2.Checked)
{
int day = Convert.ToInt32(txtProNet1.VDate.Substring(8, 2));
int mon = Convert.ToInt32(txtProNet1.VDate.Substring(5, 2));
int year = Convert.ToInt32(txtProNet1.VDate.Substring(0, 4));
System.Globalization.PersianCalendar pc = new System.Globalization.PersianCalendar();
DateTime dtz = Convert.ToDateTime((pc.ToDateTime(year, mon, day, 0, 0, 0, 0).ToString().Substring(0, 10)));

int day2 = Convert.ToInt32(txtProNet2.VDate.Substring(8, 2));
int mon2 = Convert.ToInt32(txtProNet2.VDate.Substring(5, 2));
int year2 = Convert.ToInt32(txtProNet2.VDate.Substring(0, 4));
System.Globalization.PersianCalendar pc2 = new System.Globalization.PersianCalendar();
DateTime dtz2 = Convert.ToDateTime((pc2.ToDateTime(year2, mon2, day2, 0, 0, 0, 0).ToString().Substring(0, 10)));
stiReport1.Load("Reports\\surgery_list_spec_daily_surgeon_surgery.m rt");

stiReport1.Dictionary.Variables["V1"].Value = Convert.ToString(dtz);
stiReport1.Dictionary.Variables["V2"].Value = Convert.ToString(dtz2);
stiReport1.Dictionary.Variables["V3"].Value = txtProNet1.VDate;
stiReport1.Dictionary.Variables["V4"].Value = txtProNet2.VDate;
stiReport1.Dictionary.Variables["V5"].Value = comboBox3.Text;
stiReport1.Dictionary.Variables["V6"].Value = Convert.ToString(comboBox3.SelectedValue);
stiReport1.Dictionary.Variables["V7"].Value = Convert.ToString(comboBox4.SelectedValue);
stiReport1.Show();
}
else if (checkBox1.Checked && checkBox3.Checked && checkBox4.Checked && !checkBox2.Checked)
{
int day = Convert.ToInt32(txtProNet1.VDate.Substring(8, 2));
int mon = Convert.ToInt32(txtProNet1.VDate.Substring(5, 2));
int year = Convert.ToInt32(txtProNet1.VDate.Substring(0, 4));
System.Globalization.PersianCalendar pc = new System.Globalization.PersianCalendar();
DateTime dtz = Convert.ToDateTime((pc.ToDateTime(year, mon, day, 0, 0, 0, 0).ToString().Substring(0, 10)));

int day2 = Convert.ToInt32(txtProNet2.VDate.Substring(8, 2));
int mon2 = Convert.ToInt32(txtProNet2.VDate.Substring(5, 2));
int year2 = Convert.ToInt32(txtProNet2.VDate.Substring(0, 4));
System.Globalization.PersianCalendar pc2 = new System.Globalization.PersianCalendar();
DateTime dtz2 = Convert.ToDateTime((pc2.ToDateTime(year2, mon2, day2, 0, 0, 0, 0).ToString().Substring(0, 10)));
stiReport1.Load("Reports\\surgery_list_spec_daily_bime_surgeon_surg ery.mrt");

stiReport1.Dictionary.Variables["V1"].Value = Convert.ToString(dtz);
stiReport1.Dictionary.Variables["V2"].Value = Convert.ToString(dtz2);
stiReport1.Dictionary.Variables["V3"].Value = txtProNet1.VDate;
stiReport1.Dictionary.Variables["V4"].Value = txtProNet2.VDate;
stiReport1.Dictionary.Variables["V5"].Value = comboBox3.Text;
stiReport1.Dictionary.Variables["V6"].Value = Convert.ToString(comboBox1.SelectedValue);
stiReport1.Dictionary.Variables["V7"].Value = Convert.ToString(comboBox4.SelectedValue);
stiReport1.Dictionary.Variables["V8"].Value = Convert.ToString(comboBox3.SelectedValue);
stiReport1.Show();
}
//////////
else if (!checkBox1.Checked && !checkBox4.Checked && checkBox2.Checked && checkBox3.Checked)
{
int day = Convert.ToInt32(txtProNet1.VDate.Substring(8, 2));
int mon = Convert.ToInt32(txtProNet1.VDate.Substring(5, 2));
int year = Convert.ToInt32(txtProNet1.VDate.Substring(0, 4));
System.Globalization.PersianCalendar pc = new System.Globalization.PersianCalendar();
DateTime dtz = Convert.ToDateTime((pc.ToDateTime(year, mon, day, 0, 0, 0, 0).ToString().Substring(0, 10)));

int day2 = Convert.ToInt32(txtProNet2.VDate.Substring(8, 2));
int mon2 = Convert.ToInt32(txtProNet2.VDate.Substring(5, 2));
int year2 = Convert.ToInt32(txtProNet2.VDate.Substring(0, 4));
System.Globalization.PersianCalendar pc2 = new System.Globalization.PersianCalendar();
DateTime dtz2 = Convert.ToDateTime((pc2.ToDateTime(year2, mon2, day2, 0, 0, 0, 0).ToString().Substring(0, 10)));
stiReport1.Load("Reports\\surgery_list_spec_daily_takmili_surgeon.m rt");

stiReport1.Dictionary.Variables["V1"].Value = Convert.ToString(dtz);
stiReport1.Dictionary.Variables["V2"].Value = Convert.ToString(dtz2);
stiReport1.Dictionary.Variables["V3"].Value = txtProNet1.VDate;
stiReport1.Dictionary.Variables["V4"].Value = txtProNet2.VDate;
stiReport1.Dictionary.Variables["V5"].Value = comboBox3.Text;
stiReport1.Dictionary.Variables["V6"].Value = Convert.ToString(comboBox2.SelectedValue);
stiReport1.Dictionary.Variables["V7"].Value = Convert.ToString(comboBox3.SelectedValue);
}
else if (checkBox2.Checked && checkBox3.Checked && checkBox4.Checked && !checkBox1.Checked)
{
int day = Convert.ToInt32(txtProNet1.VDate.Substring(8, 2));
int mon = Convert.ToInt32(txtProNet1.VDate.Substring(5, 2));
int year = Convert.ToInt32(txtProNet1.VDate.Substring(0, 4));
System.Globalization.PersianCalendar pc = new System.Globalization.PersianCalendar();
DateTime dtz = Convert.ToDateTime((pc.ToDateTime(year, mon, day, 0, 0, 0, 0).ToString().Substring(0, 10)));

int day2 = Convert.ToInt32(txtProNet2.VDate.Substring(8, 2));
int mon2 = Convert.ToInt32(txtProNet2.VDate.Substring(5, 2));
int year2 = Convert.ToInt32(txtProNet2.VDate.Substring(0, 4));
System.Globalization.PersianCalendar pc2 = new System.Globalization.PersianCalendar();
DateTime dtz2 = Convert.ToDateTime((pc2.ToDateTime(year2, mon2, day2, 0, 0, 0, 0).ToString().Substring(0, 10)));
stiReport1.Load("Reports\\surgery_list_spec_daily_takmili_surgeon_s urgery.mrt");

stiReport1.Dictionary.Variables["V1"].Value = Convert.ToString(dtz);
stiReport1.Dictionary.Variables["V2"].Value = Convert.ToString(dtz2);
stiReport1.Dictionary.Variables["V3"].Value = txtProNet1.VDate;
stiReport1.Dictionary.Variables["V4"].Value = txtProNet2.VDate;
stiReport1.Dictionary.Variables["V5"].Value = comboBox3.Text;
stiReport1.Dictionary.Variables["V6"].Value = Convert.ToString(comboBox2.SelectedValue);
stiReport1.Dictionary.Variables["V7"].Value = Convert.ToString(comboBox3.SelectedValue);
stiReport1.Dictionary.Variables["V8"].Value = Convert.ToString(comboBox4.SelectedValue);
}


من کد ها رو به این صورت تغییر دادم . همه IF ها اجرا می شوند به جز 2 Else if آخر . یعنی این 2 تا


else if (!checkBox1.Checked && !checkBox4.Checked && checkBox2.Checked && checkBox3.Checked)
{
int day = Convert.ToInt32(txtProNet1.VDate.Substring(8, 2));
int mon = Convert.ToInt32(txtProNet1.VDate.Substring(5, 2));
int year = Convert.ToInt32(txtProNet1.VDate.Substring(0, 4));
System.Globalization.PersianCalendar pc = new System.Globalization.PersianCalendar();
DateTime dtz = Convert.ToDateTime((pc.ToDateTime(year, mon, day, 0, 0, 0, 0).ToString().Substring(0, 10)));

int day2 = Convert.ToInt32(txtProNet2.VDate.Substring(8, 2));
int mon2 = Convert.ToInt32(txtProNet2.VDate.Substring(5, 2));
int year2 = Convert.ToInt32(txtProNet2.VDate.Substring(0, 4));
System.Globalization.PersianCalendar pc2 = new System.Globalization.PersianCalendar();
DateTime dtz2 = Convert.ToDateTime((pc2.ToDateTime(year2, mon2, day2, 0, 0, 0, 0).ToString().Substring(0, 10)));
stiReport1.Load("Reports\\surgery_list_spec_daily_takmili_surgeon.m rt");

stiReport1.Dictionary.Variables["V1"].Value = Convert.ToString(dtz);
stiReport1.Dictionary.Variables["V2"].Value = Convert.ToString(dtz2);
stiReport1.Dictionary.Variables["V3"].Value = txtProNet1.VDate;
stiReport1.Dictionary.Variables["V4"].Value = txtProNet2.VDate;
stiReport1.Dictionary.Variables["V5"].Value = comboBox3.Text;
stiReport1.Dictionary.Variables["V6"].Value = Convert.ToString(comboBox2.SelectedValue);
stiReport1.Dictionary.Variables["V7"].Value = Convert.ToString(comboBox3.SelectedValue);
}
else if (checkBox2.Checked && checkBox3.Checked && checkBox4.Checked && !checkBox1.Checked)
{
int day = Convert.ToInt32(txtProNet1.VDate.Substring(8, 2));
int mon = Convert.ToInt32(txtProNet1.VDate.Substring(5, 2));
int year = Convert.ToInt32(txtProNet1.VDate.Substring(0, 4));
System.Globalization.PersianCalendar pc = new System.Globalization.PersianCalendar();
DateTime dtz = Convert.ToDateTime((pc.ToDateTime(year, mon, day, 0, 0, 0, 0).ToString().Substring(0, 10)));

int day2 = Convert.ToInt32(txtProNet2.VDate.Substring(8, 2));
int mon2 = Convert.ToInt32(txtProNet2.VDate.Substring(5, 2));
int year2 = Convert.ToInt32(txtProNet2.VDate.Substring(0, 4));
System.Globalization.PersianCalendar pc2 = new System.Globalization.PersianCalendar();
DateTime dtz2 = Convert.ToDateTime((pc2.ToDateTime(year2, mon2, day2, 0, 0, 0, 0).ToString().Substring(0, 10)));
stiReport1.Load("Reports\\surgery_list_spec_daily_takmili_surgeon_s urgery.mrt");

stiReport1.Dictionary.Variables["V1"].Value = Convert.ToString(dtz);
stiReport1.Dictionary.Variables["V2"].Value = Convert.ToString(dtz2);
stiReport1.Dictionary.Variables["V3"].Value = txtProNet1.VDate;
stiReport1.Dictionary.Variables["V4"].Value = txtProNet2.VDate;
stiReport1.Dictionary.Variables["V5"].Value = comboBox3.Text;
stiReport1.Dictionary.Variables["V6"].Value = Convert.ToString(comboBox2.SelectedValue);
stiReport1.Dictionary.Variables["V7"].Value = Convert.ToString(comboBox3.SelectedValue);
stiReport1.Dictionary.Variables["V8"].Value = Convert.ToString(comboBox4.SelectedValue);
}


چه باید کرد ؟

mousa1992
شنبه 18 آذر 1391, 10:20 صبح
عزیز چرا این کارو میکنی :-o
شما با ی حلقه بیا همه کنترل های checkBox رو چک بکن و هر کدوم که چک خورده بود نمایش بده و یا از مشخصه هاش استفاده کن و هر کاری که دوس داری چرا این همه شرط !!

NasimBamdad
شنبه 18 آذر 1391, 11:03 صبح
میشه یه مثال کوچیک برام بزنی ؟ ممنون میشم !

mousa1992
شنبه 18 آذر 1391, 11:12 صبح
foreach (Control control in this.Controls)
{
if (control is CheckBox && ((CheckBox)control).Checked)
{
// .....
}

}

NasimBamdad
یک شنبه 19 آذر 1391, 17:24 عصر
foreach (Control control in this.Controls)
{
if (control is CheckBox && ((CheckBox)control).Checked)
{
// .....
}

}

یه سوال ، الان من چه طوری CheckBox های مختلف رو تشخیص بدم ؟ بگم مثلا CheckBox1 و CheckBox4 اگه تیک خوردن این کد اجرا بشه !؟

NasimBamdad
دوشنبه 20 آذر 1391, 10:12 صبح
چون شرط هات به چند چک باکس وابسته است نمیشه فقط با حلقه این کار رو انجام داد چون در حلقه در هر بار تکرار فقط یک چک باکس بررسی میشه.

کدهای تکراری رو از داخل if ها خارج کنید. متد show مربوط به گزارش را هم به آخر ببرید. و یک سوال اینکه چرا تاریخ را هم شمسی و هم میلادیش رو ذخیره میکنی؟!!


if (checkBox3.Checked)
{
int day = Convert.ToInt32(txtProNet1.VDate.Substring(8, 2));
int mon = Convert.ToInt32(txtProNet1.VDate.Substring(5, 2));
int year = Convert.ToInt32(txtProNet1.VDate.Substring(0, 4));
DateTime dtz = new DateTime(year, mon, day , new PersianCalendar());

int day2 = Convert.ToInt32(txtProNet2.VDate.Substring(8, 2));
int mon2 = Convert.ToInt32(txtProNet2.VDate.Substring(5, 2));
int year2 = Convert.ToInt32(txtProNet2.VDate.Substring(0, 4));
DateTime dtz2 = new DateTime(year2, mon2, day2,new PersianCalendar());

stiReport1.Dictionary.Variables["V1"].Value = Convert.ToString(dtz);
stiReport1.Dictionary.Variables["V2"].Value = Convert.ToString(dtz2);
stiReport1.Dictionary.Variables["V3"].Value = txtProNet1.VDate;
stiReport1.Dictionary.Variables["V4"].Value = txtProNet2.VDate;
stiReport1.Dictionary.Variables["V5"].Value = comboBox3.Text;

if (checkBox1.Checked && !checkBox2.Checked && !checkBox4.Checked)
{
stiReport1.Load("Reports\\surgery_list_spec_daily_bime_surgeon.mrt");

stiReport1.Dictionary.Variables["V6"].Value = Convert.ToString(comboBox1.SelectedValue);
stiReport1.Dictionary.Variables["V7"].Value = Convert.ToString(comboBox3.SelectedValue);
}
else if (checkBox1.Checked && checkBox2.Checked && !checkBox4.Checked)
{
stiReport1.Load("Reports\\surgery_list_spec_daily_bime_surgeon_takm ili.mrt");
stiReport1.Dictionary.Variables["V6"].Value = Convert.ToString(comboBox1.SelectedValue);
stiReport1.Dictionary.Variables["V7"].Value = Convert.ToString(comboBox2.SelectedValue);
stiReport1.Dictionary.Variables["V8"].Value = Convert.ToString(comboBox3.SelectedValue);
}
else if (checkBox1.Checked && checkBox2.Checked && checkBox4.Checked)
{
stiReport1.Load("Reports\\surgery_list_spec_daily_bime_surgeon_takm ili_surgery.mrt");
stiReport1.Dictionary.Variables["V6"].Value = Convert.ToString(comboBox1.SelectedValue);
stiReport1.Dictionary.Variables["V7"].Value = Convert.ToString(comboBox2.SelectedValue);
stiReport1.Dictionary.Variables["V8"].Value = Convert.ToString(comboBox3.SelectedValue);
stiReport1.Dictionary.Variables["V9"].Value = Convert.ToString(comboBox4.SelectedValue);
}
else if (!checkBox1.Checked && !checkBox2.Checked && !checkBox4.Checked)
{
stiReport1.Load("Reports\\surgery_list_spec_daily_surgeon.mrt");
stiReport1.Dictionary.Variables["V6"].Value = Convert.ToString(comboBox3.SelectedValue);
}
else if (!checkBox1.Checked && !checkBox2.Checked && checkBox4.Checked)
{
stiReport1.Load("Reports\\surgery_list_spec_daily_surgeon_surgery.m rt");
stiReport1.Dictionary.Variables["V6"].Value = Convert.ToString(comboBox3.SelectedValue);
stiReport1.Dictionary.Variables["V7"].Value = Convert.ToString(comboBox4.SelectedValue);
}
else if (checkBox1.Checked && !checkBox2.Checked && checkBox4.Checked)
{
stiReport1.Load("Reports\\surgery_list_spec_daily_bime_surgeon_surg ery.mrt");
stiReport1.Dictionary.Variables["V6"].Value = Convert.ToString(comboBox1.SelectedValue);
stiReport1.Dictionary.Variables["V7"].Value = Convert.ToString(comboBox4.SelectedValue);
stiReport1.Dictionary.Variables["V8"].Value = Convert.ToString(comboBox3.SelectedValue);
}
else if (!checkBox1.Checked && checkBox2.Checked && !checkBox4.Checked)
{
stiReport1.Load("Reports\\surgery_list_spec_daily_takmili_surgeon.m rt");
stiReport1.Dictionary.Variables["V6"].Value = Convert.ToString(comboBox2.SelectedValue);
stiReport1.Dictionary.Variables["V7"].Value = Convert.ToString(comboBox3.SelectedValue);
}
else if (!checkBox1.Checked && checkBox2.Checked && checkBox4.Checked)
{
stiReport1.Load("Reports\\surgery_list_spec_daily_takmili_surgeon_s urgery.mrt");
stiReport1.Dictionary.Variables["V6"].Value = Convert.ToString(comboBox2.SelectedValue);
stiReport1.Dictionary.Variables["V7"].Value = Convert.ToString(comboBox3.SelectedValue);
stiReport1.Dictionary.Variables["V8"].Value = Convert.ToString(comboBox4.SelectedValue);
}
stiReport1.Show();


مرسی دوست عزیز . میرم که چک کنم کد ها رو . ممنون که زمان گذاشتید .

تاریخ رو من به صورت شمسی و میلادی در دیتابیس دارم . برای نمایش به کاربر شمسی رو نشون میدم و برای کار کردن و گزارش گیری میلادی .

یادم میاد در ورژن های قدیمی StimulReport تاریخ شمسی رو نمی گرفت .

NasimBamdad
دوشنبه 20 آذر 1391, 10:38 صبح
پست شماره 8 درست هست و مشکلی نداره . اون 2 Else آخر هم چون متد stiReport1.Show(); رو صدا نزده بودم اجرا نمی شدند .


ممنونم از همه عزیزانی که اطلاعات کم من رو افزایش دادند ! ! ! !