示例#1
0
        /// <summary>
        /// 将对象转换实体
        /// </summary>
        public Model.article_spec DataRowToModel(DataRow row)
        {
            Model.article_spec model = new Model.article_spec();
            if (row != null)
            {
                #region 主表信息======================
                //利用反射获得属性的所有公共属性
                Type modelType = model.GetType();
                for (int i = 0; i < row.Table.Columns.Count; i++)
                {
                    PropertyInfo proInfo = modelType.GetProperty(row.Table.Columns[i].ColumnName);
                    if (proInfo != null && row[i] != DBNull.Value)
                    {
                        //用索引值设置属性值
                        proInfo.SetValue(model, row[i], null);
                    }
                }
                #endregion

                #region 子表信息======================
                StringBuilder strSql1 = new StringBuilder();
                strSql1.Append("select * from " + databaseprefix + "article_spec");
                strSql1.Append(" where parent_id=@parent_id");
                SqlParameter[] parameters1 =
                {
                    new SqlParameter("@parent_id", SqlDbType.Int, 4)
                };
                parameters1[0].Value = model.id;
                DataTable dt1 = DbHelperSQL.Query(strSql1.ToString(), parameters1).Tables[0];

                if (dt1.Rows.Count > 0)
                {
                    int rowsCount = dt1.Rows.Count;
                    List <Model.article_spec_value> models = new List <Model.article_spec_value>();
                    Model.article_spec_value        modelt;
                    for (int n = 0; n < rowsCount; n++)
                    {
                        modelt = new Model.article_spec_value();
                        Type modeltType = modelt.GetType();
                        for (int i = 0; i < dt1.Rows[n].Table.Columns.Count; i++)
                        {
                            PropertyInfo proInfo = modeltType.GetProperty(dt1.Rows[n].Table.Columns[i].ColumnName);
                            if (proInfo != null && dt1.Rows[n][i] != DBNull.Value)
                            {
                                proInfo.SetValue(modelt, dt1.Rows[n][i], null);
                            }
                        }
                        models.Add(modelt);
                    }
                    model.values = models;
                }
                #endregion
            }
            return(model);
        }
示例#2
0
        private bool DoEdit(int _id)
        {
            bool result = false;

            BLL.article_spec   bll   = new BLL.article_spec();
            Model.article_spec model = bll.GetModel(_id);

            model.channel_id = this.channel_id;
            model.title      = txtTitle.Text.Trim();
            model.remark     = txtRemark.Text.Trim();
            model.sort_id    = Utils.StrToInt(txtSortId.Text.Trim(), 99);

            #region 保存规格选项
            string[] itemIdArr     = Request.Form.GetValues("item_id");
            string[] itemTitleArr  = Request.Form.GetValues("item_title");
            string[] itemImgUrlArr = Request.Form.GetValues("item_imgurl");
            string[] itemSortIdArr = Request.Form.GetValues("item_sortid");
            if (itemIdArr != null && itemTitleArr != null && itemImgUrlArr != null && itemSortIdArr != null)
            {
                if ((itemIdArr.Length == itemTitleArr.Length) && (itemTitleArr.Length == itemImgUrlArr.Length) && (itemImgUrlArr.Length == itemSortIdArr.Length))
                {
                    List <Model.article_spec_value> ls = new List <Model.article_spec_value>();
                    for (int i = 0; i < itemIdArr.Length; i++)
                    {
                        Model.article_spec_value modelt = new Model.article_spec_value();
                        modelt.id        = Utils.StrToInt(itemIdArr[i].Trim(), 0);
                        modelt.parent_id = model.id;
                        modelt.title     = itemTitleArr[i].Trim();
                        modelt.img_url   = itemImgUrlArr[i].Trim();
                        modelt.sort_id   = Utils.StrToInt(itemSortIdArr[i].Trim(), 99);
                        ls.Add(modelt);
                    }
                    model.values = ls;
                }
            }
            #endregion

            if (bll.Update(model))
            {
                AddAdminLog(DTEnums.ActionEnum.Edit.ToString(), "修改商品规格:" + model.title); //记录日志
                result = true;
            }
            return(result);
        }
