Beispiel #1
0
        //--END


        //BTN INSERT DATA --START
        private async void button1_Click(object sender, EventArgs e)
        {
            if (pictureboximage.Image == null)
            {
                labelimagevalidate.Visible = true;
                await Task.Delay(1000);

                labelimagevalidate.Visible = false;
            }
            else if (textboxtrackorstrand.Text == "")  //studentinfo form validation --start
            {
                labeltrcorstrndvalidate.Visible = true;
                await Task.Delay(1000);

                labeltrcorstrndvalidate.Visible = false;

                textboxtrackorstrand.Select();
            }
            else if (textboxlrn.Text == "")
            {
                labellrnvalidate.Visible = true;
                await Task.Delay(1000);

                labellrnvalidate.Visible = false;

                textboxlrn.Select();
            }
            else if (textboxfname.Text == "")
            {
                labelstudfnamevalidate.Visible = true;
                await Task.Delay(1000);

                labelstudfnamevalidate.Visible = false;

                textboxfname.Select();
            }
            else if (textboxmiddlename.Text == "")
            {
                labelstudmnamevalidate.Visible = true;
                await Task.Delay(1000);

                labelstudmnamevalidate.Visible = false;

                textboxmiddlename.Select();
            }
            else if (textboxlname.Text == "")
            {
                labelstudlnamevalidate.Visible = true;
                await Task.Delay(1000);

                labelstudlnamevalidate.Visible = false;

                textboxlname.Select();
            }
            else if (comboBoxextraname.Text == "")
            {
                labelstudextranamevalidate.Visible = true;
                await Task.Delay(1000);

                labelstudextranamevalidate.Visible = false;

                comboBoxextraname.Select();
            }
            else if (comboBoxSex.Text == "")
            {
                labelstudsexvalidate.Visible = true;
                await Task.Delay(1000);

                labelstudsexvalidate.Visible = false;

                comboBoxSex.Select();
            }
            else if (textboxage.Text == "")
            {
                labelstudagevalidate.Visible = true;
                await Task.Delay(1000);

                labelstudagevalidate.Visible = false;

                textboxage.Select();
            }
            else if (dateTimePickerdob.Text == string.Empty)
            {
                labelstuddobvalidate.Visible = true;
                await Task.Delay(1000);

                labelstuddobvalidate.Visible = false;

                dateTimePickerdob.Select();
            }
            else if (textBoxcitizenship.Text == "")
            {
                labelstudcitizenshipvalidate.Visible = true;
                await Task.Delay(1000);

                labelstudcitizenshipvalidate.Visible = false;

                textBoxcitizenship.Select();
            }
            else if (comboBoxcivilstatus.Text == "")
            {
                labelstudstatusvalidate.Visible = true;
                await Task.Delay(1000);

                labelstudstatusvalidate.Visible = false;

                comboBoxcivilstatus.Select();
            }
            else if (textboxhomeaddress.Text == "")
            {
                labelstudhomeaddvalidate.Visible = true;
                await Task.Delay(1000);

                labelstudhomeaddvalidate.Visible = false;

                textboxhomeaddress.Select();
            }
            else if (textboxdistrict.Text == "")
            {
                labelstuddistrictvalidate.Visible = true;
                await Task.Delay(1000);

                labelstuddistrictvalidate.Visible = false;

                textboxdistrict.Select();
            }
            else if (textboxzipcode.Text == "")
            {
                labelstudzipcodevalidate.Visible = true;
                await Task.Delay(1000);

                labelstudzipcodevalidate.Visible = false;

                textboxzipcode.Select();
            }
            else if (textboxemail.Text == "")
            {
                labelstudmailvalidate.Visible = true;
                await Task.Delay(1000);

                labelstudmailvalidate.Visible = false;

                textboxemail.Select();
            }
            else if (textboxcontactnumber.Text == "")
            {
                labelstudcontactvalidate.Visible = true;
                await Task.Delay(1000);

                labelstudcontactvalidate.Visible = false;

                textboxcontactnumber.Select();
            } // --end
            else if (textboxmothersname.Text == "") // parent form validation --start
            {
                labelmothersnamevalidate.Visible = true;
                await Task.Delay(1000);

                labelmothersnamevalidate.Visible = false;

                textboxmothersname.Select();
            }
            else if (textboxmothersoccupation.Text == "")
            {
                labelmothersoccupvalidate.Visible = true;
                await Task.Delay(1000);

                labelmothersoccupvalidate.Visible = false;

                textboxmothersoccupation.Select();
            }
            else if (textboxmothercontactnumber.Text == "")
            {
                labelcnmothernamevalidate.Visible = true;
                await Task.Delay(1000);

                labelcnmothernamevalidate.Visible = false;

                textboxmothercontactnumber.Select();
            }
            else if (textboxfathersname.Text == "")
            {
                labelfathersnamevalidate.Visible = true;
                await Task.Delay(1000);

                labelfathersnamevalidate.Visible = false;

                textboxfathersname.Select();
            }
            else if (textboxfathersoccupation.Text == "")
            {
                labelfathersoccupvalidate.Visible = true;
                await Task.Delay(1000);

                labelfathersoccupvalidate.Visible = false;

                textboxfathersoccupation.Select();
            }
            else if (textboxfathescontactnumber.Text == "")
            {
                labelcnfathervalidate.Visible = true;
                await Task.Delay(1000);

                labelcnfathervalidate.Visible = false;

                textboxfathescontactnumber.Select();
            }
            else if (comboBoxpreferredcontact.Text == "")
            {
                labelprffdvalidate.Visible = true;
                await Task.Delay(1000);

                labelprffdvalidate.Visible = false;

                comboBoxpreferredcontact.Select();
            } //--end
            else if (textboxlastschoolattended.Text == "") // school info form validation --start
            {
                labelcnlsavalidate.Visible = true;
                await Task.Delay(1000);

                labelcnlsavalidate.Visible = false;

                textboxlastschoolattended.Select();
            }
            else if (textboxyeargraduated.Text == "")
            {
                labelygvalidate.Visible = true;
                await Task.Delay(1000);

                labelygvalidate.Visible = false;

                textboxyeargraduated.Select();
            }
            else if (textboxaddress_school.Text == "")
            {
                labelaofvalidate.Visible = true;
                await Task.Delay(1000);

                labelaofvalidate.Visible = false;

                textboxaddress_school.Select();
            } //--end
            else
            {
                button1.Enabled = false;
                SqlConnection sqlcnn;
                sqlcnn = new SqlConnection(conn_string);
                sqlcnn.Open();

                // convert image to byte array --start
                MemoryStream mem_stream = new MemoryStream();
                pictureboximage.Image.Save(mem_stream, ImageFormat.Jpeg);

                byte[] photo_arr = new byte[mem_stream.Length];

                mem_stream.Position = 0;
                mem_stream.Read(photo_arr, 0, photo_arr.Length);
                // --end

                SqlCommand sqlcmd_stud    = new SqlCommand("sp_students", sqlcnn);
                SqlCommand sqlcmd_contact = new SqlCommand("sp_contact", sqlcnn);
                SqlCommand sqlcmd_parent  = new SqlCommand("sp_parent", sqlcnn);
                SqlCommand sqlcmd_school  = new SqlCommand("sp_school", sqlcnn);

                //students insert
                sqlcmd_stud.CommandType = CommandType.StoredProcedure;
                sqlcmd_stud.Parameters.AddWithValue("@ProfileImage", photo_arr);
                sqlcmd_stud.Parameters.AddWithValue("@TrackOrStrand", textboxtrackorstrand.Text);
                sqlcmd_stud.Parameters.AddWithValue("@LRN_Number", textboxlrn.Text);
                sqlcmd_stud.Parameters.AddWithValue("@Firstname", textboxfname.Text);
                sqlcmd_stud.Parameters.AddWithValue("@Middlename", textboxmiddlename.Text);
                sqlcmd_stud.Parameters.AddWithValue("@Lastname", textboxlname.Text);
                sqlcmd_stud.Parameters.AddWithValue("@ExtraName", comboBoxextraname.SelectedItem.ToString());
                sqlcmd_stud.Parameters.AddWithValue("@Sex", comboBoxSex.SelectedItem.ToString());
                sqlcmd_stud.Parameters.AddWithValue("@Age", int.Parse(textboxage.Text.ToString()));
                sqlcmd_stud.Parameters.AddWithValue("@DOB", dateTimePickerdob.Value.ToString("MM/dd/yyyy"));
                sqlcmd_stud.Parameters.AddWithValue("@Citizenship", textBoxcitizenship.Text);
                sqlcmd_stud.Parameters.AddWithValue("@CivilStatus", comboBoxcivilstatus.SelectedItem.ToString());
                //end

                //contact insert
                sqlcmd_contact.CommandType = CommandType.StoredProcedure;
                sqlcmd_contact.Parameters.AddWithValue("@HomeAddress", textboxhomeaddress.Text);
                sqlcmd_contact.Parameters.AddWithValue("@District", textboxdistrict.Text);
                sqlcmd_contact.Parameters.AddWithValue("@ZipCode", textboxzipcode.Text);
                sqlcmd_contact.Parameters.AddWithValue("@Email", textboxemail.Text);
                sqlcmd_contact.Parameters.AddWithValue("@ContactNumber", textboxcontactnumber.Text);
                //end

                //parent insert
                sqlcmd_parent.CommandType = CommandType.StoredProcedure;
                sqlcmd_parent.Parameters.AddWithValue("@MotherName", textboxmothersname.Text);
                sqlcmd_parent.Parameters.AddWithValue("@MotherOccupation", textboxmothersoccupation.Text);
                sqlcmd_parent.Parameters.AddWithValue("@MotherMobileNumber", textboxmothercontactnumber.Text);
                sqlcmd_parent.Parameters.AddWithValue("@FatherName", textboxfathersname.Text);
                sqlcmd_parent.Parameters.AddWithValue("@FatherOccupation", textboxfathersoccupation.Text);
                sqlcmd_parent.Parameters.AddWithValue("@FatherMobileNumber", textboxfathescontactnumber.Text);
                sqlcmd_parent.Parameters.AddWithValue("@PreferredContact", comboBoxpreferredcontact.SelectedItem.ToString());
                //end

                //school insert
                sqlcmd_school.CommandType = CommandType.StoredProcedure;
                sqlcmd_school.Parameters.AddWithValue("@SchoolLastAttended", textboxlastschoolattended.Text);
                sqlcmd_school.Parameters.AddWithValue("@YearGraduated", textboxyeargraduated.Text);
                sqlcmd_school.Parameters.AddWithValue("@AddressOfSchool", textboxaddress_school.Text);
                //end

                int stud, contact, parent, school;
                stud    = sqlcmd_stud.ExecuteNonQuery();
                contact = sqlcmd_contact.ExecuteNonQuery();
                parent  = sqlcmd_parent.ExecuteNonQuery();
                school  = sqlcmd_school.ExecuteNonQuery();

                if (stud > 0 && contact > 0 && parent > 0 && school > 0)
                {
                    Success s = new Success();
                    s.Show();
                    await Task.Delay(1000);

                    s.Close();
                    await Task.Delay(1000);

                    ClearInputField();
                    button1.Enabled = true;
                    //DisplayUserData();
                }
                else
                {
                    Failed f = new Failed();
                    f.Show();
                    await Task.Delay(1000);

                    f.Close();
                    //ClearInputField();
                }
                sqlcnn.Close();
            }
        }
