Ejemplo n.º 1
0
    /// <summary>
    /// 添加各种选项
    /// </summary>
    /// <param name="articleId">文章ID</param>
    /// <param name="ops">一级选项名字,二级选项名字</param>
    /// <returns></returns>
    public static bool addOptions(int articleId, Dictionary <string, string> ops)
    {
        List <int> opsls = new List <int>();

        foreach (KeyValuePair <string, string> s in ops)
        {
            opsls.Add(LabelHelper.getOptionId(s.Key, s.Value));
        }
        try
        {
            using (var db = new PaperDbEntities())
            {
                //增加所有选项
                foreach (int id in opsls)
                {
                    TypeConnection tc = new TypeConnection();
                    tc.ArticleId = articleId;
                    tc.OptionId  = id;
                    db.TypeConnection.Add(tc);
                }
                db.SaveChanges();
                return(true);
            }
        }
        catch (Exception ex)
        {
            return(false);
        }
    }
Ejemplo n.º 2
0
 /// <summary>
 /// 删除文章类型选项记录
 /// </summary>
 /// <param name="typeConnId"></param>
 /// <returns></returns>
 public static bool delTypeConnection(List <int> typeConnId)
 {
     try
     {
         using (var db = new PaperDbEntities())
         {
             foreach (int id in typeConnId)
             {
                 TypeConnection kc = db.TypeConnection.Single(a => a.id == id);
                 db.TypeConnection.Remove(kc);
             }
             db.SaveChanges();
         }
         return(true);
     }
     catch (Exception ex)
     {
         return(false);
     }
 }
Ejemplo n.º 3
0
 /// <summary>
 /// 添加各种选项,通过给出optionId
 /// </summary>
 /// <param name="articleId"></param>
 /// <param name="opsId"></param>
 /// <returns></returns>
 public static bool addOptions(int articleId, List <int> opsId)
 {
     try
     {
         using (var db = new PaperDbEntities())
         {
             foreach (int i in opsId)
             {
                 TypeConnection tc = new TypeConnection();
                 tc.ArticleId = articleId;
                 tc.OptionId  = i;
                 db.TypeConnection.Add(tc);
             }
             db.SaveChanges();
         }
         return(true);
     }
     catch (Exception ex)
     {
         return(false);
     }
 }
Ejemplo n.º 4
0
 public void SetType(TypeConnection type, float valueBlend = 0.5f)
 {
     typeConnection = type;
     SetBlend(valueBlend);
 }
Ejemplo n.º 5
0
        /// <summary>
        /// Cria esse banco de dados se ele nao existir
        /// </summary>
        /// <param colName="nameOrConnectionString"></param>
        /// <param name="nameOrConnectionString"></param>
        /// <param name="typeConnection"></param>
        public DbContextIts(string nameOrConnectionString, TypeConnection typeConnection = TypeConnection.SqlServer)
        //tenta codificar a string de conexão ou usa a string original
            : base(nameOrConnectionString)
        {
            //impedir que o EF trunque os valores decimais > 2 casas
            SqlProviderServices.TruncateDecimalsToScale = false;

            this.IsDispose = false;

            //guarda a referencia da string
            this.NameOrConnectionString = nameOrConnectionString;

            if (this.NameOrConnectionString == null)
            {
                throw new Exception("Connection String not found");
            }
            Exception exception = null;

            try
            {
                this.Database.CreateIfNotExists();
                //avise q o banco deve ser dropado caso haja alteracao
                Database.SetInitializer <DbContextIts>
                    (new DropCreateDatabaseIfModelChanges <DbContextIts>());

                if (typeConnection == TypeConnection.SqlServer)
                {
                    try
                    {
                        //string conn = AppConfigManager.Configuration.ConnectionStringRuntime;
                        this.ConnectionSql = new ConnectionFactoryIts(NameOrConnectionString);
                    }
                    catch (Exception ex)
                    {
                        //dificilmente vai dar erro se conseguiu chegar ate aqui
                        exception = ex;
                    }
                }
                //others
            }

            catch (InvalidOperationException ex)
            {
                exception = ex;
            }

            catch (Exception ex)
            {
                exception = ex;
            }

            if (exception != null)
            {
                XMessageIts.ExceptionJustMessage(exception, null, "Falha na inicialização do controle do Sistema");
                LoggerUtilIts.GenerateLogs(exception);
                if (exception.GetType() != typeof(SqlException))
                {
                    Application.Exit();
                    Environment.Exit(0);
                }
            }
        }