Exemple #1
0
        public static NewSDetailM GetNews(string Connection, int id)
        {
            NewSDetailM value = new NewSDetailM();

            using (SqlConnection con = new SqlConnection(Connection))
            {
                con.Open();
                SqlCommand com = new SqlCommand("SELECT * FROM details WHERE id=@id", con);
                com.Parameters.AddWithValue("id", id);
                SqlDataReader rd = com.ExecuteReader();

                if (rd.Read())
                {
                    value.status    = Convert.ToInt32(rd["status"]);
                    value.maincateg = Convert.ToInt32(rd["category_main"]);
                    value.subcateg  = Convert.ToInt32(rd["category_sub"]);

                    value.owner   = 1;
                    value.title   = rd["title"].ToString();
                    value.picture = rd["picture"].ToString();
                    value.likes   = Convert.ToInt32(rd["likes"]);

                    value.datec = Convert.ToDateTime(rd["date_created"]);
                    value.datem = Convert.ToDateTime(rd["date_modified"]);
                }
            }

            return(value);
        }
Exemple #2
0
        public static NewSDetailM newsDoldur()
        {
            NewSDetailM news = new NewSDetailM();

            news.status    = 2;
            news.maincateg = 0;
            news.subcateg  = 0;

            news.owner   = 0;
            news.title   = "title";
            news.picture = "picture link www";
            news.likes   = 0;

            news.datec = Convert.ToDateTime("16.03.2019");
            news.datem = Convert.ToDateTime("16.03.2019");

            return(news);
        }
Exemple #3
0
        public static void dbEditUpp(List <string> tipler, List <string> bolumler, NewSDetailM newsModel)
        {
            string typeString, partString;

            #region CreatingCommands
            {
                string komut = "UPDATE types SET";
                for (int i = 0; i < Model.tab; i++)
                {
                    string temp = ", t{0}=@t{0}";
                    temp  = string.Format(temp, (i + 1));
                    komut = komut + temp;
                }
                komut      = komut + " WHERE id=@id"; komut = komut.Replace("SET,", "SET");
                typeString = komut;
            }

            {
                string komut = "UPDATE parts SET";
                for (int i = 0; i < Model.tab; i++)
                {
                    string temp = ", p{0}=@p{0}";
                    temp  = string.Format(temp, (i + 1));
                    komut = komut + temp;
                }
                komut      = komut + " WHERE id=@id"; komut = komut.Replace("SET,", "SET");
                partString = komut;
            }
            #endregion
            #region update
            using (SqlConnection con = new SqlConnection(Model.Connection))
            {
                con.Open();
                SqlCommand command1 = new SqlCommand(typeString, con);
                SqlCommand command2 = new SqlCommand(partString, con);
                command1.Parameters.AddWithValue("@id", Model.ContentID);
                command2.Parameters.AddWithValue("@id", Model.ContentID);

                for (int i = 0; i < Model.tab; i++)
                {
                    try
                    {
                        command1.Parameters.AddWithValue("t" + (i + 1), tipler[i].ToString());
                        command2.Parameters.AddWithValue("p" + (i + 1), bolumler[i].ToString());
                    }
                    catch
                    {
                        command1.Parameters.AddWithValue("t" + (i + 1), "");
                        command2.Parameters.AddWithValue("p" + (i + 1), "");
                    }
                }
                command1.ExecuteNonQuery();
                command2.ExecuteNonQuery();

                con.Close();


                con.Open();
                SqlCommand com = new SqlCommand("UPDATE details SET status=@status,category_main=@category_main,category_sub=@category_sub,owner=@owner,title=@title,picture=@picture,likes=@likes,date_created=@date_created,date_modified=@date_modified WHERE id=@id", con);
                com.Parameters.AddWithValue("id", Model.ContentID);
                com.Parameters.AddWithValue("status", newsModel.status);
                com.Parameters.AddWithValue("category_main", newsModel.maincateg);
                com.Parameters.AddWithValue("category_sub", newsModel.subcateg);
                com.Parameters.AddWithValue("owner", newsModel.owner);
                com.Parameters.AddWithValue("title", newsModel.title);
                com.Parameters.AddWithValue("picture", newsModel.picture);
                com.Parameters.AddWithValue("likes", newsModel.likes);
                com.Parameters.AddWithValue("date_created", newsModel.datec);
                com.Parameters.AddWithValue("date_modified", newsModel.datem);

                com.ExecuteNonQuery();
                con.Close();
            }
            #endregion
        }
