Example #1
0
        public bool Delete(WorkingDays w)
        {
            bool x = false;

            SqlConnection con = new SqlConnection(@"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=C:\Users\ASUS\Documents\TimeTableManagement.mdf;Integrated Security=True;Connect Timeout=30");

            try
            {
                string     sql = "DELETE FROM WorkingDays WHERE Emp_ID = @id";
                SqlCommand cmd = new SqlCommand(sql, con);
                cmd.Parameters.AddWithValue("@id", w.Emp_ID);

                con.Open();

                int rows = cmd.ExecuteNonQuery();
                if (rows > 0)
                {
                    x = true;
                }
                else
                {
                    x = false;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                con.Close();
            }

            return(x);
        }
Example #2
0
        public bool Insert(WorkingDays w)
        {
            bool x = false;

            SqlConnection con = new SqlConnection(@"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=C:\Users\ASUS\Documents\TimeTableManagement.mdf;Integrated Security=True;Connect Timeout=30");

            try
            {
                string     sql = "INSERT INTO WorkingDays (Emp_ID,NoOfWork,WorkDays,WorkingPerDay) VALUES (@empid,@noofwork,@workdays,@workingperday)";
                SqlCommand cmd = new SqlCommand(sql, con);

                cmd.Parameters.AddWithValue("@empid", w.Emp_ID);
                cmd.Parameters.AddWithValue("@noofwork", w.NoOfWork);
                cmd.Parameters.AddWithValue("@workdays", w.WorkDays);
                cmd.Parameters.AddWithValue("@workingperday", w.WorkingPerDay);


                con.Open();
                int rows = cmd.ExecuteNonQuery();
                if (rows > 0)
                {
                    x = true;
                }
                else
                {
                    x = false;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                con.Close();
            }

            return(x);
        }