Exemplo n.º 1
0
        public List <StandardModel> SelectAllStandards()
        {
            AutomationStandardsContext db     = new AutomationStandardsContext();
            List <StandardModel>       Result = (from d in db.Standard
                                                 select new StandardModel
            {
                StandardID = d.StandardID,
                StandardName = d.StandardName,
                StandardDefinition = d.StandardDefinition,
                DBTableName = d.DBTableName,
                StandardGroupID = d.StandardGroupID,
                StandardGroupName = d.StandardGroup.StandardGroupName,
                ManageRoles = d.ManageRoles,
                ViewerRoles = d.ViewerRoles,
                VersionConfig = d.VersionConfig,
                VersionValue = d.VersionValue,
                Tags = d.Tags,
                NotifiyOwner = d.NotifiyOwner,
                OwnerEmail = d.OwnerEmail,
                UsageCount = d.UsageCount
            }).ToList();

            StandardSQLManagement sql = new StandardSQLManagement();

            foreach (StandardModel item in Result)
            {
                item.StandardCount = sql.GetStandardRowsCount(item.DBTableName);
            }

            return(Result);
        }
Exemplo n.º 2
0
        public bool DeleteStandard(int StandardID)
        {
            AutomationStandardsContext db = new AutomationStandardsContext();
            var Standards = db.Standard.Where(d => d.StandardID == StandardID).ToList();

            if (Standards.Count > 0)
            {
                var Configs = db.StandardConfig.Where(c => c.StandardID == StandardID).ToList();
                foreach (var Config in Configs)
                {
                    db.StandardConfig.Remove(Config);
                    db.SaveChanges();
                }

                db.Standard.Remove(Standards.First());



                try
                {
                    db.SaveChanges();

                    //DELETE TABLE
                    StandardSQLManagement sql = new StandardSQLManagement();
                    bool SQLOK = sql.DeleteStandardTable(Standards.First().DBTableName);

                    return(SQLOK);
                }
                catch (DbEntityValidationException ex)
                {
                    string body = "";
                    foreach (var eve in ex.EntityValidationErrors)
                    {
                        body += string.Format("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:", eve.Entry.Entity.GetType().Name, eve.Entry.State);
                        body += "<br>";
                        foreach (var ve in eve.ValidationErrors)
                        {
                            body += string.Format("- Property: \"{0}\", Error: \"{1}\"", ve.PropertyName, ve.ErrorMessage);
                        }
                    }

                    //GlobalFunctions gf = new //GlobalFunctions();
                    //gf.SendErrorModelEmail(this.GetType().Name, body);
                    return(false);
                }
            }

            return(true);
        }
Exemplo n.º 3
0
        public bool UpdateStandardConfig(StandardConfigModel model)
        {
            AutomationStandardsContext db     = new AutomationStandardsContext();
            StandardConfig             Result = db.StandardConfig.First(d => d.StandardConfigID == model.StandardConfigID);

            Standard st = db.Standard.First(x => x.StandardID == model.StandardID);

            Result.Standard = st;
            bool   RenameCol = false;
            string OldCol = "", NewCol = "", TableName = "";

            if (Result.FieldName != model.FieldName)
            {
                RenameCol = true;
                OldCol    = Result.FieldName;
                NewCol    = model.FieldName;
                TableName = Result.Standard.DBTableName;
            }

            Result.DisplayName = model.DisplayName;
            Result.FieldName   = model.FieldName;
            Result.SortOrder   = model.SortOrder;

            Result.VersionNumber     = model.VersionNumber;
            Result.UseToolTip        = model.UseToolTip;
            Result.ToolTip           = model.ToolTip;
            Result.UseStandardData   = model.UseStandardData;
            Result.AllowMultiSelect  = model.AllowMultiSelect;
            Result.StandardLUID      = model.StandardLUID;
            Result.StandardLUValue   = model.StandardLUValue;
            Result.StandardUseFilter = model.StandardUseFilter;
            Result.StandardFilterSQL = model.StandardFilterSQL;

            try
            {
                db.SaveChanges();

                if (RenameCol)
                {
                    StandardSQLManagement sql = new StandardSQLManagement();
                    bool SQLOK = sql.RenameColumn(TableName, OldCol, NewCol);
                    return(SQLOK);
                }

                SetStandardVersion(model.StandardID);

                return(true);
            }
            catch (DbEntityValidationException ex)
            {
                string body = "";
                foreach (var eve in ex.EntityValidationErrors)
                {
                    body += string.Format("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:", eve.Entry.Entity.GetType().Name, eve.Entry.State);
                    body += "<br>";
                    foreach (var ve in eve.ValidationErrors)
                    {
                        body += string.Format("- Property: \"{0}\", Error: \"{1}\"", ve.PropertyName, ve.ErrorMessage);
                    }
                }

                ////GlobalFunctions gf = new //GlobalFunctions();
                ////gf.SendErrorModelEmail(this.GetType().Name, body);
                return(false);
            }
        }
