الفريق العربي للبرمجةأرشيف المنتديات · 2000 – 2023
نسخة أرشيفية للقراءة فقط — التسجيل والمشاركة مغلقان، والمحتوى محفوظ كما كان.

مشكلة غريبة: عند وضع جملة if داخل وظيفة ... ؟

بدأه red_scorpion1 في 1 يوليو 2012 · 2 رد · 400 مشاهدة · في Microsoft Visual C#.NET
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

السلام عليكم ورحمة الله وبركاته

قمت بعمل وظيفة

private Void no_emp()
{
if (tx_id.Text == "")
            {
                MessageBox.Show("لا يوجد اى موظفين كى يتم الحفظ");
                return;
            }
            else if (tx_mon.Text == "")
            {
                MessageBox.Show("يجب اختيار الشهر");
                return;
            }
            else if (tx_tk.Text == "")
            {
                MessageBox.Show("يجب إدخال نسبة التحقيق");
                return;
            }
            else if (tx_th.Text == "")
            {
                MessageBox.Show("يجب إدخال نسبة التحصيل");
                return;
            }
            else if (tx_late.Text == "")
            {
                MessageBox.Show("يجب إدخال عدد دقائق التأخير");
                return;
            }
            else if (tx_ezn.Text == "")
            {
                MessageBox.Show("يجب إدخال عدد الإذون");
                return;
            }
            else if (tx_geza.Text == "")
            {
                MessageBox.Show("يجب إدخال عدد الجزاءات");
                return;
            }
            else if (tx_ghy.Text == "")
            {
                MessageBox.Show("يجب إدخال عدد أيام الغياب");
                return;
            }
            else if (tx_deg.Text == "")
            {
                MessageBox.Show("يجب إدخال التقييم الشهرى");
                return;
            }
}

وعند تنفيذها تظهر الرسالة المطلوبة ثم يكمل البرنامج الكود بالرغم من إستدعائى الوظيفة فى الكود

this.no_emp();

عند كتابة نفس الكود الخاص بقاعدة IF ولكن ليس داخل وظيفة يعمل دون مشاكل وبالفعل يقف البرنامج لحين اكمال المطلوب

الكود كاملا

 private void save_b_Click(object sender, EventArgs e)
        {
            if (tx_id.Text == "")
            {
                MessageBox.Show("لا يوجد اى موظفين كى يتم الحفظ");
                return;
            }
            else if (tx_mon.Text == "")
            {
                MessageBox.Show("يجب اختيار الشهر");
                return;
            }
            else if (tx_tk.Text == "")
            {
                MessageBox.Show("يجب إدخال نسبة التحقيق");
                return;
            }
            else if (tx_th.Text == "")
            {
                MessageBox.Show("يجب إدخال نسبة التحصيل");
                return;
            }
            else if (tx_late.Text == "")
            {
                MessageBox.Show("يجب إدخال عدد دقائق التأخير");
                return;
            }
            else if (tx_ezn.Text == "")
            {
                MessageBox.Show("يجب إدخال عدد الإذون");
                return;
            }
            else if (tx_geza.Text == "")
            {
                MessageBox.Show("يجب إدخال عدد الجزاءات");
                return;
            }
            else if (tx_ghy.Text == "")
            {
                MessageBox.Show("يجب إدخال عدد أيام الغياب");
                return;
            }
            else if (tx_deg.Text == "")
            {
                MessageBox.Show("يجب إدخال التقييم الشهرى");
                return;
            }
            using (SqlConnection cn = new SqlConnection("Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=Emplo;Data Source=Server"))
            {
                cn.Open();
                using (SqlCommand com = new SqlCommand("Insert_M_Data",cn))
                {
                    string x = "select * from M_Data where emplo_id= " + tx_id.Text + " and mo_nm='" + tx_mon.SelectedItem + "'";
                    SqlDataAdapter sda = new SqlDataAdapter(x,cn);
                    DataSet ds = new DataSet();
                    sda.Fill(ds);
                    DataTable dt = ds.Tables[0];
                    if (dt.Rows.Count > 0)
                    {
                        MessageBox.Show("تم إدخال هذا الشهر للموظف من قبل");
                        return;
                    }
                    com.CommandType = CommandType.StoredProcedure;
                    com.Parameters.Add("@emplo_id", SqlDbType.Int).Value = tx_id.Text;
                    com.Parameters.Add("@mo_nm", SqlDbType.VarChar, 50).Value = tx_mon.Text;
                    com.Parameters.Add("@thkek", SqlDbType.Decimal).Value = tx_tk.Text;
                    com.Parameters.Add("@thsel", SqlDbType.Decimal).Value = tx_th.Text;
                    com.Parameters.Add("@late", SqlDbType.Int).Value = tx_late.Text;
                    com.Parameters.Add("@ezn", SqlDbType.Int).Value = tx_ezn.Text;
                    com.Parameters.Add("@geza", SqlDbType.Int).Value = tx_geza.Text;
                    com.Parameters.Add("@ghyab", SqlDbType.Int).Value = tx_ghy.Text;
                    com.Parameters.Add("@doc_degree", SqlDbType.Decimal).Value = tx_deg.Text;
                    com.ExecuteNonQuery();
                    MessageBox.Show("تم الحفظ");
                    this.clr_tx();
                    cn.Close();
                    cn.Dispose();
                }
            }

        }

