Example #1
0
        private void button2_Click(object sender, EventArgs e)
        {
            try
            {
                db = new linqDataContext();
                test pinfo = new test();
                pinfo.lvl         = TestInf.lvl;
                pinfo.language    = TestInf.language;
                pinfo.theme       = TestInf.theme;
                pinfo.description = TestInf.descript;
                pinfo.t_name      = TestInf.name;
                db.test.InsertOnSubmit(pinfo);
                db.SubmitChanges();


                var query = from pe in db.test

                            select pe;
                dataGridView2.DataSource = query.ToList();


                var uinfo = Convert.ToInt32(dataGridView2.Rows[dataGridView2.RowCount - 1].Cells[0].Value.ToString());


                for (int i = 0; i < dataGridView1.RowCount - 1; i++)
                {
                    task_struct pcode = new task_struct();
                    pcode.id_test = uinfo;

                    pcode.position = Convert.ToInt32(dataGridView1.Rows[i].Cells[0].Value.ToString());

                    if (TestInf.lvl == "Легкий")
                    {
                        pcode.code_text = dataGridView1.Rows[i].Cells[1].Value.ToString();
                    }
                    if (TestInf.lvl == "Середній")
                    {
                        pcode.code_text = dataGridView1.Rows[i].Cells[1].Value.ToString();
                        if (dataGridView1.Rows[i].Cells[2].Value.ToString() != "")
                        {
                            pcode.code_text2 = dataGridView1.Rows[i].Cells[2].Value.ToString();
                        }
                    }
                    if (TestInf.lvl == "Складний")
                    {
                        pcode.handwork  = Convert.ToInt32(dataGridView1.Rows[i].Cells[1].Value.ToString());
                        pcode.code_text = dataGridView1.Rows[i].Cells[2].Value.ToString();
                    }
                    db.task_struct.InsertOnSubmit(pcode);
                    db.SubmitChanges();
                }


                MessageBox.Show("Тест успішно додано");
                this.Close();
            }
            catch { MessageBox.Show("Помилка добавлення"); }
        }
 partial void Updatetask_struct(task_struct instance);
 partial void Deletetask_struct(task_struct instance);
 partial void Inserttask_struct(task_struct instance);