示例#1
0
        public bool AddUser(string Email, string Name, string phone, int GroupId)
        {
            System.Data.DataView dv = GetUsers(string.Format("Email='{0}'", StringUtils.SQLEncode(Email)));
            if (dv.Count > 0)
            {
                AddUserToGroup((int)dv[0]["UserId"], GroupId);
                return(false);
            }
            NewsDs       _ds = new NewsDs();
            IDataAdapter adp = base.GetAdapter(cte.NewsleterUsersAdp);

            NewsDs.NewsletterUsersRow row = _ds.NewsletterUsers.NewNewsletterUsersRow();

            row.Name  = Name;
            row.Email = Email;
            row.Phone = phone;

            row.DateAdded = DateTime.Now;

            _ds.NewsletterUsers.AddNewsletterUsersRow(row);
            base.UpdateData(adp, _ds);

            AddUserToGroup(row.UserId, GroupId);

            return(true);
        }
示例#2
0
        public DataView GetUsers(string condition)
        {
            NewsDs       _ds = new NewsDs();
            IDataAdapter Adp = base.GetAdapter(cte.NewsleterUsersAdp);

            return(((NewsDs)base.FillData(Adp, _ds, condition)).NewsletterUsers.DefaultView);
        }
示例#3
0
        public DataView GetNews(string cond)
        {
            NewsDs       _ds = new NewsDs();
            IDataAdapter Adp = base.GetAdapter(cte.NewsAdp);

            return(((NewsDs)base.FillData(Adp, _ds, cond)).News.DefaultView);
        }
示例#4
0
        public void DeleteGroup(int GroupId)
        {
            NewsDs       _ds = new NewsDs();
            IDataAdapter adp = base.GetAdapter(cte.NewsletterGroupsAdp);

            NewsDs.NewsletterGroupsRow row = _ds.NewsletterGroups.NewNewsletterGroupsRow();

            row.GroupId = GroupId;
            _ds.NewsletterGroups.AddNewsletterGroupsRow(row);
            row.AcceptChanges();

            row.Delete();

            base.UpdateData(adp, _ds);
        }
示例#5
0
        public bool DeleteUser(int UserId)
        {
            NewsDs       _ds = new NewsDs();
            IDataAdapter adp = base.GetAdapter(cte.NewsleterUsersAdp);

            NewsDs.NewsletterUsersRow row = _ds.NewsletterUsers.NewNewsletterUsersRow();

            row.UserId = UserId;
            _ds.NewsletterUsers.AddNewsletterUsersRow(row);
            row.AcceptChanges();

            row.Delete();
            base.UpdateData(adp, _ds);
            return(true);
        }
示例#6
0
        public int AddGroup(string GroupName)
        {
            System.Data.DataView dv = GetGroups(string.Format("GroupName='{0}'", StringUtils.SQLEncode(GroupName)));
            if (dv.Count > 0)
            {
                return((int)dv[0]["GroupId"]);
            }
            NewsDs       _ds = new NewsDs();
            IDataAdapter adp = base.GetAdapter(cte.NewsletterGroupsAdp);

            NewsDs.NewsletterGroupsRow row = _ds.NewsletterGroups.NewNewsletterGroupsRow();
            row.GroupName = GroupName;

            _ds.NewsletterGroups.AddNewsletterGroupsRow(row);
            base.UpdateData(adp, _ds);
            return(row.GroupId);
        }
示例#7
0
        public void UpdateUser(int UserId, string Email, string Name, string Groups)
        {
            NewsDs       _ds = new NewsDs();
            IDataAdapter adp = base.GetAdapter(cte.NewsleterUsersAdp);

            NewsDs.NewsletterUsersRow row = _ds.NewsletterUsers.NewNewsletterUsersRow();

            row.UserId = UserId;
            _ds.NewsletterUsers.AddNewsletterUsersRow(row);
            row.AcceptChanges();

            row.Email = Email;
            row.Name  = Name;

            base.UpdateData(adp, _ds);

            UpdateUserGroups(row.UserId, Groups);
        }
