コード例 #1
0
        public string getStringPeople(int Id)
        {
            string result = "";

            try
            {
                var       db = new SQLDatabaseHelper();
                DataTable recipe;
                String    query = "SELECT * FROM People WHERE ID =" + Id;
                recipe = db.GetDataTable(query);
                if (recipe != null)
                {
                    foreach (DataRow r in recipe.Rows)
                    {
                        result = (string)r["RealName"];
                    }
                }
            }
            catch (Exception fail)
            {
                String error = "The following error has occurred:\n\n";
                error += fail.Message.ToString() + "\n\n";
            }
            return(result);
        }
コード例 #2
0
 public void ShowData(int type, int people, int author)
 {
     try
     {
         var       db = new SQLDatabaseHelper();
         DataTable recipe;
         String    query =
             "SELECT  s.ID,s.Sentence AS 'Câu',t.Description AS 'Kiểu câu',p.RealName AS 'Viết cho',s.Author AS 'Người viết' " +
             "FROM Sentence s, TypeSentence t, People p " +
             "WHERE (s.TypeId = t.ID AND s.PeopleId = p.ID";
         if (type != 0)
         {
             query += " AND s.TypeId =" + type;
         }
         if (people != 0)
         {
             query += " AND s.PeopleId =" + people;
         }
         if (author != 0)
         {
             query += " AND s.Author =" + author;
         }
         query += ")";
         recipe = db.GetDataTable(query);
         dgvSentence.DataSource = recipe;
     }
     catch (Exception fail)
     {
         String error = "The following error has occurred:\n\n";
         error += fail.Message.ToString() + "\n\n";
     }
 }
コード例 #3
0
        public int getIDPeople(string str)
        {
            if (str == "")
            {
                return(0);
            }
            int result = 1;

            try
            {
                var       db = new SQLDatabaseHelper();
                DataTable recipe;
                String    query = "SELECT * FROM People WHERE RealName LIKE N'%" + str + "%'";
                recipe = db.GetDataTable(query);
                if (recipe != null)
                {
                    foreach (DataRow r in recipe.Rows)
                    {
                        result = (int)r["ID"];
                    }
                }
            }
            catch (Exception fail)
            {
                String error = "The following error has occurred:\n\n";
                error += fail.Message.ToString() + "\n\n";
            }
            return(result);
        }
コード例 #4
0
 public void FillAllCombobox()
 {
     try
     {
         var       db = new SQLDatabaseHelper();
         DataTable recipe;
         String    query = "SELECT * FROM TypeSentence";
         recipe = db.GetDataTable(query);
         if (recipe != null)
         {
             foreach (DataRow r in recipe.Rows)
             {
                 cbbType.Items.Add(r["Description"].ToString());
             }
         }
         query  = "SELECT * FROM People";
         recipe = db.GetDataTable(query);
         if (recipe != null)
         {
             foreach (DataRow r in recipe.Rows)
             {
                 cbbPeople.Items.Add(r["RealName"].ToString());
                 cbbAuthor.Items.Add(r["RealName"].ToString());
             }
         }
     }
     catch (Exception fail)
     {
         String error = "The following error has occurred:\n\n";
         error += fail.Message.ToString() + "\n\n";
     }
 }
コード例 #5
0
        public bool Delete(int sentenceId)
        {
            var db = new SQLDatabaseHelper();

            try
            {
                db.Delete("Sentence", String.Format("ID = {0}", sentenceId));
                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
            //db.Delete("HAS_INGREDIENT", String.Format("ID = {0}", sentenceId));
        }
コード例 #6
0
        public bool Insert(string sentence, int typeId, int peopleId, int author)
        {
            var db   = new SQLDatabaseHelper();
            var data = new Dictionary <String, String>();

            data.Add("Sentence", sentence);
            data.Add("TypeId", typeId.ToString());
            data.Add("PeopleId", peopleId.ToString());
            data.Add("Author", peopleId.ToString());
            try
            {
                db.Insert("Sentence", data);
                return(true);
            }
            catch (Exception crap)
            {
                MessageBox.Show(crap.Message);
                return(false);
            }
        }
コード例 #7
0
        public bool Update(int sentenceId, string sentence, int typeId, int peopleId, int author)
        {
            var db   = new SQLDatabaseHelper();
            var data = new Dictionary <String, String>();

            // DataTable rows;
            data.Add("Sentence", sentence);
            data.Add("TypeId", typeId.ToString());
            data.Add("PeopleId", peopleId.ToString());
            data.Add("Author", peopleId.ToString());
            try
            {
                db.Update("Sentence", data, String.Format("ID = {0}", sentenceId));
                return(true);
            }
            catch (Exception crap)
            {
                return(false);
            }
        }