Example #1
0
        private void btnDissolve_Click(object sender, EventArgs e)
        {
            try
            {
                //get the selected TeamID from frmTeamEmployee 's clicked Team name
                string        qry = "select TeamID from team  where Name= '" + frmTeamEmployee.AllocaedTName + "'";
                SqlConnection con = new SqlConnection(cs);
                con.Open();
                SqlCommand    cmd = new SqlCommand(qry, con);
                SqlDataReader dr  = cmd.ExecuteReader();
                dr.Read();
                int tid = Convert.ToInt16(dr[0]); //TeamID set to a integer for further use
                dr.Close();

                //Dissolve Team
                string     qry2 = " update Team set   IsAllocated = 0 where TeamID='" + tid + "'    ";
                SqlCommand cmd2 = new SqlCommand(qry2, con);
                cmd2.ExecuteNonQuery();


                //Deallocated the selected team members in Employee table
                string     qry3 = "update employee set IsAllocated = 0 where EmpNo in ( select e.EmpNo from TeamEmployee te, Employee e where te.status=1 and  te.EMPNo = e.EmpNo and te.TeamID='" + tid + "'  ) ";
                SqlCommand cmd3 = new SqlCommand(qry3, con);
                cmd3.ExecuteNonQuery();


                //Set TeamEmployee table status=0 when dissolving the team table with particular teamID
                string     qry4 = " update TeamEmployee set   Status = 0 where TeamID='" + tid + "'    ";
                SqlCommand cmd4 = new SqlCommand(qry4, con);
                cmd4.ExecuteNonQuery();


                //set vehicle table isAllocated = 0
                string     qry6 = " update Vehicle set IsAllocated = 0  where VID in (select VID from TeamVehicle where TeamID='" + tid + "') ";
                SqlCommand cmd6 = new SqlCommand(qry6, con);
                cmd6.ExecuteNonQuery();



                con.Close();


                MessageBox.Show("Dissolve the team that you selected", "Team Dissolve", MessageBoxButtons.OK, MessageBoxIcon.Information);
                frmTeamEmployee frt = new frmTeamEmployee();
                frt.RefreshDGV();
                this.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Example #2
0
        private void employeeTeamAssignmentToolStripMenuItem_Click(object sender, EventArgs e)
        {
            bool Isopen = false;

            foreach (Form f15 in Application.OpenForms)
            {
                if (f15.Text == "Team Employee Assignment")
                {
                    Isopen = true;
                    f15.BringToFront();
                    break;
                }
            }
            if (Isopen == false)
            {
                frmTeamEmployee f15 = new frmTeamEmployee();
                f15.Show();
            }
        }