Beispiel #2
0
        //--END


        //UPDATE DATA --START
        private async void button2_Click(object sender, EventArgs e)
        {
            SqlConnection sqlcnn;

            sqlcnn = new SqlConnection(connection_string);
            sqlcnn.Open();

            //convert image to binary
            MemoryStream mem_stream = new MemoryStream();

            pictureboximage.Image.Save(mem_stream, ImageFormat.Jpeg);

            byte[] photo_arr = new byte[mem_stream.Length];

            mem_stream.Position = 0;
            mem_stream.Read(photo_arr, 0, photo_arr.Length);
            //end

            SqlCommand sqlcmd_stud    = new SqlCommand("sp_student_update", sqlcnn);
            SqlCommand sqlcmd_contact = new SqlCommand("sp_contact_update", sqlcnn);
            SqlCommand sqlcmd_parent  = new SqlCommand("sp_parent_update", sqlcnn);
            SqlCommand sqlcmd_school  = new SqlCommand("sp_school_update", sqlcnn);


            // student
            sqlcmd_stud.CommandType = CommandType.StoredProcedure;
            sqlcmd_stud.Parameters.AddWithValue("@Stud_ID", userid);
            sqlcmd_stud.Parameters.AddWithValue("@ProfileImage", photo_arr);
            sqlcmd_stud.Parameters.AddWithValue("@TrackOrStrand", textboxtrackorstrand.Text);
            sqlcmd_stud.Parameters.AddWithValue("@LRN_Number", textboxlrn.Text);
            sqlcmd_stud.Parameters.AddWithValue("@Firstname", textboxfname.Text);
            sqlcmd_stud.Parameters.AddWithValue("@Middlename", textboxmiddlename.Text);
            sqlcmd_stud.Parameters.AddWithValue("@Lastname", textboxlname.Text);
            sqlcmd_stud.Parameters.AddWithValue("@ExtraName", comboBoxextraname.SelectedItem.ToString());
            sqlcmd_stud.Parameters.AddWithValue("@Sex", comboBoxSex.SelectedItem.ToString());
            sqlcmd_stud.Parameters.AddWithValue("@Age", int.Parse(textboxage.Text.ToString()));
            sqlcmd_stud.Parameters.AddWithValue("@DOB", dateTimePickerdob.Value.ToString("MM/dd/yyyy"));
            sqlcmd_stud.Parameters.AddWithValue("@Citizenship", textBoxcitizenship.Text);
            sqlcmd_stud.Parameters.AddWithValue("@CivilStatus", comboBoxcivilstatus.SelectedItem.ToString());
            // end

            //contact insert
            sqlcmd_contact.CommandType = CommandType.StoredProcedure;
            sqlcmd_contact.Parameters.AddWithValue("@Contact_ID", userid);
            sqlcmd_contact.Parameters.AddWithValue("@HomeAddress", textboxhomeaddress.Text);
            sqlcmd_contact.Parameters.AddWithValue("@District", textboxdistrict.Text);
            sqlcmd_contact.Parameters.AddWithValue("@ZipCode", textboxzipcode.Text);
            sqlcmd_contact.Parameters.AddWithValue("@Email", textboxemail.Text);
            sqlcmd_contact.Parameters.AddWithValue("@ContactNumber", textboxcontactnumber.Text);
            //end

            //parent
            sqlcmd_parent.CommandType = CommandType.StoredProcedure;
            sqlcmd_parent.Parameters.AddWithValue("@Parent_ID", userid);
            sqlcmd_parent.Parameters.AddWithValue("@MotherName", textboxmothersname.Text);
            sqlcmd_parent.Parameters.AddWithValue("@MotherOccupation", textboxmothersoccupation.Text);
            sqlcmd_parent.Parameters.AddWithValue("@MotherMobileNumber", textboxmothercontactnumber.Text);
            sqlcmd_parent.Parameters.AddWithValue("@FatherName", textboxfathersname.Text);
            sqlcmd_parent.Parameters.AddWithValue("@FatherOccupation", textboxfathersoccupation.Text);
            sqlcmd_parent.Parameters.AddWithValue("@FatherMobileNumber", textboxfathescontactnumber.Text);
            sqlcmd_parent.Parameters.AddWithValue("@PreferredContact", comboBoxpreferredcontact.SelectedItem.ToString());
            //end

            //school
            sqlcmd_school.CommandType = CommandType.StoredProcedure;
            sqlcmd_school.Parameters.AddWithValue("@School_ID", userid);
            sqlcmd_school.Parameters.AddWithValue("@SchoolLastAttended", textboxlastschoolattended.Text);
            sqlcmd_school.Parameters.AddWithValue("@YearGraduated", textboxyeargraduated.Text);
            sqlcmd_school.Parameters.AddWithValue("@AddressOfSchool", textboxaddress_school.Text);
            //end

            int stud, contact, parent, school;

            stud    = sqlcmd_stud.ExecuteNonQuery();
            contact = sqlcmd_contact.ExecuteNonQuery();
            parent  = sqlcmd_parent.ExecuteNonQuery();
            school  = sqlcmd_school.ExecuteNonQuery();
            if (stud > 0 && contact > 0 && parent > 0 && school > 0)
            {
                Success s = new Success();
                s.Show();
                StudentSummary();
                Student();
                Contact();
                Parents();
                School();
                await Task.Delay(1000);

                s.Close();
                ClearInputField();
            }
            else
            {
                Failed f = new Failed();
                f.Show();
                await Task.Delay(1000);

                f.Close();
            }
            sqlcnn.Close();
        }