Beispiel #1
0
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(Maticsoft.Model.t_unit model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update t_unit set ");
            strSql.Append("code=@code,");
            strSql.Append("unit_kind=@unit_kind,");
            strSql.Append("unit_name=@unit_name,");
            strSql.Append("count=@count,");
            strSql.Append("price=@price,");
            strSql.Append("total_price=@total_price,");
            strSql.Append("begin_time=@begin_time,");
            strSql.Append("end_time=@end_time,");
            strSql.Append("status_code=@status_code,");
            strSql.Append("create_time=@create_time,");
            strSql.Append("update_time=@update_time");
            strSql.Append(" where id=@id");
            MySqlParameter[] parameters =
            {
                new MySqlParameter("@code",        MySqlDbType.VarChar,   255),
                new MySqlParameter("@unit_kind",   MySqlDbType.VarChar,   255),
                new MySqlParameter("@unit_name",   MySqlDbType.VarChar,   255),
                new MySqlParameter("@count",       MySqlDbType.Int32,      11),
                new MySqlParameter("@price",       MySqlDbType.Decimal,    10),
                new MySqlParameter("@total_price", MySqlDbType.Decimal,    10),
                new MySqlParameter("@begin_time",  MySqlDbType.DateTime),
                new MySqlParameter("@end_time",    MySqlDbType.DateTime),
                new MySqlParameter("@status_code", MySqlDbType.Int32,     255),
                new MySqlParameter("@create_time", MySqlDbType.DateTime),
                new MySqlParameter("@update_time", MySqlDbType.DateTime),
                new MySqlParameter("@id",          MySqlDbType.Int32, 11)
            };
            parameters[0].Value  = model.code;
            parameters[1].Value  = model.unit_kind;
            parameters[2].Value  = model.unit_name;
            parameters[3].Value  = model.count;
            parameters[4].Value  = model.price;
            parameters[5].Value  = model.total_price;
            parameters[6].Value  = model.begin_time;
            parameters[7].Value  = model.end_time;
            parameters[8].Value  = model.status_code;
            parameters[9].Value  = model.create_time;
            parameters[10].Value = model.update_time;
            parameters[11].Value = model.id;

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

            if (rows > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Beispiel #2
0
 /// <summary>
 /// 得到一个对象实体
 /// </summary>
 public Maticsoft.Model.t_unit DataRowToModel(DataRow row)
 {
     Maticsoft.Model.t_unit model = new Maticsoft.Model.t_unit();
     if (row != null)
     {
         if (row["id"] != null && row["id"].ToString() != "")
         {
             model.id = int.Parse(row["id"].ToString());
         }
         if (row["code"] != null)
         {
             model.code = row["code"].ToString();
         }
         if (row["unit_kind"] != null)
         {
             model.unit_kind = row["unit_kind"].ToString();
         }
         if (row["unit_name"] != null)
         {
             model.unit_name = row["unit_name"].ToString();
         }
         if (row["count"] != null && row["count"].ToString() != "")
         {
             model.count = int.Parse(row["count"].ToString());
         }
         if (row["price"] != null && row["price"].ToString() != "")
         {
             model.price = decimal.Parse(row["price"].ToString());
         }
         if (row["total_price"] != null && row["total_price"].ToString() != "")
         {
             model.total_price = decimal.Parse(row["total_price"].ToString());
         }
         if (row["begin_time"] != null && row["begin_time"].ToString() != "")
         {
             model.begin_time = DateTime.Parse(row["begin_time"].ToString());
         }
         if (row["end_time"] != null && row["end_time"].ToString() != "")
         {
             model.end_time = DateTime.Parse(row["end_time"].ToString());
         }
         if (row["status_code"] != null && row["status_code"].ToString() != "")
         {
             model.status_code = int.Parse(row["status_code"].ToString());
         }
         if (row["create_time"] != null && row["create_time"].ToString() != "")
         {
             model.create_time = DateTime.Parse(row["create_time"].ToString());
         }
         if (row["update_time"] != null && row["update_time"].ToString() != "")
         {
             model.update_time = DateTime.Parse(row["update_time"].ToString());
         }
     }
     return(model);
 }
Beispiel #3
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public bool Add(Maticsoft.Model.t_unit model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into t_unit(");
            strSql.Append("code,unit_kind,unit_name,count,price,total_price,begin_time,end_time,status_code,create_time,update_time)");
            strSql.Append(" values (");
            strSql.Append("@code,@unit_kind,@unit_name,@count,@price,@total_price,@begin_time,@end_time,@status_code,@create_time,@update_time)");
            MySqlParameter[] parameters =
            {
                new MySqlParameter("@code",        MySqlDbType.VarChar,   255),
                new MySqlParameter("@unit_kind",   MySqlDbType.VarChar,   255),
                new MySqlParameter("@unit_name",   MySqlDbType.VarChar,   255),
                new MySqlParameter("@count",       MySqlDbType.Int32,      11),
                new MySqlParameter("@price",       MySqlDbType.Decimal,    10),
                new MySqlParameter("@total_price", MySqlDbType.Decimal,    10),
                new MySqlParameter("@begin_time",  MySqlDbType.DateTime),
                new MySqlParameter("@end_time",    MySqlDbType.DateTime),
                new MySqlParameter("@status_code", MySqlDbType.Int32,     255),
                new MySqlParameter("@create_time", MySqlDbType.DateTime),
                new MySqlParameter("@update_time", MySqlDbType.DateTime)
            };
            parameters[0].Value  = model.code;
            parameters[1].Value  = model.unit_kind;
            parameters[2].Value  = model.unit_name;
            parameters[3].Value  = model.count;
            parameters[4].Value  = model.price;
            parameters[5].Value  = model.total_price;
            parameters[6].Value  = model.begin_time;
            parameters[7].Value  = model.end_time;
            parameters[8].Value  = model.status_code;
            parameters[9].Value  = model.create_time;
            parameters[10].Value = model.update_time;

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

            if (rows > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Beispiel #4
0
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Maticsoft.Model.t_unit GetModel(int id)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select id,code,unit_kind,unit_name,count,price,total_price,begin_time,end_time,status_code,create_time,update_time from t_unit ");
            strSql.Append(" where id=@id");
            MySqlParameter[] parameters =
            {
                new MySqlParameter("@id", MySqlDbType.Int32)
            };
            parameters[0].Value = id;

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

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