Exemplo n.º 1
0
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(Maticsoft.Model.Customer model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update Customer set ");
            if (model.cusName != null)
            {
                strSql.Append("cusName='" + model.cusName + "',");
            }
            if (model.cusSex != null)
            {
                strSql.Append("cusSex='" + model.cusSex + "',");
            }
            if (model.cusAge >= 18 && model.cusAge <= 80)
            {
                strSql.Append("cusAge=" + model.cusAge + ",");
            }
            int n = strSql.ToString().LastIndexOf(",");

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

            if (rowsAffected > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public bool Add(Maticsoft.Model.Customer model)
        {
            StringBuilder strSql  = new StringBuilder();
            StringBuilder strSql1 = new StringBuilder();
            StringBuilder strSql2 = new StringBuilder();

            if (model.cusID != null)
            {
                strSql1.Append("cusID,");
                strSql2.Append("'" + model.cusID + "',");
            }
            if (model.cusName != null)
            {
                strSql1.Append("cusName,");
                strSql2.Append("'" + model.cusName + "',");
            }
            if (model.cusSex != null)
            {
                strSql1.Append("cusSex,");
                strSql2.Append("'" + model.cusSex + "',");
            }
            if (model.cusAge >= 18 && model.cusAge <= 80)
            {
                strSql1.Append("cusAge,");
                strSql2.Append("" + model.cusAge + ",");
            }
            strSql.Append("insert into Customer(");
            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);
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Maticsoft.Model.Customer GetModel(string cusID)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select  top 1  ");
            strSql.Append(" cusID,cusName,cusSex,cusAge ");
            strSql.Append(" from Customer ");
            strSql.Append(" where cusID='" + cusID + "' ");
            Maticsoft.Model.Customer model = new Maticsoft.Model.Customer();
            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.º 4
0
 /// <summary>
 /// 得到一个对象实体
 /// </summary>
 public Maticsoft.Model.Customer DataRowToModel(DataRow row)
 {
     Maticsoft.Model.Customer model = new Maticsoft.Model.Customer();
     if (row != null)
     {
         if (row["cusID"] != null)
         {
             model.cusID = row["cusID"].ToString();
         }
         if (row["cusName"] != null)
         {
             model.cusName = row["cusName"].ToString();
         }
         if (row["cusSex"] != null)
         {
             model.cusSex = row["cusSex"].ToString();
         }
         if (row["cusAge"] != null && row["cusAge"].ToString() != "")
         {
             model.cusAge = int.Parse(row["cusAge"].ToString());
         }
     }
     return(model);
 }