با سلام
میخوام قبل ثبت چک بشه که:
هر نفر در یکسال فقط می تواند حاوی یک نفره باشه.... (مثلا کد پرسنلی 100 در سال 1396 دارای نمره 85 هست. حال اگه کاربر به اشتباه برای کد پرسنلی 100 در سال 1396 باز نمره داد سیستم پیغام هشدار بده) در غیر اینصورت ثبت بشه...
پایگاه داده من sql هست.
کد های من:
private void insert_click(object sender, EventArgs e)
{
try
{
if (tids.Text != string.Empty && tyear.Text != string.Empty && taverage.Text != string.Empty)
{
SqlConnection con = new SqlConnection(Connection);
/* OleDbCommand com = new OleDbCommand("INSERT into arzeshyabi ([tid],tyear,taverage) values('" + tids.Text + "','" + tyear.Text + "')", con);*/
SqlCommand com = new SqlCommand("Insert Into arzeshyabi ([tid],tyear,taverage) Values (@tid,@tyear,@taverage)", con);
com.Parameters.AddWithValue("@tid", tids.Text);
com.Parameters.AddWithValue("@tyear", tyear.Text);
com.Parameters.AddWithValue("@taverage", taverage.Text);
con.Open();
com.ExecuteNonQuery();
con.Close();
BindGrid();
FarsiMessageBox.MessageBox.Show("پیام", "اطلاعات با موفقیت ثبت شد", FarsiMessageBox.MessageBox.Buttons.OK, FarsiMessageBox.MessageBox.Icons.Information);
tids.Text = "";
tyear.Text = "";
taverage.Text = "";
}
else
{
MessageBox.Show("همه مقادیر را پر کنید", "خطا");
}
}
catch
{
MessageBox.Show("کارمندی با این کد پرسنلی ثبت نشده است");
}
}