Beispiel #1
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public bool Add(Maticsoft.Model.cccc.user model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into user(");
            strSql.Append("password,sex,age,heig,weight,beizhu)");
            strSql.Append(" values (");
            strSql.Append("@password,@sex,@age,@heig,@weight,@beizhu)");
            MySqlParameter[] parameters =
            {
                new MySqlParameter("@password", MySqlDbType.VarChar, 64),
                new MySqlParameter("@sex",      MySqlDbType.VarChar, 64),
                new MySqlParameter("@age",      MySqlDbType.Int32,   64),
                new MySqlParameter("@heig",     MySqlDbType.Int32,   64),
                new MySqlParameter("@weight",   MySqlDbType.Int32,   64),
                new MySqlParameter("@beizhu",   MySqlDbType.VarChar, 64)
            };
            parameters[0].Value = model.password;
            parameters[1].Value = model.sex;
            parameters[2].Value = model.age;
            parameters[3].Value = model.heig;
            parameters[4].Value = model.weight;
            parameters[5].Value = model.beizhu;

            int rows = DbHelperMySQL.ExecuteSql(strSql.ToString(), parameters);

            if (rows > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Beispiel #2
0
        public void btnSave_Click(object sender, EventArgs e)
        {
            string strErr = "";

            if (this.txtpassword.Text.Trim().Length == 0)
            {
                strErr += "password不能为空!\\n";
            }
            if (this.txtsex.Text.Trim().Length == 0)
            {
                strErr += "sex不能为空!\\n";
            }
            if (!PageValidate.IsNumber(txtage.Text))
            {
                strErr += "age格式错误!\\n";
            }
            if (!PageValidate.IsNumber(txtheig.Text))
            {
                strErr += "heig格式错误!\\n";
            }
            if (!PageValidate.IsNumber(txtweight.Text))
            {
                strErr += "weight格式错误!\\n";
            }
            if (this.txtbeizhu.Text.Trim().Length == 0)
            {
                strErr += "beizhu不能为空!\\n";
            }

            if (strErr != "")
            {
                MessageBox.Show(this, strErr);
                return;
            }
            int    username = int.Parse(this.lblusername.Text);
            string password = this.txtpassword.Text;
            string sex      = this.txtsex.Text;
            int    age      = int.Parse(this.txtage.Text);
            int    heig     = int.Parse(this.txtheig.Text);
            int    weight   = int.Parse(this.txtweight.Text);
            string beizhu   = this.txtbeizhu.Text;


            Maticsoft.Model.cccc.user model = new Maticsoft.Model.cccc.user();
            model.username = username;
            model.password = password;
            model.sex      = sex;
            model.age      = age;
            model.heig     = heig;
            model.weight   = weight;
            model.beizhu   = beizhu;

            Maticsoft.BLL.cccc.user bll = new Maticsoft.BLL.cccc.user();
            bll.Update(model);
            Maticsoft.Common.MessageBox.ShowAndRedirect(this, "保存成功!", "list.aspx");
        }
Beispiel #3
0
 private void ShowInfo(int username)
 {
     Maticsoft.BLL.cccc.user   bll   = new Maticsoft.BLL.cccc.user();
     Maticsoft.Model.cccc.user model = bll.GetModel(username);
     this.lblusername.Text = model.username.ToString();
     this.lblpassword.Text = model.password;
     this.lblsex.Text      = model.sex;
     this.lblage.Text      = model.age.ToString();
     this.lblheig.Text     = model.heig.ToString();
     this.lblweight.Text   = model.weight.ToString();
     this.lblbeizhu.Text   = model.beizhu;
 }
Beispiel #4
0
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(Maticsoft.Model.cccc.user model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update user set ");
            strSql.Append("password=@password,");
            strSql.Append("sex=@sex,");
            strSql.Append("age=@age,");
            strSql.Append("heig=@heig,");
            strSql.Append("weight=@weight,");
            strSql.Append("beizhu=@beizhu");
            strSql.Append(" where username=@username");
            MySqlParameter[] parameters =
            {
                new MySqlParameter("@password", MySqlDbType.VarChar, 64),
                new MySqlParameter("@sex",      MySqlDbType.VarChar, 64),
                new MySqlParameter("@age",      MySqlDbType.Int32,   64),
                new MySqlParameter("@heig",     MySqlDbType.Int32,   64),
                new MySqlParameter("@weight",   MySqlDbType.Int32,   64),
                new MySqlParameter("@beizhu",   MySqlDbType.VarChar, 64),
                new MySqlParameter("@username", MySqlDbType.Int32, 64)
            };
            parameters[0].Value = model.password;
            parameters[1].Value = model.sex;
            parameters[2].Value = model.age;
            parameters[3].Value = model.heig;
            parameters[4].Value = model.weight;
            parameters[5].Value = model.beizhu;
            parameters[6].Value = model.username;

            int rows = DbHelperMySQL.ExecuteSql(strSql.ToString(), parameters);

            if (rows > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Beispiel #5
0
 /// <summary>
 /// 得到一个对象实体
 /// </summary>
 public Maticsoft.Model.cccc.user DataRowToModel(DataRow row)
 {
     Maticsoft.Model.cccc.user model = new Maticsoft.Model.cccc.user();
     if (row != null)
     {
         if (row["username"] != null && row["username"].ToString() != "")
         {
             model.username = int.Parse(row["username"].ToString());
         }
         if (row["password"] != null)
         {
             model.password = row["password"].ToString();
         }
         if (row["sex"] != null)
         {
             model.sex = row["sex"].ToString();
         }
         if (row["age"] != null && row["age"].ToString() != "")
         {
             model.age = int.Parse(row["age"].ToString());
         }
         if (row["heig"] != null && row["heig"].ToString() != "")
         {
             model.heig = int.Parse(row["heig"].ToString());
         }
         if (row["weight"] != null && row["weight"].ToString() != "")
         {
             model.weight = int.Parse(row["weight"].ToString());
         }
         if (row["beizhu"] != null)
         {
             model.beizhu = row["beizhu"].ToString();
         }
     }
     return(model);
 }
Beispiel #6
0
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Maticsoft.Model.cccc.user GetModel(int username)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select username,password,sex,age,heig,weight,beizhu from user ");
            strSql.Append(" where username=@username");
            MySqlParameter[] parameters =
            {
                new MySqlParameter("@username", MySqlDbType.Int32)
            };
            parameters[0].Value = username;

            Maticsoft.Model.cccc.user model = new Maticsoft.Model.cccc.user();
            DataSet ds = DbHelperMySQL.Query(strSql.ToString(), parameters);

            if (ds.Tables[0].Rows.Count > 0)
            {
                return(DataRowToModel(ds.Tables[0].Rows[0]));
            }
            else
            {
                return(null);
            }
        }