Ejemplo n.º 1
0
        //internal int Add(int UserID, CUSTOMRP.Model.SOURCEVIEWCOLUMN model)
        //{
        //    return dal.Add(UserID, model);
        //}

        //internal int AddColList(int UserID, int SVID, string[] columns)
        //{
        //    return dal.AddColList(UserID, SVID, columns);
        //}

        //internal bool Delete(int UserID, int SVCID)
        //{
        //    return dal.Delete(UserID, SVCID);
        //}

        //public bool DeleteForSourceView(int SVID)
        //{
        //    return dal.DeleteForSourceView(SVID);
        //}

        public void UpdateModelList(int UserID, CUSTOMRP.Model.SOURCEVIEWCOLUMN[] modelList)
        {
            if ((modelList == null) || (modelList.Length == 0))
            {
                return;
            }

            CUSTOMRP.Model.SOURCEVIEWCOLUMN[] currentlist = null;
            CUSTOMRP.Model.SOURCEVIEWCOLUMN   currentitem = null;


            CUSTOMRP.Model.SOURCEVIEWCOLUMN[] original = GetModelsForSourceView(UserID, modelList[0].SVID).ToArray();
            // prepare AuditLog object
            Model.AUDITLOG auditobj = modelList.GetAuditLogObject(original);
            auditobj.UserID     = UserID;
            auditobj.CreateDate = DateTime.Now;

            try
            {
                currentlist = GetModelsForSourceView(UserID, modelList[0].SVID).ToArray();
            }
            catch
            {
                currentlist = new CUSTOMRP.Model.SOURCEVIEWCOLUMN[0];
            }

            #region Delete non-existent columns

            foreach (CUSTOMRP.Model.SOURCEVIEWCOLUMN item in currentlist)
            {
                if (modelList.Where(x => x.COLUMNNAME == item.COLUMNNAME).Count() == 0)
                {
                    dal.Delete(UserID, item.ID);
                }
            }

            foreach (CUSTOMRP.Model.SOURCEVIEWCOLUMN item in modelList)
            {
                currentitem = currentlist.Where(x => x.COLUMNNAME == item.COLUMNNAME).FirstOrDefault();

                if (currentitem == null)
                {
                    dal.Add(UserID, item);
                }
                else
                {
                    currentitem.DISPLAYNAME = item.DISPLAYNAME;
                    currentitem.HIDDEN      = item.HIDDEN;
                    currentitem.DATA_TYPE   = item.DATA_TYPE;

                    dal.Update(UserID, currentitem);
                }
            }

            #endregion

            auditobj.MessageType = Model.AUDITLOG.Severity.Audit;
            auditobj.ModuleName  = "BLL.SOURCEVIEWCOLUMN.UpdateModelList";
            auditobj.Message     = String.Format(original.Length == 0 ? DAL.AppNum.AuditMessage.SourceViewColumnInsertSuccess : DAL.AppNum.AuditMessage.SourceViewColumnUpdateSuccess, modelList[0].SVID);

            DAL.AUDITLOG.Add(auditobj);
        }
Ejemplo n.º 2
0
        //v1.7.0 Ben 2017.08.21 - Above will no update Hidden as GetModelsForSourceView will not get hidden
        public void UpdateModelList(int UserID, CUSTOMRP.Model.SOURCEVIEWCOLUMN[] modelList, bool UpdateHidden)
        {
            if ((modelList == null) || (modelList.Length == 0))
            {
                return;
            }

            CUSTOMRP.Model.SOURCEVIEWCOLUMN[] currentlist = null;
            CUSTOMRP.Model.SOURCEVIEWCOLUMN   currentitem = null;


            CUSTOMRP.Model.SOURCEVIEWCOLUMN[] original = GetModelsForSourceView(UserID, modelList[0].SVID, UpdateHidden).ToArray();
            // prepare AuditLog object
            Model.AUDITLOG auditobj = modelList.GetAuditLogObject(original);
            auditobj.UserID     = UserID;
            auditobj.CreateDate = DateTime.Now;
            currentlist         = original;

            #region Delete non-existent columns
            foreach (CUSTOMRP.Model.SOURCEVIEWCOLUMN item in currentlist)
            {
                //if (modelList.Where(x => x.COLUMNNAME == item.COLUMNNAME && x.ID != -1).Count() == 0)
                if (modelList.Where(x => x.COLUMNNAME.ToUpper() == item.COLUMNNAME.ToUpper() && x.ID != -1).Count() == 0)
                {
                    dal.Delete(UserID, item.ID);
                    //v1.8.2 Ben 2018.02.22 - Same as below but even deleted record pass to Below seems not update/insert
                    var models = modelList.Where(x => x.COLUMNNAME.ToUpper() == item.COLUMNNAME.ToUpper() && x.ID != -1);
                    if (models.Any())
                    {
                        models.First().ID = -1;
                    }
                    item.ID = 0;
                }
            }
            #endregion

            #region Delete existing more than one columns
            foreach (CUSTOMRP.Model.SOURCEVIEWCOLUMN item in currentlist)
            {
                //v1.8.2 Ben 2018.02.26 - Prevent duplicate even just difeerent case
                //if (modelList.Where(x => x.COLUMNNAME == item.COLUMNNAME && x.ID != -1).Count() > 1)
                if (modelList.Where(x => x.COLUMNNAME.ToUpper() == item.COLUMNNAME.ToUpper() && x.ID != -1).Count() > 1)
                {
                    dal.Delete(UserID, item.ID);
                    //modelList.Where(x => x.COLUMNNAME == item.COLUMNNAME && x.ID != -1).First().ID = -1;
                    var models = modelList.Where(x => x.COLUMNNAME.ToUpper() == item.COLUMNNAME.ToUpper() && x.ID != -1);
                    if (models.Any())
                    {
                        models.First().ID = -1;
                    }
                    item.ID = 0;
                }
            }
            modelList = modelList.Where(x => x.ID != -1).ToArray();
            #endregion

            foreach (CUSTOMRP.Model.SOURCEVIEWCOLUMN item in modelList)
            {
                //currentitem = currentlist.Where(x => x.COLUMNNAME == item.COLUMNNAME).FirstOrDefault();
                //v1.8.2 Ben 2018.02.26 - Prevent duplicate even just difeerent case
                //currentitem = currentlist.Where(x => x.COLUMNNAME == item.COLUMNNAME).OrderByDescending(x => x.ID).FirstOrDefault();
                currentitem = currentlist.Where(x => x.COLUMNNAME.ToUpper() == item.COLUMNNAME.ToUpper()).OrderByDescending(x => x.ID).FirstOrDefault();

                if (currentitem == null || currentitem.ID == 0)
                {
                    dal.Add(UserID, item);
                }
                else
                {
                    //v1.8.2 Ben 2018.02.26 - Use actual case
                    currentitem.COLUMNNAME = item.COLUMNNAME;

                    currentitem.DISPLAYNAME = item.DISPLAYNAME;
                    currentitem.HIDDEN      = item.HIDDEN;
                    dal.Update(UserID, currentitem);
                }
            }

            auditobj.MessageType = Model.AUDITLOG.Severity.Audit;
            auditobj.ModuleName  = "BLL.SOURCEVIEWCOLUMN.UpdateModelList";
            auditobj.Message     = String.Format(original.Length == 0 ? DAL.AppNum.AuditMessage.SourceViewColumnInsertSuccess : DAL.AppNum.AuditMessage.SourceViewColumnUpdateSuccess, modelList[0].SVID);
            DAL.AUDITLOG.Add(auditobj);
        }