Ejemplo n.º 1
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);
        }
        public bool DeleteStandardDataType(int DataTypeID)
        {
            AutomationStandardsContext db = new AutomationStandardsContext();
            var DataTypes = db.StandardDataType.Where(d => d.DataTypeID == DataTypeID).ToList();

            if (DataTypes.Count > 0)
            {
                db.StandardDataType.Remove(DataTypes.First());

                try
                {
                    db.SaveChanges();
                    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);
                }
            }

            return(true);
        }
        public bool InsertStandardDataType(StandardDataTypeModel model)
        {
            AutomationStandardsContext db     = new AutomationStandardsContext();
            StandardDataType           Result = new StandardDataType();

            Result.DataTypeName = model.StandardDataTypeName;
            Result.SQLDataType  = model.SQLDataType;

            db.StandardDataType.Add(Result);

            try
            {
                db.SaveChanges();
                model.StandardDataTypeID = Result.DataTypeID;
                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);
            }
        }
        public bool UpdateStandardGroup(StandardGroupModel model)
        {
            AutomationStandardsContext db = new AutomationStandardsContext();
            StandardGroup Result          = db.StandardGroup.First(d => d.StandardGroupID == model.StandardGroupID);

            Result.StandardGroupName = model.StandardGroupName;

            try
            {
                db.SaveChanges();
                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);
            }
        }
        //public bool NotifyStandardOwner(string EntryType, FormCollection fc, List<StandardConfigModel> Configs, StandardModel StandardInfo, string CurrentUser)
        //{
        //    int StandardID = Convert.ToInt32(fc["StandardID"]);
        //    string RecordID = fc["ID"];

        //    string To, Subject, Body, Type;

        //    ActiveDirectoryUserInfo UserInfo = new ActiveDirectoryUserInfo(CurrentUser);

        //    To = StandardInfo.OwnerEmail;
        //    Subject = "OneClick Standard - " + StandardInfo.StandardName;
        //    Body = "";
        //    Type = "";

        //    #region Build Body
        //    switch (EntryType)
        //    {
        //        case "INSERT":
        //            Subject = Subject + " - New Standard Added";
        //            Type = "Inserted";
        //            Body = "A new standard has been added to <b>" + StandardInfo.StandardName + "</b>.  Below is the new standard added.<br><br><br>";

        //            Body += @"<table class=""details-table"" width=""80%""><tr><td class=""titles"" style=""font-family:Calibri,Arial;"">Field</td><td class=""titles"" style=""font-family:Calibri,Arial;"">New Value</td></tr>";

        //            foreach (var formKey in fc.Keys) //AllKeys)
        //            {
        //                List<StandardConfigModel> foundConfig = Configs.Where(c => c.FieldName == formKey).ToList();
        //                if (foundConfig.Count > 0)
        //                {
        //                    StandardConfigModel config = foundConfig.First();
        //                    string newValue;
        //                    if (config.AllowMultiSelect)
        //                    {
        //                        newValue = ";" + fc[config.FieldName].Replace(",", ";") + ";";
        //                    }
        //                    else
        //                    {
        //                        newValue = fc[config.FieldName];
        //                    }

        //                    Body += @"<tr><td class=""values"" style=""font-family:Calibri,Arial;"">" + config.DisplayName + @"</td><td class=""values"" style=""font-family:Calibri,Arial;"">" + newValue + "</td></tr>";
        //                }
        //            }
        //            Body += "</table>";

        //            break;

        //        case "UPDATE":

        //            DataRow OldData = GetStandardRow(StandardInfo.DBTableName, RecordID);

        //            Subject = Subject + " - Existing Standard Updated";
        //            Type = "Updated";
        //            Body = "An existing standard has been updated to <b>" + StandardInfo.StandardName + "</b>.  Below is the old and new standard values.<br><br><br>";

        //            Body += @"<table class=""details-table"" width=""80%""><tr><td class=""titles"" style=""font-family:Calibri,Arial;"">Field</td><td class=""titles"" style=""font-family:Calibri,Arial;"">Old Value</td><td class=""titles"" style=""font-family:Calibri,Arial;"">New Value</td></tr>";

        //            foreach (var formKey in fc.Keys) //AllKeys)
        //            {
        //                List<StandardConfigModel> foundConfig = Configs.Where(c => c.FieldName == formKey).ToList();
        //                if (foundConfig.Count > 0)
        //                {
        //                    StandardConfigModel config = foundConfig.First();

        //                    string newValue;
        //                    if (config.AllowMultiSelect)
        //                    {
        //                        newValue = ";" + fc[config.FieldName].Replace(",", ";") + ";";
        //                    }
        //                    else
        //                    {
        //                        newValue = fc[config.FieldName];
        //                    }

        //                    string OldValue = OldData[config.FieldName].ToString();

        //                    Body += @"<tr><td class=""values"" style=""font-family:Calibri,Arial;"">" + config.DisplayName + @"</td><td class=""values"" style=""font-family:Calibri,Arial;"">" + OldValue + @"</td><td class=""values"" style=""font-family:Calibri,Arial;"">" + newValue + "</td></tr>";
        //                }
        //            }
        //            Body += "</table>";



        //            break;

        //        case "DELETE":
        //            DataRow DeletedData = GetStandardRow(StandardInfo.DBTableName, RecordID);

        //            Subject = Subject + " - Standard Deleted";
        //            Type = "Deleted";
        //            Body = "A standard has been deleted from <b>" + StandardInfo.StandardName + "</b>.  Below is the standard that was deleted.<br><br><br>";

        //            Body += @"<table class=""details-table"" width=""80%""><tr><td class=""titles"" style=""font-family:Calibri,Arial;"">Field</td><td class=""titles"" style=""font-family:Calibri,Arial;"">Deleted Value</td></tr>";

        //            foreach (var config in Configs.OrderBy(c => c.SortOrder))
        //            {

        //                string DeletedValue = DeletedData[config.FieldName].ToString();

        //                Body += @"<tr><td class=""values"" style=""font-family:Calibri,Arial;"">" + config.DisplayName + @"</td><td class=""values"" style=""font-family:Calibri,Arial;"">" + DeletedValue + "</td></tr>";
        //            }
        //            Body += "</table>";

        //            break;
        //    }
        //    #endregion

        //    NotificationTemplateModel tempinfo = new NotificationTemplateModel().SelectSingleNotificationTemplateByName("Standard");

        //    Body = tempinfo.NotificationBody.Replace("{#NotificationBody#}", Body)
        //        .Replace("{#Type#}", Type)
        //        .Replace("{#ChangedBy#}", UserInfo.FirstName + " " + UserInfo.LastName)
        //        .Replace("{#StandardName#}", StandardInfo.StandardName)
        //        .Replace("{#RequestUrl#}", "http://util.obs.org/OneClick/Standard/Viewer/" + StandardInfo.StandardName);


        //    wsESEUtil.ESEUtilitySoapClient ws = new wsESEUtil.ESEUtilitySoapClient();
        //    bool result = ws.sendEmail(Subject, Body, To, true, "eseautomation", "", "", "", "");
        //    return result;
        //}

        public bool SetStandardVersionValue(int StandardID)
        {
            AutomationStandardsContext db = new AutomationStandardsContext();
            var Standards = db.Standard.Where(d => d.StandardID == StandardID).ToList();

            if (Standards.Count > 0)
            {
                Standard CurrentStandard = Standards.First();
                int      NewVersion      = CurrentStandard.VersionValue + 1;

                CurrentStandard.VersionValue = NewVersion;

                db.SaveChanges();
            }

            return(true);
        }