示例#3
0
        private bool DoAdd()
        {
            bool result = false;
            Model.article_spec model = new Model.article_spec();
            BLL.article_spec bll = new BLL.article_spec();

            model.title = txtTitle.Text.Trim();
            model.remark = txtRemark.Text.Trim();
            model.sort_id = Utils.StrToInt(txtSortId.Text.Trim(), 99);

            #region 保存规格选项
            string[] itemIdArr = Request.Form.GetValues("item_id");
            string[] itemTitleArr = Request.Form.GetValues("item_title");
            string[] itemImgUrlArr = Request.Form.GetValues("item_imgurl");
            string[] itemSortIdArr = Request.Form.GetValues("item_sortid");
            if (itemIdArr != null && itemTitleArr != null && itemImgUrlArr != null && itemSortIdArr != null)
            {
                if ((itemIdArr.Length == itemTitleArr.Length) && (itemTitleArr.Length == itemImgUrlArr.Length) && (itemImgUrlArr.Length == itemSortIdArr.Length))
                {
                    List<Model.article_spec_value> ls = new List<Model.article_spec_value>();
                    for (int i = 0; i < itemIdArr.Length; i++)
                    {
                        Model.article_spec_value modelt = new Model.article_spec_value();
                        modelt.id = Utils.StrToInt(itemIdArr[i].Trim(), 0);
                        modelt.title = itemTitleArr[i].Trim();
                        modelt.img_url = itemImgUrlArr[i].Trim();
                        modelt.sort_id = Utils.StrToInt(itemSortIdArr[i].Trim(), 99);
                        ls.Add(modelt);
                    }
                    model.values = ls;
                }
            }
            #endregion

            if (bll.Add(model) > 0)
            {
                AddAdminLog(DTEnums.ActionEnum.Add.ToString(), "添加商品规格:" + model.title); //记录日志
                result = true;
            }
            return result;
        }
示例#4
0
		/// <summary>
		/// 得到一个对象实体
		/// </summary>
        public Model.article_spec DataRowToModel(DataRow row)
        {
            Model.article_spec model = new Model.article_spec();
            if (row != null)
            {
                #region 主表信息======================
                if (row["id"] != null && row["id"].ToString() != "")
                {
                    model.id = int.Parse(row["id"].ToString());
                }
                if (row["parent_id"] != null && row["parent_id"].ToString() != "")
                {
                    model.parent_id = int.Parse(row["parent_id"].ToString());
                }
                if (row["title"] != null)
                {
                    model.title = row["title"].ToString();
                }
                if (row["remark"] != null)
                {
                    model.remark = row["remark"].ToString();
                }
                if (row["sort_id"] != null && row["sort_id"].ToString() != "")
                {
                    model.sort_id = int.Parse(row["sort_id"].ToString());
                }
                #endregion

                #region 子表信息======================
                StringBuilder strSql2 = new StringBuilder();
                strSql2.Append("select id,parent_id,title,img_url,sort_id from " + databaseprefix + "article_spec");
                strSql2.Append(" where parent_id=@parent_id ");
                SqlParameter[] parameters2 = {
					    new SqlParameter("@parent_id", SqlDbType.Int,4)};
                parameters2[0].Value = model.id;
                DataSet ds2 = DbHelperSQL.Query(strSql2.ToString(), parameters2);

                if (ds2.Tables[0].Rows.Count > 0)
                {
                    List<Model.article_spec_value> ls = new List<Model.article_spec_value>();
                    for (int n = 0; n < ds2.Tables[0].Rows.Count; n++)
                    {
                        Model.article_spec_value modelt = new Model.article_spec_value();
                        if (ds2.Tables[0].Rows[n]["id"] != null && ds2.Tables[0].Rows[n]["id"].ToString() != "")
                        {
                            modelt.id = int.Parse(ds2.Tables[0].Rows[n]["id"].ToString());
                        }
                        if (ds2.Tables[0].Rows[n]["parent_id"] != null && ds2.Tables[0].Rows[n]["parent_id"].ToString() != "")
                        {
                            modelt.parent_id = int.Parse(ds2.Tables[0].Rows[n]["parent_id"].ToString());
                        }
                        if (ds2.Tables[0].Rows[n]["title"] != null)
                        {
                            modelt.title = ds2.Tables[0].Rows[n]["title"].ToString();
                        }
                        if (ds2.Tables[0].Rows[n]["img_url"] != null)
                        {
                            modelt.img_url = ds2.Tables[0].Rows[n]["img_url"].ToString();
                        }
                        if (ds2.Tables[0].Rows[n]["sort_id"] != null && ds2.Tables[0].Rows[n]["sort_id"].ToString() != "")
                        {
                            modelt.sort_id = int.Parse(ds2.Tables[0].Rows[n]["sort_id"].ToString());
                        }
                        ls.Add(modelt);
                    }
                    model.values = ls;
                }
                #endregion
            }
            return model;
        }