Exemplo n.º 4
0
        public bool InsertStandard(StandardModel model)
        {
            bool OkToCreate = false;
            AutomationStandardsContext db = new AutomationStandardsContext();
            var CurrentStds = (from s in db.Standard where s.DBTableName.ToLower() == model.DBTableName.ToLower() select s).ToList();

            if (CurrentStds.Count == 0)
            {
                OkToCreate = true;
            }


            if (OkToCreate)
            {
                Standard Result = new Standard();
                Result.StandardName       = model.StandardName;
                Result.DBTableName        = model.DBTableName;
                Result.StandardDefinition = model.StandardDefinition;
                Result.StandardGroupID    = model.StandardGroupID;
                Result.ManageRoles        = model.ManageRoles;
                Result.ViewerRoles        = model.ViewerRoles;
                Result.VersionConfig      = model.VersionConfig;
                Result.VersionValue       = model.VersionValue;
                Result.Tags         = model.Tags;
                Result.NotifiyOwner = model.NotifiyOwner;
                Result.OwnerEmail   = model.OwnerEmail;
                Result.UsageCount   = 0;

                db.Standard.Add(Result);

                try
                {
                    db.SaveChanges();
                    model.StandardID = Result.StandardID;

                    //Create Table in DB with MODEL Values
                    StandardSQLManagement sql = new StandardSQLManagement();
                    bool SQLOK = sql.CreateStandardTable(model.DBTableName);
                    return(SQLOK);
                }
                catch (DbEntityValidationException ex)
                {
                    string body = "";
                    foreach (var eve in ex.EntityValidationErrors)
                    {
                        body += string.Format("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:", eve.Entry.Entity.GetType().Name, eve.Entry.State);
                        body += "<br>";
                        foreach (var ve in eve.ValidationErrors)
                        {
                            body += string.Format("- Property: \"{0}\", Error: \"{1}\"", ve.PropertyName, ve.ErrorMessage);
                        }
                    }

                    //GlobalFunctions gf = new //GlobalFunctions();
                    //gf.SendErrorModelEmail(this.GetType().Name, body);
                    return(false);
                }
            }


            return(true);
        }
Exemplo n.º 5
0
        public bool InsertStandardConfig(StandardConfigModel model)
        {
            AutomationStandardsContext db     = new AutomationStandardsContext();
            StandardConfig             Result = new StandardConfig();

            Result.StandardID = model.StandardID;
            //Result.FieldName = model.FieldName;
            Result.FieldName         = model.DisplayName.Replace(" ", "");
            Result.DisplayName       = model.DisplayName;
            Result.DataTypeID        = model.DataTypeID;
            Result.SortOrder         = model.SortOrder;
            Result.VersionNumber     = model.VersionNumber;
            Result.UseToolTip        = model.UseToolTip;
            Result.ToolTip           = model.ToolTip;
            Result.UseStandardData   = model.UseStandardData;
            Result.AllowMultiSelect  = model.AllowMultiSelect;
            Result.StandardLUID      = model.StandardLUID;
            Result.StandardLUValue   = model.StandardLUValue;
            Result.StandardUseFilter = model.StandardUseFilter;
            Result.StandardFilterSQL = model.StandardFilterSQL;

            db.StandardConfig.Add(Result);

            try
            {
                db.SaveChanges();
                model.StandardConfigID = Result.StandardConfigID;

                //Add Column To the Table
                StandardSQLManagement sql = new StandardSQLManagement();

                var    Standard     = db.Standard.First(s => s.StandardID == model.StandardID);
                var    DBType       = db.StandardDataType.First(d => d.DataTypeID == model.DataTypeID);
                string DefaultValue = "";
                bool   AllowNull    = true;
                if (DBType.SQLDataType == "BIT")
                {
                    DefaultValue = "(0)";
                }

                sql.AddColumn(Standard.DBTableName, Result.FieldName, DBType.SQLDataType, DefaultValue, AllowNull);

                SetStandardVersion(model.StandardID);

                return(true);
            }
            catch (DbEntityValidationException ex)
            {
                string body = "";
                foreach (var eve in ex.EntityValidationErrors)
                {
                    body += string.Format("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:", eve.Entry.Entity.GetType().Name, eve.Entry.State);
                    body += "<br>";
                    foreach (var ve in eve.ValidationErrors)
                    {
                        body += string.Format("- Property: \"{0}\", Error: \"{1}\"", ve.PropertyName, ve.ErrorMessage);
                    }
                }

                ////GlobalFunctions gf = new //GlobalFunctions();
                ////gf.SendErrorModelEmail(this.GetType().Name, body);
                return(false);
            }
        }