Exemple #4
0
        public static void dbAddUpp(List <string> tipler, List <string> bolumler, NewSDetailM newsModel)
        {
            string typeString, partString;

            #region Commands
            {
                {
                    string komut = "INSERT INTO types(id";
                    for (int i = 0; i < Model.tab; i++)
                    {
                        string temp = ",t{0}";
                        temp  = string.Format(temp, (i + 1));
                        komut = komut + temp;
                    }
                    komut = komut + ") values (@id";
                    for (int i = 0; i < Model.tab; i++)
                    {
                        string temp = ",@t{0}";
                        temp  = string.Format(temp, (i + 1));
                        komut = komut + temp;
                    }
                    typeString = komut + ")";
                    typeString = typeString.Replace("id,", null);
                    typeString = typeString.Replace("@id,", null);
                    typeString = typeString.Replace("@@t", "@t");
                }

                {
                    string komut = "INSERT INTO parts(id";
                    for (int i = 0; i < Model.tab; i++)
                    {
                        string temp = ",p{0}";
                        temp  = string.Format(temp, (i + 1));
                        komut = komut + temp;
                    }
                    komut = komut + ") values (@id";
                    for (int i = 0; i < Model.tab; i++)
                    {
                        string temp = ",@p{0}";
                        temp  = string.Format(temp, (i + 1));
                        komut = komut + temp;
                    }
                    partString = komut + ")";
                    partString = partString.Replace("id,", null);
                    partString = partString.Replace("@id,", null);
                    partString = partString.Replace("@@p", "@p");
                }
            }

            #endregion
            #region update

            using (SqlConnection con = new SqlConnection(Model.Connection))
            {
                con.Open();
                SqlCommand com1 = new SqlCommand(typeString, con);
                SqlCommand com2 = new SqlCommand(partString, con);

                for (int i = 0; i < Model.tab; i++)
                {
                    try
                    {
                        com1.Parameters.AddWithValue("t" + (i + 1), tipler[i].ToString());
                        com2.Parameters.AddWithValue("p" + (i + 1), bolumler[i].ToString());
                    }
                    catch
                    {
                        com1.Parameters.AddWithValue("t" + (i + 1), "");
                        com2.Parameters.AddWithValue("p" + (i + 1), "");
                    }
                }
                com1.Parameters.Add("@id", SqlDbType.Int).Direction = ParameterDirection.Output;

                com1.ExecuteNonQuery();
                com2.ExecuteNonQuery();

                con.Close();


                con.Open();
                SqlCommand com = new SqlCommand("INSERT INTO details(status,category_main,category_sub,owner,title,picture,likes,date_created,date_modified) values (@status,@category_main,@category_sub,@owner,@title,@picture,@likes,@date_created,@date_modified)", con);
                com.Parameters.AddWithValue("status", newsModel.status);
                com.Parameters.AddWithValue("category_main", newsModel.maincateg);
                com.Parameters.AddWithValue("category_sub", newsModel.subcateg);
                com.Parameters.AddWithValue("owner", newsModel.owner);
                com.Parameters.AddWithValue("title", newsModel.owner);
                com.Parameters.AddWithValue("picture", newsModel.picture);
                com.Parameters.AddWithValue("likes", newsModel.likes);
                com.Parameters.AddWithValue("date_created", newsModel.datec);
                com.Parameters.AddWithValue("date_modified", newsModel.datem);

                com.ExecuteNonQuery();
                con.Close();
            }
            #endregion
        }