示例#8
0
        public DataView GetNewsDateView(string cond)
        {
            NewsDs       _ds  = new NewsDs();
            IDataAdapter Adp  = base.GetAdapter(cte.NewsDateViewAdp);
            DataView     view = ((NewsDs)base.FillData(Adp, _ds, cond)).NewsDateView.DefaultView;

            view.Table.Columns.Add("MonthDate", DateTime.Now.GetType());

            foreach (DataRow row in view.Table.Rows)
            {
                row["MonthDate"] = DateTime.Parse(row["NewsMonth"].ToString());
            }

            view.Table.AcceptChanges();

            view.Sort = "MonthDate desc";

            return(view);
        }
示例#9
0
        public int AddNewsType(string Name, int ParentId)
        {
            NewsDs _ds = new NewsDs();

            IDataAdapter Adp = base.GetAdapter(cte.NewsTypesAdp);

            NewsDs.NewsTypesRow row = _ds.NewsTypes.NewNewsTypesRow();

            row.Name         = Name;
            row.UniqueName   = StringUtils.ToURL(Name);
            row.ParentId     = ParentId;
            row.DateCreated  = DateTime.Now;
            row.LastModified = DateTime.Now;

            _ds.NewsTypes.AddNewsTypesRow(row);
            base.UpdateData(Adp, _ds);

            return(row.TypeId);
        }
示例#10
0
        public bool DeleteNewsType(int TypeId)
        {
            DataRow newsType = this.GetNewsTypes(string.Format("TypeId={0}", TypeId))[0].Row;

            NewsDs _ds = new NewsDs();

            IDataAdapter Adp = base.GetAdapter(cte.NewsTypesAdp);

            NewsDs.NewsTypesRow row = _ds.NewsTypes.NewNewsTypesRow();

            row.TypeId = TypeId;
            _ds.NewsTypes.AddNewsTypesRow(row);

            row.AcceptChanges();

            row.Delete();
            base.UpdateData(Adp, _ds);

            return(true);
        }
示例#11
0
        public void UpdateNewsType(int TypeId, string Name)
        {
            NewsDs _ds = new NewsDs();

            DataRow newsType = this.GetNewsTypes(string.Format("TypeId={0}", TypeId))[0].Row;

            IDataAdapter Adp = base.GetAdapter(cte.NewsTypesAdp);

            NewsDs.NewsTypesRow row = _ds.NewsTypes.NewNewsTypesRow();

            row.TypeId = TypeId;
            _ds.NewsTypes.AddNewsTypesRow(row);

            row.AcceptChanges();

            row.Name       = Name;
            row.UniqueName = StringUtils.ToURL(Name);

            base.UpdateData(Adp, _ds);
        }
示例#12
0
        public bool AddUser(string Title, string FirstName, string LastName, string Company,
                            string Position, string Address, string City, string State, string ZipCode,
                            int Country, string Phone, string Email, string Former, string Year,
                            string Children, string School, string Aware,
                            int GroupId)
        {
            System.Data.DataView dv = GetUsers(string.Format("Email='{0}'", StringUtils.SQLEncode(Email)));
            if (dv.Count > 0)
            {
                return(false);
            }

            NewsDs       _ds = new NewsDs();
            IDataAdapter adp = base.GetAdapter(cte.NewsleterUsersAdp);

            NewsDs.NewsletterUsersRow row = _ds.NewsletterUsers.NewNewsletterUsersRow();

            /*row.Title = Title;
             * row.FirstName = FirstName;
             * row.LastName = LastName;
             * row.Company = Company;
             * row.Position = Position;
             * row.Phone = Phone;
             * row.Email = Email;
             * row.Former = Former;
             * row.Year = Year;
             * row.Children = Children;
             * row.School = Int32.Parse(School);
             * row.Aware = Aware;
             * row.GroupId = GroupId;
             */

            row.Email     = Email;
            row.DateAdded = DateTime.Now;

            _ds.NewsletterUsers.AddNewsletterUsersRow(row);
            base.UpdateData(adp, _ds);
            return(true);
        }
