コード例 #1
0
ファイル: DataCommand.cs プロジェクト: jason163/MS360
        /// <summary>
        /// 查询,返回条件页的实体列表
        /// 查询的SQL语句有两个,第一个返回总的数量,第二个返回数据结果集
        /// 查询条件可以使用参数,也可以自己定义拼装,注意拼装时,对参数值都使用SetSafeParameter(string parameterValue)处理一下。
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="filter"></param>
        /// <returns></returns>
        public QueryResult <T> Query <T>(QueryFilter filter, string defaultSortBy, Action <DataRow, T> manualMapper = null) where T : class, new()
        {
            DataSet ds    = _queryExecute(filter, defaultSortBy);
            int     count = int.Parse(ds.Tables[0].Rows[0][0].ToString());

            QueryResult <T> result = new QueryResult <T>();

            result.PageIndex    = filter.PageIndex;
            result.PageSize     = filter.PageSize;
            result.SortFields   = filter.SortFields;
            result.draw         = filter.draw;
            result.recordsTotal = count;

            if (ds.Tables[1] != null && ds.Tables[1].Rows != null && ds.Tables[1].Rows.Count > 0)
            {
                result.data = DataMapperHelper.GetEntityList <T, List <T> >(ds.Tables[1].Rows, true, true, manualMapper);
            }
            else
            {
                result.data = new List <T>();
            }

            if (ds.Tables.Count >= 3)
            {
                result.Summary = ds.Tables[2].Rows[0][0] != null ? ds.Tables[2].Rows[0][0].ToString().Trim() : "";
            }

            return(result);
        }
コード例 #2
0
ファイル: DataCommand.cs プロジェクト: jason163/MS360
 private void ConvertColumnFromRow(DataRow row, EnumColumnList enumColumns)
 {
     if (enumColumns != null && enumColumns.Count > 0)
     {
         foreach (var entry in enumColumns)
         {
             Type enumType = entry.EnumType;
             if (!enumType.IsEnum)
             {
                 throw new ArgumentException("The type '" + enumType.AssemblyQualifiedName + "' is not enum.", "enumColumns");
             }
             int columnIndex = entry.ColumnIndex.HasValue ? entry.ColumnIndex.Value : row.Table.Columns.IndexOf(entry.ColumnName + "_ECCentral_Auto_Removed_820319");
             if (columnIndex < 0)
             {
                 continue;
             }
             if (row[columnIndex] == null || row[columnIndex] == DBNull.Value)
             {
                 row[entry.NewColumnIndex] = DBNull.Value;
                 continue;
             }
             object orignalData = row[columnIndex];
             if (orignalData == null || orignalData == DBNull.Value || orignalData.ToString().Trim().Length <= 0)
             {
                 row[entry.NewColumnIndex] = DBNull.Value;
             }
             row[entry.NewColumnIndex] = DataMapperHelper.ConvertIfEnum(orignalData, enumType);
         }
     }
 }
コード例 #3
0
ファイル: OrderDA.cs プロジェクト: jason163/MS360
        public List <SODiscountMaster> GetSODiscountBySOSysNo(int sosysno)
        {
            IDataCommand cmd = IocManager.Instance.Resolve <IDataCommand>();

            cmd.CreateCommand("GetSODiscountBySOSysNo");

            //DataCommand cmd = new DataCommand("GetSODiscountBySOSysNo");
            cmd.SetParameter("@SOSysNo", DbType.Int32, sosysno);
            DataSet ds = cmd.ExecuteDataSet();
            List <SODiscountMaster> dmList = null;

            if (ds != null && ds.Tables.Count > 1)
            {
                dmList = DataMapperHelper.GetEntityList <SODiscountMaster, List <SODiscountMaster> >(ds.Tables[0].Rows);
                if (dmList != null && dmList.Count > 0)
                {
                    List <SODiscountDetail> ddList = DataMapperHelper.GetEntityList <SODiscountDetail, List <SODiscountDetail> >(ds.Tables[1].Rows);

                    foreach (var dm in dmList)
                    {
                        dm.Details = ddList.FindAll(dd => dd.MasterSysNo == dm.SysNo);
                    }
                }
            }
            return(dmList);
        }
コード例 #4
0
        public string GetCode(string Title)
        {
            var data   = KindCodeOperation.CodeData.Where(x => x.Title == Title).First();
            var result = DataMapperHelper.Map <CodeViewModel>(data);

            result.Kind = KindCodeOperation.Path_Kind(Title);
            return(JsonConvert.SerializeObject(result));
        }
