コード例 #1
0
 public bool UpdateWorkshopById(tbl_Workshop Wp, int WorkShopId)
 {
     try
     {
         string        conStr = "Data Source=rakib;Initial Catalog=WorkShopDB;Integrated Security=True";
         string        cmdStr = @"Update tbl_WorkShop 
                                         Set WorkShopTitle=@WorkShopTitle,WorkShopDate=@WorkShopDate,
                                         WorkShopDuration=@WorkShopDuration,WorkshopTopics=@WorkshopTopics 
                                         where  WorkShopId=@WorkShopId";
         SqlConnection con    = new SqlConnection(conStr);
         SqlCommand    cmd    = new SqlCommand(cmdStr, con);
         cmd.Parameters.AddWithValue("@WorkShopTitle", Wp.WorkShopTitle);
         cmd.Parameters.AddWithValue("@WorkShopDate", Wp.WorkShopDate);
         cmd.Parameters.AddWithValue("@WorkShopDuration", Wp.WorkShopDuration);
         cmd.Parameters.AddWithValue("@WorkshopTopics", Wp.WorkShopTopics);
         cmd.Parameters.AddWithValue("@WorkShopId", WorkShopId);
         con.Open();
         cmd.ExecuteNonQuery();
         con.Close();
         return(true);
     }
     catch
     {
         return(false);
     }
 }
コード例 #2
0
        public tbl_Workshop GetWorkshopById(int WorkShopId)
        {
            tbl_Workshop Wp = null;

            string        conStr = "Data Source=rakib;Initial Catalog=WorkShopDB;Integrated Security=True";
            string        cmdStr = "select * from tbl_WorkShop where WorkShopId=@WorkShopId";
            SqlConnection con    = new SqlConnection(conStr);
            SqlCommand    cmd    = new SqlCommand(cmdStr, con);

            cmd.Parameters.AddWithValue("@WorkShopId", WorkShopId);
            con.Open();
            SqlDataReader dr = cmd.ExecuteReader();

            if (dr.Read())
            {
                Wp                  = new tbl_Workshop();
                Wp.WorkShopId       = int.Parse(dr["WorkShopId"].ToString());
                Wp.WorkShopTitle    = dr["WorkShopTitle"].ToString();
                Wp.WorkShopDate     = DateTime.Parse(dr["WorkShopDate"].ToString());
                Wp.WorkShopDuration = dr["WorkShopDuration"].ToString();
                Wp.WorkShopTopics   = dr["WorkShopTopics"].ToString();
            }
            dr.Close();
            con.Close();
            return(Wp);
        }
コード例 #3
0
        public tbl_Workshop GetWorkshopById(int WorkShopId)
        {
            WorkShopDb   WD = new WorkShopDb();
            tbl_Workshop Wp = WD.GetWorkshopById(WorkShopId);

            return(Wp);
        }
コード例 #4
0
ファイル: WorkshopDB.cs プロジェクト: Pritesh03/Workshop
        //Insert new workshop into database
        public bool InsertIntoDB(tbl_Workshop workshop)
        {
            SqlConnection conn = new SqlConnection();

            conn.ConnectionString = "Data Source = ADMIN-PC\\PritSQLExpress; Initial Catalog = Workshop; Integrated Security = True;";
            try
            {
                //Insert the 'workshop' into DB

                SqlCommand cmd = new SqlCommand();
                cmd.CommandType = CommandType.Text;
                cmd.CommandText = "INSERT INTO tbl_Workshop VALUES (@WorkshopTitle, @WorkshopDate, @WorkshopDuration, @WorkshopTopics, NULL, NULL, NULL, NULL);";
                cmd.Connection  = conn;

                cmd.Parameters.AddWithValue("@WorkshopTitle", workshop.WorkshopTitle);
                cmd.Parameters.AddWithValue("@WorkshopDate", workshop.WorkshopDate);
                cmd.Parameters.AddWithValue("@WorkshopDuration", workshop.WorkshopDuration);
                cmd.Parameters.AddWithValue("@WorkshopTopics", workshop.WorkshopTopics);

                conn.Open();
                cmd.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
            }
            finally
            {
                conn.Close();
            }
            return(true);
        }