Ejemplo n.º 6
0
        public Standard SelectSingleStandardAsDbStandard(int StandardID)
        {
            AutomationStandardsContext db = new AutomationStandardsContext();
            StandardModel Result          = new StandardModel();

            //if (StandardID != 0)
            //{
            //    Result = (from d in db.Standard
            //                            where d.StandardID == StandardID
            //                            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
            //                            }).First();
            //}

            Standard CurrentStandard = db.Standard.First(s => s.StandardID == StandardID);

            CurrentStandard.UsageCount = CurrentStandard.UsageCount + 1;
            try
            {
                db.SaveChanges();
            }
            catch
            {
                string body = "";
                body += string.Format("Failed to increment usage counter for Standard: \"{0}\" ID: \"{1}\" ", CurrentStandard.DBTableName, StandardID);
                //GlobalFunctions gf = new //GlobalFunctions();
                //gf.SendErrorModelEmail(this.GetType().Name, body);
                return(CurrentStandard);
            }

            return(Result);
        }
Ejemplo n.º 7
0
        public bool SetStandardConfigSortOrder(int ConfigID, int SortOrder)
        {
            AutomationStandardsContext db = new AutomationStandardsContext();
            var ConfigInfo = (from f in db.StandardConfig
                              where f.StandardConfigID == ConfigID
                              select f).ToList();

            if (ConfigInfo.Count == 0)
            {
                return(false);
            }

            var Config = ConfigInfo.First();

            Config.SortOrder = SortOrder;

            try
            {
                db.SaveChanges();
            }
            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);
        }
Ejemplo n.º 8
0
        public bool UpdateStandard(StandardModel model)
        {
            AutomationStandardsContext db = new AutomationStandardsContext();
            Standard Result = db.Standard.First(d => d.StandardID == model.StandardID);

            Result.StandardName       = model.StandardName;
            Result.StandardGroupID    = model.StandardGroupID;
            Result.StandardDefinition = model.StandardDefinition;
            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;

            try
            {
                db.SaveChanges();
                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);
            }
        }
Ejemplo n.º 9
0
        public bool SetStandardVersion(int StandardID)
        {
            AutomationStandardsContext db = new AutomationStandardsContext();
            var Standards = db.Standard.Where(d => d.StandardID == StandardID).ToList();

            if (Standards.Count > 0)
            {
                Standard CurrentStandard = Standards.First();
                int      NewVersion      = CurrentStandard.VersionConfig + 1;

                CurrentStandard.VersionConfig = NewVersion;

                foreach (StandardConfig config in CurrentStandard.StandardConfig)
                {
                    config.VersionNumber = NewVersion;
                }

                db.SaveChanges();
            }


            return(true);
        }
Ejemplo n.º 10
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);
        }
Ejemplo n.º 11
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);
            }
        }
Ejemplo n.º 12
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);
            }
        }