Hello,
I have a C# Windows form Project with SQL Server. I have a ticket opening form. At this form, user opens a ticket for help desk. What I want to do is, while user opening a ticket, there must be a warning for cases non-exist users, at this case the ticket must be prevented. For example, I want to open a ticket and I enter 21 for kullaniciID, but this ID does not exist at my user table and this record must be prevented, of course with a message. How can I do that?
Thanks for your help. My code block is below:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace ITHelpDeskProject
{
public partial class CgrKydOlstr : Form
{
public CgrKydOlstr()
{
InitializeComponent();
}
private void CgrKydOlstr_Load(object sender, EventArgs e)
{
CMBBOXproblemTur.Items.Add("Donanım Arızası");
CMBBOXproblemTur.Items.Add("Yazılım Problemi");
CMBBOXproblemTur.Items.Add("Network Problemi");
}
private void BTNkaydet_Click(object sender, EventArgs e)
{
SqlConnection baglanti = new SqlConnection("Data Source=EMREY\\MS_SQLSERVER;Initial Catalog=ITHelpDeskProjesi;Integrated Security=True");
baglanti.Open();
string SonKayitID;
DateTime dt = Convert.ToDateTime(DTPCKRkayitTarih.Value.ToString("yyyy-MM-dd"));
String zaman = dt.ToString("yyyy-MM-dd hh:mm:ss");
SqlCommand cmd = new SqlCommand("INSERT INTO tblKayit(kullaniciID, bilgisayarID, yaziciID, problemTur, kayitTarihi) VALUES(@kullaniciID, @bilgisayarID, @yaziciID, @problemTur, @kayitTarihi); select scope_identity()");
cmd.Parameters.AddWithValue("@kullaniciID", TXTBOXkulID.Text);
cmd.Parameters.AddWithValue("@bilgisayarID", TXTBOXbilID.Text);
cmd.Parameters.AddWithValue("@yaziciID", TXTBOXyaziciID.Text);
cmd.Parameters.AddWithValue("@problemTur", CMBBOXproblemTur.Text);
cmd.Parameters.AddWithValue("@kayitTarihi", dt);
cmd.Connection = baglanti;
SonKayitID = cmd.ExecuteScalar().ToString();
MessageBox.Show("Yardım masası çağrı kaydınız oluşturulmuştur. Çağrı kaydınız hakkında bilgi almak için kullanabileceğiniz referans numaranız : " + SonKayitID);
baglanti.Close();
CgrKydOlstr_Load(sender, e);
}
private void BTNanaSayfa_Click(object sender, EventArgs e)
{
personelAnaMenu prsana = new personelAnaMenu();
prsana.Show();
this.Hide();
}
private void BTNsistemdenCik_Click(object sender, EventArgs e)
{
this.Close();
}
private void CgrKydOlstr_FormClosing(object sender, FormClosingEventArgs e)
{
Application.Exit();
}
}
}
[edit]Code block added - OriginalGriff[/edit]