/// <summary>
        /// 得到一个对象实体
        /// </summary>
        public DiaoYanXuanXiang_Model DataRowToModel(DataRow row)
        {
            DiaoYanXuanXiang_Model model = new DiaoYanXuanXiang_Model();

            if (row != null)
            {
                if (row["Id"] != null && row["Id"].ToString() != "")
                {
                    model.Id = new Guid(row["Id"].ToString());
                }
                if (row["Options"] != null)
                {
                    model.Options = row["Options"].ToString();
                }
                if (row["Numbers"] != null && row["Numbers"].ToString() != "")
                {
                    model.Numbers = int.Parse(row["Numbers"].ToString());
                }
                if (row["TiMuZhuJian"] != null && row["TiMuZhuJian"].ToString() != "")
                {
                    model.TiMuZhuJian = new Guid(row["TiMuZhuJian"].ToString());
                }
            }
            return(model);
        }
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(DiaoYanXuanXiang_Model model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update DiaoYanXuanXiang set ");
            if (model.Options != null)
            {
                strSql.Append("Options='" + model.Options + "',");
            }
            if (model.Numbers != null)
            {
                strSql.Append("Numbers=" + model.Numbers + ",");
            }
            if (model.TiMuZhuJian != null)
            {
                strSql.Append("TiMuZhuJian='" + model.TiMuZhuJian + "',");
            }
            int n = strSql.ToString().LastIndexOf(",");

            strSql.Remove(n, 1);
            strSql.Append(" where Id='" + model.Id + "' ");
            int rowsAffected = DbHelperSQL.ExecuteSql(strSql.ToString());

            if (rowsAffected > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
        /// <summary>
        ///     刷新数据
        /// </summary>
        private void RefreshData()
        {
            var diaoYanXuanXiangBll   = new DiaoYanXuanXiang_BLL();
            var diaoYanXuanXiangModel = new DiaoYanXuanXiang_Model();

            var diaoYanXuanXiangModels =
                diaoYanXuanXiangBll.GetModelList("TiMuZhuJian='" + TiMu + "'");

            Repeater1.DataSource = diaoYanXuanXiangModels;
            Repeater1.DataBind();
        }
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public bool Add(DiaoYanXuanXiang_Model model)
        {
            StringBuilder strSql  = new StringBuilder();
            StringBuilder strSql1 = new StringBuilder();
            StringBuilder strSql2 = new StringBuilder();

            if (model.Id != null)
            {
                strSql1.Append("Id,");
                strSql2.Append("'" + Guid.NewGuid().ToString() + "',");
            }
            if (model.Options != null)
            {
                strSql1.Append("Options,");
                strSql2.Append("'" + model.Options + "',");
            }
            if (model.Numbers != null)
            {
                strSql1.Append("Numbers,");
                strSql2.Append("" + model.Numbers + ",");
            }
            if (model.TiMuZhuJian != null)
            {
                strSql1.Append("TiMuZhuJian,");
                strSql2.Append("'" + model.TiMuZhuJian + "',");
            }
            strSql.Append("insert into DiaoYanXuanXiang(");
            strSql.Append(strSql1.ToString().Remove(strSql1.Length - 1));
            strSql.Append(")");
            strSql.Append(" values (");
            strSql.Append(strSql2.ToString().Remove(strSql2.Length - 1));
            strSql.Append(")");
            int rows = DbHelperSQL.ExecuteSql(strSql.ToString());

            if (rows > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public DiaoYanXuanXiang_Model GetModel(Guid Id)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select  top 1  ");
            strSql.Append(" Id,Options,Numbers,TiMuZhuJian ");
            strSql.Append(" from DiaoYanXuanXiang ");
            strSql.Append(" where Id='" + Id + "' ");
            DiaoYanXuanXiang_Model model = new DiaoYanXuanXiang_Model();
            DataSet ds = DbHelperSQL.Query(strSql.ToString());

            if (ds.Tables[0].Rows.Count > 0)
            {
                return(DataRowToModel(ds.Tables[0].Rows[0]));
            }
            else
            {
                return(null);
            }
        }
Exemplo n.º 6
0
        protected void Button1_Click1(object sender, EventArgs e)
        {
            var diaoYanXuanXiangBll   = new DiaoYanXuanXiang_BLL();
            var diaoYanXuanXiangModel = new DiaoYanXuanXiang_Model();

            diaoYanXuanXiangModel.Id          = Guid.NewGuid();
            diaoYanXuanXiangModel.Numbers     = 0;
            diaoYanXuanXiangModel.Options     = TextBox1.Text;
            diaoYanXuanXiangModel.TiMuZhuJian = new Guid(DropDownList1.SelectedValue);
            var result = diaoYanXuanXiangBll.Add(diaoYanXuanXiangModel);

            if (result)
            {
                Response.Write("添加成功");
            }
            else
            {
                Response.Write("添加失败,请重试");
            }

            TextBox1.Text = "";
        }
        /// <summary>
        ///     进行投票操作
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Button1_OnClick(object sender, EventArgs e)
        {
            var diaoYanXuanXiangBll   = new DiaoYanXuanXiang_BLL();
            var diaoYanXuanXiangModel = new DiaoYanXuanXiang_Model();
            // 获取当前选择的选项id进行查询提交数量,之后让后台加1
            var id = "";

            if (CheckBoxList1.SelectedItem != null)
            {
                id = CheckBoxList1.SelectedItem.Value;
            }

            if (string.IsNullOrEmpty(id))
            {
                Response.Write("请检查是否勾选了内容");
                return;
            }

            diaoYanXuanXiangModel         = diaoYanXuanXiangBll.GetModel(new Guid(id));
            diaoYanXuanXiangModel.Numbers = diaoYanXuanXiangModel.Numbers + 1;
            diaoYanXuanXiangBll.Update(diaoYanXuanXiangModel);
            RefreshData();
            GetDiaoYanList();
        }
 /// <summary>
 /// 更新一条数据
 /// </summary>
 public bool Update(DiaoYanXuanXiang_Model model)
 {
     return(dal.Update(model));
 }
 /// <summary>
 /// 增加一条数据
 /// </summary>
 public bool Add(DiaoYanXuanXiang_Model model)
 {
     return(dal.Add(model));
 }