示例#13
0
        public bool UpdateNews(int newsId, string uniqueName, string title, string header, string content, string date,
                               int NewsType, short Language, byte Status, bool DeleteFile,
                               HttpPostedFile RelatedFile,
                               HttpPostedFile DefaultImage, bool autoResizePicture, bool deleteOldPicture,
                               int?Ranking, int?UserRating, int?Views, DateTime?publishDate)
        {
            NewsDs _ds = new NewsDs();

            DataRow news = this.GetNews(string.Format("NewsId={0}", newsId))[0].Row;

            string oldImage = NewsPicture(newsId);

            IDataAdapter Adp = base.GetAdapter(cte.NewsAdp);

            NewsDs.NewsRow row = _ds.News.NewNewsRow();

            row.NewsId = newsId;
            _ds.News.AddNewsRow(row);
            row.AcceptChanges();

            row.Title = title;

            if (String.IsNullOrEmpty(uniqueName) || (uniqueName == news["UniqueName"].ToString() && uniqueName == StringUtils.ToURL(news["Title"].ToString())))
            {
                uniqueName = StringUtils.ToURL(title);
            }

            row.UniqueName = uniqueName;
            row.Header     = header;
            row.NewsText   = content;
            if (date != null && date != "")
            {
                row.NewsDate = DateTime.Parse(date);
            }

            row.NewsType     = NewsType;
            row.NewsLanguage = Language;
            row.Status       = Status;
            row.NewsFile     = string.Format("{0}", news["NewsFile"]);
            row.DateModified = DateTime.Now;
            row.ModifierId   = WebContext.Profile.UserId;

            if (Ranking != null)
            {
                row.Ranking = Ranking.Value;
            }
            if (UserRating != null)
            {
                row.UserRating = UserRating.Value;
            }
            if (Views != null)
            {
                row.Views = Views.Value;
            }
            if (publishDate != null)
            {
                row.PublishDate = publishDate.Value;
            }

            base.UpdateData(Adp, _ds);

            string path = "";

            try
            {
                if (!StringUtils.IsNullOrWhiteSpace(oldImage) && title != news["Title"].ToString())
                {
                    path = WebContext.Server.MapPath("~/" + lw.CTE.Folders.NewsImages);

                    path = System.IO.Path.Combine(path, string.Format("News{0}", newsId));

                    path = Path.Combine(path, StringUtils.ToURL(title) + ".JPG");

                    File.Move(WebContext.Server.MapPath(oldImage), path);
                }
            }
            catch (Exception Ex)
            {
                ErrorContext.Add("default-picture", "Could not re-copy default picture. " + Ex.Message);
            }

            path = WebContext.Server.MapPath("~/");
            path = Path.Combine(path, Folders.NewsFile);

            DeleteFile = (DeleteFile || (RelatedFile != null && RelatedFile.ContentLength > 0)) &&
                         !StringUtils.IsNullOrWhiteSpace(news["NewsFile"]);

            if (DeleteFile)
            {
                string fileName = Path.Combine(path, news["NewsFile"].ToString());
                if (File.Exists(fileName))
                {
                    File.Delete(fileName);
                }

                row.NewsFile = "";
            }

            if (RelatedFile != null && RelatedFile.ContentLength > 0)
            {
                string ext = StringUtils.GetFileExtension(RelatedFile.FileName);

                string fileName = StringUtils.GetFriendlyFileName(RelatedFile.FileName);

                if (title.Trim() == "")
                {
                    row.Title = fileName;
                }

                fileName = string.Format("{0}_{1}.{2}",
                                         fileName, row.NewsId, ext);

                try
                {
                    if (!Directory.Exists(path))
                    {
                        Directory.CreateDirectory(path);
                    }
                    RelatedFile.SaveAs(Path.Combine(path, fileName));
                }
                catch (IOException ex)
                {
                    throw new Exception("IO ERROR, Could not save related news file: " + ex.Message);
                }
                catch (Exception ex1)
                {
                    throw ex1;
                }
                row.NewsFile = fileName;
            }

            if (row.NewsFile != string.Format("{0}", news["NewsFile"]))
            {
                base.UpdateData(Adp, _ds);
            }

            try
            {
                string sql = string.Format("Update News set UniqueName=N'{0}' where NewsId={1}",
                                           uniqueName, row.NewsId);
                DBUtils.ExecuteQuery(sql, cte.lib);
            }
            catch (Exception Ex)
            {
                ErrorContext.Add("unique-name", "cannot update unique name. " + Ex.Message);
            }

            if ((DefaultImage != null && DefaultImage.ContentLength > 0) || deleteOldPicture)
            {
                UpdateDefaultImage(row.NewsId, NewsType, DefaultImage, autoResizePicture, deleteOldPicture, row.UniqueName);
            }

            //Search.NewsSearch.UpdateIndex(row.NewsId);

            return(true);
        }
