示例#1
0
 /// <summary>
 /// 根据梦想Id获取梦想编辑信息
 /// </summary>
 /// <param name="id"></param>
 /// <returns></returns>
 public DreamInfoEditModel GetDreamInfoById(string id)
 {
     try
     {
         if (string.IsNullOrWhiteSpace(id))
         {
             throw new Exception("梦想Id不能为空!");
         }
         DreamInfoEditModel result = new DreamInfoEditModel();
         DataTable          dt     = _sql.Query("SELECT DreamCode,StartStage,EndStage,Type FROM DreamInfo WHERE IsDeleted = 0 AND DreamInfoId = @id", new Dictionary <string, object> {
             { "@id", id }
         });
         if (dt != null && dt.Rows.Count > 0)
         {
             result.DreamInfoId = id;
             result.DreamCode   = Cast.ConToString(dt.Rows[0]["DreamCode"]);
             result.StartStage  = Cast.ConToInt(dt.Rows[0]["StartStage"]);
             result.EndStage    = Cast.ConToInt(dt.Rows[0]["EndStage"]);
             result.Type        = Cast.ConToInt(dt.Rows[0]["Type"]);
         }
         return(result);
     }
     catch (Exception ex)
     {
         _log.Error(ex);
         throw ex;
     }
 }
示例#2
0
 /// <summary>
 /// 创建或更新菜单信息
 /// </summary>
 /// <param name="info">菜单编辑信息</param>
 /// <returns></returns>
 public string CreateOrUpdateMenuInfo(MenuInfoEditModel info)
 {
     try
     {
         if (string.IsNullOrWhiteSpace(info.MenuName))
         {
             throw new Exception("菜单名称不能为空!");
         }
         if (string.IsNullOrWhiteSpace(info.MenuCode))
         {
             throw new Exception("菜单编码不能为空!");
         }
         if (string.IsNullOrWhiteSpace(info.MenuPath))
         {
             throw new Exception("菜单路径不能为空!");
         }
         if (Cast.ConToInt(info.MenuSeq) == 0)
         {
             throw new Exception("菜单排序不能为空!");
         }
         _sql.OpenDb();
         string   result = string.Empty;
         MenuInfo main   = new MenuInfo();
         info.FillTableWithModel <MenuInfo>(main);
         if (!string.IsNullOrEmpty(info.MenuInfoId))
         {
             if (main.MenuInfoId == main.PMenuId)
             {
                 throw new Exception("上级菜单不能为当前菜单!");
             }
             _sql.Update(main);
             result = Constants.UpdateSuccessMssg;
         }
         else
         {
             DataTable dt = _sql.Query("SELECT MenuName FROM MenuInfo WHERE IsDeleted = 0 AND MenuCode = @code", new Dictionary <string, object> {
                 { "@code", info.MenuCode }
             });
             if (dt != null && dt.Rows.Count > 0)
             {
                 throw new Exception(string.Format("当前菜单【{0}:{1}】已存在!", info.MenuCode, Cast.ConToString(dt.Rows[0]["MenuName"])));
             }
             _sql.Create(main);
             result = Constants.CreateSuccessMssg;
         }
         return(result);
     }
     catch (Exception ex)
     {
         _log.Error(ex);
         throw ex;
     }
     finally
     {
         _sql.CloseDb();
     }
 }
