Пример #1
0
        public int insert(AdvertiseModels item)
        {
            int rs = 0;
            StringBuilder sqlBuilder = new StringBuilder();
            sqlBuilder.Append("INSERT ");
            sqlBuilder.Append("INTO ");
            sqlBuilder.Append("gov_advertise ");
            sqlBuilder.Append("( ");
            sqlBuilder.Append("title, ");
            sqlBuilder.Append("attach_file, ");
            sqlBuilder.Append("link, ");
            sqlBuilder.Append("type_link, ");
            sqlBuilder.Append("department, ");
            sqlBuilder.Append("price, ");
            sqlBuilder.Append("note, ");
            sqlBuilder.Append("order_number, ");
            sqlBuilder.Append("begin_date, ");
            sqlBuilder.Append("end_date, ");
            sqlBuilder.Append("location, ");
            sqlBuilder.Append("active_flg, ");
            sqlBuilder.Append("update_username, ");
            sqlBuilder.Append("update_datetime");
            sqlBuilder.Append(") ");
            sqlBuilder.Append("values(");
            sqlBuilder.Append("@1, @2, @3, @4, @5, @6, @7, @8, @9, @10, @11, @12, @13, @14");
            sqlBuilder.Append(")");
            this.Sql = sqlBuilder.ToString();
            MySqlCommand objCmd = new MySqlCommand(Sql, getConnection());
            objCmd.Parameters.AddWithValue("@1", item.Title);
            objCmd.Parameters.AddWithValue("@2", item.AttachFile);
            objCmd.Parameters.AddWithValue("@3", item.Link);
            objCmd.Parameters.AddWithValue("@4", item.TypeLink);
            objCmd.Parameters.AddWithValue("@5", item.Department);
            objCmd.Parameters.AddWithValue("@6", item.Price);
            objCmd.Parameters.AddWithValue("@7", item.Note);
            objCmd.Parameters.AddWithValue("@8", item.OrderNumber);
            objCmd.Parameters.AddWithValue("@9", item.StartDate);
            objCmd.Parameters.AddWithValue("@10", item.EndDate);
            objCmd.Parameters.AddWithValue("@11", item.Location);
            objCmd.Parameters.AddWithValue("@12", item.ActiveFlg);
            objCmd.Parameters.AddWithValue("@13", item.UpdateUsername);
            objCmd.Parameters.AddWithValue("@14", item.UpdateDatetime);

            rs = objCmd.ExecuteNonQuery();
            return rs;
        }
Пример #2
0
        public int Update(AdvertiseModels item)
        {
            int rs = 0;
            StringBuilder sqlBuilder = new StringBuilder();
            sqlBuilder.Append("UPDATE ");
            sqlBuilder.Append("gov_advertise ");
            sqlBuilder.Append("SET ");
            sqlBuilder.Append("title = @1, ");
            sqlBuilder.Append("attach_file = @2, ");
            sqlBuilder.Append("link = @3, ");
            sqlBuilder.Append("type_link = @4, ");
            sqlBuilder.Append("department = @5, ");
            sqlBuilder.Append("price = @6, ");
            sqlBuilder.Append("note = @7, ");
            sqlBuilder.Append("order_number = @8, ");
            sqlBuilder.Append("begin_date = @9, ");
            sqlBuilder.Append("end_date = @10, ");
            sqlBuilder.Append("location = @11, ");
            sqlBuilder.Append("active_flg = @12, ");
            sqlBuilder.Append("update_username = @13, ");
            sqlBuilder.Append("update_datetime = @14 ");
            sqlBuilder.Append("WHERE ");
            sqlBuilder.Append("id = @15");
            this.Sql = sqlBuilder.ToString();
            MySqlCommand objCmd = new MySqlCommand(Sql, getConnection());
            objCmd.Parameters.AddWithValue("@1", item.Title);
            objCmd.Parameters.AddWithValue("@2", item.AttachFile);
            objCmd.Parameters.AddWithValue("@3", item.Link);
            objCmd.Parameters.AddWithValue("@4", item.TypeLink);
            objCmd.Parameters.AddWithValue("@5", item.Department);
            objCmd.Parameters.AddWithValue("@6", item.Price);
            objCmd.Parameters.AddWithValue("@7", item.Note);
            objCmd.Parameters.AddWithValue("@8", item.OrderNumber);
            objCmd.Parameters.AddWithValue("@9", item.StartDate);
            objCmd.Parameters.AddWithValue("@10", item.EndDate);
            objCmd.Parameters.AddWithValue("@11", item.Location);
            objCmd.Parameters.AddWithValue("@12", item.ActiveFlg);
            objCmd.Parameters.AddWithValue("@13", item.UpdateUsername);
            objCmd.Parameters.AddWithValue("@14", item.UpdateDatetime);
            objCmd.Parameters.AddWithValue("@15", item.Id);

            rs = objCmd.ExecuteNonQuery();
            return rs;
        }
Пример #3
0
        public List<AdvertiseModels> select(int page, int limit)
        {

            int offset = (page - 1) * limit;
            StringBuilder sqlBuilder = new StringBuilder();
            sqlBuilder.Append("SELECT ");
            sqlBuilder.Append("* ");
            sqlBuilder.Append("FROM ");
            sqlBuilder.Append("gov_advertise gat ");
            sqlBuilder.Append(getBaseSQL());
            if (page > 0 && limit > 0)
            {
                sqlBuilder.Append(" LIMIT @limit ");
                sqlBuilder.Append(" OFFSET @offset ");
            }
            this.Sql = sqlBuilder.ToString();

            MySqlCommand objCmd = new MySqlCommand(Sql, getConnection());
            if (page > 0 && limit > 0)
            {
                objCmd.Parameters.AddWithValue("@limit", limit);
                objCmd.Parameters.AddWithValue("@offset", offset);
            }

            List<AdvertiseModels> lstAdvertise = new List<AdvertiseModels>();
            AdvertiseModels item;
            try
            {
                MySqlDataReader dataReader = objCmd.ExecuteReader();
                while (dataReader.Read())
                {
                    item = new AdvertiseModels();
                    item.Id = Convert.ToInt32(dataReader["id"]);
                    item.Title = dataReader["title"].ToString();
                    item.AttachFile = dataReader["attach_file"].ToString();
                    item.Link = dataReader["link"].ToString();
                    item.TypeLink = Convert.ToBoolean(dataReader["type_link"]);
                    item.Department = dataReader["department"].ToString();
                    item.Price = Convert.ToInt32(dataReader["price"]);
                    item.Note = dataReader["note"].ToString();
                    item.OrderNumber = Convert.ToInt32(dataReader["order_number"]);
                    item.StartDate = Convert.ToDateTime(dataReader["begin_date"]);
                    item.EndDate = Convert.ToDateTime(dataReader["end_date"]);
                    item.Location = Convert.ToInt32(dataReader["location"]);
                    item.ActiveFlg = Convert.ToBoolean(dataReader["active_flg"]);
                    item.UpdateUsername = dataReader["update_username"].ToString();
                    item.UpdateDatetime = Convert.ToDateTime(dataReader["update_datetime"]);
                    lstAdvertise.Add(item);
                }
                getConnection().Close();
            }
            catch (Exception ex)
            {
                getConnection().Close();
            }
            return lstAdvertise;
        }