示例#14
0
        public int AddNews(string uniqueName, string title, string header, string content, string date,
                           int NewsType, short Language, byte Status,
                           HttpPostedFile RelatedFile,
                           HttpPostedFile DefaultImage, bool autoResizePicture, DateTime?publishDate)
        {
            NewsDs _ds = new NewsDs();

            IDataAdapter Adp = base.GetAdapter(cte.NewsAdp);

            NewsDs.NewsRow row = _ds.News.NewNewsRow();

            row.Title    = title;
            row.Header   = header;
            row.NewsText = content;
            if (date != null && date != "")
            {
                row.NewsDate = DateTime.Parse(date);
            }
            else
            {
                row.NewsDate = DateTime.Now;
            }

            if (String.IsNullOrEmpty(uniqueName))
            {
                uniqueName = StringUtils.ToURL(title);
            }

            row.NewsType     = NewsType;
            row.NewsLanguage = Language;
            row.Status       = Status;
            row.DateAdded    = DateTime.Now;
            row.DateModified = DateTime.Now;
            row.CreatorId    = WebContext.Profile.UserId;
            row.ModifierId   = WebContext.Profile.UserId;

            row.Views      = 0;
            row.Ranking    = 0;
            row.UserRating = 0;

            if (publishDate != null)
            {
                row.PublishDate = publishDate.Value;
            }
            else
            {
                row.PublishDate = DateTime.Now;
            }
            row.NewsFile    = "";
            row.ThumbImage  = "";
            row.LargeImage  = "";
            row.MediumImage = "";

            _ds.News.AddNewsRow(row);
            base.UpdateData(Adp, _ds);

            string path = WebContext.Server.MapPath("~/" + lw.CTE.Folders.NewsImages);

            path = System.IO.Path.Combine(path, string.Format("News{0}", row.NewsId));


            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }

            Directory.CreateDirectory(Path.Combine(path, "Original"));
            Directory.CreateDirectory(Path.Combine(path, "Large"));
            Directory.CreateDirectory(Path.Combine(path, "Thumb"));



            if (RelatedFile != null && RelatedFile.ContentLength > 0)
            {
                string ext = StringUtils.GetFileExtension(RelatedFile.FileName);

                string fileName = StringUtils.GetFriendlyFileName(RelatedFile.FileName);

                if (title.Trim() == "")
                {
                    row.Title = fileName;
                }

                path = WebContext.Server.MapPath("~/");
                path = Path.Combine(path, Folders.NewsFile);

                if (!Directory.Exists(path))
                {
                    Directory.CreateDirectory(path);
                }

                fileName = string.Format("{0}_{1}.{2}",
                                         fileName, row.NewsId, ext);

                try
                {
                    RelatedFile.SaveAs(Path.Combine(path, fileName));
                }
                catch (IOException ex)
                {
                    throw new Exception("IO ERROR, Could not save related news file: " + ex.Message);
                }
                catch (Exception ex1)
                {
                    throw ex1;
                }
                row.NewsFile = fileName;
                base.UpdateData(Adp, _ds);
            }

            try
            {
                string sql = string.Format("Update News set UniqueName=N'{0}' where NewsId={1}",
                                           uniqueName, row.NewsId);
                DBUtils.ExecuteQuery(sql, cte.lib);
            }
            catch (Exception Ex)
            {
                ErrorContext.Add("unique-name", "cannot update unique name. " + Ex.Message);
            }
            if (DefaultImage != null && DefaultImage.ContentLength > 0)
            {
                UpdateDefaultImage(row.NewsId, NewsType, DefaultImage, autoResizePicture, false, uniqueName);
            }

            // search need to be checked for the path cannot be value null

            ///		Search.NewsSearch.AddToIndex(row.NewsId);

            return(row.NewsId);
        }