Click here to Skip to main content
15,885,914 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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:

C#
	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]
Posted
Updated 20-May-14 1:15am
v2
Comments
OriginalGriff 20-May-14 7:15am    
What have you tried?
Where are you stuck?
[no name] 20-May-14 7:15am    
What do you mean "how". You write a query to see if the user id exists. If not then show your message.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900