PageRenderTime 83ms CodeModel.GetById 10ms app.highlight 64ms RepoModel.GetById 1ms app.codeStats 1ms

/projects/PigeonCms.Core/DAL/ItemsManager.cs

http://pigeoncms.googlecode.com/
C# | 1145 lines | 984 code | 87 blank | 74 comment | 185 complexity | 7bc6e56dfc93ad3922c892e828b46c28 MD5 | raw file

Large files files are truncated, but you can click here to view the full file

  1using System;
  2using System.Data;
  3using System.Configuration;
  4using System.Web;
  5using System.Web.Security;
  6using System.Web.UI;
  7using System.Web.UI.WebControls;
  8using System.Web.UI.WebControls.WebParts;
  9using System.Web.UI.HtmlControls;
 10using System.ComponentModel;
 11using System.Collections.Generic;
 12using System.IO;
 13using System.Data.Common;
 14using PigeonCms;
 15using System.Diagnostics;
 16
 17namespace PigeonCms
 18{
 19    public class ItemsManager<T, F> : TableManagerWithOrdering<T, F, int>, ITableManagerWithPermission
 20        where T: Item, new()
 21        where F: ItemsFilter, new()
 22    {
 23        public const string MaxItemsException = "1";
 24
 25        private bool checkUserContext = false;
 26        private bool writeMode = false;
 27
 28        public bool CheckUserContext
 29        {
 30            get { return checkUserContext; }
 31        }
 32
 33        public bool WriteMode
 34        {
 35            get { return writeMode; }
 36        }
 37
 38        /// <summary>
 39        /// CheckUserContext=false
 40        /// WriteMode=false
 41        /// </summary>
 42        [DebuggerStepThrough()]
 43        public ItemsManager(): this(false, false)
 44        { }
 45
 46        public ItemsManager(bool checkUserContext, bool writeMode)
 47        {
 48            this.TableName = "#__items";
 49            this.KeyFieldName = "Id";
 50            this.checkUserContext = checkUserContext;
 51            this.writeMode = writeMode;
 52            if (this.writeMode) this.checkUserContext = true;    //forced
 53        }
 54
 55        public override Dictionary<string, string> GetList()
 56        {
 57            Dictionary<string, string> res = new Dictionary<string, string>();
 58            F filter = new F();
 59            Category cat = new Category();
 60            List<T> list = GetByFilter(filter, "");
 61            foreach (T item in list)
 62            {
 63                string sectionTitle = "";
 64                string categoryTitle = "";
 65                cat = new CategoriesManager().GetByKey(item.CategoryId);
 66                categoryTitle = cat.Title;
 67                sectionTitle = new SectionsManager().GetByKey(cat.SectionId).Title;
 68                res.Add(item.Id.ToString(), sectionTitle + " > " + categoryTitle + " > " + item.Title);
 69            }
 70            return res;
 71        }
 72
 73        public override List<T> GetByFilter(F filter, string sort)
 74        {
 75            DbProviderFactory myProv = Database.ProviderFactory;
 76            DbConnection myConn = myProv.CreateConnection();
 77            DbDataReader myRd = null;
 78            DbCommand myCmd = myConn.CreateCommand();
 79            string sSql;
 80            List<T> result = new List<T>();
 81            var sectionsList = new List<Section>();
 82            var categoriesList = new List<Category>();
 83
 84            string topItems = "";
 85
 86            try
 87            {
 88                myConn.ConnectionString = Database.ConnString;
 89                myConn.Open();
 90                myCmd.Connection = myConn;
 91
 92                if (filter.NumOfRecords > 0)
 93                {
 94                    topItems = "TOP " + filter.NumOfRecords.ToString();
 95                }
 96
 97                sSql = "SELECT " + topItems + " t.Id, t.ItemType, t.CategoryId, categ.SectionId, "
 98                    + " t.Enabled, t.Alias, t.Ordering, t.DefaultImageName, "
 99                    + " t.[DateInserted], t.[UserInserted], t.[DateUpdated], t.[UserUpdated], "
100                    + " t.ItemDate, t.ValidFrom, t.ValidTo, "
101                    + " t.CustomBool1, t.CustomBool2, t.CustomBool3, "
102                    + " t.CustomDate1, t.CustomDate2, t.CustomDate3, "
103                    + " t.CustomDecimal1, t.CustomDecimal2, t.CustomDecimal3, "
104                    + " t.CustomInt1, t.CustomInt2, t.CustomInt3, "
105                    + " t.CustomString1, t.CustomString2, t.CustomString3, "
106                    + " t.ItemParams, t.AccessType, t.PermissionId, t.AccessCode, t.AccessLevel, "
107                    + " t.CommentsGroupId, t.WriteAccessType, t.WritePermissionId, t.WriteAccessCode, t.WriteAccessLevel, "
108                    + " t.ThreadId, "
109                    + " categ.AccessType categAccessType, categ.PermissionId categPermissionId, "
110                    + " categ.AccessCode categAccessCode, categ.AccessLevel categAccessLevel, "
111                    + " categ.WriteAccessType categWriteAccessType, categ.WritePermissionId categWritePermissionId, "
112                    + " categ.WriteAccessCode categWriteAccessCode, categ.WriteAccessLevel categWriteAccessLevel, "
113                    + " sect.AccessType sectAccessType, sect.PermissionId sectPermissionId, "
114                    + " sect.AccessCode sectAccessCode, sect.AccessLevel sectAccessLevel, "
115                    + " sect.WriteAccessType sectWriteAccessType, sect.WritePermissionId sectWritePermissionId, "
116                    + " sect.WriteAccessCode sectWriteAccessCode, sect.WriteAccessLevel sectWriteAccessLevel "
117                    + " FROM [" + this.TableName + "] t "
118                    + " LEFT JOIN [" + this.TableName + "_Culture] c ON t.Id = c.ItemId "
119                    + " LEFT JOIN #__categories categ ON t.CategoryId = categ.Id "
120                    + " LEFT JOIN #__sections sect ON categ.SectionId = sect.Id "
121                    + " WHERE t.Id > 0 ";
122                if (filter.ShowOnlyRootItems)
123                {
124                    //default
125                    sSql += " AND (t.ThreadId = t.Id) ";
126                }
127
128                if (filter.Id > 0 || filter.Id == -1)
129                {
130                    sSql += " AND t.Id = @Id ";
131                    myCmd.Parameters.Add(Database.Parameter(myProv, "Id", filter.Id));
132                }
133                if (!string.IsNullOrEmpty(filter.ItemType))
134                {
135                    sSql += " AND (t.ItemType = @ItemType) ";
136                    myCmd.Parameters.Add(Database.Parameter(myProv, "ItemType", filter.ItemType));
137                }
138                if (filter.CategoryId > 0 || filter.CategoryId == -1)
139                {
140                    sSql += " AND t.CategoryId = @CategoryId ";
141                    myCmd.Parameters.Add(Database.Parameter(myProv, "CategoryId", filter.CategoryId));
142                }
143                if (filter.SectionId > 0 || filter.SectionId == -1)
144                {
145                    sSql += " AND categ.SectionId = @SectionId ";
146                    myCmd.Parameters.Add(Database.Parameter(myProv, "SectionId", filter.SectionId));
147                }
148                if (!string.IsNullOrEmpty(filter.TitleSearch))
149                {
150                    sSql += " AND (c.Title like @TitleSearch) ";
151                    myCmd.Parameters.Add(Database.Parameter(myProv, "TitleSearch", "%" + filter.TitleSearch + "%"));
152                }
153                if (!string.IsNullOrEmpty(filter.Alias))
154                {
155                    sSql += " AND t.Alias = @Alias ";
156                    myCmd.Parameters.Add(Database.Parameter(myProv, "Alias", filter.Alias));
157                }
158                if (!string.IsNullOrEmpty(filter.DescriptionSearch))
159                {
160                    sSql += " AND (c.Description like @DescriptionSearch) ";
161                    myCmd.Parameters.Add(Database.Parameter(myProv, "DescriptionSearch", "%" + filter.DescriptionSearch + "%"));
162                }
163                if (!string.IsNullOrEmpty(filter.FullSearch))
164                {
165                    sSql += " AND (c.Title like @TitleSearch OR c.Description like @DescriptionSearch) ";
166                    myCmd.Parameters.Add(Database.Parameter(myProv, "TitleSearch", "%" + filter.FullSearch + "%"));
167                    myCmd.Parameters.Add(Database.Parameter(myProv, "DescriptionSearch", "%" + filter.FullSearch + "%"));
168                }
169                if (filter.Enabled != Utility.TristateBool.NotSet)
170                {
171                    sSql += " AND t.Enabled = @Enabled ";
172                    myCmd.Parameters.Add(Database.Parameter(myProv, "Enabled", filter.Enabled));
173                }
174                if (!string.IsNullOrEmpty(filter.AccessCode))
175                {
176                    sSql += " AND t.AccessCode = @AccessCode ";
177                    myCmd.Parameters.Add(Database.Parameter(myProv, "AccessCode", filter.AccessCode));
178                }
179                if (filter.AccessLevel > 0)
180                {
181                    sSql += " AND t.AccessLevel <= @AccessLevel ";
182                    myCmd.Parameters.Add(Database.Parameter(myProv, "AccessLevel", filter.AccessLevel));
183                }
184                if (!string.IsNullOrEmpty(filter.WriteAccessCode))
185                {
186                    sSql += " AND t.WriteAccessCode = @WriteAccessCode ";
187                    myCmd.Parameters.Add(Database.Parameter(myProv, "WriteAccessCode", filter.WriteAccessCode));
188                }
189                if (filter.WriteAccessLevel > 0)
190                {
191                    sSql += " AND t.WriteAccessLevel <= @WriteAccessLevel ";
192                    myCmd.Parameters.Add(Database.Parameter(myProv, "WriteAccessLevel", filter.WriteAccessLevel));
193                }
194                if (filter.ThreadId > 0 || filter.ThreadId == -1)
195                {
196                    sSql += " AND t.ThreadId = @ThreadId ";
197                    myCmd.Parameters.Add(Database.Parameter(myProv, "ThreadId", filter.ThreadId));                   
198                }
199
200                //datesrange filter
201                sSql += " AND ("
202                     + Database.AddDatesRangeParameters(myCmd.Parameters, myProv, "t.ItemDate", filter.ItemDateRange)
203                     + ")";
204
205                if (filter.IsValidItem != Utility.TristateBool.NotSet)
206                {
207                    DateTime getDate = DateTime.Now.Date;
208                    if (filter.IsValidItem == Utility.TristateBool.True)
209                    {
210                        sSql += " AND (t.ValidFrom <= @GetDate OR t.ValidFrom is null) ";
211                        sSql += " AND (t.ValidTo   >= @GetDate OR t.ValidTo   is null) ";
212                        myCmd.Parameters.Add(Database.Parameter(myProv, "GetDate", getDate));
213                    }
214                    else
215                    {
216                        sSql += " AND (t.ValidFrom >= @GetDate OR t.ValidTo <= @GetDate) ";
217                        myCmd.Parameters.Add(Database.Parameter(myProv, "GetDate", getDate));
218                    }
219                }
220
221                //custom fields
222                if (filter.CustomBool1 != Utility.TristateBool.NotSet)
223                {
224                    sSql += " AND t.CustomBool1 = @CustomBool1 ";
225                    myCmd.Parameters.Add(Database.Parameter(myProv, "CustomBool1", filter.CustomBool1));
226                }
227                if (filter.CustomBool2 != Utility.TristateBool.NotSet)
228                {
229                    sSql += " AND t.CustomBool2 = @CustomBool2 ";
230                    myCmd.Parameters.Add(Database.Parameter(myProv, "CustomBool2", filter.CustomBool2));
231                }
232                if (filter.CustomBool1 != Utility.TristateBool.NotSet)
233                {
234                    sSql += " AND t.CustomBool3 = @CustomBool3 ";
235                    myCmd.Parameters.Add(Database.Parameter(myProv, "CustomBool3", filter.CustomBool3));
236                }
237                if (filter.CustomInt1 > 0)
238                {
239                    sSql += " AND t.CustomInt1 = @CustomInt1 ";
240                    myCmd.Parameters.Add(Database.Parameter(myProv, "CustomInt1", filter.CustomInt1));
241                }
242                if (filter.CustomInt2 > 0)
243                {
244                    sSql += " AND t.CustomInt2 = @CustomInt2 ";
245                    myCmd.Parameters.Add(Database.Parameter(myProv, "CustomInt2", filter.CustomInt2));
246                }
247                if (filter.CustomInt3 > 0)
248                {
249                    sSql += " AND t.CustomInt3 = @CustomInt3 ";
250                    myCmd.Parameters.Add(Database.Parameter(myProv, "CustomInt3", filter.CustomInt3));
251                }
252                if (!string.IsNullOrEmpty(filter.CustomString1))
253                {
254                    sSql += " AND t.CustomString1 = @CustomString1 ";
255                    myCmd.Parameters.Add(Database.Parameter(myProv, "CustomString1", filter.CustomString1));
256                }
257                if (!string.IsNullOrEmpty(filter.CustomString2))
258                {
259                    sSql += " AND t.CustomString2 = @CustomString2 ";
260                    myCmd.Parameters.Add(Database.Parameter(myProv, "CustomString2", filter.CustomString2));
261                }
262                if (!string.IsNullOrEmpty(filter.CustomString3))
263                {
264                    sSql += " AND t.CustomString3 = @CustomString3 ";
265                    myCmd.Parameters.Add(Database.Parameter(myProv, "CustomString3", filter.CustomString3));
266                }
267
268                sSql += " GROUP BY t.Id, t.ItemType, t.CategoryId, categ.SectionId, "
269                    + " t.Enabled, t.Alias, t.Ordering, t.DefaultImageName, "
270                    + " t.[DateInserted], t.[UserInserted], t.[DateUpdated], t.[UserUpdated], "
271                    + " t.ItemDate, t.ValidFrom, t.ValidTo, "
272                    + " t.CustomBool1, t.CustomBool2, t.CustomBool3, "
273                    + " t.CustomDate1, t.CustomDate2, t.CustomDate3, "
274                    + " t.CustomDecimal1, t.CustomDecimal2, t.CustomDecimal3, "
275                    + " t.CustomInt1, t.CustomInt2, t.CustomInt3, "
276                    + " t.CustomString1, t.CustomString2, t.CustomString3, "
277                    + " t.ItemParams, t.AccessType, t.PermissionId, t.AccessCode, t.AccessLevel, "
278                    + " t.CommentsGroupId, t.WriteAccessType, t.WritePermissionId, t.WriteAccessCode, t.WriteAccessLevel, "
279                    + " t.ThreadId, "
280                    + " categ.AccessType, categ.PermissionId, "
281                    + " categ.AccessCode, categ.AccessLevel, "
282                    + " categ.WriteAccessType, categ.WritePermissionId, "
283                    + " categ.WriteAccessCode, categ.WriteAccessLevel, "
284                    + " sect.AccessType, sect.PermissionId, "
285                    + " sect.AccessCode, sect.AccessLevel, "
286                    + " sect.WriteAccessType, sect.WritePermissionId, "
287                    + " sect.WriteAccessCode, sect.WriteAccessLevel";
288                if (!string.IsNullOrEmpty(sort))
289                {
290                    sSql += " ORDER BY " + sort;
291                }
292                else
293                {
294                    sSql += " ORDER BY categ.SectionId, t.CategoryId, t.Ordering ";
295                    //sSql += " ORDER BY categ.SectionId, t.CategoryId, t.ThreadId, t.Ordering ";
296                }
297
298                myCmd.CommandText = Database.ParseSql(sSql);
299                myRd = myCmd.ExecuteReader();
300                while (myRd.Read())
301                {
302                    T item = new T();
303                    FillObject(item, myRd);
304                    result.Add(item);
305
306                    var sec = new Section();
307                    fillSection(sec, myRd);
308                    if (!sectionsList.Exists(
309                        delegate(Section s)
310                        {
311                            return s.Id == sec.Id;
312                        }))
313                        sectionsList.Add(sec);
314
315                    var cat = new Category();
316                    fillCategory(cat, myRd);
317                    if (!categoriesList.Exists(
318                        delegate(Category s)
319                        {
320                            return s.Id == cat.Id;
321                        }))
322                        categoriesList.Add(cat);
323                }
324                myRd.Close();
325
326                //(other loop to avoid multiple reader on same command)
327                foreach (T item in result)
328                {
329                    //load read roles
330                    if (item.ReadPermissionId > 0 && item.ReadAccessType != MenuAccesstype.Public)
331                        item.ReadRolenames = new PermissionProvider().GetPermissionRoles(item.ReadPermissionId);
332                    //load write roles
333                    if (item.WritePermissionId > 0 && item.WriteAccessType != MenuAccesstype.Public)
334                        item.WriteRolenames = new PermissionProvider().GetPermissionRoles(item.WritePermissionId);
335                }
336                if (this.CheckUserContext)
337                {
338                    result.RemoveAll(new PermissionProvider().IsItemNotAllowed);
339                    if (this.WriteMode)
340                        result.RemoveAll(new PermissionProvider().IsItemNotAllowedForWrite);
341
342                    //check parent sections
343                    loadSectionsRoles(sectionsList);
344                    sectionsList.RemoveAll(new PermissionProvider().IsItemNotAllowed);
345                    if (this.WriteMode)
346                        sectionsList.RemoveAll(new PermissionProvider().IsItemNotAllowedForWrite);
347                    //remove items for not allowed sections
348                    result.RemoveAll(new SectionPredicate(sectionsList).IsItemNotInSection);
349
350                    //check parent categories
351                    loadCategoriesRoles(categoriesList);
352                    categoriesList.RemoveAll(new PermissionProvider().IsItemNotAllowed);
353                    if (this.WriteMode)
354                        categoriesList.RemoveAll(new PermissionProvider().IsItemNotAllowedForWrite);
355                    //remove items for not allowed categories
356                    result.RemoveAll(new CategoryPredicate(categoriesList).IsItemNotInCategory);
357                }
358
359                //culture specifics
360                foreach (T item in result)
361                {
362                    getCultureSpecific(item, myRd, myCmd, myProv);
363                }
364
365            }
366            finally
367            {
368                myConn.Dispose();
369            }
370            return result;
371        }
372
373        public override T GetByKey(int id)
374        {
375            T result = new T();
376            List<T> resultList = new List<T>();
377            F filter = new F();
378            filter.Id = id==0 ? -1 : id;
379            resultList = GetByFilter(filter, "");
380            if (resultList.Count > 0)
381                result = resultList[0];
382            return result;
383        }
384
385        public override int Update(T theObj)
386        {
387            DbProviderFactory myProv = Database.ProviderFactory;
388            DbTransaction myTrans = null;
389            DbConnection myConn = myProv.CreateConnection();
390            DbCommand myCmd = myConn.CreateCommand();
391            string sSql;
392            int result = 0;
393
394            if (theObj.Ordering == 0)
395            {
396                theObj.Ordering = this.GetNextOrdering();
397            }
398            theObj.DateUpdated = DateTime.Now;
399            theObj.UserUpdated = PgnUserCurrent.UserName;
400            if (theObj.DateInserted == DateTime.MinValue)
401                theObj.DateInserted = DateTime.Now;
402            try
403            {
404                //fill ReadPermissionId and WritePermissionId before trans
405                new PermissionProvider().UpdatePermissionObj(theObj);
406
407                myConn.ConnectionString = Database.ConnString;
408                myConn.Open();
409                myCmd.Connection = myConn;
410
411                myTrans = myConn.BeginTransaction();
412                myCmd.Transaction = myTrans;
413
414                sSql = "UPDATE [" + this.TableName + "] "
415                + " SET ItemType=@ItemType, CategoryId=@CategoryId, Enabled=@Enabled, "
416                + " Alias=@Alias, Ordering=@Ordering, DefaultImageName=@DefaultImageName, "
417                + " [DateInserted]=@DateInserted, [UserInserted]=@UserInserted, "
418                + " [DateUpdated]=@DateUpdated, [UserUpdated]=@UserUpdated, "
419                + " ItemDate=@ItemDate, ValidFrom=@ValidFrom, ValidTo=@ValidTo, "
420                + " CustomBool1=@CustomBool1, CustomBool2=@CustomBool2, CustomBool3=@CustomBool3, "
421                + " CustomDate1=@CustomDate1, CustomDate2=@CustomDate2, CustomDate3=@CustomDate3, "
422                + " CustomDecimal1=@CustomDecimal1, CustomDecimal2=@CustomDecimal2, CustomDecimal3=@CustomDecimal3, "
423                + " CustomInt1=@CustomInt1, CustomInt2=@CustomInt2, CustomInt3=@CustomInt3, "
424                + " CustomString1=@CustomString1, CustomString2=@CustomString2, CustomString3=@CustomString3, "
425                + " [ItemParams]=@ItemParams, AccessType=@AccessType, PermissionId=@PermissionId, "
426                + " [AccessCode]=@AccessCode, AccessLevel=@AccessLevel, CommentsGroupId=@CommentsGroupId, "
427                + " WriteAccessType=@WriteAccessType, WritePermissionId=@WritePermissionId, [WriteAccessCode]=@WriteAccessCode, "
428                + " WriteAccessLevel=@WriteAccessLevel, ThreadId=@ThreadId "
429                + " WHERE Id = @Id";
430                myCmd.CommandText = Database.ParseSql(sSql);
431                myCmd.Parameters.Add(Database.Parameter(myProv, "Id", theObj.Id));
432                myCmd.Parameters.Add(Database.Parameter(myProv, "ItemType", theObj.ItemTypeName));
433                myCmd.Parameters.Add(Database.Parameter(myProv, "CategoryId", theObj.CategoryId));
434                myCmd.Parameters.Add(Database.Parameter(myProv, "Enabled", theObj.Enabled));
435                myCmd.Parameters.Add(Database.Parameter(myProv, "Alias", theObj.Alias));
436                myCmd.Parameters.Add(Database.Parameter(myProv, "Ordering", theObj.Ordering));
437                myCmd.Parameters.Add(Database.Parameter(myProv, "DefaultImageName", theObj.DefaultImageName));
438                myCmd.Parameters.Add(Database.Parameter(myProv, "DateInserted", theObj.DateInserted));
439                myCmd.Parameters.Add(Database.Parameter(myProv, "UserInserted", theObj.UserInserted));
440                myCmd.Parameters.Add(Database.Parameter(myProv, "DateUpdated", theObj.DateUpdated));
441                myCmd.Parameters.Add(Database.Parameter(myProv, "UserUpdated", theObj.UserUpdated));
442                if (theObj.ItemDate == DateTime.MinValue)
443                    myCmd.Parameters.Add(Database.Parameter(myProv, "ItemDate", DBNull.Value));
444                else
445                    myCmd.Parameters.Add(Database.Parameter(myProv, "ItemDate", theObj.ItemDate));
446
447                if (theObj.ValidFrom == DateTime.MinValue)
448                    myCmd.Parameters.Add(Database.Parameter(myProv, "ValidFrom", DBNull.Value));
449                else
450                    myCmd.Parameters.Add(Database.Parameter(myProv, "ValidFrom", theObj.ValidFrom));
451
452                if (theObj.ValidTo == DateTime.MinValue)
453                    myCmd.Parameters.Add(Database.Parameter(myProv, "ValidTo", DBNull.Value));
454                else
455                    myCmd.Parameters.Add(Database.Parameter(myProv, "ValidTo", theObj.ValidTo));
456
457                myCmd.Parameters.Add(Database.Parameter(myProv, "CustomBool1", theObj.CustomBool1));
458                myCmd.Parameters.Add(Database.Parameter(myProv, "CustomBool2", theObj.CustomBool2));
459                myCmd.Parameters.Add(Database.Parameter(myProv, "CustomBool3", theObj.CustomBool3));
460                if (theObj.CustomDate1 == DateTime.MinValue)
461                    myCmd.Parameters.Add(Database.Parameter(myProv, "CustomDate1", DBNull.Value));
462                else
463                    myCmd.Parameters.Add(Database.Parameter(myProv, "CustomDate1", theObj.CustomDate1));
464                if (theObj.CustomDate2 == DateTime.MinValue)
465                    myCmd.Parameters.Add(Database.Parameter(myProv, "CustomDate2", DBNull.Value));
466                else
467                    myCmd.Parameters.Add(Database.Parameter(myProv, "CustomDate2", theObj.CustomDate2));
468                if (theObj.CustomDate3 == DateTime.MinValue)
469                    myCmd.Parameters.Add(Database.Parameter(myProv, "CustomDate3", DBNull.Value));
470                else
471                    myCmd.Parameters.Add(Database.Parameter(myProv, "CustomDate3", theObj.CustomDate3));
472                myCmd.Parameters.Add(Database.Parameter(myProv, "CustomDecimal1", theObj.CustomDecimal1));
473                myCmd.Parameters.Add(Database.Parameter(myProv, "CustomDecimal2", theObj.CustomDecimal2));
474                myCmd.Parameters.Add(Database.Parameter(myProv, "CustomDecimal3", theObj.CustomDecimal3));
475                myCmd.Parameters.Add(Database.Parameter(myProv, "CustomInt1", theObj.CustomInt1));
476                myCmd.Parameters.Add(Database.Parameter(myProv, "CustomInt2", theObj.CustomInt2));
477                myCmd.Parameters.Add(Database.Parameter(myProv, "CustomInt3", theObj.CustomInt3));
478                myCmd.Parameters.Add(Database.Parameter(myProv, "CustomString1", theObj.CustomString1));
479                myCmd.Parameters.Add(Database.Parameter(myProv, "CustomString2", theObj.CustomString2));
480                myCmd.Parameters.Add(Database.Parameter(myProv, "CustomString3", theObj.CustomString3));
481                myCmd.Parameters.Add(Database.Parameter(myProv, "ItemParams", theObj.ItemParams));
482                //read permissions
483                myCmd.Parameters.Add(Database.Parameter(myProv, "AccessType", theObj.ReadAccessType));
484                myCmd.Parameters.Add(Database.Parameter(myProv, "PermissionId", theObj.ReadPermissionId));
485                myCmd.Parameters.Add(Database.Parameter(myProv, "AccessCode", theObj.ReadAccessCode));
486                myCmd.Parameters.Add(Database.Parameter(myProv, "AccessLevel", theObj.ReadAccessLevel));
487                //write permissions
488                myCmd.Parameters.Add(Database.Parameter(myProv, "WriteAccessType", theObj.WriteAccessType));
489                myCmd.Parameters.Add(Database.Parameter(myProv, "WritePermissionId", theObj.WritePermissionId));
490                myCmd.Parameters.Add(Database.Parameter(myProv, "WriteAccessCode", theObj.WriteAccessCode));
491                myCmd.Parameters.Add(Database.Parameter(myProv, "WriteAccessLevel", theObj.WriteAccessLevel));
492
493                myCmd.Parameters.Add(Database.Parameter(myProv, "CommentsGroupId", theObj.CommentsGroupId));
494                myCmd.Parameters.Add(Database.Parameter(myProv, "ThreadId", theObj.ThreadId));
495
496                result = myCmd.ExecuteNonQuery();
497                updateCultureText(theObj, myCmd, myProv);
498                myTrans.Commit();
499            }
500            catch (Exception e)
501            {
502                myTrans.Rollback();
503                throw e;
504            }
505            finally
506            {
507                myTrans.Dispose();
508                myConn.Dispose();
509            }
510            return result;
511        }
512
513        public override T Insert(T newObj)
514        {
515            DbProviderFactory myProv = Database.ProviderFactory;
516            DbTransaction myTrans = null;
517            DbConnection myConn = myProv.CreateConnection();
518            DbCommand myCmd = myConn.CreateCommand();
519            string sSql;
520            T result = new T();
521
522            if (!checkMaxItemsAllowed(newObj))
523                throw new CustomException(
524                    MaxItemsException, CustomExceptionSeverity.Info, CustomExceptionLogLevel.Log);
525
526            try
527            {
528                //create read/write permission
529                new PermissionProvider().CreatePermissionObj(newObj);
530
531                myConn.ConnectionString = Database.ConnString;
532                myConn.Open();
533                myCmd.Connection = myConn;
534
535                myTrans = myConn.BeginTransaction();
536                myCmd.Transaction = myTrans;
537
538                result = newObj;
539                result.Id = base.GetNextId();
540                if (result.ThreadId == 0)
541                    result.ThreadId = result.Id;
542                result.Ordering = base.GetNextOrdering();
543                result.DateInserted = DateTime.Now;
544                result.UserInserted = PgnUserCurrent.UserName;
545                result.DateUpdated = DateTime.Now;
546                result.UserUpdated = PgnUserCurrent.UserName;
547
548                sSql = "INSERT INTO [" + this.TableName + "](Id, ItemType, CategoryId, Enabled, "
549                + " Alias, Ordering, DefaultImageName, "
550                + " DateInserted, UserInserted, DateUpdated, UserUpdated, "
551                + " ItemDate, ValidFrom, ValidTo, "
552                + " CustomBool1, CustomBool2, CustomBool3, "
553                + " CustomDate1, CustomDate2, CustomDate3, "
554                + " CustomDecimal1, CustomDecimal2, CustomDecimal3, "
555                + " CustomInt1, CustomInt2, CustomInt3, "
556                + " CustomString1, CustomString2, CustomString3, "
557                + " ItemParams, AccessType, PermissionId, AccessCode, AccessLevel, CommentsGroupId, "
558                + " WriteAccessType, WritePermissionId, WriteAccessCode, WriteAccessLevel, "
559                + " ThreadId) "
560                + " VALUES(@Id, @ItemType, @CategoryId, @Enabled, "
561                + " @Alias, @Ordering, @DefaultImageName, "
562                + " @DateInserted, @UserInserted, @DateUpdated, @UserUpdated, "
563                + " @ItemDate, @ValidFrom, @ValidTo, "
564                + " @CustomBool1, @CustomBool2, @CustomBool3, "
565                + " @CustomDate1, @CustomDate2, @CustomDate3, "
566                + " @CustomDecimal1, @CustomDecimal2, @CustomDecimal3, "
567                + " @CustomInt1, @CustomInt2, @CustomInt3, "
568                + " @CustomString1, @CustomString2, @CustomString3, "
569                + " @ItemParams, @AccessType, @PermissionId, @AccessCode, @AccessLevel, @CommentsGroupId, "
570                + " @WriteAccessType, @WritePermissionId, @WriteAccessCode, @WriteAccessLevel, "
571                + " @ThreadId)";
572                myCmd.CommandText = Database.ParseSql(sSql);
573
574                myCmd.Parameters.Add(Database.Parameter(myProv, "Id", result.Id));
575                myCmd.Parameters.Add(Database.Parameter(myProv, "ItemType", result.ItemTypeName));
576                myCmd.Parameters.Add(Database.Parameter(myProv, "CategoryId", result.CategoryId));
577                myCmd.Parameters.Add(Database.Parameter(myProv, "Enabled", result.Enabled));
578                myCmd.Parameters.Add(Database.Parameter(myProv, "Alias", result.Alias));
579                myCmd.Parameters.Add(Database.Parameter(myProv, "Ordering", result.Ordering));
580                myCmd.Parameters.Add(Database.Parameter(myProv, "DefaultImageName", result.DefaultImageName));
581                myCmd.Parameters.Add(Database.Parameter(myProv, "DateInserted", result.DateInserted));
582                myCmd.Parameters.Add(Database.Parameter(myProv, "UserInserted", result.UserInserted));
583                myCmd.Parameters.Add(Database.Parameter(myProv, "DateUpdated", result.DateUpdated));
584                myCmd.Parameters.Add(Database.Parameter(myProv, "UserUpdated", result.UserUpdated));
585
586                if (result.ItemDate == DateTime.MinValue)
587                    myCmd.Parameters.Add(Database.Parameter(myProv, "ItemDate", DBNull.Value));
588                else
589                    myCmd.Parameters.Add(Database.Parameter(myProv, "ItemDate", result.ItemDate));
590
591                if (result.ValidFrom == DateTime.MinValue)
592                    myCmd.Parameters.Add(Database.Parameter(myProv, "ValidFrom", DBNull.Value));
593                else
594                    myCmd.Parameters.Add(Database.Parameter(myProv, "ValidFrom", result.ValidFrom));
595
596                if (result.ValidTo == DateTime.MinValue)
597                    myCmd.Parameters.Add(Database.Parameter(myProv, "ValidTo", DBNull.Value));
598                else
599                    myCmd.Parameters.Add(Database.Parameter(myProv, "ValidTo", result.ValidTo));
600
601                myCmd.Parameters.Add(Database.Parameter(myProv, "CustomBool1", result.CustomBool1));
602                myCmd.Parameters.Add(Database.Parameter(myProv, "CustomBool2", result.CustomBool2));
603                myCmd.Parameters.Add(Database.Parameter(myProv, "CustomBool3", result.CustomBool3));
604                if (result.CustomDate1 == DateTime.MinValue)
605                    myCmd.Parameters.Add(Database.Parameter(myProv, "CustomDate1", DBNull.Value));
606                else
607                    myCmd.Parameters.Add(Database.Parameter(myProv, "CustomDate1", result.CustomDate1));
608                if (result.CustomDate2 == DateTime.MinValue)
609                    myCmd.Parameters.Add(Database.Parameter(myProv, "CustomDate2", DBNull.Value));
610                else
611                    myCmd.Parameters.Add(Database.Parameter(myProv, "CustomDate2", result.CustomDate2));
612                if (result.CustomDate3 == DateTime.MinValue)
613                    myCmd.Parameters.Add(Database.Parameter(myProv, "CustomDate3", DBNull.Value));
614                else
615                    myCmd.Parameters.Add(Database.Parameter(myProv, "CustomDate3", result.CustomDate3));
616                myCmd.Parameters.Add(Database.Parameter(myProv, "CustomDecimal1", result.CustomDecimal1));
617                myCmd.Parameters.Add(Database.Parameter(myProv, "CustomDecimal2", result.CustomDecimal2));
618                myCmd.Parameters.Add(Database.Parameter(myProv, "CustomDecimal3", result.CustomDecimal3));
619                myCmd.Parameters.Add(Database.Parameter(myProv, "CustomInt1", result.CustomInt1));
620                myCmd.Parameters.Add(Database.Parameter(myProv, "CustomInt2", result.CustomInt2));
621                myCmd.Parameters.Add(Database.Parameter(myProv, "CustomInt3", result.CustomInt3));
622                myCmd.Parameters.Add(Database.Parameter(myProv, "CustomString1", result.CustomString1));
623                myCmd.Parameters.Add(Database.Parameter(myProv, "CustomString2", result.CustomString2));
624                myCmd.Parameters.Add(Database.Parameter(myProv, "CustomString3", result.CustomString3));
625                myCmd.Parameters.Add(Database.Parameter(myProv, "ItemParams", result.ItemParams));
626                //read permissions
627                myCmd.Parameters.Add(Database.Parameter(myProv, "AccessType", (int)result.ReadAccessType));
628                myCmd.Parameters.Add(Database.Parameter(myProv, "PermissionId", result.ReadPermissionId));
629                myCmd.Parameters.Add(Database.Parameter(myProv, "AccessCode", (string)result.ReadAccessCode));
630                myCmd.Parameters.Add(Database.Parameter(myProv, "AccessLevel", (int)result.ReadAccessLevel));
631                //write permissions
632                myCmd.Parameters.Add(Database.Parameter(myProv, "WriteAccessType", (int)result.WriteAccessType));
633                myCmd.Parameters.Add(Database.Parameter(myProv, "WritePermissionId", result.WritePermissionId));
634                myCmd.Parameters.Add(Database.Parameter(myProv, "WriteAccessCode", (string)result.WriteAccessCode));
635                myCmd.Parameters.Add(Database.Parameter(myProv, "WriteAccessLevel", (int)result.WriteAccessLevel));
636
637                myCmd.Parameters.Add(Database.Parameter(myProv, "CommentsGroupId", result.CommentsGroupId));
638                myCmd.Parameters.Add(Database.Parameter(myProv, "ThreadId", result.ThreadId));
639
640                myCmd.ExecuteNonQuery();
641                updateCultureText(result, myCmd, myProv);
642                myTrans.Commit();
643            }
644            catch (Exception e)
645            {
646                myTrans.Rollback();
647                throw e;
648            }
649            finally
650            {
651                myTrans.Dispose();
652                myConn.Dispose();
653            }
654            return result;
655        }
656
657        public override int DeleteById(int id)
658        {
659            DbProviderFactory myProv = Database.ProviderFactory;
660            DbConnection myConn = myProv.CreateConnection();
661            DbCommand myCmd = myProv.CreateCommand();
662            int res = 0;
663
664            try
665            {
666                T currObj = this.GetByKey(id);
667                var list = new List<Item>();
668
669                if (currObj.IsThreadRoot)
670                    list = currObj.ThreadList;
671                else
672                    list.Add(currObj);
673
674
675                myConn.ConnectionString = Database.ConnString;
676                myConn.Open();
677                myCmd.Connection = myConn;
678                foreach (var item in list)
679                {
680                    deleteObj(item, myProv, myConn, myCmd);
681                }
682            }
683            catch (Exception e)
684            {
685                throw e;
686            }
687            finally
688            {
689                myConn.Dispose();
690            }
691            return res;
692        }
693
694        private void deleteObj(Item currObj, 
695            DbProviderFactory myProv, DbConnection myConn, DbCommand myCmd)
696        {
697            string sSql;
698
699            currObj.DeleteImages();
700            currObj.DeleteFiles();
701            new PermissionProvider().RemovePermissionById(currObj.ReadPermissionId);
702            new PermissionProvider().RemovePermissionById(currObj.WritePermissionId);
703
704            //myTrans = myConn.BeginTransaction();
705            //myCmd.Transaction = myTrans;
706
707            sSql = "DELETE FROM [" + this.TableName + "] WHERE Id = @Id ";
708            myCmd.CommandText = Database.ParseSql(sSql);
709            myCmd.Parameters.Clear();
710            myCmd.Parameters.Add(Database.Parameter(myProv, "Id", currObj.Id));
711            myCmd.ExecuteNonQuery();
712
713            sSql = "DELETE FROM [" + this.TableName + "_Culture] WHERE ItemId = @ItemId ";
714            myCmd.CommandText = Database.ParseSql(sSql);
715            myCmd.Parameters.Clear();
716            myCmd.Parameters.Add(Database.Parameter(myProv, "ItemId", currObj.Id));
717            myCmd.ExecuteNonQuery();
718        }
719
720        private class SectionPredicate
721        {
722            private List<Section> list = null;
723            public SectionPredicate(List<Section> list)
724            {
725                this.list = list;
726            }
727
728            public bool IsItemNotInSection(T item)
729            {
730                foreach (var s in list)
731                    if (s.Id == item.SectionId) return false;
732                return true;
733            }
734        }
735
736        private void loadSectionsRoles(List<Section> list)
737        {
738            foreach (var item in list)
739            {
740                //load read roles
741                if (item.ReadPermissionId > 0 && item.ReadAccessType != MenuAccesstype.Public)
742                    item.ReadRolenames = new PermissionProvider().GetPermissionRoles(item.ReadPermissionId);
743                //load write roles
744                if (item.WritePermissionId > 0 && item.WriteAccessType != MenuAccesstype.Public)
745                    item.WriteRolenames = new PermissionProvider().GetPermissionRoles(item.WritePermissionId);
746            }
747        }
748
749        private class CategoryPredicate
750        {
751            private List<Category> list = null;
752            public CategoryPredicate(List<Category> list)
753            {
754                this.list = list;
755            }
756
757            public bool IsItemNotInCategory(T item)
758            {
759                foreach (var s in list)
760                    if (s.Id == item.CategoryId) return false;
761                return true;
762            }
763        }
764
765        private void loadCategoriesRoles(List<Category> list)
766        {
767            foreach (var item in list)
768            {
769                //load read roles
770                if (item.ReadPermissionId > 0 && item.ReadAccessType != MenuAccesstype.Public)
771                    item.ReadRolenames = new PermissionProvider().GetPermissionRoles(item.ReadPermissionId);
772                //load write roles
773                if (item.WritePermissionId > 0 && item.WriteAccessType != MenuAccesstype.Public)
774                    item.WriteRolenames = new PermissionProvider().GetPermissionRoles(item.WritePermissionId);
775            }
776        }
777
778        private void fillSection(Section result, DbDataReader myRd)
779        {
780            if (!Convert.IsDBNull(myRd["SectionId"]))
781                result.Id = (int)myRd["SectionId"];
782            //read permissions
783            if (!Convert.IsDBNull(myRd["SectAccessType"]))
784                result.ReadAccessType = (MenuAccesstype)int.Parse(myRd["SectAccessType"].ToString());
785            if (!Convert.IsDBNull(myRd["SectPermissionId"]))
786                result.ReadPermissionId = (int)myRd["SectPermissionId"];
787            if (!Convert.IsDBNull(myRd["SectAccessCode"]))
788                result.ReadAccessCode = (string)myRd["SectAccessCode"];
789            if (!Convert.IsDBNull(myRd["SectAccessLevel"]))
790                result.ReadAccessLevel = (int)myRd["SectAccessLevel"];
791            //write permissions
792            if (!Convert.IsDBNull(myRd["SectWriteAccessType"]))
793                result.WriteAccessType = (MenuAccesstype)int.Parse(myRd["SectWriteAccessType"].ToString());
794            if (!Convert.IsDBNull(myRd["SectWritePermissionId"]))
795                result.WritePermissionId = (int)myRd["SectWritePermissionId"];
796            if (!Convert.IsDBNull(myRd["SectWriteAccessCode"]))
797                result.WriteAccessCode = (string)myRd["SectWriteAccessCode"];
798            if (!Convert.IsDBNull(myRd["SectWriteAccessLevel"]))
799                result.WriteAccessLevel = (int)myRd["SectWriteAccessLevel"];
800        }
801
802        private void fillCategory(Category result, DbDataReader myRd)
803        {
804            if (!Convert.IsDBNull(myRd["CategoryId"]))
805                result.Id = (int)myRd["CategoryId"];
806            //read permissions
807            if (!Convert.IsDBNull(myRd["CategAccessType"]))
808                result.ReadAccessType = (MenuAccesstype)int.Parse(myRd["CategAccessType"].ToString());
809            if (!Convert.IsDBNull(myRd["CategPermissionId"]))
810                result.ReadPermissionId = (int)myRd["CategPermissionId"];
811            if (!Convert.IsDBNull(myRd["CategAccessCode"]))
812                result.ReadAccessCode = (string)myRd["CategAccessCode"];
813            if (!Convert.IsDBNull(myRd["CategAccessLevel"]))
814                result.ReadAccessLevel = (int)myRd["CategAccessLevel"];
815            //write permissions
816            if (!Convert.IsDBNull(myRd["CategWriteAccessType"]))
817                result.WriteAccessType = (MenuAccesstype)int.Parse(myRd["CategWriteAccessType"].ToString());
818            if (!Convert.IsDBNull(myRd["CategWritePermissionId"]))
819                result.WritePermissionId = (int)myRd["CategWritePermissionId"];
820            if (!Convert.IsDBNull(myRd["CategWriteAccessCode"]))
821                result.WriteAccessCode = (string)myRd["CategWriteAccessCode"];
822            if (!Convert.IsDBNull(myRd["CategWriteAccessLevel"]))
823                result.WriteAccessLevel = (int)myRd["CategWriteAccessLevel"];
824        }
825
826        protected override void FillObject(T result, DbDataReader myRd)
827        {
828            if (!Convert.IsDBNull(myRd["Id"]))
829                result.Id = (int)myRd["Id"];
830            if (!Convert.IsDBNull(myRd["ItemType"]))
831                result.ItemTypeName = (string)myRd["ItemType"];
832            if (!Convert.IsDBNull(myRd["CategoryId"]))
833                result.CategoryId = (int)myRd["CategoryId"];
834            if (!Convert.IsDBNull(myRd["SectionId"]))
835                result.SectionId = (int)myRd["SectionId"];
836            if (!Convert.IsDBNull(myRd["Enabled"]))
837                result.Enabled = (bool)myRd["Enabled"];
838            if (!Convert.IsDBNull(myRd["Ordering"]))
839                result.Ordering = (int)myRd["Ordering"];
840            if (!Convert.IsDBNull(myRd["Alias"]))
841                result.Alias = (string)myRd["Alias"];
842            if (!Convert.IsDBNull(myRd["DefaultImageName"]))
843                result.DefaultImageName = myRd["DefaultImageName"].ToString();
844            if (!Convert.IsDBNull(myRd["DateInserted"]))
845                result.DateInserted = (DateTime)myRd["DateInserted"];
846            if (!Convert.IsDBNull(myRd["UserInserted"]))
847                result.UserInserted = (string)myRd["UserInserted"];
848            if (!Convert.IsDBNull(myRd["DateUpdated"]))
849                result.DateUpdated = (DateTime)myRd["DateUpdated"];
850            if (!Convert.IsDBNull(myRd["UserUpdated"]))
851                result.UserUpdated = (string)myRd["UserUpdated"];
852            if (!Convert.IsDBNull(myRd["ItemDate"]))
853                result.ItemDate = (DateTime)myRd["ItemDate"];
854            if (!Convert.IsDBNull(myRd["ValidFrom"]))
855                result.ValidFrom = (DateTime)myRd["ValidFrom"];
856            if (!Convert.IsDBNull(myRd["ValidTo"]))
857                result.ValidTo = (DateTime)myRd["ValidTo"];
858
859            //custom fields
860            if (!Convert.IsDBNull(myRd["CustomBool1"]))
861                result.CustomBool1 = (bool)myRd["CustomBool1"];
862            if (!Convert.IsDBNull(myRd["CustomBool2"]))
863                result.CustomBool2 = (bool)myRd["CustomBool2"];
864            if (!Convert.IsDBNull(myRd["CustomBool3"]))
865                result.CustomBool3 = (bool)myRd["CustomBool3"];
866            if (!Convert.IsDBNull(myRd["CustomDate1"]))
867                result.CustomDate1 = (DateTime)myRd["CustomDate1"];
868            if (!Convert.IsDBNull(myRd["CustomDate2"]))
869                result.CustomDate2 = (DateTime)myRd["CustomDate2"];
870            if (!Convert.IsDBNull(myRd["CustomDate3"]))
871                result.CustomDate3 = (DateTime)myRd["CustomDate3"];
872            if (!Convert.IsDBNull(myRd["CustomDecimal1"]))
873                result.CustomDecimal1 = (decimal)myRd["CustomDecimal1"];
874            if (!Convert.IsDBNull(myRd["CustomDecimal2"]))
875                result.CustomDecimal2 = (decimal)myRd["CustomDecimal2"];
876            if (!Convert.IsDBNull(myRd["CustomDecimal3"]))
877                result.CustomDecimal3 = (decimal)myRd["CustomDecimal3"];
878            if (!Convert.IsDBNull(myRd["CustomInt1"]))
879                result.CustomInt1 = (int)myRd["CustomInt1"];
880            if (!Convert.IsDBNull(myRd["CustomInt2"]))
881                result.CustomInt2 = (int)myRd["CustomInt2"];
882            if (!Convert.IsDBNull(myRd["CustomInt3"]))
883                result.CustomInt3 = (int)myRd["CustomInt3"];
884            if (!Convert.IsDBNull(myRd["CustomString1"]))
885                result.CustomString1 = (string)myRd["CustomString1"];
886            if (!Convert.IsDBNull(myRd["CustomString2"]))
887                result.CustomString2 = (string)myRd["CustomString2"];
888            if (!Convert.IsDBNull(myRd["CustomString3"]))
889                result.CustomString3 = (string)myRd["CustomString3"];
890            if (!Convert.IsDBNull(myRd["ItemParams"]))
891                result.ItemParams = (string)myRd["ItemParams"];
892            //read permissions
893            if (!Convert.IsDBNull(myRd["AccessType"]))
894                result.ReadAccessType = (MenuAccesstype)int.Parse(myRd["AccessType"].ToString());
895            if (!Convert.IsDBNull(myRd["PermissionId"]))
896                result.ReadPermissionId = (int)myRd["PermissionId"];
897            if (!Convert.IsDBNull(myRd["AccessCode"]))
898                result.ReadAccessCode = (string)myRd["AccessCode"];
899            if (!Convert.IsDBNull(myRd["AccessLevel"]))
900                result.ReadAccessLevel = (int)myRd["AccessLevel"];
901            //write permissions
902            if (!Convert.IsDBNull(myRd["WriteAccessType"]))
903                result.WriteAccessType = (MenuAccesstype)int.Parse(myRd["WriteAccessType"].ToString());
904            if (!Convert.IsDBNull(myRd["WritePermissionId"]))
905                result.WritePermissionId = (int)myRd["WritePermissionId"];
906            if (!Convert.IsDBNull(myRd["WriteAccessCode"]))
907                result.WriteAccessCode = (string)myRd["WriteAccessCode"];
908            if (!Convert.IsDBNull(myRd["WriteAccessLevel"]))
909                result.WriteAccessLevel = (int)myRd["WriteAccessLevel"];
910
911            if (!Convert.IsDBNull(myRd["ThreadId"]))
912                result.ThreadId = (int)myRd["ThreadId"];
913        }
914
915        protected override int GetPreviousRecordInOrder(int ordering, int currentRecordId)
916        {
917            DbProviderFactory myProv = Database.ProviderFactory;
918            DbConnection myConn = myProv.CreateConnection();
919            DbDataReader myRd = null;
920            DbCommand myCmd = myConn.CreateCommand();
921            string sSql;
922            int result = currentRecordId;
923            var manCateg = new CategoriesManager();
924
925            try
926            {
927                var o1 = new PigeonCms.Item();
928                o1 = this.GetByKey(currentRecordId);
929                var cat1 = new PigeonCms.Category();
930                cat1 = manCateg.GetByKey(o1.CategoryId);
931
932                myConn.ConnectionString = Database.ConnString;
933                myConn.Open();
934                myCmd.Connection = myConn;
935
936                sSql = "SELECT TOP 1 t.Id "
937                + " FROM [" + this.TableName + "] t "
938                + " LEFT JOIN #__categories categ ON t.CategoryId = categ.Id "
939                + " WHERE t.Ordering < @Ordering  "
940                + " AND t.CategoryId = @CategoryId "
941                + " AND categ.SectionId = @SectionId "
942                + " ORDER BY t.Ordering DESC ";
943                myCmd.CommandText = Database.ParseSql(sSql);
944                myCmd.Parameters.Add(Database.Parameter(myProv, "Ordering", ordering));
945                myCmd.Parameters.Add(Database.Parameter(myProv, "CategoryId", o1.CategoryId));
946                myCmd.Parameters.Add(Database.Parameter(myProv, "SectionId", cat1.Sectio

Large files files are truncated, but you can click here to view the full file