Esempio n. 1
0
        /// <summary>
        /// 获取实体
        /// </summary>
        public Model.redpacket GetRedPacketModel(int id)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select TOP 1 [id],[channel_id],[title],[content],[market_price],[sell_price],[total_count],[start_date],[end_date],[add_time],[status],[is_top],[is_slide],[is_red],[sort_id],[remark1],[remark2],[img_url] ");
            strSql.Append(" ,(case when c.book_count is null  then '0' else  c.book_count end)  as book_count  ");
            strSql.Append(" FROM dt_redpacket a ");
            strSql.Append(" left join (select COUNT(*) as book_count ,redpacket_id  from dbo.dt_redpacket_guid  t group by t.redpacket_id) c  ");
            strSql.Append(" on a.id=c.redpacket_id ");
            strSql.Append(" where id=@id ");

            SqlParameter[] parameters = {
                    new SqlParameter("@id", SqlDbType.Int,4)};
            parameters[0].Value = id;

            Model.redpacket model = new Model.redpacket();
            DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);
            if (ds.Tables[0].Rows.Count > 0)
            {
                #region  DATA
                if (ds.Tables[0].Rows[0]["id"] != null && ds.Tables[0].Rows[0]["id"].ToString() != "")
                {
                    model.id = int.Parse(ds.Tables[0].Rows[0]["id"].ToString());
                }

                if (ds.Tables[0].Rows[0]["channel_id"] != null && ds.Tables[0].Rows[0]["channel_id"].ToString() != "")
                {
                    model.channel_id = int.Parse(ds.Tables[0].Rows[0]["channel_id"].ToString());
                }

                if (ds.Tables[0].Rows[0]["title"] != null && ds.Tables[0].Rows[0]["title"].ToString() != "")
                {
                    model.title = ds.Tables[0].Rows[0]["title"].ToString();
                }

                if (ds.Tables[0].Rows[0]["content"] != null && ds.Tables[0].Rows[0]["content"].ToString() != "")
                {
                    model.content = ds.Tables[0].Rows[0]["content"].ToString();
                }

                if (ds.Tables[0].Rows[0]["market_price"] != null && ds.Tables[0].Rows[0]["market_price"].ToString() != "")
                {
                    model.market_price = decimal.Parse(ds.Tables[0].Rows[0]["market_price"].ToString());
                }

                if (ds.Tables[0].Rows[0]["sell_price"] != null && ds.Tables[0].Rows[0]["sell_price"].ToString() != "")
                {
                    model.sell_price = decimal.Parse(ds.Tables[0].Rows[0]["sell_price"].ToString());
                }

                if (ds.Tables[0].Rows[0]["total_count"] != null && ds.Tables[0].Rows[0]["total_count"].ToString() != "")
                {
                    model.total_count = int.Parse(ds.Tables[0].Rows[0]["total_count"].ToString());
                }

                if (ds.Tables[0].Rows[0]["book_count"] != null && ds.Tables[0].Rows[0]["book_count"].ToString() != "")
                {
                    model.book_count = int.Parse(ds.Tables[0].Rows[0]["book_count"].ToString());
                }

                if (ds.Tables[0].Rows[0]["start_date"] != null && ds.Tables[0].Rows[0]["start_date"].ToString() != "")
                {
                    model.start_date = ds.Tables[0].Rows[0]["start_date"].ToString();
                }

                if (ds.Tables[0].Rows[0]["end_date"] != null && ds.Tables[0].Rows[0]["end_date"].ToString() != "")
                {
                    model.end_date = ds.Tables[0].Rows[0]["end_date"].ToString();
                }

                if (ds.Tables[0].Rows[0]["add_time"] != null && ds.Tables[0].Rows[0]["add_time"].ToString() != "")
                {
                    model.add_time = DateTime.Parse(ds.Tables[0].Rows[0]["add_time"].ToString());
                }

                if (ds.Tables[0].Rows[0]["status"] != null && ds.Tables[0].Rows[0]["status"].ToString() != "")
                {
                    model.status = int.Parse(ds.Tables[0].Rows[0]["status"].ToString());
                }

                if (ds.Tables[0].Rows[0]["is_top"] != null && ds.Tables[0].Rows[0]["is_top"].ToString() != "")
                {
                    model.is_top = int.Parse(ds.Tables[0].Rows[0]["is_top"].ToString());
                }

                if (ds.Tables[0].Rows[0]["is_slide"] != null && ds.Tables[0].Rows[0]["is_slide"].ToString() != "")
                {
                    model.is_slide = int.Parse(ds.Tables[0].Rows[0]["is_slide"].ToString());
                }

                if (ds.Tables[0].Rows[0]["is_red"] != null && ds.Tables[0].Rows[0]["is_red"].ToString() != "")
                {
                    model.is_red = int.Parse(ds.Tables[0].Rows[0]["is_red"].ToString());
                }

                if (ds.Tables[0].Rows[0]["sort_id"] != null && ds.Tables[0].Rows[0]["sort_id"].ToString() != "")
                {
                    model.sort_id = int.Parse(ds.Tables[0].Rows[0]["sort_id"].ToString());
                }

                if (ds.Tables[0].Rows[0]["remark1"] != null && ds.Tables[0].Rows[0]["remark1"].ToString() != "")
                {
                    model.remark1 = ds.Tables[0].Rows[0]["remark1"].ToString();
                }

                if (ds.Tables[0].Rows[0]["remark2"] != null && ds.Tables[0].Rows[0]["remark2"].ToString() != "")
                {
                    model.remark2 = int.Parse(ds.Tables[0].Rows[0]["remark2"].ToString());
                }

                if (ds.Tables[0].Rows[0]["img_url"] != null && ds.Tables[0].Rows[0]["img_url"].ToString() != "")
                {
                    model.img_url = ds.Tables[0].Rows[0]["img_url"].ToString();
                }

                #endregion
                model.albums = new article_albums().GetList(id);
                return model;
            }
            else
            {
                return null;
            }
        }
Esempio n. 2
0
        private bool DoAdd()
        {
            bool result = true;
            Model.redpacket model = new Model.redpacket();
            BLL.redpacket bll = new BLL.redpacket();

            model.channel_id = this.channel_id;
            model.title = txtTitle.Text.Trim();
            model.content = Utils.ToHtml(txtContent.Text);
            model.market_price = decimal.Parse(txtMarketPrice.Text);
            model.sell_price = decimal.Parse(txtSellPrice.Text);
            model.total_count = int.Parse(txtTotal.Text.Trim());
            model.book_count = 0;
            model.img_url =txtImgUrl.Text.Trim();
            model.start_date = txtStartDate.Text.Trim();
            model.end_date = txtEndDate.Text.Trim();
            model.status = string.IsNullOrEmpty(rdoStatus.SelectedValue) ? 0 : int.Parse(rdoStatus.SelectedValue);
            model.sort_id = int.Parse(txtSortId.Text.Trim());
            model.add_time = DateTime.Now;
            model.is_slide = 0;
            model.is_top = 0;
            model.is_red = 0;
            model.remark1 = "";
            model.remark2 = 0;
            if (cblItem.Items[0].Selected == true)
            {
                model.is_top = 1;
            }
            if (cblItem.Items[1].Selected == true)
            {
                model.is_red = 1;
            }

            model.albums = null;

            if (bll.Add(model) < 1)
            {
                result = false;
            }
            return result;
        }