تم تعديل هذه المشاركة بواسطة red_scorpion1 في 1 يوليو 2012 في 14:54

#2

السلام عليكم ..

الــ return; تقوم بالخروج من الوظيفة التي تم وضعها فيها ... و ليس باقي الوظائف ...

لا إله إلا الله ... محمد رسول الله

لو كانت مشاركتي مفيدة و تريد تشجيعي على المزيد من العطاء , فضلا قم بتقييم المشاركة

المعرًف القديم : houssam11350_11350

من مواضيعي : ArabGenCode : مولد كود و إجراءات مخزنة و واجهات لجداول سيكوال سيرفر

#3

السلام عليكم

بدلا من

private Void no_emp()

خليها

private bool no_emp()

وبدل return ;

خليها ترجع false

return false;

ثم عند استدعاء الداله

if(no_emp())
{

هنا كودك

}

هيكون شكل الداله كده

  	private bool no_emp()

      	{

          	if (tx_id.Text == "")

          	{

                  MessageBox.Show("لا يوجد اى موظفين كى يتم الحفظ");

              	return false;

          	}

          	else if (tx_mon.Text == "")

          	{

 	             MessageBox.Show("يجب اختيار الشهر");

              	return false;

          	}

          	else if (tx_tk.Text == "")

          	{

                  MessageBox.Show("يجب إدخال نسبة التحقيق");

              	return false;

          	}

          	else if (tx_th.Text == "")

          	{

                  MessageBox.Show("يجب إدخال نسبة التحصيل");

              	return false;

          	}

          	else if (tx_late.Text == "")

          	{

                  MessageBox.Show("يجب إدخال عدد دقائق التأخير");

              	return false;

          	}

          	else if (tx_ezn.Text == "")

          	{

                  MessageBox.Show("يجب إدخال عدد الإذون");

              	return false;

          	}

          	else if (tx_geza.Text == "")

              {

                  MessageBox.Show("يجب إدخال عدد الجزاءات");

              	return false;

          	}

          	else if (tx_ghy.Text == "")

          	{

                  MessageBox.Show("يجب إدخال عدد أيام الغياب");

              	return false;

          	}

          	else if (tx_deg.Text == "")

          	{

                  MessageBox.Show("يجب إدخال التقييم الشهرى");

              	return false;

          	}

          	return true;

      	}

أقلب الغريب كقلب أخيك ؟! أعيناه تشبه عينا أخيك ؟؟!! fb.pngtwitter.png

مواضيع مشابهة

عدد الزوار حالياً

المتواجدون خلال آخر دقيقتين · يتحدّث كل ٣٠ ثانية

—الإجمالي—أعضاء مسجّلون—زوار بدون تسجيل

جارٍ التحقق من المتواجدين…