Exemplo n.º 1
0
        public static IEnumerable <WorkArea> ShowAllAreas(int num)
        {
            List <WorkArea> list = new List <WorkArea>();

            using (var conn = Connection.conn = new SqlConnection(Connection.connectstr))
            {
                conn.Open();
                using (var cmd = Connection.cmd = new SqlCommand($"select * from WorkAreas_{num}", conn))
                {
                    var dreder = Connection.dreder = cmd.ExecuteReader();
                    while (dreder.Read())
                    {
                        WorkArea area = new WorkArea();
                        area.Coments    = dreder["Coments"].ToString();
                        area.Email      = dreder["Email"].ToString();
                        area.DateCreate = Convert.ToDateTime(dreder["DateCreate"].ToString());
                        area.SiteName   = dreder["SiteName"].ToString();
                        area.Login      = dreder["Login"].ToString();
                        area.Password   = dreder["Password"].ToString();
                        area.Phone      = Convert.ToInt32(dreder["Phone"].ToString());
                        area.URL        = dreder["URL"].ToString();
                        area.Id         = Convert.ToInt32(dreder["Id"].ToString());

                        list.Add(area);
                    }
                }
                return(list);
            }
        }
Exemplo n.º 2
0
        public static string AddWorkArea(WorkArea area, int num)
        {
            string msg   = string.Empty,
                   query = $"insert into WorkAreas_{num}(SiteName, Email, Login, Password, URL, Phone, Coments, DateCreate) " +
                           $"values(@SiteName, @Email, @Login, @Password, @URL, @Phone, @Coments, @DateCreate)";

            using (var c = Connection.conn = new System.Data.SqlClient.SqlConnection(Connection.connectstr))
            {
                c.Open();
                using (var cmd = Connection.cmd = new System.Data.SqlClient.SqlCommand(query, c))
                {
                    cmd.Parameters.AddWithValue("@SiteName", area.SiteName);
                    cmd.Parameters.AddWithValue("@Email", area.Email);
                    cmd.Parameters.AddWithValue("@Login", area.Login);
                    cmd.Parameters.AddWithValue("@Password", area.Password);
                    cmd.Parameters.AddWithValue("@URL", area.URL);
                    cmd.Parameters.AddWithValue("@Phone", area.Phone);
                    cmd.Parameters.AddWithValue("@Coments", area.Coments);
                    cmd.Parameters.AddWithValue("@DateCreate", area.DateCreate = System.DateTime.Now);

                    int res = cmd.ExecuteNonQuery();

                    if (res == 1)
                    {
                        msg = "Info about Website has inserted Successfuly!!!";
                    }
                    else
                    {
                        msg = "Something went wrong...";
                    }
                }
            }

            return(msg);
        }
Exemplo n.º 3
0
        public static string DeleteInfo(WorkArea d)
        {
            string msg = "";

            using (var conn = Connection.conn = new SqlConnection(Connection.connectstr))
            {
                conn.Open();
                using (var cmd = Connection.cmd = new SqlCommand($"delete from WorkAreas where id = {d.Id}", conn))
                {
                    int res = cmd.ExecuteNonQuery();

                    if (res == 1)
                    {
                        msg = $"info about - {d.SiteName} was delete successfuly";
                    }
                    else if (res == 0)
                    {
                        msg = $"info about - {d.SiteName} has NOT delete...";
                    }
                }
            }

            return(msg);
        }