示例#5
0
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Model.article_spec DataRowToModel(DataRow row)
        {
            Model.article_spec model = new Model.article_spec();
            if (row != null)
            {
                #region 主表信息======================
                if (row["id"] != null && row["id"].ToString() != "")
                {
                    model.id = int.Parse(row["id"].ToString());
                }
                if (row["parent_id"] != null && row["parent_id"].ToString() != "")
                {
                    model.parent_id = int.Parse(row["parent_id"].ToString());
                }
                if (row["title"] != null)
                {
                    model.title = row["title"].ToString();
                }
                if (row["remark"] != null)
                {
                    model.remark = row["remark"].ToString();
                }
                if (row["sort_id"] != null && row["sort_id"].ToString() != "")
                {
                    model.sort_id = int.Parse(row["sort_id"].ToString());
                }
                #endregion

                #region 子表信息======================
                StringBuilder strSql2 = new StringBuilder();
                strSql2.Append("select id,parent_id,title,img_url,sort_id from " + databaseprefix + "article_spec");
                strSql2.Append(" where parent_id=@parent_id ");
                OleDbParameter[] parameters2 =
                {
                    new OleDbParameter("@parent_id", OleDbType.Integer, 4)
                };
                parameters2[0].Value = model.id;
                DataSet ds2 = DbHelperOleDb.Query(strSql2.ToString(), parameters2);

                if (ds2.Tables[0].Rows.Count > 0)
                {
                    List <Model.article_spec_value> ls = new List <Model.article_spec_value>();
                    for (int n = 0; n < ds2.Tables[0].Rows.Count; n++)
                    {
                        Model.article_spec_value modelt = new Model.article_spec_value();
                        if (ds2.Tables[0].Rows[n]["id"] != null && ds2.Tables[0].Rows[n]["id"].ToString() != "")
                        {
                            modelt.id = int.Parse(ds2.Tables[0].Rows[n]["id"].ToString());
                        }
                        if (ds2.Tables[0].Rows[n]["parent_id"] != null && ds2.Tables[0].Rows[n]["parent_id"].ToString() != "")
                        {
                            modelt.parent_id = int.Parse(ds2.Tables[0].Rows[n]["parent_id"].ToString());
                        }
                        if (ds2.Tables[0].Rows[n]["title"] != null)
                        {
                            modelt.title = ds2.Tables[0].Rows[n]["title"].ToString();
                        }
                        if (ds2.Tables[0].Rows[n]["img_url"] != null)
                        {
                            modelt.img_url = ds2.Tables[0].Rows[n]["img_url"].ToString();
                        }
                        if (ds2.Tables[0].Rows[n]["sort_id"] != null && ds2.Tables[0].Rows[n]["sort_id"].ToString() != "")
                        {
                            modelt.sort_id = int.Parse(ds2.Tables[0].Rows[n]["sort_id"].ToString());
                        }
                        ls.Add(modelt);
                    }
                    model.values = ls;
                }
                #endregion
            }
            return(model);
        }