コード例 #5
0
ファイル: WorkshopDB.cs プロジェクト: Pritesh03/Workshop
        //Fetch all workshops to display on screen
        public List <tbl_Workshop> GetWorkshops()
        {
            List <tbl_Workshop> lstWorkshops = new List <tbl_Workshop>();

            try
            {
                using (SqlConnection conn = new SqlConnection("Data Source = ADMIN-PC\\PritSQLExpress; Initial Catalog = Workshop; Integrated Security = True;"))
                {
                    SqlCommand cmd = new SqlCommand("SELECT * FROM tbl_Workshop", conn);

                    conn.Open();
                    SqlDataReader dr = cmd.ExecuteReader();

                    while (dr.Read())
                    {
                        tbl_Workshop workshop = new tbl_Workshop();
                        workshop.WorkshopId       = int.Parse(dr["WorkshopId"].ToString());
                        workshop.WorkshopTitle    = Convert.ToString(dr["WorkshopTitle"]);
                        workshop.WorkshopDate     = DateTime.Parse(dr["WorkshopDate"].ToString());
                        workshop.WorkshopDuration = Convert.ToString(dr["WorkshopDuration"]);
                        workshop.WorkshopTopics   = Convert.ToString(dr["WorkshopTopics"]);

                        lstWorkshops.Add(workshop);
                    }
                    dr.Close();
                }
            }
            catch
            {
            }
            return(lstWorkshops);
        }
コード例 #6
0
    protected void btnSave_Click(object sender, EventArgs e)
    {
        tbl_Workshop Wp = new tbl_Workshop();

        Wp.WorkShopTitle    = txtWorkShopTitle.Text;
        Wp.WorkShopDate     = DateTime.Parse(txtWorkShopDate.Text);
        Wp.WorkShopTopics   = txtWorkShopTopics.Text;
        Wp.WorkShopDuration = txtWorkShopDuration.Text;

        List <int> Ls = new List <int>();

        foreach (ListItem item in ckbLTrainers.Items)
        {
            int TrainerId;
            if (item.Selected)
            {
                TrainerId = int.Parse(item.Value);
                Ls.Add(TrainerId);
            }
        }

        WorkshopBusiness WB = new WorkshopBusiness();

        WB.InsertWorkshop(Wp, Ls);
        GetWorkShops();
    }
コード例 #7
0
        public List <tbl_Workshop> GetWorkshops()
        {
            List <tbl_Workshop> Ls;

            Ls = new List <tbl_Workshop>();

            string        conStr = "Data Source=rakib;Initial Catalog=WorkShopDB;Integrated Security=True";
            string        cmdStr = "select * from tbl_WorkShop";
            SqlConnection con    = new SqlConnection(conStr);
            SqlCommand    cmd    = new SqlCommand(cmdStr, con);

            con.Open();
            SqlDataReader dr = cmd.ExecuteReader();

            while (dr.Read())
            {
                tbl_Workshop Wp = new tbl_Workshop();
                Wp.WorkShopId       = int.Parse(dr["WorkShopId"].ToString());
                Wp.WorkShopTitle    = dr["WorkShopTitle"].ToString();
                Wp.WorkShopDate     = DateTime.Parse(dr["WorkShopDate"].ToString());
                Wp.WorkShopDuration = dr["WorkShopDuration"].ToString();
                Wp.WorkShopTopics   = dr["WorkShopTopics"].ToString();

                Ls.Add(Wp);
            }
            dr.Close();
            con.Close();
            return(Ls);
        }
