Example #1
0
        private void button1_Click(object sender, EventArgs e)
        {
            SqlConnection con        = new SqlConnection(conStr);
            SqlCommand    checkExist = new SqlCommand("select count(*) from Student where RegistrationNo=@registrationNo", con);

            checkExist.Parameters.AddWithValue("@registrationNo", txtRegNo.Text);
            // checkExist.CommandType = System.Data.CommandType.Text;
            con.Open();
            int asdas = (int)checkExist.ExecuteScalar();

            if (txtRegNo.Text == "" || txtFName.Text == "" || txtLName.Text == "" || txtContact.Text == "" || txtEmail.Text == "" || txtGender.Text == "")
            {
                label8.Visible = true;
                label8.Text    = "Please fill the Required Field....";
            }
            else if (txtRegNo.Text.Count() != 11 || txtRegNo.Text.Split('-')[0].Any(char.IsLetter) || txtRegNo.Text[4] != '-' ||
                     txtRegNo.Text[5] != 'C' || txtRegNo.Text[6] != 'S' || txtRegNo.Text[7] != '-')
            {
                txtRegNo.Focus();
                label8.Visible = true;
                label8.Text    = "i.e 2016-CS-306";
            }
            else if (txtContact.Text.Count() != 12 || txtContact.Text[4] != '-' || txtContact.Text.Any(char.IsLetter) == true)
            {
                label8.Text = "";
                txtContact.Focus();
                lbContact.Text      = "i.e 0123-3456789";
                lbContact.ForeColor = Color.Red;
            }
            else if (isEdit)
            {
                //if (asdas > 0)
                //{
                //    label8.Visible = true;
                //    label8.Text = "Registration No already exist";
                //}
                //else
                //{
                string update = string.Format("update Person set FirstName='{0}', LastName='{1}', Contact='{2}',Email='{3}',DateOfBirth='{4}', Gender=(select Id from Lookup where Value='{5}') where Id='{6}'", txtFName.Text, txtLName.Text, txtContact.Text, txtEmail.Text, Convert.ToDateTime(txtDOB.Value), txtGender.Text, id);
                DatabaseConnection.getInstance().executeQuery(update);
                string updateStudent = string.Format("update Student set RegistrationNo='{0}' where Id='{1}'", txtRegNo.Text, id);
                DatabaseConnection.getInstance().executeQuery(updateStudent);
                MessageBox.Show("Data Updated Successfully...");
                txtRegNo.Text = ""; txtFName.Text = ""; txtLName.Text = ""; txtContact.Text = ""; txtEmail.Text = ""; txtGender.Text = ""; label8.Text = "";
                Manage_Student ms = new Manage_Student();
                this.Hide();
                ms.Show();
                //}
            }

            else if (asdas > 0)
            {
                label8.Visible = true;
                label8.Text    = "Registration No already exist";
                con.Close();
            }
            else
            {
                try
                {
                    string countMaxId = string.Format("select max(Id) from Person");
                    var    re         = DatabaseConnection.getInstance().readData(countMaxId);
                    int    count      = 0;
                    while (re.Read())
                    {
                        count = re.GetInt32(0);
                    }
                    string query = string.Format("insert into Person(FirstName,LastName,Contact,Email,DateOfBirth,Gender) values('{0}','{1}','{2}','{3}','{4}',(select Id from Lookup where Value='{5}'))", txtFName.Text, txtLName.Text, txtContact.Text, txtEmail.Text, Convert.ToDateTime(txtDOB.Value), txtGender.Text);
                    DatabaseConnection.getInstance().executeQuery(query);
                    string qwrt = "insert into Student(Id, RegistrationNo) values('" + (count + 1) + "','" + txtRegNo.Text + "')";
                    DatabaseConnection.getInstance().executeQuery(qwrt);
                    MessageBox.Show("Data Inserted Successfully!");
                    txtRegNo.Text = ""; txtFName.Text = ""; txtLName.Text = ""; txtContact.Text = ""; txtEmail.Text = ""; txtGender.Text = ""; label8.Text = "";
                    Manage_Student ms = new Manage_Student();
                    this.Hide();
                    ms.Show();
                }
                catch
                {
                    int    count = 1;
                    string query = string.Format("insert into Person(FirstName,LastName,Contact,Email,DateOfBirth,Gender) values('{0}','{1}','{2}','{3}','{4}',(select Id from Lookup where Value='{5}'))", txtFName.Text, txtLName.Text, txtContact.Text, txtEmail.Text, Convert.ToDateTime(txtDOB.Value), txtGender.Text);
                    DatabaseConnection.getInstance().executeQuery(query);
                    string qwrt = "insert into Student(Id, RegistrationNo) values('" + count + "','" + txtRegNo.Text + "')";
                    DatabaseConnection.getInstance().executeQuery(qwrt);
                    MessageBox.Show("Data Inserted Successfully!");
                    txtRegNo.Text = ""; txtFName.Text = ""; txtLName.Text = ""; txtContact.Text = ""; txtEmail.Text = ""; txtGender.Text = ""; label8.Text = "";
                    Manage_Student ms = new Manage_Student();
                    this.Hide();
                    ms.Show();
                }
            }
        }