示例#3
0
        /// <summary>
        /// 获取视频信息List
        /// </summary>
        /// <param name="searchList"></param>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="orderBy"></param>
        /// <param name="type">1-所有;2-最新;3-最热;4-我的;</param>
        /// <returns></returns>
        public VedioInfoListData GetVedioInfoList(List <SearchCondition> searchList, int pageIndex, int pageSize, string orderBy, int type)
        {
            try
            {
                VedioInfoListData result = new VedioInfoListData();

                #region 初始化数据
                string sqlString = @"SELECT * FROM VedioInfo WHERE IsDeleted = 0";
                Dictionary <string, object> paramList = new Dictionary <string, object>();
                switch (type)
                {
                case 4:
                    sqlString += " AND CreatedBy = @account";
                    paramList.Add("@account", _identity.UserAccount);
                    break;

                default:
                    sqlString += " AND IsPublic = 1";
                    break;
                }
                #endregion

                #region 条件过滤
                if (searchList != null && searchList.Count > 0)
                {
                    searchList.ForEach(s =>
                    {
                        switch (s.Type)
                        {
                        case Constants.COMMON_SEARCHCONDITIONTYPE_EQUAL:
                            sqlString += string.Concat(" AND ", s.Table, s.Key, " = @", s.Key);
                            paramList.Add(string.Concat("@", s.Key), s.Value);
                            break;

                        case Constants.COMMON_SEARCHCONDITIONTYPE_LIKE:
                            sqlString += string.Concat(" AND ", s.Table, s.Key, " like @", s.Key);
                            paramList.Add(string.Concat("@", s.Key), s.Value + "%");
                            break;

                        case Constants.COMMON_SEARCHCONDITIONTYPE_RANGE:
                            if (s.Key.ToLower().Contains("after"))
                            {
                                sqlString += string.Concat(" AND ", s.Table, s.Key.Replace("after", ""), " >= @", s.Key);
                                paramList.Add(string.Concat("@", s.Key), Cast.ConToInt(s.Value));
                            }
                            else if (s.Key.ToLower().Contains("before"))
                            {
                                sqlString += string.Concat(" AND ", s.Table, s.Key.Replace("before", ""), " <= @", s.Key);
                                paramList.Add(string.Concat("@", s.Key), Cast.ConToInt(s.Value));
                            }
                            else
                            {
                                throw new Exception("调用的参数错误,无法认定区间起始:" + s.Value);
                            }
                            break;

                        case Constants.COMMON_SEARCHCONDITIONTYPE_CUSTOMER:
                            break;
                        }
                    });
                }
                #endregion

                #region 查询数据
                int       recordCount = 0;
                DataTable dtResult    = _sql.Query(sqlString, paramList, orderBy, pageSize, pageIndex, out recordCount);
                #endregion

                #region 构建结果
                if (dtResult != null && dtResult.Rows.Count > 0)
                {
                    result.RecordCount = recordCount;
                    result.RecordList  = dtResult.ToModelList <VedioInfoListModel>();
                }
                #endregion

                return(result);
            }
            catch (Exception ex)
            {
                _log.Error(ex);
                throw;
            }
        }
示例#4
0
 /// <summary>
 /// 上传多个附件
 /// </summary>
 /// <param name="moduleType">模块类型</param>
 /// <param name="moduleId">模块Id</param>
 /// <param name="files">文件</param>
 /// <param name="fileDir">文件目录</param>
 /// <returns></returns>
 public List <Attachment> UploadFile(string moduleType, string moduleId, List <IFormFile> files, string fileDir = Constants.AttachmentPath)
 {
     try
     {
         if (files == null || files.Count == 0)
         {
             throw new FileNotFoundException("文件丢失");
         }
         string[] type = _config.Upload_Type == "*" ? null : _config.Upload_Type.Split(',');
         if (files.Count > Cast.ConToInt(_config.Upload_MaxCount))
         {
             throw new FileLoadException("每次最多上传" + _config.Upload_MaxCount + "个附件");
         }
         foreach (IFormFile file in files)
         {
             if (type != null && type.Length > 0 && !type.Contains(Path.GetExtension(file.FileName)))
             {
                 throw new FileFormatException("文件" + file.FileName + "类型不允许");
             }
             if (file.Length / 1024 > Cast.ConToInt(_config.Upload_MaxLength) * 1024)
             {
                 throw new FileLoadException("文件" + file.FileName + "超过" + _config.Upload_MaxLength + "M");
             }
         }
         fileDir = Path.Combine(Constants.ServerMapPath() + fileDir);
         if (!Directory.Exists(fileDir))
         {
             Directory.CreateDirectory(fileDir);
         }
         _sql.OpenDb();
         List <Attachment> result = new List <Attachment>();
         foreach (IFormFile file in files)
         {
             string   fileName   = DateTimeUtils.NowBeijing().ToString("yyyyMMdd") + "_" + moduleType + "_" + Guid.NewGuid();
             string[] array      = file.FileName.Split('.');
             string   fileSufFix = array[array.Length - 1];
             string   filePath   = Path.Combine(fileDir, fileName + "." + fileSufFix);
             using (FileStream fs = File.Create(filePath))
             {
                 file.CopyTo(fs);
                 fs.Flush();
             }
             Attachment attachment = new Attachment();
             attachment.FilePath     = filePath;
             attachment.FileName     = file.FileName;
             attachment.FileSize     = file.Length;
             attachment.MimeType     = file.ContentType;
             attachment.ModuleType   = moduleType;
             attachment.ModuleId     = moduleId;
             attachment.AttachmentId = _sql.Create(attachment);
             result.Add(attachment);
         }
         return(result);
     }
     catch (Exception ex)
     {
         _log.Error(ex);
         throw ex;
     }
     finally
     {
         _sql.CloseDb();
     }
 }