コード例 #8
0
        public bool InsertWorkshop(tbl_Workshop Wp, List <int> Ls)
        {
            SqlConnection con = new SqlConnection(conStr);

            string cmdStr  = @"insert into tbl_WorkShop values(@WorkShopTitle,@WorkShopDate,@WorkShopDuration
                                            ,@WorkshopTopics,null,null,null,null) ;select Scope_Identity() as Id";
            string cmdStr2 = "insert into tbl_Trainer_WorkShop_Mapping values(@TrainerId,@WorkShopId,null,null,null,null) ";

            con.Open();
            SqlTransaction SqTrans = con.BeginTransaction();

            try
            {
                //Inserting Workshop
                SqlCommand cmd = new SqlCommand(cmdStr, con, SqTrans);
                cmd.Parameters.AddWithValue("@WorkShopTitle", Wp.WorkShopTitle);
                cmd.Parameters.AddWithValue("@WorkShopDate", Wp.WorkShopDate);
                cmd.Parameters.AddWithValue("@WorkShopDuration", Wp.WorkShopDuration);
                cmd.Parameters.AddWithValue("@WorkshopTopics", Wp.WorkShopTopics);
                SqlDataReader dr = cmd.ExecuteReader();

                //Reading WorkshopId returned from Scope_Identity
                int WorkShopId = 0;
                if (dr.Read())
                {
                    WorkShopId = int.Parse(dr[0].ToString());
                }
                dr.Close();

                //Inserting multiple records in tbl_Trainer_Workshop_Mapping
                //with retrived WorkshopId from Scope_Identity
                //And TrainerIds from Ls
                if (WorkShopId != 0)
                {
                    foreach (var TrainerId in Ls)
                    {
                        SqlCommand cmd2 = new SqlCommand(cmdStr2, con, SqTrans);
                        cmd2.Parameters.AddWithValue("@TrainerId", TrainerId);
                        cmd2.Parameters.AddWithValue("@WorkshopId", WorkShopId);
                        cmd2.ExecuteNonQuery();
                    }
                }

                //If Every thing is successful then commiting the transaction
                SqTrans.Commit();
                con.Close();
                return(true);
            }
            catch
            {
                //If any thing goes wrong then Rolling back the transaction
                SqTrans.Rollback();
                return(false);
            }
        }
コード例 #9
0
    protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
    {
        int id = int.Parse(GridView1.SelectedValue.ToString());
        WorkshopBusiness WB = new WorkshopBusiness();
        tbl_Workshop     Wp = WB.GetWorkshopById(id);

        txtWorkShopTitle.Text    = Wp.WorkShopTitle;
        txtWorkShopDate.Text     = Wp.WorkShopDate.ToString();
        txtWorkShopDuration.Text = Wp.WorkShopDuration;
        txtWorkShopTopics.Text   = Wp.WorkShopTopics;
    }
コード例 #10
0
    protected void gvWorkshops_SelectedIndexChanged(object sender, EventArgs e)
    {
        int selectedRowWorkshopId = int.Parse(gvWorkshops.SelectedValue.ToString());

        WorkshopBusiness workshopBusiness = new WorkshopBusiness();
        tbl_Workshop     workshop         = workshopBusiness.GetWorkshopById(selectedRowWorkshopId);

        txtWorkshopTitle.Text    = workshop.WorkshopTitle;
        txtWorkshopDate.Text     = workshop.WorkshopDate.ToShortDateString();
        txtWorkshopDuration.Text = workshop.WorkshopDuration;
        txtWorkshopTopics.Text   = workshop.WorkshopTopics;
    }
コード例 #11
0
 public bool UpdateWorkshopById(tbl_Workshop Wp, int WorkShopId)
 {
     if (Wp.WorkShopDate > DateTime.Now)
     {
         WD.UpdateWorkshopById(Wp, WorkShopId);
         return(true);
     }
     else
     {
         return(false);
     }
 }
コード例 #12
0
 public bool InsertWorkshop(tbl_Workshop Wp, List <int> Ls)
 {
     //Workshopdate should be greater than current date
     if (Wp.WorkShopDate > DateTime.Now)
     {
         WD.InsertWorkshop(Wp, Ls);
         return(true);
     }
     else
     {
         return(false);
     }
 }
コード例 #13
0
    protected void btnSave_Click(object sender, EventArgs e)
    {
        tbl_Workshop Wp = new tbl_Workshop();

        Wp.WorkShopTitle    = txtWorkShopTitle.Text;
        Wp.WorkShopDate     = DateTime.Parse(txtWorkShopDate.Text);
        Wp.WorkShopTopics   = txtWorkShopTopics.Text;
        Wp.WorkShopDuration = txtWorkShopDuration.Text;
        WorkshopBusiness WB = new WorkshopBusiness();

        WB.InsertWorkshop(Wp);
        GetWorkShops();
    }
コード例 #14
0
 public bool InsertWorkshop(tbl_Workshop Wp)
 {
     //Workshopdate should be greater than current date
     if (Wp.WorkShopDate > DateTime.Now)
     {
         WorkShopDb WD = new WorkShopDb();
         WD.InsertWorkshop(Wp);
         return(true);
     }
     else
     {
         return(false);
     }
 }