コード例 #5
0
        //获取所有数据
        public IEnumerable <TModel> GetAll(string BmobTable)
        {
            var query = new BmobQuery();

            query.Limit(500);
            var future = Bmob.FindTaskAsync <TBmobModel>(BmobTable, query);
            var model  = DataMapperHelper.MapList <TModel>(future.Result.results);

            return(model);
        }
コード例 #6
0
ファイル: DataCommand.cs プロジェクト: jason163/MS360
        /// <summary>
        /// 执行返回对象列表
        /// </summary>
        /// <typeparam name="T">实体类型,必须是可无参实例化的class</typeparam>
        /// <param name="manualMapper">可以手动mapping</param>
        /// <returns></returns>
        public List <T> ExecuteEntityList <T>(Action <DataRow, T> manualMapper = null) where T : class, new()
        {
            DataTable dt = ExecuteDataTable();

            List <T> list = new List <T>();

            if (dt != null && dt.Rows.Count > 0)
            {
                list = DataMapperHelper.GetEntityList <T, List <T> >(dt.Rows, true, true, manualMapper);
            }
            return(list);
        }
コード例 #7
0
 /// <summary>
 /// 创建数据
 /// </summary>
 /// <param name="model"></param>
 /// <returns></returns>
 public string Create(TModel model)
 {
     try
     {
         TBmobModel Bmodel = DataMapperHelper.Map <TBmobModel>(model);
         var        future = Bmob.CreateTaskAsync(Bmodel);
         return(future.Result.objectId);
     }catch (Exception e)
     {
         return(null);
     }
 }
コード例 #8
0
ファイル: DataCommand.cs プロジェクト: jason163/MS360
        /// <summary>
        /// 执行返回一个实体对象,将第一行DataRow转换为实体
        /// </summary>
        /// <typeparam name="T">实体类型,必须是可无参实例化的class</typeparam>
        /// <param name="manualMapper">可以手动mapping</param>
        /// <returns></returns>
        public T ExecuteEntity <T>(Action <DataRow, T> manualMapper = null) where T : class, new()
        {
            DataRow dr = ExecuteDataRow();

            if (dr != null)
            {
                T t = DataMapperHelper.GetEntity <T>(dr, true, true, manualMapper);
                return(t);
            }
            else
            {
                return(null);
            }
        }
コード例 #9
0
 //修改字段
 public bool ModifyData(TModel model)
 {
     try
     {
         TBmobModel Bmodel = DataMapperHelper.Map <TBmobModel>(model);
         var        future = Bmob.UpdateTaskAsync <TBmobModel>(Bmodel);
         return(true);
     }
     catch (Exception e)
     {
         string message = e.Message;
         return(false);
     }
 }
コード例 #10
0
        //根据字段获取数据
        public IEnumerable <TModel> GetByNoId(string BmobTable, string Field, object Value)
        {
            var query = new BmobQuery();

            query.WhereEqualTo(Field, Value);
            var           future = Bmob.FindTaskAsync <TBmobModel>(BmobTable, query);
            List <TModel> model  = new List <TModel>();

            foreach (var data in future.Result.results)
            {
                model.Add(DataMapperHelper.Map <TModel>(data));
            }
            return(model);
        }
コード例 #11
0
 /// <summary>
 /// 获取代码给app
 /// </summary>
 /// <param name="title"></param>
 /// <returns></returns>
 public string GetCode(string title)
 {
     try
     {
         var data = KindCodeOperation.CodeData.Where(x => x.Title == title).First();
         data.Code = HttpUtility.UrlDecode(data.Code);
         data.Code = data.Code.Replace(" ", "\\b");
         var result = DataMapperHelper.Map <CodeViewModel>(data);
         result.Kind = KindCodeOperation.Path_Kind(title);
         return(JsonConvert.SerializeObject(result));
     }
     catch (Exception e)
     {
         return("您提交的数据标题为:" + title + "\n" + e.Message);
     }
 }
コード例 #12
0
ファイル: DataCommand.cs プロジェクト: jason163/MS360
        /// <summary>
        /// 执行返回第一行第一列的值,并自动转换为对应的类型,如果是泛型值且为空则会返回null
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <returns></returns>
        public T ExecuteScalar <T>()
        {
            object v = DataMapperHelper.ConvertIfEnum(ExecuteScalar(), typeof(T));

            return(DataConvertor.GetValue <T>(v, null, null));
        }
コード例 #13
0
        //根据id获取单个数据
        public TModel GetById(string BmobTable, string ObjectId)
        {
            var future = Bmob.GetTaskAsync <TBmobModel>(BmobTable, ObjectId);

            return(DataMapperHelper.Map <TModel>(future.Result));
        }