コード例 #1
0
        private void bunifuFlatButton2_Click(object sender, EventArgs e)
        {
            DialogResult resu = MessageBox.Show("Are you sure to cancel operation?", "Cancel Operation?", MessageBoxButtons.YesNo);

            if (resu == DialogResult.Yes)
            {
                Clear();
                //calling instance of programs
                try
                {
                    this.Controls.Clear();
                    tab_programs tr = new tab_programs();

                    this.Controls.Add(tr);
                    tr.IDS  = this.ID.Trim();
                    tr.Dock = DockStyle.Fill;
                    tr.Show();
                }
                catch
                {
                }
                finally
                {
                }
            }
            else if (resu == DialogResult.No)
            {
            }
        }
コード例 #2
0
        private void bunifuFlatButton1_Click(object sender, EventArgs e)
        {
            Connection con = new Connection();

            con.Connect();
            SqlCommand cmd  = new SqlCommand();
            SqlCommand scmd = new SqlCommand();
            SqlCommand cmd2 = new SqlCommand();

            cmd.CommandText = "INSERT INTO program(PROGRAM_NAME,PROGRAM_DATE,PARTICIPANTS_CATEGORY,ADMIN_ID)" +
                              "VALUES(@pn,@date,@cat,@id)";
            if (all.Checked)
            {
                scmd.CommandText = "INSERT INTO LIST(PROGRAM_ID,RESIDENT_ID) SELECT PROGRAM.PROGRAM_ID ,RESIDENT.RESIDENT_ID FROM RESIDENT, PROGRAM	WHERE PROGRAM.PROGRAM_ID = (SELECT MAX(PROGRAM_ID) FROM PROGRAM) ";
                cmd2.CommandText = "UPDATE PROGRAM SET PARTICIPANTS_COUNT = (SELECT COUNT(RESIDENT_ID) FROM RESIDENT WHERE RESIDENT.FAMILY_ID IS NOT NULL), PARTICIPANTS_REMAINING =  (SELECT COUNT(RESIDENT_ID) FROM RESIDENT WHERE RESIDENT.FAMILY_ID IS NOT NULL) WHERE PROGRAM_ID = (SELECT MAX(PROGRAM_ID) FROM PROGRAM)";
            }
            else if (mother.Checked)
            {
                scmd.CommandText = "INSERT INTO LIST(PROGRAM_ID,RESIDENT_ID) SELECT PROGRAM.PROGRAM_ID ,RESIDENT.RESIDENT_ID FROM RESIDENT, PROGRAM WHERE RESIDENT_POSITION = 'Mother' AND PROGRAM_ID = (SELECT MAX(PROGRAM_ID) FROM PROGRAM) ";
                cmd2.CommandText = "UPDATE PROGRAM SET PARTICIPANTS_COUNT = (SELECT COUNT(RESIDENT_ID) FROM RESIDENT WHERE RESIDENT.FAMILY_ID IS NOT NULL AND RESIDENT_POSITION = 'Mother'), PARTICIPANTS_REMAINING = (SELECT COUNT(RESIDENT_ID) FROM RESIDENT WHERE RESIDENT.FAMILY_ID IS NOT NULL AND RESIDENT_POSITION = 'Mother')  WHERE PROGRAM_ID = (SELECT MAX(PROGRAM_ID) FROM PROGRAM)";
            }
            else if (father.Checked)
            {
                scmd.CommandText = "INSERT INTO LIST(PROGRAM_ID,RESIDENT_ID) SELECT PROGRAM.PROGRAM_ID ,RESIDENT.RESIDENT_ID FROM RESIDENT, PROGRAM WHERE RESIDENT_POSITION = 'Father' AND PROGRAM_ID = (SELECT MAX(PROGRAM_ID) FROM PROGRAM) ";
                cmd2.CommandText = "UPDATE PROGRAM SET PARTICIPANTS_COUNT = (SELECT COUNT(RESIDENT_ID) FROM RESIDENT WHERE RESIDENT.FAMILY_ID IS NOT NULL AND RESIDENT_POSITION = 'Father'), PARTICIPANTS_REMAINING = (SELECT COUNT(RESIDENT_ID) FROM RESIDENT WHERE RESIDENT.FAMILY_ID IS NOT NULL AND RESIDENT_POSITION = 'Father')  WHERE PROGRAM_ID = (SELECT MAX(PROGRAM_ID) FROM PROGRAM)";
            }
            else if (male.Checked)
            {
                scmd.CommandText = "INSERT INTO LIST(PROGRAM_ID,RESIDENT_ID) SELECT PROGRAM.PROGRAM_ID ,RESIDENT.RESIDENT_ID FROM RESIDENT, PROGRAM WHERE RESIDENT_GENDER = 'Male' AND PROGRAM_ID = (SELECT MAX(PROGRAM_ID) FROM PROGRAM) ";
                cmd2.CommandText = "UPDATE PROGRAM SET PARTICIPANTS_COUNT = (SELECT COUNT(RESIDENT_ID) FROM RESIDENT WHERE RESIDENT.FAMILY_ID IS NOT NULL AND RESIDENT_GENDER = 'Male'), PARTICIPANTS_REMAINING = (SELECT COUNT(RESIDENT_ID) FROM RESIDENT WHERE RESIDENT.FAMILY_ID IS NOT NULL AND RESIDENT_GENDER = 'Male') WHERE PROGRAM_ID = (SELECT MAX(PROGRAM_ID) FROM PROGRAM)";
            }
            else if (female.Checked)
            {
                scmd.CommandText = "INSERT INTO LIST(PROGRAM_ID,RESIDENT_ID) SELECT PROGRAM.PROGRAM_ID ,RESIDENT.RESIDENT_ID FROM RESIDENT, PROGRAM WHERE RESIDENT_GENDER = 'Female' AND PROGRAM_ID = (SELECT MAX(PROGRAM_ID) FROM PROGRAM) ";
                cmd2.CommandText = "UPDATE PROGRAM SET PARTICIPANTS_COUNT = (SELECT COUNT(RESIDENT_ID) FROM RESIDENT WHERE RESIDENT.FAMILY_ID IS NOT NULL AND RESIDENT_GENDER = 'Female'), PARTICIPANTS_REMAINING = (SELECT COUNT(RESIDENT_ID) FROM RESIDENT WHERE RESIDENT.FAMILY_ID IS NOT NULL AND RESIDENT_GENDER = 'Female') WHERE PROGRAM_ID = (SELECT MAX(PROGRAM_ID) FROM PROGRAM)";
            }
            else if (HOTF.Checked)
            {
                scmd.CommandText = "INSERT INTO LIST(PROGRAM_ID,RESIDENT_ID) SELECT PROGRAM.PROGRAM_ID ,RESIDENT.RESIDENT_ID FROM RESIDENT, PROGRAM WHERE RESIDENT_FAMILY_HEAD = 'Yes' AND PROGRAM_ID = (SELECT MAX(PROGRAM_ID) FROM PROGRAM) ";
                cmd2.CommandText = "UPDATE PROGRAM SET PARTICIPANTS_COUNT = (SELECT COUNT(RESIDENT_ID) FROM RESIDENT WHERE RESIDENT.FAMILY_ID IS NOT NULL AND RESIDENT_FAMILY_HEAD = 'Yes'), PARTICIPANTS_REMAINING = (SELECT COUNT(RESIDENT_ID) FROM RESIDENT WHERE RESIDENT.FAMILY_ID IS NOT NULL AND RESIDENT_FAMILY_HEAD = 'Yes')  WHERE PROGRAM_ID = (SELECT MAX(PROGRAM_ID) FROM PROGRAM)";
            }
            else if (etinUp.Checked)
            {
                scmd.CommandText = "INSERT INTO LIST(PROGRAM_ID,RESIDENT_ID) SELECT PROGRAM.PROGRAM_ID ,RESIDENT.RESIDENT_ID FROM RESIDENT, PROGRAM WHERE RESIDENT_AGE >= 18 AND PROGRAM_ID = (SELECT MAX(PROGRAM_ID) FROM PROGRAM) ";
                cmd2.CommandText = "UPDATE PROGRAM SET PARTICIPANTS_COUNT = (SELECT COUNT(RESIDENT_ID) FROM RESIDENT WHERE RESIDENT.FAMILY_ID IS NOT NULL AND RESIDENT_AGE >= 18), PARTICIPANTS_REMAINING =(SELECT COUNT(RESIDENT_ID) FROM RESIDENT WHERE RESIDENT.FAMILY_ID IS NOT NULL AND RESIDENT_AGE >= 18) WHERE PROGRAM_ID = (SELECT MAX(PROGRAM_ID) FROM PROGRAM)";
            }
            else if (etindown.Checked)
            {
                scmd.CommandText = "INSERT INTO LIST(PROGRAM_ID,RESIDENT_ID) SELECT PROGRAM.PROGRAM_ID ,RESIDENT.RESIDENT_ID FROM RESIDENT, PROGRAM WHERE RESIDENT_AGE < 18 AND PROGRAM_ID = (SELECT MAX(PROGRAM_ID) FROM PROGRAM) ";
                cmd2.CommandText = "UPDATE PROGRAM SET PARTICIPANTS_COUNT = (SELECT COUNT(RESIDENT_ID) FROM RESIDENT WHERE RESIDENT.FAMILY_ID IS NOT NULL AND RESIDENT_AGE < 18), PARTICIPANTS_REMAINING =  (SELECT COUNT(RESIDENT_ID) FROM RESIDENT WHERE RESIDENT.FAMILY_ID IS NOT NULL AND RESIDENT_AGE < 18) WHERE PROGRAM_ID = (SELECT MAX(PROGRAM_ID) FROM PROGRAM)";
            }
            else if (senyor.Checked)
            {
                scmd.CommandText = "INSERT INTO LIST(PROGRAM_ID,RESIDENT_ID) SELECT PROGRAM.PROGRAM_ID ,RESIDENT.RESIDENT_ID FROM RESIDENT, PROGRAM WHERE RESIDENT_AGE >= 60 AND PROGRAM_ID = (SELECT MAX(PROGRAM_ID) FROM PROGRAM) ";
                cmd2.CommandText = "UPDATE PROGRAM SET PARTICIPANTS_COUNT = (SELECT COUNT(RESIDENT_ID) FROM RESIDENT WHERE RESIDENT.FAMILY_ID IS NOT NULL AND RESIDENT_AGE >= 60), PARTICIPANTS_REMAINING = (SELECT COUNT(RESIDENT_ID) FROM RESIDENT WHERE RESIDENT.FAMILY_ID IS NOT NULL AND RESIDENT_AGE >= 60) WHERE PROGRAM_ID = (SELECT MAX(PROGRAM_ID) FROM PROGRAM)";
            }
            cmd.Connection  = Connection.con;
            scmd.Connection = Connection.con;
            cmd2.Connection = Connection.con;
            if (programName.Text == "")
            {
                MessageBox.Show("Please input a program name");
                programName.Focus();
            }
            else if (category == "")
            {
                MessageBox.Show("Please select participants");
                categoryBox.Focus();
            }
            else
            {
                try
                {
                    cmd.Parameters.AddWithValue("@pn", programName.Text);
                    cmd.Parameters.AddWithValue("@date", programDate.Value);
                    cmd.Parameters.AddWithValue("@cat", category);
                    cmd.Parameters.AddWithValue("@id", ID);
                    cmd.ExecuteNonQuery();
                    scmd.ExecuteNonQuery();
                    cmd2.ExecuteNonQuery();
                    MessageBox.Show("Successfully added new Program");
                    Clear();
                    //calling instance of programs
                    this.Controls.Clear();
                    tab_programs tr = new tab_programs();
                    this.Controls.Add(tr);
                    tr.IDS  = this.ID.Trim();
                    tr.Dock = DockStyle.Fill;
                    tr.Show();
                }
                catch
                {
                }
            }
        }