示例#5
0
        /// <summary>
        /// 获取梦想信息List
        /// </summary>
        /// <returns></returns>
        public DreamInfoListData GetDreamInfoList(List <SearchCondition> searchList, int pageIndex, int pageSize, string orderBy)
        {
            try
            {
                DreamInfoListData result = new DreamInfoListData();

                #region 初始化数据
                string sqlString = @"SELECT * FROM DreamInfo WHERE IsDeleted = 0 AND UserInfoId = @userId";
                Dictionary <string, object> paramList = new Dictionary <string, object> {
                    { "@userId", _identity.UserId }
                };
                #endregion

                #region 条件过滤
                if (searchList != null && searchList.Count > 0)
                {
                    searchList.ForEach(s =>
                    {
                        switch (s.Type)
                        {
                        case Constants.COMMON_SEARCHCONDITIONTYPE_EQUAL:
                            sqlString += string.Concat(" AND ", s.Table, s.Key, " = @", s.Key);
                            paramList.Add(string.Concat("@", s.Key), s.Value);
                            break;

                        case Constants.COMMON_SEARCHCONDITIONTYPE_LIKE:
                            sqlString += string.Concat(" AND ", s.Table, s.Key, " like @", s.Key);
                            paramList.Add(string.Concat("@", s.Key), s.Value + "%");
                            break;

                        case Constants.COMMON_SEARCHCONDITIONTYPE_RANGE:
                            if (s.Key.ToLower().Contains("after"))
                            {
                                sqlString += string.Concat(" AND ", s.Table, s.Key.Replace("after", ""), " >= @", s.Key);
                                paramList.Add(string.Concat("@", s.Key), Cast.ConToInt(s.Value));
                            }
                            else if (s.Key.ToLower().Contains("before"))
                            {
                                sqlString += string.Concat(" AND ", s.Table, s.Key.Replace("before", ""), " <= @", s.Key);
                                paramList.Add(string.Concat("@", s.Key), Cast.ConToInt(s.Value));
                            }
                            else
                            {
                                throw new Exception("调用的参数错误,无法认定区间起始:" + s.Value);
                            }
                            break;

                        case Constants.COMMON_SEARCHCONDITIONTYPE_CUSTOMER:
                            break;
                        }
                    });
                }
                #endregion

                #region 查询数据
                DataTable dtResult    = null;
                int       recordCount = 0;
                if (pageSize > 0 && pageIndex > 0)
                {
                    dtResult = _sql.Query(sqlString, paramList, orderBy, pageSize, pageIndex, out recordCount);
                }
                else
                {
                    sqlString += orderBy;
                    dtResult   = _sql.Query(sqlString, paramList);
                }
                #endregion

                #region 构建结果
                if (dtResult != null && dtResult.Rows.Count > 0)
                {
                    Dictionary <int, string> dic = new Dictionary <int, string>();
                    dic.Add(DreamInfoEnum.Type.DLT.GetHashCode(), "大乐透");
                    dic.Add(DreamInfoEnum.Type.PL3.GetHashCode(), "排列三");
                    dic.Add(DreamInfoEnum.Type.PL5.GetHashCode(), "排列五");
                    dtResult.Columns.Add("TypeText", typeof(string));
                    for (int i = 0; i < dtResult.Rows.Count; i++)
                    {
                        dtResult.Rows[i]["TypeText"] = dic[Cast.ConToInt(dtResult.Rows[i]["Type"])];
                    }
                    if (pageSize > 0 && pageIndex > 0)
                    {
                        result.RecordCount = recordCount;
                        result.RecordList  = dtResult.ToModelList <DreamInfoListModel>();
                    }
                    else
                    {
                        result.ExportBuffString = ExcelHelper.DownloadExcel(dtResult);
                        result.RecordCount      = dtResult.Rows.Count;
                    }
                }
                #endregion

                return(result);
            }
            catch (Exception ex)
            {
                _log.Error(ex);
                throw ex;
            }
        }