Exemple #1
0
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Model.standard GetModel(int id)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select id, category_id, title, add_time  ");
            strSql.Append("  from td_standard ");
            strSql.Append(" where id=@id");
            SqlParameter[] parameters = {
                    new SqlParameter("@id", SqlDbType.Int,4)
            };
            parameters[0].Value = id;

            Model.standard model = new Model.standard();
            DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);

            if (ds.Tables[0].Rows.Count > 0)
            {
                if (ds.Tables[0].Rows[0]["id"].ToString() != "")
                {
                    model.id = int.Parse(ds.Tables[0].Rows[0]["id"].ToString());
                }
                if (ds.Tables[0].Rows[0]["category_id"].ToString() != "")
                {
                    model.category_id = int.Parse(ds.Tables[0].Rows[0]["category_id"].ToString());
                }
                model.title = ds.Tables[0].Rows[0]["title"].ToString();
                if (ds.Tables[0].Rows[0]["add_time"].ToString() != "")
                {
                    model.add_time = DateTime.Parse(ds.Tables[0].Rows[0]["add_time"].ToString());
                }

                DataSet ds1 = new DAL.standard_value().GetList("standard_id=" + id);
                List<Model.standard_value> lst = new List<Model.standard_value>();
                if (ds1.Tables[0] != null && ds1.Tables[0].Rows.Count > 0)
                {
                    Model.standard_value model_value;
                    foreach (DataRow dr in ds1.Tables[0].Rows)
                    {
                        model_value = new Model.standard_value();
                        if (dr["id"] != null && dr["id"].ToString() != "")
                        {
                            model_value.id = int.Parse(dr["id"].ToString());
                        }
                        if (dr["standard_id"] != null && dr["standard_id"].ToString() != "")
                        {
                            model_value.standard_id = int.Parse(dr["standard_id"].ToString());
                        }
                        if (dr["value"] != null && dr["value"].ToString() != "")
                        {
                            model_value.value = dr["value"].ToString();
                        }
                        if (dr["add_time"] != null && dr["add_time"].ToString() != "")
                        {
                            model_value.add_time = DateTime.Parse(dr["add_time"].ToString());
                        }

                        lst.Add(model_value);
                    }
                }

                if (lst.Count > 0)
                {
                    model.standard_values = lst;
                }
                else
                {
                    model.standard_values = null;
                }

                return model;
            }
            else
            {
                return null;
            }
        }
Exemple #2
0
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Model.standard GetModel(int id)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select id, category_id, title, add_time  ");
            strSql.Append("  from td_standard ");
            strSql.Append(" where id=@id");
            SqlParameter[] parameters =
            {
                new SqlParameter("@id", SqlDbType.Int, 4)
            };
            parameters[0].Value = id;


            Model.standard model = new Model.standard();
            DataSet        ds    = DbHelperSQL.Query(strSql.ToString(), parameters);

            if (ds.Tables[0].Rows.Count > 0)
            {
                if (ds.Tables[0].Rows[0]["id"].ToString() != "")
                {
                    model.id = int.Parse(ds.Tables[0].Rows[0]["id"].ToString());
                }
                if (ds.Tables[0].Rows[0]["category_id"].ToString() != "")
                {
                    model.category_id = int.Parse(ds.Tables[0].Rows[0]["category_id"].ToString());
                }
                model.title = ds.Tables[0].Rows[0]["title"].ToString();
                if (ds.Tables[0].Rows[0]["add_time"].ToString() != "")
                {
                    model.add_time = DateTime.Parse(ds.Tables[0].Rows[0]["add_time"].ToString());
                }


                DataSet ds1 = new DAL.standard_value().GetList("standard_id=" + id);
                List <Model.standard_value> lst = new List <Model.standard_value>();
                if (ds1.Tables[0] != null && ds1.Tables[0].Rows.Count > 0)
                {
                    Model.standard_value model_value;
                    foreach (DataRow dr in ds1.Tables[0].Rows)
                    {
                        model_value = new Model.standard_value();
                        if (dr["id"] != null && dr["id"].ToString() != "")
                        {
                            model_value.id = int.Parse(dr["id"].ToString());
                        }
                        if (dr["standard_id"] != null && dr["standard_id"].ToString() != "")
                        {
                            model_value.standard_id = int.Parse(dr["standard_id"].ToString());
                        }
                        if (dr["value"] != null && dr["value"].ToString() != "")
                        {
                            model_value.value = dr["value"].ToString();
                        }
                        if (dr["add_time"] != null && dr["add_time"].ToString() != "")
                        {
                            model_value.add_time = DateTime.Parse(dr["add_time"].ToString());
                        }

                        lst.Add(model_value);
                    }
                }

                if (lst.Count > 0)
                {
                    model.standard_values = lst;
                }
                else
                {
                    model.standard_values = null;
                }

                return(model);
            }
            else
            {
                return(null);
            }
        }