السلام عليكم ورحمة الله وبركاته
قمت بعمل وظيفة
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();
}
}
}
