private void button2_Click(object sender, EventArgs e)
        {
            Disciplina d = serviciuLectori.GetDisciplinaById(Convert.ToInt32(idDisciplina.Text));
            Capitole   c = new Capitole
            {
                DisciplinaIdDisciplina = d.IdDisciplina,
                NumeCapitol            = capitolDis.Text
            };

            c.State = State.Added;
            serviciuLectori.CapitoleUDI(c);

            listareDiscipline();
        }
        public ActionResult AdaugaDisciplina()
        {
            if (!verificareSesiuneLogareLector())
            {
                return(RedirectToAction("Index", "Lector"));
            }

            //adaugam o noua disciplina
            string numeDisciplina = Request.Form["numeDisciplina"];

            if (numeDisciplina != null && numeDisciplina.Length != 0)
            {
                Disciplina d = new Disciplina
                {
                    NumeDisciplina = numeDisciplina
                };
                d.State = State.Added;
                serviciu.DisciplinaUDI(d);
            }

            //adaugam un capitol pentru disciplina
            numeDisciplina = Request.Form["valoareSelectata"];
            string numeCapitol = Request.Form["numeCapitol"];

            if (numeDisciplina != null && numeDisciplina.Length != 0)
            {
                if (numeCapitol != null && numeCapitol.Length != 0)
                {
                    Disciplina d = serviciu.GetDisciplinaByNume_Capitole(numeDisciplina);
                    Capitole   c = new Capitole
                    {
                        DisciplinaIdDisciplina = d.IdDisciplina,
                        NumeCapitol            = numeCapitol
                    };

                    c.State = State.Added;
                    serviciu.CapitoleUDI(c);
                }
            }

            var lista = serviciu.GetListaDiscipline();

            return(View(lista));
        }
        public ActionResult ImportaIntrebari(HttpPostedFileBase file)
        {
            if (file != null && file.ContentLength > 0)
            {
                try
                {
                    string path = Path.Combine(Server.MapPath("~/FisiereXML"), Path.GetFileName(file.FileName));
                    file.SaveAs(path);

                    /////////citim fisierul xml
                    System.Xml.XmlTextReader reader = new System.Xml.XmlTextReader(path);

                    Disciplina disCiplina  = null;
                    Capitole   capItol     = null;
                    Intrebari  intreBare   = null;
                    Raspunsuri rasPunsuri  = null;
                    int        idIntrebare = 0;

                    while (reader.Read())
                    {
                        reader.MoveToContent();
                        if (reader.NodeType == System.Xml.XmlNodeType.Element)
                        {
                            if (reader.Name == "Disciplina")
                            {
                                string s = reader.GetAttribute(0); // numele disciplinei


                                var v_dis = serviciu.GetDisciplinaByNume_Capitole(s);
                                disCiplina = v_dis;

                                if (disCiplina == null)
                                {
                                    // inseamna ca nu exista elemente
                                    // vom crea o noua disciplina

                                    disCiplina = new Disciplina
                                    {
                                        NumeDisciplina = s
                                    };

                                    disCiplina.State = State.Added;
                                    serviciu.DisciplinaUDI(disCiplina);
                                    disCiplina = serviciu.GetDisciplinaByNume_Capitole(s);
                                }
                            } // if disciplina

                            if (reader.Name == "capitol")
                            {
                                string numeCapitol = reader.GetAttribute(0); // numele capitolului

                                var var_cap = serviciu.GetCapitolByName(numeCapitol);
                                capItol = var_cap;
                                if (capItol == null)
                                {
                                    // inseamana ca nu exista elemente
                                    // vom crea un nou capitol
                                    capItol = new Capitole
                                    {
                                        NumeCapitol            = numeCapitol,
                                        DisciplinaIdDisciplina = disCiplina.IdDisciplina
                                    };

                                    capItol.State = State.Added;
                                    serviciu.CapitoleUDI(capItol);
                                    capItol = serviciu.GetCapitolByName(numeCapitol);
                                }
                            }
                        }

                        if (reader.NodeType == System.Xml.XmlNodeType.Element)
                        {
                            if (reader.Name == "intrebare")
                            {
                                reader.Read();
                                intreBare = new Intrebari
                                {
                                    CapitoleIdCapitol = capItol.IdCapitol,
                                    Intrebarea        = reader.Value
                                };

                                intreBare.State = State.Added;
                                serviciu.IntrebariUDI(intreBare);

                                idIntrebare = serviciu.GetMaxId();
                            }

                            //vom completa cu informatiile pentru raspuns
                            if (reader.Name == "raspunsMotivate")
                            {
                                rasPunsuri = new Raspunsuri();
                                rasPunsuri.IntrebariIdIntrebare = idIntrebare;
                            }

                            if (reader.Name == "raspuns")
                            {
                                reader.Read();
                                rasPunsuri.Raspuns = reader.Value;
                            }
                            if (reader.Name == "motivare")
                            {
                                reader.Read();
                                rasPunsuri.MotivareRaspuns = reader.Value;
                            }
                            if (reader.Name == "corect")
                            {
                                reader.Read();
                                rasPunsuri.RaspunsCorect = reader.Value == "f" ? 0 : 1;
                                rasPunsuri.State         = State.Added;
                                serviciu.RaspunsuriUDI(rasPunsuri);
                            }
                        }
                    }

                    ViewBag.Message = "Fisierul a fost incarcat cu succes";
                }
                catch (Exception ex)
                {
                    ViewBag.Message = "Exceptie:" + ex.Message.ToString();
                }
            }
            else
            {
                ViewBag.Message = "Nu ai ales nici un fisier";
            }
            return(View());
        }
示例#4
0
 //extrag din baza de date capitolele si le pun in struct
 public static Capitole[] get_capitole(string decizie)
 {
     Capitole[] capitole;
     SQLiteConnection sqlite_conn;
     SQLiteCommand sqlite_cmd;
     SQLiteDataReader sqlite_dr;
     string database_title= get_databaseName_tableName.get_databaseName(decizie, "capitole");
     string table_title=get_databaseName_tableName.get_tableName(decizie, "capitole");
     int i = 0, starting_column = get_databaseName_tableName.get_startingCol(decizie);
        /* if (decizie == "info") { database_title = "Capitole.db"; table_title = "capitole"; starting_column = 0; }
     if (decizie == "mate") { database_title = "Capitole_mate.db"; table_title = "capitole_mate"; starting_column = 1; }
     if (decizie == "bio") { database_title = "Capitole_bio.db"; table_title = "capitole_bio"; starting_column = 1; }*/
     sqlite_conn = new SQLiteConnection("Data Source="+database_title+";Version=3;New=False;Compress=True;");
     capitole = new Capitole[get_the_number_of_rows(database_title, table_title)+1];
     try
     {
         sqlite_conn.Open();
         sqlite_cmd = sqlite_conn.CreateCommand();
         sqlite_cmd.CommandText = "SELECT * FROM " + table_title;
         sqlite_dr = sqlite_cmd.ExecuteReader();
         while (sqlite_dr.Read())
         {
             i++;
             string titlu = sqlite_dr.GetString(starting_column);
             string text = sqlite_dr.GetString(starting_column + 1);
             string id_html = sqlite_dr.GetString(starting_column + 2);
             capitole[i].title = titlu;
             capitole[i].text = text;
             capitole[i].html = id_html;
         }
     }
     catch(Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
     return capitole;
 }