コード例 #15
0
    protected void btnUpdate_Click(object sender, EventArgs e)
    {
        tbl_Workshop Wp = new tbl_Workshop();

        Wp.WorkShopTitle    = txtWorkShopTitle.Text;
        Wp.WorkShopDate     = DateTime.Parse(txtWorkShopDate.Text);
        Wp.WorkShopTopics   = txtWorkShopTopics.Text;
        Wp.WorkShopDuration = txtWorkShopDuration.Text;

        WorkshopBusiness WB = new WorkshopBusiness();
        int id = int.Parse(GridView1.SelectedValue.ToString());

        WB.UpdateWorkshopById(Wp, id);

        GetWorkShops();
    }
コード例 #16
0
 //Insert record in database.
 public bool InsertWorkshop(tbl_Workshop workshop)
 {
     if (workshop.WorkshopDate > DateTime.Now)
     {
         WorkshopDB workshopDB = new WorkshopDB();
         if (workshopDB.InsertIntoDB(workshop))
         {
             return(true);
         }
         else
         {
             return(false);
         }
     }
     else
     {
         return(false);
     }
 }
コード例 #17
0
    protected void btnSave_Click(object sender, EventArgs e)
    {
        tbl_Workshop workshop = new tbl_Workshop();

        workshop.WorkshopTitle    = txtWorkshopTitle.Text;
        workshop.WorkshopDate     = DateTime.Parse(txtWorkshopDate.Text);
        workshop.WorkshopDuration = txtWorkshopDuration.Text;
        workshop.WorkshopTopics   = txtWorkshopTopics.Text;

        WorkshopBusiness workshopBusiness = new WorkshopBusiness();

        if (workshopBusiness.InsertWorkshop(workshop))
        {
            UpdateWorkshopsGrid();
            ClearInputs();
        }
        else
        {
        }
    }
コード例 #18
0
 public bool InsertWorkshop(tbl_Workshop Wp)
 {
     try
     {
         string        conStr = "Data Source=rakib;Initial Catalog=WorkShopDB;Integrated Security=True";
         string        cmdStr = "insert into tbl_WorkShop values(@WorkShopTitle,@WorkShopDate,@WorkShopDuration,@WorkshopTopics,null,null,null,null) ";
         SqlConnection con    = new SqlConnection(conStr);
         SqlCommand    cmd    = new SqlCommand(cmdStr, con);
         cmd.Parameters.AddWithValue("@WorkShopTitle", Wp.WorkShopTitle);
         cmd.Parameters.AddWithValue("@WorkShopDate", Wp.WorkShopDate);
         cmd.Parameters.AddWithValue("@WorkShopDuration", Wp.WorkShopDuration);
         cmd.Parameters.AddWithValue("@WorkshopTopics", Wp.WorkShopTopics);
         con.Open();
         cmd.ExecuteNonQuery();
         con.Close();
         return(true);
     }
     catch
     {
         return(false);
     }
 }
コード例 #19
0
ファイル: WorkshopDB.cs プロジェクト: Pritesh03/Workshop
        //Get a perticular workshop by id
        public tbl_Workshop GetWorkshopById(int?workshopId)
        {
            tbl_Workshop workshop = new tbl_Workshop();

            using (SqlConnection conn = new SqlConnection("Data Source = ADMIN-PC\\PritSQLExpress; Initial Catalog = Workshop; Integrated Security = True;"))
            {
                SqlCommand cmd = new SqlCommand("SELECT * FROM tbl_workshop WHERE WorkshopId = @WorkshopId", conn);
                cmd.Parameters.AddWithValue("@WorkshopId", workshopId);
                conn.Open();
                SqlDataReader dr = cmd.ExecuteReader();

                while (dr.Read())
                {
                    workshop.WorkshopId       = int.Parse(dr["WorkshopId"].ToString());
                    workshop.WorkshopTitle    = Convert.ToString(dr["WorkshopTitle"]);
                    workshop.WorkshopDate     = DateTime.Parse(dr["WorkshopDate"].ToString());
                    workshop.WorkshopDuration = Convert.ToString(dr["WorkshopDuration"]);
                    workshop.WorkshopTopics   = Convert.ToString(dr["WorkshopTopics"]);
                }
                dr.Close();
            }
            return(workshop);
        }
コード例 #20
0
        public tbl_Workshop GetWorkshopById(int WorkShopId)
        {
            tbl_Workshop Wp = WD.GetWorkshopById(WorkShopId);

            return(Wp);
        }