コード例 #1
0
ファイル: Main.cs プロジェクト: usmanaziz91/TestProject
        private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            int id = int.Parse(dataGridView1.Rows[e.RowIndex].Cells[0].Value.ToString());

            if (e.ColumnIndex == 5 && e.RowIndex >= 0 && operationCheck == 0 && id != 0) //delete icon button is clicked
            {
                DialogResult result = MessageBox.Show("Do you want to delete this record?", "Confirmation", MessageBoxButtons.OKCancel);
                if (result == DialogResult.OK)
                {
                    DeleteVideo(id); //delete the record from the Book table
                }
            }
            else if (e.ColumnIndex == 4 && e.RowIndex >= 0 && id != 0)
            {
                DialogResult result = MessageBox.Show("Do you want to update this record?", "Confirmation", MessageBoxButtons.OKCancel);
                if (result == DialogResult.OK)
                {
                    DAL.DataClasses1DataContext objdal = new DAL.DataClasses1DataContext();
                    DAL.Video objvideo = objdal.Videos.FirstOrDefault(x => x.ID == id);
                    if (objvideo != null)
                    {
                        objvideo.VideoTitle    = dataGridView1.Rows[e.RowIndex].Cells[1].Value.ToString();
                        objvideo.VideoUrl      = dataGridView1.Rows[e.RowIndex].Cells[2].Value.ToString();
                        objvideo.CategoryTitle = dataGridView1.Rows[e.RowIndex].Cells[3].Value.ToString();

                        objdal.SubmitChanges();
                        //bind grid
                        dataGridView1.DataSource = from c in objdal.Videos
                                                   select c;
                    }
                }
            }
            else if (e.ColumnIndex == 4 && e.RowIndex >= 0 && id == 0)
            {
                DAL.DataClasses1DataContext objdal = new DAL.DataClasses1DataContext();
                DAL.Video objvideo = new DAL.Video();
                objvideo.UserID        = LoggedInUser.UserID;
                objvideo.VideoTitle    = dataGridView1.Rows[e.RowIndex].Cells[1].Value.ToString();
                objvideo.VideoUrl      = dataGridView1.Rows[e.RowIndex].Cells[2].Value.ToString();
                objvideo.CategoryTitle = objvideo.VideoTitle = dataGridView1.Rows[e.RowIndex].Cells[3].Value.ToString();

                objdal.Videos.InsertOnSubmit(objvideo);
                objdal.SubmitChanges();
                //bind grid
                dataGridView1.DataSource = from c in objdal.Videos
                                           select c;
            }
            UpdateID();
        }
コード例 #2
0
ファイル: Main.cs プロジェクト: usmanaziz91/TestProject
 private void DeleteVideo(int id)
 {
     try
     {
         DAL.DataClasses1DataContext objdal = new DAL.DataClasses1DataContext();
         DAL.Video objvideo = objdal.Videos.FirstOrDefault(x => x.ID == id);
         if (objvideo != null)
         {
             objdal.Videos.DeleteOnSubmit(objvideo);
             objdal.SubmitChanges();
             //bind grid
             dataGridView1.DataSource = from c in objdal.Videos
                                        select c;
         }
     }
     catch
     { }
 }
コード例 #3
0
ファイル: Main.cs プロジェクト: usmanaziz91/TestProject
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                if (txtTitle.Text.Trim() != "" && txtURL.Text.Trim() != "")
                {
                    DAL.DataClasses1DataContext  objdal=new DAL.DataClasses1DataContext();

                    DAL.Video objvideo= new DAL.Video();

                    objvideo.VideoTitle = txtTitle.Text.Trim();
                    objvideo.VideoUrl = txtURL.Text.Trim();
                    objvideo.CategoryTitle = comboBox1.SelectedValue.ToString();
                    objvideo.UserID = LoggedInUser.UserID;

                    objdal.Videos.InsertOnSubmit(objvideo);
                    objdal.SubmitChanges();
                    if (objvideo.ID > 0)
                    {
                        MessageBox.Show("Record added successfully");
                        dataGridView1.DataSource = from c in objdal.Videos
                                                   select c;
                        UpdateID();
                        txtTitle.Text = txtURL.Text = "";
                    }
                    else
                    {
                        MessageBox.Show("Record not added");
                    }

                }
            }
            catch
            {

            }
        }