Example #2
0
 private void Person_FormClosed(object sender, FormClosedEventArgs e)
 {
     DatabaseConnection.getInstance().closeConnection();
 }
Example #3
0
 public grp()
 {
     InitializeComponent();
     DatabaseConnection.getInstance().ConnectionString = "Data Source=HIBA\\SQLSERVER;Initial Catalog=ProjectA;Integrated Security=False;User ID=sa;Password=05feb1999;Connect Timeout=30;Encrypt=False;TrustServerCertificate=True;ApplicationIntent=ReadWrite;MultiSubnetFailover=False";
 }
Example #4
0
 public Person()
 {
     InitializeComponent();
     DatabaseConnection.getInstance().ConnectionString = "Data Source=TAYYABA-RASHEED;Initial Catalog=ProjectA;User ID=sa;Password=alohamora";
 }
Example #5
0
        private void button1_Click(object sender, EventArgs e)
        {
            int           asdas = 0;
            SqlConnection con   = new SqlConnection(conStr);

            try
            {
                SqlCommand checkExist = new SqlCommand("select count(*) from GroupEvaluation where GroupId=(select Id from Group1 where Id=@title) AND EvaluationId=(select Id from Evaluation where Name=@groupId)", con);
                checkExist.Parameters.AddWithValue("@title", comGroupId.Text);
                checkExist.CommandType = System.Data.CommandType.Text;
                checkExist.Parameters.AddWithValue("@groupId", comEvaluationId.Text);
                con.Open();
                asdas = (int)checkExist.ExecuteScalar();
            }
            catch
            {
                label4.Text = "Already Exists";
            }
            string date       = DateTime.Now.ToShortDateString();
            string query1     = "select TotalMarks from Evaluation";
            var    totalMarks = DatabaseConnection.getInstance().getRowsCount(query1);

            if (isEdit)
            {
                try
                {
                    string query = string.Format("update GroupEvaluation set GroupId='{0}', EvaluationId=(select Id from Evaluation where Name='{1}'), ObtainedMarks='{2}', EvaluationDate='{3}' where GroupId='{4}'", int.Parse(comGroupId.Text), comEvaluationId.Text, int.Parse(textBox3.Text), date, int.Parse(grpId));
                    DatabaseConnection.getInstance().executeQuery(query);
                    MessageBox.Show("Data updated Successfully!");
                    dataGridView1 = null;
                    this.groupEvaluationTableAdapter.Fill(this.projectADataSet7.GroupEvaluation);
                    isEdit          = false;
                    comGroupId.Text = ""; comEvaluationId.Text = ""; textBox3.Text = "";
                }
                catch (Exception err)
                {
                    MessageBox.Show(err.Message);
                }
            }

            else if (comGroupId.Text == "" || comEvaluationId.Text == "" || textBox3.Text == "")
            {
                label4.Text = "Please Fill Required Field!";
            }

            else if (textBox3.Text.Any(char.IsLetter) == true)
            {
                textBox3.Focus();
                label4.Text = "Integer Value!";
            }
            else if (asdas > 0)
            {
                comGroupId.Focus();
                label4.Text = "Group Already Exists";
                con.Close();
            }

            else if (totalMarks < int.Parse(textBox3.Text))
            {
                textBox3.Focus();
                label4.Text = "Obtained Marks should be Less than Total Marks";
            }
            else
            {
                try
                {
                    string query = string.Format("insert into GroupEvaluation values('{0}',(select Id from Evaluation where Name='{1}'),'{2}','{3}')", int.Parse(comGroupId.Text), comEvaluationId.Text, int.Parse(textBox3.Text), date);
                    DatabaseConnection.getInstance().executeQuery(query);
                    MessageBox.Show("Data Inserted Successfully!");
                    dataGridView1 = null;
                    this.groupEvaluationTableAdapter.Fill(this.projectADataSet7.GroupEvaluation);
                    comGroupId.Text = ""; comEvaluationId.Text = ""; textBox3.Text = "";
                }
                catch (Exception err)
                {
                    MessageBox.Show(err.Message);
                }
            }
        }