コード例 #4
0
ファイル: Main.cs プロジェクト: usmanaziz91/TestProject
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                if (txtTitle.Text.Trim() != "" && txtURL.Text.Trim() != "")
                {
                    DAL.DataClasses1DataContext objdal = new DAL.DataClasses1DataContext();


                    DAL.Video objvideo = new DAL.Video();

                    objvideo.VideoTitle    = txtTitle.Text.Trim();
                    objvideo.VideoUrl      = txtURL.Text.Trim();
                    objvideo.CategoryTitle = comboBox1.SelectedValue.ToString();
                    objvideo.UserID        = LoggedInUser.UserID;

                    objdal.Videos.InsertOnSubmit(objvideo);
                    objdal.SubmitChanges();
                    if (objvideo.ID > 0)
                    {
                        MessageBox.Show("Record added successfully");
                        dataGridView1.DataSource = from c in objdal.Videos
                                                   select c;
                        UpdateID();
                        txtTitle.Text = txtURL.Text = "";
                    }
                    else
                    {
                        MessageBox.Show("Record not added");
                    }
                }
            }
            catch
            {
            }
        }
コード例 #5
0
ファイル: Main.cs プロジェクト: usmanaziz91/TestProject
        private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            int id = int.Parse(dataGridView1.Rows[e.RowIndex].Cells[0].Value.ToString());
            if (e.ColumnIndex == 5 && e.RowIndex >= 0 && operationCheck == 0 && id!=0) //delete icon button is clicked
            {

                DialogResult result = MessageBox.Show("Do you want to delete this record?", "Confirmation", MessageBoxButtons.OKCancel);
                if (result == DialogResult.OK)
                {
                    DeleteVideo(id); //delete the record from the Book table

                }

            }
            else if (e.ColumnIndex == 4 && e.RowIndex >= 0 && id!=0)
            {
                DialogResult result = MessageBox.Show("Do you want to update this record?", "Confirmation", MessageBoxButtons.OKCancel);
                if (result == DialogResult.OK)
                {
                    DAL.DataClasses1DataContext objdal = new DAL.DataClasses1DataContext();
                    DAL.Video objvideo = objdal.Videos.FirstOrDefault(x => x.ID == id);
                    if (objvideo != null)
                    {
                        objvideo.VideoTitle = dataGridView1.Rows[e.RowIndex].Cells[1].Value.ToString();
                        objvideo.VideoUrl = dataGridView1.Rows[e.RowIndex].Cells[2].Value.ToString();
                        objvideo.CategoryTitle = dataGridView1.Rows[e.RowIndex].Cells[3].Value.ToString();

                        objdal.SubmitChanges();
                        //bind grid
                        dataGridView1.DataSource = from c in objdal.Videos
                                                   select c;
                    }
                }
            }
            else if (e.ColumnIndex == 4 && e.RowIndex >= 0  && id==0)
            {

                DAL.DataClasses1DataContext objdal = new DAL.DataClasses1DataContext();
                DAL.Video objvideo = new DAL.Video();
                objvideo.UserID = LoggedInUser.UserID;
                objvideo.VideoTitle = dataGridView1.Rows[e.RowIndex].Cells[1].Value.ToString();
                objvideo.VideoUrl = dataGridView1.Rows[e.RowIndex].Cells[2].Value.ToString();
                objvideo.CategoryTitle = objvideo.VideoTitle = dataGridView1.Rows[e.RowIndex].Cells[3].Value.ToString();

                objdal.Videos.InsertOnSubmit(objvideo);
                objdal.SubmitChanges();
                //bind grid
                dataGridView1.DataSource = from c in objdal.Videos
                                           select c;

            }
            UpdateID();
        }